Implement the tips panel in the new titlescreen.
This commit is contained in:
parent
a7982dedcb
commit
5522542d29
4 changed files with 186 additions and 5 deletions
|
@ -49,6 +49,108 @@
|
|||
[/window_definition]
|
||||
|
||||
#define _GUI_TIP_SECTION
|
||||
[panel]
|
||||
definition = "title_screen"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[label]
|
||||
id = "tip"
|
||||
definition = "default"
|
||||
|
||||
wrap = "true"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[label]
|
||||
id = "source"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[button]
|
||||
id = "help"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Help"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
grow_factor = 1
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "previous_tip"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Previous"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "next_tip"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Next"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/panel]
|
||||
#enddef
|
||||
|
||||
|
||||
|
@ -109,6 +211,11 @@
|
|||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
vertical_alignment = "bottom"
|
||||
{_GUI_TIP_SECTION}
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
horizontal_alignment = "right"
|
||||
{_GUI_MENU_SECTION}
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
#include "gui/dialogs/addon_connect.hpp"
|
||||
#include "gui/dialogs/language_selection.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "titlescreen.hpp"
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_CF LOG_STREAM(err, log_config)
|
||||
|
@ -52,6 +54,13 @@ void show_dialog(twidget* caller)
|
|||
* This shows the title screen.
|
||||
*/
|
||||
|
||||
ttitle_screen::ttitle_screen()
|
||||
: video_(NULL)
|
||||
, tips_()
|
||||
{
|
||||
read_tips_of_day(tips_);
|
||||
}
|
||||
|
||||
twindow* ttitle_screen::build_window(CVideo& video)
|
||||
{
|
||||
return build(video, get_id(TITLE_SCREEN));
|
||||
|
@ -69,13 +78,22 @@ void ttitle_screen::pre_show(CVideo& video, twindow& window)
|
|||
|
||||
/**** Set the buttons ****/
|
||||
window.get_widget<tbutton>("addons", false).
|
||||
set_callback_mouse_left_click(show_dialog<gui2::taddon_connect>);
|
||||
set_callback_mouse_left_click(show_dialog<gui2::taddon_connect>);
|
||||
|
||||
// Note changing the language doesn't upate the title screen...
|
||||
window.get_widget<tbutton>("language", false).
|
||||
set_callback_mouse_left_click(
|
||||
show_dialog<gui2::tlanguage_selection>);
|
||||
|
||||
/**** Set the tip of the day ****/
|
||||
update_tip(window, true);
|
||||
|
||||
window.get_widget<tbutton>("next_tip", false).
|
||||
set_callback_mouse_left_click(next_tip);
|
||||
|
||||
window.get_widget<tbutton>("previous_tip", false).
|
||||
set_callback_mouse_left_click(previous_tip);
|
||||
|
||||
/***** Select a random game_title *****/
|
||||
std::vector<std::string> game_title_list =
|
||||
utils::split(game_config::game_title
|
||||
|
@ -95,4 +113,42 @@ void ttitle_screen::post_show(twindow& /*window*/)
|
|||
video_ = NULL;
|
||||
}
|
||||
|
||||
void ttitle_screen::update_tip(twindow& window, const bool previous)
|
||||
{
|
||||
next_tip_of_day(tips_, previous);
|
||||
const config *tip = get_tip_of_day(tips_);
|
||||
assert(tip);
|
||||
|
||||
window.get_widget<tlabel>("tip", false).set_label((*tip)["text"]);
|
||||
window.get_widget<tlabel>("source", false).set_label((*tip)["source"]);
|
||||
|
||||
/**
|
||||
* @todo Convert the code to use a multi_page so the invalidate is not
|
||||
* needed.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class ttitle_screen : public tdialog
|
||||
{
|
||||
public:
|
||||
ttitle_screen() :
|
||||
video_(NULL)
|
||||
{
|
||||
}
|
||||
ttitle_screen();
|
||||
|
||||
CVideo* video() { return video_; }
|
||||
|
||||
|
@ -41,6 +40,23 @@ private:
|
|||
|
||||
/** Inherited from tdialog. */
|
||||
void post_show(twindow& window);
|
||||
|
||||
/** Hold the tips of the day. */
|
||||
config tips_;
|
||||
|
||||
/**
|
||||
* Updates the tip of day widget.
|
||||
*
|
||||
* @param previous Show the previous tip, else shows the next
|
||||
* 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
|
||||
|
|
|
@ -336,6 +336,8 @@ twindow::tretval twindow::get_retval_by_id(const std::string& id)
|
|||
* engine can't handle all dialogs yet, so it needs to fall back to the old
|
||||
* engine to make certain things happen.
|
||||
*/
|
||||
} else if(id == "help") {
|
||||
return static_cast<tretval>(gui::SHOW_HELP);
|
||||
} else if(id == "campaign") {
|
||||
return static_cast<tretval>(gui::NEW_CAMPAIGN);
|
||||
} else if(id == "multiplayer") {
|
||||
|
|
Loading…
Add table
Reference in a new issue