Skip to content

Commit 914f0e1

Browse files
authored
Merge pull request #5526 from Goober5000/hud_set_coords
add screen resolution scaling for hud-set-coords
2 parents df68da3 + dd0af0e commit 914f0e1

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

code/mod_table/mod_table.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ bool Supernova_hits_at_zero;
129129
bool Show_subtitle_uses_pixels;
130130
int Show_subtitle_screen_base_res[2];
131131
int Show_subtitle_screen_adjusted_res[2];
132+
int HUD_set_coords_screen_base_res[2];
132133
bool Always_warn_player_about_unbound_keys;
133134
leadIndicatorBehavior Lead_indicator_behavior;
134135
shadow_disable_overrides Shadow_disable_overrides {false, false, false, false};
@@ -465,6 +466,21 @@ void parse_mod_table(const char *filename)
465466
}
466467
}
467468

469+
if (optional_string("$HUD-set-coords base resolution:")) {
470+
int base_res[2];
471+
if (stuff_int_list(base_res, 2) == 2) {
472+
if (base_res[0] >= 640 && base_res[1] >= 480) {
473+
HUD_set_coords_screen_base_res[0] = base_res[0];
474+
HUD_set_coords_screen_base_res[1] = base_res[1];
475+
mprintf(("Game Settings Table: HUD-set-coords base resolution is (%d, %d)\n", base_res[0], base_res[1]));
476+
} else {
477+
Warning(LOCATION, "$HUD-set-coords base resolution: arguments must be at least 640x480!");
478+
}
479+
} else {
480+
Warning(LOCATION, "$HUD-set-coords base resolution: must specify two arguments");
481+
}
482+
}
483+
468484
optional_string("#GRAPHICS SETTINGS");
469485

470486
if (optional_string("$Enable External Shaders:")) {
@@ -1295,15 +1311,17 @@ void mod_table_post_process()
12951311
// use the same widescreen code as in adjust_base_res()
12961312
// This calculates an adjusted resolution if the aspect ratio of the base resolution doesn't exactly match that of the current resolution.
12971313
// The base resolution specified in game_settings.tbl does not need to be 1024x768 or even 4:3.
1298-
float aspect_quotient = ((float)gr_screen.center_w / (float)gr_screen.center_h) / ((float)Show_subtitle_screen_base_res[0] / (float)Show_subtitle_screen_base_res[1]);
1299-
if (aspect_quotient >= 1.0) {
1300-
Show_subtitle_screen_adjusted_res[0] = (int)(Show_subtitle_screen_base_res[0] * aspect_quotient);
1314+
float aspect_quotient_subtitle = ((float)gr_screen.center_w / (float)gr_screen.center_h) / ((float)Show_subtitle_screen_base_res[0] / (float)Show_subtitle_screen_base_res[1]);
1315+
if (aspect_quotient_subtitle >= 1.0) {
1316+
Show_subtitle_screen_adjusted_res[0] = (int)(Show_subtitle_screen_base_res[0] * aspect_quotient_subtitle);
13011317
Show_subtitle_screen_adjusted_res[1] = Show_subtitle_screen_base_res[1];
13021318
} else {
13031319
Show_subtitle_screen_adjusted_res[0] = Show_subtitle_screen_base_res[0];
1304-
Show_subtitle_screen_adjusted_res[1] = (int)(Show_subtitle_screen_base_res[1] / aspect_quotient);
1320+
Show_subtitle_screen_adjusted_res[1] = (int)(Show_subtitle_screen_base_res[1] / aspect_quotient_subtitle);
13051321
}
13061322
mprintf(("Game Settings Table: Show-subtitle adjusted resolution is (%d, %d)\n", Show_subtitle_screen_adjusted_res[0], Show_subtitle_screen_adjusted_res[1]));
1323+
1324+
// we don't need to calculate adjusted resolution for hud-set-coords because that function doesn't do screen scaling
13071325
}
13081326

13091327
bool mod_supports_version(int major, int minor, int build)
@@ -1416,6 +1434,8 @@ void mod_table_reset()
14161434
Show_subtitle_screen_base_res[1] = -1;
14171435
Show_subtitle_screen_adjusted_res[0] = -1;
14181436
Show_subtitle_screen_adjusted_res[1] = -1;
1437+
HUD_set_coords_screen_base_res[0] = -1;
1438+
HUD_set_coords_screen_base_res[1] = -1;
14191439
Always_warn_player_about_unbound_keys = false;
14201440
Lead_indicator_behavior = leadIndicatorBehavior::DEFAULT;
14211441
Thruster_easing = 0;

code/mod_table/mod_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ extern bool Supernova_hits_at_zero;
123123
extern bool Show_subtitle_uses_pixels;
124124
extern int Show_subtitle_screen_base_res[];
125125
extern int Show_subtitle_screen_adjusted_res[];
126+
extern int HUD_set_coords_screen_base_res[];
126127
extern bool Always_warn_player_about_unbound_keys;
127128
extern leadIndicatorBehavior Lead_indicator_behavior;
128129
extern struct shadow_disable_overrides {

code/parse/sexp.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12624,6 +12624,12 @@ void sexp_hud_set_coords(int n)
1262412624

1262512625
HudGauge* hg = hud_get_gauge(gaugename);
1262612626
if (hg) {
12627+
// we might need to adjust the coordinates
12628+
if (HUD_set_coords_screen_base_res[0] > 0 && HUD_set_coords_screen_base_res[1] > 0) {
12629+
coord_x = fl2i(i2fl(coord_x) * gr_screen.center_w / HUD_set_coords_screen_base_res[0]);
12630+
coord_y = fl2i(i2fl(coord_y) * gr_screen.center_h / HUD_set_coords_screen_base_res[1]);
12631+
}
12632+
1262712633
hg->setGaugeCoords(coord_x, coord_y);
1262812634
} else {
1262912635
WarningEx(LOCATION, "Could not find a hud gauge named %s\n", gaugename);
@@ -39333,7 +39339,8 @@ SCP_vector<sexp_help_struct> Sexp_help = {
3933339339

3933439340
//WMC
3933539341
{ OP_HUD_SET_COORDS, "hud-set-coords\r\n"
39336-
"\tSets the coordinates of a given HUD gauge. Works for custom and retail gauges. Takes 3 arguments...\r\n"
39342+
"\tSets the coordinates of a given HUD gauge. Works for custom and retail gauges. The coordinates can be configured to scale according to "
39343+
" screen resolution via the '$HUD-set-coords base resolution' option in game_settings.tbl. Takes 3 arguments...\r\n"
3933739344
"\t1:\tHUD gauge to be modified\r\n"
3933839345
"\t2:\tCoordinate X component\r\n"
3933939346
"\t2:\tCoordinate Y component"

0 commit comments

Comments
 (0)