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_CREATE_EMPTY), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME); } else { FileNameDialog blueprintNameDialog = Utilities.CreateBlueprintRenameDialog(); SpeedControlScreen.Instance.Pause(false); blueprintNameDialog.onConfirm = delegate(string blueprintName) { blueprint.Rename(blueprintName.Substring(0, blueprintName.Length - 4)); SpeedControlScreen.Instance.Unpause(false); blueprintNameDialog.Deactivate(); blueprint.Write(); PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_CREATE_CREATED), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME); BlueprintsState.LoadedBlueprints.Add(blueprint); BlueprintsState.SelectedBlueprintIndex = BlueprintsState.LoadedBlueprints.Count - 1; }; blueprintNameDialog.onCancel = delegate { SpeedControlScreen.Instance.Unpause(false); PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_CREATE_CANCELLED), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME); blueprintNameDialog.Deactivate(); }; blueprintNameDialog.Activate(); } } }
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_CREATE_EMPTY), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME); } else { void onConfirmDelegate(string blueprintName, FileNameDialog parent) { blueprint.Rename(blueprintName, false); blueprint.SetFolder(""); SpeedControlScreen.Instance.Unpause(false); PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_CREATE_CREATED), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME); parent.Deactivate(); } FileNameDialog blueprintNameDialog = UIUtilities.CreateTextDialog(Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_NAMEBLUEPRINT_TITLE), false, onConfirmDelegate); SpeedControlScreen.Instance.Pause(false); blueprintNameDialog.onCancel = delegate { SpeedControlScreen.Instance.Unpause(false); PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, Strings.Get(BlueprintsStrings.STRING_BLUEPRINTS_CREATE_CANCELLED), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.BLUEPRINTS_CONFIG_FXTIME); blueprintNameDialog.Deactivate(); }; blueprintNameDialog.Activate(); } } }
static void OnConfirmDelegate(string blueprintFolder, FileNameDialog parent) { string newFolder = blueprintFolder.Trim(' ', '/', '\\', Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (newFolder == BlueprintsState.SelectedBlueprint.Folder) { PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, BlueprintsStrings.STRING_BLUEPRINTS_USE_FOLDERBLUEPRINT_NA, null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.Options.FXTime); } else { string blueprintName = BlueprintsState.SelectedBlueprint.FriendlyName; BlueprintsState.SelectedBlueprint.SetFolder(newFolder); PopFXManager.Instance.SpawnFX(BlueprintsAssets.BLUEPRINTS_CREATE_ICON_SPRITE, string.Format(BlueprintsStrings.STRING_BLUEPRINTS_USE_MOVEDBLUEPRINT, blueprintName, newFolder), null, PlayerController.GetCursorPos(KInputManager.GetMousePos()), BlueprintsAssets.Options.FXTime); } SpeedControlScreen.Instance.Unpause(false); parent.Deactivate(); }
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(); } } } }