示例#1
0
    public TestPop4()
    {
        m_popId    = POP_ID.TEST_POP_4;
        m_layerIdx = POP_LAYER_IDX.LAYER_POP_1;

        ShowGameObject();

        //
        m_btnOk    = GetChildByName <KButton>("Button_Ok", true);
        m_btnClose = GetChildByName <KButton>("Button_Close", true);

        m_panel = GameObjUtil.GetParent(m_btnOk.gameObject);

        //
        m_inputName      = GetChildByName <KInputField>("Input_name", true);
        m_labelTestInput = GetChildByName <KText>("Label_testInput", true);
        //
        m_tgl_1      = GetChildByName <KToggle>("Toggle_position1", true);
        m_labelTgl_1 = GetChildByName <KText>(m_tgl_1.gameObject, "Label_Text", true);
        m_tglGroup_1 = GetChildByName <KToggleGroup>("ToggleGroup_a1", true);
        //
        m_sliderSchedule = GetChildByName <KSlider>("Slider_Schedule1", true);
        m_labelSchedule  = GetChildByName <KText>("Label_testSilder", true);
        //
        m_barLoading = GetChildByName <KProgressBar>("ProgressBar_loading", true);
        //
        m_icon = GetChildByName <KImage>("Image_sharedAnchor", true);
        //
        m_scrollView = GetChildByName <KScrollView>("ScrollView_GuildList", true);
        m_listView   = ComponentUtil.EnsureComponent <KListViewScroll>(m_scrollView.gameObject);
    }
    public void ClearSelection()
    {
        GameObject[] array = buttonObjects;
        foreach (GameObject gameObject in array)
        {
            KToggle component = gameObject.GetComponent <KToggle>();
            if ((UnityEngine.Object)component != (UnityEngine.Object)null)
            {
                component.Deselect();
                component.isOn = false;
            }
            else
            {
                KBasicToggle component2 = gameObject.GetComponent <KBasicToggle>();
                if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
                {
                    component2.isOn = false;
                }
            }
            ImageToggleState component3 = gameObject.GetComponent <ImageToggleState>();
            if (component3.GetIsActive())
            {
                component3.SetInactive();
            }
        }
        ToggleGroup component4 = GetComponent <ToggleGroup>();

        if ((UnityEngine.Object)component4 != (UnityEngine.Object)null)
        {
            component4.SetAllTogglesOff();
        }
        SelectToggle(null);
    }
示例#3
0
    public TestKUIPop3()
    {
        m_popId    = POP_ID.TEST_KUI_3;
        m_layerIdx = POP_LAYER_IDX.LAYER_POP_1;

        ShowGameObject();

        m_toggle1 = GetChildByName <KToggle>("Toggle_position1", true);
        m_toggle1.needReqChange = true;

        m_toggleGroup1 = GetChildByName <KToggleGroup>("ToggleGroup_1", true);
        //m_toggleGroup1.allowMultiple = true;
        //m_toggleGroup1.needReqChange = true;
        //m_toggleGroup1.allowSwitchOff = true;

        m_inputName = GetChildByName <KInputField>("Input_name", true);


        m_buttonAnnounce = GetChildByName <KButton>("Button_SystemAnnounce", true);
        m_buttonClose    = GetChildByName <KButton>("Button_Close", true);


        m_barExp          = GetChildByName <KProgressBar>("ProgressBar_EXP", true);
        m_sliderSchedule1 = GetChildByName <KSlider>("Slider_Schedule1", true);

        m_icon1 = GetChildByName <KImage>("Image_Icon1", true);


        m_scrollViewItemList = GetChildByName <KScrollView>("ScrollView_ItemList", true);
    }
示例#4
0
        /// <summary>
        /// Sets the toggle state of a button only if it actually changed.
        /// </summary>
        /// <param name="instance">The side screen being updated.</param>
        /// <param name="toggle">The toggle to modify.</param>
        /// <param name="state">The state to apply.</param>
        private static void SetImageToggleState(ReceptacleSideScreen instance, KToggle toggle,
                                                ITState state)
        {
            if (toggle.TryGetComponent(out ImageToggleState its) && state != its.currentState)
            {
                // SetState provides no feedback on whether the state actually changed
                var targetImage = toggle.gameObject.GetComponentInChildrenOnly <Image>();
                switch (state)
                {
                case ITState.Disabled:
                    its.SetDisabled();
                    targetImage.material = instance.desaturatedMaterial;
                    break;

                case ITState.Inactive:
                    its.SetInactive();
                    targetImage.material = instance.defaultMaterial;
                    break;

                case ITState.Active:
                    its.SetActive();
                    targetImage.material = instance.defaultMaterial;
                    break;

                case ITState.DisabledActive:
                    its.SetDisabledActive();
                    targetImage.material = instance.desaturatedMaterial;
                    break;

                default:
                    break;
                }
            }
        }
    public void Add(Sprite icon, string name, OnClick onClick, int id, string tooltip = "")
    {
        GameObject    gameObject = Util.KInstantiateUI(prefab.gameObject, null, false);
        RectTransform component  = gameObject.GetComponent <RectTransform>();

        component.transform.SetParent(base.transform, false);
        component.name = name;
        if (tooltip == string.Empty)
        {
            component.GetComponent <ToolTip>().toolTip = name;
        }
        else
        {
            component.GetComponent <ToolTip>().toolTip = tooltip;
        }
        ActivateTabArtwork(id);
        TabHeaderIcon componentInChildren = component.GetComponentInChildren <TabHeaderIcon>();

        if ((bool)componentInChildren)
        {
            componentInChildren.TitleText.text = name;
        }
        KToggle component2 = gameObject.GetComponent <KToggle>();

        if ((bool)component2 && (bool)component2.fgImage)
        {
            component2.fgImage.sprite = icon;
        }
        component2.group    = GetComponent <ToggleGroup>();
        component2.onClick += delegate
        {
            onClick(id);
        };
    }
 private void RefreshIngredientAvailabilityVis()
 {
     foreach (KeyValuePair <GameObject, ComplexRecipe> item in recipeMap)
     {
         HierarchyReferences component = item.Key.GetComponent <HierarchyReferences>();
         bool    flag       = HasAllRecipeRequirements(item.Value);
         KToggle component2 = item.Key.GetComponent <KToggle>();
         if (flag)
         {
             if (selectedRecipe == item.Value)
             {
                 component2.ActivateFlourish(true, ImageToggleState.State.Active);
             }
             else
             {
                 component2.ActivateFlourish(false, ImageToggleState.State.Inactive);
             }
         }
         else if (selectedRecipe == item.Value)
         {
             component2.ActivateFlourish(true, ImageToggleState.State.DisabledActive);
         }
         else
         {
             component2.ActivateFlourish(false, ImageToggleState.State.Disabled);
         }
         component.GetReference <LocText>("Label").color = ((!flag) ? new Color(0.22f, 0.22f, 0.22f, 1f) : Color.black);
     }
 }
