UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_sequence.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_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"
37
38#include "ui_node_sequence.h"
39
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
48static 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
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
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
107void 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
127void 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
142
145
146}
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.
void SEQ_FreeContext(sequenceContext_t *context)
Free a sequence context.
void SEQ_SetView(sequenceContext_t *context, vec2_t pos, vec2_t size)
Define the position of the viewport on the screen.
sequenceContext_t * SEQ_AllocContext(void)
Allocate a sequence context.
bool SEQ_Render(sequenceContext_t *context)
Execute and render a sequence.
virtual void onPropertyChanged(uiNode_t *node, const value_t *property)
virtual void initNode(uiNode_t *node)
void draw(uiNode_t *node) override
void initNode(uiNode_t *node) override
void onWindowOpened(uiNode_t *node, linkedList_t *params) override
void onPropertyChanged(uiNode_t *node, const value_t *property) override
void onWindowClosed(uiNode_t *node) override
void onLeftClick(uiNode_t *node, int x, int y) override
Primary header for client.
#define Mem_PoolStrDup(in, pool, tagNum)
Definition mem.h:50
void R_CleanupDepthBuffer(int x, int y, int width, int height)
"Clean up" the depth buffer into a rect
Definition r_draw.cpp:596
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
void R_PopMatrix(void)
Removes the current matrix from the stack.
Definition r_misc.cpp:248
void R_PushMatrix(void)
Push a new matrix to the stack.
Definition r_misc.cpp:240
Header for lua script functions.
node behaviour, how a node work
const char * name
void * lua_SWIG_typeinfo
UINodePtr manager
intptr_t extraDataSize
vec2_t size
Definition ui_nodes.h:52
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiBox_t box
Definition ui_nodes.h:96
vec_t vec2_t[2]
Definition ufotypes.h:38
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
void UI_FreeStringProperty(void *pointer)
Free a string property if it is allocated into ui_dynStringPool.
#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...
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
Definition ui_node.cpp:526
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:554
SharedPtr< uiNode > UINodePtr
#define EXTRADATA_TYPE
#define EXTRADATA(node)
static const uiBehaviour_t * localBehaviour
memPool_t * ui_dynStringPool
Definition ui_main.cpp:40
void UI_RegisterSequenceNode(uiBehaviour_t *behaviour)
#define EXTRADATA(node)
static const value_t * propertySource
void UI_Sequence_SetSource(uiNode_t *node, const char *name)
#define V_UI_ACTION
Definition ui_parse.h:54
#define V_CVAR_OR_STRING
Definition ui_parse.h:69
void UI_PushClipRect(int x, int y, int width, int height)
Definition ui_render.cpp:47
void UI_PopClipRect(void)
Definition ui_render.cpp:52