Progress on multiplayer campaign:

- Moved SaveUtils to the shared project.
- Moved the "new game"/"load game" menu logic to a separate class.
- Somewhat functional campaign UI in the server lobby (only the map view is usable atm though).
This commit is contained in:
Joonas Rikkonen
2017-08-31 18:53:37 +03:00
parent c7ae91da42
commit c1f5e3cbda
18 changed files with 856 additions and 601 deletions
@@ -0,0 +1,210 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Barotrauma
{
class CampaignSetupUI
{
private GUIComponent newGameContainer, loadGameContainer;
private GUIListBox subList;
private GUIListBox saveList;
private GUITextBox saveNameBox, seedBox;
public Action<Submarine, string, string> StartNewGame;
public Action<string> LoadGame;
private bool isMultiplayer;
public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer)
{
this.isMultiplayer = isMultiplayer;
this.newGameContainer = newGameContainer;
this.loadGameContainer = loadGameContainer;
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Selected submarine:", null, null, Alignment.Left, "", newGameContainer);
subList = new GUIListBox(new Rectangle(0, 30, 230, newGameContainer.Rect.Height - 100), "", newGameContainer);
UpdateSubList();
new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 0, 100, 20),
"Save name: ", "", Alignment.Left, Alignment.Left, newGameContainer);
saveNameBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 30, 180, 20),
Alignment.TopLeft, "", newGameContainer);
new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 60, 100, 20),
"Map Seed: ", "", Alignment.Left, Alignment.Left, newGameContainer);
seedBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 90, 180, 20),
Alignment.TopLeft, "", newGameContainer);
seedBox.Text = ToolBox.RandomSeed(8);
var startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.BottomRight, "", newGameContainer);
startButton.OnClicked = (GUIButton btn, object userData) =>
{
if (string.IsNullOrWhiteSpace(saveNameBox.Text))
{
saveNameBox.Flash(Color.Red);
return false;
}
Submarine selectedSub = subList.SelectedData as Submarine;
if (selectedSub != null && selectedSub.HasTag(SubmarineTag.Shuttle))
{
var msgBox = new GUIMessageBox("Shuttle selected",
"Most shuttles are not adequately equipped to deal with the dangers of the Europan depths. " +
"Are you sure you want to choose a shuttle as your vessel?",
new string[] { "Yes", "No" });
msgBox.Buttons[0].OnClicked = (button, obj) => { StartNewGame?.Invoke(selectedSub, saveNameBox.Text, seedBox.Text); return true; };
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = msgBox.Close;
return false;
}
StartNewGame?.Invoke(selectedSub, saveNameBox.Text, seedBox.Text);
return true;
};
UpdateLoadMenu();
}
public void CreateDefaultSaveName()
{
saveNameBox.Text = SaveUtil.CreateSavePath();
}
public void UpdateSubList()
{
var subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus));
subList.ClearChildren();
foreach (Submarine sub in subsToShow)
{
var textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
ToolBox.LimitString(sub.Name, GUI.Font, subList.Rect.Width - 65), "ListBoxElement",
Alignment.Left, Alignment.Left, subList)
{
Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f),
ToolTip = sub.Description,
UserData = sub
};
if (sub.HasTag(SubmarineTag.Shuttle))
{
textBlock.TextColor = textBlock.TextColor * 0.85f;
var shuttleText = new GUITextBlock(new Rectangle(0, 0, 0, 25), "Shuttle", "", Alignment.Left, Alignment.CenterY | Alignment.Right, textBlock, false, GUI.SmallFont);
shuttleText.TextColor = textBlock.TextColor * 0.8f;
shuttleText.ToolTip = textBlock.ToolTip;
}
}
if (Submarine.SavedSubmarines.Count > 0) subList.Select(Submarine.SavedSubmarines[0]);
}
public void UpdateLoadMenu()
{
loadGameContainer.ClearChildren();
string[] saveFiles = SaveUtil.GetSaveFiles(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer);
saveList = new GUIListBox(new Rectangle(0, 0, 200, loadGameContainer.Rect.Height - 80), Color.White, "", loadGameContainer);
saveList.OnSelected = SelectSaveFile;
foreach (string saveFile in saveFiles)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
Path.GetFileNameWithoutExtension(saveFile),
"ListBoxElement",
Alignment.Left,
Alignment.Left,
saveList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = saveFile;
}
var button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.Right | Alignment.Bottom, "", loadGameContainer);
button.OnClicked = (btn, obj) => { LoadGame?.Invoke(saveList.SelectedData as string); return true; };
}
private bool SelectSaveFile(GUIComponent component, object obj)
{
string fileName = (string)obj;
XDocument doc = SaveUtil.LoadGameSessionDoc(fileName);
if (doc == null)
{
DebugConsole.ThrowError("Error loading save file \"" + fileName + "\". The file may be corrupted.");
return false;
}
RemoveSaveFrame();
string subName = ToolBox.GetAttributeString(doc.Root, "submarine", "");
string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown");
string mapseed = ToolBox.GetAttributeString(doc.Root, "mapseed", "unknown");
GUIFrame saveFileFrame = new GUIFrame(new Rectangle((int)(saveList.Rect.Width + 20), 0, 200, 230), Color.Black * 0.4f, "", loadGameContainer);
saveFileFrame.UserData = "savefileframe";
saveFileFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
new GUITextBlock(new Rectangle(0, 0, 0, 20), Path.GetFileNameWithoutExtension(fileName), "", Alignment.TopLeft, Alignment.TopLeft, saveFileFrame, false, GUI.LargeFont);
new GUITextBlock(new Rectangle(0, 35, 0, 20), "Submarine: ", "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 52, 0, 20), subName, "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(0, 70, 0, 20), "Last saved: ", "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 85, 0, 20), saveTime, "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(0, 105, 0, 20), "Map seed: ", "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 120, 0, 20), mapseed, "", saveFileFrame).Font = GUI.SmallFont;
var deleteSaveButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Delete", Alignment.BottomCenter, "", saveFileFrame);
deleteSaveButton.UserData = fileName;
deleteSaveButton.OnClicked = DeleteSave;
return true;
}
private bool DeleteSave(GUIButton button, object obj)
{
string saveFile = obj as string;
if (obj == null) return false;
SaveUtil.DeleteSave(saveFile);
UpdateLoadMenu();
return true;
}
private void RemoveSaveFrame()
{
GUIComponent prevFrame = null;
foreach (GUIComponent child in loadGameContainer.children)
{
if (child.UserData as string != "savefileframe") continue;
prevFrame = child;
break;
}
loadGameContainer.RemoveChild(prevFrame);
}
}
}
@@ -29,7 +29,7 @@ namespace Barotrauma
private Level selectedLevel;
float mapZoom = 3.0f;
private float mapZoom = 3.0f;
public Action StartRound;
public Action<Location, LocationConnection> OnLocationSelected;
@@ -126,12 +126,11 @@ namespace Barotrauma
x += 110;
}
SelectTab(Tab.Crew);
SelectTab(Tab.Map);
GameMain.GameSession.Map.OnLocationSelected += SelectLocation;
}
private void UpdateLocationTab(Location location)
{
if (location.HireManager == null)
@@ -163,11 +162,14 @@ namespace Barotrauma
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
GameMain.GameSession.Map.Update((float)deltaTime, new Rectangle(
tabs[(int)selectedTab].Rect.X + 20,
tabs[(int)selectedTab].Rect.Y + 20,
tabs[(int)selectedTab].Rect.Width - 310,
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
if (GameMain.GameSession?.Map != null)
{
GameMain.GameSession.Map.Update(deltaTime, new Rectangle(
tabs[(int)selectedTab].Rect.X + 20,
tabs[(int)selectedTab].Rect.Y + 20,
tabs[(int)selectedTab].Rect.Width - 310,
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
}
}
public void Draw(SpriteBatch spriteBatch)
@@ -179,7 +181,7 @@ namespace Barotrauma
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
*/
if (selectedTab == Tab.Map)
if (selectedTab == Tab.Map && GameMain.GameSession?.Map != null)
{
GameMain.GameSession.Map.Draw(spriteBatch, new Rectangle(
tabs[(int)selectedTab].Rect.X + 20,
@@ -278,17 +280,15 @@ namespace Barotrauma
if (location == null) return;
new GUITextBlock(new Rectangle(0, 0, 250, 0), location.Name, "", Alignment.TopLeft, Alignment.TopCenter, locationPanel, true, GUI.LargeFont);
var titleText = new GUITextBlock(new Rectangle(0, 0, 250, 0), location.Name, "", Alignment.TopLeft, Alignment.TopCenter, locationPanel, true, GUI.LargeFont);
if (GameMain.GameSession.Map.SelectedConnection != null && GameMain.GameSession.Map.SelectedConnection.Mission != null)
{
var mission = GameMain.GameSession.Map.SelectedConnection.Mission;
new GUITextBlock(new Rectangle(0, 80, 0, 20), "Mission: " + mission.Name, "", locationPanel);
new GUITextBlock(new Rectangle(0, 100, 0, 20), "Reward: " + mission.Reward + " credits", "", locationPanel);
new GUITextBlock(new Rectangle(0, 130, 0, 0), mission.Description, "", locationPanel, true);
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 20, 0, 20), "Mission: " + mission.Name, "", locationPanel);
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 40, 0, 20), "Reward: " + mission.Reward + " credits", "", locationPanel);
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 70, 0, 0), mission.Description, "", Alignment.TopLeft, Alignment.TopLeft, locationPanel, true, GUI.SmallFont);
}
startButton.Enabled = true;
@@ -11,15 +11,12 @@ namespace Barotrauma
class MainMenuScreen : Screen
{
public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3, Settings = 4 }
GUIFrame buttonsTab;
private GUIFrame buttonsTab;
private GUIFrame[] menuTabs;
private GUIListBox subList;
private GUIListBox saveList;
private GUITextBox saveNameBox, seedBox;
private CampaignSetupUI campaignSetupUI;
private GUITextBox serverNameBox, portBox, passwordBox, maxPlayersBox;
private GUITickBox isPublicBox, useUpnpBox;
@@ -30,12 +27,10 @@ namespace Barotrauma
public MainMenuScreen(GameMain game)
{
menuTabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length+1];
menuTabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length + 1];
buttonsTab = new GUIFrame(new Rectangle(0,0,0,0), Color.Transparent, Alignment.Left | Alignment.CenterY);
buttonsTab = new GUIFrame(new Rectangle(0, 0, 0, 0), Color.Transparent, Alignment.Left | Alignment.CenterY);
buttonsTab.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
//menuTabs[(int)Tabs.Main].Padding = GUI.style.smallPadding;
int y = (int)(GameMain.GraphicsHeight * 0.3f);
@@ -86,62 +81,17 @@ namespace Barotrauma
//----------------------------------------------------------------------
menuTabs[(int)Tab.NewGame] = new GUIFrame(panelRect, "");
menuTabs[(int)Tab.NewGame].Padding = new Vector4(20.0f,20.0f,20.0f,20.0f);
//new GUITextBlock(new Rectangle(0, -20, 0, 30), "New Game", null, null, Alignment.CenterX, "", menuTabs[(int)Tabs.NewGame]);
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Selected submarine:", null, null, Alignment.Left, "", menuTabs[(int)Tab.NewGame]);
subList = new GUIListBox(new Rectangle(0, 30, 230, panelRect.Height-100), "", menuTabs[(int)Tab.NewGame]);
UpdateSubList();
new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 0, 100, 20),
"Save name: ", "", Alignment.Left, Alignment.Left, menuTabs[(int)Tab.NewGame]);
saveNameBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 30, 180, 20),
Alignment.TopLeft, "", menuTabs[(int)Tab.NewGame]);
new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 60, 100, 20),
"Map Seed: ", "", Alignment.Left, Alignment.Left, menuTabs[(int)Tab.NewGame]);
seedBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 90, 180, 20),
Alignment.TopLeft, "", menuTabs[(int)Tab.NewGame]);
seedBox.Text = ToolBox.RandomSeed(8);
button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.BottomRight, "", menuTabs[(int)Tab.NewGame]);
button.OnClicked = (GUIButton btn, object userData) =>
{
Submarine selectedSub = subList.SelectedData as Submarine;
if (selectedSub != null && selectedSub.HasTag(SubmarineTag.Shuttle))
{
var msgBox = new GUIMessageBox("Shuttle selected",
"Most shuttles are not adequately equipped to deal with the dangers of the Europan depths. "+
"Are you sure you want to choose a shuttle as your vessel?",
new string[] {"Yes", "No"});
msgBox.Buttons[0].OnClicked = StartGame;
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = msgBox.Close;
return false;
}
StartGame(btn, userData);
return true;
};
//----------------------------------------------------------------------
menuTabs[(int)Tab.NewGame].Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
menuTabs[(int)Tab.LoadGame] = new GUIFrame(panelRect, "");
//menuTabs[(int)Tabs.LoadGame].Padding = GUI.style.smallPadding;
campaignSetupUI = new CampaignSetupUI(false, menuTabs[(int)Tab.NewGame], menuTabs[(int)Tab.LoadGame]);
campaignSetupUI.LoadGame = LoadGame;
campaignSetupUI.StartNewGame = StartGame;
//----------------------------------------------------------------------
menuTabs[(int)Tab.HostServer] = new GUIFrame(panelRect, "");
//menuTabs[(int)Tabs.JoinServer].Padding = GUI.style.smallPadding;
//new GUITextBlock(new Rectangle(0, -25, 0, 30), "Host Server", "", Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer], false, GUI.LargeFont);
new GUITextBlock(new Rectangle(0, 0, 100, 30), "Server Name:", "", Alignment.TopLeft, Alignment.Left, menuTabs[(int)Tab.HostServer]);
serverNameBox = new GUITextBox(new Rectangle(160, 0, 200, 30), null, null, Alignment.TopLeft, Alignment.Left, "", menuTabs[(int)Tab.HostServer]);
@@ -194,41 +144,11 @@ namespace Barotrauma
Submarine.Unload();
UpdateSubList();
campaignSetupUI.UpdateSubList();
SelectTab(null, 0);
}
private void UpdateSubList()
{
var subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus));
subList.ClearChildren();
foreach (Submarine sub in subsToShow)
{
var textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
ToolBox.LimitString(sub.Name, GUI.Font, subList.Rect.Width - 65), "ListBoxElement",
Alignment.Left, Alignment.Left, subList)
{
Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f),
ToolTip = sub.Description,
UserData = sub
};
if (sub.HasTag(SubmarineTag.Shuttle))
{
textBlock.TextColor = textBlock.TextColor * 0.85f;
var shuttleText = new GUITextBlock(new Rectangle(0, 0, 0, 25), "Shuttle", "", Alignment.Left, Alignment.CenterY | Alignment.Right, textBlock, false, GUI.SmallFont);
shuttleText.TextColor = textBlock.TextColor * 0.8f;
shuttleText.ToolTip = textBlock.ToolTip;
}
}
if (Submarine.SavedSubmarines.Count > 0) subList.Select(Submarine.SavedSubmarines[0]);
}
public bool SelectTab(GUIButton button, object obj)
{
try
@@ -276,10 +196,10 @@ namespace Barotrauma
switch (selectedTab)
{
case Tab.NewGame:
saveNameBox.Text = SaveUtil.CreateSavePath();
campaignSetupUI.CreateDefaultSaveName();
break;
case Tab.LoadGame:
UpdateLoadScreen();
campaignSetupUI.UpdateLoadMenu();
break;
case Tab.Settings:
GameMain.Config.ResetSettingsFrame();
@@ -379,99 +299,6 @@ namespace Barotrauma
return true;
}
private void UpdateLoadScreen()
{
menuTabs[(int)Tab.LoadGame].ClearChildren();
string[] saveFiles = SaveUtil.GetSaveFiles();
saveList = new GUIListBox(new Rectangle(0, 0, 200, menuTabs[(int)Tab.LoadGame].Rect.Height - 80), Color.White, "", menuTabs[(int)Tab.LoadGame]);
saveList.OnSelected = SelectSaveFile;
foreach (string saveFile in saveFiles)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
saveFile,
"ListBoxElement",
Alignment.Left,
Alignment.Left,
saveList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = saveFile;
}
var button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.Right | Alignment.Bottom, "", menuTabs[(int)Tab.LoadGame]);
button.OnClicked = LoadGame;
}
private bool SelectSaveFile(GUIComponent component, object obj)
{
string fileName = (string)obj;
XDocument doc = SaveUtil.LoadGameSessionDoc(fileName);
if (doc==null)
{
DebugConsole.ThrowError("Error loading save file \""+fileName+"\". The file may be corrupted.");
return false;
}
RemoveSaveFrame();
string subName = ToolBox.GetAttributeString(doc.Root, "submarine", "");
string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown");
string mapseed = ToolBox.GetAttributeString(doc.Root, "mapseed", "unknown");
GUIFrame saveFileFrame = new GUIFrame(new Rectangle((int)(saveList.Rect.Width + 20), 0, 200, 230), Color.Black*0.4f, "", menuTabs[(int)Tab.LoadGame]);
saveFileFrame.UserData = "savefileframe";
saveFileFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
new GUITextBlock(new Rectangle(0,0,0,20), fileName, "", Alignment.TopLeft, Alignment.TopLeft, saveFileFrame, false, GUI.LargeFont);
new GUITextBlock(new Rectangle(0, 35, 0, 20), "Submarine: ", "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 52, 0, 20), subName, "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(0, 70, 0, 20), "Last saved: ", "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 85, 0, 20), saveTime, "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(0, 105, 0, 20), "Map seed: ", "", saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 120, 0, 20), mapseed, "", saveFileFrame).Font = GUI.SmallFont;
var deleteSaveButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Delete", Alignment.BottomCenter, "", saveFileFrame);
deleteSaveButton.UserData = fileName;
deleteSaveButton.OnClicked = DeleteSave;
return true;
}
private bool DeleteSave(GUIButton button, object obj)
{
string saveFile = obj as string;
if (obj == null) return false;
SaveUtil.DeleteSave(saveFile);
UpdateLoadScreen();
return true;
}
private void RemoveSaveFrame()
{
GUIComponent prevFrame = null;
foreach (GUIComponent child in menuTabs[(int)Tab.LoadGame].children)
{
if (child.UserData as string != "savefileframe") continue;
prevFrame = child;
break;
}
menuTabs[(int)Tab.LoadGame].RemoveChild(prevFrame);
}
public override void AddToGUIUpdateList()
{
@@ -513,53 +340,42 @@ namespace Barotrauma
spriteBatch.End();
}
private bool StartGame(GUIButton button, object userData)
private void StartGame(Submarine selectedSub, string saveName, string mapSeed)
{
if (string.IsNullOrEmpty(saveNameBox.Text)) return false;
if (string.IsNullOrEmpty(saveName)) return;
string[] existingSaveFiles = SaveUtil.GetSaveFiles();
string[] existingSaveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Singleplayer);
if (Array.Find(existingSaveFiles, s => s == saveNameBox.Text)!=null)
if (Array.Find(existingSaveFiles, s => s == saveName) != null)
{
new GUIMessageBox("Save name already in use", "Please choose another name for the save file");
return false;
return;
}
Submarine selectedSub = subList.SelectedData as Submarine;
if (selectedSub == null)
{
new GUIMessageBox("Submarine not selected", "Please select a submarine");
return false;
return;
}
if (!Directory.Exists(SaveUtil.TempPath))
{
Directory.CreateDirectory(SaveUtil.TempPath);
}
File.Copy(selectedSub.FilePath, Path.Combine(SaveUtil.TempPath, selectedSub.Name+".sub"), true);
File.Copy(selectedSub.FilePath, Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"), true);
selectedSub = new Submarine(Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"), "");
GameMain.GameSession = new GameSession(selectedSub, saveNameBox.Text, GameModePreset.list.Find(gm => gm.Name == "Single Player"));
(GameMain.GameSession.GameMode as CampaignMode).GenerateMap(seedBox.Text);
GameMain.GameSession = new GameSession(selectedSub, saveName, GameModePreset.list.Find(gm => gm.Name == "Single Player"));
(GameMain.GameSession.GameMode as CampaignMode).GenerateMap(mapSeed);
GameMain.LobbyScreen.Select();
return true;
}
private bool PreviousTab(GUIButton button, object obj)
private void LoadGame(string saveFile)
{
//selectedTab = (int)Tabs.Main;
return true;
}
private bool LoadGame(GUIButton button, object obj)
{
string saveFile = saveList.SelectedData as string;
if (string.IsNullOrWhiteSpace(saveFile)) return false;
if (string.IsNullOrWhiteSpace(saveFile)) return;
try
{
@@ -568,13 +384,11 @@ namespace Barotrauma
catch (Exception e)
{
DebugConsole.ThrowError("Loading save \""+saveFile+"\" failed", e);
return false;
return;
}
GameMain.LobbyScreen.Select();
return true;
}
}
@@ -34,6 +34,10 @@ namespace Barotrauma
private GUITextBox textBox, seedBox;
private GUIFrame defaultModeContainer, campaignContainer;
private GUIButton campaignViewButton;
private GUIFrame myPlayerFrame;
private GUIFrame jobInfoFrame;
@@ -44,6 +48,8 @@ namespace Barotrauma
private GUIDropDown shuttleList;
private CampaignUI campaignUI;
private Sprite backgroundSprite;
private GUITextBox serverMessage;
@@ -215,37 +221,43 @@ namespace Barotrauma
playerList = new GUIListBox(new Rectangle(0, 0, 0, 0), null, "", playerListFrame);
playerList.OnSelected = SelectPlayer;
defaultModeContainer = new GUIFrame(new Rectangle(0, 10, 0, 0), null, infoFrame);
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 ------------------------------------------------------------------
int columnWidth = infoFrame.Rect.Width / 3 - 5;
int columnX = 0;
new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Submarine:", "", infoFrame);
subList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, infoFrame.Rect.Height - 150 - 80), Color.White, "", infoFrame);
new GUITextBlock(new Rectangle(columnX, 110, columnWidth, 30), "Submarine:", "", defaultModeContainer);
subList = new GUIListBox(new Rectangle(columnX, 140, columnWidth, defaultModeContainer.Rect.Height - 170), Color.White, "", defaultModeContainer);
subList.OnSelected = VotableClicked;
var voteText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Votes: ", "", Alignment.TopLeft, Alignment.TopRight, infoFrame);
var voteText = new GUITextBlock(new Rectangle(columnX, 110, columnWidth, 30), "Votes: ", "", Alignment.TopLeft, Alignment.TopRight, defaultModeContainer);
voteText.UserData = "subvotes";
voteText.Visible = false;
//UpdateSubList(Submarine.SavedSubmarines);
columnX += columnWidth + 20;
//respawn shuttle ------------------------------------------------------------------
new GUITextBlock(new Rectangle(columnX, 120, 20, 20), "Respawn shuttle:", "", infoFrame);
shuttleList = new GUIDropDown(new Rectangle(columnX, 150, 200, 20), "", "", infoFrame);
new GUITextBlock(new Rectangle(columnX, 110, 20, 20), "Respawn shuttle:", "", defaultModeContainer);
shuttleList = new GUIDropDown(new Rectangle(columnX, 140, 200, 20), "", "", defaultModeContainer);
//gamemode ------------------------------------------------------------------
new GUITextBlock(new Rectangle(columnX, 180, 0, 30), "Game mode: ", "", infoFrame);
modeList = new GUIListBox(new Rectangle(columnX, 200, columnWidth, infoFrame.Rect.Height - 300), "", infoFrame);
new GUITextBlock(new Rectangle(columnX, 170, 0, 30), "Game mode: ", "", defaultModeContainer);
modeList = new GUIListBox(new Rectangle(columnX, 200, columnWidth, defaultModeContainer.Rect.Height - 230), "", defaultModeContainer);
modeList.OnSelected = VotableClicked;
voteText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Votes: ", "", Alignment.TopLeft, Alignment.TopRight, infoFrame);
voteText = new GUITextBlock(new Rectangle(columnX, 170, columnWidth, 30), "Votes: ", "", Alignment.TopLeft, Alignment.TopRight, defaultModeContainer);
voteText.UserData = "modevotes";
voteText.Visible = false;
@@ -265,7 +277,7 @@ namespace Barotrauma
//mission type ------------------------------------------------------------------
missionTypeBlock = new GUITextBlock(new Rectangle(columnX, -10, 300, 20), "Mission type:", "", Alignment.BottomLeft, Alignment.CenterLeft, infoFrame);
missionTypeBlock = new GUITextBlock(new Rectangle(columnX, -10, 300, 20), "Mission type:", "", Alignment.BottomLeft, Alignment.CenterLeft, defaultModeContainer);
missionTypeBlock.Padding = Vector4.Zero;
missionTypeBlock.UserData = 0;
@@ -296,46 +308,46 @@ namespace Barotrauma
//seed ------------------------------------------------------------------
new GUITextBlock(new Rectangle(columnX, 120, 180, 20),
"Level Seed: ", "", Alignment.Left, Alignment.TopLeft, infoFrame);
new GUITextBlock(new Rectangle(columnX, 110, 180, 20),
"Level Seed: ", "", Alignment.Left, Alignment.TopLeft, defaultModeContainer);
seedBox = new GUITextBox(new Rectangle(columnX, 150, columnWidth / 2, 20),
Alignment.TopLeft, "", infoFrame);
seedBox = new GUITextBox(new Rectangle(columnX, 140, columnWidth / 2, 20),
Alignment.TopLeft, "", defaultModeContainer);
seedBox.OnTextChanged = SelectSeed;
LevelSeed = ToolBox.RandomSeed(8);
//traitor probability ------------------------------------------------------------------
new GUITextBlock(new Rectangle(columnX, 180, 20, 20), "Traitors:", "", infoFrame);
new GUITextBlock(new Rectangle(columnX, 170, 20, 20), "Traitors:", "", defaultModeContainer);
traitorProbabilityButtons = new GUIButton[2];
traitorProbabilityButtons[0] = new GUIButton(new Rectangle(columnX, 205, 20, 20), "<", "", infoFrame);
traitorProbabilityButtons[0] = new GUIButton(new Rectangle(columnX, 195, 20, 20), "<", "", defaultModeContainer);
traitorProbabilityButtons[0].UserData = -1;
traitorProbabilityText = new GUITextBlock(new Rectangle(columnX + 20, 205, 80, 20), "No", null, null, Alignment.Center, "", infoFrame);
traitorProbabilityText = new GUITextBlock(new Rectangle(columnX + 20, 195, 80, 20), "No", null, null, Alignment.Center, "", defaultModeContainer);
traitorProbabilityButtons[1] = new GUIButton(new Rectangle(columnX + 100, 205, 20, 20), ">", "", infoFrame);
traitorProbabilityButtons[1] = new GUIButton(new Rectangle(columnX + 100, 195, 20, 20), ">", "", defaultModeContainer);
traitorProbabilityButtons[1].UserData = 1;
//automatic restart ------------------------------------------------------------------
autoRestartBox = new GUITickBox(new Rectangle(columnX, 240, 20, 20), "Automatic restart", Alignment.TopLeft, infoFrame);
autoRestartBox = new GUITickBox(new Rectangle(columnX, 230, 20, 20), "Automatic restart", Alignment.TopLeft, defaultModeContainer);
autoRestartBox.OnSelected = ToggleAutoRestart;
var restartText = new GUITextBlock(new Rectangle(columnX, 265, 20, 20), "", "", infoFrame);
var restartText = new GUITextBlock(new Rectangle(columnX, 255, 20, 20), "", "", defaultModeContainer);
restartText.Font = GUI.SmallFont;
restartText.TextGetter = AutoRestartText;
//server info ------------------------------------------------------------------
var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, "", infoFrame);
var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, "", defaultModeContainer);
serverName.TextGetter = GetServerName;
serverName.Enabled = GameMain.Server != null;
serverName.OnTextChanged = ChangeServerName;
serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, "", infoFrame);
serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, "", defaultModeContainer);
serverMessage.Wrap = true;
serverMessage.OnTextChanged = UpdateServerMessage;
@@ -422,10 +434,14 @@ namespace Barotrauma
missionTypeButtons[0].OnClicked = ToggleMissionType;
missionTypeButtons[1].OnClicked = ToggleMissionType;
StartButton = new GUIButton(new Rectangle(0, 0, 80, 30), "Start", Alignment.BottomRight, "", infoFrame);
StartButton = new GUIButton(new Rectangle(0, 0, 80, 30), "Start", Alignment.BottomRight, "", defaultModeContainer);
StartButton.OnClicked = GameMain.Server.StartGameClicked;
GUIButton settingsButton = new GUIButton(new Rectangle(-100, 0, 80, 30), "Settings", Alignment.BottomRight, "", infoFrame);
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;
settingsButton.UserData = "settingsButton";
@@ -983,6 +999,12 @@ namespace Barotrauma
menu.Update((float)deltaTime);
}
if (campaignContainer.Visible && campaignUI != null)
{
campaignContainer.Update((float)deltaTime);
campaignUI.Update((float)deltaTime);
}
if (autoRestartTimer != 0.0f && autoRestartBox.Selected)
{
autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f);
@@ -1009,6 +1031,11 @@ namespace Barotrauma
if (playerFrame != null) playerFrame.Draw(spriteBatch);
if (campaignContainer.Visible && campaignUI != null)
{
campaignUI.Draw(spriteBatch);
}
GUI.Draw((float)deltaTime, spriteBatch, null);
spriteBatch.End();
@@ -1071,27 +1098,50 @@ namespace Barotrauma
{
modeList.Select(modeIndex, true);
ToggleCampaignMode(SelectedMode.Name == "Campaign");
missionTypeBlock.Visible = SelectedMode != null && SelectedMode.Name == "Mission";
}
private bool SelectMode(GUIComponent component, object obj)
{
if (GameMain.NetworkMember == null) return false;
//if (GameMain.Server==null)
//{
// return VotableClicked(component, obj);
//}
GameModePreset modePreset = obj as GameModePreset;
if (modePreset == null) return false;
missionTypeBlock.Visible = modePreset.Name == "Mission";
lastUpdateID++;
if (modePreset.Name == "Campaign")
{
MultiplayerCampaign.StartCampaignSetup();
}
lastUpdateID++;
return true;
}
public void ToggleCampaignView(bool enabled)
{
defaultModeContainer.Visible = !enabled;
StartButton.Visible = !enabled;
campaignContainer.Visible = enabled;
}
public void ToggleCampaignMode(bool enabled)
{
StartButton.Visible = !enabled;
campaignViewButton.Visible = enabled;
ToggleCampaignView(enabled);
if (enabled && campaignUI == null)
{
campaignUI = new CampaignUI(GameMain.GameSession.GameMode as CampaignMode, campaignContainer);
campaignUI.StartRound = () => { GameMain.Server.StartGame(); };
}
}
private bool SelectSeed(GUITextBox textBox, string seed)
{
if (GameMain.Server == null) return false;
@@ -1102,26 +1152,7 @@ namespace Barotrauma
return true;
}
//private bool ChangeCharacterName(GUITextBox textBox, string newName)
//{
// if (string.IsNullOrEmpty(newName)) return false;
// if (GameMain.NetworkMember == null || GameMain.NetworkMember.CharacterInfo == null) return true;
// GameMain.NetworkMember.CharacterInfo.Name = newName;
// if (GameMain.Client != null)
// {
// GameMain.Client.Name = newName;
// GameMain.Client.SendCharacterData();
// }
// textBox.Text = newName;
// textBox.Selected = false;
// return true;
//}
private bool ViewJobInfo(GUIButton button, object obj)
{
GUIComponent jobText = button.Parent;