Project Alice
Loading...
Searching...
No Matches
gui_factory_buttons_window.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace ui {
8
10public:
11 void button_action(sys::state& state) noexcept override {
12 if(!parent)
13 return;
14
15 for(auto p : state.world.nation_get_province_ownership(state.local_player_nation)) {
16 for(auto fac : p.get_province().get_factory_location()) {
17 if(!fac.get_factory().get_subsidized()) {
18 Cyto::Any payload = commodity_filter_query_data{fac.get_factory().get_building_type().get_output(), false};
19 parent->impl_get(state, payload);
20 bool is_set = any_cast<commodity_filter_query_data>(payload).filter;
21
22 if(is_set) {
23 command::change_factory_settings(state, state.local_player_nation, fac.get_factory(),
24 uint8_t(economy::factory_priority(state, fac.get_factory())), true);
25 }
26 }
27 }
28 }
29 }
30
31 void on_update(sys::state& state) noexcept override {
32 auto rules = state.world.nation_get_combined_issue_rules(state.local_player_nation);
33 disabled = (rules & issue_rule::can_subsidise) == 0;
34 color = sys::pack_color(255, 255, 255);
35 if(state.user_settings.color_blind_mode == sys::color_blind_mode::deutan || state.user_settings.color_blind_mode == sys::color_blind_mode::protan) {
36 color = sys::pack_color(114, 150, 77); //remap to yellow
37 } else if(state.user_settings.color_blind_mode == sys::color_blind_mode::achroma) {
38 color = sys::pack_color(128, 128, 128);
39 }
40 }
41
44 }
45
46 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
47 auto box = text::open_layout_box(contents, 0);
48 text::localised_format_box(state, contents, box, std::string_view("subsidize_all_tooltip"));
49 text::close_layout_box(contents, box);
50 }
51};
52
54public:
55 void button_action(sys::state& state) noexcept override {
56 if(!parent)
57 return;
58
59 for(auto p : state.world.nation_get_province_ownership(state.local_player_nation)) {
60 for(auto fac : p.get_province().get_factory_location()) {
61 if(fac.get_factory().get_subsidized()) {
62 Cyto::Any payload = commodity_filter_query_data{fac.get_factory().get_building_type().get_output(), false};
63 parent->impl_get(state, payload);
64 bool is_set = any_cast<commodity_filter_query_data>(payload).filter;
65
66 if(is_set) {
67 command::change_factory_settings(state, state.local_player_nation, fac.get_factory(),
68 uint8_t(economy::factory_priority(state, fac.get_factory())), false);
69 }
70 }
71 }
72 }
73 }
74
75 void on_update(sys::state& state) noexcept override {
76 auto rules = state.world.nation_get_combined_issue_rules(state.local_player_nation);
77 disabled = (rules & issue_rule::can_subsidise) == 0;
78 color = sys::pack_color(255, 255, 255);
79 if(state.user_settings.color_blind_mode == sys::color_blind_mode::deutan || state.user_settings.color_blind_mode == sys::color_blind_mode::protan) {
80 color = sys::pack_color(255, 100, 255); //remap to blue
81 } else if(state.user_settings.color_blind_mode == sys::color_blind_mode::achroma) {
82 color = sys::pack_color(196, 196, 196);
83 }
84 }
85
88 }
89
90 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
91 auto box = text::open_layout_box(contents, 0);
92 text::localised_format_box(state, contents, box, std::string_view("unsubsidize_all_tooltip"));
93 text::close_layout_box(contents, box);
94 }
95};
96
98public:
99 void on_create(sys::state& state) noexcept override {
101 set_visible(state, false);
102 }
103 void button_action(sys::state& state) noexcept override {
104
105 }
106
109 }
110
111 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
112 auto box = text::open_layout_box(contents, 0);
113 text::localised_format_box(state, contents, box, std::string_view("open_all_tooltip"));
114 text::close_layout_box(contents, box);
115 }
116};
117
119public:
120 void on_create(sys::state& state) noexcept override {
122 set_visible(state, false);
123 }
124 void button_action(sys::state& state) noexcept override {
125 }
126
129 }
130
131 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
132 auto box = text::open_layout_box(contents, 0);
133 text::localised_format_box(state, contents, box, std::string_view("close_all_tooltip"));
134 text::close_layout_box(contents, box);
135 }
136};
137
141
143public:
145
146 void button_action(sys::state& state) noexcept override {
147 if(parent) {
149 for(auto com : state.world.in_commodity) {
150 Cyto::Any payload = commodity_filter_query_data{ com.id, false };
151 parent->impl_get(state, payload);
152 bool is_set = any_cast<commodity_filter_query_data>(payload).filter;
153
154 if(!is_set) {
155 Cyto::Any payloadb = commodity_filter_toggle_data{ com.id };
156 parent->impl_get(state, payloadb);
157 }
158 }
159
162 }
164 for(auto com : state.world.in_commodity) {
165 Cyto::Any payload = commodity_filter_query_data{ com.id, false };
166 parent->impl_get(state, payload);
167 bool is_set = any_cast<commodity_filter_query_data>(payload).filter;
168
169 if(is_set) {
170 Cyto::Any payloadb = commodity_filter_toggle_data{ com.id };
171 parent->impl_get(state, payloadb);
172 }
173 }
174
177 }
178 }
179 }
180
183 }
184
185 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
187 auto box = text::open_layout_box(contents, 0);
188 text::localised_format_box(state, contents, box, std::string_view("production_select_all_tooltip"));
189 text::close_layout_box(contents, box);
190 }
192 auto box = text::open_layout_box(contents, 0);
193 text::localised_format_box(state, contents, box, std::string_view("production_deselect_all_tooltip"));
194 text::close_layout_box(contents, box);
195 }
196 }
197
198 void on_update(sys::state& state) noexcept override {
200 text::produce_simple_string(state, btn_state == factory_select_all_button_state::select_all ? "PRODUCTION_SELECT_ALL" : "PRODUCTION_DESELECT_ALL"));
201
202 }
203};
204
206public:
207 void button_action(sys::state& state) noexcept override {
208 if(parent) {
209 Cyto::Any payload = bool{};
210 parent->impl_get(state, payload);
211 auto content = any_cast<bool>(payload);
212
213 Cyto::Any payload2 = element_selection_wrapper<bool>{!content};
214 parent->impl_get(state, payload2);
215 }
216 }
217
220 }
221
222 void on_update(sys::state& state) noexcept override {
224 text::produce_simple_string(state, retrieve<bool>(state, parent) ? "production_hide_empty_states" : "production_show_empty_states"));
225
226 }
227
228 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
229 auto box = text::open_layout_box(contents, 0);
230 text::localised_format_box(state, contents, box, std::string_view("production_show_empty_tooltip"));
231 text::close_layout_box(contents, box);
232 }
233};
234
236 void button_action(sys::state& state) noexcept override {
237 if(parent) {
239 parent->impl_get(state, payload);
240 }
241 }
242};
243
245 void button_action(sys::state& state) noexcept override {
246 if(parent) {
248 parent->impl_get(state, payload);
249 }
250 }
251};
252
254 void button_action(sys::state& state) noexcept override {
255 if(parent) {
257 parent->impl_get(state, payload);
258 }
259 }
260};
261
263public:
264 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
265 if(name == "prod_subsidize_all") {
266 return make_element_by_type<factory_prod_subsidise_all_button>(state, id);
267
268 } else if(name == "prod_unsubsidize_all") {
269 return make_element_by_type<factory_prod_unsubsidise_all_button>(state, id);
270
271 } else if(name == "prod_open_all_factories") {
272 return make_element_by_type<factory_prod_open_all_button>(state, id);
273
274 } else if(name == "prod_close_all_factories") {
275 return make_element_by_type<factory_prod_close_all_button>(state, id);
276
277 } else if(name == "select_all") {
278 return make_element_by_type<factory_select_all_button>(state, id);
279
280 } else if(name == "deselect_all") {
281 return make_element_by_type<invisible_element>(state, id);
282
283 } else if(name == "show_empty_states") {
284 return make_element_by_type<factory_show_empty_states_button>(state, id);
285
286 } else if(name == "sort_by_name") {
287 return make_element_by_type<factory_name_sort>(state, id);
288
289 } else if(name == "sort_by_factories") {
290 return make_element_by_type<factory_count_sort>(state, id);
291
292 } else if(name == "sort_by_infra") {
293 return make_element_by_type<factory_infrastructure_sort>(state, id);
294
295 } else if(name == "filter_bounds") {
296 return make_element_by_type<commodity_filters_window>(state, id);
297
298 } else {
299 return nullptr;
300 }
301 }
302};
303
304} // namespace ui
void set_button_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
element_base * parent
virtual void impl_on_update(sys::state &state) noexcept
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
void set_visible(sys::state &state, bool vis)
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_create(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
factory_select_all_button_state btn_state
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
int32_t factory_priority(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1885
constexpr uint32_t can_subsidise
Definition: culture.hpp:13
uint32_t pack_color(float r, float g, float b)
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1823
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1904
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1831
tooltip_behavior
uchar uint8_t
Holds important data about the game world, state, and other data regarding windowing,...