UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_video.cpp
Go to the documentation of this file.
1 
11 /*
12 Copyright (C) 2002-2020 UFO: Alien Invasion.
13 
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License
16 as published by the Free Software Foundation; either version 2
17 of the License, or (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 
23 See the GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, 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"
37 #include "ui_node_abstractnode.h"
38 
39 #include "../../client.h"
40 #include "../../cinematic/cl_cinematic.h"
41 
42 #include "../../../common/scripts_lua.h"
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 
121 void 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);
138  UI_RegisterExtradataNodeProperty(behaviour, "onEnd", V_UI_ACTION, EXTRADATA_TYPE, onEnd);
139 }
void initNode(uiNode_t *node) override
vec2_t size
Definition: ui_nodes.h:52
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
const char * name
Definition: ui_behaviour.h:41
void CIN_RunCinematic(cinematic_t *cin)
void UI_CaptureDrawOver(uiNode_t *node)
Capture a node we will draw over all nodes (per window)
Definition: ui_draw.cpp:64
void onWindowClosed(uiNode_t *node) override
void CIN_OpenCinematic(cinematic_t *cin, const char *fileName)
Open a cinematic file and store status to a structure.
#define UI_VIDEOEXTRADATACONST(node)
Definition: ui_node_video.h:42
void CIN_CloseCinematic(cinematic_t *cin)
Close a cinematic, and clean up status and memory.
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
void drawOverWindow(uiNode_t *node) override
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
#define EXTRADATA_TYPE
SharedPtr< uiNode > UINodePtr
void UI_RegisterVideoNode(uiBehaviour_t *behaviour)
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
void draw(uiNode_t *node) override
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
Definition: ui_actions.cpp:726
void UI_Video_SetSource(uiNode_t *node, const char *name)
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
memPool_t * ui_dynStringPool
Definition: ui_main.cpp:40
virtual void initNode(uiNode_t *node)
intptr_t extraDataSize
Definition: ui_behaviour.h:54
Definition: scripts.h:50
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
void CIN_SetParameters(cinematic_t *cin, int x, int y, int w, int h, int status, bool noSound)
void CIN_InitCinematic(cinematic_t *cin)
vec_t vec2_t[2]
Definition: ufotypes.h:38
#define EXTRADATA(node)
#define V_CVAR_OR_STRING
Definition: ui_parse.h:69
#define V_UI_ACTION
Definition: ui_parse.h:54
void onWindowOpened(uiNode_t *node, linkedList_t *params) override
#define Mem_PoolStrDup(in, pool, tagNum)
Definition: mem.h:50
uiBox_t box
Definition: ui_nodes.h:96