Ejemplo n.º 1
0
 /// <summary>
 /// Loads the codex on a background thread, logging any errors.
 /// </summary>
 private static void LoadCodex()
 {
     try {
         CodexCache.CodexCacheInit();
     } catch (Exception e) {
         DebugUtil.LogException(Global.Instance, e.Message, e);
     }
 }
Ejemplo n.º 2
0
        private static void Action(Tag speciesTag, string name, Dictionary <string, CodexEntry> results)
        {
            List <GameObject> brains = Assets.GetPrefabsWithComponent <CreatureBrain>();
            CodexEntry        entry  = new CodexEntry("CREATURES", new List <ContentContainer>()
            {
                new ContentContainer(new List <ICodexWidget>()
                {
                    new CodexSpacer(),
                    new CodexSpacer()
                }, ContentContainer.ContentLayout.Vertical)
            }, name);

            entry.parentId = "CREATURES";
            CodexCache.AddEntry(speciesTag.ToString(), entry, null);
            results.Add(speciesTag.ToString(), entry);
            foreach (GameObject gameObject in brains)
            {
                if (gameObject.GetDef <BabyMonitor.Def>() == null)
                {
                    Sprite     sprite = null;
                    GameObject prefab = Assets.TryGetPrefab((gameObject.PrefabID().ToString() + "Baby"));
                    if (prefab != null)
                    {
                        sprite = Def.GetUISprite(prefab, "ui", false).first;
                    }
                    CreatureBrain component = gameObject.GetComponent <CreatureBrain>();
                    if (component.species == speciesTag)
                    {
                        List <ContentContainer> contentContainerList = new List <ContentContainer>();
                        string symbolPrefix = component.symbolPrefix;
                        Sprite first        = Def.GetUISprite(gameObject, symbolPrefix + "ui", false).first;
                        if ((bool)((UnityEngine.Object)sprite))
                        {
                            Traverse.Create(typeof(CodexEntryGenerator)).Method("GenerateImageContainers", new[] { typeof(Sprite[]), typeof(List <ContentContainer>), typeof(ContentContainer.ContentLayout) })
                            .GetValue(new Sprite[2]
                            {
                                first,
                                sprite
                            }, contentContainerList, ContentContainer.ContentLayout.Horizontal);
                        }
                        else
                        {
                            contentContainerList.Add(new ContentContainer(new List <ICodexWidget>()
                            {
                                new CodexImage(128, 128, first)
                            }, ContentContainer.ContentLayout.Vertical));
                        }

                        Traverse.Create(typeof(CodexEntryGenerator)).Method("GenerateCreatureDescriptionContainers", new[] { typeof(GameObject), typeof(List <ContentContainer>) }).GetValue(gameObject, contentContainerList);
                        entry.subEntries.Add(new SubEntry(component.PrefabID().ToString(), speciesTag.ToString(), contentContainerList, component.GetProperName())
                        {
                            icon      = first,
                            iconColor = UnityEngine.Color.white
                        });
                    }
                }
            }
        }
    private string GetSelectedObjectCodexID()
    {
        string text = string.Empty;
        CellSelectionObject       component  = SelectTool.Instance.selected.GetComponent <CellSelectionObject>();
        BuildingUnderConstruction component2 = SelectTool.Instance.selected.GetComponent <BuildingUnderConstruction>();
        CreatureBrain             component3 = SelectTool.Instance.selected.GetComponent <CreatureBrain>();
        PlantableSeed             component4 = SelectTool.Instance.selected.GetComponent <PlantableSeed>();
        BudUprootedMonitor        component5 = SelectTool.Instance.selected.GetComponent <BudUprootedMonitor>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(component.element.id.ToString());
        }
        else if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(component2.Def.PrefabID);
        }
        else if ((UnityEngine.Object)component3 != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(SelectTool.Instance.selected.PrefabID().ToString());
            text = text.Replace("BABY", string.Empty);
        }
        else if ((UnityEngine.Object)component4 != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(SelectTool.Instance.selected.PrefabID().ToString());
            text = text.Replace("SEED", string.Empty);
        }
        else if ((UnityEngine.Object)component5 != (UnityEngine.Object)null)
        {
            if ((UnityEngine.Object)component5.parentObject.Get() != (UnityEngine.Object)null)
            {
                text = CodexCache.FormatLinkID(component5.parentObject.Get().PrefabID().ToString());
            }
            else if ((UnityEngine.Object)component5.GetComponent <TreeBud>() != (UnityEngine.Object)null)
            {
                text = CodexCache.FormatLinkID(component5.GetComponent <TreeBud>().buddingTrunk.Get().PrefabID().ToString());
            }
        }
        else
        {
            text = CodexCache.FormatLinkID(SelectTool.Instance.selected.PrefabID().ToString());
        }
        if (CodexCache.entries.ContainsKey(text) || CodexCache.FindSubEntry(text) != null)
        {
            return(text);
        }
        return(string.Empty);
    }
