UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_timer.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "../ui_timer.h"
26#include "../ui_parse.h"
27#include "../ui_actions.h"
28#include "../ui_behaviour.h"
29#include "../ui_lua.h"
30#include "ui_node_timer.h"
31
33
34#define EXTRADATA_TYPE timerExtraData_t
35#define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
36#define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
37
42{
43 EXTRADATA(node).lastTime = CL_Milliseconds();
44}
45
49
54{
57 /* embedded timer */
58 if (data.onTimeOut && data.timeOut) {
59 if (data.lastTime == 0)
60 data.lastTime = CL_Milliseconds();
61 if (data.lastTime + data.timeOut < CL_Milliseconds()) {
62 /* allow to reset timeOut on the event, and restart it, with an uptodate lastTime */
63 data.lastTime = 0;
64 Com_DPrintf(DEBUG_CLIENT, "uiTimerNode::draw: Timeout for node '%s'\n", node->name);
65 if (data.onTimeOut != nullptr) {
66 UI_ExecuteEventActions(node, data.onTimeOut);
67 }
68 else if (data.lua_onEvent != LUA_NOREF) {
69 UI_ExecuteLuaEventScript(node, data.lua_onEvent);
70 }
71 }
72 }
73}
74
76{
77 behaviour->name = "timer";
78 behaviour->manager = UINodePtr(new uiTimerNode());
79 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
80 behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiTimerNode_t *");
81
82 /* This property control milliseconds between each calls of <code>onEvent</code>.
83 * If the value is 0 (the default value) nothing is called. We can change the
84 * value at runtime.
85 */
86 UI_RegisterExtradataNodeProperty(behaviour, "timeout", V_INT, EXTRADATA_TYPE, timeOut);
87
88 /* Invoked periodically. See <code>timeout</code>. */
89 UI_RegisterExtradataNodeProperty(behaviour, "onEvent", V_UI_ACTION, EXTRADATA_TYPE, onTimeOut);
90}
int CL_Milliseconds(void)
Definition cl_main.cpp:1207
virtual void draw(uiNode_t *node)
void onWindowClosed(uiNode_t *node) override
void onWindowOpened(uiNode_t *node, linkedList_t *params) override
Called when we init the node on the screen.
void draw(uiNode_t *node) override
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition common.cpp:440
#define DEBUG_CLIENT
Definition defines.h:59
QGL_EXTERN GLsizei const GLvoid * data
Definition r_gl.h:89
@ V_INT
Definition scripts.h:52
Header for lua script functions.
extradata for the window node
node behaviour, how a node work
const char * name
void * lua_SWIG_typeinfo
UINodePtr manager
intptr_t extraDataSize
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
char name[MAX_VAR]
Definition ui_nodes.h:82
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
Definition ui_lua.cpp:71
Basic lua initialization for the ui.
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
SharedPtr< uiNode > UINodePtr
#define EXTRADATA_TYPE
#define EXTRADATA(node)
void UI_RegisterTimerNode(uiBehaviour_t *behaviour)
#define V_UI_ACTION
Definition ui_parse.h:54