1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
|
#include "hudconfig.h"
#include "hud/hudconfig.h"
#include "ui/ui.h"
#include "scripting/api/objs/color.h"
#include "iff_defs/iff_defs.h"
#include "globalincs/alphacolors.h"
namespace scripting {
namespace api {
gauge_config_h::gauge_config_h(SCP_string l_gauge) : gauge(std::move(l_gauge)) {}
HudGauge* gauge_config_h::getGauge() const
{
if (!isValid()) {
return nullptr;
}
return hud_config_get_gauge_pointer(gauge);
}
SCP_string gauge_config_h::getId() const
{
return gauge;
}
bool gauge_config_h::isValid() const
{
return hud_config_get_gauge_pointer(gauge) != nullptr;
}
hud_preset_h::hud_preset_h() : preset(-1) {}
hud_preset_h::hud_preset_h(int l_preset) : preset(l_preset) {}
int hud_preset_h::getIndex() const
{
return preset;
}
SCP_string hud_preset_h::getName() const
{
if (!isValid()) {
return "";
}
return HC_preset_filenames[preset];
}
bool hud_preset_h::isValid() const
{
return preset >= 0 && preset < static_cast<int>(HC_preset_filenames.size());
}
hud_color_preset_h::hud_color_preset_h() : preset(-1) {}
hud_color_preset_h::hud_color_preset_h(int l_preset) : preset(l_preset) {}
int hud_color_preset_h::getIndex() const
{
return preset;
}
SCP_string hud_color_preset_h::getName() const
{
if (!isValid()) {
return "";
}
return XSTR(HC_colors[preset].name.c_str(), HC_colors[preset].xstr);
}
bool hud_color_preset_h::isValid() const
{
return preset >= 0 && preset < NUM_HUD_COLOR_PRESETS;
}
//**********HANDLE: hud color preset
ADE_OBJ(l_HUD_Color_Preset, hud_color_preset_h, "hud_color_preset", "Hud preset handle");
ADE_VIRTVAR(Name, l_HUD_Color_Preset, nullptr, "The name of this preset", "string", "The name")
{
hud_color_preset_h current;
if (!ade_get_args(L, "o", l_HUD_Color_Preset.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", current.getName().c_str());
}
ADE_VIRTVAR(Color, l_HUD_Color_Preset, nullptr, "The name of this preset", "color", "color")
{
hud_color_preset_h current;
if (!ade_get_args(L, "o", l_HUD_Color_Preset.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
const auto &preset = HC_colors[current.getIndex()];
color c;
gr_init_color(&c, preset.r, preset.g, preset.b);
return ade_set_args(L, "o", l_Color.Set(c));
}
ADE_FUNC(isValid,
l_HUD_Color_Preset,
nullptr,
"Detects whether handle is valid",
"boolean",
"true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
hud_color_preset_h current;
if (!ade_get_args(L, "o", l_HUD_Color_Preset.Get(¤t)))
return ADE_RETURN_NIL;
return ade_set_args(L, "b", current.isValid());
}
//**********HANDLE: hud preset
ADE_OBJ(l_HUD_Preset, hud_preset_h, "hud_preset", "Hud preset handle");
ADE_VIRTVAR(Name, l_HUD_Preset, nullptr, "The name of this preset", "string", "The name")
{
hud_preset_h current;
if (!ade_get_args(L, "o", l_HUD_Preset.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", current.getName().c_str());
}
ADE_FUNC(deletePreset, l_HUD_Preset, nullptr, "Deletes the preset file", nullptr, nullptr)
{
hud_preset_h current;
if (!ade_get_args(L, "o", l_HUD_Preset.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ADE_RETURN_NIL;
}
hud_config_delete_preset(current.getName());
return ADE_RETURN_NIL;
}
ADE_FUNC(isValid, l_HUD_Preset, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
hud_preset_h current;
if (!ade_get_args(L, "o", l_HUD_Preset.Get(¤t)))
return ADE_RETURN_NIL;
return ade_set_args(L, "b", current.isValid());
}
//**********HANDLE: gauge config
ADE_OBJ(l_Gauge_Config, gauge_config_h, "gauge_config", "Gauge config handle");
ADE_VIRTVAR(Name, l_Gauge_Config, nullptr, "The name of this gauge", "string", "The name")
{
gauge_config_h current;
if (!ade_get_args(L, "o", l_Gauge_Config.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", current.getGauge()->getConfigName().c_str());
}
ADE_VIRTVAR(isCustom, l_Gauge_Config, nullptr, "If the gauge is custom or builtin", "boolean", "True if custom, false otherwise")
{
gauge_config_h current;
if (!ade_get_args(L, "o", l_Gauge_Config.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "b", false);
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "b", current.getGauge()->isCustom());
}
ADE_VIRTVAR(CurrentColor,
l_Gauge_Config,
"color",
"Gets the current color of the gauge. If setting the color, gauges that use IFF for color cannot be set.",
"color",
"The gauge color or nil if the gauge is invalid")
{
gauge_config_h current;
color newColor;
if (!ade_get_args(L, "o|o", l_Gauge_Config.Get(¤t), l_Color.Get(&newColor))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "o", l_Color.Set(Color_text_normal));
}
if (ADE_SETTING_VAR) {
if (!current.getGauge()->getConfigUseIffColor()) {
HUD_config.set_gauge_color(current.getId(), newColor);
}
}
color thisColor;
if (!current.getGauge()->getConfigUseIffColor()) {
thisColor = HUD_config.get_gauge_color(current.getId());
} else {
if (current.getGauge()->getConfigUseTagColor()) {
thisColor = *iff_get_color(IFF_COLOR_TAGGED, 0);
} else {
thisColor = Color_bright_red;
}
}
return ade_set_args(L, "o", l_Color.Set(thisColor));
}
ADE_VIRTVAR(ShowGaugeFlag,
l_Gauge_Config,
"boolean Show",
"Gets the current status of the show gauge flag.",
"boolean",
"True if on, false if otherwise")
{
gauge_config_h current;
bool show;
if (!ade_get_args(L, "o|b", l_Gauge_Config.Get(¤t), &show)) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "b", false);
}
if (ADE_SETTING_VAR) {
HUD_config.set_gauge_visibility(current.getId(), show);
}
return ade_set_args(L, "b", HUD_config.is_gauge_visible(current.getId()));
}
ADE_VIRTVAR(PopupGaugeFlag,
l_Gauge_Config,
"boolean Popup",
"Gets the current status of the popup gauge flag.",
"boolean",
"True if on, false otherwise")
{
gauge_config_h current;
bool popup;
if (!ade_get_args(L, "o|b", l_Gauge_Config.Get(¤t), &popup)) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "b", false);
}
if (ADE_SETTING_VAR) {
HUD_config.set_gauge_popup(current.getId(), popup);
}
if (!current.getGauge()->getConfigCanPopup()) {
return ADE_RETURN_FALSE;
}
return ade_set_args(L, "b", HUD_config.is_gauge_popup(current.getId()));
}
ADE_VIRTVAR(CanPopup,
l_Gauge_Config,
nullptr,
"Gets whether or not the gauge can have the popup flag.",
"boolean",
"True if can popup, false otherwise")
{
gauge_config_h current;
if (!ade_get_args(L, "o", l_Gauge_Config.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "b", false);
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
if (!current.getGauge()->getConfigCanPopup()) {
return ADE_RETURN_FALSE;
}
return ADE_RETURN_TRUE;
}
ADE_VIRTVAR(UsesIffForColor,
l_Gauge_Config,
nullptr,
"Gets whether or not the gauge uses IFF for color.",
"boolean",
"True if uses IFF, false otherwise")
{
gauge_config_h current;
if (!ade_get_args(L, "o", l_Gauge_Config.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "b", false);
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
if (!current.getGauge()->getConfigUseIffColor()) {
return ADE_RETURN_FALSE;
}
return ADE_RETURN_TRUE;
}
ADE_VIRTVAR(isCustomGauge,
l_Gauge_Config,
nullptr,
"Gets whether or not the gauge is a custom gauge.",
"boolean",
"True if custom, false otherwise")
{
gauge_config_h current;
if (!ade_get_args(L, "o", l_Gauge_Config.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "b", false);
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
if (!current.getGauge()->isCustom()) {
return ADE_RETURN_FALSE;
}
return ADE_RETURN_TRUE;
}
ADE_FUNC(setSelected, l_Gauge_Config, "boolean", "Sets if the gauge is the currently selected gauge for drawing as selected.", nullptr, nullptr)
{
gauge_config_h current;
bool select;
if (!ade_get_args(L, "o|b", l_Gauge_Config.Get(¤t), &select)) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ADE_RETURN_NIL;
}
if (select) {
HC_gauge_selected = current.getId();
}
return ADE_RETURN_NIL;
}
ADE_FUNC(isValid, l_Gauge_Config, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
gauge_config_h current;
if (!ade_get_args(L, "o", l_Gauge_Config.Get(¤t)))
return ADE_RETURN_NIL;
return ade_set_args(L, "b", current.isValid());
}
} // namespace api
} // namespace scripting
|