示例#7
0
    void OnTglGroupValue(KToggleGroup tglGroup_, int idx_, bool b_)
    {
        KToggle child = tglGroup_.GetToggle(idx_);
        KText   label = GetChildByName <KText>(child.gameObject, "Label_Text");

        label.text = b_ ? "选中" : "没选中";
    }
示例#8
0
 public void RefreshToggleContents()
 {
     foreach (KeyValuePair <Tag, KToggle> elementToggle in ElementToggles)
     {
         KToggle    value                = elementToggle.Value;
         Tag        elem                 = elementToggle.Key;
         GameObject gameObject           = value.gameObject;
         LocText[]  componentsInChildren = gameObject.GetComponentsInChildren <LocText>();
         LocText    locText              = componentsInChildren[0];
         LocText    locText2             = componentsInChildren[1];
         Image      image                = gameObject.GetComponentsInChildren <Image>()[1];
         locText2.text = Util.FormatWholeNumber(WorldInventory.Instance.GetAmount(elem));
         locText.text  = Util.FormatWholeNumber(activeMass);
         GameObject gameObject2 = Assets.TryGetPrefab(elementToggle.Key);
         if ((Object)gameObject2 != (Object)null)
         {
             KBatchedAnimController component = gameObject2.GetComponent <KBatchedAnimController>();
             image.sprite = Def.GetUISpriteFromMultiObjectAnim(component.AnimFiles[0], "ui", false, string.Empty);
         }
         gameObject.SetActive(WorldInventory.Instance.IsDiscovered(elem) || DebugHandler.InstantBuildMode || Game.Instance.SandboxModeActive);
         SetToggleBGImage(elementToggle.Value, elementToggle.Key);
         value.soundPlayer.AcceptClickCondition = (() => IsEnoughMass(elem));
         value.ClearOnClick();
         if (IsEnoughMass(elem))
         {
             value.onClick += delegate
             {
                 OnSelectMaterial(elem, activeRecipe, false);
             };
         }
     }
     SortElementToggles();
     UpdateMaterialTooltips();
     UpdateHeader();
 }
 private void ToggleClicked(KToggle toggle)
 {
     if (!recipeMap.ContainsKey(toggle.gameObject))
     {
         Debug.LogError("Recipe not found on recipe list.");
     }
     else
     {
         if ((Object)selectedToggle == (Object)toggle)
         {
             selectedToggle.isOn = false;
             selectedToggle      = null;
             selectedRecipe      = null;
         }
         else
         {
             selectedToggle      = toggle;
             selectedToggle.isOn = true;
             selectedRecipe      = recipeMap[toggle.gameObject];
             selectedRecipeFabricatorMap[targetFab] = recipeToggles.IndexOf(toggle.gameObject);
         }
         RefreshIngredientAvailabilityVis();
         if (toggle.isOn)
         {
             recipeScreen = (SelectedRecipeQueueScreen)DetailsScreen.Instance.SetSecondarySideScreen(recipeScreenPrefab, UI.UISIDESCREENS.FABRICATORSIDESCREEN.RECIPE_DETAILS);
             recipeScreen.SetRecipe(this, targetFab, selectedRecipe);
         }
         else
         {
             DetailsScreen.Instance.ClearSecondarySideScreen();
         }
     }
 }
