autoupdater fixes, cursor fix, consistent directory separators + use of Path.Combine(), wire bugfixes, more loading screens
This commit is contained in:
@@ -601,11 +601,6 @@ namespace Subsurface
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
@@ -49,11 +49,6 @@ namespace Subsurface
|
||||
|
||||
public override void UpdateAnim(float deltaTime)
|
||||
{
|
||||
if (PlayerInput.KeyHit(Keys.I))
|
||||
{
|
||||
SimplePhysicsEnabled = !SimplePhysicsEnabled;
|
||||
}
|
||||
|
||||
if (character.IsDead)
|
||||
{
|
||||
UpdateDying(deltaTime);
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -24,6 +24,14 @@ namespace Subsurface
|
||||
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)
|
||||
{
|
||||
IEnumerator<object> coroutine = Coroutines.FirstOrDefault(c => c.ToString().Contains(name));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<GUIMessage> messages = new List<GUIMessage>();
|
||||
@@ -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)
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class GUIMessageBox : GUIFrame
|
||||
public class GUIMessageBox : GUIFrame
|
||||
{
|
||||
public static Queue<GUIMessageBox> MessageBoxes = new Queue<GUIMessageBox>();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<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 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<object> 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;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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<object> loader)
|
||||
{
|
||||
titleScreenOpen = true;
|
||||
CoroutineManager.StartCoroutine(TitleScreen.DoLoading(loader));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void OnExiting(object sender, EventArgs args)
|
||||
{
|
||||
if (NetworkMember != null) NetworkMember.Disconnect();
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace Subsurface
|
||||
|
||||
class Submarine : Entity
|
||||
{
|
||||
public const string SavePath = "Data/SavedSubs";
|
||||
|
||||
public static List<Submarine> SavedSubmarines = new List<Submarine>();
|
||||
|
||||
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);
|
||||
|
||||
@@ -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<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);
|
||||
GameMain.ShowLoading(StartGame(inc));
|
||||
|
||||
break;
|
||||
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)
|
||||
{
|
||||
gameStarted = false;
|
||||
|
||||
@@ -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<object> 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<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
|
||||
@@ -622,7 +630,7 @@ namespace Subsurface.Networking
|
||||
List<Character> crew = new List<Character>();
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -118,10 +118,7 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
Physics.Alpha = Physics.accumulator / Physics.step;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<object> 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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 + ")");
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user