-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
LunaLobby.cpp
154 lines (119 loc) · 5.36 KB
/
LunaLobby.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "Luna.h"
int Luna::lobby() {
// #ifndef NDEBUG
// falsify the quit flags
events.quit = false;
events.login = false;
// Flush the gui factory
guienv->clear();
smgr->clear();
device->setEventReceiver ( &events );
smgr->loadScene ( "./data/models/maps/lobby.irr" );
//smgr->addCameraSceneNode(0, vector3df(20,100, 0), vector3df(0,100,0), -1);
//smgr->addCameraSceneNodeFPS();
ITexture *loginWindow = driver->getTexture ( "./data/textures/lobby/loginBg.png" );
int buttonPosX = ( resolution[0] / 2 ) - 60;
int buttonPosY = ( resolution[1] / 100 ) * 80;
IGUIEditBox *uname = guienv->addEditBox ( L"", rect<s32> ( buttonPosX - 30, buttonPosY - 100, buttonPosX + 150, buttonPosY - 80 ), true, 0, -1 );
IGUIEditBox *pword = guienv->addEditBox ( L"", rect<s32> ( buttonPosX - 30, buttonPosY - 60, buttonPosX + 150, buttonPosY - 40 ), true, 0, -1 );
pword->setPasswordBox ( true, L'*' );
// Load the button textures
ITexture *menuButtonNormal = driver->getTexture ( "./data/textures/lobby/lobbyButtonNormal.png" );
ITexture *menuButtonDepressed = driver->getTexture ( "./data/textures/lobby/lobbyButtonDepressed.png" );
IGUIButton *exitButton = guienv->addButton ( rect<s32> ( buttonPosX, buttonPosY + 50, buttonPosX + 120, buttonPosY + 70 ), 0, 101, L"Exit" );
exitButton->setImage ( menuButtonNormal );
exitButton->setPressedImage ( menuButtonDepressed );
IGUIButton *loginButton = guienv->addButton ( rect<s32> ( buttonPosX, buttonPosY + 0, buttonPosX + 120, buttonPosY + 20 ), 0, 102, L"Login" );
loginButton->setImage ( menuButtonNormal );
loginButton->setPressedImage ( menuButtonDepressed );
IGUIButton *optionsButton = guienv->addButton ( rect<s32> ( buttonPosX, buttonPosY + 25, buttonPosX + 120, buttonPosY + 45 ), 0, 103, L"Options" );
optionsButton->setImage ( menuButtonNormal );
optionsButton->setPressedImage ( menuButtonDepressed );
// Developers login box
#ifdef NDEBUG
IGUIButton *devButton = guienv->addButton ( rect<s32> ( buttonPosX, buttonPosY - 25, buttonPosX + 120, buttonPosY-10 ), 0, 901, L"Dev Login" );
devButton->setImage ( menuButtonNormal );
devButton->setPressedImage ( menuButtonDepressed );
#endif
// Do the text
guienv->addStaticText ( L"Account Login.", rect<s32> ( buttonPosX - 60, buttonPosY - 148, buttonPosX + 120, buttonPosY - 138 ) );
guienv->addStaticText ( L"Username:", rect<s32> ( buttonPosX - 30, buttonPosY - 110, buttonPosX + 120, buttonPosY - 100 ) );
guienv->addStaticText ( L"Password:", rect<s32> ( buttonPosX - 30, buttonPosY - 70, buttonPosX + 120, buttonPosY - 60 ) );
// Error message buttons
IGUIButton *conOK;
IGUIStaticText *conMessage;
IGUIButton *wrongPWOK;
IGUIStaticText *wrongPWMessage;
// Error message flags
bool conRefOK = false;
bool wrongPassOK = false;
while ( device->run() && !events.quit && !events.devLogin )
{
if ( conRefOK && events.conRefOK ) {
conRefOK = events.conRefOK = false;
conOK->remove();
conMessage->remove();
loginButton->setEnabled ( true );
optionsButton->setEnabled ( true );
exitButton->setEnabled ( true );
uname->setEnabled ( true );
pword->setEnabled ( true );
}
if ( wrongPassOK && events.wrongPassOK ) {
events.wrongPassOK = false;
wrongPWOK->remove();
wrongPWMessage->remove();
loginButton->setEnabled ( true );
optionsButton->setEnabled ( true );
exitButton->setEnabled ( true );
uname->setEnabled ( true );
pword->setEnabled ( true );
}
if ( events.login ) { // login button was clicked
// and connected
int ret = doLogin ( std::wstring ( uname->getText() ), std::wstring ( pword->getText() ) );
//nt ret=-1;
if ( ret == -1 ){ // if ret -1 and the server says yes
printf ("returned -1\n");
events.quit=true;
// break;
return 1;
}
else if ( ret == 1 ) {
printf ("returned 1\n");
wrongPWMessage = guienv->addStaticText ( L"Incorrect username or password.", rect<s32> ( 0, 0, 130, 10 ) );
wrongPWOK = guienv->addButton ( rect<s32> ( buttonPosX, resolution[1] / 2, buttonPosX + 120, ( resolution[1]/2 ) + 20 ), 0, 105, L"Wrong Password" );
wrongPWOK->setImage ( menuButtonNormal );
wrongPWOK->setPressedImage ( menuButtonDepressed );
loginButton->setEnabled ( false );
optionsButton->setEnabled ( false );
exitButton->setEnabled ( false );
uname->setEnabled ( false ); pword->setEnabled ( false );
events.login = false;
wrongPassOK = true;
}
else if ( ret == 0 ) {
printf ("returned 0\n");
conMessage = guienv->addStaticText ( L"Could not connect to the server, please see the status page", rect<s32> ( 0, 0, 130, 10 ) );
conOK = guienv->addButton ( rect<s32> ( buttonPosX, resolution[1] / 2, buttonPosX + 120, ( resolution[1]/2 ) + 20 ), 0, 104, L"no server connection" );
conOK->setImage ( menuButtonNormal );
conOK->setPressedImage ( menuButtonDepressed );
loginButton->setEnabled ( false );
optionsButton->setEnabled ( false );
exitButton->setEnabled ( false );
uname->setEnabled ( false );
pword->setEnabled ( false );
events.login = false;
//conRefOK = true;
}
}
driver->beginScene ( true, true, SColor ( 0, 0, 0, 0 ) );
smgr->drawAll();
driver->draw2DImage ( loginWindow, core::position2d<s32> ( buttonPosX - 65, buttonPosY - 150 ) );
guienv->drawAll();
driver->endScene();
// device->sleep ( 10, true );
}
return 0;
// #endif
}