diff --git a/Launcher/Form1.Designer.cs b/Launcher/Form1.Designer.cs index 39e556ab8..827db9ed0 100644 --- a/Launcher/Form1.Designer.cs +++ b/Launcher/Form1.Designer.cs @@ -227,7 +227,7 @@ this.Controls.Add(this.pictureBox1); this.DoubleBuffered = true; this.Name = "LauncherMain"; - this.Text = "Form1"; + this.Text = "Launcher"; this.Load += new System.EventHandler(this.LauncherMain_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); diff --git a/Launcher/Form1.cs b/Launcher/Form1.cs index 644810e88..ed2448611 100644 --- a/Launcher/Form1.cs +++ b/Launcher/Form1.cs @@ -131,7 +131,30 @@ namespace Launcher { SaveSettings(configPath); - Process.Start(new ProcessStartInfo(Directory.GetCurrentDirectory() + "//"+settings.SelectedContentPackage.GetFilesOfType(ContentType.Executable)[0])); + var executables = settings.SelectedContentPackage.GetFilesOfType(ContentType.Executable); + if (executables.Count == 0) + { + MessageBox.Show("Error", "The game executable isn't configured in the selected content package."); + return; + } + + string exePath = Directory.GetCurrentDirectory() + "//" + executables[0]; + if (!File.Exists(exePath)) + { + MessageBox.Show("Error", "Couldn't find the executable ''" + exePath + "''!"); + return; + } + + try + { + Process.Start(new ProcessStartInfo(exePath)); + } + catch (Exception exception) + { + MessageBox.Show("Error while opening executable ''" + exePath + "''", exception.Message); + return; + } + Application.Exit(); } @@ -294,6 +317,7 @@ namespace Launcher updateLabel.Visible = false; MessageBox.Show("Download completed!"); + settings.WasGameUpdated = true; return; } diff --git a/Launcher/Form1.resx b/Launcher/Form1.resx index 3a4f4e9e2..4c150f4e1 100644 --- a/Launcher/Form1.resx +++ b/Launcher/Form1.resx @@ -3677,7 +3677,7 @@ iVBORw0KGgoAAAANSUhEUgAABYQAAAWKCAYAAABIIWEyAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1 - MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACxAAAAsQAa0jvXUAAP+WSURBVHhe7P3ptuw8c6QJSpka + MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACw8AAAsPAZL5A6UAAP+WSURBVHhe7P3ptuw8c6QJSpka Xs2Zyqys6q5/ff/3qKZ7uHkYjA4QZDBiDwda61mAmw8YyIgg8W2d92+2//uvxWKxWCzu4G//9r+V+uJz /KRrwHO1PuxPreEd41Rrcv7735UxPXoxqJc216X+CMzHkXG4/q5POdVYGRN5CfLUx7qgY6q9q7O1GePa 3z8I+5n/996HjT7T00dgHMzVNZ4rzZnjEZs55PeW8rIea/9N+mFzPd6HJPZhr0d9HavSldm4X0XcZ3fy diff --git a/Launcher2/LauncherMain.cs b/Launcher2/LauncherMain.cs index f9e99b77b..376b92b44 100644 --- a/Launcher2/LauncherMain.cs +++ b/Launcher2/LauncherMain.cs @@ -66,7 +66,7 @@ namespace Launcher2 { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 640; - graphics.PreferredBackBufferHeight = 360; + graphics.PreferredBackBufferHeight = 400; IsMouseVisible = true; @@ -116,13 +116,13 @@ namespace Launcher2 updateInfoText = new GUITextBlock(new Rectangle(0,y+30,100,20), "", GUI.Style, guiRoot); - updateInfoBox = new GUIListBox(new Rectangle(0, y + 55, 330, 150), GUI.Style, guiRoot); + updateInfoBox = new GUIListBox(new Rectangle(0, y + 55, 330, graphicsHeight-y-55-30-80), GUI.Style, guiRoot); updateInfoBox.Visible = false; - progressBar = new GUIProgressBar(new Rectangle(110,y+220,220,20), Color.Green, 0.0f, guiRoot); + progressBar = new GUIProgressBar(new Rectangle(110,0,220,20), Color.Green, 0.0f, Alignment.BottomLeft, guiRoot); progressBar.Visible = false; - downloadButton = new GUIButton(new Rectangle(0, y+220, 100, 20), "Download", GUI.Style, guiRoot); + downloadButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Download", Alignment.BottomLeft, GUI.Style, guiRoot); downloadButton.OnClicked = DownloadButtonClicked; downloadButton.Visible = false; @@ -196,10 +196,15 @@ namespace Launcher2 Color.White); spriteBatch.Draw(titleTexture, new Vector2(40.0f, 20.0f), null, Color.White, 0.0f, Vector2.Zero, new Vector2(0.2f, 0.2f), SpriteEffects.None, 0.0f); - - + guiRoot.Draw(spriteBatch); + if (GUIMessageBox.MessageBoxes.Count > 0) + { + var messageBox = GUIMessageBox.MessageBoxes.Peek(); + if (messageBox != null) messageBox.Draw(spriteBatch); + } + spriteBatch.End(); } @@ -236,8 +241,31 @@ namespace Launcher2 private bool LaunchClick(GUIButton button, object obj) { if (!TrySaveSettings(configPath)) return false; + + var executables = settings.SelectedContentPackage.GetFilesOfType(ContentType.Executable); + if (executables.Count == 0) + { + ShowError("Error", "The game executable isn't configured in the selected content package."); + return false; + } - Process.Start(new ProcessStartInfo(Directory.GetCurrentDirectory() + "//" + settings.SelectedContentPackage.GetFilesOfType(ContentType.Executable)[0])); + string exePath = Directory.GetCurrentDirectory() + "//" + executables[0]; + if (!File.Exists(exePath)) + { + ShowError("Error", "Couldn't find the executable ''" + exePath + "''!"); + return false; + } + + try + { + Process.Start(new ProcessStartInfo(exePath)); + } + catch (Exception exception) + { + ShowError("Error while opening executable ''" + exePath + "''", exception.Message); + return false; + } + Exit(); return true; @@ -428,12 +456,15 @@ namespace Launcher2 catch (Exception e) { updateInfoText.Text = "Update failed"; - SetUpdateInfoBox("Error while installing the update: "+e.Message); + ShowError("Error while installing the update", e.Message); + launchButton.Enabled = true; return; - } + } - //UpdaterUtil.CleanUnnecessaryFiles(latestVersionFiles); + settings.WasGameUpdated = true; + + UpdaterUtil.CleanUnnecessaryFiles(latestVersionFiles); updateInfoText.Text = "The game was updated succesfully!"; launchButton.Enabled = true; @@ -468,6 +499,13 @@ namespace Launcher2 webClient.DownloadFileAsync(new Uri(latestVersionFolder + filesToDownload[filesDownloaded]), @dir + "\\" + filesToDownload[filesDownloaded]); } + private void ShowError(string header, string message) + { + GUIFrame dummyFrame = new GUIFrame(new Rectangle(0,0,graphicsWidth,graphicsHeight)); + + new GUIMessageBox(header, message, new string[] { "OK" }, 400, 250, Alignment.TopLeft, dummyFrame); + } + private void Completed(object sender, AsyncCompletedEventArgs e) { if (e.Error!=null) diff --git a/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml b/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml index ab56223ad..bd90adf5f 100644 --- a/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml +++ b/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml @@ -1,10 +1,10 @@  - + - + \ No newline at end of file diff --git a/Subsurface/Content/SavedMaps/Aegir.gz b/Subsurface/Content/SavedMaps/Aegir.gz deleted file mode 100644 index a20d57629..000000000 Binary files a/Subsurface/Content/SavedMaps/Aegir.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/ag2.gz b/Subsurface/Content/SavedMaps/ag2.gz deleted file mode 100644 index f3a29161a..000000000 Binary files a/Subsurface/Content/SavedMaps/ag2.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/ag3.gz b/Subsurface/Content/SavedMaps/ag3.gz deleted file mode 100644 index 81226941f..000000000 Binary files a/Subsurface/Content/SavedMaps/ag3.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/c.gz b/Subsurface/Content/SavedMaps/c.gz deleted file mode 100644 index 2398312c9..000000000 Binary files a/Subsurface/Content/SavedMaps/c.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/d.gz b/Subsurface/Content/SavedMaps/d.gz deleted file mode 100644 index c3cbf794a..000000000 Binary files a/Subsurface/Content/SavedMaps/d.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/empty.gz b/Subsurface/Content/SavedMaps/empty.gz deleted file mode 100644 index 9a982a560..000000000 Binary files a/Subsurface/Content/SavedMaps/empty.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/small.gz b/Subsurface/Content/SavedMaps/small.gz deleted file mode 100644 index ae850ffba..000000000 Binary files a/Subsurface/Content/SavedMaps/small.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/test.gz b/Subsurface/Content/SavedMaps/test.gz deleted file mode 100644 index fd4283f53..000000000 Binary files a/Subsurface/Content/SavedMaps/test.gz and /dev/null differ diff --git a/Subsurface/Content/SavedMaps/test2.xml b/Subsurface/Content/SavedMaps/test2.xml deleted file mode 100644 index d986442b9..000000000 --- a/Subsurface/Content/SavedMaps/test2.xml +++ /dev/null @@ -1,1036 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Subsurface/Content/UI/cursor.png b/Subsurface/Content/UI/cursor.png new file mode 100644 index 000000000..cfcbe4ec5 Binary files /dev/null and b/Subsurface/Content/UI/cursor.png differ diff --git a/Subsurface/Data/ContentPackages/Vanilla 0.1.3.xml b/Subsurface/Data/ContentPackages/Vanilla 0.1.3.xml new file mode 100644 index 000000000..f16534828 --- /dev/null +++ b/Subsurface/Data/ContentPackages/Vanilla 0.1.3.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Subsurface/Data/SavedSubs/Aegir Mark II.gz b/Subsurface/Data/SavedSubs/Aegir Mark II.gz new file mode 100644 index 000000000..21d1c980f Binary files /dev/null and b/Subsurface/Data/SavedSubs/Aegir Mark II.gz differ diff --git a/Subsurface/Data/SavedSubs/TutorialSub.gz b/Subsurface/Data/SavedSubs/TutorialSub.gz new file mode 100644 index 000000000..96f8aa1b3 Binary files /dev/null and b/Subsurface/Data/SavedSubs/TutorialSub.gz differ diff --git a/Subsurface/Data/SavedSubs/Vellamo.gz b/Subsurface/Data/SavedSubs/Vellamo.gz new file mode 100644 index 000000000..aacaeab7f Binary files /dev/null and b/Subsurface/Data/SavedSubs/Vellamo.gz differ diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 1962bc932..416b51dcd 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -601,11 +601,6 @@ namespace Subsurface /// public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true) { - if (PlayerInput.KeyHit(Keys.U)) - { - AnimController.SimplePhysicsEnabled = !AnimController.SimplePhysicsEnabled; - } - Limb head = AnimController.GetLimb(LimbType.Head); Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(head.SimPosition); diff --git a/Subsurface/Source/Characters/FishAnimController.cs b/Subsurface/Source/Characters/FishAnimController.cs index 9ef14ac76..dda729e26 100644 --- a/Subsurface/Source/Characters/FishAnimController.cs +++ b/Subsurface/Source/Characters/FishAnimController.cs @@ -49,11 +49,6 @@ namespace Subsurface public override void UpdateAnim(float deltaTime) { - if (PlayerInput.KeyHit(Keys.I)) - { - SimplePhysicsEnabled = !SimplePhysicsEnabled; - } - if (character.IsDead) { UpdateDying(deltaTime); diff --git a/Subsurface/Source/ContentPackage.cs b/Subsurface/Source/ContentPackage.cs index d44fd3576..aaf32d591 100644 --- a/Subsurface/Source/ContentPackage.cs +++ b/Subsurface/Source/ContentPackage.cs @@ -125,7 +125,7 @@ namespace Subsurface //{ // doc.Root.Add(new XElement("item", new XAttribute("file", itemFile))); //} - doc.Save(filePath+"//"+name+".xml"); + doc.Save(System.IO.Path.Combine(filePath, name+".xml")); } private void CalculateHash() diff --git a/Subsurface/Source/CoroutineManager.cs b/Subsurface/Source/CoroutineManager.cs index c5be073fc..d1ffb1f09 100644 --- a/Subsurface/Source/CoroutineManager.cs +++ b/Subsurface/Source/CoroutineManager.cs @@ -24,6 +24,14 @@ namespace Subsurface Coroutines.Add(func.GetEnumerator()); } + public static bool IsCoroutineRunning(string name) + { + IEnumerator coroutine = Coroutines.FirstOrDefault( + c => c.ToString().Contains(name)); + + return coroutine!=null; + } + public static void StopCoroutine(string name) { IEnumerator coroutine = Coroutines.FirstOrDefault(c => c.ToString().Contains(name)); diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index b5aba238a..fcf5de848 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -282,13 +282,13 @@ namespace Subsurface DebugConsole.ThrowError("Illegal symbols in filename (../)"); return; } - Submarine.SaveCurrent("Content/SavedMaps/" + fileName +".gz"); + Submarine.SaveCurrent(fileName +".gz"); NewMessage("map saved", Color.Green); break; case "loadmap": case "loadsub": if (commands.Length < 2) break; - Submarine.Load("Content/SavedMaps/" + string.Join(" ", commands.Skip(1))); + Submarine.Load(string.Join(" ", commands.Skip(1))); break; case "messagebox": if (commands.Length < 3) break; diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index 602304e6d..369ac7475 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -23,6 +23,8 @@ namespace Subsurface static Texture2D t; public static SpriteFont Font, SmallFont, LargeFont; + private static Sprite cursor; + private static GraphicsDevice graphicsDevice; private static List messages = new List(); @@ -37,6 +39,8 @@ namespace Subsurface GUI.Font = ToolBox.TryLoadFont("SpriteFont1", content); GUI.SmallFont = ToolBox.TryLoadFont("SmallFont", content); GUI.LargeFont = ToolBox.TryLoadFont("LargeFont", content); + + cursor = new Sprite("Content/UI/cursor.png" ,Vector2.Zero); } public static bool PauseMenuOpen @@ -344,9 +348,10 @@ namespace Subsurface } DebugConsole.Draw(spriteBatch); - - + if (GUIComponent.MouseOn != null && !string.IsNullOrWhiteSpace(GUIComponent.MouseOn.ToolTip)) GUIComponent.MouseOn.DrawToolTip(spriteBatch); + + cursor.Draw(spriteBatch, PlayerInput.MousePosition); } public static void Update(float deltaTime) diff --git a/Subsurface/Source/GUI/GUIMessageBox.cs b/Subsurface/Source/GUI/GUIMessageBox.cs index 6bd36bbe9..c7143dff7 100644 --- a/Subsurface/Source/GUI/GUIMessageBox.cs +++ b/Subsurface/Source/GUI/GUIMessageBox.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace Subsurface { - class GUIMessageBox : GUIFrame + public class GUIMessageBox : GUIFrame { public static Queue MessageBoxes = new Queue(); @@ -38,18 +38,10 @@ namespace Subsurface this.Buttons[0].OnClicked = Close; } - public GUIMessageBox(string header, string text, string[] buttons, int width=DefaultWidth, int height=DefaultHeight, Alignment textAlignment = Alignment.TopLeft) + public GUIMessageBox(string header, string text, string[] buttons, int width=DefaultWidth, int height=DefaultHeight, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null) : base(new Rectangle(0,0, width, height), - null, Alignment.Center, GUI.Style, null) + null, Alignment.Center, GUI.Style, parent) { - //Padding = GUI.style.smallPadding; - - //if (buttons == null || buttons.Length == 0) - //{ - // DebugConsole.ThrowError("Creating a message box with no buttons isn't allowed"); - // return; - //} - new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, GUI.Style, this, true); new GUITextBlock(new Rectangle(0, 30, 0, height - 70), text, Color.Transparent, Color.White, textAlignment, GUI.Style, this, true); diff --git a/Subsurface/Source/GUI/TitleScreen.cs b/Subsurface/Source/GUI/TitleScreen.cs index f52d86d37..5908a09aa 100644 --- a/Subsurface/Source/GUI/TitleScreen.cs +++ b/Subsurface/Source/GUI/TitleScreen.cs @@ -9,7 +9,7 @@ using System.Text; namespace Subsurface { - class TitleScreen + class LoadingScreen { private Texture2D backgroundTexture,monsterTexture,titleTexture; @@ -20,6 +20,8 @@ namespace Subsurface public Vector2 CenterPosition; public Vector2 TitlePosition; + + private float? loadState; public Vector2 TitleSize { @@ -32,7 +34,24 @@ namespace Subsurface private set; } - public TitleScreen(GraphicsDevice graphics) + public float? LoadState + { + get { return loadState; } + set + { + loadState = value; + DrawLoadingText = true; + } + } + + public bool DrawLoadingText + { + get; + set; + } + + + public LoadingScreen(GraphicsDevice graphics) { backgroundTexture = TextureLoader.FromFile("Content/UI/titleBackground.png"); monsterTexture = TextureLoader.FromFile("Content/UI/titleMonster.png"); @@ -40,31 +59,27 @@ namespace Subsurface renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + DrawLoadingText = true; } - public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics, float loadState, float deltaTime) + + public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics, float deltaTime) { - //if (stopwatch == null) - //{ - // stopwatch = new Stopwatch(); - // stopwatch.Start(); - //} + drawn = true; graphics.SetRenderTarget(renderTarget); - //Debug.WriteLine(stopwatch.Elapsed.TotalMilliseconds); Scale = GameMain.GraphicsHeight/1500.0f; state += deltaTime; - if (loadState>-1) + if (DrawLoadingText) { CenterPosition = new Vector2(GameMain.GraphicsWidth*0.3f, GameMain.GraphicsHeight/2.0f); TitlePosition = CenterPosition + new Vector2(-0.0f + (float)Math.Sqrt(state) * 220.0f, 0.0f) * Scale; TitlePosition.X = Math.Min(TitlePosition.X, (float)GameMain.GraphicsWidth / 2.0f); } - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied); graphics.Clear(Color.Black); @@ -92,21 +107,51 @@ namespace Subsurface TitlePosition, null, Color.White * Math.Min((state - 3.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), Scale, SpriteEffects.None, 0.0f); - string loadText = ""; - if (loadState == 100.0f) + if (DrawLoadingText) { - loadText = "Press any key to continue"; + string loadText = ""; + if (loadState == 100.0f) + { + loadText = "Press any key to continue"; + } + else + { + loadText = "Loading... "; + if (loadState!=null) + { + loadText += (int)loadState + " %"; + } + } + spriteBatch.DrawString(GUI.LargeFont, loadText, + new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f), + Color.White); } - else if (loadState > 0.0f) - { - loadText = "Loading... " + (int)loadState + " %"; - } - - spriteBatch.DrawString(GUI.Font, loadText, new Vector2(GameMain.GraphicsWidth/2.0f - 50.0f, GameMain.GraphicsHeight*0.8f), Color.White); - spriteBatch.End(); } + + bool drawn; + public IEnumerable DoLoading(IEnumerable loader) + { + drawn = false; + LoadState = null; + + while (!drawn) + { + yield return CoroutineStatus.Running; + } + + CoroutineManager.StartCoroutine(loader); + + yield return CoroutineStatus.Running; + + while (CoroutineManager.IsCoroutineRunning(loader.ToString())) + { + yield return CoroutineStatus.Running; + } + + loadState = 100.0f; + } } } diff --git a/Subsurface/Source/Game1.cs b/Subsurface/Source/GameMain.cs similarity index 86% rename from Subsurface/Source/Game1.cs rename to Subsurface/Source/GameMain.cs index 3a188df65..351812ead 100644 --- a/Subsurface/Source/Game1.cs +++ b/Subsurface/Source/GameMain.cs @@ -57,11 +57,13 @@ namespace Subsurface public static World World; - public static TitleScreen TitleScreen; - private bool titleScreenOpen; + public static LoadingScreen TitleScreen; + private static bool titleScreenOpen; public static GameSettings Config; + private bool hasLoaded; + //public static Random localRandom; //public static Random random; @@ -98,6 +100,12 @@ namespace Subsurface Graphics = new GraphicsDeviceManager(this); Config = new GameSettings("config.xml"); + if (Config.WasGameUpdated) + { + UpdaterUtil.CleanOldFiles(); + Config.WasGameUpdated = false; + Config.Save("config.xml"); + } graphicsWidth = Config.GraphicsWidth; graphicsHeight = Config.GraphicsHeight; @@ -112,9 +120,7 @@ namespace Subsurface FrameCounter = new FrameCounter(); - //renderTimer = new Stopwatch(); - - IsMouseVisible = true; + //IsMouseVisible = true; IsFixedTimeStep = false; //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55); @@ -158,12 +164,11 @@ namespace Subsurface TextureLoader.Init(GraphicsDevice); titleScreenOpen = true; - TitleScreen = new TitleScreen(GraphicsDevice); + TitleScreen = new LoadingScreen(GraphicsDevice); CoroutineManager.StartCoroutine(Load()); } - private float loadState = 0.0f; private IEnumerable Load() { GUI.Init(Content); @@ -173,42 +178,42 @@ namespace Subsurface LightManager = new Lights.LightManager(GraphicsDevice); Hull.renderer = new WaterRenderer(GraphicsDevice); - loadState = 1.0f; + TitleScreen.LoadState = 1.0f; yield return CoroutineStatus.Running; GUI.LoadContent(GraphicsDevice); - loadState = 2.0f; + TitleScreen.LoadState = 2.0f; yield return CoroutineStatus.Running; MapEntityPrefab.Init(); - loadState = 10.0f; + TitleScreen.LoadState = 10.0f; yield return CoroutineStatus.Running; JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs)); - loadState = 15.0f; + TitleScreen.LoadState = 15.0f; yield return CoroutineStatus.Running; StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure)); - loadState = 25.0f; + TitleScreen.LoadState = 25.0f; yield return CoroutineStatus.Running; ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item)); - loadState = 40.0f; + TitleScreen.LoadState = 40.0f; yield return CoroutineStatus.Running; Debug.WriteLine("sounds"); CoroutineManager.StartCoroutine(AmbientSoundManager.Init()); - loadState = 70.0f; + TitleScreen.LoadState = 70.0f; yield return CoroutineStatus.Running; GameModePreset.Init(); - Submarine.Preload("Content/SavedMaps"); - loadState = 80.0f; + Submarine.Preload(); + TitleScreen.LoadState = 80.0f; yield return CoroutineStatus.Running; GameScreen = new GameScreen(Graphics.GraphicsDevice); - loadState = 90.0f; + TitleScreen.LoadState = 90.0f; yield return CoroutineStatus.Running; MainMenuScreen = new MainMenuScreen(this); @@ -233,8 +238,10 @@ namespace Subsurface MainMenuScreen.Select(); yield return CoroutineStatus.Running; - loadState = 100.0f; + TitleScreen.LoadState = 100.0f; + hasLoaded = true; yield return CoroutineStatus.Success; + } /// @@ -259,7 +266,7 @@ namespace Subsurface double deltaTime = gameTime.ElapsedGameTime.TotalSeconds; PlayerInput.Update(deltaTime); - if (loadState >= 100.0f && !titleScreenOpen) + if (hasLoaded && !titleScreenOpen) { if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu(); @@ -296,18 +303,18 @@ namespace Subsurface if (titleScreenOpen) { - TitleScreen.Draw(spriteBatch, GraphicsDevice, loadState, (float)deltaTime); - if (loadState>=100.0f && (PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked())) + TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime); + if (TitleScreen.LoadState>=100.0f && (PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked())) { titleScreenOpen = false; } } - else if (loadState >= 100.0f) + else if (hasLoaded) { Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch); } - double elapsed =sw.Elapsed.TotalSeconds; + double elapsed = sw.Elapsed.TotalSeconds; if (elapsed < Physics.step) { System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0)); @@ -317,6 +324,15 @@ namespace Subsurface Stopwatch sw; + public static void ShowLoading(IEnumerable loader) + { + titleScreenOpen = true; + CoroutineManager.StartCoroutine(TitleScreen.DoLoading(loader)); + + } + + + protected override void OnExiting(object sender, EventArgs args) { if (NetworkMember != null) NetworkMember.Disconnect(); diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index 08b279630..641f711a7 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -190,6 +190,8 @@ namespace Subsurface var now = DateTime.Now; doc.Root.Add(new XAttribute("savetime", now.Hour + ":" + now.Minute + ", " + now.ToShortDateString())); + doc.Root.Add(new XAttribute("submarine", submarine==null ? "" : submarine.Name)); + ((SinglePlayerMode)gameMode).Save(doc.Root); try diff --git a/Subsurface/Source/GameSettings.cs b/Subsurface/Source/GameSettings.cs index 74b84e378..cdf8df2ba 100644 --- a/Subsurface/Source/GameSettings.cs +++ b/Subsurface/Source/GameSettings.cs @@ -43,6 +43,12 @@ namespace Subsurface set; } + public bool WasGameUpdated + { + get; + set; + } + public GameSettings(string filePath) { Load(filePath); @@ -75,6 +81,7 @@ namespace Subsurface MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", ""); AutoCheckUpdates = ToolBox.GetAttributeBool(doc.Root, "autocheckupdates", true); + WasGameUpdated = ToolBox.GetAttributeBool(doc.Root, "wasgameupdated", false); foreach (XElement subElement in doc.Root.Elements()) { @@ -102,6 +109,11 @@ namespace Subsurface doc.Root.Add( new XAttribute("masterserverurl", MasterServerUrl), new XAttribute("autocheckupdates", AutoCheckUpdates)); + + if (WasGameUpdated) + { + doc.Root.Add(new XAttribute("gamupdated", true)); + } XElement gMode = doc.Root.Element("graphicsmode"); diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 0dbb5c1f1..b9c2e38d1 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -232,7 +232,10 @@ namespace Subsurface.Items.Components case "sound": string filePath = ToolBox.GetAttributeString(subElement, "file", ""); if (filePath=="") continue; - if (!filePath.Contains("/")) filePath = Path.GetDirectoryName(item.Prefab.ConfigFile)+"/"+filePath; + if (!filePath.Contains("/") && !filePath.Contains("\\") && !filePath.Contains(Path.DirectorySeparatorChar)) + { + filePath = Path.Combine(Path.GetDirectoryName(item.Prefab.ConfigFile), filePath); + } ActionType type; diff --git a/Subsurface/Source/Items/Components/Power/Powered.cs b/Subsurface/Source/Items/Components/Power/Powered.cs index 2ca91e3d8..1e5334b99 100644 --- a/Subsurface/Source/Items/Components/Power/Powered.cs +++ b/Subsurface/Source/Items/Components/Power/Powered.cs @@ -78,7 +78,6 @@ namespace Subsurface.Items.Components if (sparkSounds == null) { sparkSounds = new Sound[4]; - string dir = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\"; for (int i = 0; i < 4; i++) { sparkSounds[i] = Sound.Load("Content/Items/Electricity/zap" + (i + 1) + ".ogg", false); diff --git a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs index 18806c7e3..467341d1a 100644 --- a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs @@ -82,21 +82,10 @@ namespace Subsurface.Items.Components } float degreeOfSuccess = DegreeOfSuccess(character); - if (Rand.Range(0.0f, 0.5f) < degreeOfSuccess) return false; + if (Rand.Range(0.0f, 50.0f) < degreeOfSuccess) return false; item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character); - //Vector2 baseVel = Rand.Vector(300.0f); - //for (int i = 0; i < 10; i++) - //{ - // var particle = GameMain.ParticleManager.CreateParticle("spark", item.Position, - // baseVel + Rand.Vector(100.0f), 0.0f); - - // if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f); - //} - - //character.AddDamage(item.SimPosition, DamageType.None, Math.Abs(degreeOfSuccess-100.0f)/10.0f, 0.0f, 3.0f, false); - return true; } diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index 4cc8d5121..d8ddde6ca 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -68,6 +68,15 @@ namespace Subsurface.Items.Components if (connections[i] == newConnection) return; } + for (int i = 0; i < 2; i++) + { + if (connections[i] != null && connections[i].Item == newConnection.Item) + { + addNode = false; + break; + } + } + for (int i = 0; i < 2; i++) { if (connections[i] != null) continue; @@ -76,6 +85,9 @@ namespace Subsurface.Items.Components if (!addNode) break; + if (Nodes.Count>0&&Nodes[0] == newConnection.Item.Position) break; + if (Nodes.Count > 1 && Nodes[Nodes.Count-1] == newConnection.Item.Position) break; + if (i == 0) { Nodes.Insert(0, newConnection.Item.Position); diff --git a/Subsurface/Source/Map/Explosion.cs b/Subsurface/Source/Map/Explosion.cs index 2946127ce..d04cba010 100644 --- a/Subsurface/Source/Map/Explosion.cs +++ b/Subsurface/Source/Map/Explosion.cs @@ -126,7 +126,7 @@ namespace Subsurface distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/attack.Range; c.AddDamage(limb.SimPosition, DamageType.None, - attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, true); + attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, false); if (force>0.0f) { limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition - simPosition) * distFactor * force); diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 8d18ce961..e9cb8e845 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -22,6 +22,8 @@ namespace Subsurface class Submarine : Entity { + public const string SavePath = "Data/SavedSubs"; + public static List SavedSubmarines = new List(); public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f); @@ -33,7 +35,6 @@ namespace Subsurface private static Vector2 lastPickedPosition; private static float lastPickedFraction; - static string SaveFolder; Md5Hash hash; private string filePath; @@ -448,35 +449,34 @@ namespace Subsurface //doc.Save(filePath); } - public static void SaveCurrent(string savePath) + public static void SaveCurrent(string fileName) { if (loaded==null) { - loaded = new Submarine(savePath); + loaded = new Submarine(fileName); // return; } - loaded.SaveAs(savePath); + loaded.SaveAs(SavePath+"/"+fileName); } - public static void Preload(string folder) + public static void Preload() { - SaveFolder = folder; //string[] mapFilePaths; Unload(); SavedSubmarines.Clear(); - if (!Directory.Exists(SaveFolder)) + if (!Directory.Exists(SavePath)) { try { - Directory.CreateDirectory(SaveFolder); + Directory.CreateDirectory(SavePath); } - catch + catch (Exception e) { - DebugConsole.ThrowError("Directory ''"+SaveFolder+"'' not found and creating the directory failed."); + DebugConsole.ThrowError("Directory ''" + SavePath + "'' not found and creating the directory failed.", e); return; } } @@ -485,11 +485,11 @@ namespace Subsurface try { - filePaths = Directory.GetFiles(SaveFolder); + filePaths = Directory.GetFiles(SavePath); } catch (Exception e) { - DebugConsole.ThrowError("Couldn't open directory ''" + SaveFolder + "''!", e); + DebugConsole.ThrowError("Couldn't open directory ''" + SavePath + "''!", e); return; } @@ -618,11 +618,11 @@ namespace Subsurface loaded = this; } - public static Submarine Load(string file) + public static Submarine Load(string fileName) { Unload(); - Submarine sub = new Submarine(file); + Submarine sub = new Submarine(SavePath+"/"+fileName); sub.Load(); //Entity.dictionary.Add(int.MaxValue, sub); diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 7e8224bf2..299c145ee 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -319,47 +319,7 @@ namespace Subsurface.Networking case (byte)PacketTypes.StartGame: if (gameStarted) continue; - if (this.Character != null) Character.Remove(); - - int seed = inc.ReadInt32(); - - - string levelSeed = inc.ReadString(); - - string mapName = inc.ReadString(); - string mapHash = inc.ReadString(); - - GameMain.NetLobbyScreen.TrySelectMap(mapName, mapHash); - - double durationMinutes = inc.ReadDouble(); - - TimeSpan duration = new TimeSpan(0,(int)durationMinutes,0); - Rand.SetSyncedSeed(seed); - //int gameModeIndex = inc.ReadInt32(); - GameMain.GameSession = new GameSession(Submarine.Loaded, "", GameMain.NetLobbyScreen.SelectedMode); - GameMain.GameSession.StartShift(duration, levelSeed); - - //myCharacter = ReadCharacterData(inc); - //Character.Controlled = myCharacter; - - List crew = new List(); - - int count = inc.ReadInt32(); - for (int n = 0; n < count; n++) - { - int id = inc.ReadInt32(); - Character newCharacter = ReadCharacterData(inc, id == myID); - - crew.Add(newCharacter); - } - - gameStarted = true; - - GameMain.GameScreen.Select(); - - AddChatMessage("Press TAB to chat", ChatMessageType.Server); - - CreateCrewFrame(crew); + GameMain.ShowLoading(StartGame(inc)); break; case (byte)PacketTypes.EndGame: @@ -416,6 +376,63 @@ namespace Subsurface.Networking } } + private IEnumerable StartGame(NetIncomingMessage inc) + { + + if (this.Character != null) Character.Remove(); + + int seed = inc.ReadInt32(); + + string levelSeed = inc.ReadString(); + + string mapName = inc.ReadString(); + string mapHash = inc.ReadString(); + + GameMain.NetLobbyScreen.TrySelectMap(mapName, mapHash); + + yield return CoroutineStatus.Running; + + double durationMinutes = inc.ReadDouble(); + + TimeSpan duration = new TimeSpan(0, (int)durationMinutes, 0); + Rand.SetSyncedSeed(seed); + //int gameModeIndex = inc.ReadInt32(); + GameMain.GameSession = new GameSession(Submarine.Loaded, "", GameMain.NetLobbyScreen.SelectedMode); + + yield return CoroutineStatus.Running; + + GameMain.GameSession.StartShift(duration, levelSeed); + + yield return CoroutineStatus.Running; + + //myCharacter = ReadCharacterData(inc); + //Character.Controlled = myCharacter; + + List crew = new List(); + + int count = inc.ReadInt32(); + for (int n = 0; n < count; n++) + { + int id = inc.ReadInt32(); + Character newCharacter = ReadCharacterData(inc, id == myID); + + crew.Add(newCharacter); + + yield return CoroutineStatus.Running; + } + + gameStarted = true; + + GameMain.GameScreen.Select(); + + AddChatMessage("Press TAB to chat", ChatMessageType.Server); + + CreateCrewFrame(crew); + + yield return CoroutineStatus.Success; + } + + public IEnumerable EndGame(string endMessage) { gameStarted = false; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 81fd3e84b..fa95c2e06 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -578,25 +578,33 @@ namespace Subsurface.Networking } - public bool StartGame(GUIButton button, object obj) + public bool StartGameClicked(GUIButton button, object obj) { - Submarine selectedMap = GameMain.NetLobbyScreen.SelectedMap as Submarine; + Submarine selectedSub = GameMain.NetLobbyScreen.SelectedMap as Submarine; - if (selectedMap == null) + if (selectedSub == null) { GameMain.NetLobbyScreen.SubList.Flash(); return false; } - - AssignJobs(); - + + GameMain.ShowLoading(StartGame(selectedSub)); + + return true; + } + + private IEnumerable StartGame(Submarine selectedSub) + { + AssignJobs(); + //selectedMap.Load(); int seed = DateTime.Now.Millisecond; Rand.SetSyncedSeed(seed); - GameMain.GameSession = new GameSession(selectedMap, "", GameMain.NetLobbyScreen.SelectedMode); + GameMain.GameSession = new GameSession(selectedSub, "", GameMain.NetLobbyScreen.SelectedMode); GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.GameDuration, GameMain.NetLobbyScreen.LevelSeed); - //EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent); + + yield return CoroutineStatus.Running; List characterInfos = new List(); @@ -622,7 +630,7 @@ namespace Subsurface.Networking List crew = new List(); WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos); - for (int i = 0; i < connectedClients.Count; i++ ) + for (int i = 0; i < connectedClients.Count; i++) { connectedClients[i].character = new Character( connectedClients[i].characterInfo, assignedWayPoints[i], true); @@ -633,14 +641,16 @@ namespace Subsurface.Networking if (characterInfo != null) { - myCharacter = new Character(characterInfo, assignedWayPoints[assignedWayPoints.Length-1]); + myCharacter = new Character(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1]); Character.Controlled = myCharacter; myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]); crew.Add(myCharacter); } - + + yield return CoroutineStatus.Running; + NetOutgoingMessage msg = server.CreateMessage(); msg.Write((byte)PacketTypes.StartGame); @@ -650,10 +660,10 @@ namespace Subsurface.Networking msg.Write(GameMain.NetLobbyScreen.SelectedMap.Name); msg.Write(GameMain.NetLobbyScreen.SelectedMap.MD5Hash.Hash); - + msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes); - msg.Write((myCharacter == null) ? connectedClients.Count : connectedClients.Count+1); + msg.Write((myCharacter == null) ? connectedClients.Count : connectedClients.Count + 1); foreach (Client client in connectedClients) { msg.Write(client.ID); @@ -666,7 +676,9 @@ namespace Subsurface.Networking WriteCharacterData(msg, myCharacter.Info.Name, Character.Controlled); } - SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null); + SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null); + + yield return CoroutineStatus.Running; gameStarted = true; @@ -676,7 +688,8 @@ namespace Subsurface.Networking CreateCrewFrame(crew); - return true; + yield return CoroutineStatus.Success; + } private bool EndButtonHit(GUIButton button, object obj) diff --git a/Subsurface/Source/PlayerInput.cs b/Subsurface/Source/PlayerInput.cs index bc687faea..89cfad5a3 100644 --- a/Subsurface/Source/PlayerInput.cs +++ b/Subsurface/Source/PlayerInput.cs @@ -80,7 +80,7 @@ namespace Subsurface public static Vector2 MousePosition { - get { return new Vector2(mouseState.X, mouseState.Y); } + get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); } } public static MouseState GetMouseState diff --git a/Subsurface/Source/Screens/EditCharacterScreen.cs b/Subsurface/Source/Screens/EditCharacterScreen.cs index dec16e249..faffba83e 100644 --- a/Subsurface/Source/Screens/EditCharacterScreen.cs +++ b/Subsurface/Source/Screens/EditCharacterScreen.cs @@ -118,10 +118,7 @@ namespace Subsurface } Physics.Alpha = Physics.accumulator / Physics.step; - } - - - + } } /// diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index dedcc3737..3ddf107f6 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -225,8 +225,9 @@ namespace Subsurface } } - dummyCharacter.ControlLocalPlayer((float)deltaTime, cam); + dummyCharacter.ControlLocalPlayer((float)deltaTime, cam, false); dummyCharacter.Control((float)deltaTime, cam); + cam.TargetPos = Vector2.Zero; } else { diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 891779d48..1451423ec 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -58,15 +58,8 @@ namespace Subsurface //http://gafferongames.com/game-physics/fix-your-timestep/ Physics.accumulator += deltaTime; - Stopwatch sw = new Stopwatch(); - sw.Start(); - AmbientSoundManager.Update(); - sw.Stop(); - Debug.WriteLine("************** abupdate: "+sw.ElapsedTicks); - sw.Restart(); - //if (Game1.GameSession != null && Game1.GameSession.Level != null) //{ // Vector2 targetMovement = Vector2.Zero; @@ -81,38 +74,17 @@ namespace Subsurface if (GameMain.GameSession!=null) GameMain.GameSession.Update((float)deltaTime); //EventManager.Update(gameTime); - sw.Stop(); - Debug.WriteLine("gamesession update: " + sw.ElapsedTicks); - sw.Restart(); - Character.UpdateAll(cam, (float)deltaTime); - sw.Stop(); - Debug.WriteLine("characterupdate: " + sw.ElapsedTicks); - sw.Restart(); - BackgroundSpriteManager.Update(cam, (float)deltaTime); - sw.Stop(); - Debug.WriteLine("bgsprite: " + sw.ElapsedTicks); - sw.Restart(); - GameMain.ParticleManager.Update((float)deltaTime); - sw.Stop(); - Debug.WriteLine("particlemanager: " + sw.ElapsedTicks); - sw.Restart(); - StatusEffect.UpdateAll((float)deltaTime); - sw.Stop(); - Debug.WriteLine("statuseff: " + sw.ElapsedTicks); - - Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4); while (Physics.accumulator >= Physics.step) { - sw.Restart(); cam.MoveCamera((float)Physics.step); foreach (PhysicsBody pb in PhysicsBody.list) @@ -122,16 +94,8 @@ namespace Subsurface MapEntity.UpdateAll(cam, (float)Physics.step); - sw.Stop(); - Debug.WriteLine(" mapentity: " + sw.ElapsedTicks); - sw.Restart(); - Character.UpdateAnimAll((float)Physics.step); - sw.Stop(); - Debug.WriteLine(" char: " + sw.ElapsedTicks); - sw.Restart(); - Ragdoll.UpdateAll(cam, (float)Physics.step); if (GameMain.GameSession != null && GameMain.GameSession.Level != null) @@ -139,16 +103,8 @@ namespace Subsurface GameMain.GameSession.Submarine.Update((float)Physics.step); } - sw.Stop(); - Debug.WriteLine(" sub: " + sw.ElapsedTicks); - sw.Restart(); - GameMain.World.Step((float)Physics.step); - sw.Stop(); - Debug.WriteLine(" worldstep: " + sw.ElapsedTicks); - sw.Restart(); - Level.AfterWorldStep(); Physics.accumulator -= Physics.step; diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index 286a8fecc..c06a2ecf3 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -4,6 +4,7 @@ using FarseerPhysics.Factories; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.Collections.Generic; namespace Subsurface { @@ -444,13 +445,21 @@ namespace Subsurface } private bool StartShift(GUIButton button, object selection) - { - GameMain.GameSession.StartShift(TimeSpan.Zero, selectedLevel, false); - GameMain.GameScreen.Select(); + { + GameMain.ShowLoading(ShiftLoading()); return true; } + private IEnumerable ShiftLoading() + { + + GameMain.GameSession.StartShift(TimeSpan.Zero, selectedLevel, false); + GameMain.GameScreen.Select(); + + yield return CoroutineStatus.Success; + } + public bool QuitToMainMenu(GUIButton button, object selection) { GameMain.MainMenuScreen.Select(); diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 8df5cd707..1d9e4e416 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -4,6 +4,7 @@ using Microsoft.Xna.Framework.Graphics; using Subsurface.Networking; using System.IO; using System.Xml.Linq; +using System.Collections.Generic; namespace Subsurface { @@ -231,6 +232,7 @@ namespace Subsurface return true; } + private bool QuitClicked(GUIButton button, object obj) { game.Exit(); @@ -261,7 +263,6 @@ namespace Subsurface var button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.Right | Alignment.Bottom, GUI.Style, menuTabs[(int)Tabs.LoadGame]); button.OnClicked = LoadGame; - } private bool SelectSaveFile(GUIComponent component, object obj) @@ -278,6 +279,8 @@ namespace Subsurface RemoveSaveFrame(); + string subName = ToolBox.GetAttributeString(doc.Root, "submarine", ""); + string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown"); XElement modeElement = null; @@ -291,17 +294,20 @@ namespace Subsurface string mapseed = ToolBox.GetAttributeString(modeElement, "mapseed", "unknown"); - GUIFrame saveFileFrame = new GUIFrame(new Rectangle((int)(saveList.Rect.Width + 20), 0, 200, 200), Color.Black*0.4f, GUI.Style, menuTabs[(int)Tabs.LoadGame]); + GUIFrame saveFileFrame = new GUIFrame(new Rectangle((int)(saveList.Rect.Width + 20), 0, 200, 230), Color.Black*0.4f, GUI.Style, menuTabs[(int)Tabs.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, GUI.Style, saveFileFrame); - new GUITextBlock(new Rectangle(0, 30, 0, 20), "Last saved: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; - new GUITextBlock(new Rectangle(15, 45, 0, 20), saveTime, GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(0, 30, 0, 20), subName, GUI.Style, saveFileFrame); - new GUITextBlock(new Rectangle(0, 65, 0, 20), "Map seed: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; - new GUITextBlock(new Rectangle(15, 80, 0, 20), mapseed, GUI.Style, saveFileFrame).Font = GUI.SmallFont; + + new GUITextBlock(new Rectangle(0, 50, 0, 20), "Last saved: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(15, 65, 0, 20), saveTime, GUI.Style, saveFileFrame).Font = GUI.SmallFont; + + new GUITextBlock(new Rectangle(0, 85, 0, 20), "Map seed: ", GUI.Style, saveFileFrame).Font = GUI.SmallFont; + new GUITextBlock(new Rectangle(15, 100, 0, 20), mapseed, GUI.Style, saveFileFrame).Font = GUI.SmallFont; var deleteSaveButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Delete", Alignment.BottomCenter, GUI.Style, saveFileFrame); deleteSaveButton.UserData = fileName; @@ -353,7 +359,8 @@ namespace Subsurface { graphics.Clear(Color.CornflowerBlue); - GameMain.TitleScreen.Draw(spriteBatch, graphics, -1.0f, (float)deltaTime); + GameMain.TitleScreen.DrawLoadingText = false; + GameMain.TitleScreen.Draw(spriteBatch, graphics, (float)deltaTime); //Game1.GameScreen.DrawMap(graphics, spriteBatch); @@ -406,7 +413,6 @@ namespace Subsurface private bool LoadGame(GUIButton button, object obj) { - string saveFile = saveList.SelectedData as string; if (string.IsNullOrWhiteSpace(saveFile)) return false; diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 8089d8c56..7ca5533ee 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -273,7 +273,7 @@ namespace Subsurface if (IsServer && GameMain.Server != null) { GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.BottomRight, GUI.Style, infoFrame); - startButton.OnClicked = GameMain.Server.StartGame; + startButton.OnClicked = GameMain.Server.StartGameClicked; startButton.UserData = "startButton"; //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); @@ -523,14 +523,7 @@ namespace Subsurface if ((prevSize == 1.0f && chatBox.BarScroll == 0.0f) || (prevSize < 1.0f && chatBox.BarScroll == 1.0f)) chatBox.BarScroll = 1.0f; } - - - public bool StartGame(object obj) - { - GameMain.Server.StartGame(null, obj); - return true; - } - + public bool EnterChatMessage(GUITextBox textBox, string message) { if (String.IsNullOrEmpty(message)) return false; diff --git a/Subsurface/Source/Sounds/Sound.cs b/Subsurface/Source/Sounds/Sound.cs index 4e831a597..df1190f66 100644 --- a/Subsurface/Source/Sounds/Sound.cs +++ b/Subsurface/Source/Sounds/Sound.cs @@ -229,6 +229,9 @@ namespace Subsurface public void Remove() { + //sound already removed? + if (!loadedSounds.Contains(this)) return; + loadedSounds.Remove(this); System.Diagnostics.Debug.WriteLine("Removing sound " + filePath + " (buffer id" + AlBufferId + ")"); diff --git a/Subsurface/Source/Utils/SaveUtil.cs b/Subsurface/Source/Utils/SaveUtil.cs index 140cde774..c73ea070c 100644 --- a/Subsurface/Source/Utils/SaveUtil.cs +++ b/Subsurface/Source/Utils/SaveUtil.cs @@ -10,7 +10,7 @@ namespace Subsurface { public class SaveUtil { - private const string SaveFolder = "Content/Data/Saves/"; + private const string SaveFolder = "Data/Saves/"; public delegate void ProgressDelegate(string sMessage); @@ -18,10 +18,8 @@ namespace Subsurface { fileName = SaveFolder + fileName; - string tempPath = SaveFolder + "\\temp"; - - - + string tempPath = Path.Combine(SaveFolder, "temp"); + if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); @@ -34,11 +32,11 @@ namespace Subsurface { if (Submarine.Loaded!=null) { - Submarine.Loaded.SaveAs(tempPath + "\\map.gz"); + Submarine.Loaded.SaveAs(Path.Combine(tempPath, "map.gz")); } else { - File.Copy(GameMain.GameSession.Submarine.FilePath, tempPath + "\\map.gz"); + File.Copy(GameMain.GameSession.Submarine.FilePath, Path.Combine(tempPath, "map.gz")); } } catch (Exception e) @@ -48,7 +46,7 @@ namespace Subsurface try { - GameMain.GameSession.Save(tempPath + "\\gamesession.xml"); + GameMain.GameSession.Save(Path.Combine(tempPath, "gamesession.xml")); } catch (Exception e) @@ -69,32 +67,31 @@ namespace Subsurface public static void LoadGame(string fileName) { - string filePath = SaveFolder + fileName+".save"; - - string tempPath = SaveFolder + "\\temp"; + string filePath = Path.Combine(SaveFolder, fileName+".save"); + string tempPath = Path.Combine(SaveFolder, "temp"); DecompressToDirectory(filePath, tempPath, null); - Submarine selectedMap = Submarine.Load(tempPath +"\\map.gz"); - GameMain.GameSession = new GameSession(selectedMap, fileName, tempPath + "\\gamesession.xml"); + Submarine selectedMap = new Submarine(Path.Combine(tempPath, "map.gz"), "");// Submarine.Load(); + GameMain.GameSession = new GameSession(selectedMap, fileName, Path.Combine(tempPath, "gamesession.xml")); //Directory.Delete(tempPath, true); } public static XDocument LoadGameSessionDoc(string fileName) { - string filePath = SaveFolder + fileName + ".save"; + string filePath = Path.Combine(SaveFolder, fileName + ".save"); - string tempPath = SaveFolder + "\\temp"; + string tempPath = Path.Combine(SaveFolder, "temp"); DecompressToDirectory(filePath, tempPath, null); - return ToolBox.TryLoadXml(tempPath + "\\gamesession.xml"); + return ToolBox.TryLoadXml(Path.Combine(tempPath, "gamesession.xml")); } public static void DeleteSave(string fileName) { - fileName = SaveFolder + fileName + ".save"; + fileName = Path.Combine(SaveFolder, fileName + ".save"); try { @@ -142,9 +139,10 @@ namespace Subsurface } string extension = ".save"; + string pathWithoutExtension = Path.Combine(SaveFolder, fileName); int i = 0; - while (File.Exists(SaveFolder + fileName + i + extension)) + while (File.Exists(pathWithoutExtension + i + extension)) { i++; } diff --git a/Subsurface/Source/Utils/UpdaterUtil.cs b/Subsurface/Source/Utils/UpdaterUtil.cs index 5541efa7d..83e55b512 100644 --- a/Subsurface/Source/Utils/UpdaterUtil.cs +++ b/Subsurface/Source/Utils/UpdaterUtil.cs @@ -136,17 +136,25 @@ namespace Subsurface File.Delete(fileRelPath); } + //couldn't delete file, probably because it's already in use catch { - string oldFileName = currentDir+"\\"+Path.GetDirectoryName(fileRelPath)+"\\OLD_"+Path.GetFileName(fileRelPath); + string oldFileName = Path.Combine(currentDir, Path.GetDirectoryName(fileRelPath), "OLD_"+Path.GetFileName(fileRelPath)); if (File.Exists(oldFileName)) File.Delete(oldFileName); - - //couldn't delete file, probably because it's already in use + File.Move(fileRelPath, oldFileName); } } + string directoryName = Path.GetDirectoryName(fileRelPath); + if (!string.IsNullOrWhiteSpace(directoryName)) + { + Directory.CreateDirectory(directoryName); + } + + + System.Diagnostics.Debug.WriteLine("moving: "+file+" -> "+fileRelPath); File.Move(file, fileRelPath); } @@ -161,13 +169,20 @@ namespace Subsurface foreach (string file in files) { - if (filesToKeep.Contains(GetRelativePath(file, currentDir))) continue; + string relativePath = GetRelativePath(file, currentDir); + + string dirRoot = relativePath.Split(Path.DirectorySeparatorChar).First(); + if (dirRoot == "Data") continue; + + if (filesToKeep.Contains(relativePath)) continue; + + if (Path.GetFileName(file).Split('_').First() == "OLD") continue; System.Diagnostics.Debug.WriteLine("deleting file "+file); try { - File.Delete(currentDir + "\\" + file); + File.Delete(file); } catch (Exception e) @@ -187,13 +202,13 @@ namespace Subsurface foreach (string file in files) { - if (file.Length<4 || file.Substring(0,4)!="OLD_") continue; + if (Path.GetFileName(file).Split('_').First() != "OLD") continue; System.Diagnostics.Debug.WriteLine("deleting file " + file); try { - File.Delete(currentDir + "\\" + file); + File.Delete(file); } catch (Exception e) diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index ef3785d5f..493c0afeb 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -215,7 +215,7 @@ - + @@ -536,6 +536,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -741,6 +744,7 @@ PreserveNewest + PreserveNewest @@ -976,7 +980,7 @@ - + diff --git a/Subsurface/Subsurface.csproj.user b/Subsurface/Subsurface.csproj.user index c2dd67340..d8060d791 100644 --- a/Subsurface/Subsurface.csproj.user +++ b/Subsurface/Subsurface.csproj.user @@ -9,7 +9,7 @@ en-US false - ShowAllFiles + ProjectFiles diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 3932c192e..b6b8ebe6f 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