|
2 | 2 | // |
3 | 3 |
|
4 | 4 | #include "hudgauge.h" |
| 5 | +#include "hud/hudscripting.h" |
5 | 6 |
|
6 | 7 | namespace scripting { |
7 | 8 | namespace api { |
@@ -40,6 +41,59 @@ ADE_VIRTVAR(Text, l_HudGauge, "string", "Custom HUD Gauge text", "string", "Cust |
40 | 41 | return ade_set_args(L, "s", gauge->getCustomGaugeText()); |
41 | 42 | } |
42 | 43 |
|
| 44 | +ADE_VIRTVAR(RenderFunction, |
| 45 | + l_HudGauge, |
| 46 | + "function (HudGaugeDrawFunctions gauge_handle)", |
| 47 | + "For scripted HUD gauges, the function that will be called for rendering the HUD gauge", |
| 48 | + "function (HudGaugeDrawFunctions gauge_handle)", |
| 49 | + "Render function or nil if no action is set or handle is invalid") { |
| 50 | + HudGauge* gauge; |
| 51 | + luacpp::LuaFunction func; |
| 52 | + |
| 53 | + if (!ade_get_args(L, "o|u", l_HudGauge.Get(&gauge), &func)) { |
| 54 | + return ADE_RETURN_NIL; |
| 55 | + } |
| 56 | + |
| 57 | + if (gauge->getObjectType() != HUD_OBJECT_SCRIPTING) { |
| 58 | + return ADE_RETURN_NIL; |
| 59 | + } |
| 60 | + |
| 61 | + auto scriptedGauge = static_cast<HudGaugeScripting*>(gauge); |
| 62 | + |
| 63 | + if (ADE_SETTING_VAR && func.isValid()) { |
| 64 | + scriptedGauge->setRenderFunction(func); |
| 65 | + } |
| 66 | + |
| 67 | + return ade_set_args(L, "u", scriptedGauge->getRenderFunction()); |
| 68 | +} |
| 69 | + |
| 70 | +ADE_OBJ(l_HudGaugeDrawFuncs, |
| 71 | + HudGauge*, |
| 72 | + "HudGaugeDrawFunctions", |
| 73 | + "Handle to the rendering functions used for HUD gauges. Do not keep a reference to this since these are only useful inside the rendering callback of a HUD gauge."); |
| 74 | + |
| 75 | +ADE_FUNC(drawString, |
| 76 | + l_HudGaugeDrawFuncs, |
| 77 | + "number x, number y, string text", |
| 78 | + "Draws a string in the context of the HUD gauge.", |
| 79 | + "boolean", |
| 80 | + "true on success, false otherwise") { |
| 81 | + HudGauge* gauge; |
| 82 | + float x; |
| 83 | + float y; |
| 84 | + const char* text; |
| 85 | + |
| 86 | + if (!ade_get_args(L, "offs", l_HudGaugeDrawFuncs.Get(&gauge), &x, &y, &text)) { |
| 87 | + return ADE_RETURN_FALSE; |
| 88 | + } |
| 89 | + |
| 90 | + int gauge_x, gauge_y; |
| 91 | + gauge->getPosition(&gauge_x, &gauge_y); |
| 92 | + |
| 93 | + gauge->renderString(fl2i(gauge_x + x), fl2i(gauge_y), text); |
| 94 | + |
| 95 | + return ADE_RETURN_TRUE; |
| 96 | +} |
43 | 97 |
|
44 | 98 | } |
45 | 99 | } |
0 commit comments