Esempio n. 1
0
        public void SetRegion(UIGridCell.CellState state, int x1, int y1, int x2, int y2)
        {
            int x1f = Utils.Clamp(0, this.width - 1, x1);
            int x2f = Utils.Clamp(0, this.width - 1, x2);
            int y1f = Utils.Clamp(0, this.height - 1, y1);
            int y2f = Utils.Clamp(0, this.height - 1, y2);

            for (int h = y1f; h <= y2f; h++)
            {
                for (int w = x1f; w <= x2f; w++)
                {
                    grid[h, w].cellState = state;
                }
            }
        }
Esempio n. 2
0
        public void SetRegion(UIGridCell.CellState state, int centerX, int centerY, int radius)
        {
            int nx1 = Utils.Clamp(0, this.width - 1, centerX - radius + 1);
            int nx2 = Utils.Clamp(0, this.width - 1, centerX + radius - 1);
            int ny1 = Utils.Clamp(0, this.height - 1, centerY - radius + 1);
            int ny2 = Utils.Clamp(0, this.height - 1, centerY + radius - 1);

            for (int h = ny1; h <= ny2; h++)
            {
                for (int w = nx1; w <= nx2; w++)
                {
                    this.grid[h, w].cellState = state;
                }
            }
        }
Esempio n. 3
0
 //When the mouse exits a cell
 public void CellLeave(UIGridCell.CellState state, int xInd, int yInd)
 {
     //Reset cell states surrounding the left cell
     if (this.activeAbility.healAbility)
     {
         this.UIGrid.SetRegion(UIGridCell.CellState.Inactive, xInd, yInd, this.healRadius);
     }
     else if (this.activeAbility.attackAbility)
     {
         this.UIGrid.SetRegion(UIGridCell.CellState.Inactive, xInd, yInd, this.attackRadius);
     }
     else if (this.activeAbility.teleportAbility)
     {
         this.UIGrid.SetRegion(UIGridCell.CellState.Inactive, xInd, yInd, this.teleportRadius);
     }
 }
Esempio n. 4
0
        //When the mouse enters a cell
        public void CellEnter(UIGridCell.CellState state, int xInd, int yInd)
        {
            //Set the mouse hover.  Contain it to the attack range
            int range = this.activeAbility.Range;

            if (this.activeAbility.healAbility)
            {
                this.healHoverX = Utils.Clamp(this.activeUnit.sprite.xInd - range + 1, this.activeUnit.sprite.xInd + range - 1, xInd);
                this.healHoverY = Utils.Clamp(this.activeUnit.sprite.yInd - range + 1, this.activeUnit.sprite.yInd + range - 1, yInd);
                //Else, this is an attack ability
            }
            else if (this.activeAbility.attackAbility)
            {
                this.attackHoverX = Utils.Clamp(this.activeUnit.sprite.xInd - range + 1, this.activeUnit.sprite.xInd + range - 1, xInd);
                this.attackHoverY = Utils.Clamp(this.activeUnit.sprite.yInd - range + 1, this.activeUnit.sprite.yInd + range - 1, yInd);
            }
            else if (this.activeAbility.teleportAbility)
            {
                this.teleportHoverX = Utils.Clamp(this.activeUnit.sprite.xInd - range + 1, this.activeUnit.sprite.xInd + range - 1, xInd);
                this.teleportHoverY = Utils.Clamp(this.activeUnit.sprite.yInd - range + 1, this.activeUnit.sprite.yInd + range - 1, yInd);
            }
        }
Esempio n. 5
0
 public void Set(UIGridCell.CellState state, int xInd, int yInd)
 {
     grid[yInd, xInd].cellState = state;
 }
Esempio n. 6
0
 //Handle individual cells being exited with the mouse
 public void CellExit(UIGridCell.CellState state, int x, int y)
 {
     UnitManager.Manager.CellLeave(state, x, y);
 }
Esempio n. 7
0
 //Handle individual cells being entered with the mouse
 public void CellEnter(UIGridCell.CellState state, int x, int y)
 {
     UnitManager.Manager.CellEnter(state, x, y);
 }
Esempio n. 8
0
 //Handle an individual cell being clicked
 public void CellClick(UIGridCell.CellState state, int x, int y)
 {
     //Pass different parameters depending on the state of the cell clicked
     UnitManager.Manager.CellClick(state, x, y);
 }
