Author: mordante
Date: Tue Jun 10 23:10:55 2008
New Revision: 27092
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27092&view=rev
Log:
Refactoring; make a generic dialog class and let the other dialogs inherit from
this class. Also added some wiki comment.
Modified:
trunk/po/wesnoth-lib/POTFILES.in
trunk/src/CMakeLists.txt
trunk/src/Makefile.am
trunk/src/SConscript
trunk/src/gui/dialogs/addon_connect.cpp
trunk/src/gui/dialogs/addon_connect.hpp
trunk/src/gui/dialogs/language_selection.cpp
trunk/src/gui/dialogs/language_selection.hpp
trunk/src/gui/dialogs/mp_method_selection.cpp
trunk/src/gui/dialogs/mp_method_selection.hpp
trunk/src/gui/widgets/helper.cpp
trunk/src/gui/widgets/helper.hpp
Modified: trunk/po/wesnoth-lib/POTFILES.in
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/po/wesnoth-lib/POTFILES.in?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/po/wesnoth-lib/POTFILES.in (original)
+++ trunk/po/wesnoth-lib/POTFILES.in Tue Jun 10 23:10:55 2008
@@ -5,6 +5,7 @@
src/game_preferences.cpp
src/game_preferences_display.cpp
src/gui/dialogs/addon_connect.cpp
+src/gui/dialogs/dialog.cpp
src/gui/dialogs/language_selection.cpp
src/gui/dialogs/mp_method_selection.cpp
src/gui/widgets/button.cpp
Modified: trunk/src/CMakeLists.txt
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Tue Jun 10 23:10:55 2008
@@ -213,6 +213,7 @@
generate_report.cpp
generic_event.cpp
gui/dialogs/addon_connect.cpp
+ gui/dialogs/dialog.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/mp_method_selection.cpp
gui/widgets/button.cpp
Modified: trunk/src/Makefile.am
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Tue Jun 10 23:10:55 2008
@@ -70,6 +70,7 @@
generate_report.cpp \
generic_event.cpp \
gui/dialogs/addon_connect.cpp \
+ gui/dialogs/dialog.cpp \
gui/dialogs/language_selection.cpp \
gui/dialogs/mp_method_selection.cpp \
gui/widgets/button.cpp \
Modified: trunk/src/SConscript
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Tue Jun 10 23:10:55 2008
@@ -82,9 +82,10 @@
widgets/textbox.cpp
widgets/widget.cpp
wml_exception.cpp
+ gui/dialogs/addon_connect.cpp
+ gui/dialogs/dialog.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/mp_method_selection.cpp
- gui/dialogs/addon_connect.cpp
gui/widgets/button.cpp
gui/widgets/canvas.cpp
gui/widgets/control.cpp
Modified: trunk/src/gui/dialogs/addon_connect.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/addon_connect.cpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/dialogs/addon_connect.cpp (original)
+++ trunk/src/gui/dialogs/addon_connect.cpp Tue Jun 10 23:10:55 2008
@@ -21,7 +21,7 @@
#include "gui/widgets/settings.hpp"
#include "gui/widgets/text_box.hpp"
#include "log.hpp"
-#include "video.hpp"
+#include "wml_exception.hpp"
#define DBG_GUI LOG_STREAM_INDENT(debug, widget)
#define LOG_GUI LOG_STREAM_INDENT(info, widget)
@@ -30,24 +30,45 @@
namespace gui2 {
-void taddon_connect::show(CVideo& video)
+/*WIKI
+ * @page = GUIWindowWML
+ * @order = 2_addon_connect
+ *
+ * == Addon connect ==
+ *
+ * This shows the dialog for managing addons and connecting to the addon
server.
+ *
+ * @start_table = container
+ * [] button (2) This button closes the dialog and starts
+ * the addon manager.
+ * host_name text_box This text contains the name of the
server
+ * to connect to.
+ * @end_table
+ */
+
+twindow taddon_connect::build_window(CVideo& video)
{
- twindow window = build(video, get_id(ADDON_CONNECT));
+ return build(video, get_id(ADDON_CONNECT));
+}
+
+void taddon_connect::pre_show(CVideo& video, twindow& window)
+{
ttext_box* host_widget =
dynamic_cast<ttext_box*>(window.find_widget("host_name", false));
- if(host_widget) {
- host_widget->set_text(host_name_);
- window.keyboard_capture(host_widget);
- }
+ VALIDATE(host_widget, missing_widget("host_name"));
- retval_ = window.show(true);
+ host_widget->set_text(host_name_);
+ window.keyboard_capture(host_widget);
+}
- if(host_widget) {
- if(retval_ == tbutton::OK) {
- host_widget->save_to_history();
- }
+void taddon_connect::post_show(twindow& window)
+{
+ if(get_retval() == tbutton::OK) {
+ ttext_box* host_widget =
dynamic_cast<ttext_box*>(window.find_widget("host_name", false));
+ assert(host_widget);
+
+ host_widget->save_to_history();
host_name_= host_widget->get_text();
}
}
-
} // namespace gui2
Modified: trunk/src/gui/dialogs/addon_connect.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/addon_connect.hpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/dialogs/addon_connect.hpp (original)
+++ trunk/src/gui/dialogs/addon_connect.hpp Tue Jun 10 23:10:55 2008
@@ -15,23 +15,16 @@
#ifndef GUI_DIALOGS_ADDON_CONNECT_HPP_INCLUDED
#define GUI_DIALOGS_ADDON_CONNECT_HPP_INCLUDED
-#include <string>
-
-class CVideo;
+#include "gui/dialogs/dialog.hpp"
namespace gui2 {
-class taddon_connect
+class taddon_connect : public tdialog
{
public:
taddon_connect() :
- retval_(0),
host_name_()
{}
-
- void show(CVideo& video);
-
- int get_retval() const { return retval_; }
const std::string& host_name() const { return host_name_; }
@@ -39,9 +32,16 @@
{ host_name_ = host_name; }
private:
- int retval_;
std::string host_name_;
+ /** 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);
};
} // namespace gui2
Modified: trunk/src/gui/dialogs/language_selection.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/language_selection.cpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/dialogs/language_selection.cpp (original)
+++ trunk/src/gui/dialogs/language_selection.cpp Tue Jun 10 23:10:55 2008
@@ -33,12 +33,28 @@
namespace gui2 {
-void tlanguage_selection::show(CVideo& video)
+/*WIKI
+ * @page = GUIWindowWML
+ * @order = 2_language_selection
+ *
+ * == Language selection ==
+ *
+ * This shows the dialog to select the language to use.
+ *
+ * @start_table = container
+ * language_list listbox This text contains the list with
+ * available languages.
+ * @end_table
+ */
+twindow tlanguage_selection::build_window(CVideo& video)
{
- twindow window = build(video, get_id(LANGUAGE_SELECTION));
+ return build(video, get_id(LANGUAGE_SELECTION));
+}
+void tlanguage_selection::pre_show(CVideo& video, twindow& window)
+{
tlistbox* list =
dynamic_cast<tlistbox*>(window.find_widget("language_list", false));
- VALIDATE(list, "No list defined.");
+ VALIDATE(list, missing_widget("language_list"));
const std::vector<language_def>& languages = get_languages();
const language_def& current_language = get_language();
@@ -53,16 +69,20 @@
}
window.recalculate_size();
+}
- retval_ = window.show(true);
+void tlanguage_selection::post_show(twindow& window)
+{
+ if(get_retval() == tbutton::OK) {
+ tlistbox* list =
dynamic_cast<tlistbox*>(window.find_widget("language_list", false));
+ assert(list);
- if(retval_ == tbutton::OK) {
const unsigned res = list->get_selected_row();
+ const std::vector<language_def>& languages = get_languages();
::set_language(languages[res]);
preferences::set_language(languages[res].localename);
}
}
-
} // namespace gui2
Modified: trunk/src/gui/dialogs/language_selection.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/language_selection.hpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/dialogs/language_selection.hpp (original)
+++ trunk/src/gui/dialogs/language_selection.hpp Tue Jun 10 23:10:55 2008
@@ -15,26 +15,25 @@
#ifndef GUI_DIALOGS_LANGUAGE_SELECTION_HPP_INCLUDED
#define GUI_DIALOGS_LANGUAGE_SELECTION_HPP_INCLUDED
-#include <string>
-
-class CVideo;
+#include "gui/dialogs/dialog.hpp"
namespace gui2 {
-class tlanguage_selection
+class tlanguage_selection : public tdialog
{
public:
- tlanguage_selection() :
- retval_(0)
- {}
-
- void show(CVideo& video);
-
- int get_retval() const { return retval_; }
+ tlanguage_selection() {}
private:
- int retval_;
+ /** 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);
};
} // namespace gui2
Modified: trunk/src/gui/dialogs/mp_method_selection.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/mp_method_selection.cpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/dialogs/mp_method_selection.cpp (original)
+++ trunk/src/gui/dialogs/mp_method_selection.cpp Tue Jun 10 23:10:55 2008
@@ -34,25 +34,49 @@
namespace gui2 {
-void tmp_method_selection::show(CVideo& video)
+/*WIKI
+ * @page = GUIWindowWML
+ * @order = 2_mp_method_selection
+ *
+ * == MP method selection ==
+ *
+ * This shows the dialog to select the kind of MP game the user wants to play.
+ *
+ * @start_table = container
+ * user_name text_box This text contains the name the user on
+ * the MP server.
+ * method_list listbox The list with possible game methods.
+ * @end_table
+ */
+twindow tmp_method_selection::build_window(CVideo& video)
{
- twindow window = build(video, get_id(MP_METHOD_SELECTION));
+ return build(video, get_id(MP_METHOD_SELECTION));
+}
+void tmp_method_selection::pre_show(CVideo& video, twindow& window)
+{
user_name_ = preferences::login();
ttext_box* user_widget =
dynamic_cast<ttext_box*>(window.find_widget("user_name", false));
- if(user_widget) {
- user_widget->set_text(user_name_);
- window.keyboard_capture(user_widget);
- }
+ VALIDATE(user_widget, missing_widget("user_name"));
+
+ user_widget->set_text(user_name_);
+ window.keyboard_capture(user_widget);
tlistbox* list =
dynamic_cast<tlistbox*>(window.find_widget("method_list", false));
- VALIDATE(list, "No list defined.");
+ VALIDATE(list, missing_widget("method_list"));
window.recalculate_size();
+}
- retval_ = window.show(true);
+void tmp_method_selection::post_show(twindow& window)
+{
+ if(get_retval() == tbutton::OK) {
- if(retval_ == tbutton::OK) {
+ ttext_box* user_widget =
dynamic_cast<ttext_box*>(window.find_widget("user_name", false));
+ assert(user_widget);
+
+ tlistbox* list =
dynamic_cast<tlistbox*>(window.find_widget("method_list", false));
+ assert(list);
choice_ = list->get_selected_row();
user_widget->save_to_history();
Modified: trunk/src/gui/dialogs/mp_method_selection.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/mp_method_selection.hpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/dialogs/mp_method_selection.hpp (original)
+++ trunk/src/gui/dialogs/mp_method_selection.hpp Tue Jun 10 23:10:55 2008
@@ -15,34 +15,35 @@
#ifndef GUI_DIALOGS_MP_METHOD_SELECTION_HPP_INCLUDED
#define GUI_DIALOGS_MP_METHOD_SELECTION_HPP_INCLUDED
-
-#include <string>
-
-class CVideo;
+#include "gui/dialogs/dialog.hpp"
namespace gui2 {
-class tmp_method_selection
+class tmp_method_selection : public tdialog
{
public:
tmp_method_selection() :
- retval_(0),
user_name_(),
choice_(-1)
{}
-
- void show(CVideo& video);
-
- int get_retval() const { return retval_; }
const std::string& user_name() const { return user_name_; }
int get_choice() const { return choice_; }
private:
- int retval_;
std::string user_name_;
int choice_;
+
+
+ /** 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);
};
} // namespace gui2
Modified: trunk/src/gui/widgets/helper.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/helper.cpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/widgets/helper.cpp (original)
+++ trunk/src/gui/widgets/helper.cpp Tue Jun 10 23:10:55 2008
@@ -14,9 +14,11 @@
#include "gui/widgets/helper.hpp"
+#include "gettext.hpp"
#include "gui/widgets/settings.hpp"
#include "sdl_utils.hpp"
#include "serialization/string_utils.hpp"
+#include "tstring.hpp"
#include "log.hpp"
#include "SDL_ttf.h"
@@ -174,5 +176,13 @@
}
}
+t_string missing_widget(const std::string& id)
+{
+ utils::string_map symbols;
+ symbols["id"] = id;
+
+ return t_string(vgettext("Mandatory widget '$id' hasn't been defined.",
symbols));
+}
+
} // namespace gui2
Modified: trunk/src/gui/widgets/helper.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/helper.hpp?rev=27092&r1=27091&r2=27092&view=diff
==============================================================================
--- trunk/src/gui/widgets/helper.hpp (original)
+++ trunk/src/gui/widgets/helper.hpp Tue Jun 10 23:10:55 2008
@@ -20,6 +20,7 @@
#include <string>
class surface;
+class t_string;
namespace gui2 {
@@ -94,6 +95,14 @@
void restore_background(const surface& restorer,
surface& background,const SDL_Rect& rect);
+/**
+ * Returns a default error message if a mandatory widget is ommited.
+ *
+ * @param id The id of the omitted widget.
+ * @returns The error message.
+ */
+t_string missing_widget(const std::string& id);
+
} // namespace gui2
#endif
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits