Skip to content

Commit 1f7903f

Browse files
authored
add a few hud lua methods (#6692)
1 parent 2576515 commit 1f7903f

5 files changed

Lines changed: 74 additions & 3 deletions

File tree

code/hud/hud.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static int Damage_flash_timer;
291291

292292
HudGauge::HudGauge():
293293
base_w(0), base_h(0), gauge_type(-1), font_num(font::FONT1), lock_color(false), sexp_lock_color(false), reticle_follow(false),
294-
active(false), off_by_default(false), sexp_override(false), pop_up(false), disabled_views(0), only_render_in_chase_view(false), render_for_cockpit_toggle(0), custom_gauge(false),
294+
active(false), off_by_default(false), sexp_override(false), pop_up(false), disabled_views(0), scripting_render_override(false), only_render_in_chase_view(false), render_for_cockpit_toggle(0), custom_gauge(false),
295295
texture_target(-1), canvas_w(-1), canvas_h(-1), target_w(-1), target_h(-1)
296296
{
297297
position[0] = 0;
@@ -323,7 +323,7 @@ texture_target(-1), canvas_w(-1), canvas_h(-1), target_w(-1), target_h(-1)
323323
HudGauge::HudGauge(int _gauge_object, int _gauge_config, bool _slew, bool _message, int _disabled_views, int r, int g, int b):
324324
base_w(0), base_h(0), gauge_type(_gauge_config), gauge_object(_gauge_object), font_num(font::FONT1), lock_color(false), sexp_lock_color(false),
325325
reticle_follow(_slew), active(false), off_by_default(false), sexp_override(false), pop_up(false), message_gauge(_message),
326-
disabled_views(_disabled_views), only_render_in_chase_view(false), render_for_cockpit_toggle(0), custom_gauge(false), textoffset_x(0), textoffset_y(0), texture_target(-1),
326+
disabled_views(_disabled_views), scripting_render_override(false), only_render_in_chase_view(false), render_for_cockpit_toggle(0), custom_gauge(false), textoffset_x(0), textoffset_y(0), texture_target(-1),
327327
canvas_w(-1), canvas_h(-1), target_w(-1), target_h(-1)
328328
{
329329
Assertion(_gauge_config <= NUM_HUD_GAUGES && _gauge_config >= 0, "Gauge has an invalid config ID!");
@@ -367,7 +367,7 @@ canvas_w(-1), canvas_h(-1), target_w(-1), target_h(-1)
367367
HudGauge::HudGauge(int _gauge_config, bool _slew, int r, int g, int b, char* _custom_name, char* _custom_text, char* frame_fname, int txtoffset_x, int txtoffset_y):
368368
base_w(0), base_h(0), gauge_type(_gauge_config), gauge_object(HUD_OBJECT_CUSTOM), font_num(font::FONT1), lock_color(false), sexp_lock_color(false),
369369
reticle_follow(_slew), active(false), off_by_default(false), sexp_override(false), pop_up(false), message_gauge(false),
370-
disabled_views(VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY), can_popup(false), use_iff_color(false), use_tag_color(false), only_render_in_chase_view(false),
370+
disabled_views(VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY), scripting_render_override(false), can_popup(false), use_iff_color(false), use_tag_color(false), only_render_in_chase_view(false),
371371
render_for_cockpit_toggle(0), custom_gauge(true), textoffset_x(txtoffset_x), textoffset_y(txtoffset_y), texture_target(-1), canvas_w(-1), canvas_h(-1), target_w(-1), target_h(-1)
372372
{
373373
position[0] = 0;
@@ -780,6 +780,16 @@ void HudGauge::updateSexpOverride(bool sexp)
780780
sexp_override = sexp;
781781
}
782782

783+
bool HudGauge::getScriptingOverride() const
784+
{
785+
return scripting_render_override;
786+
}
787+
788+
void HudGauge::updateScriptingOverride(bool toggle)
789+
{
790+
scripting_render_override = toggle;
791+
}
792+
783793
void HudGauge::updatePopUp(bool pop_up_flag)
784794
{
785795
pop_up = pop_up_flag;
@@ -1415,6 +1425,10 @@ bool HudGauge::canRender() const
14151425
}
14161426
}
14171427

1428+
if (scripting_render_override) {
1429+
return false;
1430+
}
1431+
14181432
return true;
14191433
}
14201434

@@ -4342,6 +4356,21 @@ HudGauge *hud_get_gauge(const char *name, bool check_all_custom_gauges)
43424356
if (idx >= 0 && idx < (int)default_hud_gauges.size())
43434357
gauge = default_hud_gauges[idx].get();
43444358
}
4359+
4360+
// If we still haven't found it then we might be using ship specific builtin gauges and not a default_hud_gauge
4361+
if (gauge == nullptr) {
4362+
ship_info* player_sip = nullptr;
4363+
if (Player_ship && Player_ship->ship_info_index >= 0)
4364+
player_sip = &Ship_info[Player_ship->ship_info_index];
4365+
4366+
if (player_sip != nullptr) {
4367+
for (auto& ship_gauge : player_sip->hud_gauges) {
4368+
if (!stricmp(name, ship_gauge->getConfigName().c_str())) {
4369+
gauge = ship_gauge.get();
4370+
}
4371+
}
4372+
}
4373+
}
43454374
return gauge;
43464375
}
43474376

