private void DeactivateBuildTools()
    {
        InterfaceTool activeTool = PlayerController.Instance.ActiveTool;

        if ((UnityEngine.Object)activeTool != (UnityEngine.Object)null)
        {
            Type type = activeTool.GetType();
            if (type == typeof(BuildTool) || typeof(BaseUtilityBuildTool).IsAssignableFrom(type) || typeof(PrebuildTool).IsAssignableFrom(type))
            {
                activeTool.DeactivateTool(null);
            }
        }
    }
Пример #2
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);
            }