diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index aa1a33b04..9cd7cb2ee 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -467,7 +467,6 @@ namespace Barotrauma public static void Update(float deltaTime) { - if (pauseMenuOpen) { pauseMenu.Update(0.016f); diff --git a/Subsurface/Source/GUI/GUIComponent.cs b/Subsurface/Source/GUI/GUIComponent.cs index 70eaeddfb..eda451602 100644 --- a/Subsurface/Source/GUI/GUIComponent.cs +++ b/Subsurface/Source/GUI/GUIComponent.cs @@ -311,10 +311,13 @@ namespace Barotrauma } - for (int i = 0; i < children.Count; i++) + //use a fixed list since children can change their order in the main children list + //TODO: maybe find a more efficient way of handling changes in list order + List fixedChildren = new List(children); + foreach (GUIComponent c in fixedChildren) { - if (!children[i].Visible) continue; - children[i].Update(deltaTime); + if (!c.Visible) continue; + c.Update(deltaTime); } } diff --git a/Subsurface/Source/GUI/GUIDropDown.cs b/Subsurface/Source/GUI/GUIDropDown.cs index b4ae51dc7..b88afd7c9 100644 --- a/Subsurface/Source/GUI/GUIDropDown.cs +++ b/Subsurface/Source/GUI/GUIDropDown.cs @@ -153,7 +153,7 @@ namespace Barotrauma private bool OnClicked(GUIComponent component, object obj) { if (wasOpened) return false; - + wasOpened = true; Dropped = !Dropped; diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 19aa4fa31..6d77ff4a1 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -284,8 +284,7 @@ namespace Barotrauma { Sound.Dispose(); } - - + /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. @@ -324,7 +323,10 @@ namespace Barotrauma paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) && (NetworkMember == null || !NetworkMember.GameStarted); - if (!paused || Screen.Selected is MainMenuScreen) Screen.Selected.Update(deltaTime); + if (!paused) + { + Screen.Selected.Update(deltaTime); + } if (NetworkMember != null) { @@ -336,7 +338,6 @@ namespace Barotrauma } GUI.Update((float)deltaTime); - } CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime); diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 3548b360b..095b12e7b 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -11,9 +11,7 @@ namespace Barotrauma class MainMenuScreen : Screen { public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3, Settings = 4 } - - private GUIButton[] menuButtons; - + GUIFrame buttonsTab; private GUIFrame[] menuTabs; @@ -44,53 +42,43 @@ namespace Barotrauma Rectangle panelRect = new Rectangle( 290, y, 500, 360); - - menuButtons = new GUIButton[8]; - + 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; - menuButtons[0] = button; 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; - menuButtons[1] = button; 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; - menuButtons[2] = button; 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; - menuButtons[3] = button; 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; - menuButtons[4] = button; 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; }; - menuButtons[5] = button; 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; - menuButtons[6] = button; button = new GUIButton(new Rectangle(0, 0, 150, 30), "Quit", Alignment.BottomRight, GUI.Style, buttonsTab); button.Color = button.Color * 0.8f; button.OnClicked = QuitClicked; - menuButtons[7] = button; panelRect.Y += 10; @@ -491,14 +479,11 @@ namespace Barotrauma public override void Update(double deltaTime) { //GameMain.TitleScreen.Update(); - - foreach (GUIButton button in menuButtons) - { - button.Update((float)deltaTime); - } - buttonsTab.Update((float)deltaTime); - if (selectedTab>0) menuTabs[selectedTab].Update((float)deltaTime); + if (selectedTab > 0) + { + menuTabs[selectedTab].Update((float)deltaTime); + } GameMain.TitleScreen.TitlePosition = Vector2.Lerp(GameMain.TitleScreen.TitlePosition, new Vector2( diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index 7bfce1543..bdf2f7f44 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -340,7 +340,7 @@ namespace Barotrauma menu.Update((float)deltaTime); - GUI.Update((float)deltaTime); + //GUI.Update((float)deltaTime); } } }