Exemple #1
0
    public void UpdateSell(List <string> sellableSpells)
    {
        foreach (VendorButton ib in sellButtons)
        {
            RemoveUIObj(ib);
        }
        foreach (ImageButton ib in swapButtons)
        {
            RemoveUIObj(ib);
        }
        sellButtons = new VendorButton[sellableSpells.Count];
        bool buyPossible = pawn.GetSpells().Length < pawn.SpellSlotCount.GetValue();

        for (int i = 0; i < buyButtons.Length; i++)
        {
            buyButtons[i].blocked = !buyPossible || pawn.DoesKnowSpell(buyButtons[i].spell);
        }
        int height = 28 * sellableSpells.Count + (4 * (sellableSpells.Count - 1));
        int yStart = size.height / 2 - height / 2;

        for (int i = 0; i < sellButtons.Length; i++)
        {
            sellButtons[i] = new VendorButton(Spells.Get(sellableSpells[i]), new Vector2i(3 * (size.width / 4), yStart + i * 32));
            AddUIObj(sellButtons[i]);
            int x = i;
            if (i > 0)
            {
                ImageButton up = new ImageButton(new Vector2i(3 * (size.width / 4) + 50, yStart + 7 + i * 32), RB.PackedSpriteGet("ButtonUp", Game.SPRITEPACK_BATTLE));
                swapButtons.Add(up);
                AddUIObj(up);
                up.SetOnClick(() => {
                    Game.client.Send(GameMsg.SwapSpells, new GameMsg.MsgIntegerArray(x - 1, x));
                    Spell temp = sellButtons[x - 1].spell;
                    sellButtons[x - 1].spell = sellButtons[x].spell;
                    sellButtons[x].spell     = temp;
                });
            }
            if (i < sellButtons.Length - 1)
            {
                ImageButton down = new ImageButton(new Vector2i(3 * (size.width / 4) + 50, yStart + 19 + i * 32), RB.PackedSpriteGet("ButtonDown", Game.SPRITEPACK_BATTLE));
                swapButtons.Add(down);
                AddUIObj(down);
                down.SetOnClick(() => {
                    Game.client.Send(GameMsg.SwapSpells, new GameMsg.MsgIntegerArray(x, x + 1));
                    Spell temp               = sellButtons[x].spell;
                    sellButtons[x].spell     = sellButtons[x + 1].spell;
                    sellButtons[x + 1].spell = temp;
                });
            }
        }
        sellHeader.SetPosition(new Vector2i(3 * size.width / 4, yStart - 10));
    }
Exemple #2
0
    public void UpdateBuy(List <string> buyableSpells)
    {
        foreach (VendorButton ib in buyButtons)
        {
            RemoveUIObj(ib);
        }
        buyButtons = new VendorButton[buyableSpells.Count];
        bool buyPossible = pawn.GetSpells().Length < pawn.SpellSlotCount.GetValue();
        int  height      = 28 * buyableSpells.Count + (4 * (buyableSpells.Count - 1));
        int  yStart      = size.height / 2 - height / 2;

        for (int i = 0; i < buyButtons.Length; i++)
        {
            string spellId = buyableSpells[i];
            buyButtons[i] = new VendorButton(Spells.Get(spellId), new Vector2i(size.width / 4, yStart + i * 32), true, !buyPossible || pawn.DoesKnowSpell(spellId));
            AddUIObj(buyButtons[i]);
        }
        buyHeader.SetPosition(new Vector2i(size.width / 4, yStart - 10));
    }