Project Alice
Loading...
Searching...
No Matches
gui_state_select.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "demographics.hpp"
5#include "system_state.hpp"
6#include "text.hpp"
7#include <vector>
8
9namespace ui {
10
12public:
13 void on_update(sys::state& state) noexcept override {
14 set_text(state, text::produce_simple_string(state, "alice_state_select_title"));
15 }
16};
17
19public:
20 void on_update(sys::state& state) noexcept override {
21 auto content = retrieve<dcon::state_definition_id>(state, parent);
22 set_button_text(state, text::produce_simple_string(state, state.world.state_definition_get_name(content)));
23 //auto it = std::find(state.selected_states.begin(), state.selected_states.end(), content);
24 //disabled = (it != state.selected_states.end());
25 }
26 void button_action(sys::state& state) noexcept override {
27 auto content = retrieve<dcon::state_definition_id>(state, parent);
28 state.state_select(content);
29 }
30};
31
32class map_state_select_entry : public listbox_row_element_base<dcon::state_definition_id> {
33public:
34 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
35 if(name == "button") {
36 return make_element_by_type<map_state_select_button>(state, id);
37 } else {
38 return nullptr;
39 }
40 }
41
42 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
43 if(payload.holds_type<dcon::nation_id>()) {
44 auto memb = state.world.state_definition_get_abstract_state_membership(content);
45 if(memb.begin() == memb.end()) {
46 payload.emplace<dcon::nation_id>(state.world.national_identity_get_nation_from_identity_holder(state.national_definitions.rebel_id));
48 }
49 auto n = (*(memb.begin())).get_province().get_state_membership().get_capital().get_province_control().get_nation();
50 payload.emplace<dcon::nation_id>(n);
52 }
53 return listbox_row_element_base::get(state, payload);
54 }
55};
56
57class map_state_select_listbox : public listbox_element_base<map_state_select_entry, dcon::state_definition_id> {
58protected:
59 std::string_view get_row_element_name() override {
60 return "alice_select_legend_entry";
61 }
62public:
63 void on_update(sys::state& state) noexcept override {
64 row_contents.clear();
65 assert(state.state_selection.has_value());
66 row_contents = state.state_selection->selectable_states;
68 }
69};
70
72public:
73 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
74 if(name == "legend_title") {
75 return make_element_by_type<map_state_select_title>(state, id);
76 } else if(name == "selectable") {
77 return make_element_by_type<map_state_select_listbox>(state, id);
78 } else {
79 return nullptr;
80 }
81 }
82};
83
84} //namespace ui
void set_button_text(sys::state &state, std::string const &new_text)
element_base * parent
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
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_update(sys::state &state) noexcept override
std::string_view get_row_element_name() 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
void set_text(sys::state &state, std::string const &new_text)
#define assert(condition)
Definition: debug.h:74
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
message_result