示例#10
0
 private void UpdateHeader()
 {
     if (activeIngredient != null)
     {
         int num = 0;
         foreach (KeyValuePair <Tag, KToggle> elementToggle in ElementToggles)
         {
             KToggle value = elementToggle.Value;
             if (value.gameObject.activeSelf)
             {
                 num++;
             }
         }
         LocText componentInChildren = Headerbar.GetComponentInChildren <LocText>();
         if (num == 0)
         {
             componentInChildren.text = string.Format(UI.PRODUCTINFO_MISSINGRESOURCES_TITLE, activeIngredient.tag.ProperName(), GameUtil.GetFormattedMass(activeIngredient.amount, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}"));
             string text = string.Format(UI.PRODUCTINFO_MISSINGRESOURCES_DESC, activeIngredient.tag.ProperName());
             NoMaterialDiscovered.text = text;
             NoMaterialDiscovered.gameObject.SetActive(true);
             NoMaterialDiscovered.color = Constants.NEGATIVE_COLOR;
             BadBG.SetActive(true);
             Scrollbar.SetActive(false);
             LayoutContainer.SetActive(false);
         }
         else
         {
             componentInChildren.text = string.Format(UI.PRODUCTINFO_SELECTMATERIAL, activeIngredient.tag.ProperName());
             NoMaterialDiscovered.gameObject.SetActive(false);
             BadBG.SetActive(false);
             LayoutContainer.SetActive(true);
             UpdateScrollBar();
         }
     }
 }
 protected void SelectToggle(KToggle selectedToggle)
 {
     if (!((UnityEngine.Object)UnityEngine.EventSystems.EventSystem.current == (UnityEngine.Object)null) && UnityEngine.EventSystems.EventSystem.current.enabled)
     {
         if ((UnityEngine.Object)currentlySelectedToggle == (UnityEngine.Object)selectedToggle)
         {
             currentlySelectedToggle = null;
         }
         else
         {
             currentlySelectedToggle = selectedToggle;
         }
         GameObject[] array = buttonObjects;
         foreach (GameObject gameObject in array)
         {
             KToggle component = gameObject.GetComponent <KToggle>();
             if ((UnityEngine.Object)component != (UnityEngine.Object)null)
             {
                 if ((UnityEngine.Object)component == (UnityEngine.Object)currentlySelectedToggle)
                 {
                     component.Select();
                     component.isOn = true;
                 }
                 else
                 {
                     component.Deselect();
                     component.isOn = false;
                 }
             }
         }
     }
 }
示例#12
0
    private void UpdateBuildingButtonList(ToggleInfo toggle_info)
    {
        KToggle toggle = toggle_info.toggle;

        if ((UnityEngine.Object)toggle == (UnityEngine.Object)null)
        {
            foreach (ToggleInfo item in toggleInfo)
            {
                if (item.userData == toggle_info.userData)
                {
                    toggle = item.toggle;
                }
            }
        }
        int num = 2;

        if ((UnityEngine.Object)toggle != (UnityEngine.Object)null && ActiveToggles.Count != 0)
        {
            for (int i = 0; i < num; i++)
            {
                if (building_button_refresh_idx >= ActiveToggles.Count)
                {
                    building_button_refresh_idx = 0;
                }
                RefreshBuildingButton(ActiveToggles.ElementAt(building_button_refresh_idx).Key, ActiveToggles.ElementAt(building_button_refresh_idx).Value, (HashedString)toggle_info.userData);
                building_button_refresh_idx++;
            }
        }
        if (productInfoScreen.gameObject.activeSelf)
        {
            productInfoScreen.materialSelectionPanel.UpdateResourceToggleValues();
        }
    }
示例#13
0
 private static void UpdateToggle(KToggle off, KToggle on, bool isOn)
 {
     off.isOn = !isOn;
     on.isOn  = isOn;
     //off.GetComponent<ImageToggleState>().SetState(off.isOn ? ImageToggleState.State.Active : ImageToggleState.State.Inactive);
     //on.GetComponent<ImageToggleState>().SetState(on.isOn ? ImageToggleState.State.Active : ImageToggleState.State.Inactive);
 }
    private void SetImageToggleState(KToggle toggle, ImageToggleState.State state)
    {
        switch (state)
        {
        case ImageToggleState.State.Active:
            toggle.GetComponent <ImageToggleState>().SetActive();
            toggle.gameObject.GetComponentInChildrenOnly <Image>().material = defaultMaterial;
            break;

        case ImageToggleState.State.Inactive:
            toggle.GetComponent <ImageToggleState>().SetInactive();
            toggle.gameObject.GetComponentInChildrenOnly <Image>().material = defaultMaterial;
            break;

        case ImageToggleState.State.Disabled:
            toggle.GetComponent <ImageToggleState>().SetDisabled();
            toggle.gameObject.GetComponentInChildrenOnly <Image>().material = desaturatedMaterial;
            break;

        case ImageToggleState.State.DisabledActive:
            toggle.GetComponent <ImageToggleState>().SetDisabledActive();
            toggle.gameObject.GetComponentInChildrenOnly <Image>().material = desaturatedMaterial;
            break;
        }
    }
示例#15
0
    private void SetMaterialTint(KToggle toggle, bool disabled)
    {
        SwapUIAnimationController component = toggle.GetComponent <SwapUIAnimationController>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            component.SetState(!disabled);
        }
    }
            private static void Prefix(ManagementMenu __instance, ref KToggle toggle, ref bool disabled, ref bool active, ref string tooltip, ref TextStyleSetting tooltip_style)
            {
                //Debug.Log(" === ManagementMenu.ConfigureToggle Postfix === ");

                //__instance.CheckResearch(null);
                //this.ConfigureToggle(this.researchInfo.toggle, flag, active, tooltip, base.ToggleToolTipTextStyleSetting);
                disabled = false;
                //active = true;
                tooltip = UI.TOOLTIPS.MANAGEMENTMENU_RESEARCH + " " + GameUtil.GetActionString(Action.ManageResearch);
            }
 protected override void OnShow(bool show)
 {
     if (show)
     {
         AudioMixer.instance.Start(AudioMixerSnapshots.Get().FabricatorSideScreenOpenSnapshot);
     }
     else
     {
         AudioMixer.instance.Stop(AudioMixerSnapshots.Get().FabricatorSideScreenOpenSnapshot, STOP_MODE.ALLOWFADEOUT);
         DetailsScreen.Instance.ClearSecondarySideScreen();
         selectedRecipe = null;
         selectedToggle = null;
     }
     base.OnShow(show);
 }
示例#18
0
    private GameObject CreateButton(BuildingDef def, GameObject parent, string plan_category, int btnIndex)
    {
        GameObject button_go = Util.KInstantiateUI(planButtonPrefab, parent, true);

        button_go.name = UI.StripLinkFormatting(def.name) + " Group:" + plan_category;
        KToggle componentInChildren = button_go.GetComponentInChildren <KToggle>();

        componentInChildren.soundPlayer.Enabled = false;
        ActiveToggles.Add(def, componentInChildren);
        RefreshBuildingButton(def, componentInChildren, plan_category);
        componentInChildren.onClick += delegate
        {
            OnSelectBuilding(button_go, def);
        };
        return(button_go);
    }
    private void ConfigureToggle(KToggle toggle, bool disabled, bool active, string tooltip, TextStyleSetting tooltip_style)
    {
        toggle.interactable = active;
        toggle.GetComponent <KToggle>().interactable = !disabled;
        if (disabled)
        {
            toggle.GetComponentInChildren <ImageToggleState>().SetDisabled();
        }
        else
        {
            toggle.GetComponentInChildren <ImageToggleState>().SetActiveState(active);
        }
        ToolTip component = toggle.GetComponent <ToolTip>();

        component.ClearMultiStringTooltip();
        component.AddMultiStringTooltip(tooltip, tooltip_style);
    }
