From d5cd6f83ae9a6c9b3ca3e53cfbfa36828c83a3d6 Mon Sep 17 00:00:00 2001 From: Regalis Date: Thu, 11 Aug 2016 21:54:05 +0300 Subject: [PATCH] Shuttle-tag is visible in menus, some menu layout tweaking --- Subsurface/Source/Networking/NetworkMember.cs | 2 +- Subsurface/Source/Screens/EditMapScreen.cs | 18 ++++++++---- Subsurface/Source/Screens/MainMenuScreen.cs | 29 +++++++++++-------- Subsurface/Source/Screens/NetLobbyScreen.cs | 12 ++++++-- Subsurface/Source/Utils/ToolBox.cs | 21 +++++++++++++- 5 files changed, 61 insertions(+), 21 deletions(-) diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index 6130f118f..61e3f24cd 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -404,7 +404,7 @@ namespace Barotrauma.Networking if (!string.IsNullOrEmpty(respawnInfo)) { GUI.DrawString(spriteBatch, - new Vector2(GameMain.GraphicsWidth - 400.0f, 20), + new Vector2(120.0f, 10), respawnInfo, Color.White, null, 0, GUI.SmallFont); } diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 0cb58aea0..b33aac9b0 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -343,6 +343,8 @@ namespace Barotrauma Submarine.MainSub.CheckForErrors(); GUI.AddMessage("Submarine saved to " + Submarine.MainSub.FilePath, Color.Green, 3.0f); + + saveFrame = null; return false; } @@ -376,7 +378,7 @@ namespace Barotrauma Alignment.TopLeft, GUI.Style, saveFrame); descriptionBox.Wrap = true; descriptionBox.Text = Submarine.MainSub == null ? "" : Submarine.MainSub.Description; - descriptionBox.OnEnterPressed = ChangeSubDescription; + descriptionBox.OnTextChanged = ChangeSubDescription; y += descriptionBox.Rect.Height + 15; new GUITextBlock(new Rectangle(0, y, 150, 20), "Settings:", GUI.Style, saveFrame); @@ -454,10 +456,16 @@ namespace Barotrauma new Rectangle(0, 0, 0, 25), sub.Name, GUI.Style, - Alignment.Left, Alignment.Left, subList); + Alignment.Left, Alignment.CenterY | Alignment.Right, subList); textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); textBlock.UserData = sub; textBlock.ToolTip = sub.FilePath; + + if (sub.HasTag(SubmarineTag.Shuttle)) + { + var shuttleText = new GUITextBlock(new Rectangle(0, 0, 0, 25), "Shuttle", GUI.Style, Alignment.Left, Alignment.CenterY | Alignment.Right, textBlock, false, GUI.SmallFont); + shuttleText.TextColor = textBlock.TextColor * 0.8f; + } } var deleteButton = new GUIButton(new Rectangle(0, 0, 70, 20), "Delete", Alignment.BottomLeft, GUI.Style, loadFrame); @@ -748,10 +756,10 @@ namespace Barotrauma // textBox.Rect = new Rectangle(textBox.Rect.Location, new Point(textBox.Rect.Width, 20)); - textBox.Text = ToolBox.LimitString(text, 15); + //textBox.Text = ToolBox.LimitString(text, 15); - textBox.Flash(Color.Green); - textBox.Deselect(); + //textBox.Flash(Color.Green); + //textBox.Deselect(); return true; } diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 99e3dbe7b..86e0741d1 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -15,7 +15,7 @@ namespace Barotrauma GUIFrame buttonsTab; private GUIFrame[] menuTabs; - private GUIListBox mapList; + private GUIListBox subList; private GUIListBox saveList; @@ -85,40 +85,45 @@ namespace Barotrauma //---------------------------------------------------------------------- menuTabs[(int)Tab.NewGame] = new GUIFrame(panelRect, GUI.Style); - //menuTabs[(int)Tabs.NewGame].Padding = GUI.style.smallPadding; + menuTabs[(int)Tab.NewGame].Padding = new Vector4(20.0f,20.0f,20.0f,20.0f); //new GUITextBlock(new Rectangle(0, -20, 0, 30), "New Game", null, null, Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.NewGame]); new GUITextBlock(new Rectangle(0, 0, 0, 30), "Selected submarine:", null, null, Alignment.Left, GUI.Style, menuTabs[(int)Tab.NewGame]); - mapList = new GUIListBox(new Rectangle(0, 30, 200, panelRect.Height-100), GUI.Style, menuTabs[(int)Tab.NewGame]); + subList = new GUIListBox(new Rectangle(0, 30, 230, panelRect.Height-100), GUI.Style, menuTabs[(int)Tab.NewGame]); var subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)); foreach (Submarine sub in Submarine.SavedSubmarines) { - new GUITextBlock( + var textBlock = new GUITextBlock( new Rectangle(0, 0, 0, 25), - sub.Name, GUI.Style, - Alignment.Left, Alignment.Left, mapList) + ToolBox.LimitString(sub.Name, GUI.Font, subList.Rect.Width-65), GUI.Style, + Alignment.Left, Alignment.Left, subList) { Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f), ToolTip = sub.Description, UserData = sub }; + if (sub.HasTag(SubmarineTag.Shuttle)) + { + var shuttleText = new GUITextBlock(new Rectangle(0, 0, 0, 25), "Shuttle", GUI.Style, Alignment.Left, Alignment.CenterY | Alignment.Right, textBlock, false, GUI.SmallFont); + shuttleText.TextColor = textBlock.TextColor * 0.8f; + } } - if (Submarine.SavedSubmarines.Count > 0) mapList.Select(Submarine.SavedSubmarines[0]); + if (Submarine.SavedSubmarines.Count > 0) subList.Select(Submarine.SavedSubmarines[0]); - new GUITextBlock(new Rectangle((int)(mapList.Rect.Width + 20), 0, 100, 20), + new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 0, 100, 20), "Save name: ", GUI.Style, Alignment.Left, Alignment.Left, menuTabs[(int)Tab.NewGame]); - saveNameBox = new GUITextBox(new Rectangle((int)(mapList.Rect.Width + 30), 30, 180, 20), + saveNameBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 30, 180, 20), Alignment.TopLeft, GUI.Style, menuTabs[(int)Tab.NewGame]); - new GUITextBlock(new Rectangle((int)(mapList.Rect.Width + 20), 60, 100, 20), + new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 60, 100, 20), "Map Seed: ", GUI.Style, Alignment.Left, Alignment.Left, menuTabs[(int)Tab.NewGame]); - seedBox = new GUITextBox(new Rectangle((int)(mapList.Rect.Width + 30), 90, 180, 20), + seedBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 90, 180, 20), Alignment.TopLeft, GUI.Style, menuTabs[(int)Tab.NewGame]); seedBox.Text = ToolBox.RandomSeed(8); @@ -492,7 +497,7 @@ namespace Barotrauma return false; } - Submarine selectedSub = mapList.SelectedData as Submarine; + Submarine selectedSub = subList.SelectedData as Submarine; if (selectedSub == null) return false; if (!Directory.Exists(SaveUtil.TempPath)) diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index d7ee819ae..c505567eb 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -655,14 +655,15 @@ namespace Barotrauma public void AddSubmarine(GUIComponent subList, Submarine sub) { var subTextBlock = new GUITextBlock( - new Rectangle(0, 0, 0, 25), sub.Name, GUI.Style, - Alignment.Left, Alignment.Left, subList) + new Rectangle(0, 0, 0, 25), ToolBox.LimitString(sub.Name, GUI.Font, subList.Rect.Width - 65), GUI.Style, + Alignment.Left, Alignment.CenterY | Alignment.Left, subList) { Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f), ToolTip = sub.Description, UserData = sub }; + var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name); if (matchingSub == null) { @@ -681,6 +682,13 @@ namespace Barotrauma subTextBlock.TextColor = sub.HasTag(SubmarineTag.Shuttle) ? Color.White : Color.DarkGray; } } + + + if (sub.HasTag(SubmarineTag.Shuttle)) + { + var shuttleText = new GUITextBlock(new Rectangle(0, 0, 0, 25), "Shuttle", GUI.Style, Alignment.Left, Alignment.CenterY | Alignment.Right, subTextBlock, false, GUI.SmallFont); + shuttleText.TextColor = subTextBlock.TextColor * 0.8f; + } } diff --git a/Subsurface/Source/Utils/ToolBox.cs b/Subsurface/Source/Utils/ToolBox.cs index 09bb2330c..c13b97ad3 100644 --- a/Subsurface/Source/Utils/ToolBox.cs +++ b/Subsurface/Source/Utils/ToolBox.cs @@ -308,8 +308,27 @@ namespace Barotrauma if (maxCharacters < 4 || str.Length <= maxCharacters) return str; - return str.Substring(0, maxCharacters-3) + "..."; + return str.Substring(0, maxCharacters-3) + "..."; + } + + public static string LimitString(string str, SpriteFont font, int maxWidth) + { + if (maxWidth <= 0 || string.IsNullOrWhiteSpace(str)) return ""; + + StringBuilder sb = new StringBuilder(); + float currWidth = font.MeasureString("...").X; + for (int i = 0; i < str.Length; i++ ) + { + currWidth += font.MeasureString(str[i].ToString()).X; + + if (currWidth > maxWidth) + { + return str.Substring(0, i + 1) + "..."; + } + } + + return str; } public static string RandomSeed(int length)