| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name interface.h - The user interface header file. */ |
| 11 |
// |
| 12 |
// (c) Copyright 1998-2007 by Lutz Sammer and Jimmy Salmon |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
|
| 28 |
#ifndef __INTERFACE_H__ |
| 29 |
#define __INTERFACE_H__ |
| 30 |
|
| 31 |
//@{ |
| 32 |
|
| 33 |
/*---------------------------------------------------------------------------- |
| 34 |
-- Declarations |
| 35 |
----------------------------------------------------------------------------*/ |
| 36 |
|
| 37 |
#include <vector> |
| 38 |
#include "icons.h" |
| 39 |
|
| 40 |
/*---------------------------------------------------------------------------- |
| 41 |
-- Declarations |
| 42 |
----------------------------------------------------------------------------*/ |
| 43 |
|
| 44 |
class CUnit; |
| 45 |
struct _event_callback_; |
| 46 |
|
| 47 |
/*---------------------------------------------------------------------------- |
| 48 |
-- Definitons |
| 49 |
----------------------------------------------------------------------------*/ |
| 50 |
|
| 51 |
/// Button Commands that need target selection |
| 52 |
enum ButtonCmd { |
| 53 |
ButtonMove, /// order move |
| 54 |
ButtonAttack, /// order attack |
| 55 |
ButtonRepair, /// order repair |
| 56 |
ButtonHarvest, /// order harvest |
| 57 |
ButtonBuild, /// order build |
| 58 |
ButtonPatrol, /// order patrol |
| 59 |
ButtonAttackGround, /// order attack ground |
| 60 |
ButtonSpellCast, /// order cast spell |
| 61 |
ButtonUnload, /// order unload unit |
| 62 |
ButtonStop, /// order stop |
| 63 |
ButtonButton, /// choose other button set |
| 64 |
ButtonTrain, /// order train |
| 65 |
ButtonStandGround, /// order stand ground |
| 66 |
ButtonCancel, /// cancel |
| 67 |
ButtonCancelTrain, /// cancel training |
| 68 |
ButtonCancelBuild, /// cancel building |
| 69 |
}; |
| 70 |
|
| 71 |
class ButtonAction; |
| 72 |
typedef bool (*ButtonCheckFunc)(const CUnit *, const ButtonAction *); |
| 73 |
|
| 74 |
/// Action of button |
| 75 |
class ButtonAction { |
| 76 |
public: |
| 77 |
ButtonAction() : Pos(0), Level(0), Action(ButtonMove), Value(0), |
| 78 |
Allowed(NULL), Key(0) {} |
| 79 |
|
| 80 |
int Pos; /// button position in the grid |
| 81 |
int Level; /// requires button level |
| 82 |
ButtonCmd Action; /// command on button press |
| 83 |
int Value; /// extra value for command |
| 84 |
std::string ValueStr; /// keep original value string |
| 85 |
|
| 86 |
ButtonCheckFunc Allowed; /// Check if this button is allowed |
| 87 |
std::string AllowStr; /// argument for allowed |
| 88 |
std::string UnitMask; /// for which units is it available |
| 89 |
IconConfig Icon; /// icon to display |
| 90 |
int Key; /// alternative on keyboard |
| 91 |
std::string Hint; /// tip text |
| 92 |
}; |
| 93 |
|
| 94 |
/// Button area under cursor |
| 95 |
enum _button_area_ { |
| 96 |
ButtonAreaSelected, /// Selected button |
| 97 |
ButtonAreaTraining, /// Training button |
| 98 |
ButtonAreaTransporting, /// Transporting button |
| 99 |
ButtonAreaButton, /// Button panel button |
| 100 |
ButtonAreaMenu, /// Menu button |
| 101 |
}; |
| 102 |
|
| 103 |
/// Menu button under cursor |
| 104 |
enum _menu_button_under_ { |
| 105 |
ButtonUnderMenu, /// Menu button |
| 106 |
ButtonUnderNetworkMenu, /// Network menu button |
| 107 |
ButtonUnderNetworkDiplomacy, /// Diplomacy button |
| 108 |
}; |
| 109 |
|
| 110 |
/// current interface state |
| 111 |
enum _iface_state_ { |
| 112 |
IfaceStateNormal, /// Normal Game state |
| 113 |
IfaceStateMenu, /// Menu active |
| 114 |
}; |
| 115 |
|
| 116 |
/// current key state |
| 117 |
enum _key_state_ { |
| 118 |
KeyStateCommand = 0, /// keys -> commands |
| 119 |
KeyStateInput /// keys -> line editor |
| 120 |
}; /// current keyboard state |
| 121 |
|
| 122 |
/// Key modifier |
| 123 |
#define ModifierShift 1 /// any shift key pressed |
| 124 |
#define ModifierControl 2 /// any control key pressed |
| 125 |
#define ModifierAlt 4 /// any alt key pressed |
| 126 |
#define ModifierSuper 8 /// super key (reserved for WM) |
| 127 |
#define ModifierDoublePress 16 /// key double pressed |
| 128 |
|
| 129 |
#define MouseDoubleShift 8 /// shift for double click button |
| 130 |
#define MouseDragShift 16 /// shift for drag button |
| 131 |
#define MouseHoldShift 24 /// shift for hold button |
| 132 |
|
| 133 |
/// pressed mouse button flags |
| 134 |
#define NoButton 0 /// No button |
| 135 |
#define LeftButton 2 /// Left button on mouse |
| 136 |
#define MiddleButton 4 /// Middle button on mouse |
| 137 |
#define RightButton 8 /// Right button on mouse |
| 138 |
|
| 139 |
#define UpButton 16 /// Scroll up button on mouse |
| 140 |
#define DownButton 32 /// Scroll down button on mouse |
| 141 |
|
| 142 |
#define LeftAndMiddleButton (LeftButton | MiddleButton) /// Left + Middle button on mouse |
| 143 |
#define LeftAndRightButton (LeftButton | RightButton) /// Left + Right button on mouse |
| 144 |
#define MiddleAndRightButton (MiddleButton | RightButton) /// Middle + Right button on mouse |
| 145 |
|
| 146 |
/// Where is our cursor ? |
| 147 |
enum _cursor_on_ { |
| 148 |
CursorOnUnknown = -1, /// not known |
| 149 |
CursorOnMinimap, /// minimap area |
| 150 |
CursorOnButton, /// button area see: ButtonUnderCursor |
| 151 |
CursorOnMap, /// over map area |
| 152 |
CursorOnScrollUp, /// in scroll up area |
| 153 |
CursorOnScrollDown, /// in scroll down area |
| 154 |
CursorOnScrollLeft, /// in scroll left area |
| 155 |
CursorOnScrollRight, /// in scroll right area |
| 156 |
CursorOnScrollLeftUp, /// in scroll left+up area |
| 157 |
CursorOnScrollLeftDown, /// in scroll left+down area |
| 158 |
CursorOnScrollRightUp, /// in scroll right+up area |
| 159 |
CursorOnScrollRightDown, /// in scroll right+down area |
| 160 |
}; |
| 161 |
|
| 162 |
/// Are We Scrolling With the Keyboard ? |
| 163 |
#define ScrollNone 0 /// not scrolling |
| 164 |
#define ScrollUp 1 /// scroll up only |
| 165 |
#define ScrollDown 2 /// scroll down only |
| 166 |
#define ScrollLeft 4 /// scroll left only |
| 167 |
#define ScrollRight 8 /// scroll right only |
| 168 |
#define ScrollLeftUp 5 /// scroll left + up |
| 169 |
#define ScrollLeftDown 6 /// scroll left + down |
| 170 |
#define ScrollRightUp 9 /// scroll right + up |
| 171 |
#define ScrollRightDown 10 /// scroll right + down |
| 172 |
|
| 173 |
/*---------------------------------------------------------------------------- |
| 174 |
-- Variables |
| 175 |
----------------------------------------------------------------------------*/ |
| 176 |
|
| 177 |
/// Flag telling if the game is running |
| 178 |
extern bool GameRunning; |
| 179 |
/// Flag telling if the game is paused |
| 180 |
extern bool GamePaused; |
| 181 |
/// Flag telling if the game is in observe mode |
| 182 |
extern bool GameObserve; |
| 183 |
/// Flag telling not to advance to the next game cycle |
| 184 |
extern char SkipGameCycle; |
| 185 |
/// Invincibility cheat |
| 186 |
extern bool GodMode; |
| 187 |
/// Whether the map is the only thing displayed or not |
| 188 |
extern char BigMapMode; |
| 189 |
|
| 190 |
/// pressed mouse buttons (normal,double,dragged,long) |
| 191 |
extern int MouseButtons; |
| 192 |
/// current active modifiers |
| 193 |
extern int KeyModifiers; |
| 194 |
/// current interface state |
| 195 |
extern enum _iface_state_ InterfaceState; |
| 196 |
/// current scroll state of keyboard |
| 197 |
extern int KeyScrollState; |
| 198 |
/// current scroll state of mouse |
| 199 |
extern int MouseScrollState; |
| 200 |
/// current key state |
| 201 |
extern enum _key_state_ KeyState; |
| 202 |
/// pointer to unit under the cursor |
| 203 |
extern CUnit *UnitUnderCursor; |
| 204 |
/// button area under the cursor |
| 205 |
extern int ButtonAreaUnderCursor; |
| 206 |
/// button number under the cursor |
| 207 |
extern int ButtonUnderCursor; |
| 208 |
/// menu button was clicked down |
| 209 |
extern bool GameMenuButtonClicked; |
| 210 |
/// diplomacy button was clicked down |
| 211 |
extern bool GameDiplomacyButtonClicked; |
| 212 |
/// Mouse leaves windows stops scroll |
| 213 |
extern bool LeaveStops; |
| 214 |
/// current CursorOn field |
| 215 |
extern enum _cursor_on_ CursorOn; |
| 216 |
|
| 217 |
/// vladi: used for unit buttons sub-menus etc |
| 218 |
extern int CurrentButtonLevel; |
| 219 |
|
| 220 |
/// Time to detect double clicks |
| 221 |
extern int DoubleClickDelay; |
| 222 |
/// Time to detect hold clicks |
| 223 |
extern int HoldClickDelay; |
| 224 |
|
| 225 |
/// All buttons for units |
| 226 |
extern std::vector<ButtonAction *> UnitButtonTable; |
| 227 |
|
| 228 |
/*---------------------------------------------------------------------------- |
| 229 |
-- Functions |
| 230 |
----------------------------------------------------------------------------*/ |
| 231 |
|
| 232 |
// |
| 233 |
// in botpanel.cpp |
| 234 |
// |
| 235 |
/// Generate all buttons |
| 236 |
extern void InitButtons(void); |
| 237 |
/// Free memory for buttons |
| 238 |
extern void CleanButtons(void); |
| 239 |
/// Make a new button |
| 240 |
extern int AddButton(int pos, int level, const std::string &IconIdent, |
| 241 |
ButtonCmd action, const std::string &value, const ButtonCheckFunc func, |
| 242 |
const std::string &arg, const std::string &hint, const std::string &umask); |
| 243 |
|
| 244 |
// |
| 245 |
// in mouse.cpp |
| 246 |
// |
| 247 |
/// Called if any mouse button is pressed down |
| 248 |
extern void HandleButtonDown(unsigned button); |
| 249 |
/// Called if any mouse button is released up |
| 250 |
extern void HandleButtonUp(unsigned button); |
| 251 |
/// Keep coordinates in window and update cursor position |
| 252 |
extern void HandleCursorMove(int *x, int *y); |
| 253 |
/// Called if the mouse is moved |
| 254 |
extern void HandleMouseMove(int x, int y); |
| 255 |
/// Called if the mouse exits the game window (only for some videomodes) |
| 256 |
extern void HandleMouseExit(void); |
| 257 |
|
| 258 |
/// Update KeyModifiers if a key is pressed |
| 259 |
extern int HandleKeyModifiersDown(unsigned keycode, unsigned keychar); |
| 260 |
/// Update KeyModifiers if a key is released |
| 261 |
extern int HandleKeyModifiersUp(unsigned keycode, unsigned keychar); |
| 262 |
|
| 263 |
/// Called if a key is pressed |
| 264 |
extern void HandleKeyDown(unsigned keycode, unsigned keychar); |
| 265 |
/// Called when a key is released |
| 266 |
extern void HandleKeyUp(unsigned keycode, unsigned keychar); |
| 267 |
/// Called when a key is repeated |
| 268 |
extern void HandleKeyRepeat(unsigned keycode, unsigned keychar); |
| 269 |
|
| 270 |
// |
| 271 |
// in interface.c (for link between video and mouse.c) |
| 272 |
// |
| 273 |
/// Called if any mouse button is pressed down |
| 274 |
extern void InputMouseButtonPress(const struct _event_callback_ *callbacks, |
| 275 |
unsigned ticks, unsigned button); |
| 276 |
/// Called if any mouse button is released up |
| 277 |
extern void InputMouseButtonRelease(const struct _event_callback_ *callbacks, |
| 278 |
unsigned ticks, unsigned button); |
| 279 |
/// Called if the mouse is moved |
| 280 |
extern void InputMouseMove(const struct _event_callback_ *callbacks, |
| 281 |
unsigned ticks, int x, int y); |
| 282 |
/// Called if the mouse exits the game window (when supported by videomode) |
| 283 |
extern void InputMouseExit(const struct _event_callback_ *callbacks, |
| 284 |
unsigned ticks); |
| 285 |
/// Called to look for mouse timeouts |
| 286 |
extern void InputMouseTimeout(const struct _event_callback_ *callbacks, |
| 287 |
unsigned ticks); |
| 288 |
|
| 289 |
/// Called if any key button is pressed down |
| 290 |
extern void InputKeyButtonPress(const struct _event_callback_ *callbacks, |
| 291 |
unsigned ticks, unsigned ikey, unsigned ikeychar); |
| 292 |
/// Called if any key button is released up |
| 293 |
extern void InputKeyButtonRelease(const struct _event_callback_ *callbacks, |
| 294 |
unsigned ticks, unsigned ikey, unsigned ikeychar); |
| 295 |
/// Called to look for key timeouts |
| 296 |
extern void InputKeyTimeout(const struct _event_callback_ *callbacks, |
| 297 |
unsigned ticks); |
| 298 |
|
| 299 |
/// Get double click delay |
| 300 |
extern int GetDoubleClickDelay(void); |
| 301 |
/// Set double click delay |
| 302 |
extern void SetDoubleClickDelay(int delay); |
| 303 |
/// Get hold click delay |
| 304 |
extern int GetHoldClickDelay(void); |
| 305 |
/// Set hold click delay |
| 306 |
extern void SetHoldClickDelay(int delay); |
| 307 |
|
| 308 |
/// Toggle pause mode |
| 309 |
extern void UiTogglePause(void); |
| 310 |
/// Handle cheats |
| 311 |
extern int HandleCheats(const std::string &input); |
| 312 |
|
| 313 |
/// Call the lua function HandleCommandKey |
| 314 |
bool HandleCommandKey(int key); |
| 315 |
|
| 316 |
// |
| 317 |
// Chaos pur. |
| 318 |
// |
| 319 |
/// Called if right mouse button is pressed |
| 320 |
extern void DoRightButton(int tx, int ty); |
| 321 |
/// Cancel the building input mode |
| 322 |
extern void CancelBuildingMode(void); |
| 323 |
|
| 324 |
/// Draw menu button area |
| 325 |
extern void DrawMenuButtonArea(void); |
| 326 |
/// Update messages |
| 327 |
extern void UpdateMessages(void); |
| 328 |
/// Draw messages as overlay over of the map |
| 329 |
extern void DrawMessages(void); |
| 330 |
/// Draw the player resource in resource line |
| 331 |
extern void DrawResources(void); |
| 332 |
/// Set message to display |
| 333 |
extern void SetMessage(const char *fmt, ...) GCC_ATTR((format(printf, 1, 2))); |
| 334 |
/// Set message to display with event point |
| 335 |
extern void SetMessageEvent(int x, int y, const char *fmt, ...) GCC_ATTR((format(printf, 3, 4))); |
| 336 |
/// Center view-point on last event message |
| 337 |
extern void CenterOnMessage(void); |
| 338 |
/// Cleanup all messages |
| 339 |
extern void CleanMessages(void); |
| 340 |
|
| 341 |
/// Draw costs in status line |
| 342 |
extern void DrawCosts(void); |
| 343 |
/// Set costs to be displayed in status line |
| 344 |
extern void SetCosts(int charge, const int *costs); |
| 345 |
/// Clear the costs displayed in status line (undisplay!) |
| 346 |
extern void ClearCosts(void); |
| 347 |
|
| 348 |
/// Draw the timer |
| 349 |
extern void DrawTimer(void); |
| 350 |
/// Update the timer |
| 351 |
extern void UpdateTimer(void); |
| 352 |
/// Update the status line with hints from the button |
| 353 |
extern void UpdateStatusLineForButton(const ButtonAction *button); |
| 354 |
/// Check if the button is allowed for the unit. |
| 355 |
extern bool IsButtonAllowed(const CUnit *, const ButtonAction *); |
| 356 |
/// Draw the Pie Menu |
| 357 |
extern void DrawPieMenu(void); |
| 358 |
|
| 359 |
/// Handle the mouse in scroll area |
| 360 |
extern int HandleMouseScrollArea(int x, int y); |
| 361 |
|
| 362 |
// |
| 363 |
// in button_checks.cpp |
| 364 |
// |
| 365 |
/// Check is always true |
| 366 |
extern bool ButtonCheckTrue(const CUnit *unit, |
| 367 |
const ButtonAction *button); |
| 368 |
/// Check is always false |
| 369 |
extern bool ButtonCheckFalse(const CUnit *unit, |
| 370 |
const ButtonAction *button); |
| 371 |
/// Check if allowed units exists |
| 372 |
extern bool ButtonCheckUnitsOr(const CUnit *unit, |
| 373 |
const ButtonAction *button); |
| 374 |
/// Check if allowed units exists |
| 375 |
extern bool ButtonCheckUnitsAnd(const CUnit *unit, |
| 376 |
const ButtonAction *button); |
| 377 |
/// Check if have network play |
| 378 |
extern bool ButtonCheckNetwork(const CUnit *unit, |
| 379 |
const ButtonAction *button); |
| 380 |
/// Check if don't have network play |
| 381 |
extern bool ButtonCheckNoNetwork(const CUnit *unit, |
| 382 |
const ButtonAction *button); |
| 383 |
/// Check if unit isn't working (train) |
| 384 |
extern bool ButtonCheckNoWork(const CUnit *unit, |
| 385 |
const ButtonAction *button); |
| 386 |
/// Check if all requirements for an attack to are meet |
| 387 |
extern bool ButtonCheckAttack(const CUnit *unit, |
| 388 |
const ButtonAction *button); |
| 389 |
|
| 390 |
// |
| 391 |
// in script_ui.cpp |
| 392 |
// |
| 393 |
/// Called whenever the units selection is altered |
| 394 |
extern void SelectionChanged(void); |
| 395 |
/// Called whenever the selected unit was updated |
| 396 |
extern void SelectedUnitChanged(void); |
| 397 |
|
| 398 |
// |
| 399 |
// in game.cpp |
| 400 |
// |
| 401 |
/// Set the game paused or unpaused |
| 402 |
extern void SetGamePaused(bool paused); |
| 403 |
/// Get the game paused or unpaused |
| 404 |
extern bool GetGamePaused(); |
| 405 |
/// Set the game speed |
| 406 |
extern void SetGameSpeed(int speed); |
| 407 |
/// Get the game speed |
| 408 |
extern int GetGameSpeed(); |
| 409 |
|
| 410 |
//@} |
| 411 |
|
| 412 |
#endif // !__INTERFACE_H__ |