Middle-click to Pan + Remember Scroll Position
In the editor, clicking and dragging with the middle mouse button will scroll the view of the editor in place of the arrow keys. When entering Play Mode, the original scroll position in the level editor is remembered for when you come back - no more having to scroll from 0,0 each time to get back to where you were working!
This commit is contained in:
parent
489a43ea8c
commit
c2c91e45a9
|
@ -25,10 +25,11 @@ import (
|
||||||
// EditorScene manages the "Edit Level" game mode.
|
// EditorScene manages the "Edit Level" game mode.
|
||||||
type EditorScene struct {
|
type EditorScene struct {
|
||||||
// Configuration for the scene initializer.
|
// Configuration for the scene initializer.
|
||||||
DrawingType enum.DrawingType
|
DrawingType enum.DrawingType
|
||||||
OpenFile bool
|
OpenFile bool
|
||||||
Filename string
|
Filename string
|
||||||
DoodadSize int
|
DoodadSize int
|
||||||
|
RememberScrollPosition render.Point // Play mode remembers it for us
|
||||||
|
|
||||||
UI *EditorUI
|
UI *EditorUI
|
||||||
d *Doodle
|
d *Doodle
|
||||||
|
@ -209,6 +210,11 @@ func (s *EditorScene) setupAsync(d *Doodle) error {
|
||||||
// Recompute the UI Palette window for the level's palette.
|
// Recompute the UI Palette window for the level's palette.
|
||||||
s.UI.FinishSetup(d)
|
s.UI.FinishSetup(d)
|
||||||
|
|
||||||
|
// Scroll the level to the remembered position from when we went
|
||||||
|
// to Play Mode and back. If no remembered position, this is zero
|
||||||
|
// anyway.
|
||||||
|
s.UI.Canvas.ScrollTo(s.RememberScrollPosition)
|
||||||
|
|
||||||
d.Flash("Editor Mode.")
|
d.Flash("Editor Mode.")
|
||||||
if s.DrawingType == enum.LevelDrawing {
|
if s.DrawingType == enum.LevelDrawing {
|
||||||
d.Flash("Press 'P' to playtest this level.")
|
d.Flash("Press 'P' to playtest this level.")
|
||||||
|
@ -221,9 +227,10 @@ func (s *EditorScene) setupAsync(d *Doodle) error {
|
||||||
func (s *EditorScene) Playtest() {
|
func (s *EditorScene) Playtest() {
|
||||||
log.Info("Play Mode, Go!")
|
log.Info("Play Mode, Go!")
|
||||||
s.d.Goto(&PlayScene{
|
s.d.Goto(&PlayScene{
|
||||||
Filename: s.filename,
|
Filename: s.filename,
|
||||||
Level: s.Level,
|
Level: s.Level,
|
||||||
CanEdit: true,
|
CanEdit: true,
|
||||||
|
RememberScrollPosition: s.UI.Canvas.Scroll,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,3 +244,8 @@ func Down(ev *event.State) bool {
|
||||||
func Use(ev *event.State) bool {
|
func Use(ev *event.State) bool {
|
||||||
return ev.Space || ev.KeyDown("q")
|
return ev.Space || ev.KeyDown("q")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MiddleClick of the mouse for panning the level.
|
||||||
|
func MiddleClick(ev *event.State) bool {
|
||||||
|
return ev.Button2
|
||||||
|
}
|
||||||
|
|
|
@ -23,10 +23,11 @@ import (
|
||||||
// PlayScene manages the "Edit Level" game mode.
|
// PlayScene manages the "Edit Level" game mode.
|
||||||
type PlayScene struct {
|
type PlayScene struct {
|
||||||
// Configuration attributes.
|
// Configuration attributes.
|
||||||
Filename string
|
Filename string
|
||||||
Level *level.Level
|
Level *level.Level
|
||||||
CanEdit bool // i.e. you came from the Editor Mode
|
CanEdit bool // i.e. you came from the Editor Mode
|
||||||
HasNext bool // has a next level to load next
|
HasNext bool // has a next level to load next
|
||||||
|
RememberScrollPosition render.Point // for the Editor quality of life
|
||||||
|
|
||||||
// Private variables.
|
// Private variables.
|
||||||
d *Doodle
|
d *Doodle
|
||||||
|
@ -294,8 +295,9 @@ func (s *PlayScene) setupPlayer() {
|
||||||
func (s *PlayScene) EditLevel() {
|
func (s *PlayScene) EditLevel() {
|
||||||
log.Info("Edit Mode, Go!")
|
log.Info("Edit Mode, Go!")
|
||||||
s.d.Goto(&EditorScene{
|
s.d.Goto(&EditorScene{
|
||||||
Filename: s.Filename,
|
Filename: s.Filename,
|
||||||
Level: s.Level,
|
Level: s.Level,
|
||||||
|
RememberScrollPosition: s.RememberScrollPosition,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,10 @@ type Canvas struct {
|
||||||
lastPixel *level.Pixel
|
lastPixel *level.Pixel
|
||||||
|
|
||||||
// We inherit the ui.Widget which manages the width and height.
|
// We inherit the ui.Widget which manages the width and height.
|
||||||
Scroll render.Point // Scroll offset for which parts of canvas are visible.
|
Scroll render.Point // Scroll offset for which parts of canvas are visible.
|
||||||
|
scrollDragging bool // Middle-click to pan scroll
|
||||||
|
scrollStartAt render.Point // Cursor point at beginning of pan
|
||||||
|
scrollWasAt render.Point // copy of Scroll at beginning of pan
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCanvas initializes a Canvas widget.
|
// NewCanvas initializes a Canvas widget.
|
||||||
|
|
|
@ -54,6 +54,24 @@ func (w *Canvas) loopEditorScroll(ev *event.State) error {
|
||||||
w.ScrollBy(scrollBy)
|
w.ScrollBy(scrollBy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Middle click of the mouse to pan the level.
|
||||||
|
// NOTE: returns are below!
|
||||||
|
if keybind.MiddleClick(ev) {
|
||||||
|
if !w.scrollDragging {
|
||||||
|
w.scrollDragging = true
|
||||||
|
w.scrollStartAt = shmem.Cursor
|
||||||
|
w.scrollWasAt = w.Scroll
|
||||||
|
} else {
|
||||||
|
delta := shmem.Cursor.Compare(w.scrollStartAt)
|
||||||
|
w.Scroll = w.scrollWasAt
|
||||||
|
w.Scroll.Subtract(delta)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if w.scrollDragging {
|
||||||
|
w.scrollDragging = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user