theme ui, gui2/ttheme_list: New theme chooser, implement [theme] description
Adds a new 'description' attribute to [theme] and replaces the previous instance of gui2::tsimple_item_selector used to select themes with a brand new dialog (that's actually based on it) that allows for displaying theme descriptions in a nice format. Because some of the theme names aren't obvious enough to players ("UnitBox" comes to mind), we ought to provide descriptions of each theme to save people some clicks since it's not possible at the moment to switch the theme mid-game and see the results immediately.
This commit is contained in:
parent
eadb22f67b
commit
a9c93201c8
8 changed files with 396 additions and 17 deletions
190
data/gui/default/window/theme_list.cfg
Normal file
190
data/gui/default/window/theme_list.cfg
Normal file
|
@ -0,0 +1,190 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to select a GUI theme.
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "theme_list"
|
||||
description = "GUI theme selection dialog."
|
||||
|
||||
[resolution]
|
||||
definition = "default"
|
||||
|
||||
automatic_placement = "true"
|
||||
vertical_placement = "center"
|
||||
horizontal_placement = "center"
|
||||
|
||||
maximum_width = 600
|
||||
maximum_height = 600
|
||||
|
||||
[linked_group]
|
||||
id = "name"
|
||||
fixed_width = "true"
|
||||
[/linked_group]
|
||||
|
||||
[linked_group]
|
||||
id = "description"
|
||||
fixed_width = "true"
|
||||
[/linked_group]
|
||||
|
||||
[tooltip]
|
||||
id = "tooltip_large"
|
||||
[/tooltip]
|
||||
|
||||
[helptip]
|
||||
id = "tooltip_large"
|
||||
[/helptip]
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
definition = "title"
|
||||
label = _ "Choose Theme"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
definition = "default"
|
||||
#label = _ "The new theme will take effect after loading or starting a new game."
|
||||
label = _ "New theme will take effect on next new or loaded game."
|
||||
wrap = true
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
horizontal_grow = "true"
|
||||
vertical_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[listbox]
|
||||
id = "themes"
|
||||
definition = "default"
|
||||
|
||||
[list_definition]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
vertical_grow = "true"
|
||||
horizontal_grow = "true"
|
||||
[toggle_panel]
|
||||
definition = "default"
|
||||
return_value_id = "ok"
|
||||
[grid]
|
||||
[row]
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
[label]
|
||||
id = "name"
|
||||
definition = "default"
|
||||
linked_group = "name"
|
||||
[/label]
|
||||
[/column]
|
||||
[/row]
|
||||
[row]
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
border = "all"
|
||||
border_size = 5
|
||||
[label]
|
||||
id = "description"
|
||||
definition = "gold_small"
|
||||
linked_group = "description"
|
||||
[/label]
|
||||
[/column]
|
||||
[/row]
|
||||
[/grid]
|
||||
[/toggle_panel]
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/list_definition]
|
||||
|
||||
[/listbox]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
label = _ "OK"
|
||||
[/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]
|
|
@ -780,6 +780,7 @@ set(wesnoth-main_SRC
|
|||
gui/dialogs/popup.cpp
|
||||
gui/dialogs/edit_text.cpp
|
||||
gui/dialogs/simple_item_selector.cpp
|
||||
gui/dialogs/theme_list.cpp
|
||||
gui/dialogs/title_screen.cpp
|
||||
gui/dialogs/transient_message.cpp
|
||||
gui/dialogs/unit_attack.cpp
|
||||
|
|
|
@ -389,6 +389,7 @@ wesnoth_sources = Split("""
|
|||
gui/dialogs/popup.cpp
|
||||
gui/dialogs/edit_text.cpp
|
||||
gui/dialogs/simple_item_selector.cpp
|
||||
gui/dialogs/theme_list.cpp
|
||||
gui/dialogs/tip.cpp
|
||||
gui/dialogs/title_screen.cpp
|
||||
gui/dialogs/transient_message.cpp
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/game_paths.hpp"
|
||||
#include "gui/dialogs/simple_item_selector.hpp"
|
||||
#include "gui/dialogs/theme_list.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "lobby_preferences.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "preferences_display.hpp"
|
||||
#include "wml_separators.hpp"
|
||||
#include "widgets/combo.hpp"
|
||||
|
@ -1437,9 +1439,20 @@ void show_preferences_dialog(display& disp, const config& game_cfg)
|
|||
|
||||
bool show_theme_dialog(display& disp)
|
||||
{
|
||||
std::vector<std::string> options = disp.get_theme().get_known_themes();
|
||||
std::vector<theme_info> themes = disp.get_theme().get_known_themes();
|
||||
std::vector<std::string> options;
|
||||
|
||||
BOOST_FOREACH(const theme_info& t, themes)
|
||||
{
|
||||
options.push_back(t.name);
|
||||
|
||||
if(!t.description.empty()) {
|
||||
options.back() += "\n<span size='small' color='#" + font::color2hexa(font::TITLE_COLOR) + "'>"+ t.description +"</span>";
|
||||
}
|
||||
}
|
||||
|
||||
if(!options.empty()){
|
||||
gui2::tsimple_item_selector dlg(_("Choose Theme"), "", options);
|
||||
gui2::ttheme_list dlg(themes);
|
||||
|
||||
for(size_t k = 0; k < options.size(); ++k) {
|
||||
if(options[k] == preferences::theme()) {
|
||||
|
@ -1451,16 +1464,16 @@ bool show_theme_dialog(display& disp)
|
|||
const int action = dlg.selected_index();
|
||||
|
||||
if(action >= 0){
|
||||
preferences::set_theme(options[action]);
|
||||
//it would be preferable for the new theme to take effect
|
||||
//immediately, however, this will have to do for now.
|
||||
gui2::show_transient_message(disp.video(),"",_("New theme will take effect on next new or loaded game."));
|
||||
return(1);
|
||||
preferences::set_theme(options[action]);
|
||||
// FIXME: it would be preferable for the new theme to take effect
|
||||
// immediately.
|
||||
return 1;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
gui2::show_transient_message(disp.video(),"",_("No known themes. Try changing from within an existing game."));
|
||||
}
|
||||
return(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void show_paths_dialog(display& disp)
|
||||
|
|
97
src/gui/dialogs/theme_list.cpp
Normal file
97
src/gui/dialogs/theme_list.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "gui/dialogs/theme_list.hpp"
|
||||
|
||||
#include "gui/auxiliary/find_widget.tpp"
|
||||
#ifdef GUI2_EXPERIMENTAL_LISTBOX
|
||||
#include "gui/widgets/list.hpp"
|
||||
#else
|
||||
#include "gui/widgets/listbox.hpp"
|
||||
#endif
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "theme.hpp"
|
||||
#include "utils/foreach.tpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWindowDefinitionWML
|
||||
* @order = 2_theme_list
|
||||
*
|
||||
* == Theme list ==
|
||||
*
|
||||
* Dialog for selecting a GUI theme.
|
||||
*
|
||||
* @begin{table}{dialog_widgets}
|
||||
*
|
||||
* themes & & listbox & m &
|
||||
* Listbox displaying user choices. $
|
||||
*
|
||||
* -name & & control & m &
|
||||
* Widget which shows a theme item name. $
|
||||
*
|
||||
* -description & & control & m &
|
||||
* Widget which shows a theme item description. $
|
||||
*
|
||||
* @end{table}
|
||||
*/
|
||||
|
||||
REGISTER_DIALOG(theme_list)
|
||||
|
||||
ttheme_list::ttheme_list(const std::vector<theme_info>& themes,
|
||||
int selection)
|
||||
: index_(selection)
|
||||
, themes_(themes)
|
||||
{
|
||||
}
|
||||
|
||||
void ttheme_list::pre_show(CVideo& /*video*/, twindow& window)
|
||||
{
|
||||
tlistbox& list = find_widget<tlistbox>(&window, "themes", false);
|
||||
window.keyboard_capture(&list);
|
||||
|
||||
FOREACH(const AUTO & t, themes_)
|
||||
{
|
||||
std::map<std::string, string_map> data;
|
||||
string_map column;
|
||||
|
||||
column["label"] = t.name;
|
||||
data.insert(std::make_pair("name", column));
|
||||
column["label"] = t.description;
|
||||
data.insert(std::make_pair("description", column));
|
||||
|
||||
list.add_row(data);
|
||||
}
|
||||
|
||||
if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) {
|
||||
list.select_row(index_);
|
||||
}
|
||||
|
||||
index_ = -1;
|
||||
}
|
||||
|
||||
void ttheme_list::post_show(twindow& window)
|
||||
{
|
||||
if(get_retval() != twindow::OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
tlistbox& list = find_widget<tlistbox>(&window, "themes", false);
|
||||
index_ = list.get_selected_row();
|
||||
}
|
||||
|
||||
}
|
63
src/gui/dialogs/theme_list.hpp
Normal file
63
src/gui/dialogs/theme_list.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
|
||||
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_THEME_LIST_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_THEME_LIST_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
|
||||
struct theme_info;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class ttheme_list : public tdialog
|
||||
{
|
||||
public:
|
||||
explicit ttheme_list(const std::vector<theme_info>& themes,
|
||||
int selection = -1);
|
||||
|
||||
/**
|
||||
* Returns the selected item index after displaying.
|
||||
* @return -1 if the dialog was canceled.
|
||||
*/
|
||||
int selected_index() const
|
||||
{
|
||||
return index_;
|
||||
}
|
||||
|
||||
/** Sets the initially selected item index (-1 by default). */
|
||||
void set_selected_index(int index)
|
||||
{
|
||||
index_ = index;
|
||||
}
|
||||
|
||||
private:
|
||||
int index_;
|
||||
|
||||
std::vector<theme_info> themes_;
|
||||
|
||||
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
|
||||
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
|
|
@ -904,7 +904,9 @@ const theme::status_item* theme::get_status_item(const std::string& key) const
|
|||
return NULL;
|
||||
}
|
||||
|
||||
std::map<std::string, config> theme::known_themes;
|
||||
typedef std::map<std::string, config> known_themes_map;
|
||||
known_themes_map theme::known_themes;
|
||||
|
||||
void theme::set_known_themes(const config* cfg)
|
||||
{
|
||||
known_themes.clear();
|
||||
|
@ -919,14 +921,20 @@ void theme::set_known_themes(const config* cfg)
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> theme::get_known_themes(){
|
||||
std::vector<std::string> names;
|
||||
std::vector<theme_info> theme::get_known_themes()
|
||||
{
|
||||
std::vector<theme_info> res;
|
||||
|
||||
for(known_themes_map::const_iterator i = known_themes.begin();
|
||||
i != known_themes.end();
|
||||
++i)
|
||||
{
|
||||
res.push_back(theme_info());
|
||||
res.back().name = i->first;
|
||||
res.back().description = i->second["description"].t_str();
|
||||
}
|
||||
|
||||
for(std::map<std::string, config>::iterator p_thm=known_themes.begin();p_thm!=known_themes.end();++p_thm){
|
||||
names.push_back(p_thm->first);
|
||||
}
|
||||
return(names);
|
||||
return res;
|
||||
}
|
||||
|
||||
const theme::menu *theme::get_menu_item(const std::string &key) const
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
|
||||
typedef struct { size_t x1,y1,x2,y2; } _rect;
|
||||
|
||||
struct theme_info
|
||||
{
|
||||
std::string name;
|
||||
t_string description;
|
||||
};
|
||||
|
||||
class theme
|
||||
{
|
||||
|
||||
|
@ -279,7 +285,7 @@ public:
|
|||
{ return palette_.location(screen); }
|
||||
|
||||
static void set_known_themes(const config* cfg);
|
||||
static std::vector<std::string> get_known_themes();
|
||||
static std::vector<theme_info> get_known_themes();
|
||||
|
||||
const tborder& border() const { return border_; }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue