private void RefreshToggle(ToggleInfo info)
 {
     if (info != null && !((UnityEngine.Object)info.toggle == (UnityEngine.Object)null))
     {
         UserData    userData = info.userData as UserData;
         BuildingDef def      = userData.def;
         TechItem    techItem = Db.Get().TechItems.TryGet(def.PrefabID);
         bool        flag     = DebugHandler.InstantBuildMode || techItem == null || techItem.IsComplete();
         bool        flag2    = flag || techItem == null || techItem.parentTech.ArePrerequisitesComplete();
         KToggle     toggle   = info.toggle;
         if (toggle.gameObject.activeSelf != flag2)
         {
             toggle.gameObject.SetActive(flag2);
         }
         if (!((UnityEngine.Object)toggle.bgImage == (UnityEngine.Object)null))
         {
             Image  image  = toggle.bgImage.GetComponentsInChildren <Image>()[1];
             Sprite sprite = image.sprite = def.GetUISprite("ui", false);
             image.SetNativeSize();
             image.rectTransform().sizeDelta /= 4f;
             ToolTip component = toggle.gameObject.GetComponent <ToolTip>();
             component.ClearMultiStringTooltip();
             string text   = def.Name;
             string effect = def.Effect;
             if (def.HotKey != Action.NumActions)
             {
                 text = GameUtil.AppendHotkeyString(text, def.HotKey);
             }
             component.AddMultiStringTooltip(text, buildingToolTipSettings.BuildButtonName);
             component.AddMultiStringTooltip(effect, buildingToolTipSettings.BuildButtonDescription);
             LocText componentInChildren = toggle.GetComponentInChildren <LocText>();
             if ((UnityEngine.Object)componentInChildren != (UnityEngine.Object)null)
             {
                 componentInChildren.text = def.Name;
             }
             PlanScreen.RequirementsState requirementsState = BuildMenu.Instance.BuildableState(def);
             ImageToggleState.State       state             = (requirementsState == PlanScreen.RequirementsState.Complete) ? ImageToggleState.State.Inactive : ImageToggleState.State.Disabled;
             state = ((!((UnityEngine.Object)def == (UnityEngine.Object)selectedBuilding) || (requirementsState != PlanScreen.RequirementsState.Complete && !DebugHandler.InstantBuildMode)) ? ((requirementsState == PlanScreen.RequirementsState.Complete || DebugHandler.InstantBuildMode) ? ImageToggleState.State.Inactive : ImageToggleState.State.Disabled) : ImageToggleState.State.Active);
             if ((UnityEngine.Object)def == (UnityEngine.Object)selectedBuilding && state == ImageToggleState.State.Disabled)
             {
                 state = ImageToggleState.State.DisabledActive;
             }
             else if (state == ImageToggleState.State.Disabled)
             {
                 state = ImageToggleState.State.Disabled;
             }
             toggle.GetComponent <ImageToggleState>().SetState(state);
             Material material;
             Color    color;
             if (requirementsState == PlanScreen.RequirementsState.Complete || DebugHandler.InstantBuildMode)
             {
                 material = defaultUIMaterial;
                 color    = Color.white;
             }
             else
             {
                 material = desaturatedUIMaterial;
                 Color color2;
                 if (flag)
                 {
                     color2 = new Color(1f, 1f, 1f, 0.6f);
                 }
                 else
                 {
                     Color color4 = image.color = new Color(1f, 1f, 1f, 0.15f);
                     color2 = color4;
                 }
                 color = color2;
             }
             if ((UnityEngine.Object)image.material != (UnityEngine.Object)material)
             {
                 image.material = material;
                 image.color    = color;
             }
             Image fgImage = toggle.gameObject.GetComponent <KToggle>().fgImage;
             fgImage.gameObject.SetActive(false);
             if (!flag)
             {
                 fgImage.sprite = Overlay_NeedTech;
                 fgImage.gameObject.SetActive(true);
                 string newString = string.Format(UI.PRODUCTINFO_REQUIRESRESEARCHDESC, techItem.parentTech.Name);
                 component.AddMultiStringTooltip("\n", buildingToolTipSettings.ResearchRequirement);
                 component.AddMultiStringTooltip(newString, buildingToolTipSettings.ResearchRequirement);
             }
             else if (requirementsState != PlanScreen.RequirementsState.Complete)
             {
                 fgImage.gameObject.SetActive(false);
                 component.AddMultiStringTooltip("\n", buildingToolTipSettings.ResearchRequirement);
                 string newString2 = UI.PRODUCTINFO_MISSINGRESOURCES_HOVER;
                 component.AddMultiStringTooltip(newString2, buildingToolTipSettings.ResearchRequirement);
                 foreach (Recipe.Ingredient ingredient in def.CraftRecipe.Ingredients)
                 {
                     string newString3 = string.Format("{0}{1}: {2}", "• ", ingredient.tag.ProperName(), GameUtil.GetFormattedMass(ingredient.amount, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}"));
                     component.AddMultiStringTooltip(newString3, buildingToolTipSettings.ResearchRequirement);
                 }
                 component.AddMultiStringTooltip(string.Empty, buildingToolTipSettings.ResearchRequirement);
             }
         }
     }
 }
    public void Configure(HashedString category, IList <BuildMenu.BuildingInfo> building_infos)
    {
        ClearButtons();
        SetHasFocus(true);
        List <ToggleInfo> list = new List <ToggleInfo>();
        string            text = HashCache.Get().Get(category).ToUpper();

        text            = text.Replace(" ", string.Empty);
        titleLabel.text = Strings.Get("STRINGS.UI.NEWBUILDCATEGORIES." + text + ".BUILDMENUTITLE");
        foreach (BuildMenu.BuildingInfo building_info in building_infos)
        {
            BuildMenu.BuildingInfo current = building_info;
            BuildingDef            def     = Assets.GetBuildingDef(current.id);
            if (def.ShowInBuildMenu && !def.Deprecated)
            {
                ToggleInfo item = new ToggleInfo(def.Name, new UserData(def, PlanScreen.RequirementsState.Tech), def.HotKey, () => def.GetUISprite("ui", false));
                list.Add(item);
            }
        }
        Setup(list);
        for (int i = 0; i < toggleInfo.Count; i++)
        {
            RefreshToggle(toggleInfo[i]);
        }
        int         num         = 0;
        IEnumerator enumerator2 = gridSizer.transform.GetEnumerator();

        try
        {
            while (enumerator2.MoveNext())
            {
                Transform transform = (Transform)enumerator2.Current;
                if (transform.gameObject.activeSelf)
                {
                    num++;
                }
            }
        }
        finally
        {
            IDisposable disposable;
            if ((disposable = (enumerator2 as IDisposable)) != null)
            {
                disposable.Dispose();
            }
        }
        gridSizer.constraintCount = Mathf.Min(num, 3);
        int     num2      = Mathf.Min(num, gridSizer.constraintCount);
        int     num3      = (num + gridSizer.constraintCount - 1) / gridSizer.constraintCount;
        int     num4      = num2 - 1;
        int     num5      = num3 - 1;
        float   num6      = (float)num2;
        Vector2 cellSize  = gridSizer.cellSize;
        float   num7      = num6 * cellSize.x;
        float   num8      = (float)num4;
        Vector2 spacing   = gridSizer.spacing;
        float   x         = num7 + num8 * spacing.x + (float)gridSizer.padding.left + (float)gridSizer.padding.right;
        float   num9      = (float)num3;
        Vector2 cellSize2 = gridSizer.cellSize;
        float   num10     = num9 * cellSize2.y;
        float   num11     = (float)num5;
        Vector2 spacing2  = gridSizer.spacing;
        Vector2 vector    = new Vector2(x, num10 + num11 * spacing2.y + (float)gridSizer.padding.top + (float)gridSizer.padding.bottom);

        contentSizeLayout.minWidth  = vector.x;
        contentSizeLayout.minHeight = vector.y;
    }
Exemple #3
0
 public void RefreshBuildingButton(BuildingDef def, KToggle toggle, HashedString buildingCategory)
 {
     if (!((UnityEngine.Object)toggle == (UnityEngine.Object)null))
     {
         if (GetToggleEntryForCategory(buildingCategory, out ToggleEntry toggleEntry) && toggleEntry.pendingResearchAttentions.Contains(def.Tag))
         {
             toggle.GetComponent <PlanCategoryNotifications>().ToggleAttention(true);
         }
         TechItem techItem = Db.Get().TechItems.TryGet(def.PrefabID);
         bool     flag     = TechRequirementsMet(techItem);
         bool     flag2    = TechRequirementsUpcoming(techItem);
         if (toggle.gameObject.activeSelf != flag2)
         {
             toggle.gameObject.SetActive(flag2);
             ConfigurePanelSize();
             SetScrollPoint(0f);
         }
         if (toggle.gameObject.activeInHierarchy && !((UnityEngine.Object)toggle.bgImage == (UnityEngine.Object)null))
         {
             Image  image    = toggle.bgImage.GetComponentsInChildren <Image>()[1];
             Sprite uISprite = def.GetUISprite("ui", false);
             if ((UnityEngine.Object)uISprite == (UnityEngine.Object)null)
             {
                 uISprite = defaultBuildingIconSprite;
             }
             image.sprite = uISprite;
             image.SetNativeSize();
             image.rectTransform().sizeDelta /= 4f;
             ToolTip component = toggle.gameObject.GetComponent <ToolTip>();
             PositionTooltip(toggle, component);
             component.ClearMultiStringTooltip();
             string name   = def.Name;
             string effect = def.Effect;
             component.AddMultiStringTooltip(name, buildingToolTipSettings.BuildButtonName);
             component.AddMultiStringTooltip(effect, buildingToolTipSettings.BuildButtonDescription);
             LocText componentInChildren = toggle.GetComponentInChildren <LocText>();
             if ((UnityEngine.Object)componentInChildren != (UnityEngine.Object)null)
             {
                 componentInChildren.text = def.Name;
             }
             ImageToggleState.State state = (BuildableState(def) == RequirementsState.Complete) ? ImageToggleState.State.Inactive : ImageToggleState.State.Disabled;
             state = ((!((UnityEngine.Object)toggle.gameObject == (UnityEngine.Object)selectedBuildingGameObject) || (BuildableState(def) != RequirementsState.Complete && !DebugHandler.InstantBuildMode && !Game.Instance.SandboxModeActive)) ? ((BuildableState(def) == RequirementsState.Complete || DebugHandler.InstantBuildMode || Game.Instance.SandboxModeActive) ? ImageToggleState.State.Inactive : ImageToggleState.State.Disabled) : ImageToggleState.State.Active);
             if ((UnityEngine.Object)toggle.gameObject == (UnityEngine.Object)selectedBuildingGameObject && state == ImageToggleState.State.Disabled)
             {
                 state = ImageToggleState.State.DisabledActive;
             }
             else if (state == ImageToggleState.State.Disabled)
             {
                 state = ImageToggleState.State.Disabled;
             }
             toggle.GetComponent <ImageToggleState>().SetState(state);
             Material material = (BuildableState(def) != RequirementsState.Complete && !DebugHandler.InstantBuildMode && !Game.Instance.SandboxModeActive) ? desaturatedUIMaterial : defaultUIMaterial;
             if ((UnityEngine.Object)image.material != (UnityEngine.Object)material)
             {
                 image.material = material;
                 if ((UnityEngine.Object)material == (UnityEngine.Object)desaturatedUIMaterial)
                 {
                     if (flag)
                     {
                         image.color = new Color(1f, 1f, 1f, 0.6f);
                     }
                     else
                     {
                         image.color = new Color(1f, 1f, 1f, 0.15f);
                     }
                 }
                 else
                 {
                     image.color = Color.white;
                 }
             }
             Image fgImage = toggle.gameObject.GetComponent <KToggle>().fgImage;
             fgImage.gameObject.SetActive(false);
             if (!flag)
             {
                 fgImage.sprite = Overlay_NeedTech;
                 fgImage.gameObject.SetActive(true);
                 string newString = string.Format(UI.PRODUCTINFO_REQUIRESRESEARCHDESC, techItem.parentTech.Name);
                 component.AddMultiStringTooltip("\n", buildingToolTipSettings.ResearchRequirement);
                 component.AddMultiStringTooltip(newString, buildingToolTipSettings.ResearchRequirement);
             }
             else if (BuildableState(def) != RequirementsState.Complete)
             {
                 fgImage.gameObject.SetActive(false);
                 component.AddMultiStringTooltip("\n", buildingToolTipSettings.ResearchRequirement);
                 string newString2 = UI.PRODUCTINFO_MISSINGRESOURCES_HOVER;
                 component.AddMultiStringTooltip(newString2, buildingToolTipSettings.ResearchRequirement);
                 foreach (Recipe.Ingredient ingredient in def.CraftRecipe.Ingredients)
                 {
                     string newString3 = string.Format("{0}{1}: {2}", "• ", ingredient.tag.ProperName(), GameUtil.GetFormattedMass(ingredient.amount, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}"));
                     component.AddMultiStringTooltip(newString3, buildingToolTipSettings.ResearchRequirement);
                 }
                 component.AddMultiStringTooltip(string.Empty, buildingToolTipSettings.ResearchRequirement);
             }
         }
     }
 }