Beispiel #1
0
        private void CenterNodesBetween(SpellButton leftNode, SpellButton rightNode, int treeDistance, int nodeSize)
        {
            var leftIndex  = leftNode.Parent.Children.IndexOf(rightNode);
            var rightIndex = leftNode.Parent.Children.IndexOf(leftNode);

            var numNodesBetween = (rightIndex - leftIndex) - 1;

            if (numNodesBetween > 0)
            {
                var distanceBetweenNodes = (leftNode.X - rightNode.X) / (numNodesBetween + 1);

                int count = 1;
                for (int i = leftIndex + 1; i < rightIndex; i++)
                {
                    var middleNode = leftNode.Parent.Children[i];

                    var desiredX = rightNode.X + (distanceBetweenNodes * count);
                    var offset   = desiredX - middleNode.X;
                    middleNode.X   += offset;
                    middleNode.Mod += offset;

                    count++;
                }

                CheckForConflicts(leftNode, treeDistance, nodeSize);
            }
        }
Beispiel #2
0
 public void InitializeSpellButtonRecursive(SpellButton button)
 {
     foreach (SpellTree.Node spell in button.Spell.Children)
     {
         SpellButton newButton = new SpellButton()
         {
             Spell       = spell,
             ImageButton = new Button(GUI, MainPanel, spell.Spell.Name, GUI.SmallFont, Button.ButtonMode.ImageButton, spell.Spell.Image)
             {
                 ToolTip         = spell.Spell.Description,
                 KeepAspectRatio = true,
                 DontMakeSmaller = true,
                 DontMakeBigger  = true
             },
             Level    = button.Level + 1,
             Children = new List <SpellButton>(),
             Parent   = button
         };
         SpellTree.Node rSpell = spell;
         newButton.ImageButton.OnClicked += () => ImageButton_OnClicked(rSpell);
         button.Children.Add(newButton);
         SpellButtons.Add(newButton);
         InitializeSpellButtonRecursive(newButton);
     }
 }
Beispiel #3
0
    public void SetState(OptionState state)
    {
        gameObject.SetActive(true);
        AttackButton.gameObject.SetActive(false);
        SpellButton.gameObject.SetActive(false);
        ItemButton.gameObject.SetActive(false);
        WaitButton.gameObject.SetActive(false);
        foreach (var button in ChoiseButtons)
        {
            Destroy(button.gameObject);
        }
        ChoiseButtons.Clear();

        switch (state)
        {
        case OptionState.None:
            ChoiseButtons.Clear();
            gameObject.SetActive(false);
            break;

        case OptionState.Main:

            AttackButton.gameObject.SetActive(true);
            SpellButton.gameObject.SetActive(true);
            ItemButton.gameObject.SetActive(true);
            WaitButton.gameObject.SetActive(true);
            GLG.cellSize = new Vector2(100, 40);
            if (Fighter.Selected != null &&
                Fighter.Selected.GetComponent <Atributes>().CharClass == CharacterClass.Mage)
            {
                SpellButton.GetComponentInChildren <Text>().text = "Spell";
                SpellButton.onClick.RemoveAllListeners();
                SpellButton.onClick.AddListener(delegate { Magic(); });
            }
            else
            {
                SpellButton.GetComponentInChildren <Text>().text = "Power";
                SpellButton.onClick.AddListener(delegate { Power(); });
            }
            break;

        case OptionState.Attacks:
            GLG.cellSize = new Vector2(40, 40);
            SetAttacks();
            break;

        case OptionState.Powers:
            break;

        case OptionState.Spells:
            break;

        case OptionState.Items:
            break;

        default:
            break;
        }
    }
Beispiel #4
0
 public void BeginTargeting(Spell spell, SpellButton button)
 {
     targetSpell     = spell;
     renderTargeting = true;
     targetPawn      = null;
     originPoint     = targetPoint = new Vector2i(button.pos.x - 2, button.pos.y + button.size.height / 2);
     originButton    = button;
 }
 private void TutorialFinished()
 {
     GrayPanel.gameObject.SetActive(false);
     base.ActivateUIForPlayer();
     OnSpellToggle(true);
     SpellButton.Select();
     DisableDialogInteracuable();
 }
