/// <summary> /// Method to activate and deactivate the required UIs based on the current state of game /// </summary> void SetPageState(UserInterfaceState state) { switch (state) { case UserInterfaceState.None: startMenuUI.SetActive(false); gameOverUI.SetActive(false); countdownUI.SetActive(false); break; case UserInterfaceState.Start: startMenuUI.SetActive(true); gameOverUI.SetActive(false); countdownUI.SetActive(false); break; case UserInterfaceState.Countdown: startMenuUI.SetActive(false); gameOverUI.SetActive(false); countdownUI.SetActive(true); break; case UserInterfaceState.GameOver: startMenuUI.SetActive(false); gameOverUI.SetActive(true); countdownUI.SetActive(false); break; } }
public UserInterface() { _player1Go = new Button(0, 600, 100, 100, true, "Go to\nPlayer 2", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _player2Go = new Button(0, 600, 100, 100, true, "Run\nSimulation", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _makeSpecialMinion = new Button(0, 500, 100, 100, true, "Make Special\nMinion", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _makeSpecialMinionSelected = new Button(0, 500, 100, 100, true, "Make Special\nMinion", new Sprite(new List<string>() { "Images/blueButtonLIGHT.png" }, 0)); _editTree = new Button(0, 400, 100, 100, true, "Edit\nBehaviours", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _mapScroll = new ScrollBar(970, 0, 30, 1800, false, 0, 1800, false, new Sprite(new List<string>() { "Images/SCROLLDAGGER5000.png" }, 0)); _editSelect = new Select(0, 0, false, _selectOptions, new Sprite(new List<string>() { "Images/blueButtonSmall.png" }, 0), new List<string>() { "Images/blueButtonSmall.png" }); _minion1 = new Button(0, 0, 100, 100, true, "Minion 1", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _minion1Selected = new Button(0, 0, 100, 100, true, "Minion 1", new Sprite(new List<string>() { "Images/blueButtonLIGHT.png" }, 0)); _minion2 = new Button(0, 100, 100, 100, true, "Minion 2", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _minion2Selected = new Button(0, 100, 100, 100, true, "Minion 2", new Sprite(new List<string>() { "Images/blueButtonLIGHT.png" }, 0)); _minion3 = new Button(0, 200, 100, 100, true, "Minion 3", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _minion3Selected = new Button(0, 200, 100, 100, true, "Minion 3", new Sprite(new List<string>() { "Images/blueButtonLIGHT.png" }, 0)); _state = UserInterfaceState.Player1MinionSelect; Reset(); Sound.Strategize.PlayLooping(); }
public override void Initialize() { if (Overlay == null) { throw new InvalidOperationException(string.Format("'{0}' cannot be null", ReflectionHelper.GetPropertyName((UserInterfaceComponent c) => c.Overlay))); } UserInterfaceState = Services.GetService <IUserInterfaceState>(); if (UserInterfaceState == null) { throw new InvalidOperationException("UserInterfaceState"); } UserInterfaceState.Initialize(); UserInterfaceState.SetOverlay(Overlay); }
private void ChangeState(UserInterfaceState state) { timeOfStatusChange = SimulationManager.SimulationTime; CurrentState = state; labelState.Text = String.Format("UI State: {0}", state); }
public void Update(double lastFrameTime) { switch (_state) { case UserInterfaceState.Player1EditMinionTree: if (_inSelectMode) { _editSelect.Update(lastFrameTime); if (_editSelect.Canceled) { _inSelectMode = false; _editSelect.Reset(); } else if (_editSelect.SelectedIndex != -1) { int index = _player1ParentList[_inSelectModeButton].Item1.Children.IndexOf(_inSelectModeButton); bool query = _selectOptions[_editSelect.SelectedIndex].StartsWith("Is"); if (query) { if (index == -1) { index = _player1ParentList[_inSelectModeButton].Item1.Children.IndexOf(_player1ParentList[_inSelectModeButton].Item2); _player1ParentList[_inSelectModeButton].Item1.Children.Remove(_player1ParentList[_inSelectModeButton].Item2); } else { _player1ParentList[_inSelectModeButton].Item1.Children.Remove(_inSelectModeButton); } StackPanel panel = new StackPanel(0, 0, false, false); StackPanel panel2 = new StackPanel(0, 0, false, true); panel.Children.Add(panel2); Button button = new Button(0, 0, 100, 100, false, "Go To Base", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); panel.Children.Add(button); _player1ParentList.Add(button, new Tuple<StackPanel, StackPanel>(panel, null)); Button queryButton = new Button(0, 0, 100, 100, false, _selectOptions[_editSelect.SelectedIndex], new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); panel2.Children.Add(queryButton); _player1ParentList.Add(queryButton, new Tuple<StackPanel, StackPanel>(_player1ParentList[_inSelectModeButton].Item1, panel)); Button queryChildButton = new Button(0, 0, 100, 100, false, "Go To Base", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); panel2.Children.Add(queryChildButton); _player1ParentList.Add(queryChildButton, new Tuple<StackPanel, StackPanel>(panel2, null)); _player1ParentList[_inSelectModeButton].Item1.Children.Insert(index, panel); _player1ParentList.Remove(_inSelectModeButton); } else { if (index == -1) { index = _player1ParentList[_inSelectModeButton].Item1.Children.IndexOf(_player1ParentList[_inSelectModeButton].Item2); _player1ParentList[_inSelectModeButton].Item1.Children.Remove(_player1ParentList[_inSelectModeButton].Item2); } else { _player1ParentList[_inSelectModeButton].Item1.Children.Remove(_inSelectModeButton); } Button button = new Button(0, 0, 100, 100, false, _selectOptions[_editSelect.SelectedIndex], new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _player1ParentList[_inSelectModeButton].Item1.Children.Insert(index, button); _player1ParentList.Add(button, _player1ParentList[_inSelectModeButton]); _player1ParentList.Remove(_inSelectModeButton); } _inSelectMode = false; _editSelect.Reset(); } } else { _player1TreeRoot[_minionEditing].Update(lastFrameTime); for (int i = 0; i < _player1ParentList.Keys.Count; ++i) { Button button = _player1ParentList.Keys.ElementAt(i); if (button.Pressed) { _inSelectMode = true; _inSelectModeButton = button; } } } if (((Button)_player1TreeRoot[_minionEditing].Children[_player1TreeRoot[_minionEditing].Children.Count - 1]).Pressed) { _state = UserInterfaceState.Player1MinionSelect; Camera.X = 0; Camera.Y = 0; } break; case UserInterfaceState.Player1MinionSelect: _player1Go.Update(lastFrameTime); _makeSpecialMinion.Update(lastFrameTime); _editTree.Update(lastFrameTime); _mapScroll.Update(lastFrameTime); _minion1.Update(lastFrameTime); _minion2.Update(lastFrameTime); _minion3.Update(lastFrameTime); if (Game.Player1.Minions[_minionEditing].IsSpecial) { _makeSpecialMinionSelected.Update(lastFrameTime); } else { _makeSpecialMinion.Update(lastFrameTime); } if (_makeSpecialMinion.Pressed) { foreach (var minion in Game.Player1.Minions) { minion.Value.IsSpecial = false; } Game.Player1.Minions[_minionEditing].IsSpecial = true; } if (_player1Go.Pressed) { _state = UserInterfaceState.Player2MinionSelect; _minionEditing = 1; } if (_makeSpecialMinion.Pressed) { // Make current minion special } if (_editTree.Pressed) { _state = UserInterfaceState.Player1EditMinionTree; } if (_minion1.Pressed) { _minionEditing = 1; } else if (_minion2.Pressed) { _minionEditing = 2; } else if (_minion3.Pressed) { _minionEditing = 3; } break; case UserInterfaceState.Player2EditMinionTree: if (_inSelectMode) { _editSelect.Update(lastFrameTime); if (_editSelect.Canceled) { _inSelectMode = false; _editSelect.Reset(); } else if (_editSelect.SelectedIndex != -1) { int index = _player2ParentList[_inSelectModeButton].Item1.Children.IndexOf(_inSelectModeButton); bool query = _selectOptions[_editSelect.SelectedIndex].StartsWith("Is"); if (query) { if (index == -1) { index = _player2ParentList[_inSelectModeButton].Item1.Children.IndexOf(_player2ParentList[_inSelectModeButton].Item2); _player2ParentList[_inSelectModeButton].Item1.Children.Remove(_player2ParentList[_inSelectModeButton].Item2); } else { _player2ParentList[_inSelectModeButton].Item1.Children.Remove(_inSelectModeButton); } StackPanel panel = new StackPanel(0, 0, false, false); StackPanel panel2 = new StackPanel(0, 0, false, true); panel.Children.Add(panel2); Button button = new Button(0, 0, 100, 100, false, "Go To Base", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); panel.Children.Add(button); _player2ParentList.Add(button, new Tuple<StackPanel, StackPanel>(panel, null)); Button queryButton = new Button(0, 0, 100, 100, false, _selectOptions[_editSelect.SelectedIndex], new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); panel2.Children.Add(queryButton); _player2ParentList.Add(queryButton, new Tuple<StackPanel, StackPanel>(_player2ParentList[_inSelectModeButton].Item1, panel)); Button queryChildButton = new Button(0, 0, 100, 100, false, "Go To Base", new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); panel2.Children.Add(queryChildButton); _player2ParentList.Add(queryChildButton, new Tuple<StackPanel, StackPanel>(panel2, null)); _player2ParentList[_inSelectModeButton].Item1.Children.Insert(index, panel); _player2ParentList.Remove(_inSelectModeButton); } else { if (index == -1) { index = _player2ParentList[_inSelectModeButton].Item1.Children.IndexOf(_player2ParentList[_inSelectModeButton].Item2); _player2ParentList[_inSelectModeButton].Item1.Children.Remove(_player2ParentList[_inSelectModeButton].Item2); } else { _player2ParentList[_inSelectModeButton].Item1.Children.Remove(_inSelectModeButton); } Button button = new Button(0, 0, 100, 100, false, _selectOptions[_editSelect.SelectedIndex], new Sprite(new List<string>() { "Images/blueButton.png" }, 0)); _player2ParentList[_inSelectModeButton].Item1.Children.Insert(index, button); _player2ParentList.Add(button, _player2ParentList[_inSelectModeButton]); _player2ParentList.Remove(_inSelectModeButton); } _inSelectMode = false; _editSelect.Reset(); } } else { _player2TreeRoot[_minionEditing].Update(lastFrameTime); for (int i = 0; i < _player2ParentList.Keys.Count; ++i) { Button button = _player2ParentList.Keys.ElementAt(i); if (button.Pressed) { _inSelectMode = true; _inSelectModeButton = button; } } } if (((Button)_player2TreeRoot[_minionEditing].Children[_player2TreeRoot[_minionEditing].Children.Count - 1]).Pressed) { _state = UserInterfaceState.Player2MinionSelect; Camera.X = 0; Camera.Y = 0; } break; case UserInterfaceState.Player2MinionSelect: _player2Go.Update(lastFrameTime); _makeSpecialMinion.Update(lastFrameTime); _editTree.Update(lastFrameTime); _mapScroll.Update(lastFrameTime); _minion1.Update(lastFrameTime); _minion2.Update(lastFrameTime); _minion3.Update(lastFrameTime); if (Game.Player2.Minions[_minionEditing].IsSpecial) { _makeSpecialMinionSelected.Update(lastFrameTime); } else { _makeSpecialMinion.Update(lastFrameTime); } if (_makeSpecialMinion.Pressed) { foreach (var minion in Game.Player2.Minions) { minion.Value.IsSpecial = false; } Game.Player2.Minions[_minionEditing].IsSpecial = true; } if (_player2Go.Pressed) { _state = UserInterfaceState.Running; CreateDecisionTrees(); Sound.Combat.PlayLooping(); } if (_makeSpecialMinion.Pressed) { // Make current minion special } if (_editTree.Pressed) { _state = UserInterfaceState.Player2EditMinionTree; } if (_minion1.Pressed) { _minionEditing = 1; } else if (_minion2.Pressed) { _minionEditing = 2; } else if (_minion3.Pressed) { _minionEditing = 3; } break; case UserInterfaceState.Running: _mapScroll.Update(lastFrameTime); Game.Player1.Update(lastFrameTime); Game.Player2.Update(lastFrameTime); Game.DeathClouds.Update(lastFrameTime); Game.DeathClouds.Flush(); // Check for collisions List<int> player1MinionsToRemove = new List<int>(); List<int> player2MinionsToRemove = new List<int>(); foreach (var player1Minion in Game.Player1.Minions) { foreach (var player2Minion in Game.Player2.Minions) { if (player1Minion.Value.IsCollidingWith(player2Minion.Value)) { player1MinionsToRemove.Add(player1Minion.Key); player2MinionsToRemove.Add(player2Minion.Key); Game.DeathClouds.Add(new DeathCloud(DoublePoint.GetAverage( player1Minion.Value.Pos, player2Minion.Value.Pos))); } } } foreach (var player1Minion in Game.Player1.Minions) { if (player1Minion.Value.IsCollidingWith(Game.Player2.Base) && player1Minion.Value.IsSpecial) { //TODO: win state _state = UserInterfaceState.Player1Wins; Sound.Victory.Play(); } } foreach (var player2Minion in Game.Player2.Minions) { if (player2Minion.Value.IsCollidingWith(Game.Player1.Base) && player2Minion.Value.IsSpecial) { _state = UserInterfaceState.Player2Wins; Sound.Victory.Play(); } } bool player1SpecialAlive = Game.Player1.Minions.Where(e => e.Value.IsSpecial).Count() > 0; bool player2SpecialAlive = Game.Player2.Minions.Where(e => e.Value.IsSpecial).Count() > 0; if (!player1SpecialAlive && !player2SpecialAlive) { _state = UserInterfaceState.Draw; Sound.Death.Play(); } else if (!player1SpecialAlive) { _state = UserInterfaceState.Player2Wins; Sound.Victory.Play(); } else if (!player2SpecialAlive) { _state = UserInterfaceState.Player1Wins; Sound.Victory.Play(); } player1MinionsToRemove.ForEach(f => Game.Player1.Minions.Remove(f)); player2MinionsToRemove.ForEach(f => Game.Player2.Minions.Remove(f)); break; case UserInterfaceState.Player1Wins: case UserInterfaceState.Player2Wins: case UserInterfaceState.Draw: Camera.X = 0; Camera.Y = 0; if (Game.MouseState.LeftButton == OpenTK.Input.ButtonState.Pressed && Game.PreviousMouseState.LeftButton == OpenTK.Input.ButtonState.Released) { _state = UserInterfaceState.Player1MinionSelect; Reset(); } break; } }