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
139public:
140 void button_action(sys::state& state) noexcept override {
141 if(parent) {
142 for(auto com : state.world.in_commodity) {
143 Cyto::Any payload = commodity_filter_query_data{com.id, false};
144 parent->impl_get(state, payload);
145 bool is_set = any_cast<commodity_filter_query_data>(payload).filter;
146
147 if(!is_set) {
148 Cyto::Any payloadb = commodity_filter_toggle_data{com.id};
149 parent->impl_get(state, payloadb);
150 }
151 }
152 }
153 }
154
157 }
158
159 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
160 auto box = text::open_layout_box(contents, 0);
161 text::localised_format_box(state, contents, box, std::string_view("production_select_all_tooltip"));
162 text::close_layout_box(contents, box);
163 }
164};
165
167public:
168 void button_action(sys::state& state) noexcept override {
169 if(parent) {
170 for(auto com : state.world.in_commodity) {
171 Cyto::Any payload = commodity_filter_query_data{com.id, false};
172 parent->impl_get(state, payload);
173 bool is_set = any_cast<commodity_filter_query_data>(payload).filter;
174
175 if(is_set) {
176 Cyto::Any payloadb = commodity_filter_toggle_data{com.id};
177 parent->impl_get(state, payloadb);
178 }
179 }
180 }
181 }
182
185 }
186
187 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
188 auto box = text::open_layout_box(contents, 0);
189 text::localised_format_box(state, contents, box, std::string_view("production_deselect_all_tooltip"));
190 text::close_layout_box(contents, box);
191 }
192};
193
195public:
196 void button_action(sys::state& state) noexcept override {
197 if(parent) {
198 Cyto::Any payload = bool{};
199 parent->impl_get(state, payload);
200 auto content = any_cast<bool>(payload);
201
202 Cyto::Any payload2 = element_selection_wrapper<bool>{!content};
203 parent->impl_get(state, payload2);
204 }
205 }
206
209 }
210
211 void on_update(sys::state& state) noexcept override {
213 text::produce_simple_string(state, retrieve<bool>(state, parent) ? "production_hide_empty_states" : "production_show_empty_states"));
214
215 }
216
217 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
218 auto box = text::open_layout_box(contents, 0);
219 text::localised_format_box(state, contents, box, std::string_view("production_show_empty_tooltip"));
220 text::close_layout_box(contents, box);
221 }
222};
223
225 void button_action(sys::state& state) noexcept override {
226 if(parent) {
228 parent->impl_get(state, payload);
229 }
230 }
231};
232
234 void button_action(sys::state& state) noexcept override {
235 if(parent) {
237 parent->impl_get(state, payload);
238 }
239 }
240};
241
243 void button_action(sys::state& state) noexcept override {
244 if(parent) {
246 parent->impl_get(state, payload);
247 }
248 }
249};
250
252public:
253 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
254 if(name == "prod_subsidize_all") {
255 return make_element_by_type<factory_prod_subsidise_all_button>(state, id);
256
257 } else if(name == "prod_unsubsidize_all") {
258 return make_element_by_type<factory_prod_unsubsidise_all_button>(state, id);
259
260 } else if(name == "prod_open_all_factories") {
261 return make_element_by_type<factory_prod_open_all_button>(state, id);
262
263 } else if(name == "prod_close_all_factories") {
264 return make_element_by_type<factory_prod_close_all_button>(state, id);
265
266 } else if(name == "select_all") {
267 return make_element_by_type<factory_select_all_button>(state, id);
268
269 } else if(name == "deselect_all") {
270 return make_element_by_type<factory_deselect_all_button>(state, id);
271
272 } else if(name == "show_empty_states") {
273 return make_element_by_type<factory_show_empty_states_button>(state, id);
274
275 } else if(name == "sort_by_name") {
276 return make_element_by_type<factory_name_sort>(state, id);
277
278 } else if(name == "sort_by_factories") {
279 return make_element_by_type<factory_count_sort>(state, id);
280
281 } else if(name == "sort_by_infra") {
282 return make_element_by_type<factory_infrastructure_sort>(state, id);
283
284 } else if(name == "filter_bounds") {
285 return make_element_by_type<commodity_filters_window>(state, id);
286
287 } else {
288 return nullptr;
289 }
290 }
291};
292
293} // 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
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
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
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
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:1003
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:1799
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:1880
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:1807
tooltip_behavior
uchar uint8_t