UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_video.cpp
Go to the documentation of this file.
1
10
11/*
12Copyright (C) 2002-2025 UFO: Alien Invasion.
13
14This program is free software; you can redistribute it and/or
15modify it under the terms of the GNU General Public License
16as published by the Free Software Foundation; either version 2
17of the License, or (at your option) any later version.
18
19This program is distributed in the hope that it will be useful,
20but WITHOUT ANY WARRANTY; without even the implied warranty of
21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
23See the GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program; if not, write to the Free Software
27Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
29*/
30
31#include "../ui_nodes.h"
32#include "../ui_parse.h"
33#include "../ui_behaviour.h"
34#include "../ui_draw.h"
35#include "../ui_actions.h"
36#include "../ui_lua.h"
38
39#include "../../client.h"
41
43
44#include "ui_node_video.h"
45
46#define EXTRADATA_TYPE videoExtraData_t
47#define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
48#define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
49
51
54 EXTRADATA(node).lua_onEnd = LUA_NOREF;
55}
56
58{
59 if (EXTRADATA(node).cin.status == CIN_STATUS_INVALID) {
61 return;
62 }
63
64 if (EXTRADATA(node).cin.status == CIN_STATUS_NONE) {
65 vec2_t pos;
66 bool nosound = UI_VIDEOEXTRADATACONST(node).nosound;
67
68 CIN_OpenCinematic(&(EXTRADATA(node).cin), va("videos/%s", EXTRADATA(node).source));
69 if (EXTRADATA(node).cin.status == CIN_STATUS_INVALID) {
70 if (EXTRADATA(node).onEnd != nullptr) {
71 UI_ExecuteEventActions(node, EXTRADATA(node).onEnd);
72 }
73 else if (EXTRADATA(node).lua_onEnd != LUA_NOREF) {
74 UI_ExecuteLuaEventScript(node, EXTRADATA(node).lua_onEnd);
75 }
76 return;
77 }
78
79 UI_GetNodeAbsPos(node, pos);
80 CIN_SetParameters(&(EXTRADATA(node).cin), pos[0], pos[1], node->box.size[0], node->box.size[1], CIN_STATUS_PLAYING, nosound);
81 }
82
83 if (EXTRADATA(node).cin.status == CIN_STATUS_PLAYING || EXTRADATA(node).cin.status == CIN_STATUS_PAUSE) {
84 /* only set replay to true if video was found and is running */
85 CIN_RunCinematic(&(EXTRADATA(node).cin));
86 if (EXTRADATA(node).cin.status == CIN_STATUS_NONE) {
87 if (EXTRADATA(node).onEnd != nullptr) {
88 UI_ExecuteEventActions(node, EXTRADATA(node).onEnd);
89 }
90 else if (EXTRADATA(node).lua_onEnd != LUA_NOREF) {
91 UI_ExecuteLuaEventScript(node, EXTRADATA(node).lua_onEnd);
92 }
93 }
94 }
95}
96
98{
99 if (!EXTRADATA(node).source)
100 return;
101
102 if (EXTRADATA(node).cin.fullScreen) {
103 UI_CaptureDrawOver(node);
104 return;
105 }
106
107 drawOverWindow(node);
108}
109
111{
112 CIN_InitCinematic(&(EXTRADATA(node).cin));
113}
114
116{
117 /* If playing a cinematic, stop it */
118 CIN_CloseCinematic(&(EXTRADATA(node).cin));
119}
120
121void UI_Video_SetSource (uiNode_t* node, const char* name) {
122 UI_FreeStringProperty(const_cast<char*>(EXTRADATA(node).source));
123 EXTRADATA(node).source = Mem_PoolStrDup(name, ui_dynStringPool, 0);
124}
125
127{
128 behaviour->name = "video";
129 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
130 behaviour->manager = UINodePtr(new uiVideoNode());
131 behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiVideoNode_t *");
132
136 UI_RegisterExtradataNodeProperty(behaviour, "nosound", V_BOOL, EXTRADATA_TYPE, nosound);
139}
void CIN_InitCinematic(cinematic_t *cin)
void CIN_RunCinematic(cinematic_t *cin)
void CIN_SetParameters(cinematic_t *cin, int x, int y, int w, int h, int status, bool noSound)
void CIN_OpenCinematic(cinematic_t *cin, const char *fileName)
Open a cinematic file and store status to a structure.
void CIN_CloseCinematic(cinematic_t *cin)
Close a cinematic, and clean up status and memory.
Header file for cinematics.
@ CIN_STATUS_NONE
@ CIN_STATUS_PLAYING
@ CIN_STATUS_PAUSE
@ CIN_STATUS_INVALID
virtual void initNode(uiNode_t *node)
void onWindowOpened(uiNode_t *node, linkedList_t *params) override
void onWindowClosed(uiNode_t *node) override
void drawOverWindow(uiNode_t *node) override
void initNode(uiNode_t *node) override
void draw(uiNode_t *node) override
Primary header for client.
#define Mem_PoolStrDup(in, pool, tagNum)
Definition mem.h:50
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
@ V_BOOL
Definition scripts.h:50
Header for lua script functions.
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
Definition shared.cpp:410
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.
void UI_CaptureDrawOver(uiNode_t *node)
Capture a node we will draw over all nodes (per window).
Definition ui_draw.cpp:64
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
SharedPtr< uiNode > UINodePtr
#define EXTRADATA_TYPE
#define EXTRADATA(node)
memPool_t * ui_dynStringPool
Definition ui_main.cpp:40
void UI_Video_SetSource(uiNode_t *node, const char *name)
#define EXTRADATA(node)
void UI_RegisterVideoNode(uiBehaviour_t *behaviour)
#define UI_VIDEOEXTRADATACONST(node)
#define V_UI_ACTION
Definition ui_parse.h:54
#define V_CVAR_OR_STRING
Definition ui_parse.h:69