Skip to content

Commit 77469b5

Browse files
committed
ui: correct slide top menu bar
1 parent 9666f07 commit 77469b5

7 files changed

+25
-21
lines changed

src/io/gamestate/boilerplate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#include "scenario/request.h"
6262
#include "sound/sound_city.h"
6363
#include "sound/sound.h"
64-
#include "widget/top_menu_game.h"
64+
#include "widget/widget_top_menu_game.h"
6565
#include "window/window_city.h"
6666
#include "window/file_dialog.h"
6767
#include "window/mission_briefing.h"

src/scripts/ui.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ top_menu_bar = {
4747
offset : [10, 6],
4848
item_height : 20,
4949
background: IMG_TOP_MENU_BACKGROUND,
50+
sidebar_offset : 158,
5051
spacing : 32,
5152
offset_funds_basic : 540,
5253
offset_population_basic : 400,

src/widget/widget_sidebar.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "window/message_list.h"
3333
#include "window/mission_briefing.h"
3434
#include "window/overlay_menu.h"
35+
#include "widget/widget_top_menu_game.h"
3536
#include "sound/sound.h"
3637
#include "game/game.h"
3738

@@ -206,6 +207,7 @@ void ui::sidebar_window_expanded::ui_draw_foreground() {
206207
}
207208
x_offset += rel_offset;
208209
}
210+
widget_top_menu_draw(true);
209211
} else {
210212
x_offset -= expanded_offset_x;
211213
}
@@ -316,6 +318,7 @@ void ui::sidebar_window_collapsed::ui_draw_foreground() {
316318
}
317319
x_offset += rel_offset;
318320
}
321+
widget_top_menu_draw(true);
319322
} else {
320323
x_offset -= expanded_offset_x;
321324
}

src/widget/top_menu_game.cpp src/widget/widget_top_menu_game.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "top_menu_game.h"
1+
#include "widget_top_menu_game.h"
22

33
#include "game/game.h"
44

@@ -76,6 +76,7 @@ struct top_menu_data_t {
7676
vec2i offset;
7777
int item_height;
7878
int spacing;
79+
int sidebar_offset;
7980
e_image_id background;
8081

8182
ui::widget headers;
@@ -144,6 +145,7 @@ void config_load_top_menu_bar() {
144145
data.offset_population_basic = arch.r_int("offset_population_basic");
145146
data.offset_date_basic = arch.r_int("offset_date_basic");
146147
data.offset_rotate_basic = arch.r_int("offset_rotate_basic");
148+
data.sidebar_offset = arch.r_int("sidebar_offset");
147149

148150
data.headers.load(arch, "headers");
149151
for (auto &header : data.headers.elements) {
@@ -635,13 +637,13 @@ static void widget_top_menu_init() {
635637
set_text_for_debug_render();
636638
}
637639

638-
static void top_menu_draw_background() {
640+
static void widget_sub_menu_draw_background() {
639641
window_city_draw_panels();
640642
window_city_draw();
641643
widget_sidebar_city_draw_foreground();
642644
}
643645

644-
static void top_menu_draw_foreground() {
646+
static void widget_sub_menu_draw_foreground() {
645647
auto& data = g_top_menu_data;
646648
if (!data.open_sub_menu) {
647649
return;
@@ -650,11 +652,11 @@ static void top_menu_draw_foreground() {
650652
top_menu_menu_draw(data.open_sub_menu, data.focus_sub_menu_id);
651653
}
652654

653-
void widget_top_menu_show() {
655+
void widget_sub_menu_show() {
654656
static window_type window = {
655657
WINDOW_TOP_MENU,
656-
top_menu_draw_background,
657-
top_menu_draw_foreground,
658+
widget_sub_menu_draw_background,
659+
widget_sub_menu_draw_foreground,
658660
widget_top_menu_handle_input
659661
};
660662
widget_top_menu_init();
@@ -666,18 +668,16 @@ int orientation_button_pressed = 0;
666668

667669
void wdiget_top_menu_draw_background() {
668670
painter ctx = game.painter();
669-
int block_width = 96;
670-
int s_width = screen_width();
671-
672-
int s_end = s_width - 1000 - 24 + city_view_is_sidebar_collapsed() * (162 - 18);
673-
int s_start = s_end - ceil((float)s_end / (float)block_width) * block_width;
674671

675672
int img_id = image_group(g_top_menu_data.background);
676-
for (int i = 0; s_start + i * block_width < s_end; i++) {
677-
ImageDraw::img_generic(ctx, img_id, s_start + (i * block_width), COLOR_MASK_NONE);
673+
const image_t *img = image_get(img_id);
674+
const int block_width = img->width;
675+
676+
for (int x = -(screen_width() - widget_sidebar_city_offset_x()); x < screen_width(); x += (block_width - g_top_menu_data.sidebar_offset)) {
677+
ImageDraw::img_generic(ctx, img_id, x, 0);
678678
}
679679

680-
ImageDraw::img_generic(ctx, img_id, s_end, 0);
680+
ImageDraw::img_generic(ctx, img_id, widget_sidebar_city_offset_x() - block_width + g_top_menu_data.sidebar_offset, 0);
681681
}
682682

683683
void widget_top_menu_draw(int force) {
@@ -818,7 +818,7 @@ static bool widget_top_menu_handle_mouse_menu(const mouse* m) {
818818
xstring menu_id = top_menu_bar_handle_mouse(m);
819819
if (!!menu_id && m->left.went_up) {
820820
data.open_sub_menu = menu_id;
821-
widget_top_menu_show();
821+
widget_sub_menu_show();
822822
return true;
823823
}
824824

File renamed without changes.

src/window/window_city.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "scenario/scenario.h"
2626
#include "scenario/criteria.h"
2727
#include "widget/widget_sidebar.h"
28-
#include "widget/top_menu_game.h"
28+
#include "widget/widget_top_menu_game.h"
2929
#include "widget/widget_city.h"
3030
#include "window/advisors.h"
3131
#include "window/file_dialog.h"
@@ -41,7 +41,7 @@ static int center_in_city(int element_width_pixels) {
4141

4242
void window_city_draw_background() {
4343
OZZY_PROFILER_SECTION("Render/Frame/Window/City/Bakground");
44-
widget_top_menu_draw(1);
44+
widget_top_menu_draw(true);
4545
}
4646

4747
void window_city_draw_paused_and_time_left() {
@@ -93,7 +93,7 @@ static void draw_cancel_construction() {
9393

9494
static void window_city_draw_foreground() {
9595
// clear_city_view(0);
96-
widget_top_menu_draw(0);
96+
widget_top_menu_draw(false);
9797
window_city_draw();
9898
widget_sidebar_city_draw_foreground();
9999
if (window_is(WINDOW_CITY) || window_is(WINDOW_CITY_MILITARY)) {

src/window/window_city_military.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "city/warning.h"
55
#include "widget/widget_city.h"
66
#include "widget/minimap.h"
7-
#include "widget/top_menu_game.h"
7+
#include "widget/widget_top_menu_game.h"
88
#include "widget/sidebar/common.h"
99
#include "widget/widget_sidebar.h"
1010
#include "graphics/window.h"
@@ -73,7 +73,7 @@ void handle_input_military(const mouse* m, const hotkeys* h) {
7373
}
7474

7575
void draw_foreground_military() {
76-
widget_top_menu_draw(0);
76+
widget_top_menu_draw(false);
7777
window_city_draw();
7878
widget_sidebar_city_draw_foreground_military();
7979
window_city_draw_paused_and_time_left();

0 commit comments

Comments
 (0)