Make the tip shown a window configuration.
This commit is contained in:
parent
43ec60a6ac
commit
d68da20fa4
7 changed files with 104 additions and 14 deletions
|
@ -146,7 +146,9 @@ twindow *build(CVideo &video, const twindow_builder::tresolution *definition)
|
|||
, definition->vertical_placement
|
||||
, definition->maximum_width
|
||||
, definition->maximum_height
|
||||
, definition->definition);
|
||||
, definition->definition
|
||||
, definition->tooltip
|
||||
, definition->helptip);
|
||||
assert(window);
|
||||
|
||||
foreach(const twindow_builder::tresolution::tlinked_group& lg,
|
||||
|
@ -254,6 +256,8 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
|
|||
click_dismiss(cfg["click_dismiss"].to_bool()),
|
||||
definition(cfg["definition"]),
|
||||
linked_groups(),
|
||||
tooltip(cfg.child_or_empty("tooltip")), /** @todo will be mandatory soon. */
|
||||
helptip(cfg.child_or_empty("helptip")), /** @todo will be mandatory soon. */
|
||||
grid(0)
|
||||
{
|
||||
/*WIKI
|
||||
|
@ -319,6 +323,11 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
|
|||
*
|
||||
* linked_group & sections & [] & A group of linked widget sections. $
|
||||
*
|
||||
* tooltip & section & & Information regarding the tooltip for this
|
||||
* window. $
|
||||
* helptip & section & & Information regarding the helptip for this
|
||||
* window. $
|
||||
*
|
||||
* grid & grid & & The grid with the widgets to show. $
|
||||
* @end{table}
|
||||
*
|
||||
|
@ -331,8 +340,13 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
|
|||
* fixed_height & bool & false & Should widget in this group have the same
|
||||
* height. $
|
||||
* @end{table}
|
||||
*
|
||||
* A linked group needs to have at least one size fixed.
|
||||
*
|
||||
* A tooltip and helptip section have the following field:
|
||||
* @begin{table}{config}
|
||||
* id & string & & The id of the tip to show. $
|
||||
* @begin{table}{config}
|
||||
* Note more fields will probably be added later on.
|
||||
*/
|
||||
|
||||
const config &c = cfg.child("grid");
|
||||
|
@ -379,6 +393,21 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
|
|||
}
|
||||
}
|
||||
|
||||
twindow_builder::tresolution::ttip::ttip(const config& cfg)
|
||||
: id(cfg["id"])
|
||||
{
|
||||
/** @todo Remove for 1.9.7. */
|
||||
if(id.empty()) {
|
||||
lg::wml_error << "Window builder: parsing resolution tip with empty "
|
||||
<< "'id' field. Will become mandatory in 1.9.7.\n";
|
||||
id = "tooltip_large";
|
||||
return;
|
||||
}
|
||||
|
||||
VALIDATE(!id.empty()
|
||||
, missing_mandatory_wml_key("[window][resolution][tip]", "id"));
|
||||
}
|
||||
|
||||
tbuilder_grid::tbuilder_grid(const config& cfg) :
|
||||
tbuilder_widget(cfg),
|
||||
id(cfg["id"]),
|
||||
|
|
|
@ -162,6 +162,17 @@ public:
|
|||
|
||||
std::vector<tlinked_group> linked_groups;
|
||||
|
||||
/** Helper struct to store information about the tips. */
|
||||
struct ttip
|
||||
{
|
||||
ttip(const config& cfg);
|
||||
|
||||
std::string id;
|
||||
};
|
||||
|
||||
ttip tooltip;
|
||||
ttip helptip;
|
||||
|
||||
tbuilder_grid_ptr grid;
|
||||
};
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_CFG LOG_STREAM(warn , log_config)
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
/*WIKI
|
||||
|
@ -138,11 +141,26 @@ void show(CVideo& video
|
|||
, const t_string& message
|
||||
, const tpoint& mouse)
|
||||
{
|
||||
/*
|
||||
* For now allow invalid tip names, might turn them to invalid wml messages
|
||||
* later on.
|
||||
*/
|
||||
ttip& t = tip();
|
||||
t.set_window_id(window_id);
|
||||
t.set_message(message);
|
||||
t.set_mouse(mouse);
|
||||
try {
|
||||
t.show(video);
|
||||
} catch(twindow_builder_invalid_id&) {
|
||||
ERR_CFG << "Tip with the requested id '" << window_id
|
||||
<< "' doesn't exist, fall back to the default.\n";
|
||||
t.set_window_id("tooltip_large");
|
||||
try {
|
||||
t.show(video);
|
||||
} catch(twindow_builder_invalid_id&) {
|
||||
ERR_CFG << "Default tooltip doesn't exist, no message shown.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remove()
|
||||
|
|
|
@ -550,7 +550,8 @@ tresolution_definition_ptr get_control(
|
|||
ERROR_LOG(false);
|
||||
}
|
||||
|
||||
std::vector<twindow_builder::tresolution>::const_iterator get_window_builder(const std::string& type)
|
||||
std::vector<twindow_builder::tresolution>::const_iterator get_window_builder(
|
||||
const std::string& type)
|
||||
{
|
||||
twindow::update_screen_size();
|
||||
|
||||
|
@ -558,7 +559,9 @@ std::vector<twindow_builder::tresolution>::const_iterator get_window_builder(con
|
|||
window = current_gui->second.window_types.find(type);
|
||||
|
||||
if(true) { // FIXME Test for default gui.
|
||||
assert(window != current_gui->second.window_types.end());
|
||||
if(window == current_gui->second.window_types.end()) {
|
||||
throw twindow_builder_invalid_id();
|
||||
}
|
||||
} else {
|
||||
// FIXME Get the definition in the default gui and do an assertion test.
|
||||
}
|
||||
|
|
|
@ -123,6 +123,25 @@ void load_widget_definitions(
|
|||
tresolution_definition_ptr get_control(
|
||||
const std::string& control_type, const std::string& definition);
|
||||
|
||||
/** Helper struct to signal that get_window_builder failed. */
|
||||
struct twindow_builder_invalid_id {};
|
||||
|
||||
/**
|
||||
* Returns an interator to the requested builder.
|
||||
*
|
||||
* The builder is determined by the @p type and the current screen
|
||||
* resolution.
|
||||
*
|
||||
* @pre There is a valid builder for @p type at the
|
||||
* current resolution.
|
||||
*
|
||||
* @throw twindow_builder_invalid_id
|
||||
* When the precondition is violated.
|
||||
*
|
||||
* @param type The type of builder window to get.
|
||||
*
|
||||
* @returns An iterator to the requested builder.
|
||||
*/
|
||||
std::vector<twindow_builder::tresolution>::const_iterator
|
||||
get_window_builder(const std::string& type);
|
||||
|
||||
|
|
|
@ -269,7 +269,9 @@ twindow::twindow(CVideo& video,
|
|||
const unsigned vertical_placement,
|
||||
const unsigned maximum_width,
|
||||
const unsigned maximum_height,
|
||||
const std::string& definition)
|
||||
const std::string& definition,
|
||||
const twindow_builder::tresolution::ttip& tooltip,
|
||||
const twindow_builder::tresolution::ttip& helptip)
|
||||
: tpanel()
|
||||
, cursor::setter(cursor::NORMAL)
|
||||
, video_(video)
|
||||
|
@ -291,6 +293,8 @@ twindow::twindow(CVideo& video,
|
|||
, y_(y)
|
||||
, w_(w)
|
||||
, h_(h)
|
||||
, tooltip_(tooltip)
|
||||
, helptip_(helptip)
|
||||
, click_dismiss_(false)
|
||||
, enter_disabled_(false)
|
||||
, escape_disabled_(false)
|
||||
|
@ -360,7 +364,7 @@ twindow::twindow(CVideo& video,
|
|||
, _5)
|
||||
, event::tdispatcher::back_pre_child);
|
||||
|
||||
register_hotkey(hotkey::GLOBAL__HELPTIP, boost::bind(helptip));
|
||||
register_hotkey(hotkey::GLOBAL__HELPTIP, boost::bind(gui2::helptip));
|
||||
}
|
||||
|
||||
twindow::~twindow()
|
||||
|
@ -1303,11 +1307,10 @@ void twindow::signal_handler_message_show_tooltip(
|
|||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
event::tmessage_show_tooltip& tooltip =
|
||||
event::tmessage_show_tooltip& request =
|
||||
dynamic_cast<event::tmessage_show_tooltip&>(message);
|
||||
|
||||
/** @todo Make not hard coded. */
|
||||
tip::show(video_, "tooltip_large", tooltip.message, tooltip.location);
|
||||
tip::show(video_, tooltip_.id, request.message, request.location);
|
||||
|
||||
handled = true;
|
||||
}
|
||||
|
@ -1319,11 +1322,10 @@ void twindow::signal_handler_message_show_helptip(
|
|||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
event::tmessage_show_helptip& helptip =
|
||||
event::tmessage_show_helptip& request =
|
||||
dynamic_cast<event::tmessage_show_helptip&>(message);
|
||||
|
||||
/** @todo Make not hard coded. */
|
||||
tip::show(video_, "tooltip_large", helptip.message, helptip.location);
|
||||
tip::show(video_, helptip_.id, request.message, request.location);
|
||||
|
||||
handled = true;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,9 @@ public:
|
|||
const unsigned vertical_placement,
|
||||
const unsigned maximum_width,
|
||||
const unsigned maximum_height,
|
||||
const std::string& definition);
|
||||
const std::string& definition,
|
||||
const twindow_builder::tresolution::ttip& tooltip,
|
||||
const twindow_builder::tresolution::ttip& helptip);
|
||||
|
||||
~twindow();
|
||||
|
||||
|
@ -472,6 +474,12 @@ private:
|
|||
/** The formula to calulate the height of the dialog. */
|
||||
tformula<unsigned>h_;
|
||||
|
||||
/** The settings for the tooltip. */
|
||||
twindow_builder::tresolution::ttip tooltip_;
|
||||
|
||||
/** The settings for the helptip. */
|
||||
twindow_builder::tresolution::ttip helptip_;
|
||||
|
||||
/**
|
||||
* Do we want to have easy close behaviour?
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue