ControlBarScheme.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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: ControlBarScheme.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Apr 2002
  34. //
  35. // Filename: ControlBarScheme.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: Contains all the Command bar goodness in terms of how it looks
  40. // For instrucitons on how to use, please see it's .h file
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. //-----------------------------------------------------------------------------
  45. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  46. //-----------------------------------------------------------------------------
  47. //-----------------------------------------------------------------------------
  48. // USER INCLUDES //////////////////////////////////////////////////////////////
  49. //-----------------------------------------------------------------------------
  50. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  51. #include "Common/Player.h"
  52. #include "Common/PlayerTemplate.h"
  53. #include "Common/Recorder.h"
  54. #include "GameClient/ControlBarScheme.h"
  55. #include "GameClient/Display.h"
  56. #include "GameClient/ControlBar.h"
  57. #include "GameClient/Image.h"
  58. #include "GameClient/GameWindowManager.h"
  59. #include "GameClient/GadgetPushButton.h"
  60. #ifdef _INTERNAL
  61. // for occasional debugging...
  62. //#pragma optimize("", off)
  63. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  64. #endif
  65. //-----------------------------------------------------------------------------
  66. // DEFINES ////////////////////////////////////////////////////////////////////
  67. //-----------------------------------------------------------------------------
  68. enum{
  69. COMMAND_BAR_SIZE_OFFSET = 0
  70. };
  71. const FieldParse ControlBarSchemeManager::m_controlBarSchemeFieldParseTable[] =
  72. {
  73. { "ImagePart", ControlBarSchemeManager::parseImagePart, NULL, NULL },
  74. { "AnimatingPart", ControlBarSchemeManager::parseAnimatingPart, NULL, NULL },
  75. { "ScreenCreationRes", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_ScreenCreationRes ) },
  76. { "Side", INI::parseAsciiString, NULL, offsetof( ControlBarScheme, m_side ) },
  77. { "QueueButtonImage", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_buttonQueueImage ) },
  78. { "RightHUDImage", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_rightHUDImage ) },
  79. { "BuildUpClockColor", INI::parseColorInt, NULL, offsetof( ControlBarScheme, m_buildUpClockColor ) },
  80. { "ButtonBorderBuildColor", INI::parseColorInt, NULL, offsetof( ControlBarScheme, m_borderBuildColor ) },
  81. { "CommandBarBorderColor", INI::parseColorInt, NULL, offsetof( ControlBarScheme, m_commandBarBorderColor ) },
  82. { "ButtonBorderActionColor", INI::parseColorInt, NULL, offsetof( ControlBarScheme, m_borderActionColor ) },
  83. { "ButtonBorderUpgradeColor", INI::parseColorInt, NULL, offsetof( ControlBarScheme, m_borderUpgradeColor ) },
  84. { "ButtonBorderSystemColor", INI::parseColorInt, NULL, offsetof( ControlBarScheme, m_borderSystemColor ) },
  85. { "OptionsButtonEnable", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_optionsButtonEnable ) },
  86. { "OptionsButtonHightlited", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_optionsButtonHightlited ) },
  87. { "OptionsButtonPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_optionsButtonPushed ) },
  88. { "OptionsButtonDisabled", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_optionsButtonDisabled ) },
  89. { "IdleWorkerButtonEnable", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_idleWorkerButtonEnable ) },
  90. { "IdleWorkerButtonHightlited", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_idleWorkerButtonHightlited ) },
  91. { "IdleWorkerButtonPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_idleWorkerButtonPushed ) },
  92. { "IdleWorkerButtonDisabled", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_idleWorkerButtonDisabled ) },
  93. { "BuddyButtonEnable", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_buddyButtonEnable ) },
  94. { "BuddyButtonHightlited", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_buddyButtonHightlited ) },
  95. { "BuddyButtonPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_buddyButtonPushed ) },
  96. { "BuddyButtonDisabled", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_buddyButtonDisabled) },
  97. { "BeaconButtonEnable", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_beaconButtonEnable ) },
  98. { "BeaconButtonHightlited", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_beaconButtonHightlited ) },
  99. { "BeaconButtonPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_beaconButtonPushed ) },
  100. { "BeaconButtonDisabled", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_beaconButtonDisabled ) },
  101. { "GenBarButtonIn", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_genBarButtonIn ) },
  102. { "GenBarButtonOn", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_genBarButtonOn ) },
  103. { "ToggleButtonUpIn", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_toggleButtonUpIn ) },
  104. { "ToggleButtonUpOn", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_toggleButtonUpOn ) },
  105. { "ToggleButtonUpPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_toggleButtonUpPushed ) },
  106. { "ToggleButtonDownIn", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_toggleButtonDownIn ) },
  107. { "ToggleButtonDownOn", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_toggleButtonDownOn ) },
  108. { "ToggleButtonDownPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_toggleButtonDownPushed ) },
  109. { "GeneralButtonEnable", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_generalButtonEnable ) },
  110. { "GeneralButtonHightlited", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_generalButtonHightlited ) },
  111. { "GeneralButtonPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_generalButtonPushed ) },
  112. { "GeneralButtonDisabled", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_generalButtonDisabled ) },
  113. { "UAttackButtonEnable", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_uAttackButtonEnable ) },
  114. { "UAttackButtonHightlited", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_uAttackButtonHightlited ) },
  115. { "UAttackButtonPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_uAttackButtonPushed ) },
  116. { "GenArrow", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_genArrow) },
  117. { "MinMaxButtonEnable", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_minMaxButtonEnable ) },
  118. { "MinMaxButtonHightlited", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_minMaxButtonHightlited ) },
  119. { "MinMaxButtonPushed", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_minMaxButtonPushed ) },
  120. { "MinMaxUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_minMaxUL ) },
  121. { "MinMaxLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_minMaxLR ) },
  122. { "GeneralUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_generalUL ) },
  123. { "GeneralLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_generalLR ) },
  124. { "UAttackUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_uAttackUL ) },
  125. { "UAttackLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_uAttackLR ) },
  126. { "OptionsUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_optionsUL ) },
  127. { "OptionsLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_optionsLR ) },
  128. { "WorkerUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_workerUL ) },
  129. { "WorkerLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_workerLR ) },
  130. { "ChatUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_chatUL ) },
  131. { "ChatLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_chatLR ) },
  132. { "BeaconUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_beaconUL ) },
  133. { "BeaconLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_beaconLR ) },
  134. { "PowerBarUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_powerBarUL ) },
  135. { "PowerBarLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_powerBarLR ) },
  136. { "MoneyUL", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_moneyUL ) },
  137. { "MoneyLR", INI::parseICoord2D, NULL, offsetof( ControlBarScheme, m_moneyLR ) },
  138. { "CommandMarkerImage", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_commandMarkerImage) },
  139. { "ExpBarForegroundImage", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_expBarForeground) },
  140. { "PowerPurchaseImage", INI::parseMappedImage, NULL, offsetof( ControlBarScheme, m_powerPurchaseImage) },
  141. { NULL, NULL, NULL, 0 } // keep this last
  142. };
  143. // used to parse the anim types that each animation part of a scheme can have
  144. static const LookupListRec AnimTypeNames[] =
  145. {
  146. { "SLIDE_RIGHT", ControlBarSchemeAnimation::CB_ANIM_SLIDE_RIGHT },
  147. { NULL, 0 }
  148. };
  149. static void animSlideRight( ControlBarSchemeAnimation *anim );
  150. //-----------------------------------------------------------------------------
  151. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  152. //-----------------------------------------------------------------------------
  153. ControlBarSchemeImage::ControlBarSchemeImage( void )
  154. {
  155. m_name.clear();
  156. m_position.x = m_position.y = 0;
  157. m_size.x = m_size.y = 0;
  158. m_image = NULL;
  159. m_layer = 0;
  160. }
  161. ControlBarSchemeImage::~ControlBarSchemeImage( void )
  162. {
  163. m_image = NULL;
  164. }
  165. ControlBarSchemeAnimation::ControlBarSchemeAnimation( void )
  166. {
  167. // Added by Sadullah Nader
  168. // Initializations missing and needed
  169. m_animDuration = 0;
  170. m_finalPos.x = m_finalPos.y = 0;
  171. // End Add
  172. m_name.clear();
  173. m_animType = 0;
  174. m_animImage = NULL;
  175. m_startPos.x = m_startPos.y = 0;
  176. m_currentFrame = 0;
  177. }
  178. ControlBarSchemeAnimation::~ControlBarSchemeAnimation( void )
  179. {
  180. m_animImage = NULL;
  181. }
  182. void ControlBarScheme::reset(void)
  183. {
  184. for (Int i = 0; i < MAX_CONTROL_BAR_SCHEME_IMAGE_LAYERS; i++)
  185. {
  186. ControlBarSchemeImageList::iterator it = m_layer[i].begin();
  187. while (it != m_layer[i].end())
  188. {
  189. ControlBarSchemeImage *im = *it;
  190. if( im )
  191. delete im;
  192. im = NULL;
  193. it ++;
  194. }
  195. m_layer[i].clear();
  196. }
  197. ControlBarSchemeAnimationList::iterator it = m_animations.begin();
  198. while (it != m_animations.end())
  199. {
  200. ControlBarSchemeAnimation *anim = *it;
  201. if( anim )
  202. {
  203. anim->m_animImage = NULL;
  204. delete(anim);
  205. }
  206. anim = NULL;
  207. it ++;
  208. }
  209. m_animations.clear();
  210. m_name.clear();
  211. m_ScreenCreationRes.x = m_ScreenCreationRes.y = 0;
  212. m_side.clear();
  213. m_buttonQueueImage = NULL;
  214. m_rightHUDImage = NULL;
  215. m_optionsButtonEnable = NULL;
  216. m_optionsButtonHightlited = NULL;
  217. m_optionsButtonPushed = NULL;
  218. m_optionsButtonDisabled = NULL;
  219. m_idleWorkerButtonEnable = NULL;
  220. m_idleWorkerButtonHightlited = NULL;
  221. m_idleWorkerButtonPushed = NULL;
  222. m_idleWorkerButtonDisabled = NULL;
  223. m_buddyButtonEnable = NULL;
  224. m_buddyButtonHightlited = NULL;
  225. m_buddyButtonPushed = NULL;
  226. m_buddyButtonDisabled = NULL;
  227. m_beaconButtonEnable = NULL;
  228. m_beaconButtonHightlited = NULL;
  229. m_beaconButtonPushed = NULL;
  230. m_beaconButtonDisabled = NULL;
  231. m_genBarButtonIn = NULL;
  232. m_genBarButtonOn = NULL;
  233. m_toggleButtonUpIn = NULL;
  234. m_toggleButtonUpOn = NULL;
  235. m_toggleButtonUpPushed = NULL;
  236. m_toggleButtonDownIn = NULL;
  237. m_toggleButtonDownOn = NULL;
  238. m_toggleButtonDownPushed = NULL;
  239. m_commandMarkerImage = NULL;
  240. m_expBarForeground = NULL;
  241. m_powerPurchaseImage = NULL;
  242. }
  243. ControlBarScheme::~ControlBarScheme(void)
  244. {
  245. reset();
  246. }
  247. ControlBarScheme::ControlBarScheme(void)
  248. {
  249. m_animations.clear();
  250. for (Int i = 0; i < MAX_CONTROL_BAR_SCHEME_IMAGE_LAYERS; i++)
  251. m_layer[i].clear();
  252. m_name.clear();
  253. m_ScreenCreationRes.x = m_ScreenCreationRes.y = 0;
  254. m_side.clear();
  255. m_buttonQueueImage = NULL;
  256. m_rightHUDImage = NULL;
  257. m_buildUpClockColor = GameMakeColor(0,0,0,100);
  258. m_borderBuildColor = GAME_COLOR_UNDEFINED;
  259. m_borderActionColor = GAME_COLOR_UNDEFINED;
  260. m_borderUpgradeColor = GAME_COLOR_UNDEFINED;
  261. m_borderSystemColor = GAME_COLOR_UNDEFINED;
  262. //m_buttonQueueImage = TheMappedImageCollection("")
  263. m_optionsButtonEnable = NULL;
  264. m_optionsButtonHightlited = NULL;
  265. m_optionsButtonPushed = NULL;
  266. m_optionsButtonDisabled = NULL;
  267. // Added By Sadullah Nader
  268. // Initializations needed
  269. m_commandBarBorderColor = 0;
  270. //
  271. m_idleWorkerButtonEnable = NULL;
  272. m_idleWorkerButtonHightlited = NULL;
  273. m_idleWorkerButtonPushed = NULL;
  274. m_idleWorkerButtonDisabled = NULL;
  275. m_buddyButtonEnable = NULL;
  276. m_buddyButtonHightlited = NULL;
  277. m_buddyButtonPushed = NULL;
  278. m_buddyButtonDisabled= NULL;
  279. m_beaconButtonEnable = NULL;
  280. m_beaconButtonHightlited = NULL;
  281. m_beaconButtonPushed = NULL;
  282. m_beaconButtonDisabled= NULL;
  283. m_genBarButtonIn = NULL;
  284. m_genBarButtonOn = NULL;
  285. m_toggleButtonUpIn = NULL;
  286. m_toggleButtonUpOn = NULL;
  287. m_toggleButtonUpPushed = NULL;
  288. m_toggleButtonDownIn = NULL;
  289. m_toggleButtonDownOn = NULL;
  290. m_toggleButtonDownPushed = NULL;
  291. m_commandMarkerImage = NULL;
  292. m_expBarForeground = NULL;
  293. m_powerPurchaseImage = NULL;
  294. m_generalButtonEnable = NULL;
  295. m_generalButtonHightlited = NULL;
  296. m_generalButtonPushed = NULL;
  297. m_generalButtonDisabled = NULL;
  298. m_uAttackButtonEnable = NULL;
  299. m_uAttackButtonHightlited = NULL;
  300. m_uAttackButtonPushed = NULL;
  301. m_genArrow = NULL;
  302. m_minMaxButtonEnable = NULL;
  303. m_minMaxButtonHightlited = NULL;
  304. m_minMaxButtonPushed = NULL;
  305. m_minMaxUL.x = 0;
  306. m_minMaxLR.x = 0;
  307. m_generalUL.x = 0;
  308. m_generalLR.x = 0;
  309. m_uAttackUL.x = 0;
  310. m_uAttackLR.x = 0;
  311. m_optionsUL.x = 0;
  312. m_optionsLR.x = 0;
  313. m_workerUL.x = 0;
  314. m_workerLR.x = 0;
  315. m_chatUL.x = 0;
  316. m_chatLR.x = 0;
  317. m_beaconUL.x = 0;
  318. m_beaconLR.x = 0;
  319. m_powerBarUL.x = 0;
  320. m_powerBarLR.x = 0;
  321. m_minMaxUL.y = 0;
  322. m_minMaxLR.y = 0;
  323. m_generalUL.y = 0;
  324. m_generalLR.y = 0;
  325. m_uAttackUL.y = 0;
  326. m_uAttackLR.y = 0;
  327. m_optionsUL.y = 0;
  328. m_optionsLR.y = 0;
  329. m_workerUL.y = 0;
  330. m_workerLR.y = 0;
  331. m_chatUL.y = 0;
  332. m_chatLR.y = 0;
  333. m_beaconUL.y = 0;
  334. m_beaconLR.y = 0;
  335. m_powerBarUL.y = 0;
  336. m_powerBarLR.y = 0;
  337. m_moneyUL.x = 0;
  338. m_moneyUL.y = 0;
  339. m_moneyLR.x = 0;
  340. m_moneyLR.y = 0;
  341. }
  342. void ControlBarScheme::init(void)
  343. {
  344. if(TheControlBar)
  345. {
  346. TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
  347. TheControlBar->updateBuildQueueDisabledImages( m_buttonQueueImage );
  348. TheControlBar->updateRightHUDImage(m_rightHUDImage);
  349. TheControlBar->updateBuildUpClockColor( m_buildUpClockColor );
  350. TheControlBar->updateCommanBarBorderColors(m_borderBuildColor, m_borderActionColor, m_borderUpgradeColor,m_borderSystemColor);
  351. TheControlBar->updateBorderColor(m_commandBarBorderColor);
  352. //TheControlBar->updateCommandMarkerImage(m_commandMarkerImage);
  353. TheControlBar->updateSlotExitImage(m_commandMarkerImage);
  354. TheControlBar->updateUpDownImages(m_toggleButtonUpIn, m_toggleButtonUpOn, m_toggleButtonUpPushed, m_toggleButtonDownIn, m_toggleButtonDownOn, m_toggleButtonDownPushed, m_generalButtonEnable, m_generalButtonHightlited);
  355. TheControlBar->setArrowImage( m_genArrow);
  356. }
  357. GameWindow *win = NULL;
  358. Coord2D resMultiplier;
  359. resMultiplier.x = TheDisplay->getWidth()/INT_TO_REAL(m_ScreenCreationRes.x) ;
  360. resMultiplier.y = TheDisplay->getHeight()/INT_TO_REAL(m_ScreenCreationRes.y);
  361. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:PopupCommunicator" ) );
  362. if(win)
  363. {
  364. // DEBUG_ASSERTCRASH(m_buddyButtonEnable, ("No enable button image for communicator in scheme %s!\n", m_name.str()));
  365. // DEBUG_ASSERTCRASH(m_buddyButtonHightlited, ("No hilite button image for communicator in scheme %s!\n", m_name.str()));
  366. // DEBUG_ASSERTCRASH(m_buddyButtonPushed, ("No pushed button image for communicator in scheme %s!\n", m_name.str()));
  367. GadgetButtonSetEnabledImage(win, m_buddyButtonEnable);
  368. GadgetButtonSetHiliteImage(win, m_buddyButtonHightlited);
  369. GadgetButtonSetHiliteSelectedImage(win, m_buddyButtonPushed);
  370. GadgetButtonSetDisabledImage(win, m_buddyButtonDisabled);
  371. Int x, y;
  372. GameWindow* parent =win->winGetParent();
  373. if(parent)
  374. {
  375. Int parX, parY;
  376. parent->winGetScreenPosition(&parX, &parY);
  377. x = m_chatUL.x * resMultiplier.x - parX;
  378. y = m_chatUL.y * resMultiplier.y - parY;
  379. }
  380. else
  381. {
  382. x = m_chatUL.x * resMultiplier.x;
  383. y = m_chatUL.y * resMultiplier.y;
  384. }
  385. win->winSetPosition(x,y );
  386. win->winSetSize((m_chatLR.x - m_chatUL.x)*resMultiplier.x + COMMAND_BAR_SIZE_OFFSET,(m_chatLR.y - m_chatUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  387. }
  388. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonIdleWorker" ) );
  389. if(win)
  390. {
  391. GadgetButtonSetEnabledImage(win, m_idleWorkerButtonEnable);
  392. GadgetButtonSetHiliteImage(win, m_idleWorkerButtonHightlited);
  393. GadgetButtonSetHiliteSelectedImage(win, m_idleWorkerButtonPushed);
  394. GadgetButtonSetDisabledImage(win, m_idleWorkerButtonDisabled);
  395. Int x, y;
  396. GameWindow* parent =win->winGetParent();
  397. if(parent)
  398. {
  399. Int parX, parY;
  400. parent->winGetScreenPosition(&parX, &parY);
  401. x = m_workerUL.x * resMultiplier.x - parX;
  402. y = m_workerUL.y * resMultiplier.y - parY;
  403. }
  404. else
  405. {
  406. x = m_workerUL.x * resMultiplier.x;
  407. y = m_workerUL.y * resMultiplier.y;
  408. }
  409. win->winSetPosition(x,y );
  410. win->winSetSize((m_workerLR.x - m_workerUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_workerLR.y - m_workerUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  411. }
  412. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ExpBarForeground" ) );
  413. if(win)
  414. {
  415. win->winSetEnabledImage(0, m_expBarForeground);
  416. }
  417. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonOptions" ) );
  418. if(win)
  419. {
  420. GadgetButtonSetEnabledImage(win, m_optionsButtonEnable);
  421. GadgetButtonSetHiliteImage(win, m_optionsButtonHightlited);
  422. GadgetButtonSetHiliteSelectedImage(win, m_optionsButtonPushed);
  423. GadgetButtonSetDisabledImage(win, m_optionsButtonDisabled);
  424. Int x, y;
  425. GameWindow* parent =win->winGetParent();
  426. if(parent)
  427. {
  428. Int parX, parY;
  429. parent->winGetScreenPosition(&parX, &parY);
  430. x = m_optionsUL.x * resMultiplier.x - parX;
  431. y = m_optionsUL.y * resMultiplier.y - parY;
  432. }
  433. else
  434. {
  435. x = m_optionsUL.x * resMultiplier.x;
  436. y = m_optionsUL.y * resMultiplier.y;
  437. }
  438. win->winSetPosition(x,y );
  439. win->winSetSize((m_optionsLR.x - m_optionsUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_optionsLR.y - m_optionsUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  440. }
  441. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonPlaceBeacon" ) );
  442. if(win)
  443. {
  444. GadgetButtonSetEnabledImage(win, m_beaconButtonEnable);
  445. GadgetButtonSetHiliteImage(win, m_beaconButtonHightlited);
  446. GadgetButtonSetHiliteSelectedImage(win, m_beaconButtonPushed);
  447. GadgetButtonSetDisabledImage(win, m_beaconButtonDisabled);
  448. Int x, y;
  449. GameWindow* parent =win->winGetParent();
  450. if(parent)
  451. {
  452. Int parX, parY;
  453. parent->winGetScreenPosition(&parX, &parY);
  454. x = m_beaconUL.x * resMultiplier.x - parX;
  455. y = m_beaconUL.y * resMultiplier.y - parY;
  456. }
  457. else
  458. {
  459. x = m_beaconUL.x * resMultiplier.x;
  460. y = m_beaconUL.y * resMultiplier.y;
  461. }
  462. win->winSetPosition(x,y );
  463. win->winSetSize((m_beaconLR.x - m_beaconUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_beaconLR.y - m_beaconUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  464. }
  465. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:MoneyDisplay" ) );
  466. if(win)
  467. {
  468. Int x, y;
  469. GameWindow* parent =win->winGetParent();
  470. if(parent)
  471. {
  472. Int parX, parY;
  473. parent->winGetScreenPosition(&parX, &parY);
  474. x = m_moneyUL.x * resMultiplier.x - parX;
  475. y = m_moneyUL.y * resMultiplier.y - parY;
  476. }
  477. else
  478. {
  479. x = m_moneyUL.x * resMultiplier.x;
  480. y = m_moneyUL.y * resMultiplier.y;
  481. }
  482. win->winSetPosition(x,y );
  483. win->winSetSize((m_moneyLR.x - m_moneyUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_moneyLR.y - m_moneyUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  484. }
  485. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:PowerWindow" ) );
  486. if(win)
  487. {
  488. Int x, y;
  489. GameWindow* parent =win->winGetParent();
  490. if(parent)
  491. {
  492. Int parX, parY;
  493. parent->winGetScreenPosition(&parX, &parY);
  494. x = m_powerBarUL.x * resMultiplier.x - parX;
  495. y = m_powerBarUL.y * resMultiplier.y - parY;
  496. }
  497. else
  498. {
  499. x = m_powerBarUL.x * resMultiplier.x;
  500. y = m_powerBarUL.y * resMultiplier.y;
  501. }
  502. win->winSetPosition(x,y );
  503. win->winSetSize((m_powerBarLR.x - m_powerBarUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_powerBarLR.y - m_powerBarUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  504. DEBUG_LOG(("Power Bar UL X:%d Y:%d LR X:%d Y:%d size X:%d Y:%d\n",m_powerBarUL.x, m_powerBarUL.y,m_powerBarLR.x, m_powerBarLR.y, (m_powerBarLR.x - m_powerBarUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_powerBarLR.y - m_powerBarUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET ));
  505. }
  506. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonGeneral" ) );
  507. if(win)
  508. {
  509. GadgetButtonSetEnabledImage(win, m_generalButtonEnable);
  510. GadgetButtonSetHiliteImage(win, m_generalButtonHightlited);
  511. GadgetButtonSetHiliteSelectedImage(win, m_generalButtonPushed);
  512. GadgetButtonSetDisabledImage(win, m_generalButtonDisabled);
  513. Int x, y;
  514. GameWindow* parent =win->winGetParent();
  515. if(parent)
  516. {
  517. Int parX, parY;
  518. parent->winGetScreenPosition(&parX, &parY);
  519. x = m_generalUL.x * resMultiplier.x - parX;
  520. y = m_generalUL.y * resMultiplier.y - parY;
  521. }
  522. else
  523. {
  524. x = m_generalUL.x * resMultiplier.x;
  525. y = m_generalUL.y * resMultiplier.y;
  526. }
  527. win->winSetPosition(x,y );
  528. win->winSetSize((m_generalLR.x - m_generalUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_generalLR.y - m_generalUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  529. }
  530. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonLarge" ) );
  531. if(win)
  532. {
  533. // The images are set above
  534. // GadgetButtonSetEnabledImage(win, m_minMaxButtonEnable);
  535. // GadgetButtonSetHiliteImage(win, m_minMaxButtonHightlited);
  536. // GadgetButtonSetHiliteSelectedImage(win, m_minMaxButtonPushed);
  537. Int x, y;
  538. GameWindow* parent =win->winGetParent();
  539. if(parent)
  540. {
  541. Int parX, parY;
  542. parent->winGetScreenPosition(&parX, &parY);
  543. x = m_minMaxUL.x * resMultiplier.x - parX;
  544. y = m_minMaxUL.y * resMultiplier.y - parY;
  545. }
  546. else
  547. {
  548. x = m_minMaxUL.x * resMultiplier.x;
  549. y = m_minMaxUL.y * resMultiplier.y;
  550. }
  551. win->winSetPosition(x,y );
  552. win->winSetSize((m_minMaxLR.x - m_minMaxUL.x)*resMultiplier.x + COMMAND_BAR_SIZE_OFFSET,(m_minMaxLR.y - m_minMaxUL.y)*resMultiplier.y + COMMAND_BAR_SIZE_OFFSET);
  553. }
  554. win= TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:WinUAttack" ) );
  555. if(win)
  556. {
  557. win->winSetEnabledImage(0,m_uAttackButtonEnable);
  558. win->winSetDisabledImage(0,m_uAttackButtonHightlited);
  559. Int x, y;
  560. GameWindow* parent =win->winGetParent();
  561. if(parent)
  562. {
  563. Int parX, parY;
  564. parent->winGetScreenPosition(&parX, &parY);
  565. x = m_uAttackUL.x * resMultiplier.x - parX;
  566. y = m_uAttackUL.y * resMultiplier.y - parY;
  567. }
  568. else
  569. {
  570. x = m_uAttackUL.x * resMultiplier.x;
  571. y = m_uAttackUL.y * resMultiplier.y;
  572. }
  573. win->winSetPosition(x,y );
  574. win->winSetSize((m_uAttackLR.x - m_uAttackUL.x)*resMultiplier.x+ COMMAND_BAR_SIZE_OFFSET,(m_uAttackLR.y - m_uAttackUL.y)*resMultiplier.y+ COMMAND_BAR_SIZE_OFFSET);
  575. }
  576. win = TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:GenExpParent" ) );
  577. if(win)
  578. {
  579. win->winSetEnabledImage(0,m_powerPurchaseImage);
  580. if( m_powerPurchaseImage )
  581. {
  582. win->winSetSize(m_powerPurchaseImage->getImageWidth() * resMultiplier.x, m_powerPurchaseImage->getImageHeight() * resMultiplier.y);
  583. }
  584. }
  585. }
  586. //
  587. // Add an animation to the animation list
  588. //-----------------------------------------------------------------------------
  589. void ControlBarScheme::addAnimation( ControlBarSchemeAnimation *schemeAnim )
  590. {
  591. if( !schemeAnim )
  592. {
  593. DEBUG_ASSERTCRASH(FALSE,("Trying to add a null animation to the controlbarscheme\n"));
  594. return;
  595. }
  596. m_animations.push_back( schemeAnim );
  597. }// addAnimation
  598. //
  599. // Add an image to the proper layer list
  600. //-----------------------------------------------------------------------------
  601. void ControlBarScheme::addImage( ControlBarSchemeImage *schemeImage )
  602. {
  603. if( !schemeImage )
  604. {
  605. DEBUG_ASSERTCRASH(FALSE,("Trying to add a null image to the controlbarscheme\n"));
  606. return;
  607. }
  608. if(schemeImage->m_layer < 0 || schemeImage->m_layer >= MAX_CONTROL_BAR_SCHEME_IMAGE_LAYERS)
  609. {
  610. DEBUG_ASSERTCRASH(FALSE,("SchemeImage %s attempted to be added to layer %d which is not Between to %d, %d\n",
  611. schemeImage->m_name.str(), schemeImage->m_layer, 0, MAX_CONTROL_BAR_SCHEME_IMAGE_LAYERS));
  612. // bring the foobar to the front so we make it obvious that something's wrong
  613. schemeImage->m_layer = 0;
  614. }
  615. m_layer[schemeImage->m_layer].push_back(schemeImage);
  616. }// addImage
  617. //
  618. // Update the position of the image that's animating
  619. //-----------------------------------------------------------------------------
  620. void ControlBarScheme::updateAnim (ControlBarSchemeAnimation * anim)
  621. {
  622. switch(anim->m_animType)
  623. {
  624. case ControlBarSchemeAnimation::CB_ANIM_SLIDE_RIGHT:
  625. {
  626. animSlideRight( anim );
  627. break;
  628. }
  629. default:
  630. {
  631. DEBUG_ASSERTCRASH(FALSE,("We tried to animate but not animate function was found %d", anim->m_animType));
  632. }
  633. }
  634. }
  635. //
  636. // Add an image to the proper layer list
  637. //-----------------------------------------------------------------------------
  638. void ControlBarScheme::update( void )
  639. {
  640. ControlBarSchemeAnimationList::iterator it = m_animations.begin();
  641. while (it != m_animations.end())
  642. {
  643. ControlBarSchemeAnimation *anim = *it;
  644. if( !anim )
  645. {
  646. DEBUG_ASSERTCRASH(FALSE,("THere's no Animation in the ControlBarSchemeAnimationList:m_animations"));
  647. return;
  648. }
  649. updateAnim( anim );
  650. it ++;
  651. }
  652. }
  653. //
  654. // Loop through the propper lists and draw everything for the forground
  655. //-----------------------------------------------------------------------------
  656. void ControlBarScheme::drawForeground( Coord2D multi, ICoord2D offset )
  657. {
  658. for(Int i = CONTROL_BAR_SCHEME_FOREGROUND_IMAGE_LAYERS - 1; i >= 0; i--)
  659. {
  660. ControlBarSchemeImageList::iterator it = m_layer[i].begin();
  661. while (it != m_layer[i].end())
  662. {
  663. ControlBarSchemeImage *schemeImage = *it;
  664. if( !schemeImage )
  665. {
  666. DEBUG_ASSERTCRASH(FALSE,("There is no ControlBarSchemeImage found in the m_layer list"));
  667. it++;
  668. continue;
  669. }
  670. // if we dont' have an image, don't try to draw it
  671. if(!schemeImage->m_image)
  672. {
  673. it++;
  674. continue;
  675. }
  676. // draw the image
  677. TheDisplay->drawImage(schemeImage->m_image, schemeImage->m_position.x * multi.x + offset.x,
  678. schemeImage->m_position.y * multi.y + offset.y,
  679. (schemeImage->m_position.x + schemeImage->m_size.x) * multi.x + offset.x,
  680. (schemeImage->m_position.y + schemeImage->m_size.y) * multi.y + offset.y);
  681. it ++;
  682. }
  683. }
  684. }
  685. //
  686. // Add an image to the proper layer list
  687. //-----------------------------------------------------------------------------
  688. void ControlBarScheme::drawBackground( Coord2D multi, ICoord2D offset )
  689. {
  690. for(Int i = MAX_CONTROL_BAR_SCHEME_IMAGE_LAYERS - 1; i >= CONTROL_BAR_SCHEME_FOREGROUND_IMAGE_LAYERS; i--)
  691. {
  692. ControlBarSchemeImageList::iterator it = m_layer[i].begin();
  693. while (it != m_layer[i].end())
  694. {
  695. ControlBarSchemeImage *schemeImage = *it;
  696. if( !schemeImage )
  697. {
  698. DEBUG_ASSERTCRASH(FALSE,("There is no ControlBarSchemeImage found in the m_layer list"));
  699. it++;
  700. continue;
  701. }
  702. // if we don't have an image, don't try to draw it
  703. if(!schemeImage->m_image)
  704. {
  705. it++;
  706. continue;
  707. }
  708. // draw it
  709. TheDisplay->drawImage(schemeImage->m_image, schemeImage->m_position.x * multi.x + offset.x,
  710. schemeImage->m_position.y * multi.y + offset.y,
  711. (schemeImage->m_position.x + schemeImage->m_size.x) * multi.x + offset.x,
  712. (schemeImage->m_position.y + schemeImage->m_size.y) * multi.y + offset.y);
  713. it ++;
  714. }
  715. }
  716. }
  717. //
  718. // Constructor for the manager
  719. //-----------------------------------------------------------------------------
  720. ControlBarSchemeManager::ControlBarSchemeManager( void )
  721. {
  722. m_currentScheme = NULL;
  723. m_schemeList.clear();
  724. m_multiplyer.x = m_multiplyer.y = 1;
  725. }
  726. //
  727. // Destructor for the Manager
  728. //-----------------------------------------------------------------------------
  729. ControlBarSchemeManager::~ControlBarSchemeManager( void )
  730. {
  731. ControlBarSchemeList::iterator it = m_schemeList.begin();
  732. // iterate through the list and return the scheme that we're looking for
  733. while (it != m_schemeList.end())
  734. {
  735. ControlBarScheme *CBScheme = *it;
  736. if( CBScheme )
  737. delete CBScheme;
  738. CBScheme = NULL;
  739. it ++;
  740. }
  741. m_schemeList.clear();
  742. m_currentScheme = NULL;
  743. }
  744. //
  745. // Parse the Image Part of the command bar
  746. //-----------------------------------------------------------------------------
  747. void ControlBarSchemeManager::parseImagePart(INI *ini, void *instance, void* /*store*/, const void* /*userData*/)
  748. {
  749. static const FieldParse myFieldParse[] =
  750. {
  751. { "Position", INI::parseICoord2D, NULL, offsetof( ControlBarSchemeImage, m_position ) },
  752. { "Size", INI::parseICoord2D, NULL, offsetof( ControlBarSchemeImage, m_size ) },
  753. { "ImageName", INI::parseMappedImage, NULL, offsetof( ControlBarSchemeImage, m_image ) },
  754. { "Layer", INI::parseInt, NULL, offsetof( ControlBarSchemeImage, m_layer ) },
  755. { NULL, NULL, NULL, 0 } // keep this last
  756. };
  757. ControlBarSchemeImage *schemeImage = NEW ControlBarSchemeImage;
  758. ini->initFromINI(schemeImage, myFieldParse);
  759. ((ControlBarScheme*)instance)->addImage(schemeImage);
  760. }
  761. //
  762. // each animation part contains and image, parse it
  763. //-----------------------------------------------------------------------------
  764. void ControlBarSchemeManager::parseAnimatingPartImage(INI *ini, void *instance, void* /*store*/, const void* /*userData*/)
  765. {
  766. static const FieldParse myFieldParse[] =
  767. {
  768. { "Position", INI::parseICoord2D, NULL, offsetof( ControlBarSchemeImage, m_position ) },
  769. { "Size", INI::parseICoord2D, NULL, offsetof( ControlBarSchemeImage, m_size ) },
  770. { "ImageName", INI::parseMappedImage, NULL, offsetof( ControlBarSchemeImage, m_image ) },
  771. { "Layer", INI::parseInt, NULL, offsetof( ControlBarSchemeImage, m_layer ) },
  772. { NULL, NULL, NULL, 0 } // keep this last
  773. };
  774. ControlBarSchemeImage *schemeImage = NEW ControlBarSchemeImage;
  775. ini->initFromINI(schemeImage, myFieldParse);
  776. ((ControlBarSchemeAnimation*)instance)->m_animImage = schemeImage;
  777. }
  778. //
  779. // parse the animating part of the control bar scheme
  780. //-----------------------------------------------------------------------------
  781. void ControlBarSchemeManager::parseAnimatingPart(INI *ini, void *instance, void* /*store*/, const void* /*userData*/)
  782. {
  783. static const FieldParse myFieldParse[] =
  784. {
  785. { "Name", INI::parseAsciiString, NULL, offsetof( ControlBarSchemeAnimation, m_name ) },
  786. { "Animation", INI::parseLookupList, AnimTypeNames, offsetof( ControlBarSchemeAnimation, m_animType ) },
  787. { "Duration", INI::parseDurationUnsignedInt, NULL, offsetof( ControlBarSchemeAnimation, m_animDuration ) },
  788. { "FinalPos", INI::parseICoord2D, NULL, offsetof( ControlBarSchemeAnimation, m_finalPos ) },
  789. { "ImagePart", ControlBarSchemeManager::parseAnimatingPartImage, NULL, NULL },
  790. { NULL, NULL, NULL, 0 } // keep this last
  791. };
  792. ControlBarSchemeAnimation *schemeAnim = NEW ControlBarSchemeAnimation;
  793. ini->initFromINI(schemeAnim, myFieldParse);
  794. ((ControlBarScheme*)instance)->addAnimation(schemeAnim);
  795. ((ControlBarScheme*)instance)->addImage(schemeAnim->m_animImage);
  796. }
  797. //
  798. // Create a new control bar and return it. Link it into our control bar list
  799. //-----------------------------------------------------------------------------
  800. ControlBarScheme *ControlBarSchemeManager::newControlBarScheme( AsciiString name )
  801. {
  802. ControlBarScheme *cbScheme = findControlBarScheme(name);
  803. if(cbScheme)
  804. {
  805. DEBUG_ASSERTCRASH(false,("We're overwriting a previous control bar scheme %s",name.str()));
  806. cbScheme->reset();
  807. cbScheme->m_name.set( name );
  808. cbScheme->m_name.toLower();
  809. return cbScheme;
  810. }
  811. cbScheme = NEW ControlBarScheme;
  812. if( !cbScheme || name.isEmpty() )
  813. {
  814. DEBUG_ASSERTCRASH(FALSE,("Could not create controlbar %s", name.str()));
  815. return NULL;
  816. }
  817. cbScheme->m_name.set( name );
  818. cbScheme->m_name.toLower();
  819. m_schemeList.push_back(cbScheme);
  820. return cbScheme;
  821. }
  822. //
  823. // Find a scheme based on name
  824. //-----------------------------------------------------------------------------
  825. ControlBarScheme *ControlBarSchemeManager::findControlBarScheme( AsciiString name )
  826. {
  827. name.toLower();
  828. ControlBarSchemeList::iterator it = m_schemeList.begin();
  829. // iterate through the list and return the scheme that we're looking for
  830. while (it != m_schemeList.end())
  831. {
  832. ControlBarScheme *CBScheme = *it;
  833. if( !CBScheme )
  834. {
  835. DEBUG_ASSERTCRASH(FALSE,("There's no ControlBarScheme in the ControlBarSchemeList:m_schemeList"));
  836. return NULL;
  837. }
  838. if(CBScheme->m_name.compareNoCase( name ) == 0)
  839. return CBScheme;
  840. it ++;
  841. }
  842. return NULL;
  843. }
  844. //
  845. // Preload assets
  846. //-----------------------------------------------------------------------------
  847. void ControlBarSchemeManager::preloadAssets( TimeOfDay timeOfDay )
  848. {
  849. for (ControlBarSchemeList::iterator it = m_schemeList.begin(); it != m_schemeList.end(); ++it)
  850. {
  851. ControlBarScheme *CBScheme = *it;
  852. if( !CBScheme )
  853. {
  854. DEBUG_ASSERTCRASH(FALSE,("There's no ControlBarScheme in the ControlBarSchemeList:m_schemeList"));
  855. continue;
  856. }
  857. if (CBScheme->m_buttonQueueImage)
  858. {
  859. TheDisplay->preloadTextureAssets(CBScheme->m_buttonQueueImage->getFilename());
  860. }
  861. if (CBScheme->m_rightHUDImage)
  862. {
  863. TheDisplay->preloadTextureAssets(CBScheme->m_buttonQueueImage->getFilename());
  864. }
  865. for (Int layer = 0; layer < MAX_CONTROL_BAR_SCHEME_IMAGE_LAYERS; ++layer)
  866. {
  867. for (ControlBarScheme::ControlBarSchemeImageList::iterator listIt = CBScheme->m_layer[layer].begin(); listIt != CBScheme->m_layer[layer].end(); ++listIt)
  868. {
  869. ControlBarSchemeImage *cbImage = *listIt;
  870. if (cbImage)
  871. {
  872. const Image *image = TheMappedImageCollection->findImageByName( cbImage->m_name );
  873. if (image)
  874. {
  875. TheDisplay->preloadTextureAssets(image->getFilename());
  876. }
  877. }
  878. }
  879. }
  880. }
  881. }
  882. //
  883. // Find a scheme based on name
  884. //-----------------------------------------------------------------------------
  885. void ControlBarSchemeManager::init( void )
  886. {
  887. INI ini;
  888. // Read from INI all the ControlBarSchemes
  889. ini.load( AsciiString( "Data\\INI\\Default\\ControlBarScheme.ini" ), INI_LOAD_OVERWRITE, NULL );
  890. ini.load( AsciiString( "Data\\INI\\ControlBarScheme.ini" ), INI_LOAD_OVERWRITE, NULL );
  891. // //Load the user modified control bar schemes
  892. // WIN32_FIND_DATA findData;
  893. // AsciiString userDataPath;
  894. // if(TheGlobalData)
  895. // {
  896. // userDataPath.format("%sINI\\ControlBarScheme.ini",TheGlobalData->getPath_UserData().str());
  897. // if (FindFirstFile(userDataPath.str(), &findData) !=INVALID_HANDLE_VALUE)
  898. // ini.load(userDataPath, INI_LOAD_OVERWRITE, NULL );
  899. // }
  900. if( m_schemeList.size() <= 0 )
  901. {
  902. DEBUG_ASSERTCRASH(FALSE,("There's no ControlBarScheme in the ControlBarSchemeList:m_schemeList that was just read from the INI file"));
  903. return;
  904. }
  905. }
  906. //
  907. // only recommended to use if you know what you're doing, cause you could actually load in
  908. // a control bar built for 16x12 into an 8x6 screen which would use a lot more memory then it should
  909. //-----------------------------------------------------------------------------
  910. void ControlBarSchemeManager::setControlBarScheme(AsciiString schemeName)
  911. {
  912. ControlBarScheme *tempScheme = findControlBarScheme( schemeName );
  913. if(tempScheme)
  914. {
  915. // setup the multiplyer value
  916. m_multiplyer.x = TheDisplay->getWidth() / tempScheme->m_ScreenCreationRes.x;
  917. m_multiplyer.y = TheDisplay->getHeight() / tempScheme->m_ScreenCreationRes.y;
  918. m_currentScheme = tempScheme;
  919. }
  920. else
  921. {
  922. DEBUG_ASSERTCRASH(FALSE,("There's no ControlBarScheme in the ControlBarSchemeList:m_schemeList"));
  923. m_currentScheme = NULL;
  924. }
  925. if(m_currentScheme)
  926. m_currentScheme->init();
  927. }
  928. //
  929. // Update calls all the animation update calls for the
  930. //-----------------------------------------------------------------------------
  931. void ControlBarSchemeManager::update( void )
  932. {
  933. if(m_currentScheme)
  934. m_currentScheme->update();
  935. }
  936. //-----------------------------------------------------------------------------
  937. void ControlBarSchemeManager::drawForeground( ICoord2D offset )
  938. {
  939. if(m_currentScheme)
  940. m_currentScheme->drawForeground( m_multiplyer, offset);
  941. }
  942. //-----------------------------------------------------------------------------
  943. void ControlBarSchemeManager::drawBackground( ICoord2D offset )
  944. {
  945. if(m_currentScheme)
  946. m_currentScheme->drawBackground( m_multiplyer, offset );
  947. }
  948. //-----------------------------------------------------------------------------
  949. void ControlBarSchemeManager::setControlBarSchemeByPlayerTemplate( const PlayerTemplate *pt, Bool useSmall)
  950. {
  951. if(!pt)
  952. return;
  953. AsciiString side = pt->getSide();
  954. if(useSmall)
  955. side.concat("Small");
  956. if(m_currentScheme && (m_currentScheme->m_side.compare(side) == 0))
  957. {
  958. m_currentScheme->init();
  959. DEBUG_LOG(("setControlBarSchemeByPlayer already is using %s as its side\n", side.str()));
  960. return;
  961. }
  962. // if we don't have a side, set it to Observer shell
  963. if(side.isEmpty())
  964. side.set("Observer");
  965. DEBUG_LOG(("setControlBarSchemeByPlayer used %s as its side\n", side.str()));
  966. ControlBarScheme *tempScheme = NULL;
  967. ControlBarSchemeList::iterator it = m_schemeList.begin();
  968. // iterate through the list and return the scheme that we're looking for
  969. while (it != m_schemeList.end())
  970. {
  971. ControlBarScheme *CBScheme = *it;
  972. if( !CBScheme )
  973. {
  974. DEBUG_ASSERTCRASH(FALSE,("There's no ControlBarScheme in the ControlBarSchemeList:m_schemeList"));
  975. it++;
  976. continue;
  977. }
  978. // find the scheme that best matches our resolution
  979. if(CBScheme->m_side.compareNoCase( side ) == 0)
  980. {
  981. if((!tempScheme || tempScheme->m_ScreenCreationRes.x < CBScheme->m_ScreenCreationRes.x) )//&& TheDisplay->getWidth() >= CBScheme->m_ScreenCreationRes.x )
  982. tempScheme = CBScheme;
  983. }
  984. it ++;
  985. }
  986. if(tempScheme)
  987. {
  988. // setup the multiplyer value
  989. m_multiplyer.x = TheDisplay->getWidth() / (Real)tempScheme->m_ScreenCreationRes.x;
  990. m_multiplyer.y = TheDisplay->getHeight() / (Real)tempScheme->m_ScreenCreationRes.y;
  991. m_currentScheme = tempScheme;
  992. }
  993. else
  994. {
  995. // well, we couldn't find
  996. m_currentScheme = findControlBarScheme("Default");
  997. DEBUG_LOG(("There's no ControlBarScheme with a side of %s", side.str()));
  998. // m_currentScheme = NULL;
  999. }
  1000. if(m_currentScheme)
  1001. m_currentScheme->init();
  1002. }
  1003. //-----------------------------------------------------------------------------
  1004. void ControlBarSchemeManager::setControlBarSchemeByPlayer(Player *p)
  1005. {
  1006. GameWindow *communicatorButton = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY("ControlBar.wnd:PopupCommunicator") );
  1007. if (communicatorButton && TheControlBar)
  1008. {
  1009. if (TheRecorder->isMultiplayer())
  1010. TheControlBar->setControlCommand(communicatorButton, TheControlBar->findCommandButton("NonCommand_Communicator") );
  1011. else
  1012. TheControlBar->setControlCommand(communicatorButton, TheControlBar->findCommandButton("NonCommand_BriefingHistory") );
  1013. }
  1014. if(!p)
  1015. return;
  1016. AsciiString side = p->getSide();
  1017. if(m_currentScheme && (m_currentScheme->m_side.compare(side) == 0))
  1018. {
  1019. m_currentScheme->init();
  1020. DEBUG_LOG(("setControlBarSchemeByPlayer already is using %s as its side\n", side.str()));
  1021. return;
  1022. }
  1023. // if we don't have a side, set it to Observer shell
  1024. if(side.isEmpty())
  1025. side.set("Observer");
  1026. DEBUG_LOG(("setControlBarSchemeByPlayer used %s as its side\n", side.str()));
  1027. ControlBarScheme *tempScheme = NULL;
  1028. ControlBarSchemeList::iterator it = m_schemeList.begin();
  1029. // iterate through the list and return the scheme that we're looking for
  1030. while (it != m_schemeList.end())
  1031. {
  1032. ControlBarScheme *CBScheme = *it;
  1033. if( !CBScheme )
  1034. {
  1035. DEBUG_ASSERTCRASH(FALSE,("There's no ControlBarScheme in the ControlBarSchemeList:m_schemeList"));
  1036. it++;
  1037. continue;
  1038. }
  1039. // find the scheme that best matches our resolution
  1040. if(CBScheme->m_side.compareNoCase( side ) == 0)
  1041. {
  1042. if((!tempScheme || tempScheme->m_ScreenCreationRes.x < CBScheme->m_ScreenCreationRes.x) )//&& TheDisplay->getWidth() >= CBScheme->m_ScreenCreationRes.x )
  1043. tempScheme = CBScheme;
  1044. }
  1045. it ++;
  1046. }
  1047. if(tempScheme)
  1048. {
  1049. // setup the multiplyer value
  1050. m_multiplyer.x = TheDisplay->getWidth() / (Real)tempScheme->m_ScreenCreationRes.x;
  1051. m_multiplyer.y = TheDisplay->getHeight() / (Real)tempScheme->m_ScreenCreationRes.y;
  1052. m_currentScheme = tempScheme;
  1053. }
  1054. else
  1055. {
  1056. // well, we couldn't find
  1057. m_currentScheme = findControlBarScheme("Default");
  1058. DEBUG_LOG(("There's no ControlBarScheme with a side of %s", side.str()));
  1059. // m_currentScheme = NULL;
  1060. }
  1061. if(m_currentScheme)
  1062. m_currentScheme->init();
  1063. }
  1064. //-----------------------------------------------------------------------------
  1065. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  1066. //-----------------------------------------------------------------------------
  1067. static void animSlideRight( ControlBarSchemeAnimation *anim )
  1068. {
  1069. if(!anim->m_animImage || (anim->m_animDuration == 0))
  1070. return;
  1071. UnsignedInt currentFrame = anim->getCurrentFrame();
  1072. ICoord2D startPos = anim->getStartPos();
  1073. // if we're at the end, bring us to the beginning
  1074. if(currentFrame == anim->m_animDuration)
  1075. {
  1076. anim->m_animImage->m_position.x = startPos.x;
  1077. anim->m_animImage->m_position.y = startPos.y;
  1078. anim->setCurrentFrame( 0 );
  1079. return;
  1080. }
  1081. else if(currentFrame == 0)
  1082. {
  1083. // if we're at the beginning, save off the start position
  1084. startPos.x = anim->m_animImage->m_position.x;
  1085. startPos.y = anim->m_animImage->m_position.y;
  1086. anim->setStartPos(startPos);
  1087. }
  1088. // now lets animate this bad boy!
  1089. // now increment the frame
  1090. currentFrame++;
  1091. anim->setCurrentFrame(currentFrame);
  1092. // now lets find what position we should be at.
  1093. anim->m_animImage->m_position.x = startPos.x + (((anim->m_finalPos.x - startPos.x) * currentFrame) / anim->m_animDuration);
  1094. }