mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 17:52:15 -10:00
As described in #1278, the current scripting system has issues with handling non-trivial C++ types. Since fixing that deficiency is too much work, especially since we are in a feature freeze, I decided to simply enforce the usage of trivial types for scripting handles. Fortunately, only two handles used non-trivial types so it was relatively easy to fix those instances by dynamically allocating those and only storing the pointers in the lua memory. This fixes a bug in JAD-XA where the game would crash at the last boss. Also, I noticed that the HudGauge handle used a copy of the hud gauge rather than a pointer to the actual instance so I'm pretty sure that any scripting changes to a custom HUD gauge simply didn't work before.
109 lines
2.3 KiB
C++
109 lines
2.3 KiB
C++
//
|
|
//
|
|
|
|
#include "hud.h"
|
|
#include "scripting/api/objs/hudgauge.h"
|
|
|
|
#include "hud/hud.h"
|
|
#include "hud/hudconfig.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
|
|
//**********LIBRARY: HUD library
|
|
ADE_LIB(l_HUD, "HUD", "hu", "HUD library");
|
|
|
|
ADE_VIRTVAR(HUDDrawn, l_HUD, "boolean", "Current HUD draw status", "boolean", "If the HUD is drawn or not")
|
|
{
|
|
bool to_draw = false;
|
|
|
|
if(!ade_get_args(L, "*|b", &to_draw))
|
|
return ADE_RETURN_NIL;
|
|
|
|
if(ADE_SETTING_VAR)
|
|
{
|
|
if (to_draw)
|
|
HUD_draw = 1;
|
|
else
|
|
HUD_draw = 0;
|
|
}
|
|
|
|
if (HUD_draw)
|
|
return ADE_RETURN_TRUE;
|
|
else
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
ADE_VIRTVAR(HUDDisabledExceptMessages, l_HUD, "boolean", "Specifies if only the messages gauges of the hud are drawn", "boolean", "true if only the message gauges are drawn, false otherwise")
|
|
{
|
|
bool to_draw = false;
|
|
|
|
if (!ade_get_args(L, "*|b", &to_draw))
|
|
return ADE_RETURN_NIL;
|
|
|
|
if (ADE_SETTING_VAR)
|
|
{
|
|
hud_disable_except_messages(to_draw);
|
|
}
|
|
|
|
if (hud_disabled_except_messages())
|
|
return ADE_RETURN_TRUE;
|
|
else
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
ADE_FUNC(setHUDGaugeColor, l_HUD, "number (index number of the gauge), [integer red, number green, number blue, number alpha]", "Color used to draw the gauge", "boolean", "If the operation was successful")
|
|
{
|
|
int idx = -1;
|
|
int r = 0;
|
|
int g = 0;
|
|
int b = 0;
|
|
int a = 0;
|
|
|
|
if(!ade_get_args(L, "i|iiii", &idx, &r, &g, &b, &a))
|
|
return ADE_RETURN_FALSE;
|
|
|
|
if ((idx < 0) || (idx >= NUM_HUD_GAUGES))
|
|
return ADE_RETURN_FALSE;
|
|
|
|
gr_init_alphacolor(&HUD_config.clr[idx], r, g, b, a);
|
|
|
|
return ADE_RETURN_TRUE;
|
|
}
|
|
|
|
ADE_FUNC(getHUDGaugeColor, l_HUD, "number (index number of the gauge)", "Color used to draw the gauge", "number, number, number, number", "Red, green, blue, and alpha of the gauge")
|
|
{
|
|
int idx = -1;
|
|
|
|
if(!ade_get_args(L, "i", &idx))
|
|
return ADE_RETURN_NIL;
|
|
|
|
if ((idx < 0) || (idx >= NUM_HUD_GAUGES))
|
|
return ADE_RETURN_NIL;
|
|
|
|
color c = HUD_config.clr[idx];
|
|
|
|
return ade_set_args(L, "iiii", (int) c.red, (int) c.green, (int) c.blue, (int) c.alpha);
|
|
}
|
|
|
|
ADE_FUNC(getHUDGaugeHandle, l_HUD, "string Name", "Returns a handle to a specified HUD gauge", "HudGauge", "HUD Gauge handle, or nil if invalid")
|
|
{
|
|
char* name;
|
|
if (!ade_get_args(L, "s", &name))
|
|
return ADE_RETURN_NIL;
|
|
HudGauge* gauge = NULL;
|
|
|
|
gauge = hud_get_gauge(name);
|
|
|
|
if (gauge == NULL)
|
|
return ADE_RETURN_NIL;
|
|
else
|
|
return ade_set_args(L, "o", l_HudGauge.Set(gauge));
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|