diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index d63eda23f..a227e2f9f 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -324,12 +324,12 @@ namespace Barotrauma ScreenOverlayColor, true); } - spriteBatch.DrawString(Font, - "FPS: " + (int)GameMain.FrameCounter.AverageFramesPerSecond, - new Vector2(10, 10), Color.White); - if (GameMain.DebugDraw) { + spriteBatch.DrawString(Font, + "FPS: " + (int)GameMain.FrameCounter.AverageFramesPerSecond, + new Vector2(10, 10), Color.White); + spriteBatch.DrawString(Font, "Physics: " + GameMain.World.UpdateTime, new Vector2(10, 30), Color.White); diff --git a/Subsurface/Source/GUI/GUIComponent.cs b/Subsurface/Source/GUI/GUIComponent.cs index 81e43e3b5..c2de9d40b 100644 --- a/Subsurface/Source/GUI/GUIComponent.cs +++ b/Subsurface/Source/GUI/GUIComponent.cs @@ -203,7 +203,7 @@ namespace Barotrauma return false; } - public void Flash(Color? color = null) + public virtual void Flash(Color? color = null) { flashTimer = FlashDuration; flashColor = (color == null) ? Color.Red * 0.8f : (Color)color; diff --git a/Subsurface/Source/GUI/GUITextBox.cs b/Subsurface/Source/GUI/GUITextBox.cs index 897f680e4..47d29dc84 100644 --- a/Subsurface/Source/GUI/GUITextBox.cs +++ b/Subsurface/Source/GUI/GUITextBox.cs @@ -171,6 +171,11 @@ namespace Barotrauma if (keyboardDispatcher.Subscriber == this) keyboardDispatcher.Subscriber = null; } + public override void Flash(Color? color = null) + { + textBlock.Flash(color); + } + //MouseState previousMouse; public override void Update(float deltaTime) { diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 6ef3443e1..5f46b32fb 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -1,18 +1,15 @@ using FarseerPhysics; -using FarseerPhysics.Collision; using FarseerPhysics.Common; using FarseerPhysics.Dynamics; using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Barotrauma.Items.Components; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Xml.Linq; -using Barotrauma.Lights; namespace Barotrauma { @@ -27,7 +24,7 @@ namespace Barotrauma //position of the "actual submarine" which is rendered wherever the SubmarineBody is //should be in an unreachable place - public static readonly Vector2 HiddenSubPosition = new Vector2(0.0f, 50000.0f); + public static readonly Vector2 HiddenSubPosition = new Vector2(0.0f, 50032.0f); public static List SavedSubmarines = new List(); @@ -517,6 +514,8 @@ namespace Barotrauma // return; } + loaded.filePath = SavePath + System.IO.Path.DirectorySeparatorChar + fileName; + return loaded.SaveAs(SavePath+System.IO.Path.DirectorySeparatorChar+fileName); } @@ -524,7 +523,7 @@ namespace Barotrauma { //string[] mapFilePaths; - Unload(); + //Unload(); SavedSubmarines.Clear(); if (!Directory.Exists(SavePath)) diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index b0b02e5a1..999f3ac4e 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -10,11 +10,13 @@ namespace Barotrauma { private Camera cam; - public GUIComponent GUIpanel; + public GUIComponent topPanel, leftPanel; private GUIComponent[] GUItabs; private int selectedTab; + private GUIFrame loadFrame; + private GUITextBox nameBox; const int PreviouslyUsedCount = 10; @@ -70,26 +72,35 @@ namespace Barotrauma selectedTab = -1; - GUIpanel = new GUIFrame(new Rectangle(0, 0, 150, GameMain.GraphicsHeight), GUI.Style); - GUIpanel.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); + topPanel = new GUIFrame(new Rectangle(0, 0, 0, 31), GUI.Style); + topPanel.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); + + var button = new GUIButton(new Rectangle(0, 0, 70, 20), "Open...", GUI.Style, topPanel); + button.OnClicked = CreateLoadScreen; + + // var nameBlock =new GUITextBlock(new Rectangle(0, 20, 0, 20), "Submarine:", GUI.Style, leftPanel); + nameBox = new GUITextBox(new Rectangle(150, 0, 150, 20), GUI.Style, topPanel); + nameBox.OnEnterPressed = ChangeSubName; + + button = new GUIButton(new Rectangle(310,0,70,20), "Save", GUI.Style, topPanel); + button.OnClicked = SaveSub; + + leftPanel = new GUIFrame(new Rectangle(0, 30, 150, GameMain.GraphicsHeight-30), GUI.Style); + leftPanel.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); //GUIListBox constructionList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, GUIpanel); //constructionList.OnSelected = MapEntityPrefab.SelectPrefab; //constructionList.CheckSelected = MapEntityPrefab.GetSelected; - var nameBlock =new GUITextBlock(new Rectangle(0, 20, 0, 20), "Submarine:", GUI.Style, GUIpanel); - //nameBox = new GUITextBox(new Rectangle(0, 40, 0, 20), GUI.Style, GUIpanel); - //nameBox.OnEnterPressed = ChangeSubName; - nameBlock.TextGetter = GetSubName; //GUIButton button = new GUIButton(new Rectangle(0,70,0,20), "Save", GUI.Style, GUIpanel); //button.OnClicked = SaveSub; - GUITextBlock itemCount = new GUITextBlock(new Rectangle(0, 100, 0, 20), "", GUI.Style, GUIpanel); + GUITextBlock itemCount = new GUITextBlock(new Rectangle(0, 30, 0, 20), "", GUI.Style, leftPanel); itemCount.TextGetter = GetItemCount; - GUITextBlock structureCount = new GUITextBlock(new Rectangle(0, 120, 0, 20), "", GUI.Style, GUIpanel); + GUITextBlock structureCount = new GUITextBlock(new Rectangle(0, 50, 0, 20), "", GUI.Style, leftPanel); structureCount.TextGetter = GetStructureCount; //GUITextBlock physicsBodyCount = new GUITextBlock(new Rectangle(0, 120, 0, 20), "", GUI.Style, GUIpanel); @@ -105,11 +116,11 @@ namespace Barotrauma int width = 400, height = 400; - int y = 160; + int y = 90; int i = 0; foreach (MapEntityCategory category in Enum.GetValues(typeof(MapEntityCategory))) { - var catButton = new GUIButton(new Rectangle(0, y, 0, 20), category.ToString(), Alignment.Left, GUI.Style, GUIpanel); + var catButton = new GUIButton(new Rectangle(0, y, 0, 20), category.ToString(), Alignment.Left, GUI.Style, leftPanel); catButton.UserData = i; catButton.OnClicked = SelectTab; y+=25; @@ -161,31 +172,32 @@ namespace Barotrauma } y+=50; - var button = new GUIButton(new Rectangle(0, y, 0, 20), "Character mode", Alignment.Left, GUI.Style, GUIpanel); + button = new GUIButton(new Rectangle(0, y, 0, 20), "Character mode", Alignment.Left, GUI.Style, leftPanel); button.ToolTip = "Allows you to pick up and use items. Useful for things such as placing items inside closets, turning devices on/off and doing the wiring."; button.OnClicked = ToggleCharacterMode; y+=50; - button = new GUIButton(new Rectangle(0, y, 0, 20), "Generate waypoints", Alignment.Left, GUI.Style, GUIpanel); + button = new GUIButton(new Rectangle(0, y, 0, 20), "Generate waypoints", Alignment.Left, GUI.Style, leftPanel); + button.ToolTip = "AI controlled crew members require waypoints to navigate around the sub."; button.OnClicked = GenerateWaypoints; y+=50; - new GUITextBlock(new Rectangle(0, y, 0, 20), "Show:", GUI.Style, GUIpanel); + new GUITextBlock(new Rectangle(0, y, 0, 20), "Show:", GUI.Style, leftPanel); - var tickBox = new GUITickBox(new Rectangle(0,y+20,20,20), "Waypoints", Alignment.TopLeft, GUIpanel); + var tickBox = new GUITickBox(new Rectangle(0,y+20,20,20), "Waypoints", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { WayPoint.ShowWayPoints = !WayPoint.ShowWayPoints; return true; }; tickBox.Selected = true; - tickBox = new GUITickBox(new Rectangle(0, y + 45, 20, 20), "Spawnpoints", Alignment.TopLeft, GUIpanel); + tickBox = new GUITickBox(new Rectangle(0, y + 45, 20, 20), "Spawnpoints", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { WayPoint.ShowSpawnPoints = !WayPoint.ShowSpawnPoints; return true; }; tickBox.Selected = true; - tickBox = new GUITickBox(new Rectangle(0, y + 70, 20, 20), "Links", Alignment.TopLeft, GUIpanel); + tickBox = new GUITickBox(new Rectangle(0, y + 70, 20, 20), "Links", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { Item.ShowLinks = !Item.ShowLinks; return true; }; tickBox.Selected = true; - tickBox = new GUITickBox(new Rectangle(0, y + 95, 20, 20), "Hulls", Alignment.TopLeft, GUIpanel); + tickBox = new GUITickBox(new Rectangle(0, y + 95, 20, 20), "Hulls", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { Hull.ShowHulls = !Hull.ShowHulls; return true; }; tickBox.Selected = true; - tickBox = new GUITickBox(new Rectangle(0, y + 120, 20, 20), "Gaps", Alignment.TopLeft, GUIpanel); + tickBox = new GUITickBox(new Rectangle(0, y + 120, 20, 20), "Gaps", Alignment.TopLeft, leftPanel); tickBox.OnSelected = (GUITickBox obj) => { Gap.ShowGaps = !Gap.ShowGaps; return true; }; tickBox.Selected = true; @@ -193,9 +205,9 @@ namespace Barotrauma if (y < GameMain.GraphicsHeight - 100) { - new GUITextBlock(new Rectangle(0, y, 0, 15), "Previously used:", GUI.Style, GUIpanel); + new GUITextBlock(new Rectangle(0, y, 0, 15), "Previously used:", GUI.Style, leftPanel); - previouslyUsedList = new GUIListBox(new Rectangle(0, y + 15, 0, Math.Min(GameMain.GraphicsHeight - y - 40, 150)), GUI.Style, GUIpanel); + previouslyUsedList = new GUIListBox(new Rectangle(0, y + 15, 0, Math.Min(GameMain.GraphicsHeight - y - 40, 150)), GUI.Style, leftPanel); previouslyUsedList.OnSelected = SelectPrefab; } @@ -218,13 +230,16 @@ namespace Barotrauma if (Submarine.Loaded != null) { cam.Position = Submarine.Loaded.Position + Submarine.HiddenSubPosition; - //nameBox.Text = Submarine.Loaded.Name; + nameBox.Text = Submarine.Loaded.Name; } else { cam.Position = Submarine.HiddenSubPosition; + nameBox.Text = ""; } + nameBox.Deselect(); + cam.UpdateTransform(); } @@ -252,7 +267,7 @@ namespace Barotrauma for (int i = 0; i + { + var deleteBtn = loadFrame.FindChild("delete") as GUIButton; + if (deleteBtn != null) deleteBtn.Enabled = true; + + return true; + }; + + foreach (Submarine sub in Submarine.SavedSubmarines) + { + GUITextBlock textBlock = new GUITextBlock( + new Rectangle(0, 0, 0, 25), + sub.Name, + GUI.Style, + Alignment.Left, Alignment.Left, subList); + textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); + textBlock.UserData = sub; + textBlock.ToolTip = sub.FilePath; + } + + var deleteButton = new GUIButton(new Rectangle(0, 0, 70, 20), "Delete", Alignment.BottomLeft, GUI.Style, loadFrame); + deleteButton.Enabled = false; + deleteButton.UserData = "delete"; + deleteButton.OnClicked = (GUIButton btn, object userdata) => + { + var subListBox = loadFrame.GetChild(); + + if (subList.Selected!=null) + { + Submarine sub = subList.Selected.UserData as Submarine; + try + { + System.IO.File.Delete(sub.FilePath); + } + catch (Exception e) + { + DebugConsole.ThrowError("Couldn't delete file ''"+sub.FilePath+"''!", e); + } + } + + deleteButton.Enabled = false; + + CreateLoadScreen(null, null); + + return true; + }; + + var loadButton = new GUIButton(new Rectangle(-90, 0, 80, 20), "Load", Alignment.Right | Alignment.Bottom, GUI.Style, loadFrame); + loadButton.OnClicked = LoadSub; + + var cancelButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Cancel", Alignment.Right | Alignment.Bottom, GUI.Style, loadFrame); + cancelButton.OnClicked = (GUIButton btn, object userdata) => + { + loadFrame = null; + return true; + }; + + return true; + } + + private bool LoadSub(GUIButton button, object obj) + { + GUIListBox subList = loadFrame.GetChild(); + + if (subList.Selected == null) return false; + + Submarine selectedSub = subList.Selected.UserData as Submarine; + + if (selectedSub == null) return false; + + selectedSub.Load(); + + nameBox.Text = selectedSub.Name; + + loadFrame = null; + + return true; + } + private bool SelectTab(GUIButton button, object obj) { selectedTab = (int)obj; @@ -332,15 +431,23 @@ namespace Barotrauma return true; } - //private bool ChangeSubName(GUITextBox textBox, string text) - //{ - // if (Submarine.Loaded != null) Submarine.Loaded.Name = text; - // textBox.Deselect(); + private bool ChangeSubName(GUITextBox textBox, string text) + { + if (string.IsNullOrWhiteSpace(text)) + { + textBox.Flash(Color.Red); + return false; + } - // textBox.Text = text; + if (Submarine.Loaded != null) Submarine.Loaded.Name = text; + textBox.Deselect(); - // return true; - //} + textBox.Text = text; + + textBox.Flash(Color.Green); + + return true; + } private bool SelectPrefab(GUIComponent component, object obj) { @@ -393,10 +500,15 @@ namespace Barotrauma /// Provides a snapshot of timing values. public override void Update(double deltaTime) { - if (tutorial!=null) tutorial.Update((float)deltaTime); + if (tutorial != null) tutorial.Update((float)deltaTime); if (GUIComponent.MouseOn == null) { + if (nameBox.Selected && PlayerInput.LeftButtonClicked()) + { + ChangeSubName(nameBox, nameBox.Text); + } + cam.MoveCamera((float)deltaTime); //cam.Zoom = MathHelper.Clamp(cam.Zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f)*cam.Zoom, 0.1f, 2.0f); } @@ -435,8 +547,16 @@ namespace Barotrauma } GUIComponent.MouseOn = null; - GUIpanel.Update((float)deltaTime); - if (selectedTab > -1) + + leftPanel.Update((float)deltaTime); + topPanel.Update((float)deltaTime); + + if (loadFrame!=null) + { + loadFrame.Update((float)deltaTime); + if (PlayerInput.RightButtonClicked()) loadFrame = null; + } + else if (selectedTab > -1) { GUItabs[selectedTab].Update((float)deltaTime); if (PlayerInput.RightButtonClicked()) selectedTab = -1; @@ -473,7 +593,8 @@ namespace Barotrauma spriteBatch.Begin(); - GUIpanel.Draw(spriteBatch); + leftPanel.Draw(spriteBatch); + topPanel.Draw(spriteBatch); //EntityPrefab.DrawList(spriteBatch, new Vector2(20,50)); @@ -512,7 +633,14 @@ namespace Barotrauma } else { - if (selectedTab > -1) GUItabs[selectedTab].Draw(spriteBatch); + if (loadFrame!=null) + { + loadFrame.Draw(spriteBatch); + } + else if (selectedTab > -1) + { + GUItabs[selectedTab].Draw(spriteBatch); + } MapEntity.Edit(spriteBatch, cam); } diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 49e649c3f..f870fb958 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -33,37 +33,52 @@ namespace Barotrauma - buttonsTab = new GUIFrame(new Rectangle(50, 0, 200, 360), Color.Transparent, Alignment.Left | Alignment.CenterY); + buttonsTab = new GUIFrame(new Rectangle(0,0,0,0), Color.Transparent, Alignment.Left | Alignment.CenterY); + buttonsTab.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); //menuTabs[(int)Tabs.Main].Padding = GUI.style.smallPadding; + + int y = 170; + Rectangle panelRect = new Rectangle( - 290, buttonsTab.Rect.Y, + 290, y, 500, 360); - GUIButton button = new GUIButton(new Rectangle(0, 0, 0, 30), "Tutorial", Alignment.CenterX, GUI.Style, buttonsTab); + GUIButton button = new GUIButton(new Rectangle(50, y, 200, 30), "Tutorial", null, Alignment.TopLeft, Alignment.Left, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; button.OnClicked = TutorialButtonClicked; - button = new GUIButton(new Rectangle(0, 60, 0, 30), "New Game", Alignment.CenterX, GUI.Style, buttonsTab); + button = new GUIButton(new Rectangle(50, y + 60, 200, 30), "New Game", null, Alignment.TopLeft, Alignment.Left, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; button.UserData = Tab.NewGame; button.OnClicked = SelectTab; - button = new GUIButton(new Rectangle(0, 100, 0, 30), "Load Game", Alignment.CenterX, GUI.Style, buttonsTab); + button = new GUIButton(new Rectangle(50, y + 100, 200, 30), "Load Game", null, Alignment.TopLeft, Alignment.Left, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; button.UserData = Tab.LoadGame; button.OnClicked = SelectTab; - button = new GUIButton(new Rectangle(0, 160, 0, 30), "Join Server", Alignment.CenterX, GUI.Style, buttonsTab); + button = new GUIButton(new Rectangle(50, y + 160, 200, 30), "Join Server", null, Alignment.TopLeft, Alignment.Left, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; //button.UserData = (int)Tabs.JoinServer; button.OnClicked = JoinServerClicked; - button = new GUIButton(new Rectangle(0, 200, 0, 30), "Host Server", Alignment.CenterX, GUI.Style, buttonsTab); + button = new GUIButton(new Rectangle(50, y + 200, 200, 30), "Host Server", null, Alignment.TopLeft, Alignment.Left, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; button.UserData = Tab.HostServer; button.OnClicked = SelectTab; - button = new GUIButton(new Rectangle(0, 260, 0, 30), "Settings", Alignment.CenterX, GUI.Style, buttonsTab); + button = new GUIButton(new Rectangle(50, y + 260, 200, 30), "Submarine Editor", null, Alignment.TopLeft, Alignment.Left, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; + button.OnClicked = (GUIButton btn, object userdata) => { GameMain.EditMapScreen.Select(); return true; }; + + button = new GUIButton(new Rectangle(50, y + 320, 200, 30), "Settings", null, Alignment.TopLeft, Alignment.Left, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; button.UserData = Tab.Settings; button.OnClicked = SelectTab; - button = new GUIButton(new Rectangle(0, 320, 0, 30), "Quit", Alignment.CenterX, GUI.Style, buttonsTab); + button = new GUIButton(new Rectangle(0, 0, 150, 30), "Quit", Alignment.BottomRight, GUI.Style, buttonsTab); + button.Color = button.Color * 0.8f; button.OnClicked = QuitClicked; //---------------------------------------------------------------------- diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 75965e6de..64899467d 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