2f107db...5202af9

This commit is contained in:
Joonas Rikkonen
2019-03-18 21:42:26 +02:00
parent 58c92888b7
commit 044fd3344b
395 changed files with 27417 additions and 19754 deletions
@@ -1,6 +1,7 @@
using Barotrauma.Tutorials;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
@@ -32,7 +33,7 @@ namespace Barotrauma
private bool isMultiplayer;
public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer)
public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable<string> saveFiles=null)
{
this.isMultiplayer = isMultiplayer;
this.newGameContainer = newGameContainer;
@@ -70,7 +71,7 @@ namespace Barotrauma
if (!isMultiplayer)
{
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), "Tutorial active" + ":", textAlignment: Alignment.BottomLeft);
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("TutorialActive") + ":", textAlignment: Alignment.BottomLeft);
contextualTutorialBox = new GUITickBox(new RectTransform(new Point(30, 30), rightColumn.RectTransform), string.Empty);
UpdateTutorialSelection();
}
@@ -112,7 +113,14 @@ namespace Barotrauma
msgBox.Buttons[0].OnClicked = msgBox.Close;
msgBox.Buttons[0].OnClicked += (button, obj) =>
{
if (GUIMessageBox.MessageBoxes.Count == 0) StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
if (GUIMessageBox.MessageBoxes.Count == 0)
{
StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
if (isMultiplayer)
{
CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
}
}
return true;
};
@@ -125,7 +133,15 @@ namespace Barotrauma
TextManager.Get("ShuttleWarning"),
new string[] { TextManager.Get("Yes"), TextManager.Get("No") });
msgBox.Buttons[0].OnClicked = (button, obj) => { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); return true; };
msgBox.Buttons[0].OnClicked = (button, obj) =>
{
StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
if (isMultiplayer)
{
CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
}
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = msgBox.Close;
@@ -135,13 +151,40 @@ namespace Barotrauma
else
{
StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
if (isMultiplayer)
{
CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
}
}
return true;
}
};
UpdateLoadMenu();
UpdateLoadMenu(saveFiles);
}
private IEnumerable<object> WaitForCampaignSetup()
{
string headerText = TextManager.Get("CampaignStartingPleaseWait");
var msgBox = new GUIMessageBox(headerText, TextManager.Get("CampaignStarting"), new string[] { TextManager.Get("Cancel") });
msgBox.Buttons[0].OnClicked = (btn, userdata) =>
{
GameMain.NetLobbyScreen.SelectMode(0);
CoroutineManager.StopCoroutines("WaitForCampaignSetup");
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10);
while (GameMain.NetLobbyScreen.CampaignUI == null && DateTime.Now < timeOut)
{
msgBox.Header.Text = headerText + new string('.', ((int)Timing.TotalTime % 3 + 1));
yield return CoroutineStatus.Running;
}
msgBox.Close();
yield return CoroutineStatus.Success;
}
public void CreateDefaultSaveName()
@@ -211,12 +254,15 @@ namespace Barotrauma
}
}
public void UpdateLoadMenu()
public void UpdateLoadMenu(IEnumerable<string> saveFiles=null)
{
loadGameContainer.ClearChildren();
string[] saveFiles = SaveUtil.GetSaveFiles(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer);
if (saveFiles == null)
{
saveFiles = SaveUtil.GetSaveFiles(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer);
}
saveList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f), loadGameContainer.RectTransform, Anchor.CenterLeft))
{
OnSelected = SelectSaveFile
@@ -285,6 +331,10 @@ namespace Barotrauma
{
if (string.IsNullOrWhiteSpace(saveList.SelectedData as string)) return false;
LoadGame?.Invoke(saveList.SelectedData as string);
if (isMultiplayer)
{
CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
}
return true;
},
Enabled = false
@@ -39,6 +39,11 @@ namespace Barotrauma
public GUIComponent MapContainer { get; private set; }
public GUIButton StartButton
{
get { return startButton; }
}
public CampaignMode Campaign { get; }
public CampaignUI(CampaignMode campaign, GUIFrame container)
@@ -74,6 +79,7 @@ namespace Barotrauma
int i = 0;
var tabValues = Enum.GetValues(typeof(Tab));
float minTextScale = 1.0f;
foreach (Tab tab in tabValues)
{
var tabButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), tabButtonContainer.RectTransform),
@@ -90,9 +96,16 @@ namespace Barotrauma
(int)(tabButton.Rect.Height * (buttonSprite.Sprite.size.X / buttonSprite.Sprite.size.Y)), int.MaxValue);
tabButtons.Add(tabButton);
tabButton.Font = GUI.LargeFont;
tabButton.TextBlock.AutoScale = true;
minTextScale = Math.Min(tabButton.TextBlock.TextScale, minTextScale);
i++;
}
foreach (GUIButton tabButton in tabButtons)
{
tabButton.TextBlock.TextScale = minTextScale;
}
// crew tab -------------------------------------------------------------------------
tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length];
@@ -180,9 +193,10 @@ namespace Barotrauma
};
itemCategoryButtons.Add(categoryButton);
new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.25f), categoryButton.RectTransform, Anchor.BottomCenter),
new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.25f), categoryButton.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) },
TextManager.Get("MapEntityCategory." + category), textAlignment: Alignment.Center, textColor: categoryButton.TextColor)
{
Padding = Vector4.Zero,
AutoScale = true,
Color = Color.Transparent,
HoverColor = Color.Transparent,
@@ -374,13 +388,13 @@ namespace Barotrauma
{
AutoScale = true
};
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), container.RectTransform), location.Type.DisplayName);
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), container.RectTransform), location.Type.Name);
Sprite portrait = location.Type.GetPortrait(location.PortraitId);
new GUIImage(new RectTransform(new Vector2(1.0f, 0.6f),
container.RectTransform), portrait, scaleToFit: true);
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), container.RectTransform), "Select a mission", font: GUI.LargeFont)
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), container.RectTransform), TextManager.Get("SelectMission"), font: GUI.LargeFont)
{
AutoScale = true
};
@@ -424,7 +438,7 @@ namespace Barotrauma
};
missionTickBoxes.Add(tickBox);
}
GUITickBox.CreateRadioButtonGroup(missionTickBoxes);
RefreshMissionTab(selectedMission);
startButton = new GUIButton(new RectTransform(new Vector2(0.3f, 0.7f), missionContent.RectTransform, Anchor.CenterRight),
@@ -449,6 +463,11 @@ namespace Barotrauma
GameMain.GameSession.Map.CurrentLocation.SelectedMission = selectedMission;
foreach (GUITickBox missionTickBox in missionTickBoxes)
{
missionTickBox.Selected = missionTickBox.UserData == selectedMission;
}
selectedMissionInfo.ClearChildren();
var container = selectedMissionInfo.Content;
selectedMissionInfo.Visible = selectedMission != null;
@@ -485,13 +504,14 @@ namespace Barotrauma
ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;
GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Point(listBox.Rect.Width - 50, 25), frame.RectTransform, Anchor.CenterLeft)
GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Point(listBox.Rect.Width - (pi.Quantity > 0 ? 160 : 120), 25), frame.RectTransform, Anchor.CenterLeft)
{
AbsoluteOffset = new Point(40, 0)
AbsoluteOffset = new Point(40, 0),
}, pi.ItemPrefab.Name, font: font)
{
{
ToolTip = pi.ItemPrefab.Description
};
textBlock.Text = ToolBox.LimitString(textBlock.Text, textBlock.Font, textBlock.Rect.Width);
Sprite itemIcon = pi.ItemPrefab.InventoryIcon ?? pi.ItemPrefab.sprite;
@@ -504,13 +524,13 @@ namespace Barotrauma
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
}
textBlock = new GUITextBlock(new RectTransform(new Point(120, 25), frame.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(20, 0) },
priceInfo.BuyPrice.ToString(), font: font)
textBlock = new GUITextBlock(new RectTransform(new Point(60, 25), frame.RectTransform, Anchor.CenterRight)
{ AbsoluteOffset = new Point(pi.Quantity > 0 ? 70 : 25, 0) },
priceInfo.BuyPrice.ToString(), font: font, textAlignment: Alignment.CenterRight)
{
ToolTip = pi.ItemPrefab.Description
};
//If its the store menu, quantity will always be 0
if (pi.Quantity > 0)
{
File diff suppressed because it is too large Load Diff
@@ -38,11 +38,11 @@ namespace Barotrauma
};
#if LINUX || OSX
var blurEffect = content.Load<Effect>("Effects/blurshader_opengl");
//var blurEffect = content.Load<Effect>("Effects/blurshader_opengl");
damageEffect = content.Load<Effect>("Effects/damageshader_opengl");
postProcessEffect = content.Load<Effect>("Effects/postprocess_opengl");
#else
var blurEffect = content.Load<Effect>("Effects/blurshader");
//var blurEffect = content.Load<Effect>("Effects/blurshader");
damageEffect = content.Load<Effect>("Effects/damageshader");
postProcessEffect = content.Load<Effect>("Effects/postprocess");
#endif
@@ -56,6 +56,10 @@ namespace Barotrauma
postProcessEffect.Parameters["xDistortTexture"].SetValue(distortTexture);
}
distortTexture = TextureLoader.FromFile("Content/Effects/distortnormals.png");
postProcessEffect.Parameters["xDistortTexture"].SetValue(distortTexture);
}
private void CreateRenderTargets(GraphicsDevice graphics)
{
renderTarget?.Dispose();
@@ -356,9 +360,13 @@ namespace Barotrauma
postProcessTechnique += "Distort";
postProcessEffect.Parameters["distortScale"].SetValue(Vector2.One * DistortStrength);
postProcessEffect.Parameters["distortUvOffset"].SetValue(WaterRenderer.Instance.WavePos * 0.001f);
#if LINUX || OSX
postProcessEffect.Parameters["xTexture"].SetValue(distortTexture);
#else
postProcessEffect.Parameters["xTexture"].SetValue(renderTargetFinal);
#endif
}
if (string.IsNullOrEmpty(postProcessTechnique))
{
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None);
@@ -369,7 +377,11 @@ namespace Barotrauma
postProcessEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None, effect: postProcessEffect);
}
#if LINUX || OSX
spriteBatch.Draw(renderTargetFinal, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
#else
spriteBatch.Draw(DistortStrength > 0.0f ? distortTexture : renderTargetFinal, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
#endif
spriteBatch.End();
}
}
@@ -8,12 +8,15 @@ using System.IO;
using System.Collections.Generic;
using System.Linq;
using Barotrauma.Extensions;
using System.Diagnostics;
using Lidgren.Network;
using System.Threading;
namespace Barotrauma
{
class MainMenuScreen : Screen
{
public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3, Settings = 4, Tutorials = 5 }
public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3, Settings = 4, Tutorials = 5, JoinServer = 6, CharacterEditor = 7, SubmarineEditor = 8, QuickStartDev = 9, SteamWorkshop = 10 }
private GUIComponent buttonsParent;
@@ -30,6 +33,7 @@ namespace Barotrauma
private Tab selectedTab;
#region Creation
public MainMenuScreen(GameMain game)
{
buttonsParent = new GUILayoutGroup(new RectTransform(new Vector2(0.15f, 0.5f), parent: Frame.RectTransform, anchor: Anchor.BottomLeft)
@@ -46,61 +50,12 @@ namespace Barotrauma
#if DEBUG
new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform, Anchor.TopCenter, Pivot.BottomCenter) { AbsoluteOffset = new Point(0, -40) },
"Quickstart (dev)", style: "GUIButtonLarge", color: Color.Red)
{
{
IgnoreLayoutGroups = true,
UserData = Tab.QuickStartDev,
OnClicked = (tb, userdata) =>
{
Submarine selectedSub = null;
string subName = GameMain.Config.QuickStartSubmarineName;
if (!string.IsNullOrEmpty(subName))
{
DebugConsole.NewMessage($"Loading the predefined quick start sub \"{subName}\"", Color.White);
selectedSub = Submarine.SavedSubmarines.FirstOrDefault(s =>
s.Name.ToLower() == subName.ToLower());
if (selectedSub == null)
{
DebugConsole.NewMessage($"Cannot find a sub that matches the name \"{subName}\".", Color.Red);
}
}
if (selectedSub == null)
{
DebugConsole.NewMessage("Loading a random sub.", Color.White);
var subs = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.Shuttle) && !s.HasTag(SubmarineTag.HideInMenus));
selectedSub = subs.ElementAt(Rand.Int(subs.Count()));
}
var gamesession = new GameSession(
selectedSub,
"Data/Saves/test.xml",
GameModePreset.List.Find(gm => gm.Identifier == "devsandbox"),
missionPrefab: null);
//(gamesession.GameMode as SinglePlayerCampaign).GenerateMap(ToolBox.RandomSeed(8));
gamesession.StartRound(ToolBox.RandomSeed(8));
GameMain.GameScreen.Select();
string[] jobIdentifiers = new string[] { "captain", "engineer", "mechanic" };
for (int i = 0; i < 3; i++)
{
var spawnPoint = WayPoint.GetRandom(SpawnType.Human, null, Submarine.MainSub);
if (spawnPoint == null)
{
DebugConsole.ThrowError("No spawnpoints found in the selected submarine. Quickstart failed.");
GameMain.MainMenuScreen.Select();
return true;
}
var characterInfo = new CharacterInfo(
Character.HumanConfigFile,
jobPrefab: JobPrefab.List.Find(j => j.Identifier == jobIdentifiers[i]));
if (characterInfo.Job == null)
{
DebugConsole.ThrowError("Failed to find the job \"" + jobIdentifiers[i] + "\"!");
}
var newCharacter = Character.Create(Character.HumanConfigFile, spawnPoint.WorldPosition, ToolBox.RandomSeed(8), characterInfo);
newCharacter.GiveJobItems(spawnPoint);
gamesession.CrewManager.AddCharacter(newCharacter);
Character.Controlled = newCharacter;
}
SelectTab(tb, userdata);
return true;
}
};
@@ -121,24 +76,41 @@ namespace Barotrauma
new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("NewGameButton"), style: "GUIButtonLarge")
{
UserData = Tab.NewGame,
OnClicked = SelectTab
OnClicked = (tb, userdata) =>
{
SelectTab(tb, userdata);
return true;
}
};
new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("LoadGameButton"), style: "GUIButtonLarge")
{
UserData = Tab.LoadGame,
OnClicked = SelectTab
OnClicked = (tb, userdata) =>
{
SelectTab(tb, userdata);
return true;
}
};
new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), buttonsParent.RectTransform), style: null); //spacing
joinServerButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("JoinServerButton"), style: "GUIButtonLarge")
{
OnClicked = JoinServerClicked
UserData = Tab.JoinServer,
OnClicked = (tb, userdata) =>
{
SelectTab(tb, userdata);
return true;
}
};
hostServerButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("HostServerButton"), style: "GUIButtonLarge")
{
UserData = Tab.HostServer,
OnClicked = SelectTab
OnClicked = (tb, userdata) =>
{
SelectTab(tb, userdata);
return true;
}
};
@@ -146,15 +118,20 @@ namespace Barotrauma
new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("SubEditorButton"), style: "GUIButtonLarge")
{
OnClicked = (btn, userdata) => { GameMain.SubEditorScreen.Select(); return true; }
UserData = Tab.SubmarineEditor,
OnClicked = (tb, userdata) =>
{
SelectTab(tb, userdata);
return true;
}
};
new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("CharacterEditorButton"), style: "GUIButtonLarge")
{
OnClicked = (btn, userdata) =>
UserData = Tab.CharacterEditor,
OnClicked = (tb, userdata) =>
{
Submarine.MainSub = null;
GameMain.CharacterEditorScreen.Select();
SelectTab(tb, userdata);
return true;
}
};
@@ -164,7 +141,8 @@ namespace Barotrauma
steamWorkshopButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("SteamWorkshopButton"), style: "GUIButtonLarge")
{
Enabled = false,
OnClicked = SteamWorkshopClicked
UserData = Tab.SteamWorkshop,
OnClicked = SelectTab
};
}
@@ -236,15 +214,17 @@ namespace Barotrauma
this.game = game;
}
#endregion
#region Selection
public override void Select()
{
base.Select();
if (GameMain.NetworkMember != null)
if (GameMain.Client != null)
{
GameMain.NetworkMember.Disconnect();
GameMain.NetworkMember = null;
GameMain.Client.Disconnect();
GameMain.Client = null;
}
Submarine.Unload();
@@ -253,16 +233,76 @@ namespace Barotrauma
campaignSetupUI.UpdateSubList();
SelectTab(null, 0);
ResetButtonStates(null);
GameAnalyticsManager.SetCustomDimension01("");
}
public bool SelectTab(GUIButton button, object obj)
private bool SelectTab(GUIButton button, object obj)
{
if (obj is Tab)
{
SelectTab((Tab)obj);
if (GameMain.Config.UnsavedSettings)
{
var applyBox = new GUIMessageBox(
TextManager.Get("ApplySettingsLabel"),
TextManager.Get("ApplySettingsQuestion"),
new string[] { TextManager.Get("ApplySettingsYes"), TextManager.Get("ApplySettingsNo") });
applyBox.Buttons[0].UserData = (Tab)obj;
applyBox.Buttons[0].OnClicked = (tb, userdata) =>
{
applyBox.Close(button, userdata);
ApplySettings(button, userdata);
return true;
};
applyBox.Buttons[1].UserData = (Tab)obj;
applyBox.Buttons[1].OnClicked = (tb, userdata) =>
{
applyBox.Close(button, userdata);
DiscardSettings(button, userdata);
return true;
};
return false;
}
selectedTab = (Tab)obj;
switch (selectedTab)
{
case Tab.NewGame:
campaignSetupUI.CreateDefaultSaveName();
campaignSetupUI.UpdateTutorialSelection();
break;
case Tab.LoadGame:
campaignSetupUI.UpdateLoadMenu();
break;
case Tab.Settings:
GameMain.Config.ResetSettingsFrame();
menuTabs[(int)Tab.Settings] = GameMain.Config.SettingsFrame;
break;
case Tab.JoinServer:
GameMain.ServerListScreen.Select();
break;
case Tab.HostServer:
break;
case Tab.Tutorials:
break;
case Tab.CharacterEditor:
Submarine.MainSub = null;
GameMain.CharacterEditorScreen.Select();
break;
case Tab.SubmarineEditor:
GameMain.SubEditorScreen.Select();
break;
case Tab.QuickStartDev:
QuickStart();
break;
case Tab.SteamWorkshop:
if (!Steam.SteamManager.IsInitialized) return false;
GameMain.SteamWorkshopScreen.Select();
break;
}
}
else
{
@@ -270,7 +310,29 @@ namespace Barotrauma
}
if (button != null) button.Selected = true;
ResetButtonStates(button);
return true;
}
public bool ReturnToMainMenu(GUIButton button, object obj)
{
if (Selected != this)
{
Select();
}
else
{
ResetButtonStates(button);
}
SelectTab(null, 0);
return true;
}
private void ResetButtonStates(GUIButton button)
{
foreach (GUIComponent child in buttonsParent.Children)
{
GUIButton otherButton = child as GUIButton;
@@ -278,45 +340,73 @@ namespace Barotrauma
otherButton.Selected = false;
}
}
#endregion
if (Selected != this) Select();
private void QuickStart()
{
Submarine selectedSub = null;
string subName = GameMain.Config.QuickStartSubmarineName;
if (!string.IsNullOrEmpty(subName))
{
DebugConsole.NewMessage($"Loading the predefined quick start sub \"{subName}\"", Color.White);
selectedSub = Submarine.SavedSubmarines.FirstOrDefault(s =>
s.Name.ToLower() == subName.ToLower());
return true;
if (selectedSub == null)
{
DebugConsole.NewMessage($"Cannot find a sub that matches the name \"{subName}\".", Color.Red);
}
}
if (selectedSub == null)
{
DebugConsole.NewMessage("Loading a random sub.", Color.White);
var subs = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.Shuttle) && !s.HasTag(SubmarineTag.HideInMenus));
selectedSub = subs.ElementAt(Rand.Int(subs.Count()));
}
var gamesession = new GameSession(
selectedSub,
"Data/Saves/test.xml",
GameModePreset.List.Find(gm => gm.Identifier == "devsandbox"),
missionPrefab: null);
//(gamesession.GameMode as SinglePlayerCampaign).GenerateMap(ToolBox.RandomSeed(8));
gamesession.StartRound(ToolBox.RandomSeed(8));
GameMain.GameScreen.Select();
string[] jobIdentifiers = new string[] { "captain", "engineer", "mechanic" };
for (int i = 0; i < 3; i++)
{
var spawnPoint = WayPoint.GetRandom(SpawnType.Human, null, Submarine.MainSub);
if (spawnPoint == null)
{
DebugConsole.ThrowError("No spawnpoints found in the selected submarine. Quickstart failed.");
GameMain.MainMenuScreen.Select();
return;
}
var characterInfo = new CharacterInfo(
Character.HumanConfigFile,
jobPrefab: JobPrefab.List.Find(j => j.Identifier == jobIdentifiers[i]));
if (characterInfo.Job == null)
{
DebugConsole.ThrowError("Failed to find the job \"" + jobIdentifiers[i] + "\"!");
}
var newCharacter = Character.Create(Character.HumanConfigFile, spawnPoint.WorldPosition, ToolBox.RandomSeed(8), characterInfo);
newCharacter.GiveJobItems(spawnPoint);
gamesession.CrewManager.AddCharacter(newCharacter);
Character.Controlled = newCharacter;
}
}
public void SelectTab(Tab tab)
private void UpdateTutorialList()
{
if (GameMain.Config.UnsavedSettings)
var tutorialList = menuTabs[(int)Tab.Tutorials].GetChild<GUIListBox>();
foreach (GUITextBlock tutorialText in tutorialList.Content.Children)
{
var applyBox = new GUIMessageBox(
TextManager.Get("ApplySettingsLabel"),
TextManager.Get("ApplySettingsQuestion"),
new string[] { TextManager.Get("ApplySettingsYes"), TextManager.Get("ApplySettingsNo") });
applyBox.Buttons[0].OnClicked += applyBox.Close;
applyBox.Buttons[0].OnClicked += ApplySettings;
applyBox.Buttons[0].UserData = tab;
applyBox.Buttons[1].OnClicked += applyBox.Close;
applyBox.Buttons[1].OnClicked += DiscardSettings;
applyBox.Buttons[1].UserData = tab;
return;
}
selectedTab = tab;
switch (selectedTab)
{
case Tab.NewGame:
campaignSetupUI.CreateDefaultSaveName();
campaignSetupUI.UpdateTutorialSelection();
break;
case Tab.LoadGame:
campaignSetupUI.UpdateLoadMenu();
break;
case Tab.Settings:
GameMain.Config.ResetSettingsFrame();
menuTabs[(int)Tab.Settings] = GameMain.Config.SettingsFrame;
break;
if (((Tutorial)tutorialText.UserData).Completed)
{
tutorialText.TextColor = Color.LightGreen;
}
}
}
@@ -334,9 +424,9 @@ namespace Barotrauma
private bool ApplySettings(GUIButton button, object userData)
{
GameMain.Config.Save();
GameMain.Config.SaveNewPlayerConfig();
if (userData is Tab) SelectTab((Tab)userData);
if (userData is Tab) SelectTab(button, (Tab)userData);
if (GameMain.GraphicsWidth != GameMain.Config.GraphicsWidth || GameMain.GraphicsHeight != GameMain.Config.GraphicsHeight)
{
@@ -350,8 +440,8 @@ namespace Barotrauma
private bool DiscardSettings(GUIButton button, object userData)
{
GameMain.Config.Load("config.xml");
if (userData is Tab) SelectTab((Tab)userData);
GameMain.Config.LoadPlayerConfig();
if (userData is Tab) SelectTab(button, (Tab)userData);
return true;
}
@@ -410,15 +500,41 @@ namespace Barotrauma
GameMain.NetLobbyScreen = new NetLobbyScreen();
try
{
GameMain.NetworkMember = new GameServer(name, port, queryPort, isPublicBox.Selected, passwordBox.Text, useUpnpBox.Selected, int.Parse(maxPlayersBox.Text));
}
int ownerKey = Math.Max(CryptoRandom.Instance.Next(),1);
string arguments = "-name \"" + name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
" -port " + port.ToString() +
" -queryport " + queryPort.ToString() +
" -password \"" + passwordBox.Text.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
" -upnp " + useUpnpBox.Selected +
" -playercount " + maxPlayersBox.Text +
" -ownerkey " + ownerKey.ToString();
string filename = "DedicatedServer.exe";
#if LINUX
filename = "mono";
arguments = "./DedicatedServer.exe " + arguments;
#endif
var processInfo = new ProcessStartInfo
{
FileName = filename,
Arguments = arguments,
#if !DEBUG
WindowStyle = ProcessWindowStyle.Hidden
#endif
};
GameMain.ServerChildProcess = Process.Start(processInfo);
Thread.Sleep(1000); //wait until the server is ready before connecting
GameMain.Client = new GameClient(name, "127.0.0.1:" + port.ToString(),ownerKey);
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to start server", e);
}
GameMain.NetLobbyScreen.IsServer = true;
return true;
}
@@ -432,7 +548,7 @@ namespace Barotrauma
{
Frame.AddToGUIUpdateList(ignoreChildren: true);
buttonsParent.AddToGUIUpdateList();
if (selectedTab > 0)
if (selectedTab > 0 && menuTabs[(int)selectedTab] != null)
{
menuTabs[(int)selectedTab].AddToGUIUpdateList();
}
@@ -490,7 +606,7 @@ namespace Barotrauma
if (Array.Find(existingSaveFiles, s => s == saveName) != null)
{
new GUIMessageBox("Save name already in use", "Please choose another name for the save file");
new GUIMessageBox(TextManager.Get("SaveNameInUseHeader"), TextManager.Get("SaveNameInUseText"));
return;
}
@@ -548,8 +664,7 @@ namespace Barotrauma
GameMain.LobbyScreen.Select();
}
#region UI Methods
#region UI Methods
private void CreateHostServerFields()
{
Vector2 textLabelSize = new Vector2(1.0f, 0.1f);
File diff suppressed because it is too large Load Diff
@@ -129,7 +129,7 @@ namespace Barotrauma
GUIButton button = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform, Anchor.TopLeft),
TextManager.Get("Back"), style: "GUIButtonLarge")
{
OnClicked = GameMain.MainMenuScreen.SelectTab
OnClicked = GameMain.MainMenuScreen.ReturnToMainMenu
};
var refreshButton = new GUIButton(new RectTransform(new Vector2(buttonContainer.Rect.Height / (float)buttonContainer.Rect.Width, 0.9f), buttonContainer.RectTransform, Anchor.Center),
@@ -591,7 +591,7 @@ namespace Barotrauma
}
GameMain.Config.DefaultPlayerName = clientNameBox.Text;
GameMain.Config.Save();
GameMain.Config.SaveNewPlayerConfig();
string ip = null;
if (ipBox.UserData is ServerInfo serverInfo)
@@ -617,17 +617,18 @@ namespace Barotrauma
private IEnumerable<object> ConnectToServer(string ip)
{
#if !DEBUG
try
{
GameMain.NetworkMember = new GameClient(clientNameBox.Text);
GameMain.Client.ConnectToServer(ip);
#endif
GameMain.Client = new GameClient(clientNameBox.Text, ip);
#if !DEBUG
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to start the client", e);
}
#endif
yield return CoroutineStatus.Success;
}
@@ -1,10 +1,8 @@
using Barotrauma.Extensions;
using Barotrauma.Steam;
using Barotrauma.Steam;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
@@ -58,7 +56,7 @@ namespace Barotrauma
GUIButton backButton = new GUIButton(new RectTransform(new Vector2(0.15f, 1.0f), buttonContainer.RectTransform),
TextManager.Get("Back"))
{
OnClicked = GameMain.MainMenuScreen.SelectTab
OnClicked = GameMain.MainMenuScreen.ReturnToMainMenu
};
backButton.SelectedColor = backButton.Color;
@@ -66,7 +64,7 @@ namespace Barotrauma
foreach (Tab tab in Enum.GetValues(typeof(Tab)))
{
GUIButton tabButton = new GUIButton(new RectTransform(new Vector2(0.15f, 1.0f), buttonContainer.RectTransform) { RelativeOffset = new Vector2(0.4f + 0.15f * i, 0.0f) },
tab.ToString())
TextManager.Get(tab.ToString() + "Tab"))
{
UserData = tab,
OnClicked = (btn, userData) => { SelectTab((Tab)userData); return true; }
@@ -92,7 +90,7 @@ namespace Barotrauma
{
OnSelected = (GUIComponent component, object userdata) =>
{
if (GUI.MouseOn is GUIButton) { return false; }
if (GUI.MouseOn is GUIButton || GUI.MouseOn?.Parent is GUIButton) { return false; }
ShowItemPreview(userdata as Facepunch.Steamworks.Workshop.Item);
return true;
}
@@ -136,7 +134,7 @@ namespace Barotrauma
{
OnSelected = (component, userdata) =>
{
if (GUI.MouseOn is GUIButton) { return false; }
if (GUI.MouseOn is GUIButton || GUI.MouseOn?.Parent is GUIButton) { return false; }
myItemList.Deselect();
if (userdata is Facepunch.Steamworks.Workshop.Item item)
{
@@ -153,7 +151,7 @@ namespace Barotrauma
{
OnSelected = (component, userdata) =>
{
if (GUI.MouseOn is GUIButton) { return false; }
if (GUI.MouseOn is GUIButton || GUI.MouseOn?.Parent is GUIButton) { return false; }
publishedItemList.Deselect();
if (userdata is Submarine sub)
{
@@ -360,13 +358,29 @@ namespace Barotrauma
if (item.Installed)
{
if (listBox != publishedItemList && SteamManager.CheckWorkshopItemEnabled(item) && !SteamManager.CheckWorkshopItemUpToDate(item))
{
new GUIButton(new RectTransform(new Vector2(0.4f, 0.5f), rightColumn.RectTransform, Anchor.BottomLeft), text: "Update")
{
UserData = "updatebutton",
IgnoreLayoutGroups = true,
OnClicked = (btn, userdata) =>
{
SteamManager.UpdateWorkshopItem(item, out string errorMsg);
btn.Enabled = false;
btn.Visible = false;
return true;
}
};
}
GUITickBox enabledTickBox = null;
try
{
bool? compatible = SteamManager.CheckWorkshopItemCompatibility(item);
if (compatible.HasValue && !compatible.Value)
{
new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.5f), rightColumn.RectTransform),
new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.3f), rightColumn.RectTransform),
TextManager.Get("WorkshopItemIncompatible"), textColor: Color.Red)
{
ToolTip = TextManager.Get("WorkshopItemIncompatibleTooltip")
@@ -513,11 +527,13 @@ namespace Barotrauma
Facepunch.Steamworks.Workshop.Item item = tickBox.UserData as Facepunch.Steamworks.Workshop.Item;
if (item == null) { return false; }
var updateButton = tickBox.Parent.FindChild("updatebutton");
string errorMsg = "";
if (tickBox.Selected)
{
if (!SteamManager.EnableWorkShopItem(item, false, out errorMsg))
{
{
tickBox.Enabled = false;
}
}
@@ -528,6 +544,10 @@ namespace Barotrauma
tickBox.Enabled = false;
}
}
if (!tickBox.Enabled && updateButton == null)
{
updateButton.Enabled = false;
}
if (!string.IsNullOrEmpty(errorMsg))
{
new GUIMessageBox(TextManager.Get("Error"), errorMsg);
@@ -573,7 +593,10 @@ namespace Barotrauma
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), content.RectTransform), TextManager.Get("WorkshopItemDescription"));
var descriptionContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.2f), content.RectTransform));
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), descriptionContainer.Content.RectTransform), item.Description, wrap: true);
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), descriptionContainer.Content.RectTransform), item.Description, wrap: true)
{
CanBeFocused = false
};
//score -------------------------------------
@@ -603,7 +626,10 @@ namespace Barotrauma
for (int i = 0; i < item.Tags.Length && i < 5; i++)
{
if (string.IsNullOrEmpty(item.Tags[i])) { continue; }
new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), tagContainer.RectTransform), item.Tags[i].CapitaliseFirstInvariant(), style: "ListBoxElement");
string tag = TextManager.Get("Workshop.ContentTag." + item.Tags[i], true);
if (tag.Length == 0) tag = item.Tags[i].CapitaliseFirstInvariant();
new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), tagContainer.RectTransform), tag, style: "ListBoxElement");
}
var creationDate = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.0f), content.RectTransform), TextManager.Get("WorkshopItemCreationDate") +": ");
@@ -815,6 +841,12 @@ namespace Barotrauma
if (ofd.ShowDialog() == DialogResult.OK)
{
string previewImagePath = Path.GetFullPath(Path.Combine(SteamManager.WorkshopItemStagingFolder, SteamManager.PreviewImageName));
if (new FileInfo(ofd.FileName).Length > 1024 * 1024)
{
new GUIMessageBox(TextManager.Get("Error"), TextManager.Get("WorkshopItemPreviewImageTooLarge"));
return false;
}
if (ofd.FileName != previewImagePath)
{
File.Copy(ofd.FileName, previewImagePath, overwrite: true);
@@ -917,11 +949,22 @@ namespace Barotrauma
foreach (string file in ofd.FileNames)
{
string filePathRelativeToStagingFolder = UpdaterUtil.GetRelativePath(file, Path.Combine(Environment.CurrentDirectory, SteamManager.WorkshopItemStagingFolder));
//file is not inside the staging folder -> copy it
string filePathRelativeToBaseFolder = UpdaterUtil.GetRelativePath(file, Environment.CurrentDirectory);
//file is not inside the staging folder
if (filePathRelativeToStagingFolder.StartsWith(".."))
{
string filePathRelativeToBaseFolder = UpdaterUtil.GetRelativePath(file, Environment.CurrentDirectory);
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.None);
//submarines can be included in the content package directly
string basePath = Path.GetDirectoryName(filePathRelativeToBaseFolder.Replace("..", ""));
if (basePath == "Submarines")
{
string destinationPath = Path.Combine(SteamManager.WorkshopItemStagingFolder, "Submarines", Path.GetFileName(file));
File.Copy(file, destinationPath);
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.Submarine);
}
else
{
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.None);
}
}
else
{
@@ -1091,6 +1134,7 @@ namespace Barotrauma
OnClicked = (btn, userdata) =>
{
itemContentPackage.RemoveFile(contentFile);
RefreshCreateItemFileList();
return true;
}
};
@@ -60,7 +60,9 @@ namespace Barotrauma
private GUIFrame wiringToolPanel;
private Tutorials.EditorTutorial tutorial;
private DateTime editorSelectedTime;
private readonly string containerDeleteTag = "containerdelete";
private DateTime editorSelectedTime;
@@ -83,7 +85,7 @@ namespace Barotrauma
private string GetStructureCount()
{
return TextManager.Get("Structures") + ": " + (MapEntity.mapEntityList.Count - Item.ItemList.Count);
return TextManager.Get("Structures") + ": " + (MapEntity.mapEntityList.Count - Item.ItemList.Count - Hull.hullList.Count - WayPoint.WayPointList.Count - Gap.GapList.Count);
}
private string GetTotalHullVolume()
@@ -532,7 +534,7 @@ namespace Barotrauma
}
else
{
Submarine.MainSub = new Submarine(Path.Combine(Submarine.SavePath, "Unnamed.sub"), "", false);
Submarine.MainSub = new Submarine(Path.Combine(Submarine.SavePath, TextManager.Get("UnspecifiedSubFileName") + ".sub"), "", false);
cam.Position = Submarine.MainSub.Position;
}
@@ -846,11 +848,7 @@ namespace Barotrauma
foreach (SubmarineTag tag in Enum.GetValues(typeof(SubmarineTag)))
{
FieldInfo fi = typeof(SubmarineTag).GetField(tag.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
string tagStr = attributes.Length > 0 ? attributes[0].Description : "";
string tagStr = TextManager.Get(tag.ToString());
var tagTickBox = new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), tagContainer.Content.RectTransform),
tagStr, font: GUI.SmallFont)
{
@@ -1215,11 +1213,8 @@ namespace Barotrauma
return false;
}
if (subList.SelectedComponent == null) return false;
Submarine selectedSub = subList.SelectedComponent.UserData as Submarine;
if (selectedSub == null) return false;
if (subList.SelectedComponent == null) { return false; }
if (!(subList.SelectedComponent.UserData is Submarine selectedSub)) { return false; }
Submarine.MainSub = selectedSub;
selectedSub.Load(true);
@@ -1433,9 +1428,8 @@ namespace Barotrauma
foreach (MapEntityPrefab ep in MapEntityPrefab.List)
{
var itemPrefab = ep as ItemPrefab;
if (itemPrefab == null || itemPrefab.Name == null) continue;
if (!itemPrefab.Name.Contains("Wire") && (itemPrefab.Aliases == null || !itemPrefab.Aliases.Any(a => a.Contains("Wire")))) continue;
if (!(ep is ItemPrefab itemPrefab) || itemPrefab.Name == null) { continue; }
if (!itemPrefab.Tags.Contains("wire")) { continue; }
GUIFrame imgFrame = new GUIFrame(new RectTransform(new Point(listBox.Rect.Width - 20, listBox.Rect.Width / 2), listBox.Content.RectTransform), style: "ListBoxElement")
{
@@ -1453,13 +1447,9 @@ namespace Barotrauma
private bool SelectLinkedSub(GUIComponent selected, object userData)
{
var submarine = selected.UserData as Submarine;
if (submarine == null) return false;
if (!(selected.UserData is Submarine submarine)) return false;
var prefab = new LinkedSubmarinePrefab(submarine);
MapEntityPrefab.SelectPrefab(prefab);
return true;
}
@@ -1877,8 +1867,6 @@ namespace Barotrauma
public override void AddToGUIUpdateList()
{
if (tutorial != null) tutorial.AddToGUIUpdateList();
if (MapEntity.SelectedList.Count == 1)
{
MapEntity.SelectedList[0].AddToGUIUpdateList();