Use widget groups in the advanced graphics options dialog
This commit is contained in:
parent
63a3312e70
commit
2e36ed230f
4 changed files with 54 additions and 72 deletions
|
@ -162,7 +162,20 @@
|
|||
[button]
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
label = _ "Close"
|
||||
label = _ "OK"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "cancel"
|
||||
definition = "default"
|
||||
label = _ "Cancel"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
|
|
@ -38,83 +38,42 @@
|
|||
namespace gui2
|
||||
{
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWindowDefinitionWML
|
||||
* @order = 2_mp_alerts_options
|
||||
*
|
||||
* == Lobby sounds options ==
|
||||
*
|
||||
* A Preferences subdialog permitting to configure the sounds and notifications
|
||||
* generated in response to various mp lobby / game events.
|
||||
*
|
||||
* @begin{table}{dialog_widgets}
|
||||
*
|
||||
* _label & & label & m &
|
||||
* Item name. $
|
||||
*
|
||||
* _sound & & toggle_button & m &
|
||||
* Toggles whether to play the item sound. $
|
||||
*
|
||||
* _notif & & toggle_button & m &
|
||||
* Toggles whether to give a notification. $
|
||||
*
|
||||
* _lobby & & toggle_button & m &
|
||||
* Toggles whether to take actions for this item when in the lobby. $
|
||||
*
|
||||
* @end{table}
|
||||
*/
|
||||
|
||||
REGISTER_DIALOG(advanced_graphics_options)
|
||||
|
||||
const std::vector<std::string> tadvanced_graphics_options::scale_cases = boost::assign::list_of("zoom")("hex");
|
||||
|
||||
void tadvanced_graphics_options::setup_scale_button(const std::string & case_id, SCALING_ALGORITHM button, twindow & window )
|
||||
tadvanced_graphics_options::SCALING_ALGORITHM tadvanced_graphics_options::get_scale_pref(const std::string& pref_id)
|
||||
{
|
||||
SCALING_ALGORITHM algo = SCALING_ALGORITHM::LINEAR;
|
||||
try {
|
||||
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
|
||||
} catch (bad_enum_cast &) {
|
||||
preferences::set(pref_id, algo.to_string());
|
||||
}
|
||||
// algo is now synced with preference, and default value of linear if something went wrong
|
||||
return algo;
|
||||
}
|
||||
|
||||
void tadvanced_graphics_options::setup_scale_case(const std::string & case_id, twindow & window)
|
||||
{
|
||||
std::string pref_id = "scale_" + case_id;
|
||||
|
||||
tadvanced_graphics_options::SCALING_ALGORITHM algo = tadvanced_graphics_options::SCALING_ALGORITHM::LINEAR;
|
||||
try {
|
||||
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
|
||||
} catch (bad_enum_cast &) {
|
||||
preferences::set(pref_id, algo.to_string());
|
||||
tgroup<SCALING_ALGORITHM>& group = groups_[case_id];
|
||||
for (size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
|
||||
SCALING_ALGORITHM scale = SCALING_ALGORITHM::from_int(x);
|
||||
ttoggle_button* button = &find_widget<ttoggle_button>(&window, pref_id + "_" + scale.to_string(), false);
|
||||
group.add_member(button, scale);
|
||||
}
|
||||
|
||||
// algo is now synced with preference, and default value of linear if something went wrong
|
||||
|
||||
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + button.to_string(), false);
|
||||
b->set_value(algo == button);
|
||||
|
||||
connect_signal_mouse_left_click(*b, boost::bind(&tadvanced_graphics_options::scale_button_callback, this, pref_id, button, boost::ref(window)));
|
||||
group.set_member_states(get_scale_pref(pref_id));
|
||||
}
|
||||
|
||||
void tadvanced_graphics_options::scale_button_callback(std::string pref_id, SCALING_ALGORITHM me, twindow & window)
|
||||
void tadvanced_graphics_options::update_scale_case(const std::string & case_id)
|
||||
{
|
||||
tadvanced_graphics_options::SCALING_ALGORITHM algo = tadvanced_graphics_options::SCALING_ALGORITHM::LINEAR;
|
||||
try {
|
||||
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
|
||||
} catch (bad_enum_cast &) {
|
||||
preferences::set(pref_id, algo.to_string());
|
||||
}
|
||||
|
||||
if (algo != me) {
|
||||
std::string pref_id = "scale_" + case_id;
|
||||
SCALING_ALGORITHM new_val = groups_[case_id].get_active_member_value();
|
||||
if(new_val != get_scale_pref(pref_id)) {
|
||||
image::flush_cache();
|
||||
}
|
||||
|
||||
preferences::set(pref_id, me.to_string());
|
||||
|
||||
for (size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
|
||||
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM::from_int(x).to_string(), false);
|
||||
b->set_value(x == me.cast<size_t>());
|
||||
}
|
||||
|
||||
image::update_from_preferences();
|
||||
}
|
||||
|
||||
void tadvanced_graphics_options::setup_scale_case(const std::string & i, twindow & window)
|
||||
{
|
||||
for (size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
|
||||
setup_scale_button(i, SCALING_ALGORITHM::from_int(x), window);
|
||||
}
|
||||
preferences::set(pref_id, new_val.to_string());
|
||||
}
|
||||
|
||||
tadvanced_graphics_options::tadvanced_graphics_options()
|
||||
|
@ -136,6 +95,12 @@ void tadvanced_graphics_options::pre_show(CVideo& /*video*/, twindow& window)
|
|||
|
||||
void tadvanced_graphics_options::post_show(twindow& /*window*/)
|
||||
{
|
||||
if(get_retval() == twindow::OK) {
|
||||
BOOST_FOREACH(const std::string & i, scale_cases) {
|
||||
update_scale_case(i);
|
||||
}
|
||||
image::update_from_preferences();
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace gui2
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define GUI_DIALOGS_ADVANCED_GRAPHICS_OPTIONS_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "gui/widgets/group.hpp"
|
||||
#include "make_enum.hpp"
|
||||
|
||||
namespace gui2
|
||||
|
@ -61,8 +62,10 @@ private:
|
|||
void post_show(twindow& window);
|
||||
|
||||
void setup_scale_case(const std::string &, twindow &);
|
||||
void setup_scale_button(const std::string &, SCALING_ALGORITHM, twindow &);
|
||||
void scale_button_callback(std::string, SCALING_ALGORITHM, twindow &);
|
||||
void update_scale_case(const std::string &);
|
||||
SCALING_ALGORITHM get_scale_pref(const std::string& pref_id);
|
||||
|
||||
std::map<std::string,tgroup<SCALING_ALGORITHM> > groups_;
|
||||
};
|
||||
|
||||
} // end namespace gui2
|
||||
|
|
|
@ -1278,16 +1278,17 @@ bool save_image(const surface & surf, const std::string & filename)
|
|||
|
||||
bool update_from_preferences()
|
||||
{
|
||||
gui2::tadvanced_graphics_options::SCALING_ALGORITHM algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::LINEAR;
|
||||
typedef gui2::tadvanced_graphics_options::SCALING_ALGORITHM SCALING_ALGORITHM;
|
||||
SCALING_ALGORITHM algo = SCALING_ALGORITHM::LINEAR;
|
||||
try {
|
||||
algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::string_to_enum(preferences::get("scale_hex"));
|
||||
algo = SCALING_ALGORITHM::string_to_enum(preferences::get("scale_hex"));
|
||||
} catch (bad_enum_cast &) {}
|
||||
|
||||
scale_to_hex_func = select_algorithm(algo);
|
||||
|
||||
algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::LINEAR;
|
||||
algo = SCALING_ALGORITHM::LINEAR;
|
||||
try {
|
||||
algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::string_to_enum(preferences::get("scale_zoom"));
|
||||
algo = SCALING_ALGORITHM::string_to_enum(preferences::get("scale_zoom"));
|
||||
} catch (bad_enum_cast &) {}
|
||||
|
||||
scale_to_zoom_func = select_algorithm(algo);
|
||||
|
|
Loading…
Add table
Reference in a new issue