Esempio n. 1
0
            public void CheckForLeaves(
                ActionButtonNode parent,
                List <ActionOption> optionsLeft,
                Actor actor,
                CheckInOptionLeafAction checkIn,
                DeadEndOptionLeafAction deadEnd)
            {
                if (optionsLeft.Count == 0 && parent.PathLengthToRoot == ActionOptions.Count)                 //this is a leaf state
                {
                    checkIn(parent);
                    return;
                }

                ActionOption nextOne = optionsLeft.First();

                optionsLeft.Remove(nextOne);

                //here there could be a check for 0 choices on the options, and a way to "get a reason explanation" for the pat dead end
                if (nextOne.GetChoices(actor, this).Count == 0)
                {
                    deadEnd(parent, nextOne.LastNoChoiceReason);
                    return;
                }

                foreach (IActionOptionChoice choice in nextOne.GetChoices(actor, this))
                {
                    ActionButtonNode child = new ActionButtonNode();
                    child.label = choice.ValueLabel();

                    //imitate the next choice being chosen, so GetChoices works correctly...
                    nextOne.chosenChoice = choice;
                    CheckForLeaves(child, optionsLeft.ToList(), actor, checkIn, deadEnd);
                    nextOne.chosenChoice = null;
                }
            }
Esempio n. 2
0
            private void DressRootWithInventoryActions(ActionButtonNode root)
            {
                List <Action> inventoryActions = new List <Action> ();

                inventoryActions.Add(new PickUp(this));
                inventoryActions.Add(new DropItem(this));
                inventoryActions.Add(new Equip(this));
                inventoryActions.Add(new GiveItem(this));
                List <ActionButtonNode> nodes = inventoryActions.Select((ac) => {
                    //					actions.Remove(ac);
                    ActionButtonNode actionRoot = ac.GetOptionTreeRoot();

                    if (UsedInteraction())
                    {
                        if (UsedAction())
                        {
                            actionRoot.disabled       = true;
                            actionRoot.disabledReason = "You've already taken an action\n and an interaction this turn.";
                        }
                        else
                        {
                            //Allows the interaction to happen as an action.
                            ac.IsInteraction = false;
                        }
                    }


                    return(actionRoot);
                }).ToList();

                ActionPointer inventory = new ActionPointer("Inventory", nodes);

                inventory.spriteLabel = IconDispenser.instance.SpriteFromIconName(IconName.INVENTORY);
                root.AddChild(inventory.GetRoot());
            }
        public void DecorateOption(ActionButtonNode n)
        {
            //			Debug.LogError ("HERE!");
            //			n.spriteLabel = IconDispenser.instance.SpriteFromIconName (weapon.IconType);
            //			n.label = weapon.Name;
            //			if (IsRanged ()) {
            //				if (weapon.IsThrown()) {
            //					n.label += " Throw";
            //				} else {
            //					n.label += " Shot";
            //				}
            //			} else {
            //				n.label += " Swing";
            //			}
            //
            //
            //			if (IsRanged ()) {
            //				n.cornerSpriteLabel = IconDispenser.instance.SpriteFromIconName (IconName.RANGED_ATTACK);
            //			} else {
            //				n.cornerSpriteLabel = IconDispenser.instance.SpriteFromIconName (IconName.MELEE_ATTACK);
            //			}
            //

            Debug.LogWarning("hsidfhih spell!!");
            //			Debug.LogWarning (GetType () + " didn't override decorate option.");
        }
Esempio n. 4
0
    private void SetOnClickForOpt(OptButton opt, ActionButtonNode n)
    {
        if (n.disabled)
        {
            opt.OnOptMousedOver += (button) => {
                UIManager.instance.Tooltip.SetText(n.label + ": " + n.disabledReason);
                UIManager.instance.Tooltip.Show(opt.transform as RectTransform);
            };

            opt.OnOptMousedOut += (button) => {
                UIManager.instance.Tooltip.Hide();
//				UIManager.instance.tooltip.SetText(n.disabledReason);
            };

            opt.GetComponent <Button> ().interactable = false;
        }
        else
        {
            opt.OnOptLeftClicked += (button) => {
                NodeSelected(n);
            };

            opt.SetTooltipInfo(Tooltip.TooltipPosition.TOP, 0, n.label, n.rightClickDescription);
        }
    }
Esempio n. 5
0
    private ActionButtonNode SoleOption(List <ActionButtonNode> options)
    {
        ActionButtonNode soleOption = null;

        foreach (ActionButtonNode n in options)
        {
            if (n.disabled)
            {
                continue;
            }

            if (!(n.choice is Action))               //don't want to autoselect actions....

            {
                if (soleOption != null)                   //found another enabled option...
                {
                    soleOption = null;
                    break;
                }
                else
                {
                    soleOption = n;
                }
            }
        }

        return(soleOption);
    }
