1 //       _________ __                 __
2 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
3 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
4 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
5 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
6 //             \/                  \/          \//_____/            \/
7 //  ______________________                           ______________________
8 //                        T H E   W A R   B E G I N S
9 //         Stratagus - A free fantasy real time strategy game engine
10 //
11 /**@name popup.h - The Popup header file. */
12 //
13 //      (c) Copyright 2012 by Joris Dauphin
14 //
15 //      This program is free software; you can redistribute it and/or modify
16 //      it under the terms of the GNU General Public License as published by
17 //      the Free Software Foundation; only version 2 of the License.
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.  See the
22 //      GNU General Public License for more details.
23 //
24 //      You should have received a copy of the GNU General Public License
25 //      along with this program; if not, write to the Free Software
26 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 //      02111-1307, USA.
28 //
29 
30 #ifndef __POPUP_H__
31 #define __POPUP_H__
32 
33 //@{
34 
35 #include "script.h"
36 #include "color.h"
37 #include "vec2i.h"
38 #include <vector>
39 #include <string>
40 
41 /*----------------------------------------------------------------------------
42 --  Declarations
43 ----------------------------------------------------------------------------*/
44 
45 class ButtonAction;
46 class CFont;
47 class CPopup;
48 
49 #define MARGIN_X 4
50 #define MARGIN_Y 2
51 
52 class PopupConditionPanel
53 {
54 public:
PopupConditionPanel()55 	PopupConditionPanel() :  HasHint(false), HasDescription(false), HasDependencies(false),
56 		//Wyrmgus start
57 		Class(false), Description(false), Quote(false), Encyclopedia(false), SettlementName(false), CanActiveHarvest(false),
58 		Opponent(0), Neutral(0), AutoCast(0), Equipped(0), Equippable(0), Consumable(0), Affixed(0), Spell(0), CanUse(0), Work(0), ReadWork(0), Elixir(0), ConsumedElixir(0), Unique(0), UniqueSet(0), Bound(0), Identified(0), Weapon(0), Shield(0), Boots(0), Arrows(0), Regeneration(0), FactionUpgrade(0), FactionCoreSettlements(0), Ability(0), ChildResources(0), ImproveIncomes(0), LuxuryResource(0), RequirementsString(0), ExperienceRequirementsString(0), BuildingRulesString(0),
59 //		ButtonAction(-1), BoolFlags(nullptr), Variables(nullptr) {}
60 		ButtonAction(-1), UnitTypeType(-1), UnitTypeClass(-1), ItemClass(-1), CanStore(-1), ImproveIncome(-1), BoolFlags(nullptr), Variables(nullptr) {}
61 		//Wyrmgus end
~PopupConditionPanel()62 	~PopupConditionPanel()
63 	{
64 		delete[] BoolFlags;
65 		delete[] Variables;
66 	}
67 
68 	bool HasHint;               /// check if button has hint.
69 	bool HasDescription;        /// check if button has description.
70 	bool HasDependencies;       /// check if button has dependencies or restrictions.
71 	//Wyrmgus start
72 	bool Class;					/// check if the button's unit type has a class.
73 	bool Description;			/// check if the button's unit type has a description.
74 	bool Quote;					/// check if the button's unit type has a quote.
75 	bool Encyclopedia;			/// check if the button's unit type has an encyclopedia entry.
76 	bool SettlementName;		/// check if the button's unit has a settlement name.
77 	bool CanActiveHarvest;			/// check if the active unit can harvest the button's unit.
78 	//Wyrmgus end
79 	int ButtonAction;           /// action type of button
80 	//Wyrmgus start
81 	int UnitTypeType;			/// unit type type (i.e. land, fly, etc.) of the button's unit type
82 	int UnitTypeClass;			/// unit type class of the button's unit type
83 	int ItemClass;				/// item class of the button's item
84 	int CanStore;				/// whether the button's unit type can store a particular resource
85 	int ImproveIncome;			/// whether the button's unit type improves the processing of a particular resource
86 	CUpgrade *ResearchedUpgrade = nullptr;	/// whether the button's player has researched a particular upgrade
87 	int ResearchedUpgradeClass = -1;		/// whether the button's player has researched a particular upgrade class
88 	//Wyrmgus end
89 	std::string ButtonValue;    /// value used in ValueStr field of button
90 
91 	//Wyrmgus start
92 	char Opponent;				/// check if button's item is an opponent
93 	char Neutral;				/// check if button's item is neutral
94 	char AutoCast;				/// check if button's spell can be autocasted
95 	char Equipped;				/// check if button's item is equipped
96 	char Equippable;			/// check if button's item is equippable by its owner
97 	char Consumable;			/// check if button's item is consumable
98 	char Affixed;				/// check if button's item has an affix
99 	char Spell;					/// check if button's item has a spell
100 	char CanUse;				/// check if button's item's can be used
101 	char Work;					/// check if button's item is a work
102 	char ReadWork;				/// check if button's item is a work that has been read
103 	char Elixir;				/// check if button's item is an elixir
104 	char ConsumedElixir;		/// check if button's item is an elixir that has been consumed
105 	char Unique;				/// check if button's item is unique
106 	char UniqueSet;				/// check if button's item is part of a unique item set
107 	char Bound;					/// check if button's item is bound to its owner
108 	char Identified;			/// check if button's item has been identified
109 	char Weapon;				/// check if button's item is a weapon
110 	char Shield;				/// check if button's item is a shield
111 	char Boots;					/// check if button's item are boots
112 	char Arrows;				/// check if button's item are arrows
113 	char Regeneration;			/// check if button's item has regeneration
114 	char FactionUpgrade;		/// check if the button's upgrade is a faction upgrade
115 	char FactionCoreSettlements;	/// check if the button's faction has core settlements
116 	char UpgradeResearched = 0;		/// check if the button's upgrade has already been researched
117 	char Ability;				/// check if the button's upgrade is an ability
118 	char ChildResources;		/// check if the button's resource has child resources
119 	char ImproveIncomes;		/// check if the button's unit type has processing bonuses for any resource
120 	char LuxuryResource;		/// check if the button's resource is a luxury resource
121 	char RequirementsString;	/// check if the button's unit type or upgrade has a requirements string
122 	char ExperienceRequirementsString;	/// check if the button's unit type or upgrade has an experience requirements string
123 	char BuildingRulesString;	/// check if the button's unit type has a building rules string
124 	//Wyrmgus end
125 	char *BoolFlags;            /// array of condition about user flags.
126 	char *Variables;            /// array of variable to verify (enable and max > 0)
127 };
128 
129 class CPopupContentType
130 {
131 public:
CPopupContentType()132 	CPopupContentType() : pos(0, 0),
133 		MarginX(MARGIN_X), MarginY(MARGIN_Y), minSize(0, 0),
134 		Wrap(true), Condition(nullptr) {}
~CPopupContentType()135 	virtual ~CPopupContentType() { delete Condition; }
136 
137 	/// Tell how show the variable Index.
138 	virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const = 0;
139 	/// Get the content's width
140 	virtual int GetWidth(const ButtonAction &button, int *Costs) const = 0;
141 	/// Get the content's height
142 	virtual int GetHeight(const ButtonAction &button, int *Costs) const = 0;
143 
144 	virtual void Parse(lua_State *l) = 0;
145 
146 	static CPopupContentType *ParsePopupContent(lua_State *l);
147 
148 public:
149 	PixelPos pos;               /// position to draw.
150 
151 	int MarginX;                /// Left and right margin width.
152 	int MarginY;                /// Upper and lower margin height.
153 	PixelSize minSize;          /// Minimal size covered by content type.
154 	bool Wrap;                  /// If true, the next content will be placed on the next "line".
155 protected:
156 	std::string TextColor;      /// Color used for plain text in content.
157 	std::string HighlightColor; /// Color used for highlighted letters.
158 public:
159 	PopupConditionPanel *Condition; /// Condition to show the content; if null, no condition.
160 };
161 
162 enum PopupButtonInfo_Types {
163 	PopupButtonInfo_Hint,
164 	PopupButtonInfo_Description,
165 	PopupButtonInfo_Dependencies
166 };
167 
168 class CPopupContentTypeButtonInfo : public CPopupContentType
169 {
170 public:
CPopupContentTypeButtonInfo()171 	CPopupContentTypeButtonInfo() : InfoType(0), MaxWidth(0), Font(nullptr) {}
~CPopupContentTypeButtonInfo()172 	virtual ~CPopupContentTypeButtonInfo() {}
173 
174 	virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
175 
176 	virtual int GetWidth(const ButtonAction &button, int *Costs) const;
177 	virtual int GetHeight(const ButtonAction &button, int *Costs) const;
178 
179 	virtual void Parse(lua_State *l);
180 
181 private:
182 	int InfoType;                /// Type of information to show.
183 	unsigned int MaxWidth;       /// Maximum width of multilined information.
184 	CFont *Font;                 /// Font to use.
185 };
186 
187 class CPopupContentTypeText : public CPopupContentType
188 {
189 public:
190 	//Wyrmgus start
191 //	CPopupContentTypeText() : MaxWidth(0), Font(nullptr) {}
CPopupContentTypeText()192 	CPopupContentTypeText() : Text(nullptr), MaxWidth(0), Font(nullptr) {}
193 	//Wyrmgus end
194 	//Wyrmgus start
195 //	virtual ~CPopupContentTypeText() {}
~CPopupContentTypeText()196 	virtual ~CPopupContentTypeText() {
197 		FreeStringDesc(Text);
198 		delete Text;
199 	}
200 	//Wyrmgus end
201 
202 	virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
203 
204 	virtual int GetWidth(const ButtonAction &button, int *Costs) const;
205 	virtual int GetHeight(const ButtonAction &button, int *Costs) const;
206 
207 	virtual void Parse(lua_State *l);
208 
209 private:
210 	//Wyrmgus start
211 //	std::string Text;            /// Text to display
212 	StringDesc *Text;            /// Text to display.
213 	//Wyrmgus end
214 	unsigned int MaxWidth;       /// Maximum width of multilined text.
215 	CFont *Font;                 /// Font to use.
216 };
217 
218 class CPopupContentTypeCosts : public CPopupContentType
219 {
220 public:
CPopupContentTypeCosts()221 	CPopupContentTypeCosts() : Font(nullptr), Centered(0) {}
~CPopupContentTypeCosts()222 	virtual ~CPopupContentTypeCosts() {}
223 
224 	virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
225 
226 	virtual int GetWidth(const ButtonAction &button, int *Costs) const;
227 	virtual int GetHeight(const ButtonAction &button, int *Costs) const;
228 
229 	virtual void Parse(lua_State *l);
230 
231 private:
232 	CFont *Font;                 /// Font to use.
233 	char Centered;               /// if true, center the display.
234 };
235 
236 class CPopupContentTypeLine : public CPopupContentType
237 {
238 public:
239 	CPopupContentTypeLine();
~CPopupContentTypeLine()240 	virtual ~CPopupContentTypeLine() {}
241 
242 	virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
243 
244 	virtual int GetWidth(const ButtonAction &button, int *Costs) const;
245 	virtual int GetHeight(const ButtonAction &button, int *Costs) const;
246 
247 	virtual void Parse(lua_State *l);
248 
249 private:
250 	IntColor Color;  /// Color used for line.
251 	unsigned int Width;     /// line height
252 	unsigned int Height;    /// line height
253 };
254 
255 class CPopupContentTypeVariable : public CPopupContentType
256 {
257 public:
CPopupContentTypeVariable()258 	CPopupContentTypeVariable() : Text(nullptr), Font(nullptr), Centered(0), Index(-1) {}
~CPopupContentTypeVariable()259 	virtual ~CPopupContentTypeVariable()
260 	{
261 		FreeStringDesc(Text);
262 		delete Text;
263 	}
264 
265 	virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
266 
267 	virtual int GetWidth(const ButtonAction &button, int *Costs) const;
268 	virtual int GetHeight(const ButtonAction &button, int *Costs) const;
269 
270 	virtual void Parse(lua_State *l);
271 
272 private:
273 	StringDesc *Text;            /// Text to display.
274 	CFont *Font;                 /// Font to use.
275 	char Centered;               /// if true, center the display.
276 	int Index;                   /// Index of the variable to show, -1 if not.
277 };
278 
279 class CPopup
280 {
281 public:
282 	CPopup();
283 	~CPopup();
284 
285 	std::vector<CPopupContentType *> Contents; /// Array of contents to display.
286 	std::string Ident;                         /// Ident of the popup.
287 	int MarginX;                               /// Left and right margin width.
288 	int MarginY;                               /// Upper and lower margin height.
289 	int MinWidth;                              /// Minimal width covered by popup.
290 	int MinHeight;                             /// Minimal height covered by popup.
291 	CFont *DefaultFont;                        /// Default font for content.
292 	IntColor BackgroundColor;                  /// Color used for popup's background.
293 	IntColor BorderColor;                      /// Color used for popup's borders.
294 };
295 
296 
297 //@}
298 
299 #endif // !__UI_H__
300