Skip to content

Commit 5e9f86a

Browse files
committed
storages: allow manage orders for granary
1 parent 92feed3 commit 5e9f86a

13 files changed

+236
-197
lines changed

src/building/building_storage.cpp

+5-15
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,21 @@ void building_storage_delete(int storage_id) {
9999

100100
storage_t backup_settings;
101101
static int backup_storage_id = -1;
102-
static bool has_unsaved_changes = false;
103102

104103
void backup_storage_settings(int storage_id) {
105104
if (backup_storage_id != -1)
106105
return;
107106

108-
has_unsaved_changes = false;
109107
backup_storage_id = storage_id;
110108
backup_settings = g_storages[storage_id].storage;
111109
}
112110

111+
bool building_storage_has_unsaved_changes() {
112+
return memcmp(&backup_settings, &g_storages[backup_storage_id].storage, sizeof(backup_settings)) != 0;
113+
}
114+
113115
void storage_settings_backup_check() {
114-
if (has_unsaved_changes) {
116+
if (building_storage_has_unsaved_changes()) {
115117
window_popup_dialog_show_confirmation("#exit_without_saving", [] (bool do_forget_changes) {
116118
if (!do_forget_changes) {
117119
return;
@@ -132,7 +134,6 @@ void storage_settings_backup_check() {
132134
}
133135

134136
void storage_settings_backup_reset() {
135-
has_unsaved_changes = false;
136137
backup_storage_id = -1;
137138
}
138139

@@ -141,7 +142,6 @@ const storage_t* building_storage_get(int storage_id) {
141142
}
142143

143144
void building_storage_toggle_empty_all(int storage_id) {
144-
has_unsaved_changes = true;
145145
g_storages[storage_id].storage.empty_all = 1 - g_storages[storage_id].storage.empty_all;
146146

147147
auto &storage = g_storages[storage_id].storage;
@@ -151,7 +151,6 @@ void building_storage_toggle_empty_all(int storage_id) {
151151
}
152152

153153
void building_storage_cycle_resource_state(int storage_id, int resource_id, bool backwards) {
154-
has_unsaved_changes = true;
155154
int state = g_storages[storage_id].storage.resource_state[resource_id];
156155
if (!backwards) {
157156
if (state == STORAGE_STATE_PHARAOH_ACCEPT)
@@ -179,7 +178,6 @@ void building_storage_cycle_resource_state(int storage_id, int resource_id, bool
179178
void building_storage::set_permission(int p) {
180179
auto& data = g_storages;
181180

182-
has_unsaved_changes = true;
183181
const storage_t* s = storage();
184182
int permission_bit = 1 << p;
185183
int perms = s->permissions;
@@ -197,7 +195,6 @@ void building_storage_increase_decrease_resource_state(int storage_id, int resou
197195
int state = g_storages[storage_id].storage.resource_state[resource_id];
198196
if (state == STORAGE_STATE_PHARAOH_ACCEPT) {
199197
int max_accept = g_storages[storage_id].storage.resource_max_accept[resource_id];
200-
int old = max_accept;
201198
if (increase) {
202199
if (max_accept == 2400)
203200
max_accept = 3200;
@@ -214,12 +211,8 @@ void building_storage_increase_decrease_resource_state(int storage_id, int resou
214211
max_accept = 800;
215212
}
216213
g_storages[storage_id].storage.resource_max_accept[resource_id] = max_accept;
217-
if (old != max_accept)
218-
has_unsaved_changes = true;
219-
220214
} else if (state == STORAGE_STATE_PHARAOH_GET) {
221215
int max_get = g_storages[storage_id].storage.resource_max_get[resource_id];
222-
int old = max_get;
223216
if (increase) {
224217
if (max_get == 2400)
225218
max_get = 3200;
@@ -237,13 +230,10 @@ void building_storage_increase_decrease_resource_state(int storage_id, int resou
237230
}
238231

239232
g_storages[storage_id].storage.resource_max_get[resource_id] = max_get;
240-
if (old != max_get)
241-
has_unsaved_changes = true;
242233
}
243234
}
244235

245236
void building_storage_accept_none(int storage_id) {
246-
has_unsaved_changes = true;
247237
auto &storage = g_storages[storage_id].storage;
248238
for (auto &state: storage.resource_state) {
249239
state = STORAGE_STATE_PHARAOH_REFUSE;

src/building/building_storage.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ int building_storage_create(int building_type);
5252

5353
int building_storage_restore(int storage_id);
5454
void building_storage_delete(int storage_id);
55+
bool building_storage_has_unsaved_changes();
5556

5657
const storage_t* building_storage_get(int storage_id);
5758

src/scripts/common.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ var advisor_ratings_window = {}
171171
var advisor_labors_window = {}
172172
var mission_briefing_window = {}
173173
var granary_info_window = {}
174+
var granary_orders_window = {}
174175
var advisor_religion_window = {}
175176
var workshop_info_window = {}
176177
var main_menu_window = {}
177178
var bazaar_info_window = {}
179+
var bazaar_orders_window = {}
178180
var well_info_window = {}
179181
var minimap_window = {}
180182
var advisor_trade_window = {}
@@ -190,7 +192,6 @@ var info_window_health = {}
190192
var info_window_farm = {}
191193
var info_window_storageyard = {}
192194
var info_window_storageyard_orders = {}
193-
var orders_window_granary = {}
194195
var info_window_figure_enemy = {}
195196
var info_window_figure_animal = {}
196197
var info_window_figure_caravan_donkey = {}

src/scripts/ui.js

+54-30
Original file line numberDiff line numberDiff line change
@@ -798,43 +798,67 @@ roadblock_info_window = {
798798
}
799799
}
800800

801-
orders_window_granary = {
801+
granary_orders_window = {
802802
ui : {
803-
background : { type : "outer_panel", pos: [0, 0], size: [29, 17]},
804-
title : { type : "text", pos: [0, 12], size: [px(28), 0], text:{group:98, id:5}, font : FONT_LARGE_BLACK_ON_LIGHT, align:"center"},
805-
orders_panel : { type : "inner_panel", pos : [16, 42], size: [27, 10] },
806-
button_help : { type : "image_button", margin:{left:14, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134 },
807-
button_close : { type : "image_button", margin:{right:-40, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134, offset:4 },
808-
empty_all : { type:"generic_button", pos:[80, -1], size:[300, 24], margin:{bottom:-64} },
809-
accept_none : { type:"generic_button", pos:[80, -1], size:[300, 24], text:{group:99, id:7}, margin:{bottom:-38} },
803+
background : outer_panel({size: [29, 17]}),
804+
title : text({pos: [0, 12], size: [px(28), 0], text:{group:98, id:5}, font : FONT_LARGE_BLACK_ON_LIGHT, align:"center"}),
805+
orders_panel : inner_panel({pos : [16, 42], size: [27, 10] }),
806+
button_help : image_button({margin:{left:14, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134 }),
807+
button_close : image_button({margin:{right:-40, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134, offset:4 }),
808+
empty_all : button({pos:[80, -1], size:[300, 24], margin:{bottom:-64} }),
809+
accept_none : button({pos:[80, -1], size:[300, 24], text:{group:99, id:7}, margin:{bottom:-38} }),
810+
811+
item_orders_column : dummy({margin:{centerx:0}}),
812+
item_arrows_column : dummy({margin:{centerx:-36}}),
813+
item_icon_column : dummy({pos:[25, 0]}),
814+
item_row : dummy({size:[px(13), 20]}),
815+
items_area : dummy({pos:[0, 50]}),
810816
}
811817
}
812818

813819
granary_info_window = {
814820
resource_text_group : 23,
815821
ui : {
816-
background : { type : "outer_panel", pos: [0, 0], size: [29, 17]},
817-
title : { type : "text", text: "#granary_info_title", pos: [0, 12], size: [px(28), 0], font : FONT_LARGE_BLACK_ON_LIGHT, align:"center"},
818-
warning_text : { type : "text", pos: [32, 40], wrap:px(28), font : FONT_NORMAL_BLACK_ON_LIGHT, multiline:true },
819-
storing : { type : "text", pos: [34, 40], font : FONT_NORMAL_BLACK_ON_LIGHT },
820-
free_space : { type : "text", pos: [220, 40], font : FONT_NORMAL_BLACK_ON_LIGHT },
821-
food0_icon : { type : "resource_icon", pos: [34, 68] },
822-
food0_text : { type : "text", pos: [68, 75], font: FONT_NORMAL_BLACK_ON_LIGHT },
823-
food1_icon : { type : "resource_icon", pos: [240, 68] },
824-
food1_text : { type : "text", pos: [274, 75], font: FONT_NORMAL_BLACK_ON_LIGHT },
825-
food2_icon : { type : "resource_icon", pos: [34, 92] },
826-
food2_text : { type : "text", pos: [68, 99], font: FONT_NORMAL_BLACK_ON_LIGHT },
827-
food3_icon : { type : "resource_icon", pos: [240, 92] },
828-
food3_text : { type : "text", pos: [274, 99], font: FONT_NORMAL_BLACK_ON_LIGHT },
829-
workers_panel : { type : "inner_panel", pos : [16, 142], size: [27, 5] },
830-
workers_img : { type : "image", pack:PACK_GENERAL, id:134, offset:14, pos:[40, 142 + 6] },
831-
workers_text : { type : "text", pos: [70, 142 + 12], font: FONT_NORMAL_BLACK_ON_DARK },
832-
workers_desc : { type : "text", pos: [70, 142 + 26], font: FONT_NORMAL_BLACK_ON_DARK },
833-
orders : { type:"generic_button", margin:{left:100, bottom:-40}, size:[270, 25], text:{group: 98, id: 5}},
834-
button_help : { type : "image_button", margin:{left:14, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134 },
835-
button_close : { type : "image_button", margin:{right:-40, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134, offset:4 },
836-
show_overlay : { type:"generic_button", margin:{right:-64, bottom:-40}, size:[23, 23]},
837-
mothball : { type:"generic_button", margin:{right:-90, bottom:-40}, size:[23, 23]},
822+
background : outer_panel({size: [29, 17]}),
823+
title : text({text: "#granary_info_title", pos: [0, 12], size: [px(28), 0], font : FONT_LARGE_BLACK_ON_LIGHT, align:"center"}),
824+
warning_text : text({pos: [32, 40], wrap:px(28), font : FONT_NORMAL_BLACK_ON_LIGHT, multiline:true }),
825+
storing : text({pos: [34, 40], font : FONT_NORMAL_BLACK_ON_LIGHT }),
826+
free_space : text({pos: [220, 40], font : FONT_NORMAL_BLACK_ON_LIGHT }),
827+
food0_icon : resource_icon({pos:[34, 68]}),
828+
food0_text : text({pos: [68, 75], font: FONT_NORMAL_BLACK_ON_LIGHT }),
829+
food1_icon : resource_icon({pos: [240, 68] }),
830+
food1_text : text({pos: [274, 75], font: FONT_NORMAL_BLACK_ON_LIGHT }),
831+
food2_icon : resource_icon({pos: [34, 92] }),
832+
food2_text : text({pos: [68, 99], font: FONT_NORMAL_BLACK_ON_LIGHT }),
833+
food3_icon : resource_icon({pos: [240, 92] }),
834+
food3_text : text({pos: [274, 99], font: FONT_NORMAL_BLACK_ON_LIGHT }),
835+
workers_panel : inner_panel({pos: [16, 142], size: [27, 5] }),
836+
workers_img : image({pack:PACK_GENERAL, id:134, offset:14, pos:[40, 142 + 6] }),
837+
workers_text : text({pos: [70, 142 + 12], font: FONT_NORMAL_BLACK_ON_DARK }),
838+
workers_desc : text({pos: [70, 142 + 26], font: FONT_NORMAL_BLACK_ON_DARK }),
839+
orders : button({margin:{centerx:-135, bottom:-40}, size:[270, 25], text:{group: 98, id: 5}}),
840+
button_help : image_button({margin:{left:14, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134 }),
841+
button_close : image_button({margin:{right:-40, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134, offset:4 }),
842+
show_overlay : button({margin:{right:-64, bottom:-40}, size:[23, 23]}),
843+
mothball : button({margin:{right:-90, bottom:-40}, size:[23, 23]}),
844+
}
845+
}
846+
847+
bazaar_orders_window = {
848+
ui : {
849+
background : outer_panel({size: [29, 17]}),
850+
title : text({pos: [0, 12], size: [px(28), 0], text:{group:98, id:5}, font : FONT_LARGE_BLACK_ON_LIGHT, align:"center"}),
851+
orders_panel : inner_panel({pos : [16, 42], size: [27, 10] }),
852+
button_help : image_button({margin:{left:14, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134 }),
853+
button_close : image_button({margin:{right:-40, bottom:-40}, size:[27, 27], pack:PACK_GENERAL, id:134, offset:4 }),
854+
empty_all : button({pos:[80, -1], size:[300, 24], margin:{bottom:-64} }),
855+
accept_none : button({pos:[80, -1], size:[300, 24], text:{group:99, id:7}, margin:{bottom:-38} }),
856+
857+
item_orders_column : dummy({margin:{centerx:0}}),
858+
item_arrows_column : dummy({margin:{centerx:-36}}),
859+
item_icon_column : dummy({pos:[25, 0]}),
860+
item_row : dummy({size:[px(13), 20]}),
861+
items_area : dummy({pos:[0, 50]}),
838862
}
839863
}
840864

src/window/window_bazaar_info.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include "game/game.h"
1414
#include "js/js_game.h"
1515

16-
struct bazaar_info_window : public building_info_window {
16+
void window_bazaar_orders_show(object_info &c);
17+
18+
struct bazaar_info_window : public building_info_window_t<bazaar_info_window>{
1719
int resource_text_group;
1820

1921
using widget::load;
@@ -24,6 +26,7 @@ struct bazaar_info_window : public building_info_window {
2426

2527
virtual void window_info_background(object_info &c) override;
2628
virtual void window_info_foreground(object_info &c) override;
29+
virtual void init(object_info &c) override;
2730
virtual bool check(object_info &c) override {
2831
return c.building_get()->type == BUILDING_BAZAAR;
2932
}
@@ -33,12 +36,7 @@ struct bazaar_info_window : public building_info_window {
3336
void draw_orders_foreground(object_info &c);
3437
};
3538

36-
bazaar_info_window g_bazaar_info_window;
37-
38-
ANK_REGISTER_CONFIG_ITERATOR(config_load_bazaar_info_window);
39-
void config_load_bazaar_info_window() {
40-
g_bazaar_info_window.load("bazaar_info_window");
41-
}
39+
bazaar_info_window g_bazaar_infow;
4240

4341
void bazaar_info_window::draw_simple_background(object_info &c) {
4442
auto bazaar = c.building_get()->dcast_bazaar();
@@ -47,11 +45,6 @@ void bazaar_info_window::draw_simple_background(object_info &c) {
4745

4846
window_building_play_sound(&c, bazaar->get_sound());
4947

50-
ui["orders"].onclick([&c] (int, int) {
51-
c.storage_show_special_orders = 1;
52-
window_invalidate();
53-
});
54-
5548
std::pair<int, int> reason = {0, 0};
5649
if (!c.has_road_access) {
5750
reason = {69, 25};
@@ -113,10 +106,17 @@ void bazaar_info_window::window_info_foreground(object_info &ctx) {
113106
if (ctx.storage_show_special_orders) {
114107
draw_orders_foreground(ctx);
115108
} else {
116-
g_bazaar_info_window.draw();
109+
g_bazaar_infow.draw();
117110
}
118111
}
119112

113+
void bazaar_info_window::init(object_info &c) {
114+
ui["orders"].onclick([&c] (int, int) {
115+
c.storage_show_special_orders = 1;
116+
window_invalidate();
117+
});
118+
}
119+
120120
void bazaar_info_window::draw_orders_foreground(object_info &c) {
121121
auto &data = g_window_building_distribution;
122122
draw_orders_background(c);

src/window/window_bazaar_orders.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "window_info.h"
2+
3+
#include "building/building_bazaar.h"
4+
#include "window/building/distribution.h"
5+
#include "window/window_building_info.h"
6+
#include "city/object_info.h"
7+
#include "city/city_resource.h"
8+
#include "graphics/window.h"
9+
#include "game/game.h"
10+
#include "js/js_game.h"
11+
12+
struct bazaar_orders_window : public building_info_window_t<bazaar_orders_window> {
13+
virtual void window_info_background(object_info &c) override;
14+
virtual void window_info_foreground(object_info &c) override;
15+
};
16+
17+
bazaar_orders_window granary_ordersw;
18+
19+
20+
void window_bazaar_orders_show(object_info &c) {
21+
c.ui = &granary_ordersw;
22+
c.ui->window_info_background(c);
23+
}
24+
25+
void bazaar_orders_window::window_info_background(object_info &c) {
26+
}
27+
28+
void bazaar_orders_window::window_info_foreground(object_info &c) {
29+
}

src/window/window_building_info.cpp

+21-28
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void window_building_draw_native_crops(object_info* c) {
5656

5757

5858
void building_info_window::window_info_foreground(object_info &c) {
59-
draw();
60-
59+
common_info_window::window_info_foreground(c);
60+
6161
building *b = building_get(c);
6262
b->dcast()->window_info_foreground(c);
6363
}
@@ -136,6 +136,8 @@ textid building_info_window::get_tooltip(object_info &c) {
136136
}
137137

138138
void building_info_window::init(object_info &c) {
139+
common_info_window::init(c);
140+
139141
g_debug_building_id = c.building_id;
140142
building *b = building_get(c);
141143

@@ -201,48 +203,39 @@ void building_info_window::init(object_info &c) {
201203
c.group_id = params.meta.text_id;
202204

203205
ui["title"] = ui::str(28, b->type);
206+
207+
int workers_needed = model_get_building(b->type)->laborers;
208+
ui["mothball"].onclick([&c, b, workers_needed] {
209+
if (workers_needed) {
210+
building_mothball_toggle(b);
211+
window_invalidate();
212+
}
213+
});
214+
215+
ui["show_overlay"].onclick([&c] {
216+
if (game.current_overlay != c.show_overlay) {
217+
game_state_set_overlay((e_overlay)c.show_overlay);
218+
} else {
219+
game_state_reset_overlay();
220+
}
221+
window_invalidate();
222+
});
204223
}
205224

206225
void building_info_window::update_buttons(object_info &c) {
207226
common_info_window::update_buttons(c);
208227
building *b = building_get(c);
209228

210229
int workers_needed = model_get_building(b->type)->laborers;
211-
vec2i bgsize = ui["background"].pxsize();
212230
ui["mothball"].enabled = workers_needed > 0;
213231
if (workers_needed) {
214232
ui["mothball"] = (b->state == BUILDING_STATE_VALID ? "x" : "");
215-
ui["mothball"].onclick([&c, b, workers_needed] {
216-
if (workers_needed) {
217-
building_mothball_toggle(b);
218-
window_invalidate();
219-
}
220-
});
221233
auto tooltip = (b->state == BUILDING_STATE_VALID) ? textid{54, 16} : textid{54, 17};
222234
ui["mothball"].tooltip(tooltip);
223235
}
224236

225-
//ui::img_button(GROUP_CONTEXT_ICONS, vec2i(16 * c.bgsize.x - 40, y_offset + 16 * height_blocks - 40), {28, 28}, {4})
226-
// .onclick([&c] (int, int) {
227-
// if (c.storage_show_special_orders) {
228-
// c.storage_show_special_orders = 0;
229-
// storage_settings_backup_reset();
230-
// window_invalidate();
231-
// } else {
232-
// window_city_show();
233-
// }
234-
//});
235-
236237
ui["show_overlay"].enabled = (c.show_overlay != OVERLAY_NONE);
237238
ui["show_overlay"] = (game.current_overlay != c.show_overlay ? "v" : "V");
238-
ui["show_overlay"].onclick([&c] {
239-
if (game.current_overlay != c.show_overlay) {
240-
game_state_set_overlay((e_overlay)c.show_overlay);
241-
} else {
242-
game_state_reset_overlay();
243-
}
244-
window_invalidate();
245-
});
246239
}
247240

248241
building *building_info_window::building_get(object_info &c) {

0 commit comments

Comments
 (0)