Author: mordante
Date: Thu Oct 14 21:33:06 2010
New Revision: 47047
URL: http://svn.gna.org/viewcvs/wesnoth?rev=47047&view=rev
Log:
Add new tips code for gui2.
It doesn't implement the filtering of the tips yet, but that's not used in
mainline at the moment.
Added:
trunk/src/gui/auxiliary/tips.cpp (with props)
trunk/src/gui/auxiliary/tips.hpp (with props)
Modified:
trunk/data/gui/default.cfg
trunk/po/wesnoth-lib/POTFILES.in
trunk/src/CMakeLists.txt
trunk/src/Makefile.am
trunk/src/SConscript
trunk/src/gui/dialogs/title_screen.cpp
trunk/src/gui/dialogs/title_screen.hpp
trunk/src/gui/widgets/settings.cpp
trunk/src/gui/widgets/settings.hpp
Modified: trunk/data/gui/default.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default.cfg?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/data/gui/default.cfg (original)
+++ trunk/data/gui/default.cfg Thu Oct 14 21:33:06 2010
@@ -21,6 +21,8 @@
sound_slider_adjust = "slider.wav"
[/settings]
+ {hardwired/tips.cfg}
+
{gui/default/macros/}
{gui/default/window/}
{gui/default/widget/}
Modified: trunk/po/wesnoth-lib/POTFILES.in
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/po/wesnoth-lib/POTFILES.in?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/po/wesnoth-lib/POTFILES.in (original)
+++ trunk/po/wesnoth-lib/POTFILES.in Thu Oct 14 21:33:06 2010
@@ -10,6 +10,7 @@
src/gui/auxiliary/event/handler.cpp
src/gui/auxiliary/log.cpp
src/gui/auxiliary/timer.cpp
+src/gui/auxiliary/tips.cpp
src/gui/auxiliary/widget_definition/button.cpp
src/gui/auxiliary/widget_definition.cpp
src/gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
Modified: trunk/src/CMakeLists.txt
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Thu Oct 14 21:33:06 2010
@@ -350,6 +350,7 @@
gui/auxiliary/event/handler.cpp
gui/auxiliary/log.cpp
gui/auxiliary/timer.cpp
+ gui/auxiliary/tips.cpp
gui/auxiliary/widget_definition.cpp
gui/auxiliary/widget_definition/button.cpp
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
Modified: trunk/src/Makefile.am
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Thu Oct 14 21:33:06 2010
@@ -120,6 +120,7 @@
gui/auxiliary/event/handler.cpp \
gui/auxiliary/log.cpp \
gui/auxiliary/timer.cpp \
+ gui/auxiliary/tips.cpp \
gui/auxiliary/widget_definition.cpp \
gui/auxiliary/widget_definition/button.cpp \
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp \
Modified: trunk/src/SConscript
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Thu Oct 14 21:33:06 2010
@@ -288,6 +288,7 @@
gui/auxiliary/event/handler.cpp
gui/auxiliary/log.cpp
gui/auxiliary/timer.cpp
+ gui/auxiliary/tips.cpp
gui/auxiliary/widget_definition.cpp
gui/auxiliary/widget_definition/button.cpp
gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
Added: trunk/src/gui/auxiliary/tips.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/tips.cpp?rev=47047&view=auto
==============================================================================
--- trunk/src/gui/auxiliary/tips.cpp (added)
+++ trunk/src/gui/auxiliary/tips.cpp Thu Oct 14 21:33:06 2010
@@ -1,0 +1,56 @@
+/* $Id$ */
+/*
+ Copyright (C) 2010 by Mark de Wever <[email protected]>
+ 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/auxiliary/tips.hpp"
+
+#include "config.hpp"
+#include "foreach.hpp"
+
+namespace gui2 {
+
+ttip::ttip(const t_string& text, const t_string& source)
+ : text_(text)
+ , source_(source)
+{
+}
+
+namespace tips {
+
+
+/** @todo Implement the filtering of the tips. */
+std::vector<ttip> load(const config& cfg)
+{
+ std::vector<ttip> result;
+
+ foreach(const config &tip, cfg.child_range("tip")) {
+ result.push_back(ttip(tip["text"], tip["source"]));
+ }
+
+ return result;
+}
+
+/** @todo Implement the filtering of the tips. */
+std::vector<ttip> shuffle(const std::vector<ttip>& tips)
+{
+ std::vector<ttip> result = tips;
+ std::random_shuffle(result.begin(), result.end());
+ return result;
+}
+
+} // namespace tips
+
+} // namespace gui2
Propchange: trunk/src/gui/auxiliary/tips.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/gui/auxiliary/tips.cpp
------------------------------------------------------------------------------
svn:keywords = r"Author Date Id Revision"
Added: trunk/src/gui/auxiliary/tips.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/tips.hpp?rev=47047&view=auto
==============================================================================
--- trunk/src/gui/auxiliary/tips.hpp (added)
+++ trunk/src/gui/auxiliary/tips.hpp Thu Oct 14 21:33:06 2010
@@ -1,0 +1,72 @@
+/* $Id$ */
+/*
+ Copyright (C) 2010 by Mark de Wever <[email protected]>
+ 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_AUXILIARY_TIPS_HPP_INCLUDED
+#define GUI_AUXILIARY_TIPS_HPP_INCLUDED
+
+#include "tstring.hpp"
+
+#include <vector>
+
+class config;
+
+namespace gui2 {
+
+class ttip;
+
+namespace tips {
+
+/**
+ * Loads the tips from a config.
+ *
+ * @param cfg A config with the tips.
+ *
+ * @returns The loaded tips.
+ */
+std::vector<ttip> load(const config& cfg);
+
+/**
+ * Shuffles the tips.
+ *
+ * This routine shuffles the tips and filters out the unwanted ones.
+ *
+ * @param tips The tips.
+ *
+ * @returns The filtered tips in random order.
+ */
+std::vector<ttip> shuffle(const std::vector<ttip>& tips);
+
+} // namespace tips {
+
+/** The tips of day structure. */
+class ttip
+{
+public:
+
+ const t_string& text() const { return text_; }
+ const t_string& source() const { return source_; }
+
+private:
+ friend std::vector<ttip> tips::load(const config&);
+ ttip(const t_string& text, const t_string& source);
+
+ t_string text_;
+ t_string source_;
+};
+
+} // namespace gui2
+
+#endif
+
Propchange: trunk/src/gui/auxiliary/tips.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/gui/auxiliary/tips.hpp
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: trunk/src/gui/dialogs/title_screen.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/title_screen.cpp?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/src/gui/dialogs/title_screen.cpp (original)
+++ trunk/src/gui/dialogs/title_screen.cpp Thu Oct 14 21:33:06 2010
@@ -23,6 +23,7 @@
#include "gettext.hpp"
#include "log.hpp"
#include "gui/auxiliary/timer.hpp"
+#include "gui/auxiliary/tips.hpp"
#include "gui/dialogs/language_selection.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/label.hpp"
@@ -35,6 +36,8 @@
#include <boost/bind.hpp>
+#include <algorithm>
+
static lg::log_domain log_config("config");
#define ERR_CF LOG_STREAM(err, log_config)
#define WRN_CF LOG_STREAM(warn, log_config)
@@ -56,7 +59,7 @@
* language & & button & m &
* The button to change the language. $
*
- * tips & & multi_page & o &
+ * tips & & multi_page & m &
* A multi_page to hold all tips, when this widget is used the area of
* the tips doesn't need to be resized when the next or previous button
* is pressed. $
@@ -93,10 +96,8 @@
ttitle_screen::ttitle_screen()
: video_(NULL)
- , tips_()
, logo_timer_id_(0)
{
- read_tips_of_day(tips_);
}
ttitle_screen::~ttitle_screen()
@@ -105,6 +106,7 @@
remove_timer(logo_timer_id_);
}
}
+
static void animate_logo(
unsigned long& timer_id
, unsigned& percentage
@@ -123,7 +125,6 @@
*/
window.set_dirty();
-
if(percentage == 100) {
remove_timer(timer_id);
timer_id = 0;
@@ -277,33 +278,29 @@
variant(_("Version") + std::string(" ") +
game_config::revision));
/**** Set the tip of the day ****/
- /*
- * NOTE: although the tips are set in the multi_page only the first page
- * will be used and the widget content is set there. This is a kind of
- * hack, but will be fixed when this dialog will be moved out of
- * --new-widgets. Then the tips part of the code no longer needs to be
- * shared with the other title screen and can be moved here.
- */
- tmulti_page* tip_pages =
- find_widget<tmulti_page>(&window, "tips", false, false);
- if(tip_pages) {
- foreach(const config& tip, tips_.child_range("tip")) {
-
- string_map widget;
- std::map<std::string, string_map> page;
-
- widget["label"] = tip["text"];
- widget["use_markup"] = "true";
- page["tip"] = widget;
-
- widget["label"] = tip["source"];
- widget["use_markup"] = "true";
- page["source"] = widget;
-
- tip_pages->add_page(page);
-
- }
- }
+ tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips",
false);
+
+ std::vector<ttip> tips(settings::get_tips());
+ if(tips.empty()) {
+ WRN_CF << "There are not tips of day available.\n";
+ }
+
+ foreach(const ttip& tip, tips) {
+
+ string_map widget;
+ std::map<std::string, string_map> page;
+
+ widget["label"] = tip.text();
+ widget["use_markup"] = "true";
+ page["tip"] = widget;
+
+ widget["label"] = tip.source();
+ widget["use_markup"] = "true";
+ page["source"] = widget;
+
+ tip_pages.add_page(page);
+ }
+
update_tip(window, true);
connect_signal_mouse_left_click(
@@ -359,46 +356,25 @@
void ttitle_screen::update_tip(twindow& window, const bool previous)
{
- next_tip_of_day(tips_, previous);
- const config *tip = get_tip_of_day(tips_);
- if(!tip) {
- WRN_CF << "There are not tips of day defined.\n";
+ tmulti_page& tips = find_widget<tmulti_page>(&window, "tips", false);
+ if(tips.get_page_count() == 0) {
return;
}
- find_widget<tlabel>(&window, "tip", false).set_label((*tip)["text"]);
- find_widget<tlabel>(&window, "source",
false).set_label((*tip)["source"]);
-
- /**
- * @todo Need to move the real tips "calculation" to this file so we can
- * move through the pages.
- *
- */
- if(!find_widget<tmulti_page>(&window, "tips", false, false)) {
- window.invalidate_layout();
- }
-}
-
-void ttitle_screen::next_tip(twidget* caller)
-{
- ttitle_screen *dialog = dynamic_cast<ttitle_screen*>(caller->dialog());
- assert(dialog);
-
- twindow *window = caller->get_window();
- assert(window);
-
- dialog->update_tip(*window, true);
-}
-
-void ttitle_screen::previous_tip(twidget* caller)
-{
- ttitle_screen *dialog = dynamic_cast<ttitle_screen*>(caller->dialog());
- assert(dialog);
-
- twindow *window = caller->get_window();
- assert(window);
-
- dialog->update_tip(*window, false);
+ int page = tips.get_selected_page();
+ if(previous) {
+ if(page <= 0) {
+ page = tips.get_page_count();
+ }
+ --page;
+ } else {
+ ++page;
+ if(static_cast<unsigned>(page) >= tips.get_page_count()) {
+ page = 0;
+ }
+ }
+
+ tips.select_page(page);
}
} // namespace gui2
Modified: trunk/src/gui/dialogs/title_screen.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/title_screen.hpp?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/src/gui/dialogs/title_screen.hpp (original)
+++ trunk/src/gui/dialogs/title_screen.hpp Thu Oct 14 21:33:06 2010
@@ -17,8 +17,6 @@
#define GUI_DIALOGS_TITLE_SCREEN_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
-
-#include "config.hpp"
namespace gui2 {
@@ -47,9 +45,6 @@
/** Inherited from tdialog. */
void post_show(twindow& window);
- /** Hold the tips of the day. */
- config tips_;
-
/** The progress bar time for the logo. */
unsigned long logo_timer_id_;
@@ -61,12 +56,6 @@
* one.
*/
void update_tip(twindow& window, const bool previous);
-
- /** Helper to forward the call to update_tip. */
- static void next_tip(twidget* caller);
-
- /** Helper to forward the call to update_tip. */
- static void previous_tip(twidget* caller);
};
} // namespace gui2
Modified: trunk/src/gui/widgets/settings.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Thu Oct 14 21:33:06 2010
@@ -28,6 +28,7 @@
#include "foreach.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/log.hpp"
+#include "gui/auxiliary/tips.hpp"
#include "gui/widgets/window.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
@@ -54,6 +55,13 @@
std::string sound_toggle_button_click = "";
std::string sound_toggle_panel_click = "";
std::string sound_slider_adjust = "";
+
+ std::vector<ttip> tips;
+
+ std::vector<ttip> get_tips()
+ {
+ return tips::shuffle(tips);
+ }
} // namespace settings
@@ -135,6 +143,7 @@
std::string sound_toggle_button_click_;
std::string sound_toggle_panel_click_;
std::string sound_slider_adjust_;
+ std::vector<ttip> tips_;
};
const std::string& tgui_definition::read(const config& cfg)
@@ -353,6 +362,8 @@
sound_toggle_panel_click_ = settings["sound_toggle_panel_click"].str();
sound_slider_adjust_ = settings["sound_slider_adjust"].str();
+ tips_ = tips::load(cfg);
+
return id;
}
@@ -367,6 +378,7 @@
settings::sound_toggle_button_click = sound_toggle_button_click_;
settings::sound_toggle_panel_click = sound_toggle_panel_click_;
settings::sound_slider_adjust = sound_slider_adjust_;
+ settings::tips = tips_;
}
void tgui_definition::load_widget_definitions(
@@ -448,7 +460,6 @@
current_gui = guis.find("default");
current_gui->second.activate();
}
-
tstate_definition::tstate_definition(const config &cfg) :
canvas()
Modified: trunk/src/gui/widgets/settings.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.hpp?rev=47047&r1=47046&r2=47047&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.hpp (original)
+++ trunk/src/gui/widgets/settings.hpp Thu Oct 14 21:33:06 2010
@@ -31,6 +31,7 @@
namespace gui2 {
struct tgui_definition;
+class ttip;
/** Do we wish to use the new library or not. */
extern bool new_widgets;
@@ -156,6 +157,8 @@
extern std::string sound_toggle_button_click;
extern std::string sound_toggle_panel_click;
extern std::string sound_slider_adjust;
+
+ std::vector<ttip> get_tips();
}
} // namespace gui2
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits