File: hudscripting.cpp

package info (click to toggle)
freespace2 25.0.0~rc11%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (52 lines) | stat: -rw-r--r-- 1,358 bytes parent folder | download
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
//
//

#include "hud/hudscripting.h"

#include "parse/parselo.h"
#include "scripting/api/objs/hudgauge.h"
#include "scripting/scripting.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*/, bool config) {
	using namespace scripting::api;

	// Not yet supported in config
	if (config) {
		return;
	}

	if (!_renderFunction.isValid()) {
		return;
	}

	_renderFunction.call(Script_system.GetLuaSession(),
		{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;
}