code/hud/hud.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ class HudGauge
241241
int popup_timer;
242242
bool message_gauge;
243243
int disabled_views;
244+
bool scripting_render_override;
244245

245246
// Config stuff
246247
SCP_string config_name;
@@ -322,6 +323,8 @@ class HudGauge
322323
void updateActive(bool show);
323324
void updatePopUp(bool pop_up_flag);
324325
void updateSexpOverride(bool sexp);
326+
bool getScriptingOverride() const;
327+
void updateScriptingOverride(bool toggle);
325328
void initChase_view_only(bool chase_view_only);
326329
void initCockpit_view_choice(int cockpit_view_choice);
327330
void initVisible_in_config(bool visible);

code/hud/hudsquadmsg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,10 @@ bool HudGaugeSquadMessage::canRender() const
27702770
return false;
27712771
}
27722772

2773+
if (scripting_render_override) {
2774+
return false;
2775+
}
2776+
27732777
return true;
27742778
}
27752779

code/scripting/api/objs/hudconfig.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ ADE_VIRTVAR(Name, l_Gauge_Config, nullptr, "The name of this gauge", "string", "
199199
return ade_set_args(L, "s", current.getGauge()->getConfigName().c_str());
200200
}
201201

202+
ADE_VIRTVAR(isCustom, l_Gauge_Config, nullptr, "If the gauge is custom or builtin", "boolean", "True if custom, false otherwise")
203+
{
204+
gauge_config_h current;
205+
if (!ade_get_args(L, "o", l_Gauge_Config.Get(&current))) {
206+
return ADE_RETURN_NIL;
207+
}
208+
209+
if (!current.isValid()) {
210+
return ade_set_error(L, "b", false);
211+
}
212+
213+
if (ADE_SETTING_VAR) {
214+
LuaError(L, "This property is read only.");
215+
}
216+
217+
return ade_set_args(L, "b", current.getGauge()->isCustom());
218+
}
219+
202220
ADE_VIRTVAR(CurrentColor,
203221
l_Gauge_Config,
204222
"color",

code/scripting/api/objs/hudgauge.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,23 @@ ADE_FUNC(setColor,
256256
return ADE_RETURN_NIL;
257257
}
258258

259+
ADE_FUNC(setRenderOverride,
260+
l_HudGauge,
261+
"boolean",
262+
"Sets a rendering override to enable or disable rendering of this gauge. This takes precedence over all other gauge toggles!",
263+
"boolean",
264+
"True to enable the override and stop the gauge from rendering, false otherwise")
265+
{
266+
HudGauge* gauge;
267+
bool override = false;
268+
if (!ade_get_args(L, "o|b", l_HudGauge.Get(&gauge), &override))
269+
return ADE_RETURN_NIL;
270+
271+
gauge->updateScriptingOverride(override);
272+
273+
return ade_set_args(L, "b", gauge->getScriptingOverride());
274+
}
275+
259276
ADE_VIRTVAR(RenderFunction,
260277
l_HudGauge,
261278
"function (HudGaugeDrawFunctions gauge_handle) => void",

0 commit comments

Comments
 (0)