Exemplo n.º 1
0
 private void ConfigureDiseaseSelector()
 {
     diseaseSelector = new SelectorValue(Db.Get().Diseases.resources.ToArray(), delegate(object disease)
     {
         settings.SelectDisease(disease as Disease);
     }, (object disease) => (disease as Disease).Name, delegate(string filterText, object option)
     {
         if ((option as Disease).Name.ToUpper().Contains(filterText.ToUpper()))
         {
             return(true);
         }
         return(false);
     }, (object disease) => new Tuple <Sprite, Color>(Assets.GetSprite("germ"), (disease as Disease).overlayColour), null);
 }
Exemplo n.º 2
0
 public override string GetAttributeString()
 {
     return(SelectorValue.ToString());
 }
Exemplo n.º 3
0
    private GameObject SpawnSelector(SelectorValue selector)
    {
        GameObject          gameObject       = Util.KInstantiateUI(selectorPropertyPrefab, base.gameObject, true);
        HierarchyReferences component        = gameObject.GetComponent <HierarchyReferences>();
        GameObject          panel            = component.GetReference("ScrollPanel").gameObject;
        GameObject          gameObject2      = component.GetReference("Content").gameObject;
        InputField          filterInputField = component.GetReference <InputField>("Filter");
        KButton             reference        = component.GetReference <KButton>("Button");

        reference.onClick += delegate
        {
            panel.SetActive(!panel.activeSelf);
            if (panel.activeSelf)
            {
                panel.GetComponent <KScrollRect>().verticalNormalizedPosition = 1f;
                filterInputField.ActivateInputField();
            }
        };
        GameObject gameObject3 = component.GetReference("optionPrefab").gameObject;

        selector.row           = gameObject;
        selector.optionButtons = new List <KeyValuePair <object, GameObject> >();
        if (selector.filters != null)
        {
            GameObject clearFilterButton = Util.KInstantiateUI(gameObject3, gameObject2, false);
            clearFilterButton.GetComponentInChildren <LocText>().text      = UI.SANDBOXTOOLS.FILTERS.BACK;
            clearFilterButton.GetComponentsInChildren <Image>()[1].enabled = false;
            clearFilterButton.GetComponent <KButton>().onClick            += delegate
            {
                selector.currentFilter = null;
                selector.optionButtons.ForEach(delegate(KeyValuePair <object, GameObject> test)
                {
                    if (test.Key is SelectorValue.SearchFilter)
                    {
                        test.Value.SetActive((test.Key as SelectorValue.SearchFilter).parentFilter == null);
                    }
                    else
                    {
                        test.Value.SetActive(false);
                    }
                });
                clearFilterButton.SetActive(false);
                panel.GetComponent <KScrollRect>().verticalNormalizedPosition = 1f;
            };
            SelectorValue.SearchFilter[] filters = selector.filters;
            foreach (SelectorValue.SearchFilter filter in filters)
            {
                GameObject gameObject4 = Util.KInstantiateUI(gameObject3, gameObject2, false);
                gameObject4.SetActive(filter.parentFilter == null);
                gameObject4.GetComponentInChildren <LocText>().text = filter.Name;
                if (filter.icon != null)
                {
                    gameObject4.GetComponentsInChildren <Image>()[1].sprite = filter.icon.first;
                    gameObject4.GetComponentsInChildren <Image>()[1].color  = filter.icon.second;
                }
                gameObject4.GetComponent <KButton>().onClick += delegate
                {
                    selector.currentFilter = filter;
                    clearFilterButton.SetActive(true);
                    selector.optionButtons.ForEach(delegate(KeyValuePair <object, GameObject> test)
                    {
                        if (!(test.Key is SelectorValue.SearchFilter))
                        {
                            test.Value.SetActive(selector.runCurrentFilter(test.Key));
                        }
                        else if ((test.Key as SelectorValue.SearchFilter).parentFilter == null)
                        {
                            test.Value.SetActive(false);
                        }
                        else
                        {
                            test.Value.SetActive((test.Key as SelectorValue.SearchFilter).parentFilter == filter);
                        }
                    });
                    panel.GetComponent <KScrollRect>().verticalNormalizedPosition = 1f;
                };
                selector.optionButtons.Add(new KeyValuePair <object, GameObject>(filter, gameObject4));
            }
        }
        object[] options = selector.options;
        foreach (object option in options)
        {
            GameObject gameObject5 = Util.KInstantiateUI(gameObject3, gameObject2, true);
            gameObject5.GetComponentInChildren <LocText>().text = selector.getOptionName(option);
            gameObject5.GetComponent <KButton>().onClick       += delegate
            {
                selector.onValueChanged(option);
                panel.SetActive(false);
            };
            Tuple <Sprite, Color> tuple = selector.getOptionSprite(option);
            gameObject5.GetComponentsInChildren <Image>()[1].sprite = tuple.first;
            gameObject5.GetComponentsInChildren <Image>()[1].color  = tuple.second;
            selector.optionButtons.Add(new KeyValuePair <object, GameObject>(option, gameObject5));
            if (option is SelectorValue.SearchFilter)
            {
                gameObject5.SetActive((option as SelectorValue.SearchFilter).parentFilter == null);
            }
            else
            {
                gameObject5.SetActive(false);
            }
        }
        selector.button = reference;
        filterInputField.onValueChanged.AddListener(delegate(string filterString)
        {
            List <KeyValuePair <object, GameObject> > list = new List <KeyValuePair <object, GameObject> >();
            selector.optionButtons.ForEach(delegate(KeyValuePair <object, GameObject> test)
            {
                if (test.Key is SelectorValue.SearchFilter)
                {
                    test.Value.SetActive((test.Key as SelectorValue.SearchFilter).Name.ToUpper().Contains(filterString.ToUpper()));
                }
            });
            object[] options2 = selector.options;
            foreach (object option2 in options2)
            {
                list = selector.optionButtons.FindAll((KeyValuePair <object, GameObject> match) => match.Key == option2);
                foreach (KeyValuePair <object, GameObject> item in list)
                {
                    if (filterString == string.Empty)
                    {
                        item.Value.SetActive(false);
                    }
                    else
                    {
                        item.Value.SetActive(selector.filterOptionFunction(filterString, option2));
                    }
                }
            }
            panel.GetComponent <KScrollRect>().verticalNormalizedPosition = 1f;
        });
        inputFields.Add(filterInputField.gameObject);
        panel.SetActive(false);
        return(gameObject);
    }
