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.
|
||||
type EditorScene struct {
|
||||
// Configuration for the scene initializer.
|
||||
DrawingType enum.DrawingType
|
||||
OpenFile bool
|
||||
Filename string
|
||||
DoodadSize int
|
||||
DrawingType enum.DrawingType
|
||||
OpenFile bool
|
||||
Filename string
|
||||
DoodadSize int
|
||||
RememberScrollPosition render.Point // Play mode remembers it for us
|
||||
|
||||
UI *EditorUI
|
||||
d *Doodle
|
||||
|
@ -209,6 +210,11 @@ func (s *EditorScene) setupAsync(d *Doodle) error {
|
|||
// Recompute the UI Palette window for the level's palette.
|
||||
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.")
|
||||
if s.DrawingType == enum.LevelDrawing {
|
||||
d.Flash("Press 'P' to playtest this level.")
|
||||
|
@ -221,9 +227,10 @@ func (s *EditorScene) setupAsync(d *Doodle) error {
|
|||
func (s *EditorScene) Playtest() {
|
||||
log.Info("Play Mode, Go!")
|
||||
s.d.Goto(&PlayScene{
|
||||
Filename: s.filename,
|
||||
Level: s.Level,
|
||||
CanEdit: true,
|
||||
Filename: s.filename,
|
||||
Level: s.Level,
|
||||
CanEdit: true,
|
||||
RememberScrollPosition: s.UI.Canvas.Scroll,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -244,3 +244,8 @@ func Down(ev *event.State) bool {
|
|||
func Use(ev *event.State) bool {
|
||||
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.
|
||||
type PlayScene struct {
|
||||
// Configuration attributes.
|
||||
Filename string
|
||||
Level *level.Level
|
||||
CanEdit bool // i.e. you came from the Editor Mode
|
||||
HasNext bool // has a next level to load next
|
||||
Filename string
|
||||
Level *level.Level
|
||||
CanEdit bool // i.e. you came from the Editor Mode
|
||||
HasNext bool // has a next level to load next
|
||||
RememberScrollPosition render.Point // for the Editor quality of life
|
||||
|
||||
// Private variables.
|
||||
d *Doodle
|
||||
|
@ -294,8 +295,9 @@ func (s *PlayScene) setupPlayer() {
|
|||
func (s *PlayScene) EditLevel() {
|
||||
log.Info("Edit Mode, Go!")
|
||||
s.d.Goto(&EditorScene{
|
||||
Filename: s.Filename,
|
||||
Level: s.Level,
|
||||
Filename: s.Filename,
|
||||
Level: s.Level,
|
||||
RememberScrollPosition: s.RememberScrollPosition,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,10 @@ type Canvas struct {
|
|||
lastPixel *level.Pixel
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -54,6 +54,24 @@ func (w *Canvas) loopEditorScroll(ev *event.State) error {
|
|||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user