Example #1
0
        public static void ReloadBlueprints(bool ingame)
        {
            BlueprintsState.LoadedBlueprints.Clear();
            string[] blueprintFiles = Directory.GetFiles(GetBlueprintDirectory());

            foreach (string blueprintFile in blueprintFiles)
            {
                if (blueprintFile.EndsWith(".blueprint") || blueprintFile.EndsWith(".json"))
                {
                    Blueprint blueprint = new Blueprint(blueprintFile);

                    if (blueprint.ReadBinary() && !blueprint.IsEmpty())
                    {
                        BlueprintsState.LoadedBlueprints.Add(blueprint);
                    }

                    else if (blueprint.ReadJSON() && !blueprint.IsEmpty())
                    {
                        BlueprintsState.LoadedBlueprints.Add(blueprint);
                    }
                }
            }

            if (ingame && BlueprintsState.LoadedBlueprints.Count > 0)
            {
                BlueprintsState.SelectedBlueprintIndex = 0;
                BlueprintsState.ClearVisuals();
                BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), BlueprintsState.SelectedBlueprint);
            }
        }
        protected override void OnActivateTool()
        {
            base.OnActivateTool();

            ToolMenu.Instance.PriorityScreen.Show();

            if (BlueprintsState.HasBlueprints())
            {
                GridCompositor.Instance.ToggleMajor(true);
            }

            if (BlueprintsState.HasBlueprints())
            {
                BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), BlueprintsState.SelectedBlueprint);
                if (visualizer != null)
                {
                    Destroy(visualizer);
                    visualizer = null;
                }
            }

            else
            {
                CreateVisualizer();
            }
        }
Example #3
0
        protected override void OnActivateTool()
        {
            base.OnActivateTool();

            gameObject.AddComponent <UseBlueprintToolInput>();
            gameObject.GetComponent <UseBlueprintToolInput>().ParentTool = this;
            ToolMenu.Instance.PriorityScreen.Show(true);

            if (Input.GetKey(BlueprintsAssets.BLUEPRINTS_INPUT_KEYBIND_USETOOL_RELOAD) || Input.GetKeyUp(BlueprintsAssets.BLUEPRINTS_INPUT_KEYBIND_USETOOL_RELOAD))
            {
                int oldBlueprintCount = BlueprintsState.LoadedBlueprints.Count;
                Utilities.ReloadBlueprints(true);

                int blueprintCountDelta = BlueprintsState.LoadedBlueprints.Count - oldBlueprintCount;
                PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, "Loaded " + Mathf.Abs(blueprintCountDelta) + (blueprintCountDelta >= 0 ? " additional" : " fewer") + " blueprints! (" + BlueprintsState.LoadedBlueprints.Count + " total)", null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_FXTIME * 4);
            }

            if (BlueprintsState.LoadedBlueprints.Count > 0)
            {
                BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), BlueprintsState.SelectedBlueprint);
                if (visualizer != null)
                {
                    Destroy(visualizer);
                    visualizer = null;
                }
            }

            else
            {
                CreateVisualizer();
            }
        }
Example #4
0
        protected override void OnActivateTool()
        {
            base.OnActivateTool();

            gameObject.AddComponent <UseBlueprintToolInput>();
            gameObject.GetComponent <UseBlueprintToolInput>().ParentTool = this;
            ToolMenu.Instance.PriorityScreen.Show(true);

            if (Input.GetKey(BlueprintsAssets.BLUEPRINTS_KEYBIND_USE_RELOAD) || Input.GetKeyUp(BlueprintsAssets.BLUEPRINTS_KEYBIND_USE_RELOAD))
            {
                int oldBlueprintCount = BlueprintsState.LoadedBlueprints.Count;
                Utilities.ReloadBlueprints(true);

                int blueprintCountDelta = BlueprintsState.LoadedBlueprints.Count - oldBlueprintCount;
                PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, string.Format(Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_USE_LOADEDBLUEPRINTS), Mathf.Abs(blueprintCountDelta) + " " + (blueprintCountDelta >= 0 ? Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_USE_LOADEDBLUEPRINTS_ADDITIONAL) : Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_USE_LOADEDBLUEPRINTS_FEWER)), BlueprintsState.LoadedBlueprints.Count), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME * 4);
            }

            if (BlueprintsState.LoadedBlueprints.Count > 0)
            {
                BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), BlueprintsState.SelectedBlueprint);
                if (visualizer != null)
                {
                    Destroy(visualizer);
                    visualizer = null;
                }
            }

            else
            {
                CreateVisualizer();
            }
        }
Example #5
0
        public static void ReloadBlueprints(bool ingame)
        {
            BlueprintsState.LoadedBlueprints.Clear();
            LoadFolder(GetBlueprintDirectory());

            if (ingame && BlueprintsState.HasBlueprints())
            {
                BlueprintsState.ClearVisuals();
                BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), BlueprintsState.SelectedBlueprint);
            }
        }
