MPDirectTcpip.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #define MPDIRECTTCPIP_CPP
  2. /*************************************************************************************************\
  3. MPDirectTcpip.cpp : Implementation of the MPDirectTcpip component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "MPDirectTcpip.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 int connectionType = 0;
  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. MPDirectTcpip::MPDirectTcpip()
  22. {
  23. bDone = 0;
  24. status = RUNNING;
  25. }
  26. MPDirectTcpip::~MPDirectTcpip()
  27. {
  28. }
  29. int MPDirectTcpip::indexOfButtonWithID(int id)
  30. {
  31. int i;
  32. for (i = 0; i < buttonCount; i++)
  33. {
  34. buttons[i].setMessageOnRelease();
  35. if (buttons[i].getID() == id)
  36. {
  37. return i;
  38. }
  39. }
  40. return -1;
  41. }
  42. void MPDirectTcpip::init(FitIniFile* file)
  43. {
  44. LogisticsScreen::init( *file, "Static", "Text", "Rect", "Button" );
  45. if ( buttonCount )
  46. {
  47. for ( int i = 0; i < buttonCount; i++ )
  48. {
  49. if (buttons[i].getID() == 0)
  50. {
  51. buttons[i].setID(FIRST_BUTTON_ID + i);
  52. }
  53. }
  54. }
  55. {
  56. char path[256];
  57. strcpy( path, artPath );
  58. strcat( path, "mcl_mp_tcpip_combobox0.fit" );
  59. FitIniFile PNfile;
  60. if ( NO_ERR != PNfile.open( path ) )
  61. {
  62. char error[256];
  63. sprintf( error, "couldn't open file %s", path );
  64. Assert( 0, 0, error );
  65. return;
  66. }
  67. ipAddressComboBox.init(&PNfile, "TCIPNumberComboBox");
  68. aStyle7TextListItem *pTmp2;
  69. int i;
  70. for (i = 0; i < 15; i += 1)
  71. {
  72. pTmp2 = new aStyle7TextListItem;
  73. EString tmpStr;
  74. tmpStr.Format("Text0");
  75. pTmp2->init(&PNfile, tmpStr.Data());
  76. ipAddressComboBox.AddItem(pTmp2);
  77. }
  78. ipAddressComboBox.SelectItem(0);
  79. }
  80. }
  81. void MPDirectTcpip::begin()
  82. {
  83. status = RUNNING;
  84. }
  85. void MPDirectTcpip::end()
  86. {
  87. }
  88. void MPDirectTcpip::render(int xOffset, int yOffset )
  89. {
  90. if ((0 == xOffset) && (0 == yOffset))
  91. {
  92. ipAddressComboBox.render();
  93. }
  94. LogisticsScreen::render(xOffset, yOffset);
  95. }
  96. void MPDirectTcpip::render()
  97. {
  98. render(0, 0);
  99. }
  100. int MPDirectTcpip::handleMessage( unsigned long message, unsigned long who)
  101. {
  102. if ( RUNNING == status )
  103. {
  104. switch ( who )
  105. {
  106. case 57/*MB_MSG_MAINMENU*/:
  107. {
  108. getButton( 57/*MB_MSG_MAINMENU*/ )->press( 0 );
  109. status = MAINMENU;
  110. }
  111. break;
  112. case 51/*MB_MSG_PREV*/:
  113. {
  114. getButton( 51/*MB_MSG_PREV*/ )->press( 0 );
  115. status = PREVIOUS;
  116. }
  117. break;
  118. case 50/*MB_MSG_NEXT*/:
  119. {
  120. getButton( 50/*MB_MSG_NEXT*/ )->press( 0 );
  121. //status = NEXT;
  122. }
  123. break;
  124. case FIRST_BUTTON_ID+1:
  125. {
  126. //join game
  127. getButton( FIRST_BUTTON_ID+1 )->press( 0 );
  128. status = NEXT;
  129. return 1;
  130. }
  131. break;
  132. case FIRST_BUTTON_ID+2:
  133. {
  134. //host game
  135. getButton( FIRST_BUTTON_ID+2 )->press( 0 );
  136. status = SKIPONENEXT;
  137. return 1;
  138. }
  139. break;
  140. }
  141. }
  142. return 0;
  143. }
  144. bool MPDirectTcpip::isDone()
  145. {
  146. return bDone;
  147. }
  148. void MPDirectTcpip::update()
  149. {
  150. LogisticsScreen::update();
  151. ipAddressComboBox.update();
  152. helpTextID = 0;
  153. helpTextHeaderID = 0;
  154. /*
  155. for ( int i = 0; i < buttonCount; i++ )
  156. {
  157. buttons[i].update();
  158. if ( buttons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() )
  159. && userInput->isLeftClick() )
  160. {
  161. handleMessage( buttons[i].getID(), buttons[i].getID() );
  162. }
  163. }
  164. */
  165. }
  166. long aStyle7TextListItem::init( FitIniFile* file, const char* blockName )
  167. {
  168. file->seekBlock( blockName );
  169. long x = 0;
  170. long y = 0;
  171. file->readIdLong( "XLocation", x );
  172. file->readIdLong( "YLocation", y );
  173. long fontResID = 0;
  174. file->readIdLong( "Font", fontResID );
  175. long textID = 0;
  176. file->readIdLong( "TextID", textID );
  177. aTextListItem::init(fontResID);
  178. setText(textID);
  179. long color = 0xff808080;
  180. file->readIdLong( "Color", color );
  181. normalColor = color;
  182. setColor(color);
  183. char tmpStr[64];
  184. strcpy(tmpStr, "");
  185. file->readIdString( "Animation", tmpStr, 63 );
  186. if (0 == strcmp("", tmpStr))
  187. {
  188. hasAnimation = false;
  189. }
  190. else
  191. {
  192. hasAnimation = true;
  193. animGroup.init(file, tmpStr);
  194. }
  195. moveTo(x, y);
  196. return 0;
  197. }
  198. void aStyle7TextListItem::render()
  199. {
  200. float color;
  201. if (aListItem::SELECTED == getState())
  202. {
  203. color = 0.33 * ((unsigned long)normalColor) + 0.67 * ((unsigned long)0xffffffff);
  204. }
  205. else if (aListItem::HIGHLITE == getState())
  206. {
  207. color = 0.67 * ((unsigned long)normalColor) + 0.33 * ((unsigned long)0xffffffff);
  208. }
  209. else
  210. {
  211. color = normalColor;
  212. }
  213. aTextListItem::setColor((unsigned long)color);
  214. aTextListItem::render();
  215. }
  216. //////////////////////////////////////////////
  217. //*************************************************************************************************
  218. // end of file ( MPDirectTcpip.cpp )