Exemple #1
0
    internal void UpdateGridHighlightedness()
    {
        foreach (GameObject go in highlightRectangles)
        {
            GameObject.Destroy(go);
        }
        highlightRectangles.Clear();
        foreach (S_Tile tile in allTiles)
        {
            tile.SetHighlight(false);
        }
        S_Ability activeAbility = abilityPanel.activeAbility;

        if (activeAbility != null)
        {
            //bunch of long codey bits because it's paperwork to do this sort of thing in unity it seems
            switch (activeAbility.GetTargetingType())
            {
            case S_Ability.TargetingType.Line:
                foreach (S_Tile tile in activeAbility.GetValidTiles(player.currentTile))
                {
                    int baseWidth  = tile.x - player.currentTile.x;
                    int baseHeight = tile.y - player.currentTile.y;
                    int rWidth     = baseWidth == 0 ? 1 : baseWidth;
                    int rHeight    = baseHeight == 0 ? 1 : baseHeight;
                    rWidth  *= S_Tile.height;
                    rHeight *= S_Tile.width;
                    rWidth  += -S_Camera.scale * Util.ProperSign(rWidth);
                    rHeight += -S_Camera.scale * Util.ProperSign(rHeight);
                    GameObject go = Primitives.CreateRectangle(rWidth, rHeight, S_Camera.scale, Colours.LIGHT);
                    Util.SetLayerContainer(go, Util.LayerName.Entities, 5);
                    S_Tile origin = player.currentTile;
                    if (baseWidth > 0)
                    {
                        origin = origin.GetTile(1, 0);
                    }
                    else if (baseHeight > 0)
                    {
                        origin = origin.GetTile(0, 1);
                    }
                    go.transform.position = new Vector2(origin.transform.position.x + (baseWidth < 0 ? -S_Camera.scale : 0), origin.transform.position.y + (baseHeight < 0 ? -S_Camera.scale : 0));
                    highlightRectangles.Add(go);
                    go.transform.SetParent(Game.GetMisc("effects").transform);
                }
                break;

            case S_Ability.TargetingType.SingleTile:
                foreach (S_Tile tile in activeAbility.GetValidTiles(player.currentTile))
                {
                    tile.SetHighlight(true);
                }
                break;
            }
        }
    }
Exemple #2
0
    internal bool DeselectAbility(S_Ability s_Ability, bool sound = true)
    {
        if (activeAbility == null)
        {
            return(true);
        }
        bool same = s_Ability == activeAbility;

        activeAbility.Toggle(s_Ability == activeAbility && sound);
        return(!same);
    }
Exemple #3
0
 internal void ActivateAbility(S_Ability ability, bool active)
 {
     if (active)
     {
         activeAbility = ability;
     }
     else
     {
         activeAbility = null;
     }
     Level.Get(gameObject).UpdateGridHighlightedness();
 }
Exemple #4
0
    public void Setup(int[] headerData)
    {
        List <S_Button> buttons = new List <S_Button>();

        name = "Ability Panel";
        int numAbilities = Util.ProperSign(headerData[0]) + Util.ProperSign(headerData[1]) + Util.ProperSign(headerData[2]);

        //
        for (int i = 0; i < headerData.Length; i++)
        {
            int datum = headerData[i];
            if (datum == 0)
            {
                continue;
            }
            S_Button  buttonScrip = S_Button.CreateButton(Sprites.ability_border);
            S_Ability ability     = null;
            switch (datum & 3)
            {
            case 1: ability = buttonScrip.gameObject.AddComponent <S_Ability_Move3>(); break;

            case 2: ability = buttonScrip.gameObject.AddComponent <S_Ability_Eye>(); break;

            case 3: ability = buttonScrip.gameObject.AddComponent <S_Ability_Swap>(); break;
            }
            abilities.Add(ability);
            ability.init((datum & 28) >> 2);
            buttonScrip.SetDownAction(() => {
                if (Game.IsPaused())
                {
                    return;
                }
                ability.Click();
            });
            GameObject button = buttonScrip.gameObject;
            button.name = "Button";
            Util.SetColour(button, Colours.RED);
            buttons.Add(button.GetComponent <S_Button>());
            S_Camera.SetupScale(buttonScrip.transform);
            GameObject image = Primitives.CreateActor(ability.GetSprite(), 1, 9);
            image.name = "image";
            Util.SetLayer(image, Util.LayerName.Tiles, 0);
            image.transform.SetParent(buttonScrip.gameObject.transform, false);
            if (Game.KEYBOARD)
            {
                GameObject text     = Primitives.CreateText("[" + ability.GetKey() + "]", 0, 0);
                S_Follower follower = text.AddComponent <S_Follower>();
                follower.Follow(button, -20 * S_Camera.scale, (int)((Sprites.GetBounds(Sprites.ability_border).y *S_Camera.scale / 2f - 7 * S_Camera.scale)));
                ability.SetText(text);
            }
            Util.SetZ(button, Util.ZLayer.Gameplay);
        }

        int gap      = 10 * S_Camera.scale;
        int currentY = -gap;

        foreach (S_Button butt in buttons)
        {
            currentY += gap;
            butt.transform.position = new Vector2(0, currentY);
            currentY += (int)(butt.GetBounds().size.y);
        }

        width  = 37 * S_Camera.scale;;
        height = currentY;
        foreach (S_Button butt in buttons)
        {
            butt.transform.SetParent(transform, false);
        }
    }