Beispiel #6
0
        private void CalculateInitialX(SpellButton node, int nodeSize, int siblingDistance, int treeDistance)
        {
            foreach (var child in node.Children)
            {
                CalculateInitialX(child, nodeSize, siblingDistance, treeDistance);
            }

            // if no children
            if (node.IsLeaf())
            {
                // if there is a previous sibling in this set, set X to prevous sibling + designated distance
                if (!node.IsLeftMost())
                {
                    node.X = node.GetPreviousSibling().X + nodeSize + siblingDistance;
                }
                else
                {
                    // if this is the first node in a set, set X to 0
                    node.X = 0;
                }
            }
            // if there is only one child
            else if (node.Children.Count == 1)
            {
                // if this is the first node in a set, set it's X value equal to it's child's X value
                if (node.IsLeftMost())
                {
                    node.X = node.Children[0].X;
                }
                else
                {
                    node.X   = node.GetPreviousSibling().X + nodeSize + siblingDistance;
                    node.Mod = node.X - node.Children[0].X;
                }
            }
            else
            {
                var leftChild  = node.GetLeftMostChild();
                var rightChild = node.GetRightMostChild();
                var mid        = (leftChild.X + rightChild.X) / 2;

                if (node.IsLeftMost())
                {
                    node.X = mid;
                }
                else
                {
                    node.X   = node.GetPreviousSibling().X + nodeSize + siblingDistance;
                    node.Mod = node.X - mid;
                }
            }

            if (node.Children.Count > 0 && !node.IsLeftMost())
            {
                // Since subtrees can overlap, check for conflicts and shift tree right if needed
                CheckForConflicts(node, treeDistance, nodeSize);
            }
        }
Beispiel #7
0
    public void SetSpells(Spell[] spells)
    {
        foreach (Spell s in spells)
        {
            GameObject  newSpellBtn = Instantiate(spellCastButtonPrefab, magicListContent.transform);
            SpellButton sb          = newSpellBtn.GetComponent <SpellButton>();

            sb.spell = s;
        }
    }
 private void OnPointerEnterButton(SpellButton obj)
 {
     // Dont set if spell is null and ensure it is closed
     if(obj.Spell == null)
     {
         _container.gameObject.SetActive(false);
         return;
     }
     SetDetails(obj.Spell);
     _container.gameObject.SetActive(true);
 }
Beispiel #9
0
 public void enableSpells()
 {
     foreach (Transform spellButton in spellButtons.transform)
     {
         SpellButton tempButton = spellButton.GetComponent <SpellButton>();
         if (tempButton != null)
         {
             tempButton.turnReady = true;
         }
     }
 }
Beispiel #10
0
        // recusrively initialize x, y, and mod values of nodes
        private void InitializeNodes(SpellButton node, int depth)
        {
            node.X   = -1;
            node.Y   = depth;
            node.Mod = 0;

            foreach (var child in node.Children)
            {
                InitializeNodes(child, depth + 1);
            }
        }
Beispiel #11
0
        public void CalculateNodePositions(SpellButton rootNode, int nodeSize, int siblingDistance, int treeDistance)
        {
            // initialize node x, y, and mod values
            InitializeNodes(rootNode, 0);

            // assign initial X and Mod values for nodes
            CalculateInitialX(rootNode, 1, 1, 1);

            // ensure no node is being drawn off screen
            CheckAllChildrenOnScreen(rootNode);

            // assign final X values to nodes
            CalculateFinalPositions(rootNode, 0);

            UpdateRects(40, 75);
        }
    public void NewSpell(string spell)
    {
        GameObject spellToBeAdded;

        if (newSpellBtns.TryGetValue(spell, out spellToBeAdded))
        {
            Debug.Log("Spell already exists");
        }
        else
        {
            GameObject  splBtnGo = GameObjectUtility.CustomInstantiate(spellButton.gameObject, transform);
            SpellButton splBtn   = splBtnGo.GetComponent <SpellButton>();
            splBtn.Initialize(spell, this);
            newSpellBtns.Add(spell, splBtnGo);
        }
    }
Beispiel #13
0
        private void GetRightContour(SpellButton node, float modSum, ref Dictionary <int, float> values)
        {
            if (!values.ContainsKey(node.Y))
            {
                values.Add(node.Y, node.X + modSum);
            }
            else
            {
                values[node.Y] = Math.Max(values[node.Y], node.X + modSum);
            }

            modSum += node.Mod;
            foreach (var child in node.Children)
            {
                GetRightContour(child, modSum, ref values);
            }
        }
