diff --git a/Subsurface/Characters/Character.cs b/Subsurface/Characters/Character.cs index cb5f938dc..b84404b8a 100644 --- a/Subsurface/Characters/Character.cs +++ b/Subsurface/Characters/Character.cs @@ -79,7 +79,7 @@ namespace Subsurface protected float soundInterval; private float bleeding; - private float blood; + //private float blood; private Sound[] sounds; //which AIstate each sound is for @@ -152,15 +152,15 @@ namespace Subsurface } } - public float Blood - { - get { return blood; } - set - { - blood = MathHelper.Clamp(value, 0.0f, 100.0f); - if (blood == 0.0f) Kill(); - } - } + //public float Blood + //{ + // get { return blood; } + // set + // { + // blood = MathHelper.Clamp(value, 0.0f, 100.0f); + // if (blood == 0.0f) Kill(); + // } + //} public Item[] SelectedItems { @@ -286,20 +286,20 @@ namespace Subsurface IsNetworkPlayer = isNetworkPlayer; oxygen = 100.0f; - blood = 100.0f; + //blood = 100.0f; aiTarget = new AITarget(this); properties = ObjectProperty.GetProperties(this); + info = characterInfo==null ? new CharacterInfo(file) : characterInfo; + XDocument doc = ToolBox.TryLoadXml(file); if (doc == null) return; - + speciesName = ToolBox.GetAttributeString(doc.Root, "name", "Unknown"); isHumanoid = ToolBox.GetAttributeBool(doc.Root, "humanoid", false); - - info = characterInfo ?? new CharacterInfo(file); - + if (isHumanoid) { animController = new HumanoidAnimController(this, doc.Root.Element("ragdoll")); @@ -427,7 +427,11 @@ namespace Subsurface /// public void ControlLocalPlayer(Camera cam, bool moveCam = true) { - if (isDead) return; + //if (isDead) + //{ + + // return; + //} Limb head = animController.GetLimb(LimbType.Head); @@ -522,7 +526,16 @@ namespace Subsurface public void Update(Camera cam, float deltaTime) { - if (isDead) return; + if (isDead) + { + if (controlled == this) + { + cam.Zoom = MathHelper.Lerp(cam.Zoom, 1.5f, 0.1f); + cam.TargetPos = ConvertUnits.ToDisplayUnits(animController.limbs[0].SimPosition); + cam.OffsetAmount = 0.0f; + } + return; + } if (PressureProtection==0.0f && (animController.CurrentHull == null || animController.CurrentHull.LethalPressure >= 100.0f)) @@ -568,7 +581,7 @@ namespace Subsurface //foreach (Limb limb in animController.limbs) //{ - Blood = blood - bleeding * deltaTime; + Health = health - bleeding * deltaTime; //} if (aiController != null) aiController.Update(deltaTime); @@ -591,18 +604,24 @@ namespace Subsurface aiTarget.SightRange += torso.LinearVelocity.Length() * 500.0f; } } - + public void Draw(SpriteBatch spriteBatch) { animController.Draw(spriteBatch); if (IsNetworkPlayer) { - Vector2 pos = new Vector2(Position.X, -Position.Y - 50.0f) - GUI.font.MeasureString(info.name) * 0.5f; - spriteBatch.DrawString(GUI.font, info.name, pos - new Vector2(1.0f, 1.0f), Color.Black); - spriteBatch.DrawString(GUI.font, info.name, pos, Color.White); + Vector2 namePos = new Vector2(Position.X, -Position.Y - 80.0f) - GUI.font.MeasureString(info.name) * 0.5f; + spriteBatch.DrawString(GUI.font, info.name, namePos - new Vector2(1.0f, 1.0f), Color.Black); + spriteBatch.DrawString(GUI.font, info.name, namePos, Color.White); } + if (this == Character.controlled) return; + + Vector2 healthBarPos = new Vector2(Position.X - 50, -Position.Y - 50.0f); + GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X-2, (int)healthBarPos.Y-2, 100+4, 15+4), Color.Black, false); + GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X, (int)healthBarPos.Y, (int)(100.0f*(health/maxHealth)), 15), Color.Red, true); + //spriteBatch.DrawString(GUI.font, ID.ToString(), ConvertUnits.ToDisplayUnits(animController.limbs[0].Position), Color.White); //GUI.DrawLine(spriteBatch, ConvertUnits.ToDisplayUnits(animController.limbs[0].SimPosition.X, animController.limbs[0].SimPosition.Y), // ConvertUnits.ToDisplayUnits(animController.limbs[0].SimPosition.X, animController.limbs[0].SimPosition.Y) + @@ -610,7 +629,7 @@ namespace Subsurface } - private static GUIProgressBar drowningBar, bloodBar; + private static GUIProgressBar drowningBar, healthBar; public void DrawHud(SpriteBatch spriteBatch, Camera cam) { if (drowningBar==null) @@ -618,19 +637,16 @@ namespace Subsurface int width = 100, height = 20; drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight/2, width, height), Color.Blue, 1.0f); - bloodBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f); + healthBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f); } drowningBar.BarSize = Controlled.Oxygen / 100.0f; - if (drowningBar.BarSize < 1.0f) - drowningBar.Draw(spriteBatch); + if (drowningBar.BarSize < 0.95f) drowningBar.Draw(spriteBatch); - bloodBar.BarSize = Blood / 100.0f; - if (bloodBar.BarSize < 1.0f) - bloodBar.Draw(spriteBatch); + healthBar.BarSize = health / maxHealth; + if (healthBar.BarSize < 1.0f) healthBar.Draw(spriteBatch); - if (Controlled.Inventory != null) - Controlled.Inventory.Draw(spriteBatch); + if (Controlled.Inventory != null) Controlled.Inventory.Draw(spriteBatch); if (closestItem!=null) { @@ -773,29 +789,6 @@ namespace Subsurface { if (isDead) return; - //if the game is run by a client, characters are only killed when the server says so - if (Game1.Client != null) - { - if (networkMessage) - { - new NetworkEvent(NetworkEventType.KillCharacter, ID, true); - } - else - { - return; - } - } - - if (Game1.Server != null) - { - new NetworkEvent(NetworkEventType.KillCharacter, ID, false); - } - - if (Game1.GameSession!=null && Game1.GameSession.crewManager != null) - { - Game1.GameSession.crewManager.KillCharacter(this); - } - isDead = true; animController.movement = Vector2.Zero; animController.TargetMovement = Vector2.Zero; @@ -820,6 +813,30 @@ namespace Subsurface joint.MotorEnabled = false; joint.MaxMotorTorque = 0.0f; } + + + //if the game is run by a client, characters are only killed when the server says so + if (Game1.Client != null) + { + if (networkMessage) + { + new NetworkEvent(NetworkEventType.KillCharacter, ID, true); + } + else + { + return; + } + } + + if (Game1.Server != null) + { + new NetworkEvent(NetworkEventType.KillCharacter, ID, false); + } + + if (Game1.GameSession != null) + { + Game1.GameSession.KillCharacter(this); + } } public override void FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data) diff --git a/Subsurface/Characters/CharacterInfo.cs b/Subsurface/Characters/CharacterInfo.cs index 17f4177e2..c6c583cce 100644 --- a/Subsurface/Characters/CharacterInfo.cs +++ b/Subsurface/Characters/CharacterInfo.cs @@ -89,12 +89,16 @@ namespace Subsurface public CharacterInfo(XElement element) { - name = element.Name.ToString(); + name = ToolBox.GetAttributeString(element, "name", "unnamed"); string genderStr = ToolBox.GetAttributeString(element, "gender", "male").ToLower(); gender = (genderStr == "male") ? Gender.Male : Gender.Female; + file = ToolBox.GetAttributeString(element, "file", ""); + salary = ToolBox.GetAttributeInt(element, "salary", 1000); + + headSpriteId = ToolBox.GetAttributeInt(element, "headspriteid", 1); } public virtual XElement Save(XElement parentElement) @@ -103,6 +107,7 @@ namespace Subsurface componentElement.Add( new XAttribute("name", name), + new XAttribute("file", file), new XAttribute("gender", gender == Gender.Male ? "male" : "female"), new XAttribute("salary", salary), new XAttribute("headspriteid", headSpriteId)); diff --git a/Subsurface/Content/Characters/Crawler/crawler.xml b/Subsurface/Content/Characters/Crawler/crawler.xml index c2151cd42..dd5fce2a4 100644 --- a/Subsurface/Content/Characters/Crawler/crawler.xml +++ b/Subsurface/Content/Characters/Crawler/crawler.xml @@ -26,7 +26,7 @@ - + diff --git a/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml b/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml index 321b558a0..6a0aae69a 100644 --- a/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml +++ b/Subsurface/Content/Characters/TigerThresher/tigerthresher.xml @@ -15,7 +15,7 @@ - + diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index fe3d8c847..d73e3941c 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -11,7 +11,7 @@ - + diff --git a/Subsurface/DebugConsole.cs b/Subsurface/DebugConsole.cs index 772eb006c..6bac7d957 100644 --- a/Subsurface/DebugConsole.cs +++ b/Subsurface/DebugConsole.cs @@ -148,8 +148,13 @@ namespace Subsurface { WayPoint spawnPoint = WayPoint.GetRandom(WayPoint.SpawnType.Human); Character.Controlled = new Character("Content/Characters/Human/human.xml", (spawnPoint == null) ? Vector2.Zero : spawnPoint.SimPosition); - if (Game1.GameSession != null) Game1.GameSession.crewManager.AddCharacter(Character.Controlled); - if (Game1.GameSession != null) Game1.GameSession.crewManager.SelectCharacter(Character.Controlled); + if (Game1.GameSession != null) + { + SinglePlayerMode mode = Game1.GameSession.gameMode as SinglePlayerMode; + if (mode == null) break; + mode.crewManager.AddCharacter(Character.Controlled); + mode.crewManager.SelectCharacter(Character.Controlled); + } } else { diff --git a/Subsurface/GUI/GUIComponent.cs b/Subsurface/GUI/GUIComponent.cs index bea9cc29b..c21a4dd73 100644 --- a/Subsurface/GUI/GUIComponent.cs +++ b/Subsurface/GUI/GUIComponent.cs @@ -242,7 +242,7 @@ namespace Subsurface if (children.Contains(child)) children.Remove(child); } - public void ClearChildren() + public virtual void ClearChildren() { children.Clear(); } diff --git a/Subsurface/GUI/GUIListBox.cs b/Subsurface/GUI/GUIListBox.cs index 8f5db6ddc..92e1ff62a 100644 --- a/Subsurface/GUI/GUIListBox.cs +++ b/Subsurface/GUI/GUIListBox.cs @@ -28,7 +28,10 @@ namespace Subsurface public object SelectedData { - get { return (selected == null) ? null : selected.UserData; } + get + { + return (selected == null) ? null : selected.UserData; + } } public int SelectedIndex @@ -166,12 +169,19 @@ namespace Subsurface } + public override void ClearChildren() + { + base.ClearChildren(); + selected = null; + } + public override void RemoveChild(GUIComponent child) { base.RemoveChild(child); - UpdateScrollBarSize(); - + if (selected == child) selected = null; + + UpdateScrollBarSize(); } private void ShowScrollBar() diff --git a/Subsurface/GUI/GUIMessageBox.cs b/Subsurface/GUI/GUIMessageBox.cs index 1676c778f..de5f4dfd8 100644 --- a/Subsurface/GUI/GUIMessageBox.cs +++ b/Subsurface/GUI/GUIMessageBox.cs @@ -13,12 +13,12 @@ namespace Subsurface //public OnClickedHandler OnClicked; //GUIFrame frame; - GUIButton[] buttons; + public GUIButton[] Buttons; public GUIMessageBox(string header, string text) : this(header, text, new string[] {"OK"}) { - this.buttons[0].OnClicked = OkClicked; + this.Buttons[0].OnClicked = Close; } public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left | Alignment.Top)) @@ -37,22 +37,21 @@ namespace Subsurface new GUITextBlock(new Rectangle(0, 30, 0, DefaultHeight - 70), text, Color.Transparent, Color.White, textAlignment, this, true); int x = 0; - this.buttons = new GUIButton[buttons.Length]; + this.Buttons = new GUIButton[buttons.Length]; for (int i = 0; i < buttons.Length; i++) { - this.buttons[i] = new GUIButton(new Rectangle(x, 0, 150, 30), buttons[i], GUI.style, Alignment.Left | Alignment.Bottom, this); + this.Buttons[i] = new GUIButton(new Rectangle(x, 0, 150, 30), buttons[i], GUI.style, Alignment.Left | Alignment.Bottom, this); - x += this.buttons[i].Rect.Width + 20; + x += this.Buttons[i].Rect.Width + 20; } messageBoxes.Enqueue(this); } - private bool OkClicked(GUIButton button, object obj) + public bool Close(GUIButton button, object obj) { messageBoxes.Dequeue(); return true; - } } } diff --git a/Subsurface/GameSession/CrewManager.cs b/Subsurface/GameSession/CrewManager.cs index ea3d019e0..631306fe2 100644 --- a/Subsurface/GameSession/CrewManager.cs +++ b/Subsurface/GameSession/CrewManager.cs @@ -77,16 +77,16 @@ namespace Subsurface characterInfos.Add(character.info); } - GUIFrame frame = new GUIFrame(new Rectangle(0,0,0,40), Color.Transparent, listBox); + GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, listBox); frame.UserData = character; frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); frame.HoverColor = Color.LightGray * 0.5f; frame.SelectedColor = Color.Gold * 0.5f; - string name = character.info.name.Replace(' ','\n'); + string name = character.info.name.Replace(' ', '\n'); GUITextBlock textBlock = new GUITextBlock( - new Rectangle(40,0,0,25), + new Rectangle(40, 0, 0, 25), name, Color.Transparent, Color.White, Alignment.Left, @@ -94,7 +94,7 @@ namespace Subsurface frame); textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f); - new GUIImage(new Rectangle(-10,-10,0,0), character.animController.limbs[0].sprite, Alignment.Left, frame); + new GUIImage(new Rectangle(-10, -10, 0, 0), character.animController.limbs[0].sprite, Alignment.Left, frame); } public void Update(float deltaTime) @@ -106,7 +106,11 @@ namespace Subsurface { GUIComponent characterBlock = listBox.GetChild(killedCharacter) as GUIComponent; if (characterBlock != null) characterBlock.Color = Color.DarkRed * 0.5f; - + + if (characters.Find(c => !c.IsDead)==null) + { + Game1.GameSession.EndShift(null, null); + } } public void StartShift() diff --git a/Subsurface/GameSession/GameMode.cs b/Subsurface/GameSession/GameMode.cs index ab7e72f67..45ab79427 100644 --- a/Subsurface/GameSession/GameMode.cs +++ b/Subsurface/GameSession/GameMode.cs @@ -1,19 +1,53 @@ -using System; +using Microsoft.Xna.Framework.Graphics; +using System; using System.Collections.Generic; +using System.Reflection; namespace Subsurface { + class GameModePreset + { + public static List list = new List(); + + public ConstructorInfo Constructor; + public string Name; + public bool IsSinglePlayer; + + public GameModePreset(string name, Type type, bool isSinglePlayer = false) + { + this.Name = name; + //Constructor = constructor; + + + Constructor = type.GetConstructor(new Type[] { typeof(GameModePreset) }); + + IsSinglePlayer = isSinglePlayer; + + list.Add(this); + } + + public GameMode Instantiate() + { + object[] lobject = new object[] { this }; + return(GameMode)Constructor.Invoke(lobject); + } + } + class GameMode { - public static List list = new List(); + public static List presetList = new List(); //TimeSpan duration; protected DateTime startTime; protected DateTime endTime; + //public readonly bool IsSinglePlayer; + protected bool isRunning; - protected string name; + //protected string name; + + protected GameModePreset preset; private string endMessage; @@ -32,9 +66,14 @@ namespace Subsurface get { return isRunning; } } + public bool IsSinglePlayer + { + get { return preset.IsSinglePlayer; } + } + public string Name { - get { return name; } + get { return preset.Name; } } public string EndMessage @@ -42,13 +81,16 @@ namespace Subsurface get { return endMessage; } } - public GameMode(string name) + public GameMode(GameModePreset preset) { - this.name = name; + this.preset = preset; - list.Add(this); + //list.Add(this); } + public virtual void Draw(SpriteBatch spriteBatch) + { } + public virtual void Start(TimeSpan duration) { startTime = DateTime.Now; @@ -59,7 +101,7 @@ namespace Subsurface isRunning = true; } - public virtual void Update() + public virtual void Update(float deltaTime) { if (!isRunning) return; @@ -69,7 +111,7 @@ namespace Subsurface } } - public void End(string endMessage = "") + public virtual void End(string endMessage = "") { isRunning = false; @@ -80,8 +122,14 @@ namespace Subsurface public static void Init() { - new GameMode("Sandbox"); - new TraitorMode("Traitor"); + new GameModePreset("Single Player", typeof(SinglePlayerMode), true); + new GameModePreset("SandBox", typeof(GameMode), false); + new GameModePreset("Traitor", typeof(TraitorMode), false); + + + //new SinglePlayerMode("Single Player", true); + //new GameMode("Sandbox"); + //new TraitorMode("Traitor"); } } } diff --git a/Subsurface/GameSession/GameSession.cs b/Subsurface/GameSession/GameSession.cs index 6dda2ee69..a1b98ea42 100644 --- a/Subsurface/GameSession/GameSession.cs +++ b/Subsurface/GameSession/GameSession.cs @@ -13,8 +13,7 @@ namespace Subsurface class GameSession { public readonly TaskManager taskManager; - public readonly CrewManager crewManager; - public readonly HireManager hireManager; + protected DateTime startTime; protected DateTime endTime; @@ -34,23 +33,20 @@ namespace Subsurface private Map selectedMap; - private int day; + - public int Day + public GameSession(Map selectedMap, TimeSpan gameDuration, GameModePreset gameModePreset) + :this(selectedMap, gameDuration, gameModePreset.Instantiate()) { - get { return day; } + } public GameSession(Map selectedMap, TimeSpan gameDuration, GameMode gameMode = null) { taskManager = new TaskManager(this); - crewManager = new CrewManager(); - hireManager = new HireManager(); savePath = SaveUtil.CreateSavePath(SaveUtil.SaveFolder); - hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10); - guiRoot = new GUIFrame(new Rectangle(0,0,Game1.GraphicsWidth,Game1.GraphicsWidth), Color.Transparent); int width = 350, height = 100; @@ -75,10 +71,12 @@ namespace Subsurface } timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, guiRoot); - - + this.gameMode = gameMode; - if (this.gameMode != null) this.gameMode.Start(Game1.NetLobbyScreen.GameDuration); + //if (gameMode != null && !gameMode.IsSinglePlayer) + //{ + // gameMode.Start(Game1.NetLobbyScreen.GameDuration); + //} startTime = DateTime.Now; endTime = startTime + gameDuration; @@ -88,53 +86,38 @@ namespace Subsurface //if (!save) return; //CreateSaveFile(selectedMapFile); - - day = 1; + } - public GameSession(string filePath) - : this(null, new TimeSpan(0,0,0,0)) + public GameSession(Map selectedMap, string savePath, string filePath) + : this(selectedMap, new TimeSpan(0,0,0,0)) { XDocument doc = ToolBox.TryLoadXml(filePath); if (doc == null) return; - day = ToolBox.GetAttributeInt(doc.Root,"day",1); + //gameMode = GameModePreset.list.Find(gm => gm.Name == "Single Player").Instantiate(); + + //day = ToolBox.GetAttributeInt(doc.Root,"day",1); foreach (XElement subElement in doc.Root.Elements()) { - if (subElement.Name.ToString().ToLower()=="crew") - { - crewManager = new CrewManager(subElement); - } + if (subElement.Name.ToString().ToLower() != "gamemode") continue; + + gameMode = new SinglePlayerMode(subElement); } - savePath = filePath; - } - - public bool TryHireCharacter(CharacterInfo characterInfo) - { - if (crewManager.Money < characterInfo.salary) return false; - - hireManager.availableCharacters.Remove(characterInfo); - crewManager.characterInfos.Add(characterInfo); - - crewManager.Money -= characterInfo.salary; - - return true; - } - - public string GetMoney() - { - return ("Money: " + crewManager.Money); + this.savePath = savePath; } public void StartShift(int scriptedEventCount = 1) { - if (crewManager.characterInfos.Count == 0) return; + //if (crewManager.characterInfos.Count == 0) return; if (Map.Loaded!=selectedMap) selectedMap.Load(); - crewManager.StartShift(); + gameMode.Start(TimeSpan.Zero); + + //crewManager.StartShift(); taskManager.StartShift(scriptedEventCount); } @@ -148,76 +131,30 @@ namespace Subsurface } else if (Game1.Client==null) - { - StringBuilder sb = new StringBuilder(); - List casualties = crewManager.characters.FindAll(c => c.IsDead); - - if (casualties.Any()) - { - sb.Append("Casualties: \n"); - foreach (Character c in casualties) - { - sb.Append(" - " + c.info.name + "\n"); - } - } - else - { - sb.Append("No casualties!"); - } - - new GUIMessageBox("Day #" + day + " is over!\n", sb.ToString()); - - - //if (saveFile == null) return false; - - //Map.Loaded.SaveAs(saveFile); - - crewManager.EndShift(); - + { Game1.LobbyScreen.Select(); - day++; - } - - for (int i = Character.characterList.Count - 1; i >= 0; i--) - { - Character.characterList.RemoveAt(i); + SaveUtil.SaveGame(savePath); } taskManager.EndShift(); + gameMode.End(); return true; } - private void CreateSaveFile(string mapName) + + public void KillCharacter(Character character) { - //string path = "Content/Data/Saves/"; + SinglePlayerMode singlePlayerMode = gameMode as SinglePlayerMode; + if (singlePlayerMode == null) return; + singlePlayerMode.crewManager.KillCharacter(character); + } - //if (!Directory.Exists(path)) - //{ - // Directory.CreateDirectory(path); - //} - - //string name = Path.GetFileNameWithoutExtension(mapName); - //string extension = Path.GetExtension(mapName); - - //int i = 0; - //while (File.Exists(path + name + i + extension)) - //{ - // i++; - //} - - //saveFile = path + name + i+extension; - - - //try - //{ - // File.Copy(mapName, saveFile); - //} - //catch (Exception e) - //{ - // DebugConsole.ThrowError("Copying map file ''" + mapName + "'' to ''" + saveFile + "'' failed", e); - //} + public bool LoadPrevious(GUIButton button, object obj) + { + SaveUtil.LoadGame(savePath); + return true; } public bool EnterChatMessage(GUITextBox textBox, string message) @@ -237,7 +174,7 @@ namespace Subsurface return true; } - + public void NewChatMessage(string text, Color color) { GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), text, @@ -252,20 +189,20 @@ namespace Subsurface chatBox.RemoveChild(chatBox.children.First()); } } - + public void Update(float deltaTime) { taskManager.Update(deltaTime); - if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks; - + //if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks; + endShiftButton.Enabled = true; guiRoot.Update(deltaTime); - crewManager.Update(deltaTime); + //endShiftButton.Update(deltaTime); //textBox.Update(deltaTime); - if (gameMode != null) gameMode.Update(); + if (gameMode != null) gameMode.Update(deltaTime); double duration = (endTime - startTime).TotalSeconds; double elapsedTime = (DateTime.Now-startTime).TotalSeconds; @@ -288,9 +225,11 @@ namespace Subsurface public void Draw(SpriteBatch spriteBatch) { guiRoot.Draw(spriteBatch); - crewManager.Draw(spriteBatch); + //crewManager.Draw(spriteBatch); taskManager.Draw(spriteBatch); + gameMode.Draw(spriteBatch); + //chatBox.Draw(spriteBatch); //textBox.Draw(spriteBatch); @@ -304,7 +243,11 @@ namespace Subsurface XDocument doc = new XDocument( new XElement((XName)"Gamesession")); - doc.Root.Add(new XAttribute("day", day)); + ((SinglePlayerMode)gameMode).Save(doc.Root); + + //doc.Root.Add(new XAttribute("day", day)); + + //crewManager.Save(doc.Root); try { diff --git a/Subsurface/GameSession/SinglePlayerMode.cs b/Subsurface/GameSession/SinglePlayerMode.cs new file mode 100644 index 000000000..678dae8c2 --- /dev/null +++ b/Subsurface/GameSession/SinglePlayerMode.cs @@ -0,0 +1,155 @@ +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace Subsurface +{ + class SinglePlayerMode : GameMode + { + public readonly CrewManager crewManager; + public readonly HireManager hireManager; + + private int day; + + public int Day + { + get { return day; } + } + + bool crewDead; + private float endTimer; + + public SinglePlayerMode(GameModePreset preset) + : base(preset) + { + crewManager = new CrewManager(); + hireManager = new HireManager(); + + hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10); + + day = 1; + } + + public SinglePlayerMode(XElement element) + : this(GameModePreset.list.Find(gm => gm.Name == "Single Player")) + { + day = ToolBox.GetAttributeInt(element,"day",1); + + foreach (XElement subElement in element.Elements()) + { + if (subElement.Name.ToString().ToLower() != "crew") continue; + + crewManager = new CrewManager(subElement); + } + } + + public override void Start(TimeSpan duration) + { + endTimer = 5.0f; + + crewManager.StartShift(); + } + + public bool TryHireCharacter(CharacterInfo characterInfo) + { + if (crewManager.Money < characterInfo.salary) return false; + + hireManager.availableCharacters.Remove(characterInfo); + crewManager.characterInfos.Add(characterInfo); + + crewManager.Money -= characterInfo.salary; + + return true; + } + + public string GetMoney() + { + return ("Money: " + crewManager.Money); + } + + + public override void Draw(SpriteBatch spriteBatch) + { + crewManager.Draw(spriteBatch); + + //chatBox.Draw(spriteBatch); + //textBox.Draw(spriteBatch); + + //timerBar.Draw(spriteBatch); + + //if (Game1.Client == null) endShiftButton.Draw(spriteBatch); + } + + public override void Update(float deltaTime) + { + crewManager.Update(deltaTime); + + if (!crewDead) + { + if (crewManager.characters.Find(c => !c.IsDead) == null) + { + crewDead = true; + } + } + else + { + endTimer -= deltaTime; + + if (endTimer <= 0.0f) End(""); + } + } + + public override void End(string endMessage = "") + { + StringBuilder sb = new StringBuilder(); + List casualties = crewManager.characters.FindAll(c => c.IsDead); + + if (casualties.Count == crewManager.characters.Count) + { + sb.Append("Your entire crew has died!"); + + var msgBox = new GUIMessageBox("GG", sb.ToString(), new string[] { "Load game", "Quit" }); + msgBox.Buttons[0].OnClicked += Game1.GameSession.LoadPrevious; + msgBox.Buttons[0].OnClicked += msgBox.Close; + msgBox.Buttons[1].OnClicked = Game1.LobbyScreen.QuitToMainMenu; + msgBox.Buttons[1].OnClicked += msgBox.Close; + } + else + { + if (casualties.Any()) + { + sb.Append("Casualties: \n"); + foreach (Character c in casualties) + { + sb.Append(" - " + c.info.name + "\n"); + } + } + else + { + sb.Append("No casualties!"); + } + + new GUIMessageBox("Day #" + day + " is over!\n", sb.ToString()); + + day++; + } + + crewManager.EndShift(); + for (int i = Character.characterList.Count-1; i>=0; i--) + { + Character.characterList.RemoveAt(i); + } + } + + public void Save(XElement element) + { + element.Add(new XAttribute("day", day)); + + crewManager.Save(element); + + } + } +} diff --git a/Subsurface/GameSession/TraitorMode.cs b/Subsurface/GameSession/TraitorMode.cs index e114f9fbb..c8f1b066b 100644 --- a/Subsurface/GameSession/TraitorMode.cs +++ b/Subsurface/GameSession/TraitorMode.cs @@ -9,8 +9,8 @@ namespace Subsurface Client traitor; Client target; - public TraitorMode(string name) - : base(name) + public TraitorMode(GameModePreset preset) + : base(preset) { } @@ -23,9 +23,8 @@ namespace Subsurface target = null; } - public override void Update() + public override void Update(float deltaTime) { - if (!isRunning) return; if (DateTime.Now >= endTime) diff --git a/Subsurface/Items/Components/Signal/Wire.cs b/Subsurface/Items/Components/Signal/Wire.cs index 56553d701..b2ce301cf 100644 --- a/Subsurface/Items/Components/Signal/Wire.cs +++ b/Subsurface/Items/Components/Signal/Wire.cs @@ -224,10 +224,10 @@ namespace Subsurface.Items.Components { if (nodes.Count == 0) return; - for (int i = 0; i < nodes.Count; i++) - { - GUI.DrawRectangle(spriteBatch, new Rectangle((int)nodes[i].X, (int)-nodes[i].Y, 5, 5), Color.DarkGray, true, wireSprite.Depth - 0.01f); - } + //for (int i = 0; i < nodes.Count; i++) + //{ + // GUI.DrawRectangle(spriteBatch, new Rectangle((int)nodes[i].X, (int)-nodes[i].Y, 5, 5), Color.DarkGray, true, wireSprite.Depth - 0.01f); + //} for (int i = 1; i < nodes.Count; i++) { diff --git a/Subsurface/Map/Map.cs b/Subsurface/Map/Map.cs index 64dd2ca72..05d67c70c 100644 --- a/Subsurface/Map/Map.cs +++ b/Subsurface/Map/Map.cs @@ -275,8 +275,7 @@ namespace Subsurface // DebugConsole.ThrowError("No save file selected"); // return; //} - XDocument doc = new XDocument( - new XElement((XName)name)); + XDocument doc = new XDocument(new XElement((XName)name)); foreach (MapEntity e in MapEntity.mapEntityList) { @@ -290,9 +289,9 @@ namespace Subsurface { SaveUtil.CompressStringToFile(filePath, doc.ToString()); } - catch + catch (Exception e) { - DebugConsole.ThrowError("Saving map ''" + filePath + "'' failed!"); + DebugConsole.ThrowError("Saving map ''" + filePath + "'' failed!", e); } @@ -505,12 +504,14 @@ namespace Subsurface loaded = this; } - public static void Load(string file) + public static Map Load(string file) { Unload(); Map map = new Map(file); map.Load(); + + return map; } @@ -528,9 +529,8 @@ namespace Subsurface if (Game1.GameScreen.Cam != null) Game1.GameScreen.Cam.TargetPos = Vector2.Zero; Entity.RemoveAll(); - - if (Game1.GameSession!=null) - Game1.GameSession.crewManager.EndShift(); + + if (Game1.GameSession != null) Game1.GameSession.EndShift(null, null); PhysicsBody.list.Clear(); diff --git a/Subsurface/SaveUtil.cs b/Subsurface/SaveUtil.cs index 397d46e52..beef366c4 100644 --- a/Subsurface/SaveUtil.cs +++ b/Subsurface/SaveUtil.cs @@ -9,36 +9,40 @@ namespace Subsurface { class SaveUtil { - public const string SaveFolder = "Content/SavedMaps/"; + public const string SaveFolder = "Content/Data/Saves/"; public delegate void ProgressDelegate(string sMessage); - public static void SaveGame(string directory) + public static void SaveGame(string savePath) { - if (Directory.Exists(directory)) + string tempPath = Path.GetDirectoryName(savePath) + "\\temp"; + if (!Directory.Exists(tempPath)) { - Directory.Delete(directory, true); + Directory.CreateDirectory(tempPath); } - Directory.CreateDirectory(directory); + //Directory.CreateDirectory(Path.GetDirectoryName(filePath) + "\\temp"); - Map.Loaded.SaveAs(directory+"\\map.gz"); + Map.Loaded.SaveAs(tempPath + "\\map.gz"); - Game1.GameSession.Save(directory+"\\gamesession.xml"); + Game1.GameSession.Save(tempPath + "\\gamesession.xml"); //Game1.GameSession.crewManager.Save(directory+"\\crew.xml"); - CompressDirectory(directory, directory+".save", null); + CompressDirectory(tempPath, savePath, null); - Directory.Delete(directory, true); + Directory.Delete(tempPath, true); } public static void LoadGame(string filePath) { - DecompressToDirectory(filePath+".save", Path.GetDirectoryName(filePath)+"\\temp", null); + string tempPath = Path.GetDirectoryName(filePath) + "\\temp"; - Map.Load(Path.GetDirectoryName(filePath) + "\\temp\\map.gz"); - Game1.GameSession = new GameSession(Path.GetDirectoryName(filePath) + "\\temp\\gamesession.gz"); + DecompressToDirectory(filePath, tempPath, null); + Map selectedMap = Map.Load(tempPath +"\\map.gz"); + Game1.GameSession = new GameSession(selectedMap, filePath, tempPath + "\\gamesession.xml"); + + Directory.Delete(tempPath, true); } public static string CreateSavePath(string saveFolder, string fileName="save") @@ -57,7 +61,7 @@ namespace Subsurface i++; } - return saveFolder + fileName + i + extension; + return saveFolder + fileName + i; } public static void CompressStringToFile(string fileName, string value) diff --git a/Subsurface/Screens/LobbyScreen.cs b/Subsurface/Screens/LobbyScreen.cs index f2233466a..7b573ff33 100644 --- a/Subsurface/Screens/LobbyScreen.cs +++ b/Subsurface/Screens/LobbyScreen.cs @@ -1,4 +1,7 @@ -using Microsoft.Xna.Framework; +using FarseerPhysics; +using FarseerPhysics.Dynamics; +using FarseerPhysics.Factories; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Subsurface @@ -15,6 +18,13 @@ namespace Subsurface GUIListBox characterList; GUIListBox hireList; + SinglePlayerMode gameMode; + + Body previewPlatform; + Hull previewHull; + + Character previewCharacter; + public LobbyScreen() { Rectangle panelRect = new Rectangle( @@ -81,14 +91,14 @@ namespace Subsurface new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, rightPanel[0]); characterList = new GUIListBox(new Rectangle(0, 30, 300, 0), Color.White, rightPanel[0]); + characterList.OnSelected = SelectCharacter; //--------------------------------------- rightPanel[1] = new GUIFrame(panelRect, GUI.style.backGroundColor); rightPanel[1].Padding = GUI.style.smallPadding; - hireList = new GUIListBox(new Rectangle(0, 30, 300, 0), Color.White, Alignment.Left, rightPanel[1]); - + hireList = new GUIListBox(new Rectangle(0, 30, 300, 0), Color.White, Alignment.Left, rightPanel[1]); hireList.OnSelected = HireCharacter; } @@ -96,16 +106,74 @@ namespace Subsurface { base.Select(); + gameMode = Game1.GameSession.gameMode as SinglePlayerMode; + //Map.Unload(); - UpdateCharacterLists(); - + UpdateCharacterLists(); + } + + public override void Deselect() + { + base.Deselect(); + + if (previewPlatform != null) + { + Game1.world.RemoveBody(previewPlatform); + previewPlatform = null; + } + + if (previewHull != null) + { + previewHull.Remove(); + previewHull = null; + } + + if (previewCharacter != null) + { + previewCharacter.Remove(); + previewCharacter = null; + } + } + + private void CreatePreviewCharacter() + { + if (previewCharacter != null) previewCharacter.Remove(); + + Vector2 pos = new Vector2(1000.0f, 1000.0f); + + previewCharacter = new Character(characterList.SelectedData as CharacterInfo, pos); + + previewCharacter.animController.isStanding = true; + + if (previewPlatform == null) + { + Body platform = BodyFactory.CreateRectangle(Game1.world, 3.0f, 1.0f, 5.0f); + platform.SetTransform(new Vector2(pos.X, pos.Y - 3.5f), 0.0f); + platform.IsStatic = true; + } + + if (previewHull == null) + { + pos = ConvertUnits.ToDisplayUnits(pos); + previewHull = new Hull(new Rectangle((int)pos.X - 100, (int)pos.Y + 100, 200, 500)); + } + + Physics.Alpha = 1.0f; + + for (int i = 0; i < 500; i++) + { + previewCharacter.animController.Update((float)Physics.step); + previewCharacter.animController.UpdateAnim((float)Physics.step); + Game1.world.Step((float)Physics.step); + } + } private void UpdateCharacterLists() { characterList.ClearChildren(); - foreach (CharacterInfo c in Game1.GameSession.crewManager.characterInfos) + foreach (CharacterInfo c in gameMode.crewManager.characterInfos) { GUITextBlock textBlock = new GUITextBlock( new Rectangle(0, 0, 0, 25), @@ -114,10 +182,11 @@ namespace Subsurface Alignment.Left, characterList); textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); + textBlock.UserData = c; } hireList.ClearChildren(); - foreach (CharacterInfo c in Game1.GameSession.hireManager.availableCharacters) + foreach (CharacterInfo c in gameMode.hireManager.availableCharacters) { GUIFrame frame = new GUIFrame( new Rectangle(0, 0, 0, 25), @@ -156,8 +225,8 @@ namespace Subsurface public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { - if (characterList.CountChildren != Game1.GameSession.crewManager.characterInfos.Count - || hireList.CountChildren != Game1.GameSession.hireManager.availableCharacters.Count) + if (characterList.CountChildren != gameMode.crewManager.characterInfos.Count + || hireList.CountChildren != gameMode.hireManager.availableCharacters.Count) { UpdateCharacterLists(); } @@ -168,10 +237,6 @@ namespace Subsurface spriteBatch.Begin(); - - //ConstructionPrefab.list[5].sprite.Draw(spriteBatch, Vector2.Zero, new Vector2(10.0f, 1.0f), Color.White); - - leftPanel.Draw(spriteBatch); shiftPanel.Draw(spriteBatch); @@ -180,6 +245,26 @@ namespace Subsurface GUI.Draw((float)deltaTime, spriteBatch, null); spriteBatch.End(); + + if (characterList.SelectedData != null) + { + if (previewCharacter != null) + { + Vector2 position = new Vector2(characterList.Rect.Right + 100, characterList.Rect.Y + 25.0f); + + Vector2 pos = previewCharacter.Position; + pos.Y = -pos.Y; + Matrix transform = Matrix.CreateTranslation(new Vector3(-pos + position, 0.0f)); + + spriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, transform); + previewCharacter.Draw(spriteBatch); + spriteBatch.End(); + } + else + { + CreatePreviewCharacter(); + } + } } public bool SelectRightPanel(GUIButton button, object selection) @@ -189,49 +274,93 @@ namespace Subsurface return true; } + //private void CreatePreviewCharacter() + //{ + // if (Game1.Client.Character != null) Game1.Client.Character.Remove(); + + // Vector2 pos = new Vector2(1000.0f, 1000.0f); + + // Character character = new Character(Game1.Client.CharacterInfo, pos); + + // Game1.Client.Character = character; + + // character.animController.isStanding = true; + + // if (previewPlatform == null) + // { + // Body platform = BodyFactory.CreateRectangle(Game1.world, 3.0f, 1.0f, 5.0f); + // platform.SetTransform(new Vector2(pos.X, pos.Y - 2.5f), 0.0f); + // platform.IsStatic = true; + // } + + // if (previewPlatform == null) + // { + // pos = ConvertUnits.ToDisplayUnits(pos); + // new Hull(new Rectangle((int)pos.X - 100, (int)pos.Y + 100, 200, 200)); + // } + + // Physics.Alpha = 1.0f; + + // for (int i = 0; i < 500; i++) + // { + // character.animController.Update((float)Physics.step); + // character.animController.UpdateAnim((float)Physics.step); + // Game1.world.Step((float)Physics.step); + // } + //} + private string GetMoney() { - return "Money: " + ((Game1.GameSession == null) ? "" : Game1.GameSession.crewManager.Money.ToString()); + return "Money: " + ((Game1.GameSession == null) ? "" : gameMode.crewManager.Money.ToString()); } private string GetDay() { - return "Day #" + ((Game1.GameSession == null) ? "" : Game1.GameSession.Day.ToString()); + return "Day #" + ((Game1.GameSession == null) ? "" : gameMode.Day.ToString()); } private float GetWeekProgress() { if (Game1.GameSession == null) return 0.0f; - return (float)((Game1.GameSession.Day - 1) % 7) / 7.0f; + return (float)((gameMode.Day - 1) % 7) / 7.0f; + } + + private bool SelectCharacter(object selection) + { + CharacterInfo characterInfo = selection as CharacterInfo; + if (characterInfo == null) return false; + + if (Character.Controlled != null && characterInfo == Character.Controlled.info) return false; + + CreatePreviewCharacter(); + + return false; } private bool HireCharacter(object selection) { - CharacterInfo characterInfo; - try { characterInfo = (CharacterInfo)selection; } - catch { return false; } - + CharacterInfo characterInfo = selection as CharacterInfo; if (characterInfo == null) return false; - Game1.GameSession.TryHireCharacter(characterInfo); + gameMode.TryHireCharacter(characterInfo); return false; } private bool StartShift(GUIButton button, object selection) - { - - //Map.Load(Game1.GameSession.SaveFile); - + { Game1.GameSession.StartShift(); - - //EventManager.StartShift(); - Game1.GameScreen.Select(); return true; } + + public bool QuitToMainMenu(GUIButton button, object selection) + { + Game1.MainMenuScreen.Select(); + return true; + } } } diff --git a/Subsurface/Screens/MainMenu.cs b/Subsurface/Screens/MainMenu.cs index 7e9ef24f1..da30e75e1 100644 --- a/Subsurface/Screens/MainMenu.cs +++ b/Subsurface/Screens/MainMenu.cs @@ -2,16 +2,19 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Subsurface.Networking; +using System.IO; namespace Subsurface { class MainMenuScreen : Screen { - enum Tabs { Main = 0, NewGame = 1, JoinServer = 2} + enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, JoinServer = 3 } GUIFrame[] menuTabs; GUIListBox mapList; + GUIListBox saveList; + GUITextBox nameBox; GUITextBox ipBox; @@ -21,7 +24,7 @@ namespace Subsurface public MainMenuScreen(Game1 game) { - menuTabs = new GUIFrame[3]; + menuTabs = new GUIFrame[Enum.GetValues(typeof(Tabs)).Length]; Rectangle panelRect = new Rectangle( Game1.GraphicsWidth / 2 - 250, @@ -32,17 +35,23 @@ namespace Subsurface menuTabs[(int)Tabs.Main].Padding = GUI.style.smallPadding; GUIButton button = new GUIButton(new Rectangle(0, 0, 0, 30), "New Game", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); - button.OnClicked = NewGameClicked; + button.UserData = (int)Tabs.NewGame; + button.OnClicked = SelectTab; //button.Enabled = false; - button = new GUIButton(new Rectangle(0, 60, 0, 30), "Join Server", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); - button.OnClicked = JoinServerClicked; + button = new GUIButton(new Rectangle(0, 60, 0, 30), "Load Game", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); + button.UserData = (int)Tabs.LoadGame; + button.OnClicked = SelectTab; - button = new GUIButton(new Rectangle(0, 120, 0, 30), "Host Server", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); + button = new GUIButton(new Rectangle(0, 120, 0, 30), "Join Server", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); + button.UserData = (int)Tabs.JoinServer; + button.OnClicked = SelectTab; + + button = new GUIButton(new Rectangle(0, 180, 0, 30), "Host Server", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); button.OnClicked = HostServerClicked; //button.Enabled = false; - button = new GUIButton(new Rectangle(0, 180, 0, 30), "Quit", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); + button = new GUIButton(new Rectangle(0, 240, 0, 30), "Quit", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]); button.OnClicked = QuitClicked; //---------------------------------------------------------------------- @@ -53,7 +62,7 @@ namespace Subsurface new GUITextBlock(new Rectangle(0, 0, 0, 30), "New Game", Color.Transparent, Color.Black, Alignment.CenterX, menuTabs[(int)Tabs.NewGame]); new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, menuTabs[(int)Tabs.NewGame]); - mapList = new GUIListBox(new Rectangle(0, 60, 200, 400), Color.White, menuTabs[1]); + mapList = new GUIListBox(new Rectangle(0, 60, 200, 400), Color.White, menuTabs[(int)Tabs.NewGame]); foreach (Map map in Map.SavedMaps) { @@ -73,6 +82,34 @@ namespace Subsurface button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", GUI.style, Alignment.Right | Alignment.Bottom, menuTabs[(int)Tabs.NewGame]); button.OnClicked = StartGame; + //---------------------------------------------------------------------- + + menuTabs[(int)Tabs.LoadGame] = new GUIFrame(panelRect, GUI.style.backGroundColor); + menuTabs[(int)Tabs.LoadGame].Padding = GUI.style.smallPadding; + + new GUITextBlock(new Rectangle(0, 0, 0, 30), "Load Game", Color.Transparent, Color.Black, Alignment.CenterX, menuTabs[(int)Tabs.LoadGame]); + + + string[] saveFiles = Directory.GetFiles(SaveUtil.SaveFolder, "*.save"); + + //new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, menuTabs[(int)Tabs.NewGame]); + saveList = new GUIListBox(new Rectangle(0, 60, 200, 400), Color.White, menuTabs[(int)Tabs.LoadGame]); + + foreach (string saveFile in saveFiles) + { + GUITextBlock textBlock = new GUITextBlock( + new Rectangle(0, 0, 0, 25), + saveFile, + GUI.style, + Alignment.Left, + Alignment.Left, + saveList); + textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); + textBlock.UserData = saveFile; + } + + button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", GUI.style, Alignment.Right | Alignment.Bottom, menuTabs[(int)Tabs.LoadGame]); + button.OnClicked = LoadGame; //---------------------------------------------------------------------- @@ -95,18 +132,12 @@ namespace Subsurface } - private bool NewGameClicked(GUIButton button, object obj) + private bool SelectTab(GUIButton button, object obj) { - selectedTab = (int)Tabs.NewGame; + selectedTab = (int)obj; return true; } - - private bool JoinServerClicked(GUIButton button, object obj) - { - selectedTab = (int)Tabs.JoinServer; - return true; - } - + private bool HostServerClicked(GUIButton button, object obj) { Game1.NetLobbyScreen.isServer = true; @@ -142,18 +173,39 @@ namespace Subsurface private bool StartGame(GUIButton button, object obj) { - Map selectedMap = mapList.SelectedData as Map; if (selectedMap == null) return false; - - Game1.GameSession = new GameSession(selectedMap, TimeSpan.Zero); + Game1.GameSession = new GameSession(selectedMap, TimeSpan.Zero, GameModePreset.list.Find(gm => gm.Name == "Single Player")); Game1.LobbyScreen.Select(); return true; } + private bool LoadGame(GUIButton button, object obj) + { + + string saveFile = saveList.SelectedData as string; + if (string.IsNullOrWhiteSpace(saveFile)) return false; + + try + { + SaveUtil.LoadGame(saveFile); + } + catch (Exception e) + { + DebugConsole.ThrowError("Loading map ''"+saveFile+"'' failed", e); + return false; + } + + + Game1.LobbyScreen.Select(); + + return true; + } + + private bool JoinServer(GUIButton button, object obj) { if (string.IsNullOrEmpty(nameBox.Text)) return false; diff --git a/Subsurface/Screens/NetLobbyScreen.cs b/Subsurface/Screens/NetLobbyScreen.cs index 4992832d9..d2e304ce3 100644 --- a/Subsurface/Screens/NetLobbyScreen.cs +++ b/Subsurface/Screens/NetLobbyScreen.cs @@ -36,9 +36,9 @@ namespace Subsurface } - public GameMode SelectedMode + public GameModePreset SelectedMode { - get { return modeList.SelectedData as GameMode; } + get { return modeList.SelectedData as GameModePreset; } } public TimeSpan GameDuration @@ -161,8 +161,10 @@ namespace Subsurface modeList.Enabled = (Game1.Server != null); //modeList.OnSelected = new GUIListBox.OnSelectedHandler(SelectEvent); - foreach (GameMode mode in GameMode.list) + foreach (GameModePreset mode in GameModePreset.list) { + if (mode.IsSinglePlayer) continue; + GUITextBlock textBlock = new GUITextBlock( new Rectangle(0, 0, 0, 25), mode.Name, @@ -192,8 +194,8 @@ namespace Subsurface modeList.OnSelected = Game1.Server.UpdateNetLobby; durationBar.OnMoved = Game1.Server.UpdateNetLobby; - if (mapList.CountChildren > 0) mapList.Select(Map.SavedMaps[0]); - if (GameMode.list.Count > 0) modeList.Select(GameMode.list[0]); + if (mapList.CountChildren > 0) mapList.Select(0); + if (GameModePreset.list.Count > 0) modeList.Select(0); } else { @@ -319,9 +321,9 @@ namespace Subsurface Vector2 pos = Game1.Client.Character.Position; pos.Y = -pos.Y; - Matrix transform = Matrix.CreateTranslation(new Vector3(-pos+position, 0.0f)); - - spriteBatch.Begin(SpriteSortMode.BackToFront, null,null,null,null,null,transform); + Matrix transform = Matrix.CreateTranslation(new Vector3(-pos + position, 0.0f)); + + spriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, transform); Game1.Client.Character.Draw(spriteBatch); spriteBatch.End(); } @@ -386,10 +388,10 @@ namespace Subsurface platform.IsStatic = true; } - if (previewPlatform==null) + if (previewHull==null) { pos = ConvertUnits.ToDisplayUnits(pos); - new Hull(new Rectangle((int)pos.X - 100, (int)pos.Y + 100, 200, 200)); + previewHull = new Hull(new Rectangle((int)pos.X - 100, (int)pos.Y + 100, 200, 200)); } Physics.Alpha = 1.0f; @@ -473,7 +475,7 @@ namespace Subsurface } else { - msg.Write(Path.GetFileName(selectedMap.FilePath)); + msg.Write(Path.GetFileName(selectedMap.Name)); msg.Write(selectedMap.MapHash.MD5Hash); } diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index 35706e91c..97d8e02d9 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -71,6 +71,7 @@ + diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index b61cebe5a..62606192a 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