Skip to content

Commit

Permalink
feature: adds the single move tool (#218)
Browse files Browse the repository at this point in the history
* feature: move tool

adds the move tool that allows you to move single objects

* prettify

* removes unused
  • Loading branch information
mc-oofert authored Jul 31, 2023
1 parent 82b5a28 commit 49956b5
Show file tree
Hide file tree
Showing 11 changed files with 1,209 additions and 979 deletions.
2 changes: 2 additions & 0 deletions internal/app/ui/cpwsarea/wsmap/pmap/canvas_overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (p *PaneMap) processCanvasOverlayTools() {
colTileBorder = overlay.ColorToolSelectTileBorder
case tools.TNPick:
colInstance = overlay.ColorToolPickInstance
case tools.TNMove:
colInstance = overlay.ColorToolPickInstance
case tools.TNDelete:
if !tools.Selected().AltBehaviour() {
colInstance = overlay.ColorToolDeleteInstance
Expand Down
12 changes: 12 additions & 0 deletions internal/app/ui/cpwsarea/wsmap/pmap/panel_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
tools.TNAdd,
tools.TNFill,
tools.TNGrab,
tools.TNMove,
tSeparator,
tools.TNPick,
tools.TNDelete,
Expand Down Expand Up @@ -63,6 +64,17 @@ var (
w.Text("Select the area / Move the selection with visible objects inside"),
},
},
tools.TNMove: {
btnIcon: icon.Shrink,
tooltip: w.Layout{
w.AlignTextToFramePadding(),
w.Text(tools.TNMove),
w.SameLine(),
w.TextFrame("4"),
w.Separator(),
w.Text("Move a singular object"),
},
},
tools.TNPick: {
btnIcon: icon.EyeDropper,
tooltip: w.Layout{
Expand Down
6 changes: 6 additions & 0 deletions internal/app/ui/cpwsarea/wsmap/pmap/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func (p *PaneMap) addShortcuts() {
FirstKeyAlt: glfw.KeyKP3,
Action: selectSelectTool,
})
p.shortcuts.Add(shortcut.Shortcut{
Name: "pmap#selectMoveTool",
FirstKey: glfw.Key4,
FirstKeyAlt: glfw.KeyKP4,
Action: selectMoveTool,
})

p.shortcuts.Add(shortcut.Shortcut{
Name: "pmap#doDeselectAll",
Expand Down
4 changes: 4 additions & 0 deletions internal/app/ui/cpwsarea/wsmap/pmap/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ func selectFillTool() {
func selectSelectTool() {
tools.SetSelected(tools.TNGrab)
}

func selectMoveTool() {
tools.SetSelected(tools.TNMove)
}
74 changes: 74 additions & 0 deletions internal/app/ui/cpwsarea/wsmap/tools/move.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package tools

import (
"sdmm/internal/dmapi/dm"
"sdmm/internal/dmapi/dmmap"
"sdmm/internal/dmapi/dmmap/dmminstance"
"sdmm/internal/util"
)

// ToolPick can be used move a single object.
type ToolMove struct {
tool
instance *dmminstance.Instance
lastTile *dmmap.Tile
}

func (ToolMove) Name() string {
return TNMove
}

func newMove() *ToolMove {
return &ToolMove{}
}

func (t *ToolMove) Stale() bool {
return t.instance == nil
}

func (ToolMove) AltBehaviour() bool {
return false
}

func (t *ToolMove) onStart(util.Point) {
if hoveredInstance := ed.HoveredInstance(); hoveredInstance != nil {
ed.InstanceSelect(hoveredInstance)
t.instance = hoveredInstance
}
}

func (t *ToolMove) onMove(coord util.Point) {
if t.instance != nil {
prefab := t.instance.Prefab()
if t.lastTile != nil {
t.lastTile.InstancesRegenerate() //should stop some issues
}
t.lastTile = ed.Dmm().GetTile(coord)
ed.InstanceDelete(t.instance)
t.lastTile.InstancesAdd(prefab)
t.lastTile.InstancesRegenerate()
for _, found := range t.lastTile.Instances() {
if found.Prefab().Id() == prefab.Id() {
t.instance = found
break
}
}
ed.UpdateCanvasByCoords([]util.Point{coord})
}
}

func (t *ToolMove) onStop(util.Point) {
if t.instance != nil {
//remove other turfs if we moved a turf
if dm.IsPath(t.instance.Prefab().Path(), "/turf") {
for _, found := range t.lastTile.Instances() {
if dm.IsPath(found.Prefab().Path(), "/turf") && found != t.instance {
ed.InstanceDelete(found)
}
}
}
t.instance = nil
t.lastTile = nil
go ed.CommitChanges("Moved Prefab")
}
}
2 changes: 2 additions & 0 deletions internal/app/ui/cpwsarea/wsmap/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
TNAdd = "Add"
TNFill = "Fill"
TNGrab = "Grab"
TNMove = "Move"
TNPick = "Pick"
TNDelete = "Delete"
TNReplace = "Replace"
Expand Down Expand Up @@ -73,6 +74,7 @@ var (
TNAdd: newAdd(),
TNFill: newFill(),
TNGrab: newGrab(),
TNMove: newMove(),
TNPick: newPick(),
TNDelete: newDelete(),
TNReplace: newReplace(),
Expand Down
1 change: 1 addition & 0 deletions internal/imguiext/icon/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ const (
KoFi = "\ue91d"
Repeat = "\ue91e"
AccessTime = "\ue91f"
Shrink = "\ue98a"
)
112 changes: 40 additions & 72 deletions internal/rsc/font/icons/icomoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/rsc/font/icons/icomoon.ttf
Binary file not shown.
Binary file modified internal/rsc/font/icons/icomoon.woff
Binary file not shown.
Loading

0 comments on commit 49956b5

Please sign in to comment.