Beispiel #14
0
 private int FillSpellPane(TabbedPane pane, int index, int buttonIndexStart)
 {
     Spell[] knownSpells = battle.allies[index].GetSpells();
     for (int i = 0; i < knownSpells.Length; i++)
     {
         SpellButton sb = new SpellButton(this, battle, knownSpells[i], new Vector2i(size.width - 97, 5 + i * 31), index != Game.peerId);
         if (index == Game.peerId)
         {
             sb.SetKeybind(KeyCode.Alpha1 + i);
         }
         spellButtons[i + buttonIndexStart]         = sb;
         spellButtonOwnership[i + buttonIndexStart] = index;
         AddUIObj(sb);
         pane.AddToTab(index, sb);
     }
     return(buttonIndexStart + knownSpells.Length);
 }
Beispiel #15
0
    public void RpcUpdateButtons()
    {
        if (spellButtons.activeSelf)
        {
            foreach (Transform spellButton in spellButtons.transform)
            {
                SpellButton tempButton = spellButton.GetComponent <SpellButton>();

                if (tempButton != null)
                {
                    if (!tempButton.turnReady && !status.blnHexed)
                    {
                        spellButton.GetComponent <Available>().DecreaseRecharge();
                    }
                }
            }
        }
    }
Beispiel #16
0
        public void InitializeSpellButtons()
        {
            SpellButtons = new List <SpellButton>();

            int         xOffset    = 15;
            int         yOffset    = 32;
            SpellButton fakeButton = new SpellButton()
            {
                Children = new List <SpellButton>()
            };

            foreach (SpellTree.Node spell in Tree.RootSpells)
            {
                SpellButton newButton = new SpellButton()
                {
                    Spell       = spell,
                    ImageButton = new Button(GUI, MainPanel, spell.Spell.Name, GUI.SmallFont, Button.ButtonMode.ImageButton, spell.Spell.Image)
                    {
                        ToolTip         = spell.Spell.Description,
                        KeepAspectRatio = true,
                        DontMakeSmaller = true,
                        DontMakeBigger  = true,
                        LocalBounds     = new Rectangle(xOffset, yOffset, 0, 0),
                    },
                    Children = new List <SpellButton>(),
                    Level    = 0,
                    Parent   = fakeButton
                };
                SpellTree.Node rSpell = spell;
                newButton.ImageButton.OnClicked += () => ImageButton_OnClicked(rSpell);
                SpellButtons.Add(newButton);
                InitializeSpellButtonRecursive(newButton);
                fakeButton.Children.Add(newButton);
            }

            //Rectangle newRect = AlignImagesTree(fakeButton, xOffset, yOffset);
            //xOffset = newRect.Left;
            //yOffset = newRect.Bottom;
            //MainPanel.LocalBounds = new Rectangle(0, 0, Math.Max(MainPanel.LocalBounds.Width, newRect.Width + xOffset), Math.Max(MainPanel.LocalBounds.Height, newRect.Height + yOffset));
            CalculateNodePositions(fakeButton, 48, 10, 100);
        }
Beispiel #17
0
        private void CalculateFinalPositions(SpellButton node, int modSum)
        {
            node.X += modSum;
            modSum += node.Mod;

            foreach (var child in node.Children)
            {
                CalculateFinalPositions(child, modSum);
            }

            if (node.Children.Count == 0)
            {
                node.Width  = node.X;
                node.Height = node.Y;
            }
            else
            {
                node.Width  = node.Children.OrderByDescending(p => p.Width).First().Width;
                node.Height = node.Children.OrderByDescending(p => p.Height).First().Height;
            }
        }
Beispiel #18
0
        private void CheckAllChildrenOnScreen(SpellButton node)
        {
            var nodeContour = new Dictionary <int, float>();

            GetLeftContour(node, 0, ref nodeContour);

            int shiftAmount = 0;

            foreach (var y in nodeContour.Keys)
            {
                if (nodeContour[y] + shiftAmount < 0)
                {
                    shiftAmount = (int)(nodeContour[y] * -1);
                }
            }

            if (shiftAmount > 0)
            {
                node.X   += shiftAmount;
                node.Mod += shiftAmount;
            }
        }
