commit 34a0748a370bbbe4b64e814f9d2c1b3c99297075
parent 1327d19db0d20bd9cd5f169defbf09a8e41f9db0
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Wed, 9 Oct 2024 11:02:24 -0700
Improve furniture adding
Add furniture at the center of the viewport unless the last click
on the editor is in view, in which case add it there.
Diffstat:
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js
@@ -25,7 +25,8 @@ const zoomBit = 2
let State = {
panZoom: 0,
- pointOp: 'Create'
+ pointOp: 'Create',
+ lastClick: null
}
// turn off bubbling
@@ -126,14 +127,27 @@ function init() {
})
)
- let addFurn = ui.button("Add Furniture", "Add furniture", "add", { handlers: {
+ let addFurn = ui.button("Add Furniture", "Add furniture", null, { handlers: {
// TODO: Create it at the last clicked point if on screen, else somewhere reasonable on screen
- click: function() { furnitureMenu(editor, { x: 0, y: 0 }) }
+ click: function() {
+ let p
+ const v = editor.draw.viewbox()
+ const c = { x: v.x + v.width / 2, y: v.y + v.height / 2 }
+ if (State.lastClick != null) {
+ p = State.lastClick
+ if (p.x < v.x || p.x > v.x + v.width || p.y < p.height || p.y > p.y + p.height) {
+ p = c
+ }
+ } else {
+ p = c
+ }
+ furnitureMenu(editor, p)
+ }
}})
- toolbar.append(item(addFurn))
toolbar.append(undoRedo)
toolbar.append(pushpull)
+ toolbar.append(item(addFurn))
if (debug) {
toolbar.append(item(
@@ -345,6 +359,7 @@ function selectionHandler(event, editor) {
}
let p = editor.draw.point(event.clientX, event.clientY)
+ State.lastClick = structuredClone(p)
let order = [ "#" + editor.layoutG(), "#points", "#pointmaps" ]
for (let i = 0; i < order.length; ++i) {
let x = editor.thingAt(p, order[i])
@@ -925,6 +940,8 @@ function furnitureMenuX(editor, pointOrID) {
}
id = editor.addMappedFurniture(params)
+ editor.finishAction()
+ editor.findObj(id).select()
}
let items = [