redoing the login dialog with the new widgets

This commit is contained in:
Thomas Baumhauer 2008-12-30 19:41:58 +00:00
parent d597566c5d
commit 06cf6bdf04
6 changed files with 276 additions and 6 deletions

View file

@ -0,0 +1,190 @@
#textdomain wesnoth-lib
###
### Definition of the window to log in to the MP server
###
[window]
id = "mp_login"
description =_ "Multiplayer server login dialog"
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Login"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "login_label"
definition = "default"
label = ""
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor = 1
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Password:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[text_box]
id = "password"
definition = "default"
label = ""
[/text_box]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "ok"
definition = "default"
label = _ "Login"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
definition = "default"
id = "change_username"
label = _ "Change username"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
definition = "default"
id = "password_reminder"
label = _ "Password Reminder"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -21,6 +21,7 @@
#include "gui/dialogs/field.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/label.hpp"
namespace gui2 {
@ -183,5 +184,58 @@ void tmp_connect::show_server_list(twindow& window)
}
}
/*WIKI
* @page = GUIWindowWML
* @order = 2_mp_login
*
* == Multiplayer connect ==
*
* This shows the dialog to log in to the MP server
*
* @start_table = container
* password (text_box) the password
* [password_reminder] (button) Request a password reminder
* [change_username] (button) Use a different username
* [login_label] (button) Displays the information received
* from the server
* @end_table
*/
tmp_login::tmp_login(const t_string& label) : password_(), label_(label) { }
twindow* tmp_login::build_window(CVideo& video)
{
return build(video, get_id(MP_LOGIN));
}
void tmp_login::pre_show(CVideo& video, twindow& window)
{
ttext_box* password =
dynamic_cast<ttext_box*>(window.find_widget("password", false));
VALIDATE(password, missing_widget("password"));
window.keyboard_capture(password);
tbutton *password_reminder =
dynamic_cast<tbutton*>(window.find_widget("password_reminder", false));
if(password_reminder) password_reminder->set_retval(1);
tbutton* change_username =
dynamic_cast<tbutton*>(window.find_widget("change_username", false));
if(change_username) change_username->set_retval(2);
tlabel* label =
dynamic_cast<tlabel*>(window.find_widget("login_label", false));
if(label) label->set_label(label_);
}
void tmp_login::post_show(twindow& window)
{
ttext_box* password =
dynamic_cast<ttext_box*>(window.find_widget("password", false));
VALIDATE(password, missing_widget("password"));
password_ = password->get_value();
}
} // namespace gui2

View file

@ -16,6 +16,7 @@
#define GUI_DIALOGS_MP_CONNECT_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "tstring.hpp"
namespace gui2 {
@ -44,6 +45,27 @@ private:
tfield_text* host_name_;
};
class tmp_login : public tdialog
{
public:
tmp_login(const t_string& label);
const std::string& password() const { return password_; }
private:
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
std::string password_;
t_string label_;
};
} // namespace gui2
#endif

View file

@ -72,6 +72,7 @@ static void fill_window_types()
window_type_list[MP_CONNECT] = "mp_connect";
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";
window_type_list[MP_SERVER_LIST] = "mp_server_list";
window_type_list[MP_LOGIN] = "mp_login";
window_type_list[MP_CREATE_GAME] = "mp_create_game";
window_type_list[TITLE_SCREEN] = "title_screen";
#ifndef DISABLE_EDITOR2

View file

@ -54,6 +54,7 @@ enum twindow_type {
* mp game the user wants to play.
*/
MP_SERVER_LIST, /**< The mp server list dialog. */
MP_LOGIN, /**< The mp login dialog. */
MP_CREATE_GAME, /**< The mp creation dialog. */
#ifndef DISABLE_EDITOR2
EDITOR_NEW_MAP, /**< New map dialog. */

View file

@ -196,16 +196,18 @@ static server_type open_connection(game_display& disp, const std::string& origin
if(!first_time) {
//Somewhat hacky implementation, including a goto of death
/** @todo A fancy textbox that displays characters as dots or asterisks would nice. */
if(!((*error)["password_request"].empty())) {
const int res = gui::show_dialog(disp, NULL, _("Login"),
(*error)["message"], gui::OK_CANCEL,
&opts, NULL, _("Password: "), &password, mp::max_login_size);
gui2::tmp_login dlg((*error)["message"]);
dlg.show(disp.video());
switch(res) {
password = dlg.password();
switch(dlg.get_retval()) {
//Log in with password
case 0:
case gui2::twindow::OK:
break;
//Request a password reminder
case 1: