/// <summary> /// Changes the game lobby's UI depending on whether the local player is the host. /// </summary> /// <param name="isHost">Determines whether the local player is the host of the game.</param> protected void Refresh(bool isHost) { IsHost = isHost; Locked = false; UpdateMapPreviewBoxEnabledStatus(); //MapPreviewBox.EnableContextMenu = IsHost; btnLaunchGame.Text = IsHost ? "Launch Game" : "I'm Ready"; if (IsHost) { ShowMapList(); btnLockGame.Text = "Lock Game"; btnLockGame.Enabled = true; btnLockGame.Visible = true; chkAutoReady.Disable(); foreach (GameLobbyDropDown dd in DropDowns) { dd.InputEnabled = true; dd.SelectedIndex = dd.UserDefinedIndex; } foreach (GameLobbyCheckBox checkBox in CheckBoxes) { checkBox.AllowChanges = true; checkBox.Checked = checkBox.UserDefinedValue; } GenerateGameID(); } else { HideMapList(); btnLockGame.Enabled = false; btnLockGame.Visible = false; chkAutoReady.GetAttributes(ThemeIni); foreach (GameLobbyDropDown dd in DropDowns) { dd.InputEnabled = false; } foreach (GameLobbyCheckBox checkBox in CheckBoxes) { checkBox.AllowChanges = false; } } LoadDefaultMap(); lbChatMessages.Clear(); lbChatMessages.TopIndex = 0; lbChatMessages.AddItem("Type / to view a list of available chat commands.", Color.Silver, true); if (SavedGameManager.GetSaveGameCount() > 0) { lbChatMessages.AddItem("Multiplayer saved games from a previous match have been detected. " + "The saved games of the previous match will be deleted if you create new saves during this match.", Color.Yellow, true); } }
public override void Initialize() { Name = "MultiplayerGameLobby"; base.Initialize(); InitPlayerOptionDropdowns(); ReadyBoxes = new XNACheckBox[MAX_PLAYER_COUNT]; int readyBoxX = GameOptionsIni.GetIntValue(Name, "PlayerReadyBoxX", 7); int readyBoxY = GameOptionsIni.GetIntValue(Name, "PlayerReadyBoxY", 4); for (int i = 0; i < MAX_PLAYER_COUNT; i++) { XNACheckBox chkPlayerReady = new XNACheckBox(WindowManager); chkPlayerReady.Name = "chkPlayerReady" + i; chkPlayerReady.Checked = false; chkPlayerReady.AllowChecking = false; chkPlayerReady.ClientRectangle = new Rectangle(readyBoxX, ddPlayerTeams[i].Y + readyBoxY, 0, 0); PlayerOptionsPanel.AddChild(chkPlayerReady); chkPlayerReady.DisabledClearTexture = chkPlayerReady.ClearTexture; chkPlayerReady.DisabledCheckedTexture = chkPlayerReady.CheckedTexture; ReadyBoxes[i] = chkPlayerReady; ddPlayerSides[i].AddItem("Spectator", AssetLoader.LoadTexture("spectatoricon.png")); } ddGameMode.ClientRectangle = new Rectangle( MapPreviewBox.X - 12 - ddGameMode.Width, MapPreviewBox.Y, ddGameMode.Width, ddGameMode.Height); lblGameModeSelect.ClientRectangle = new Rectangle( btnLaunchGame.X, ddGameMode.Y + 1, lblGameModeSelect.Width, lblGameModeSelect.Height); lbMapList.ClientRectangle = new Rectangle(btnLaunchGame.X, MapPreviewBox.Y + 23, MapPreviewBox.X - btnLaunchGame.X - 12, MapPreviewBox.Height - 23); lbChatMessages = new ChatListBox(WindowManager); lbChatMessages.Name = "lbChatMessages"; lbChatMessages.ClientRectangle = new Rectangle(lbMapList.X, GameOptionsPanel.Y, lbMapList.Width, GameOptionsPanel.Height - 24); lbChatMessages.PanelBackgroundDrawMode = PanelBackgroundImageDrawMode.STRETCHED; lbChatMessages.BackgroundTexture = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1); lbChatMessages.LineHeight = 16; lbChatMessages.DrawOrder = -1; lbChatMessages.UpdateOrder = -1; tbChatInput = new XNAChatTextBox(WindowManager); tbChatInput.Name = "tbChatInput"; tbChatInput.Suggestion = "Type here to chat.."; tbChatInput.ClientRectangle = new Rectangle(lbChatMessages.X, lbChatMessages.Bottom + 3, lbChatMessages.Width, 21); tbChatInput.MaximumTextLength = 150; tbChatInput.EnterPressed += TbChatInput_EnterPressed; tbChatInput.DrawOrder = 1; tbChatInput.UpdateOrder = 1; btnLockGame = new XNAClientButton(WindowManager); btnLockGame.Name = "btnLockGame"; btnLockGame.ClientRectangle = new Rectangle(btnLaunchGame.Right + 12, btnLaunchGame.Y, 133, 23); btnLockGame.Text = "Lock Game"; btnLockGame.LeftClick += BtnLockGame_LeftClick; chkAutoReady = new XNAClientCheckBox(WindowManager); chkAutoReady.Name = "chkAutoReady"; chkAutoReady.ClientRectangle = new Rectangle(btnLaunchGame.Right + 12, btnLaunchGame.Y + 2, 133, 23); chkAutoReady.Text = "Auto-Ready"; chkAutoReady.CheckedChanged += ChkAutoReady_CheckedChanged; chkAutoReady.Disable(); AddChild(lbChatMessages); AddChild(tbChatInput); AddChild(btnLockGame); AddChild(chkAutoReady); MapPreviewBox.LocalStartingLocationSelected += MapPreviewBox_LocalStartingLocationSelected; MapPreviewBox.StartingLocationApplied += MapPreviewBox_StartingLocationApplied; InitializeWindow(); sndJoinSound = new EnhancedSoundEffect("joingame.wav"); sndLeaveSound = new EnhancedSoundEffect("leavegame.wav"); sndMessageSound = new EnhancedSoundEffect("message.wav"); sndGetReadySound = new EnhancedSoundEffect("getready.wav", 0.0, 0.0, 5.0f); if (SavedGameManager.AreSavedGamesAvailable()) { fsw = new FileSystemWatcher(ProgramConstants.GamePath + "Saved Games", "*.NET"); fsw.Created += fsw_Created; fsw.Changed += fsw_Created; fsw.EnableRaisingEvents = false; } else { Logger.Log("MultiplayerGameLobby: Saved games are not available!"); } CenterOnParent(); // To move the lblMapAuthor label into its correct position // if it was moved in the theme description INI file LoadDefaultMap(); }