Beispiel #19
0
    public void InitialiseTargetList()
    {
        foreach (Transform transform in listContainer)
        {
            Destroy(transform.gameObject);
        }

        if (!overworldSpell)
        {
            for (int i = 0; i < CombatManager.instance.currentActor.spellList.Count; i++)
            {
                SpellButton button    = Instantiate(buttonPrefab, listContainer).GetComponent <SpellButton>();
                bool        canAfford = CombatManager.instance.currentActor.currentMP >= CombatManager.instance.currentActor.spellList[i].manaCost;
                button.Initialise(i, commandMenu, CombatManager.instance.currentActor.spellList[i], canAfford);
            }
        }

        else
        {
            for (int i = 0; i < PartyManager.instance.partyMembers.Count; i++)
            {
                SpellButton namePlate = Instantiate(buttonPrefab, listContainer).GetComponent <SpellButton>();
                namePlate.Initialise(PartyManager.instance.partyMembers[i].characterName);

                for (int j = 0; j < PartyManager.instance.partyMembers[i].spellList.Count; j++)
                {
                    if (PartyManager.instance.partyMembers[i].spellList[j].spellType == SpellType.Heal && !PartyManager.instance.partyMembers[i].spellList[j].attackAll)
                    {
                        SpellButton button = Instantiate(buttonPrefab, listContainer).GetComponent <SpellButton>();
                        button.thisCanvas = thisCanvas;
                        bool canAfford = PartyManager.instance.partyMembers[i].currentMP >= PartyManager.instance.partyMembers[i].spellList[j].manaCost;
                        button.Initialise(j, commandMenu, PartyManager.instance.partyMembers[i].spellList[j], canAfford);
                        button.SetOverworldSpell(targetingMenu, targetingCanvas, PartyManager.instance.partyMembers[i]);
                    }
                }
            }
        }
    }
Beispiel #20
0
        private void CheckForConflicts(SpellButton node, int treeDistance, int nodeSize)
        {
            var minDistance = treeDistance + nodeSize;
            var shiftValue  = 0F;

            var nodeContour = new Dictionary <int, float>();

            GetLeftContour(node, 0, ref nodeContour);

            var sibling = node.GetLeftMostSibling();

            while (sibling != null && sibling != node)
            {
                var siblingContour = new Dictionary <int, float>();
                GetRightContour(sibling, 0, ref siblingContour);

                for (int level = node.Y + 1; level <= Math.Min(siblingContour.Keys.Max(), nodeContour.Keys.Max()); level++)
                {
                    var distance = nodeContour[level] - siblingContour[level];
                    if (distance + shiftValue < minDistance)
                    {
                        shiftValue = minDistance - distance;
                    }
                }

                if (shiftValue > 0)
                {
                    node.X   += (int)shiftValue;
                    node.Mod += (int)shiftValue;

                    CenterNodesBetween(node, sibling, treeDistance, nodeSize);

                    shiftValue = 0;
                }

                sibling = sibling.GetNextSibling();
            }
        }
    public void Initialize(List <string> spells, Hero user)
    {
        this.user    = user;
        newSpellBtns = new Dictionary <string, GameObject>();
        foreach (string spell in spells)
        {
            GameObject  splBtnGo = GameObjectUtility.CustomInstantiate(spellButton.gameObject, transform);
            SpellButton splBtn   = splBtnGo.GetComponent <SpellButton>();
            splBtn.Initialize(spell, this);
        }

        displayPanelGameObject = GameObject.Find("DisplayPanel");
        displayPanel           = displayPanelGameObject.GetComponent <DisplayPanel>();

        GameObject BackBtnGO = GameObjectUtility.CustomInstantiate(BackSpaceBtn.gameObject, transform);

        BackBtnGO.GetComponent <Button>().onClick.RemoveAllListeners();
        BackBtnGO.GetComponent <Button>().onClick.AddListener(() => { BackSpace(); });
        GameObject ClearBtnGO = GameObjectUtility.CustomInstantiate(ClearAllBtn.gameObject, transform);

        ClearBtnGO.GetComponent <Button>().onClick.RemoveAllListeners();
        ClearBtnGO.GetComponent <Button>().onClick.AddListener(() => { ClearAll(); });
    }
Beispiel #22
0
    private void Start()
    {
        status               = new statusEffect();
        status.blnCursed     = false;
        status.blnHexed      = false;
        status.accuracy      = 100;
        status.hexDuration   = -1;
        status.curseDuration = -1;

        GameObject.FindGameObjectWithTag("Goal1").GetComponent <GoalArea>().GameScore = GameScore;
        GameObject.FindGameObjectWithTag("Goal2").GetComponent <GoalArea>().GameScore = GameScore;

        gameMaster = GameObject.Find("GameMaster").GetComponent <GameMaster>();

        if (isLocalPlayer == true)
        {
            GameObject tempViewChange = Instantiate(Resources.Load("ViewChanger") as GameObject);

            tempViewChange.GetComponent <ViewChanger>().SetView(playerID);

            int spellCount = 0;

            foreach (Transform item in spellButtons.transform)
            {
                SpellButton tempSpellButton = item.GetComponent <SpellButton>();

                if (tempSpellButton != null)
                {
                    tempSpellButton.player     = gameObject;
                    tempSpellButton.gameMaster = gameMaster;

                    switch (spellCount)
                    {
                    case 0:
                        tempSpellButton.spell = GetComponent <ProjectileSpell>();
                        break;

                    case 1:
                        tempSpellButton.spell = GetComponent <WallSpell>();
                        break;

                    case 2:
                        tempSpellButton.spell = GetComponent <TornadoSpell>();
                        break;

                    case 3:
                        tempSpellButton.spell = GetComponent <HexSpell>();
                        break;

                    case 4:
                        tempSpellButton.spell = GetComponent <CurseSpell>();
                        break;

                    case 5:
                        tempSpellButton.spell = GetComponent <MonsterSpell>();
                        break;

                    default:
                        break;
                    }

                    spellCount += 1;
                }
            }

            playerCamera.SetActive(true);
        }
        else
        {
            playerCamera.SetActive(false);
        }
    }
