Skip to content

Commit

Permalink
Allow per-stage briefing grid colors (#6448)
Browse files Browse the repository at this point in the history
* Allow per-stage briefing grid colors

* parameter name

* remove redundant initializer

* const const const

* check for 25_0 mission data

* 24.3 instead of 25.0

* clang
  • Loading branch information
MjnMixael authored Jan 5, 2025
1 parent 297a938 commit 402ca07
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 16 deletions.
18 changes: 18 additions & 0 deletions code/graphics/2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,24 @@ void gr_set_color_fast(const color *dst)
gr_screen.current_color = *dst;
}

//Compares the RGBA values of two colors. Returns true if the colors are identical
bool gr_compare_color_values(const color& clr1, const color& clr2)
{
if (clr1.red != clr2.red) {
return false;
}
if (clr1.green != clr2.green) {
return false;
}
if (clr1.blue != clr2.blue) {
return false;
}
if (clr1.alpha != clr2.alpha) {
return false;
}
return true;
}

// shader functions
void gr_create_shader(shader *shade, ubyte r, ubyte g, ubyte b, ubyte c )
{
Expand Down
1 change: 1 addition & 0 deletions code/graphics/2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ void gr_init_color(color *c, int r, int g, int b);
void gr_init_alphacolor( color *clr, int r, int g, int b, int alpha, int type = AC_TYPE_HUD );
void gr_set_color( int r, int g, int b );
void gr_set_color_fast(const color *dst);
bool gr_compare_color_values(const color& clr1, const color& clr2);

// shader functions
void gr_create_shader(shader *shade, ubyte r, ubyte g, ubyte b, ubyte c);
Expand Down
16 changes: 8 additions & 8 deletions code/mission/missionbriefcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ void brief_render_icons(int stage_num, float frametime);
void brief_maybe_create_new_grid(grid *gridp, vec3d *pos, matrix *orient, int force = 0);
grid *brief_create_grid(grid *gridp, vec3d *forward, vec3d *right, vec3d *center, int nrows, int ncols, float square_size);
grid *brief_create_default_grid(void);
void brief_render_grid(grid *gridp);
void brief_render_grid(grid *gridp, const color& color);
void brief_modify_grid(grid *gridp);
void brief_rpd_line(vec3d *v0, vec3d *v1);
void brief_rpd_line(vec3d *v0, vec3d *v1, const color& color);
void brief_set_text_color(char color_tag);
extern void get_camera_limits(const matrix *start_camera, const matrix *end_camera, float time, vec3d *acc_max, vec3d *w_max);
int brief_text_wipe_finished();
Expand Down Expand Up @@ -1319,7 +1319,7 @@ void brief_render_map(int stage_num, float frametime)
brief_maybe_create_new_grid(The_grid, &Current_cam_pos, &Current_cam_orient);

if (Briefing->stages[stage_num].draw_grid)
brief_render_grid(The_grid);
brief_render_grid(The_grid, Briefing->stages[stage_num].grid_color);

brief_render_fade_outs(frametime);

Expand Down Expand Up @@ -2281,13 +2281,13 @@ grid *brief_create_default_grid(void)
/**
* Rotate and project points and draw a line.
*/
void brief_rpd_line(vec3d *v0, vec3d *v1)
void brief_rpd_line(vec3d *v0, vec3d *v1, const color& clr)
{
vertex tv0, tv1;
g3_rotate_vertex(&tv0, v0);
g3_rotate_vertex(&tv1, v1);

gr_set_color_fast(&Color_briefing_grid);
gr_set_color_fast(&clr);
g3_draw_line(&tv0, &tv1);
}

Expand All @@ -2296,7 +2296,7 @@ void brief_rpd_line(vec3d *v0, vec3d *v1)
*
* @param gridp Grid defined in a grid struct to render
*/
void brief_render_grid(grid *gridp)
void brief_render_grid(grid *gridp, const color& gridc)
{
int i, ncols, nrows;

Expand All @@ -2312,11 +2312,11 @@ void brief_render_grid(grid *gridp)

// Draw the column lines.
for (i=0; i<=ncols; i++)
brief_rpd_line(&gridp->gpoints1[i], &gridp->gpoints2[i]);
brief_rpd_line(&gridp->gpoints1[i], &gridp->gpoints2[i], gridc);

// Draw the row lines.
for (i=0; i<=nrows; i++)
brief_rpd_line(&gridp->gpoints3[i], &gridp->gpoints4[i]);
brief_rpd_line(&gridp->gpoints3[i], &gridp->gpoints4[i], gridc);
}

void brief_modify_grid(grid *gridp)
Expand Down
7 changes: 5 additions & 2 deletions code/mission/missionbriefcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define __MISSIONBRIEFCOMMON_H__

#include "globalincs/globals.h"
#include "globalincs/alphacolors.h"

#include "anim/packunpack.h"
#include "graphics/generic.h"
Expand Down Expand Up @@ -160,14 +161,16 @@ class brief_stage
int num_lines;
brief_line *lines;
bool draw_grid;
color grid_color;

brief_stage( )
: text( ), camera_time( 0 ), flags( 0 ), formula( -1 ), num_icons(0), icons(NULL), num_lines(0), lines(NULL),
draw_grid( true )
: camera_time( 0 ), flags( 0 ), formula( -1 ), num_icons(0), icons(nullptr), num_lines(0), lines(nullptr),
draw_grid(true)
{
voice[ 0 ] = 0;
camera_pos = vmd_zero_vector;
camera_orient = vmd_identity_matrix;
grid_color = Color_briefing_grid;
}
};

