ControlBarScheme.cpp 43 KB

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