Skip to content

Commit 1ffcaaf

Browse files
authored
Allow customizing the fs2 selection effect (#6868)
* allow customizing the fs2 selection effect * undo color color shift
1 parent 06f576b commit 1ffcaaf

12 files changed

Lines changed: 222 additions & 21 deletions

File tree

code/missionui/missionscreencommon.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ void draw_model_icon(int model_id, uint64_t flags, float closeup_zoom, int x, in
16631663
gr_reset_clip();
16641664
}
16651665

1666-
void draw_model_rotating(model_render_params *render_info, int model_id, int x1, int y1, int x2, int y2, float *rotation_buffer, const vec3d *closeup_pos, float closeup_zoom, float rev_rate, uint64_t flags, int resize_mode, int effect)
1666+
void draw_model_rotating(model_render_params *render_info, int model_id, int x1, int y1, int x2, int y2, float *rotation_buffer, const vec3d *closeup_pos, float closeup_zoom, float rev_rate, uint64_t flags, int resize_mode, select_effect_params effect_params)
16671667
{
16681668
//WMC - Can't draw a non-model
16691669
if (model_id < 0)
@@ -1680,7 +1680,7 @@ void draw_model_rotating(model_render_params *render_info, int model_id, int x1,
16801680

16811681
const bool& shadow_disable_override = flags & MR_IS_MISSILE ? Shadow_disable_overrides.disable_mission_select_weapons : Shadow_disable_overrides.disable_mission_select_ships;
16821682

1683-
if (effect == 2) { // FS2 Effect; Phase 0 Expand scanline, Phase 1 scan the grid and wireframe, Phase 2 scan up and reveal the ship, Phase 3 tilt the camera, Phase 4 start rotating the ship
1683+
if (effect_params.effect == 2) { // FS2 Effect; Phase 0 Expand scanline, Phase 1 scan the grid and wireframe, Phase 2 scan up and reveal the ship, Phase 3 tilt the camera, Phase 4 start rotating the ship
16841684
// rotate the ship as much as required for this frame
16851685
if (time >= 3.6f) // Phase 4
16861686
*rotation_buffer += PI2 * flFrametime / rev_rate;
@@ -1743,7 +1743,7 @@ void draw_model_rotating(model_render_params *render_info, int model_id, int x1,
17431743
g3_start_instance_angles(&vmd_zero_vector,&view_angles);
17441744

17451745
if (time < 0.5f) { // Do the expanding scanline in phase 0
1746-
gr_set_color(0,255,0);
1746+
gr_set_color(effect_params.fs2_scanline_color.red, effect_params.fs2_scanline_color.green, effect_params.fs2_scanline_color.blue);
17471747
start.xyz.x = size*start_scale;
17481748
start.xyz.y = 0.0f;
17491749
start.xyz.z = -clip;
@@ -1758,32 +1758,38 @@ void draw_model_rotating(model_render_params *render_info, int model_id, int x1,
17581758
gr_zbuffer_set(GR_ZBUFF_NONE); // Turn off Depthbuffer so we don't get gridlines over the ship or a disappearing scanline
17591759
Glowpoint_use_depth_buffer = false; // Since we don't have one
17601760
if (time >= 0.5f) { // Phase 1 onward draw the grid
1761-
int i;
17621761
start.xyz.y = -offset;
17631762
start.xyz.z = size+offset*0.5f;
17641763
stop.xyz.y = -offset;
17651764
stop.xyz.z = -size+offset*0.5f;
1766-
gr_set_color(0,200,0);
1765+
gr_set_color(effect_params.fs2_grid_color.red, effect_params.fs2_grid_color.green, effect_params.fs2_grid_color.blue);
17671766
g3_start_instance_angles(&vmd_zero_vector,&view_angles);
17681767

17691768
if (time < 1.5f) {
17701769
stop.xyz.z = -clip;
17711770
}
17721771

1773-
for (i = -3; i < 4; i++) {
1774-
start.xyz.x = stop.xyz.x = size*0.333f*i;
1775-
//g3_draw_htl_line(&start,&stop);
1772+
int num_lines = std::max(3, effect_params.fs2_grid_density);
1773+
float x_step = (size * 2.0f) / (num_lines - 1);
1774+
float x_start = -size;
1775+
1776+
for (int i = 0; i < num_lines; ++i) {
1777+
start.xyz.x = stop.xyz.x = x_start + i * x_step;
17761778
g3_render_line_3d(false, &start, &stop);
17771779
}
17781780

17791781
start.xyz.x = size;
17801782
stop.xyz.x = -size;
17811783

1782-
for (i = 3; i > -4; i--) {
1783-
start.xyz.z = stop.xyz.z = size*0.333f*i+offset*0.5f;
1784-
if ((time < 1.5f) && (start.xyz.z <= -clip))
1784+
float z_step = (size * 2.0f) / (num_lines - 1);
1785+
float z_start = size + offset * 0.5f;
1786+
1787+
for (int i = 0; i < num_lines; ++i) {
1788+
float z = z_start - i * z_step;
1789+
if ((time < 1.5f) && (z <= -clip))
17851790
break;
1786-
//g3_draw_htl_line(&start,&stop);
1791+
1792+
start.xyz.z = stop.xyz.z = z;
17871793
g3_render_line_3d(false, &start, &stop);
17881794
}
17891795

@@ -1825,8 +1831,8 @@ void draw_model_rotating(model_render_params *render_info, int model_id, int x1,
18251831
gr_set_view_matrix(&Eye_position, &Eye_matrix);
18261832
}
18271833
gr_zbuffer_set(false);
1828-
gr_set_color(80,49,160);
1829-
render_info->set_color(80, 49, 160);
1834+
gr_set_color(effect_params.fs2_wireframe_color.red, effect_params.fs2_wireframe_color.green, effect_params.fs2_wireframe_color.blue);
1835+
render_info->set_color(effect_params.fs2_wireframe_color.red, effect_params.fs2_wireframe_color.green, effect_params.fs2_wireframe_color.blue);
18301836

18311837
render_info->set_animated_effect(ANIMATED_SHADER_LOADOUTSELECT_FS2, -clip);
18321838

@@ -1847,7 +1853,7 @@ void draw_model_rotating(model_render_params *render_info, int model_id, int x1,
18471853
}
18481854

18491855
if (time < 2.5f) { // Render the scanline in Phase 1 and 2
1850-
gr_set_color(0,255,0);
1856+
gr_set_color(effect_params.fs2_scanline_color.red, effect_params.fs2_scanline_color.green, effect_params.fs2_scanline_color.blue);
18511857
start.xyz.x = size*1.25f;
18521858
start.xyz.y = 0.0f;
18531859
start.xyz.z = -clip;
@@ -1924,7 +1930,7 @@ void draw_model_rotating(model_render_params *render_info, int model_id, int x1,
19241930

19251931
gr_set_color(0,128,0);
19261932

1927-
if (effect == 1) { // FS1 effect
1933+
if (effect_params.effect == 1) { // FS1 effect
19281934
render_info->set_animated_effect(ANIMATED_SHADER_LOADOUTSELECT_FS1, MIN(time*0.5f,2.0f));
19291935
render_info->set_flags(flags);
19301936
} else {

code/missionui/missionscreencommon.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "globalincs/globals.h"
1616
#include "gamesnd/gamesnd.h"
17+
#include "mod_table/mod_table.h"
1718
#include "model/model.h"
1819
#include "ui/ui.h"
1920

@@ -212,6 +213,18 @@ typedef struct loadout_data
212213

213214
extern loadout_data Player_loadout;
214215

216+
struct select_effect_params {
217+
int effect; // effect type (0 = none/rotate, 1 = FS1, 2 = FS2)
218+
color fs2_grid_color; // color of the grid in FS2 effect
219+
color fs2_scanline_color; // color of the scanlines in FS2 effect
220+
int fs2_grid_density; // density of the grid in FS2 effect
221+
color fs2_wireframe_color; // color of the model wireframe in FS2 effect
222+
223+
select_effect_params() : effect(2), fs2_grid_color(Default_fs2_effect_grid_color), fs2_scanline_color(Default_fs2_effect_scanline_color), fs2_grid_density(Default_fs2_effect_grid_density), fs2_wireframe_color(Default_fs2_effect_wireframe_color)
224+
{
225+
}
226+
};
227+
215228
void wss_save_loadout();
216229
void wss_maybe_restore_loadout();
217230
void wss_direct_restore_loadout();
@@ -222,7 +235,7 @@ int restore_wss_data(ubyte *data);
222235

223236
class ship_info;
224237
void draw_model_icon(int model_id, uint64_t flags, float closeup_zoom, int x1, int x2, int y1, int y2, ship_info* sip = NULL, int resize_mode = GR_RESIZE_FULL, const vec3d *closeup_pos = &vmd_zero_vector);
225-
void draw_model_rotating(model_render_params *render_info, int model_id, int x1, int y1, int x2, int y2, float *rotation_buffer, const vec3d *closeup_pos=nullptr, float closeup_zoom = .65f, float rev_rate = REVOLUTION_RATE, uint64_t flags = MR_AUTOCENTER | MR_NO_FOGGING, int resize_mode=GR_RESIZE_FULL, int effect = 2);
238+
void draw_model_rotating(model_render_params *render_info, int model_id, int x1, int y1, int x2, int y2, float *rotation_buffer, const vec3d *closeup_pos=nullptr, float closeup_zoom = .65f, float rev_rate = REVOLUTION_RATE, uint64_t flags = MR_AUTOCENTER | MR_NO_FOGGING, int resize_mode=GR_RESIZE_FULL, select_effect_params effect_params = select_effect_params{});
226239

227240
void common_set_team_pointers(int team);
228241
void common_reset_team_pointers();

code/missionui/missionshipchoice.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,13 @@ void ship_select_do(float frametime)
14521452
render_info.set_replacement_textures(ShipSelectModelNum, sip->replacement_textures);
14531453
}
14541454

1455+
select_effect_params params;
1456+
params.effect = sip->selection_effect;
1457+
params.fs2_grid_color = sip->fs2_effect_grid_color;
1458+
params.fs2_scanline_color = sip->fs2_effect_scanline_color;
1459+
params.fs2_grid_density = sip->fs2_effect_grid_density;
1460+
params.fs2_wireframe_color = sip->fs2_effect_wireframe_color;
1461+
14551462
draw_model_rotating(
14561463
&render_info,
14571464
ShipSelectModelNum,
@@ -1465,7 +1472,7 @@ void ship_select_do(float frametime)
14651472
rev_rate,
14661473
MR_AUTOCENTER | MR_NO_FOGGING,
14671474
GR_RESIZE_MENU,
1468-
sip->selection_effect);
1475+
params);
14691476
}
14701477
}
14711478

code/missionui/missionweaponchoice.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,13 @@ void weapon_select_do(float frametime)
28132813
modelIdx = model_load(wip->pofbitmap_name, nullptr, ErrorType::FATAL_ERROR);
28142814
}
28152815

2816+
select_effect_params params;
2817+
params.effect = wip->selection_effect;
2818+
params.fs2_grid_color = wip->fs2_effect_grid_color;
2819+
params.fs2_scanline_color = wip->fs2_effect_scanline_color;
2820+
params.fs2_grid_density = wip->fs2_effect_grid_density;
2821+
params.fs2_wireframe_color = wip->fs2_effect_wireframe_color;
2822+
28162823
model_render_params render_info;
28172824
draw_model_rotating(&render_info,
28182825
modelIdx,
@@ -2826,7 +2833,7 @@ void weapon_select_do(float frametime)
28262833
REVOLUTION_RATE,
28272834
MR_IS_MISSILE | MR_AUTOCENTER | MR_NO_FOGGING,
28282835
GR_RESIZE_MENU,
2829-
wip->selection_effect);
2836+
params);
28302837
} else if ( Weapon_anim_class != -1 && ( Selected_wl_class == Weapon_anim_class )) {
28312838
Assert(Selected_wl_class >= 0 && Selected_wl_class < weapon_info_size());
28322839
if ( Weapon_anim_class != Selected_wl_class )

code/mod_table/mod_table.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ bool Use_3d_overhead_ship;
4646
overhead_style Default_overhead_ship_style;
4747
int Default_ship_select_effect;
4848
int Default_weapon_select_effect;
49+
color Default_fs2_effect_grid_color;
50+
color Default_fs2_effect_scanline_color;
51+
color Default_fs2_effect_wireframe_color;
52+
int Default_fs2_effect_grid_density;
4953
int Default_fiction_viewer_ui;
5054
bool Enable_external_shaders;
5155
bool Enable_external_default_scripts;
@@ -1217,6 +1221,44 @@ void parse_mod_table(const char *filename)
12171221
mprintf(("Game Settings Table: Using 3D weapon icons\n"));
12181222
}
12191223

1224+
if (optional_string("$FS2 effect grid color:")) {
1225+
int rgb[3];
1226+
stuff_int_list(rgb, 3);
1227+
CLAMP(rgb[0], 0, 255);
1228+
CLAMP(rgb[1], 0, 255);
1229+
CLAMP(rgb[2], 0, 255);
1230+
gr_init_color(&Default_fs2_effect_grid_color, rgb[0], rgb[1], rgb[2]);
1231+
}
1232+
1233+
if (optional_string("$FS2 effect scanline color:")) {
1234+
int rgb[3];
1235+
stuff_int_list(rgb, 3);
1236+
CLAMP(rgb[0], 0, 255);
1237+
CLAMP(rgb[1], 0, 255);
1238+
CLAMP(rgb[2], 0, 255);
1239+
gr_init_color(&Default_fs2_effect_scanline_color, rgb[0], rgb[1], rgb[2]);
1240+
}
1241+
1242+
if (optional_string("$FS2 effect grid density:")) {
1243+
int tmp;
1244+
stuff_int(&tmp);
1245+
// only set value if it is above 0
1246+
if (tmp > 0) {
1247+
Default_fs2_effect_grid_density = tmp;
1248+
} else {
1249+
Warning(LOCATION, "The $FS2 effect grid density must be above 0.\n");
1250+
}
1251+
}
1252+
1253+
if (optional_string("$FS2 effect wireframe color:")) {
1254+
int rgb[3];
1255+
stuff_int_list(rgb, 3);
1256+
CLAMP(rgb[0], 0, 255);
1257+
CLAMP(rgb[1], 0, 255);
1258+
CLAMP(rgb[2], 0, 255);
1259+
gr_init_color(&Default_fs2_effect_wireframe_color, rgb[0], rgb[1], rgb[2]);
1260+
}
1261+
12201262
if (optional_string("$Use 3d overhead ship:")) {
12211263
stuff_boolean(&Use_3d_overhead_ship);
12221264
if (Use_3d_overhead_ship)
@@ -1658,6 +1700,10 @@ void mod_table_reset()
16581700
Always_show_directive_value_count = false;
16591701
Default_ship_select_effect = 2;
16601702
Default_weapon_select_effect = 2;
1703+
gr_init_color(&Default_fs2_effect_grid_color, 0, 200, 0);
1704+
gr_init_color(&Default_fs2_effect_scanline_color, 0, 255, 0);
1705+
Default_fs2_effect_grid_density = 7; // Default original value
1706+
gr_init_color(&Default_fs2_effect_wireframe_color, 80, 49, 160);
16611707
Default_overhead_ship_style = OH_TOP_VIEW;
16621708
Default_fiction_viewer_ui = -1;
16631709
Enable_external_shaders = false;

code/mod_table/mod_table.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ extern bool Use_3d_weapon_select;
5959
extern int Default_weapon_select_effect;
6060
extern bool Use_3d_weapon_icons;
6161
extern bool Use_3d_overhead_ship;
62+
extern color Default_fs2_effect_grid_color;
63+
extern color Default_fs2_effect_scanline_color;
64+
extern color Default_fs2_effect_wireframe_color;
65+
extern int Default_fs2_effect_grid_density;
6266
extern overhead_style Default_overhead_ship_style;
6367
extern int Default_fiction_viewer_ui;
6468
extern bool Enable_external_shaders;

code/scripting/api/objs/shipclass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,13 @@ ADE_FUNC(renderSelectModel,
12621262
render_info.set_replacement_textures(modelNum, sip->replacement_textures);
12631263
}
12641264

1265+
select_effect_params params;
1266+
params.effect = effect;
1267+
params.fs2_grid_color = sip->fs2_effect_grid_color;
1268+
params.fs2_scanline_color = sip->fs2_effect_scanline_color;
1269+
params.fs2_grid_density = sip->fs2_effect_grid_density;
1270+
params.fs2_wireframe_color = sip->fs2_effect_wireframe_color;
1271+
12651272
draw_model_rotating(&render_info,
12661273
modelNum,
12671274
x1,
@@ -1274,7 +1281,7 @@ ADE_FUNC(renderSelectModel,
12741281
rev_rate,
12751282
MR_AUTOCENTER | MR_NO_FOGGING,
12761283
GR_RESIZE_NONE,
1277-
effect);
1284+
params);
12781285

12791286
return ade_set_args(L, "b", true);
12801287
}

code/scripting/api/objs/weaponclass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,13 @@ ADE_FUNC(renderSelectModel,
11511151

11521152
model_render_params render_info;
11531153

1154+
select_effect_params params;
1155+
params.effect = effect;
1156+
params.fs2_grid_color = wip->fs2_effect_grid_color;
1157+
params.fs2_scanline_color = wip->fs2_effect_scanline_color;
1158+
params.fs2_grid_density = wip->fs2_effect_grid_density;
1159+
params.fs2_wireframe_color = wip->fs2_effect_wireframe_color;
1160+
11541161
draw_model_rotating(&render_info,
11551162
modelNum,
11561163
x1,
@@ -1163,7 +1170,7 @@ ADE_FUNC(renderSelectModel,
11631170
REVOLUTION_RATE,
11641171
MR_IS_MISSILE | MR_AUTOCENTER | MR_NO_FOGGING,
11651172
GR_RESIZE_NONE,
1166-
effect);
1173+
params);
11671174

11681175
return ade_set_args(L, "b", true);
11691176
}

code/ship/ship.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,10 @@ void ship_info::clone(const ship_info& other)
12091209
strcpy_s(anim_filename, other.anim_filename);
12101210
strcpy_s(overhead_filename, other.overhead_filename);
12111211
selection_effect = other.selection_effect;
1212+
fs2_effect_grid_color = other.fs2_effect_grid_color;
1213+
fs2_effect_scanline_color = other.fs2_effect_scanline_color;
1214+
fs2_effect_grid_density = other.fs2_effect_grid_density;
1215+
fs2_effect_wireframe_color = other.fs2_effect_wireframe_color;
12121216

12131217
wingmen_status_dot_override = other.wingmen_status_dot_override;
12141218

@@ -1549,6 +1553,10 @@ void ship_info::move(ship_info&& other)
15491553
std::swap(anim_filename, other.anim_filename);
15501554
std::swap(overhead_filename, other.overhead_filename);
15511555
selection_effect = other.selection_effect;
1556+
fs2_effect_grid_color = other.fs2_effect_grid_color;
1557+
fs2_effect_scanline_color = other.fs2_effect_scanline_color;
1558+
fs2_effect_grid_density = other.fs2_effect_grid_density;
1559+
fs2_effect_wireframe_color = other.fs2_effect_wireframe_color;
15521560

15531561
wingmen_status_dot_override = other.wingmen_status_dot_override;
15541562

@@ -1926,6 +1934,10 @@ ship_info::ship_info()
19261934
overhead_filename[0] = '\0';
19271935

19281936
selection_effect = Default_ship_select_effect;
1937+
fs2_effect_grid_color = Default_fs2_effect_grid_color;
1938+
fs2_effect_scanline_color = Default_fs2_effect_scanline_color;
1939+
fs2_effect_grid_density = Default_fs2_effect_grid_density;
1940+
fs2_effect_wireframe_color = Default_fs2_effect_wireframe_color;
19291941

19301942
wingmen_status_dot_override = -1;
19311943

@@ -3036,6 +3048,44 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
30363048
sip->selection_effect = 0;
30373049
}
30383050

3051+
if (optional_string("$FS2 effect grid color:")) {
3052+
int rgb[3];
3053+
stuff_int_list(rgb, 3);
3054+
CLAMP(rgb[0], 0, 255);
3055+
CLAMP(rgb[1], 0, 255);
3056+
CLAMP(rgb[2], 0, 255);
3057+
gr_init_color(&sip->fs2_effect_grid_color, rgb[0], rgb[1], rgb[2]);
3058+
}
3059+
3060+
if (optional_string("$FS2 effect scanline color:")) {
3061+
int rgb[3];
3062+
stuff_int_list(rgb, 3);
3063+
CLAMP(rgb[0], 0, 255);
3064+
CLAMP(rgb[1], 0, 255);
3065+
CLAMP(rgb[2], 0, 255);
3066+
gr_init_color(&sip->fs2_effect_scanline_color, rgb[0], rgb[1], rgb[2]);
3067+
}
3068+
3069+
if (optional_string("$FS2 effect grid density:")) {
3070+
int tmp;
3071+
stuff_int(&tmp);
3072+
// only set value if it is above 0
3073+
if (tmp > 0) {
3074+
sip->fs2_effect_grid_density = tmp;
3075+
} else {
3076+
Warning(LOCATION, "The $FS2 effect grid density must be above 0.\n");
3077+
}
3078+
}
3079+
3080+
if (optional_string("$FS2 effect wireframe color:")) {
3081+
int rgb[3];
3082+
stuff_int_list(rgb, 3);
3083+
CLAMP(rgb[0], 0, 255);
3084+
CLAMP(rgb[1], 0, 255);
3085+
CLAMP(rgb[2], 0, 255);
3086+
gr_init_color(&sip->fs2_effect_wireframe_color, rgb[0], rgb[1], rgb[2]);
3087+
}
3088+
30393089
// This only works if the hud gauge defined uses $name assignment
30403090
if (optional_string("$HUD Gauge Configs:")) {
30413091
SCP_vector<SCP_string> gauge_configs;

code/ship/ship.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,10 @@ class ship_info
13541354
char anim_filename[MAX_FILENAME_LEN]; // filename for animation that plays in ship selection
13551355
char overhead_filename[MAX_FILENAME_LEN]; // filename for animation that plays weapons loadout
13561356
int selection_effect;
1357+
color fs2_effect_grid_color; // color of the grid effect in the ship selection screen
1358+
color fs2_effect_scanline_color; // color of the scanline effect in the ship selection screen
1359+
int fs2_effect_grid_density; // density of the grid effect in the ship selection screen
1360+
color fs2_effect_wireframe_color; // color of the wireframe effect in the ship selection screen
13571361

13581362
int wingmen_status_dot_override; // optional wingmen dot status animation to use instead of default --wookieejedi
13591363

0 commit comments

Comments
 (0)