Exemplo n.º 1
0
    void RefreshView()
    {
        // Assume all rule uis will be destroyed
        List <UIRuleToken> toDestroy = new List <UIRuleToken>(rules);

        foreach (var rule in editBehavior.rules)
        {
            int prevIndex = toDestroy.FindIndex(r => r.editRule == rule);
            if (prevIndex == -1)
            {
                // New rule
                // Check if we should hide it
                if (!UIParameterEnum.ShouldSkipValue(rule.condition.type))
                {
                    var ruleui = GameObject.Instantiate <UIRuleToken>(ruleTokenPrefab, Vector3.zero, Quaternion.identity, rulesRoot);
                    ruleui.Setup(rule);
                    ruleui.onClick.AddListener(() => NavigationManager.Instance.GoToPage(UIPage.PageId.Rule, rule));
                    ruleui.onEdit.AddListener(() => NavigationManager.Instance.GoToPage(UIPage.PageId.Rule, rule));
                    ruleui.onMoveUp.AddListener(() => MoveUp(rule));
                    ruleui.onMoveDown.AddListener(() => MoveDown(rule));
                    ruleui.onDuplicate.AddListener(() => DuplicateRule(rule));
                    ruleui.onRemove.AddListener(() => DeleteRule(rule));
                    ruleui.onExpand.AddListener(() => ExpandRule(rule));
                    rules.Add(ruleui);
                    spacer.SetAsLastSibling();
                }
            }
            else
            {
                var ruleui = toDestroy[prevIndex];

                // Still there, don't update it
                toDestroy.RemoveAt(prevIndex);

                // However, it may need to refresh its display
                ruleui.Refresh();

                // Fix the sibling index
                int order = editBehavior.rules.IndexOf(rule);
                ruleui.transform.SetSiblingIndex(order);
            }
        }

        // Remove all remaining rule uis
        foreach (var ruleui in toDestroy)
        {
            rules.Remove(ruleui);
            GameObject.Destroy(ruleui.gameObject);
        }
    }
Exemplo n.º 2
0
    protected override void SetupControls(string name, System.Func <object> getterFunc, System.Action <object> setterAction, IEnumerable <object> attributes = null)
    {
        // Set name
        nameText.text = name;

        // List all the enum values and populate the dropdown
        var initialValue    = getterFunc();
        int initialValueInt = System.Convert.ToInt32(initialValue);
        var enumType        = initialValue.GetType();

        var vals        = System.Enum.GetValues(enumType);
        var validValues = new List <System.Enum>();

        foreach (var val in vals)
        {
            if (!UIParameterEnum.ShouldSkipValue(val))
            {
                validValues.Add(val as System.Enum);
            }
        }

        for (int i = 0; i < validValues.Count; ++i)
        {
            var bitui           = GameObject.Instantiate <UIParameterBitfieldBit>(bitPrefab, buttonRoot);
            int bit             = System.Convert.ToInt32(validValues[i]);
            int backgroundIndex = 1;
            if (i == 0)
            {
                backgroundIndex = 0;
            }
            else if (i == validValues.Count - 1)
            {
                backgroundIndex = 2;
            }

            bitui.Setup(UIParameterEnum.GetNameAttribute(validValues[i], validValues[i].ToString()), (initialValueInt & bit) != 0, backgrounds[backgroundIndex], bitColor, bitColorSelected);
            bitui.onValueChanged.AddListener((val) =>
            {
                if (val)
                {
                    setterAction(System.Enum.Parse(enumType, (System.Convert.ToInt32(getterFunc()) | bit).ToString(), true));
                }
                else
                {
                    setterAction(System.Enum.Parse(enumType, (System.Convert.ToInt32(getterFunc()) & ~bit).ToString(), true));
                }
            });
            bits.Add(bitui);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Invoke the die picker
    /// </sumary>
    public void Show(string title, System.Enum previousValue, System.Action <bool, System.Enum> closeAction, List <System.Enum> validValues)
    {
        if (isShown)
        {
            Debug.LogWarning("Previous Enum picker still active");
            ForceHide();
        }

        gameObject.SetActive(true);
        currentValue     = previousValue;
        titleText.text   = title;
        this.closeAction = closeAction;

        var enumValues = new List <System.Enum>();

        if (validValues != null)
        {
            enumValues.AddRange(validValues);
        }
        else
        {
            var vals = System.Enum.GetValues(previousValue.GetType());
            foreach (var val in vals)
            {
                enumValues.Add(val as System.Enum);
            }
        }

        List <string> enumValueNames = new List <string>();

        foreach (var value in enumValues)
        {
            enumValueNames.Add(UIParameterEnum.GetNameAttribute(value, value.ToString()));
        }

        for (int i = 0; i < enumValues.Count; ++i)
        {
            var value = enumValues[i];
            var token = CreateEnumToken(enumValueNames[i], value);
            tokens.Add(token);
            token.SetSelected(value.Equals(currentValue));
        }
    }