Skip to content

Commit a635857

Browse files
committed
ui: sidebar goto problem button moved to config
1 parent bc98f55 commit a635857

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

src/city/message.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,13 @@ void city_message_delete(int message_id) {
486486
data.messages[message_id].MM_text_id = 0;
487487
city_message_sort_and_compact();
488488
}
489-
int city_message_count(void) {
489+
490+
int city_message_count() {
490491
auto& data = g_message_data;
491492
return data.total_messages;
492493
}
493494

494-
int city_message_problem_area_count(void) {
495+
int city_message_problem_area_count() {
495496
auto& data = g_message_data;
496497
return data.problem_count;
497498
}
@@ -512,7 +513,7 @@ static int has_problem_area(const city_message* msg, int lang_msg_type) {
512513
return 0;
513514
}
514515

515-
int city_message_next_problem_area_grid_offset(void) {
516+
int city_message_next_problem_area_grid_offset() {
516517
auto& data = g_message_data;
517518
time_millis now = time_get_millis();
518519
if (now - data.problem_last_click_time > 3000)

src/scripts/ui.js

+2
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ sidebar_window = {
834834
build_image : image({pos:[11, 211]}),
835835

836836
overlay_text : text_center({pos:[15, 30], size:[117, 20]}),
837+
838+
goto_problem : image_button({pos:[86, 434], pack:PACK_GENERAL, id:136, offset:56}),
837839
}
838840
}
839841

src/widget/widget_sidebar.cpp

+40-35
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ static void button_build(int submenu, int param2);
4141
static void button_undo(int param1, int param2);
4242
static void button_messages(int param1, int param2);
4343
static void button_help(int param1, int param2);
44-
static void button_go_to_problem(int param1, int param2);
4544
static void button_advisors(int param1, int param2);
4645
static void button_empire(int param1, int param2);
4746
static void button_mission_briefing(int param1, int param2);
@@ -103,7 +102,6 @@ static image_button buttons_build_expanded[] = {
103102

104103
{COL1, ROW4, 35, 45, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 48, button_undo, button_none, 0, 0, 1},
105104
{COL2, ROW4, 38, 45, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 52, button_messages, button_help, 0, MESSAGE_DIALOG_MESSAGES, 1},
106-
{COL3, ROW4, 28, 45, IB_NORMAL, GROUP_SIDEBAR_BUTTONS, 56, button_go_to_problem, button_none, 0, 0, 1},
107105
};
108106

109107
static image_button buttons_top_expanded[3] = {
@@ -152,15 +150,15 @@ static void draw_buttons_collapsed(int x_offset) {
152150
image_buttons_draw({x_offset, TOP_MENU_HEIGHT}, buttons_build_collapsed, 12);
153151
}
154152

155-
static void draw_buttons_expanded(int x_offset) {
153+
void ui::sidebar_window::draw_buttons_expanded(int x_offset) {
156154
buttons_build_expanded[12].enabled = game_can_undo();
157-
buttons_build_expanded[14].enabled = city_message_problem_area_count();
155+
ui["goto_problem"].readonly = !city_message_problem_area_count();
158156
image_buttons_draw({x_offset, TOP_MENU_HEIGHT}, buttons_overlays_collapse_sidebar, 1);
159157
image_buttons_draw({x_offset, TOP_MENU_HEIGHT}, buttons_build_expanded, 15);
160158
image_buttons_draw({x_offset, TOP_MENU_HEIGHT}, buttons_top_expanded, 3);
161159
}
162160

163-
static void refresh_build_menu_buttons(void) {
161+
static void refresh_build_menu_buttons() {
164162
int num_buttons = 12;
165163
for (int i = 0; i < num_buttons; i++) {
166164
buttons_build_expanded[i].enabled = 1;
@@ -190,6 +188,16 @@ void ui::sidebar_window::load(archive arch, pcstr section) {
190188

191189
void ui::sidebar_window::init() {
192190
extra_block_size = image_get(extra_block)->size();
191+
192+
ui["goto_problem"].onclick([] {
193+
int grid_offset = city_message_next_problem_area_grid_offset();
194+
if (grid_offset) {
195+
camera_go_to_mappoint(tile2i(grid_offset));
196+
window_city_show();
197+
} else {
198+
window_invalidate();
199+
}
200+
});
193201
}
194202

195203
void ui::sidebar_window::ui_draw_foreground() {
@@ -198,9 +206,11 @@ void ui::sidebar_window::ui_draw_foreground() {
198206
x_offset = sidebar_common_get_x_offset_expanded();
199207
ui.pos.x = x_offset;
200208

209+
ui.begin_widget(ui.pos);
201210
ui.draw();
202211
const animation_t &anim = window_build_menu_image();
203212
ui["build_image"].image(image_desc{ anim.pack, anim.iid, anim.offset });
213+
ui.end_widget();
204214

205215
widget_minimap_draw({x_offset + 12, MINIMAP_Y_OFFSET}, MINIMAP_WIDTH, MINIMAP_HEIGHT, 1);
206216

@@ -218,26 +228,7 @@ void ui::sidebar_window::ui_draw_foreground() {
218228
draw_overlay_text();
219229

220230
draw_sidebar_remainder(x_offset, false);
221-
}
222-
223-
void widget_sidebar_city_init() {
224-
g_sidebar.init();
225-
}
226231

227-
void widget_sidebar_city_draw_background() {
228-
OZZY_PROFILER_SECTION("Render/Frame/Window/City/Sidebar");
229-
if (city_view_is_sidebar_collapsed()) {
230-
draw_collapsed_background();
231-
} else {
232-
g_sidebar.ui_draw_foreground();
233-
}
234-
}
235-
236-
void widget_sidebar_city_draw_foreground_military(void) {
237-
widget_minimap_draw({sidebar_common_get_x_offset_expanded() + 8, MINIMAP_Y_OFFSET}, MINIMAP_WIDTH, MINIMAP_HEIGHT, 1);
238-
}
239-
240-
void widget_sidebar_city_draw_foreground() {
241232
if (building_menu_has_changed()) {
242233
refresh_build_menu_buttons();
243234
}
@@ -248,9 +239,8 @@ void widget_sidebar_city_draw_foreground() {
248239
} else {
249240
int x_offset = sidebar_common_get_x_offset_expanded();
250241
draw_buttons_expanded(x_offset);
251-
g_sidebar.draw_overlay_text();
252242

253-
widget_minimap_draw({x_offset + 12, MINIMAP_Y_OFFSET}, MINIMAP_WIDTH, MINIMAP_HEIGHT, 0);
243+
widget_minimap_draw({ x_offset + 12, MINIMAP_Y_OFFSET }, MINIMAP_WIDTH, MINIMAP_HEIGHT, 0);
254244
draw_number_of_messages(x_offset - 26);
255245
}
256246
sidebar_extra_draw_foreground();
@@ -259,11 +249,35 @@ void widget_sidebar_city_draw_foreground() {
259249
draw_debug_ui(10, 30);
260250
}
261251

252+
void widget_sidebar_city_init() {
253+
g_sidebar.init();
254+
}
255+
256+
void widget_sidebar_city_draw_foreground() {
257+
g_sidebar.ui_draw_foreground();
258+
}
259+
260+
void widget_sidebar_city_draw_background() {
261+
OZZY_PROFILER_SECTION("Render/Frame/Window/City/Sidebar");
262+
263+
if (city_view_is_sidebar_collapsed()) {
264+
draw_collapsed_background();
265+
} else {
266+
g_sidebar.ui_draw_foreground();
267+
}
268+
}
269+
270+
void widget_sidebar_city_draw_foreground_military(void) {
271+
widget_minimap_draw({sidebar_common_get_x_offset_expanded() + 8, MINIMAP_Y_OFFSET}, MINIMAP_WIDTH, MINIMAP_HEIGHT, 1);
272+
}
273+
262274
int widget_sidebar_city_handle_mouse(const mouse* m) {
263275
if (widget_city_has_input()) {
264276
return false;
265277
}
266278

279+
g_sidebar.ui_handle_mouse(m);
280+
267281
bool handled = false;
268282
int button_id;
269283
auto& data = g_sidebar;
@@ -352,15 +366,6 @@ static void button_messages(int param1, int param2) {
352366
static void button_help(int param1, int param2) {
353367
window_message_dialog_show(param2, -1, window_city_draw_all);
354368
}
355-
static void button_go_to_problem(int param1, int param2) {
356-
int grid_offset = city_message_next_problem_area_grid_offset();
357-
if (grid_offset) {
358-
camera_go_to_mappoint(map_point(grid_offset));
359-
window_city_show();
360-
} else {
361-
window_invalidate();
362-
}
363-
}
364369

365370
static void button_advisors(int param1, int param2) {
366371
window_advisors_show_checked();

src/widget/widget_sidebar.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct sidebar_window : public autoconfig_window_t<sidebar_window> {
2222
virtual void init() override;
2323

2424
void draw_overlay_text();
25+
void draw_buttons_expanded(int x_offset);
2526
};
2627

2728
}

0 commit comments

Comments
 (0)