InGameUI.h 38 KB

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