Changeset 5c95436 in network-game for client/Client/main.cpp
- Timestamp:
- Jun 21, 2013, 1:52:53 AM (12 years ago)
- Branches:
- master
- Children:
- 109e8a3
- Parents:
- 5a5f131
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r5a5f131 r5c95436 36 36 #include "Textbox.h" 37 37 #include "Button.h" 38 #include "RadioButtonList.h" 38 39 #include "chat.h" 39 40 … … 53 54 54 55 // callbacks 56 void goToLoginScreen(); 57 void goToRegisterScreen(); 55 58 void registerAccount(); 56 59 void login(); … … 75 78 76 79 Window* wndLogin; 80 Window* wndRegister; 77 81 Window* wndMain; 78 82 Window* wndCurrent; 79 83 84 // wndLogin 80 85 Textbox* txtUsername; 81 86 Textbox* txtPassword; 87 88 // wndRegister 89 Textbox* txtUsernameRegister; 90 Textbox* txtPasswordRegister; 91 RadioButtonList* rblClasses; 92 93 // wndMain 82 94 Textbox* txtChat; 83 95 … … 160 172 wndLogin->addComponent(new Textbox(104, 40, 100, 20, font)); 161 173 wndLogin->addComponent(new Textbox(104, 70, 100, 20, font)); 162 wndLogin->addComponent(new Button(22, 100, 90, 20, font, " Register", registerAccount));174 wndLogin->addComponent(new Button(22, 100, 90, 20, font, "Create an Account", goToRegisterScreen)); 163 175 wndLogin->addComponent(new Button(122, 100, 60, 20, font, "Login", login)); 164 176 wndLogin->addComponent(new Button(540, 10, 80, 20, font, "Quit", quit)); … … 166 178 txtUsername = (Textbox*)wndLogin->getComponent(0); 167 179 txtPassword = (Textbox*)wndLogin->getComponent(1); 180 181 wndRegister = new Window(0, 0, SCREEN_W, SCREEN_H); 182 wndRegister->addComponent(new Textbox(104, 40, 100, 20, font)); 183 wndRegister->addComponent(new Textbox(104, 70, 100, 20, font)); 184 wndRegister->addComponent(new Button(22, 100, 90, 20, font, "Back", goToLoginScreen)); 185 wndRegister->addComponent(new Button(122, 100, 60, 20, font, "Submit", registerAccount)); 186 wndRegister->addComponent(new Button(540, 10, 80, 20, font, "Quit", quit)); 187 wndRegister->addComponent(new RadioButtonList(20, 130, "Pick a class", font)); 188 189 txtUsernameRegister = (Textbox*)wndRegister->getComponent(0); 190 txtPasswordRegister = (Textbox*)wndRegister->getComponent(1); 191 192 rblClasses = (RadioButtonList*)wndRegister->getComponent(5); 193 rblClasses->addRadioButton("Warrior"); 194 rblClasses->addRadioButton("Ranger"); 168 195 169 196 wndMain = new Window(0, 0, SCREEN_W, SCREEN_H); … … 833 860 } 834 861 835 void registerAccount() 836 { 837 string username = txtUsername->getStr(); 838 string password = txtPassword->getStr(); 862 void goToRegisterScreen() 863 { 864 wndCurrent = wndRegister; 865 866 txtUsernameRegister->clear(); 867 txtPasswordRegister->clear(); 868 } 869 870 void goToLoginScreen() 871 { 872 wndCurrent = wndLogin; 839 873 840 874 txtUsername->clear(); 841 875 txtPassword->clear(); 876 } 877 878 void registerAccount() 879 { 880 string username = txtUsernameRegister->getStr(); 881 string password = txtPasswordRegister->getStr(); 882 883 txtUsernameRegister->clear(); 884 txtPasswordRegister->clear(); 885 // maybe clear rblClasses as well (add a method to RadioButtonList to enable this) 886 887 Player::PlayerClass playerClass; 888 889 switch (rblClasses->getSelectedButton()) { 890 case 0: 891 playerClass = Player::CLASS_WARRIOR; 892 break; 893 case 1: 894 playerClass = Player::CLASS_RANGER; 895 break; 896 default: 897 cout << "Invalid class selection" << endl; 898 playerClass = Player::CLASS_NONE; 899 break; 900 } 842 901 843 902 msgTo.type = MSG_TYPE_REGISTER; … … 845 904 strcpy(msgTo.buffer, username.c_str()); 846 905 strcpy(msgTo.buffer+username.size()+1, password.c_str()); 906 memcpy(msgTo.buffer+username.size()+password.size()+2, &playerClass, 4); 847 907 848 908 sendMessage(&msgTo, sock, &server);
Note:
See TracChangeset
for help on using the changeset viewer.