Пример #1
0
        public GameObject CreateEnumPropertyFilterPanel(PropertyDef property)
        {
            GameObject newPanel = Instantiate(enumPropertyPanel.gameObject, propertyFiltersContent);

            newPanel.gameObject.SetActive(true);

            SearchPropertyPanel config = newPanel.GetComponent <SearchPropertyPanel>();

            config.nameLabelText.text = !string.IsNullOrEmpty(property.Display) ? property.Display : property.Name;
            int storedFilter;

            Filters.EnumProperties.TryGetValue(property.Name, out storedFilter);

            EnumDef enumDef       = CardGameManager.Current.Enums.First(def => def.Property.Equals(property.Name));
            Vector3 localPosition = config.enumToggle.transform.localPosition;
            float   panelWidth    = 0;

            foreach (KeyValuePair <string, string> enumValue in enumDef.Values)
            {
                int lookupKey;
                if (!enumDef.Lookup.TryGetValue(enumValue.Key, out lookupKey))
                {
                    lookupKey = enumDef.CreateLookup(enumValue.Key);
                }
                Toggle newToggle = Instantiate(config.enumToggle.gameObject, config.enumContent).GetOrAddComponent <Toggle>();
                newToggle.isOn = (storedFilter & lookupKey) != 0;
                newToggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(property.Name, lookupKey, isOn));
                newToggle.GetComponentInChildren <Text>().text = enumValue.Value;
                newToggle.transform.localPosition = localPosition;
                float         width          = newToggle.GetComponentInChildren <Text>().preferredWidth + 25;
                RectTransform imageTransform = (RectTransform)newToggle.GetComponentInChildren <Image>().transform;
                imageTransform.sizeDelta = new Vector2(width, imageTransform.sizeDelta.y);
                localPosition.x         += width;
                panelWidth += width;
            }

            if (!string.IsNullOrEmpty(property.Empty))
            {
                int lookupKey;
                if (!enumDef.Lookup.TryGetValue(property.Empty, out lookupKey))
                {
                    lookupKey = enumDef.CreateLookup(property.Empty);
                }
                Toggle newToggle = Instantiate(config.enumToggle.gameObject, config.enumContent).GetOrAddComponent <Toggle>();
                newToggle.isOn = (storedFilter & lookupKey) != 0;
                newToggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(property.Name, lookupKey, isOn));
                newToggle.GetComponentInChildren <Text>().text = property.Empty;
                newToggle.transform.localPosition = localPosition;
                float         width          = newToggle.GetComponentInChildren <Text>().preferredWidth + 25;
                RectTransform imageTransform = (RectTransform)newToggle.GetComponentInChildren <Image>().transform;
                imageTransform.sizeDelta = new Vector2(width, imageTransform.sizeDelta.y);
                localPosition.x         += width;
                panelWidth += width;
            }
            config.enumToggle.gameObject.SetActive(false);
            config.enumContent.sizeDelta = new Vector2(panelWidth, config.enumContent.sizeDelta.y);

            return(newPanel);
        }
Пример #2
0
        public GameObject CreateEnumPropertyFilterPanel(string propertyName, PropertyDef property)
        {
            GameObject newPanel = Instantiate(toggleFilterPanel.gameObject, propertyFiltersContent);

            newPanel.gameObject.SetActive(true);

            SearchFilterPanel config = newPanel.GetComponent <SearchFilterPanel>();

            config.nameLabelText.text = !string.IsNullOrEmpty(property.Display) ? property.Display : propertyName;
            int storedFilter = 0;

            Filters.EnumProperties.TryGetValue(propertyName, out storedFilter);
            EnumDef enumDef             = CardGameManager.Current.Enums.First(def => def.Property.Equals(propertyName));
            float   toggleWidth         = 0;
            Vector3 toggleLocalPosition = config.toggle.transform.localPosition;
            float   panelWidth          = 0;

            if (property.DisplayEmptyFirst)
            {
                toggleWidth            = CreateEmptyEnumToggle(propertyName, property, enumDef, config, storedFilter, toggleLocalPosition);
                toggleLocalPosition.x += toggleWidth;
                panelWidth            += toggleWidth;
            }

            foreach (KeyValuePair <string, string> enumValue in enumDef.Values)
            {
                int lookupKey = 0;
                if (!enumDef.Lookups.TryGetValue(enumValue.Key, out lookupKey))
                {
                    lookupKey = enumDef.CreateLookup(enumValue.Key);
                }
                Toggle toggle = Instantiate(config.toggle.gameObject, config.toggleGroupContainer).GetOrAddComponent <Toggle>();
                toggle.isOn = (storedFilter & lookupKey) != 0;
                toggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(propertyName, lookupKey, isOn));
                toggle.GetComponentInChildren <Text>().text = enumValue.Value;
                toggle.transform.localPosition = toggleLocalPosition;
                toggleWidth = toggle.GetComponentInChildren <Text>().preferredWidth + 25;
                RectTransform toggleImageTransform = (RectTransform)toggle.GetComponentInChildren <Image>().transform;
                toggleImageTransform.sizeDelta = new Vector2(toggleWidth, toggleImageTransform.sizeDelta.y);
                toggleLocalPosition.x         += toggleWidth;
                panelWidth += toggleWidth;
            }

            if (!property.DisplayEmptyFirst && !string.IsNullOrEmpty(property.DisplayEmpty))
            {
                toggleWidth            = CreateEmptyEnumToggle(propertyName, property, enumDef, config, storedFilter, toggleLocalPosition);
                toggleLocalPosition.x += toggleWidth;
                panelWidth            += toggleWidth;
            }
            config.toggle.gameObject.SetActive(false);
            config.toggleGroupContainer.sizeDelta = new Vector2(panelWidth, config.toggleGroupContainer.sizeDelta.y);

            return(newPanel);
        }
Пример #3
0
        public float CreateEmptyEnumToggle(string propertyName, PropertyDef property, EnumDef enumDef, SearchFilterPanel config, int storedFilter, Vector3 toggleLocalPosition)
        {
            int lookupKey = 0;

            if (!enumDef.Lookups.TryGetValue(property.DisplayEmpty, out lookupKey))
            {
                lookupKey = enumDef.CreateLookup(property.DisplayEmpty);
            }
            Toggle toggle = Instantiate(config.toggle.gameObject, config.toggleGroupContainer).GetOrAddComponent <Toggle>();

            toggle.isOn = (storedFilter & lookupKey) != 0;
            toggle.onValueChanged.AddListener(isOn => SetEnumPropertyFilter(propertyName, lookupKey, isOn));
            toggle.GetComponentInChildren <Text>().text = property.DisplayEmpty;
            toggle.transform.localPosition = toggleLocalPosition;
            float         toggleWidth          = toggle.GetComponentInChildren <Text>().preferredWidth + 25;
            RectTransform toggleImageTransform = (RectTransform)toggle.GetComponentInChildren <Image>().transform;

            toggleImageTransform.sizeDelta = new Vector2(toggleWidth, toggleImageTransform.sizeDelta.y);
            return(toggleWidth);
        }