UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_timer.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, 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 
32 #include "../../../common/scripts_lua.h"
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 
47 {
48 }
49 
54 {
55  uiLocatedNode::draw(node);
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) {
67  }
68  else if (data.lua_onEvent != LUA_NOREF) {
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 }
void onWindowClosed(uiNode_t *node) override
const char * name
Definition: ui_behaviour.h:41
char name[MAX_VAR]
Definition: ui_nodes.h:82
UINodePtr manager
Definition: ui_behaviour.h:43
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
Definition: ui_lua.cpp:71
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition: ui_behaviour.h:109
#define DEBUG_CLIENT
Definition: defines.h:59
#define EXTRADATA_TYPE
SharedPtr< uiNode > UINodePtr
void UI_RegisterTimerNode(uiBehaviour_t *behaviour)
LUA_EVENT lua_onEvent
Definition: ui_node_timer.h:48
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
Definition: ui_actions.cpp:726
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition: common.cpp:398
extradata for the window node
Definition: ui_node_timer.h:44
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
virtual void draw(uiNode_t *node)
#define EXTRADATA(node)
intptr_t extraDataSize
Definition: ui_behaviour.h:54
node behaviour, how a node work
Definition: ui_behaviour.h:39
Definition: scripts.h:52
GLsizei const GLvoid * data
Definition: r_gl.h:152
#define V_UI_ACTION
Definition: ui_parse.h:54
struct uiAction_s * onTimeOut
Definition: ui_node_timer.h:47
void onWindowOpened(uiNode_t *node, linkedList_t *params) override
Called when we init the node on the screen.
int CL_Milliseconds(void)
Definition: cl_main.cpp:1208
void draw(uiNode_t *node) override