From 95667feed32d594ea59f368d7726df97ec777ed6 Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Tue, 7 Dec 2010 21:49:53 +0000 Subject: [PATCH] Convert the MP create game-set password dialog to GUI2 --- .../window/mp_create_game_set_password.cfg | 136 ++++++++++++++++++ src/CMakeLists.txt | 1 + src/Makefile.am | 1 + src/SConscript | 1 + .../dialogs/mp_create_game_set_password.cpp | 66 +++++++++ .../dialogs/mp_create_game_set_password.hpp | 53 +++++++ src/multiplayer_create.cpp | 6 +- 7 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 data/gui/default/window/mp_create_game_set_password.cfg create mode 100644 src/gui/dialogs/mp_create_game_set_password.cpp create mode 100644 src/gui/dialogs/mp_create_game_set_password.hpp diff --git a/data/gui/default/window/mp_create_game_set_password.cfg b/data/gui/default/window/mp_create_game_set_password.cfg new file mode 100644 index 00000000000..431fb140dd5 --- /dev/null +++ b/data/gui/default/window/mp_create_game_set_password.cfg @@ -0,0 +1,136 @@ +#textdomain wesnoth-lib +### +### Definition of the window to place and edit gamemap labels +### + +[window] + id = "mp_create_game_set_password" + description = "Dialog for setting a join password for MP games." + + [resolution] + definition = "default" + + automatic_placement = "true" + vertical_placement = "center" + horizontal_placement = "center" + + maximum_width = 800 + + [grid] + + [row] + grow_factor = 0 + + [column] + grow_factor = 1 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + [label] + id = "title" + definition = "title" + + label = _ "Set Password" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 0 + + [column] + + border = "all" + border_size = 5 + horizontal_alignment = "left" + [scroll_label] + id = "message" + definition = "default" + + label = _ "Set the password that people wanting to join your game as players must enter." + [/scroll_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" + + border = "all" + border_size = 5 + horizontal_alignment = "right" + + [button] + id = "ok" + definition = "default" + + label = _ "OK" + [/button] + + [/column] + + [/row] + + [/grid] + + [/resolution] + +[/window] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4ee81a27419..908e126aaf0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -420,6 +420,7 @@ set(wesnoth-main_SRC gui/dialogs/message.cpp gui/dialogs/mp_connect.cpp gui/dialogs/mp_create_game.cpp + gui/dialogs/mp_create_game_set_password.cpp gui/dialogs/mp_method_selection.cpp gui/dialogs/mp_cmd_wrapper.cpp gui/dialogs/simple_item_selector.cpp diff --git a/src/Makefile.am b/src/Makefile.am index a4798e5a81d..f1fae8be716 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -191,6 +191,7 @@ wesnoth_source = \ gui/dialogs/message.cpp \ gui/dialogs/mp_connect.cpp \ gui/dialogs/mp_create_game.cpp \ + gui/dialogs/mp_create_game_set_password.cpp \ gui/dialogs/mp_method_selection.cpp \ gui/dialogs/mp_cmd_wrapper.cpp \ gui/dialogs/simple_item_selector.cpp \ diff --git a/src/SConscript b/src/SConscript index 184d3cfd170..b98f5377465 100644 --- a/src/SConscript +++ b/src/SConscript @@ -359,6 +359,7 @@ wesnoth_sources = Split(""" gui/dialogs/message.cpp gui/dialogs/mp_connect.cpp gui/dialogs/mp_create_game.cpp + gui/dialogs/mp_create_game_set_password.cpp gui/dialogs/mp_method_selection.cpp gui/dialogs/mp_cmd_wrapper.cpp gui/dialogs/simple_item_selector.cpp diff --git a/src/gui/dialogs/mp_create_game_set_password.cpp b/src/gui/dialogs/mp_create_game_set_password.cpp new file mode 100644 index 00000000000..9704046b0bf --- /dev/null +++ b/src/gui/dialogs/mp_create_game_set_password.cpp @@ -0,0 +1,66 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Ignacio Riquelme Morelle + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-lib" + +#include "gui/dialogs/mp_create_game_set_password.hpp" + +#include "gui/dialogs/field.hpp" +#include "gui/widgets/settings.hpp" +#include "gui/widgets/window.hpp" + +namespace gui2 { + +/*WIKI + * @page = GUIWindowDefinitionWML + * @order = 2_mp_create_game_set_password + * + * == Create Game: Set Password == + * + * Dialog for setting a join password for MP games. + * + * @begin{table}[dialog_widgets] + * + * password & & text_box & m & + * Input field for the game password. $ + * + * @end{table} + */ + +REGISTER_WINDOW(mp_create_game_set_password) + +tmp_create_game_set_password::tmp_create_game_set_password(const std::string& password) + : password_(password) + , password_field_(register_text("password", false)) +{ +} + +void tmp_create_game_set_password::pre_show(CVideo& /*video*/, twindow& window) +{ + assert(password_field_); + password_field_->set_widget_value(window, password_); + window.keyboard_capture(password_field_->widget(window)); +} + +void tmp_create_game_set_password::post_show(twindow& window) +{ + if(get_retval() != twindow::OK) { + return; + } + + password_ = password_field_->get_widget_value(window); +} + +} diff --git a/src/gui/dialogs/mp_create_game_set_password.hpp b/src/gui/dialogs/mp_create_game_set_password.hpp new file mode 100644 index 00000000000..24d8eae6d31 --- /dev/null +++ b/src/gui/dialogs/mp_create_game_set_password.hpp @@ -0,0 +1,53 @@ +/* $Id$ */ +/* + Copyright (C) 2010 by Ignacio Riquelme Morelle + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#ifndef GUI_DIALOGS_MP_CREATE_GAME_SET_PASSWORD_HPP_INCLUDED +#define GUI_DIALOGS_MP_CREATE_GAME_SET_PASSWORD_HPP_INCLUDED + +#include "gui/dialogs/dialog.hpp" +#include "gui/dialogs/field-fwd.hpp" + +namespace gui2 { + +class tmp_create_game_set_password : public tdialog +{ +public: + tmp_create_game_set_password(const std::string& password); + + const std::string& password() const { + return password_; + } + + void set_password(const std::string& password) { + password_ = password; + } + +private: + std::string password_; + tfield_text* password_field_; + + /** Inherited from tdialog, implemented by REGISTER_WINDOW. */ + virtual const std::string& window_id() const; + + /** Inherited from tdialog. */ + void pre_show(CVideo& video, twindow& window); + + /** Inherited from tdialog. */ + void post_show(twindow& window); +}; + +} + +#endif /* ! GUI_DIALOGS_MP_CREATE_GAME_SET_PASSWORD_HPP_INCLUDED */ diff --git a/src/multiplayer_create.cpp b/src/multiplayer_create.cpp index fb817f03fa5..0d66e11ecd0 100644 --- a/src/multiplayer_create.cpp +++ b/src/multiplayer_create.cpp @@ -30,6 +30,7 @@ #include "map_exception.hpp" #include "map_create.hpp" #include "gui/dialogs/message.hpp" +#include "gui/dialogs/mp_create_game_set_password.hpp" #include "gui/dialogs/transient_message.hpp" #include "minimap.hpp" #include "multiplayer_create.hpp" @@ -342,8 +343,9 @@ void create::process_event() } if(password_button_.pressed()) { - gui::show_dialog(disp_, NULL, _("Set Password"), - _("Set the password that people wanting to join your game as players must enter."), gui::OK_ONLY, NULL, NULL, _("Password: "), ¶meters_.password); + gui2::tmp_create_game_set_password pwd_dlg(parameters_.password); + pwd_dlg.show(disp_.video()); + parameters_.password = pwd_dlg.password(); } // Turns per game