Fixed messageboxes opened by the mp campaign setup UI not being shown until the UI is closed (e.g. shuttle & incompatible content package warnings), renamed MultiplayerCampaign -> MultiPlayerCampaign for consistency. See #315

This commit is contained in:
Joonas Rikkonen
2018-03-06 16:43:36 +02:00
parent dda8854b58
commit 10ce4bd20d
12 changed files with 275 additions and 232 deletions
@@ -80,6 +80,7 @@
<Compile Include="Source\Characters\AI\HumanAIController.cs" /> <Compile Include="Source\Characters\AI\HumanAIController.cs" />
<Compile Include="Source\Characters\Animation\Ragdoll.cs" /> <Compile Include="Source\Characters\Animation\Ragdoll.cs" />
<Compile Include="Source\Characters\Attack.cs" /> <Compile Include="Source\Characters\Attack.cs" />
<Compile Include="Source\GameSession\GameModes\MultiPlayerCampaign.cs" />
<Compile Include="Source\Items\Components\Machines\Controller.cs" /> <Compile Include="Source\Items\Components\Machines\Controller.cs" />
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreature.cs" /> <Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreature.cs" />
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreatureManager.cs" /> <Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreatureManager.cs" />
@@ -0,0 +1,166 @@
using Barotrauma.Networking;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
namespace Barotrauma
{
partial class MultiPlayerCampaign : CampaignMode
{
public static GUIComponent StartCampaignSetup()
{
GUIFrame background = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, null);
GUIFrame setupBox = new GUIFrame(new Rectangle(0, 0, 500, 500), null, Alignment.Center, "", background);
setupBox.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
new GUITextBlock(new Rectangle(0, 0, 10, 10), "Campaign Setup", "", setupBox, GUI.LargeFont);
setupBox.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);
var newCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);
var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);
var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);
var newCampaignButton = new GUIButton(new Rectangle(0, 0, 120, 20), "New campaign", "", setupBox);
newCampaignButton.OnClicked += (btn, obj) =>
{
newCampaignContainer.Visible = true;
loadCampaignContainer.Visible = false;
return true;
};
var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox);
loadCampaignButton.OnClicked += (btn, obj) =>
{
newCampaignContainer.Visible = false;
loadCampaignContainer.Visible = true;
return true;
};
loadCampaignContainer.Visible = false;
campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
{
GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
campaign.GenerateMap(mapSeed);
campaign.SetDelegates();
background.Visible = false;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
campaign.Map.SelectRandomLocation(true);
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
campaign.LastSaveID++;
};
campaignSetupUI.LoadGame = (string fileName) =>
{
SaveUtil.LoadGame(fileName);
var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
campaign.LastSaveID++;
background.Visible = false;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
campaign.Map.SelectRandomLocation(true);
};
var cancelButton = new GUIButton(new Rectangle(0, 0, 120, 30), "Cancel", Alignment.BottomLeft, "", setupBox);
cancelButton.OnClicked += (btn, obj) =>
{
background.Visible = false;
int otherModeIndex = 0;
for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
{
if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiPlayerCampaign) continue;
break;
}
GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
return true;
};
return background;
}
public void ClientWrite(NetBuffer msg)
{
System.Diagnostics.Debug.Assert(map.Locations.Count < UInt16.MaxValue);
msg.Write(map.SelectedLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.SelectedLocationIndex);
msg.Write((UInt16)CargoManager.PurchasedItems.Count);
foreach (ItemPrefab ip in CargoManager.PurchasedItems)
{
msg.Write((UInt16)MapEntityPrefab.List.IndexOf(ip));
}
}
//static because we may need to instantiate the campaign if it hasn't been done yet
public static void ClientRead(NetBuffer msg)
{
byte campaignID = msg.ReadByte();
UInt16 updateID = msg.ReadUInt16();
UInt16 saveID = msg.ReadUInt16();
string mapSeed = msg.ReadString();
UInt16 currentLocIndex = msg.ReadUInt16();
UInt16 selectedLocIndex = msg.ReadUInt16();
int money = msg.ReadInt32();
UInt16 purchasedItemCount = msg.ReadUInt16();
List<ItemPrefab> purchasedItems = new List<ItemPrefab>();
for (int i = 0; i < purchasedItemCount; i++)
{
UInt16 itemPrefabIndex = msg.ReadUInt16();
purchasedItems.Add(MapEntityPrefab.List[itemPrefabIndex] as ItemPrefab);
}
MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
if (campaign == null || campaignID != campaign.CampaignID)
{
string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer);
GameMain.GameSession = new GameSession(null, savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
campaign.CampaignID = campaignID;
campaign.GenerateMap(mapSeed);
}
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
if (NetIdUtils.IdMoreRecent(campaign.lastUpdateID, updateID)) return;
//server has a newer save file
if (NetIdUtils.IdMoreRecent(saveID, campaign.PendingSaveID))
{
/*//stop any active campaign save transfers, they're outdated now
List<FileReceiver.FileTransferIn> saveTransfers =
GameMain.Client.FileReceiver.ActiveTransfers.FindAll(t => t.FileType == FileTransferType.CampaignSave);
foreach (var transfer in saveTransfers)
{
GameMain.Client.FileReceiver.StopTransfer(transfer);
}
GameMain.Client.RequestFile(FileTransferType.CampaignSave, null, null);*/
campaign.PendingSaveID = saveID;
}
//we've got the latest save file
else if (!NetIdUtils.IdMoreRecent(saveID, campaign.lastSaveID))
{
campaign.Map.SetLocation(currentLocIndex == UInt16.MaxValue ? -1 : currentLocIndex);
campaign.Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex);
campaign.Money = money;
campaign.CargoManager.SetPurchasedItems(purchasedItems);
campaign.lastUpdateID = updateID;
}
}
}
}
@@ -722,8 +722,8 @@ namespace Barotrauma.Networking
inc.ReadPadBits(); inc.ReadPadBits();
GameModePreset gameMode = GameModePreset.list.Find(gm => gm.Name == modeName); GameModePreset gameMode = GameModePreset.list.Find(gm => gm.Name == modeName);
MultiplayerCampaign campaign = GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ? MultiPlayerCampaign campaign = GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ?
GameMain.GameSession?.GameMode as MultiplayerCampaign : null; GameMain.GameSession?.GameMode as MultiPlayerCampaign : null;
if (gameMode == null) if (gameMode == null)
{ {
@@ -955,7 +955,7 @@ namespace Barotrauma.Networking
inc.ReadPadBits(); inc.ReadPadBits();
if (campaignUpdated) if (campaignUpdated)
{ {
MultiplayerCampaign.ClientRead(inc); MultiPlayerCampaign.ClientRead(inc);
} }
lastSentChatMsgID = inc.ReadUInt16(); lastSentChatMsgID = inc.ReadUInt16();
@@ -1065,7 +1065,7 @@ namespace Barotrauma.Networking
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID); outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
outmsg.Write(ChatMessage.LastID); outmsg.Write(ChatMessage.LastID);
var campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
if (campaign == null || campaign.LastSaveID == 0) if (campaign == null || campaign.LastSaveID == 0)
{ {
outmsg.Write((UInt16)0); outmsg.Write((UInt16)0);
@@ -1228,7 +1228,7 @@ namespace Barotrauma.Networking
break; break;
case FileTransferType.CampaignSave: case FileTransferType.CampaignSave:
var campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
if (campaign == null) return; if (campaign == null) return;
GameMain.GameSession.SavePath = transfer.FilePath; GameMain.GameSession.SavePath = transfer.FilePath;
@@ -1446,7 +1446,7 @@ namespace Barotrauma.Networking
public void SendCampaignState() public void SendCampaignState()
{ {
MultiplayerCampaign campaign = GameMain.GameSession.GameMode as MultiplayerCampaign; MultiPlayerCampaign campaign = GameMain.GameSession.GameMode as MultiPlayerCampaign;
if (campaign == null) if (campaign == null)
{ {
DebugConsole.ThrowError("Failed send campaign state to the server (no campaign active).\n" + Environment.StackTrace); DebugConsole.ThrowError("Failed send campaign state to the server (no campaign active).\n" + Environment.StackTrace);
@@ -57,6 +57,7 @@ namespace Barotrauma
private GUITickBox shuttleTickBox; private GUITickBox shuttleTickBox;
private CampaignUI campaignUI; private CampaignUI campaignUI;
private GUIComponent campaignSetupUI;
private Sprite backgroundSprite; private Sprite backgroundSprite;
@@ -1111,7 +1112,11 @@ namespace Barotrauma
{ {
base.AddToGUIUpdateList(); base.AddToGUIUpdateList();
if (jobInfoFrame != null) if (campaignSetupUI != null)
{
campaignSetupUI.AddToGUIUpdateList();
}
else if (jobInfoFrame != null)
{ {
jobInfoFrame.AddToGUIUpdateList(); jobInfoFrame.AddToGUIUpdateList();
} }
@@ -1155,10 +1160,21 @@ namespace Barotrauma
if (campaignContainer.Visible && campaignUI != null) if (campaignContainer.Visible && campaignUI != null)
{ {
//campaignContainer.Update((float)deltaTime);
campaignUI.Update((float)deltaTime); campaignUI.Update((float)deltaTime);
} }
if (campaignSetupUI != null)
{
if (!campaignSetupUI.Visible)
{
campaignSetupUI = null;
}
else
{
campaignSetupUI.Update((float)deltaTime);
}
}
if (autoRestartTimer != 0.0f && autoRestartBox.Selected) if (autoRestartTimer != 0.0f && autoRestartBox.Selected)
{ {
autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f); autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f);
@@ -1186,6 +1202,11 @@ namespace Barotrauma
campaignUI.Draw(spriteBatch); campaignUI.Draw(spriteBatch);
} }
if (campaignSetupUI != null)
{
campaignSetupUI.Draw(spriteBatch);
}
if (playerFrame != null) playerFrame.Draw(spriteBatch); if (playerFrame != null) playerFrame.Draw(spriteBatch);
GUI.Draw((float)deltaTime, spriteBatch, null); GUI.Draw((float)deltaTime, spriteBatch, null);
@@ -1254,7 +1275,7 @@ namespace Barotrauma
{ {
if (GameMain.Server != null) if (GameMain.Server != null)
{ {
MultiplayerCampaign.StartCampaignSetup(); campaignSetupUI = MultiPlayerCampaign.StartCampaignSetup();
return; return;
} }
} }
@@ -1282,7 +1303,7 @@ namespace Barotrauma
// -> don't select the mode yet and start campaign setup // -> don't select the mode yet and start campaign setup
if (GameMain.Server != null && !campaignContainer.Visible) if (GameMain.Server != null && !campaignContainer.Visible)
{ {
MultiplayerCampaign.StartCampaignSetup(); campaignSetupUI = MultiPlayerCampaign.StartCampaignSetup();
return false; return false;
} }
} }
@@ -83,6 +83,7 @@
<Compile Include="Source\Characters\Character.cs" /> <Compile Include="Source\Characters\Character.cs" />
<Compile Include="Source\DebugConsole.cs" /> <Compile Include="Source\DebugConsole.cs" />
<Compile Include="Source\GameMain.cs" /> <Compile Include="Source\GameMain.cs" />
<Compile Include="Source\GameSession\MultiPlayerCampaign.cs" />
<Compile Include="Source\Items\Components\ItemComponent.cs" /> <Compile Include="Source\Items\Components\ItemComponent.cs" />
<Compile Include="Source\Items\Components\ItemLabel.cs" /> <Compile Include="Source\Items\Components\ItemLabel.cs" />
<Compile Include="Source\Items\Components\Machines\Steering.cs" /> <Compile Include="Source\Items\Components\Machines\Steering.cs" />
@@ -138,9 +139,7 @@
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="Source\GameSession\" />
</ItemGroup>
<Import Project="..\BarotraumaShared\BarotraumaShared.projitems" Label="Shared" /> <Import Project="..\BarotraumaShared\BarotraumaShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -81,7 +81,7 @@ namespace Barotrauma
if (index > 0 && index < GameMain.NetLobbyScreen.GameModes.Length && if (index > 0 && index < GameMain.NetLobbyScreen.GameModes.Length &&
GameMain.NetLobbyScreen.GameModes[index].Name == "Campaign") GameMain.NetLobbyScreen.GameModes[index].Name == "Campaign")
{ {
MultiplayerCampaign.StartCampaignSetup(); MultiPlayerCampaign.StartCampaignSetup();
} }
else else
{ {
@@ -93,7 +93,7 @@ namespace Barotrauma
string modeName = string.Join(" ", args); string modeName = string.Join(" ", args);
if (modeName.ToLowerInvariant() == "campaign") if (modeName.ToLowerInvariant() == "campaign")
{ {
MultiplayerCampaign.StartCampaignSetup(); MultiPlayerCampaign.StartCampaignSetup();
} }
else else
{ {
@@ -0,0 +1,56 @@
using Microsoft.Xna.Framework;
namespace Barotrauma
{
partial class MultiPlayerCampaign
{
public static void StartCampaignSetup()
{
DebugConsole.NewMessage("********* CAMPAIGN SETUP *********", Color.White);
DebugConsole.ShowQuestionPrompt("Do you want to start a new campaign? Y/N", (string arg) =>
{
if (arg.ToLowerInvariant() == "y" || arg.ToLowerInvariant() == "yes")
{
DebugConsole.ShowQuestionPrompt("Enter a save name for the campaign:", (string saveName) =>
{
if (string.IsNullOrWhiteSpace(saveName)) return;
string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
GameMain.GameSession = new GameSession(new Submarine(GameMain.NetLobbyScreen.SelectedSub.FilePath, ""), savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
campaign.SetDelegates();
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
GameMain.GameSession.Map.SelectRandomLocation(true);
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
campaign.LastSaveID++;
DebugConsole.NewMessage("Campaign started!", Color.Cyan);
});
}
else
{
string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
DebugConsole.NewMessage("Saved campaigns:", Color.White);
for (int i = 0; i < saveFiles.Length; i++)
{
DebugConsole.NewMessage(" " + i + ". " + saveFiles[i], Color.White);
}
DebugConsole.ShowQuestionPrompt("Select a save file to load (0 - " + (saveFiles.Length - 1) + "):", (string selectedSave) =>
{
int saveIndex = -1;
if (!int.TryParse(selectedSave, out saveIndex)) return;
SaveUtil.LoadGame(saveFiles[saveIndex]);
((MultiPlayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
GameMain.GameSession.Map.SelectRandomLocation(true);
DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
});
}
});
}
}
}
@@ -1489,7 +1489,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\GameMode.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\GameMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\GameModePreset.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\GameModePreset.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\MissionMode.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\MissionMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\MultiplayerCampaign.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\MultiPlayerCampaign.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\TraitorManager.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\TraitorManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameSession.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameSession.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSettings.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Source\GameSettings.cs" />
@@ -63,7 +63,7 @@ namespace Barotrauma
+ "an alien artifact or killing a creature that's terrorizing nearby outposts. The game ends " + "an alien artifact or killing a creature that's terrorizing nearby outposts. The game ends "
+ "when the task is completed or everyone in the crew has died."; + "when the task is completed or everyone in the crew has died.";
new GameModePreset("Campaign", typeof(MultiplayerCampaign), false, false); new GameModePreset("Campaign", typeof(MultiPlayerCampaign), false, false);
} }
} }
} }
@@ -8,7 +8,7 @@ using System.Collections.Generic;
namespace Barotrauma namespace Barotrauma
{ {
class MultiplayerCampaign : CampaignMode partial class MultiPlayerCampaign : CampaignMode
{ {
private UInt16 lastUpdateID; private UInt16 lastUpdateID;
public UInt16 LastUpdateID public UInt16 LastUpdateID
@@ -37,135 +37,13 @@ namespace Barotrauma
get; private set; get; private set;
} }
public MultiplayerCampaign(GameModePreset preset, object param) : public MultiPlayerCampaign(GameModePreset preset, object param) :
base(preset, param) base(preset, param)
{ {
currentCampaignID++; currentCampaignID++;
CampaignID = currentCampaignID; CampaignID = currentCampaignID;
} }
#if CLIENT
public static void StartCampaignSetup()
{
var setupBox = new GUIMessageBox("Campaign Setup", "", new string [0], 500, 500);
setupBox.InnerFrame.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);
var newCampaignContainer = new GUIFrame(new Rectangle(0,40,0,0), null, setupBox.InnerFrame);
var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox.InnerFrame);
var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);
var newCampaignButton = new GUIButton(new Rectangle(0,0,120,20), "New campaign", "", setupBox.InnerFrame);
newCampaignButton.OnClicked += (btn, obj) =>
{
newCampaignContainer.Visible = true;
loadCampaignContainer.Visible = false;
return true;
};
var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox.InnerFrame);
loadCampaignButton.OnClicked += (btn, obj) =>
{
newCampaignContainer.Visible = false;
loadCampaignContainer.Visible = true;
return true;
};
loadCampaignContainer.Visible = false;
campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
{
GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
campaign.GenerateMap(mapSeed);
campaign.SetDelegates();
setupBox.Close();
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
campaign.Map.SelectRandomLocation(true);
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
campaign.LastSaveID++;
};
campaignSetupUI.LoadGame = (string fileName) =>
{
SaveUtil.LoadGame(fileName);
var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
campaign.LastSaveID++;
setupBox.Close();
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
campaign.Map.SelectRandomLocation(true);
};
var cancelButton = new GUIButton(new Rectangle(0,0,120,30), "Cancel", Alignment.BottomLeft, "", setupBox.InnerFrame);
cancelButton.OnClicked += (btn, obj) =>
{
setupBox.Close();
int otherModeIndex = 0;
for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
{
if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiplayerCampaign) continue;
break;
}
GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
return true;
};
}
#elif SERVER
public static void StartCampaignSetup()
{
DebugConsole.NewMessage("********* CAMPAIGN SETUP *********", Color.White);
DebugConsole.ShowQuestionPrompt("Do you want to start a new campaign? Y/N", (string arg) =>
{
if (arg.ToLowerInvariant() == "y" || arg.ToLowerInvariant() == "yes")
{
DebugConsole.ShowQuestionPrompt("Enter a save name for the campaign:", (string saveName) =>
{
if (string.IsNullOrWhiteSpace(saveName)) return;
string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
GameMain.GameSession = new GameSession(new Submarine(GameMain.NetLobbyScreen.SelectedSub.FilePath, ""), savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
campaign.SetDelegates();
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
GameMain.GameSession.Map.SelectRandomLocation(true);
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
campaign.LastSaveID++;
DebugConsole.NewMessage("Campaign started!", Color.Cyan);
});
}
else
{
string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
DebugConsole.NewMessage("Saved campaigns:", Color.White);
for (int i = 0; i < saveFiles.Length; i++)
{
DebugConsole.NewMessage(" " + i + ". " + saveFiles[i], Color.White);
}
DebugConsole.ShowQuestionPrompt("Select a save file to load (0 - " + (saveFiles.Length - 1) + "):", (string selectedSave) =>
{
int saveIndex = -1;
if (!int.TryParse(selectedSave, out saveIndex)) return;
SaveUtil.LoadGame(saveFiles[saveIndex]);
((MultiplayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
GameMain.GameSession.Map.SelectRandomLocation(true);
DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
});
}
});
}
#endif
private void SetDelegates() private void SetDelegates()
{ {
if (GameMain.Server != null) if (GameMain.Server != null)
@@ -267,9 +145,9 @@ namespace Barotrauma
} }
} }
public static MultiplayerCampaign LoadNew(XElement element) public static MultiPlayerCampaign LoadNew(XElement element)
{ {
MultiplayerCampaign campaign = new MultiplayerCampaign(GameModePreset.list.Find(gm => gm.Name == "Campaign"), null); MultiPlayerCampaign campaign = new MultiPlayerCampaign(GameModePreset.list.Find(gm => gm.Name == "Campaign"), null);
campaign.Load(element); campaign.Load(element);
campaign.SetDelegates(); campaign.SetDelegates();
@@ -328,84 +206,6 @@ namespace Barotrauma
} }
} }
#if CLIENT
//static because we may need to instantiate the campaign if it hasn't been done yet
public static void ClientRead(NetBuffer msg)
{
byte campaignID = msg.ReadByte();
UInt16 updateID = msg.ReadUInt16();
UInt16 saveID = msg.ReadUInt16();
string mapSeed = msg.ReadString();
UInt16 currentLocIndex = msg.ReadUInt16();
UInt16 selectedLocIndex = msg.ReadUInt16();
int money = msg.ReadInt32();
UInt16 purchasedItemCount = msg.ReadUInt16();
List<ItemPrefab> purchasedItems = new List<ItemPrefab>();
for (int i = 0; i < purchasedItemCount; i++)
{
UInt16 itemPrefabIndex = msg.ReadUInt16();
purchasedItems.Add(MapEntityPrefab.List[itemPrefabIndex] as ItemPrefab);
}
MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign;
if (campaign == null || campaignID != campaign.CampaignID)
{
string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer);
GameMain.GameSession = new GameSession(null, savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
campaign.CampaignID = campaignID;
campaign.GenerateMap(mapSeed);
}
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
if (NetIdUtils.IdMoreRecent(campaign.lastUpdateID, updateID)) return;
//server has a newer save file
if (NetIdUtils.IdMoreRecent(saveID, campaign.PendingSaveID))
{
/*//stop any active campaign save transfers, they're outdated now
List<FileReceiver.FileTransferIn> saveTransfers =
GameMain.Client.FileReceiver.ActiveTransfers.FindAll(t => t.FileType == FileTransferType.CampaignSave);
foreach (var transfer in saveTransfers)
{
GameMain.Client.FileReceiver.StopTransfer(transfer);
}
GameMain.Client.RequestFile(FileTransferType.CampaignSave, null, null);*/
campaign.PendingSaveID = saveID;
}
//we've got the latest save file
else if (!NetIdUtils.IdMoreRecent(saveID, campaign.lastSaveID))
{
campaign.Map.SetLocation(currentLocIndex == UInt16.MaxValue ? -1 : currentLocIndex);
campaign.Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex);
campaign.Money = money;
campaign.CargoManager.SetPurchasedItems(purchasedItems);
campaign.lastUpdateID = updateID;
}
}
#endif
public void ClientWrite(NetBuffer msg)
{
System.Diagnostics.Debug.Assert(map.Locations.Count < UInt16.MaxValue);
msg.Write(map.SelectedLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.SelectedLocationIndex);
msg.Write((UInt16)CargoManager.PurchasedItems.Count);
foreach (ItemPrefab ip in CargoManager.PurchasedItems)
{
msg.Write((UInt16)MapEntityPrefab.List.IndexOf(ip));
}
}
public void ServerRead(NetBuffer msg, Client sender) public void ServerRead(NetBuffer msg, Client sender)
{ {
UInt16 selectedLocIndex = msg.ReadUInt16(); UInt16 selectedLocIndex = msg.ReadUInt16();
@@ -134,7 +134,7 @@ namespace Barotrauma
break; break;
#endif #endif
case "multiplayercampaign": case "multiplayercampaign":
GameMode = MultiplayerCampaign.LoadNew(subElement); GameMode = MultiPlayerCampaign.LoadNew(subElement);
break; break;
} }
} }
@@ -303,7 +303,7 @@ namespace Barotrauma
break; break;
#endif #endif
case "multiplayercampaign": case "multiplayercampaign":
MultiplayerCampaign mpCampaign = GameMode as MultiplayerCampaign; MultiPlayerCampaign mpCampaign = GameMode as MultiPlayerCampaign;
if (mpCampaign == null) if (mpCampaign == null)
{ {
DebugConsole.ThrowError("Error while loading a save file: the save file is for a multiplayer campaign but the current gamemode is "+GameMode.GetType().ToString()); DebugConsole.ThrowError("Error while loading a save file: the save file is for a multiplayer campaign but the current gamemode is "+GameMode.GetType().ToString());
@@ -608,11 +608,11 @@ namespace Barotrauma.Networking
byte campaignID = inc.ReadByte(); byte campaignID = inc.ReadByte();
c.LastRecvCampaignUpdate = inc.ReadUInt16(); c.LastRecvCampaignUpdate = inc.ReadUInt16();
if (GameMain.GameSession?.GameMode is MultiplayerCampaign) if (GameMain.GameSession?.GameMode is MultiPlayerCampaign)
{ {
//the client has a campaign save for another campaign //the client has a campaign save for another campaign
//(the server started a new campaign and the client isn't aware of it yet?) //(the server started a new campaign and the client isn't aware of it yet?)
if (((MultiplayerCampaign)GameMain.GameSession.GameMode).CampaignID != campaignID) if (((MultiPlayerCampaign)GameMain.GameSession.GameMode).CampaignID != campaignID)
{ {
c.LastRecvCampaignSave = 0; c.LastRecvCampaignSave = 0;
c.LastRecvCampaignUpdate = 0; c.LastRecvCampaignUpdate = 0;
@@ -804,7 +804,7 @@ namespace Barotrauma.Networking
var modeList = GameMain.NetLobbyScreen.SelectedModeIndex = modeIndex; var modeList = GameMain.NetLobbyScreen.SelectedModeIndex = modeIndex;
break; break;
case ClientPermissions.ManageCampaign: case ClientPermissions.ManageCampaign:
MultiplayerCampaign campaign = GameMain.GameSession.GameMode as MultiplayerCampaign; MultiPlayerCampaign campaign = GameMain.GameSession.GameMode as MultiPlayerCampaign;
if (campaign != null) if (campaign != null)
{ {
campaign.ServerRead(inc, sender); campaign.ServerRead(inc, sender);
@@ -839,7 +839,7 @@ namespace Barotrauma.Networking
ClientWriteLobby(c); ClientWriteLobby(c);
MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
if (campaign != null && NetIdUtils.IdMoreRecent(campaign.LastSaveID, c.LastRecvCampaignSave)) if (campaign != null && NetIdUtils.IdMoreRecent(campaign.LastSaveID, c.LastRecvCampaignSave))
{ {
if (!fileSender.ActiveTransfers.Any(t => t.Connection == c.Connection && t.FileType == FileTransferType.CampaignSave)) if (!fileSender.ActiveTransfers.Any(t => t.Connection == c.Connection && t.FileType == FileTransferType.CampaignSave))
@@ -1013,7 +1013,7 @@ namespace Barotrauma.Networking
outmsg.WritePadBits(); outmsg.WritePadBits();
} }
var campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
if (campaign != null) if (campaign != null)
{ {
if (NetIdUtils.IdMoreRecent(campaign.LastUpdateID, c.LastRecvCampaignUpdate)) if (NetIdUtils.IdMoreRecent(campaign.LastUpdateID, c.LastRecvCampaignUpdate))
@@ -1202,8 +1202,8 @@ namespace Barotrauma.Networking
int teamCount = 1; int teamCount = 1;
byte hostTeam = 1; byte hostTeam = 1;
MultiplayerCampaign campaign = GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ? MultiPlayerCampaign campaign = GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ?
GameMain.GameSession?.GameMode as MultiplayerCampaign : null; GameMain.GameSession?.GameMode as MultiPlayerCampaign : null;
//don't instantiate a new gamesession if we're playing a campaign //don't instantiate a new gamesession if we're playing a campaign
if (campaign == null || GameMain.GameSession == null) if (campaign == null || GameMain.GameSession == null)
@@ -1398,7 +1398,7 @@ namespace Barotrauma.Networking
msg.Write(selectedMode.Name); msg.Write(selectedMode.Name);
MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
bool missionAllowRespawn = campaign == null && bool missionAllowRespawn = campaign == null &&
(!(GameMain.GameSession.GameMode is MissionMode) || (!(GameMain.GameSession.GameMode is MissionMode) ||