Preferences: code cleanup and minor bugfix

This commit is contained in:
Celtic Minstrel 2016-02-21 00:38:27 -05:00
parent 85fefbe5b8
commit 6848a6d596
4 changed files with 28 additions and 24 deletions

View file

@ -208,7 +208,7 @@
[/grid]
[/column]
[/row]
{_GUI_PREFERENCES_SPACER_ROW}
[row]
[column]
horizontal_grow = true

View file

@ -291,7 +291,7 @@ void tpreferences::setup_friends_list(twindow& window)
{
tlistbox& friends_list = find_widget<tlistbox>(&window, "friends_list", false);
const std::map<std::string, preferences::acquaintance>& acquaintances = get_acquaintances();
const std::map<std::string, acquaintance>& acquaintances = get_acquaintances();
std::map<std::string, string_map> data;
@ -364,11 +364,12 @@ void tpreferences::add_friend_list_entry(const bool is_friend,
void tpreferences::edit_friend_list_entry(tlistbox& friends,
ttext_box& textbox)
{
const int num_available = get_acquaintances().size();
const int sel = friends.get_selected_row();
if(sel < 0) {
if(sel < 0 || sel >= num_available) {
return;
}
std::map<std::string, preferences::acquaintance>::const_iterator who = get_acquaintances().begin();
std::map<std::string, acquaintance>::const_iterator who = get_acquaintances().begin();
std::advance(who, sel);
textbox.set_value(who->second.get_nick() + " " + who->second.get_notes());
}
@ -491,7 +492,7 @@ void tpreferences::initialize_members(twindow& window)
/** SET HOTKEYS **/
connect_signal_mouse_left_click(find_widget<tbutton>(&window, "hotkeys", false),
boost::bind(&preferences::show_hotkeys_preferences_dialog,
boost::bind(&show_hotkeys_preferences_dialog,
boost::ref(window.video())));
/** CACHE MANAGE **/
@ -562,7 +563,7 @@ void tpreferences::initialize_members(twindow& window)
/** SELECT THEME **/
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "choose_theme", false),
boost::bind(&preferences::show_theme_dialog,
boost::bind(&show_theme_dialog,
boost::ref(window.video())));
@ -672,7 +673,7 @@ void tpreferences::initialize_members(twindow& window)
/** SET WESNOTHD PATH **/
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "mp_wesnothd", false), boost::bind(
&preferences::show_wesnothd_server_search,
&show_wesnothd_server_search,
boost::ref(window.video())));

View file

@ -55,27 +55,26 @@ void tselect_orb_colors::pre_show(CVideo&, twindow& window)
setup_orb_group("enemy", show_enemy_, enemy_, window);
tbutton& reset = find_widget<tbutton>(&window, "orb_defaults", false);
event::connect_signal_mouse_left_click(reset, boost::bind(
connect_signal_mouse_left_click(reset, boost::bind(
&tselect_orb_colors::handle_reset_click,
this, boost::ref(window)
));
}
void tselect_orb_colors::display(CVideo& video)
void tselect_orb_colors::post_show(twindow&)
{
tselect_orb_colors dialog;
if(dialog.show(video)) {
preferences::set_show_unmoved_orb(dialog.show_unmoved_);
preferences::set_show_partial_orb(dialog.show_partial_);
preferences::set_show_moved_orb(dialog.show_moved_);
preferences::set_show_allied_orb(dialog.show_ally_);
preferences::set_show_enemy_orb(dialog.show_enemy_);
if(get_retval() == twindow::OK) {
preferences::set_show_unmoved_orb(show_unmoved_);
preferences::set_show_partial_orb(show_partial_);
preferences::set_show_moved_orb(show_moved_);
preferences::set_show_allied_orb(show_ally_);
preferences::set_show_enemy_orb(show_enemy_);
preferences::set_unmoved_color(dialog.unmoved_);
preferences::set_partial_color(dialog.partial_);
preferences::set_moved_color(dialog.moved_);
preferences::set_allied_color(dialog.ally_);
preferences::set_enemy_color(dialog.enemy_);
preferences::set_unmoved_color(unmoved_);
preferences::set_partial_color(partial_);
preferences::set_moved_color(moved_);
preferences::set_allied_color(ally_);
preferences::set_enemy_color(enemy_);
}
}
@ -84,7 +83,7 @@ void tselect_orb_colors::setup_orb_group(const std::string& base_id, bool& shown
ttoggle_button& toggle = find_widget<ttoggle_button>(&window, "orb_" + base_id + "_show", false);
toggle.set_value_bool(shown);
if(connect) {
event::connect_signal_mouse_left_click(toggle, boost::bind(
connect_signal_mouse_left_click(toggle, boost::bind(
&tselect_orb_colors::handle_toggle_click,
this,
boost::ref(shown)
@ -106,7 +105,7 @@ void tselect_orb_colors::setup_orb_group(const std::string& base_id, bool& shown
button->set_value_bool(false);
}
if(connect) {
event::connect_signal_mouse_left_click(*button, boost::bind(
connect_signal_mouse_left_click(*button, boost::bind(
&tselect_orb_colors::handle_orb_click,
this,
button,

View file

@ -30,7 +30,9 @@ public:
*
* See @ref tdialog for more information.
*/
static void display(CVideo& video);
static void display(CVideo& video) {
tselect_orb_colors().show(video);
}
private:
void setup_orb_group(const std::string& base_id, bool& shown, std::string& color, twindow& window, bool connect = true);
void handle_orb_click(ttoggle_button* clicked, const std::vector<ttoggle_button*>& group, std::string& storage);
@ -46,6 +48,8 @@ private:
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
};
}