Esempio n. 6
0
    public ActionButtonNode GetRoot()
    {
        ActionButtonNode n = new ActionButtonNode();

        n.SetChildren(actionRoots);
        n.label             = label;
        n.spriteLabel       = spriteLabel;
        n.cornerSpriteLabel = cornerSpriteLabel;
        bool dis = true;

        foreach (ActionButtonNode child in n.children)
        {
            if (!child.disabled)
            {
                dis = false;
            }
        }
        if (dis)
        {
            n.disabled       = true;
            n.disabledReason = "There are no options.";
        }

        return(n);
    }
Esempio n. 7
0
            /// <summary>
            /// Produces the root action button node, used on turn begin to populate the action bar.
            /// </summary>
            /// <returns>The root action button node.</returns>
            public ActionButtonNode ProduceRootActionButtonNode()
            {
                ActionButtonNode root = new ActionButtonNode();

                DressRootWithStandardActions(root);
                DressRootWithBonusActions(root);
                DressRootWithInventoryActions(root);
                return(root);
            }
Esempio n. 8
0
 private void NodeSelected(ActionButtonNode n)
 {
     if (n.children.Count > 0)
     {
         SetCurrentActionNodes(n.children);
     }
     else
     {
         Debug.Log("resolving!!!!");
         Resolve(n);
     }
 }
Esempio n. 9
0
    private void SetCurrentActionNodes(List <ActionButtonNode> nodes)
    {
        currentSet = nodes.ToList();
        if (currentSet.Count == 0)
        {
            ClearCurrentBar();
            return;
        }


        if (IsRoot)
        {
            adjustedMaxPerPage = maxPerPage;
//			Debug.Log ("is max");
        }
        else
        {
//			Debug.Log ("adbusting ");
            adjustedMaxPerPage = maxPerPage - 1;             //to allow for back button
        }



        ActionButtonNode soleOpt = SoleOption(nodes);

        if (soleOpt != null && !IsRoot)
        {
            autoSelectStackLength += 1;
            NodeSelected(soleOpt);
            return;
        }

        if (adjustedMaxPerPage >= nodes.Count)
        {
            currentActionNodesShown = nodes.ToList();
            toTheRight = new List <ActionButtonNode> ();
            toTheLeft  = new List <ActionButtonNode> ();
        }
        else
        {
            currentActionNodesShown = nodes.GetRange(0, adjustedMaxPerPage);
            toTheRight = nodes.GetRange(adjustedMaxPerPage, nodes.Count - adjustedMaxPerPage);
            pageRight.gameObject.SetActive(true);
            //pageRight.optText.text = toTheRight.Count.ToString ();
            toTheLeft = new List <ActionButtonNode> ();
        }


        Populate(currentActionNodesShown);
    }
Esempio n. 10
0
            public void PopulatePathChildren(ActionButtonNode parent, List <ActionOption> optionsLeft, Actor actor)
            {
                //this is a leaf state of the action in the following case.
                //Now check to see if there are any target leaves it leads to for the purpose of setting the parent disabled
                if (optionsLeft.Count == 0)
                {
                    Actor theActor = null;                     //need to change our character for an actor instead....
                    //dead end, can't fill params at this option leaf.  Set parent disabled, and reason to "cannot fil prams"
                    if (!CanFillParams(theActor))
                    {
                        parent.disabled       = true;
                        parent.disabledReason = LastLackOfTargetReason;
                    }
                    return;
                }

                ActionOption nextOne = optionsLeft.First();

                optionsLeft.Remove(nextOne);

                List <IActionOptionChoice> choices = nextOne.GetChoices(actor, this);

                //set parent disabled.
                if (choices.Count <= 0)
                {
                    parent.disabled = true;

                    parent.disabledReason = nextOne.LastNoChoiceReason;
                }

                foreach (IActionOptionChoice choice in choices)
                {
                    ActionButtonNode child = new ActionButtonNode();
                    child.label  = choice.ValueLabel();
                    child.choice = choice;
                    choice.DecorateOption(child);

                    parent.AddChild(child);

                    //imitate the next choice being chosen, so GetChoices works correctly...
                    nextOne.chosenChoice = choice;
                    PopulatePathChildren(child, optionsLeft.ToList(), actor);
                    nextOne.chosenChoice = null;
                }
            }
