private MouseScreenObjectState(MouseScreenObjectState clonedCopy)
 {
     ScreenObject         = clonedCopy.ScreenObject;
     Mouse                = clonedCopy.Mouse.Clone();
     Cell                 = clonedCopy.Cell;
     SurfaceCellPosition  = clonedCopy.SurfaceCellPosition;
     CellPosition         = clonedCopy.CellPosition;
     WorldCellPosition    = clonedCopy.WorldCellPosition;
     SurfacePixelPosition = clonedCopy.SurfacePixelPosition;
     IsOnScreenObject     = clonedCopy.IsOnScreenObject;
 }
        public override bool ProcessMouse(SadConsole.Input.MouseScreenObjectState info)
        {
            var worldLocation   = info.Mouse.ScreenPosition.PixelLocationToSurface(FontSize.X, FontSize.Y);
            var consoleLocation = new Point(worldLocation.X - Position.X, worldLocation.Y - Position.Y);

            // Check if mouse is within the upper/lower bounds of the console
            if (Surface.View.Contains(info.SurfaceCellPosition))
            {
                bool isHexRow = info.SurfaceCellPosition.Y % 2 == 1;

                var newMouse = info.Mouse.Clone();

                // Check if mouse is on an alternating row
                if (isHexRow)
                {
                    newMouse.ScreenPosition = (newMouse.ScreenPosition.X - FontSize.X / 2, newMouse.ScreenPosition.Y);
                }

                var newInfo = new MouseScreenObjectState(this, newMouse);

                if (info.ScreenObject == this)
                {
                    FillHexes(lastCell, 176, lastCellHexRow);
                    lastCell       = info.SurfaceCellPosition.ToIndex(Surface.Width);
                    lastCellHexRow = isHexRow;
                    FillHexes(lastCell, 45, isHexRow);
                    IsDirty = true;
                    return(true);
                }
            }

            //base.ProcessMouse(info);

            FillHexes(lastCell, 176, lastCellHexRow);

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Builds information about the mouse state based on the <see cref="GameHost.FocusedScreenObjects"/> or <see cref="GameHost.Screen"/>. Should be called each frame.
        /// </summary>
        public virtual void Process()
        {
            // Check if last mouse was marked exclusive
            if (_lastMouseScreenObject != null && _lastMouseScreenObject.IsExclusiveMouse)
            {
                var state = new MouseScreenObjectState(_lastMouseScreenObject, this);

                _lastMouseScreenObject.ProcessMouse(state);
            }

            // Check if the focused input screen object wants exclusive mouse
            else if (GameHost.Instance.FocusedScreenObjects.ScreenObject != null && GameHost.Instance.FocusedScreenObjects.ScreenObject.IsExclusiveMouse)
            {
                var state = new MouseScreenObjectState(GameHost.Instance.FocusedScreenObjects.ScreenObject, this);

                // if the last screen object to have the mouse is not our global, signal
                if (_lastMouseScreenObject != null && _lastMouseScreenObject != GameHost.Instance.FocusedScreenObjects.ScreenObject)
                {
                    _lastMouseScreenObject.LostMouse(state);
                    _lastMouseScreenObject = null;
                }

                GameHost.Instance.FocusedScreenObjects.ScreenObject.ProcessMouse(state);

                _lastMouseScreenObject = GameHost.Instance.FocusedScreenObjects.ScreenObject;
            }

            // Scan through each "screen object" in the current screen, including children.
            else if (GameHost.Instance.Screen != null)
            {
                bool foundMouseTarget = false;

                // Build a list of all screen objects
                var screenObjects = new List <IScreenObject>();
                GetConsoles(GameHost.Instance.Screen, ref screenObjects);

                // Process top-most screen objects first.
                screenObjects.Reverse();

                for (int i = 0; i < screenObjects.Count; i++)
                {
                    var state = new MouseScreenObjectState(screenObjects[i], this);

                    if (screenObjects[i].ProcessMouse(state))
                    {
                        if (_lastMouseScreenObject != null && _lastMouseScreenObject != screenObjects[i])
                        {
                            _lastMouseScreenObject.LostMouse(state);
                        }

                        foundMouseTarget       = true;
                        _lastMouseScreenObject = screenObjects[i];
                        break;
                    }
                }

                if (!foundMouseTarget)
                {
                    _lastMouseScreenObject?.LostMouse(new MouseScreenObjectState(null, this));
                }
            }
        }
 public override bool ProcessMouse(SadConsole.Input.MouseScreenObjectState state) => base.ProcessMouse(state);