示例#20
0
    public void ConfigureScreen(Recipe.Ingredient ingredient, Recipe recipe)
    {
        ClearMaterialToggles();
        activeIngredient = ingredient;
        activeRecipe     = recipe;
        activeMass       = ingredient.amount;
        List <Tag> list = new List <Tag>();

        foreach (Element element in ElementLoader.elements)
        {
            if (element.IsSolid && (element.tag == ingredient.tag || element.HasTag(ingredient.tag)))
            {
                list.Add(element.tag);
            }
        }
        foreach (Tag materialBuildingElement in GameTags.MaterialBuildingElements)
        {
            if (materialBuildingElement == ingredient.tag)
            {
                foreach (GameObject item in Assets.GetPrefabsWithTag(materialBuildingElement))
                {
                    KPrefabID component = item.GetComponent <KPrefabID>();
                    if ((Object)component != (Object)null && !list.Contains(component.PrefabTag))
                    {
                        list.Add(component.PrefabTag);
                    }
                }
            }
        }
        foreach (Tag item2 in list)
        {
            if (!ElementToggles.ContainsKey(item2))
            {
                GameObject gameObject = Util.KInstantiate(TogglePrefab, LayoutContainer, "MaterialSelection_" + item2.ProperName());
                gameObject.transform.localScale = Vector3.one;
                gameObject.SetActive(true);
                KToggle component2 = gameObject.GetComponent <KToggle>();
                ElementToggles.Add(item2, component2);
                component2.group = toggleGroup;
                ToolTip component3 = gameObject.gameObject.GetComponent <ToolTip>();
                component3.toolTip = item2.ProperName();
            }
        }
        RefreshToggleContents();
    }
示例#21
0
    public void OnSelectMaterial(Tag elem, Recipe recipe, bool focusScrollRect = false)
    {
        KToggle kToggle = null;

        kToggle = ElementToggles[elem];
        if ((Object)kToggle != (Object)selectedToggle)
        {
            selectedToggle = kToggle;
            if (recipe != null)
            {
                SaveGame.Instance.materialSelectorSerializer.SetSelectedElement(selectorIndex, recipe.Result, elem);
            }
            CurrentSelectedElement = elem;
            if (selectMaterialActions != null)
            {
                selectMaterialActions();
            }
            UpdateHeader();
            SetDescription(elem);
            SetEffects(elem);
            if (!MaterialDescriptionPane.gameObject.activeSelf && !MaterialEffectsPane.gameObject.activeSelf)
            {
                DescriptorsPanel.SetActive(false);
            }
            else
            {
                DescriptorsPanel.SetActive(true);
            }
        }
        if (focusScrollRect && ElementToggles.Count > 1)
        {
            List <Tag> list = new List <Tag>();
            foreach (KeyValuePair <Tag, KToggle> elementToggle in ElementToggles)
            {
                list.Add(elementToggle.Key);
            }
            list.Sort(ElementSorter);
            int   num = list.IndexOf(elem);
            float x   = (float)num / (float)(list.Count - 1);
            ScrollRect.normalizedPosition = new Vector2(x, 0f);
        }
        RefreshToggleContents();
    }
示例#22
0
            public static bool Prefix(PlanScreen __instance, bool __state)
            {
                BuildingDef def = null;
                KToggle     currentlySelectedToggle = Traverse.Create(__instance).Field("currentlySelectedToggle").GetValue <KToggle>();

                foreach (KeyValuePair <BuildingDef, KToggle> kvp in __instance.ActiveToggles)
                {
                    if (kvp.Value == currentlySelectedToggle)
                    {
                        def = kvp.Key;
                        break;
                    }
                }
                if (def.name.Contains(Mod.TILE_POSTFIX))
                {
                    ProductInfoScreen productInfoScreen = Traverse.Create(__instance).Field("productInfoScreen").GetValue <ProductInfoScreen>();
                    IList <Tag>       elements          = productInfoScreen.materialSelectionPanel.GetSelectedElementAsList;
                    string            newID             = Mod.MOD_PREFIX + elements[0].ToString() + Mod.TILE_POSTFIX;
                    BuildingDef       newDef            = Assets.GetBuildingDef(newID);

                    if (newDef == null)
                    {
                        newDef = Assets.GetBuildingDef(StainedGlassTileConfig.ID);
                    }

                    InterfaceTool tool = PlayerController.Instance.ActiveTool;

                    if (tool != null)
                    {
                        Type tool_type = tool.GetType();
                        if (tool_type == typeof(BuildTool) || typeof(BaseUtilityBuildTool).IsAssignableFrom(tool_type))
                        {
                            tool.DeactivateTool(null);
                        }
                    }

                    BuildTool.Instance.Activate(newDef, productInfoScreen.materialSelectionPanel.GetSelectedElementAsList, null);

                    return(false);
                }
                return(true);
            }
 private void RefreshButtons()
 {
     foreach (KToggle toggle in toggles)
     {
         if ((Object)toggle != (Object)null)
         {
             Object.Destroy(toggle.gameObject);
         }
     }
     toggles.Clear();
     if (this.toggleInfo != null)
     {
         Transform parent = (!((Object)toggleParent != (Object)null)) ? base.transform : toggleParent;
         for (int i = 0; i < this.toggleInfo.Count; i++)
         {
             int        idx        = i;
             ToggleInfo toggleInfo = this.toggleInfo[i];
             if (toggleInfo == null)
             {
                 toggles.Add(null);
             }
             else
             {
                 KToggle kToggle = Object.Instantiate(prefab, Vector3.zero, Quaternion.identity);
                 kToggle.gameObject.name = "Toggle:" + toggleInfo.text;
                 kToggle.transform.SetParent(parent, false);
                 kToggle.group    = group;
                 kToggle.onClick += delegate
                 {
                     OnClick(idx);
                 };
                 Text text = kToggle.GetComponentsInChildren <Text>(true)[0];
                 text.text         = toggleInfo.text;
                 toggleInfo.toggle = kToggle;
                 toggles.Add(kToggle);
             }
         }
     }
 }
