Skip to content

Commit

Permalink
feature: add "Jump To Coordinates" (#226)
Browse files Browse the repository at this point in the history
* feature: jump to coordinates

adds a button that allows you to jump to inputted coordinates

* review stuff, hopefully

* linter

* Update action_user.go

* please work
  • Loading branch information
mc-oofert authored Aug 3, 2023
1 parent ad257d5 commit 6d53a42
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/app/action_user.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app

import (
"strconv"

"sdmm/internal/app/prefs"
"sdmm/internal/app/render"
"sdmm/internal/app/ui/cpwsarea/workspace"
Expand All @@ -11,8 +13,13 @@ import (
"sdmm/internal/dmapi/dmmap/dmmdata/dmmprefab"
"sdmm/internal/dmapi/dmmap/dmminstance"
"sdmm/internal/env"
w "sdmm/internal/imguiext/widget"
"sdmm/internal/util"
"sdmm/internal/util/slice"

dial "sdmm/internal/app/ui/dialog"

"github.com/SpaiR/imgui-go"
"github.com/rs/zerolog/log"
"github.com/skratchdot/open-golang/open"
"github.com/sqweek/dialog"
Expand Down Expand Up @@ -349,3 +356,30 @@ func (a *app) DoCheckForUpdates() {
log.Print("do check for updates")
a.checkForUpdatesV(true)
}

// DoOpenJumpWindow opens a window where the user can jump to the inputted coordinates.
func (a *app) DoOpenJumpWindow() {
log.Print("do jump")
var x, y, z string
z = strconv.Itoa(a.CurrentEditor().ActiveLevel())
dial.Open(dial.TypeCustom{
Title: "Jump/Go To Coordinate",
CloseButton: true,
Layout: w.Layout{
w.AlignTextToFramePadding(),
w.InputTextWithHint("##x", "X", &x),
w.InputTextWithHint("##y", "Y", &y),
w.InputTextWithHint("##z", "Z", &z),
w.Button("Jump!", func() {
intX, errX := strconv.Atoi(x)
intY, errY := strconv.Atoi(y)
intZ, errZ := strconv.Atoi(z)
if errX == nil && errY == nil && errZ == nil {
e := a.CurrentEditor()
e.FocusCameraOnPosition(util.Point{X: intX, Y: intY, Z: intZ})
imgui.CloseCurrentPopup()
}
}),
},
})
}
12 changes: 12 additions & 0 deletions internal/app/ui/cpwsarea/wsmap/pmap/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,15 @@ func (e *Editor) FocusCamera(i *dmminstance.Instance) {

e.pMap.SetActiveLevel(relPos.Z)
}

// FocusCameraOnPosition centers the camera on given coordinates.
func (e *Editor) FocusCameraOnPosition(coord util.Point) {
absPos := util.Point{X: (coord.X - 1) * -dmmap.WorldIconSize, Y: (coord.Y - 1) * -dmmap.WorldIconSize, Z: coord.Z}

camera := e.pMap.Canvas().Render().Camera
camera.ShiftX = e.pMap.Size().X/2/camera.Scale + float32(absPos.X)
camera.ShiftY = e.pMap.Size().Y/2/camera.Scale + float32(absPos.Y)

e.pMap.SetActiveLevel(coord.Z)
e.OverlaySetTileFlick(coord)
}
5 changes: 5 additions & 0 deletions internal/app/ui/menu/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type app interface {
DoDelete()
DoSearch()
DoDeselect()
DoOpenJumpWindow()

// View
DoAreaBorders()
Expand Down Expand Up @@ -193,6 +194,10 @@ func (m *Menu) Process() {
Icon(icon.Search).
Enabled(m.app.HasActiveMap()).
Shortcut(platform.KeyModName(), "F"),
w.MenuItem("Go to Coords", m.app.DoOpenJumpWindow).
Icon(icon.Shrink).
Enabled(m.app.HasActiveMap()).
Shortcut(platform.KeyModName(), "G"),
}),

w.Menu("View", w.Layout{
Expand Down
8 changes: 8 additions & 0 deletions internal/app/ui/menu/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ func (m *Menu) addShortcuts() {
Action: m.app.DoSearch,
IsEnabled: m.app.HasActiveMap,
})
m.shortcuts.Add(shortcut.Shortcut{
Name: "menu#DoOpenJumpWindow",
FirstKey: platform.KeyModLeft(),
FirstKeyAlt: platform.KeyModRight(),
SecondKey: glfw.KeyG,
Action: m.app.DoOpenJumpWindow,
IsEnabled: m.app.HasActiveMap,
})

m.shortcuts.Add(shortcut.Shortcut{
Name: "menu#DoMultiZRendering",
Expand Down

0 comments on commit 6d53a42

Please sign in to comment.