Beispiel #23
0
        public void CalculateNodePositions(SpellButton rootNode, int nodeSize, int siblingDistance, int treeDistance)
        {
            // initialize node x, y, and mod values
            InitializeNodes(rootNode, 0);

            // assign initial X and Mod values for nodes
            CalculateInitialX(rootNode, 1, 1, 1);

            // ensure no node is being drawn off screen
            CheckAllChildrenOnScreen(rootNode);

            // assign final X values to nodes
            CalculateFinalPositions(rootNode, 0);

            UpdateRects(40, 75);
        }
Beispiel #24
0
        private void CalculateInitialX(SpellButton node, int nodeSize, int siblingDistance, int treeDistance)
        {
            foreach (var child in node.Children)
                CalculateInitialX(child, nodeSize, siblingDistance, treeDistance);

            // if no children
            if (node.IsLeaf())
            {
                // if there is a previous sibling in this set, set X to prevous sibling + designated distance
                if (!node.IsLeftMost())
                    node.X = node.GetPreviousSibling().X + nodeSize + siblingDistance;
                else
                    // if this is the first node in a set, set X to 0
                    node.X = 0;
            }
            // if there is only one child
            else if (node.Children.Count == 1)
            {
                // if this is the first node in a set, set it's X value equal to it's child's X value
                if (node.IsLeftMost())
                {
                    node.X = node.Children[0].X;
                }
                else
                {
                    node.X = node.GetPreviousSibling().X + nodeSize + siblingDistance;
                    node.Mod = node.X - node.Children[0].X;
                }
            }
            else
            {
                var leftChild = node.GetLeftMostChild();
                var rightChild = node.GetRightMostChild();
                var mid = (leftChild.X + rightChild.X) / 2;

                if (node.IsLeftMost())
                {
                    node.X = mid;
                }
                else
                {
                    node.X = node.GetPreviousSibling().X + nodeSize + siblingDistance;
                    node.Mod = node.X - mid;
                }
            }

            if (node.Children.Count > 0 && !node.IsLeftMost())
            {
                // Since subtrees can overlap, check for conflicts and shift tree right if needed
                CheckForConflicts(node, treeDistance, nodeSize);
            }
        }
Beispiel #25
0
        private void CalculateFinalPositions(SpellButton node, int modSum)
        {
            node.X += modSum;
            modSum += node.Mod;

            foreach (var child in node.Children)
                CalculateFinalPositions(child, modSum);

            if (node.Children.Count == 0)
            {
                node.Width = node.X;
                node.Height = node.Y;
            }
            else
            {
                node.Width = node.Children.OrderByDescending(p => p.Width).First().Width;
                node.Height = node.Children.OrderByDescending(p => p.Height).First().Height;
            }
        }
 private void OnPointerExitButton(SpellButton obj)
 {
     _container.gameObject.SetActive(false);
 }
Beispiel #27
0
        private void CenterNodesBetween(SpellButton leftNode, SpellButton rightNode, int treeDistance, int nodeSize)
        {
            var leftIndex = leftNode.Parent.Children.IndexOf(rightNode);
            var rightIndex = leftNode.Parent.Children.IndexOf(leftNode);

            var numNodesBetween = (rightIndex - leftIndex) - 1;

            if (numNodesBetween > 0)
            {
                var distanceBetweenNodes = (leftNode.X - rightNode.X) / (numNodesBetween + 1);

                int count = 1;
                for (int i = leftIndex + 1; i < rightIndex; i++)
                {
                    var middleNode = leftNode.Parent.Children[i];

                    var desiredX = rightNode.X + (distanceBetweenNodes * count);
                    var offset = desiredX - middleNode.X;
                    middleNode.X += offset;
                    middleNode.Mod += offset;

                    count++;
                }

                CheckForConflicts(leftNode, treeDistance, nodeSize);
            }
        }