示例#24
0
 private void SetToggleBGImage(KToggle toggle, Tag elem)
 {
     if ((Object)toggle == (Object)selectedToggle)
     {
         toggle.GetComponentsInChildren <Image>()[1].material = GlobalResources.Instance().AnimUIMaterial;
         toggle.GetComponent <ImageToggleState>().SetActive();
     }
     else if (WorldInventory.Instance.GetAmount(elem) >= activeMass || DebugHandler.InstantBuildMode || Game.Instance.SandboxModeActive)
     {
         toggle.GetComponentsInChildren <Image>()[1].material = GlobalResources.Instance().AnimUIMaterial;
         toggle.GetComponentsInChildren <Image>()[1].color    = Color.white;
         toggle.GetComponent <ImageToggleState>().SetInactive();
     }
     else
     {
         toggle.GetComponentsInChildren <Image>()[1].material = GlobalResources.Instance().AnimMaterialUIDesaturated;
         toggle.GetComponentsInChildren <Image>()[1].color    = new Color(1f, 1f, 1f, 0.6f);
         if (!AllowInsufficientMaterialBuild())
         {
             toggle.GetComponent <ImageToggleState>().SetDisabled();
         }
     }
 }
    public void Activate(int itemIdx, int previouslyActiveTabIdx)
    {
        int childCount = base.transform.childCount;

        if (itemIdx < childCount)
        {
            for (int i = 0; i < childCount; i++)
            {
                Transform child = base.transform.GetChild(i);
                if (child.gameObject.activeSelf)
                {
                    KButton componentInChildren = child.GetComponentInChildren <KButton>();
                    if ((Object)componentInChildren != (Object)null)
                    {
                        Text componentInChildren2 = componentInChildren.GetComponentInChildren <Text>();
                        if ((Object)componentInChildren2 != (Object)null && i == itemIdx)
                        {
                            ActivateTabArtwork(itemIdx);
                        }
                    }
                    KToggle component = child.GetComponent <KToggle>();
                    if ((Object)component != (Object)null)
                    {
                        ActivateTabArtwork(itemIdx);
                        if (i == itemIdx)
                        {
                            component.Select();
                        }
                        else
                        {
                            component.Deselect();
                        }
                    }
                }
            }
        }
    }
 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);
             }
         }
     }
 }
