public void SetInteractivity(bool interactable)
 {
     Button.interactable = interactable;
     if (interactable)
     {
         tooltip.ShowDefaultDescription();
     }
     else
     {
         tooltip.ShowAlternativeDescription();
     }
 }
Example #2
0
    public async void UpdateMenu()
    {
        scrollableContent.GetComponent <VerticalLayoutGroup>().enabled = true;

        Base.ActionPoint actionPoint;
        if (CurrentActionPoint == null)
        {
            return;
        }
        else
        {
            actionPoint = CurrentActionPoint.GetComponent <Base.ActionPoint>();
        }

        foreach (RectTransform o in dynamicContent.GetComponentsInChildren <RectTransform>())
        {
            if (o.gameObject.tag != "Persistent")
            {
                Destroy(o.gameObject);
            }
        }
        SetHeader(actionPoint.Data.Name);
        if (actionPoint.Parent != null)
        {
            ActionObjectType.text = actionPoint.Parent.GetName();
        }
        else
        {
            ActionObjectType.text = "Global action point";
        }

        Dictionary <IActionProvider, List <Base.ActionMetadata> > actionsMetadata;

        if (actionPoint.Parent == null)
        {
            actionsMetadata = Base.ActionsManager.Instance.GetAllFreeActions();
        }
        else
        {
            Base.ActionObject parentActionObject = actionPoint.Parent.GetActionObject();
            if (parentActionObject == null)
            {
                actionsMetadata = Base.ActionsManager.Instance.GetAllFreeActions();
            }
            else
            {
                actionsMetadata = Base.ActionsManager.Instance.GetAllActionsOfObject(parentActionObject);
            }
        }

        foreach (KeyValuePair <IActionProvider, List <Base.ActionMetadata> > keyval in actionsMetadata)
        {
            CollapsableMenu collapsableMenu = Instantiate(CollapsablePrefab, dynamicContent.transform).GetComponent <CollapsableMenu>();
            collapsableMenu.SetLabel(keyval.Key.GetProviderName());
            collapsableMenu.Collapsed = true;

            foreach (Base.ActionMetadata am in keyval.Value)
            {
                ActionButton btn = Instantiate(Base.GameManager.Instance.ButtonPrefab, collapsableMenu.Content.transform).GetComponent <ActionButton>();
                btn.transform.localScale = new Vector3(1, 1, 1);
                btn.SetLabel(am.Name);
                if (am.Disabled)
                {
                    CreateTooltip(am.Problem, btn);
                    btn.Button.interactable = false;
                }
                else if (!string.IsNullOrEmpty(am.Description))
                {
                    CreateTooltip(am.Description, btn);
                }

                btn.Button.onClick.AddListener(() => ShowAddNewActionDialog(am.Name, keyval.Key));
            }
        }

        UpdateLockedBtns(CurrentActionPoint.Locked);
        if (CurrentActionPoint.Parent == null)
        {
            UntieBtn.onClick.RemoveAllListeners();
            UntieBtn.onClick.AddListener(() => AssignToParent());
            UntieBtnTooltip.ShowAlternativeDescription();
        }
        else
        {
            UntieBtn.onClick.RemoveAllListeners();
            UntieBtn.onClick.AddListener(() => ShowUntieActionPointDialog());
            UntieBtnTooltip.ShowDefaultDescription();
        }

        RemoveBtn.SetInteractivity(await GameManager.Instance.RemoveActionPoint(CurrentActionPoint.Data.Id, true));
        ExpandBtn.gameObject.SetActive(CurrentActionPoint.ActionsCollapsed);
        CollapseBtn.gameObject.SetActive(!CurrentActionPoint.ActionsCollapsed);
    }