Project Alice
Loading...
Searching...
No Matches
gui_commodity_filters_window.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace ui {
7
9 dcon::commodity_id cid;
10 bool filter;
11};
12struct commodity_filter_toggle_data : public element_selection_wrapper<dcon::commodity_id> { };
13
15public:
16 void button_action(sys::state& state) noexcept override {
17 if(parent) {
18 auto cid = retrieve<dcon::commodity_id>(state, parent);
20 parent->impl_get(state, f_payload);
21 }
22 }
23
26 }
27
28 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
29 auto box = text::open_layout_box(contents, 0);
30 auto content = retrieve<dcon::commodity_id>(state, parent); // Runtime Error >w<
31 text::localised_single_sub_box(state, contents, box, std::string_view("production_toggle_filter_tooltip"),
33 text::close_layout_box(contents, box);
34 }
35};
36
38public:
39 void on_update(sys::state& state) noexcept override {
40 if(parent) {
41 auto cid = retrieve<dcon::commodity_id>(state, parent);
42 Cyto::Any f_payload = commodity_filter_query_data{cid, false};
43 parent->impl_get(state, f_payload);
44 auto content = any_cast<commodity_filter_query_data>(f_payload);
45 frame = content.filter ? 1 : 0; // Enabled=1, Disabled=0
46 }
47 }
48};
49
51public:
52 dcon::commodity_id content{};
53
54 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
55 if(name == "filter_button") {
56 return make_element_by_type<commodity_filter_button>(state, id);
57 } else if(name == "filter_enabled") {
58 return make_element_by_type<commodity_filter_enabled_image>(state, id);
59 } else if(name == "goods_type") {
60 return make_element_by_type<commodity_image>(state, id);
61 } else {
62 return nullptr;
63 }
64 }
65
66 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
67 if(payload.holds_type<dcon::commodity_id>()) {
68 payload.emplace<dcon::commodity_id>(content);
70 }
72 }
73};
74
76public:
77 void on_create(sys::state& state) noexcept override {
79
80 int16_t index = 0;
81 state.world.for_each_commodity([&](dcon::commodity_id cid) {
82
83 bool can_be_produced = false;
84 state.world.for_each_factory_type([&](dcon::factory_type_id ftid) {
85 can_be_produced = can_be_produced || state.world.factory_type_get_output(ftid) == cid;
86 });
87 if(!can_be_produced)
88 return;
89
90
91 auto ptr = make_element_by_type<commodity_filter_item>(state, "goods_filter_template");
92 static_cast<commodity_filter_item*>(ptr.get())->content = cid;
93
94 int16_t rowlimiter = index - (24 * (index / 24));
95 if(rowlimiter == 0) {
96 ptr->base_data.position.x = int16_t(33 * rowlimiter);
97 } else {
98 ptr->base_data.position.x = int16_t((33 * rowlimiter) - (rowlimiter * 2));
99 }
100 ptr->base_data.position.y = int16_t(30 * (index / 24));
101 add_child_to_back(std::move(ptr));
102 index++;
103 });
104 }
105};
106
107} // namespace ui
dcon::text_key get_name() noexcept
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
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 add_child_to_back(std::unique_ptr< element_base > child) noexcept final
element_base * parent
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
void on_create(sys::state &state) noexcept override
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
void localised_single_sub_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, variable_type subkey, substitution value)
Definition: text.cpp:1888
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
tooltip_behavior
message_result