Skip to content

Commit 849a0da

Browse files
author
s.kushnirenko
committed
ui: moved title, subtitle in mission briefing window to jsconfig
1 parent b4a3671 commit 849a0da

File tree

8 files changed

+127
-98
lines changed

8 files changed

+127
-98
lines changed

src/graphics/elements/rich_text.cpp

+9-24
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ struct rich_text_data_t {
4545

4646
rich_text_data_t g_rich_text_data;
4747

48-
int rich_text_init(const uint8_t* text,
49-
int x_text,
50-
int y_text,
51-
int width_blocks,
52-
int height_blocks,
53-
int adjust_width_on_no_scroll) {
48+
int rich_text_init(const uint8_t* text, int x_text, int y_text, int width_blocks, int height_blocks, int adjust_width_on_no_scroll) {
5449
auto &data = g_rich_text_data;
5550
data.x_text = x_text;
5651
data.y_text = y_text;
@@ -59,14 +54,14 @@ int rich_text_init(const uint8_t* text,
5954
data.text_height_lines = height_blocks - 1;
6055
data.text_width_blocks = width_blocks;
6156

62-
data.num_lines = rich_text_draw(
63-
text, data.x_text + 8, data.y_text + 6, 16 * data.text_width_blocks - 16, data.text_height_lines, 1);
57+
data.num_lines = rich_text_draw(text, data.x_text + 8, data.y_text + 6, 16 * data.text_width_blocks - 16, data.text_height_lines, 1);
6458
scrollbar.x = data.x_text + 16 * data.text_width_blocks - 1;
6559
scrollbar.y = data.y_text;
6660
scrollbar.height = 16 * data.text_height_blocks;
6761
scrollbar_init(&scrollbar, scrollbar.scroll_position, data.num_lines - data.text_height_lines);
68-
if (data.num_lines <= data.text_height_lines && adjust_width_on_no_scroll)
62+
if (data.num_lines <= data.text_height_lines && adjust_width_on_no_scroll) {
6963
data.text_width_blocks += 2;
64+
}
7065

7166
window_invalidate();
7267
}
@@ -231,7 +226,7 @@ static void draw_line(painter &ctx, const uint8_t* str, int x, int y, color colo
231226
}
232227
}
233228

234-
static int draw_text(const uint8_t* text, int x_offset, int y_offset, int box_width, int height_lines, color color, bool measure_only) {
229+
static int rich_text_draw_impl(const uint8_t* text, int x_offset, int y_offset, int box_width, int height_lines, color color, bool measure_only) {
235230
int image_height_lines = 0;
236231
int image_id = 0;
237232
int lines_before_image = 0;
@@ -343,22 +338,12 @@ static int draw_text(const uint8_t* text, int x_offset, int y_offset, int box_wi
343338
return num_lines;
344339
}
345340

346-
int rich_text_draw(const uint8_t* text,
347-
int x_offset,
348-
int y_offset,
349-
int box_width,
350-
int height_lines,
351-
bool measure_only) {
352-
return draw_text(text, x_offset, y_offset, box_width, height_lines, 0, measure_only);
341+
int rich_text_draw(const uint8_t* text, int x_offset, int y_offset, int box_width, int height_lines, bool measure_only) {
342+
return rich_text_draw_impl(text, x_offset, y_offset, box_width, height_lines, 0, measure_only);
353343
}
354344

355-
int rich_text_draw_colored(const uint8_t* text,
356-
int x_offset,
357-
int y_offset,
358-
int box_width,
359-
int height_lines,
360-
color color) {
361-
return draw_text(text, x_offset, y_offset, box_width, height_lines, color, 0);
345+
int rich_text_draw_colored(const uint8_t* text, int x_offset, int y_offset, int box_width, int height_lines, color color) {
346+
return rich_text_draw_impl(text, x_offset, y_offset, box_width, height_lines, color, 0);
362347
}
363348

364349
void rich_text_draw_scrollbar(void) {

src/graphics/elements/ui.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "image_button.h"
77
#include "lang_text.h"
88
#include "panel.h"
9+
#include "graphics/text.h"
910
#include "game/game.h"
1011
#include "graphics/boilerplate.h"
1112
#include "io/gamefiles/lang.h"
@@ -145,8 +146,8 @@ void ui::icon(vec2i pos, e_resource img) {
145146
}
146147

147148
void ui::icon(vec2i pos, e_advisor adv) {
148-
const vec2i offset = g_state.offset();
149149
painter ctx = game.painter();
150+
const vec2i offset = g_state.offset();
150151
ImageDraw::img_generic(ctx, image_group(IMG_ADVISOR_ICONS) + (adv - 1), offset.x + pos.x, offset.y + pos.y);
151152
}
152153

@@ -177,7 +178,9 @@ void ui::outer_panel::load(archive arch) {
177178

178179
void ui::widget::draw() {
179180
for (auto &e : elements) {
180-
e->draw();
181+
if (e->enabled) {
182+
e->draw();
183+
}
181184
}
182185
}
183186

@@ -192,6 +195,8 @@ void ui::widget::load(archive arch) {
192195
elm = std::make_shared<image>();
193196
} else if (!strcmp(type, "label")) {
194197
elm = std::make_shared<elabel>();
198+
} else if (!strcmp(type, "text")) {
199+
elm = std::make_shared<etext>();
195200
}
196201

197202
if (elm) {
@@ -227,7 +232,6 @@ void ui::elabel::load(archive arch) {
227232
element::load(arch);
228233

229234
pcstr type = arch.r_string("type");
230-
assert(!strcmp(type, "label"));
231235

232236
_text = arch.r_string("text");
233237
_font = (e_font)arch.r_int("font", FONT_NORMAL_BLACK_ON_LIGHT);
@@ -236,3 +240,14 @@ void ui::elabel::load(archive arch) {
236240
void ui::elabel::text(pcstr v) {
237241
_text = v;
238242
}
243+
244+
void ui::etext::load(archive arch) {
245+
elabel::load(arch);
246+
247+
pcstr type = arch.r_string("type");
248+
assert(!strcmp(type, "text"));
249+
}
250+
251+
void ui::etext::draw() {
252+
text_draw((uint8_t*)_text.c_str(), pos.x, pos.y, _font, 0);
253+
}

src/graphics/elements/ui.h

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct element {
4444
bstring64 id;
4545
vec2i pos;
4646
vec2i size;
47+
bool enabled = true;
4748

4849
virtual void draw() {}
4950
virtual void load(archive);
@@ -73,6 +74,11 @@ struct elabel : public element {
7374
virtual void text(pcstr) override;
7475
};
7576

77+
struct etext : public elabel {
78+
virtual void draw() override;
79+
virtual void load(archive elem) override;
80+
};
81+
7682
struct widget {
7783
std::vector<element::ptr> elements;
7884

src/scenario/criteria.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ int winning_kingdom() {
4444
return g_scenario_data.win_criteria.kingdom.goal;
4545
}
4646
int winning_housing() {
47-
if (!g_scenario_data.win_criteria.housing_count.enabled)
47+
if (!g_scenario_data.win_criteria.housing_count.enabled) {
4848
return 0;
49+
}
50+
4951
return g_scenario_data.win_criteria.housing_count.goal;
5052
}
5153
int winning_houselevel() {

src/scripts/common.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ var empire_window = {}
3030
var images_remap = []
3131
var imagepaks = []
3232
var advisor_rating_window = {}
33+
var mission_briefing_window = {}

src/scripts/ui.js

+54-28
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,61 @@ main_menu_window = {
2727
}
2828

2929
advisor_rating_window = {
30-
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-
},
30+
ui : {
31+
outer_panel : {
32+
type : "outer_panel",
33+
pos : {x:0, y:0},
34+
size : {w:40, h:27},
5735
},
58-
column_offset : {x: 30, y:-11}
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+
},
57+
},
58+
column_offset : {x: 30, y:-11}
59+
}
60+
61+
mission_briefing_window = {
62+
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+
}
5985
}
6086

6187
empire_window = {

src/window/intermezzo.cpp

+6-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#define DISPLAY_TIME_MILLIS 1200
2020

21-
static const char SOUND_FILE_LOSE[] = "wavs/lose_game.wav";
21+
static pcstr SOUND_FILE_LOSE = "wavs/lose_game.wav";
2222

2323
struct intermezzo_data_t {
2424
intermezzo_type type;
@@ -59,29 +59,20 @@ static void init(intermezzo_type type, void (*callback)(void)) {
5959
static void draw_background(void) {
6060
graphics_clear_screen();
6161
graphics_reset_dialog();
62-
int x_offset = (screen_width() - 1024) / 2;
63-
int y_offset = (screen_height() - 768) / 2;
62+
vec2i offset = vec2i{screen_width() - 1024, screen_height() - 768} / 2;
6463

6564
// draw background by mission
6665
int mission = scenario_campaign_scenario_id();
6766
int image_base = image_id_from_group(GROUP_INTERMEZZO_BACKGROUND);
6867
painter ctx = game.painter();
6968
if (g_intermezzo_data.type == INTERMEZZO_MISSION_BRIEFING) {
70-
if (scenario_is_custom()) {
71-
ImageDraw::img_generic(ctx, image_base + 1, x_offset, y_offset);
72-
} else {
73-
ImageDraw::img_generic(ctx, image_base + 1 + (mission >= 20), x_offset, y_offset);
74-
}
69+
ImageDraw::img_generic(ctx, scenario_is_custom() ? image_base + 1 : image_base + 1 + (mission >= 20), offset);
7570

7671
} else if (g_intermezzo_data.type == INTERMEZZO_FIRED) {
77-
ImageDraw::img_generic(ctx, image_base, x_offset, y_offset);
72+
ImageDraw::img_generic(ctx, image_base, offset);
7873

7974
} else if (g_intermezzo_data.type == INTERMEZZO_WON) {
80-
if (scenario_is_custom()) {
81-
ImageDraw::img_generic(ctx, image_base + 2, x_offset, y_offset);
82-
} else {
83-
ImageDraw::img_generic(ctx, image_base, x_offset, y_offset);
84-
}
75+
ImageDraw::img_generic(ctx, scenario_is_custom() ? image_base + 2 : image_base, offset);
8576
}
8677
}
8778

@@ -93,7 +84,7 @@ static void handle_input(const mouse* m, const hotkeys* h) {
9384
}
9485
}
9586

96-
void window_intermezzo_show(intermezzo_type type, void (*callback)(void)) {
87+
void window_intermezzo_show(intermezzo_type type, void (*callback)()) {
9788
window_type window = {
9889
WINDOW_INTERMEZZO,
9990
draw_background,

0 commit comments

Comments
 (0)