Changeset 5c95436 in network-game


Ignore:
Timestamp:
Jun 21, 2013, 1:52:53 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
109e8a3
Parents:
5a5f131
Message:

Add a RadioButtonList gui control to the client, re-organize the login/registration screen into two separate screens, and allow the player to select their class during registration

Location:
client/Client
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Client.vcxproj

    r5a5f131 r5c95436  
    7373    <ClCompile Include="GuiComponent.cpp" />
    7474    <ClCompile Include="main.cpp" />
     75    <ClCompile Include="RadioButtonList.cpp" />
    7576    <ClCompile Include="Textbox.cpp" />
    7677    <ClCompile Include="Window.cpp" />
     
    8687    <ClInclude Include="Button.h" />
    8788    <ClInclude Include="GuiComponent.h" />
     89    <ClInclude Include="RadioButtonList.h" />
    8890    <ClInclude Include="Textbox.h" />
    8991    <ClInclude Include="Window.h" />
  • client/Client/Client.vcxproj.filters

    r5a5f131 r5c95436  
    6161      <Filter>Source Files\common</Filter>
    6262    </ClCompile>
     63    <ClCompile Include="RadioButtonList.cpp">
     64      <Filter>Source Files\gui</Filter>
     65    </ClCompile>
    6366  </ItemGroup>
    6467  <ItemGroup>
     
    9699      <Filter>Header Files\common</Filter>
    97100    </ClInclude>
     101    <ClInclude Include="RadioButtonList.h">
     102      <Filter>Header Files\gui</Filter>
     103    </ClInclude>
    98104  </ItemGroup>
    99105  <ItemGroup>
  • client/Client/main.cpp

    r5a5f131 r5c95436  
    3636#include "Textbox.h"
    3737#include "Button.h"
     38#include "RadioButtonList.h"
    3839#include "chat.h"
    3940
     
    5354
    5455// callbacks
     56void goToLoginScreen();
     57void goToRegisterScreen();
    5558void registerAccount();
    5659void login();
     
    7578
    7679Window* wndLogin;
     80Window* wndRegister;
    7781Window* wndMain;
    7882Window* wndCurrent;
    7983
     84// wndLogin
    8085Textbox* txtUsername;
    8186Textbox* txtPassword;
     87
     88// wndRegister
     89Textbox* txtUsernameRegister;
     90Textbox* txtPasswordRegister;
     91RadioButtonList* rblClasses;
     92
     93// wndMain
    8294Textbox* txtChat;
    8395
     
    160172   wndLogin->addComponent(new Textbox(104, 40, 100, 20, font));
    161173   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));
    163175   wndLogin->addComponent(new Button(122, 100, 60, 20, font, "Login", login));
    164176   wndLogin->addComponent(new Button(540, 10, 80, 20, font, "Quit", quit));
     
    166178   txtUsername = (Textbox*)wndLogin->getComponent(0);
    167179   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");
    168195
    169196   wndMain = new Window(0, 0, SCREEN_W, SCREEN_H);
     
    833860}
    834861
    835 void registerAccount()
    836 {
    837    string username = txtUsername->getStr();
    838    string password = txtPassword->getStr();
     862void goToRegisterScreen()
     863{
     864   wndCurrent = wndRegister;
     865
     866   txtUsernameRegister->clear();
     867   txtPasswordRegister->clear();
     868}
     869
     870void goToLoginScreen()
     871{
     872   wndCurrent = wndLogin;
    839873
    840874   txtUsername->clear();
    841875   txtPassword->clear();
     876}
     877
     878void 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   }
    842901
    843902   msgTo.type = MSG_TYPE_REGISTER;
     
    845904   strcpy(msgTo.buffer, username.c_str());
    846905   strcpy(msgTo.buffer+username.size()+1, password.c_str());
     906   memcpy(msgTo.buffer+username.size()+password.size()+2, &playerClass, 4);
    847907
    848908   sendMessage(&msgTo, sock, &server);
Note: See TracChangeset for help on using the changeset viewer.