2018-10-20 22:42:49 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
// XXX REFACTOR XXX
|
|
|
|
// This function only uses EditorUI and not Doodle and is a candidate for
|
|
|
|
// refactor into a subpackage if EditorUI itself can ever be decoupled.
|
|
|
|
|
|
|
|
import (
|
2022-09-24 22:17:25 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/uix"
|
2019-12-28 03:16:34 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2018-10-20 22:42:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DraggableActor is a Doodad being dragged from the Doodad palette.
|
|
|
|
type DraggableActor struct {
|
|
|
|
canvas *uix.Canvas
|
2019-07-05 23:04:36 +00:00
|
|
|
doodad *doodads.Doodad // if a new one from the palette
|
|
|
|
actor *level.Actor // if a level actor
|
2018-10-20 22:42:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-09 21:41:24 +00:00
|
|
|
// Teardown the DraggableActor and free its textures.
|
|
|
|
func (da *DraggableActor) Teardown() {
|
|
|
|
log.Debug("Teardown DraggableActor")
|
|
|
|
da.canvas.Destroy()
|
|
|
|
}
|
|
|
|
|
2018-10-21 00:08:20 +00:00
|
|
|
// startDragActor begins the drag event for a Doodad onto a level.
|
2019-07-05 23:04:36 +00:00
|
|
|
// actor may be nil (if you drag a new doodad from the palette) or otherwise
|
|
|
|
// is an existing actor from the level.
|
|
|
|
func (u *EditorUI) startDragActor(doodad *doodads.Doodad, actor *level.Actor) {
|
2018-10-21 00:08:20 +00:00
|
|
|
u.Supervisor.DragStart()
|
|
|
|
|
2019-07-05 23:04:36 +00:00
|
|
|
if doodad == nil {
|
|
|
|
if actor != nil {
|
2023-02-19 01:37:54 +00:00
|
|
|
obj, err := doodads.LoadFromEmbeddable(actor.Filename, u.Scene.Level, false)
|
2019-07-05 23:04:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("startDragExistingActor: actor doodad name %s not found: %s", actor.Filename, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
doodad = obj
|
|
|
|
} else {
|
|
|
|
panic("EditorUI.startDragActor: doodad AND/OR actor is required, but neither were given")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 22:26:51 +00:00
|
|
|
// Size and scale this doodad according to the zoom level.
|
2023-02-17 05:47:18 +00:00
|
|
|
size := doodad.Size
|
2021-09-12 22:26:51 +00:00
|
|
|
size.W = u.Canvas.ZoomMultiply(size.W)
|
|
|
|
size.H = u.Canvas.ZoomMultiply(size.H)
|
|
|
|
|
2018-10-21 00:08:20 +00:00
|
|
|
// Create the canvas to render on the mouse cursor.
|
|
|
|
drawing := uix.NewCanvas(doodad.Layers[0].Chunker.Size, false)
|
|
|
|
drawing.LoadDoodad(doodad)
|
2021-09-12 22:26:51 +00:00
|
|
|
drawing.Resize(size)
|
|
|
|
drawing.Zoom = u.Canvas.Zoom
|
2018-10-21 00:08:20 +00:00
|
|
|
drawing.SetBackground(render.RGBA(0, 0, 1, 0)) // TODO: invisible becomes white
|
|
|
|
drawing.MaskColor = balance.DragColor // blueprint effect
|
|
|
|
u.DraggableActor = &DraggableActor{
|
|
|
|
canvas: drawing,
|
|
|
|
doodad: doodad,
|
2019-07-05 23:04:36 +00:00
|
|
|
actor: actor,
|
2018-10-21 00:08:20 +00:00
|
|
|
}
|
|
|
|
}
|