Project Alice
Loading...
Searching...
No Matches
gui_unciv_reforms_window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "culture.hpp"
4#include "dcon_generated.hpp"
7#include "politics.hpp"
8#include "system_state.hpp"
9#include <cstdint>
10
11namespace ui {
12
13
14void reform_description(sys::state& state, text::columnar_layout& contents, dcon::reform_option_id ref) {
15 auto reform = fatten(state.world, ref);
16
17 {
18 auto box = text::open_layout_box(contents);
19 text::add_to_layout_box(state, contents, box, reform.get_name(), text::text_color::yellow);
20 text::close_layout_box(contents, box);
21 }
22 if(auto desc = reform.get_desc(); state.key_is_localized(desc)) {
26 text::add_to_substitution_map(sub, text::variable_type::capital, state.world.nation_get_capital(state.local_player_nation));
27 auto box = text::open_layout_box(contents);
28 text::add_to_layout_box(state, contents, box, desc, sub);
29 text::close_layout_box(contents, box);
30 }
31
32 float cost = 0.0f;
33 if(state.world.reform_get_reform_type(state.world.reform_option_get_parent_reform(ref)) == uint8_t(culture::issue_type::military)) {
34 float base_cost = float(state.world.reform_option_get_technology_cost(ref));
35 float reform_factor = politics::get_military_reform_multiplier(state, state.local_player_nation);
36 cost = base_cost * reform_factor;
37 } else {
38 float base_cost = float(state.world.reform_option_get_technology_cost(ref));
39 float reform_factor = politics::get_economic_reform_multiplier(state, state.local_player_nation);
40 cost = base_cost * reform_factor;
41 }
42
43 text::add_line(state, contents, "reform_research_cost", text::variable_type::cost, int64_t(cost + 0.99f));
45
46 auto mod_id = reform.get_modifier();
47 if(bool(mod_id)) {
48 modifier_description(state, contents, mod_id);
50 }
51
52 auto allow = reform.get_allow();
53 if(allow) {
54 // allow_reform_cond
55 text::add_line(state, contents, "allow_reform_cond");
56 trigger_description(state, contents, allow, trigger::to_generic(state.local_player_nation),
57 trigger::to_generic(state.local_player_nation), -1);
59 }
60
61 auto ext = reform.get_on_execute_trigger();
62 if(ext) {
63 text::add_line(state, contents, "reform_effect_if_desc");
64 trigger_description(state, contents, ext, trigger::to_generic(state.local_player_nation),
65 trigger::to_generic(state.local_player_nation), -1);
66 }
67 auto ex = reform.get_on_execute_effect();
68 if(ex) {
69 if(ext)
70 text::add_line(state, contents, "reform_effect_then_desc");
71 else
72 text::add_line(state, contents, "reform_effect_desc");
73
74 effect_description(state, contents, ex, trigger::to_generic(state.local_player_nation),
75 trigger::to_generic(state.local_player_nation), -1, uint32_t(state.current_date.value),
76 uint32_t((ref.index() << 2) ^ state.local_player_nation.index()));
78 }
79 reform_rules_description(state, contents, reform.get_rules());
80}
81
83public:
86 }
87
88 void on_update(sys::state& state) noexcept override {
89 auto nation_id = retrieve<dcon::nation_id>(state, parent);
91 }
92
93 void button_action(sys::state& state) noexcept override {
94 auto nation_id = retrieve<dcon::nation_id>(state, parent);
96 }
97};
98
100public:
103 }
104
105 void button_action(sys::state& state) noexcept override {
106 auto content = retrieve<dcon::reform_option_id>(state, parent);
107 command::enact_reform(state, state.local_player_nation, content);
108 }
109
112 }
113
114 void on_update(sys::state& state) noexcept override {
115 auto content = retrieve<dcon::reform_option_id>(state, parent);
116 disabled = !command::can_enact_reform(state, state.local_player_nation, content);
117 }
118
119 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
120 auto content = retrieve<dcon::reform_option_id>(state, parent);
121 reform_description(state, contents, content);
122 }
123};
124
125class unciv_reforms_option : public listbox_row_element_base<dcon::reform_option_id> {
126 image_element_base* selected_icon = nullptr;
127
128public:
129 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
130 if(name == "reform_name") {
131 return make_element_by_type<generic_name_text<dcon::reform_option_id>>(state, id);
132 } else if(name == "selected") {
133 auto ptr = make_element_by_type<image_element_base>(state, id);
134 selected_icon = ptr.get();
135 return ptr;
136 } else if(name == "reform_option") {
137 return make_element_by_type<unciv_reforms_reform_button>(state, id);
138 } else {
139 return nullptr;
140 }
141 }
142
143 void on_update(sys::state& state) noexcept override {
144 selected_icon->set_visible(state, politics::reform_is_selected(state, state.local_player_nation, content));
145 }
146};
147
148class unciv_reforms_listbox : public listbox_element_base<unciv_reforms_option, dcon::reform_option_id> {
149protected:
150 std::string_view get_row_element_name() override {
151 return "reform_option_window";
152 }
153
154public:
155 message_result set(sys::state& state, Cyto::Any& payload) noexcept override {
156 if(payload.holds_type<dcon::reform_id>()) {
157 auto reform_id = any_cast<dcon::reform_id>(payload);
158 row_contents.clear();
159 auto fat_id = dcon::fatten(state.world, reform_id);
160 for(auto& option : fat_id.get_options()) {
161 if(option) {
162 row_contents.push_back(option);
163 }
164 }
165 update(state);
167 }
169 }
170};
171
172
174public:
175 void on_create(sys::state& state) noexcept override {
176 base_data.position.y -= int16_t(7);
178 }
179 void on_update(sys::state& state) noexcept override {
180 auto content = retrieve<dcon::reform_id>(state, parent);
185 auto fat_id = dcon::fatten(state.world, content);
186 auto box = text::open_layout_box(container);
187 text::add_to_layout_box(state, container, box, fat_id.get_name(), text::substitution_map{});
188 text::close_layout_box(container, box);
189 }
190};
191
193 dcon::reform_id reform_id{};
194
195public:
196 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
197 if(name == "reform_name") {
198 return make_element_by_type<reform_name_text>(state, id);
199 } else {
200 return nullptr;
201 }
202 }
203
204 void on_create(sys::state& state) noexcept override {
206 auto reforms_listbox = std::make_unique<unciv_reforms_listbox>();
212 }
213
214 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
215 if(payload.holds_type<dcon::reform_id>()) {
216 payload.emplace<dcon::reform_id>(reform_id);
218 }
220 }
221
222 message_result set(sys::state& state, Cyto::Any& payload) noexcept override {
223 if(payload.holds_type<dcon::reform_id>()) {
224 reform_id = any_cast<dcon::reform_id>(payload);
226 }
228 }
229};
230
232public:
233 void on_create(sys::state& state) noexcept override {
235 set_visible(state, false);
236 }
237
238 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
239 if(name == "civ_progress") {
240 return make_element_by_type<nation_westernization_progress_bar>(state, id);
241 } else if(name == "westernize_button") {
242 return make_element_by_type<unciv_reforms_westernize_button>(state, id);
243 } else if(name == "research_points_val") {
244 return make_element_by_type<nation_research_points_text>(state, id);
245 } else if(auto reform_id = politics::get_reform_by_name(state, name); bool(reform_id)) {
246 auto ptr = make_element_by_type<unciv_reforms_reform_window>(state, id);
247 Cyto::Any payload = reform_id;
248 ptr->impl_set(state, payload);
249 return ptr;
250 } else if(name == "mil_plusminus_icon") {
251 return make_element_by_type<nation_military_reform_multiplier_icon>(state, id);
252 } else if(name == "eco_plusminus_icon") {
253 return make_element_by_type<nation_economic_reform_multiplier_icon>(state, id);
254 } else if(name == "eco_main_icon" || name == "mil_main_icon") {
255 auto ptr = make_element_by_type<image_element_base>(state, id);
256 ptr->frame -= 1;
257 return ptr;
258 } else {
259 return nullptr;
260 }
261 }
262};
263
264} // namespace ui
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
message_result set(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
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 button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
sound::audio_instance & get_click_sound(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
message_result set(sys::state &state, Cyto::Any &payload) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
sound::audio_instance & get_click_sound(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
bool can_civilize_nation(sys::state &state, dcon::nation_id source)
Definition: commands.cpp:1807
bool can_enact_reform(sys::state &state, dcon::nation_id source, dcon::reform_option_id r)
Definition: commands.cpp:1862
void enact_reform(sys::state &state, dcon::nation_id source, dcon::reform_option_id r)
Definition: commands.cpp:1854
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
float get_military_reform_multiplier(sys::state &state, dcon::nation_id n)
Definition: politics.cpp:263
float get_economic_reform_multiplier(sys::state &state, dcon::nation_id n)
Definition: politics.cpp:278
bool reform_is_selected(sys::state &state, dcon::nation_id nation, dcon::reform_option_id reform_option)
Definition: politics.cpp:97
dcon::reform_id get_reform_by_name(sys::state &state, std::string_view name)
Definition: politics.cpp:69
audio_instance & get_enact_sound(sys::state &state)
Definition: sound_nix.cpp:281
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
endless_layout create_endless_layout(sys::state &state, layout &dest, layout_parameters const &params)
Definition: text.cpp:1100
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
dcon::text_key get_adjective(sys::state &state, dcon::nation_id id)
Definition: text.cpp:890
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:794
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
void modifier_description(sys::state &state, text::layout_base &layout, dcon::modifier_id mid, int32_t indentation=0)
void reform_description(sys::state &state, text::columnar_layout &contents, dcon::issue_option_id ref)
void make_size_from_graphics(sys::state &state, ui::element_data &dat)
void effect_description(sys::state &state, text::layout_base &layout, dcon::effect_key k, int32_t primary_slot, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
tooltip_behavior
void trigger_description(sys::state &state, text::layout_base &layout, dcon::trigger_key k, int32_t primary_slot=-1, int32_t this_slot=-1, int32_t from_slot=-1)
message_result
void reform_rules_description(sys::state &state, text::columnar_layout &contents, uint32_t rules)
uint uint32_t
uchar uint8_t
union ui::element_data::internal_data data