Beispiel #28
0
        private void CheckAllChildrenOnScreen(SpellButton node)
        {
            var nodeContour = new Dictionary<int, float>();
            GetLeftContour(node, 0, ref nodeContour);

            int shiftAmount = 0;
            foreach (var y in nodeContour.Keys)
            {
                if (nodeContour[y] + shiftAmount < 0)
                    shiftAmount = (int)(nodeContour[y] * -1);
            }

            if (shiftAmount > 0)
            {
                node.X += shiftAmount;
                node.Mod += shiftAmount;
            }
        }
Beispiel #29
0
        public Rectangle AlignImagesTree(SpellButton root, int xOffset, int yOffset)
        {
            Dictionary <int, List <SpellButton> > levels = new Dictionary <int, List <SpellButton> >();

            root.CountLevelsRecursive(levels);
            int rowHeight = 80;
            int colWidth  = 120;
            int maxLevel  = 1;

            foreach (var level in levels)
            {
                maxLevel = Math.Max(maxLevel, level.Value.Count);
            }

            int height = maxLevel * rowHeight;
            int width  = colWidth * levels.Count;
            int x      = xOffset;

            foreach (var level in levels)
            {
                int y = yOffset + (maxLevel - level.Value.Count) * rowHeight / 2;
                foreach (SpellButton button in level.Value)
                {
                    if (button.ImageButton != null)
                    {
                        button.ImageButton.LocalBounds = new Rectangle(x, y, button.ImageButton.LocalBounds.Width,
                                                                       button.ImageButton.LocalBounds.Height);
                        y += rowHeight;
                    }
                }
                x += colWidth;
            }

            for (int i = levels.Values.Count - 2; i >= 0; i--)
            {
                List <SpellButton> level = levels.Values.ElementAt(i);
                //List<SpellButton> childless = new List<SpellButton>();
                int maxY = 0;
                foreach (SpellButton button in level)
                {
                    if (button.ImageButton == null)
                    {
                        continue;
                    }
                    int avg = 0;

                    foreach (SpellButton child in button.Children)
                    {
                        avg += child.ImageButton.LocalBounds.Y;
                    }



                    if (avg > 0)
                    {
                        avg /= button.Children.Count;
                        button.ImageButton.LocalBounds = new Rectangle(button.ImageButton.LocalBounds.X, avg, button.ImageButton.LocalBounds.Width, button.ImageButton.LocalBounds.Height);
                        maxY = Math.Max(maxY, avg);
                    }
                    else
                    {
                        button.ImageButton.LocalBounds = new Rectangle(button.ImageButton.LocalBounds.X, maxY + rowHeight, button.ImageButton.LocalBounds.Width, button.ImageButton.LocalBounds.Height);
                        maxY += rowHeight;
                    }
                }

                /*
                 * foreach (SpellButton button in childless)
                 * {
                 *  button.ImageButton.LocalBounds =  new Rectangle(button.ImageButton.LocalBounds.X, maxY + rowHeight, button.ImageButton.LocalBounds.Width, button.ImageButton.LocalBounds.Height);
                 *  maxY += rowHeight;
                 * }
                 */
            }

            return(new Rectangle(xOffset, yOffset, width, height));
        }
