Fixed bug with GUIComponent children changing order in parent's list

This commit is contained in:
juanjp600
2016-09-19 22:02:00 -03:00
parent c97f729fb3
commit f3fbbb8aec
6 changed files with 19 additions and 31 deletions
-1
View File
@@ -467,7 +467,6 @@ namespace Barotrauma
public static void Update(float deltaTime) public static void Update(float deltaTime)
{ {
if (pauseMenuOpen) if (pauseMenuOpen)
{ {
pauseMenu.Update(0.016f); pauseMenu.Update(0.016f);
+6 -3
View File
@@ -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<GUIComponent> fixedChildren = new List<GUIComponent>(children);
foreach (GUIComponent c in fixedChildren)
{ {
if (!children[i].Visible) continue; if (!c.Visible) continue;
children[i].Update(deltaTime); c.Update(deltaTime);
} }
} }
+4 -3
View File
@@ -285,7 +285,6 @@ namespace Barotrauma
Sound.Dispose(); Sound.Dispose();
} }
/// <summary> /// <summary>
/// Allows the game to run logic such as updating the world, /// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio. /// checking for collisions, gathering input, and playing audio.
@@ -324,7 +323,10 @@ namespace Barotrauma
paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) && paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) &&
(NetworkMember == null || !NetworkMember.GameStarted); (NetworkMember == null || !NetworkMember.GameStarted);
if (!paused || Screen.Selected is MainMenuScreen) Screen.Selected.Update(deltaTime); if (!paused)
{
Screen.Selected.Update(deltaTime);
}
if (NetworkMember != null) if (NetworkMember != null)
{ {
@@ -336,7 +338,6 @@ namespace Barotrauma
} }
GUI.Update((float)deltaTime); GUI.Update((float)deltaTime);
} }
CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime); CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime);
+4 -19
View File
@@ -12,8 +12,6 @@ namespace Barotrauma
{ {
public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3, Settings = 4 } public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3, Settings = 4 }
private GUIButton[] menuButtons;
GUIFrame buttonsTab; GUIFrame buttonsTab;
private GUIFrame[] menuTabs; private GUIFrame[] menuTabs;
@@ -45,52 +43,42 @@ namespace Barotrauma
290, y, 290, y,
500, 360); 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); 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.Color = button.Color * 0.8f;
button.OnClicked = TutorialButtonClicked; 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 = 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.Color = button.Color * 0.8f;
button.UserData = Tab.NewGame; button.UserData = Tab.NewGame;
button.OnClicked = SelectTab; 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 = 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.Color = button.Color * 0.8f;
button.UserData = Tab.LoadGame; button.UserData = Tab.LoadGame;
button.OnClicked = SelectTab; 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 = 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.Color = button.Color * 0.8f;
//button.UserData = (int)Tabs.JoinServer; //button.UserData = (int)Tabs.JoinServer;
button.OnClicked = JoinServerClicked; 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 = 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.Color = button.Color * 0.8f;
button.UserData = Tab.HostServer; button.UserData = Tab.HostServer;
button.OnClicked = SelectTab; 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 = 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.Color = button.Color * 0.8f;
button.OnClicked = (GUIButton btn, object userdata) => { GameMain.EditMapScreen.Select(); return true; }; 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 = 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.Color = button.Color * 0.8f;
button.UserData = Tab.Settings; button.UserData = Tab.Settings;
button.OnClicked = SelectTab; button.OnClicked = SelectTab;
menuButtons[6] = button;
button = new GUIButton(new Rectangle(0, 0, 150, 30), "Quit", Alignment.BottomRight, 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.Color = button.Color * 0.8f;
button.OnClicked = QuitClicked; button.OnClicked = QuitClicked;
menuButtons[7] = button;
panelRect.Y += 10; panelRect.Y += 10;
@@ -491,14 +479,11 @@ namespace Barotrauma
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
//GameMain.TitleScreen.Update(); //GameMain.TitleScreen.Update();
foreach (GUIButton button in menuButtons)
{
button.Update((float)deltaTime);
}
buttonsTab.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 = GameMain.TitleScreen.TitlePosition =
Vector2.Lerp(GameMain.TitleScreen.TitlePosition, new Vector2( Vector2.Lerp(GameMain.TitleScreen.TitlePosition, new Vector2(
@@ -340,7 +340,7 @@ namespace Barotrauma
menu.Update((float)deltaTime); menu.Update((float)deltaTime);
GUI.Update((float)deltaTime); //GUI.Update((float)deltaTime);
} }
} }
} }