MPAddAIPlayer.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. #define MPADDAIPLAYER_CPP
  2. /*************************************************************************************************\
  3. MPAddAIPlayer.cpp : Implementation of the MPAddAIPlayer component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "MPAddAIPlayer.h"
  9. #include "prefs.h"
  10. #include "IniFile.h"
  11. #include "../MCLib/UserInput.h"
  12. #include "..\resource.h"
  13. #ifndef GAMESOUND_H
  14. #include "gamesound.h"
  15. #endif
  16. #define CHECK_BUTTON 200
  17. static CFocusManager *g_focusManager = NULL;
  18. static const int FIRST_BUTTON_ID = 1000010;
  19. static const int OK_BUTTON_ID = 1000001;
  20. static const int CANCEL_BUTTON_ID = 1000002;
  21. MPAddAIPlayer::MPAddAIPlayer()
  22. {
  23. status = RUNNING;
  24. g_focusManager = &focusManager;
  25. }
  26. MPAddAIPlayer::~MPAddAIPlayer()
  27. {
  28. g_focusManager = NULL;
  29. }
  30. int MPAddAIPlayer::indexOfButtonWithID(int id)
  31. {
  32. int i;
  33. for (i = 0; i < buttonCount; i++)
  34. {
  35. if (buttons[i].getID() == id)
  36. {
  37. return i;
  38. }
  39. }
  40. return -1;
  41. }
  42. void MPAddAIPlayer::init(FitIniFile* file)
  43. {
  44. if (g_focusManager)
  45. {
  46. g_focusManager->registerDropList(experienceDropList);
  47. g_focusManager->registerDropList(factionDropList);
  48. int row;
  49. for (row = 0; row < 4; row += 1)
  50. {
  51. int column;
  52. for (column = 0; column < 3; column += 1)
  53. {
  54. g_focusManager->registerDropList(mechSelectionDropLists[row][column]);
  55. }
  56. }
  57. }
  58. LogisticsScreen::init( *file, "Static", "Text", "Rect", "Button" );
  59. if ( buttonCount )
  60. {
  61. for ( int i = 0; i < buttonCount; i++ )
  62. {
  63. buttons[i].setMessageOnRelease();
  64. if (buttons[i].getID() == 0)
  65. {
  66. buttons[i].setID(FIRST_BUTTON_ID + i);
  67. }
  68. }
  69. }
  70. nameEntry.init(file, "EditBox0");
  71. nameEntryOutline.init(file, "EditBoxRect0");
  72. {
  73. char path[256];
  74. strcpy( path, artPath );
  75. strcat( path, "mcl_mp_addai_combobox1.fit" );
  76. FitIniFile PNfile;
  77. if ( NO_ERR != PNfile.open( path ) )
  78. {
  79. char error[256];
  80. sprintf( error, "couldn't open file %s", path );
  81. Assert( 0, 0, error );
  82. return;
  83. }
  84. experienceDropList.init(&PNfile, "ExperienceComboBox");
  85. PNfile.seekBlock( "Texts" );
  86. long listItemCount = 0;
  87. PNfile.readIdLong( "Textcount", listItemCount );
  88. aStyle4TextListItem *pTmp2;
  89. int i;
  90. for (i = 0; i < listItemCount; i += 1)
  91. {
  92. pTmp2 = new aStyle4TextListItem;
  93. EString tmpStr;
  94. tmpStr.Format("Text%d", i);
  95. pTmp2->init(&PNfile, tmpStr.Data());
  96. experienceDropList.AddItem(pTmp2);
  97. }
  98. experienceDropList.SelectItem(0);
  99. }
  100. {
  101. char path[256];
  102. strcpy( path, artPath );
  103. strcat( path, "mcl_mp_addai_combobox2.fit" );
  104. FitIniFile PNfile;
  105. if ( NO_ERR != PNfile.open( path ) )
  106. {
  107. char error[256];
  108. sprintf( error, "couldn't open file %s", path );
  109. Assert( 0, 0, error );
  110. return;
  111. }
  112. factionDropList.init(&PNfile, "FactionComboBox");
  113. PNfile.seekBlock( "Texts" );
  114. long listItemCount = 0;
  115. PNfile.readIdLong( "Textcount", listItemCount );
  116. aStyle4TextListItem *pTmp2;
  117. int i;
  118. for (i = 0; i < listItemCount; i += 1)
  119. {
  120. pTmp2 = new aStyle4TextListItem;
  121. EString tmpStr;
  122. tmpStr.Format("Text%d", i);
  123. pTmp2->init(&PNfile, tmpStr.Data());
  124. factionDropList.AddItem(pTmp2);
  125. }
  126. factionDropList.SelectItem(0);
  127. }
  128. int row;
  129. for (row = 0; row < 4; row += 1)
  130. {
  131. int column;
  132. for (column = 0; column < 3; column += 1)
  133. {
  134. {
  135. char path[256];
  136. strcpy( path, artPath );
  137. strcat( path, "mcl_mp_addai_combobox3.fit" );
  138. FitIniFile PNfile;
  139. if ( NO_ERR != PNfile.open( path ) )
  140. {
  141. char error[256];
  142. sprintf( error, "couldn't open file %s", path );
  143. Assert( 0, 0, error );
  144. return;
  145. }
  146. mechSelectionDropLists[row][column].init(&PNfile, "MechSelectionComboBox");
  147. PNfile.seekBlock( "Texts" );
  148. long listItemCount = 0;
  149. PNfile.readIdLong( "Textcount", listItemCount );
  150. aStyle4TextListItem *pTmp2;
  151. int i;
  152. for (i = 0; i < listItemCount; i += 1)
  153. {
  154. pTmp2 = new aStyle4TextListItem;
  155. EString tmpStr;
  156. tmpStr.Format("Text%d", i);
  157. pTmp2->init(&PNfile, tmpStr.Data());
  158. mechSelectionDropLists[row][column].AddItem(pTmp2);
  159. }
  160. mechSelectionDropLists[row][column].SelectItem(0);
  161. mechSelectionDropLists[row][column].moveTo(126 + column * (176 + 10), 317 + row * (32 + 5));
  162. }
  163. }
  164. }
  165. }
  166. void MPAddAIPlayer::begin()
  167. {
  168. status = RUNNING;
  169. }
  170. void MPAddAIPlayer::end()
  171. {
  172. }
  173. void MPAddAIPlayer::render(int xOffset, int yOffset )
  174. {
  175. LogisticsScreen::render(xOffset, yOffset);
  176. if ((0 == xOffset) && (0 == yOffset))
  177. {
  178. nameEntry.render();
  179. nameEntryOutline.render();
  180. experienceDropList.render();
  181. factionDropList.render();
  182. int row;
  183. for (row = 0; row < 4; row += 1)
  184. {
  185. int column;
  186. for (column = 0; column < 3; column += 1)
  187. {
  188. mechSelectionDropLists[row][column].render();
  189. }
  190. }
  191. /*make sure that that the control that has the focus is not obscured*/
  192. aObject *pControlThatHasTheFocus = focusManager.pControlThatHasTheFocus();
  193. if (pControlThatHasTheFocus)
  194. {
  195. pControlThatHasTheFocus->render();
  196. }
  197. }
  198. }
  199. void MPAddAIPlayer::render()
  200. {
  201. render(0, 0);
  202. }
  203. int MPAddAIPlayer::handleMessage( unsigned long message, unsigned long who)
  204. {
  205. if ( RUNNING == status )
  206. {
  207. switch ( who )
  208. {
  209. case 57/*MB_MSG_MAINMENU*/:
  210. {
  211. getButton( 57/*MB_MSG_MAINMENU*/ )->press( 0 );
  212. status = MAINMENU;
  213. }
  214. break;
  215. case 51/*MB_MSG_PREV*/:
  216. {
  217. getButton( 51/*MB_MSG_PREV*/ )->press( 0 );
  218. status = DOWN;
  219. }
  220. break;
  221. case 50/*MB_MSG_NEXT*/:
  222. {
  223. getButton( 50/*MB_MSG_NEXT*/ )->press( 0 );
  224. //status = NEXT;
  225. status = DOWN;
  226. }
  227. break;
  228. }
  229. }
  230. return 0;
  231. }
  232. void MPAddAIPlayer::update()
  233. {
  234. focusManager.update();
  235. aObject *pControlThatHasTheFocus = focusManager.pControlThatHasTheFocus();
  236. if (pControlThatHasTheFocus)
  237. {
  238. pControlThatHasTheFocus->update();
  239. }
  240. else
  241. {
  242. LogisticsScreen::update();
  243. nameEntry.update();
  244. nameEntryOutline.update();
  245. experienceDropList.update();
  246. factionDropList.update();
  247. int row;
  248. for (row = 0; row < 4; row += 1)
  249. {
  250. int column;
  251. for (column = 0; column < 3; column += 1)
  252. {
  253. mechSelectionDropLists[row][column].update();
  254. }
  255. }
  256. }
  257. helpTextID = 0;
  258. helpTextHeaderID = 0;
  259. /*
  260. for ( int i = 0; i < buttonCount; i++ )
  261. {
  262. buttons[i].update();
  263. if ( buttons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() )
  264. && userInput->isLeftClick() )
  265. {
  266. handleMessage( buttons[i].getID(), buttons[i].getID() );
  267. }
  268. }
  269. */
  270. }
  271. long aStyle4TextListItem::init( FitIniFile* file, const char* blockName )
  272. {
  273. file->seekBlock( blockName );
  274. long fontResID = 0;
  275. file->readIdLong( "Font", fontResID );
  276. long textID = 0;
  277. file->readIdLong( "TextID", textID );
  278. aTextListItem::init(fontResID);
  279. setText(textID);
  280. long color = 0xff808080;
  281. file->readIdLong( "Color", color );
  282. normalColor = color;
  283. setColor(color);
  284. char tmpStr[64];
  285. strcpy(tmpStr, "");
  286. file->readIdString( "Animation", tmpStr, 63 );
  287. if (0 == strcmp("", tmpStr))
  288. {
  289. hasAnimation = false;
  290. }
  291. else
  292. {
  293. hasAnimation = true;
  294. animGroup.init(file, tmpStr);
  295. }
  296. return 0;
  297. }
  298. void aStyle4TextListItem::render()
  299. {
  300. float color;
  301. if (aListItem::SELECTED == getState())
  302. {
  303. color = 0.33 * ((unsigned long)normalColor) + 0.67 * ((unsigned long)0xffffffff);
  304. }
  305. else if (aListItem::HIGHLITE == getState())
  306. {
  307. color = 0.67 * ((unsigned long)normalColor) + 0.33 * ((unsigned long)0xffffffff);
  308. }
  309. else
  310. {
  311. color = normalColor;
  312. }
  313. aTextListItem::setColor((unsigned long)color);
  314. aTextListItem::render();
  315. }
  316. //////////////////////////////////////////////
  317. //*************************************************************************************************
  318. // end of file ( MPAddAIPlayer.cpp )