Ejemplo n.º 1
0
 private void SetCategoryButtonState()
 {
     foreach (ToggleEntry toggleEntry in toggleEntries)
     {
         ToggleEntry current    = toggleEntry;
         ToggleInfo  toggleInfo = current.toggleInfo;
         toggleInfo.toggle.ActivateFlourish(activeCategoryInfo != null && toggleInfo.userData == activeCategoryInfo.userData);
         bool flag  = false;
         bool flag2 = true;
         if (DebugHandler.InstantBuildMode || Game.Instance.SandboxModeActive)
         {
             flag  = true;
             flag2 = false;
         }
         else
         {
             foreach (BuildingDef buildingDef in current.buildingDefs)
             {
                 RequirementsState requirementsState = BuildableState(buildingDef);
                 if (requirementsState == RequirementsState.Complete)
                 {
                     flag  = true;
                     flag2 = false;
                     break;
                 }
             }
             if (flag2 && current.AreAnyRequiredTechItemsAvailable())
             {
                 flag2 = false;
             }
         }
         CategoryInteractive[toggleInfo] = !flag2;
         GameObject gameObject = toggleInfo.toggle.fgImage.transform.Find("ResearchIcon").gameObject;
         if (!flag)
         {
             if (flag2 && current.hideIfNotResearched)
             {
                 toggleInfo.toggle.gameObject.SetActive(false);
             }
             else if (flag2)
             {
                 toggleInfo.toggle.gameObject.SetActive(true);
                 toggleInfo.toggle.fgImage.SetAlpha(0.2509804f);
                 gameObject.gameObject.SetActive(true);
             }
             else
             {
                 toggleInfo.toggle.gameObject.SetActive(true);
                 toggleInfo.toggle.fgImage.SetAlpha(1f);
                 gameObject.gameObject.SetActive(false);
             }
             ImageToggleState.State state        = (activeCategoryInfo != null && toggleInfo.userData == activeCategoryInfo.userData) ? ImageToggleState.State.DisabledActive : ImageToggleState.State.Disabled;
             ImageToggleState[]     toggleImages = current.toggleImages;
             foreach (ImageToggleState imageToggleState in toggleImages)
             {
                 imageToggleState.SetState(state);
             }
         }
         else
         {
             toggleInfo.toggle.gameObject.SetActive(true);
             toggleInfo.toggle.fgImage.SetAlpha(1f);
             gameObject.gameObject.SetActive(false);
             ImageToggleState.State state2        = (activeCategoryInfo == null || toggleInfo.userData != activeCategoryInfo.userData) ? ImageToggleState.State.Inactive : ImageToggleState.State.Active;
             ImageToggleState[]     toggleImages2 = current.toggleImages;
             foreach (ImageToggleState imageToggleState2 in toggleImages2)
             {
                 imageToggleState2.SetState(state2);
             }
         }
     }
 }
Ejemplo n.º 2
0
    private void GetBuildableStates(bool force_update)
    {
        if (Assets.BuildingDefs != null && Assets.BuildingDefs.Count != 0)
        {
            if (timeSinceNotificationPing < specialNotificationEmbellishDelay)
            {
                timeSinceNotificationPing += Time.unscaledDeltaTime;
            }
            if (timeSinceNotificationPing >= notificationPingExpire)
            {
                notificationPingCount = 0;
            }
            int num = 10;
            if (force_update)
            {
                num = Assets.BuildingDefs.Count;
                buildable_state_update_idx = 0;
            }
            ListPool <HashedString, PlanScreen> .PooledList pooledList = ListPool <HashedString, PlanScreen> .Allocate();

            for (int i = 0; i < num; i++)
            {
                buildable_state_update_idx = (buildable_state_update_idx + 1) % Assets.BuildingDefs.Count;
                BuildingDef buildingDef = Assets.BuildingDefs[buildable_state_update_idx];
                if (!buildingDef.Deprecated && tagCategoryMap.TryGetValue(buildingDef.Tag, out HashedString value))
                {
                    RequirementsState requirementsState = RequirementsState.Complete;
                    if (!DebugHandler.InstantBuildMode && !Game.Instance.SandboxModeActive)
                    {
                        if (!Db.Get().TechItems.IsTechItemComplete(buildingDef.PrefabID))
                        {
                            requirementsState = RequirementsState.Tech;
                        }
                        else if (!ProductInfoScreen.MaterialsMet(buildingDef.CraftRecipe))
                        {
                            requirementsState = RequirementsState.Materials;
                        }
                    }
                    if (!buildableDefs.ContainsKey(buildingDef))
                    {
                        buildableDefs.Add(buildingDef, requirementsState);
                    }
                    else if (buildableDefs[buildingDef] != requirementsState)
                    {
                        buildableDefs[buildingDef] = requirementsState;
                        if ((UnityEngine.Object)productInfoScreen.currentDef == (UnityEngine.Object)buildingDef)
                        {
                            ignoreToolChangeMessages++;
                            productInfoScreen.ClearProduct(false);
                            productInfoScreen.Show(true);
                            productInfoScreen.ConfigureScreen(buildingDef);
                            ignoreToolChangeMessages--;
                        }
                        if (requirementsState == RequirementsState.Complete)
                        {
                            foreach (ToggleInfo item in toggleInfo)
                            {
                                HashedString x = (HashedString)item.userData;
                                if (x == value)
                                {
                                    string   text      = "NotificationPing";
                                    Animator component = item.toggle.GetComponent <Animator>();
                                    if (!component.GetCurrentAnimatorStateInfo(0).IsTag(text) && !pooledList.Contains(value))
                                    {
                                        pooledList.Add(value);
                                        item.toggle.gameObject.GetComponent <Animator>().Play(text);
                                        if (KTime.Instance.UnscaledGameTime - initTime > 1.5f)
                                        {
                                            if (timeSinceNotificationPing >= specialNotificationEmbellishDelay)
                                            {
                                                string sound = GlobalAssets.GetSound("NewBuildable_Embellishment", false);
                                                if (sound != null)
                                                {
                                                    EventInstance instance = SoundEvent.BeginOneShot(sound, SoundListenerController.Instance.transform.GetPosition());
                                                    SoundEvent.EndOneShot(instance);
                                                }
                                            }
                                            string sound2 = GlobalAssets.GetSound("NewBuildable", false);
                                            if (sound2 != null)
                                            {
                                                EventInstance instance2 = SoundEvent.BeginOneShot(sound2, SoundListenerController.Instance.transform.GetPosition());
                                                instance2.setParameterValue("playCount", (float)notificationPingCount);
                                                SoundEvent.EndOneShot(instance2);
                                            }
                                        }
                                        timeSinceNotificationPing = 0f;
                                        notificationPingCount++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            pooledList.Recycle();
        }
    }