Beispiel #30
0
    public void UpdateContext()
    {
        RollContext context     = battle.BuildContext();
        bool        anyCastable = false;

        for (int i = 0; i < spellButtons.Length; i++)
        {
            SpellButton b = spellButtons[i];
            b.castable = b.spell.Matches(context);
            if (!b.castable && b.currentState != UIObj.State.Disabled)
            {
                b.currentState = UIObj.State.Disabled;
            }
            else
            if (b.castable && b.currentState == UIObj.State.Disabled)
            {
                b.currentState = UIObj.State.Enabled;
            }
            if (b.castable && spellButtonOwnership[i] == battle.currentTurn)
            {
                anyCastable = true;
            }
        }

        if (battle.currentTurn != Game.peerId || battle.rollsLeft == 0)
        {
            if (!(battle.currentTurn == Game.peerId && battle.rollsLeft == 0 && !anyCastable))
            {
                rollButton.currentState = UIObj.State.Disabled;
            }
            foreach (DieButton db in dieButtons)
            {
                db.currentState = UIObj.State.Disabled;
            }
        }
        else
        {
            if (rollButton.currentState == UIObj.State.Disabled)
            {
                rollButton.currentState = UIObj.State.Enabled;
            }
            foreach (DieButton db in dieButtons)
            {
                if (db.currentState == UIObj.State.Disabled)
                {
                    db.currentState = UIObj.State.Enabled;
                }
            }
        }

        if (battle.currentTurn == Game.peerId && battle.rollsLeft == 0)
        {
            //rollButton.SetText("Pass"); TODO
            passButton.isVisible    = true;
            rollButton.currentState = UIObj.State.Disabled;
        }
        else
        {
            passButton.isVisible = false;
        }

        /* OLD Pass button behaviour (appears only when no castable spells)
         * if(battle.currentTurn == Game.peerId && battle.rollsLeft == 0 && !anyCastable) {
         *      //rollButton.SetText("Pass"); TODO
         *      passButton.isVisible = true;
         *      rollButton.currentState = UIObj.State.Disabled;
         * }
         */

        if (battle.log.Count > 0)
        {
            int    start = Mathf.Max(0, battle.log.Count - 7);
            int    end   = battle.log.Count - 1;
            string text  = "";
            for (int i = start; i <= end; i++)
            {
                if (i > start)
                {
                    text += "\n";
                }
                text += battle.log[i];
            }

            battleLog.SetText(text);
        }
    }
Beispiel #31
0
        private void CheckForConflicts(SpellButton node, int treeDistance, int nodeSize)
        {
            var minDistance = treeDistance + nodeSize;
            var shiftValue = 0F;

            var nodeContour = new Dictionary<int, float>();
            GetLeftContour(node, 0, ref nodeContour);

            var sibling = node.GetLeftMostSibling();
            while (sibling != null && sibling != node)
            {
                var siblingContour = new Dictionary<int, float>();
                GetRightContour(sibling, 0, ref siblingContour);

                for (int level = node.Y + 1; level <= Math.Min(siblingContour.Keys.Max(), nodeContour.Keys.Max()); level++)
                {
                    var distance = nodeContour[level] - siblingContour[level];
                    if (distance + shiftValue < minDistance)
                    {
                        shiftValue = minDistance - distance;
                    }
                }

                if (shiftValue > 0)
                {
                    node.X += (int)shiftValue;
                    node.Mod += (int)shiftValue;

                    CenterNodesBetween(node, sibling, treeDistance, nodeSize);

                    shiftValue = 0;
                }

                sibling = sibling.GetNextSibling();
            }
        }
Beispiel #32
0
    private void SetupSpellButton(AgeTransform tableItem, SpellDefinition spellDefinition, int index)
    {
        SpellButton component = tableItem.GetComponent <SpellButton>();

        component.SetContent(spellDefinition, base.Empire, base.gameObject, this.isInTargetingPhase, this.thereAlreadyIsASpellCasted, this.encounter);
    }
Beispiel #33
0
        // recusrively initialize x, y, and mod values of nodes
        private void InitializeNodes(SpellButton node, int depth)
        {
            node.X = -1;
            node.Y = depth;
            node.Mod = 0;

            foreach (var child in node.Children)
                InitializeNodes(child, depth + 1);
        }
Beispiel #34
0
        public Rectangle AlignImagesTree(SpellButton root, int xOffset, int yOffset)
        {
            Dictionary<int, List<SpellButton> > levels = new Dictionary<int, List<SpellButton>>();
            root.CountLevelsRecursive(levels);
            int rowHeight = 80;
            int colWidth = 120;
            int maxLevel = 1;
            foreach (var level in levels)
            {
                maxLevel = Math.Max(maxLevel, level.Value.Count);
            }

            int height = maxLevel * rowHeight;
            int width = colWidth*levels.Count;
            int x = xOffset;

            foreach (var level in levels)
            {
                int y = yOffset + (maxLevel - level.Value.Count) * rowHeight / 2;
                foreach (SpellButton button in level.Value)
                {
                    if (button.ImageButton != null)
                    {
                        button.ImageButton.LocalBounds = new Rectangle(x, y, button.ImageButton.LocalBounds.Width,
                            button.ImageButton.LocalBounds.Height);
                        y += rowHeight;
                    }
                }
                x += colWidth;
            }

            for (int i = levels.Values.Count - 2; i >= 0; i--)
            {
                List<SpellButton> level = levels.Values.ElementAt(i);
                //List<SpellButton> childless = new List<SpellButton>();
                int maxY = 0;
                foreach (SpellButton button in level)
                {
                    if (button.ImageButton == null) continue;
                    int avg = 0;

                    foreach (SpellButton child in button.Children)
                    {
                        avg += child.ImageButton.LocalBounds.Y;
                    }

                    if (avg > 0)
                    {
                        avg /= button.Children.Count;
                        button.ImageButton.LocalBounds = new Rectangle(button.ImageButton.LocalBounds.X, avg, button.ImageButton.LocalBounds.Width, button.ImageButton.LocalBounds.Height);
                        maxY = Math.Max(maxY, avg);
                    }
                    else
                    {
                        button.ImageButton.LocalBounds = new Rectangle(button.ImageButton.LocalBounds.X, maxY + rowHeight, button.ImageButton.LocalBounds.Width, button.ImageButton.LocalBounds.Height);
                        maxY += rowHeight;
                    }
                }

                /*
                foreach (SpellButton button in childless)
                {
                    button.ImageButton.LocalBounds =  new Rectangle(button.ImageButton.LocalBounds.X, maxY + rowHeight, button.ImageButton.LocalBounds.Width, button.ImageButton.LocalBounds.Height);
                    maxY += rowHeight;
                }
                 */
            }

            return  new Rectangle(xOffset, yOffset, width, height);
        }