Esempio n. 9
0
        //A cell was clicked at this index, process that data and set relevant loop variables
        //The first variable shows what state the cell was in when it was clicked
        public void CellClick(UIGridCell.CellState state, int xInd, int yInd)
        {
            switch (state)
            {
            //If the clicked grid cell was Inactive
            case UIGridCell.CellState.Possible:
                //If active unit isn't null
                if (activeUnit != null)
                {
                    //If the target location is not the currently active unit, and it contains a unit
                    if ((xInd != this.activeUnit.sprite.xInd || yInd != this.activeUnit.sprite.yInd) && this.dataGrid.Get(xInd, yInd) != null)
                    {
                        //Remove the fixed qualifiaction from the current unit's cell
                        this.UIGrid.grid[this.activeUnit.sprite.yInd, this.activeUnit.sprite.xInd].fixedState = false;

                        //Check if the unit can be selected

                        if (!this.UIGrid.dataGrid.Get(xInd, yInd).ContainsBuffType(BuffType.IsUnselectable))
                        {
                            //If it can be, set the new active unit
                            this.activeUnit = this.UIGrid.dataGrid.Get(xInd, yInd);
                        }
                        else
                        {
                            this.activeUnit = null;
                        }
                        //Clear the UIGrid of all active states
                        this.UIGrid.Clear();
                        //Set attacking to false
                        this.attacking = false;
                        //Set displayingMovement to false
                        this.displayingMovement = false;
                        //Set moveTargetSelected to false
                        this.moveTargetSelected = false;
                    }
                }
                //If the target location contains no units
                if (this.dataGrid.Get(xInd, yInd) == null)
                {
                    //Remove the fixed qualification from the current unit's cell
                    if (this.activeUnit != null)
                    {
                        this.UIGrid.grid[this.activeUnit.sprite.yInd, this.activeUnit.sprite.xInd].fixedState = false;
                    }
                    //Set activeUnit to null
                    this.activeUnit = null;
                    //Clear the grid
                    this.UIGrid.Clear();
                    //Reset state variables
                    this.attacking          = false;
                    this.displayingMovement = false;
                    this.moveTargetSelected = false;
                    //If the target location contains a unit
                }
                else
                {
                    //Set the new active unit


                    if (!this.UIGrid.dataGrid.Get(xInd, yInd).ContainsBuffType(BuffType.IsUnselectable))
                    {
                        this.activeUnit = this.dataGrid.Get(xInd, yInd);
                    }
                }
                break;

            //If the clicked grid cell was MoveActive
            case UIGridCell.CellState.MoveActive:
                //If the target movement location has not yet been selected, set the clicked cell to active
                if (this.moveTargetSelected == false)
                {
                    this.moveTargetSelected = true;
                    this.moveTargetX        = xInd;
                    this.moveTargetY        = yInd;

                    //Else, moveTargetSelected is true.  Make sure the clicked location is the same cell.  If it is not, move the target cell
                }
                else if (xInd != this.moveTargetX || yInd != this.moveTargetY)
                {
                    this.UIGrid.grid[this.moveTargetY, this.moveTargetX].cellState  = UIGridCell.CellState.MovePossible;
                    this.UIGrid.grid[this.moveTargetY, this.moveTargetX].fixedState = false;
                    this.moveTargetSelected = true;
                    this.moveTargetX        = xInd;
                    this.moveTargetY        = yInd;

                    //Else, this is the second click on the target cell.  Set readyMove to true
                }
                else
                {
                    this.readyMove = true;
                }
                break;

            //If the clicked grid cell was AttackActive
            case UIGridCell.CellState.AttackActive:
                this.attack = true;
                break;

            //If the clicked grid cell was HealActive
            case UIGridCell.CellState.HealActive:
                this.heal = true;
                break;

            //If the clicked grid cell was TeleportActive
            case UIGridCell.CellState.TeleportActive:
                if (this.teleportTargetSelected == false)
                {
                    this.teleportTargetX = xInd;
                    this.teleportTargetY = yInd;

                    this.teleportTargetSelected = true;

                    //Make sure the second location is not the same cell
                }
                else if (xInd != this.teleportTargetX || yInd != this.teleportTargetY)
                {
                    this.teleport = true;
                }
                break;
            }
        }