UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_sequence.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_nodes.h"
26 #include "../ui_parse.h"
27 #include "../ui_behaviour.h"
28 #include "../ui_actions.h"
29 #include "../ui_draw.h"
30 #include "../ui_render.h"
31 #include "../ui_lua.h"
32 #include "../../client.h"
33 #include "../../renderer/r_misc.h"
34 #include "../../renderer/r_draw.h"
35 #include "../../cinematic/cl_sequence.h"
36 #include "ui_node_abstractnode.h"
37 
38 #include "ui_node_sequence.h"
39 
40 #include "../../../common/scripts_lua.h"
41 
42 #define EXTRADATA_TYPE sequenceExtraData_t
43 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
44 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
45 
47 
48 static const value_t* propertySource;
49 
51 
54  EXTRADATA(node).lua_onEnd = LUA_NOREF;
55 }
56 
58 {
59  if (EXTRADATA(node).context != nullptr && EXTRADATA(node).playing) {
60  bool finished = false;
61  vec2_t pos;
62  vec2_t screenPos;
63  UI_GetNodeAbsPos(node, pos);
64  UI_GetNodeScreenPos(node, screenPos);
65 
66  R_PushMatrix();
67  R_CleanupDepthBuffer(pos[0], pos[1], node->box.size[0], node->box.size[1]);
68  UI_PushClipRect(screenPos[0], screenPos[1], node->box.size[0], node->box.size[1]);
69 
70  SEQ_SetView(EXTRADATA(node).context, pos, node->box.size);
71  finished = !SEQ_Render(EXTRADATA(node).context);
72 
74  R_PopMatrix();
75 
76  if (finished) {
77  if (EXTRADATA(node).onEnd != nullptr) {
78  UI_ExecuteEventActions(node, EXTRADATA(node).onEnd);
79  }
80  else if (EXTRADATA(node).lua_onEnd != LUA_NOREF) {
81  UI_ExecuteLuaEventScript(node, EXTRADATA(node).lua_onEnd);
82  }
83  EXTRADATA(node).playing = false;
84  }
85  }
86 }
87 
89 {
90  if (EXTRADATA(node).context == nullptr)
91  EXTRADATA(node).context = SEQ_AllocContext();
92  if (EXTRADATA(node).source != nullptr) {
93  SEQ_InitContext(EXTRADATA(node).context, EXTRADATA(node).source);
94  EXTRADATA(node).playing = true;
95  }
96 }
97 
99 {
100  if (EXTRADATA(node).context != nullptr) {
101  SEQ_FreeContext(EXTRADATA(node).context);
102  EXTRADATA(node).context = nullptr;
103  }
104  EXTRADATA(node).playing = false;
105 }
106 
107 void uiSequenceNode::onLeftClick (uiNode_t* node, int x, int y)
108 {
109  if (EXTRADATA(node).context != nullptr) {
110  SEQ_SendClickEvent(EXTRADATA(node).context);
111  }
112 }
113 
115 {
116  if (property == propertySource) {
117  if (EXTRADATA(node).source != nullptr) {
118  onWindowOpened(node, nullptr);
119  } else if (EXTRADATA(node).context != nullptr) {
120  onWindowClosed(node);
121  }
122  return;
123  }
124  uiLocatedNode::onPropertyChanged(node, property);
125 }
126 
127 void UI_Sequence_SetSource(uiNode_t* node, const char* name) {
128  UI_FreeStringProperty(const_cast<char*>(EXTRADATA(node).source));
129  EXTRADATA(node).source = Mem_PoolStrDup(name, ui_dynStringPool, 0);
130 }
131 
133 {
134  localBehaviour = behaviour;
135  behaviour->name = "sequence";
136  behaviour->manager = UINodePtr(new uiSequenceNode());
137  behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
138  behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiSequenceNode_t *");
139 
141  propertySource = UI_RegisterExtradataNodeProperty(behaviour, "src", V_CVAR_OR_STRING, EXTRADATA_TYPE, source);
142 
144  UI_RegisterExtradataNodeProperty(behaviour, "onEnd", V_UI_ACTION, EXTRADATA_TYPE, onEnd);
145 
146 }
vec2_t size
Definition: ui_nodes.h:52
void onWindowOpened(uiNode_t *node, linkedList_t *params) override
void UI_PopClipRect(void)
Definition: ui_render.cpp:52
void UI_Sequence_SetSource(uiNode_t *node, const char *name)
void onWindowClosed(uiNode_t *node) override
const char * name
Definition: ui_behaviour.h:41
UINodePtr manager
Definition: ui_behaviour.h:43
void draw(uiNode_t *node) override
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
Definition: ui_lua.cpp:71
bool SEQ_InitContext(sequenceContext_t *context, const char *name)
Initialize a sequence context from data of a named script sequence.
void SEQ_SendClickEvent(sequenceContext_t *context)
Unlock a click event for the current sequence or ends the current sequence if not locked...
#define EXTRADATA_TYPE
void SEQ_FreeContext(sequenceContext_t *context)
Free a sequence context.
void UI_FreeStringProperty(void *pointer)
Free a string property if it is allocated into ui_dynStringPool.
Definition: ui_actions.cpp:778
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition: ui_behaviour.h:109
memPool_t * ui_dynStringPool
Definition: ui_main.cpp:40
void initNode(uiNode_t *node) override
SharedPtr< uiNode > UINodePtr
void UI_RegisterSequenceNode(uiBehaviour_t *behaviour)
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
Definition: ui_actions.cpp:726
static const value_t * propertySource
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...
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
Definition: ui_node.cpp:514
#define EXTRADATA(node)
virtual void initNode(uiNode_t *node)
static const uiBehaviour_t * localBehaviour
intptr_t extraDataSize
Definition: ui_behaviour.h:54
void R_PopMatrix(void)
Removes the current matrix from the stack.
Definition: r_misc.cpp:248
node behaviour, how a node work
Definition: ui_behaviour.h:39
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
bool SEQ_Render(sequenceContext_t *context)
Execute and render a sequence.
vec_t vec2_t[2]
Definition: ufotypes.h:38
virtual void onPropertyChanged(uiNode_t *node, const value_t *property)
void UI_PushClipRect(int x, int y, int width, int height)
Definition: ui_render.cpp:47
sequenceContext_t * SEQ_AllocContext(void)
Allocate a sequence context.
#define V_CVAR_OR_STRING
Definition: ui_parse.h:69
#define V_UI_ACTION
Definition: ui_parse.h:54
#define Mem_PoolStrDup(in, pool, tagNum)
Definition: mem.h:50
uiBox_t box
Definition: ui_nodes.h:96
void R_PushMatrix(void)
Push a new matrix to the stack.
Definition: r_misc.cpp:240
void onLeftClick(uiNode_t *node, int x, int y) override
void SEQ_SetView(sequenceContext_t *context, vec2_t pos, vec2_t size)
Define the position of the viewport on the screen.
void onPropertyChanged(uiNode_t *node, const value_t *property) override
void R_CleanupDepthBuffer(int x, int y, int width, int height)
"Clean up" the depth buffer into a rect
Definition: r_draw.cpp:596
void UI_GetNodeScreenPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node in the screen. Screen position is not used for the node rende...
Definition: ui_node.cpp:542