Esempio n. 11
0
    // Use this for initialization
    void Start()
    {
        root = new ActionButtonNode();
        adjustedMaxPerPage = maxPerPage;
        UpdateActionBarWidth();


        //test this out.
        List <ActionButtonNode> list = new List <ActionButtonNode>();

        //InitiateActionTree (list);
        ClearCurrentBar();
        DisableLeft();
        DisableRight();

        pageLeft.OnOptLeftClicked  += PageLeft_OnOptClicked;
        pageRight.OnOptLeftClicked += PageRight_OnOptClicked;
    }
Esempio n. 12
0
            public bool HasActionOptions()
            {
                ActionButtonNode n   = ProduceRootActionButtonNode();
                bool             ret = false;

                if (n.children.Count > 0)
                {
                    foreach (ActionButtonNode child in n.children)
                    {
                        if (!child.disabled)
                        {
                            ret = true;
                            break;
                        }
                    }
                }
                return(ret);
            }
Esempio n. 13
0
            public ActionButtonNode GetOptionTreeRoot(Actor actor)
            {
                ActionButtonNode root = new ActionButtonNode();

                root.label = ValueLabel();
                DecorateOption(root);
                root.choice = this;
                PopulatePathChildren(root, ActionOptions.ToList(), actor);


                if (UseLimitReachedUntilLongRest)
                {
                    root.disabled       = true;
                    root.disabledReason = "You have to wait until a long rest to use this again.";
                }

                return(root);
            }
Esempio n. 14
0
            public void ActionFromResolutionPath(ActionBar bar, List <int> path)
            {
                bar.OnPathResolved -= ActionFromResolutionPath;
                ActionButtonNode root = ProduceRootActionButtonNode();

                Action           ret  = null;
                ActionButtonNode trav = root;
                int pathI             = 0;
                int childI            = path[pathI];

                //find the action first...
                while (ret == null)
                {
                    trav = trav.children [childI];
                    if (trav.choice is Action)
                    {
                        ret = trav.choice as Action;
                    }
                    pathI++;
                    if (pathI < path.Count)
                    {
                        childI = path [pathI];
                    }
                }


                //now fill the options
                foreach (ActionOption opt in ret.ActionOptions)
                {
                    trav = trav.children [childI];


                    opt.chosenChoice = trav.choice;
                    pathI++;
                    if (pathI < path.Count)
                    {
                        childI = path [pathI];
                    }
                }

                ret.LateSetTargetParameters();
                CallOnReadyToFillParams(ret);
            }
Esempio n. 15
0
    public GameObject InstantiateButtonFromNode(ActionButtonNode n)
    {
        GameObject ret = Instantiate(optTemplate);

        ret.SetActive(true);
        Text  text      = ret.GetComponent <OptButton>().optText;
        Image cornerImg = ret.transform.GetChild(1).gameObject.GetComponent <Image>();
        Text  cornerTxt = ret.transform.GetChild(2).gameObject.GetComponent <Text>();

        if (n.spriteLabel != null)
        {
            ret.GetComponent <Image> ().sprite = n.spriteLabel;
            //tooltip on hover for the action
        }
        else
        {
            text.fontSize = 13;
            text.text     = n.label;
        }

        if (n.cornerSpriteLabel != null)
        {
            cornerImg.sprite = n.cornerSpriteLabel;
            cornerImg.color  = new Color(1f, 1f, 1f, 1f);
        }
        else
        {
            cornerImg.color = new Color(1f, 1f, 1f, 0f);
        }

        if (n.cornerText != null)
        {
            cornerTxt.text = n.cornerText;
        }
        else
        {
            cornerTxt.text = "";
        }

        ret.transform.SetParent(actionsContainer, false);
        return(ret);
    }
Esempio n. 16
0
            private void DressRootWithStandardActions(ActionButtonNode root)
            {
                List <Action> actions = QueryActions();

                foreach (Action action in actions)
                {
                    ActionButtonNode actionRoot = action.GetOptionTreeRoot();

                    if (action.IsAttack)
                    {
                        if (AttacksLeft() <= 0)
                        {
                            actionRoot.disabled       = true;
                            actionRoot.disabledReason = "You cannot attack more than\n" + CharSheet.AttacksPerRound + " time(s) per turn.";
                        }
                        else if (UsedAction())
                        {
                            actionRoot.disabled       = true;
                            actionRoot.disabledReason = "You've already taken an action this turn";
                        }
                    }
                    else if (UsedAction() && !action.IsWait)
                    {
                        actionRoot.disabled       = true;
                        actionRoot.disabledReason = "You've already taken an action this turn";
                    }

                    //implements the rule where casting can't be done with unproficent equipment
                    if (action is Cast)
                    {
                        if (!CharSheet.IsProficientInAllWornEquipment())
                        {
                            actionRoot.disabled       = true;
                            actionRoot.disabledReason = "You cannot cast spells when wielding weapons or armour you are not proficient in";
                        }
                    }

                    root.AddChild(actionRoot);
                }
            }
