Skip to content

Commit c43f673

Browse files
author
s.kushnirenko
committed
ui: mission briefing moved criteria labels to jsconfig
1 parent 71da37c commit c43f673

File tree

6 files changed

+57
-118
lines changed

6 files changed

+57
-118
lines changed

src/graphics/elements/ui.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ arrow_button &ui::arw_button(vec2i pos, bool up, bool tiny) {
165165
void ui::element::load(archive arch) {
166166
pos = arch.r_vec2i("pos");
167167
size = arch.r_size2i("size");
168+
enabled = arch.r_bool("enabled", true);
168169
}
169170

170171
void ui::outer_panel::draw() {
@@ -240,7 +241,10 @@ void ui::image::load(archive arch) {
240241
}
241242

242243
void ui::elabel::draw() {
243-
ui::label(_text.c_str(), pos, _font);
244+
if (_body.x > 0) {
245+
label_draw(pos.x, pos.y, _body.x, _body.y);
246+
}
247+
ui::label(_text.c_str(), pos + ((_body.x > 0) ? vec2i{8, 4} : vec2i{0, 0}), _font);
244248
}
245249

246250
void ui::elabel::load(archive arch) {
@@ -250,10 +254,12 @@ void ui::elabel::load(archive arch) {
250254

251255
_text = arch.r_string("text");
252256
_font = (e_font)arch.r_int("font", FONT_NORMAL_BLACK_ON_LIGHT);
257+
_body = arch.r_size2i("body");
253258
}
254259

255260
void ui::elabel::text(pcstr v) {
256261
_text = v;
262+
enabled = strlen(v) > 0;
257263
}
258264

259265
void ui::etext::load(archive arch) {

src/graphics/elements/ui.h

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ struct element {
5151
virtual void load(archive);
5252
virtual void text(pcstr) {}
5353

54+
template<class ... Args>
55+
inline void text_var(pcstr fmt, const Args&... args) { text(bstring512().printf(fmt, args...)); }
56+
5457
using ptr = std::shared_ptr<element>;
5558
};
5659

@@ -74,6 +77,7 @@ struct inner_panel : public element {
7477
struct elabel : public element {
7578
std::string _text;
7679
e_font _font;
80+
vec2i _body;
7781

7882
virtual void draw() override;
7983
virtual void load(archive elem) override;

src/js/js_game.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ e_image_id archive::r_image(pcstr name) {
140140
return (e_image_id)r_int(name);
141141
}
142142

143-
bool archive::r_bool(pcstr name) {
143+
bool archive::r_bool(pcstr name, bool def) {
144144
js_getproperty(vm, -1, name);
145-
bool result = js_isundefined(vm, -1) ? 0 : js_toboolean(vm, -1);
145+
bool result = js_isundefined(vm, -1) ? def : js_toboolean(vm, -1);
146146
js_pop(vm, 1);
147147
return result;
148148
}

src/js/js_game.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct archive {
1919
std::vector<std::string> r_array_str(pcstr name);
2020
int r_int(pcstr name, int def = 0);
2121
e_image_id r_image(pcstr name);
22-
bool r_bool(pcstr name);
22+
bool r_bool(pcstr name, bool def = false);
2323
vec2i r_size2i(pcstr name, pcstr w = "w", pcstr h = "h");
2424
vec2i r_vec2i(pcstr name, pcstr x = "x", pcstr y = "y");
2525

src/scripts/ui.js

+20-52
Original file line numberDiff line numberDiff line change
@@ -28,64 +28,32 @@ main_menu_window = {
2828

2929
advisor_rating_window = {
3030
ui : {
31-
outer_panel : {
32-
type : "outer_panel",
33-
pos : {x:0, y:0},
34-
size : {w:40, h:27},
35-
},
36-
advisor_icon : {
37-
type : "image",
38-
image : IMG_ADVISOR_RATING_ICON,
39-
pos : {x: 10, y: 10},
40-
},
41-
header_label : {
42-
type : "label",
43-
font : FONT_LARGE_BLACK_ON_LIGHT,
44-
text : {group: 53, id: 0},
45-
pos : {x: 60, y:17}
46-
},
47-
population_label : {
48-
type : "label",
49-
text : "",
50-
pos : {x: 300, y:20}
51-
},
52-
background_image : {
53-
type : "image",
54-
image : IMG_ADVISOR_BACKGROUND,
55-
pos : {x:60, y:38},
56-
},
31+
outer_panel : { type : "outer_panel", pos : {x:0, y:0}, size : {w:40, h:27} },
32+
advisor_icon : { type : "image", image : IMG_ADVISOR_RATING_ICON, pos : {x: 10, y: 10} },
33+
header_label : { type : "label", font : FONT_LARGE_BLACK_ON_LIGHT, text : {group: 53, id: 0}, pos : {x: 60, y:17} },
34+
population_label : { type : "label", text : "", pos : {x: 300, y:20} },
35+
background_image : { type : "image", image : IMG_ADVISOR_BACKGROUND, pos : {x:60, y:38} },
5736
},
5837
column_offset : {x: 30, y:-11}
5938
}
6039

6140
mission_briefing_window = {
6241
ui : {
63-
outer_panel : {
64-
type : "outer_panel",
65-
pos : {x:16, y:32},
66-
size : {w:38, h:27},
67-
},
68-
title : {
69-
type : "text",
70-
pos : {x:32, y:48},
71-
font : FONT_LARGE_BLACK_ON_LIGHT,
72-
},
73-
subtitle : {
74-
type : "text",
75-
pos : {x: 32, y:78},
76-
font : FONT_NORMAL_BLACK_ON_LIGHT
77-
},
78-
objectives : {
79-
type : "label",
80-
text : {group:62, id:7},
81-
pos : {x:376, y:433},
82-
font : FONT_NORMAL_BLACK_ON_LIGHT
83-
},
84-
objectives_panel : {
85-
type : "inner_panel",
86-
pos : {x:32, y:96},
87-
size: {w:33, h:6}
88-
}
42+
outer_panel : { type : "outer_panel", pos: {x:16, y:32}, size : {w:38, h:27} },
43+
title : { type : "text", pos : {x:32, y:48}, font : FONT_LARGE_BLACK_ON_LIGHT },
44+
subtitle : { type : "text", pos : {x: 32, y:78}, font : FONT_NORMAL_BLACK_ON_LIGHT },
45+
objectives_label : { type : "label", text : {group:62, id:10}, pos : {x:48, y:104}, font : FONT_NORMAL_WHITE_ON_DARK },
46+
objectives_panel : { type : "inner_panel", pos : {x:32, y:96}, size: {w:33, h:6} },
47+
tocity_label : { type : "label", text : {group:62, id:7}, pos : {x:416, y:433}, font : FONT_NORMAL_BLACK_ON_LIGHT },
48+
goal_0 : { type : "label", pos : {x:32 + 16, y:90 + 32}, body : {w:15, h:1}, font : FONT_NORMAL_YELLOW, enabled: false },
49+
goal_1 : { type : "label", pos : {x:288 + 16, y:90 + 32}, body : {w:15, h:1}, font : FONT_NORMAL_YELLOW, enabled: false },
50+
goal_2 : { type : "label", pos : {x:32 + 16, y:112 + 32}, body : {w:15, h:1}, font : FONT_NORMAL_YELLOW, enabled: false },
51+
goal_3 : { type : "label", pos : {x:288 + 16, y:112 + 32}, body : {w:15, h:1}, font : FONT_NORMAL_YELLOW, enabled: false },
52+
goal_4 : { type : "label", pos : {x:32 + 16, y:134 + 32}, body : {w:15, h:1}, font : FONT_NORMAL_YELLOW, enabled: false },
53+
goal_5 : { type : "label", pos : {x:288 + 16, y:134 + 32}, body : {w:15, h:1}, font : FONT_NORMAL_YELLOW, enabled: false },
54+
goal_immediate : { type : "label", pos : {x:32 + 16, y:134 + 32}, body : {w:31, h:1}, font : FONT_NORMAL_YELLOW, enabled: false },
55+
description_panel : { type : "inner_panel", pos : {x:32, y:200}, size: {w:33, h:14} },
56+
difficulty_label : { type : "label", pos : {x:35 + 45, y:433} },
8957
}
9058
}
9159

src/window/mission_briefing.cpp

+23-62
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ static void button_back(int param1, int param2);
2929
static void button_start_mission(int param1, int param2);
3030
static void inc_dec_difficulty(int param1, int param2);
3131

32-
static const vec2i GOAL_OFFSET[] = {{32, 90}, {288, 90}, {32, 112}, {288, 112}, {32, 134}, {288, 134}};
33-
3432
struct mission_briefing : ui::widget {
3533
struct {
3634
image_button back = {0, 0, 31, 20, IB_NORMAL, GROUP_MESSAGE_ICON, 8, button_back, button_none, 0, 0, 1};
@@ -74,6 +72,29 @@ static void draw_background() {
7472

7573
g_mission_briefing["title"].text((pcstr)msg->title.text);
7674
g_mission_briefing["subtitle"].text((pcstr)msg->subtitle.text);
75+
g_mission_briefing["difficulty_lable"].text(ui::str(153, g_settings.difficulty + 1));
76+
77+
const pcstr widgets[] = {"goal_0", "goal_1", "goal_2", "goal_3", "goal_4", "goal_5"};
78+
auto goal_label = widgets;
79+
80+
auto setup_goal = [&] (int group, int tid, bool enabled, int value) {
81+
g_mission_briefing[*goal_label].enabled = enabled;
82+
if (enabled) {
83+
g_mission_briefing[*goal_label++].text_var("%s: %u", ui::str(group, tid), value);
84+
}
85+
};
86+
87+
setup_goal(62, 11, winning_population() > 0, winning_population());
88+
setup_goal(29, 20 + winning_houselevel(), winning_housing() > 0, winning_housing());
89+
setup_goal(62, 12, winning_culture() > 0, winning_culture());
90+
setup_goal(62, 13, winning_prosperity() > 0, winning_prosperity());
91+
setup_goal(62, 14, winning_monuments() > 0, winning_monuments());
92+
setup_goal(62, 15, winning_kingdom() > 0, winning_kingdom());
93+
94+
int immediate_goal_text = tutorial_get_immediate_goal_text();
95+
if (immediate_goal_text) {
96+
g_mission_briefing["goal_immediate"].text(ui::str(62, immediate_goal_text));
97+
}
7798

7899
rich_text_set_fonts(FONT_NORMAL_WHITE_ON_DARK, FONT_NORMAL_YELLOW);
79100
rich_text_init(msg->content.text, 64, 200, 31, 14, 0);
@@ -90,66 +111,6 @@ static void draw_foreground(void) {
90111

91112
g_mission_briefing.draw();
92113

93-
lang_text_draw(62, 10, 48, 104, FONT_NORMAL_WHITE_ON_DARK);
94-
int goal_index = 0;
95-
96-
if (winning_population()) {
97-
vec2i offset = GOAL_OFFSET[goal_index];
98-
goal_index++;
99-
label_draw(16 + offset.x, 32 + offset.y, 15, 1);
100-
int width = lang_text_draw(62, 11, 16 + offset.x + 8, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
101-
text_draw_number(winning_population(), '@', " ", 16 + offset.x + 8 + width, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
102-
}
103-
104-
if (winning_housing()) {
105-
vec2i offset = GOAL_OFFSET[goal_index];
106-
goal_index++;
107-
label_draw(16 + offset.x, 32 + offset.y, 15, 1);
108-
int width = text_draw_number(winning_housing(), '@', " ", 16 + offset.x + 8, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
109-
lang_text_draw(29, 20 + winning_houselevel(), 16 + offset.x + 8 + width, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
110-
}
111-
112-
if (winning_culture()) {
113-
vec2i offset = GOAL_OFFSET[goal_index];
114-
goal_index++;
115-
label_draw(16 + offset.x, 32 + offset.y, 15, 1);
116-
int width = lang_text_draw(62, 12, 16 + offset.x + 8, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
117-
text_draw_number(winning_culture(), '@', " ", 16 + offset.x + 8 + width, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
118-
}
119-
120-
if (winning_prosperity()) {
121-
vec2i offset = GOAL_OFFSET[goal_index];
122-
goal_index++;
123-
label_draw(16 + offset.x, 32 + offset.y, 15, 1);
124-
int width = lang_text_draw(62, 13, 16 + offset.x + 8, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
125-
text_draw_number(winning_prosperity(), '@', " ", 16 + offset.x + 8 + width, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
126-
}
127-
128-
if (winning_monuments()) {
129-
vec2i offset = GOAL_OFFSET[goal_index];
130-
goal_index++;
131-
label_draw(16 + offset.x, 32 + offset.y, 15, 1);
132-
int width = lang_text_draw(62, 14, 16 + offset.x + 8, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
133-
text_draw_number(winning_monuments(), '@', " ", 16 + offset.x + 8 + width, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
134-
}
135-
136-
if (winning_kingdom()) {
137-
vec2i offset = GOAL_OFFSET[goal_index];
138-
goal_index++;
139-
label_draw(16 + offset.x, 32 + offset.y, 15, 1);
140-
int width = lang_text_draw(62, 15, 16 + offset.x + 8, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
141-
text_draw_number(winning_kingdom(), '@', " ", 16 + offset.x + 8 + width, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
142-
}
143-
int immediate_goal_text = tutorial_get_immediate_goal_text();
144-
if (immediate_goal_text) {
145-
vec2i offset = GOAL_OFFSET[4];
146-
label_draw(16 + offset.x, 32 + offset.y, 31, 1);
147-
lang_text_draw(62, immediate_goal_text, 16 + offset.x + 8, 32 + offset.y + 3, FONT_NORMAL_YELLOW);
148-
}
149-
150-
inner_panel_draw(32, 200, 33, 14);
151-
lang_text_draw(153, g_settings.difficulty + 1, 65 + 45, 433, FONT_NORMAL_BLACK_ON_LIGHT);
152-
153114
graphics_set_clip_rectangle(35, 187, 522, 234);
154115
rich_text_draw(msg->content.text, 48, 202, 512, 14, 0);
155116
graphics_reset_clip_rectangle();

0 commit comments

Comments
 (0)