Files
fs2open.github.com/code/hud/hudscripting.cpp
T
asarium 1662a3c317 Add new HUD gauge type for scripted gauges
The new gauge can be accessed by the scripting API with which a function
can be set which will be called when this gauge is rendered. This can be
used for exposing the HUD gauge positioning and RTT options to the
scripting API without a lot of work needed for the script writer.

There is currently only one rendering function implemented since this is
only a proof of concept.
2019-03-17 09:27:58 +01:00

48 lines
1.2 KiB
C++

//
//
#include "hud/hudscripting.h"
#include "parse/parselo.h"
#include "scripting/api/objs/hudgauge.h"
HudGaugeScripting::HudGaugeScripting() :
HudGauge(HUD_OBJECT_SCRIPTING,
HUD_CENTER_RETICLE,
true,
false,
(VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_TOPDOWN | VM_OTHER_SHIP),
255,
255,
255) {
}
void HudGaugeScripting::render(float /*frametime*/) {
using namespace scripting::api;
if (!_renderFunction.isValid()) {
return;
}
_renderFunction.call({ luacpp::LuaValue::createValue(_renderFunction.getLuaState(),
l_HudGaugeDrawFuncs.Set(this)) });
}
void HudGaugeScripting::initName(SCP_string name) {
if (name.size() > NAME_LENGTH - 1) {
error_display(0,
"Name \"%s\" is too long. May not be longer than %d! Name will be truncated",
name.c_str(),
NAME_LENGTH - 1);
name.resize(NAME_LENGTH - 1);
}
strcpy(custom_name, name.c_str());
}
const luacpp::LuaFunction& HudGaugeScripting::getRenderFunction() const {
return _renderFunction;
}
void HudGaugeScripting::setRenderFunction(const luacpp::LuaFunction& renderFunction) {
_renderFunction = renderFunction;
}