Noah Petherbridge
20771fbe13
Add the JSON format for embedding Actors (Doodad instances) inside of a Level. I made a test map that manually inserted a couple of actors. Actors are given to the Canvas responsible for the Level via the function `InstallActors()`. So it means you'll call LoadLevel and then InstallActors to hook everything up. The Canvas creates sub-Canvas widgets from each Actor. After drawing the main level geometry from the Canvas.Chunker, it calls the drawActors() function which does the same but for Actors. Levels keep a global map of all Actors that exist. For any Actors that are visible within the Viewport, their sub-Canvas widgets are presented appropriately on top of the parent Canvas. In case their sub-Canvas overlaps the parent's boundaries, their sub-Canvas is resized and moved appropriately. - Allow the MainWindow to be resized at run time, and the UI recalculates its sizing and position. - Made the in-game Shell properties editable via environment variables. The kirsle.env file sets a blue and pink color scheme. - Begin the ground work for Levels and Doodads to embed files inside their data via the level.FileSystem type. - UI: Labels can now contain line break characters. It will appropriately render multiple lines of render.Text and take into account the proper BoxSize to contain them all. - Add environment variable DOODLE_DEBUG_ALL=true that will turn on ALL debug overlay and visualization options. - Add debug overlay to "tag" each Canvas widget with some of its details, like its Name and World Position. Can be enabled with the environment variable DEBUG_CANVAS_LABEL=true - Improved the FPS debug overlay to show in labeled columns and multiple colors, with easy ability to add new data points to it.
297 lines
5.8 KiB
Go
297 lines
5.8 KiB
Go
package doodle
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.kirsle.net/apps/doodle/balance"
|
|
"git.kirsle.net/apps/doodle/events"
|
|
"git.kirsle.net/apps/doodle/render"
|
|
"git.kirsle.net/apps/doodle/ui"
|
|
)
|
|
|
|
// GUITestScene implements the main menu of Doodle.
|
|
type GUITestScene struct {
|
|
Supervisor *ui.Supervisor
|
|
|
|
// Private widgets.
|
|
Frame *ui.Frame
|
|
Window *ui.Frame
|
|
}
|
|
|
|
// Name of the scene.
|
|
func (s *GUITestScene) Name() string {
|
|
return "Main"
|
|
}
|
|
|
|
// Setup the scene.
|
|
func (s *GUITestScene) Setup(d *Doodle) error {
|
|
s.Supervisor = ui.NewSupervisor()
|
|
|
|
window := ui.NewFrame("window")
|
|
s.Window = window
|
|
window.Configure(ui.Config{
|
|
Width: 750,
|
|
Height: 450,
|
|
Background: render.Grey,
|
|
BorderStyle: ui.BorderRaised,
|
|
BorderSize: 2,
|
|
})
|
|
|
|
// Title Bar
|
|
titleBar := ui.NewLabel(ui.Label{
|
|
Text: "Widget Toolkit",
|
|
Font: render.Text{
|
|
Size: 12,
|
|
Color: render.White,
|
|
Stroke: render.DarkBlue,
|
|
},
|
|
})
|
|
titleBar.Configure(ui.Config{
|
|
Background: render.Blue,
|
|
})
|
|
window.Pack(titleBar, ui.Pack{
|
|
Anchor: ui.N,
|
|
Fill: true,
|
|
})
|
|
|
|
// Window Body
|
|
body := ui.NewFrame("Window Body")
|
|
body.Configure(ui.Config{
|
|
Background: render.Yellow,
|
|
})
|
|
window.Pack(body, ui.Pack{
|
|
Anchor: ui.N,
|
|
Expand: true,
|
|
})
|
|
|
|
// Left Frame
|
|
leftFrame := ui.NewFrame("Left Frame")
|
|
leftFrame.Configure(ui.Config{
|
|
Background: render.Grey,
|
|
BorderStyle: ui.BorderSolid,
|
|
BorderSize: 4,
|
|
Width: 100,
|
|
})
|
|
body.Pack(leftFrame, ui.Pack{
|
|
Anchor: ui.W,
|
|
FillY: true,
|
|
})
|
|
|
|
// Some left frame buttons.
|
|
for _, label := range []string{"New", "Edit", "Play", "Help"} {
|
|
btn := ui.NewButton("dummy "+label, ui.NewLabel(ui.Label{
|
|
Text: label,
|
|
Font: balance.StatusFont,
|
|
}))
|
|
btn.Handle(ui.Click, func(p render.Point) {
|
|
d.Flash("%s clicked", btn)
|
|
})
|
|
s.Supervisor.Add(btn)
|
|
leftFrame.Pack(btn, ui.Pack{
|
|
Anchor: ui.N,
|
|
FillX: true,
|
|
PadY: 2,
|
|
})
|
|
}
|
|
|
|
// Main Frame
|
|
frame := ui.NewFrame("Main Frame")
|
|
frame.Configure(ui.Config{
|
|
Background: render.White,
|
|
BorderSize: 0,
|
|
})
|
|
body.Pack(frame, ui.Pack{
|
|
Anchor: ui.W,
|
|
Expand: true,
|
|
Fill: true,
|
|
})
|
|
|
|
// Right Frame
|
|
rightFrame := ui.NewFrame("Right Frame")
|
|
rightFrame.Configure(ui.Config{
|
|
Background: render.SkyBlue,
|
|
BorderStyle: ui.BorderSunken,
|
|
BorderSize: 2,
|
|
Width: 80,
|
|
})
|
|
body.Pack(rightFrame, ui.Pack{
|
|
Anchor: ui.W,
|
|
Fill: true,
|
|
})
|
|
|
|
// A grid of buttons.
|
|
for row := 0; row < 3; row++ {
|
|
rowFrame := ui.NewFrame(fmt.Sprintf("Row%d", row))
|
|
rowFrame.Configure(ui.Config{
|
|
Background: render.RGBA(0, uint8((row*20)+120), 0, 255),
|
|
})
|
|
for col := 0; col < 3; col++ {
|
|
(func(row, col int, frame *ui.Frame) {
|
|
btn := ui.NewButton(fmt.Sprintf("Grid Button %d:%d", col, row),
|
|
ui.NewFrame(fmt.Sprintf("Col%d", col)),
|
|
)
|
|
btn.Configure(ui.Config{
|
|
Height: 20,
|
|
BorderStyle: ui.BorderRaised,
|
|
})
|
|
btn.Handle(ui.Click, func(p render.Point) {
|
|
d.Flash("%s clicked", btn)
|
|
})
|
|
rowFrame.Pack(btn, ui.Pack{
|
|
Anchor: ui.W,
|
|
Expand: true,
|
|
FillX: true,
|
|
})
|
|
s.Supervisor.Add(btn)
|
|
})(row, col, rowFrame)
|
|
}
|
|
rightFrame.Pack(rowFrame, ui.Pack{
|
|
Anchor: ui.N,
|
|
Fill: true,
|
|
})
|
|
}
|
|
|
|
// Main frame widgets.
|
|
frame.Pack(ui.NewLabel(ui.Label{
|
|
Text: "Hello World!",
|
|
Font: render.Text{
|
|
Size: 14,
|
|
Color: render.Black,
|
|
},
|
|
}), ui.Pack{
|
|
Anchor: ui.NW,
|
|
Padding: 2,
|
|
})
|
|
|
|
cb := ui.NewCheckbox("Overlay",
|
|
&DebugOverlay,
|
|
ui.NewLabel(ui.Label{
|
|
Text: "Toggle Debug Overlay",
|
|
Font: balance.StatusFont,
|
|
}),
|
|
)
|
|
frame.Pack(cb, ui.Pack{
|
|
Anchor: ui.NW,
|
|
Padding: 4,
|
|
})
|
|
cb.Supervise(s.Supervisor)
|
|
|
|
// Put an image in.
|
|
img, err := ui.OpenImage(d.Engine, "exit.bmp")
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
}
|
|
frame.Pack(img, ui.Pack{
|
|
Anchor: ui.NE,
|
|
Padding: 4,
|
|
})
|
|
|
|
frame.Pack(ui.NewLabel(ui.Label{
|
|
Text: "Like Tk!",
|
|
Font: render.Text{
|
|
Size: 16,
|
|
Color: render.Red,
|
|
},
|
|
}), ui.Pack{
|
|
Anchor: ui.SE,
|
|
Padding: 8,
|
|
})
|
|
frame.Pack(ui.NewLabel(ui.Label{
|
|
Text: "Frame widget for pack layouts",
|
|
Font: render.Text{
|
|
Size: 14,
|
|
Color: render.Blue,
|
|
},
|
|
}), ui.Pack{
|
|
Anchor: ui.SE,
|
|
Padding: 8,
|
|
})
|
|
|
|
// Buttom Frame
|
|
btnFrame := ui.NewFrame("btnFrame")
|
|
btnFrame.Configure(ui.Config{
|
|
Background: render.Grey,
|
|
})
|
|
window.Pack(btnFrame, ui.Pack{
|
|
Anchor: ui.N,
|
|
})
|
|
|
|
button1 := ui.NewButton("Button1", ui.NewLabel(ui.Label{
|
|
Text: "New Map",
|
|
Font: balance.StatusFont,
|
|
}))
|
|
button1.SetBackground(render.Blue)
|
|
button1.Handle(ui.Click, func(p render.Point) {
|
|
d.NewMap()
|
|
})
|
|
|
|
log.Info("Button1 bg: %s", button1.Background())
|
|
|
|
button2 := ui.NewButton("Button2", ui.NewLabel(ui.Label{
|
|
Text: "Load Map",
|
|
Font: balance.StatusFont,
|
|
}))
|
|
button2.Handle(ui.Click, func(p render.Point) {
|
|
d.Prompt("Map name>", func(name string) {
|
|
d.EditDrawing(name)
|
|
})
|
|
})
|
|
|
|
var align = ui.W
|
|
btnFrame.Pack(button1, ui.Pack{
|
|
Anchor: align,
|
|
Padding: 20,
|
|
})
|
|
btnFrame.Pack(button2, ui.Pack{
|
|
Anchor: align,
|
|
Padding: 20,
|
|
})
|
|
|
|
s.Supervisor.Add(button1)
|
|
s.Supervisor.Add(button2)
|
|
|
|
return nil
|
|
}
|
|
|
|
// Loop the editor scene.
|
|
func (s *GUITestScene) Loop(d *Doodle, ev *events.State) error {
|
|
s.Supervisor.Loop(ev)
|
|
return nil
|
|
}
|
|
|
|
// Draw the pixels on this frame.
|
|
func (s *GUITestScene) Draw(d *Doodle) error {
|
|
// Clear the canvas and fill it with white.
|
|
d.Engine.Clear(render.White)
|
|
|
|
label := ui.NewLabel(ui.Label{
|
|
Text: "GUITest Doodle v" + Version,
|
|
Font: render.Text{
|
|
Size: 26,
|
|
Color: render.Pink,
|
|
Stroke: render.SkyBlue,
|
|
Shadow: render.Black,
|
|
},
|
|
})
|
|
label.Compute(d.Engine)
|
|
label.MoveTo(render.Point{
|
|
X: (int32(d.width) / 2) - (label.Size().W / 2),
|
|
Y: 40,
|
|
})
|
|
label.Present(d.Engine, label.Point())
|
|
|
|
s.Window.Compute(d.Engine)
|
|
s.Window.MoveTo(render.Point{
|
|
X: (int32(d.width) / 2) - (s.Window.Size().W / 2),
|
|
Y: 100,
|
|
})
|
|
s.Window.Present(d.Engine, s.Window.Point())
|
|
|
|
return nil
|
|
}
|
|
|
|
// Destroy the scene.
|
|
func (s *GUITestScene) Destroy() error {
|
|
return nil
|
|
}
|