Project Alice
Loading...
Searching...
No Matches
gui_message_window.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "notifications.hpp"
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};
25
27public:
28 void button_action(sys::state& state) noexcept override {
30 }
31};
32
34public:
35 void on_create(sys::state& state) noexcept override {
37 black_text = false;
38 }
39};
40
41
43 virtual void populate_layout(sys::state& state, text::endless_layout& contents) noexcept override {
44 auto msg = retrieve< notification::message*>(state, parent);
45 if(msg) {
46 msg->body(state, contents);
47 }
48 }
49};
50
52protected:
55public:
56 void on_create(sys::state& state) noexcept override;
57 message_result get(sys::state& state, Cyto::Any& payload) noexcept override;
58 void on_update(sys::state& state) noexcept override;
59 message_result on_scroll(sys::state& state, int32_t x, int32_t y, float amount, sys::key_modifiers mods) noexcept override;
60 message_result test_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
62 }
63};
64
65
67 base_data.size.x = 500 - (base_data.position.x * 2) - 8;
68 base_data.size.y = 18 * 6;
69
70 auto res = std::make_unique<message_body_text_internal>();
71 std::memcpy(&(res->base_data), &(base_data), sizeof(ui::element_data));
72 make_size_from_graphics(state, res->base_data);
73 res->base_data.data.text_common.font_handle = text::name_into_font_id(state, "garamond_16");
74 res->base_data.position.x = 0;
75 res->base_data.position.y = 0;
76 res->on_create(state);
77 delegate = res.get();
78 add_child_to_front(std::move(res));
79
80 auto ptr = make_element_by_type<multiline_text_scrollbar>(state, "standardlistbox_slider");
81 text_scrollbar = static_cast<multiline_text_scrollbar*>(ptr.get());
82 add_child_to_front(std::move(ptr));
83 text_scrollbar->scale_to_parent();
84}
85
87 if(delegate->internal_layout.number_of_lines > delegate->visible_lines) {
88 text_scrollbar->set_visible(state, true);
89 text_scrollbar->change_settings(state,
90 mutable_scrollbar_settings{ 0, delegate->internal_layout.number_of_lines - delegate->visible_lines, 0, 0, false });
91 } else {
92 text_scrollbar->set_visible(state, false);
93 delegate->current_line = 0;
94 }
95}
96
97message_result message_body_text::on_scroll(sys::state& state, int32_t x, int32_t y, float amount, sys::key_modifiers mods) noexcept {
98 if(delegate->internal_layout.number_of_lines > delegate->visible_lines) {
99 text_scrollbar->update_scaled_value(state, text_scrollbar->scaled_value() + std::clamp(-amount, -1.f, 1.f));
100 delegate->current_line = int32_t(text_scrollbar->scaled_value());
102 } else {
104 }
105}
106
108 if(payload.holds_type<multiline_text_scroll_event>()) {
109 auto event = any_cast<multiline_text_scroll_event>(payload);
110 delegate->current_line = event.new_value;
112 } else {
114 }
115}
116
118public:
119 void on_create(sys::state& state) noexcept override {
120 base_data.position.y -= 6;
121 base_data.size.y += 32;
122
123 base_data.position.x += 8;
124 base_data.size.x -= 16;
125 }
126
127 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
128 dcon::gfx_object_id gid;
133 }
134 if(gid && flag_texture_handle > 0) {
135 auto& gfx_def = state.ui_defs.gfx[gid];
136 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
137 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
139 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle, base_data.get_rotation(),
140 gfx_def.is_vertically_flipped(),
141 false);
142 }
144 }
145};
146
148 simple_text_element_base* count_text = nullptr;
149 int32_t index = 0;
150 int32_t prev_size = 0;
151
152 simple_text_element_base* title_text = nullptr;
153 message_body_text* desc_text = nullptr;
154
155public:
156 std::vector<notification::message> messages;
157
158 void on_create(sys::state& state) noexcept override {
160 xy_pair cur_pos{0, 0};
161 {
162 auto ptr = make_element_by_type<message_lr_button<false>>(state,
163 state.ui_state.defs_by_name.find(state.lookup_key("alice_left_right_button"))->second.definition);
164 cur_pos.x = base_data.size.x - (ptr->base_data.size.x * 2);
165 cur_pos.y = ptr->base_data.size.y * 1;
166 ptr->base_data.position = cur_pos;
167 add_child_to_front(std::move(ptr));
168 }
169 {
170 auto ptr = make_element_by_type<message_count_text>(state,
171 state.ui_state.defs_by_name.find(state.lookup_key("alice_page_count"))->second.definition);
172 cur_pos.x -= ptr->base_data.size.x;
173 ptr->base_data.position = cur_pos;
174 count_text = ptr.get();
175 add_child_to_front(std::move(ptr));
176 }
177 {
178 auto ptr = make_element_by_type<message_lr_button<true>>(state,
179 state.ui_state.defs_by_name.find(state.lookup_key("alice_left_right_button"))->second.definition);
180 cur_pos.x -= ptr->base_data.size.x;
181 ptr->base_data.position = cur_pos;
182 add_child_to_front(std::move(ptr));
183 }
184 set_visible(state, false);
185 }
186
187 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
188 if(name == "header") {
189 return make_element_by_type<invisible_element>(state, id);
190 } else if(name == "line1") {
191 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
192 ptr->base_data.size.x = base_data.size.x - (ptr->base_data.position.x * 2);
193 ptr->base_data.size.y = 22;
194 title_text = ptr.get();
195 return ptr;
196 } else if(name == "line3") {
197 auto ptr = make_element_by_type<message_body_text>(state, id);
198 desc_text = ptr.get();
199 return ptr;
200 } else if(name.substr(0, 4) == "line") {
201 return make_element_by_type<invisible_element>(state, id);
202 } else if(name == "agreebutton") {
203 return make_element_by_type<invisible_element>(state, id);
204 } else if(name == "declinebutton") {
205 return make_element_by_type<invisible_element>(state, id);
206 } else if(name == "centerok") {
207 return make_element_by_type<message_dismiss_button>(state, id);
208 } else if(name == "leftshield") {
209 return make_element_by_type<message_flag_button>(state, id);
210 } else if(name == "rightshield") {
211 return make_element_by_type<message_flag_button>(state, id);
212 } else if(name == "background") {
213 auto ptr = make_element_by_type<draggable_target>(state, id);
214 ptr->base_data.size = base_data.size;
215 return ptr;
216 } else {
217 return nullptr;
218 }
219 }
220
221 void on_update(sys::state& state) noexcept override {
222 if(messages.empty()) {
223 state.ui_pause.store(false, std::memory_order_release);
224 set_visible(state, false);
225 } else {
226 if(int32_t(messages.size()) > prev_size) {
227 index = int32_t(messages.size()) - 1;
228 } else {
229 if(index >= int32_t(messages.size()))
230 index = 0;
231 else if(index < 0)
232 index = int32_t(messages.size()) - 1;
233 }
234 prev_size = int32_t(messages.size());
235
236 count_text->set_text(state, std::to_string(int32_t(index) + 1) + "/" + std::to_string(int32_t(messages.size())));
237
238 auto const& m = messages[index];
239 title_text->set_text(state, text::produce_simple_string(state, m.title));
240 }
241 }
242
243 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
244 if(index >= int32_t(messages.size()))
245 index = 0;
246 else if(index < 0)
247 index = int32_t(messages.size()) - 1;
248
249 if(payload.holds_type<dcon::nation_id>()) {
250 if(messages.empty()) {
251 payload.emplace<dcon::nation_id>(dcon::nation_id{});
252 } else {
253 payload.emplace<dcon::nation_id>(messages[index].source);
254 }
256 } else if(payload.holds_type<dcon::national_identity_id>()) {
257 if(messages.empty()) {
258 payload.emplace<dcon::national_identity_id>(dcon::national_identity_id{});
259 } else {
260 payload.emplace<dcon::national_identity_id>(state.world.nation_get_identity_from_identity_holder(messages[index].source));
261 }
263 } else if(payload.holds_type<element_selection_wrapper<bool>>()) {
264 bool b = any_cast<element_selection_wrapper<bool>>(payload).data;
265 index += b ? -1 : +1;
268 } else if(payload.holds_type<message_dismiss_notification>()) {
269 messages.clear();
272 } else if(payload.holds_type<notification::message*>()) {
273 if(messages.empty()) {
274 payload.emplace<notification::message*>(nullptr);
275 } else {
276 payload.emplace<notification::message*>(&(messages[index]));
277 }
278 }
279 return window_element_base::get(state, payload);
280 }
281};
282
283} // 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
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
void on_update(sys::state &state) noexcept override
message_body_text_internal * delegate
multiline_text_scrollbar * text_scrollbar
message_result on_scroll(sys::state &state, int32_t x, int32_t y, float amount, sys::key_modifiers mods) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
message_result test_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
void on_create(sys::state &state) noexcept override
void button_action(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
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::vector< notification::message > messages
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 set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
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:665
key_modifiers
Definition: constants.hpp:156
uint16_t name_into_font_id(sys::state &state, std::string_view txt)
Definition: fonts.cpp:93
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
void make_size_from_graphics(sys::state &state, ui::element_data &dat)
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)
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