Expand Down
25 changes: 21 additions & 4 deletions code/mission/missionparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,14 @@ void parse_briefing(mission * /*pm*/, int flags)
if (optional_string("$no_grid"))
bs->draw_grid = false;

if (optional_string("$grid_color:")) {
int rgba[4] = {0, 0, 0, 0};
stuff_int_list(rgba, 4, RAW_INTEGER_TYPE);
gr_init_alphacolor(&bs->grid_color, rgba[0], rgba[1], rgba[2], rgba[3]);
} else {
bs->grid_color = Color_briefing_grid;
}

if ( optional_string("$num_lines:") ) {
stuff_int(&bs->num_lines);

Expand Down Expand Up @@ -9054,9 +9062,18 @@ bool check_for_24_1_data()
}
}

if ((Asteroid_field.debris_genre == DG_DEBRIS && !Asteroid_field.field_debris_type.empty()) ||
(Asteroid_field.debris_genre == DG_ASTEROID && !Asteroid_field.field_asteroid_type.empty()))
return true;
return (Asteroid_field.debris_genre == DG_DEBRIS && !Asteroid_field.field_debris_type.empty()) ||
(Asteroid_field.debris_genre == DG_ASTEROID && !Asteroid_field.field_asteroid_type.empty());
}

bool check_for_24_3_data()
{
for (int i = 0; i < Num_teams; i++) {
for (int j = 0; j < Briefings[i].num_stages; j++) {
if (!gr_compare_color_values(Briefings[i].stages[j].grid_color, Color_briefing_grid)) {
return true;
}
}
}
return false;
}
}
1 change: 1 addition & 0 deletions code/mission/missionparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern const gameversion::version LEGACY_MISSION_VERSION;
// a "soft version bump" rather than a hard bump because not all missions are affected.
extern bool check_for_23_3_data();
extern bool check_for_24_1_data();
extern bool check_for_24_3_data();

#define WING_PLAYER_BASE 0x80000 // used by Fred to tell ship_index in a wing points to a player

Expand Down
4 changes: 4 additions & 0 deletions fred2/briefingeditordlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mission/missionparse.h"
#include "FredRender.h"
#include "Management.h"
#include "globalincs/alphacolors.h"
#include "globalincs/linklist.h"
#include "MainFrm.h"
#include "bmpman/bmpman.h"
Expand Down Expand Up @@ -934,6 +935,7 @@ void briefing_editor_dlg::copy_stage(int from, int to)
Briefing->stages[to].camera_time = 500;
Briefing->stages[to].num_icons = 0;
Briefing->stages[to].formula = Locked_sexp_true;
Briefing->stages[to].grid_color = Color_briefing_grid;
return;
}

Expand All @@ -947,6 +949,8 @@ void briefing_editor_dlg::copy_stage(int from, int to)
Briefing->stages[to].num_icons = Briefing->stages[from].num_icons;
Briefing->stages[to].num_lines = Briefing->stages[from].num_lines;
Briefing->stages[to].formula = Briefing->stages[from].formula;
// For now let's just always set this back to default. Eventually when we have a UI color picker in qtFRED, we can copy from stage to stage
Briefing->stages[to].grid_color = Color_briefing_grid;

