mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-11 04:31:35 -10:00
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.
48 lines
1.2 KiB
C++
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;
|
|
}
|