Exemplo n.º 4
0
    private void ConfigureEntitySelector()
    {
        List <SelectorValue.SearchFilter> list = new List <SelectorValue.SearchFilter>();
        string name = UI.SANDBOXTOOLS.FILTERS.ENTITIES.FOOD;
        Func <object, bool> condition = delegate(object entity)
        {
            string idString = (entity as KPrefabID).PrefabID().ToString();
            return(!(entity as KPrefabID).HasTag(GameTags.Egg) && FOOD.FOOD_TYPES_LIST.Find((EdiblesManager.FoodInfo match) => match.Id == idString) != null);
        };
        Tuple <Sprite, Color> uISprite = Def.GetUISprite(Assets.GetPrefab("MushBar"), "ui", false);

        SelectorValue.SearchFilter item = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.SPECIAL;
        condition = ((object entity) => (entity as KPrefabID).PrefabID().Name == MinionConfig.ID || (entity as KPrefabID).PrefabID().Name == DustCometConfig.ID || (entity as KPrefabID).PrefabID().Name == RockCometConfig.ID || (entity as KPrefabID).PrefabID().Name == IronCometConfig.ID);
        uISprite  = new Tuple <Sprite, Color>(Assets.GetSprite("ui_duplicant_portrait_placeholder"), Color.white);
        SelectorValue.SearchFilter item2 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item2);
        SelectorValue.SearchFilter searchFilter  = null;
        SelectorValue.SearchFilter searchFilter2 = null;
        name         = UI.SANDBOXTOOLS.FILTERS.ENTITIES.CREATURE;
        condition    = ((object entity) => false);
        uISprite     = Def.GetUISprite(Assets.GetPrefab("Hatch"), "ui", false);
        searchFilter = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(searchFilter);
        List <Tag> list2 = new List <Tag>();

        foreach (GameObject item7 in Assets.GetPrefabsWithTag("CreatureBrain".ToTag()))
        {
            CreatureBrain brain = item7.GetComponent <CreatureBrain>();
            if (!list2.Contains(brain.species))
            {
                Tuple <Sprite, Color> icon = new Tuple <Sprite, Color>(CodexCache.entries[brain.species.ToString().ToUpper()].icon, CodexCache.entries[brain.species.ToString().ToUpper()].iconColor);
                list2.Add(brain.species);
                string key = "STRINGS.CREATURES.FAMILY_PLURAL." + brain.species.ToString().ToUpper();
                SelectorValue.SearchFilter item3 = new SelectorValue.SearchFilter(Strings.Get(key), delegate(object entity)
                {
                    CreatureBrain component2 = Assets.GetPrefab((entity as KPrefabID).PrefabID()).GetComponent <CreatureBrain>();
                    return((entity as KPrefabID).HasTag("CreatureBrain".ToString()) && component2.species == brain.species);
                }, searchFilter, icon);
                list.Add(item3);
            }
        }
        searchFilter2 = new SelectorValue.SearchFilter(UI.SANDBOXTOOLS.FILTERS.ENTITIES.CREATURE_EGG, (object entity) => (entity as KPrefabID).HasTag(GameTags.Egg), searchFilter, Def.GetUISprite(Assets.GetPrefab("HatchEgg"), "ui", false));
        list.Add(searchFilter2);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.EQUIPMENT;
        condition = delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject4 = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject4 != (UnityEngine.Object)null)
            {
                return((UnityEngine.Object)gameObject4.GetComponent <Equippable>() != (UnityEngine.Object)null);
            }
            return(false);
        };
        uISprite = Def.GetUISprite(Assets.GetPrefab("Funky_Vest"), "ui", false);
        SelectorValue.SearchFilter item4 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item4);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.PLANTS;
        condition = delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject3 = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject3 != (UnityEngine.Object)null)
            {
                return((UnityEngine.Object)gameObject3.GetComponent <Harvestable>() != (UnityEngine.Object)null || (UnityEngine.Object)gameObject3.GetComponent <WiltCondition>() != (UnityEngine.Object)null);
            }
            return(false);
        };
        uISprite = Def.GetUISprite(Assets.GetPrefab("PrickleFlower"), "ui", false);
        SelectorValue.SearchFilter searchFilter3 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(searchFilter3);
        SelectorValue.SearchFilter item5 = new SelectorValue.SearchFilter(UI.SANDBOXTOOLS.FILTERS.ENTITIES.SEEDS, delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject2 = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject2 != (UnityEngine.Object)null)
            {
                return((UnityEngine.Object)gameObject2.GetComponent <PlantableSeed>() != (UnityEngine.Object)null);
            }
            return(false);
        }, searchFilter3, Def.GetUISprite(Assets.GetPrefab("PrickleFlowerSeed"), "ui", false));
        list.Add(item5);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.INDUSTRIAL_PRODUCTS;
        condition = delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
            {
                return(gameObject.HasTag(GameTags.IndustrialIngredient) || gameObject.HasTag(GameTags.IndustrialProduct) || gameObject.HasTag(GameTags.Medicine) || gameObject.HasTag(GameTags.MedicalSupplies));
            }
            return(false);
        };
        uISprite = Def.GetUISprite(Assets.GetPrefab("BasicCure"), "ui", false);
        SelectorValue.SearchFilter item6 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item6);
        List <KPrefabID> list3 = new List <KPrefabID>();

        foreach (KPrefabID prefab2 in Assets.Prefabs)
        {
            foreach (SelectorValue.SearchFilter item8 in list)
            {
                if (item8.condition(prefab2))
                {
                    list3.Add(prefab2);
                    break;
                }
            }
        }
        entitySelector = new SelectorValue(list3.ToArray(), delegate(object entity)
        {
            settings.SelectEntity(entity as KPrefabID);
        }, (object entity) => (entity as KPrefabID).GetProperName(), delegate(string filterString, object option)
        {
            if ((option as KPrefabID).GetProperName().ToUpper().Contains(filterString.ToUpper()))
            {
                return(true);
            }
            return(false);
        }, delegate(object entity)
        {
            GameObject prefab = Assets.GetPrefab((entity as KPrefabID).PrefabTag);
            if ((UnityEngine.Object)prefab != (UnityEngine.Object)null)
            {
                if (prefab.PrefabID() == (Tag)MinionConfig.ID)
                {
                    return(new Tuple <Sprite, Color>(Assets.GetSprite("ui_duplicant_portrait_placeholder"), Color.white));
                }
                KBatchedAnimController component = prefab.GetComponent <KBatchedAnimController>();
                if ((UnityEngine.Object)component != (UnityEngine.Object)null && component.AnimFiles.Length > 0)
                {
                    KAnimFile x = component.AnimFiles[0];
                    if ((UnityEngine.Object)x != (UnityEngine.Object)null)
                    {
                        return(Def.GetUISprite(prefab, "ui", false));
                    }
                }
            }
            return(null);
        }, list.ToArray());
    }
