1 /*
2  * Martian: Motor para creaci�n de videojuegos con SDL y OpenGL
3  * Copyright (C) 2007  Javier P�rez Pacheco
4  *
5  * Este motor tiene licencia Creative Commons y se permite
6  * su modificacion y utilizacion libremente siempre y cuando se
7  * cite al autor original y se comparta con la misma licencia.
8  * No se permite su uso comercial.
9  *
10  * Para mas informacion visite la web:
11  * http://creativecommons.org/licenses/by-nc-sa/2.0/es/
12  *
13  * PROGRAMADOR
14  * Javier P�rez Pacheco
15  * Cadiz (Spain)
16  * javielinux@gmail.com
17  *
18  */
19 
20 #ifndef SCENEANIMATION_H_
21 #define SCENEANIMATION_H_
22 
23 #include <SDL.h>
24 #include <SDL_mixer.h>
25 #include "defines.h"
26 #include "elements.h"
27 #include "joystick.h"
28 #include "font.h"
29 #include "timer.h"
30 #include "language.h"
31 #include "hash.h"
32 #include <stdio.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #include <string>
36 
37 #include <cmath>
38 #include <iostream>
39 #include <vector>
40 
41 using namespace std;
42 
43 namespace Martian {
44 
45 	#define SCENEANIMATION_MAIN 0
46 
47 	class GroupScene;
48 	class Fonts;
49 	class SceneAnimation;
50 	class ObjectAnimation;
51 	class SoundAnimation;
52 
53 	void parseXMLAnimation(char fileXML[128], SceneAnimation *s);
54 
55 	int nElementsXMLAnimation(char fileXML[128]);
56 
57 	typedef struct
58 	{
59 		SceneAnimation *scene;
60 		ObjectAnimation *aux;
61 		SoundAnimation *auxSound;
62 		bool inSound;
63 		bool inElement;
64 		bool inFrames;
65 		bool inAnimation;
66 		string nameAnimation;
67 		bool inAction;
68 		bool inActionOnClick;
69 		bool todoBorder;
70 		int rBorder, gBorder, bBorder, sizeBorder, paddingBorder;
71 		bool showBorder;
72 		bool todoBackground;
73 		int rBg, gBg, bBg, paddingBg;
74 		bool showBackground;
75 	} AnimationXML;
76 
77 	typedef struct
78 	{
79 		int nElements;
80 	} ElementsAnimationXML;
81 
82 
83 	typedef struct
84 	{
85 		string type;
86 		int cycle;
87 	} ShowHideElement;
88 
89 	class ActionAnimation {
90 
91 	private:
92 		map<string, string> parameters;
93 
94 	public:
95 		string nameObjetive;
96 		string function;
97 		int cycle;
98 		int cyclesRepeat;
99 
100 		ActionAnimation();
101 		ActionAnimation(string f, int t);
addParameter(string name,string value)102 		void addParameter(string name, string value) { parameters[name] = value; }
103 		string getParameter(string name);
104 
setTime(int t)105 		void setTime(int t) { cycle = Converter::GetInstance()->ml2cycles(t); }
setTimeRepeat(int t)106 		void setTimeRepeat(int t) { cyclesRepeat = Converter::GetInstance()->ml2cycles(t); }
107 
108 		bool existParameter(string name);
109 
110 	};
111 
112 	class ObjectAnimation {
113 
114 	private:
115 		AnimatedElement *elem;
116 		Button *button;
117 		string name;
118 		string type;
119 
120 	public:
121 
122 		vector<ActionAnimation*> actions;
123 		vector<ActionAnimation*> actionsOnClick;
124 
125 		ObjectAnimation();
126 		~ObjectAnimation();
127 		void setType(string t);
getType()128 		string getType() { return type; }
setName(string n)129 		void setName(string n) { name = n; }
getName()130 		string getName() { return name; }
131 		AnimatedElement* getElement();
addAction(ActionAnimation * action)132 		void addAction(ActionAnimation* action) { actions.push_back(action); }
addActionOnClick(ActionAnimation * action)133 		void addActionOnClick(ActionAnimation* action) { actionsOnClick.push_back(action); }
134 
135 		vector<ActionAnimation*> verifyActions(int cycle);
136 
137 		void unLoad();
138 
139 	};
140 
141 	class SoundAnimation {
142 
143 	private:
144 		string name;
145 		string category;
146 		string file;
147 
148 	public:
149 
150 		vector<ActionAnimation*> actions;
151 
152 		SoundAnimation();
153 		~SoundAnimation();
setFile(string f)154 		void setFile(string f) { file = f; }
getFile()155 		string getFile() { return file; }
setName(string n)156 		void setName(string n) { name = n; }
getName()157 		string getName() { return name; }
setCategory(string c)158 		void setCategory(string c) { category = c; }
getCategory()159 		string getCategory() { return category; }
160 
addAction(ActionAnimation * action)161 		void addAction(ActionAnimation* action) { actions.push_back(action); }
162 
163 		vector<ActionAnimation*> verifyActions(int cycle);
164 
165 	};
166 
167 	class SceneAnimation : public Scene {
168 
169 	protected:
170 		string directory;
171 		int cycles;
172 		string nameSceneWhenScape;
173 		vector<ObjectAnimation*> objectsanimation;
174 		vector<SoundAnimation*> soundsanimation;
175 
176 		ParticlesSystem *stars;
177 		bool drawStar;
178 		vector<ShowHideElement> showHideStar;
179 
180 	public:
181 
182 		ProgressBar *pb;
183 		bool drawProgressBar;
184 
185 		SceneAnimation();
186 		~SceneAnimation();
187 
188 		string replace(string chain);
189 
190 		void createStars(string f);
addShowHideStar(ShowHideElement s)191 		void addShowHideStar(ShowHideElement s) { showHideStar.push_back(s); }
192 
setCycles(int c)193 		void setCycles (int c) { cycles = c; }
getCycles()194 		int getCycles () { return cycles; }
195 
setDirectory(string d)196 		void setDirectory (string d) { directory = d; }
getDirectory()197 		string getDirectory () { return directory; }
setNameSceneWhenScape(string n)198 		void setNameSceneWhenScape (string n) { nameSceneWhenScape = n; }
getNameSceneWhenScape()199 		string getNameSceneWhenScape () { return nameSceneWhenScape; }
200 		void load();
addObjectAnimation(ObjectAnimation * o)201 		void addObjectAnimation(ObjectAnimation *o) { objectsanimation.push_back(o); }
202 		ObjectAnimation* getObjectAnimation(string name);
203 
204 		void addSoundAnimation(SoundAnimation *s);
205 		SoundAnimation* getSoundAnimation(string name);
206 
207 		void makeAction_Object(ObjectAnimation *obj, ActionAnimation* act);
208 
209 		void makeAction_Sound(SoundAnimation *obj, ActionAnimation* act);
210 
211 		/*********************
212 		* BUTTONS
213 		**********************/
214 		void verifyClickElements_Main();
215 		void verifyOverElements_Main();
216 		/*********************
217 		* SCENES
218 		**********************/
219 		bool drawScene ();
220 
221 		void drawSceneMain ();
222 		void drawSceneMainByIndexZ(int z);
223 
224 		/*********************
225 		* CONTROL
226 		**********************/
227 		void unLoad();
228 
229 	};
230 
231 }
232 
233 #endif /* SCENEANIMATION_H_ */
234