diff --git a/dev-assets/doodads/azulian/azulian.js b/dev-assets/doodads/azulian/azulian.js index 5178cc7..40291ca 100644 --- a/dev-assets/doodads/azulian/azulian.js +++ b/dev-assets/doodads/azulian/azulian.js @@ -1,6 +1,9 @@ function main() { log.Info("Azulian '%s' initialized!", Self.Doodad.Title); + + Self.Canvas.SetBackground(RGBA(0, 153, 255, 100)); + var playerSpeed = 12; var gravity = 4; var Vx = Vy = 0; diff --git a/dev-assets/doodads/doors/locked-door.js b/dev-assets/doodads/doors/locked-door.js index cabbce2..fee9610 100644 --- a/dev-assets/doodads/doors/locked-door.js +++ b/dev-assets/doodads/doors/locked-door.js @@ -2,6 +2,8 @@ function main() { Self.AddAnimation("open", 0, [1]); var unlocked = false; + Self.Canvas.SetBackground(RGBA(0, 255, 255, 100)); + // Map our door names to key names. var KeyMap = { "Blue Door": "Blue Key", @@ -32,6 +34,5 @@ function main() { }); Events.OnLeave(function(e) { console.log("%s has stopped touching %s", e, Self.Doodad.Title) - Self.Canvas.SetBackground(RGBA(0, 0, 1, 0)); }) } diff --git a/dev-assets/doodads/trapdoors/down.js b/dev-assets/doodads/trapdoors/down.js index e861082..1f383cb 100644 --- a/dev-assets/doodads/trapdoors/down.js +++ b/dev-assets/doodads/trapdoors/down.js @@ -3,7 +3,7 @@ function main() { var timer = 0; - Self.SetHitbox(0, 0, 72, 9); + Self.SetHitbox(0, 0, 72, 6); var animationSpeed = 100; var opened = false; diff --git a/lib/events/events.go b/lib/events/events.go index 9c650fb..c3957ec 100644 --- a/lib/events/events.go +++ b/lib/events/events.go @@ -8,8 +8,9 @@ import ( // State keeps track of event states. type State struct { // Mouse buttons. - Button1 *BoolTick - Button2 *BoolTick + Button1 *BoolTick // left + Button2 *BoolTick // right + Button3 *BoolTick // middle EscapeKey *BoolTick EnterKey *BoolTick @@ -33,6 +34,7 @@ func New() *State { return &State{ Button1: &BoolTick{}, Button2: &BoolTick{}, + Button3: &BoolTick{}, EscapeKey: &BoolTick{}, EnterKey: &BoolTick{}, ShiftActive: &BoolTick{}, diff --git a/lib/render/sdl/events.go b/lib/render/sdl/events.go index 3ec1a92..6c958da 100644 --- a/lib/render/sdl/events.go +++ b/lib/render/sdl/events.go @@ -83,7 +83,7 @@ func (r *Renderer) Poll() (*events.State, error) { return false } - if checkDown(1, s.Button1) || checkDown(3, s.Button2) { + if checkDown(1, s.Button1) || checkDown(3, s.Button2) || checkDown(2, s.Button3) { // Return the event immediately. return s, nil } diff --git a/pkg/doodads/actor.go b/pkg/doodads/actor.go index 0b1f173..037b1f7 100644 --- a/pkg/doodads/actor.go +++ b/pkg/doodads/actor.go @@ -17,8 +17,8 @@ type Actor interface { SetGrounded(bool) // Actor's elected hitbox set by their script. - SetHitbox(x, y, w, h int) - Hitbox() render.Rect + // SetHitbox(x, y, w, h int) + // Hitbox() render.Rect // Movement commands. MoveBy(render.Point) // Add {X,Y} to current Position. @@ -39,3 +39,12 @@ func GetBoundingRect(d Actor) render.Rect { H: S.H, } } + +// GetBoundingRectWithHitbox is like GetBoundingRect but adjusts it for the +// relative hitbox of the actor. +// func GetBoundingRectWithHitbox(d Actor, hitbox render.Rect) render.Rect { +// rect := GetBoundingRect(d) +// rect.W = hitbox.W +// rect.H = hitbox.H +// return rect +// } diff --git a/pkg/doodads/drawing.go b/pkg/doodads/drawing.go index dbe404c..9fcf401 100644 --- a/pkg/doodads/drawing.go +++ b/pkg/doodads/drawing.go @@ -76,20 +76,20 @@ func (d *Drawing) SetGrounded(v bool) { d.grounded = v } -// SetHitbox sets the actor's elected hitbox. -func (d *Drawing) SetHitbox(x, y, w, h int) { - d.hitbox = render.Rect{ - X: int32(x), - Y: int32(y), - W: int32(w), - H: int32(h), - } -} - -// Hitbox returns the actor's elected hitbox. -func (d *Drawing) Hitbox() render.Rect { - return d.hitbox -} +// // SetHitbox sets the actor's elected hitbox. +// func (d *Drawing) SetHitbox(x, y, w, h int) { +// d.hitbox = render.Rect{ +// X: int32(x), +// Y: int32(y), +// W: int32(w), +// H: int32(h), +// } +// } +// +// // Hitbox returns the actor's elected hitbox. +// func (d *Drawing) Hitbox() render.Rect { +// return d.hitbox +// } // MoveBy a relative value. func (d *Drawing) MoveBy(by render.Point) { diff --git a/pkg/editor_ui.go b/pkg/editor_ui.go index 1664e6c..e77937e 100644 --- a/pkg/editor_ui.go +++ b/pkg/editor_ui.go @@ -548,9 +548,12 @@ func (u *EditorUI) SetupStatusBar(d *Doodle) *ui.Frame { } } - // TODO: right-aligned labels clip out of bounds + var shareware string + if balance.FreeVersion { + shareware = " (shareware)" + } extraLabel := ui.NewLabel(ui.Label{ - Text: "blah", + Text: "Doodle v" + Version + shareware, Font: balance.StatusFont, }) extraLabel.Configure(ui.Config{ diff --git a/pkg/editor_ui_doodad.go b/pkg/editor_ui_doodad.go index 4bae7d0..fa09133 100644 --- a/pkg/editor_ui_doodad.go +++ b/pkg/editor_ui_doodad.go @@ -49,6 +49,68 @@ func (u *EditorUI) setupDoodadFrame(e render.Engine, window *ui.Window) (*ui.Fra perRow = balance.UIDoodadsPerRow ) + frame.SetBackground(render.RGBA(0, 153, 255, 153)) + + // Toolbar on top of the Doodad panel. + toolbar := ui.NewFrame("Doodad Palette Toolbar") + toolbar.Configure(ui.Config{ + Background: render.Grey, + BorderSize: 2, + BorderStyle: ui.BorderRaised, + Height: 20, + }) + { + // Link button. + linkButton := ui.NewButton("Link", ui.NewLabel(ui.Label{ + Text: "Link Doodads", + })) + linkButton.Handle(ui.Click, func(p render.Point) { + u.d.Flash("Hello world") + }) + u.Supervisor.Add(linkButton) + + toolbar.Pack(linkButton, ui.Pack{ + Anchor: ui.N, + FillX: true, + }) + } + frame.Pack(toolbar, ui.Pack{ + Anchor: ui.N, + Fill: true, + }) + + // Pager buttons on top of the doodad list. + pager := ui.NewFrame("Doodad Pager") + { + leftBtn := ui.NewButton("Prev Page", ui.NewLabel(ui.Label{ + Text: "<", + })) + u.Supervisor.Add(leftBtn) + pager.Pack(leftBtn, ui.Pack{ + Anchor: ui.W, + }) + + pageLabel := ui.NewLabel(ui.Label{ + Text: " Page 1 of 20", + }) + pager.Pack(pageLabel, ui.Pack{ + Anchor: ui.W, + Expand: true, + }) + + rightBtn := ui.NewButton("Next Page", ui.NewLabel(ui.Label{ + Text: ">", + })) + u.Supervisor.Add(rightBtn) + pager.Pack(rightBtn, ui.Pack{ + Anchor: ui.W, + }) + } + frame.Pack(pager, ui.Pack{ + Anchor: ui.N, + Fill: true, + }) + doodadsAvailable, err := doodads.ListDoodads() if err != nil { return frame, fmt.Errorf( diff --git a/pkg/uix/canvas.go b/pkg/uix/canvas.go index b68fb0c..557c483 100644 --- a/pkg/uix/canvas.go +++ b/pkg/uix/canvas.go @@ -65,6 +65,10 @@ type Canvas struct { OnDeleteActors func([]*level.Actor) OnDragStart func(filename string) + // When the Canvas wants to link two actors together. Arguments are the IDs + // of the two actors. + OnLinkActors func(a, b string) + // Tracking pixels while editing. TODO: get rid of pixelHistory? pixelHistory []*level.Pixel lastPixel *level.Pixel diff --git a/pkg/uix/canvas_wallpaper.go b/pkg/uix/canvas_wallpaper.go index a1f623c..8c5f25d 100644 --- a/pkg/uix/canvas_wallpaper.go +++ b/pkg/uix/canvas_wallpaper.go @@ -88,19 +88,19 @@ func (w *Canvas) PresentWallpaper(e render.Engine, p render.Point) error { // from the Origin (0,0) we find out by how far (subtract full tile sizes) // and use the remainder as an offset for drawing the tiles. var dx, dy int32 - if origin.X > 0 { - for origin.X > 0 && origin.X > size.W { + if origin.X > p.X { + for origin.X > p.X && origin.X > size.W { origin.X -= size.W } dx = origin.X - origin.X = 0 + origin.X = p.X } - if origin.Y > 0 { - for origin.Y > 0 && origin.Y > size.H { + if origin.Y > p.Y { + for origin.Y > p.Y && origin.Y > size.H { origin.Y -= size.H } dy = origin.Y - origin.Y = 0 + origin.Y = p.Y } // And capping the scroll delta in the other direction. diff --git a/pkg/uix/draw_modes.go b/pkg/uix/draw_modes.go index 2168b1f..ebf631f 100644 --- a/pkg/uix/draw_modes.go +++ b/pkg/uix/draw_modes.go @@ -7,11 +7,13 @@ type Tool int const ( PencilTool Tool = iota // draw pixels where the mouse clicks ActorTool // drag and move actors + LinkTool ) var toolNames = []string{ "Pencil", "Doodad", // readable name for ActorTool + "Link", } func (t Tool) String() string {