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.
128 lines
3.1 KiB
Go
128 lines
3.1 KiB
Go
package sdl
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.kirsle.net/apps/doodle/events"
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
)
|
|
|
|
// Poll for events.
|
|
func (r *Renderer) Poll() (*events.State, error) {
|
|
s := r.events
|
|
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
|
switch t := event.(type) {
|
|
case *sdl.QuitEvent:
|
|
return s, errors.New("quit")
|
|
case *sdl.WindowEvent:
|
|
if DebugWindowEvents {
|
|
if t.Event == sdl.WINDOWEVENT_RESIZED {
|
|
log.Debug("[%d ms] tick:%d Window Resized to %dx%d",
|
|
t.Timestamp,
|
|
r.ticks,
|
|
t.Data1,
|
|
t.Data2,
|
|
)
|
|
}
|
|
}
|
|
s.Resized.Push(true)
|
|
case *sdl.MouseMotionEvent:
|
|
if DebugMouseEvents {
|
|
log.Debug("[%d ms] tick:%d MouseMotion type:%d id:%d x:%d y:%d xrel:%d yrel:%d",
|
|
t.Timestamp, r.ticks, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel,
|
|
)
|
|
}
|
|
|
|
// Push the cursor position.
|
|
s.CursorX.Push(t.X)
|
|
s.CursorY.Push(t.Y)
|
|
s.Button1.Push(t.State == 1)
|
|
case *sdl.MouseButtonEvent:
|
|
if DebugClickEvents {
|
|
log.Debug("[%d ms] tick:%d MouseButton type:%d id:%d x:%d y:%d button:%d state:%d",
|
|
t.Timestamp, r.ticks, t.Type, t.Which, t.X, t.Y, t.Button, t.State,
|
|
)
|
|
}
|
|
|
|
// Push the cursor position.
|
|
s.CursorX.Push(t.X)
|
|
s.CursorY.Push(t.Y)
|
|
|
|
// Is a mouse button pressed down?
|
|
if t.Button == 1 {
|
|
var eventName string
|
|
if t.State == 1 && s.Button1.Now == false {
|
|
eventName = "DOWN"
|
|
} else if t.State == 0 && s.Button1.Now == true {
|
|
eventName = "UP"
|
|
}
|
|
|
|
if eventName != "" {
|
|
s.Button1.Push(eventName == "DOWN")
|
|
|
|
// Return the event immediately.
|
|
return s, nil
|
|
}
|
|
}
|
|
|
|
// s.Button2.Push(t.Button == 3 && t.State == 1)
|
|
case *sdl.MouseWheelEvent:
|
|
if DebugMouseEvents {
|
|
log.Debug("[%d ms] tick:%d MouseWheel type:%d id:%d x:%d y:%d",
|
|
t.Timestamp, r.ticks, t.Type, t.Which, t.X, t.Y,
|
|
)
|
|
}
|
|
case *sdl.KeyboardEvent:
|
|
if DebugKeyEvents {
|
|
log.Debug("[%d ms] tick:%d Keyboard type:%d sym:%c modifiers:%d state:%d repeat:%d\n",
|
|
t.Timestamp, r.ticks, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat,
|
|
)
|
|
}
|
|
|
|
switch t.Keysym.Scancode {
|
|
case sdl.SCANCODE_ESCAPE:
|
|
if t.Repeat == 1 {
|
|
continue
|
|
}
|
|
s.EscapeKey.Push(t.State == 1)
|
|
case sdl.SCANCODE_RETURN:
|
|
if t.Repeat == 1 {
|
|
continue
|
|
}
|
|
s.EnterKey.Push(t.State == 1)
|
|
case sdl.SCANCODE_F12:
|
|
s.ScreenshotKey.Push(t.State == 1)
|
|
case sdl.SCANCODE_UP:
|
|
s.Up.Push(t.State == 1)
|
|
case sdl.SCANCODE_LEFT:
|
|
s.Left.Push(t.State == 1)
|
|
case sdl.SCANCODE_RIGHT:
|
|
s.Right.Push(t.State == 1)
|
|
case sdl.SCANCODE_DOWN:
|
|
s.Down.Push(t.State == 1)
|
|
case sdl.SCANCODE_LSHIFT:
|
|
case sdl.SCANCODE_RSHIFT:
|
|
s.ShiftActive.Push(t.State == 1)
|
|
continue
|
|
case sdl.SCANCODE_LALT:
|
|
case sdl.SCANCODE_RALT:
|
|
case sdl.SCANCODE_LCTRL:
|
|
case sdl.SCANCODE_RCTRL:
|
|
continue
|
|
case sdl.SCANCODE_BACKSPACE:
|
|
// Make it a key event with "\b" as the sequence.
|
|
if t.State == 1 || t.Repeat == 1 {
|
|
s.KeyName.Push(`\b`)
|
|
}
|
|
default:
|
|
// Push the string value of the key.
|
|
if t.State == 1 {
|
|
s.KeyName.Push(string(t.Keysym.Sym))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return s, nil
|
|
}
|