protected override void OnSpawn() { base.OnSpawn(); ConsumeMouseScroll = true; initTime = KTime.Instance.UnscaledGameTime; bool flag = UseHotkeyBuildMenu(); if (flag) { Instance = this; productInfoScreen = Util.KInstantiateUI <ProductInfoScreen>(productInfoScreenPrefab, base.gameObject, true); productInfoScreen.rectTransform().pivot = new Vector2(0f, 0f); productInfoScreen.onElementsFullySelected = OnRecipeElementsFullySelected; productInfoScreen.Show(false); buildingsScreen = Util.KInstantiateUI <BuildMenuBuildingsScreen>(buildingsMenuPrefab.gameObject, base.gameObject, true); BuildMenuBuildingsScreen buildMenuBuildingsScreen = buildingsScreen; buildMenuBuildingsScreen.onBuildingSelected = (Action <BuildingDef>)Delegate.Combine(buildMenuBuildingsScreen.onBuildingSelected, new Action <BuildingDef>(OnBuildingSelected)); buildingsScreen.Show(false); Game.Instance.Subscribe(288942073, OnUIClear); Game.Instance.Subscribe(-1190690038, OnBuildToolDeactivated); Initialize(); this.rectTransform().anchoredPosition = Vector2.zero; } else { base.gameObject.SetActive(flag); } }
static void Prefix(ref ProductInfoScreen ___productInfoScreen, bool playSound) { if (!ignoreCategoryClose || playSound) { ___productInfoScreen?.materialSelectionPanel?.PriorityScreen?.ResetPriority(); } }
public static void SetToolPrioritySetting(InterfaceTool tool, PrioritySetting prioritySetting) { if (tool is BuildTool || tool is BaseUtilityBuildTool) { ProductInfoScreen productInfoScreen = null; if (BuildMenu.Instance != null) { productInfoScreen = _buildProductInfoScreen.GetValue(BuildMenu.Instance) as ProductInfoScreen; } else if (PlanScreen.Instance != null) { productInfoScreen = _planProductInfoScreen.GetValue(PlanScreen.Instance) as ProductInfoScreen; } if (productInfoScreen == null) { return; } productInfoScreen.materialSelectionPanel.PriorityScreen.SetScreenPriority(prioritySetting); } else { ToolMenu.Instance.PriorityScreen.SetScreenPriority(prioritySetting); } }
protected override void OnCleanUp() { base.OnCleanUp(); // Clean up everything needed DestroySelector(); if (infoScreen != null) { Destroy(infoScreen); infoScreen = null; } }
public PlanScreen.RequirementsState BuildableState(BuildingDef def) { PlanScreen.RequirementsState result = PlanScreen.RequirementsState.Complete; if (!DebugHandler.InstantBuildMode && !Game.Instance.SandboxModeActive) { if (!Db.Get().TechItems.IsTechItemComplete(def.PrefabID)) { result = PlanScreen.RequirementsState.Tech; } else if (!ProductInfoScreen.MaterialsMet(def.CraftRecipe)) { result = PlanScreen.RequirementsState.Materials; } } return(result); }
protected override void OnPrefabInit() { if (BuildMenu.UseHotkeyBuildMenu()) { base.gameObject.SetActive(false); } else { base.OnPrefabInit(); productInfoScreen = Util.KInstantiateUI <ProductInfoScreen>(productInfoScreenPrefab, recipeInfoScreenParent, true); productInfoScreen.rectTransform().pivot = new Vector2(0f, 0f); productInfoScreen.rectTransform().SetLocalPosition(new Vector3(280f, 0f, 0f)); productInfoScreen.onElementsFullySelected = OnRecipeElementsFullySelected; Game.Instance.Subscribe(-107300940, OnResearchComplete); Game.Instance.Subscribe(1174281782, OnActiveToolChanged); } buildingGroupsRoot.gameObject.SetActive(false); }
protected override void OnActivateTool() { var menu = ToolMenu.Instance.toolParameterMenu; base.OnActivateTool(); // Reuse the "Product Info" asset from BuildMenu to allow resource selection if (infoScreen == null) { infoScreen = Util.KInstantiateUI <ProductInfoScreen>(Traverse.Create( PlanScreen.Instance).GetField <GameObject>("productInfoScreenPrefab"), gameObject, false); infoScreen.Show(false); } ToolMenu.Instance.PriorityScreen.Show(true); // Default to "sweep all" optionState = PToolMode.PopulateMenu(menu, toolOptions); menu.onParametersChanged += UpdateViewMode; UpdateViewMode(); }
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 GetBuildableStates(bool force_update) { if (Assets.BuildingDefs != null && Assets.BuildingDefs.Count != 0) { if (timeSinceNotificationPing < specialNotificationEmbellishDelay) { timeSinceNotificationPing += Time.unscaledDeltaTime; } if (timeSinceNotificationPing >= notificationPingExpire) { notificationPingCount = 0; } int num = 10; if (force_update) { num = Assets.BuildingDefs.Count; buildable_state_update_idx = 0; } ListPool <HashedString, PlanScreen> .PooledList pooledList = ListPool <HashedString, PlanScreen> .Allocate(); for (int i = 0; i < num; i++) { buildable_state_update_idx = (buildable_state_update_idx + 1) % Assets.BuildingDefs.Count; BuildingDef buildingDef = Assets.BuildingDefs[buildable_state_update_idx]; if (!buildingDef.Deprecated && tagCategoryMap.TryGetValue(buildingDef.Tag, out HashedString value)) { RequirementsState requirementsState = RequirementsState.Complete; if (!DebugHandler.InstantBuildMode && !Game.Instance.SandboxModeActive) { if (!Db.Get().TechItems.IsTechItemComplete(buildingDef.PrefabID)) { requirementsState = RequirementsState.Tech; } else if (!ProductInfoScreen.MaterialsMet(buildingDef.CraftRecipe)) { requirementsState = RequirementsState.Materials; } } if (!buildableDefs.ContainsKey(buildingDef)) { buildableDefs.Add(buildingDef, requirementsState); } else if (buildableDefs[buildingDef] != requirementsState) { buildableDefs[buildingDef] = requirementsState; if ((UnityEngine.Object)productInfoScreen.currentDef == (UnityEngine.Object)buildingDef) { ignoreToolChangeMessages++; productInfoScreen.ClearProduct(false); productInfoScreen.Show(true); productInfoScreen.ConfigureScreen(buildingDef); ignoreToolChangeMessages--; } if (requirementsState == RequirementsState.Complete) { foreach (ToggleInfo item in toggleInfo) { HashedString x = (HashedString)item.userData; if (x == value) { string text = "NotificationPing"; Animator component = item.toggle.GetComponent <Animator>(); if (!component.GetCurrentAnimatorStateInfo(0).IsTag(text) && !pooledList.Contains(value)) { pooledList.Add(value); item.toggle.gameObject.GetComponent <Animator>().Play(text); if (KTime.Instance.UnscaledGameTime - initTime > 1.5f) { if (timeSinceNotificationPing >= specialNotificationEmbellishDelay) { string sound = GlobalAssets.GetSound("NewBuildable_Embellishment", false); if (sound != null) { EventInstance instance = SoundEvent.BeginOneShot(sound, SoundListenerController.Instance.transform.GetPosition()); SoundEvent.EndOneShot(instance); } } string sound2 = GlobalAssets.GetSound("NewBuildable", false); if (sound2 != null) { EventInstance instance2 = SoundEvent.BeginOneShot(sound2, SoundListenerController.Instance.transform.GetPosition()); instance2.setParameterValue("playCount", (float)notificationPingCount); SoundEvent.EndOneShot(instance2); } } timeSinceNotificationPing = 0f; notificationPingCount++; } } } } } } } pooledList.Recycle(); } }