Skip to content

Commit d3552d4

Browse files
committed
ui: redesigned empire map window
1 parent e3c9739 commit d3552d4

File tree

8 files changed

+218
-277
lines changed

8 files changed

+218
-277
lines changed

src/graphics/elements/ui.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void ui::begin_frame() {
198198
}
199199

200200
void ui::end_frame() {
201-
201+
202202
}
203203

204204
void ui::end_widget() {
@@ -490,10 +490,13 @@ void ui::panel(vec2i pos, vec2i size, UiFlags flags) {
490490
}
491491
}
492492

493-
void ui::icon(vec2i pos, e_resource img) {
493+
void ui::icon(vec2i pos, e_resource res, UiFlags flags) {
494494
const vec2i offset = g_state.offset();
495495
painter ctx = game.painter();
496-
ImageDraw::img_generic(ctx, image_id_resource_icon(img), offset.x + pos.x, offset.y + pos.y);
496+
const image_t *img = ImageDraw::img_generic(ctx, image_id_resource_icon(res), offset.x + pos.x, offset.y + pos.y);
497+
if (!!(flags & UiFlags_Outline)) {
498+
graphics_draw_inset_rect(pos - vec2i{1, 1}, vec2i{ img->width, img->height } + vec2i{2, 2});
499+
}
497500
}
498501

499502
void ui::icon(vec2i pos, e_advisor adv) {
@@ -735,6 +738,10 @@ void ui::elabel::draw() {
735738
label_draw(pos.x + offset.x, pos.y + offset.y, _body.x, _body.y);
736739
}
737740
ui::label(_text.c_str(), pos + ((_body.x > 0) ? vec2i{8, 4} : vec2i{0, 0}), _font, _flags, size.x);
741+
742+
if (_draw_callback) {
743+
_draw_callback(this);
744+
}
738745
}
739746

740747
void ui::elabel::load(archive arch, element *parent, items &elems) {
@@ -934,6 +941,10 @@ void ui::etext::draw() {
934941
}
935942
text_draw((uint8_t *)_text.c_str(), offset.x + pos.x, offset.y + pos.y, _font, _color);
936943
}
944+
945+
if (_draw_callback) {
946+
_draw_callback(this);
947+
}
937948
}
938949