Beispiel #35
0
        public void InitializeSpellButtons()
        {
            SpellButtons = new List<SpellButton>();

            int xOffset = 15;
            int yOffset = 32;
            SpellButton fakeButton = new SpellButton()
            {
                Children = new List<SpellButton>()
            };
            foreach (SpellTree.Node spell in Tree.RootSpells)
            {
                SpellButton newButton = new SpellButton()
                {
                    Spell = spell,
                    ImageButton = new Button(GUI, MainPanel, spell.Spell.Name, GUI.SmallFont, Button.ButtonMode.ImageButton, spell.Spell.Image)
                    {
                        ToolTip = spell.Spell.Description,
                        KeepAspectRatio = true,
                        DontMakeSmaller = true,
                        DontMakeBigger = true,
                        LocalBounds = new Rectangle(xOffset, yOffset, 0, 0),
                    },
                    Children = new List<SpellButton>(),
                    Level = 0,
                    Parent = fakeButton

                };
                SpellTree.Node rSpell = spell;
                newButton.ImageButton.OnClicked += () => ImageButton_OnClicked(rSpell);
                SpellButtons.Add(newButton);
                InitializeSpellButtonRecursive(newButton);
                fakeButton.Children.Add(newButton);
            }

            //Rectangle newRect = AlignImagesTree(fakeButton, xOffset, yOffset);
            //xOffset = newRect.Left;
            //yOffset = newRect.Bottom;
            //MainPanel.LocalBounds = new Rectangle(0, 0, Math.Max(MainPanel.LocalBounds.Width, newRect.Width + xOffset), Math.Max(MainPanel.LocalBounds.Height, newRect.Height + yOffset));
            CalculateNodePositions(fakeButton, 48, 10, 100);
        }
Beispiel #36
0
        private void GetRightContour(SpellButton node, float modSum, ref Dictionary<int, float> values)
        {
            if (!values.ContainsKey(node.Y))
                values.Add(node.Y, node.X + modSum);
            else
                values[node.Y] = Math.Max(values[node.Y], node.X + modSum);

            modSum += node.Mod;
            foreach (var child in node.Children)
            {
                GetRightContour(child, modSum, ref values);
            }
        }
 private void Start()
 {
     player = GameMainReferences.Instance.PlayerController;
     spellbutton = transform.parent.GetComponentInChildren<SpellButton>();
     selectedImage = GetComponent<Image>();
 }
Beispiel #38
0
 public void InitializeSpellButtonRecursive(SpellButton button)
 {
     foreach (SpellTree.Node spell in button.Spell.Children)
     {
         SpellButton newButton = new SpellButton()
         {
             Spell = spell,
             ImageButton = new Button(GUI, MainPanel, spell.Spell.Name, GUI.SmallFont, Button.ButtonMode.ImageButton, spell.Spell.Image)
             {
                 ToolTip = spell.Spell.Description,
                 KeepAspectRatio = true,
                 DontMakeSmaller = true,
                 DontMakeBigger = true
             },
             Level = button.Level +1,
             Children = new List<SpellButton>(),
             Parent = button
         };
         SpellTree.Node rSpell = spell;
         newButton.ImageButton.OnClicked += () => ImageButton_OnClicked(rSpell);
         button.Children.Add(newButton);
         SpellButtons.Add(newButton);
         InitializeSpellButtonRecursive(newButton);
     }
 }