The Battle for Wesnoth  1.15.2+dev
select_orb_colors.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #define GETTEXT_DOMAIN "wesnoth-lib"
15 
17 
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/grid.hpp"
23 #include "gui/widgets/settings.hpp"
25 #include "gui/widgets/window.hpp"
26 
27 #include "game_config.hpp"
28 #include "preferences/general.hpp"
29 #include "utils/functional.hpp"
30 
31 namespace gui2
32 {
33 namespace dialogs
34 {
35 namespace
36 {
37 std::string get_orb_widget_prefix(const std::string& base_id)
38 {
39  return "orb_" + base_id + "_";
40 }
41 
42 } // end anon namespace
43 
44 REGISTER_DIALOG(select_orb_colors)
45 
47  : show_unmoved_(preferences::show_unmoved_orb())
48  , show_partial_(preferences::show_partial_orb())
49  , show_moved_(preferences::show_moved_orb())
50  , show_ally_(preferences::show_allied_orb())
51  , show_enemy_(preferences::show_enemy_orb())
52 {
53 }
54 
56 {
62 
63  connect_signal_mouse_left_click(find_widget<button>(&window, "orb_defaults", false),
64  std::bind(&select_orb_colors::reset_orb_callback, this));
65 }
66 
68 {
69  if(get_retval() != retval::OK) {
70  return;
71  }
72 
78 
79  preferences::set_unmoved_color(groups_["unmoved"].get_active_member_value());
80  preferences::set_partial_color(groups_["partial"].get_active_member_value());
81  preferences::set_moved_color(groups_["moved"].get_active_member_value());
82  preferences::set_allied_color(groups_["ally"].get_active_member_value());
83  preferences::set_enemy_color(groups_["enemy"].get_active_member_value());
84 }
85 
86 void select_orb_colors::setup_orb_group(const std::string& base_id, bool& shown, const std::string& initial)
87 {
88  const std::string prefix = get_orb_widget_prefix(base_id);
89 
90  //
91  // Set up the "show this group of orbs" toggle.
92  //
93  toggle_button& toggle = find_widget<toggle_button>(get_window(), prefix + "show", false);
94  toggle.set_value_bool(shown);
95 
97  std::bind(&select_orb_colors::toggle_orb_callback, this, std::ref(shown)));
98 
99  //
100  // Set up the toggle group.
101  //
102  group<std::string>& group = groups_[base_id];
103 
104  // Grid containing each color option toggle.
105  grid& selection = find_widget<grid>(get_window(), prefix + "selection", false);
106 
107  for(iteration::bottom_up_iterator<true, false, true> iter(selection); !iter.at_end(); ++iter) {
108  if(toggle_button* button = dynamic_cast<toggle_button*>(iter.get())) {
109  const std::string& id = button->id();
110  group.add_member(button, id.substr(prefix.size()));
111  }
112  }
113 
114  group.set_member_states(initial);
115 }
116 
117 void select_orb_colors::reset_orb_group(const std::string& base_id, bool& shown, const std::string& initial)
118 {
119  const std::string prefix = get_orb_widget_prefix(base_id);
120 
121  toggle_button& toggle = find_widget<toggle_button>(get_window(), prefix + "show", false);
122  toggle.set_value_bool(shown);
123 
124  groups_[base_id].set_member_states(initial);
125 }
126 
128 {
129  storage = !storage;
130 }
131 
133 {
139 
145 }
146 
147 } // namespace dialogs
148 } // namespace gui2
void set_show_enemy_orb(bool show_orb)
Definition: general.cpp:266
std::string unmoved_color()
Definition: general.cpp:343
void set_value_bool(bool value, bool fire_event=false)
bool show_unmoved_orb
void set_moved_color(const std::string &color_id)
Definition: general.cpp:339
void set_allied_color(const std::string &color_id)
Definition: general.cpp:309
void set_unmoved_color(const std::string &color_id)
Definition: general.cpp:349
void reset_orb_group(const std::string &base_id, bool &shown, const std::string &initial)
void set_show_unmoved_orb(bool show_orb)
Definition: general.cpp:280
const std::string & id() const
Definition: widget.cpp:107
This file contains the window object, this object is a top level container which has the event manage...
bool show_allied_orb()
Definition: general.cpp:256
window * get_window() const
Returns a pointer to the dialog&#39;s window.
std::string enemy_orb_color
bool show_enemy_orb
bool show_ally_orb
Generic file dialog.
Definition: field-fwd.hpp:22
Base container class.
Definition: grid.hpp:30
std::string ally_orb_color
bool at_end() const
Has the iterator reached the end?
Definition: iterator.hpp:60
void set_enemy_color(const std::string &color_id)
Definition: general.cpp:329
This file contains the settings handling of the widget library.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:233
void setup_orb_group(const std::string &base_id, bool &shown, const std::string &initial)
The display function.
void set_partial_color(const std::string &color_id)
Definition: general.cpp:359
void set_show_partial_orb(bool show_orb)
Definition: general.cpp:287
Modify, read and display user preferences.
std::string moved_orb_color
virtual void post_show(window &window) override
Inherited from modal_dialog.
void set_show_moved_orb(bool show_orb)
Definition: general.cpp:273
Various uncategorised dialogs.
virtual void pre_show(window &window) override
Inherited from modal_dialog.
void add_member(selectable_item *w, const T &value)
Adds a widget/value pair to the group map.
Definition: group.hpp:41
std::string allied_color()
Definition: general.cpp:303
std::string unmoved_orb_color
std::string moved_color()
Definition: general.cpp:333
bool show_moved_orb
The iterator class.
Definition: iterator.hpp:38
std::string partial_color()
Definition: general.cpp:353
Simple push button.
Definition: button.hpp:35
Contains the base iterator class for the gui2 widgets.
bool show_partial_orb
std::string partial_orb_color
Dialog was closed with the OK button.
Definition: retval.hpp:34
std::map< std::string, group< std::string > > groups_
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
void set_show_allied_orb(bool show_orb)
Definition: general.cpp:259
std::string enemy_color()
Definition: general.cpp:323
Class for a toggle button.
void set_member_states(const T &value)
Sets the toggle values for all widgets besides the one associated with the specified value to false...
Definition: group.hpp:110