2019-04-10 02:17:56 +00:00
|
|
|
package uix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2022-09-24 22:17:25 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
Doodad/Actor Runtime Options
* Add "Options" support for Doodads: these allow for individual Actor instances
on your level to customize properties about the doodad. They're like "Tags"
except the player can customize them on a per-actor basis.
* Doodad Editor: you can specify the Options in the Doodad Properties window.
* Level Editor: when the Actor Tool is selected, on mouse-over of an actor,
clicking on the gear icon will open a new "Actor Properties" window which
shows metadata (title, author, ID, position) and an Options tab to configure
the actor's options.
Updates to the scripting API:
* Self.Options() returns a list of option names defined on the Doodad.
* Self.GetOption(name) returns the value for the named option, or nil if
neither the actor nor its doodad have the option defined. The return type
will be correctly a string, boolean or integer type.
Updates to the doodad command-line tool:
* `doodad show` will print the Options on a .doodad file and, when showing a
.level file with --actors, prints any customized Options with the actors.
* `doodad edit-doodad` adds a --option parameter to define options.
Options added to the game's built-in doodads:
* Warp Doors: "locked (exit only)" will make it so the door can not be opened
by the player, giving the "locked" message (as if it had no linked door),
but the player may still exit from the door if sent by another warp door.
* Electric Door & Electric Trapdoor: "opened" can make the door be opened by
default when the level begins instead of closed. A switch or a button that
removes power will close the door as normal.
* Colored Doors & Small Key Door: "unlocked" will make the door unlocked at
level start, not requiring a key to open it.
* Colored Keys & Small Key: "has gravity" will make the key subject to gravity
and set its Mobile flag so that if it falls onto a button, it will activate.
* Gemstones: they had gravity by default; you can now uncheck "has gravity" to
remove their Gravity and IsMobile status.
* Gemstone Totems: "has gemstone" will set the totem to its unlocked status by
default with the gemstone inserted. No power signal will be emitted; it is
cosmetic only.
* Fire Region: "name" can let you set a name for the fire region similarly to
names for fire pixels: "Watch out for ${name}!"
* Invisible Warp Door: "locked (exit only)" added as well.
2022-10-10 00:41:24 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/sprites"
|
2019-12-28 03:16:34 +00:00
|
|
|
"git.kirsle.net/go/render"
|
|
|
|
"git.kirsle.net/go/ui"
|
2019-04-10 02:17:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Present the canvas.
|
|
|
|
func (w *Canvas) Present(e render.Engine, p render.Point) {
|
|
|
|
var (
|
|
|
|
S = w.Size()
|
|
|
|
Viewport = w.Viewport()
|
2021-07-12 04:54:28 +00:00
|
|
|
// Bezel = render.NewRect(
|
|
|
|
// p.X+w.Scroll.X+w.BoxThickness(1),
|
|
|
|
// p.Y+w.Scroll.Y+w.BoxThickness(1),
|
|
|
|
// )
|
|
|
|
// zoomMultiplier = int(w.GetZoomMultiplier())
|
2019-04-10 02:17:56 +00:00
|
|
|
)
|
|
|
|
// w.MoveTo(p) // TODO: when uncommented the canvas will creep down the Workspace frame in EditorMode
|
|
|
|
w.DrawBox(e, p)
|
|
|
|
e.DrawBox(w.Background(), render.Rect{
|
|
|
|
X: p.X + w.BoxThickness(1),
|
|
|
|
Y: p.Y + w.BoxThickness(1),
|
|
|
|
W: S.W - w.BoxThickness(2),
|
|
|
|
H: S.H - w.BoxThickness(2),
|
|
|
|
})
|
|
|
|
|
2022-01-09 21:16:29 +00:00
|
|
|
// If we are an Actor canvas as part of a Level, get the absolute position of
|
|
|
|
// the parent (Level) canvas so we can compare where the Actor is drawn on-screen
|
|
|
|
// and detect if we are at the Top or Left edges of the parent, to crop and adjust
|
|
|
|
// the texture accordingly.
|
|
|
|
var ParentPosition render.Point
|
|
|
|
if w.parent != nil {
|
|
|
|
ParentPosition = ui.AbsolutePosition(w.parent)
|
|
|
|
}
|
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
// Draw the wallpaper.
|
|
|
|
if w.wallpaper.Valid() {
|
|
|
|
err := w.PresentWallpaper(e, p)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 04:20:45 +00:00
|
|
|
// Scale the viewport to account for zoom level.
|
2021-07-13 05:19:36 +00:00
|
|
|
if w.Zoom != 0 {
|
2021-07-13 04:20:45 +00:00
|
|
|
// Zoomed out (level go tiny)
|
2021-07-13 05:19:36 +00:00
|
|
|
// TODO: seems unstable as shit on Zoom In??
|
2021-07-13 04:20:45 +00:00
|
|
|
Viewport.W = w.ZoomDivide(Viewport.W)
|
2021-09-12 22:26:51 +00:00
|
|
|
Viewport.H = w.ZoomDivide(Viewport.H)
|
2021-09-12 22:47:16 +00:00
|
|
|
if w.Zoom != 0 {
|
2021-09-12 22:26:51 +00:00
|
|
|
Viewport.X = w.ZoomDivide(Viewport.X)
|
|
|
|
Viewport.Y = w.ZoomDivide(Viewport.Y)
|
2021-09-12 05:21:47 +00:00
|
|
|
}
|
2021-07-13 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 05:19:36 +00:00
|
|
|
// Disappearing chunks issue:
|
|
|
|
// When at the top-left corner of a bounded level,
|
|
|
|
// And Zoom=2 (200% zoom), Level Chunk Size=128,
|
|
|
|
// When you scroll down exactly -128 pixels, the whole row
|
|
|
|
// of chunks along the top edge of the viewport unload.
|
|
|
|
// At -256, the next row of chunks unloads.
|
|
|
|
// At -383, another row - it's creeping down the page with
|
|
|
|
// the top 1/3 of the level editor showing blank wallpaper
|
|
|
|
// At -768, about 3/4 the level editor is blank
|
|
|
|
//
|
|
|
|
// It must think the upper 128px of chunks had left the
|
|
|
|
// viewport when in fact the bottom half of them was still
|
|
|
|
// in view, not respecting the 2X zoom level.
|
|
|
|
//
|
|
|
|
// Viewport is like: Rect<128,0,1058,721>
|
|
|
|
// Level chunks would be:
|
|
|
|
// (0, 0) = (0,0, 127,127) chunk A
|
|
|
|
// (1, 0) = (128,128, 255,255) chunk B
|
|
|
|
// At 2x zoom, Chunk A is still half on screen at -128 scroll
|
2021-09-12 21:42:39 +00:00
|
|
|
// if w.Zoom > 0 {
|
|
|
|
// Viewport.X = w.ZoomDivide(w.chunks.Size)
|
|
|
|
// Viewport.Y = w.ZoomDivide(w.chunks.Size)
|
|
|
|
// }
|
2021-09-12 22:26:51 +00:00
|
|
|
// Seems resolved now?
|
2021-07-13 05:19:36 +00:00
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
// Get the chunks in the viewport and cache their textures.
|
|
|
|
for coord := range w.chunks.IterViewportChunks(Viewport) {
|
|
|
|
if chunk, ok := w.chunks.GetChunk(coord); ok {
|
|
|
|
var tex render.Texturer
|
|
|
|
if w.MaskColor != render.Invisible {
|
|
|
|
tex = chunk.TextureMasked(e, w.MaskColor)
|
|
|
|
} else {
|
|
|
|
tex = chunk.Texture(e)
|
|
|
|
}
|
2020-11-20 04:08:38 +00:00
|
|
|
|
|
|
|
// Zoom in the texture.
|
2021-07-12 04:54:28 +00:00
|
|
|
var (
|
|
|
|
texSize = tex.Size()
|
2022-01-09 21:16:29 +00:00
|
|
|
texSizeOrig = texSize
|
2021-07-12 04:54:28 +00:00
|
|
|
)
|
|
|
|
|
2020-11-20 04:08:38 +00:00
|
|
|
if w.Zoom != 0 {
|
|
|
|
texSize.W = w.ZoomMultiply(texSize.W)
|
|
|
|
texSize.H = w.ZoomMultiply(texSize.H)
|
|
|
|
}
|
2019-04-10 02:17:56 +00:00
|
|
|
src := render.Rect{
|
2020-11-20 04:08:38 +00:00
|
|
|
W: texSize.W,
|
|
|
|
H: texSize.H,
|
2019-04-10 02:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the source bitmap is already bigger than the Canvas widget
|
|
|
|
// into which it will render, cap the source width and height.
|
|
|
|
// This is especially useful for Doodad buttons because the drawing
|
|
|
|
// is bigger than the button.
|
|
|
|
if src.W > S.W {
|
|
|
|
src.W = S.W
|
|
|
|
}
|
|
|
|
if src.H > S.H {
|
|
|
|
src.H = S.H
|
|
|
|
}
|
|
|
|
|
|
|
|
dst := render.Rect{
|
2021-07-12 04:54:28 +00:00
|
|
|
X: p.X + w.Scroll.X + w.BoxThickness(1) + w.ZoomMultiply(coord.X*chunk.Size),
|
|
|
|
Y: p.Y + w.Scroll.Y + w.BoxThickness(1) + w.ZoomMultiply(coord.Y*chunk.Size),
|
2019-04-10 02:17:56 +00:00
|
|
|
|
|
|
|
// src.W and src.H will be AT MOST the full width and height of
|
|
|
|
// a Canvas widget. Subtract the scroll offset to keep it bounded
|
|
|
|
// visually on its right and bottom sides.
|
|
|
|
W: src.W,
|
|
|
|
H: src.H,
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: all this shit is in TrimBox(), make it DRY
|
|
|
|
|
|
|
|
// If the destination width will cause it to overflow the widget
|
|
|
|
// box, trim off the right edge of the destination rect.
|
|
|
|
//
|
|
|
|
// Keep in mind we're dealing with chunks here, and a chunk is
|
|
|
|
// a small part of the image. Example:
|
|
|
|
// - Canvas is 800x600 (S.W=800 S.H=600)
|
|
|
|
// - Chunk wants to render at 790,0 width 100,100 or whatever
|
|
|
|
// dst={790, 0, 100, 100}
|
|
|
|
// - Chunk box would exceed 800px width (X=790 + W=100 == 890)
|
|
|
|
// - Find the delta how much it exceeds as negative (800 - 890 == -90)
|
|
|
|
// - Lower the Source and Dest rects by that delta size so they
|
|
|
|
// stay proportional and don't scale or anything dumb.
|
2022-01-09 21:16:29 +00:00
|
|
|
if dst.X+src.W > p.X+S.W+w.BoxThickness(1) {
|
2019-04-10 02:17:56 +00:00
|
|
|
// NOTE: delta is a negative number,
|
|
|
|
// so it will subtract from the width.
|
|
|
|
delta := (p.X + S.W - w.BoxThickness(1)) - (dst.W + dst.X)
|
|
|
|
src.W += delta
|
|
|
|
dst.W += delta
|
|
|
|
}
|
2022-01-09 21:16:29 +00:00
|
|
|
if dst.Y+src.H > p.Y+S.H+w.BoxThickness(1) {
|
2019-04-10 02:17:56 +00:00
|
|
|
// NOTE: delta is a negative number
|
|
|
|
delta := (p.Y + S.H - w.BoxThickness(1)) - (dst.H + dst.Y)
|
|
|
|
src.H += delta
|
|
|
|
dst.H += delta
|
|
|
|
}
|
|
|
|
|
|
|
|
// The same for the top left edge, so the drawings don't overlap
|
|
|
|
// menu bars or left side toolbars.
|
|
|
|
// - Canvas was placed 80px from the left of the screen.
|
|
|
|
// Canvas.MoveTo(80, 0)
|
|
|
|
// - A texture wants to draw at 60, 0 which would cause it to
|
|
|
|
// overlap 20 pixels into the left toolbar. It needs to be cropped.
|
|
|
|
// - The delta is: p.X=80 - dst.X=60 == 20
|
|
|
|
// - Set destination X to p.X to constrain it there: 20
|
|
|
|
// - Subtract the delta from destination W so we don't scale it.
|
|
|
|
// - Add 20 to X of the source: the left edge of source is not visible
|
2022-01-09 21:16:29 +00:00
|
|
|
//
|
|
|
|
// Note: the +w.BoxThickness works around a bug if the Actor Canvas has
|
|
|
|
// a border on it (e.g. in the Actor/Link Tool mouse-over or debug setting)
|
|
|
|
if dst.X == ParentPosition.X+w.BoxThickness(1) {
|
2019-04-10 02:17:56 +00:00
|
|
|
// NOTE: delta is a positive number,
|
|
|
|
// so it will add to the destination coordinates.
|
2022-01-09 21:16:29 +00:00
|
|
|
delta := texSizeOrig.W - src.W
|
2019-04-10 02:17:56 +00:00
|
|
|
dst.X = p.X + w.BoxThickness(1)
|
|
|
|
src.X += delta
|
|
|
|
}
|
2022-01-09 21:16:29 +00:00
|
|
|
if dst.Y == ParentPosition.Y+w.BoxThickness(1) {
|
|
|
|
delta := texSizeOrig.H - src.H
|
2019-04-10 02:17:56 +00:00
|
|
|
dst.Y = p.Y + w.BoxThickness(1)
|
|
|
|
src.Y += delta
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trim the destination width so it doesn't overlap the Canvas border.
|
|
|
|
if dst.W >= S.W-w.BoxThickness(1) {
|
|
|
|
dst.W = S.W - w.BoxThickness(1)
|
|
|
|
}
|
|
|
|
|
2021-07-12 04:54:28 +00:00
|
|
|
// When zooming OUT, make sure the source rect is at least the
|
|
|
|
// full size of the chunk texture; otherwise the ZoomMultiplies
|
|
|
|
// above do correctly scale e.g. 128x128 to 64x64, but it only
|
|
|
|
// samples the top-left 64x64 then and not the full texture so
|
|
|
|
// it more crops it than scales it, but does fit it neatly with
|
|
|
|
// its neighbors.
|
|
|
|
if w.Zoom < 0 {
|
|
|
|
src.W = texSizeOrig.W
|
|
|
|
src.H = texSizeOrig.H
|
|
|
|
}
|
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
e.Copy(tex, src, dst)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.drawActors(e, p)
|
2019-07-03 23:22:30 +00:00
|
|
|
w.presentStrokes(e)
|
Doodad/Actor Runtime Options
* Add "Options" support for Doodads: these allow for individual Actor instances
on your level to customize properties about the doodad. They're like "Tags"
except the player can customize them on a per-actor basis.
* Doodad Editor: you can specify the Options in the Doodad Properties window.
* Level Editor: when the Actor Tool is selected, on mouse-over of an actor,
clicking on the gear icon will open a new "Actor Properties" window which
shows metadata (title, author, ID, position) and an Options tab to configure
the actor's options.
Updates to the scripting API:
* Self.Options() returns a list of option names defined on the Doodad.
* Self.GetOption(name) returns the value for the named option, or nil if
neither the actor nor its doodad have the option defined. The return type
will be correctly a string, boolean or integer type.
Updates to the doodad command-line tool:
* `doodad show` will print the Options on a .doodad file and, when showing a
.level file with --actors, prints any customized Options with the actors.
* `doodad edit-doodad` adds a --option parameter to define options.
Options added to the game's built-in doodads:
* Warp Doors: "locked (exit only)" will make it so the door can not be opened
by the player, giving the "locked" message (as if it had no linked door),
but the player may still exit from the door if sent by another warp door.
* Electric Door & Electric Trapdoor: "opened" can make the door be opened by
default when the level begins instead of closed. A switch or a button that
removes power will close the door as normal.
* Colored Doors & Small Key Door: "unlocked" will make the door unlocked at
level start, not requiring a key to open it.
* Colored Keys & Small Key: "has gravity" will make the key subject to gravity
and set its Mobile flag so that if it falls onto a button, it will activate.
* Gemstones: they had gravity by default; you can now uncheck "has gravity" to
remove their Gravity and IsMobile status.
* Gemstone Totems: "has gemstone" will set the totem to its unlocked status by
default with the gemstone inserted. No power signal will be emitted; it is
cosmetic only.
* Fire Region: "name" can let you set a name for the fire region similarly to
names for fire pixels: "Watch out for ${name}!"
* Invisible Warp Door: "locked (exit only)" added as well.
2022-10-10 00:41:24 +00:00
|
|
|
w.presentDoodadButtons(e)
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
w.presentCursor(e)
|
2019-07-03 23:22:30 +00:00
|
|
|
|
2021-01-04 01:06:33 +00:00
|
|
|
// Custom label in the canvas corner? (e.g. for Inventory item counts)
|
|
|
|
if w.CornerLabel != "" {
|
|
|
|
label := ui.NewLabel(ui.Label{
|
|
|
|
Text: w.CornerLabel,
|
|
|
|
Font: render.Text{
|
|
|
|
FontFilename: balance.ShellFontFilename,
|
|
|
|
Size: balance.ShellFontSizeSmall,
|
|
|
|
Color: render.White,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
label.SetBackground(render.RGBA(0, 0, 50, 150))
|
|
|
|
label.Compute(e)
|
|
|
|
label.Present(e, render.Point{
|
|
|
|
X: p.X + S.W - label.Size().W - w.BoxThickness(1),
|
|
|
|
Y: p.Y + S.H - label.Size().H - w.BoxThickness(1),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
// XXX: Debug, show label in canvas corner.
|
|
|
|
if balance.DebugCanvasLabel {
|
|
|
|
rows := []string{
|
|
|
|
w.Name,
|
|
|
|
|
|
|
|
// XXX: debug options, uncomment for more details
|
|
|
|
|
|
|
|
// Size of the canvas
|
|
|
|
// fmt.Sprintf("S=%d,%d", S.W, S.H),
|
|
|
|
|
|
|
|
// Viewport of the canvas
|
|
|
|
// fmt.Sprintf("V=%d,%d:%d,%d",
|
|
|
|
// Viewport.X, Viewport.Y,
|
|
|
|
// Viewport.W, Viewport.H,
|
|
|
|
// ),
|
|
|
|
}
|
2019-04-14 22:25:03 +00:00
|
|
|
|
|
|
|
// Draw the actor's position details.
|
|
|
|
// LP = Level Position, where the Actor starts at in the level data
|
|
|
|
// WP = World Position, the Actor's current position in the level
|
2019-04-10 02:17:56 +00:00
|
|
|
if w.actor != nil {
|
|
|
|
rows = append(rows,
|
2019-04-14 22:25:03 +00:00
|
|
|
fmt.Sprintf("LP=%s", w.actor.Actor.Point),
|
|
|
|
fmt.Sprintf("WP=%s", w.actor.Position()),
|
2019-04-10 02:17:56 +00:00
|
|
|
)
|
|
|
|
}
|
2019-04-14 22:25:03 +00:00
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
label := ui.NewLabel(ui.Label{
|
|
|
|
Text: strings.Join(rows, "\n"),
|
|
|
|
Font: render.Text{
|
|
|
|
FontFilename: balance.ShellFontFilename,
|
|
|
|
Size: balance.ShellFontSizeSmall,
|
|
|
|
Color: render.White,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
label.SetBackground(render.RGBA(0, 0, 50, 150))
|
|
|
|
label.Compute(e)
|
|
|
|
label.Present(e, render.Point{
|
|
|
|
X: p.X + S.W - label.Size().W - w.BoxThickness(1),
|
|
|
|
Y: p.Y + w.BoxThickness(1),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
Doodad/Actor Runtime Options
* Add "Options" support for Doodads: these allow for individual Actor instances
on your level to customize properties about the doodad. They're like "Tags"
except the player can customize them on a per-actor basis.
* Doodad Editor: you can specify the Options in the Doodad Properties window.
* Level Editor: when the Actor Tool is selected, on mouse-over of an actor,
clicking on the gear icon will open a new "Actor Properties" window which
shows metadata (title, author, ID, position) and an Options tab to configure
the actor's options.
Updates to the scripting API:
* Self.Options() returns a list of option names defined on the Doodad.
* Self.GetOption(name) returns the value for the named option, or nil if
neither the actor nor its doodad have the option defined. The return type
will be correctly a string, boolean or integer type.
Updates to the doodad command-line tool:
* `doodad show` will print the Options on a .doodad file and, when showing a
.level file with --actors, prints any customized Options with the actors.
* `doodad edit-doodad` adds a --option parameter to define options.
Options added to the game's built-in doodads:
* Warp Doors: "locked (exit only)" will make it so the door can not be opened
by the player, giving the "locked" message (as if it had no linked door),
but the player may still exit from the door if sent by another warp door.
* Electric Door & Electric Trapdoor: "opened" can make the door be opened by
default when the level begins instead of closed. A switch or a button that
removes power will close the door as normal.
* Colored Doors & Small Key Door: "unlocked" will make the door unlocked at
level start, not requiring a key to open it.
* Colored Keys & Small Key: "has gravity" will make the key subject to gravity
and set its Mobile flag so that if it falls onto a button, it will activate.
* Gemstones: they had gravity by default; you can now uncheck "has gravity" to
remove their Gravity and IsMobile status.
* Gemstone Totems: "has gemstone" will set the totem to its unlocked status by
default with the gemstone inserted. No power signal will be emitted; it is
cosmetic only.
* Fire Region: "name" can let you set a name for the fire region similarly to
names for fire pixels: "Watch out for ${name}!"
* Invisible Warp Door: "locked (exit only)" added as well.
2022-10-10 00:41:24 +00:00
|
|
|
|
|
|
|
// Draw doodad buttons on mouseover in the level editor.
|
|
|
|
func (w *Canvas) presentDoodadButtons(e render.Engine) {
|
|
|
|
if !w.ShowDoodadButtons || w.parent == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the buttons the first time?
|
|
|
|
if w.doodadButtonFrame == nil {
|
|
|
|
var (
|
|
|
|
img ui.Widget
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
img, err = sprites.LoadImage(e, balance.GearIcon)
|
|
|
|
if err != nil {
|
|
|
|
// Error loading sprite, make a fallback frame.
|
|
|
|
frame := ui.NewFrame("Buttons")
|
|
|
|
frame.Configure(ui.Config{
|
|
|
|
Width: balance.UICanvasDoodadButtonSize,
|
|
|
|
Height: balance.UICanvasDoodadButtonSize,
|
|
|
|
Background: render.Green,
|
|
|
|
})
|
|
|
|
w.doodadButtonFrame = frame
|
|
|
|
} else {
|
|
|
|
w.doodadButtonFrame = img
|
|
|
|
}
|
|
|
|
|
|
|
|
w.doodadButtonFrame.Compute(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Error("presentDoodadButtons: parentP=%s w at %s (abs %s) actor at %s draw at %s", parentP, w.Point(), P, actorPoint, drawAt)
|
|
|
|
w.doodadButtonFrame.Present(e, w.doodadButtonRect().Point())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the screen rectangle where the doodad buttons would draw.
|
|
|
|
// screenCords: pass true to get on-screen coords (ignores scroll offset)
|
|
|
|
func (w *Canvas) doodadButtonRect() render.Rect {
|
|
|
|
if !w.ShowDoodadButtons || w.parent == nil {
|
|
|
|
return render.Rect{}
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
parentP = ui.AbsolutePosition(w.parent)
|
|
|
|
scroll = w.parent.Scroll
|
|
|
|
actorPoint = w.actor.Position()
|
|
|
|
actorSize = w.Size()
|
|
|
|
drawAt = render.Point{
|
|
|
|
X: parentP.X + scroll.X + actorPoint.X + actorSize.W - balance.UICanvasDoodadButtonSize - w.BoxThickness(1),
|
|
|
|
Y: parentP.Y + scroll.Y + actorPoint.Y + w.BoxThickness(1),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// If the doodad is Very Small so that its buttons take up a disproportionate
|
|
|
|
// amount of its space, draw the buttons further to the right.
|
|
|
|
if actorSize.W <= balance.UICanvasDoodadButtonSpaceNeeded {
|
|
|
|
drawAt.X += balance.UICanvasDoodadButtonSize / 2
|
|
|
|
drawAt.Y -= balance.UICanvasDoodadButtonSize / 2
|
|
|
|
}
|
|
|
|
|
|
|
|
return render.Rect{
|
|
|
|
X: drawAt.X,
|
|
|
|
Y: drawAt.Y,
|
|
|
|
W: drawAt.X + balance.UICanvasDoodadButtonSize,
|
|
|
|
H: drawAt.Y + balance.UICanvasDoodadButtonSize,
|
|
|
|
}
|
|
|
|
}
|