Centralize Keybinds, Improve Menus
* pkg/keybinds holds central functions to check global keybinds, like DebugOverlay (F3), Undo (Ctrl-Z), GotoPlay/GotoEdit (p/e), etc. * The Tools menu in the editor mode lists out more options to select various drawing tools (line, pencil, etc.) - and showing the hotkey for each tool.
This commit is contained in:
parent
190d4be1b6
commit
24aef28a0d
|
@ -9,6 +9,7 @@ import (
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/branding"
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
||||||
"git.kirsle.net/apps/doodle/pkg/enum"
|
"git.kirsle.net/apps/doodle/pkg/enum"
|
||||||
|
"git.kirsle.net/apps/doodle/pkg/keybind"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/modal"
|
"git.kirsle.net/apps/doodle/pkg/modal"
|
||||||
"git.kirsle.net/apps/doodle/pkg/native"
|
"git.kirsle.net/apps/doodle/pkg/native"
|
||||||
|
@ -135,21 +136,18 @@ func (d *Doodle) Run() error {
|
||||||
ev.Enter = false
|
ev.Enter = false
|
||||||
} else {
|
} else {
|
||||||
// Global event handlers.
|
// Global event handlers.
|
||||||
if ev.Escape {
|
if keybind.Shutdown(ev) {
|
||||||
d.ConfirmExit()
|
d.ConfirmExit()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ev.KeyDown("F1") {
|
if keybind.Help(ev) {
|
||||||
// TODO: launch the guidebook.
|
// TODO: launch the guidebook.
|
||||||
native.OpenURL(balance.GuidebookPath)
|
native.OpenURL(balance.GuidebookPath)
|
||||||
ev.SetKeyDown("F1", false)
|
} else if keybind.DebugOverlay(ev) {
|
||||||
} else if ev.KeyDown("F3") {
|
|
||||||
DebugOverlay = !DebugOverlay
|
DebugOverlay = !DebugOverlay
|
||||||
ev.SetKeyDown("F3", false)
|
} else if keybind.DebugCollision(ev) {
|
||||||
} else if ev.KeyDown("F4") {
|
|
||||||
DebugCollision = !DebugCollision
|
DebugCollision = !DebugCollision
|
||||||
ev.SetKeyDown("F4", false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is a UI modal active?
|
// Is a UI modal active?
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
||||||
"git.kirsle.net/apps/doodle/pkg/enum"
|
"git.kirsle.net/apps/doodle/pkg/enum"
|
||||||
|
"git.kirsle.net/apps/doodle/pkg/keybind"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/modal"
|
"git.kirsle.net/apps/doodle/pkg/modal"
|
||||||
|
@ -195,31 +196,39 @@ func (s *EditorScene) Loop(d *Doodle, ev *event.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undo/Redo key bindings.
|
// Undo/Redo key bindings.
|
||||||
if ev.Ctrl {
|
if keybind.Undo(ev) {
|
||||||
if ev.KeyDown("z") {
|
s.UI.Canvas.UndoStroke()
|
||||||
s.UI.Canvas.UndoStroke()
|
} else if keybind.Redo(ev) {
|
||||||
} else if ev.KeyDown("y") {
|
s.UI.Canvas.RedoStroke()
|
||||||
s.UI.Canvas.RedoStroke()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.UI.Loop(ev)
|
s.UI.Loop(ev)
|
||||||
|
|
||||||
// Switching to Play Mode?
|
// Switching to Play Mode?
|
||||||
if ev.KeyDown("p") {
|
if keybind.GotoPlay(ev) {
|
||||||
s.Playtest()
|
s.Playtest()
|
||||||
} else if ev.KeyDown("l") {
|
} else if keybind.LineTool(ev) {
|
||||||
d.Flash("Line Tool selected.")
|
d.Flash("Line Tool selected.")
|
||||||
s.UI.Canvas.Tool = drawtool.LineTool
|
s.UI.Canvas.Tool = drawtool.LineTool
|
||||||
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
||||||
} else if ev.KeyDown("f") {
|
} else if keybind.PencilTool(ev) {
|
||||||
d.Flash("Pencil Tool selected.")
|
d.Flash("Pencil Tool selected.")
|
||||||
s.UI.Canvas.Tool = drawtool.PencilTool
|
s.UI.Canvas.Tool = drawtool.PencilTool
|
||||||
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
||||||
} else if ev.KeyDown("r") {
|
} else if keybind.RectTool(ev) {
|
||||||
d.Flash("Rectangle Tool selected.")
|
d.Flash("Rectangle Tool selected.")
|
||||||
s.UI.Canvas.Tool = drawtool.RectTool
|
s.UI.Canvas.Tool = drawtool.RectTool
|
||||||
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
||||||
|
} else if keybind.EllipseTool(ev) {
|
||||||
|
d.Flash("Ellipse Tool selected.")
|
||||||
|
s.UI.Canvas.Tool = drawtool.EllipseTool
|
||||||
|
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
||||||
|
} else if keybind.EraserTool(ev) {
|
||||||
|
d.Flash("Eraser Tool selected.")
|
||||||
|
s.UI.Canvas.Tool = drawtool.EraserTool
|
||||||
|
s.UI.activeTool = s.UI.Canvas.Tool.String()
|
||||||
|
} else if keybind.DoodadDropper(ev) {
|
||||||
|
s.UI.doodadWindow.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -594,6 +594,45 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.MenuBar {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw Tools
|
||||||
|
toolMenu.AddItemAccel("Pencil Tool", "F", func() {
|
||||||
|
u.Canvas.Tool = drawtool.PencilTool
|
||||||
|
u.activeTool = u.Canvas.Tool.String()
|
||||||
|
d.Flash("Pencil Tool selected.")
|
||||||
|
})
|
||||||
|
toolMenu.AddItemAccel("Line Tool", "L", func() {
|
||||||
|
u.Canvas.Tool = drawtool.LineTool
|
||||||
|
u.activeTool = u.Canvas.Tool.String()
|
||||||
|
d.Flash("Line Tool selected.")
|
||||||
|
})
|
||||||
|
toolMenu.AddItemAccel("Rectangle Tool", "R", func() {
|
||||||
|
u.Canvas.Tool = drawtool.RectTool
|
||||||
|
u.activeTool = u.Canvas.Tool.String()
|
||||||
|
d.Flash("Rectangle Tool selected.")
|
||||||
|
})
|
||||||
|
toolMenu.AddItemAccel("Ellipse Tool", "C", func() {
|
||||||
|
u.Canvas.Tool = drawtool.EllipseTool
|
||||||
|
u.activeTool = u.Canvas.Tool.String()
|
||||||
|
d.Flash("Ellipse Tool selected.")
|
||||||
|
})
|
||||||
|
toolMenu.AddItemAccel("Eraser Tool", "x", func() {
|
||||||
|
u.Canvas.Tool = drawtool.EraserTool
|
||||||
|
u.activeTool = u.Canvas.Tool.String()
|
||||||
|
d.Flash("Eraser Tool selected.")
|
||||||
|
})
|
||||||
|
|
||||||
|
if u.Scene.DrawingType == enum.LevelDrawing {
|
||||||
|
toolMenu.AddItemAccel("Doodads", "d", func() {
|
||||||
|
log.Info("Open the DoodadDropper")
|
||||||
|
u.doodadWindow.Show()
|
||||||
|
})
|
||||||
|
toolMenu.AddItem("Link Tool", func() {
|
||||||
|
u.Canvas.Tool = drawtool.LinkTool
|
||||||
|
u.activeTool = u.Canvas.Tool.String()
|
||||||
|
d.Flash("Link Tool selected. Click a doodad in your level to link it to another.")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
////////
|
////////
|
||||||
// Help menu
|
// Help menu
|
||||||
helpMenu := menu.AddMenu("Help")
|
helpMenu := menu.AddMenu("Help")
|
||||||
|
|
88
pkg/keybind/keybind.go
Normal file
88
pkg/keybind/keybind.go
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
// Package keybind centralizes the global hotkey bindings.
|
||||||
|
//
|
||||||
|
// Whenever the app would need to query a hotkey like "F3" or "Ctrl-Z"
|
||||||
|
// is held down, it should use a method in this file. It can be
|
||||||
|
// expanded later to allow user customizable bindings or something.
|
||||||
|
//
|
||||||
|
// NOTE: arrow key and gameplay controls not yet ported to here.
|
||||||
|
package keybind
|
||||||
|
|
||||||
|
import "git.kirsle.net/go/render/event"
|
||||||
|
|
||||||
|
// Shutdown (Escape) signals the game to start closing down.
|
||||||
|
func Shutdown(ev *event.State) bool {
|
||||||
|
return ev.Escape
|
||||||
|
}
|
||||||
|
|
||||||
|
// Help (F1) can be checked one time.
|
||||||
|
func Help(ev *event.State) bool {
|
||||||
|
result := ev.KeyDown("F1")
|
||||||
|
ev.SetKeyDown("F1", false)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// DebugOverlay (F3) can be checked one time.
|
||||||
|
func DebugOverlay(ev *event.State) bool {
|
||||||
|
result := ev.KeyDown("F3")
|
||||||
|
ev.SetKeyDown("F3", false)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// DebugCollision (F4) can be checked one time.
|
||||||
|
func DebugCollision(ev *event.State) bool {
|
||||||
|
result := ev.KeyDown("F4")
|
||||||
|
ev.SetKeyDown("F4", false)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Undo (Ctrl-Z)
|
||||||
|
func Undo(ev *event.State) bool {
|
||||||
|
return ev.Ctrl && ev.KeyDown("z")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redo (Ctrl-Y)
|
||||||
|
func Redo(ev *event.State) bool {
|
||||||
|
return ev.Ctrl && ev.KeyDown("y")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoPlay (P) play tests the current level in the editor.
|
||||||
|
func GotoPlay(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("p")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoEdit (E) opens the current played level in Edit Mode, if the
|
||||||
|
// player has come from the editor originally.
|
||||||
|
func GotoEdit(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("e")
|
||||||
|
}
|
||||||
|
|
||||||
|
// LineTool (L) selects the Line Tool in the editor.
|
||||||
|
func LineTool(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("l")
|
||||||
|
}
|
||||||
|
|
||||||
|
// PencilTool (F) selects the freehand pencil tool in the editor.
|
||||||
|
// GotoPlay (P) play tests the current level in the editor.
|
||||||
|
func PencilTool(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("f")
|
||||||
|
}
|
||||||
|
|
||||||
|
// RectTool (R) selects the rectangle in the editor.
|
||||||
|
func RectTool(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("r")
|
||||||
|
}
|
||||||
|
|
||||||
|
// EllipseTool (C) selects this tool in the editor.
|
||||||
|
func EllipseTool(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("c")
|
||||||
|
}
|
||||||
|
|
||||||
|
// EraserTool (X) selects this tool in the editor.
|
||||||
|
func EraserTool(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("x")
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoodadDropper (D) opens the doodad dropper in the editor.
|
||||||
|
func DoodadDropper(ev *event.State) bool {
|
||||||
|
return ev.KeyDown("d")
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/collision"
|
"git.kirsle.net/apps/doodle/pkg/collision"
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
|
"git.kirsle.net/apps/doodle/pkg/keybind"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/physics"
|
"git.kirsle.net/apps/doodle/pkg/physics"
|
||||||
|
@ -391,7 +392,7 @@ func (s *PlayScene) Loop(d *Doodle, ev *event.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switching to Edit Mode?
|
// Switching to Edit Mode?
|
||||||
if s.CanEdit && ev.KeyDown("e") {
|
if s.CanEdit && keybind.GotoEdit(ev) {
|
||||||
s.EditLevel()
|
s.EditLevel()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user