Esempio n. 17
0
    private void Resolve(ActionButtonNode leaf)
    {
        autoSelectStackLength = 1;
        List <int>       path    = new List <int> ();
        ActionButtonNode current = leaf;

        while (current != root)
        {
            path.Add(current.Siblings().ToList().IndexOf(current));
            current = current.parent;
        }
        path.Reverse();

        foreach (int i in path)
        {
        }

        if (OnPathResolved != null)
        {
            OnPathResolved(this, path);
        }
    }
Esempio n. 18
0
            private void DressRootWithBonusActions(ActionButtonNode root)
            {
                //Add bonus actions...
                List <Action> bonus = QueryBonusActions(CharSheet);

                //I think this is doing nothing..... since the folooring line does a select
                foreach (Action act in bonus)
                {
                    ActionButtonNode ro = act.GetOptionTreeRoot();
                }
                ActionPointer p = new ActionPointer("Bonus Action", bonus.Select((act) => act.GetOptionTreeRoot()).ToList());

                p.spriteLabel = IconDispenser.instance.SpriteFromIconName(IconName.BONUS_ACTION);
                ActionButtonNode bonusRoot = p.GetRoot();

                if (UsedBonusAction())
                {
                    bonusRoot.disabled       = true;
                    bonusRoot.disabledReason = "You already used a bonus action this round";
                }
                root.AddChild(bonusRoot);
            }
Esempio n. 19
0
            public bool CanFillOptions(Actor actor)
            {
                ActionButtonNode root = new ActionButtonNode();

                root.label = ValueLabel();
                bool canFill = false;

                CheckInOptionLeafAction checkin = (leaf) => {
                    Debug.Log("found a leaf!: " + leaf.label);
                    //any leaf will do...
                    canFill = true;
                };

                DeadEndOptionLeafAction deadend = (leaf, reason) => {
                    Debug.Log("Dead end: " + leaf.label);
                    Debug.Log("reason: " + reason);
                };


                CheckForLeaves(root, ActionOptions.ToList(), actor, checkin, deadend);

                return(canFill);
            }
Esempio n. 20
0
    private void InstantiateAndSetOnClickForBack(ActionButtonNode n)
    {
        GameObject back = Instantiate(optTemplate);

        back.SetActive(true);
        back.transform.SetParent(actionsContainer, false);
        Text t = back.GetComponentInChildren <Text> ();

        t.text = "<";

        back.GetComponent <OptButton> ().OnOptMousedOver += (button) => {
            UIManager.instance.Tooltip.SetText("Back");
            UIManager.instance.Tooltip.Show(back.transform as RectTransform);
        };



        back.GetComponent <OptButton> ().OnOptMousedOut += (button) => {
            UIManager.instance.Tooltip.Hide();
            //				UIManager.instance.tooltip.SetText(n.disabledReason);
        };
        back.GetComponent <OptButton> ().OnOptLeftClicked += (button) => {
            //this needs to call set new action node set

            DisableLeft();
            DisableRight();
            ActionButtonNode curr = n;
            Debug.Log("Auto stack backing: " + autoSelectStackLength);
            for (int i = 0; i < autoSelectStackLength; i++)
            {
                curr = curr.parent;
            }
            autoSelectStackLength = 1;
            SetCurrentActionNodes(curr.Siblings());
        };
    }
        public void DecorateOption(ActionButtonNode n)
        {
//			Debug.LogWarning (GetType () + " didn't override decorate option.");
        }
Esempio n. 22
0
 public override void DecorateOption(ActionButtonNode n)
 {
     n.spriteLabel = IconDispenser.instance.SpriteFromIconName(IconName.DASH);
 }
Esempio n. 23
0
            public virtual void DecorateOption(ActionButtonNode n)
            {
//				n.spriteLabel = IconDispenser.instance.SpriteFromIconName (AT.Character.InventoryIconName.CHAIN_MAIL);
//				n.cornerSpriteLabel = IconDispenser.instance.SpriteFromIconName (AT.Character.InventoryIconName.DAGGER);
                Debug.LogWarning(GetType() + " didn't override decorate option.");
            }
Esempio n. 24
0
 public void AddChild(ActionButtonNode child)
 {
     children.Add(child);
     child.parent = this;
 }
Esempio n. 25
0
 public void DecorateOption(ActionButtonNode n)
 {
     n.rightClickDescription = spell.description;
 }
Esempio n. 26
0
 public override void DecorateOption(ActionButtonNode n)
 {
     //TODO: check what kind of weapon user has.
     n.spriteLabel = IconDispenser.instance.SpriteFromIconName(IconName.MELEE_ATTACK);
 }