Skip to content

Commit 6bbbee6

Browse files
committed
ui: storage yard orders moved to own class
1 parent dcba76b commit 6bbbee6

12 files changed

+237
-212
lines changed

src/building/building_storage_yard.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444

4545
buildings::model_t<building_storage_yard> storage_yard_m;
4646

47-
ANK_REGISTER_CONFIG_ITERATOR(config_load_building_storage_yard);
48-
void config_load_building_storage_yard() {
49-
storage_yard_m.load();
50-
}
51-
5247
int building_storage_yard::get_space_info() const {
5348
int total_amounts = 0;
5449
int empty_spaces = 0;

src/graphics/elements/generic_button.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ struct generic_button {
1919
int parameter1 = 0;
2020
int parameter2 = 0;
2121

22-
using function_cb = std::function<void(int, int)>;
23-
function_cb _onclick = nullptr;
24-
function_cb _onrclick = nullptr;
22+
using onclick_cb = std::function<void(int, int)>;
23+
using onclick_void = std::function<void()>;
24+
onclick_cb _onclick = nullptr;
25+
onclick_cb _onrclick = nullptr;
2526
textid _tooltip;
2627
bool hovered = false;
2728
rect clip = { {0, 0}, {0, 0} };
2829

2930
inline vec2i pos() const { return {x, y}; }
3031
inline vec2i size() const { return {width, height}; }
3132

32-
generic_button &onclick(function_cb f) { _onclick = f; return *this; }
33-
generic_button &onclick(std::function<void()> f) { return onclick([f] (int, int) { f(); }); }
33+
generic_button &onclick(onclick_cb f) { _onclick = f; return *this; }
34+
generic_button &onclick(onclick_void f) { return onclick([f] (int, int) { f(); }); }
3435

35-
generic_button &onrclick(function_cb f) { _onrclick = f; return *this; }
36-
generic_button &onrclick(std::function<void()> f) { return onrclick([f] (int, int) { f(); }); }
36+
generic_button &onrclick(onclick_cb f) { _onrclick = f; return *this; }
37+
generic_button &onrclick(onclick_void f) { return onrclick([f] (int, int) { f(); }); }
3738

3839
generic_button &tooltip(textid t) { _tooltip = t; return *this; }
3940
generic_button &tooltip(const std::initializer_list<int> &t) { _tooltip.group = *t.begin(); _tooltip.id = *(t.begin() + 1); return *this; }

src/scripts/common.js

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ var info_window_garden = {}
183183
var info_window_health = {}
184184
var info_window_farm = {}
185185
var info_window_storageyard = {}
186+
var info_window_storageyard_orders = {}
186187
var orders_window_granary = {}
187188
var info_window_figure_enemy = {}
188189
var info_window_figure_animal = {}

src/scripts/ui.js

+66-39
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function __extend(base, ext) {
2626
function inner_panel(config) { return __extend({type:"inner_panel"}, config) }
2727
function outer_panel(config) { return __extend({type:"outer_panel"}, config) }
2828
function text(config) { return __extend({type:"text"}, config) }
29+
function dummy(config) { return __extend({type:"text"}, config) }
2930
function text_center(config) { return __extend({type:"text", align:"center"}, config) }
3031
function label(config) { return __extend({type:"label", font : FONT_NORMAL_WHITE_ON_DARK}, config) }
3132
function header(config) { return __extend({type:"label", font : FONT_LARGE_BLACK_ON_LIGHT}, config) }
@@ -38,6 +39,9 @@ function button(config) { return __extend({type:"generic_button", font : FONT_NO
3839
function arrowup(config) { return __extend({type:"arrow_button", down:false}, config) }
3940
function arrowdown(config) { return __extend({type:"arrow_button", down:true}, config) }
4041
function background(config) { return __extend({type:"background", down:true}, config) }
42+
function help_button(config) { return image_button({margin:{left:14, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134 }) }
43+
function close_button(config) { return image_button({margin:{right:-40, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134, offset:4 }) }
44+
function resource_icon(config) { return __extend({ type : "resource_icon"}, config) }
4145

4246
uioptions = {
4347
resource_icons : {pack:PACK_GENERAL, id:129},
@@ -1229,47 +1233,70 @@ well_info_window = {
12291233
}
12301234
}
12311235

1232-
info_window_storageyard = {
1236+
info_window_storageyard_orders = {
1237+
parent_window_offset : [0, -250],
12331238
ui : {
1234-
background : { type : "outer_panel", pos: [0, 0], size: [29, 19] },
1235-
title : { type : "text", pos: [0, 12], size: [px(27), 20], font:FONT_LARGE_BLACK_ON_LIGHT, align:"center"},
1236-
1237-
storing : { type : "text", pos: [34, 40], font : FONT_NORMAL_BLACK_ON_LIGHT },
1238-
free_space : { type : "text", pos: [220, 40], font : FONT_NORMAL_BLACK_ON_LIGHT },
1239+
background : outer_panel({size:[29, 35] }),
1240+
title : text_center({text:[99, 3], pos:[10, 10], size:[px(29), 20], font: FONT_LARGE_BLACK_ON_LIGHT}),
1241+
1242+
items_panel : inner_panel({pos:[16, 42], size:[27, 28] }),
1243+
resource_base : dummy({pos: [10, 26] }),
1244+
icon_column : dummy({pos: [26, 6] }),
1245+
name_column : dummy({pos: [56, 6] }),
1246+
order_column : dummy({pos: [px(27)/2, 4], size:[px(27)/2, 20] }),
1247+
increase_column: dummy({pos: [px(27)/2 -30, 6] }),
1248+
decrease_column: dummy({pos: [px(27)/2 -13, 6] }),
1249+
item_row : dummy({size: [0, 20] }),
1250+
1251+
button_help : help_button({}),
1252+
button_close : close_button({}),
1253+
1254+
empty_all : button({pos:[80, -1], size:[300, 24], margin:{bottom:-64} }),
1255+
accept_none : button({pos:[80, -1], size:[300, 24], text:[99, 7], margin:{bottom:-38} }),
1256+
}
1257+
}
12391258

1240-
good0_icon : { type : "resource_icon", pos: [32, 60] },
1241-
good0_text : { type : "text", pos: [54, 64], font: FONT_NORMAL_BLACK_ON_LIGHT },
1242-
good1_icon : { type : "resource_icon", pos: [172, 60] },
1243-
good1_text : { type : "text", pos: [194, 64], font: FONT_NORMAL_BLACK_ON_LIGHT },
1244-
good2_icon : { type : "resource_icon", pos: [292, 60] },
1245-
good2_text : { type : "text", pos: [314, 64], font: FONT_NORMAL_BLACK_ON_LIGHT },
1246-
1247-
good3_icon : { type : "resource_icon", pos: [32, 90] },
1248-
good3_text : { type : "text", pos: [54, 94], font: FONT_NORMAL_BLACK_ON_LIGHT },
1249-
good4_icon : { type : "resource_icon", pos: [172, 60] },
1250-
good4_text : { type : "text", pos: [194, 94], font: FONT_NORMAL_BLACK_ON_LIGHT },
1251-
good5_icon : { type : "resource_icon", pos: [292, 90] },
1252-
good5_text : { type : "text", pos: [314, 94], font: FONT_NORMAL_BLACK_ON_LIGHT },
1253-
1254-
good6_icon : { type : "resource_icon", pos: [32, 120] },
1255-
good6_text : { type : "text", pos: [54, 124], font: FONT_NORMAL_BLACK_ON_LIGHT },
1256-
good7_icon : { type : "resource_icon", pos: [172, 120] },
1257-
good7_text : { type : "text", pos: [194, 124], font: FONT_NORMAL_BLACK_ON_LIGHT },
1258-
good8_icon : { type : "resource_icon", pos: [292, 120] },
1259-
good8_text : { type : "text", pos: [314, 124], font: FONT_NORMAL_BLACK_ON_LIGHT },
1260-
1261-
warning_text : { type : "text", pos: [32, 56], wrap:px(27), font : FONT_NORMAL_BLACK_ON_LIGHT, multiline:true },
1262-
workers_panel : { type : "inner_panel", pos : [16, 168], size: [27, 5] },
1263-
workers_img : { type : "image", pack:PACK_GENERAL, id:134, offset:14, pos:[40, 173] },
1264-
workers_text : { type : "text", pos: [70, 178], font: FONT_NORMAL_BLACK_ON_DARK, multiline:true, wrap:px(24) },
1265-
workers_desc : { type : "text", pos: [70, 178 + 16], font: FONT_NORMAL_BLACK_ON_DARK },
1266-
cartstate_img : { type : "resource_icon", pos:[40, 220] },
1267-
cartstate_desc : { type : "text", pos: [32, 223], wrap:px(27), font : FONT_NORMAL_BLACK_ON_DARK, multiline:true },
1268-
1269-
orders : { type:"generic_button", margin:{left:100, bottom:-40}, size:[270, 24], text:{group: 99, id: 2}},
1270-
button_help : { type : "image_button", margin:{left:14, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134 },
1271-
button_close : { type : "image_button", margin:{right:-40, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134, offset:4 },
1272-
mothball : { type:"generic_button", margin:{right:-90, bottom:-40}, size:[23, 23]},
1259+
info_window_storageyard = {
1260+
ui : {
1261+
background : outer_panel({size: [29, 19] }),
1262+
title : text({pos: [0, 12], size: [px(27), 20], font:FONT_LARGE_BLACK_ON_LIGHT, align:"center"}),
1263+
1264+
storing : text({ pos: [34, 40], font : FONT_NORMAL_BLACK_ON_LIGHT }),
1265+
free_space : text({ pos: [220, 40], font : FONT_NORMAL_BLACK_ON_LIGHT }),
1266+
1267+
good0_icon : resource_icon({pos: [32, 60] }),
1268+
good0_text : text({pos: [54, 64], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1269+
good1_icon : resource_icon({pos: [172, 60] }),
1270+
good1_text : text({pos: [194, 64], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1271+
good2_icon : resource_icon({pos: [292, 60] }),
1272+
good2_text : text({pos: [314, 64], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1273+
1274+
good3_icon : resource_icon({pos: [32, 90] }),
1275+
good3_text : text({pos: [54, 94], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1276+
good4_icon : resource_icon({pos: [172, 60] }),
1277+
good4_text : text({pos: [194, 94], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1278+
good5_icon : resource_icon({pos: [292, 90] }),
1279+
good5_text : text({pos: [314, 94], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1280+
1281+
good6_icon : resource_icon({pos: [32, 120] }),
1282+
good6_text : text({pos: [54, 124], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1283+
good7_icon : resource_icon({pos: [172, 120] }),
1284+
good7_text : text({pos: [194, 124], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1285+
good8_icon : resource_icon({pos: [292, 120] }),
1286+
good8_text : text({pos: [314, 124], font: FONT_NORMAL_BLACK_ON_LIGHT }),
1287+
1288+
warning_text : text({pos: [32, 56], wrap:px(27), font : FONT_NORMAL_BLACK_ON_LIGHT, multiline:true }),
1289+
workers_panel : inner_panel({pos : [16, 168], size: [27, 5] }),
1290+
workers_img : image({pack:PACK_GENERAL, id:134, offset:14, pos:[40, 173] }),
1291+
workers_text : text({pos: [70, 178], font: FONT_NORMAL_BLACK_ON_DARK, multiline:true, wrap:px(24) }),
1292+
workers_desc : text({pos: [70, 178 + 16], font: FONT_NORMAL_BLACK_ON_DARK }),
1293+
cartstate_img : resource_icon({pos:[40, 220] }),
1294+
cartstate_desc: text({pos: [32, 223], wrap:px(27), font : FONT_NORMAL_BLACK_ON_DARK, multiline:true }),
1295+
1296+
orders : button({margin:{left:100, bottom:-40}, size:[270, 24], text:[99, 2]}),
1297+
button_help : help_button({}),
1298+
button_close : close_button({}),
1299+
mothball : button({margin:{right:-90, bottom:-40}, size:[23, 23]}),
12731300
}
12741301
}
12751302

src/window/building/distribution.cpp

-47
Original file line numberDiff line numberDiff line change
@@ -333,53 +333,6 @@ static void on_scroll(void) {
333333
}
334334
static scrollbar_t g_distribution_scrollbar = {{590, 52}, 336, on_scroll};
335335

336-
int window_building_handle_mouse_warehouse(const mouse* m, object_info* c) {
337-
auto &data = g_window_building_distribution;
338-
data.building_id = c->building_id;
339-
if (generic_buttons_handle_mouse(m, {c->offset.x + 80, c->offset.y + 16 * c->bgsize.y - 34}, data.go_to_orders_button.data(), 1, &data.focus_button_id)) {
340-
}
341-
// temp - todo: fix buttons
342-
// if (generic_buttons_handle_mouse(m, c->offset.x + 64, c->offset.y + 16 * c->height_blocks - 75,
343-
// warehouse_distribution_permissions_buttons, 3,
344-
// &data.permission_focus_button_id)) {
345-
// }
346-
return 0;
347-
}
348-
349-
int window_building_handle_mouse_warehouse_orders(const mouse* m, object_info* c) {
350-
auto &data = g_window_building_distribution;
351-
int y_offset = window_building_get_vertical_offset(c, 28 + 5);
352-
data.resource_focus_button_id = 0;
353-
354-
bool handled = false;
355-
// bool handled = scrollbar_handle_mouse(&scrollbar, m);
356-
// if (handled)
357-
// return handled;
358-
359-
// arrows
360-
if (image_buttons_handle_mouse(m, {c->offset.x + 165, y_offset + 49}, data.orders_decrease_arrows.data(), 20, &data.decr_arrow_focus_button_id)) {
361-
handled = true;
362-
}
363-
364-
if (image_buttons_handle_mouse(m, {c->offset.x + 165 + 18, y_offset + 49}, data.orders_increase_arrows.data(), 20, &data.decr_arrow_focus_button_id)) {
365-
handled = true;
366-
}
367-
368-
if (handled)
369-
return 1;
370-
371-
// resources
372-
int num_resources = std::min<int>((int)city_resource_get_available().size(), 20);
373-
data.building_id = c->building_id;
374-
375-
if (generic_buttons_handle_mouse(m, {c->offset.x + 205, y_offset + 46}, data.orders_resource_buttons.data(), num_resources, &data.resource_focus_button_id)) {
376-
return 1;
377-
}
378-
379-
// extra instructions
380-
return generic_buttons_handle_mouse(m, {c->offset.x + 80, y_offset + 404}, warehouse_order_buttons, 2, &data.orders_focus_button_id);
381-
}
382-
383336
textid window_building_get_tooltip_warehouse_orders() {
384337
auto &data = g_window_building_distribution;
385338
if (data.orders_focus_button_id == 1) {

src/window/building/distribution.h

-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,5 @@ int window_building_handle_mouse_granary_orders(const mouse* m, object_info* c);
4141
textid window_building_get_tooltip_granary_orders();
4242
textid window_building_get_tooltip_warehouse_orders();
4343

44-
int window_building_handle_mouse_warehouse(const mouse* m, object_info* c);
45-
int window_building_handle_mouse_warehouse_orders(const mouse* m, object_info* c);
46-
4744
void window_building_draw_order_instruction(int instr_kind, const storage_t *storage, e_resource resource, vec2i pos, int market_order = -1);
4845
std::pair<bstring64, e_font> window_building_get_order_instruction(int instr_kind, const storage_t *storage, e_resource resource, int market_order = -1);

src/window/window_building_info.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,7 @@ building_info_window::building_info_window() {
3131

3232
int building_info_window::window_info_handle_mouse(const mouse *m, object_info &c) {
3333
building *b = building_get(c);
34-
switch (b->type) {
35-
case BUILDING_STORAGE_YARD:
36-
if (c.storage_show_special_orders)
37-
return window_building_handle_mouse_warehouse_orders(m, &c);
38-
else
39-
return window_building_handle_mouse_warehouse(m, &c);
40-
break;
41-
42-
default:
43-
return b->dcast()->window_info_handle_mouse(m, c);
44-
}
34+
return b->dcast()->window_info_handle_mouse(m, c);
4535
}
4636

4737
static void draw_native(object_info* c, int group_id) {

src/window/window_building_info.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct building_info_window_t : public building_info_window {
3232
static type_name_holder<T> _impl;
3333
static pcstr _section = strstr(_impl.value.data(), "::") ? strstr(_impl.value.data(), "::") + 2
3434
: strstr(_impl.value.data(), "struct ") ? strstr(_impl.value.data(), "struct ") + 7
35+
: strstr(_impl.value.data(), "class ") ? strstr(_impl.value.data(), "class ") + 6
3536
: _impl.value.data();
3637
return _section;
3738
}

src/window/window_info.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,13 @@ static void window_info_draw_foreground() {
234234
static void window_info_handle_input(const mouse* m, const hotkeys* h) {
235235
auto &context = g_object_info;
236236
auto &ui = *g_object_info.ui;
237-
238-
ui.begin_widget(g_object_info.offset);
239-
bool button_id = ui::handle_mouse(m);
240-
ui.end_widget();
241237

238+
bool button_id = context.ui->window_info_handle_mouse(m, context);
239+
242240
if (!button_id) {
243-
int btn_id = context.ui->window_info_handle_mouse(m, context);
244-
button_id |= !!btn_id;
241+
ui.begin_widget(g_object_info.offset);
242+
ui::handle_mouse(m);
243+
ui.end_widget();
245244
}
246245

247246
if (!button_id && input_go_back_requested(m, h)) {

0 commit comments

Comments
 (0)