LanLobbyMenu.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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. ///////////////////////////////////////////////////////////////////////////////////////
  24. // FILE: LanLobbyMenu.cpp
  25. // Author: Chris Huybregts, October 2001
  26. // Description: Lan Lobby Menu
  27. ///////////////////////////////////////////////////////////////////////////////////////
  28. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  30. #include "Lib/BaseType.h"
  31. #include "Common/CRC.h"
  32. #include "Common/GameEngine.h"
  33. #include "Common/GlobalData.h"
  34. #include "Common/MultiplayerSettings.h"
  35. #include "Common/NameKeyGenerator.h"
  36. #include "Common/Player.h"
  37. #include "Common/PlayerTemplate.h"
  38. #include "Common/QuotedPrintable.h"
  39. #include "Common/UserPreferences.h"
  40. #include "GameClient/AnimateWindowManager.h"
  41. #include "GameClient/GameText.h"
  42. #include "GameClient/MapUtil.h"
  43. #include "GameClient/Mouse.h"
  44. #include "GameClient/WindowLayout.h"
  45. #include "GameClient/Gadget.h"
  46. #include "GameClient/Shell.h"
  47. #include "GameClient/ShellHooks.h"
  48. #include "GameClient/KeyDefs.h"
  49. #include "GameClient/GameInfoWindow.h"
  50. #include "GameClient/GameWindowManager.h"
  51. #include "GameClient/GadgetListBox.h"
  52. #include "GameClient/GadgetTextEntry.h"
  53. #include "GameClient/MessageBox.h"
  54. #include "GameClient/GameWindowTransitions.h"
  55. #include "GameLogic/GameLogic.h"
  56. #include "GameNetwork/IPEnumeration.h"
  57. #include "GameNetwork/LANAPICallbacks.h"
  58. #include "GameNetwork/LANGameInfo.h"
  59. Bool LANisShuttingDown = false;
  60. Bool LANbuttonPushed = false;
  61. Bool LANSocketErrorDetected = FALSE;
  62. char *LANnextScreen = NULL;
  63. static Int initialGadgetDelay = 2;
  64. static Bool justEntered = FALSE;
  65. LANPreferences::LANPreferences( void )
  66. {
  67. // note, the superclass will put this in the right dir automatically, this is just a leaf name
  68. load("Network.ini");
  69. }
  70. LANPreferences::~LANPreferences()
  71. {
  72. }
  73. UnicodeString LANPreferences::getUserName(void)
  74. {
  75. UnicodeString ret;
  76. LANPreferences::const_iterator it = find("UserName");
  77. if (it == end())
  78. {
  79. IPEnumeration IPs;
  80. ret.translate(IPs.getMachineName());
  81. return ret;
  82. }
  83. ret = QuotedPrintableToUnicodeString(it->second);
  84. ret.trim();
  85. if (ret.isEmpty())
  86. {
  87. IPEnumeration IPs;
  88. ret.translate(IPs.getMachineName());
  89. return ret;
  90. }
  91. return ret;
  92. }
  93. Int LANPreferences::getPreferredColor(void)
  94. {
  95. Int ret;
  96. LANPreferences::const_iterator it = find("Color");
  97. if (it == end())
  98. {
  99. return -1;
  100. }
  101. ret = atoi(it->second.str());
  102. if (ret < -1 || ret >= TheMultiplayerSettings->getNumColors())
  103. ret = -1;
  104. return ret;
  105. }
  106. Int LANPreferences::getPreferredFaction(void)
  107. {
  108. Int ret;
  109. LANPreferences::const_iterator it = find("PlayerTemplate");
  110. if (it == end())
  111. {
  112. return PLAYERTEMPLATE_RANDOM;
  113. }
  114. ret = atoi(it->second.str());
  115. if (ret == PLAYERTEMPLATE_OBSERVER || ret < PLAYERTEMPLATE_MIN || ret >= ThePlayerTemplateStore->getPlayerTemplateCount())
  116. ret = PLAYERTEMPLATE_RANDOM;
  117. if (ret >= 0)
  118. {
  119. const PlayerTemplate *fac = ThePlayerTemplateStore->getNthPlayerTemplate(ret);
  120. if (!fac)
  121. ret = PLAYERTEMPLATE_RANDOM;
  122. else if (fac->getStartingBuilding().isEmpty())
  123. ret = PLAYERTEMPLATE_RANDOM;
  124. }
  125. return ret;
  126. }
  127. Bool LANPreferences::usesSystemMapDir(void)
  128. {
  129. OptionPreferences::const_iterator it = find("UseSystemMapDir");
  130. if (it == end())
  131. return TRUE;
  132. if (stricmp(it->second.str(), "yes") == 0) {
  133. return TRUE;
  134. }
  135. return FALSE;
  136. }
  137. AsciiString LANPreferences::getPreferredMap(void)
  138. {
  139. AsciiString ret;
  140. LANPreferences::const_iterator it = find("Map");
  141. if (it == end())
  142. {
  143. ret = getDefaultMap(TRUE);
  144. return ret;
  145. }
  146. ret = QuotedPrintableToAsciiString(it->second);
  147. ret.trim();
  148. if (ret.isEmpty() || !isValidMap(ret, TRUE))
  149. {
  150. ret = getDefaultMap(TRUE);
  151. return ret;
  152. }
  153. return ret;
  154. }
  155. Int LANPreferences::getNumRemoteIPs(void)
  156. {
  157. Int ret;
  158. LANPreferences::const_iterator it = find("NumRemoteIPs");
  159. if (it == end())
  160. {
  161. ret = 0;
  162. return ret;
  163. }
  164. ret = atoi(it->second.str());
  165. return ret;
  166. }
  167. UnicodeString LANPreferences::getRemoteIPEntry(Int i)
  168. {
  169. UnicodeString ret;
  170. AsciiString key;
  171. key.format("RemoteIP%d", i);
  172. AsciiString ipstr;
  173. AsciiString asciientry;
  174. LANPreferences::const_iterator it = find(key.str());
  175. if (it == end())
  176. {
  177. asciientry = "";
  178. return ret;
  179. }
  180. asciientry = it->second;
  181. asciientry.nextToken(&ipstr, ":");
  182. asciientry.set(asciientry.str() + 1); // skip the ':'
  183. ret.translate(ipstr);
  184. if (asciientry.getLength() > 0)
  185. {
  186. ret.concat(L"(");
  187. ret.concat(QuotedPrintableToUnicodeString(asciientry));
  188. ret.concat(L")");
  189. }
  190. return ret;
  191. }
  192. static const char superweaponRestrictionKey[] = "SuperweaponRestrict";
  193. Bool LANPreferences::getSuperweaponRestricted(void) const
  194. {
  195. LANPreferences::const_iterator it = find(superweaponRestrictionKey);
  196. if (it == end())
  197. {
  198. return false;
  199. }
  200. return ( it->second.compareNoCase( "yes" ) == 0 );
  201. }
  202. void LANPreferences::setSuperweaponRestricted( Bool superweaponRestricted )
  203. {
  204. (*this)[superweaponRestrictionKey] = superweaponRestricted ? "Yes" : "No";
  205. }
  206. static const char startingCashKey[] = "StartingCash";
  207. Money LANPreferences::getStartingCash(void) const
  208. {
  209. LANPreferences::const_iterator it = find(startingCashKey);
  210. if (it == end())
  211. {
  212. return TheMultiplayerSettings->getDefaultStartingMoney();
  213. }
  214. Money money;
  215. money.deposit( strtoul( it->second.str(), NULL, 10 ), FALSE );
  216. return money;
  217. }
  218. void LANPreferences::setStartingCash( const Money & startingCash )
  219. {
  220. AsciiString option;
  221. option.format( "%d", startingCash.countMoney() );
  222. (*this)[startingCashKey] = option;
  223. }
  224. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  225. // window ids ------------------------------------------------------------------------------
  226. static NameKeyType parentLanLobbyID = NAMEKEY_INVALID;
  227. static NameKeyType buttonBackID = NAMEKEY_INVALID;
  228. static NameKeyType buttonClearID = NAMEKEY_INVALID;
  229. static NameKeyType buttonHostID = NAMEKEY_INVALID;
  230. static NameKeyType buttonJoinID = NAMEKEY_INVALID;
  231. static NameKeyType buttonDirectConnectID = NAMEKEY_INVALID;
  232. static NameKeyType buttonEmoteID = NAMEKEY_INVALID;
  233. static NameKeyType staticToolTipID = NAMEKEY_INVALID;
  234. static NameKeyType textEntryPlayerNameID = NAMEKEY_INVALID;
  235. static NameKeyType textEntryChatID = NAMEKEY_INVALID;
  236. static NameKeyType listboxPlayersID = NAMEKEY_INVALID;
  237. static NameKeyType staticTextGameInfoID = NAMEKEY_INVALID;
  238. // Window Pointers ------------------------------------------------------------------------
  239. static GameWindow *parentLanLobby = NULL;
  240. static GameWindow *buttonBack = NULL;
  241. static GameWindow *buttonClear = NULL;
  242. static GameWindow *buttonHost = NULL;
  243. static GameWindow *buttonJoin = NULL;
  244. static GameWindow *buttonDirectConnect = NULL;
  245. static GameWindow *buttonEmote = NULL;
  246. static GameWindow *staticToolTip = NULL;
  247. static GameWindow *textEntryPlayerName = NULL;
  248. static GameWindow *textEntryChat = NULL;
  249. static GameWindow *staticTextGameInfo = NULL;
  250. //external declarations of the Gadgets the callbacks can use
  251. NameKeyType listboxChatWindowID = NAMEKEY_INVALID;
  252. GameWindow *listboxChatWindow = NULL;
  253. GameWindow *listboxPlayers = NULL;
  254. NameKeyType listboxGamesID = NAMEKEY_INVALID;
  255. GameWindow *listboxGames = NULL;
  256. // hack to disable framerate limiter in LAN games
  257. //static Bool shellmapOn;
  258. static Bool useFpsLimit;
  259. static UnicodeString defaultName;
  260. static void playerTooltip(GameWindow *window,
  261. WinInstanceData *instData,
  262. UnsignedInt mouse)
  263. {
  264. Int x, y, row, col;
  265. x = LOLONGTOSHORT(mouse);
  266. y = HILONGTOSHORT(mouse);
  267. GadgetListBoxGetEntryBasedOnXY(window, x, y, row, col);
  268. if (row == -1 || col == -1)
  269. {
  270. //TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:LobbyPlayers") );
  271. return;
  272. }
  273. UnsignedInt playerIP = (UnsignedInt)GadgetListBoxGetItemData( window, row, col );
  274. LANPlayer *player = TheLAN->LookupPlayer(playerIP);
  275. if (!player)
  276. {
  277. DEBUG_CRASH(("No player info in listbox!"));
  278. //TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:LobbyPlayers") );
  279. return;
  280. }
  281. UnicodeString tooltip;
  282. tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getName().str(), player->getLogin().str(), player->getHost().str());
  283. TheMouse->setCursorTooltip( tooltip );
  284. }
  285. //-------------------------------------------------------------------------------------------------
  286. /** Initialize the Lan Lobby Menu */
  287. //-------------------------------------------------------------------------------------------------
  288. void LanLobbyMenuInit( WindowLayout *layout, void *userData )
  289. {
  290. LANnextScreen = NULL;
  291. LANbuttonPushed = false;
  292. LANisShuttingDown = false;
  293. // get the ids for our controls
  294. parentLanLobbyID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:LanLobbyMenuParent" ) );
  295. buttonBackID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonBack" ) );
  296. buttonClearID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonClear" ) );
  297. buttonHostID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonHost" ) );
  298. buttonJoinID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonJoin" ) );
  299. buttonDirectConnectID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonDirectConnect" ) );
  300. buttonEmoteID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonEmote" ) );
  301. staticToolTipID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:StaticToolTip" ) );
  302. textEntryPlayerNameID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:TextEntryPlayerName" ) );
  303. textEntryChatID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:TextEntryChat" ) );
  304. listboxPlayersID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ListboxPlayers" ) );
  305. listboxChatWindowID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ListboxChatWindowLanLobby" ) );
  306. listboxGamesID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ListboxGames" ) );
  307. staticTextGameInfoID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:StaticTextGameInfo" ) );
  308. // Get pointers to the window buttons
  309. parentLanLobby = TheWindowManager->winGetWindowFromId( NULL, parentLanLobbyID );
  310. buttonBack = TheWindowManager->winGetWindowFromId( NULL, buttonBackID);
  311. buttonClear = TheWindowManager->winGetWindowFromId( NULL, buttonClearID);
  312. buttonHost = TheWindowManager->winGetWindowFromId( NULL, buttonHostID );
  313. buttonJoin = TheWindowManager->winGetWindowFromId( NULL, buttonJoinID );
  314. buttonDirectConnect = TheWindowManager->winGetWindowFromId( NULL, buttonDirectConnectID );
  315. buttonEmote = TheWindowManager->winGetWindowFromId( NULL,buttonEmoteID );
  316. staticToolTip = TheWindowManager->winGetWindowFromId( NULL, staticToolTipID );
  317. textEntryPlayerName = TheWindowManager->winGetWindowFromId( NULL, textEntryPlayerNameID );
  318. textEntryChat = TheWindowManager->winGetWindowFromId( NULL, textEntryChatID );
  319. listboxPlayers = TheWindowManager->winGetWindowFromId( NULL, listboxPlayersID );
  320. listboxChatWindow = TheWindowManager->winGetWindowFromId( NULL, listboxChatWindowID );
  321. listboxGames = TheWindowManager->winGetWindowFromId( NULL, listboxGamesID );
  322. staticTextGameInfo = TheWindowManager->winGetWindowFromId( NULL, staticTextGameInfoID );
  323. listboxPlayers->winSetTooltipFunc(playerTooltip);
  324. // Show Menu
  325. layout->hide( FALSE );
  326. // Init LAN API Singleton
  327. if (!TheLAN)
  328. {
  329. TheLAN = NEW LANAPI(); /// @todo clh delete TheLAN and
  330. useFpsLimit = TheGlobalData->m_useFpsLimit;
  331. }
  332. else
  333. {
  334. TheWritableGlobalData->m_useFpsLimit = useFpsLimit;
  335. TheLAN->reset();
  336. }
  337. // Choose an IP address, then initialize the LAN singleton
  338. UnsignedInt IP = TheGlobalData->m_defaultIP;
  339. IPEnumeration IPs;
  340. if (!IP)
  341. {
  342. EnumeratedIP *IPlist = IPs.getAddresses();
  343. /*
  344. while (IPlist && IPlist->getNext())
  345. {
  346. IPlist = IPlist->getNext();
  347. }
  348. */
  349. DEBUG_ASSERTCRASH(IPlist, ("No IP addresses found!"));
  350. if (!IPlist)
  351. {
  352. /// @todo: display error and exit lan lobby if no IPs are found
  353. }
  354. //UnicodeString str;
  355. //str.format(L"Local IP chosen: %hs", IPlist->getIPstring().str());
  356. //GadgetListBoxAddEntryText(listboxChatWindow, str, chatSystemColor, -1, 0);
  357. IP = IPlist->getIP();
  358. }
  359. else
  360. {
  361. /*
  362. UnicodeString str;
  363. str.format(L"Default local IP: %d.%d.%d.%d",
  364. (IP >> 24),
  365. (IP >> 16) & 0xFF,
  366. (IP >> 8) & 0xFF,
  367. IP & 0xFF);
  368. GadgetListBoxAddEntryText(listboxChatWindow, str, chatSystemColor, -1, 0);
  369. */
  370. }
  371. // TheLAN->init() sets us to be in a LAN menu screen automatically.
  372. TheLAN->init();
  373. if (TheLAN->SetLocalIP(IP) == FALSE) {
  374. LANSocketErrorDetected = TRUE;
  375. }
  376. //Initialize the gadgets on the window
  377. //UnicodeString txtInput;
  378. //txtInput.translate(IPs.getMachineName());
  379. LANPreferences prefs;
  380. defaultName = prefs.getUserName();
  381. while (defaultName.getLength() > g_lanPlayerNameLength)
  382. defaultName.removeLastChar();
  383. GadgetTextEntrySetText( textEntryPlayerName, defaultName);
  384. // Clear the text entry line
  385. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  386. GadgetListBoxReset(listboxPlayers);
  387. GadgetListBoxReset(listboxGames);
  388. while (defaultName.getLength() > g_lanPlayerNameLength)
  389. defaultName.removeLastChar();
  390. TheLAN->RequestSetName(defaultName);
  391. TheLAN->RequestLocations();
  392. /*
  393. UnicodeString unicodeChat;
  394. unicodeChat = L"Local IP list:";
  395. GadgetListBoxAddEntryText(listboxChatWindow, unicodeChat, chatSystemColor, -1, 0);
  396. IPlist = IPs.getAddresses();
  397. while (IPlist)
  398. {
  399. unicodeChat.translate(IPlist->getIPstring());
  400. GadgetListBoxAddEntryText(listboxChatWindow, unicodeChat, chatSystemColor, -1, 0);
  401. IPlist = IPlist->getNext();
  402. }
  403. */
  404. // Set Keyboard to Main Parent
  405. //TheWindowManager->winSetFocus( parentLanLobby );
  406. TheWindowManager->winSetFocus( textEntryChat );
  407. CreateLANGameInfoWindow(staticTextGameInfo);
  408. //TheShell->showShellMap(FALSE);
  409. //shellmapOn = FALSE;
  410. // coming out of a game, re-load the shell map
  411. TheShell->showShellMap(TRUE);
  412. // check for MOTD
  413. TheLAN->checkMOTD();
  414. layout->hide(FALSE);
  415. layout->bringForward();
  416. justEntered = TRUE;
  417. initialGadgetDelay = 2;
  418. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("LanLobbyMenu.wnd:GadgetParent"));
  419. if(win)
  420. win->winHide(TRUE);
  421. // animate controls
  422. //TheShell->registerWithAnimateManager(parentLanLobby, WIN_ANIMATION_SLIDE_TOP, TRUE);
  423. // TheShell->registerWithAnimateManager(buttonHost, WIN_ANIMATION_SLIDE_LEFT, TRUE, 600);
  424. // TheShell->registerWithAnimateManager(buttonJoin, WIN_ANIMATION_SLIDE_LEFT, TRUE, 400);
  425. // TheShell->registerWithAnimateManager(buttonDirectConnect, WIN_ANIMATION_SLIDE_LEFT, TRUE, 200);
  426. // //TheShell->registerWithAnimateManager(buttonOptions, WIN_ANIMATION_SLIDE_LEFT, TRUE, 1);
  427. // TheShell->registerWithAnimateManager(buttonBack, WIN_ANIMATION_SLIDE_RIGHT, TRUE, 1);
  428. } // GameLobbyMenuInit
  429. //-------------------------------------------------------------------------------------------------
  430. /** This is called when a shutdown is complete for this menu */
  431. //-------------------------------------------------------------------------------------------------
  432. static void shutdownComplete( WindowLayout *layout )
  433. {
  434. LANisShuttingDown = false;
  435. // hide the layout
  436. layout->hide( TRUE );
  437. // our shutdown is complete
  438. TheShell->shutdownComplete( layout, (LANnextScreen != NULL) );
  439. if (LANnextScreen != NULL)
  440. {
  441. TheShell->push(LANnextScreen);
  442. }
  443. LANnextScreen = NULL;
  444. } // end if
  445. //-------------------------------------------------------------------------------------------------
  446. /** Lan Lobby menu shutdown method */
  447. //-------------------------------------------------------------------------------------------------
  448. void LanLobbyMenuShutdown( WindowLayout *layout, void *userData )
  449. {
  450. LANPreferences prefs;
  451. prefs["UserName"] = UnicodeStringToQuotedPrintable(GadgetTextEntryGetText( textEntryPlayerName ));
  452. prefs.write();
  453. DestroyGameInfoWindow();
  454. // hide menu
  455. //layout->hide( TRUE );
  456. TheLAN->RequestLobbyLeave( true );
  457. // Reset the LAN singleton
  458. //TheLAN->reset();
  459. // our shutdown is complete
  460. //TheShell->shutdownComplete( layout );
  461. TheWritableGlobalData->m_useFpsLimit = useFpsLimit;
  462. LANisShuttingDown = true;
  463. // if we are shutting down for an immediate pop, skip the animations
  464. Bool popImmediate = *(Bool *)userData;
  465. LANSocketErrorDetected = FALSE;
  466. if( popImmediate )
  467. {
  468. shutdownComplete( layout );
  469. return;
  470. } //end if
  471. TheShell->reverseAnimatewindow();
  472. TheTransitionHandler->reverse("LanLobbyFade");
  473. //if( shellmapOn)
  474. // TheShell->showShellMap(TRUE);
  475. } // LanLobbyMenuShutdown
  476. //-------------------------------------------------------------------------------------------------
  477. /** Lan Lobby menu update method */
  478. //-------------------------------------------------------------------------------------------------
  479. void LanLobbyMenuUpdate( WindowLayout * layout, void *userData)
  480. {
  481. if (TheGameLogic->isInShellGame() && TheGameLogic->getFrame() == 1)
  482. {
  483. SignalUIInteraction(SHELL_SCRIPT_HOOK_LAN_ENTERED_FROM_GAME);
  484. }
  485. if(justEntered)
  486. {
  487. if(initialGadgetDelay == 1)
  488. {
  489. TheTransitionHandler->setGroup("LanLobbyFade");
  490. initialGadgetDelay = 2;
  491. justEntered = FALSE;
  492. }
  493. else
  494. initialGadgetDelay--;
  495. }
  496. if(LANisShuttingDown && TheShell->isAnimFinished() && TheTransitionHandler->isFinished())
  497. shutdownComplete(layout);
  498. if (TheShell->isAnimFinished() && !LANbuttonPushed && TheLAN)
  499. TheLAN->update();
  500. if (LANSocketErrorDetected == TRUE) {
  501. LANSocketErrorDetected = FALSE;
  502. DEBUG_LOG(("SOCKET ERROR! BAILING!\n"));
  503. MessageBoxOk(TheGameText->fetch("GUI:NetworkError"), TheGameText->fetch("GUI:SocketError"), NULL);
  504. // we have a socket problem, back out to the main menu.
  505. TheWindowManager->winSendSystemMsg(buttonBack->winGetParent(), GBM_SELECTED,
  506. (WindowMsgData)buttonBack, buttonBackID);
  507. }
  508. }// LanLobbyMenuUpdate
  509. //-------------------------------------------------------------------------------------------------
  510. /** Lan Lobby menu input callback */
  511. //-------------------------------------------------------------------------------------------------
  512. WindowMsgHandledType LanLobbyMenuInput( GameWindow *window, UnsignedInt msg,
  513. WindowMsgData mData1, WindowMsgData mData2 )
  514. {
  515. switch( msg )
  516. {
  517. // --------------------------------------------------------------------------------------------
  518. case GWM_CHAR:
  519. {
  520. UnsignedByte key = mData1;
  521. UnsignedByte state = mData2;
  522. if (LANbuttonPushed)
  523. break;
  524. switch( key )
  525. {
  526. // ----------------------------------------------------------------------------------------
  527. case KEY_ESC:
  528. {
  529. //
  530. // send a simulated selected event to the parent window of the
  531. // back/exit button
  532. //
  533. if( BitTest( state, KEY_STATE_UP ) )
  534. {
  535. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  536. (WindowMsgData)buttonBack, buttonBackID );
  537. } // end if
  538. // don't let key fall through anywhere else
  539. return MSG_HANDLED;
  540. } // end escape
  541. } // end switch( key )
  542. } // end char
  543. } // end switch( msg )
  544. return MSG_IGNORED;
  545. }// LanLobbyMenuInput
  546. //-------------------------------------------------------------------------------------------------
  547. /** Lan Lobby menu window system callback */
  548. //-------------------------------------------------------------------------------------------------
  549. WindowMsgHandledType LanLobbyMenuSystem( GameWindow *window, UnsignedInt msg,
  550. WindowMsgData mData1, WindowMsgData mData2 )
  551. {
  552. UnicodeString txtInput;
  553. switch( msg )
  554. {
  555. case GWM_CREATE:
  556. {
  557. SignalUIInteraction(SHELL_SCRIPT_HOOK_LAN_OPENED);
  558. break;
  559. } // case GWM_DESTROY:
  560. case GWM_DESTROY:
  561. {
  562. SignalUIInteraction(SHELL_SCRIPT_HOOK_LAN_CLOSED);
  563. break;
  564. } // case GWM_DESTROY:
  565. case GWM_INPUT_FOCUS:
  566. {
  567. // if we're givin the opportunity to take the keyboard focus we must say we want it
  568. if( mData1 == TRUE )
  569. *(Bool *)mData2 = TRUE;
  570. return MSG_HANDLED;
  571. }//case GWM_INPUT_FOCUS:
  572. case GLM_DOUBLE_CLICKED:
  573. {
  574. if (LANbuttonPushed)
  575. break;
  576. GameWindow *control = (GameWindow *)mData1;
  577. Int controlID = control->winGetWindowId();
  578. if( controlID == listboxGamesID )
  579. {
  580. int rowSelected = mData2;
  581. if (rowSelected >= 0)
  582. {
  583. LANGameInfo * theGame = TheLAN->LookupGameByListOffset(rowSelected);
  584. if (theGame)
  585. {
  586. TheLAN->RequestGameJoin(theGame);
  587. }
  588. }
  589. }
  590. break;
  591. }
  592. case GLM_SELECTED:
  593. {
  594. if (LANbuttonPushed)
  595. break;
  596. GameWindow *control = (GameWindow *)mData1;
  597. Int controlID = control->winGetWindowId();
  598. if( controlID == listboxGamesID )
  599. {
  600. int rowSelected = mData2;
  601. if( rowSelected < 0 )
  602. {
  603. HideGameInfoWindow(TRUE);
  604. break;
  605. }
  606. LANGameInfo * theGame = TheLAN->LookupGameByListOffset(rowSelected);
  607. if (theGame)
  608. RefreshGameInfoWindow(theGame, theGame->getName());
  609. else
  610. HideGameInfoWindow(TRUE);
  611. }
  612. break;
  613. }
  614. case GBM_SELECTED:
  615. {
  616. if (LANbuttonPushed)
  617. break;
  618. GameWindow *control = (GameWindow *)mData1;
  619. Int controlID = control->winGetWindowId();
  620. if ( controlID == buttonBackID )
  621. {
  622. //shellmapOn = TRUE;
  623. LANbuttonPushed = true;
  624. DEBUG_LOG(("Back was hit - popping to main menu\n"));
  625. TheShell->pop();
  626. delete TheLAN;
  627. TheLAN = NULL;
  628. //TheTransitionHandler->reverse("LanLobbyFade");
  629. } //if ( controlID == buttonBack )
  630. else if ( controlID == buttonHostID )
  631. {
  632. TheLAN->RequestGameCreate( UnicodeString(L""), FALSE);
  633. }//else if ( controlID == buttonHostID )
  634. else if ( controlID == buttonClearID )
  635. {
  636. GadgetTextEntrySetText(textEntryPlayerName, UnicodeString::TheEmptyString);
  637. TheWindowManager->winSendSystemMsg( window,
  638. GEM_UPDATE_TEXT,
  639. (WindowMsgData)textEntryPlayerName,
  640. 0 );
  641. }
  642. else if ( controlID == buttonJoinID )
  643. {
  644. //TheShell->push( AsciiString("Menus/LanGameOptionsMenu.wnd") );
  645. int rowSelected = -1;
  646. GadgetListBoxGetSelected( listboxGames, &rowSelected );
  647. if (rowSelected >= 0)
  648. {
  649. LANGameInfo * theGame = TheLAN->LookupGameByListOffset(rowSelected);
  650. if (theGame)
  651. {
  652. TheLAN->RequestGameJoin(theGame);
  653. }
  654. }
  655. else
  656. {
  657. GadgetListBoxAddEntryText(listboxChatWindow, TheGameText->fetch("LAN:ErrorNoGameSelected") , chatSystemColor, -1, 0);
  658. }
  659. } //else if ( controlID == buttonJoinID )
  660. else if ( controlID == buttonEmoteID )
  661. {
  662. // read the user's input
  663. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  664. // Clear the text entry line
  665. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  666. // Clean up the text (remove leading/trailing chars, etc)
  667. txtInput.trim();
  668. // Echo the user's input to the chat window
  669. if (!txtInput.isEmpty()) {
  670. // TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_EMOTE);
  671. TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL);
  672. }
  673. } //if ( controlID == buttonEmote )
  674. else if (controlID == buttonDirectConnectID)
  675. {
  676. TheLAN->RequestLobbyLeave( false );
  677. TheShell->push(AsciiString("Menus/NetworkDirectConnect.wnd"));
  678. }
  679. break;
  680. }// case GBM_SELECTED:
  681. case GEM_UPDATE_TEXT:
  682. {
  683. if (LANbuttonPushed)
  684. break;
  685. GameWindow *control = (GameWindow *)mData1;
  686. Int controlID = control->winGetWindowId();
  687. if ( controlID == textEntryPlayerNameID )
  688. {
  689. // grab the user's name
  690. txtInput.set(GadgetTextEntryGetText( textEntryPlayerName ));
  691. // Clean up the text (remove leading/trailing chars, etc)
  692. const WideChar *c = txtInput.str();
  693. while (c && (iswspace(*c)))
  694. c++;
  695. if (c)
  696. txtInput = UnicodeString(c);
  697. else
  698. txtInput = UnicodeString::TheEmptyString;
  699. while (txtInput.getLength() > g_lanPlayerNameLength)
  700. txtInput.removeLastChar();
  701. if (!txtInput.isEmpty() && txtInput.getCharAt(txtInput.getLength()-1) == L',')
  702. txtInput.removeLastChar(); // we use , for strtok's so we can't allow them in names. :(
  703. if (!txtInput.isEmpty() && txtInput.getCharAt(txtInput.getLength()-1) == L':')
  704. txtInput.removeLastChar(); // we use : for strtok's so we can't allow them in names. :(
  705. if (!txtInput.isEmpty() && txtInput.getCharAt(txtInput.getLength()-1) == L';')
  706. txtInput.removeLastChar(); // we use ; for strtok's so we can't allow them in names. :(
  707. // send it over the network
  708. if (!txtInput.isEmpty())
  709. TheLAN->RequestSetName(txtInput);
  710. else
  711. {
  712. TheLAN->RequestSetName(defaultName);
  713. }
  714. // Put the whitespace-free version in the box
  715. GadgetTextEntrySetText( textEntryPlayerName, txtInput );
  716. }// if ( controlID == textEntryPlayerNameID )
  717. break;
  718. }//case GEM_UPDATE_TEXT:
  719. case GEM_EDIT_DONE:
  720. {
  721. if (LANbuttonPushed)
  722. break;
  723. GameWindow *control = (GameWindow *)mData1;
  724. Int controlID = control->winGetWindowId();
  725. // Take the user's input and echo it into the chat window as well as
  726. // send it to the other clients on the lan
  727. if ( controlID == textEntryChatID )
  728. {
  729. // read the user's input
  730. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  731. // Clear the text entry line
  732. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  733. // Clean up the text (remove leading/trailing chars, etc)
  734. while (!txtInput.isEmpty() && iswspace(txtInput.getCharAt(0)))
  735. txtInput = UnicodeString(txtInput.str()+1);
  736. // Echo the user's input to the chat window
  737. if (!txtInput.isEmpty())
  738. TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL);
  739. }// if ( controlID == textEntryChatID )
  740. /*
  741. else if ( controlID == textEntryPlayerNameID )
  742. {
  743. // grab the user's name
  744. txtInput.set(GadgetTextEntryGetText( textEntryPlayerName ));
  745. // Clean up the text (remove leading/trailing chars, etc)
  746. txtInput.trim();
  747. // send it over the network
  748. if (!txtInput.isEmpty())
  749. TheLAN->RequestSetName(txtInput);
  750. // Put the whitespace-free version in the box
  751. GadgetTextEntrySetText( textEntryPlayerName, txtInput );
  752. }// if ( controlID == textEntryPlayerNameID )
  753. */
  754. break;
  755. }
  756. default:
  757. return MSG_IGNORED;
  758. }//Switch
  759. return MSG_HANDLED;
  760. }// LanLobbyMenuSystem