diff --git a/Subsurface/Source/GUI/GUIButton.cs b/Subsurface/Source/GUI/GUIButton.cs index 971f299c9..59022491c 100644 --- a/Subsurface/Source/GUI/GUIButton.cs +++ b/Subsurface/Source/GUI/GUIButton.cs @@ -103,6 +103,19 @@ namespace Barotrauma set { textBlock.Text = value; } } + public override string ToolTip + { + get + { + return base.ToolTip; + } + set + { + textBlock.ToolTip = value; + base.ToolTip = value; + } + } + public bool Selected { get; set; } public GUIButton(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null) diff --git a/Subsurface/Source/GUI/GUIDropDown.cs b/Subsurface/Source/GUI/GUIDropDown.cs index a6bd02787..2a5ecc541 100644 --- a/Subsurface/Source/GUI/GUIDropDown.cs +++ b/Subsurface/Source/GUI/GUIDropDown.cs @@ -26,6 +26,53 @@ namespace Barotrauma return listBox.Selected.UserData; } } + + public bool Enabled + { + get { return listBox.Enabled; } + set { listBox.Enabled = value; } + } + + public GUIComponent Selected + { + get { return listBox.Selected; } + } + + public GUIListBox ListBox + { + get { return listBox; } + } + + public object SelectedData + { + get + { + return (listBox.Selected == null) ? null : listBox.Selected.UserData; + } + } + + public int SelectedIndex + { + get + { + if (listBox.Selected == null) return -1; + return listBox.children.FindIndex(x => x == listBox.Selected); + } + } + + public override string ToolTip + { + get + { + return base.ToolTip; + } + set + { + base.ToolTip = value; + button.ToolTip = value; + listBox.ToolTip = value; + } + } public GUIDropDown(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null) : base(style) @@ -34,7 +81,7 @@ namespace Barotrauma if (parent != null) parent.AddChild(this); - button = new GUIButton(Rectangle.Empty, text, Color.White, Alignment.TopLeft, Alignment.TopLeft, null, this); + button = new GUIButton(this.rect, text, Color.White, Alignment.TopLeft, Alignment.TopLeft, null, null); button.TextColor = Color.White; button.Color = Color.Black * 0.8f; @@ -47,6 +94,11 @@ namespace Barotrauma //listBox.ScrollBarEnabled = false; } + public override void AddChild(GUIComponent child) + { + listBox.AddChild(child); + } + public void AddItem(string text, object userData = null) { GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, GUI.Style, listBox); @@ -61,6 +113,11 @@ namespace Barotrauma //listBox.Rect = new Rectangle(listBox.Rect.X,listBox.Rect.Y,listBox.Rect.Width,totalHeight); } + public List GetChildren() + { + return listBox.children; + } + private bool SelectItem(GUIComponent component, object obj) { GUITextBlock textBlock = component as GUITextBlock; @@ -84,6 +141,11 @@ namespace Barotrauma //SelectItem(child, userData); } + + public void Select(int index) + { + listBox.Select(index); + } private bool wasOpened; @@ -116,13 +178,12 @@ namespace Barotrauma { Rectangle listBoxRect = listBox.Rect; listBoxRect.Width += 20; - if (!listBoxRect.Contains(PlayerInput.MousePosition)) + if (!listBoxRect.Contains(PlayerInput.MousePosition) && !button.Rect.Contains(PlayerInput.MousePosition)) { Dropped = false; } } - - + button.Update(deltaTime); if (Dropped) listBox.Update(deltaTime); diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 1fbcc7c87..de9f21253 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -6,6 +6,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; using System.Reflection; @@ -18,8 +19,18 @@ namespace Barotrauma None = 0, Left = 1, Right = 2 } + [Flags] + public enum SubmarineTag + { + [Description("Shuttle")] + Shuttle = 1, + [Description("Hide in menus")] + HideInMenus = 2 + } + class Submarine : Entity { + public static string SavePath = "Submarines"; public static readonly Vector2 HiddenSubStartPosition = new Vector2(-50000.0f, 80000.0f); @@ -56,6 +67,8 @@ namespace Barotrauma private string filePath; private string name; + private SubmarineTag tags; + private Vector2 prevPosition; private float lastNetworkUpdate, networkUpdateTimer; @@ -230,6 +243,7 @@ namespace Barotrauma if (doc != null && doc.Root != null) { Description = ToolBox.GetAttributeString(doc.Root, "description", ""); + Enum.TryParse(ToolBox.GetAttributeString(doc.Root, "tags", ""), out tags); } } @@ -240,6 +254,24 @@ namespace Barotrauma base.Remove(); } + public bool HasTag(SubmarineTag tag) + { + return tags.HasFlag(tag); + } + + public void AddTag(SubmarineTag tag) + { + if (tags.HasFlag(tag)) return; + + tags |= tag; + } + + public void RemoveTag(SubmarineTag tag) + { + if (!tags.HasFlag(tag)) return; + + tags &= ~tag; + } //drawing ---------------------------------------------------- @@ -579,6 +611,8 @@ namespace Barotrauma element.Add(new XAttribute("name", name)); element.Add(new XAttribute("description", Description == null ? "" : Description)); + element.Add(new XAttribute("tags", tags.ToString())); + foreach (MapEntity e in MapEntity.mapEntityList) { if (e.MoveWithLevel || e.Submarine != this) continue; @@ -768,7 +802,7 @@ namespace Barotrauma } Description = ToolBox.GetAttributeString(submarineElement, "description", ""); - + Enum.TryParse(ToolBox.GetAttributeString(submarineElement, "tags", ""), out tags); HiddenSubPosition = HiddenSubStartPosition; foreach (Submarine sub in Submarine.loaded) diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index dc753867b..919e51063 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -286,7 +286,8 @@ namespace Barotrauma.Networking submarines.Add(new Submarine(mySubPath, subHash, false)); } - GameMain.NetLobbyScreen.UpdateSubList(submarines); + GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, Submarine.SavedSubmarines); + GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, Submarine.SavedSubmarines); //add the name of own client to the lobby screen GameMain.NetLobbyScreen.AddPlayer(name); @@ -367,7 +368,9 @@ namespace Barotrauma.Networking List subList = GameMain.NetLobbyScreen.GetSubList(); GameMain.NetLobbyScreen = new NetLobbyScreen(); - GameMain.NetLobbyScreen.UpdateSubList(subList); + GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, subList); + GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, subList); + GameMain.NetLobbyScreen.Select(); } connected = true; @@ -486,7 +489,11 @@ namespace Barotrauma.Networking string subName = inc.ReadString(); string subHash = inc.ReadString(); - if (GameMain.NetLobbyScreen.TrySelectSub(subName,subHash)) + string shuttleName = inc.ReadString(); + string shuttleHash = inc.ReadString(); + + if (GameMain.NetLobbyScreen.TrySelectSub(subName,subHash,GameMain.NetLobbyScreen.SubList) && + GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox)) { NetOutgoingMessage readyToStartMsg = client.CreateMessage(); readyToStartMsg.Write((byte)PacketTypes.StartGame); @@ -636,8 +643,11 @@ namespace Barotrauma.Networking int missionTypeIndex = inc.ReadByte(); - string mapName = inc.ReadString(); - string mapHash = inc.ReadString(); + string subName = inc.ReadString(); + string subHash = inc.ReadString(); + + string shuttleName = inc.ReadString(); + string shuttleHash = inc.ReadString(); string modeName = inc.ReadString(); @@ -651,11 +661,15 @@ namespace Barotrauma.Networking yield return CoroutineStatus.Success; } - if (!GameMain.NetLobbyScreen.TrySelectSub(mapName, mapHash)) + if (!GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList)) { yield return CoroutineStatus.Success; } + if (!GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox)) + { + yield return CoroutineStatus.Success; + } Rand.SetSyncedSeed(seed); //int gameModeIndex = inc.ReadInt32(); @@ -663,7 +677,7 @@ namespace Barotrauma.Networking GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, Mission.MissionTypes[missionTypeIndex]); GameMain.GameSession.StartShift(levelSeed); - if (respawnAllowed) respawnManager = new RespawnManager(this); + if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle); //myCharacter = ReadCharacterData(inc); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 5823de5b0..53f0d3a7a 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -905,6 +905,7 @@ namespace Barotrauma.Networking public bool StartGameClicked(GUIButton button, object obj) { Submarine selectedSub = null; + Submarine selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle; if (Voting.AllowSubVoting) { @@ -922,6 +923,12 @@ namespace Barotrauma.Networking return false; } + if (selectedShuttle == null) + { + GameMain.NetLobbyScreen.ShuttleList.Flash(); + return false; + } + GameModePreset selectedMode = Voting.HighestVoted(VoteType.Mode, connectedClients); if (selectedMode == null) selectedMode = GameMain.NetLobbyScreen.SelectedMode; @@ -931,12 +938,12 @@ namespace Barotrauma.Networking return false; } - CoroutineManager.StartCoroutine(WaitForPlayersReady(selectedSub, selectedMode), "WaitForPlayersReady"); + CoroutineManager.StartCoroutine(WaitForPlayersReady(selectedSub, selectedShuttle, selectedMode), "WaitForPlayersReady"); return true; } - private IEnumerable WaitForPlayersReady(Submarine selectedSub, GameModePreset selectedMode) + private IEnumerable WaitForPlayersReady(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode) { GameMain.NetLobbyScreen.StartButton.Enabled = false; @@ -945,6 +952,9 @@ namespace Barotrauma.Networking msg.Write(selectedSub.Name); msg.Write(selectedSub.MD5Hash.Hash); + msg.Write(selectedShuttle.Name); + msg.Write(selectedShuttle.MD5Hash.Hash); + SendMessage(msg, NetDeliveryMethod.ReliableUnordered); connectedClients.ForEach(c => c.ReadyToStart = false); @@ -974,12 +984,12 @@ namespace Barotrauma.Networking } } - GameMain.ShowLoading(StartGame(selectedSub, selectedMode), false); + GameMain.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false); yield return CoroutineStatus.Success; } - private IEnumerable StartGame(Submarine selectedSub, GameModePreset selectedMode) + private IEnumerable StartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode) { Item.Spawner.Clear(); Item.Remover.Clear(); @@ -1001,7 +1011,7 @@ namespace Barotrauma.Networking GameServer.Log("Game mode: " + selectedMode.Name, Color.Cyan); GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan); - if (AllowRespawn) respawnManager = new RespawnManager(this); + if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle); yield return CoroutineStatus.Running; @@ -1105,6 +1115,9 @@ namespace Barotrauma.Networking msg.Write(selectedSub.Name); msg.Write(selectedSub.MD5Hash.Hash); + msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name); + msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash); + msg.Write(selectedMode.Name); msg.Write(AllowRespawn); diff --git a/Subsurface/Source/Networking/RespawnManager.cs b/Subsurface/Source/Networking/RespawnManager.cs index 0d2dfa017..e27e0827f 100644 --- a/Subsurface/Source/Networking/RespawnManager.cs +++ b/Subsurface/Source/Networking/RespawnManager.cs @@ -61,11 +61,11 @@ namespace Barotrauma.Networking private float updateReturnTimer; - public RespawnManager(NetworkMember networkMember) + public RespawnManager(NetworkMember networkMember, Submarine shuttle) { this.networkMember = networkMember; - respawnShuttle = new Submarine("Submarines/Shuttle Mark I.sub"); + respawnShuttle = shuttle; respawnShuttle.Load(false); ResetShuttle(); @@ -398,7 +398,9 @@ namespace Barotrauma.Networking msg.Write((byte)characterInfos.Count); for (int i = 0; i < characterInfos.Count; i++) { - var character = Character.Create(characterInfos[i], waypoints[i].WorldPosition, true, false); + bool myCharacter = i >= clients.Count; + + var character = Character.Create(characterInfos[i], waypoints[i].WorldPosition, !myCharacter, false); if (divingSuitPrefab != null && oxyPrefab != null) { @@ -416,17 +418,17 @@ namespace Barotrauma.Networking Item.Spawner.AddToSpawnedList(oxyTank); } - if (i < clients.Count) - { - msg.Write((byte)clients[i].ID); - clients[i].Character = character; - } - else + if (myCharacter) { msg.Write((byte)0); server.Character = character; Character.Controlled = character; } + else + { + msg.Write((byte)clients[i].ID); + clients[i].Character = character; + } character.GiveJobItems(waypoints[i]); diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index d65528fab..ffb0010d8 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -3,8 +3,10 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; +using System.Reflection; namespace Barotrauma { @@ -19,7 +21,9 @@ namespace Barotrauma private GUIFrame loadFrame; - private GUITextBox nameBox, descriptionBox; + private GUIFrame saveFrame; + + private GUITextBox nameBox; const int PreviouslyUsedCount = 10; private GUIListBox previouslyUsedList; @@ -88,24 +92,23 @@ namespace Barotrauma var button = new GUIButton(new Rectangle(0, 0, 70, 20), "Open...", GUI.Style, topPanel); button.OnClicked = CreateLoadScreen; - nameBox = new GUITextBox(new Rectangle(150, 0, 150, 20), GUI.Style, topPanel); - nameBox.OnEnterPressed = ChangeSubName; + button = new GUIButton(new Rectangle(80,0,70,20), "Save", GUI.Style, topPanel); + button.OnClicked = (GUIButton btn, object data) => + { + CreateSaveScreen(); - button = new GUIButton(new Rectangle(310,0,70,20), "Save", GUI.Style, topPanel); - button.OnClicked = SaveSub; + return true; + }; - new GUITextBlock(new Rectangle(390, 0, 100, 20), "Description: ", GUI.Style, topPanel); - - descriptionBox = new GUITextBox(new Rectangle(490, 0, 200, 20), null, null, Alignment.TopLeft, - Alignment.TopLeft, GUI.Style, topPanel); - descriptionBox.Wrap = true; - descriptionBox.OnSelected += ExpandDescriptionBox; - descriptionBox.OnTextChanged = ChangeSubDescription; - - - //new GUITextBlock(new Rectangle(390, 0, 100, 20), "Link ", GUI.Style, topPanel); + var nameLabel = new GUITextBlock(new Rectangle(170, -4, 150, 20), "", GUI.Style, topPanel, GUI.LargeFont); + nameLabel.TextGetter = GetSubName; var linkedSubBox = new GUIDropDown(new Rectangle(750,0,200,20), "Add submarine", GUI.Style, topPanel); + linkedSubBox.ToolTip = + "Places another submarine into the current submarine file. "+ + "Can be used for adding things such as smaller vessels, "+ + "escape pods or detachable sections into the main submarine."; + foreach (Submarine sub in Submarine.SavedSubmarines) { linkedSubBox.AddItem(sub.Name, sub); @@ -121,8 +124,7 @@ namespace Barotrauma GUITextBlock structureCount = new GUITextBlock(new Rectangle(0, 50, 0, 20), "", GUI.Style, leftPanel); structureCount.TextGetter = GetStructureCount; - GUItabs = new GUIComponent[Enum.GetValues(typeof(MapEntityCategory)).Length]; - + GUItabs = new GUIComponent[Enum.GetValues(typeof(MapEntityCategory)).Length]; int width = 400, height = 400; int y = 90; @@ -255,19 +257,19 @@ namespace Barotrauma if (Submarine.MainSub != null) { cam.Position = Submarine.MainSub.Position + Submarine.MainSub.HiddenSubPosition; - nameBox.Text = Submarine.MainSub.Name; - descriptionBox.Text = ToolBox.LimitString(Submarine.MainSub.Description, 15); + //nameBox.Text = Submarine.MainSub.Name; + //descriptionBox.Text = ToolBox.LimitString(Submarine.MainSub.Description, 15); } else { cam.Position = Submarine.HiddenSubStartPosition; - nameBox.Text = ""; - descriptionBox.Text = ""; + //if (nameBox != null) nameBox.Text = ""; + //descriptionBox.Text = ""; Submarine.MainSub = new Submarine(Path.Combine(Submarine.SavePath, "Unnamed.sub"), "", false); } - nameBox.Deselect(); + //nameBox.Deselect(); cam.UpdateTransform(); } @@ -345,6 +347,91 @@ namespace Barotrauma return false; } + private void CreateSaveScreen() + { + int width = 400, height = 400; + + int y = 0; + + saveFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style, null); + saveFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); + + new GUITextBlock(new Rectangle(0,0,200,30), "Save submarine", GUI.Style, saveFrame, GUI.LargeFont); + + y += 30; + + new GUITextBlock(new Rectangle(0,y,150,20), "Name:", GUI.Style, saveFrame); + y += 20; + + nameBox = new GUITextBox(new Rectangle(5, y, 150, 20), GUI.Style, saveFrame); + nameBox.OnEnterPressed = ChangeSubName; + nameBox.Text = GetSubName(); + + y += 30; + + new GUITextBlock(new Rectangle(0, y, 150, 20), "Description:", GUI.Style, saveFrame); + y += 20; + + var descriptionBox = new GUITextBox(new Rectangle(5, y, 0, 100), null, null, Alignment.TopLeft, + Alignment.TopLeft, GUI.Style, saveFrame); + descriptionBox.Wrap = true; + descriptionBox.Text = Submarine.MainSub == null ? "" : Submarine.MainSub.Description; + descriptionBox.OnSelected += ExpandDescriptionBox; + descriptionBox.OnTextChanged = ChangeSubDescription; + + y += descriptionBox.Rect.Height + 15; + new GUITextBlock(new Rectangle(0, y, 150, 20), "Settings:", GUI.Style, saveFrame); + + y += 20; + + int tagX = 10, tagY = 0; + foreach (SubmarineTag tag in Enum.GetValues(typeof(SubmarineTag))) + { + FieldInfo fi = typeof(SubmarineTag).GetField(tag.ToString()); + DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); + + string tagStr = attributes.Length > 0 ? attributes[0].Description : ""; + + var tagTickBox = new GUITickBox(new Rectangle(tagX, y+ tagY, 20, 20), tagStr, Alignment.TopLeft, saveFrame); + tagTickBox.Selected = Submarine.MainSub == null ? false : Submarine.MainSub.HasTag(tag); + tagTickBox.UserData = tag; + + tagTickBox.OnSelected = (GUITickBox tickBox) => + { + if (Submarine.MainSub == null) return false; + + if (tickBox.Selected) + { + Submarine.MainSub.AddTag((SubmarineTag)tickBox.UserData); + } + else + { + Submarine.MainSub.RemoveTag((SubmarineTag)tickBox.UserData); + } + + return true; + }; + + tagY += 25; + if (tagY > 100) + { + tagY = 0; + tagX += 200; + } + } + + var saveButton = new GUIButton(new Rectangle(-90, 0, 80, 20), "Save", Alignment.Right | Alignment.Bottom, GUI.Style, saveFrame); + saveButton.OnClicked = SaveSub; + + var cancelButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Cancel", Alignment.Right | Alignment.Bottom, GUI.Style, saveFrame); + cancelButton.OnClicked = (GUIButton btn, object userdata) => + { + saveFrame = null; + return true; + }; + + } + private bool CreateLoadScreen(GUIButton button, object obj) { Submarine.Preload(); @@ -427,8 +514,8 @@ namespace Barotrauma Submarine.MainSub = selectedSub; selectedSub.Load(true); - nameBox.Text = selectedSub.Name; - descriptionBox.Text = ToolBox.LimitString(selectedSub.Description,15); + //nameBox.Text = selectedSub.Name; + //descriptionBox.Text = ToolBox.LimitString(selectedSub.Description,15); loadFrame = null; @@ -737,10 +824,10 @@ namespace Barotrauma if (GUIComponent.MouseOn == null) { - if (nameBox.Selected && PlayerInput.LeftButtonClicked()) - { - ChangeSubName(nameBox, nameBox.Text); - } + //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); @@ -797,6 +884,10 @@ namespace Barotrauma loadFrame.Update((float)deltaTime); if (PlayerInput.RightButtonClicked()) loadFrame = null; } + else if (saveFrame != null) + { + saveFrame.Update((float)deltaTime); + } else if (selectedTab > -1) { GUItabs[selectedTab].Update((float)deltaTime); @@ -879,6 +970,10 @@ namespace Barotrauma { loadFrame.Draw(spriteBatch); } + else if (saveFrame != null) + { + saveFrame.Draw(spriteBatch); + } else if (selectedTab > -1) { GUItabs[selectedTab].Draw(spriteBatch); diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 5cede6890..4f1bd5a69 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -7,6 +7,7 @@ using FarseerPhysics; using FarseerPhysics.Factories; using FarseerPhysics.Dynamics; using System.IO; +using System.Linq; using System.Collections.Generic; namespace Barotrauma @@ -37,6 +38,8 @@ namespace Barotrauma private GUITickBox autoRestartBox; + private GUIDropDown shuttleList; + public bool IsServer; public string ServerName; @@ -53,6 +56,11 @@ namespace Barotrauma get { return subList; } } + public GUIDropDown ShuttleList + { + get { return shuttleList; } + } + public GUIListBox ModeList { get { return modeList; } @@ -79,6 +87,11 @@ namespace Barotrauma get { return subList.SelectedData as Submarine; } } + public Submarine SelectedShuttle + { + get { return shuttleList.SelectedData as Submarine; } + } + public GameModePreset SelectedMode { get { return modeList.SelectedData as GameModePreset; } @@ -206,10 +219,17 @@ namespace Barotrauma columnX += columnWidth + 20; + + //respawn shuttle ------------------------------------------------------------------ + + new GUITextBlock(new Rectangle(columnX, 120, 20, 20), "Respawn shuttle:", GUI.Style, infoFrame); + shuttleList = new GUIDropDown(new Rectangle(columnX, 150, 200, 20), "", GUI.Style, infoFrame); + + //gamemode ------------------------------------------------------------------ - new GUITextBlock(new Rectangle(columnX, 120, 0, 30), "Game mode: ", GUI.Style, infoFrame); - modeList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, infoFrame.Rect.Height - 150 - 80), GUI.Style, infoFrame); + new GUITextBlock(new Rectangle(columnX, 180, 0, 30), "Game mode: ", GUI.Style, infoFrame); + modeList = new GUIListBox(new Rectangle(columnX, 200, columnWidth, infoFrame.Rect.Height - 300), GUI.Style, infoFrame); modeList.OnSelected = VotableClicked; voteText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Votes: ", GUI.Style, Alignment.TopLeft, Alignment.TopRight, infoFrame); @@ -229,8 +249,7 @@ namespace Barotrauma textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); textBlock.UserData = mode; } - - + //mission type ------------------------------------------------------------------ missionTypeBlock = new GUITextBlock(new Rectangle(columnX, 0, 300, 20), "Mission type:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, infoFrame); @@ -318,8 +337,7 @@ namespace Barotrauma GameMain.LightManager.LosEnabled = false; textBox.Select(); - - + textBox.OnEnterPressed = GameMain.NetworkMember.EnterChatMessage; textBox.OnTextChanged = GameMain.NetworkMember.TypingChatMessage; @@ -327,6 +345,7 @@ namespace Barotrauma //GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting; + shuttleList.Enabled = subList.Enabled; playerList.Enabled = GameMain.Server != null; modeList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowModeVoting; seedBox.Enabled = GameMain.Server != null; @@ -349,8 +368,11 @@ namespace Barotrauma if (IsServer && GameMain.Server != null) { - int prevSelected = subList.SelectedIndex; - UpdateSubList(Submarine.SavedSubmarines); + int prevSelectedSub = subList.SelectedIndex; + UpdateSubList(subList, Submarine.SavedSubmarines); + + int prevSelectedShuttle = shuttleList.SelectedIndex; + UpdateSubList(shuttleList, Submarine.SavedSubmarines); modeList.OnSelected = VotableClicked; modeList.OnSelected = SelectMode; @@ -369,12 +391,21 @@ namespace Barotrauma GUIButton settingsButton = new GUIButton(new Rectangle(-100, 0, 80, 30), "Settings", Alignment.BottomRight, GUI.Style, infoFrame); settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame; settingsButton.UserData = "settingsButton"; - - - if (subList.CountChildren > 0 && subList.Selected == null) + + if (subList.Selected == null) subList.Select(Math.Max(0, prevSelectedSub)); + if (shuttleList.Selected == null) { - subList.Select(Math.Max(0, prevSelected)); + var shuttles = shuttleList.GetChildren().FindAll(c => c.UserData is Submarine && ((Submarine)c.UserData).HasTag(SubmarineTag.Shuttle)); + if (prevSelectedShuttle==-1 && shuttles.Any()) + { + shuttleList.SelectItem(shuttles[0].UserData); + } + else + { + shuttleList.Select(Math.Max(0, prevSelectedShuttle)); + } } + if (GameModePreset.list.Count > 0 && modeList.Selected == null) modeList.Select(0); if (myPlayerFrame.children.Find(c => c.UserData as string == "playyourself") == null) @@ -600,7 +631,7 @@ namespace Barotrauma return true; } - public void UpdateSubList(List submarines) + public void UpdateSubList(GUIComponent subList, List submarines) { if (subList == null) return; @@ -613,11 +644,11 @@ namespace Barotrauma foreach (Submarine sub in submarines) { - AddSubmarine(sub); + AddSubmarine(subList, sub); } } - public void AddSubmarine(Submarine sub) + public void AddSubmarine(GUIComponent subList, Submarine sub) { var subTextBlock = new GUITextBlock( new Rectangle(0, 0, 0, 25), sub.Name, GUI.Style, @@ -639,8 +670,16 @@ namespace Barotrauma subTextBlock.TextColor = Color.LightGray; subTextBlock.ToolTip = "Your version of the submarine doesn't match the servers version"; } + else + { + if (subList == shuttleList || subList == shuttleList.ListBox) + { + subTextBlock.TextColor = sub.HasTag(SubmarineTag.Shuttle) ? Color.White : Color.DarkGray; + } + } } + public bool VotableClicked(GUIComponent component, object userData) { if (GameMain.Client == null) return false; @@ -1011,7 +1050,7 @@ namespace Barotrauma if (GameMain.Client!=null) GameMain.Client.SendCharacterData(); } - public bool TrySelectSub(string subName, string md5Hash) + public bool TrySelectSub(string subName, string md5Hash, GUIListBox subList) { //already downloading the selected sub file if (GameMain.Client.ActiveFileTransferName == subName+".sub") return false; @@ -1078,8 +1117,8 @@ namespace Barotrauma if (selectedSub==null) { - msg.Write(" "); - msg.Write(" "); + msg.Write(""); + msg.Write(""); } else { @@ -1087,6 +1126,17 @@ namespace Barotrauma msg.Write(selectedSub.MD5Hash.Hash); } + if (SelectedShuttle == null) + { + msg.Write(""); + msg.Write(""); + } + else + { + msg.Write(Path.GetFileName(SelectedShuttle.Name)); + msg.Write(selectedShuttle.MD5Hash.Hash); + } + msg.Write(ServerName); msg.Write(serverMessage.Text); @@ -1110,7 +1160,8 @@ namespace Barotrauma public void ReadData(NetIncomingMessage msg) { - string subName = "", md5Hash = ""; + string subName = "", subHash = ""; + string shuttleName = "", shuttleHash = ""; int modeIndex = 0; //float durationScroll = 0.0f; @@ -1125,7 +1176,10 @@ namespace Barotrauma try { subName = msg.ReadString(); - md5Hash = msg.ReadString(); + subHash = msg.ReadString(); + + shuttleName = msg.ReadString(); + shuttleHash = msg.ReadString(); ServerName = msg.ReadString(); serverMessage.Text = msg.ReadString(); @@ -1156,7 +1210,9 @@ namespace Barotrauma return; } - if (!string.IsNullOrWhiteSpace(subName) && !GameMain.NetworkMember.Voting.AllowSubVoting) TrySelectSub(subName, md5Hash); + if (!string.IsNullOrWhiteSpace(subName) && !GameMain.NetworkMember.Voting.AllowSubVoting) TrySelectSub(subName, subHash, subList); + + if (!string.IsNullOrWhiteSpace(shuttleName)) TrySelectSub(shuttleName, shuttleHash, shuttleList.ListBox); if (!GameMain.NetworkMember.Voting.AllowModeVoting) {