939950
void ui::emenu_header::load(archive arch, element *parent, items &elems) {

src/graphics/elements/ui.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum UiFlags_ {
4141
UiFlags_AlignXCentered = 1 << 12,
4242
UiFlags_Readonly = 1 << 13,
4343
UiFlags_NoBorder = 1 << 14,
44+
UiFlags_Outline = 1 << 15,
4445
};
4546
using UiFlags = int;
4647

@@ -65,7 +66,7 @@ int label_colored(pcstr tx, vec2i pos, e_font font, color color);
6566
void eimage(e_image_id img, vec2i pos, int offset = 0);
6667
void eimage(image_desc img, vec2i pos);
6768
void panel(vec2i pos, vec2i size, UiFlags flags);
68-
void icon(vec2i pos, e_resource img);
69+
void icon(vec2i pos, e_resource img, UiFlags flags = UiFlags_None);
6970
void icon(vec2i pos, e_advisor advisor);
7071
int button_hover(const mouse *m);
7172

@@ -102,6 +103,7 @@ struct recti {
102103
struct element {
103104
using ptr = std::shared_ptr<element>;
104105
using items = std::vector<ptr>;
106+
using draw_callback = std::function<void(element*)>;
105107

106108
xstring id;
107109
vec2i pos;
@@ -110,6 +112,7 @@ struct element {
110112
bool readonly = false;
111113
bool enabled = true;
112114
bool grayed = false;
115+
draw_callback _draw_callback;
113116

114117
virtual void draw() {}
115118
virtual void load(archive, element* parent, items &elems);
@@ -128,12 +131,13 @@ struct element {
128131
virtual int value() const { return 0; }
129132
virtual void select(bool v) {}
130133
virtual void max_value(int v) {}
131-
virtual const xstring &tooltip() const { return xstring(); }
134+
virtual const xstring &tooltip() const { static xstring dummy; return dummy; }
132135
virtual element &onclick(std::function<void(int, int)>) { return *this; }
133136
element &onclick(std::function<void()> f) { onclick([f] (int, int) { f(); }); return *this; }
134137
virtual void onevent(std::function<void()>) { }
135138
virtual element &onrclick(std::function<void(int, int)>) { return *this; }
136139
element &onrclick(std::function<void()> f) { onrclick([f] (int, int) { f(); }); return *this;}
140+
virtual void ondraw(draw_callback f) { _draw_callback = f;};
137141

138142
virtual emenu_header *dcast_menu_header() { return nullptr; }
139143
virtual eimage_button *dcast_image_button() { return nullptr; }

src/graphics/indexes.h

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ REGISTER_IMG(IMG_MINIMAP_BRIGHT_BLUE, 88)
2020
REGISTER_IMG(IMG_MINIMAP_LILAC, 89)
2121
REGISTER_IMG(IMG_MINIMAP_ORANGE, 90)
2222
REGISTER_IMG(IMG_MINIMAP_COLOR, 92)
23-
REGISTER_IMG(IMG_TRADE_AMOUNT, 93)
2423
REGISTER_IMG(ANIM_BREWERY_WORKSHOP, 104)
2524
REGISTER_IMG(IMG_BRICKLAYER_WALK, 109)
2625
REGISTER_IMG(IMG_BRICKLAYER_DEATH, 110)

src/platform/renderer.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ static buffer_texture* get_saved_texture_info(int texture_id) {
409409
}
410410

411411
int graphics_renderer_interface::save_texture_from_screen(int texture_id, vec2i pos, int width, int height) {
412+
assert(width > 0 && height > 0);
413+
412414
auto &data = g_renderer_data;
413415
SDL_Texture* former_target = SDL_GetRenderTarget(data.renderer);
414416
if (!former_target) {

src/scripts/common.js

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ var building_road = {}
132132
var building_burning_ruin = {}
133133
var building_marble_quarry = {}
134134
var trade_prices_window = {}
135+
var trade_city_sell = {}
136+
var trade_city_want_sell = {}
137+
var trade_city_buy = {}
138+
var trade_city_want_buy = {}
135139

136140
// houses
137141
var building_house_crude_hut = {}

src/scripts/images.js

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ images = [
2424
{img: IMG_MINIMAP_LIGHT_YELLOW, pack:PACK_GENERAL, id:149, offset:180},
2525
{img: IMG_MINIMAP_LILAC, pack:PACK_GENERAL, id:149, offset:195},
2626
{img: IMG_MINIMAP_COLOR, pack:PACK_GENERAL, id:149, offset:0},
27-
{img: IMG_TRADE_AMOUNT, pack:PACK_GENERAL, id:171, offset:0},
2827
{img: IMG_BRICKLAYER_WALK, pack:PACK_SPR_MAIN, id:109},
2928
{img: IMG_BRICKLAYER_DEATH, pack:PACK_SPR_MAIN, id:110},
3029
{img: IMG_BRICKLAYER_WORK, pack:PACK_SPR_MAIN, id:111},

src/scripts/ui.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -1392,19 +1392,16 @@ info_window_storageyard = {
13921392
}
13931393

13941394
empire_window = {
1395-
trade_column_spacing : 106,
1395+
trade_column_spacing : 146,
13961396
trade_row_spacing : 20,
13971397
info_y_traded : -3,
13981398
trade_button_offset_x : 0,
1399-
info_y_sells : 30,
1400-
info_y_buys : 52,
14011399
info_y_footer_1 : 78,
14021400
info_y_city_desc : 28,
14031401
text_group_old_names : 195,
14041402
text_group_new_names : 21,
14051403
trade_resource_size : 18,
14061404
trade_resource_offset : 3,
1407-
sell_res_group : 47,
14081405
trade_button_offset_y : 10,
14091406
start_pos : [16, 16],
14101407
finish_pos : [32, 136],
@@ -1413,6 +1410,7 @@ empire_window = {
14131410
horizontal_bar : {pack:PACK_GENERAL, id:172, offset:1},
14141411
vertical_bar : {pack:PACK_GENERAL, id:172, offset:0},
14151412
cross_bar : {pack:PACK_GENERAL, id:172, offset:2},
1413+
trade_amount : {pack:PACK_GENERAL, id:171},
14161414

14171415
ui : {
14181416
background : dummy({size:[sw(0), sh(0)]}),
@@ -1421,6 +1419,23 @@ empire_window = {
14211419
button_close : close_button({margin:{centerx:575, bottom:-40}}),
14221420
button_advisor : advisor_button({margin:{centerx:-595, bottom:-120}}),
14231421
button_open_trade : button({margin:{centerx:-220, bottom:-40}, size:[440, 20]}),
1422+
info_tooltip : text({margin:{centerx:-200, bottom:-60}, size:[400, 20], font:FONT_NORMAL_BLACK_ON_LIGHT, align:"center"}),
1423+
1424+
city_sell_title : text({text:[47, 11], margin:{centerx:250, bottom:-120}, font: FONT_NORMAL_BLACK_ON_LIGHT }),
1425+
city_sell_items : dummy({pos:[0, 100], size:[200, 0], margin:{centerx:100, bottom:-90}}),
1426+
city_sell_item : dummy({size:[120, 20], font:FONT_SMALL_PLAIN}),
1427+
1428+
city_buy_title : text({text:[47, 10], margin:{centerx:-300, bottom:-120}, font: FONT_NORMAL_BLACK_ON_LIGHT }),
1429+
city_buy_items : dummy({pos:[0, 0], size:[200, 0], margin:{centerx:-430, bottom:-90}}),
1430+
city_buy_item : dummy({size:[120, 20], font:FONT_SMALL_PLAIN}),
1431+
1432+
city_want_sell_title : text({text:[47, 5], margin:{centerx:-220, bottom:-90}, font: FONT_NORMAL_BLACK_ON_LIGHT }),
1433+
city_want_sell_items : dummy({pos:[0, 100], margin:{centerx:-170, bottom:-90}}),
1434+
city_want_sell_item : dummy({size:[110, 0], font:FONT_SMALL_PLAIN}),
1435+
1436+
city_want_buy_title : text({text:[47, 4], margin:{centerx:-220, bottom:-70}, font: FONT_NORMAL_BLACK_ON_LIGHT }),
1437+
city_want_buy_items : dummy({pos:[0, 0], margin:{centerx:-170, bottom:-70}}),
1438+
city_want_buy_item : dummy({size:[110, 0], font:FONT_SMALL_PLAIN}),
14241439
}
14251440
}
14261441

@@ -1435,9 +1450,9 @@ minimap_window = {
14351450
terrain_elevation : {pack:PACK_GENERAL, id:145},
14361451
terrain_meadow : {pack:PACK_GENERAL, id:146},
14371452
terrain_flooplain : {pack:PACK_GENERAL, id:146},
1438-
terrain_road : {pack:PACK_GENERAL, id:147},
1439-
terrain_wall : {pack:PACK_GENERAL, id:150},
1453+
terrain_road : {pack:PACK_GENERAL, id:147},
1454+
terrain_wall : {pack:PACK_GENERAL, id:150},
14401455
terrain_canal : {pack:PACK_GENERAL, id:151},
1441-
terrain_dune : {pack:PACK_GENERAL, id:211},
1442-
terrain_teal : {pack:PACK_GENERAL, id:149, offset:200},
1456+
terrain_dune : {pack:PACK_GENERAL, id:211},
1457+
terrain_teal : {pack:PACK_GENERAL, id:149, offset:200},
14431458
}

0 commit comments

Comments
 (0)