@@ -49,36 +49,49 @@ iwLobbyConnect::iwLobbyConnect()
4949 : IngameWindow(CGI_LOBBYCONNECT, IngameWindow::posLastOrCenter, Extent(500 , 260 ), _(" Connecting to Lobby" ),
5050 LOADER.GetImageN(" resource" , 41 ))
5151{
52- AddText (ID_txtUser, DrawPoint (20 , 40 ), _ (" Username:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
53- ctrlEdit* user = AddEdit (ID_edtUser, DrawPoint (260 , 40 ), Extent (220 , 22 ), TextureColor::Green2, NormalFont, 15 );
52+ DrawPoint curLblPos (20 , 40 );
53+ constexpr Extent edtSize (220 , 22 );
54+ constexpr auto ctrlStartPos = 260 ;
55+ constexpr Extent btSize (edtSize.x / 2 - 5 , edtSize.y );
56+ constexpr auto secCtrlStartPos = ctrlStartPos + btSize.x + 10 ;
57+
58+ AddText (ID_txtUser, curLblPos, _ (" Username:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
59+ ctrlEdit* user =
60+ AddEdit (ID_edtUser, DrawPoint (ctrlStartPos, curLblPos.y ), edtSize, TextureColor::Green2, NormalFont);
5461 user->SetFocus ();
5562 user->SetText (SETTINGS.lobby .name ); // -V807
63+ curLblPos.y += 30 ;
5664
57- AddText (ID_txtPw, DrawPoint (20 , 70 ), _ (" Password:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
58- ctrlEdit* pass = AddEdit (ID_edtPw, DrawPoint (260 , 70 ), Extent (220 , 22 ), TextureColor::Green2, NormalFont, 0 , true );
65+ AddText (ID_txtPw, curLblPos, _ (" Password:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
66+ ctrlEdit* pass =
67+ AddEdit (ID_edtPw, DrawPoint (ctrlStartPos, curLblPos.y ), edtSize, TextureColor::Green2, NormalFont, 0 , true );
5968 pass->SetText (isStoredPasswordHash (SETTINGS.lobby .password ) ? SETTINGS.lobby .password .substr (4 ) :
6069 SETTINGS.lobby .password );
70+ curLblPos.y += 30 ;
6171
62- AddText (ID_txtSavePw, DrawPoint (20 , 100 ), _ (" Save Password?" ), COLOR_YELLOW, FontStyle{}, NormalFont);
63-
64- Extent btSize = Extent (105 , 22 );
72+ AddText (ID_txtSavePw, curLblPos, _ (" Save Password?" ), COLOR_YELLOW, FontStyle{}, NormalFont);
6573 ctrlOptionGroup* savepassword = AddOptionGroup (ID_optSavePw, GroupSelectType::Check);
66- savepassword->AddTextButton (0 , DrawPoint (260 , 100 ), btSize, TextureColor::Green2, _ (" No" ), NormalFont);
67- savepassword->AddTextButton (1 , DrawPoint (375 , 100 ), btSize, TextureColor::Green2, _ (" Yes" ), NormalFont);
74+ savepassword->AddTextButton (0 , DrawPoint (ctrlStartPos, curLblPos.y ), btSize, TextureColor::Green2, _ (" No" ),
75+ NormalFont);
76+ savepassword->AddTextButton (1 , DrawPoint (secCtrlStartPos, curLblPos.y ), btSize, TextureColor::Green2, _ (" Yes" ),
77+ NormalFont);
6878 savepassword->SetSelection ((SETTINGS.lobby .save_password ? 1 : 0 ));
79+ curLblPos.y += 30 ;
6980
70- AddText (ID_txtProtocol, DrawPoint (20 , 130 ), _ (" Use IPv6:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
71-
81+ AddText (ID_txtProtocol, curLblPos, _ (" Use IPv6:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
7282 ctrlOptionGroup* ipv6 = AddOptionGroup (ID_optProtocol, GroupSelectType::Check);
73- ipv6->AddTextButton (0 , DrawPoint (260 , 130 ), btSize, TextureColor::Green2, _ (" IPv4" ), NormalFont);
74- ipv6->AddTextButton (1 , DrawPoint (375 , 130 ), btSize, TextureColor::Green2, _ (" IPv6" ), NormalFont);
83+ ipv6->AddTextButton (0 , DrawPoint (ctrlStartPos, curLblPos.y ), btSize, TextureColor::Green2, _ (" IPv4" ), NormalFont);
84+ ipv6->AddTextButton (1 , DrawPoint (secCtrlStartPos, curLblPos.y ), btSize, TextureColor::Green2, _ (" IPv6" ),
85+ NormalFont);
7586 ipv6->SetSelection ((SETTINGS.server .ipv6 ? 1 : 0 ));
7687
77- AddText (ID_txtStatus, DrawPoint (250 , 165 ), " " , COLOR_RED, FontStyle::CENTER, NormalFont);
88+ auto curYPos = curLblPos.y + 35 ;
89+ AddText (ID_txtStatus, DrawPoint (GetSize ().x / 2 , curYPos), " " , COLOR_RED, FontStyle::CENTER, NormalFont);
7890
79- btSize = Extent (220 , 22 );
80- AddTextButton (ID_btConnect, DrawPoint (20 , 190 ), btSize, TextureColor::Red1, _ (" Connect" ), NormalFont);
81- AddTextButton (ID_btRegister, DrawPoint (260 , 190 ), btSize, TextureColor::Green2, _ (" Register" ), NormalFont);
91+ curYPos += 25 ;
92+ AddTextButton (ID_btConnect, DrawPoint (curLblPos.x , curYPos), edtSize, TextureColor::Red1, _ (" Connect" ), NormalFont);
93+ AddTextButton (ID_btRegister, DrawPoint (ctrlStartPos, curYPos), edtSize, TextureColor::Green2, _ (" Register" ),
94+ NormalFont);
8295
8396 LOBBYCLIENT.SetProgramVersion (rttr::version::GetReadableVersion ());
8497 LOBBYCLIENT.AddListener (this );
@@ -97,24 +110,19 @@ iwLobbyConnect::~iwLobbyConnect()
97110 }
98111}
99112
100- /* *
101- * speichert die eingegebenen Benutzerdaten in die Settings
102- */
113+ // / Get entered data and save to settings
103114void iwLobbyConnect::ReadFromEditAndSaveLobbyData (std::string& user, std::string& pass)
104115{
105- // Dann Form abrufen
106116 user = GetCtrl<ctrlEdit>(ID_edtUser)->GetText ();
107117 pass = GetCtrl<ctrlEdit>(ID_edtPw)->GetText ();
108118
109- // Potential false positive: User uses new password which is equal to the hash of the old one. HIGHLY unlikely, so
110- // ignore
119+ // Potential false positive: User uses new password which is equal to the hash of the old one.
120+ // HIGHLY unlikely, so ignore
111121 if (!isStoredPasswordHash (SETTINGS.lobby .password , pass))
112122 pass = s25util::md5 (pass).toString ();
113123
114- // Name speichern
124+ // Save name and password if requested
115125 SETTINGS.lobby .name = user; // -V807
116-
117- // Ist Passwort speichern an?
118126 if (SETTINGS.lobby .save_password )
119127 SETTINGS.lobby .password = " md5:" + pass;
120128 else
@@ -123,7 +131,7 @@ void iwLobbyConnect::ReadFromEditAndSaveLobbyData(std::string& user, std::string
123131
124132void iwLobbyConnect::Msg_EditChange (const unsigned /* ctrl_id*/ )
125133{
126- // Statustext resetten
134+ // Reset status text
127135 SetText (" " , COLOR_RED, true );
128136}
129137
@@ -145,16 +153,14 @@ void iwLobbyConnect::Msg_ButtonClick(const unsigned ctrl_id)
145153{
146154 switch (ctrl_id)
147155 {
148- case ID_btConnect: // Verbinden
156+ case ID_btConnect:
149157 {
150- // Text auf "Verbinde mit Host..." setzen und Button deaktivieren
158+ // Update text and disable button
151159 SetText (_ (" Connecting with Host..." ), COLOR_RED, false );
152160
153- // Form abrufen und ggf in settings speichern
154161 std::string user, pass;
155162 ReadFromEditAndSaveLobbyData (user, pass);
156163
157- // Einloggen
158164 if (!LOBBYCLIENT.Login (LOADER.GetTextN (" client" , 0 ),
159165 s25util::fromStringClassic<unsigned >(LOADER.GetTextN (" client" , 1 )), user, pass,
160166 SETTINGS.server .ipv6 ))
@@ -164,31 +170,23 @@ void iwLobbyConnect::Msg_ButtonClick(const unsigned ctrl_id)
164170 }
165171 }
166172 break ;
167- case ID_btRegister: // Registrieren
168- {
173+ case ID_btRegister:
169174 WINDOWMANAGER.Show (std::make_unique<iwMsgbox>(
170175 _ (" Error" ),
171176 _ (" To register, you have to create a valid board account at http://forum.siedler25.org at the moment.\n " ),
172177 this , MsgboxButton::Ok, MsgboxIcon::ExclamationRed, 0 ));
173- }
174- break ;
178+ break ;
175179 }
176180}
177181
178182void iwLobbyConnect::Msg_OptionGroupChange (const unsigned ctrl_id, const unsigned selection)
179183{
180184 switch (ctrl_id)
181185 {
182- case ID_optSavePw: // Passwort speichern Ja/Nein
183- {
184- SETTINGS.lobby .save_password = (selection == 1 );
185- }
186- break ;
187- case ID_optProtocol: // IPv6 Ja/Nein
188- {
186+ case ID_optSavePw: SETTINGS.lobby .save_password = (selection == 1 ); break ;
187+ case ID_optProtocol: // IPv6 yes/no
189188 SETTINGS.server .ipv6 = (selection == 1 );
190- }
191- break ;
189+ break ;
192190 }
193191}
194192
@@ -211,47 +209,30 @@ bool iwLobbyConnect::Msg_KeyDown(const KeyEvent& ev)
211209 return true ;
212210}
213211
214- /* *
215- * Setzt den Text und Schriftfarbe vom Textfeld und den Status des
216- * Buttons.
217- */
212+ // / Set status text with given color and enables/disables buttons
218213void iwLobbyConnect::SetText (const std::string& text, unsigned color, bool button)
219214{
220215 auto * t = GetCtrl<ctrlText>(ID_txtStatus);
221- auto * b = GetCtrl<ctrlButton>(ID_btConnect);
222- auto * b2 = GetCtrl<ctrlButton>(ID_btRegister);
223-
224- // Text setzen
225216 t->SetTextColor (color);
226217 t->SetText (text);
227218
228- // Button (de)aktivieren
229- b->SetEnabled (button);
230- if (b2)
231- b2->SetEnabled (button);
219+ GetCtrl<ctrlButton>(ID_btConnect)->SetEnabled (button);
220+ GetCtrl<ctrlButton>(ID_btRegister)->SetEnabled (button);
232221}
233222
234- /* *
235- * Wir wurden eingeloggt
236- */
237223void iwLobbyConnect::LC_LoggedIn (const std::string& /* email*/ )
238224{
239225 GetCtrl<ctrlButton>(ID_btRegister)->SetEnabled (false );
240226
241227 WINDOWMANAGER.Switch (std::make_unique<dskLobby>());
242228}
243229
244- /* *
245- * Status: Warten auf Antwort.
246- */
247230void iwLobbyConnect::LC_Status_Waiting ()
248231{
249232 SetText (_ (" Waiting for Reply..." ), COLOR_YELLOW, false );
250233}
251234
252- /* *
253- * Status: Benutzerdefinierter Fehler (inkl Conn-Reset u.ä)
254- */
235+ // User defined error (e.g. connection reset)
255236void iwLobbyConnect::LC_Status_Error (const std::string& error)
256237{
257238 SetText (error, COLOR_RED, true );
0 commit comments