1 //
2 //
3
4 #include "hud/hudscripting.h"
5
6 #include "parse/parselo.h"
7 #include "scripting/api/objs/hudgauge.h"
8 #include "scripting/scripting.h"
9
HudGaugeScripting()10 HudGaugeScripting::HudGaugeScripting() :
11 HudGauge(HUD_OBJECT_SCRIPTING,
12 HUD_CENTER_RETICLE,
13 true,
14 false,
15 (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_TOPDOWN | VM_OTHER_SHIP),
16 255,
17 255,
18 255) {
19 }
20
render(float)21 void HudGaugeScripting::render(float /*frametime*/) {
22 using namespace scripting::api;
23
24 if (!_renderFunction.isValid()) {
25 return;
26 }
27
28 _renderFunction.call(Script_system.GetLuaSession(),
29 {luacpp::LuaValue::createValue(_renderFunction.getLuaState(), l_HudGaugeDrawFuncs.Set(this))});
30 }
31
initName(SCP_string name)32 void HudGaugeScripting::initName(SCP_string name) {
33 if (name.size() > NAME_LENGTH - 1) {
34 error_display(0,
35 "Name \"%s\" is too long. May not be longer than %d! Name will be truncated",
36 name.c_str(),
37 NAME_LENGTH - 1);
38 name.resize(NAME_LENGTH - 1);
39 }
40 strcpy(custom_name, name.c_str());
41 }
getRenderFunction() const42 const luacpp::LuaFunction& HudGaugeScripting::getRenderFunction() const {
43 return _renderFunction;
44 }
setRenderFunction(const luacpp::LuaFunction & renderFunction)45 void HudGaugeScripting::setRenderFunction(const luacpp::LuaFunction& renderFunction) {
46 _renderFunction = renderFunction;
47 }
48