Example #1
0
    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);
        }
    }
Example #2
0
 static void Prefix(ref ProductInfoScreen ___productInfoScreen, bool playSound)
 {
     if (!ignoreCategoryClose || playSound)
     {
         ___productInfoScreen?.materialSelectionPanel?.PriorityScreen?.ResetPriority();
     }
 }
Example #3
0
            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);
                }
            }
Example #4
0
 protected override void OnCleanUp()
 {
     base.OnCleanUp();
     // Clean up everything needed
     DestroySelector();
     if (infoScreen != null)
     {
         Destroy(infoScreen);
         infoScreen = null;
     }
 }
Example #5
0
 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);
 }
Example #6
0
 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);
 }
Example #7
0
        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();
        }
Example #8
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);
            }
Example #9
0
    private void GetBuildableStates(bool force_update)
    {
        if (Assets.BuildingDefs != null && Assets.BuildingDefs.Count != 0)
        {
            if (timeSinceNotificationPing < specialNotificationEmbellishDelay)
            {
                timeSinceNotificationPing += Time.unscaledDeltaTime;
            }
            if (timeSinceNotificationPing >= notificationPingExpire)
            {
                notificationPingCount = 0;
            }
            int num = 10;
            if (force_update)
            {
                num = Assets.BuildingDefs.Count;
                buildable_state_update_idx = 0;
            }
            ListPool <HashedString, PlanScreen> .PooledList pooledList = ListPool <HashedString, PlanScreen> .Allocate();

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