Exemplo n.º 5
0
    private void ConfigureElementSelector()
    {
        Func <object, bool> func           = (object element) => (element as Element).IsSolid;
        Func <object, bool> func2          = (object element) => (element as Element).IsLiquid;
        Func <object, bool> func3          = (object element) => (element as Element).IsGas;
        List <Element>      commonElements = new List <Element>();
        Func <object, bool> condition      = (object element) => commonElements.Contains(element as Element);

        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Oxygen));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Water));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Vacuum));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Dirt));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.SandStone));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Cuprite));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Algae));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.CarbonDioxide));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Sand));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.SlimeMold));
        commonElements.Insert(0, ElementLoader.FindElementByHash(SimHashes.Granite));
        List <Element> list = new List <Element>();

        foreach (Element element in ElementLoader.elements)
        {
            if (!element.disabled)
            {
                list.Add(element);
            }
        }
        list.Sort((Element a, Element b) => a.name.CompareTo(b.name));
        Element[]       options        = list.ToArray();
        Action <object> onValueChanged = delegate(object element)
        {
            settings.SelectElement(element as Element);
        };
        Func <object, string>       getOptionName        = (object element) => (element as Element).name + " (" + (element as Element).GetStateString() + ")";
        Func <string, object, bool> filterOptionFunction = delegate(string filterString, object option)
        {
            if (((option as Element).name.ToUpper() + (option as Element).GetStateString().ToUpper()).Contains(filterString.ToUpper()))
            {
                return(true);
            }
            return(false);
        };
        Func <object, Tuple <Sprite, Color> > getOptionSprite = (object element) => Def.GetUISprite(element as Element, "ui", false);

        SelectorValue.SearchFilter[] obj = new SelectorValue.SearchFilter[4]
        {
            new SelectorValue.SearchFilter(UI.SANDBOXTOOLS.FILTERS.COMMON, condition, null, null),
            null,
            null,
            null
        };
        string name = UI.SANDBOXTOOLS.FILTERS.SOLID;
        Func <object, bool>   condition2 = func;
        Tuple <Sprite, Color> uISprite   = Def.GetUISprite(ElementLoader.FindElementByHash(SimHashes.SandStone), "ui", false);

        obj[1]          = new SelectorValue.SearchFilter(name, condition2, null, uISprite);
        name            = UI.SANDBOXTOOLS.FILTERS.LIQUID;
        condition2      = func2;
        uISprite        = Def.GetUISprite(ElementLoader.FindElementByHash(SimHashes.Water), "ui", false);
        obj[2]          = new SelectorValue.SearchFilter(name, condition2, null, uISprite);
        name            = UI.SANDBOXTOOLS.FILTERS.GAS;
        condition2      = func3;
        uISprite        = Def.GetUISprite(ElementLoader.FindElementByHash(SimHashes.Oxygen), "ui", false);
        obj[3]          = new SelectorValue.SearchFilter(name, condition2, null, uISprite);
        elementSelector = new SelectorValue(options, onValueChanged, getOptionName, filterOptionFunction, getOptionSprite, obj);
    }