Add Play/Edit Buttons to Toggle Between Modes
* Instead of needing to press the "P" and "E" keys to toggle from edit mode to play mode (and back again), respectively, the UI now draws a "Play (P)" or "Edit (E)" button on the bottom right corner of the level canvas. Clicking it will toggle the mode.
This commit is contained in:
parent
4c2e8eca49
commit
9efe16582c
|
@ -54,4 +54,12 @@ var (
|
|||
|
||||
// Color for draggable doodad.
|
||||
DragColor = render.MustHexColor("#0099FF")
|
||||
|
||||
PlayButtonFont = render.Text{
|
||||
FontFilename: "./fonts/DejaVuSans-Bold.ttf",
|
||||
Size: 16,
|
||||
Padding: 4,
|
||||
Color: render.RGBA(255, 255, 0, 255),
|
||||
Stroke: render.RGBA(100, 100, 0, 255),
|
||||
}
|
||||
)
|
||||
|
|
|
@ -125,6 +125,15 @@ func (s *EditorScene) Setup(d *Doodle) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Playtest switches the level into Play Mode.
|
||||
func (s *EditorScene) Playtest() {
|
||||
log.Info("Play Mode, Go!")
|
||||
s.d.Goto(&PlayScene{
|
||||
Filename: s.filename,
|
||||
Level: s.Level,
|
||||
})
|
||||
}
|
||||
|
||||
// Loop the editor scene.
|
||||
func (s *EditorScene) Loop(d *Doodle, ev *events.State) error {
|
||||
// Update debug overlay values.
|
||||
|
@ -148,11 +157,7 @@ func (s *EditorScene) Loop(d *Doodle, ev *events.State) error {
|
|||
|
||||
// Switching to Play Mode?
|
||||
if ev.KeyName.Read() == "p" {
|
||||
log.Info("Play Mode, Go!")
|
||||
d.Goto(&PlayScene{
|
||||
Filename: s.filename,
|
||||
Level: s.Level,
|
||||
})
|
||||
s.Playtest()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ type EditorUI struct {
|
|||
Workspace *ui.Frame
|
||||
MenuBar *ui.Frame
|
||||
StatusBar *ui.Frame
|
||||
PlayButton *ui.Button
|
||||
|
||||
// Palette window.
|
||||
Palette *ui.Window
|
||||
|
@ -78,6 +79,15 @@ func NewEditorUI(d *Doodle, s *EditorScene) *EditorUI {
|
|||
u.StatusBar = u.SetupStatusBar(d)
|
||||
u.Workspace = u.SetupWorkspace(d) // important that this is last!
|
||||
|
||||
u.PlayButton = ui.NewButton("Play", ui.NewLabel(ui.Label{
|
||||
Text: "Play (P)",
|
||||
Font: balance.PlayButtonFont,
|
||||
}))
|
||||
u.PlayButton.Handle(ui.Click, func(p render.Point) {
|
||||
u.Scene.Playtest()
|
||||
})
|
||||
u.Supervisor.Add(u.PlayButton)
|
||||
|
||||
// Position the Canvas inside the frame.
|
||||
u.Workspace.Pack(u.Canvas, ui.Pack{
|
||||
Anchor: ui.N,
|
||||
|
@ -151,6 +161,23 @@ func (u *EditorUI) Resized(d *Doodle) {
|
|||
|
||||
u.ExpandCanvas(d.Engine)
|
||||
}
|
||||
|
||||
// Position the Play button over the workspace.
|
||||
{
|
||||
btn := u.PlayButton
|
||||
btn.Compute(d.Engine)
|
||||
|
||||
var (
|
||||
wsP = u.Workspace.Point()
|
||||
wsSize = u.Workspace.Size()
|
||||
btnSize = btn.Size()
|
||||
padding int32 = 8
|
||||
)
|
||||
btn.MoveTo(render.NewPoint(
|
||||
wsP.X+wsSize.W-btnSize.W-padding,
|
||||
wsP.Y+wsSize.H-btnSize.H-padding,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// Loop to process events and update the UI.
|
||||
|
@ -221,6 +248,7 @@ func (u *EditorUI) Present(e render.Engine) {
|
|||
u.MenuBar.Present(e, u.MenuBar.Point())
|
||||
u.StatusBar.Present(e, u.StatusBar.Point())
|
||||
u.Workspace.Present(e, u.Workspace.Point())
|
||||
u.PlayButton.Present(e, u.PlayButton.Point())
|
||||
|
||||
// Are we dragging a Doodad canvas?
|
||||
if u.Supervisor.IsDragging() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"git.kirsle.net/apps/doodle/lib/events"
|
||||
"git.kirsle.net/apps/doodle/lib/render"
|
||||
"git.kirsle.net/apps/doodle/lib/ui"
|
||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||
"git.kirsle.net/apps/doodle/pkg/level"
|
||||
|
@ -24,6 +25,10 @@ type PlayScene struct {
|
|||
drawing *uix.Canvas
|
||||
scripting *scripting.Supervisor
|
||||
|
||||
// UI widgets.
|
||||
supervisor *ui.Supervisor
|
||||
editButton *ui.Button
|
||||
|
||||
// Custom debug labels.
|
||||
debPosition *string
|
||||
debViewport *string
|
||||
|
@ -43,6 +48,7 @@ func (s *PlayScene) Name() string {
|
|||
func (s *PlayScene) Setup(d *Doodle) error {
|
||||
s.d = d
|
||||
s.scripting = scripting.NewSupervisor()
|
||||
s.supervisor = ui.NewSupervisor()
|
||||
|
||||
// Initialize debug overlay values.
|
||||
s.debPosition = new(string)
|
||||
|
@ -56,6 +62,16 @@ func (s *PlayScene) Setup(d *Doodle) error {
|
|||
{"Scroll:", s.debScroll},
|
||||
}
|
||||
|
||||
// Initialize the "Edit Map" button.
|
||||
s.editButton = ui.NewButton("Edit", ui.NewLabel(ui.Label{
|
||||
Text: "Edit (E)",
|
||||
Font: balance.PlayButtonFont,
|
||||
}))
|
||||
s.editButton.Handle(ui.Click, func(p render.Point) {
|
||||
s.EditLevel()
|
||||
})
|
||||
s.supervisor.Add(s.editButton)
|
||||
|
||||
// Initialize the drawing canvas.
|
||||
s.drawing = uix.NewCanvas(balance.ChunkSize, false)
|
||||
s.drawing.Name = "play-canvas"
|
||||
|
@ -114,6 +130,15 @@ func (s *PlayScene) Setup(d *Doodle) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// EditLevel toggles out of Play Mode to edit the level.
|
||||
func (s *PlayScene) EditLevel() {
|
||||
log.Info("Edit Mode, Go!")
|
||||
s.d.Goto(&EditorScene{
|
||||
Filename: s.Filename,
|
||||
Level: s.Level,
|
||||
})
|
||||
}
|
||||
|
||||
// Loop the editor scene.
|
||||
func (s *PlayScene) Loop(d *Doodle, ev *events.State) error {
|
||||
// Update debug overlay values.
|
||||
|
@ -122,6 +147,8 @@ func (s *PlayScene) Loop(d *Doodle, ev *events.State) error {
|
|||
*s.debViewport = s.drawing.Viewport().String()
|
||||
*s.debScroll = s.drawing.Scroll.String()
|
||||
|
||||
s.supervisor.Loop(ev)
|
||||
|
||||
// Has the window been resized?
|
||||
if resized := ev.Resized.Now; resized {
|
||||
w, h := d.Engine.WindowSize()
|
||||
|
@ -135,11 +162,7 @@ func (s *PlayScene) Loop(d *Doodle, ev *events.State) error {
|
|||
|
||||
// Switching to Edit Mode?
|
||||
if ev.KeyName.Read() == "e" {
|
||||
log.Info("Edit Mode, Go!")
|
||||
d.Goto(&EditorScene{
|
||||
Filename: s.Filename,
|
||||
Level: s.Level,
|
||||
})
|
||||
s.EditLevel()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -167,6 +190,17 @@ func (s *PlayScene) Draw(d *Doodle) error {
|
|||
// Draw out bounding boxes.
|
||||
d.DrawCollisionBox(s.Player)
|
||||
|
||||
// Draw the Edit button.
|
||||
var (
|
||||
canSize = s.drawing.Size()
|
||||
size = s.editButton.Size()
|
||||
padding int32 = 8
|
||||
)
|
||||
s.editButton.Present(d.Engine, render.Point{
|
||||
X: canSize.W - size.W - padding,
|
||||
Y: canSize.H - size.H - padding,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user