Ejemplo n.º 4
0
 private Action <InfoDialogScreen> OpenCodex(string key)
 {
     return(delegate(InfoDialogScreen dialog)
     {
         dialog.Deactivate();
         string entryForLock = CodexCache.GetEntryForLock(key);
         if (entryForLock == null)
         {
             KCrashReporter.Assert(false, "Missing codex entry: " + key);
         }
         else
         {
             ManagementMenu.Instance.OpenCodexToEntry(entryForLock);
         }
     });
 }
Ejemplo n.º 5
0
    public void ChangeArticle(string id, bool playClickSound = false)
    {
        Debug.Assert(id != null);
        if (playClickSound)
        {
            KMonoBehaviour.PlaySound(GlobalAssets.GetSound("HUD_Click", false));
        }
        if (contentContainerPool == null)
        {
            Init();
        }
        SubEntry subEntry = null;

        if (!CodexCache.entries.ContainsKey(id))
        {
            subEntry = null;
            subEntry = CodexCache.FindSubEntry(id);
            if (subEntry != null && !subEntry.disabled)
            {
                id = subEntry.parentEntryID.ToUpper();
            }
        }
        ICodexWidget codexWidget = null;

        CodexCache.entries[id].GetFirstWidget();
        RectTransform rectTransform = null;

        if (subEntry != null)
        {
            foreach (ContentContainer contentContainer2 in CodexCache.entries[id].contentContainers)
            {
                if (contentContainer2 == subEntry.contentContainers[0])
                {
                    codexWidget = contentContainer2.content[0];
                    break;
                }
            }
        }
        if (!CodexCache.entries.ContainsKey(id) || CodexCache.entries[id].disabled)
        {
            id = "PAGENOTFOUND";
        }
        int    num  = 0;
        string text = string.Empty;

        while (contentContainers.transform.childCount > 0)
        {
            while (!string.IsNullOrEmpty(text) && CodexCache.entries[activeEntryID].contentContainers[num].lockID == text)
            {
                num++;
            }
            GameObject gameObject = contentContainers.transform.GetChild(0).gameObject;
            int        num2       = 0;
            while (gameObject.transform.childCount > 0)
            {
                GameObject gameObject2 = gameObject.transform.GetChild(0).gameObject;
                Type       key;
                if (gameObject2.name == "PrefabContentLocked")
                {
                    text = CodexCache.entries[activeEntryID].contentContainers[num].lockID;
                    key  = typeof(CodexContentLockedIndicator);
                }
                else
                {
                    key = CodexCache.entries[activeEntryID].contentContainers[num].content[num2].GetType();
                }
                ContentUIPools[key].ClearElement(gameObject2);
                num2++;
            }
            contentContainerPool.ClearElement(contentContainers.transform.GetChild(0).gameObject);
            num++;
        }
        bool flag = CodexCache.entries[id] is CategoryEntry;

        activeEntryID = id;
        if (CodexCache.entries[id].contentContainers == null)
        {
            CodexCache.entries[id].contentContainers = new List <ContentContainer>();
        }
        bool   flag2 = false;
        string a     = string.Empty;

        for (int i = 0; i < CodexCache.entries[id].contentContainers.Count; i++)
        {
            ContentContainer contentContainer = CodexCache.entries[id].contentContainers[i];
            if (!string.IsNullOrEmpty(contentContainer.lockID) && !Game.Instance.unlocks.IsUnlocked(contentContainer.lockID))
            {
                if (a != contentContainer.lockID)
                {
                    GameObject gameObject3 = contentContainerPool.GetFreeElement(contentContainers.gameObject, true).gameObject;
                    ConfigureContentContainer(contentContainer, gameObject3, flag && flag2);
                    a = contentContainer.lockID;
                    GameObject gameObject4 = ContentUIPools[typeof(CodexContentLockedIndicator)].GetFreeElement(gameObject3, true).gameObject;
                }
            }
            else
            {
                GameObject gameObject3 = contentContainerPool.GetFreeElement(contentContainers.gameObject, true).gameObject;
                ConfigureContentContainer(contentContainer, gameObject3, flag && flag2);
                flag2 = !flag2;
                if (contentContainer.content != null)
                {
                    foreach (ICodexWidget item in contentContainer.content)
                    {
                        GameObject gameObject5 = ContentUIPools[item.GetType()].GetFreeElement(gameObject3, true).gameObject;
                        item.Configure(gameObject5, displayPane, textStyles);
                        if (item == codexWidget)
                        {
                            rectTransform = gameObject5.rectTransform();
                        }
                    }
                }
            }
        }
        string text2 = string.Empty;
        string text3 = id;
        int    num3  = 0;

        while (text3 != CodexCache.FormatLinkID("HOME") && num3 < 10)
        {
            num3++;
            if (text3 != null)
            {
                text2 = ((!(text3 != id)) ? text2.Insert(0, CodexCache.entries[text3].name) : text2.Insert(0, CodexCache.entries[text3].name + " > "));
                text3 = CodexCache.entries[text3].parentId;
            }
            else
            {
                text3 = CodexCache.entries[CodexCache.FormatLinkID("HOME")].id;
                text2 = text2.Insert(0, CodexCache.entries[text3].name + " > ");
            }
        }
        currentLocationText.text = ((!(text2 == string.Empty)) ? text2 : CodexCache.entries["HOME"].name);
        if (history.Count == 0)
        {
            history.Add(activeEntryID);
        }
        else if (history[history.Count - 1] != activeEntryID)
        {
            if (history.Count > 1 && history[history.Count - 2] == activeEntryID)
            {
                history.RemoveAt(history.Count - 1);
            }
            else
            {
                history.Add(activeEntryID);
            }
        }
        if (history.Count > 1)
        {
            backButton.text = UI.FormatAsLink(string.Format(UI.CODEX.BACK_BUTTON, UI.StripLinkFormatting(CodexCache.entries[history[history.Count - 2]].name)), CodexCache.entries[history[history.Count - 2]].id);
        }
        else
        {
            backButton.text = UI.StripLinkFormatting(GameUtil.ColourizeString(Color.grey, string.Format(UI.CODEX.BACK_BUTTON, CodexCache.entries["HOME"].name)));
        }
        if ((UnityEngine.Object)rectTransform != (UnityEngine.Object)null)
        {
            if (scrollToTargetRoutine != null)
            {
                StopCoroutine(scrollToTargetRoutine);
            }
            scrollToTargetRoutine = StartCoroutine(ScrollToTarget(rectTransform));
        }
        else
        {
            displayScrollRect.content.SetLocalPosition(Vector3.zero);
        }
    }
    protected override void OnPrefabInit()
    {
        base.OnPrefabInit();
        Instance = this;
        CodexCache.Init();
        ScheduledUIInstantiation component = GameScreenManager.Instance.ssOverlayCanvas.GetComponent <ScheduledUIInstantiation>();

        instantiator.Instantiate();
        jobsScreen        = instantiator.GetComponentInChildren <JobsTableScreen>(true);
        consumablesScreen = instantiator.GetComponentInChildren <ConsumablesTableScreen>(true);
        vitalsScreen      = instantiator.GetComponentInChildren <VitalsTableScreen>(true);
        starmapScreen     = component.GetInstantiatedObject <StarmapScreen>();
        codexScreen       = instantiator.GetComponentInChildren <CodexScreen>(true);
        scheduleScreen    = instantiator.GetComponentInChildren <ScheduleScreen>(true);
        skillsScreen      = component.GetInstantiatedObject <SkillsScreen>();
        Subscribe(Game.Instance.gameObject, 288942073, OnUIClear);
        consumablesInfo            = new ToggleInfo(UI.CONSUMABLES, "OverviewUI_consumables_icon", null, Action.ManageConsumables, UI.TOOLTIPS.MANAGEMENTMENU_CONSUMABLES, string.Empty);
        vitalsInfo                 = new ToggleInfo(UI.VITALS, "OverviewUI_vitals_icon", null, Action.ManageVitals, UI.TOOLTIPS.MANAGEMENTMENU_VITALS, string.Empty);
        reportsInfo                = new ToggleInfo(UI.REPORT, "OverviewUI_reports_icon", null, Action.ManageReport, UI.TOOLTIPS.MANAGEMENTMENU_DAILYREPORT, string.Empty);
        reportsInfo.prefabOverride = smallPrefab;
        researchInfo               = new ToggleInfo(UI.RESEARCH, "OverviewUI_research_nav_icon", null, Action.ManageResearch, UI.TOOLTIPS.MANAGEMENTMENU_RESEARCH, string.Empty);
        jobsInfo    = new ToggleInfo(UI.JOBS, "OverviewUI_priority_icon", null, Action.ManagePriorities, UI.TOOLTIPS.MANAGEMENTMENU_JOBS, string.Empty);
        skillsInfo  = new ToggleInfo(UI.SKILLS, "OverviewUI_jobs_icon", null, Action.ManageSkills, UI.TOOLTIPS.MANAGEMENTMENU_SKILLS, string.Empty);
        starmapInfo = new ToggleInfo(UI.STARMAP.MANAGEMENT_BUTTON, "OverviewUI_starmap_icon", null, Action.ManageStarmap, UI.TOOLTIPS.MANAGEMENTMENU_STARMAP, string.Empty);
        codexInfo   = new ToggleInfo(UI.CODEX.MANAGEMENT_BUTTON, "OverviewUI_database_icon", null, Action.ManageDatabase, UI.TOOLTIPS.MANAGEMENTMENU_CODEX, string.Empty);
        codexInfo.prefabOverride = smallPrefab;
        scheduleInfo             = new ToggleInfo(UI.SCHEDULE, "OverviewUI_schedule2_icon", null, Action.ManageSchedule, UI.TOOLTIPS.MANAGEMENTMENU_SCHEDULE, string.Empty);
        ScreenInfoMatch.Add(consumablesInfo, new ScreenData
        {
            screen     = consumablesScreen,
            tabIdx     = 3,
            toggleInfo = consumablesInfo
        });
        ScreenInfoMatch.Add(vitalsInfo, new ScreenData
        {
            screen     = vitalsScreen,
            tabIdx     = 2,
            toggleInfo = vitalsInfo
        });
        ScreenInfoMatch.Add(reportsInfo, new ScreenData
        {
            screen     = reportsScreen,
            tabIdx     = 4,
            toggleInfo = reportsInfo
        });
        ScreenInfoMatch.Add(jobsInfo, new ScreenData
        {
            screen     = jobsScreen,
            tabIdx     = 1,
            toggleInfo = jobsInfo
        });
        ScreenInfoMatch.Add(skillsInfo, new ScreenData
        {
            screen     = skillsScreen,
            tabIdx     = 0,
            toggleInfo = skillsInfo
        });
        ScreenInfoMatch.Add(codexInfo, new ScreenData
        {
            screen     = codexScreen,
            tabIdx     = 6,
            toggleInfo = codexInfo
        });
        ScreenInfoMatch.Add(scheduleInfo, new ScreenData
        {
            screen     = scheduleScreen,
            tabIdx     = 7,
            toggleInfo = scheduleInfo
        });
        ScreenInfoMatch.Add(starmapInfo, new ScreenData
        {
            screen     = starmapScreen,
            tabIdx     = 7,
            toggleInfo = starmapInfo
        });
        List <ToggleInfo> list = new List <ToggleInfo>();

        list.Add(vitalsInfo);
        list.Add(consumablesInfo);
        list.Add(scheduleInfo);
        list.Add(jobsInfo);
        list.Add(skillsInfo);
        list.Add(researchInfo);
        list.Add(starmapInfo);
        list.Add(reportsInfo);
        list.Add(codexInfo);
        Setup(list);
        base.onSelect           += OnButtonClick;
        PauseMenuButton.onClick += OnPauseMenuClicked;
        PauseMenuButton.transform.SetAsLastSibling();
        PauseMenuButton.GetComponent <ToolTip>().toolTip = GameUtil.ReplaceHotkeyString(UI.TOOLTIPS.MANAGEMENTMENU_PAUSEMENU, Action.Escape);
        Components.ResearchCenters.OnAdd    += CheckResearch;
        Components.ResearchCenters.OnRemove += CheckResearch;
        Components.RoleStations.OnAdd       += CheckSkills;
        Components.RoleStations.OnRemove    += CheckSkills;
        Game.Instance.Subscribe(-809948329, CheckResearch);
        Game.Instance.Subscribe(-809948329, CheckSkills);
        Components.Telescopes.OnAdd    += CheckStarmap;
        Components.Telescopes.OnRemove += CheckStarmap;
        skillsTooltipDisabled           = UI.TOOLTIPS.MANAGEMENTMENU_REQUIRES_SKILL_STATION;
        skillsTooltip           = GameUtil.ReplaceHotkeyString(UI.TOOLTIPS.MANAGEMENTMENU_SKILLS, Action.ManageSkills);
        researchTooltipDisabled = UI.TOOLTIPS.MANAGEMENTMENU_REQUIRES_RESEARCH;
        researchTooltip         = GameUtil.ReplaceHotkeyString(UI.TOOLTIPS.MANAGEMENTMENU_RESEARCH, Action.ManageResearch);
        starmapTooltipDisabled  = UI.TOOLTIPS.MANAGEMENTMENU_REQUIRES_TELESCOPE;
        starmapTooltip          = GameUtil.ReplaceHotkeyString(UI.TOOLTIPS.MANAGEMENTMENU_STARMAP, Action.ManageStarmap);
        CheckResearch(null);
        CheckSkills(null);
        CheckStarmap(null);
        researchInfo.toggle.soundPlayer.AcceptClickCondition = (() => ResearchAvailable() || activeScreen == ScreenInfoMatch[Instance.researchInfo]);
        KButton[] closeButtons = CloseButtons;
        foreach (KButton kButton in closeButtons)
        {
            kButton.onClick            += CloseAll;
            kButton.soundPlayer.Enabled = false;
        }
        foreach (KToggle toggle in toggles)
        {
            toggle.soundPlayer.toggle_widget_sound_events[0].PlaySound = false;
            toggle.soundPlayer.toggle_widget_sound_events[1].PlaySound = false;
        }
    }