MP campaign additions/fixes:

- Store tab & cargo spawning
- Sub & shuttle lists and level seed box are disabled when a campaign is active.
- Campaign UI is recreated if a new campaign is started while another one is active.
This commit is contained in:
Joonas Rikkonen
2017-09-14 19:39:03 +03:00
parent 348d81a66f
commit b292a301cf
8 changed files with 98 additions and 48 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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())

View File

@@ -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<MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast<MapEntityCategory>().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;

View File

@@ -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<CampaignUI.Tab> tabTypes = new List<CampaignUI.Tab>() { 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);
}

View File

@@ -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();

View File

@@ -111,7 +111,12 @@ namespace Barotrauma
public override void Start()
{
base.Start();
if (GameMain.Server != null)
{
CargoManager.CreateItems();
}
lastUpdateID++;
}

View File

@@ -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);