示例#27
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);
             }
         }
     }
 }
 public virtual void RefreshButtons()
 {
     if (buttonObjects != null)
     {
         for (int i = 0; i < buttonObjects.Length; i++)
         {
             UnityEngine.Object.Destroy(buttonObjects[i]);
         }
         buttonObjects = null;
     }
     if (buttons != null && buttons.Count != 0)
     {
         buttonObjects = new GameObject[buttons.Count];
         for (int j = 0; j < buttons.Count; j++)
         {
             ButtonInfo buttonInfo = buttons[j];
             if (buttonInfo != null)
             {
                 GameObject binstance = UnityEngine.Object.Instantiate(buttonPrefab, Vector3.zero, Quaternion.identity);
                 buttonInfo.buttonGo = binstance;
                 buttonObjects[j]    = binstance;
                 Transform transform = null;
                 transform = ((!((UnityEngine.Object)buttonParent != (UnityEngine.Object)null)) ? base.transform : buttonParent);
                 binstance.transform.SetParent(transform, false);
                 binstance.SetActive(true);
                 binstance.name = buttonInfo.text + "Button";
                 KButton component = binstance.GetComponent <KButton>();
                 if ((UnityEngine.Object)component != (UnityEngine.Object)null && buttonInfo.onClick != null)
                 {
                     component.onClick += buttonInfo.onClick;
                 }
                 Image image = null;
                 if ((bool)component)
                 {
                     image = component.fgImage;
                 }
                 if ((UnityEngine.Object)image != (UnityEngine.Object)null)
                 {
                     image.gameObject.SetActive(false);
                     Sprite[] array = icons;
                     foreach (Sprite sprite in array)
                     {
                         if ((UnityEngine.Object)sprite != (UnityEngine.Object)null && sprite.name == buttonInfo.iconName)
                         {
                             image.sprite = sprite;
                             image.gameObject.SetActive(true);
                             break;
                         }
                     }
                 }
                 if ((UnityEngine.Object)buttonInfo.texture != (UnityEngine.Object)null)
                 {
                     RawImage componentInChildren = binstance.GetComponentInChildren <RawImage>();
                     if ((UnityEngine.Object)componentInChildren != (UnityEngine.Object)null)
                     {
                         componentInChildren.gameObject.SetActive(true);
                         componentInChildren.texture = buttonInfo.texture;
                     }
                 }
                 ToolTip componentInChildren2 = binstance.GetComponentInChildren <ToolTip>();
                 if (buttonInfo.text != null && buttonInfo.text != string.Empty && (UnityEngine.Object)componentInChildren2 != (UnityEngine.Object)null)
                 {
                     componentInChildren2.toolTip = buttonInfo.GetTooltipText();
                     LocText componentInChildren3 = binstance.GetComponentInChildren <LocText>();
                     if ((UnityEngine.Object)componentInChildren3 != (UnityEngine.Object)null)
                     {
                         componentInChildren3.text = buttonInfo.text;
                     }
                 }
                 if (buttonInfo.onToolTip != null)
                 {
                     componentInChildren2.OnToolTip = buttonInfo.onToolTip;
                 }
                 System.Action onClick = buttonInfo.onClick;
                 System.Action value   = delegate
                 {
                     onClick.Signal();
                     if (!keepMenuOpen && (UnityEngine.Object) this != (UnityEngine.Object)null)
                     {
                         Deactivate();
                     }
                     if ((UnityEngine.Object)binstance != (UnityEngine.Object)null)
                     {
                         KToggle component3 = binstance.GetComponent <KToggle>();
                         if ((UnityEngine.Object)component3 != (UnityEngine.Object)null)
                         {
                             SelectToggle(component3);
                         }
                     }
                 };
                 KToggle componentInChildren4 = binstance.GetComponentInChildren <KToggle>();
                 if ((UnityEngine.Object)componentInChildren4 != (UnityEngine.Object)null)
                 {
                     componentInChildren4.onRefresh += buttonInfo.onRefresh;
                     ToggleGroup component2 = GetComponent <ToggleGroup>();
                     if ((UnityEngine.Object)component2 == (UnityEngine.Object)null)
                     {
                         component2 = externalToggleGroup;
                     }
                     componentInChildren4.group    = component2;
                     componentInChildren4.onClick += value;
                     Navigation navigation = componentInChildren4.navigation;
                     navigation.mode = (automaticNavigation ? Navigation.Mode.Automatic : Navigation.Mode.None);
                     componentInChildren4.navigation = navigation;
                 }
                 else
                 {
                     KBasicToggle componentInChildren5 = binstance.GetComponentInChildren <KBasicToggle>();
                     if ((UnityEngine.Object)componentInChildren5 != (UnityEngine.Object)null)
                     {
                         componentInChildren5.onClick += value;
                     }
                 }
                 if ((UnityEngine.Object)component != (UnityEngine.Object)null)
                 {
                     component.isInteractable = buttonInfo.isInteractable;
                 }
                 buttonInfo.onCreate.Signal(buttonInfo);
             }
         }
         Update();
     }
 }
    public void Initialize(ComplexFabricator target)
    {
        if ((Object)target == (Object)null)
        {
            Debug.LogError("ComplexFabricator provided was null.");
        }
        else
        {
            targetFab = target;
            base.gameObject.SetActive(true);
            recipeMap = new Dictionary <GameObject, ComplexRecipe>();
            recipeToggles.ForEach(delegate(GameObject rbi)
            {
                Object.Destroy(rbi.gameObject);
            });
            recipeToggles.Clear();
            GridLayoutGroup component = recipeGrid.GetComponent <GridLayoutGroup>();
            switch (targetFab.sideScreenStyle)
            {
            case StyleSetting.ListResult:
            case StyleSetting.ListInput:
            case StyleSetting.ListInputOutput:
            {
                component.constraintCount = 1;
                GridLayoutGroup gridLayoutGroup2 = component;
                Vector2         cellSize2        = component.cellSize;
                gridLayoutGroup2.cellSize = new Vector2(262f, cellSize2.y);
                break;
            }

            case StyleSetting.ClassicFabricator:
                component.constraintCount       = 128;
                component.cellSize              = new Vector2(78f, 96f);
                buttonScrollContainer.minHeight = 100f;
                break;

            case StyleSetting.ListQueueHybrid:
                component.constraintCount       = 1;
                component.cellSize              = new Vector2(264f, 64f);
                buttonScrollContainer.minHeight = 66f;
                break;

            default:
            {
                component.constraintCount = 3;
                GridLayoutGroup gridLayoutGroup = component;
                Vector2         cellSize        = component.cellSize;
                gridLayoutGroup.cellSize = new Vector2(116f, cellSize.y);
                break;
            }
            }
            int             num     = 0;
            ComplexRecipe[] recipes = targetFab.GetRecipes();
            ComplexRecipe[] array   = recipes;
            foreach (ComplexRecipe recipe in array)
            {
                bool flag = false;
                if (DebugHandler.InstantBuildMode)
                {
                    flag = true;
                }
                else if (recipe.RequiresTechUnlock() && recipe.IsRequiredTechUnlocked())
                {
                    flag = true;
                }
                else if (target.GetRecipeQueueCount(recipe) != 0)
                {
                    flag = true;
                }
                else if (AnyRecipeRequirementsDiscovered(recipe))
                {
                    flag = true;
                }
                else if (HasAnyRecipeRequirements(recipe))
                {
                    flag = true;
                }
                if (flag)
                {
                    num++;
                    Tuple <Sprite, Color> uISprite  = Def.GetUISprite(recipe.ingredients[0].material, "ui", false);
                    Tuple <Sprite, Color> uISprite2 = Def.GetUISprite(recipe.results[0].material, "ui", false);
                    KToggle    newToggle            = null;
                    GameObject entryGO;
                    switch (target.sideScreenStyle)
                    {
                    case StyleSetting.ListInputOutput:
                    case StyleSetting.GridInputOutput:
                    {
                        newToggle = Util.KInstantiateUI <KToggle>(recipeButtonMultiple, recipeGrid, false);
                        entryGO   = newToggle.gameObject;
                        HierarchyReferences           component2  = newToggle.GetComponent <HierarchyReferences>();
                        ComplexRecipe.RecipeElement[] ingredients = recipe.ingredients;
                        foreach (ComplexRecipe.RecipeElement recipeElement in ingredients)
                        {
                            GameObject gameObject = Util.KInstantiateUI(component2.GetReference("FromIconPrefab").gameObject, component2.GetReference("FromIcons").gameObject, true);
                            gameObject.GetComponent <Image>().sprite = Def.GetUISprite(recipeElement.material, "ui", false).first;
                            gameObject.GetComponent <Image>().color  = Def.GetUISprite(recipeElement.material, "ui", false).second;
                            gameObject.gameObject.name = recipeElement.material.Name;
                        }
                        ComplexRecipe.RecipeElement[] results = recipe.results;
                        foreach (ComplexRecipe.RecipeElement recipeElement2 in results)
                        {
                            GameObject gameObject2 = Util.KInstantiateUI(component2.GetReference("ToIconPrefab").gameObject, component2.GetReference("ToIcons").gameObject, true);
                            gameObject2.GetComponent <Image>().sprite = Def.GetUISprite(recipeElement2.material, "ui", false).first;
                            gameObject2.GetComponent <Image>().color  = Def.GetUISprite(recipeElement2.material, "ui", false).second;
                            gameObject2.gameObject.name = recipeElement2.material.Name;
                        }
                        break;
                    }

                    case StyleSetting.ListQueueHybrid:
                    {
                        newToggle = Util.KInstantiateUI <KToggle>(recipeButtonQueueHybrid, recipeGrid, false);
                        entryGO   = newToggle.gameObject;
                        recipeMap.Add(entryGO, recipe);
                        Image image = entryGO.GetComponentsInChildrenOnly <Image>()[2];
                        if (recipe.nameDisplay == ComplexRecipe.RecipeNameDisplay.Ingredient)
                        {
                            image.sprite = uISprite.first;
                            image.color  = uISprite.second;
                        }
                        else
                        {
                            image.sprite = uISprite2.first;
                            image.color  = uISprite2.second;
                        }
                        entryGO.GetComponentInChildren <LocText>().text = recipe.GetUIName();
                        bool flag2 = HasAllRecipeRequirements(recipe);
                        image.material = ((!flag2) ? Assets.UIPrefabs.TableScreenWidgets.DesaturatedUIMaterial : Assets.UIPrefabs.TableScreenWidgets.DefaultUIMaterial);
                        RefreshQueueCountDisplay(entryGO, targetFab);
                        entryGO.GetComponent <HierarchyReferences>().GetReference <MultiToggle>("DecrementButton").onClick = delegate
                        {
                            target.DecrementRecipeQueueCount(recipe, false);
                            RefreshQueueCountDisplay(entryGO, target);
                        };
                        entryGO.GetComponent <HierarchyReferences>().GetReference <MultiToggle>("IncrementButton").onClick = delegate
                        {
                            target.IncrementRecipeQueueCount(recipe);
                            RefreshQueueCountDisplay(entryGO, target);
                        };
                        entryGO.gameObject.SetActive(true);
                        break;
                    }

                    default:
                    {
                        newToggle = Util.KInstantiateUI <KToggle>(recipeButton, recipeGrid, false);
                        entryGO   = newToggle.gameObject;
                        Image componentInChildrenOnly = newToggle.gameObject.GetComponentInChildrenOnly <Image>();
                        if (target.sideScreenStyle == StyleSetting.GridInput || target.sideScreenStyle == StyleSetting.ListInput)
                        {
                            componentInChildrenOnly.sprite = uISprite.first;
                            componentInChildrenOnly.color  = uISprite.second;
                        }
                        else
                        {
                            componentInChildrenOnly.sprite = uISprite2.first;
                            componentInChildrenOnly.color  = uISprite2.second;
                        }
                        break;
                    }
                    }
                    if (targetFab.sideScreenStyle == StyleSetting.ClassicFabricator)
                    {
                        newToggle.GetComponentInChildren <LocText>().text = recipe.results[0].material.ProperName();
                    }
                    else if (targetFab.sideScreenStyle != StyleSetting.ListQueueHybrid)
                    {
                        newToggle.GetComponentInChildren <LocText>().text = string.Format(UI.UISIDESCREENS.REFINERYSIDESCREEN.RECIPE_FROM_TO_WITH_NEWLINES, recipe.ingredients[0].material.ProperName(), recipe.results[0].material.ProperName());
                    }
                    ToolTip component3 = entryGO.GetComponent <ToolTip>();
                    component3.toolTipPosition       = ToolTip.TooltipPosition.Custom;
                    component3.parentPositionAnchor  = new Vector2(0f, 0.5f);
                    component3.tooltipPivot          = new Vector2(1f, 1f);
                    component3.tooltipPositionOffset = new Vector2(-24f, 20f);
                    component3.ClearMultiStringTooltip();
                    component3.AddMultiStringTooltip(recipe.GetUIName(), styleTooltipHeader);
                    component3.AddMultiStringTooltip(recipe.description, styleTooltipBody);
                    newToggle.onClick += delegate
                    {
                        ToggleClicked(newToggle);
                    };
                    entryGO.SetActive(true);
                    recipeToggles.Add(entryGO);
                }
            }
            if (recipeToggles.Count > 0)
            {
                LayoutElement component4 = buttonScrollContainer.GetComponent <LayoutElement>();
                float         num2       = (float)num;
                Vector2       sizeDelta  = recipeButtonQueueHybrid.rectTransform().sizeDelta;
                component4.minHeight = Mathf.Min(451f, 2f + num2 * sizeDelta.y);
                subtitleLabel.SetText(UI.UISIDESCREENS.FABRICATORSIDESCREEN.SUBTITLE);
                noRecipesDiscoveredLabel.gameObject.SetActive(false);
            }
            else
            {
                subtitleLabel.SetText(UI.UISIDESCREENS.FABRICATORSIDESCREEN.NORECIPEDISCOVERED);
                noRecipesDiscoveredLabel.SetText(UI.UISIDESCREENS.FABRICATORSIDESCREEN.NORECIPEDISCOVERED_BODY);
                noRecipesDiscoveredLabel.gameObject.SetActive(true);
                LayoutElement component5 = buttonScrollContainer.GetComponent <LayoutElement>();
                Vector2       sizeDelta2 = noRecipesDiscoveredLabel.rectTransform.sizeDelta;
                component5.minHeight = sizeDelta2.y + 10f;
            }
            RefreshIngredientAvailabilityVis();
        }
    }
