Project Alice
Loading...
Searching...
No Matches
gui_message_settings_window.cpp
Go to the documentation of this file.
2
3namespace ui {
5 int32_t index = retrieve<int32_t>(state, parent);
6 auto const& messages = static_cast<ui::message_log_window*>(state.ui_state.msg_log_window)->messages;
7 if(index < int32_t(messages.size())) {
8 auto m = messages[index];
9 auto container = text::create_endless_layout(state, internal_layout,
10 text::layout_parameters{0, 0, base_data.size.x, base_data.size.y, base_data.data.button.font_handle, 0,
12
13 auto box = text::open_layout_box(container);
14 text::add_to_layout_box(state, container, box, text::embedded_flag{ state.world.nation_get_identity_from_identity_holder(m.source) });
15 text::add_space_to_layout_box(state, container, box);
16 if(m.target) {
17 text::add_to_layout_box(state, container, box, text::embedded_flag{ state.world.nation_get_identity_from_identity_holder(m.target) });
18 text::add_space_to_layout_box(state, container, box);
19 }
20 text::add_to_layout_box(state, container, box, std::string_view{ ":" });
21 text::add_space_to_layout_box(state, container, box);
22 text::localised_format_box(state, container, box, m.title);
23 text::close_layout_box(container, box);
24 }
25}
26
27void message_log_text::update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept {
28 int32_t index = retrieve<int32_t>(state, parent);
29 auto const& messages = static_cast<ui::message_log_window*>(state.ui_state.msg_log_window)->messages;
30 if(index < int32_t(messages.size())) {
31 messages[index].body(state, contents);
32 }
33}
34
37 cat_filters.resize(size_t(message_settings_category::count));
38}
39
40std::unique_ptr<element_base> message_log_window::make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept {
41 if(name == "close" || name == "closebutton") {
42 return make_element_by_type<message_log_close_button>(state, id);
43 } else if(name == "messagelog") {
44 auto ptr = make_element_by_type<message_log_listbox>(state, id);
45 log_list = ptr.get();
46 return ptr;
47 } else if(name == "messagecat_combat") {
48 return make_element_by_type<message_log_filter_checkbox<message_settings_category::combat>>(state, id);
49 } else if(name == "messagecat_diplomacy") {
50 return make_element_by_type<message_log_filter_checkbox<message_settings_category::diplomacy>>(state, id);
51 } else if(name == "messagecat_units") {
52 return make_element_by_type<message_log_filter_checkbox<message_settings_category::units>>(state, id);
53 } else if(name == "messagecat_provinces") {
54 return make_element_by_type<message_log_filter_checkbox<message_settings_category::provinces>>(state, id);
55 } else if(name == "messagecat_events") {
56 return make_element_by_type<message_log_filter_checkbox<message_settings_category::events>>(state, id);
57 } else if(name == "messagecat_others") {
58 return make_element_by_type<message_log_filter_checkbox<message_settings_category::others>>(state, id);
59 } else {
60 return nullptr;
61 }
62}
63
65
66 if(auto ex_size = int32_t(messages.size()) - 100; ex_size > 0) {
67 std::rotate(messages.begin(), messages.begin() + ex_size, messages.end());
68 messages.resize(100);
69 }
70
71 bool at_bottom = log_list->list_scrollbar->raw_value() == log_list->list_scrollbar->settings.upper_limit;
72
73 log_list->row_contents.clear();
74 for(int32_t i = 0; i < int32_t(messages.size()); ++i)
75 log_list->row_contents.push_back(i);
76
77 log_list->update(state);
78
79 if(at_bottom)
80 log_list->scroll_to_bottom(state);
81}
82
84 if(payload.holds_type<message_settings_category>()) {
85 auto cat = any_cast<message_settings_category>(payload);
86 payload.emplace<bool>(cat_filters[uint8_t(cat)]);
88 } else if(payload.holds_type<element_selection_wrapper<message_settings_category>>()) {
89 auto cat = any_cast<element_selection_wrapper<message_settings_category>>(payload).data;
90 cat_filters[uint8_t(cat)] = !cat_filters[uint8_t(cat)];
91 impl_on_update(state);
93 }
95}
96} // namespace ui
void on_update(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) 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 on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
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
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_space_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1788
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
message_result
uchar uint8_t
element_base * msg_log_window