diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 84ad0962ff..96215ae040 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -209,6 +209,16 @@ namespace OpenRA public Hotkey MapScrollLeft = new Hotkey(Keycode.LEFT, Modifiers.None); public Hotkey MapScrollRight = new Hotkey(Keycode.RIGHT, Modifiers.None); + public Hotkey ViewPortBookmarkSaveSlot1 = new Hotkey(Keycode.Q, Modifiers.Ctrl); + public Hotkey ViewPortBookmarkSaveSlot2 = new Hotkey(Keycode.W, Modifiers.Ctrl); + public Hotkey ViewPortBookmarkSaveSlot3 = new Hotkey(Keycode.E, Modifiers.Ctrl); + public Hotkey ViewPortBookmarkSaveSlot4 = new Hotkey(Keycode.R, Modifiers.Ctrl); + + public Hotkey ViewPortBookmarkUseSlot1 = new Hotkey(Keycode.Q, Modifiers.Alt); + public Hotkey ViewPortBookmarkUseSlot2 = new Hotkey(Keycode.W, Modifiers.Alt); + public Hotkey ViewPortBookmarkUseSlot3 = new Hotkey(Keycode.E, Modifiers.Alt); + public Hotkey ViewPortBookmarkUseSlot4 = new Hotkey(Keycode.R, Modifiers.Alt); + public Hotkey PauseKey = new Hotkey(Keycode.PAUSE, Modifiers.None); public Hotkey PlaceBeaconKey = new Hotkey(Keycode.B, Modifiers.None); public Hotkey SellKey = new Hotkey(Keycode.Z, Modifiers.None); diff --git a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs index f6f9d7472b..6676361a04 100644 --- a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs @@ -72,6 +72,29 @@ namespace OpenRA.Mods.Common.Widgets ScrollDirection edgeDirections; World world; WorldRenderer worldRenderer; + WPos?[] viewPortBookmarkSlots = new WPos?[4]; + + void SaveBookmark(int index, WPos position) + { + viewPortBookmarkSlots[index] = position; + } + + void SaveCurrentPositionToBookmark(int index) + { + SaveBookmark(index, worldRenderer.Viewport.CenterPosition); + } + + WPos? JumpToBookmark(int index) + { + return viewPortBookmarkSlots[index]; + } + + void JumpToSavedBookmark(int index) + { + var bookmark = JumpToBookmark(index); + if (bookmark != null) + worldRenderer.Viewport.Center((WPos)bookmark); + } [ObjectCreator.UseCtor] public ViewportControllerWidget(World world, WorldRenderer worldRenderer) @@ -161,7 +184,7 @@ namespace OpenRA.Mods.Common.Widgets public override string GetCursor(int2 pos) { if (!IsJoystickScrolling && - (!Game.Settings.Game.ViewportEdgeScroll || Ui.MouseOverWidget != this)) + (!Game.Settings.Game.ViewportEdgeScroll || Ui.MouseOverWidget != this)) return null; var blockedDirections = worldRenderer.Viewport.GetBlockedDirections(); @@ -308,6 +331,54 @@ namespace OpenRA.Mods.Common.Widgets return true; } + if (key == ks.ViewPortBookmarkSaveSlot1) + { + SaveCurrentPositionToBookmark(0); + return false; + } + + if (key == ks.ViewPortBookmarkSaveSlot2) + { + SaveCurrentPositionToBookmark(1); + return false; + } + + if (key == ks.ViewPortBookmarkSaveSlot3) + { + SaveCurrentPositionToBookmark(2); + return false; + } + + if (key == ks.ViewPortBookmarkSaveSlot4) + { + SaveCurrentPositionToBookmark(3); + return false; + } + + if (key == ks.ViewPortBookmarkUseSlot1) + { + JumpToSavedBookmark(0); + return false; + } + + if (key == ks.ViewPortBookmarkUseSlot2) + { + JumpToSavedBookmark(1); + return false; + } + + if (key == ks.ViewPortBookmarkUseSlot3) + { + JumpToSavedBookmark(2); + return false; + } + + if (key == ks.ViewPortBookmarkUseSlot4) + { + JumpToSavedBookmark(3); + return false; + } + return false; }