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 button_action.h - The button action header file. */
12 //
13 //      (c) Copyright 1998-2019 by Lutz Sammer, Jimmy Salmon and Andrettin
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 __BUTTON_ACTION_H__
31 #define __BUTTON_ACTION_H__
32 
33 //@{
34 
35 /*----------------------------------------------------------------------------
36 --  Includes
37 ----------------------------------------------------------------------------*/
38 
39 #include <string>
40 #include <vector>
41 
42 #include "icons.h"
43 #include "unitsound.h"
44 
45 /*----------------------------------------------------------------------------
46 --  Declarations
47 ----------------------------------------------------------------------------*/
48 
49 class CButtonLevel;
50 class CUnit;
51 
52 /*----------------------------------------------------------------------------
53 --  Definitons
54 ----------------------------------------------------------------------------*/
55 
56 /// Button Commands that need target selection
57 enum ButtonCmd {
58 	ButtonMove,           /// order move
59 	ButtonAttack,         /// order attack
60 	ButtonRepair,         /// order repair
61 	ButtonHarvest,        /// order harvest
62 	ButtonBuild,          /// order build
63 	ButtonPatrol,         /// order patrol
64 	ButtonAttackGround,   /// order attack ground
65 	ButtonSpellCast,      /// order cast spell
66 	ButtonUnload,         /// order unload unit
67 	ButtonStop,           /// order stop
68 	ButtonButton,         /// choose other button set
69 	ButtonTrain,          /// order train
70 	ButtonStandGround,    /// order stand ground
71 	ButtonReturn,         /// order return goods
72 	ButtonResearch,       /// order reseach
73 	ButtonLearnAbility,   /// order learn ability
74 	ButtonExperienceUpgradeTo,   /// order upgrade (experience)
75 	ButtonUpgradeTo,      /// order upgrade
76 	ButtonRallyPoint,		/// set rally point
77 	ButtonFaction,			/// change faction
78 	ButtonQuest,			/// receive quest
79 	ButtonBuy,				/// buy item
80 	ButtonProduceResource,	/// produce a resource
81 	ButtonSellResource,		/// sell a resource
82 	ButtonBuyResource,		/// buy a resource
83 	ButtonSalvage,			/// salvage a building
84 	ButtonEnterMapLayer,	/// enter a map layer
85 	ButtonUnit,				/// used to display popups for inventory items and for units in transporters
86 	ButtonEditorUnit,		/// used to display popups for editor unit type buttons
87 	ButtonCancel,         /// cancel
88 	ButtonCancelUpgrade,  /// cancel upgrade
89 	ButtonCancelTrain,    /// cancel training
90 	ButtonCancelBuild,    /// cancel building
91 	ButtonCallbackAction
92 };
93 
94 class ButtonAction;
95 typedef bool (*ButtonCheckFunc)(const CUnit &, const ButtonAction &);
96 
97 /// Action of button
98 class ButtonAction
99 {
100 public:
ButtonAction()101 	ButtonAction() : Pos(0), Level(nullptr), AlwaysShow(false), Action(ButtonMove), Value(0), Payload(nullptr),
102 		Allowed(nullptr), Key(0) {}
103 
104 	static void ProcessConfigData(const CConfigData *config_data);
105 
106 	void SetTriggerData() const;
107 	void CleanTriggerData() const;
108 	int GetLevelID() const;
109 	int GetKey() const;
110 	std::string GetHint() const;
111 
112 	int Pos;					/// button position in the grid
113 	CButtonLevel *Level;		/// requires button level
114 	bool AlwaysShow;			/// button is always shown but drawn grayscale if not available
115 	ButtonCmd Action;			/// command on button press
116 	int Value;					/// extra value for command
117 	void *Payload;
118 	std::string ValueStr;		/// keep original value string
119 
120 	ButtonCheckFunc Allowed;    /// Check if this button is allowed
121 	std::string AllowStr;       /// argument for allowed
122 	std::string UnitMask;       /// for which units is it available
123 	IconConfig Icon;      		/// icon to display
124 	int Key;                    /// alternative on keyboard
125 	std::string Hint;           /// tip texts
126 	std::string Description;    /// description shown on status bar (optional)
127 	SoundConfig CommentSound;   /// Sound comment used when you press the button
128 	std::string ButtonCursor;   /// Custom cursor for button action (for example, to set spell target)
129 	std::string Popup;          /// Popup screen used for button
130 	std::string Mod;			/// Mod to which this button belongs to
131 };
132 
133 /*----------------------------------------------------------------------------
134 --  Variables
135 ----------------------------------------------------------------------------*/
136 
137 extern std::vector<ButtonAction *> UnitButtonTable;
138 
139 /*----------------------------------------------------------------------------
140 --  Functions
141 ----------------------------------------------------------------------------*/
142 
143 //
144 // in botpanel.cpp
145 //
146 /// Generate all buttons
147 extern void InitButtons();
148 /// Free memory for buttons
149 extern void CleanButtons();
150 /// Make a new button
151 extern int AddButton(int pos, CButtonLevel *level, const std::string &IconIdent,
152 					 ButtonCmd action, const std::string &value, void* payload, const ButtonCheckFunc func,
153 					 const std::string &arg, const int key, const std::string &hint, const std::string &descr,
154 					 const std::string &sound, const std::string &cursor, const std::string &umask,
155 					 //Wyrmgus start
156 //					 const std::string &popup, bool alwaysShow);
157 					 const std::string &popup, bool alwaysShow, const std::string &mod_file);
158 					 //Wyrmgus end
159 // Check if the button is allowed for the unit.
160 extern bool IsButtonAllowed(const CUnit &unit, const ButtonAction &buttonaction);
161 
162 // Check if the button is usable for the unit.
163 extern bool IsButtonUsable(const CUnit &unit, const ButtonAction &buttonaction);
164 
165 // Get the cooldown for the button for the unit.
166 extern int GetButtonCooldown(const CUnit &unit, const ButtonAction &buttonaction);
167 
168 // Get the cooldown percent for the button for the unit.
169 extern int GetButtonCooldownPercent(const CUnit &unit, const ButtonAction &buttonaction);
170 
171 extern std::string GetButtonActionNameById(const int button_action);
172 extern int GetButtonActionIdByName(const std::string &button_action);
173 extern bool IsNeutralUsableButtonAction(const int button_action);
174 
175 //@}
176 
177 #endif // !__BUTTON_ACTION_H__
178