2018-07-26 02:38:54 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
2019-04-10 00:35:44 +00:00
|
|
|
"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"
|
2019-06-24 00:52:48 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
2019-06-25 21:57:11 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/level"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
2018-07-26 02:38:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MainScene implements the main menu of Doodle.
|
|
|
|
type MainScene struct {
|
2018-07-26 03:25:02 +00:00
|
|
|
Supervisor *ui.Supervisor
|
2018-08-01 00:18:13 +00:00
|
|
|
frame *ui.Frame
|
2019-06-25 21:57:11 +00:00
|
|
|
|
|
|
|
// Background wallpaper canvas.
|
|
|
|
canvas *uix.Canvas
|
2018-07-26 02:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name of the scene.
|
|
|
|
func (s *MainScene) Name() string {
|
|
|
|
return "Main"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the scene.
|
|
|
|
func (s *MainScene) Setup(d *Doodle) error {
|
2018-07-26 03:25:02 +00:00
|
|
|
s.Supervisor = ui.NewSupervisor()
|
|
|
|
|
2019-06-25 21:57:11 +00:00
|
|
|
// Set up the background wallpaper canvas.
|
|
|
|
s.canvas = uix.NewCanvas(100, false)
|
|
|
|
s.canvas.Resize(render.Rect{
|
|
|
|
W: int32(d.width),
|
|
|
|
H: int32(d.height),
|
|
|
|
})
|
|
|
|
s.canvas.LoadLevel(d.Engine, &level.Level{
|
|
|
|
Chunker: level.NewChunker(100),
|
|
|
|
Palette: level.NewPalette(),
|
|
|
|
PageType: level.Bounded,
|
|
|
|
Wallpaper: "notebook.png",
|
|
|
|
})
|
|
|
|
|
|
|
|
// Main UI button frame.
|
2018-08-02 01:52:52 +00:00
|
|
|
frame := ui.NewFrame("frame")
|
2018-08-01 00:18:13 +00:00
|
|
|
s.frame = frame
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
button1 := ui.NewButton("Button1", ui.NewLabel(ui.Label{
|
|
|
|
Text: "New Map",
|
|
|
|
Font: balance.StatusFont,
|
2018-07-26 03:25:02 +00:00
|
|
|
}))
|
2018-08-17 03:37:19 +00:00
|
|
|
button1.Handle(ui.Click, func(p render.Point) {
|
2019-06-25 21:57:11 +00:00
|
|
|
d.GotoNewMenu()
|
2018-07-26 03:25:02 +00:00
|
|
|
})
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
button2 := ui.NewButton("Button2", ui.NewLabel(ui.Label{
|
2019-06-25 21:57:11 +00:00
|
|
|
Text: "Load Map",
|
2018-08-05 19:54:57 +00:00
|
|
|
Font: balance.StatusFont,
|
2018-07-26 03:25:02 +00:00
|
|
|
}))
|
2019-06-25 22:23:01 +00:00
|
|
|
button2.Handle(ui.Click, func(p render.Point) {
|
|
|
|
d.GotoLoadMenu()
|
|
|
|
})
|
2018-08-01 00:18:13 +00:00
|
|
|
|
|
|
|
frame.Pack(button1, ui.Pack{
|
2018-08-05 19:54:57 +00:00
|
|
|
Anchor: ui.N,
|
|
|
|
Fill: true,
|
2018-08-01 00:18:13 +00:00
|
|
|
})
|
|
|
|
frame.Pack(button2, ui.Pack{
|
2018-08-05 19:54:57 +00:00
|
|
|
Anchor: ui.N,
|
|
|
|
PadY: 12,
|
|
|
|
Fill: true,
|
2018-07-26 03:25:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
s.Supervisor.Add(button1)
|
|
|
|
s.Supervisor.Add(button2)
|
|
|
|
|
2018-07-26 02:38:54 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop the editor scene.
|
|
|
|
func (s *MainScene) Loop(d *Doodle, ev *events.State) error {
|
2018-07-26 03:25:02 +00:00
|
|
|
s.Supervisor.Loop(ev)
|
2019-06-25 21:57:11 +00:00
|
|
|
|
|
|
|
if resized := ev.Resized.Read(); resized {
|
|
|
|
w, h := d.Engine.WindowSize()
|
|
|
|
d.width = w
|
|
|
|
d.height = h
|
|
|
|
log.Info("Resized to %dx%d", d.width, d.height)
|
|
|
|
s.canvas.Resize(render.Rect{
|
|
|
|
W: int32(d.width),
|
|
|
|
H: int32(d.height),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-26 02:38:54 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the pixels on this frame.
|
|
|
|
func (s *MainScene) Draw(d *Doodle) error {
|
|
|
|
// Clear the canvas and fill it with white.
|
|
|
|
d.Engine.Clear(render.White)
|
|
|
|
|
2019-06-25 21:57:11 +00:00
|
|
|
s.canvas.Present(d.Engine, render.Origin)
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
label := ui.NewLabel(ui.Label{
|
2019-06-24 00:52:48 +00:00
|
|
|
Text: branding.AppName,
|
2018-08-05 19:54:57 +00:00
|
|
|
Font: render.Text{
|
2019-06-27 01:36:54 +00:00
|
|
|
Size: 46,
|
2018-08-05 19:54:57 +00:00
|
|
|
Color: render.Pink,
|
|
|
|
Stroke: render.SkyBlue,
|
|
|
|
Shadow: render.Black,
|
|
|
|
},
|
2018-07-26 02:38:54 +00:00
|
|
|
})
|
|
|
|
label.Compute(d.Engine)
|
|
|
|
label.MoveTo(render.Point{
|
2018-10-19 20:31:58 +00:00
|
|
|
X: (int32(d.width) / 2) - (label.Size().W / 2),
|
2018-07-26 02:38:54 +00:00
|
|
|
Y: 120,
|
|
|
|
})
|
2018-08-05 19:54:57 +00:00
|
|
|
label.Present(d.Engine, label.Point())
|
2018-07-26 02:38:54 +00:00
|
|
|
|
2018-08-01 00:18:13 +00:00
|
|
|
s.frame.Compute(d.Engine)
|
|
|
|
s.frame.MoveTo(render.Point{
|
2018-10-19 20:31:58 +00:00
|
|
|
X: (int32(d.width) / 2) - (s.frame.Size().W / 2),
|
2019-06-27 01:36:54 +00:00
|
|
|
Y: 260,
|
2018-08-01 00:18:13 +00:00
|
|
|
})
|
2018-08-05 19:54:57 +00:00
|
|
|
s.frame.Present(d.Engine, s.frame.Point())
|
2018-07-26 02:38:54 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the scene.
|
|
|
|
func (s *MainScene) Destroy() error {
|
|
|
|
return nil
|
|
|
|
}
|