| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////
- // FILE: LanGameOptionsMenu.cpp
- // Author: Chris Huybregts, October 2001
- // Description: Lan Game Options Menu
- ///////////////////////////////////////////////////////////////////////////////////////
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "Common/PlayerTemplate.h"
- #include "Common/GameEngine.h"
- #include "Common/UserPreferences.h"
- #include "Common/QuotedPrintable.h"
- #include "GameClient/AnimateWindowManager.h"
- #include "GameClient/WindowLayout.h"
- #include "GameClient/Gadget.h"
- #include "GameClient/Shell.h"
- #include "GameClient/KeyDefs.h"
- #include "GameClient/GameWindowManager.h"
- #include "GameClient/GadgetListBox.h"
- #include "GameClient/GadgetComboBox.h"
- #include "GameClient/GadgetTextEntry.h"
- #include "GameClient/GadgetStaticText.h"
- #include "GameClient/GadgetPushButton.h"
- #include "GameClient/GadgetCheckbox.h"
- #include "GameClient/MapUtil.h"
- #include "GameClient/Mouse.h"
- #include "GameClient/GameWindowTransitions.h"
- #include "GameClient/ChallengeGenerals.h"
- #include "GameNetwork/GameSpy/LobbyUtils.h"
- #include "GameNetwork/FirewallHelper.h"
- #include "GameNetwork/LANAPI.h"
- #include "GameNetwork/IPEnumeration.h"
- #include "GameNetwork/LANAPICallbacks.h"
- #include "Common/MultiplayerSettings.h"
- #include "GameClient/GameText.h"
- #include "GameNetwork/GUIUtil.h"
- #ifdef _INTERNAL
- // for occasional debugging...
- //#pragma optimize("", off)
- //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
- #endif
- extern char *LANnextScreen;
- extern Bool LANisShuttingDown;
- extern Bool LANbuttonPushed;
- extern void MapSelectorTooltip(GameWindow *window, WinInstanceData *instData, UnsignedInt mouse);
- extern void gameAcceptTooltip(GameWindow *window, WinInstanceData *instData, UnsignedInt mouse);
- Color white = GameMakeColor( 255, 255, 255, 255 );
- static bool s_isIniting = FALSE;
- // window ids ------------------------------------------------------------------------------
- static NameKeyType parentLanGameOptionsID = NAMEKEY_INVALID;
- static NameKeyType comboBoxPlayerID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID };
- static NameKeyType buttonAcceptID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID };
- static NameKeyType comboBoxColorID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID };
- static NameKeyType comboBoxPlayerTemplateID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID };
- static NameKeyType comboBoxTeamID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID };
- //static NameKeyType buttonStartPositionID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
- // NAMEKEY_INVALID,NAMEKEY_INVALID,
- // NAMEKEY_INVALID,NAMEKEY_INVALID,
- // NAMEKEY_INVALID,NAMEKEY_INVALID };
- static NameKeyType buttonMapStartPositionID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID,
- NAMEKEY_INVALID,NAMEKEY_INVALID };
- static NameKeyType textEntryChatID = NAMEKEY_INVALID;
- static NameKeyType textEntryMapDisplayID = NAMEKEY_INVALID;
- static NameKeyType buttonBackID = NAMEKEY_INVALID;
- static NameKeyType buttonStartID = NAMEKEY_INVALID;
- static NameKeyType buttonEmoteID = NAMEKEY_INVALID;
- static NameKeyType buttonSelectMapID = NAMEKEY_INVALID;
- static NameKeyType checkboxLimitSuperweaponsID = NAMEKEY_INVALID;
- static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID;
- static NameKeyType windowMapID = NAMEKEY_INVALID;
- // Window Pointers ------------------------------------------------------------------------
- static GameWindow *parentLanGameOptions = NULL;
- static GameWindow *buttonBack = NULL;
- static GameWindow *buttonStart = NULL;
- static GameWindow *buttonSelectMap = NULL;
- static GameWindow *buttonEmote = NULL;
- static GameWindow *textEntryChat = NULL;
- static GameWindow *textEntryMapDisplay = NULL;
- static GameWindow *checkboxLimitSuperweapons = NULL;
- static GameWindow *comboBoxStartingCash = NULL;
- static GameWindow *windowMap = NULL;
- static GameWindow *comboBoxPlayer[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL };
- static GameWindow *buttonAccept[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL };
- static GameWindow *comboBoxColor[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL };
- static GameWindow *comboBoxPlayerTemplate[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL };
- static GameWindow *comboBoxTeam[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL };
- //static GameWindow *buttonStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
- // NULL,NULL,NULL,NULL };
- //
- static GameWindow *buttonMapStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
- NULL,NULL,NULL,NULL };
- //external declarations of the Gadgets the callbacks can use
- GameWindow *listboxChatWindowLanGame = NULL;
- NameKeyType listboxChatWindowLanGameID = NAMEKEY_INVALID;
- WindowLayout *mapSelectLayout = NULL;
- static Int getNextSelectablePlayer(Int start)
- {
- LANGameInfo *game = TheLAN->GetMyGame();
- if (!game->amIHost())
- return -1;
- for (Int j=start; j<MAX_SLOTS; ++j)
- {
- LANGameSlot *slot = game->getLANSlot(j);
- if (slot && slot->getStartPos() == -1 &&
- ( (j==game->getLocalSlotNum() && game->getConstSlot(j)->getPlayerTemplate()!=PLAYERTEMPLATE_OBSERVER)
- || slot->isAI()))
- {
- return j;
- }
- }
- return -1;
- }
- static Int getFirstSelectablePlayer(const GameInfo *game)
- {
- const GameSlot *slot = game->getConstSlot(game->getLocalSlotNum());
- if (!game->amIHost() || slot && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER)
- return game->getLocalSlotNum();
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- slot = game->getConstSlot(i);
- if (slot && slot->isAI())
- return i;
- }
- return game->getLocalSlotNum();
- }
- void updateMapStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[], Bool onLoadScreen = FALSE );
- void positionStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[], GameWindow *mapWindow);
- void LanPositionStartSpots( void )
- {
-
- positionStartSpots( TheLAN->GetMyGame(), buttonMapStartPosition, windowMap);
- }
- static void playerTooltip(GameWindow *window,
- WinInstanceData *instData,
- UnsignedInt mouse)
- {
- Int idx = -1;
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- if (window && window == GadgetComboBoxGetEditBox(comboBoxPlayer[i]))
- {
- idx = i;
- break;
- }
- }
- if (idx == -1)
- return;
- LANGameSlot *slot = TheLAN->GetMyGame()->getLANSlot(i);
- if (!slot)
- return;
- LANPlayer *player = slot->getUser();
- if (!player)
- {
- DEBUG_ASSERTCRASH(TheLAN->GetMyGame()->getIP(i) == 0, ("No player info in listbox!"));
- TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );
- return;
- }
- UnicodeString tooltip;
- tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getName().str(), player->getLogin().str(), player->getHost().str());
- TheMouse->setCursorTooltip( tooltip );
- }
- void StartPressed(void)
- {
- LANGameInfo *myGame = TheLAN->GetMyGame();
- Bool isReady = true;
- Bool allHaveMap = true;
- Int playerCount = 0;
- if (!myGame)
- {
- return;
- }
- myGame->getLANSlot(0)->setAccept(); // cause we are, of course!
- int i;
- int numUsers = 0;
- int numHumans = 0;
- for (i=0; i<MAX_SLOTS; ++i)
- {
- GameSlot *slot = myGame->getSlot(i);
- if (slot && slot->isOccupied() && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER)
- {
- if (slot && slot->isHuman())
- numHumans++;
- numUsers++;
- }
- }
- // Check for too many players
- const MapMetaData *md = TheMapCache->findMap( myGame->getMap() );
- if (!md || md->m_numPlayers < numUsers)
- {
- if (TheLAN->AmIHost())
- {
- UnicodeString text;
- text.format(TheGameText->fetch("LAN:TooManyPlayers"), (md)?md->m_numPlayers:0);
- TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
- }
- return;
- }
- // Check for observer + AI players
- if (TheGlobalData->m_netMinPlayers && !numHumans)
- {
- if (TheLAN->AmIHost())
- {
- UnicodeString text = TheGameText->fetch("GUI:NeedHumanPlayers");
- TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
- }
- return;
- }
- // Check for too few players
- if (numUsers < TheGlobalData->m_netMinPlayers)
- {
- if (TheLAN->AmIHost())
- {
- UnicodeString text;
- text.format(TheGameText->fetch("LAN:NeedMorePlayers"),numUsers);
- TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
- }
- return;
- }
- // Check for too few teams
- int numRandom = 0;
- std::set<Int> teams;
- for (i=0; i<MAX_SLOTS; ++i)
- {
- GameSlot *slot = myGame->getSlot(i);
- if (slot && slot->isOccupied() && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER)
- {
- if (slot->getTeamNumber() >= 0)
- {
- teams.insert(slot->getTeamNumber());
- }
- else
- {
- ++numRandom;
- }
- }
- }
- if (numRandom + teams.size() < TheGlobalData->m_netMinPlayers)
- {
- if (TheLAN->AmIHost())
- {
- UnicodeString text;
- text.format(TheGameText->fetch("LAN:NeedMoreTeams"));
- TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
- }
- return;
- }
- if (numRandom + teams.size() < 2)
- {
- UnicodeString text;
- text.format(TheGameText->fetch("GUI:SandboxMode"));
- TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
- }
- // see if everyone's accepted and count the number of players in the game
- UnicodeString mapDisplayName;
- const MapMetaData *mapData = TheMapCache->findMap( myGame->getMap() );
- Bool willTransfer = TRUE;
- if (mapData)
- {
- mapDisplayName.format(L"%ls", mapData->m_displayName.str());
- willTransfer = !mapData->m_isOfficial;
- }
- else
- {
- mapDisplayName.format(L"%hs", myGame->getMap().str());
- willTransfer = WouldMapTransfer(myGame->getMap());
- }
- for( i = 0; i < MAX_SLOTS; i++ )
- {
- LANGameSlot *slot = myGame->getLANSlot(i);
- if( slot->isHuman() && !slot->isAccepted())
- {
- isReady = false;
- if (!willTransfer)
- {
- if (!slot->hasMap())
- {
- UnicodeString msg;
- msg.format(TheGameText->fetch("GUI:PlayerNoMap"), slot->getName().str(), mapDisplayName.str());
- GadgetListBoxAddEntryText(listboxChatWindowLanGame, msg , chatSystemColor, -1, 0);
- allHaveMap = false;
- }
- }
- }
- if( slot->isHuman() && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER )
- playerCount++;
- }
- if(isReady)
- {
- for( i = 0; i < MAX_SLOTS; i++ )
- {
- LANGameSlot *slot = myGame->getLANSlot(i);
- if (slot && slot->isOpen())
- {
- slot->setState( SLOT_CLOSED );
- GadgetComboBoxSetSelectedPos(comboBoxPlayer[i], SLOT_CLOSED);
- }
- }
- Int seconds = TheMultiplayerSettings->getStartCountdownTimerSeconds();
- if (seconds)
- TheLAN->RequestGameStartTimer(seconds);
- else
- TheLAN->RequestGameStart();
- LANEnableStartButton(false);
- }
- else
- {
- // Does everyone have the map?
- if (allHaveMap)
- {
- GadgetListBoxAddEntryText(listboxChatWindowLanGame, TheGameText->fetch("GUI:NotifiedStartIntent") , chatSystemColor, -1, 0);
- TheLAN->RequestAccept();
- }
- }
- }//void StartPressed(void)
- void LANEnableStartButton(Bool enabled)
- {
- buttonStart->winEnable(enabled);
- buttonSelectMap->winEnable(enabled);
- }
- static void handleColorSelection(int index)
- {
- GameWindow *combo = comboBoxColor[index];
- Int color, selIndex;
- GadgetComboBoxGetSelectedPos(combo, &selIndex);
- color = (Int)GadgetComboBoxGetItemData(combo, selIndex);
- LANGameInfo *myGame = TheLAN->GetMyGame();
- if (myGame)
- {
- LANGameSlot * slot = myGame->getLANSlot(index);
- if (color == slot->getColor())
- return;
- if (color >= -1 && color < TheMultiplayerSettings->getNumColors())
- {
- Bool colorAvailable = TRUE;
- if(color != -1 )
- {
- for(Int i=0; i <MAX_SLOTS; i++)
- {
- LANGameSlot *checkSlot = myGame->getLANSlot(i);
- if(color == checkSlot->getColor() && slot != checkSlot)
- {
- colorAvailable = FALSE;
- break;
- }
- }
- }
- if(!colorAvailable)
- return;
- }
- slot->setColor(color);
- if (myGame->amIHost())
- {
- if (!s_isIniting)
- {
- // send around a new slotlist
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- lanUpdateSlotList();
- }
- }
- else
- {
- // request the color from the host
- if (!slot->isLocalPlayer() || !AreSlotListUpdatesEnabled())
- return;
- AsciiString options;
- options.format("Color=%d", color);
- TheLAN->RequestGameOptions(options, true);
- }
- }
- }
- static void handlePlayerTemplateSelection(int index)
- {
- GameWindow *combo = comboBoxPlayerTemplate[index];
- Int playerTemplate, selIndex;
- GadgetComboBoxGetSelectedPos(combo, &selIndex);
- playerTemplate = (Int)GadgetComboBoxGetItemData(combo, selIndex);
- LANGameInfo *myGame = TheLAN->GetMyGame();
- if (myGame)
- {
- LANGameSlot * slot = myGame->getLANSlot(index);
- if (playerTemplate == slot->getPlayerTemplate())
- return;
- Int oldTemplate = slot->getPlayerTemplate();
- slot->setPlayerTemplate(playerTemplate);
- if (oldTemplate == PLAYERTEMPLATE_OBSERVER)
- {
- // was observer, so populate color & team with all, and enable
- GadgetComboBoxSetSelectedPos(comboBoxColor[index], 0);
- GadgetComboBoxSetSelectedPos(comboBoxTeam[index], 0);
- slot->setStartPos(-1);
- }
- else if (playerTemplate == PLAYERTEMPLATE_OBSERVER)
- {
- // is becoming observer, so populate color & team with random only, and disable
- GadgetComboBoxSetSelectedPos(comboBoxColor[index], 0);
- GadgetComboBoxSetSelectedPos(comboBoxTeam[index], 0);
- slot->setStartPos(-1);
- }
- myGame->resetAccepted();
- if (myGame->amIHost())
- {
- if (!s_isIniting)
- {
- // send around a new slotlist
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- lanUpdateSlotList();
- }
- }
- else
- {
- // request the playerTemplate from the host
- if (AreSlotListUpdatesEnabled())
- {
- AsciiString options;
- options.format("PlayerTemplate=%d", playerTemplate);
- TheLAN->RequestGameOptions(options, true);
- }
- }
- }
- }
- static void handleStartPositionSelection(Int player, int startPos)
- {
- LANGameInfo *myGame = TheLAN->GetMyGame();
-
- if (myGame)
- {
- LANGameSlot * slot = myGame->getLANSlot(player);
- if (startPos == slot->getStartPos())
- return;
- Bool skip = FALSE;
- if (startPos < 0)
- {
- skip = TRUE;
- }
- if(!skip)
- {
- Bool isAvailable = TRUE;
- for(Int i = 0; i < MAX_SLOTS; ++i)
- {
- if(i != player && myGame->getSlot(i)->getStartPos() == startPos)
- {
- isAvailable = FALSE;
- break;
- }
- }
- if( !isAvailable )
- return;
- }
- slot->setStartPos(startPos);
- if (myGame->amIHost())
- {
- if (!s_isIniting)
- {
- // send around a new slotlist
- myGame->resetAccepted();
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- lanUpdateSlotList();
- }
- }
- else
- {
- // request the color from the host
- if (AreSlotListUpdatesEnabled())
- {
- AsciiString options;
- options.format("StartPos=%d", slot->getStartPos());
- TheLAN->RequestGameOptions(options, true);
- }
- }
- }
- }
- static void handleTeamSelection(int index)
- {
- GameWindow *combo = comboBoxTeam[index];
- Int team, selIndex;
- GadgetComboBoxGetSelectedPos(combo, &selIndex);
- team = (Int)GadgetComboBoxGetItemData(combo, selIndex);
- LANGameInfo *myGame = TheLAN->GetMyGame();
- if (myGame)
- {
- LANGameSlot * slot = myGame->getLANSlot(index);
- if (team == slot->getTeamNumber())
- return;
- slot->setTeamNumber(team);
- myGame->resetAccepted();
- if (myGame->amIHost())
- {
- if (!s_isIniting)
- {
- // send around a new slotlist
- myGame->resetAccepted();
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- lanUpdateSlotList();
- }
- }
- else
- {
- // request the team from the host
- if (AreSlotListUpdatesEnabled())
- {
- AsciiString options;
- options.format("Team=%d", team);
- TheLAN->RequestGameOptions(options, true);
- }
- }
- }
- }
- static void handleStartingCashSelection()
- {
- LANGameInfo *myGame = TheLAN->GetMyGame();
-
- if (myGame)
- {
- Int selIndex;
- GadgetComboBoxGetSelectedPos(comboBoxStartingCash, &selIndex);
- Money startingCash;
- startingCash.deposit( (UnsignedInt)GadgetComboBoxGetItemData( comboBoxStartingCash, selIndex ), FALSE );
- myGame->setStartingCash( startingCash );
- myGame->resetAccepted();
- if (myGame->amIHost())
- {
- if (!s_isIniting)
- {
- // send around the new data
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- lanUpdateSlotList(); // Update the accepted button UI
- }
- }
- }
- }
- static void handleLimitSuperweaponsClick()
- {
- LANGameInfo *myGame = TheLAN->GetMyGame();
-
- if (myGame)
- {
- // At the moment, 1 and 0 are the only choices supported in the GUI, though the system could
- // support more.
- if ( GadgetCheckBoxIsChecked( checkboxLimitSuperweapons ) )
- {
- myGame->setSuperweaponRestriction( 1 );
- }
- else
- {
- myGame->setSuperweaponRestriction( 0 );
- }
- myGame->resetAccepted();
-
- if (myGame->amIHost())
- {
- if (!s_isIniting)
- {
- // send around a new slotlist
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- lanUpdateSlotList(); // Update the accepted button UI
- }
- }
- }
- }
- void lanUpdateSlotList( void )
- {
- if(!AreSlotListUpdatesEnabled() || s_isIniting)
- return;
- UpdateSlotList( TheLAN->GetMyGame(), comboBoxPlayer, comboBoxColor,
- comboBoxPlayerTemplate, comboBoxTeam, buttonAccept, buttonStart, buttonMapStartPosition);
-
- updateMapStartSpots(TheLAN->GetMyGame(), buttonMapStartPosition);
- }
- //-------------------------------------------------------------------------------------------------
- /** Initialize the Gadgets Options Menu */
- //-------------------------------------------------------------------------------------------------
- void InitLanGameGadgets( void )
- {
- //Initialize the gadget IDs
- parentLanGameOptionsID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:LanGameOptionsMenuParent" ) );
- buttonBackID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonBack" ) );
- buttonStartID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonStart" ) );
- textEntryChatID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:TextEntryChat" ) );
- textEntryMapDisplayID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:TextEntryMapDisplay" ) );
- listboxChatWindowLanGameID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ListboxChatWindowLanGame" ) );
- buttonEmoteID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonEmote" ) );
- buttonSelectMapID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonSelectMap" ) );
- checkboxLimitSuperweaponsID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:CheckboxLimitSuperweapons" ) );
- comboBoxStartingCashID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ComboBoxStartingCash" ) );
- windowMapID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:MapWindow" ) );
- // Initialize the pointers to our gadgets
- parentLanGameOptions = TheWindowManager->winGetWindowFromId( NULL, parentLanGameOptionsID );
- DEBUG_ASSERTCRASH(parentLanGameOptions, ("Could not find the parentLanGameOptions"));
- buttonEmote = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonEmoteID );
- DEBUG_ASSERTCRASH(buttonEmote, ("Could not find the buttonEmote"));
- buttonSelectMap = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonSelectMapID );
- DEBUG_ASSERTCRASH(buttonSelectMap, ("Could not find the buttonSelectMap"));
- buttonStart = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonStartID );
- DEBUG_ASSERTCRASH(buttonStart, ("Could not find the buttonStart"));
- buttonBack = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonBackID);
- DEBUG_ASSERTCRASH(buttonBack, ("Could not find the buttonBack"));
- listboxChatWindowLanGame = TheWindowManager->winGetWindowFromId( parentLanGameOptions, listboxChatWindowLanGameID );
- DEBUG_ASSERTCRASH(listboxChatWindowLanGame, ("Could not find the listboxChatWindowLanGame"));
- textEntryChat = TheWindowManager->winGetWindowFromId( parentLanGameOptions, textEntryChatID );
- DEBUG_ASSERTCRASH(textEntryChat, ("Could not find the textEntryChat"));
- textEntryMapDisplay = TheWindowManager->winGetWindowFromId( parentLanGameOptions, textEntryMapDisplayID );
- DEBUG_ASSERTCRASH(textEntryMapDisplay, ("Could not find the textEntryMapDisplay"));
- checkboxLimitSuperweapons = TheWindowManager->winGetWindowFromId( parentLanGameOptions, checkboxLimitSuperweaponsID );
- DEBUG_ASSERTCRASH(checkboxLimitSuperweapons, ("Could not find the checkboxLimitSuperweapons"));
- comboBoxStartingCash = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxStartingCashID );
- DEBUG_ASSERTCRASH(comboBoxStartingCash, ("Could not find the comboBoxStartingCash"));
- PopulateStartingCashComboBox(comboBoxStartingCash, TheLAN->GetMyGame());
- windowMap = TheWindowManager->winGetWindowFromId( parentLanGameOptions,windowMapID );
- DEBUG_ASSERTCRASH(windowMap, ("Could not find the LanGameOptionsMenu.wnd:MapWindow" ));
- Int localSlotNum = TheLAN->GetMyGame()->getLocalSlotNum();
- DEBUG_ASSERTCRASH(localSlotNum >= 0, ("Bad slot number!"));
- //Added By Sadullah Nader
- //Tooltip function is being set for techBuildings, and supplyDocks
- windowMap->winSetTooltipFunc(MapSelectorTooltip);
- //End Add
- for (Int i = 0; i < MAX_SLOTS; i++)
- {
- AsciiString tmpString;
- tmpString.format("LanGameOptionsMenu.wnd:ComboBoxPlayer%d", i);
- comboBoxPlayerID[i] = TheNameKeyGenerator->nameToKey( tmpString );
- comboBoxPlayer[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxPlayerID[i] );
- GadgetComboBoxReset(comboBoxPlayer[i]);
- GadgetComboBoxGetEditBox(comboBoxPlayer[i])->winSetTooltipFunc(playerTooltip);
- if(localSlotNum == i)
- {
- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheLAN->GetMyName(),white);
- }
- else
- {
- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Open"),white);
- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Closed"),white);
- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:EasyAI"),white);
- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),white);
- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HardAI"),white);
- GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);
- }
- /*
- if(i != 0)
- {
- TheLAN->GetMyGame()->getLANSlot(i)->setState(SLOT_OPEN);
- }
- */
- tmpString.format("LanGameOptionsMenu.wnd:ComboBoxColor%d", i);
- comboBoxColorID[i] = TheNameKeyGenerator->nameToKey( tmpString );
- comboBoxColor[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxColorID[i] );
- DEBUG_ASSERTCRASH(comboBoxColor[i], ("Could not find the comboBoxColor[%d]",i ));
- PopulateColorComboBox(i, comboBoxColor, TheLAN->GetMyGame());
- GadgetComboBoxSetSelectedPos(comboBoxColor[i], 0);
-
- tmpString.format("LanGameOptionsMenu.wnd:ComboBoxPlayerTemplate%d", i);
- comboBoxPlayerTemplateID[i] = TheNameKeyGenerator->nameToKey( tmpString );
- comboBoxPlayerTemplate[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxPlayerTemplateID[i] );
- DEBUG_ASSERTCRASH(comboBoxPlayerTemplate[i], ("Could not find the comboBoxPlayerTemplate[%d]",i ));
- PopulatePlayerTemplateComboBox(i, comboBoxPlayerTemplate, TheLAN->GetMyGame(), TRUE);
- // add tooltips to the player template combobox and listbox
- comboBoxPlayerTemplate[i]->winSetTooltipFunc(playerTemplateComboBoxTooltip);
- GadgetComboBoxGetListBox(comboBoxPlayerTemplate[i])->winSetTooltipFunc(playerTemplateListBoxTooltip);
- tmpString.format("LanGameOptionsMenu.wnd:ComboBoxTeam%d", i);
- comboBoxTeamID[i] = TheNameKeyGenerator->nameToKey( tmpString );
- comboBoxTeam[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxTeamID[i] );
- DEBUG_ASSERTCRASH(comboBoxTeam[i], ("Could not find the comboBoxTeam[%d]",i ));
- PopulateTeamComboBox(i, comboBoxTeam, TheLAN->GetMyGame());
- tmpString.clear();
- tmpString.format("LanGameOptionsMenu.wnd:ButtonAccept%d", i);
- buttonAcceptID[i] = TheNameKeyGenerator->nameToKey( tmpString );
- buttonAccept[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonAcceptID[i] );
- DEBUG_ASSERTCRASH(buttonAccept[i], ("Could not find the buttonAccept[%d]",i ));
- //Added by Saad for the tooltips on the MultiPlayer icons
- buttonAccept[i]->winSetTooltipFunc(gameAcceptTooltip);
- //
- // tmpString.format("LanGameOptionsMenu.wnd:ButtonStartPosition%d", i);
- // buttonStartPositionID[i] = TheNameKeyGenerator->nameToKey( tmpString );
- // buttonStartPosition[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonStartPositionID[i] );
- // DEBUG_ASSERTCRASH(buttonStartPosition[i], ("Could not find the ButtonStartPosition[%d]",i ));
- tmpString.format("LanGameOptionsMenu.wnd:ButtonMapStartPosition%d", i);
- buttonMapStartPositionID[i] = TheNameKeyGenerator->nameToKey( tmpString );
- buttonMapStartPosition[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonMapStartPositionID[i] );
- DEBUG_ASSERTCRASH(buttonMapStartPosition[i], ("Could not find the ButtonMapStartPosition[%d]",i ));
- if(i !=0 && buttonAccept[i])
- buttonAccept[i]->winHide(TRUE);
- }
- if( buttonAccept[0] )
- GadgetButtonSetEnabledColor(buttonAccept[0], acceptTrueColor );
-
- }
- void DeinitLanGameGadgets( void )
- {
- parentLanGameOptions = NULL;
- buttonEmote = NULL;
- buttonSelectMap = NULL;
- buttonStart = NULL;
- buttonBack = NULL;
- listboxChatWindowLanGame = NULL;
- textEntryChat = NULL;
- textEntryMapDisplay = NULL;
- checkboxLimitSuperweapons = NULL;
- comboBoxStartingCash = NULL;
- windowMap = NULL;
- for (Int i = 0; i < MAX_SLOTS; i++)
- {
- comboBoxPlayer[i] = NULL;
- comboBoxColor[i] = NULL;
- comboBoxPlayerTemplate[i] = NULL;
- comboBoxTeam[i] = NULL;
- buttonAccept[i] = NULL;
- // buttonStartPosition[i] = NULL;
- buttonMapStartPosition[i] = NULL;
- }
- }
- //-------------------------------------------------------------------------------------------------
- /** Initialize the Lan Game Options Menu */
- //-------------------------------------------------------------------------------------------------
- void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )
- {
- if (TheLAN->GetMyGame() && TheLAN->GetMyGame()->isGameInProgress())
- {
- // If we init while the game is in progress, we are really returning to the menu
- // after the game. So, we pop the menu and go back to the lobby. Whee!
- DEBUG_LOG(("Popping to lobby after a game!\n"));
- TheShell->popImmediate();
- return;
- }
- s_isIniting = TRUE;
- LANbuttonPushed = false;
- LANisShuttingDown = false;
- //initialize the gadgets
- EnableSlotListUpdates(FALSE);
- InitLanGameGadgets();
- EnableSlotListUpdates(TRUE);
- Int start = 0;
- // Make sure the text fields are clear
- GadgetListBoxReset( listboxChatWindowLanGame );
- GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
- //The dialog needs to react differently depending on whether it's the host or not.
- TheMapCache->updateCache();
- if (TheLAN->AmIHost())
- {
- // read in some prefs
- LANGameInfo *game = TheLAN->GetMyGame();
- LANGameSlot *slot = game->getLANSlot(0);
- LANPreferences pref;
- slot->setColor( pref.getPreferredColor() );
- slot->setPlayerTemplate( pref.getPreferredFaction() );
- slot->setNATBehavior(FirewallHelperClass::FIREWALL_TYPE_SIMPLE);
- game->setMap( pref.getPreferredMap() );
- game->setStartingCash( pref.getStartingCash() );
- game->setSuperweaponRestriction( pref.getSuperweaponRestricted() ? 1 : 0 );
- AsciiString lowerMap = pref.getPreferredMap();
- lowerMap.toLower();
- std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
- if (it != TheMapCache->end())
- {
- TheLAN->GetMyGame()->getSlot(0)->setMapAvailability(true);
- TheLAN->GetMyGame()->setMapCRC( it->second.m_CRC );
- TheLAN->GetMyGame()->setMapSize( it->second.m_filesize );
- TheLAN->GetMyGame()->adjustSlotsForMap(); // BGC- adjust the slots for the selected map.
- }
- //GadgetTextEntrySetText(comboBoxPlayer[0], TheLAN->GetMyName());
- lanUpdateSlotList();
- updateGameOptions();
- start = 1; // leave my combo boxes usable
- }
- else
- {
- //DEBUG_LOG(("LanGameOptionsMenuInit(): map is %s\n", TheLAN->GetMyGame()->getMap().str()));
- buttonStart->winSetText(TheGameText->fetch("GUI:Accept"));
- buttonSelectMap->winEnable( FALSE );
- checkboxLimitSuperweapons->winEnable( FALSE ); // Can look but only host can touch
- comboBoxStartingCash->winEnable( FALSE ); // Ditto
- TheLAN->GetMyGame()->setMapCRC( TheLAN->GetMyGame()->getMapCRC() ); // force a recheck
- TheLAN->GetMyGame()->setMapSize( TheLAN->GetMyGame()->getMapSize() ); // of if we have the map
- TheLAN->RequestHasMap();
- lanUpdateSlotList();
- updateGameOptions();
- }
- for (Int i = start; i < MAX_SLOTS; ++i)
- {
- //I'm a client, disable the controls I can't touch.
- if (!TheLAN->AmIHost())
- comboBoxPlayer[i]->winEnable(FALSE);
- comboBoxColor[i]->winEnable(FALSE);
- comboBoxPlayerTemplate[i]->winEnable(FALSE);
- comboBoxTeam[i]->winEnable(FALSE);
- // buttonStartPosition[i]->winEnable(FALSE);
- }
- // for (i = 0; i < MAX_SLOTS; ++i)
- // {
- // if (buttonStartPosition[i])
- // buttonStartPosition[i]->winHide(TRUE); // not picking start spots this way any more
- // }
- //
- // Show the Menu
- layout->hide( FALSE );
-
- // Set Keyboard to Main Parent
- TheWindowManager->winSetFocus( parentLanGameOptions );
- s_isIniting = FALSE;
- if (TheLAN->AmIHost())
- {
- TheLAN->RequestGameOptions(GenerateGameOptionsString(),true);
- TheLAN->RequestGameAnnounce();
- }
- lanUpdateSlotList();
- LanPositionStartSpots();
- TheTransitionHandler->setGroup("LanGameOptionsFade");
- // animate controls
- //TheShell->registerWithAnimateManager(buttonBack, WIN_ANIMATION_SLIDE_RIGHT, TRUE, 1);
-
- }// void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )
- //-------------------------------------------------------------------------------------------------
- /** Update options on screen */
- //-------------------------------------------------------------------------------------------------
- void updateGameOptions( void )
- {
- LANGameInfo *theGame = TheLAN->GetMyGame();
- UnicodeString mapDisplayName;
- if (theGame && AreSlotListUpdatesEnabled())
- {
- const GameSlot *localSlot = theGame->getConstSlot(theGame->getLocalSlotNum());
- const MapMetaData *mapData = TheMapCache->findMap( TheLAN->GetMyGame()->getMap() );
- if (mapData && localSlot && localSlot->hasMap())
- {
- mapDisplayName.format(L"%ls", mapData->m_displayName.str());
- }
- else
- {
- AsciiString s = TheLAN->GetMyGame()->getMap();
- if (s.reverseFind('\\'))
- {
- s = s.reverseFind('\\') + 1;
- }
- mapDisplayName.format(L"%hs", s.str());
- }
- UnicodeString old = GadgetStaticTextGetText(textEntryMapDisplay);
- if(old.compare(mapDisplayName) != 0)
- LanPositionStartSpots();
- GadgetStaticTextSetText(textEntryMapDisplay, mapDisplayName);
- GadgetCheckBoxSetChecked( checkboxLimitSuperweapons, theGame->getSuperweaponRestriction() != 0 );
- Int itemCount = GadgetComboBoxGetLength(comboBoxStartingCash);
- for ( Int index = 0; index < itemCount; index++ )
- {
- Int value = (Int)GadgetComboBoxGetItemData(comboBoxStartingCash, index);
- if ( value == theGame->getStartingCash().countMoney() )
- {
- GadgetComboBoxSetSelectedPos(comboBoxStartingCash, index, TRUE);
- break;
- }
- }
- DEBUG_ASSERTCRASH( index < itemCount, ("Could not find new starting cash amount %d in list", theGame->getStartingCash().countMoney() ) );
- }
- }
- //-------------------------------------------------------------------------------------------------
- /** This is called when a shutdown is complete for this menu */
- //-------------------------------------------------------------------------------------------------
- static void shutdownComplete( WindowLayout *layout )
- {
- DeinitLanGameGadgets();
- textEntryMapDisplay = NULL;
- LANisShuttingDown = false;
- // hide the layout
- layout->hide( TRUE );
- // our shutdown is complete
- TheShell->shutdownComplete( layout, (LANnextScreen != NULL) );
- if (LANnextScreen != NULL)
- {
- TheShell->push(LANnextScreen);
- }
- LANnextScreen = NULL;
- } // end if
- //-------------------------------------------------------------------------------------------------
- /** Lan Game Options menu shutdown method */
- //-------------------------------------------------------------------------------------------------
- void LanGameOptionsMenuShutdown( WindowLayout *layout, void *userData )
- {
- TheMouse->setCursor(Mouse::ARROW);
- TheMouse->setMouseText(UnicodeString::TheEmptyString,NULL,NULL);
- EnableSlotListUpdates(FALSE);
- LANisShuttingDown = true;
- // if we are shutting down for an immediate pop, skip the animations
- Bool popImmediate = *(Bool *)userData;
- if( popImmediate )
- {
- shutdownComplete( layout );
- return;
- } //end if
- TheShell->reverseAnimatewindow();
- TheTransitionHandler->reverse("LanGameOptionsFade");
- if (TheLAN)
- TheLAN->ResetGameStartTimer();
- /*
- // hide menu
- layout->hide( TRUE );
- // Reset the LAN singleton
- // TheLAN->reset();
- // our shutdown is complete
- TheShell->shutdownComplete( layout );
- */
- } // void LanGameOptionsMenuShutdown( WindowLayout *layout, void *userData )
- //-------------------------------------------------------------------------------------------------
- /** Lan Game Options menu update method */
- //-------------------------------------------------------------------------------------------------
- void LanGameOptionsMenuUpdate( WindowLayout * layout, void *userData)
- {
- if(LANisShuttingDown && TheShell->isAnimFinished() && TheTransitionHandler->isFinished())
- shutdownComplete(layout);
- //TheLAN->update(); // this is handled in the lobby
- }// void LanGameOptionsMenuUpdate( WindowLayout * layout, void *userData)
- //-------------------------------------------------------------------------------------------------
- /** Lan Game Options menu input callback */
- //-------------------------------------------------------------------------------------------------
- WindowMsgHandledType LanGameOptionsMenuInput( GameWindow *window, UnsignedInt msg,
- WindowMsgData mData1, WindowMsgData mData2 )
- {
- switch( msg )
- {
- // --------------------------------------------------------------------------------------------
- case GWM_CHAR:
- {
- UnsignedByte key = mData1;
- UnsignedByte state = mData2;
- if (LANbuttonPushed)
- break;
- switch( key )
- {
- // ----------------------------------------------------------------------------------------
- case KEY_ESC:
- {
- //
- // send a simulated selected event to the parent window of the
- // back/exit button
- //
- if( BitTest( state, KEY_STATE_UP ) )
- {
- TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
- (WindowMsgData)buttonBack, buttonBackID );
- } // end if
- // don't let key fall through anywhere else
- return MSG_HANDLED;
- } // end escape
- } // end switch( key )
- } // end char
- } // end switch( msg )
- return MSG_IGNORED;
- }//WindowMsgHandledType LanGameOptionsMenuInput( GameWindow *window, UnsignedInt msg,
- //-------------------------------------------------------------------------------------------------
- /** Lan Game Options menu window system callback */
- //-------------------------------------------------------------------------------------------------
- WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt msg,
- WindowMsgData mData1, WindowMsgData mData2 )
- {
- UnicodeString txtInput;
- switch( msg )
- {
- //-------------------------------------------------------------------------------------------------
- case GWM_CREATE:
- {
- break;
- } // case GWM_DESTROY:
- //-------------------------------------------------------------------------------------------------
- case GWM_DESTROY:
- {
- break;
- } // case GWM_DESTROY:
- //-------------------------------------------------------------------------------------------------
- case GWM_INPUT_FOCUS:
- {
- // if we're givin the opportunity to take the keyboard focus we must say we want it
- if( mData1 == TRUE )
- *(Bool *)mData2 = TRUE;
- return MSG_HANDLED;
- }//case GWM_INPUT_FOCUS:
- //-------------------------------------------------------------------------------------------------
- case GCM_SELECTED:
- {
- if (LANbuttonPushed)
- break;
- GameWindow *control = (GameWindow *)mData1;
- Int controlID = control->winGetWindowId();
- LANGameInfo *myGame = TheLAN->GetMyGame();
- if ( controlID == comboBoxStartingCashID )
- {
- handleStartingCashSelection();
- }
- else
- {
- for (Int i = 0; i < MAX_SLOTS; i++)
- {
- if (controlID == comboBoxColorID[i])
- {
- handleColorSelection(i);
- }
- else if (controlID == comboBoxPlayerTemplateID[i])
- {
- handlePlayerTemplateSelection(i);
- }
- else if (controlID == comboBoxTeamID[i])
- {
- handleTeamSelection(i);
- }
- else if( controlID == comboBoxPlayerID[i] && myGame->amIHost() )
- {
- // We don't have anything that'll happen if we click on ourselves
- if(i == myGame->getLocalSlotNum())
- break;
- // Get
- Int pos = -1;
- GadgetComboBoxGetSelectedPos(comboBoxPlayer[i], &pos);
- if( pos != SLOT_PLAYER && pos >= 0)
- {
- if( myGame->getLANSlot(i)->getState() == SLOT_PLAYER )
- {
- UnicodeString name = myGame->getPlayerName(i);
- myGame->getLANSlot(i)->setState(SlotState(pos));
- myGame->resetAccepted();
- TheLAN->OnPlayerLeave(name);
- }
- else if( myGame->getLANSlot(i)->getState() != pos )
- {
- Bool wasAI = (myGame->getLANSlot(i)->isAI());
- myGame->getLANSlot(i)->setState(SlotState(pos));
- Bool isAI = (myGame->getLANSlot(i)->isAI());
- if (wasAI || isAI)
- myGame->resetAccepted();
- if (wasAI ^ isAI)
- PopulatePlayerTemplateComboBox(i, comboBoxPlayerTemplate, myGame, wasAI);
- if (!s_isIniting)
- {
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- lanUpdateSlotList();
- }
- }
- }
- break;
- }
- }
- }
- break;
- }// case GCM_SELECTED:
- //-------------------------------------------------------------------------------------------------
- case GBM_SELECTED:
- {
- if (LANbuttonPushed)
- break;
- GameWindow *control = (GameWindow *)mData1;
- Int controlID = control->winGetWindowId();
- if ( controlID == buttonBackID )
- {
- if( mapSelectLayout )
- {
- mapSelectLayout->destroyWindows();
- mapSelectLayout->deleteInstance();
- mapSelectLayout = NULL;
- }
- TheLAN->RequestGameLeave();
- //TheShell->pop();
- } //if ( controlID == buttonBack )
- else if ( controlID == buttonEmoteID )
- {
- // read the user's input
- txtInput.set(GadgetTextEntryGetText( textEntryChat ));
- // Clear the text entry line
- GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
- // Clean up the text (remove leading/trailing chars, etc)
- txtInput.trim();
- // Echo the user's input to the chat window
- if (!txtInput.isEmpty())
- TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_EMOTE);
- } //if ( controlID == buttonEmote )
- else if ( controlID == buttonSelectMapID )
- {
- //buttonBack->winEnable( false );
-
- mapSelectLayout = TheWindowManager->winCreateLayout( AsciiString( "Menus/LanMapSelectMenu.wnd" ) );
- mapSelectLayout->runInit();
- mapSelectLayout->hide( FALSE );
- mapSelectLayout->bringForward();
- }
- else if ( controlID == buttonStartID )
- {
- if (TheLAN->AmIHost())
- {
- StartPressed();
- //TheLAN->RequestGameStart();
- }
- else
- {
- //I'm the Client... send an accept message to the host.
- TheLAN->RequestAccept();
- // Disable the accept button
- EnableAcceptControls(TRUE, TheLAN->GetMyGame(), comboBoxPlayer, comboBoxColor, comboBoxPlayerTemplate,
- comboBoxTeam, buttonAccept, buttonStart, buttonMapStartPosition);
-
- }
- }
- else if ( controlID == checkboxLimitSuperweaponsID )
- {
- handleLimitSuperweaponsClick();
- }
- else
- {
- for (Int i = 0; i < MAX_SLOTS; i++)
- {
- if (controlID == buttonMapStartPositionID[i])
- {
- LANGameInfo *game = TheLAN->GetMyGame();
- Int playerIdxInPos = -1;
- for (Int j=0; j<MAX_SLOTS; ++j)
- {
- LANGameSlot *slot = game->getLANSlot(j);
- if (slot && slot->getStartPos() == i)
- {
- playerIdxInPos = j;
- break;
- }
- }
- if (playerIdxInPos >= 0)
- {
- LANGameSlot *slot = game->getLANSlot(playerIdxInPos);
- if (playerIdxInPos == game->getLocalSlotNum() || (game->amIHost() && slot && slot->isAI()))
- {
- // it's one of my type. Try to change it.
- Int nextPlayer = getNextSelectablePlayer(playerIdxInPos+1);
- handleStartPositionSelection(playerIdxInPos, -1);
- if (nextPlayer >= 0)
- {
- handleStartPositionSelection(nextPlayer, i);
- }
- }
- }
- else
- {
- // nobody in the slot - put us in
- Int nextPlayer = getNextSelectablePlayer(0);
- if (nextPlayer < 0)
- nextPlayer = getFirstSelectablePlayer(game);
- handleStartPositionSelection(nextPlayer, i);
- }
- }
- }
- }
- break;
- }// case GBM_SELECTED:
- //-------------------------------------------------------------------------------------------------
- case GBM_SELECTED_RIGHT:
- {
- if (LANbuttonPushed)
- break;
- GameWindow *control = (GameWindow *)mData1;
- Int controlID = control->winGetWindowId();
- for (Int i = 0; i < MAX_SLOTS; i++)
- {
- if (controlID == buttonMapStartPositionID[i])
- {
- LANGameInfo *game = TheLAN->GetMyGame();
- Int playerIdxInPos = -1;
- for (Int j=0; j<MAX_SLOTS; ++j)
- {
- LANGameSlot *slot = game->getLANSlot(j);
- if (slot && slot->getStartPos() == i)
- {
- playerIdxInPos = j;
- break;
- }
- }
- if (playerIdxInPos >= 0)
- {
- LANGameSlot *slot = game->getLANSlot(playerIdxInPos);
- if (playerIdxInPos == game->getLocalSlotNum() || (game->amIHost() && slot && slot->isAI()))
- {
- // it's one of my type. Remove it.
- handleStartPositionSelection(playerIdxInPos, -1);
- }
- }
- }
- }
- break;
- }
- //-------------------------------------------------------------------------------------------------
- case GEM_EDIT_DONE:
- {
- if (LANbuttonPushed)
- break;
- GameWindow *control = (GameWindow *)mData1;
- Int controlID = control->winGetWindowId();
- // Take the user's input and echo it into the chat window as well as
- // send it to the other clients on the lan
- if ( controlID == textEntryChatID )
- {
-
- // read the user's input
- txtInput.set(GadgetTextEntryGetText( textEntryChat ));
- // Clear the text entry line
- GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
- // Clean up the text (remove leading/trailing chars, etc)
- txtInput.trim();
- // Echo the user's input to the chat window
- if (!txtInput.isEmpty())
- TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL);
- }// if ( controlID == textEntryChatID )
- break;
- }
- //-------------------------------------------------------------------------------------------------
- default:
- return MSG_IGNORED;
- }//Switch
- return MSG_HANDLED;
- }//WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt msg,
- //-------------------------------------------------------------------------------------------------
- /** Utility FUnction used as a bridge from other windows to this one */
- //-------------------------------------------------------------------------------------------------
- void PostToLanGameOptions( PostToLanGameType post )
- {
- if (post >= POST_TO_LAN_GAME_TYPE_COUNT)
- return;
- LanPositionStartSpots();
- switch (post)
- {
- //-------------------------------------------------------------------------------------------------
- case SEND_GAME_OPTS:
- {
- LANGameInfo *game = TheLAN->GetMyGame();
- game->resetAccepted();
- updateGameOptions();
- lanUpdateSlotList();
-
- //buttonBack->winEnable( true );
-
- for(Int i = 0; i < MAX_SLOTS; ++i)
- {
- game->getSlot(i)->setStartPos(-1);
- }
- TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
- break;
- } //-------------------------------------------------------------------------------------------------
- case MAP_BACK:
- {
- //buttonBack->winEnable( true );
- }
- default:
- return;
- }
- }
|