Example #6
0
        protected override void OnDragComplete(Vector3 cursorDown, Vector3 cursorUp)
        {
            base.OnDragComplete(cursorDown, cursorUp);

            if (hasFocus)
            {
                Grid.PosToXY(cursorDown, out int x0, out int y0);
                Grid.PosToXY(cursorUp, out int x1, out int y1);

                if (x0 > x1)
                {
                    Util.Swap(ref x0, ref x1);
                }

                if (y0 < y1)
                {
                    Util.Swap(ref y0, ref y1);
                }

                Blueprint blueprint = BlueprintsState.CreateBlueprint(new Vector2I(x0, y0), new Vector2I(x1, y1), this);
                if (blueprint.IsEmpty())
                {
                    PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_SNAPSHOT_EMPTY), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME);
                }

                else
                {
                    BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), blueprint);

                    ToolMenu.Instance.toolParameterMenu.gameObject.SetActive(false);
                    ToolMenu.Instance.PriorityScreen.Show(true);

                    gameObject.GetComponent <SnapshotToolHoverCard>().UsingSnapshot = true;

                    gameObject.AddComponent <SnapshotToolInput>();
                    gameObject.GetComponent <SnapshotToolInput>().ParentTool = this;
                    DestroyVisualizer();

                    PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_SNAPSHOT_TAKEN), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME);
                    GridCompositor.Instance.ToggleMajor(true);
                    this.blueprint = blueprint;
                }
            }
        }
Example #7
0
        protected override void OnDragComplete(Vector3 cursorDown, Vector3 cursorUp)
        {
            base.OnDragComplete(cursorDown, cursorUp);

            if (hasFocus)
            {
                Grid.PosToXY(cursorDown, out int x0, out int y0);
                Grid.PosToXY(cursorUp, out int x1, out int y1);

                if (x0 > x1)
                {
                    Util.Swap(ref x0, ref x1);
                }

                if (y0 < y1)
                {
                    Util.Swap(ref y0, ref y1);
                }

                var blueprint1 = BlueprintsState.CreateBlueprint(new Vector2I(x0, y0), new Vector2I(x1, y1), MultiToolParameterMenu.Instance);
                if (blueprint1.IsEmpty())
                {
                    PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, BlueprintsStrings.STRING_BLUEPRINTS_SNAPSHOT_EMPTY, null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.Options.FXTime);
                }

                else
                {
                    BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), blueprint1);

                    MultiToolParameterMenu.Instance.HideMenu();
                    ToolMenu.Instance.PriorityScreen.Show();

                    gameObject.GetComponent <SnapshotToolHoverCard>().UsingSnapshot = true;
                    DestroyVisualizer();

                    PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, BlueprintsStrings.STRING_BLUEPRINTS_SNAPSHOT_TAKEN, null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.Options.FXTime);
                    GridCompositor.Instance.ToggleMajor(true);
                    blueprint = blueprint1;
                }
            }
        }
        public void Update()
        {
            if ((ParentTool?.hasFocus ?? false) && BlueprintsState.LoadedBlueprints.Count > 0)
            {
                bool blueprintChanged = false;

                if (Input.GetKeyDown(BlueprintsAssets.BLUEPRINTS_KEYBIND_USE_RENAME))
                {
                    FileNameDialog blueprintNameDialog = Utilities.CreateBlueprintRenameDialog();
                    SpeedControlScreen.Instance.Pause(false);

                    blueprintNameDialog.onConfirm = delegate(string blueprintName) {
                        BlueprintsState.SelectedBlueprint.Rename(blueprintName.Substring(0, blueprintName.Length - 4));
                        BlueprintsState.SelectedBlueprint.Write();

                        blueprintNameDialog.Deactivate();
                        SpeedControlScreen.Instance.Unpause(false);
                    };

                    blueprintNameDialog.Activate();
                }

                else if (Input.GetKeyDown(BlueprintsAssets.BLUEPRINTS_KEYBIND_USE_DELETE))
                {
                    BlueprintsState.SelectedBlueprint.DeleteFile();
                    BlueprintsState.LoadedBlueprints.RemoveAt(BlueprintsState.SelectedBlueprintIndex);
                    if (BlueprintsState.SelectedBlueprintIndex >= BlueprintsState.LoadedBlueprints.Count)
                    {
                        BlueprintsState.SelectedBlueprintIndex = BlueprintsState.LoadedBlueprints.Count - 1;
                    }

                    blueprintChanged = true;
                }

                if (BlueprintsState.LoadedBlueprints.Count > 1)
                {
                    if (Input.GetKeyDown(BlueprintsAssets.BLUEPRINTS_KEYBIND_USE_CYCLELEFT))
                    {
                        if (--BlueprintsState.SelectedBlueprintIndex < 0)
                        {
                            BlueprintsState.SelectedBlueprintIndex = BlueprintsState.LoadedBlueprints.Count - 1;
                        }

                        blueprintChanged = true;
                    }

                    else if (Input.GetKeyDown(BlueprintsAssets.BLUEPRINTS_KEYBIND_USE_CYCLERIGHT))
                    {
                        if (++BlueprintsState.SelectedBlueprintIndex >= BlueprintsState.LoadedBlueprints.Count)
                        {
                            BlueprintsState.SelectedBlueprintIndex = 0;
                        }

                        blueprintChanged = true;
                    }
                }

                if (blueprintChanged)
                {
                    BlueprintsState.ClearVisuals();

                    if (BlueprintsState.LoadedBlueprints.Count > 0)
                    {
                        BlueprintsState.VisualizeBlueprint(Grid.PosToXY(PlayerController.GetCursorPos(KInputManager.GetMousePos())), BlueprintsState.SelectedBlueprint);
                    }

                    else
                    {
                        UseBlueprintTool.Instance.CreateVisualizer();
                    }
                }
            }
        }