示例#30
0
        protected override void OnPrefabInit()
        {
            Log.Spam($"OnPrefabInit");

            base.OnPrefabInit();

            titleKey = "STRINGS.UI.UISIDESCREENS.COMBO_SENSOR_SIDESCREEN.TITLE";

            var sideScreens = Traverse.Create(DetailsScreen.Instance).Field <List <DetailsScreen.SideScreenRef> >("sideScreens").Value;

            if (sideScreens == null)
            {
                Log.Error("No sideScreens");
                return;
            }

            Traverse thresholdSwitchSideScreen = null;

            foreach (var sideScreen in sideScreens)
            {
                var component = sideScreen.screenPrefab?.GetComponent <ThresholdSwitchSideScreen>();
                if (component != null)
                {
                    thresholdSwitchSideScreen = Traverse.Create(component);
                    break;
                }
            }
            if (thresholdSwitchSideScreen == null)
            {
                Log.Error("No ThresholdSwitchSideScreen");
                return;
            }

            var locText         = thresholdSwitchSideScreen.Field <LocText>("currentValue").Value;
            var aboveToggle     = thresholdSwitchSideScreen.Field <KToggle>("aboveToggle").Value;
            var belowToggle     = thresholdSwitchSideScreen.Field <KToggle>("belowToggle").Value;
            var thresholdSlider = thresholdSwitchSideScreen.Field <NonLinearSlider>("thresholdSlider").Value;
            var numberInput     = thresholdSwitchSideScreen.Field <KNumberInputField>("numberInput").Value;

            var dummyPanel = Gui.CreatePanel();

            var mainPanel = Gui.CreatePanel();

            mainPanel.FindOrAddComponent <VerticalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);

            {
                var groupPanel = Gui.CreatePanel(parent: mainPanel);
                groupPanel.GetComponent <Image>().color = new Color(0, 0, 0, 0.1f);
                groupPanel.FindOrAddComponent <VerticalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);

                temperatureCurrent = Gui.Create <LocText>(prefab: locText.gameObject, parent: groupPanel);
                temperatureCurrent.FindOrAddComponent <LayoutElement>().minHeight = 20;

                var buttonPanel = Gui.CreatePanel(parent: groupPanel);
                buttonPanel.FindOrAddComponent <HorizontalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);
                temperatureBelow = Gui.Create <KToggle>(prefab: belowToggle.gameObject, parent: buttonPanel);
                temperatureAbove = Gui.Create <KToggle>(prefab: aboveToggle.gameObject, parent: buttonPanel);

                temperatureSlider = Gui.Create <NonLinearSlider>(prefab: thresholdSlider.gameObject, parent: groupPanel);

                temperatureInput = Gui.Create <KNumberInputField>(prefab: numberInput.gameObject, parent: groupPanel);
                temperatureInput.FindOrAddComponent <LayoutElement>().minHeight = 30;
                temperatureInput.transform.Find("UnitsLabel")?.DeleteObject();
            }

            Gui.CreatePanel(parent: mainPanel).FindOrAddComponent <LayoutElement>().minHeight = 5;

            {
                var groupPanel = Gui.CreatePanel(parent: mainPanel);
                groupPanel.GetComponent <Image>().color = new Color(0, 0, 0, 0.1f);
                groupPanel.FindOrAddComponent <VerticalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);

                massCurrent = Gui.Create <LocText>(prefab: locText.gameObject, parent: groupPanel);
                massCurrent.FindOrAddComponent <LayoutElement>().minHeight = 20;

                var buttonPanel = Gui.CreatePanel(parent: groupPanel);
                buttonPanel.FindOrAddComponent <HorizontalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);
                massBelow = Gui.Create <KToggle>(prefab: belowToggle.gameObject, parent: buttonPanel);
                massAbove = Gui.Create <KToggle>(prefab: aboveToggle.gameObject, parent: buttonPanel);

                massSlider = Gui.Create <NonLinearSlider>(prefab: thresholdSlider.gameObject, parent: groupPanel);

                massInput = Gui.Create <KNumberInputField>(prefab: numberInput.gameObject, parent: groupPanel);
                massInput.FindOrAddComponent <LayoutElement>().minHeight = 30;
                massInput.transform.Find("UnitsLabel")?.DeleteObject();
            }

            Gui.CreatePanel(parent: mainPanel).FindOrAddComponent <LayoutElement>().minHeight = 5;

            {
                var groupPanel = Gui.CreatePanel(parent: mainPanel);
                groupPanel.GetComponent <Image>().color = new Color(0, 0, 0, 0.1f);
                groupPanel.FindOrAddComponent <VerticalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);

                germsCurrent = Gui.Create <LocText>(prefab: locText.gameObject, parent: groupPanel);
                germsCurrent.FindOrAddComponent <LayoutElement>().minHeight = 20;

                var buttonPanel = Gui.CreatePanel(parent: groupPanel);
                buttonPanel.FindOrAddComponent <HorizontalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);
                germsBelow = Gui.Create <KToggle>(prefab: belowToggle.gameObject, parent: buttonPanel);
                germsAbove = Gui.Create <KToggle>(prefab: aboveToggle.gameObject, parent: buttonPanel);

                germsSlider = Gui.Create <NonLinearSlider>(prefab: thresholdSlider.gameObject, parent: groupPanel);

                germsInput = Gui.Create <KNumberInputField>(prefab: numberInput.gameObject, parent: groupPanel);
                germsInput.FindOrAddComponent <LayoutElement>().minHeight = 30;
                germsInput.transform.Find("UnitsLabel")?.DeleteObject();

                DumpTree(germsInput.gameObject);
            }

            Gui.CreatePanel(parent: mainPanel).FindOrAddComponent <LayoutElement>().minHeight = 5;

            {
                var groupPanel = Gui.CreatePanel(parent: mainPanel);
                groupPanel.GetComponent <Image>().color = new Color(0, 0, 0, 0.1f);
                groupPanel.FindOrAddComponent <VerticalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);

                materialCurrent = Gui.Create <LocText>(prefab: locText.gameObject, parent: groupPanel);
                materialCurrent.FindOrAddComponent <LayoutElement>().minHeight = 20;

                var buttonPanel = Gui.CreatePanel(parent: groupPanel);
                buttonPanel.FindOrAddComponent <HorizontalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);
                materialChecked   = Gui.Create <KToggle>(prefab: belowToggle.gameObject, parent: buttonPanel);
                materialUnchecked = Gui.Create <KToggle>(prefab: aboveToggle.gameObject, parent: buttonPanel);
            }

            gameObject.FindOrAddComponent <VerticalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5);
            LayoutElement layoutElement = gameObject.FindOrAddComponent <LayoutElement>();

            layoutElement.minWidth        = 150;
            layoutElement.preferredWidth  = 150;
            layoutElement.minHeight       = 450;
            layoutElement.preferredHeight = 450;

            mainPanel.transform.SetParent(gameObject.transform);
            ContentContainer = mainPanel;
        }