Skip to content

Commit 811b412

Browse files
authored
Make showing 2D radar icons a toggle-able option (#7409)
* Make showing 2D radar icons a toggle-able option * better options
1 parent 09a848a commit 811b412

7 files changed

Lines changed: 50 additions & 6 deletions

File tree

code/localization/localize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool *Lcl_unexpected_tstring_check = nullptr;
6464
// NOTE: with map storage of XSTR strings, the indexes no longer need to be contiguous,
6565
// but internal strings should still increment XSTR_SIZE to avoid collisions.
6666
// retail XSTR_SIZE = 1570
67-
// #define XSTR_SIZE 1915 // This is the next available ID
67+
// #define XSTR_SIZE 1918 // This is the next available ID
6868

6969
// struct to allow for strings.tbl-determined x offset
7070
// offset is 0 for english, by default

code/radar/radar.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ void HudGaugeRadarStd::drawBlips(int blip_type, int bright, int distort)
161161
}
162162
else
163163
{
164-
if (b->radar_image_2d == -1 && b->radar_color_image_2d == -1)
164+
bool show_icon = (Radar_2d_icon_mode == RadarIconMode::On ||
165+
(Radar_2d_icon_mode == RadarIconMode::TargetOnly && (b->flags & BLIP_CURRENT_TARGET)));
166+
if (!show_icon || (b->radar_image_2d == -1 && b->radar_color_image_2d == -1))
165167
drawContactCircle(x, y, b->rad);
166168
else
167169
drawContactImage(x, y, b->rad, b->radar_image_2d, b->radar_color_image_2d, b->radar_image_size);

code/radar/radardradis.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,14 @@ void HudGaugeRadarDradis::drawBlips(int blip_type, int bright, int distort)
319319
} else {
320320
if (b->flags & BLIP_DRAW_DISTORTED) {
321321
blipDrawFlicker(b, &pos, alpha);
322-
} else if (b->radar_image_2d >= 0 || b->radar_color_image_2d >= 0) {
323-
drawContact(&pos, b->radar_image_2d, b->radar_color_image_2d, b->dist, alpha, scale_factor);
324322
} else {
325-
drawContact(&pos, -1, unknown_contact_icon, b->dist, alpha, scale_factor);
323+
bool show_icon = (Radar_2d_icon_mode == RadarIconMode::On ||
324+
(Radar_2d_icon_mode == RadarIconMode::TargetOnly && (b->flags & BLIP_CURRENT_TARGET)));
325+
if (show_icon && (b->radar_image_2d >= 0 || b->radar_color_image_2d >= 0)) {
326+
drawContact(&pos, b->radar_image_2d, b->radar_color_image_2d, b->dist, alpha, scale_factor);
327+
} else {
328+
drawContact(&pos, -1, unknown_contact_icon, b->dist, alpha, scale_factor);
329+
}
326330
}
327331
}
328332
}

code/radar/radarorb.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ void HudGaugeRadarOrb::drawBlips(int blip_type, int bright, int distort)
281281
}
282282
else
283283
{
284-
if (b->radar_image_2d >= 0 || b->radar_color_image_2d >= 0)
284+
bool show_icon = (Radar_2d_icon_mode == RadarIconMode::On ||
285+
(Radar_2d_icon_mode == RadarIconMode::TargetOnly && (b->flags & BLIP_CURRENT_TARGET)));
286+
if (show_icon && (b->radar_image_2d >= 0 || b->radar_color_image_2d >= 0))
285287
{
286288
drawContactImage(&pos, b->rad, b->radar_image_2d, b->radar_color_image_2d, b->radar_projection_size);
287289
}

code/radar/radarsetup.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "localization/localize.h"
2222
#include "network/multi.h"
2323
#include "object/object.h"
24+
#include "options/Option.h"
2425
#include "playerman/player.h"
2526
#include "radar/radar.h"
2627
#include "radar/radarorb.h"
@@ -88,6 +89,31 @@ int See_all = 0;
8889

8990
DCF_BOOL(see_all, See_all);
9091

92+
RadarIconMode Radar_2d_icon_mode = RadarIconMode::On;
93+
94+
static auto RadarIconModeOption __UNUSED = options::OptionBuilder<RadarIconMode>("HUD.Radar2dIconMode",
95+
std::pair<const char*, int>{"Radar 2D Icons", 1915},
96+
std::pair<const char*, int>{"Controls how custom 2D ship icons are displayed on the radar", 1916})
97+
.category(std::make_pair("Game", 1824))
98+
.values({{RadarIconMode::Off, {"Off", 1286}},
99+
{RadarIconMode::On, {"On", 1285}},
100+
{RadarIconMode::TargetOnly, {"Target Only", 1917}}})
101+
.default_val(RadarIconMode::On)
102+
.bind_to(&Radar_2d_icon_mode)
103+
.importance(56)
104+
.finish();
105+
106+
void radar_check_2d_icon_options()
107+
{
108+
bool has_icons = std::any_of(Ship_info.begin(), Ship_info.end(), [](const ship_info& sip) {
109+
return sip.radar_image_2d_idx >= 0 || sip.radar_color_image_2d_idx >= 0;
110+
});
111+
112+
if (!has_icons) {
113+
options::OptionsManager::instance()->removeOption(RadarIconModeOption);
114+
}
115+
}
116+
91117
void radar_stuff_blip_info(object *objp, int is_bright, color **blip_color, int *blip_type)
92118
{
93119
ship *shipp = NULL;

code/radar/radarsetup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,18 @@ enum RadarVisibility
8989
DISTORTED //!< Visible but not fully
9090
};
9191

92+
enum class RadarIconMode {
93+
Off = 0,
94+
On = 1,
95+
TargetOnly = 2
96+
};
97+
extern RadarIconMode Radar_2d_icon_mode;
98+
9299
void radar_frame_init();
93100
void radar_mission_init();
94101
void radar_plot_object( object *objp );
95102
RadarVisibility radar_is_visible( object *objp );
103+
void radar_check_2d_icon_options();
96104

97105
extern sound_handle Radar_static_looping;
98106

code/ship/ship.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6753,6 +6753,8 @@ void ship_init()
67536753

67546754
// We shouldn't already have any subsystem pointers at this point.
67556755
Assertion(Ship_subsystems.empty(), "Some pre-allocated subsystems didn't get cleared out: " SIZE_T_ARG " batches present during ship_init(); get a coder!\n", Ship_subsystems.size());
6756+
6757+
radar_check_2d_icon_options();
67566758
}
67576759
}
67586760

0 commit comments

Comments
 (0)