diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs index 250fa63a6..e6f75c2e7 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs @@ -142,7 +142,7 @@ namespace Barotrauma private bool OnClicked(GUIComponent component, object obj) { - if (wasOpened) return false; + if (wasOpened || !Enabled) return false; wasOpened = true; Dropped = !Dropped; diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs index 3b615d908..75dc5e50b 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIListBox.cs @@ -80,7 +80,11 @@ namespace Barotrauma public bool Enabled { get { return enabled; } - set { enabled = value; } + set + { + enabled = value; + scrollBar.Enabled = value; + } } public override Color Color @@ -280,7 +284,7 @@ namespace Barotrauma UpdateChildrenRect(deltaTime); - //base.Update(deltaTime); + if (!enabled) return; if (scrollBarEnabled && !scrollBarHidden) scrollBar.Update(deltaTime); diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIScrollBar.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIScrollBar.cs index c3bce0c91..c1086fc0a 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIScrollBar.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIScrollBar.cs @@ -36,7 +36,11 @@ namespace Barotrauma public bool Enabled { get { return enabled; } - set { enabled = value; } + set + { + enabled = value; + bar.Enabled = value; + } } public float BarScroll @@ -161,6 +165,8 @@ namespace Barotrauma base.Update(deltaTime); + if (!enabled) return; + if (MouseOn == frame) { if (PlayerInput.LeftButtonClicked()) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs index 32a534483..4d6ccf230 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -39,6 +40,11 @@ namespace Barotrauma get { return selectedLevel; } } + public CampaignMode Campaign + { + get { return campaign; } + } + private string CostTextGetter() { return "Cost: " + selectedItemCost.ToString() + " credits"; @@ -112,13 +118,16 @@ namespace Barotrauma storeItemList = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, tabs[(int)Tab.Store].Rect.Height - 80), Color.White * 0.7f, Alignment.TopRight, "", tabs[(int)Tab.Store]); storeItemList.OnSelected = SelectItem; - int x = selectedItemList.Rect.Width + 40; - foreach (MapEntityCategory category in Enum.GetValues(typeof(MapEntityCategory))) - { - var items = MapEntityPrefab.list.FindAll(ep => ep.Price > 0.0f && ep.Category.HasFlag(category)); - if (!items.Any()) continue; + int x = storeItemList.Rect.X - storeItemList.Parent.Rect.X; - var categoryButton = new GUIButton(new Rectangle(x, 0, 100, 20), category.ToString(), "", tabs[(int)Tab.Store]); + List itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast().ToList(); + //don't show categories with no buyable items + itemCategories.RemoveAll(c => !MapEntityPrefab.list.Any(ep => ep.Price > 0.0f && ep.Category.HasFlag(c))); + + int buttonWidth = Math.Min(sellColumnWidth / itemCategories.Count, 100); + foreach (MapEntityCategory category in itemCategories) + { + var categoryButton = new GUIButton(new Rectangle(x, 0, buttonWidth, 20), category.ToString(), "", tabs[(int)Tab.Store]); categoryButton.UserData = category; categoryButton.OnClicked = SelectItemCategory; @@ -126,7 +135,7 @@ namespace Barotrauma { SelectItemCategory(categoryButton, category); } - x += 110; + x += buttonWidth; } SelectTab(Tab.Map); @@ -294,15 +303,13 @@ namespace Barotrauma new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 70, 0, 0), mission.Description, "", Alignment.TopLeft, Alignment.TopLeft, locationPanel, true, GUI.SmallFont); } - startButton.Enabled = true; + if (startButton != null) startButton.Enabled = true; selectedLevel = connection.Level; OnLocationSelected?.Invoke(location, connection); } - - private bool BuyItems(GUIButton button, object obj) { int cost = selectedItemCost; diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index 985f6df06..698a73999 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -225,9 +225,6 @@ namespace Barotrauma campaignContainer = new GUIFrame(new Rectangle(0, 20, 0, 0), null, infoFrame); campaignContainer.Visible = false; - var backButton = new GUIButton(new Rectangle(0, -20, 100, 30), "Back", "", campaignContainer); - backButton.OnClicked += (btn, obj) => { ToggleCampaignView(false); return true; }; - //submarine list ------------------------------------------------------------------ @@ -408,8 +405,10 @@ namespace Barotrauma infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "spectateButton")); InfoFrame.FindChild("showlog").Visible = GameMain.Server != null; - - //playerList.Parent.RemoveChild(playerList.Parent.children.Find(c => c.UserData as string == "banListButton")); + + campaignViewButton = new GUIButton(new Rectangle(0, 0, 130, 30), "Campaign view", Alignment.BottomRight, "", defaultModeContainer); + campaignViewButton.OnClicked = (btn, obj) => { ToggleCampaignView(true); return true; }; + campaignViewButton.Visible = false; if (IsServer && GameMain.Server != null) { @@ -437,9 +436,6 @@ namespace Barotrauma StartButton = new GUIButton(new Rectangle(0, 0, 80, 30), "Start", Alignment.BottomRight, "", defaultModeContainer); StartButton.OnClicked = GameMain.Server.StartGameClicked; - campaignViewButton = new GUIButton(new Rectangle(0, 0, 130, 30), "Campaign view", Alignment.BottomRight, "", defaultModeContainer); - campaignViewButton.OnClicked = (btn, obj) => { ToggleCampaignView(true); return true; }; - campaignViewButton.Visible = false; GUIButton settingsButton = new GUIButton(new Rectangle(-110, 0, 80, 20), "Settings", Alignment.TopRight, "", infoFrame); settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame; @@ -1096,16 +1092,20 @@ namespace Barotrauma public void SelectMode(int modeIndex) { - if (modeIndex < 0 || modeIndex >= modeList.children.Count) return; + if (modeIndex < 0 || modeIndex >= modeList.children.Count || modeList.SelectedIndex == modeIndex) return; - if (GameMain.Server != null) + if (((GameModePreset)modeList.children[modeIndex].UserData).Name == "Campaign") { - if (((GameModePreset)modeList.children[modeIndex].UserData).Name == "Campaign") + if (GameMain.Server != null) { MultiplayerCampaign.StartCampaignSetup(); return; } } + else + { + ToggleCampaignMode(false); + } modeList.Select(modeIndex, true); missionTypeBlock.Visible = SelectedMode != null && SelectedMode.Name == "Mission"; @@ -1113,24 +1113,28 @@ namespace Barotrauma private bool SelectMode(GUIComponent component, object obj) { - if (GameMain.NetworkMember == null) return false; + if (GameMain.NetworkMember == null || obj == modeList.SelectedData) return false; GameModePreset modePreset = obj as GameModePreset; if (modePreset == null) return false; missionTypeBlock.Visible = modePreset.Name == "Mission"; - - if (GameMain.Server != null) + + if (modePreset.Name == "Campaign") { //campaign selected and the campaign view has not been set up yet // -> don't select the mode yet and start campaign setup - if (modePreset.Name == "Campaign" && !campaignContainer.Visible) + if (GameMain.Server != null && !campaignContainer.Visible) { MultiplayerCampaign.StartCampaignSetup(); return false; } - } - + } + else + { + ToggleCampaignMode(false); + } + lastUpdateID++; return true; } @@ -1139,22 +1143,43 @@ namespace Barotrauma { campaignContainer.Visible = enabled; defaultModeContainer.Visible = !enabled; - if (StartButton != null) - { - StartButton.Visible = !enabled; - } } public void ToggleCampaignMode(bool enabled) { ToggleCampaignView(enabled); + subList.Enabled = !enabled; + shuttleList.Enabled = !enabled; + seedBox.Enabled = !enabled; + + if (campaignViewButton != null) campaignViewButton.Visible = enabled; + if (StartButton != null) StartButton.Visible = !enabled; + if (enabled) { - if (campaignUI == null) + if (campaignUI == null || campaignUI.Campaign != GameMain.GameSession.GameMode) { + campaignContainer.ClearChildren(); + campaignUI = new CampaignUI(GameMain.GameSession.GameMode as CampaignMode, campaignContainer); campaignUI.StartRound = () => { GameMain.Server.StartGame(); }; + + var backButton = new GUIButton(new Rectangle(0, -20, 100, 30), "Back", "", campaignContainer); + backButton.OnClicked += (btn, obj) => { ToggleCampaignView(false); return true; }; + + int buttonX = backButton.Rect.Width + 50; + List tabTypes = new List() { CampaignUI.Tab.Map, CampaignUI.Tab.Store }; + foreach (CampaignUI.Tab tab in tabTypes) + { + var tabButton = new GUIButton(new Rectangle(buttonX, -10, 100, 20), tab.ToString(), "", campaignContainer); + tabButton.OnClicked += (btn, obj) => + { + campaignUI.SelectTab(tab); + return true; + }; + buttonX += 110; + } } modeList.Select(2, true); } diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs b/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs index 600e91c5f..e65961e6f 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/CargoManager.cs @@ -21,7 +21,7 @@ namespace Barotrauma { WayPoint wp = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub); - if (wp==null) + if (wp == null) { DebugConsole.ThrowError("The submarine must have a waypoint marked as Cargo for bought items to be placed correctly!"); return; @@ -41,7 +41,15 @@ namespace Barotrauma Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20), cargoRoom.Rect.Y - cargoRoom.Rect.Height + prefab.Size.Y/2); - new Item(prefab, position, wp.Submarine); + if (GameMain.Server != null) + { + Entity.Spawner.AddToSpawnQueue(prefab, position, wp.Submarine); + } + else + { + new Item(prefab, position, wp.Submarine); + } + } purchasedItems.Clear(); diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs index b504cf771..69dee9eb4 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs @@ -111,7 +111,12 @@ namespace Barotrauma public override void Start() { base.Start(); - + + if (GameMain.Server != null) + { + CargoManager.CreateItems(); + } + lastUpdateID++; } diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs index fe595e66b..031b12439 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs @@ -197,21 +197,16 @@ namespace Barotrauma submarine.SetPosition(submarine.FindSpawnPos(level.StartPosition - new Vector2(0.0f, 2000.0f))); } - if (GameMode.Mission != null) - { - currentMission = GameMode.Mission; - } - - if (GameMode!=null) GameMode.Start(); + Entity.Spawner = new EntitySpawner(); + if (GameMode.Mission != null) currentMission = GameMode.Mission; + if (GameMode != null) GameMode.Start(); if (GameMode.Mission != null) Mission.Start(Level.Loaded); - + EventManager.StartRound(level); if (GameMode != null) GameMode.MsgBox(); - Entity.Spawner = new EntitySpawner(); - #if CLIENT roundSummary = new RoundSummary(this);