autoupdater fixes, cursor fix, consistent directory separators + use of Path.Combine(), wire bugfixes, more loading screens

This commit is contained in:
Regalis
2015-10-02 21:33:33 +03:00
parent 24f7a1baa5
commit a285b00eb9
51 changed files with 451 additions and 1304 deletions
+1 -1
View File
@@ -227,7 +227,7 @@
this.Controls.Add(this.pictureBox1); this.Controls.Add(this.pictureBox1);
this.DoubleBuffered = true; this.DoubleBuffered = true;
this.Name = "LauncherMain"; this.Name = "LauncherMain";
this.Text = "Form1"; this.Text = "Launcher";
this.Load += new System.EventHandler(this.LauncherMain_Load); this.Load += new System.EventHandler(this.LauncherMain_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
+25 -1
View File
@@ -131,7 +131,30 @@ namespace Launcher
{ {
SaveSettings(configPath); 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(); Application.Exit();
} }
@@ -294,6 +317,7 @@ namespace Launcher
updateLabel.Visible = false; updateLabel.Visible = false;
MessageBox.Show("Download completed!"); MessageBox.Show("Download completed!");
settings.WasGameUpdated = true;
return; return;
} }
+1 -1
View File
@@ -3677,7 +3677,7 @@
<data name="$this.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAABYQAAAWKCAYAAABIIWEyAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1 iVBORw0KGgoAAAANSUhEUgAABYQAAAWKCAYAAABIIWEyAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACxAAAAsQAa0jvXUAAP+WSURBVHhe7P3ptuw8c6QJSpka MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACw8AAAsPAZL5A6UAAP+WSURBVHhe7P3ptuw8c6QJSpka
Xs2Zyqys6q5/ff/3qKZ7uHkYjA4QZDBiDwda61mAmw8YyIgg8W2d92+2//uvxWKxWCzu4G//9r+V+uJz Xs2Zyqys6q5/ff/3qKZ7uHkYjA4QZDBiDwda61mAmw8YyIgg8W2d92+2//uvxWKxWCzu4G//9r+V+uJz
/KRrwHO1PuxPreEd41Rrcv7735UxPXoxqJc216X+CMzHkXG4/q5POdVYGRN5CfLUx7qgY6q9q7O1GePa /KRrwHO1PuxPreEd41Rrcv7735UxPXoxqJc216X+CMzHkXG4/q5POdVYGRN5CfLUx7qgY6q9q7O1GePa
3z8I+5n/996HjT7T00dgHMzVNZ4rzZnjEZs55PeW8rIea/9N+mFzPd6HJPZhr0d9HavSldm4X0XcZ3fy 3z8I+5n/996HjT7T00dgHMzVNZ4rzZnjEZs55PeW8rIea/9N+mFzPd6HJPZhr0d9HavSldm4X0XcZ3fy
+46 -8
View File
@@ -66,7 +66,7 @@ namespace Launcher2
{ {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 640; graphics.PreferredBackBufferWidth = 640;
graphics.PreferredBackBufferHeight = 360; graphics.PreferredBackBufferHeight = 400;
IsMouseVisible = true; IsMouseVisible = true;
@@ -116,13 +116,13 @@ namespace Launcher2
updateInfoText = new GUITextBlock(new Rectangle(0,y+30,100,20), "", GUI.Style, guiRoot); 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; 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; 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.OnClicked = DownloadButtonClicked;
downloadButton.Visible = false; downloadButton.Visible = false;
@@ -197,9 +197,14 @@ namespace Launcher2
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); 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); guiRoot.Draw(spriteBatch);
if (GUIMessageBox.MessageBoxes.Count > 0)
{
var messageBox = GUIMessageBox.MessageBoxes.Peek();
if (messageBox != null) messageBox.Draw(spriteBatch);
}
spriteBatch.End(); spriteBatch.End();
} }
@@ -237,7 +242,30 @@ namespace Launcher2
{ {
if (!TrySaveSettings(configPath)) return false; if (!TrySaveSettings(configPath)) return false;
Process.Start(new ProcessStartInfo(Directory.GetCurrentDirectory() + "//" + settings.SelectedContentPackage.GetFilesOfType(ContentType.Executable)[0])); 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;
}
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(); Exit();
return true; return true;
@@ -428,12 +456,15 @@ namespace Launcher2
catch (Exception e) catch (Exception e)
{ {
updateInfoText.Text = "Update failed"; updateInfoText.Text = "Update failed";
SetUpdateInfoBox("Error while installing the update: "+e.Message); ShowError("Error while installing the update", e.Message);
launchButton.Enabled = true; launchButton.Enabled = true;
return; return;
} }
//UpdaterUtil.CleanUnnecessaryFiles(latestVersionFiles); settings.WasGameUpdated = true;
UpdaterUtil.CleanUnnecessaryFiles(latestVersionFiles);
updateInfoText.Text = "The game was updated succesfully!"; updateInfoText.Text = "The game was updated succesfully!";
launchButton.Enabled = true; launchButton.Enabled = true;
@@ -468,6 +499,13 @@ namespace Launcher2
webClient.DownloadFileAsync(new Uri(latestVersionFolder + filesToDownload[filesDownloaded]), @dir + "\\" + filesToDownload[filesDownloaded]); 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) private void Completed(object sender, AsyncCompletedEventArgs e)
{ {
if (e.Error!=null) if (e.Error!=null)
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<backgroundsprites> <backgroundsprites>
<Fish1 speed ="100.0" wanderamount="5.0" wanderzamount="0.1" swarmmin="2" swarmmax="10" swarmradius="500"> <Fish1 speed ="100.0" wanderamount="5.0" wanderzamount="0.1" swarmmin="2" swarmmax="10" swarmradius="500">
<Sprite texture="Content\BackgroundSprites\bgFish1.png" sourcerect="0,0,128,64"/> <Sprite texture="Content/BackgroundSprites/bgFish1.png" sourcerect="0,0,128,64"/>
</Fish1> </Fish1>
<Fish2 speed="20.0" wanderamount="0.2" wanderzamount="0.1" swarmmin="1" swarmmax="3" swarmradius="300"> <Fish2 speed="20.0" wanderamount="0.2" wanderzamount="0.1" swarmmin="1" swarmmax="3" swarmradius="300">
<Sprite texture="Content\BackgroundSprites\bgFish1.png" sourcerect="0,64,128,64"/> <Sprite texture="Content/BackgroundSprites/bgFish1.png" sourcerect="0,64,128,64"/>
</Fish2> </Fish2>
</backgroundsprites> </backgroundsprites>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 849 B

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<contentpackage name="Vanilla 0.1.3" path="Data/ContentPackages/Vanilla 0.1.3">
<Item file="Content\Items\idcard.xml" />
<Item file="Content\Items\itemlabel.xml" />
<Item file="Content\Items\Artifacts\artifacts.xml" />
<Item file="Content\Items\Button\button.xml" />
<Item file="Content\Items\Clothes\clothes.xml" />
<Item file="Content\Items\Diving\divinggear.xml" />
<Item file="Content\Items\Door\doors.xml" />
<Item file="Content\Items\Electricity\lights.xml" />
<Item file="Content\Items\Electricity\monitors.xml" />
<Item file="Content\Items\Electricity\poweritems.xml" />
<Item file="Content\Items\Electricity\signalitems.xml" />
<Item file="Content\Items\Engine\engine.xml" />
<Item file="Content\Items\Fabricators\fabricators.xml" />
<Item file="Content\Items\Ladder\ladder.xml" />
<Item file="Content\Items\Lockers\lockers.xml" />
<Item file="Content\Items\Medical\medical.xml" />
<Item file="Content\Items\MiniMap\item.xml" />
<Item file="Content\Items\OxygenGenerator\oxygengenerator.xml" />
<Item file="Content\Items\Pump\pump.xml" />
<Item file="Content\Items\Reactor\reactor.xml" />
<Item file="Content\Items\Tools\tools.xml" />
<Item file="Content\Items\Weapons\explosives.xml" />
<Item file="Content\Items\Weapons\railgun.xml" />
<Item file="Content\Items\Weapons\weapons.xml" />
<Character file="Content\Characters\Crawler\crawler.xml" />
<Character file="Content\Characters\Human\human.xml" />
<Character file="Content\Characters\Mantis\mantis.xml" />
<Character file="Content\Characters\Moloch\moloch.xml" />
<Character file="Content\Characters\Scorpion\scorpion.xml" />
<Character file="Content\Characters\TigerThresher\tigerthresher.xml" />
<Structure file="Content\Map\StructurePrefabs.xml" />
<Jobs file="Content\Jobs.xml" />
<Executable file="Subsurface.exe" />
</contentpackage>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -601,11 +601,6 @@ namespace Subsurface
/// </summary> /// </summary>
public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true) 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); Limb head = AnimController.GetLimb(LimbType.Head);
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(head.SimPosition); Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(head.SimPosition);
@@ -49,11 +49,6 @@ namespace Subsurface
public override void UpdateAnim(float deltaTime) public override void UpdateAnim(float deltaTime)
{ {
if (PlayerInput.KeyHit(Keys.I))
{
SimplePhysicsEnabled = !SimplePhysicsEnabled;
}
if (character.IsDead) if (character.IsDead)
{ {
UpdateDying(deltaTime); UpdateDying(deltaTime);
+1 -1
View File
@@ -125,7 +125,7 @@ namespace Subsurface
//{ //{
// doc.Root.Add(new XElement("item", new XAttribute("file", itemFile))); // 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() private void CalculateHash()
+8
View File
@@ -24,6 +24,14 @@ namespace Subsurface
Coroutines.Add(func.GetEnumerator()); Coroutines.Add(func.GetEnumerator());
} }
public static bool IsCoroutineRunning(string name)
{
IEnumerator<object> coroutine = Coroutines.FirstOrDefault(
c => c.ToString().Contains(name));
return coroutine!=null;
}
public static void StopCoroutine(string name) public static void StopCoroutine(string name)
{ {
IEnumerator<object> coroutine = Coroutines.FirstOrDefault(c => c.ToString().Contains(name)); IEnumerator<object> coroutine = Coroutines.FirstOrDefault(c => c.ToString().Contains(name));
+2 -2
View File
@@ -282,13 +282,13 @@ namespace Subsurface
DebugConsole.ThrowError("Illegal symbols in filename (../)"); DebugConsole.ThrowError("Illegal symbols in filename (../)");
return; return;
} }
Submarine.SaveCurrent("Content/SavedMaps/" + fileName +".gz"); Submarine.SaveCurrent(fileName +".gz");
NewMessage("map saved", Color.Green); NewMessage("map saved", Color.Green);
break; break;
case "loadmap": case "loadmap":
case "loadsub": case "loadsub":
if (commands.Length < 2) break; if (commands.Length < 2) break;
Submarine.Load("Content/SavedMaps/" + string.Join(" ", commands.Skip(1))); Submarine.Load(string.Join(" ", commands.Skip(1)));
break; break;
case "messagebox": case "messagebox":
if (commands.Length < 3) break; if (commands.Length < 3) break;
+6 -1
View File
@@ -23,6 +23,8 @@ namespace Subsurface
static Texture2D t; static Texture2D t;
public static SpriteFont Font, SmallFont, LargeFont; public static SpriteFont Font, SmallFont, LargeFont;
private static Sprite cursor;
private static GraphicsDevice graphicsDevice; private static GraphicsDevice graphicsDevice;
private static List<GUIMessage> messages = new List<GUIMessage>(); private static List<GUIMessage> messages = new List<GUIMessage>();
@@ -37,6 +39,8 @@ namespace Subsurface
GUI.Font = ToolBox.TryLoadFont("SpriteFont1", content); GUI.Font = ToolBox.TryLoadFont("SpriteFont1", content);
GUI.SmallFont = ToolBox.TryLoadFont("SmallFont", content); GUI.SmallFont = ToolBox.TryLoadFont("SmallFont", content);
GUI.LargeFont = ToolBox.TryLoadFont("LargeFont", content); GUI.LargeFont = ToolBox.TryLoadFont("LargeFont", content);
cursor = new Sprite("Content/UI/cursor.png" ,Vector2.Zero);
} }
public static bool PauseMenuOpen public static bool PauseMenuOpen
@@ -345,8 +349,9 @@ namespace Subsurface
DebugConsole.Draw(spriteBatch); DebugConsole.Draw(spriteBatch);
if (GUIComponent.MouseOn != null && !string.IsNullOrWhiteSpace(GUIComponent.MouseOn.ToolTip)) GUIComponent.MouseOn.DrawToolTip(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) public static void Update(float deltaTime)
+3 -11
View File
@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Subsurface namespace Subsurface
{ {
class GUIMessageBox : GUIFrame public class GUIMessageBox : GUIFrame
{ {
public static Queue<GUIMessageBox> MessageBoxes = new Queue<GUIMessageBox>(); public static Queue<GUIMessageBox> MessageBoxes = new Queue<GUIMessageBox>();
@@ -38,18 +38,10 @@ namespace Subsurface
this.Buttons[0].OnClicked = Close; 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), : 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, 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); new GUITextBlock(new Rectangle(0, 30, 0, height - 70), text, Color.Transparent, Color.White, textAlignment, GUI.Style, this, true);
+66 -21
View File
@@ -9,7 +9,7 @@ using System.Text;
namespace Subsurface namespace Subsurface
{ {
class TitleScreen class LoadingScreen
{ {
private Texture2D backgroundTexture,monsterTexture,titleTexture; private Texture2D backgroundTexture,monsterTexture,titleTexture;
@@ -21,6 +21,8 @@ namespace Subsurface
public Vector2 TitlePosition; public Vector2 TitlePosition;
private float? loadState;
public Vector2 TitleSize public Vector2 TitleSize
{ {
get { return new Vector2(titleTexture.Width, titleTexture.Height); } get { return new Vector2(titleTexture.Width, titleTexture.Height); }
@@ -32,7 +34,24 @@ namespace Subsurface
private set; 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"); backgroundTexture = TextureLoader.FromFile("Content/UI/titleBackground.png");
monsterTexture = TextureLoader.FromFile("Content/UI/titleMonster.png"); monsterTexture = TextureLoader.FromFile("Content/UI/titleMonster.png");
@@ -40,31 +59,27 @@ namespace Subsurface
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); 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) drawn = true;
//{
// stopwatch = new Stopwatch();
// stopwatch.Start();
//}
graphics.SetRenderTarget(renderTarget); graphics.SetRenderTarget(renderTarget);
//Debug.WriteLine(stopwatch.Elapsed.TotalMilliseconds);
Scale = GameMain.GraphicsHeight/1500.0f; Scale = GameMain.GraphicsHeight/1500.0f;
state += deltaTime; state += deltaTime;
if (loadState>-1) if (DrawLoadingText)
{ {
CenterPosition = new Vector2(GameMain.GraphicsWidth*0.3f, GameMain.GraphicsHeight/2.0f); 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 = 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); TitlePosition.X = Math.Min(TitlePosition.X, (float)GameMain.GraphicsWidth / 2.0f);
} }
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
graphics.Clear(Color.Black); graphics.Clear(Color.Black);
@@ -92,21 +107,51 @@ namespace Subsurface
TitlePosition, null, 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); 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 (DrawLoadingText)
if (loadState == 100.0f)
{ {
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(); spriteBatch.End();
} }
bool drawn;
public IEnumerable<object> DoLoading(IEnumerable<object> 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;
}
} }
} }
@@ -57,11 +57,13 @@ namespace Subsurface
public static World World; public static World World;
public static TitleScreen TitleScreen; public static LoadingScreen TitleScreen;
private bool titleScreenOpen; private static bool titleScreenOpen;
public static GameSettings Config; public static GameSettings Config;
private bool hasLoaded;
//public static Random localRandom; //public static Random localRandom;
//public static Random random; //public static Random random;
@@ -98,6 +100,12 @@ namespace Subsurface
Graphics = new GraphicsDeviceManager(this); Graphics = new GraphicsDeviceManager(this);
Config = new GameSettings("config.xml"); Config = new GameSettings("config.xml");
if (Config.WasGameUpdated)
{
UpdaterUtil.CleanOldFiles();
Config.WasGameUpdated = false;
Config.Save("config.xml");
}
graphicsWidth = Config.GraphicsWidth; graphicsWidth = Config.GraphicsWidth;
graphicsHeight = Config.GraphicsHeight; graphicsHeight = Config.GraphicsHeight;
@@ -112,9 +120,7 @@ namespace Subsurface
FrameCounter = new FrameCounter(); FrameCounter = new FrameCounter();
//renderTimer = new Stopwatch(); //IsMouseVisible = true;
IsMouseVisible = true;
IsFixedTimeStep = false; IsFixedTimeStep = false;
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55); //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
@@ -158,12 +164,11 @@ namespace Subsurface
TextureLoader.Init(GraphicsDevice); TextureLoader.Init(GraphicsDevice);
titleScreenOpen = true; titleScreenOpen = true;
TitleScreen = new TitleScreen(GraphicsDevice); TitleScreen = new LoadingScreen(GraphicsDevice);
CoroutineManager.StartCoroutine(Load()); CoroutineManager.StartCoroutine(Load());
} }
private float loadState = 0.0f;
private IEnumerable<object> Load() private IEnumerable<object> Load()
{ {
GUI.Init(Content); GUI.Init(Content);
@@ -173,42 +178,42 @@ namespace Subsurface
LightManager = new Lights.LightManager(GraphicsDevice); LightManager = new Lights.LightManager(GraphicsDevice);
Hull.renderer = new WaterRenderer(GraphicsDevice); Hull.renderer = new WaterRenderer(GraphicsDevice);
loadState = 1.0f; TitleScreen.LoadState = 1.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
GUI.LoadContent(GraphicsDevice); GUI.LoadContent(GraphicsDevice);
loadState = 2.0f; TitleScreen.LoadState = 2.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
MapEntityPrefab.Init(); MapEntityPrefab.Init();
loadState = 10.0f; TitleScreen.LoadState = 10.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs)); JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs));
loadState = 15.0f; TitleScreen.LoadState = 15.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure)); StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure));
loadState = 25.0f; TitleScreen.LoadState = 25.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item)); ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item));
loadState = 40.0f; TitleScreen.LoadState = 40.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
Debug.WriteLine("sounds"); Debug.WriteLine("sounds");
CoroutineManager.StartCoroutine(AmbientSoundManager.Init()); CoroutineManager.StartCoroutine(AmbientSoundManager.Init());
loadState = 70.0f; TitleScreen.LoadState = 70.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
GameModePreset.Init(); GameModePreset.Init();
Submarine.Preload("Content/SavedMaps"); Submarine.Preload();
loadState = 80.0f; TitleScreen.LoadState = 80.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
GameScreen = new GameScreen(Graphics.GraphicsDevice); GameScreen = new GameScreen(Graphics.GraphicsDevice);
loadState = 90.0f; TitleScreen.LoadState = 90.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
MainMenuScreen = new MainMenuScreen(this); MainMenuScreen = new MainMenuScreen(this);
@@ -233,8 +238,10 @@ namespace Subsurface
MainMenuScreen.Select(); MainMenuScreen.Select();
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
loadState = 100.0f; TitleScreen.LoadState = 100.0f;
hasLoaded = true;
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
/// <summary> /// <summary>
@@ -259,7 +266,7 @@ namespace Subsurface
double deltaTime = gameTime.ElapsedGameTime.TotalSeconds; double deltaTime = gameTime.ElapsedGameTime.TotalSeconds;
PlayerInput.Update(deltaTime); PlayerInput.Update(deltaTime);
if (loadState >= 100.0f && !titleScreenOpen) if (hasLoaded && !titleScreenOpen)
{ {
if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu(); if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu();
@@ -296,18 +303,18 @@ namespace Subsurface
if (titleScreenOpen) if (titleScreenOpen)
{ {
TitleScreen.Draw(spriteBatch, GraphicsDevice, loadState, (float)deltaTime); TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime);
if (loadState>=100.0f && (PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked())) if (TitleScreen.LoadState>=100.0f && (PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
{ {
titleScreenOpen = false; titleScreenOpen = false;
} }
} }
else if (loadState >= 100.0f) else if (hasLoaded)
{ {
Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch); Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch);
} }
double elapsed =sw.Elapsed.TotalSeconds; double elapsed = sw.Elapsed.TotalSeconds;
if (elapsed < Physics.step) if (elapsed < Physics.step)
{ {
System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0)); System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0));
@@ -317,6 +324,15 @@ namespace Subsurface
Stopwatch sw; Stopwatch sw;
public static void ShowLoading(IEnumerable<object> loader)
{
titleScreenOpen = true;
CoroutineManager.StartCoroutine(TitleScreen.DoLoading(loader));
}
protected override void OnExiting(object sender, EventArgs args) protected override void OnExiting(object sender, EventArgs args)
{ {
if (NetworkMember != null) NetworkMember.Disconnect(); if (NetworkMember != null) NetworkMember.Disconnect();
@@ -190,6 +190,8 @@ namespace Subsurface
var now = DateTime.Now; var now = DateTime.Now;
doc.Root.Add(new XAttribute("savetime", now.Hour + ":" + now.Minute + ", " + now.ToShortDateString())); 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); ((SinglePlayerMode)gameMode).Save(doc.Root);
try try
+12
View File
@@ -43,6 +43,12 @@ namespace Subsurface
set; set;
} }
public bool WasGameUpdated
{
get;
set;
}
public GameSettings(string filePath) public GameSettings(string filePath)
{ {
Load(filePath); Load(filePath);
@@ -75,6 +81,7 @@ namespace Subsurface
MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", ""); MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", "");
AutoCheckUpdates = ToolBox.GetAttributeBool(doc.Root, "autocheckupdates", true); AutoCheckUpdates = ToolBox.GetAttributeBool(doc.Root, "autocheckupdates", true);
WasGameUpdated = ToolBox.GetAttributeBool(doc.Root, "wasgameupdated", false);
foreach (XElement subElement in doc.Root.Elements()) foreach (XElement subElement in doc.Root.Elements())
{ {
@@ -103,6 +110,11 @@ namespace Subsurface
new XAttribute("masterserverurl", MasterServerUrl), new XAttribute("masterserverurl", MasterServerUrl),
new XAttribute("autocheckupdates", AutoCheckUpdates)); new XAttribute("autocheckupdates", AutoCheckUpdates));
if (WasGameUpdated)
{
doc.Root.Add(new XAttribute("gamupdated", true));
}
XElement gMode = doc.Root.Element("graphicsmode"); XElement gMode = doc.Root.Element("graphicsmode");
if (gMode == null) if (gMode == null)
@@ -232,7 +232,10 @@ namespace Subsurface.Items.Components
case "sound": case "sound":
string filePath = ToolBox.GetAttributeString(subElement, "file", ""); string filePath = ToolBox.GetAttributeString(subElement, "file", "");
if (filePath=="") continue; 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; ActionType type;
@@ -78,7 +78,6 @@ namespace Subsurface.Items.Components
if (sparkSounds == null) if (sparkSounds == null)
{ {
sparkSounds = new Sound[4]; sparkSounds = new Sound[4];
string dir = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\";
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
sparkSounds[i] = Sound.Load("Content/Items/Electricity/zap" + (i + 1) + ".ogg", false); sparkSounds[i] = Sound.Load("Content/Items/Electricity/zap" + (i + 1) + ".ogg", false);
@@ -82,21 +82,10 @@ namespace Subsurface.Items.Components
} }
float degreeOfSuccess = DegreeOfSuccess(character); 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); 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; return true;
} }
@@ -68,6 +68,15 @@ namespace Subsurface.Items.Components
if (connections[i] == newConnection) return; 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++) for (int i = 0; i < 2; i++)
{ {
if (connections[i] != null) continue; if (connections[i] != null) continue;
@@ -76,6 +85,9 @@ namespace Subsurface.Items.Components
if (!addNode) break; 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) if (i == 0)
{ {
Nodes.Insert(0, newConnection.Item.Position); Nodes.Insert(0, newConnection.Item.Position);
+1 -1
View File
@@ -126,7 +126,7 @@ namespace Subsurface
distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/attack.Range; distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/attack.Range;
c.AddDamage(limb.SimPosition, DamageType.None, 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) if (force>0.0f)
{ {
limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition - simPosition) * distFactor * force); limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition - simPosition) * distFactor * force);
+14 -14
View File
@@ -22,6 +22,8 @@ namespace Subsurface
class Submarine : Entity class Submarine : Entity
{ {
public const string SavePath = "Data/SavedSubs";
public static List<Submarine> SavedSubmarines = new List<Submarine>(); public static List<Submarine> SavedSubmarines = new List<Submarine>();
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f); public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
@@ -33,7 +35,6 @@ namespace Subsurface
private static Vector2 lastPickedPosition; private static Vector2 lastPickedPosition;
private static float lastPickedFraction; private static float lastPickedFraction;
static string SaveFolder;
Md5Hash hash; Md5Hash hash;
private string filePath; private string filePath;
@@ -448,35 +449,34 @@ namespace Subsurface
//doc.Save(filePath); //doc.Save(filePath);
} }
public static void SaveCurrent(string savePath) public static void SaveCurrent(string fileName)
{ {
if (loaded==null) if (loaded==null)
{ {
loaded = new Submarine(savePath); loaded = new Submarine(fileName);
// return; // return;
} }
loaded.SaveAs(savePath); loaded.SaveAs(SavePath+"/"+fileName);
} }
public static void Preload(string folder) public static void Preload()
{ {
SaveFolder = folder;
//string[] mapFilePaths; //string[] mapFilePaths;
Unload(); Unload();
SavedSubmarines.Clear(); SavedSubmarines.Clear();
if (!Directory.Exists(SaveFolder)) if (!Directory.Exists(SavePath))
{ {
try 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; return;
} }
} }
@@ -485,11 +485,11 @@ namespace Subsurface
try try
{ {
filePaths = Directory.GetFiles(SaveFolder); filePaths = Directory.GetFiles(SavePath);
} }
catch (Exception e) catch (Exception e)
{ {
DebugConsole.ThrowError("Couldn't open directory ''" + SaveFolder + "''!", e); DebugConsole.ThrowError("Couldn't open directory ''" + SavePath + "''!", e);
return; return;
} }
@@ -618,11 +618,11 @@ namespace Subsurface
loaded = this; loaded = this;
} }
public static Submarine Load(string file) public static Submarine Load(string fileName)
{ {
Unload(); Unload();
Submarine sub = new Submarine(file); Submarine sub = new Submarine(SavePath+"/"+fileName);
sub.Load(); sub.Load();
//Entity.dictionary.Add(int.MaxValue, sub); //Entity.dictionary.Add(int.MaxValue, sub);
+58 -41
View File
@@ -319,47 +319,7 @@ namespace Subsurface.Networking
case (byte)PacketTypes.StartGame: case (byte)PacketTypes.StartGame:
if (gameStarted) continue; if (gameStarted) continue;
if (this.Character != null) Character.Remove(); GameMain.ShowLoading(StartGame(inc));
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<Character> crew = new List<Character>();
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);
break; break;
case (byte)PacketTypes.EndGame: case (byte)PacketTypes.EndGame:
@@ -416,6 +376,63 @@ namespace Subsurface.Networking
} }
} }
private IEnumerable<object> 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<Character> crew = new List<Character>();
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<object> EndGame(string endMessage) public IEnumerable<object> EndGame(string endMessage)
{ {
gameStarted = false; gameStarted = false;
+22 -9
View File
@@ -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(); GameMain.NetLobbyScreen.SubList.Flash();
return false; return false;
} }
GameMain.ShowLoading(StartGame(selectedSub));
return true;
}
private IEnumerable<object> StartGame(Submarine selectedSub)
{
AssignJobs(); AssignJobs();
//selectedMap.Load(); //selectedMap.Load();
int seed = DateTime.Now.Millisecond; int seed = DateTime.Now.Millisecond;
Rand.SetSyncedSeed(seed); 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); GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.GameDuration, GameMain.NetLobbyScreen.LevelSeed);
//EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent);
yield return CoroutineStatus.Running;
List<CharacterInfo> characterInfos = new List<CharacterInfo>(); List<CharacterInfo> characterInfos = new List<CharacterInfo>();
@@ -622,7 +630,7 @@ namespace Subsurface.Networking
List<Character> crew = new List<Character>(); List<Character> crew = new List<Character>();
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos); 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].character = new Character(
connectedClients[i].characterInfo, assignedWayPoints[i], true); connectedClients[i].characterInfo, assignedWayPoints[i], true);
@@ -633,7 +641,7 @@ namespace Subsurface.Networking
if (characterInfo != null) if (characterInfo != null)
{ {
myCharacter = new Character(characterInfo, assignedWayPoints[assignedWayPoints.Length-1]); myCharacter = new Character(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1]);
Character.Controlled = myCharacter; Character.Controlled = myCharacter;
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]); myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
@@ -641,6 +649,8 @@ namespace Subsurface.Networking
crew.Add(myCharacter); crew.Add(myCharacter);
} }
yield return CoroutineStatus.Running;
NetOutgoingMessage msg = server.CreateMessage(); NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.StartGame); msg.Write((byte)PacketTypes.StartGame);
@@ -653,7 +663,7 @@ namespace Subsurface.Networking
msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes); 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) foreach (Client client in connectedClients)
{ {
msg.Write(client.ID); msg.Write(client.ID);
@@ -668,6 +678,8 @@ namespace Subsurface.Networking
SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null); SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null);
yield return CoroutineStatus.Running;
gameStarted = true; gameStarted = true;
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
@@ -676,7 +688,8 @@ namespace Subsurface.Networking
CreateCrewFrame(crew); CreateCrewFrame(crew);
return true; yield return CoroutineStatus.Success;
} }
private bool EndButtonHit(GUIButton button, object obj) private bool EndButtonHit(GUIButton button, object obj)
+1 -1
View File
@@ -80,7 +80,7 @@ namespace Subsurface
public static Vector2 MousePosition 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 public static MouseState GetMouseState
@@ -119,9 +119,6 @@ namespace Subsurface
Physics.Alpha = Physics.accumulator / Physics.step; Physics.Alpha = Physics.accumulator / Physics.step;
} }
} }
/// <summary> /// <summary>
+2 -1
View File
@@ -225,8 +225,9 @@ namespace Subsurface
} }
} }
dummyCharacter.ControlLocalPlayer((float)deltaTime, cam); dummyCharacter.ControlLocalPlayer((float)deltaTime, cam, false);
dummyCharacter.Control((float)deltaTime, cam); dummyCharacter.Control((float)deltaTime, cam);
cam.TargetPos = Vector2.Zero;
} }
else else
{ {
-44
View File
@@ -58,15 +58,8 @@ namespace Subsurface
//http://gafferongames.com/game-physics/fix-your-timestep/ //http://gafferongames.com/game-physics/fix-your-timestep/
Physics.accumulator += deltaTime; Physics.accumulator += deltaTime;
Stopwatch sw = new Stopwatch();
sw.Start();
AmbientSoundManager.Update(); AmbientSoundManager.Update();
sw.Stop();
Debug.WriteLine("************** abupdate: "+sw.ElapsedTicks);
sw.Restart();
//if (Game1.GameSession != null && Game1.GameSession.Level != null) //if (Game1.GameSession != null && Game1.GameSession.Level != null)
//{ //{
// Vector2 targetMovement = Vector2.Zero; // Vector2 targetMovement = Vector2.Zero;
@@ -81,38 +74,17 @@ namespace Subsurface
if (GameMain.GameSession!=null) GameMain.GameSession.Update((float)deltaTime); if (GameMain.GameSession!=null) GameMain.GameSession.Update((float)deltaTime);
//EventManager.Update(gameTime); //EventManager.Update(gameTime);
sw.Stop();
Debug.WriteLine("gamesession update: " + sw.ElapsedTicks);
sw.Restart();
Character.UpdateAll(cam, (float)deltaTime); Character.UpdateAll(cam, (float)deltaTime);
sw.Stop();
Debug.WriteLine("characterupdate: " + sw.ElapsedTicks);
sw.Restart();
BackgroundSpriteManager.Update(cam, (float)deltaTime); BackgroundSpriteManager.Update(cam, (float)deltaTime);
sw.Stop();
Debug.WriteLine("bgsprite: " + sw.ElapsedTicks);
sw.Restart();
GameMain.ParticleManager.Update((float)deltaTime); GameMain.ParticleManager.Update((float)deltaTime);
sw.Stop();
Debug.WriteLine("particlemanager: " + sw.ElapsedTicks);
sw.Restart();
StatusEffect.UpdateAll((float)deltaTime); StatusEffect.UpdateAll((float)deltaTime);
sw.Stop();
Debug.WriteLine("statuseff: " + sw.ElapsedTicks);
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4); Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
while (Physics.accumulator >= Physics.step) while (Physics.accumulator >= Physics.step)
{ {
sw.Restart();
cam.MoveCamera((float)Physics.step); cam.MoveCamera((float)Physics.step);
foreach (PhysicsBody pb in PhysicsBody.list) foreach (PhysicsBody pb in PhysicsBody.list)
@@ -122,16 +94,8 @@ namespace Subsurface
MapEntity.UpdateAll(cam, (float)Physics.step); MapEntity.UpdateAll(cam, (float)Physics.step);
sw.Stop();
Debug.WriteLine(" mapentity: " + sw.ElapsedTicks);
sw.Restart();
Character.UpdateAnimAll((float)Physics.step); Character.UpdateAnimAll((float)Physics.step);
sw.Stop();
Debug.WriteLine(" char: " + sw.ElapsedTicks);
sw.Restart();
Ragdoll.UpdateAll(cam, (float)Physics.step); Ragdoll.UpdateAll(cam, (float)Physics.step);
if (GameMain.GameSession != null && GameMain.GameSession.Level != null) if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
@@ -139,16 +103,8 @@ namespace Subsurface
GameMain.GameSession.Submarine.Update((float)Physics.step); GameMain.GameSession.Submarine.Update((float)Physics.step);
} }
sw.Stop();
Debug.WriteLine(" sub: " + sw.ElapsedTicks);
sw.Restart();
GameMain.World.Step((float)Physics.step); GameMain.World.Step((float)Physics.step);
sw.Stop();
Debug.WriteLine(" worldstep: " + sw.ElapsedTicks);
sw.Restart();
Level.AfterWorldStep(); Level.AfterWorldStep();
Physics.accumulator -= Physics.step; Physics.accumulator -= Physics.step;
+10 -1
View File
@@ -4,6 +4,7 @@ using FarseerPhysics.Factories;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic;
namespace Subsurface namespace Subsurface
{ {
@@ -445,10 +446,18 @@ namespace Subsurface
private bool StartShift(GUIButton button, object selection) private bool StartShift(GUIButton button, object selection)
{ {
GameMain.ShowLoading(ShiftLoading());
return true;
}
private IEnumerable<object> ShiftLoading()
{
GameMain.GameSession.StartShift(TimeSpan.Zero, selectedLevel, false); GameMain.GameSession.StartShift(TimeSpan.Zero, selectedLevel, false);
GameMain.GameScreen.Select(); GameMain.GameScreen.Select();
return true; yield return CoroutineStatus.Success;
} }
public bool QuitToMainMenu(GUIButton button, object selection) public bool QuitToMainMenu(GUIButton button, object selection)
+14 -8
View File
@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking; using Subsurface.Networking;
using System.IO; using System.IO;
using System.Xml.Linq; using System.Xml.Linq;
using System.Collections.Generic;
namespace Subsurface namespace Subsurface
{ {
@@ -231,6 +232,7 @@ namespace Subsurface
return true; return true;
} }
private bool QuitClicked(GUIButton button, object obj) private bool QuitClicked(GUIButton button, object obj)
{ {
game.Exit(); 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]); var button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.Right | Alignment.Bottom, GUI.Style, menuTabs[(int)Tabs.LoadGame]);
button.OnClicked = LoadGame; button.OnClicked = LoadGame;
} }
private bool SelectSaveFile(GUIComponent component, object obj) private bool SelectSaveFile(GUIComponent component, object obj)
@@ -278,6 +279,8 @@ namespace Subsurface
RemoveSaveFrame(); RemoveSaveFrame();
string subName = ToolBox.GetAttributeString(doc.Root, "submarine", "");
string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown"); string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown");
XElement modeElement = null; XElement modeElement = null;
@@ -291,17 +294,20 @@ namespace Subsurface
string mapseed = ToolBox.GetAttributeString(modeElement, "mapseed", "unknown"); 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.UserData = "savefileframe";
saveFileFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); 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,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(0, 30, 0, 20), subName, GUI.Style, saveFileFrame);
new GUITextBlock(new Rectangle(15, 45, 0, 20), saveTime, GUI.Style, saveFileFrame).Font = GUI.SmallFont;
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); var deleteSaveButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Delete", Alignment.BottomCenter, GUI.Style, saveFileFrame);
deleteSaveButton.UserData = fileName; deleteSaveButton.UserData = fileName;
@@ -353,7 +359,8 @@ namespace Subsurface
{ {
graphics.Clear(Color.CornflowerBlue); 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); //Game1.GameScreen.DrawMap(graphics, spriteBatch);
@@ -406,7 +413,6 @@ namespace Subsurface
private bool LoadGame(GUIButton button, object obj) private bool LoadGame(GUIButton button, object obj)
{ {
string saveFile = saveList.SelectedData as string; string saveFile = saveList.SelectedData as string;
if (string.IsNullOrWhiteSpace(saveFile)) return false; if (string.IsNullOrWhiteSpace(saveFile)) return false;
+1 -8
View File
@@ -273,7 +273,7 @@ namespace Subsurface
if (IsServer && GameMain.Server != null) if (IsServer && GameMain.Server != null)
{ {
GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.BottomRight, GUI.Style, infoFrame); 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"; startButton.UserData = "startButton";
//mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby);
@@ -524,13 +524,6 @@ namespace Subsurface
if ((prevSize == 1.0f && chatBox.BarScroll == 0.0f) || (prevSize < 1.0f && chatBox.BarScroll == 1.0f)) chatBox.BarScroll = 1.0f; 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) public bool EnterChatMessage(GUITextBox textBox, string message)
{ {
if (String.IsNullOrEmpty(message)) return false; if (String.IsNullOrEmpty(message)) return false;
+3
View File
@@ -229,6 +229,9 @@ namespace Subsurface
public void Remove() public void Remove()
{ {
//sound already removed?
if (!loadedSounds.Contains(this)) return;
loadedSounds.Remove(this); loadedSounds.Remove(this);
System.Diagnostics.Debug.WriteLine("Removing sound " + filePath + " (buffer id" + AlBufferId + ")"); System.Diagnostics.Debug.WriteLine("Removing sound " + filePath + " (buffer id" + AlBufferId + ")");
+15 -17
View File
@@ -10,7 +10,7 @@ namespace Subsurface
{ {
public class SaveUtil public class SaveUtil
{ {
private const string SaveFolder = "Content/Data/Saves/"; private const string SaveFolder = "Data/Saves/";
public delegate void ProgressDelegate(string sMessage); public delegate void ProgressDelegate(string sMessage);
@@ -18,9 +18,7 @@ namespace Subsurface
{ {
fileName = SaveFolder + fileName; fileName = SaveFolder + fileName;
string tempPath = SaveFolder + "\\temp"; string tempPath = Path.Combine(SaveFolder, "temp");
if (Directory.Exists(tempPath)) if (Directory.Exists(tempPath))
{ {
@@ -34,11 +32,11 @@ namespace Subsurface
{ {
if (Submarine.Loaded!=null) if (Submarine.Loaded!=null)
{ {
Submarine.Loaded.SaveAs(tempPath + "\\map.gz"); Submarine.Loaded.SaveAs(Path.Combine(tempPath, "map.gz"));
} }
else else
{ {
File.Copy(GameMain.GameSession.Submarine.FilePath, tempPath + "\\map.gz"); File.Copy(GameMain.GameSession.Submarine.FilePath, Path.Combine(tempPath, "map.gz"));
} }
} }
catch (Exception e) catch (Exception e)
@@ -48,7 +46,7 @@ namespace Subsurface
try try
{ {
GameMain.GameSession.Save(tempPath + "\\gamesession.xml"); GameMain.GameSession.Save(Path.Combine(tempPath, "gamesession.xml"));
} }
catch (Exception e) catch (Exception e)
@@ -69,32 +67,31 @@ namespace Subsurface
public static void LoadGame(string fileName) public static void LoadGame(string fileName)
{ {
string filePath = SaveFolder + fileName+".save"; string filePath = Path.Combine(SaveFolder, fileName+".save");
string tempPath = Path.Combine(SaveFolder, "temp");
string tempPath = SaveFolder + "\\temp";
DecompressToDirectory(filePath, tempPath, null); DecompressToDirectory(filePath, tempPath, null);
Submarine selectedMap = Submarine.Load(tempPath +"\\map.gz"); Submarine selectedMap = new Submarine(Path.Combine(tempPath, "map.gz"), "");// Submarine.Load();
GameMain.GameSession = new GameSession(selectedMap, fileName, tempPath + "\\gamesession.xml"); GameMain.GameSession = new GameSession(selectedMap, fileName, Path.Combine(tempPath, "gamesession.xml"));
//Directory.Delete(tempPath, true); //Directory.Delete(tempPath, true);
} }
public static XDocument LoadGameSessionDoc(string fileName) 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); DecompressToDirectory(filePath, tempPath, null);
return ToolBox.TryLoadXml(tempPath + "\\gamesession.xml"); return ToolBox.TryLoadXml(Path.Combine(tempPath, "gamesession.xml"));
} }
public static void DeleteSave(string fileName) public static void DeleteSave(string fileName)
{ {
fileName = SaveFolder + fileName + ".save"; fileName = Path.Combine(SaveFolder, fileName + ".save");
try try
{ {
@@ -142,9 +139,10 @@ namespace Subsurface
} }
string extension = ".save"; string extension = ".save";
string pathWithoutExtension = Path.Combine(SaveFolder, fileName);
int i = 0; int i = 0;
while (File.Exists(SaveFolder + fileName + i + extension)) while (File.Exists(pathWithoutExtension + i + extension))
{ {
i++; i++;
} }
+21 -6
View File
@@ -136,17 +136,25 @@ namespace Subsurface
File.Delete(fileRelPath); File.Delete(fileRelPath);
} }
//couldn't delete file, probably because it's already in use
catch 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); if (File.Exists(oldFileName)) File.Delete(oldFileName);
//couldn't delete file, probably because it's already in use
File.Move(fileRelPath, oldFileName); 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); File.Move(file, fileRelPath);
} }
@@ -161,13 +169,20 @@ namespace Subsurface
foreach (string file in files) 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); System.Diagnostics.Debug.WriteLine("deleting file "+file);
try try
{ {
File.Delete(currentDir + "\\" + file); File.Delete(file);
} }
catch (Exception e) catch (Exception e)
@@ -187,13 +202,13 @@ namespace Subsurface
foreach (string file in files) 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); System.Diagnostics.Debug.WriteLine("deleting file " + file);
try try
{ {
File.Delete(currentDir + "\\" + file); File.Delete(file);
} }
catch (Exception e) catch (Exception e)
+6 -2
View File
@@ -215,7 +215,7 @@
<Compile Include="Source\Networking\GameServer.cs" /> <Compile Include="Source\Networking\GameServer.cs" />
<Compile Include="Source\PlayerInput.cs" /> <Compile Include="Source\PlayerInput.cs" />
<Compile Include="Source\Map\Gap.cs" /> <Compile Include="Source\Map\Gap.cs" />
<Compile Include="Source\Game1.cs" /> <Compile Include="Source\GameMain.cs" />
<Compile Include="Source\GUI\GUI.cs" /> <Compile Include="Source\GUI\GUI.cs" />
<Compile Include="Source\Program.cs" /> <Compile Include="Source\Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@@ -536,6 +536,9 @@
<Content Include="Content\UI\caret.png"> <Content Include="Content\UI\caret.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\UI\cursor.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\UI\inventoryIcons.png"> <Content Include="Content\UI\inventoryIcons.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -741,6 +744,7 @@
<Content Include="Content\waterbump.png"> <Content Include="Content\waterbump.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Data\ContentPackages\Vanilla 0.1.3.xml" />
<Content Include="Icon.ico" /> <Content Include="Icon.ico" />
<Content Include="OpenAL32.dll"> <Content Include="OpenAL32.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -976,7 +980,7 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Content\SavedMaps\" /> <Folder Include="Data\SavedSubs\" />
<Folder Include="Data\Saves\" /> <Folder Include="Data\Saves\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+1 -1
View File
@@ -9,7 +9,7 @@
<ErrorReportUrlHistory /> <ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture> <FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles> <VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ShowAllFiles</ProjectView> <ProjectView>ProjectFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ReferencePath> <ReferencePath>
Binary file not shown.