memmove( Briefing->stages[to].icons, Briefing->stages[from].icons, sizeof(brief_icon)*MAX_STAGE_ICONS );
memmove( Briefing->stages[to].lines, Briefing->stages[from].lines, sizeof(brief_line)*MAX_BRIEF_STAGE_LINES );
Expand Down
19 changes: 18 additions & 1 deletion fred2/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "asteroid/asteroid.h"
#include "cfile/cfile.h"
#include "gamesnd/eventmusic.h"
#include "globalincs/alphacolors.h"
#include "globalincs/linklist.h"
#include "globalincs/version.h"
#include "hud/hudsquadmsg.h"
Expand Down Expand Up @@ -1134,6 +1135,13 @@ int CFred_mission_save::save_briefing()
}
}

if (!gr_compare_color_values(bs->grid_color, Color_briefing_grid)) {
if (Mission_save_format != FSO_FORMAT_RETAIL) {
fout("\n$grid_color:");
fout("(%d, %d, %d, %d)", bs->grid_color.red, bs->grid_color.green, bs->grid_color.blue, bs->grid_color.alpha);
}
}

required_string_fred("$num_lines:");
parse_comments();
fout(" %d", bs->num_lines);
Expand Down Expand Up @@ -3150,7 +3158,16 @@ void CFred_mission_save::save_mission_internal(const char *pathname)
// Additional incremental version update for some features
auto version_23_3 = gameversion::version(23, 3);
auto version_24_1 = gameversion::version(24, 1);
if (MISSION_VERSION >= version_24_1)
auto version_24_3 = gameversion::version(24, 3);
if (MISSION_VERSION >= version_24_3)
{
Warning(LOCATION, "Notify an SCP coder: now that the required mission version is at least 24.3, the check_for_24_3_data(), the check_for_24_1_data() and check_for_23_3_data() code can be removed");
}
else if (check_for_24_3_data())
{
The_mission.required_fso_version = version_24_3;
}
else if (MISSION_VERSION >= version_24_1)
{
Warning(LOCATION, "Notify an SCP coder: now that the required mission version is at least 24.1, the check_for_24_1_data() and check_for_23_3_data() code can be removed");
}
Expand Down
19 changes: 18 additions & 1 deletion qtfred/src/mission/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cfile/cfile.h>
#include <hud/hudsquadmsg.h>
#include <gamesnd/eventmusic.h>
#include <globalincs/alphacolors.h>
#include <globalincs/linklist.h>
#include <globalincs/version.h>
#include <iff_defs/iff_defs.h>
Expand Down Expand Up @@ -1158,6 +1159,13 @@ int CFred_mission_save::save_briefing()
}
}

if (!gr_compare_color_values(bs->grid_color, Color_briefing_grid)) {
if (save_format != MissionFormat::RETAIL) {
fout("\n$grid_color:");
fout("(%d, %d, %d, %d)", bs->grid_color.red, bs->grid_color.green, bs->grid_color.blue, bs->grid_color.alpha);
}
}

required_string_fred("$num_lines:");
parse_comments();
fout(" %d", bs->num_lines);
Expand Down Expand Up @@ -3059,7 +3067,16 @@ void CFred_mission_save::save_mission_internal(const char* pathname)
// Additional incremental version update for some features
auto version_23_3 = gameversion::version(23, 3);
auto version_24_1 = gameversion::version(24, 1);
if (MISSION_VERSION >= version_24_1)
auto version_24_3 = gameversion::version(24, 3);
if (MISSION_VERSION >= version_24_3)
{
Warning(LOCATION, "Notify an SCP coder: now that the required mission version is at least 24.3, the check_for_24_3_data(), the check_for_24_1_data() and check_for_23_3_data() code can be removed");
}
else if (check_for_24_3_data())
{
The_mission.required_fso_version = version_24_3;
}
else if (MISSION_VERSION >= version_24_1)
{
Warning(LOCATION, "Notify an SCP coder: now that the required mission version is at least 24.1, the check_for_24_1_data() and check_for_23_3_data() code can be removed");
}
Expand Down

0 comments on commit 402ca07

Please sign in to comment.