Changeset 365e156 in network-game for client


Ignore:
Timestamp:
Jul 21, 2013, 6:25:00 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
49da01a
Parents:
09ddba7
Message:

Added a TextLabel gui element and updated the client to show status messages when registering or logging in

Location:
client/Client
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Client.vcxproj

    r09ddba7 r365e156  
    7979    <ClCompile Include="RadioButtonList.cpp" />
    8080    <ClCompile Include="Textbox.cpp" />
     81    <ClCompile Include="TextLabel.cpp" />
    8182    <ClCompile Include="Window.cpp" />
    8283  </ItemGroup>
     
    9495    <ClInclude Include="RadioButtonList.h" />
    9596    <ClInclude Include="Textbox.h" />
     97    <ClInclude Include="TextLabel.h" />
    9698    <ClInclude Include="Window.h" />
    9799  </ItemGroup>
  • client/Client/Client.vcxproj.filters

    r09ddba7 r365e156  
    6767      <Filter>Source Files\common</Filter>
    6868    </ClCompile>
     69    <ClCompile Include="TextLabel.cpp">
     70      <Filter>Source Files\gui</Filter>
     71    </ClCompile>
    6972  </ItemGroup>
    7073  <ItemGroup>
     
    108111      <Filter>Header Files\common</Filter>
    109112    </ClInclude>
     113    <ClInclude Include="TextLabel.h">
     114      <Filter>Header Files\gui</Filter>
     115    </ClInclude>
    110116  </ItemGroup>
    111117  <ItemGroup>
  • client/Client/main.cpp

    r09ddba7 r365e156  
    3838#include "Button.h"
    3939#include "RadioButtonList.h"
     40#include "TextLabel.h"
    4041#include "chat.h"
    4142
     
    8788Textbox* txtUsername;
    8889Textbox* txtPassword;
     90TextLabel* lblLoginStatus;
    8991
    9092// wndRegister
     
    9294Textbox* txtPasswordRegister;
    9395RadioButtonList* rblClasses;
     96TextLabel* lblRegisterStatus;
    9497
    9598// wndMain
     
    180183   WorldMap* gameMap = WorldMap::loadMapFromFile("../../data/map.txt");
    181184
     185   cout << "Loaded map" << endl;
     186
    182187   wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H);
    183188   wndLogin->addComponent(new Textbox(516, 40, 100, 20, font));
    184189   wndLogin->addComponent(new Textbox(516, 70, 100, 20, font));
    185    wndLogin->addComponent(new Button(330, 100, 194, 20, font, "Create an Account", goToRegisterScreen));
    186    wndLogin->addComponent(new Button(534, 100, 60, 20, font, "Login", login));
     190   wndLogin->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT));
     191   wndLogin->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT));
     192   wndLogin->addComponent(new TextLabel((SCREEN_W-600)/2, 100, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE));
     193   wndLogin->addComponent(new Button(SCREEN_W/2-100, 130, 90, 20, font, "Register", goToRegisterScreen));
     194   wndLogin->addComponent(new Button(SCREEN_W/2+10, 130, 90, 20, font, "Login", login));
    187195   wndLogin->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit));
    188196
    189197   txtUsername = (Textbox*)wndLogin->getComponent(0);
    190198   txtPassword = (Textbox*)wndLogin->getComponent(1);
     199   lblLoginStatus = (TextLabel*)wndLogin->getComponent(4);
     200
     201   cout << "Created login screen" << endl;
    191202
    192203   wndRegister = new Window(0, 0, SCREEN_W, SCREEN_H);
    193204   wndRegister->addComponent(new Textbox(516, 40, 100, 20, font));
    194205   wndRegister->addComponent(new Textbox(516, 70, 100, 20, font));
    195    wndRegister->addComponent(new Button(468, 100, 56, 20, font, "Back", goToLoginScreen));
    196    wndRegister->addComponent(new Button(534, 100, 70, 20, font, "Submit", registerAccount));
     206   wndRegister->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT));
     207   wndRegister->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT));
     208   wndRegister->addComponent(new RadioButtonList(432, 100, "Pick a class", font));
     209   wndRegister->addComponent(new TextLabel((SCREEN_W-600)/2, 190, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE));
     210   wndRegister->addComponent(new Button(SCREEN_W/2-100, 220, 90, 20, font, "Back", goToLoginScreen));
     211   wndRegister->addComponent(new Button(SCREEN_W/2+10, 220, 90, 20, font, "Submit", registerAccount));
    197212   wndRegister->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit));
    198    wndRegister->addComponent(new RadioButtonList(432, 130, "Pick a class", font));
    199213
    200214   txtUsernameRegister = (Textbox*)wndRegister->getComponent(0);
    201215   txtPasswordRegister = (Textbox*)wndRegister->getComponent(1);
    202216
    203    rblClasses = (RadioButtonList*)wndRegister->getComponent(5);
     217   rblClasses = (RadioButtonList*)wndRegister->getComponent(4);
    204218   rblClasses->addRadioButton("Warrior");
    205219   rblClasses->addRadioButton("Ranger");
     220
     221   lblRegisterStatus = (TextLabel*)wndRegister->getComponent(5);
     222
     223   cout << "Created register screen" << endl;
    206224
    207225   wndMain = new Window(0, 0, SCREEN_W, SCREEN_H);
     
    211229
    212230   txtChat = (Textbox*)wndMain->getComponent(0);
     231
     232   cout << "Created main screen" << endl;
    213233
    214234   wndCurrent = wndLogin;
     
    380400         // There should be label gui components that show these or each textbox should have a label
    381401         if(wndCurrent == wndLogin || wndCurrent == wndRegister) {
    382             al_draw_text(font, al_map_rgb(0, 255, 0), 416, 43, ALLEGRO_ALIGN_LEFT, "Username:");
    383             al_draw_text(font, al_map_rgb(0, 255, 0), 413, 73, ALLEGRO_ALIGN_LEFT, "Password:");
     402            //al_draw_text(font, al_map_rgb(0, 255, 0), 416, 43, ALLEGRO_ALIGN_LEFT, "Username:");
     403            //al_draw_text(font, al_map_rgb(0, 255, 0), 413, 73, ALLEGRO_ALIGN_LEFT, "Password:");
    384404         }
    385405         else if(wndCurrent == wndMain) {
     
    541561            case MSG_TYPE_REGISTER:
    542562            {
     563               lblRegisterStatus->setText(response);
    543564               break;
    544565            }
     
    549570                  username.clear();
    550571                  cout << "User login failed" << endl;
     572                  lblLoginStatus->setText(response);
    551573               }
    552574               else if (response.compare("Incorrect username or password") == 0)
     
    554576                  username.clear();
    555577                  cout << "User login failed" << endl;
     578                  lblLoginStatus->setText(response);
    556579               }
    557580               else
     
    573596               break;
    574597            }
    575             case MSG_TYPE_PLAYER:   // kind of hacky to put this here
     598            case MSG_TYPE_PLAYER:
    576599            {
    577600               Player p("", "");
     
    592615               break;
    593616            }
     617            default:
     618            {
     619               cout << "(STATE_REGISTER) Received invlaid message of type " << msg.type << endl;
     620               break;
     621            }
    594622         }
    595623
     
    600628         switch(msg.type)
    601629         {
    602             case MSG_TYPE_REGISTER:
    603             {
    604                break;
    605             }
    606630            case MSG_TYPE_LOGIN:
    607631            {
     
    760784            default:
    761785            {
    762                cout << "Received an unexpected message type: " << msg.type << endl;
     786               cout << "(STATE_LOGIN) Received invlaid message of type " << msg.type << endl;
     787               break;
    763788            }
    764789         }
Note: See TracChangeset for help on using the changeset viewer.