sources/interface.cpp

changeset 138
c909c38ca886
parent 137
485cb6d6b98c
child 139
da7d5a8e608f
equal deleted inserted replaced
137:485cb6d6b98c 138:c909c38ca886
187 int bg = (j == DEFAULT) ? defaultBg : j; 187 int bg = (j == DEFAULT) ? defaultBg : j;
188 188
189 if (fg != -1 || bg != -1) 189 if (fg != -1 || bg != -1)
190 { 190 {
191 if (::init_pair (pairnum, fg, bg) == ERR) 191 if (::init_pair (pairnum, fg, bg) == ERR)
192 print_warning ("Unable to initialize color pair %d (%d, %d)\n", pairnum, fg, bg); 192 printWarning ("Unable to initialize color pair %d (%d, %d)\n", pairnum, fg, bg);
193 } 193 }
194 } 194 }
195 } 195 }
196 196
197 render_full(); 197 renderFull();
198 refresh(); 198 refresh();
199 m_needRefresh = false; 199 m_needRefresh = false;
200 } 200 }
201 201
202 // ------------------------------------------------------------------------------------------------- 202 // -------------------------------------------------------------------------------------------------
218 m_needRefresh = true; 218 m_needRefresh = true;
219 } 219 }
220 220
221 // ------------------------------------------------------------------------------------------------- 221 // -------------------------------------------------------------------------------------------------
222 // 222 //
223 void Interface::set_title (const String& title) 223 void Interface::setTitle (const String& title)
224 { 224 {
225 m_title = title; 225 m_title = title;
226 render_titlebar(); 226 render_titlebar();
227 } 227 }
228 228
474 m_needStatusBarRender = false; 474 m_needStatusBarRender = false;
475 } 475 }
476 476
477 // ------------------------------------------------------------------------------------------------- 477 // -------------------------------------------------------------------------------------------------
478 // 478 //
479 void Interface::update_statusbar() 479 void Interface::updateStatusBar()
480 { 480 {
481 String text; 481 String text;
482 482
483 switch (m_session.state()) 483 switch (m_session.state())
484 { 484 {
526 } 526 }
527 } 527 }
528 528
529 // ------------------------------------------------------------------------------------------------- 529 // -------------------------------------------------------------------------------------------------
530 // 530 //
531 void Interface::render_full() 531 void Interface::renderFull()
532 { 532 {
533 update_statusbar(); 533 updateStatusBar();
534 render_titlebar(); 534 render_titlebar();
535 render_output(); 535 render_output();
536 render_statusbar(); 536 render_statusbar();
537 render_input(); 537 render_input();
538 render_nicklist(); 538 render_nicklist();
606 m_needInputRender = true; 606 m_needInputRender = true;
607 } 607 }
608 608
609 // ------------------------------------------------------------------------------------------------- 609 // -------------------------------------------------------------------------------------------------
610 // 610 //
611 void Interface::handle_input() 611 void Interface::handleInput()
612 { 612 {
613 int ch = ::getch(); 613 int ch = ::getch();
614 614
615 if (ch < 0) 615 if (ch < 0)
616 return; 616 return;
617 617
618 if (ch == KEY_RESIZE) 618 if (ch == KEY_RESIZE)
619 { 619 {
620 ::clear(); 620 ::clear();
621 render_full(); 621 renderFull();
622 return; 622 return;
623 } 623 }
624 624
625 if (m_inputState == INPUTSTATE_CONFIRM_DISCONNECTION) 625 if (m_inputState == INPUTSTATE_CONFIRM_DISCONNECTION)
626 { 626 {
816 break; 816 break;
817 817
818 case INPUTSTATE_NORMAL: 818 case INPUTSTATE_NORMAL:
819 if (current_input()[0] == '/') 819 if (current_input()[0] == '/')
820 { 820 {
821 handle_command(current_input()); 821 handleCommand(current_input());
822 flush_input(); 822 flush_input();
823 } 823 }
824 else if (m_session.send_command (current_input())) 824 else if (m_session.send_command (current_input()))
825 { 825 {
826 flush_input(); 826 flush_input();
908 print_to_console (message); 908 print_to_console (message);
909 } 909 }
910 910
911 // ------------------------------------------------------------------------------------------------- 911 // -------------------------------------------------------------------------------------------------
912 // 912 //
913 void __cdecl Interface::print_text (const char* fmtstr, ...) 913 void __cdecl Interface::printText (const char* fmtstr, ...)
914 { 914 {
915 va_list args; 915 va_list args;
916 va_start (args, fmtstr); 916 va_start (args, fmtstr);
917 vprint (fmtstr, args); 917 vprint (fmtstr, args);
918 va_end (args); 918 va_end (args);
929 va_end (args); 929 va_end (args);
930 } 930 }
931 931
932 // ------------------------------------------------------------------------------------------------- 932 // -------------------------------------------------------------------------------------------------
933 // 933 //
934 void __cdecl Interface::print_warning (const char* fmtstr, ...) 934 void __cdecl Interface::printWarning (const char* fmtstr, ...)
935 { 935 {
936 va_list args; 936 va_list args;
937 va_start (args, fmtstr); 937 va_start (args, fmtstr);
938 print_to_console (TEXTCOLOR_BrightYellow "-!- "); 938 print_to_console (TEXTCOLOR_BrightYellow "-!- ");
939 vprint (fmtstr, args); 939 vprint (fmtstr, args);
940 va_end (args); 940 va_end (args);
941 } 941 }
942 942
943 // ------------------------------------------------------------------------------------------------- 943 // -------------------------------------------------------------------------------------------------
944 // 944 //
945 void __cdecl Interface::print_error (const char* fmtstr, ...) 945 void __cdecl Interface::printError (const char* fmtstr, ...)
946 { 946 {
947 va_list args; 947 va_list args;
948 va_start (args, fmtstr); 948 va_start (args, fmtstr);
949 print_to_console (TEXTCOLOR_BrightRed "!!! "); 949 print_to_console (TEXTCOLOR_BrightRed "!!! ");
950 vprint (fmtstr, args); 950 vprint (fmtstr, args);
1011 m_session.connect (m_remoteAddress); 1011 m_session.connect (m_remoteAddress);
1012 } 1012 }
1013 1013
1014 // ------------------------------------------------------------------------------------------------- 1014 // -------------------------------------------------------------------------------------------------
1015 // 1015 //
1016 void Interface::set_player_names (const StringList& names) 1016 void Interface::setPlayerNames (const StringList& names)
1017 { 1017 {
1018 m_playerNames.clear(); 1018 m_playerNames.clear();
1019 1019
1020 for (const String& name : names) 1020 for (const String& name : names)
1021 { 1021 {
1028 m_needNicklistRender = true; 1028 m_needNicklistRender = true;
1029 } 1029 }
1030 1030
1031 // ------------------------------------------------------------------------------------------------- 1031 // -------------------------------------------------------------------------------------------------
1032 // 1032 //
1033 void Interface::tab_complete (const String& part, String complete) 1033 void Interface::tabComplete (const String& part, String complete)
1034 { 1034 {
1035 String& input = mutable_current_input(); 1035 String& input = mutable_current_input();
1036 1036
1037 if (input.starts_with (part)) 1037 if (input.starts_with (part))
1038 { 1038 {
1045 } 1045 }
1046 } 1046 }
1047 1047
1048 // ------------------------------------------------------------------------------------------------- 1048 // -------------------------------------------------------------------------------------------------
1049 // 1049 //
1050 void Interface::handle_command(const String& input) 1050 void Interface::handleCommand(const String& input)
1051 { 1051 {
1052 if (input[0] != '/') 1052 if (input[0] != '/')
1053 return; 1053 return;
1054 1054
1055 StringList args = input.right(input.length() - 1).split(" "); 1055 StringList args = input.right(input.length() - 1).split(" ");
1058 1058
1059 if (command == "connect") 1059 if (command == "connect")
1060 { 1060 {
1061 if (args.size() != 2) 1061 if (args.size() != 2)
1062 { 1062 {
1063 print_error("Usage: /connect <address> <password>\n"); 1063 printError("Usage: /connect <address> <password>\n");
1064 } 1064 }
1065 else 1065 else
1066 { 1066 {
1067 IPAddress address; 1067 IPAddress address;
1068 1068
1070 { 1070 {
1071 address = IPAddress::from_string(args[0]); 1071 address = IPAddress::from_string(args[0]);
1072 } 1072 }
1073 catch (std::exception& e) 1073 catch (std::exception& e)
1074 { 1074 {
1075 print_error("%s\n", e.what()); 1075 printError("%s\n", e.what());
1076 return; 1076 return;
1077 } 1077 }
1078 1078
1079 if (address.port == 0) 1079 if (address.port == 0)
1080 address.port = 10666; 1080 address.port = 10666;
1093 m_session.disconnect(); 1093 m_session.disconnect();
1094 endwin(); 1094 endwin();
1095 throw Exitception(); 1095 throw Exitception();
1096 } 1096 }
1097 else 1097 else
1098 print_error("Unknown command: %s\n", command.chars()); 1098 printError("Unknown command: %s\n", command.chars());
1099 } 1099 }
1100 1100
1101 // ------------------------------------------------------------------------------------------------- 1101 // -------------------------------------------------------------------------------------------------
1102 // 1102 //
1103 void Interface::disconnected() 1103 void Interface::disconnected()
1104 { 1104 {
1105 print("Disconnected from %s\n", m_session.address().to_string(IPAddress::WITH_PORT).chars()); 1105 print("Disconnected from %s\n", m_session.address().to_string(IPAddress::WITH_PORT).chars());
1106 reset_title(); 1106 reset_title();
1107 render_full(); 1107 renderFull();
1108 } 1108 }
1109 1109
1110 // ------------------------------------------------------------------------------------------------- 1110 // -------------------------------------------------------------------------------------------------
1111 // 1111 //
1112 void Interface::reset_title() 1112 void Interface::reset_title()

mercurial