InGameUI.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: InGameUI.h ///////////////////////////////////////////////////////////////////////////////
  24. // Defines the in-game user interface singleton
  25. // Author: Michael S. Booth, March 2001
  26. // Colin Day August 2001, or so
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. #ifndef _IN_GAME_UI_H_
  30. #define _IN_GAME_UI_H_
  31. #include "Common/GameCommon.h"
  32. #include "Common/GameType.h"
  33. #include "Common/MessageStream.h" // for GameMessageTranslator
  34. #include "Common/KindOf.h"
  35. #include "Common/SpecialPowerType.h"
  36. #include "Common/Snapshot.h"
  37. #include "Common/STLTypedefs.h"
  38. #include "Common/SubsystemInterface.h"
  39. #include "Common/UnicodeString.h"
  40. #include "GameClient/DisplayString.h"
  41. #include "GameClient/Mouse.h"
  42. #include "GameClient/RadiusDecal.h"
  43. #include "GameClient/View.h"
  44. // FORWARD DECLARATIONS ///////////////////////////////////////////////////////////////////////////
  45. class Drawable;
  46. class Object;
  47. class ThingTemplate;
  48. class GameWindow;
  49. class VideoBuffer;
  50. class VideoStreamInterface;
  51. class CommandButton;
  52. class SpecialPowerTemplate;
  53. class WindowLayout;
  54. class Anim2DTemplate;
  55. class Anim2D;
  56. class Shadow;
  57. enum LegalBuildCode;
  58. enum KindOfType;
  59. enum ShadowType;
  60. enum CanAttackResult;
  61. // ------------------------------------------------------------------------------------------------
  62. enum RadiusCursorType
  63. {
  64. RADIUSCURSOR_NONE = 0,
  65. RADIUSCURSOR_ATTACK_DAMAGE_AREA,
  66. RADIUSCURSOR_ATTACK_SCATTER_AREA,
  67. RADIUSCURSOR_ATTACK_CONTINUE_AREA,
  68. RADIUSCURSOR_GUARD_AREA,
  69. RADIUSCURSOR_EMERGENCY_REPAIR,
  70. RADIUSCURSOR_FRIENDLY_SPECIALPOWER,
  71. RADIUSCURSOR_OFFENSIVE_SPECIALPOWER,
  72. RADIUSCURSOR_SUPERWEAPON_SCATTER_AREA,
  73. RADIUSCURSOR_PARTICLECANNON,
  74. RADIUSCURSOR_A10STRIKE,
  75. RADIUSCURSOR_CARPETBOMB,
  76. RADIUSCURSOR_DAISYCUTTER,
  77. RADIUSCURSOR_PARADROP,
  78. RADIUSCURSOR_SPYSATELLITE,
  79. RADIUSCURSOR_SPECTREGUNSHIP,
  80. RADIUSCURSOR_HELIX_NAPALM_BOMB,
  81. RADIUSCURSOR_NUCLEARMISSILE,
  82. RADIUSCURSOR_EMPPULSE,
  83. RADIUSCURSOR_ARTILLERYBARRAGE,
  84. RADIUSCURSOR_NAPALMSTRIKE,
  85. RADIUSCURSOR_CLUSTERMINES,
  86. RADIUSCURSOR_SCUDSTORM,
  87. RADIUSCURSOR_ANTHRAXBOMB,
  88. RADIUSCURSOR_AMBUSH,
  89. RADIUSCURSOR_RADAR,
  90. RADIUSCURSOR_SPYDRONE,
  91. RADIUSCURSOR_FRENZY,
  92. RADIUSCURSOR_CLEARMINES,
  93. RADIUSCURSOR_AMBULANCE,
  94. RADIUSCURSOR_COUNT // keep last
  95. };
  96. #ifdef DEFINE_RADIUSCURSOR_NAMES
  97. static const char *TheRadiusCursorNames[] =
  98. {
  99. "NONE",
  100. "ATTACK_DAMAGE_AREA",
  101. "ATTACK_SCATTER_AREA",
  102. "ATTACK_CONTINUE_AREA",
  103. "GUARD_AREA",
  104. "EMERGENCY_REPAIR",
  105. "FRIENDLY_SPECIALPOWER", //green
  106. "OFFENSIVE_SPECIALPOWER", //red
  107. "SUPERWEAPON_SCATTER_AREA",//red
  108. "PARTICLECANNON",
  109. "A10STRIKE",
  110. "CARPETBOMB",
  111. "DAISYCUTTER",
  112. "PARADROP",
  113. "SPYSATELLITE",
  114. "SPECTREGUNSHIP",
  115. "HELIX_NAPALM_BOMB",
  116. "NUCLEARMISSILE",
  117. "EMPPULSE",
  118. "ARTILLERYBARRAGE",
  119. "NAPALMSTRIKE",
  120. "CLUSTERMINES",
  121. "SCUDSTORM",
  122. "ANTHRAXBOMB",
  123. "AMBUSH",
  124. "RADAR",
  125. "SPYDRONE",
  126. "FRENZY",
  127. "CLEARMINES",
  128. "AMBULANCE",
  129. NULL
  130. };
  131. #endif
  132. // ------------------------------------------------------------------------------------------------
  133. /** For keeping track in the UI of how much build progress has been done */
  134. // ------------------------------------------------------------------------------------------------
  135. enum { MAX_BUILD_PROGRESS = 64 }; ///< interface can support building this many different units
  136. struct BuildProgress
  137. {
  138. const ThingTemplate *m_thingTemplate;
  139. Real m_percentComplete;
  140. GameWindow *m_control;
  141. };
  142. // TYPE DEFINES ///////////////////////////////////////////////////////////////////////////////////
  143. // ------------------------------------------------------------------------------------------------
  144. typedef std::list<Drawable *> DrawableList;
  145. typedef std::list<Drawable *>::iterator DrawableListIt;
  146. typedef std::list<Drawable *>::const_iterator DrawableListCIt;
  147. // ------------------------------------------------------------------------------------------------
  148. // ------------------------------------------------------------------------------------------------
  149. class SuperweaponInfo : public MemoryPoolObject
  150. {
  151. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(SuperweaponInfo, "SuperweaponInfo")
  152. private:
  153. // not saved
  154. DisplayString * m_nameDisplayString; ///< display string used to render the message
  155. DisplayString * m_timeDisplayString; ///< display string used to render the message
  156. Color m_color;
  157. const SpecialPowerTemplate* m_powerTemplate;
  158. public:
  159. SuperweaponInfo(
  160. ObjectID id,
  161. UnsignedInt timestamp,
  162. Bool hiddenByScript,
  163. Bool hiddenByScience,
  164. Bool ready,
  165. Bool evaReadyPlayed,
  166. const AsciiString& superweaponNormalFont,
  167. Int superweaponNormalPointSize,
  168. Bool superweaponNormalBold,
  169. Color c,
  170. const SpecialPowerTemplate* spt
  171. );
  172. const SpecialPowerTemplate* getSpecialPowerTemplate() const { return m_powerTemplate; }
  173. void setFont(const AsciiString& superweaponNormalFont, Int superweaponNormalPointSize, Bool superweaponNormalBold);
  174. void setText(const UnicodeString& name, const UnicodeString& time);
  175. void drawName(Int x, Int y, Color color, Color dropColor);
  176. void drawTime(Int x, Int y, Color color, Color dropColor);
  177. Real getHeight() const;
  178. // saved & public
  179. AsciiString m_powerName;
  180. ObjectID m_id;
  181. UnsignedInt m_timestamp; ///< seconds shown in display string
  182. Bool m_hiddenByScript;
  183. Bool m_hiddenByScience;
  184. Bool m_ready; ///< Stores if we were ready last draw, since readyness can change without time changing
  185. Bool m_evaReadyPlayed; ///< Stores if Eva announced superweapon is ready
  186. // not saved, but public
  187. Bool m_forceUpdateText;
  188. };
  189. // ------------------------------------------------------------------------------------------------
  190. typedef std::list<SuperweaponInfo *> SuperweaponList;
  191. typedef std::map<AsciiString, SuperweaponList> SuperweaponMap;
  192. // ------------------------------------------------------------------------------------------------
  193. // Popup message box
  194. class PopupMessageData : public MemoryPoolObject
  195. {
  196. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(PopupMessageData, "PopupMessageData")
  197. public:
  198. UnicodeString message;
  199. Int x;
  200. Int y;
  201. Int width;
  202. Color textColor;
  203. Bool pause;
  204. Bool pauseMusic;
  205. WindowLayout* layout;
  206. };
  207. EMPTY_DTOR(PopupMessageData)
  208. // ------------------------------------------------------------------------------------------------
  209. class NamedTimerInfo : public MemoryPoolObject
  210. {
  211. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NamedTimerInfo, "NamedTimerInfo")
  212. public:
  213. AsciiString m_timerName; ///< Timer name, needed on Load to reconstruct Map.
  214. UnicodeString timerText; ///< timer text
  215. DisplayString* displayString; ///< display string used to render the message
  216. UnsignedInt timestamp; ///< seconds shown in display string
  217. Color color;
  218. Bool isCountdown;
  219. };
  220. EMPTY_DTOR(NamedTimerInfo)
  221. // ------------------------------------------------------------------------------------------------
  222. typedef std::map<AsciiString, NamedTimerInfo *> NamedTimerMap;
  223. typedef NamedTimerMap::iterator NamedTimerMapIt;
  224. // ------------------------------------------------------------------------------------------------
  225. enum {MAX_SUBTITLE_LINES = 4}; ///< The maximum number of lines a subtitle can have
  226. // ------------------------------------------------------------------------------------------------
  227. // Floating Text Data
  228. class FloatingTextData : public MemoryPoolObject
  229. {
  230. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(FloatingTextData, "FloatingTextData")
  231. public:
  232. FloatingTextData(void);
  233. //~FloatingTextData(void);
  234. Color m_color; ///< It's current color
  235. UnicodeString m_text; ///< the text we're displaying
  236. DisplayString* m_dString; ///< The display string
  237. Coord3D m_pos3D; ///< the 3d position in game coords
  238. Int m_frameTimeOut; ///< when we want this thing to disappear
  239. Int m_frameCount; ///< how many frames have we been displaying text?
  240. };
  241. typedef std::list<FloatingTextData *> FloatingTextList;
  242. typedef FloatingTextList::iterator FloatingTextListIt;
  243. enum
  244. {
  245. DEFAULT_FLOATING_TEXT_TIMEOUT = LOGICFRAMES_PER_SECOND/3,
  246. };
  247. ///////////////////////////////////////////////////////////////////////////////////////////////////
  248. ///////////////////////////////////////////////////////////////////////////////////////////////////
  249. ///////////////////////////////////////////////////////////////////////////////////////////////////
  250. // ------------------------------------------------------------------------------------------------
  251. enum WorldAnimationOptions
  252. {
  253. WORLD_ANIM_NO_OPTIONS = 0x00000000,
  254. WORLD_ANIM_FADE_ON_EXPIRE = 0x00000001,
  255. WORLD_ANIM_PLAY_ONCE_AND_DESTROY = 0x00000002,
  256. };
  257. // ------------------------------------------------------------------------------------------------
  258. class WorldAnimationData
  259. {
  260. public:
  261. WorldAnimationData( void );
  262. ~WorldAnimationData( void ) { }
  263. Anim2D *m_anim; ///< the animation instance
  264. Coord3D m_worldPos; ///< position in the world
  265. UnsignedInt m_expireFrame; ///< frame we expire on
  266. WorldAnimationOptions m_options; ///< options
  267. Real m_zRisePerSecond; ///< Z units to rise per second
  268. };
  269. typedef std::list< WorldAnimationData *> WorldAnimationList;
  270. typedef WorldAnimationList::iterator WorldAnimationListIterator;
  271. // ------------------------------------------------------------------------------------------------
  272. /** Basic functionality common to all in-game user interfaces */
  273. // ------------------------------------------------------------------------------------------------
  274. class InGameUI : public SubsystemInterface, public Snapshot
  275. {
  276. friend class Drawable; // for selection/deselection transactions
  277. public: // ***************************************************************************************
  278. enum SelectionRules
  279. {
  280. SELECTION_ANY, //Only one of the selected units has to qualify
  281. SELECTION_ALL, //All selected units have to qualify
  282. };
  283. enum ActionType
  284. {
  285. ACTIONTYPE_NONE,
  286. ACTIONTYPE_ATTACK_OBJECT,
  287. ACTIONTYPE_GET_REPAIRED_AT,
  288. ACTIONTYPE_DOCK_AT,
  289. ACTIONTYPE_GET_HEALED_AT,
  290. ACTIONTYPE_REPAIR_OBJECT,
  291. ACTIONTYPE_RESUME_CONSTRUCTION,
  292. ACTIONTYPE_ENTER_OBJECT,
  293. ACTIONTYPE_HIJACK_VEHICLE,
  294. ACTIONTYPE_CONVERT_OBJECT_TO_CARBOMB,
  295. ACTIONTYPE_CAPTURE_BUILDING,
  296. ACTIONTYPE_DISABLE_VEHICLE_VIA_HACKING,
  297. #ifdef ALLOW_SURRENDER
  298. ACTIONTYPE_PICK_UP_PRISONER,
  299. #endif
  300. ACTIONTYPE_STEAL_CASH_VIA_HACKING,
  301. ACTIONTYPE_DISABLE_BUILDING_VIA_HACKING,
  302. ACTIONTYPE_MAKE_DEFECTOR,
  303. ACTIONTYPE_SET_RALLY_POINT,
  304. ACTIONTYPE_COMBATDROP_INTO,
  305. ACTIONTYPE_SABOTAGE_BUILDING,
  306. //Keep last.
  307. NUM_ACTIONTYPES
  308. };
  309. InGameUI( void );
  310. virtual ~InGameUI( void );
  311. // Inherited from subsystem interface -----------------------------------------------------------
  312. virtual void init( void ); ///< Initialize the in-game user interface
  313. virtual void update( void ); ///< Update the UI by calling preDraw(), draw(), and postDraw()
  314. virtual void reset( void ); ///< Reset
  315. //-----------------------------------------------------------------------------------------------
  316. // interface for the popup messages
  317. virtual void popupMessage( const AsciiString& message, Int x, Int y, Int width, Bool pause, Bool pauseMusic);
  318. virtual void popupMessage( const AsciiString& message, Int x, Int y, Int width, Color textColor, Bool pause, Bool pauseMusic);
  319. PopupMessageData *getPopupMessageData( void ) { return m_popupMessageData; }
  320. void clearPopupMessageData( void );
  321. // interface for messages to the user
  322. // srj sez: passing as const-ref screws up varargs for some reason. dunno why. just pass by value.
  323. virtual void messageColor( const RGBColor *rgbColor, UnicodeString format, ... ); ///< display a colored message to the user
  324. virtual void message( UnicodeString format, ... ); ///< display a message to the user
  325. virtual void message( AsciiString stringManagerLabel, ... );///< display a message to the user
  326. virtual void toggleMessages( void ) { m_messagesOn = 1 - m_messagesOn; } ///< toggle messages on/off
  327. virtual Bool isMessagesOn( void ) { return m_messagesOn; } ///< are the display messages on
  328. void freeMessageResources( void ); ///< free resources for the ui messages
  329. Color getMessageColor(Bool altColor) { return (altColor)?m_messageColor2:m_messageColor1; }
  330. // interface for military style messages
  331. virtual void militarySubtitle( const AsciiString& label, Int duration ); // time in milliseconds
  332. virtual void removeMilitarySubtitle( void );
  333. // for can't build messages
  334. virtual void displayCantBuildMessage( LegalBuildCode lbc ); ///< display message to use as to why they can't build here
  335. // interface for graphical "hints" which provide visual feedback for user-interface commands
  336. virtual void beginAreaSelectHint( const GameMessage *msg ); ///< Used by HintSpy. An area selection is occurring, start graphical "hint"
  337. virtual void endAreaSelectHint( const GameMessage *msg ); ///< Used by HintSpy. An area selection had occurred, finish graphical "hint"
  338. virtual void createMoveHint( const GameMessage *msg ); ///< A move command has occurred, start graphical "hint"
  339. virtual void createAttackHint( const GameMessage *msg ); ///< An attack command has occurred, start graphical "hint"
  340. virtual void createForceAttackHint( const GameMessage *msg ); ///< A force attack command has occurred, start graphical "hint"
  341. virtual void createMouseoverHint( const GameMessage *msg ); ///< An object is mouse hovered over, start hint if any
  342. virtual void createCommandHint( const GameMessage *msg ); ///< Used by HintSpy. Someone is selected so generate the right Cursor for the potential action
  343. virtual void createGarrisonHint( const GameMessage *msg ); ///< A garrison command has occurred, start graphical "hint"
  344. virtual void addSuperweapon(Int playerIndex, const AsciiString& powerName, ObjectID id, const SpecialPowerTemplate *powerTemplate);
  345. virtual Bool removeSuperweapon(Int playerIndex, const AsciiString& powerName, ObjectID id, const SpecialPowerTemplate *powerTemplate);
  346. virtual void objectChangedTeam(const Object *obj, Int oldPlayerIndex, Int newPlayerIndex); // notification for superweapons, etc
  347. virtual void setSuperweaponDisplayEnabledByScript( Bool enable ); ///< Set the superweapon display enabled or disabled
  348. virtual Bool getSuperweaponDisplayEnabledByScript( void ) const; ///< Get the current superweapon display status
  349. virtual void hideObjectSuperweaponDisplayByScript(const Object *obj);
  350. virtual void showObjectSuperweaponDisplayByScript(const Object *obj);
  351. void addNamedTimer( const AsciiString& timerName, const UnicodeString& text, Bool isCountdown );
  352. void removeNamedTimer( const AsciiString& timerName );
  353. void showNamedTimerDisplay( Bool show );
  354. // mouse mode interface
  355. virtual void setScrolling( Bool isScrolling ); ///< set right-click scroll mode
  356. virtual Bool isScrolling( void ); ///< are we scrolling?
  357. virtual void setSelecting( Bool isSelecting ); ///< set drag select mode
  358. virtual Bool isSelecting( void ); ///< are we selecting?
  359. virtual void setScrollAmount( Coord2D amt ); ///< set scroll amount
  360. virtual Coord2D getScrollAmount( void ); ///< get scroll amount
  361. // gui command interface
  362. virtual void setGUICommand( const CommandButton *command ); ///< the command has been clicked in the UI and needs additional data
  363. virtual const CommandButton *getGUICommand( void ) const; ///< get the pending gui command
  364. // build interface
  365. virtual void placeBuildAvailable( const ThingTemplate *build, Drawable *buildDrawable ); ///< built thing being placed
  366. virtual const ThingTemplate *getPendingPlaceType( void ); ///< get item we're trying to place
  367. virtual const ObjectID getPendingPlaceSourceObjectID( void ); ///< get producing object
  368. virtual Bool getPreventLeftClickDeselectionInAlternateMouseModeForOneClick() const { return m_preventLeftClickDeselectionInAlternateMouseModeForOneClick; }
  369. virtual void setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( Bool set ) { m_preventLeftClickDeselectionInAlternateMouseModeForOneClick = set; }
  370. virtual void setPlacementStart( const ICoord2D *start ); ///< placement anchor point (for choosing angles)
  371. virtual void setPlacementEnd( const ICoord2D *end ); ///< set target placement point (for choosing angles)
  372. virtual Bool isPlacementAnchored( void ); ///< is placement arrow anchor set
  373. virtual void getPlacementPoints( ICoord2D *start, ICoord2D *end );///< get the placemnt arrow points
  374. virtual Real getPlacementAngle( void ); ///< placement angle of drawable at cursor when placing down structures
  375. // Drawable selection mechanisms
  376. virtual void selectDrawable( Drawable *draw ); ///< Mark given Drawable as "selected"
  377. virtual void deselectDrawable( Drawable *draw ); ///< Clear "selected" status from Drawable
  378. virtual void deselectAllDrawables( Bool postMsg = true ); ///< Clear the "select" flag from all drawables
  379. virtual Int getSelectCount( void ) { return m_selectCount; } ///< Get count of currently selected drawables
  380. virtual Int getMaxSelectCount( void ) { return m_maxSelectCount; } ///< Get the max number of selected drawables
  381. virtual UnsignedInt getFrameSelectionChanged( void ) { return m_frameSelectionChanged; } ///< Get the max number of selected drawables
  382. virtual const DrawableList *getAllSelectedDrawables( void ) const; ///< Return the list of all the currently selected Drawable IDs.
  383. virtual const DrawableList *getAllSelectedLocalDrawables( void ); ///< Return the list of all the currently selected Drawable IDs owned by the current player.
  384. virtual Drawable *getFirstSelectedDrawable( void ); ///< get the first selected drawable (if any)
  385. virtual DrawableID getSoloNexusSelectedDrawableID( void ) { return m_soloNexusSelectedDrawableID; } ///< Return the one drawable of the nexus if only 1 angry mob is selected
  386. virtual Bool isDrawableSelected( DrawableID idToCheck ) const; ///< Return true if the selected ID is in the drawable list
  387. virtual Bool isAnySelectedKindOf( KindOfType kindOf ) const; ///< is any selected object a kind of
  388. virtual Bool isAllSelectedKindOf( KindOfType kindOf ) const; ///< are all selected objects a kind of
  389. virtual void setRadiusCursor(RadiusCursorType r, const SpecialPowerTemplate* sp, WeaponSlotType wslot);
  390. virtual void setRadiusCursorNone() { setRadiusCursor(RADIUSCURSOR_NONE, NULL, PRIMARY_WEAPON); }
  391. virtual void setInputEnabled( Bool enable ); ///< Set the input enabled or disabled
  392. virtual Bool getInputEnabled( void ) { return m_inputEnabled; } ///< Get the current input status
  393. virtual void disregardDrawable( Drawable *draw ); ///< Drawable is being destroyed, clean up any UI elements associated with it
  394. virtual void preDraw( void ); ///< Logic which needs to occur before the UI renders
  395. virtual void draw( void ) = 0; ///< Render the in-game user interface
  396. virtual void postDraw( void ); ///< Logic which needs to occur after the UI renders
  397. /// Ingame video playback
  398. virtual void playMovie( const AsciiString& movieName );
  399. virtual void stopMovie( void );
  400. virtual VideoBuffer* videoBuffer( void );
  401. /// Ingame cameo video playback
  402. virtual void playCameoMovie( const AsciiString& movieName );
  403. virtual void stopCameoMovie( void );
  404. virtual VideoBuffer* cameoVideoBuffer( void );
  405. // mouse over information
  406. virtual DrawableID getMousedOverDrawableID( void ) const; ///< Get drawble ID of drawable under cursor
  407. /// Set the ingame flag as to if we have the Quit menu up or not
  408. virtual void setQuitMenuVisible( Bool t ) { m_isQuitMenuVisible = t; }
  409. virtual Bool isQuitMenuVisible( void ) const { return m_isQuitMenuVisible; }
  410. // INI file parsing
  411. virtual const FieldParse* getFieldParse( void ) const { return s_fieldParseTable; }
  412. //Provides a global way to determine whether or not we can issue orders to what we have selected.
  413. Bool areSelectedObjectsControllable() const;
  414. //Wrapper function that includes any non-attack canSelectedObjectsXXX checks.
  415. Bool canSelectedObjectsNonAttackInteractWithObject( const Object *objectToInteractWith, SelectionRules rule ) const;
  416. //Wrapper function that checks a specific action.
  417. CanAttackResult getCanSelectedObjectsAttack( ActionType action, const Object *objectToInteractWith, SelectionRules rule, Bool additionalChecking = FALSE ) const;
  418. Bool canSelectedObjectsDoAction( ActionType action, const Object *objectToInteractWith, SelectionRules rule, Bool additionalChecking = FALSE ) const;
  419. Bool canSelectedObjectsDoSpecialPower( const CommandButton *command, const Object *objectToInteractWith, const Coord3D *position, SelectionRules rule, UnsignedInt commandOptions, Object* ignoreSelObj ) const;
  420. Bool canSelectedObjectsEffectivelyUseWeapon( const CommandButton *command, const Object *objectToInteractWith, const Coord3D *position, SelectionRules rule ) const;
  421. Bool canSelectedObjectsOverrideSpecialPowerDestination( const Coord3D *loc, SelectionRules rule, SpecialPowerType spType = SPECIAL_INVALID ) const;
  422. // Selection Methods
  423. virtual Int selectUnitsMatchingCurrentSelection(); ///< selects matching units
  424. virtual Int selectMatchingAcrossScreen(); ///< selects matching units across screen
  425. virtual Int selectMatchingAcrossMap(); ///< selects matching units across map
  426. virtual Int selectMatchingAcrossRegion( IRegion2D *region ); // -1 = no locally-owned selection, 0+ = # of units selected
  427. virtual Int selectAllUnitsByType(KindOfMaskType mustBeSet, KindOfMaskType mustBeClear);
  428. virtual Int selectAllUnitsByTypeAcrossScreen(KindOfMaskType mustBeSet, KindOfMaskType mustBeClear);
  429. virtual Int selectAllUnitsByTypeAcrossMap(KindOfMaskType mustBeSet, KindOfMaskType mustBeClear);
  430. virtual Int selectAllUnitsByTypeAcrossRegion( IRegion2D *region, KindOfMaskType mustBeSet, KindOfMaskType mustBeClear );
  431. virtual void buildRegion( const ICoord2D *anchor, const ICoord2D *dest, IRegion2D *region ); ///< builds a region around the specified coordinates
  432. virtual Bool getDisplayedMaxWarning( void ) { return m_displayedMaxWarning; }
  433. virtual void setDisplayedMaxWarning( Bool selected ) { m_displayedMaxWarning = selected; }
  434. // Floating Test Methods
  435. virtual void addFloatingText(const UnicodeString& text,const Coord3D * pos, Color color);
  436. // Drawable caption stuff
  437. AsciiString getDrawableCaptionFontName( void ) { return m_drawableCaptionFont; }
  438. Int getDrawableCaptionPointSize( void ) { return m_drawableCaptionPointSize; }
  439. Bool isDrawableCaptionBold( void ) { return m_drawableCaptionBold; }
  440. Color getDrawableCaptionColor( void ) { return m_drawableCaptionColor; }
  441. inline Bool shouldMoveRMBScrollAnchor( void ) { return m_moveRMBScrollAnchor; }
  442. Bool isClientQuiet( void ) const { return m_clientQuiet; }
  443. Bool isInWaypointMode( void ) const { return m_waypointMode; }
  444. Bool isInForceAttackMode( void ) const { return m_forceAttackMode; }
  445. Bool isInForceMoveToMode( void ) const { return m_forceMoveToMode; }
  446. Bool isInPreferSelectionMode( void ) const { return m_preferSelection; }
  447. void setClientQuiet( Bool enabled ) { m_clientQuiet = enabled; }
  448. void setWaypointMode( Bool enabled ) { m_waypointMode = enabled; }
  449. void setForceMoveMode( Bool enabled ) { m_forceMoveToMode = enabled; }
  450. void setForceAttackMode( Bool enabled ) { m_forceAttackMode = enabled; }
  451. void setPreferSelectionMode( Bool enabled ) { m_preferSelection = enabled; }
  452. void toggleAttackMoveToMode( void ) { m_attackMoveToMode = !m_attackMoveToMode; }
  453. Bool isInAttackMoveToMode( void ) const { return m_attackMoveToMode; }
  454. void clearAttackMoveToMode( void ) { m_attackMoveToMode = FALSE; }
  455. void setCameraRotateLeft( Bool set ) { m_cameraRotatingLeft = set; }
  456. void setCameraRotateRight( Bool set ) { m_cameraRotatingRight = set; }
  457. void setCameraZoomIn( Bool set ) { m_cameraZoomingIn = set; }
  458. void setCameraZoomOut( Bool set ) { m_cameraZoomingOut = set; }
  459. void setCameraTrackingDrawable( Bool set ) { m_cameraTrackingDrawable = set; }
  460. Bool isCameraRotatingLeft() const { return m_cameraRotatingLeft; }
  461. Bool isCameraRotatingRight() const { return m_cameraRotatingRight; }
  462. Bool isCameraZoomingIn() const { return m_cameraZoomingIn; }
  463. Bool isCameraZoomingOut() const { return m_cameraZoomingOut; }
  464. Bool isCameraTrackingDrawable() const { return m_cameraTrackingDrawable; }
  465. void resetCamera();
  466. virtual void addIdleWorker( Object *obj );
  467. virtual void removeIdleWorker( Object *obj, Int playerNumber );
  468. virtual void selectNextIdleWorker( void );
  469. virtual void recreateControlBar( void );
  470. virtual void disableTooltipsUntil(UnsignedInt frameNum);
  471. virtual void clearTooltipsDisabled();
  472. virtual Bool areTooltipsDisabled() const;
  473. Bool getDrawRMBScrollAnchor() const { return m_drawRMBScrollAnchor; }
  474. Bool getMoveRMBScrollAnchor() const { return m_moveRMBScrollAnchor; }
  475. void setDrawRMBScrollAnchor(Bool b) { m_drawRMBScrollAnchor = b; }
  476. void setMoveRMBScrollAnchor(Bool b) { m_moveRMBScrollAnchor = b; }
  477. private:
  478. virtual Int getIdleWorkerCount( void );
  479. virtual Object *findIdleWorker( Object *obj);
  480. virtual void showIdleWorkerLayout( void );
  481. virtual void hideIdleWorkerLayout( void );
  482. virtual void updateIdleWorker( void );
  483. virtual void resetIdleWorker( void );
  484. public:
  485. void registerWindowLayout(WindowLayout *layout); // register a layout for updates
  486. void unregisterWindowLayout(WindowLayout *layout); // stop updates for this layout
  487. void triggerDoubleClickAttackMoveGuardHint( void );
  488. public:
  489. // World 2D animation methods
  490. void addWorldAnimation( Anim2DTemplate *animTemplate,
  491. const Coord3D *pos,
  492. WorldAnimationOptions options,
  493. Real durationInSeconds,
  494. Real zRisePerSecond );
  495. #if defined(_DEBUG) || defined(_INTERNAL)
  496. virtual void DEBUG_addFloatingText(const AsciiString& text,const Coord3D * pos, Color color);
  497. #endif
  498. protected:
  499. // snapshot methods
  500. virtual void crc( Xfer *xfer );
  501. virtual void xfer( Xfer *xfer );
  502. virtual void loadPostProcess( void );
  503. protected:
  504. // ----------------------------------------------------------------------------------------------
  505. // Protected Types ------------------------------------------------------------------------------
  506. // ----------------------------------------------------------------------------------------------
  507. enum HintType
  508. {
  509. MOVE_HINT = 0,
  510. ATTACK_HINT,
  511. #ifdef _DEBUG
  512. DEBUG_HINT,
  513. #endif
  514. NUM_HINT_TYPES // keep this one last
  515. };
  516. // mouse mode interface
  517. enum MouseMode
  518. {
  519. MOUSEMODE_DEFAULT = 0,
  520. MOUSEMODE_BUILD_PLACE,
  521. MOUSEMODE_GUI_COMMAND,
  522. MOUSEMODE_MAX
  523. };
  524. enum { MAX_MOVE_HINTS = 256 };
  525. struct MoveHintStruct
  526. {
  527. Coord3D pos; ///< World coords of destination point
  528. UnsignedInt sourceID; ///< id of who will move to this point
  529. UnsignedInt frame; ///< frame the command was issued on
  530. };
  531. struct UIMessage
  532. {
  533. UnicodeString fullText; ///< the whole text message
  534. DisplayString *displayString; ///< display string used to render the message
  535. UnsignedInt timestamp; ///< logic frame message was created on
  536. Color color; ///< color to render this in
  537. };
  538. enum { MAX_UI_MESSAGES = 6 };
  539. struct MilitarySubtitleData
  540. {
  541. UnicodeString subtitle; ///< The complete subtitle to be drawn, each line is separated by L"\n"
  542. UnsignedInt index; ///< the current index that we are at through the sibtitle
  543. ICoord2D position; ///< Where on the screen the subtitle should be drawn
  544. DisplayString *displayStrings[MAX_SUBTITLE_LINES]; ///< We'll only allow MAX_SUBTITLE_LINES worth of display strings
  545. UnsignedInt currentDisplayString; ///< contains the current display string we're on. (also lets us know the last display string allocated
  546. UnsignedInt lifetime; ///< the Lifetime of the Military Subtitle in frames
  547. Bool blockDrawn; ///< True if the block is drawn false if it's blank
  548. UnsignedInt blockBeginFrame; ///< The frame at which the block started it's current state
  549. ICoord2D blockPos; ///< where the upper left of the block should begin
  550. UnsignedInt incrementOnFrame; ///< if we're currently on a frame greater then this, increment our position
  551. Color color; ///< what color should we display the military subtitles
  552. };
  553. typedef std::list<Object *> ObjectList;
  554. typedef std::list<Object *>::iterator ObjectListIt;
  555. // ----------------------------------------------------------------------------------------------
  556. // Protected Methods ----------------------------------------------------------------------------
  557. // ----------------------------------------------------------------------------------------------
  558. void destroyPlacementIcons( void ); ///< Destroy placement icons
  559. void handleBuildPlacements( void ); ///< handle updating of placement icons based on mouse pos
  560. void handleRadiusCursor(); ///< handle updating of "radius cursors" that follow the mouse pos
  561. void incrementSelectCount( void ) { ++m_selectCount; } ///< Increase by one the running total of "selected" drawables
  562. void decrementSelectCount( void ) { --m_selectCount; } ///< Decrease by one the running total of "selected" drawables
  563. virtual View *createView( void ) = 0; ///< Factory for Views
  564. void evaluateSoloNexus( Drawable *newlyAddedDrawable = NULL );
  565. /// expire a hint from of the specified type at the hint index
  566. void expireHint( HintType type, UnsignedInt hintIndex );
  567. void createControlBar( void ); ///< create the control bar user interface
  568. void createReplayControl( void ); ///< create the replay control window
  569. void setMouseCursor(Mouse::MouseCursor c);
  570. void addMessageText( const UnicodeString& formattedMessage, const RGBColor *rgbColor = NULL ); ///< internal workhorse for adding plain text for messages
  571. void removeMessageAtIndex( Int i ); ///< remove the message at index i
  572. void updateFloatingText( void ); ///< Update function to move our floating text
  573. void drawFloatingText( void ); ///< Draw all our floating text
  574. void clearFloatingText( void ); ///< clear the floating text list
  575. void clearWorldAnimations( void ); ///< delete all world animations
  576. void updateAndDrawWorldAnimations( void ); ///< update and draw visible world animations
  577. SuperweaponInfo* findSWInfo(Int playerIndex, const AsciiString& powerName, ObjectID id, const SpecialPowerTemplate *powerTemplate);
  578. // ----------------------------------------------------------------------------------------------
  579. // Protected Data THAT IS SAVED/LOADED ----------------------------------------------------------
  580. // ----------------------------------------------------------------------------------------------
  581. Bool m_superweaponHiddenByScript;
  582. Bool m_inputEnabled; /// sort of
  583. // ----------------------------------------------------------------------------------------------
  584. // Protected Data -------------------------------------------------------------------------------
  585. // ----------------------------------------------------------------------------------------------
  586. std::list<WindowLayout *> m_windowLayouts;
  587. AsciiString m_currentlyPlayingMovie; ///< Used to push updates to TheScriptEngine
  588. DrawableList m_selectedDrawables; ///< A list of all selected drawables.
  589. DrawableList m_selectedLocalDrawables; ///< A list of all selected drawables owned by the local player
  590. Bool m_isDragSelecting; ///< If TRUE, an area selection is in progress
  591. IRegion2D m_dragSelectRegion; ///< if isDragSelecting is TRUE, this contains select region
  592. Bool m_displayedMaxWarning; ///< keeps the warning from being shown over and over
  593. MoveHintStruct m_moveHint[ MAX_MOVE_HINTS ];
  594. Int m_nextMoveHint;
  595. const CommandButton * m_pendingGUICommand; ///< GUI command that needs additional interaction from the user
  596. BuildProgress m_buildProgress[ MAX_BUILD_PROGRESS ]; ///< progress for building units
  597. const ThingTemplate * m_pendingPlaceType; ///< type of built thing we're trying to place
  598. ObjectID m_pendingPlaceSourceObjectID; ///< source object of the thing constructing the item
  599. Bool m_preventLeftClickDeselectionInAlternateMouseModeForOneClick;
  600. Drawable ** m_placeIcon; ///< array for drawables to appear at the cursor when building in the world
  601. Bool m_placeAnchorInProgress; ///< is place angle interface for placement active
  602. ICoord2D m_placeAnchorStart; ///< place angle anchor start
  603. ICoord2D m_placeAnchorEnd; ///< place angle anchor end
  604. Int m_selectCount; ///< Number of objects currently "selected"
  605. Int m_maxSelectCount; ///< Max number of objects to select
  606. UnsignedInt m_frameSelectionChanged; ///< Frame when the selection last changed.
  607. Int m_duringDoubleClickAttackMoveGuardHintTimer; ///< Frames left to draw the doubleClickFeedbackTimer
  608. Coord3D m_duringDoubleClickAttackMoveGuardHintStashedPosition;
  609. // Video playback data
  610. VideoBuffer* m_videoBuffer; ///< video playback buffer
  611. VideoStreamInterface* m_videoStream; ///< Video stream;
  612. // Video playback data
  613. VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
  614. VideoStreamInterface* m_cameoVideoStream;///< Video stream;
  615. // message data
  616. UIMessage m_uiMessages[ MAX_UI_MESSAGES ];/**< messages to display to the user, the
  617. array is organized with newer messages at
  618. index 0, and increasing to older ones */
  619. // superweapon timer data
  620. SuperweaponMap m_superweapons[MAX_PLAYER_COUNT];
  621. Coord2D m_superweaponPosition;
  622. Real m_superweaponFlashDuration;
  623. // superweapon timer font info
  624. AsciiString m_superweaponNormalFont;
  625. Int m_superweaponNormalPointSize;
  626. Bool m_superweaponNormalBold;
  627. AsciiString m_superweaponReadyFont;
  628. Int m_superweaponReadyPointSize;
  629. Bool m_superweaponReadyBold;
  630. Int m_superweaponLastFlashFrame; ///< for flashing the text when the weapon is ready
  631. Color m_superweaponFlashColor;
  632. Bool m_superweaponUsedFlashColor;
  633. NamedTimerMap m_namedTimers;
  634. Coord2D m_namedTimerPosition;
  635. Real m_namedTimerFlashDuration;
  636. Int m_namedTimerLastFlashFrame;
  637. Color m_namedTimerFlashColor;
  638. Bool m_namedTimerUsedFlashColor;
  639. Bool m_showNamedTimers;
  640. AsciiString m_namedTimerNormalFont;
  641. Int m_namedTimerNormalPointSize;
  642. Bool m_namedTimerNormalBold;
  643. Color m_namedTimerNormalColor;
  644. AsciiString m_namedTimerReadyFont;
  645. Int m_namedTimerReadyPointSize;
  646. Bool m_namedTimerReadyBold;
  647. Color m_namedTimerReadyColor;
  648. // Drawable caption data
  649. AsciiString m_drawableCaptionFont;
  650. Int m_drawableCaptionPointSize;
  651. Bool m_drawableCaptionBold;
  652. Color m_drawableCaptionColor;
  653. UnsignedInt m_tooltipsDisabledUntil;
  654. // Military Subtitle data
  655. MilitarySubtitleData * m_militarySubtitle; ///< The pointer to subtitle class, if it's present then draw it.
  656. Bool m_isScrolling;
  657. Bool m_isSelecting;
  658. MouseMode m_mouseMode;
  659. Int m_mouseModeCursor;
  660. DrawableID m_mousedOverDrawableID;
  661. Coord2D m_scrollAmt;
  662. Bool m_isQuitMenuVisible;
  663. Bool m_messagesOn;
  664. Color m_messageColor1;
  665. Color m_messageColor2;
  666. ICoord2D m_messagePosition;
  667. AsciiString m_messageFont;
  668. Int m_messagePointSize;
  669. Bool m_messageBold;
  670. Int m_messageDelayMS;
  671. RGBAColorInt m_militaryCaptionColor; ///< color for the military-style caption
  672. ICoord2D m_militaryCaptionPosition; ///< position for the military-style caption
  673. AsciiString m_militaryCaptionTitleFont;
  674. Int m_militaryCaptionTitlePointSize;
  675. Bool m_militaryCaptionTitleBold;
  676. AsciiString m_militaryCaptionFont;
  677. Int m_militaryCaptionPointSize;
  678. Bool m_militaryCaptionBold;
  679. Bool m_militaryCaptionRandomizeTyping;
  680. Int m_militaryCaptionSpeed;
  681. RadiusDecalTemplate m_radiusCursors[RADIUSCURSOR_COUNT];
  682. RadiusDecal m_curRadiusCursor;
  683. RadiusCursorType m_curRcType;
  684. //Floating Text Data
  685. FloatingTextList m_floatingTextList; ///< Our list of floating text
  686. UnsignedInt m_floatingTextTimeOut; ///< Ini value of our floating text timeout
  687. Real m_floatingTextMoveUpSpeed; ///< INI value of our Move up speed
  688. Real m_floatingTextMoveVanishRate; ///< INI value of our move vanish rate
  689. PopupMessageData * m_popupMessageData;
  690. Color m_popupMessageColor;
  691. Bool m_waypointMode; ///< are we in waypoint plotting mode?
  692. Bool m_forceAttackMode; ///< are we in force attack mode?
  693. Bool m_forceMoveToMode; ///< are we in force move mode?
  694. Bool m_attackMoveToMode; ///< are we in attack move mode?
  695. Bool m_preferSelection; ///< the shift key has been depressed.
  696. Bool m_cameraRotatingLeft;
  697. Bool m_cameraRotatingRight;
  698. Bool m_cameraZoomingIn;
  699. Bool m_cameraTrackingDrawable;
  700. Bool m_cameraZoomingOut;
  701. Bool m_drawRMBScrollAnchor;
  702. Bool m_moveRMBScrollAnchor;
  703. Bool m_clientQuiet; ///< When the user clicks exit,restart, etc. this is set true
  704. ///< to skip some client sounds/fx during shutdown
  705. // World Animation Data
  706. WorldAnimationList m_worldAnimationList; ///< the list of world animations
  707. // Idle worker animation
  708. ObjectList m_idleWorkers[MAX_PLAYER_COUNT];
  709. GameWindow * m_idleWorkerWin;
  710. Int m_currentIdleWorkerDisplay;
  711. DrawableID m_soloNexusSelectedDrawableID; ///< The drawable of the nexus, if only one angry mob is selected, otherwise, null
  712. // ----------------------------------------------------------------------------------------------
  713. // STATIC Protected Data -------------------------------------------------------------------------------
  714. // ----------------------------------------------------------------------------------------------
  715. static const FieldParse s_fieldParseTable[];
  716. };
  717. // the singleton
  718. extern InGameUI *TheInGameUI;
  719. #endif // _IN_GAME_UI_H_