Exemplo n.º 1
0
        /// <summary>
        /// When a different building gains focus close edit and delete buttons
        /// </summary>
        /// <param name="other"></param>
        public override void UnClicked(ScreenElement other)
        {
            this.editButton.Enabled   = false;
            this.deleteButton.Enabled = false;

            base.UnClicked(other);
        }
Exemplo n.º 2
0
 /// <summary>
 /// This method will be called if the element previously had focus, but focus has been shifted.
 /// </summary>
 /// <param name="other">The new screen element that has focus</param>
 public virtual void UnClicked(ScreenElement other)
 {
     this.TakeFocus();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Compare by just guid.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(ScreenElement other)
 {
     return other == null ? false : this.guid.Equals(other.guid);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Add a child to a screen element. These two elements will be considered the same for screen focus and collision.
 /// </summary>
 /// <param name="child"></param>
 public void AddChild(ScreenElement child)
 {
     this.children.Add(child);
     child.Parent = this;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Use this utility to tell if a Screen Element is currently within the screen.
 /// This is used to tell if we should draw the element or not during the Draw step.
 /// </summary>
 /// <param name="element">The Screen Element</param>
 /// <returns>True if the element is in the screen</returns>
 public static bool IsOnScreen(ScreenElement element)
 {
     return !(element.Position.x > Camera.Instance.x + Camera.Instance.width ||
              element.Position.x + element.Size.x < Camera.Instance.x ||
              element.Position.y > Camera.Instance.y + Camera.Instance.height ||
              element.Position.y + element.Size.y < Camera.Instance.y);
 }
Exemplo n.º 6
0
        /// <summary>
        /// When a different building gains focus close edit and delete buttons
        /// </summary>
        /// <param name="other"></param>
        public override void UnClicked(ScreenElement other)
        {
            this.editButton.Enabled = false;
            this.deleteButton.Enabled = false;

            base.UnClicked(other);
        }
Exemplo n.º 7
0
        /// <summary>
        /// If something else gets the focus from me...
        /// Then there is nothing left to live for!!!
        /// </summary>
        /// <param name="other"></param>
        public override void UnClicked(ScreenElement other)
        {
            base.UnClicked(other);

            // GameScreen.BeginBuilding(null); // This causes an infinite loop :(
        }
Exemplo n.º 8
0
 /// <summary>
 /// Compare by just guid.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(ScreenElement other)
 {
     return(other == null ? false : this.guid.Equals(other.guid));
 }
Exemplo n.º 9
0
 /// <summary>
 /// This method will be called if the element previously had focus, but focus has been shifted.
 /// </summary>
 /// <param name="other">The new screen element that has focus</param>
 public virtual void UnClicked(ScreenElement other)
 {
     this.TakeFocus();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Add a child to a screen element. These two elements will be considered the same for screen focus and collision.
 /// </summary>
 /// <param name="child"></param>
 public void AddChild(ScreenElement child)
 {
     this.children.Add(child);
     child.Parent = this;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Check and update the state of the mouse.
        /// This will see if we are clicking on UI, elements or moving the camera
        /// </summary>
        private void CheckMouseState()
        {
            var mouseOver = ScreenElementManager.Instance.CheckMouseState(Input.MouseWorldPosition);

            // LEFT MOUSE --------------------------------------------------------------------------
            // Mouse down event
            // Ignore when the game state is constructing
            if (Input.MouseLeftKeyClicked())
            {
                mouseDownPosition.x = lastMouse.x = Input.MouseX;
                mouseDownPosition.y = lastMouse.y = Input.MouseY;
                mouseDownElement = mouseOver;
                mouseDownTime = DateTime.Now;

                if (mouseOver == null)
                {
                    mouseState = MouseState.ClickedNothing;
                }
                else if (mouseOver.Type == ElementType.GUI)
                {
                    mouseState = MouseState.ClickedGUI;
                }
                else
                {
                    mouseState = MouseState.ClickedElement;
                }

                // Stop any rightclicking nonsense that might be going one. Left click is the superior click!
                // UPDATE: since we've moved right-click to the camera moving click... we have removed left click's superiority
                //mouseState2 = MouseState.Clicked;
            }

            // Check if the user is moving the mouse like they want to move the camera
            // Here's my thought process:
            //  If you clicked nothing, then you will turn into a camera movement if you move from the orgin or move the mouse a certain distance from the start
            //  If you clicked down on a GUI element then we will never move the camera. However if you mouse off the original element before you release the mouse then don't fire the clicked event.
            //  For any other mouse down state you want to turn to "camera moving" if the mouse is either clicked too long or you start moving the mouse like you want to move.
            if (mouseState == MouseState.ClickedNothing)
            {
                if (Utilities.Geometry.Dist(lastMouse, mouseDownPosition) > Constants.CLICK_PIXEL_DISTANCE || DateTime.Now.Subtract(mouseDownTime).TotalMilliseconds > Constants.CLICK_MILLISECONDS)
                {
                    mouseState = MouseState.CameraMoving;
                }
            }
            else if (mouseState == MouseState.ClickedGUI)
            {
                if (mouseOver == null || !mouseOver.Equals(mouseDownElement))
                {
                    mouseState = MouseState.Clicked;
                }
            }
            else if (mouseState == MouseState.ClickedElement)
            {
                if (mouseOver == null || !mouseOver.Equals(mouseDownElement) || Utilities.Geometry.Dist(lastMouse, mouseDownPosition) > Constants.CLICK_PIXEL_DISTANCE || DateTime.Now.Subtract(mouseDownTime).TotalMilliseconds > Constants.CLICK_MILLISECONDS)
                {
                    mouseState = MouseState.CameraMoving;
                }
            }

            // On release check if we need to click an element
            if (Input.MouseLeftKeyReleased())
            {
                if (mouseState == MouseState.ClickedElement || mouseState == MouseState.ClickedGUI)
                {
                    ScreenElementManager.Instance.SetNewFocus(mouseOver, LeftOrRight.Left);
                }
                else if (mouseState == MouseState.ClickedNothing)
                {
                    StatusBar.UpdateStatus(string.Empty);
                    ScreenElementManager.Instance.SetNewFocus(null, LeftOrRight.Left);
                }

                mouseState = MouseState.UnClicked;
            }

            // RIGHT MOUSE --------------------------------------------------------------------------
            // Right mouse currenly only will lose focus when you click on nothing and release quickly
            if (Input.MouseRightKeyClicked())
            {
                mouseDownPosition2.x = Input.MouseX;
                mouseDownPosition2.y = Input.MouseY;
                mouseDownElement2 = mouseOver;
                mouseDownTime2 = DateTime.Now;

                if (mouseOver == null)
                {
                    mouseState2 = MouseState.ClickedNothing;
                }
                else if (mouseOver.Type == ElementType.GUI)
                {
                    mouseState2 = MouseState.ClickedGUI;
                }
                else
                {
                    mouseState2 = MouseState.ClickedElement;
                }
            }

            // Update step for the right mouse click
            if (mouseState2 == MouseState.ClickedNothing)
            {
                if (Utilities.Geometry.Dist(lastMouse, mouseDownPosition2) > Constants.CLICK_PIXEL_DISTANCE || DateTime.Now.Subtract(mouseDownTime2).TotalMilliseconds > Constants.CLICK_MILLISECONDS)
                {
                    mouseState2 = MouseState.CameraMoving;
                }
            }
            else if (mouseState2 == MouseState.ClickedGUI)
            {
                if (mouseOver == null || !mouseOver.Equals(mouseDownElement2))
                {
                    mouseState2 = MouseState.Clicked;
                }
            }
            else if (mouseState2 == MouseState.ClickedElement)
            {
                if (mouseOver == null || !mouseOver.Equals(mouseDownElement2) || Utilities.Geometry.Dist(lastMouse, mouseDownPosition2) > Constants.CLICK_PIXEL_DISTANCE || DateTime.Now.Subtract(mouseDownTime2).TotalMilliseconds > Constants.CLICK_MILLISECONDS)
                {
                    mouseState2 = MouseState.CameraMoving;
                }
            }

            // Right click currently can move your focus up a parent level.
            // Also, if the left mouse (mouseState) is clicked at all then ignore the right click.
            // My current mouse philosophy is very anti right-click
            if (Input.MouseRightKeyReleased())
            {
                if (mouseState2 == MouseState.ClickedElement || mouseState2 == MouseState.ClickedGUI)
                {
                    ScreenElementManager.Instance.SetNewFocus(mouseOver, LeftOrRight.Right);
                }
                else if (mouseState2 == MouseState.ClickedNothing &&
                    DateTime.Now.Subtract(mouseDownTime2).TotalMilliseconds <= Constants.CLICK_MILLISECONDS)
                {
                    StatusBar.UpdateStatus(string.Empty);
                    ScreenElementManager.Instance.SetNewFocus(null, LeftOrRight.Right);
                }

                mouseState2 = MouseState.UnClicked;
            }
        }
Exemplo n.º 12
0
 // ///////////////////////////////////////////////
 // CRUD classes
 // ///////////////////////////////////////////////
 /// <summary>
 /// Add a new Screen Element
 /// </summary>
 /// <param name="building"></param>
 public void Add(ScreenElement building)
 {
     this.elements.Add(building.Guid, building);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Remove an element from the sorted lists
 /// </summary>
 /// <param name="building"></param>
 /// <returns></returns>
 public void Remove(ScreenElement building)
 {
     this.elements.Remove(building.Guid);
 }
Exemplo n.º 14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public bool Exists(ScreenElement building)
 {
     return this.elements.ContainsKey(building.Guid);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Remove this building from the game grid
        /// </summary>
        /// <param name="building">The building to remove</param>
        /// <returns></returns>
        public bool DeleteElement(ScreenElement element)
        {
            if (!this.Exists(element))
            {
                Logger.Log(LogLevel.Warning, "Tried to remove non-existant element", string.Format("The campus manager was told to remove element {0} ({1}) from the game grid, but no such element exists.", element, element.Guid));
                return false;
            }

            this.Remove(element);

            // Remove the element from the grid
            var elementIsoPosition = Geometry.ToIsometricGrid(element.Position);

            Building building = element as Building;
            if (building != null)
            {
                // Remove this building from the grid
                for (int y = 0; y < building.Footprint.Length; ++y)
                {
                    for (int x = 0; x < building.Footprint[y].Length; ++x)
                    {
                        if (building.Footprint[y][x])
                        {
                            var indexOffsets = building.FootprintIndexOffsets;
                            int gridX = this.WorldIsoToGridX(elementIsoPosition.x + x - indexOffsets.x);
                            int gridY = this.WorldIsoToGridY(elementIsoPosition.y + y - indexOffsets.y);

                            // Sanity checks before we remove the building
                            if (this.grid[gridY][gridX] != building.Guid)
                            {
                                Logger.Log(LogLevel.Error, "Removing a building from a corrupted grid location", string.Format("The grid location {0},{1} had Guid {2} set instead of {3}.", gridX, gridY, this.grid[gridY][gridX], building.Guid));
                            }

                            this.grid[gridY][gridX] = -1;
                        }
                    }
                }
            }
            else
            {
                // Remove this element from the grid
                int gridX = this.WorldIsoToGridX(elementIsoPosition.x);
                int gridY = this.WorldIsoToGridY(elementIsoPosition.y);

                // Sanity checks before we remove the element
                if (this.grid[gridY][gridX] != element.Guid)
                {
                    Logger.Log(LogLevel.Error, "Removing an element from a corrupted grid location", string.Format("The grid location {0},{1} had Guid {2} set instead of {3}.", gridX, gridY, this.grid[gridY][gridX], element.Guid));
                }

                this.grid[gridY][gridX] = -1;
            }

            return true;
        }