Project Alice
Loading...
Searching...
No Matches
gui_diplomacy_request_window.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace ui {
8
9template<bool Left>
11public:
12 void on_create(sys::state& state) noexcept override {
14 frame = Left ? 0 : 1;
15 }
16
17 void button_action(sys::state& state) noexcept override {
19 }
20};
21
23 int dummy = 0;
24};
25template<bool B>
27public:
28 void button_action(sys::state& state) noexcept override {
29 diplomatic_message::message m = retrieve<diplomatic_message::message>(state, parent);
30 command::respond_to_diplomatic_message(state, state.local_player_nation, m.from, m.type, B);
32 }
33};
34
36public:
37 std::string get_text(sys::state& state, diplomatic_message::message const& diplomacy_request) {
38 switch(diplomacy_request.type) {
40 return std::string("???");
42 return text::produce_simple_string(state, "askmilitaryaccess_di");
44 return text::produce_simple_string(state, "alliance_di");
46 return text::produce_simple_string(state, "callally_di");
48 return text::produce_simple_string(state, "back_crisis_di");
50 return text::produce_simple_string(state, "back_crisis_di");
52 return text::produce_simple_string(state, "peace_di");
54 return text::produce_simple_string(state, "back_crisis_di");
56 return text::produce_simple_string(state, "crisis_offer_di");
58 return text::produce_simple_string(state, "state_transfer_di");
59 default:
60 return std::string("???");
61 }
62 }
63 void on_update(sys::state& state) noexcept override {
64 auto diplomacy_request = retrieve< diplomatic_message::message>(state, parent);
65 set_text(state, get_text(state, diplomacy_request));
66 }
67};
68
70 void populate_layout(sys::state& state, text::endless_layout& contents, diplomatic_message::message diplomacy_request) noexcept {
71 switch(diplomacy_request.type) {
73 break;
75 text::add_line(state, contents, "askmilitaryaccess_offer", text::variable_type::actor, diplomacy_request.from);
76 break;
78 text::add_line(state, contents, "alliance_offer", text::variable_type::actor, diplomacy_request.from);
79 break;
81 {
82 auto war = dcon::fatten(state.world, diplomacy_request.data.war);
83 dcon::nation_id primary_attacker = state.world.war_get_primary_attacker(war);
84 dcon::nation_id primary_defender = state.world.war_get_primary_defender(war);
92 auto war_name = text::resolve_string_substitution(state, state.world.war_get_name(war), wsub);
93
94 auto box = text::open_layout_box(contents);
97 text::add_to_substitution_map(sub, text::variable_type::list, std::string_view(war_name.c_str()));
98 text::localised_format_box(state, contents, box, std::string_view("callally_offer"), sub);
99 text::close_layout_box(contents, box);
100
101 break;
102 }
104 text::add_line(state, contents, "back_crisis_offer", text::variable_type::actor, diplomacy_request.from);
105 break;
107 text::add_line(state, contents, "back_crisis_offer", text::variable_type::actor, diplomacy_request.from);
108 break;
110 {
111 text::add_line(state, contents, "peaceofferdesc", text::variable_type::country, state.world.peace_offer_get_nation_from_pending_peace_offer(diplomacy_request.data.peace));
112
113 bool is_wp = true;
114 state.world.peace_offer_for_each_peace_offer_item_as_peace_offer(diplomacy_request.data.peace, [&state, &contents, &is_wp](dcon::peace_offer_item_id poiid) {
115 dcon::wargoal_id wg = state.world.peace_offer_item_get_wargoal(poiid);
116 dcon::cb_type_id cbt = state.world.wargoal_get_type(wg);
117
118 text::substitution_map sub;
119 text::add_to_substitution_map(sub, text::variable_type::recipient, state.world.wargoal_get_target_nation(wg));
120 text::add_to_substitution_map(sub, text::variable_type::from, state.world.wargoal_get_added_by(wg));
121 text::add_to_substitution_map(sub, text::variable_type::actor, state.world.wargoal_get_added_by(wg));
122 if(state.world.wargoal_get_secondary_nation(wg))
123 text::add_to_substitution_map(sub, text::variable_type::third, state.world.wargoal_get_secondary_nation(wg));
124 else if(state.world.wargoal_get_associated_tag(wg))
125 text::add_to_substitution_map(sub, text::variable_type::third, state.world.wargoal_get_associated_tag(wg));
126 text::add_to_substitution_map(sub, text::variable_type::state, state.world.wargoal_get_associated_state(wg));
127
128 auto box = text::open_layout_box(contents);
129 text::add_to_layout_box(state, contents, box, state.world.cb_type_get_shortest_desc(cbt), sub);
130 text::close_layout_box(contents, box);
131
132 is_wp = false;
133 });
134 if(is_wp) {
135 text::add_line(state, contents, "peace_whitepeace");
136 }
137 break;
138 }
140 text::add_line(state, contents, "alice_join_crisis_offer", text::variable_type::actor, diplomacy_request.from);
141 {
142 dcon::cb_type_id cbt = diplomacy_request.data.crisis_offer.wargoal_type;
143
147 if(diplomacy_request.data.crisis_offer.wargoal_secondary_nation)
149 else if(diplomacy_request.data.crisis_offer.wargoal_tag)
152
153 auto box = text::open_layout_box(contents);
154 text::add_to_layout_box(state, contents, box, state.world.cb_type_get_shortest_desc(cbt), sub);
155 text::close_layout_box(contents, box);
156
157 }
158 break;
160 {
161 auto is_concession = state.world.peace_offer_get_is_concession(diplomacy_request.data.peace);
162 if(is_concession) {
163 text::add_line(state, contents, "crisisofferdesc", text::variable_type::country, diplomacy_request.from);
164 } else {
165 text::add_line(state, contents, "crisisdemanddesc", text::variable_type::country, diplomacy_request.from);
166 }
167 bool is_wp = true;
168 state.world.peace_offer_for_each_peace_offer_item_as_peace_offer(diplomacy_request.data.peace, [&state, &contents, &is_wp](dcon::peace_offer_item_id poiid) {
169 dcon::wargoal_id wg = state.world.peace_offer_item_get_wargoal(poiid);
170 dcon::cb_type_id cbt = state.world.wargoal_get_type(wg);
171
172 text::substitution_map sub;
173 text::add_to_substitution_map(sub, text::variable_type::recipient, state.world.wargoal_get_target_nation(wg));
174 text::add_to_substitution_map(sub, text::variable_type::from, state.world.wargoal_get_added_by(wg));
175 text::add_to_substitution_map(sub, text::variable_type::actor, state.world.wargoal_get_added_by(wg));
176 if(state.world.wargoal_get_secondary_nation(wg))
177 text::add_to_substitution_map(sub, text::variable_type::third, state.world.wargoal_get_secondary_nation(wg));
178 else if(state.world.wargoal_get_associated_tag(wg))
179 text::add_to_substitution_map(sub, text::variable_type::third, state.world.wargoal_get_associated_tag(wg));
180 text::add_to_substitution_map(sub, text::variable_type::state, state.world.wargoal_get_associated_state(wg));
181
182 auto box = text::open_layout_box(contents);
183 text::add_to_layout_box(state, contents, box, state.world.cb_type_get_shortest_desc(cbt), sub);
184 text::close_layout_box(contents, box);
185
186 is_wp = false;
187 });
188 if(is_wp) {
189 text::add_line(state, contents, "peace_whitepeace");
190 }
191 } break;
193 {
194 text::add_line(state, contents, "state_transfer_offer", text::variable_type::actor, diplomacy_request.from);
195 auto box = text::open_layout_box(contents);
196 text::add_to_layout_box(state, contents, box, diplomacy_request.data.state);
197 text::close_layout_box(contents, box);
198 }
199 break;
200 default:
201 break;
202 }
203 }
204public:
205 void on_create(sys::state& state) noexcept override {
206 base_data.size.y = int16_t(150);
208 }
209 void on_update(sys::state& state) noexcept override {
211 switch(base_data.data.text.get_alignment()) {
214 break;
217 break;
218 default:
219 break;
220 }
221 auto border = base_data.data.text.border_size;
222
223 auto content = retrieve<diplomatic_message::message>(state, parent);
225 auto container = text::create_endless_layout(state,
228 border.x,
229 border.y,
230 int16_t(base_data.size.x - border.x * 2),
231 int16_t(base_data.size.y - border.y * 2),
232 base_data.data.text.font_handle,
233 0,
234 align,
235 color,
236 false });
237 populate_layout(state, container, content);
238 }
239};
240
242public:
243 void on_create(sys::state& state) noexcept override {
245 black_text = false;
246 }
247};
248
250public:
251 void on_create(sys::state& state) noexcept override {
252 base_data.position.y -= 6;
253 base_data.size.y += 32;
254
255 base_data.position.x += 8;
256 base_data.size.x -= 16;
257 }
258
259 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
260 dcon::gfx_object_id gid;
265 }
266 if(gid && flag_texture_handle > 0) {
267 auto const& gfx_def = state.ui_defs.gfx[gid];
268 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
269 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
271 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle, base_data.get_rotation(),
272 gfx_def.is_vertically_flipped(), false);
273 }
275 }
276};
277
279public:
280 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
281 auto fat_id = dcon::fatten(state.world, state.local_player_nation);
282 return fat_id.get_identity_from_identity_holder();
283 }
284};
285
287 simple_text_element_base* count_text = nullptr;
288 int32_t index = 0;
289
290public:
291 std::vector<diplomatic_message::message> messages;
292
293 void on_create(sys::state& state) noexcept override {
295 xy_pair cur_pos{0, 0};
296 {
297 auto ptr = make_element_by_type<diplomacy_request_lr_button<false>>(state,
298 state.ui_state.defs_by_name.find(state.lookup_key("alice_left_right_button"))->second.definition);
299 cur_pos.x = base_data.size.x - (ptr->base_data.size.x * 2);
300 cur_pos.y = ptr->base_data.size.y * 1;
301 ptr->base_data.position = cur_pos;
302 add_child_to_front(std::move(ptr));
303 }
304 {
305 auto ptr = make_element_by_type<diplomacy_request_count_text>(state,
306 state.ui_state.defs_by_name.find(state.lookup_key("alice_page_count"))->second.definition);
307 cur_pos.x -= ptr->base_data.size.x;
308 ptr->base_data.position = cur_pos;
309 count_text = ptr.get();
310 add_child_to_front(std::move(ptr));
311 }
312 {
313 auto ptr = make_element_by_type<diplomacy_request_lr_button<true>>(state,
314 state.ui_state.defs_by_name.find(state.lookup_key("alice_left_right_button"))->second.definition);
315 cur_pos.x -= ptr->base_data.size.x;
316 ptr->base_data.position = cur_pos;
317 add_child_to_front(std::move(ptr));
318 }
319 set_visible(state, false);
320 }
321
322 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
323 if(name == "title") {
324 return make_element_by_type<diplomacy_request_title_text>(state, id);
325 } else if(name == "description") {
326 return make_element_by_type<diplomacy_request_desc_text>(state, id);
327 } else if(name == "agreebutton") {
328 return make_element_by_type<diplomacy_request_reply_button<true>>(state, id);
329 } else if(name == "declinebutton") {
330 return make_element_by_type<diplomacy_request_reply_button<false>>(state, id);
331 } else if(name == "leftshield") {
332 return make_element_by_type<diplomacy_request_player_flag_button>(state, id);
333 } else if(name == "rightshield") {
334 return make_element_by_type<diplomacy_request_flag_button>(state, id);
335 } else if(name == "background") {
336 auto ptr = make_element_by_type<draggable_target>(state, id);
337 ptr->base_data.size = base_data.size;
338 return ptr;
339 } else {
340 return nullptr;
341 }
342 }
343
344 void on_update(sys::state& state) noexcept override {
345 auto it = std::remove_if(messages.begin(), messages.end(), [&](auto& m) {
346 return m.when + diplomatic_message::expiration_in_days <= state.current_date
347 || !diplomatic_message::can_accept(state, m);
348 });
349 messages.erase(it, messages.end());
350
351 if(messages.empty()) {
352 set_visible(state, false);
353 }
354
355 count_text->set_text(state, std::to_string(int32_t(index + 1)) + "/" + std::to_string(int32_t(messages.size())));
356 }
357 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
358 if(messages.empty()) {
359 index = 0;
360 } else {
361 if(index >= int32_t(messages.size()))
362 index = 0;
363 else if(index < 0)
364 index = int32_t(messages.size()) - 1;
365 }
366
367 if(payload.holds_type<dcon::nation_id>()) {
368 if(messages.empty()) {
369 payload.emplace<dcon::nation_id>(dcon::nation_id{});
370 } else {
371 payload.emplace<dcon::nation_id>(messages[index].from);
372 }
374 } else if(payload.holds_type<element_selection_wrapper<bool>>()) {
375 bool b = any_cast<element_selection_wrapper<bool>>(payload).data;
376 index += b ? -1 : +1;
379 } else if(payload.holds_type<diplomatic_message::message>()) {
380 if(messages.empty()) {
382 } else {
383 payload.emplace<diplomatic_message::message>(messages[index]);
384 }
386 } else if(payload.holds_type<diplomacy_reply_taken_notification>()) {
387 if(!messages.empty()) {
388 messages.erase(messages.begin() + size_t(index));
390 }
392 }
393 return window_element_base::get(state, payload);
394 }
395};
396
397} // namespace ui
void on_create(sys::state &state) noexcept override
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
void impl_on_update(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
void on_create(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string get_text(sys::state &state, diplomatic_message::message const &diplomacy_request)
message_result get(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
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::vector< diplomatic_message::message > messages
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 render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_create(sys::state &state) noexcept override
multiline_text_element_base * delegate
void on_create(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
#define B(name, bit)
Definition: cpu.h:216
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
void render_masked_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, GLuint mask_texture_handle, ui::rotation r, bool flipped, bool rtl)
GLuint get_texture_handle(sys::state &state, dcon::texture_id id, bool keep_data)
Definition: texture.cpp:577
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
Definition: text.cpp:2113
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
alignment
Definition: text.hpp:36
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
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_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
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
void send(sys::state &state, element_base *parent, T value)
message_result
ogl::color_modification get_color_modification(bool is_under_mouse, bool is_disabled, bool is_interactable)
union diplomatic_message::message::dtype data
dcon::national_identity_id wargoal_tag
dcon::state_definition_id wargoal_state
dcon::nation_id wargoal_secondary_nation
dcon::cb_type_id wargoal_type
dcon::gfx_object_id button_image
element_type get_element_type() const
rotation get_rotation() const
union ui::element_data::internal_data data
dcon::gfx_object_id gfx_object
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
element_base * under_mouse
alignment get_alignment() const
xy_pair border_size