LanLobbyMenu.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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. ///////////////////////////////////////////////////////////////////////////////////////
  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. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  193. // window ids ------------------------------------------------------------------------------
  194. static NameKeyType parentLanLobbyID = NAMEKEY_INVALID;
  195. static NameKeyType buttonBackID = NAMEKEY_INVALID;
  196. static NameKeyType buttonClearID = NAMEKEY_INVALID;
  197. static NameKeyType buttonHostID = NAMEKEY_INVALID;
  198. static NameKeyType buttonJoinID = NAMEKEY_INVALID;
  199. static NameKeyType buttonDirectConnectID = NAMEKEY_INVALID;
  200. static NameKeyType buttonEmoteID = NAMEKEY_INVALID;
  201. static NameKeyType staticToolTipID = NAMEKEY_INVALID;
  202. static NameKeyType textEntryPlayerNameID = NAMEKEY_INVALID;
  203. static NameKeyType textEntryChatID = NAMEKEY_INVALID;
  204. static NameKeyType listboxPlayersID = NAMEKEY_INVALID;
  205. static NameKeyType staticTextGameInfoID = NAMEKEY_INVALID;
  206. // Window Pointers ------------------------------------------------------------------------
  207. static GameWindow *parentLanLobby = NULL;
  208. static GameWindow *buttonBack = NULL;
  209. static GameWindow *buttonClear = NULL;
  210. static GameWindow *buttonHost = NULL;
  211. static GameWindow *buttonJoin = NULL;
  212. static GameWindow *buttonDirectConnect = NULL;
  213. static GameWindow *buttonEmote = NULL;
  214. static GameWindow *staticToolTip = NULL;
  215. static GameWindow *textEntryPlayerName = NULL;
  216. static GameWindow *textEntryChat = NULL;
  217. static GameWindow *staticTextGameInfo = NULL;
  218. //external declarations of the Gadgets the callbacks can use
  219. NameKeyType listboxChatWindowID = NAMEKEY_INVALID;
  220. GameWindow *listboxChatWindow = NULL;
  221. GameWindow *listboxPlayers = NULL;
  222. NameKeyType listboxGamesID = NAMEKEY_INVALID;
  223. GameWindow *listboxGames = NULL;
  224. // hack to disable framerate limiter in LAN games
  225. //static Bool shellmapOn;
  226. static Bool useFpsLimit;
  227. static UnicodeString defaultName;
  228. static void playerTooltip(GameWindow *window,
  229. WinInstanceData *instData,
  230. UnsignedInt mouse)
  231. {
  232. Int x, y, row, col;
  233. x = LOLONGTOSHORT(mouse);
  234. y = HILONGTOSHORT(mouse);
  235. GadgetListBoxGetEntryBasedOnXY(window, x, y, row, col);
  236. if (row == -1 || col == -1)
  237. {
  238. //TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:LobbyPlayers") );
  239. return;
  240. }
  241. UnsignedInt playerIP = (UnsignedInt)GadgetListBoxGetItemData( window, row, col );
  242. LANPlayer *player = TheLAN->LookupPlayer(playerIP);
  243. if (!player)
  244. {
  245. DEBUG_CRASH(("No player info in listbox!"));
  246. //TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:LobbyPlayers") );
  247. return;
  248. }
  249. UnicodeString tooltip;
  250. tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getName().str(), player->getLogin().str(), player->getHost().str());
  251. TheMouse->setCursorTooltip( tooltip );
  252. }
  253. //-------------------------------------------------------------------------------------------------
  254. /** Initialize the Lan Lobby Menu */
  255. //-------------------------------------------------------------------------------------------------
  256. void LanLobbyMenuInit( WindowLayout *layout, void *userData )
  257. {
  258. LANnextScreen = NULL;
  259. LANbuttonPushed = false;
  260. LANisShuttingDown = false;
  261. // get the ids for our controls
  262. parentLanLobbyID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:LanLobbyMenuParent" ) );
  263. buttonBackID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonBack" ) );
  264. buttonClearID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonClear" ) );
  265. buttonHostID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonHost" ) );
  266. buttonJoinID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonJoin" ) );
  267. buttonDirectConnectID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonDirectConnect" ) );
  268. buttonEmoteID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ButtonEmote" ) );
  269. staticToolTipID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:StaticToolTip" ) );
  270. textEntryPlayerNameID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:TextEntryPlayerName" ) );
  271. textEntryChatID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:TextEntryChat" ) );
  272. listboxPlayersID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ListboxPlayers" ) );
  273. listboxChatWindowID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ListboxChatWindowLanLobby" ) );
  274. listboxGamesID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:ListboxGames" ) );
  275. staticTextGameInfoID = TheNameKeyGenerator->nameToKey( AsciiString( "LanLobbyMenu.wnd:StaticTextGameInfo" ) );
  276. // Get pointers to the window buttons
  277. parentLanLobby = TheWindowManager->winGetWindowFromId( NULL, parentLanLobbyID );
  278. buttonBack = TheWindowManager->winGetWindowFromId( NULL, buttonBackID);
  279. buttonClear = TheWindowManager->winGetWindowFromId( NULL, buttonClearID);
  280. buttonHost = TheWindowManager->winGetWindowFromId( NULL, buttonHostID );
  281. buttonJoin = TheWindowManager->winGetWindowFromId( NULL, buttonJoinID );
  282. buttonDirectConnect = TheWindowManager->winGetWindowFromId( NULL, buttonDirectConnectID );
  283. buttonEmote = TheWindowManager->winGetWindowFromId( NULL,buttonEmoteID );
  284. staticToolTip = TheWindowManager->winGetWindowFromId( NULL, staticToolTipID );
  285. textEntryPlayerName = TheWindowManager->winGetWindowFromId( NULL, textEntryPlayerNameID );
  286. textEntryChat = TheWindowManager->winGetWindowFromId( NULL, textEntryChatID );
  287. listboxPlayers = TheWindowManager->winGetWindowFromId( NULL, listboxPlayersID );
  288. listboxChatWindow = TheWindowManager->winGetWindowFromId( NULL, listboxChatWindowID );
  289. listboxGames = TheWindowManager->winGetWindowFromId( NULL, listboxGamesID );
  290. staticTextGameInfo = TheWindowManager->winGetWindowFromId( NULL, staticTextGameInfoID );
  291. listboxPlayers->winSetTooltipFunc(playerTooltip);
  292. // Show Menu
  293. layout->hide( FALSE );
  294. // Init LAN API Singleton
  295. if (!TheLAN)
  296. {
  297. TheLAN = NEW LANAPI(); /// @todo clh delete TheLAN and
  298. useFpsLimit = TheGlobalData->m_useFpsLimit;
  299. }
  300. else
  301. {
  302. TheWritableGlobalData->m_useFpsLimit = useFpsLimit;
  303. TheLAN->reset();
  304. }
  305. // Choose an IP address, then initialize the LAN singleton
  306. UnsignedInt IP = TheGlobalData->m_defaultIP;
  307. IPEnumeration IPs;
  308. if (!IP)
  309. {
  310. EnumeratedIP *IPlist = IPs.getAddresses();
  311. /*
  312. while (IPlist && IPlist->getNext())
  313. {
  314. IPlist = IPlist->getNext();
  315. }
  316. */
  317. DEBUG_ASSERTCRASH(IPlist, ("No IP addresses found!"));
  318. if (!IPlist)
  319. {
  320. /// @todo: display error and exit lan lobby if no IPs are found
  321. }
  322. //UnicodeString str;
  323. //str.format(L"Local IP chosen: %hs", IPlist->getIPstring().str());
  324. //GadgetListBoxAddEntryText(listboxChatWindow, str, chatSystemColor, -1, 0);
  325. IP = IPlist->getIP();
  326. }
  327. else
  328. {
  329. /*
  330. UnicodeString str;
  331. str.format(L"Default local IP: %d.%d.%d.%d",
  332. (IP >> 24),
  333. (IP >> 16) & 0xFF,
  334. (IP >> 8) & 0xFF,
  335. IP & 0xFF);
  336. GadgetListBoxAddEntryText(listboxChatWindow, str, chatSystemColor, -1, 0);
  337. */
  338. }
  339. // TheLAN->init() sets us to be in a LAN menu screen automatically.
  340. TheLAN->init();
  341. if (TheLAN->SetLocalIP(IP) == FALSE) {
  342. LANSocketErrorDetected = TRUE;
  343. }
  344. //Initialize the gadgets on the window
  345. //UnicodeString txtInput;
  346. //txtInput.translate(IPs.getMachineName());
  347. LANPreferences prefs;
  348. defaultName = prefs.getUserName();
  349. while (defaultName.getLength() > g_lanPlayerNameLength)
  350. defaultName.removeLastChar();
  351. GadgetTextEntrySetText( textEntryPlayerName, defaultName);
  352. // Clear the text entry line
  353. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  354. GadgetListBoxReset(listboxPlayers);
  355. GadgetListBoxReset(listboxGames);
  356. while (defaultName.getLength() > g_lanPlayerNameLength)
  357. defaultName.removeLastChar();
  358. TheLAN->RequestSetName(defaultName);
  359. TheLAN->RequestLocations();
  360. /*
  361. UnicodeString unicodeChat;
  362. unicodeChat = L"Local IP list:";
  363. GadgetListBoxAddEntryText(listboxChatWindow, unicodeChat, chatSystemColor, -1, 0);
  364. IPlist = IPs.getAddresses();
  365. while (IPlist)
  366. {
  367. unicodeChat.translate(IPlist->getIPstring());
  368. GadgetListBoxAddEntryText(listboxChatWindow, unicodeChat, chatSystemColor, -1, 0);
  369. IPlist = IPlist->getNext();
  370. }
  371. */
  372. // Set Keyboard to Main Parent
  373. //TheWindowManager->winSetFocus( parentLanLobby );
  374. TheWindowManager->winSetFocus( textEntryChat );
  375. CreateLANGameInfoWindow(staticTextGameInfo);
  376. //TheShell->showShellMap(FALSE);
  377. //shellmapOn = FALSE;
  378. // coming out of a game, re-load the shell map
  379. TheShell->showShellMap(TRUE);
  380. // check for MOTD
  381. TheLAN->checkMOTD();
  382. layout->hide(FALSE);
  383. layout->bringForward();
  384. justEntered = TRUE;
  385. initialGadgetDelay = 2;
  386. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("LanLobbyMenu.wnd:GadgetParent"));
  387. if(win)
  388. win->winHide(TRUE);
  389. // animate controls
  390. //TheShell->registerWithAnimateManager(parentLanLobby, WIN_ANIMATION_SLIDE_TOP, TRUE);
  391. // TheShell->registerWithAnimateManager(buttonHost, WIN_ANIMATION_SLIDE_LEFT, TRUE, 600);
  392. // TheShell->registerWithAnimateManager(buttonJoin, WIN_ANIMATION_SLIDE_LEFT, TRUE, 400);
  393. // TheShell->registerWithAnimateManager(buttonDirectConnect, WIN_ANIMATION_SLIDE_LEFT, TRUE, 200);
  394. // //TheShell->registerWithAnimateManager(buttonOptions, WIN_ANIMATION_SLIDE_LEFT, TRUE, 1);
  395. // TheShell->registerWithAnimateManager(buttonBack, WIN_ANIMATION_SLIDE_RIGHT, TRUE, 1);
  396. } // GameLobbyMenuInit
  397. //-------------------------------------------------------------------------------------------------
  398. /** This is called when a shutdown is complete for this menu */
  399. //-------------------------------------------------------------------------------------------------
  400. static void shutdownComplete( WindowLayout *layout )
  401. {
  402. LANisShuttingDown = false;
  403. // hide the layout
  404. layout->hide( TRUE );
  405. // our shutdown is complete
  406. TheShell->shutdownComplete( layout, (LANnextScreen != NULL) );
  407. if (LANnextScreen != NULL)
  408. {
  409. TheShell->push(LANnextScreen);
  410. }
  411. LANnextScreen = NULL;
  412. } // end if
  413. //-------------------------------------------------------------------------------------------------
  414. /** Lan Lobby menu shutdown method */
  415. //-------------------------------------------------------------------------------------------------
  416. void LanLobbyMenuShutdown( WindowLayout *layout, void *userData )
  417. {
  418. LANPreferences prefs;
  419. prefs["UserName"] = UnicodeStringToQuotedPrintable(GadgetTextEntryGetText( textEntryPlayerName ));
  420. prefs.write();
  421. DestroyGameInfoWindow();
  422. // hide menu
  423. //layout->hide( TRUE );
  424. TheLAN->RequestLobbyLeave( true );
  425. // Reset the LAN singleton
  426. //TheLAN->reset();
  427. // our shutdown is complete
  428. //TheShell->shutdownComplete( layout );
  429. TheWritableGlobalData->m_useFpsLimit = useFpsLimit;
  430. LANisShuttingDown = true;
  431. // if we are shutting down for an immediate pop, skip the animations
  432. Bool popImmediate = *(Bool *)userData;
  433. LANSocketErrorDetected = FALSE;
  434. if( popImmediate )
  435. {
  436. shutdownComplete( layout );
  437. return;
  438. } //end if
  439. TheShell->reverseAnimatewindow();
  440. TheTransitionHandler->reverse("LanLobbyFade");
  441. //if( shellmapOn)
  442. // TheShell->showShellMap(TRUE);
  443. } // LanLobbyMenuShutdown
  444. //-------------------------------------------------------------------------------------------------
  445. /** Lan Lobby menu update method */
  446. //-------------------------------------------------------------------------------------------------
  447. void LanLobbyMenuUpdate( WindowLayout * layout, void *userData)
  448. {
  449. if (TheGameLogic->isInShellGame() && TheGameLogic->getFrame() == 1)
  450. {
  451. SignalUIInteraction(SHELL_SCRIPT_HOOK_LAN_ENTERED_FROM_GAME);
  452. }
  453. if(justEntered)
  454. {
  455. if(initialGadgetDelay == 1)
  456. {
  457. TheTransitionHandler->setGroup("LanLobbyFade");
  458. initialGadgetDelay = 2;
  459. justEntered = FALSE;
  460. }
  461. else
  462. initialGadgetDelay--;
  463. }
  464. if(LANisShuttingDown && TheShell->isAnimFinished() && TheTransitionHandler->isFinished())
  465. shutdownComplete(layout);
  466. if (TheShell->isAnimFinished() && !LANbuttonPushed && TheLAN)
  467. TheLAN->update();
  468. if (LANSocketErrorDetected == TRUE) {
  469. LANSocketErrorDetected = FALSE;
  470. DEBUG_LOG(("SOCKET ERROR! BAILING!\n"));
  471. MessageBoxOk(TheGameText->fetch("GUI:NetworkError"), TheGameText->fetch("GUI:SocketError"), NULL);
  472. // we have a socket problem, back out to the main menu.
  473. TheWindowManager->winSendSystemMsg(buttonBack->winGetParent(), GBM_SELECTED,
  474. (WindowMsgData)buttonBack, buttonBackID);
  475. }
  476. }// LanLobbyMenuUpdate
  477. //-------------------------------------------------------------------------------------------------
  478. /** Lan Lobby menu input callback */
  479. //-------------------------------------------------------------------------------------------------
  480. WindowMsgHandledType LanLobbyMenuInput( GameWindow *window, UnsignedInt msg,
  481. WindowMsgData mData1, WindowMsgData mData2 )
  482. {
  483. switch( msg )
  484. {
  485. // --------------------------------------------------------------------------------------------
  486. case GWM_CHAR:
  487. {
  488. UnsignedByte key = mData1;
  489. UnsignedByte state = mData2;
  490. if (LANbuttonPushed)
  491. break;
  492. switch( key )
  493. {
  494. // ----------------------------------------------------------------------------------------
  495. case KEY_ESC:
  496. {
  497. //
  498. // send a simulated selected event to the parent window of the
  499. // back/exit button
  500. //
  501. if( BitTest( state, KEY_STATE_UP ) )
  502. {
  503. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  504. (WindowMsgData)buttonBack, buttonBackID );
  505. } // end if
  506. // don't let key fall through anywhere else
  507. return MSG_HANDLED;
  508. } // end escape
  509. } // end switch( key )
  510. } // end char
  511. } // end switch( msg )
  512. return MSG_IGNORED;
  513. }// LanLobbyMenuInput
  514. //-------------------------------------------------------------------------------------------------
  515. /** Lan Lobby menu window system callback */
  516. //-------------------------------------------------------------------------------------------------
  517. WindowMsgHandledType LanLobbyMenuSystem( GameWindow *window, UnsignedInt msg,
  518. WindowMsgData mData1, WindowMsgData mData2 )
  519. {
  520. UnicodeString txtInput;
  521. switch( msg )
  522. {
  523. case GWM_CREATE:
  524. {
  525. SignalUIInteraction(SHELL_SCRIPT_HOOK_LAN_OPENED);
  526. break;
  527. } // case GWM_DESTROY:
  528. case GWM_DESTROY:
  529. {
  530. SignalUIInteraction(SHELL_SCRIPT_HOOK_LAN_CLOSED);
  531. break;
  532. } // case GWM_DESTROY:
  533. case GWM_INPUT_FOCUS:
  534. {
  535. // if we're givin the opportunity to take the keyboard focus we must say we want it
  536. if( mData1 == TRUE )
  537. *(Bool *)mData2 = TRUE;
  538. return MSG_HANDLED;
  539. }//case GWM_INPUT_FOCUS:
  540. case GLM_DOUBLE_CLICKED:
  541. {
  542. if (LANbuttonPushed)
  543. break;
  544. GameWindow *control = (GameWindow *)mData1;
  545. Int controlID = control->winGetWindowId();
  546. if( controlID == listboxGamesID )
  547. {
  548. int rowSelected = mData2;
  549. if (rowSelected >= 0)
  550. {
  551. LANGameInfo * theGame = TheLAN->LookupGameByListOffset(rowSelected);
  552. if (theGame)
  553. {
  554. TheLAN->RequestGameJoin(theGame);
  555. }
  556. }
  557. }
  558. break;
  559. }
  560. case GLM_SELECTED:
  561. {
  562. if (LANbuttonPushed)
  563. break;
  564. GameWindow *control = (GameWindow *)mData1;
  565. Int controlID = control->winGetWindowId();
  566. if( controlID == listboxGamesID )
  567. {
  568. int rowSelected = mData2;
  569. if( rowSelected < 0 )
  570. {
  571. HideGameInfoWindow(TRUE);
  572. break;
  573. }
  574. LANGameInfo * theGame = TheLAN->LookupGameByListOffset(rowSelected);
  575. if (theGame)
  576. RefreshGameInfoWindow(theGame, theGame->getName());
  577. else
  578. HideGameInfoWindow(TRUE);
  579. }
  580. break;
  581. }
  582. case GBM_SELECTED:
  583. {
  584. if (LANbuttonPushed)
  585. break;
  586. GameWindow *control = (GameWindow *)mData1;
  587. Int controlID = control->winGetWindowId();
  588. if ( controlID == buttonBackID )
  589. {
  590. //shellmapOn = TRUE;
  591. LANbuttonPushed = true;
  592. DEBUG_LOG(("Back was hit - popping to main menu\n"));
  593. TheShell->pop();
  594. delete TheLAN;
  595. TheLAN = NULL;
  596. //TheTransitionHandler->reverse("LanLobbyFade");
  597. } //if ( controlID == buttonBack )
  598. else if ( controlID == buttonHostID )
  599. {
  600. TheLAN->RequestGameCreate( UnicodeString(L""), FALSE);
  601. }//else if ( controlID == buttonHostID )
  602. else if ( controlID == buttonClearID )
  603. {
  604. GadgetTextEntrySetText(textEntryPlayerName, UnicodeString::TheEmptyString);
  605. TheWindowManager->winSendSystemMsg( window,
  606. GEM_UPDATE_TEXT,
  607. (WindowMsgData)textEntryPlayerName,
  608. 0 );
  609. }
  610. else if ( controlID == buttonJoinID )
  611. {
  612. //TheShell->push( AsciiString("Menus/LanGameOptionsMenu.wnd") );
  613. int rowSelected = -1;
  614. GadgetListBoxGetSelected( listboxGames, &rowSelected );
  615. if (rowSelected >= 0)
  616. {
  617. LANGameInfo * theGame = TheLAN->LookupGameByListOffset(rowSelected);
  618. if (theGame)
  619. {
  620. TheLAN->RequestGameJoin(theGame);
  621. }
  622. }
  623. else
  624. {
  625. GadgetListBoxAddEntryText(listboxChatWindow, TheGameText->fetch("LAN:ErrorNoGameSelected") , chatSystemColor, -1, 0);
  626. }
  627. } //else if ( controlID == buttonJoinID )
  628. else if ( controlID == buttonEmoteID )
  629. {
  630. // read the user's input
  631. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  632. // Clear the text entry line
  633. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  634. // Clean up the text (remove leading/trailing chars, etc)
  635. txtInput.trim();
  636. // Echo the user's input to the chat window
  637. if (!txtInput.isEmpty()) {
  638. // TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_EMOTE);
  639. TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL);
  640. }
  641. } //if ( controlID == buttonEmote )
  642. else if (controlID == buttonDirectConnectID)
  643. {
  644. TheLAN->RequestLobbyLeave( false );
  645. TheShell->push(AsciiString("Menus/NetworkDirectConnect.wnd"));
  646. }
  647. break;
  648. }// case GBM_SELECTED:
  649. case GEM_UPDATE_TEXT:
  650. {
  651. if (LANbuttonPushed)
  652. break;
  653. GameWindow *control = (GameWindow *)mData1;
  654. Int controlID = control->winGetWindowId();
  655. if ( controlID == textEntryPlayerNameID )
  656. {
  657. // grab the user's name
  658. txtInput.set(GadgetTextEntryGetText( textEntryPlayerName ));
  659. // Clean up the text (remove leading/trailing chars, etc)
  660. const WideChar *c = txtInput.str();
  661. while (c && (iswspace(*c)))
  662. c++;
  663. if (c)
  664. txtInput = UnicodeString(c);
  665. else
  666. txtInput = UnicodeString::TheEmptyString;
  667. while (txtInput.getLength() > g_lanPlayerNameLength)
  668. txtInput.removeLastChar();
  669. if (!txtInput.isEmpty() && txtInput.getCharAt(txtInput.getLength()-1) == L',')
  670. txtInput.removeLastChar(); // we use , for strtok's so we can't allow them in names. :(
  671. if (!txtInput.isEmpty() && txtInput.getCharAt(txtInput.getLength()-1) == L':')
  672. txtInput.removeLastChar(); // we use : for strtok's so we can't allow them in names. :(
  673. if (!txtInput.isEmpty() && txtInput.getCharAt(txtInput.getLength()-1) == L';')
  674. txtInput.removeLastChar(); // we use ; for strtok's so we can't allow them in names. :(
  675. // send it over the network
  676. if (!txtInput.isEmpty())
  677. TheLAN->RequestSetName(txtInput);
  678. else
  679. {
  680. TheLAN->RequestSetName(defaultName);
  681. }
  682. // Put the whitespace-free version in the box
  683. GadgetTextEntrySetText( textEntryPlayerName, txtInput );
  684. }// if ( controlID == textEntryPlayerNameID )
  685. break;
  686. }//case GEM_UPDATE_TEXT:
  687. case GEM_EDIT_DONE:
  688. {
  689. if (LANbuttonPushed)
  690. break;
  691. GameWindow *control = (GameWindow *)mData1;
  692. Int controlID = control->winGetWindowId();
  693. // Take the user's input and echo it into the chat window as well as
  694. // send it to the other clients on the lan
  695. if ( controlID == textEntryChatID )
  696. {
  697. // read the user's input
  698. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  699. // Clear the text entry line
  700. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  701. // Clean up the text (remove leading/trailing chars, etc)
  702. while (!txtInput.isEmpty() && iswspace(txtInput.getCharAt(0)))
  703. txtInput = UnicodeString(txtInput.str()+1);
  704. // Echo the user's input to the chat window
  705. if (!txtInput.isEmpty())
  706. TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL);
  707. }// if ( controlID == textEntryChatID )
  708. /*
  709. else if ( controlID == textEntryPlayerNameID )
  710. {
  711. // grab the user's name
  712. txtInput.set(GadgetTextEntryGetText( textEntryPlayerName ));
  713. // Clean up the text (remove leading/trailing chars, etc)
  714. txtInput.trim();
  715. // send it over the network
  716. if (!txtInput.isEmpty())
  717. TheLAN->RequestSetName(txtInput);
  718. // Put the whitespace-free version in the box
  719. GadgetTextEntrySetText( textEntryPlayerName, txtInput );
  720. }// if ( controlID == textEntryPlayerNameID )
  721. */
  722. break;
  723. }
  724. default:
  725. return MSG_IGNORED;
  726. }//Switch
  727. return MSG_HANDLED;
  728. }// LanLobbyMenuSystem