The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
select_orb_colors.cpp
Go to the documentation of this file.
1 /*
2  Part of the Battle for Wesnoth Project http://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 
16 #include "select_orb_colors.hpp"
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 "preferences.hpp"
28 #include "game_config.hpp"
29 
30 #include "utils/functional.hpp"
31 
32 namespace gui2 {
33 REGISTER_DIALOG(select_orb_colors);
34 
36  : show_unmoved_(preferences::show_unmoved_orb())
37  , show_partial_(preferences::show_partial_orb())
38  , show_moved_(preferences::show_moved_orb())
39  , show_ally_(preferences::show_allied_orb())
40  , show_enemy_(preferences::show_enemy_orb())
41 {
42 }
43 
45 {
51 
52  tbutton& reset = find_widget<tbutton>(&window, "orb_defaults", false);
53  connect_signal_mouse_left_click(reset, std::bind(
55  this, std::ref(window)
56  ));
57 }
58 
60 {
61  if(get_retval() == twindow::OK) {
67 
68  preferences::set_unmoved_color(groups_["unmoved"].get_active_member_value());
69  preferences::set_partial_color(groups_["partial"].get_active_member_value());
70  preferences::set_moved_color(groups_["moved"].get_active_member_value());
71  preferences::set_allied_color(groups_["ally"].get_active_member_value());
72  preferences::set_enemy_color(groups_["enemy"].get_active_member_value());
73  }
74 }
75 
76 void tselect_orb_colors::setup_orb_group(const std::string& base_id, bool& shown, const std::string& initial, twindow& window, bool connect)
77 {
78  std::string prefix = "orb_" + base_id + "_";
79  ttoggle_button& toggle = find_widget<ttoggle_button>(&window, prefix + "show", false);
80  toggle.set_value_bool(shown);
81  if(connect) {
82  connect_signal_mouse_left_click(toggle, std::bind(
84  this,
85  std::ref(shown)
86  ));
87  }
88 
89  tgrid& selection = find_widget<tgrid>(&window, prefix + "selection", false);
90  tgroup<std::string>& group = groups_[base_id];
91 
92  using iterator::twalker_;
93  twalker_* iter = selection.create_walker();
94  while(!iter->at_end(twalker_::child)) {
95  twidget* next = iter->get(twalker_::child);
96  if(ttoggle_button* button = dynamic_cast<ttoggle_button*>(next)) {
97  const std::string& id = button->id();
98  group.add_member(button, id.substr(prefix.size()));
99  }
100  iter->next(twalker_::child);
101  }
102  group.set_member_states(initial);
103 }
104 
106 {
107  storage = !storage;
108 }
109 
111 {
117 
123 }
124 
125 }
void set_show_enemy_orb(bool show_orb)
std::string unmoved_color()
bool show_unmoved_orb
Definition: game_config.cpp:81
void set_moved_color(const std::string &color_id)
void set_allied_color(const std::string &color_id)
void set_unmoved_color(const std::string &color_id)
void post_show(twindow &window)
Inherited from tdialog.
int get_retval() const
Definition: dialog.hpp:161
std::map< std::string, tgroup< std::string > > groups_
void set_show_unmoved_orb(bool show_orb)
void setup_orb_group(const std::string &base_id, bool &shown, const std::string &initial, twindow &window, bool connect=true)
Base container class.
Definition: grid.hpp:29
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(label_settings)
bool show_allied_orb()
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
std::string enemy_orb_color
Definition: game_config.cpp:74
bool show_enemy_orb
Definition: game_config.cpp:81
bool show_ally_orb
Definition: game_config.cpp:81
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Simple push button.
Definition: button.hpp:32
virtual iterator::twalker_ * create_walker() override
See twidget::create_walker.
Definition: grid.cpp:656
std::string ally_orb_color
Definition: game_config.cpp:74
void set_enemy_color(const std::string &color_id)
Dialog is closed with ok button.
Definition: window.hpp:125
This file contains the settings handling of the widget library.
void handle_reset_click(twindow &window)
void pre_show(twindow &window)
Inherited from tdialog.
void set_partial_color(const std::string &color_id)
void set_show_partial_orb(bool show_orb)
Modify, read and display user preferences.
std::string moved_orb_color
Definition: game_config.cpp:74
void set_show_moved_orb(bool show_orb)
GLboolean reset
Definition: glew.h:3799
std::string allied_color()
std::string unmoved_orb_color
Definition: game_config.cpp:74
std::string moved_color()
bool show_moved_orb
Definition: game_config.cpp:81
#define next(ls)
Definition: llex.cpp:27
std::string partial_color()
connection connect(const std::string &host, int port)
Function to attempt to connect to a remote host.
Definition: network.cpp:498
GLenum GLint ref
Definition: glew.h:1813
GLboolean GLuint group
Definition: glew.h:2589
Base class for all widgets.
Definition: widget.hpp:49
bool show_partial_orb
Definition: game_config.cpp:81
std::string partial_orb_color
Definition: game_config.cpp:74
The walker abstract base class.
Definition: walker.hpp:27
void set_value_bool(const bool value)
Definition: selectable.hpp:54
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void set_show_allied_orb(bool show_orb)
std::string enemy_color()
void handle_toggle_click(bool &storage)