refactor map editor, add action editor
This commit is contained in:
parent
6f40e7ff40
commit
79c8791dac
12
editor/actions.fnl
Normal file
12
editor/actions.fnl
Normal file
|
@ -0,0 +1,12 @@
|
|||
(local util (require :lib.util))
|
||||
(local {: defmulti : defmethod} (util.require :lib.multimethod))
|
||||
(local {: textfield} (util.require :editor.imstate))
|
||||
|
||||
(local actions (util.hot-table ...))
|
||||
|
||||
(set actions.edit (defmulti #$1.action :edit ...))
|
||||
(set actions.generate (defmulti #$1.action :generate ...))
|
||||
|
||||
(defmethod actions.edit :default (fn [action view x y w i] y))
|
||||
|
||||
actions.hot
|
|
@ -84,7 +84,7 @@
|
|||
(fn button [view tag x y w h]
|
||||
(when (mouse-inside x y w h) (set view.cursor :hand))
|
||||
(activate view tag x y w h)
|
||||
(and (active? view tag) (= view.imstate.left :released) (mouse-inside x y w h)))
|
||||
(values (and (active? view tag) (= view.imstate.left :released) (mouse-inside x y w h)) (+ y h style.padding.y)))
|
||||
|
||||
(fn textbutton [view label x y]
|
||||
(local (w h) (values (+ (style.font:get_width label) style.padding.x) (+ (style.font:get_height) style.padding.y)))
|
||||
|
@ -244,7 +244,7 @@
|
|||
(set view.imstate.focus.selection option))
|
||||
(set row-y (+ row-y row-h)))))
|
||||
|
||||
(or new-selection selection))
|
||||
(values (or new-selection selection) (+ y row-h)))
|
||||
|
||||
{: attach-imstate : cmd-predicate : postpone : mouse-inside : activate : active?
|
||||
: button : checkbox : textbox : textfield : textbutton : dropdown}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
(local {: mouse-inside : activate : active? : checkbox : textfield : textbutton : dropdown} (util.require :editor.imstate))
|
||||
(local {: tilestrip-to-sprite} (util.require :editor.tiledraw))
|
||||
(local {: encode-yx : encode-itile : decode-itile} (util.require :game.tiles))
|
||||
(local actions (require :editor.actions))
|
||||
|
||||
(local MapEditView (GraphicsEditView:extend))
|
||||
(local sprite-scale 3)
|
||||
|
@ -140,20 +141,43 @@
|
|||
(if (= self.imstate.left :released) (set self.iobject-linking nil)
|
||||
(self:draw-link-line x y self.iobject-linking [0 1 0] true)))))
|
||||
|
||||
(fn MapEditView.draw-object-editor [self x y]
|
||||
(fn MapEditView.draw-object-code-editor [self object x y]
|
||||
(var y y)
|
||||
(local object (self:object))
|
||||
(set (object.func y) (textfield self "Word" object.func x y 100 200))
|
||||
(set (object.name y) (textfield self "Name" object.name x (+ y 5) 100 200))
|
||||
(set (object.linkword y) (textfield self "Link word" object.linkword x (+ y 5) 100 200))
|
||||
(if object.link
|
||||
(match (textbutton self "Unlink" x (+ y 5))
|
||||
(unlink yNext) (do (when unlink (set object.link nil))
|
||||
(set y yNext)))
|
||||
(set (object.linkentity y) (textfield self "Link entity" object.linkentity x (+ y 5) 100 200)))
|
||||
(when (textbutton self "Delete" x (+ y 40))
|
||||
(var istep-to-delete nil)
|
||||
(when (not object.steps) (set object.steps []))
|
||||
(each [istep step (ipairs object.steps)]
|
||||
(when (textbutton self "X" (+ x 280) y)
|
||||
(set istep-to-delete istep))
|
||||
(set (step.action y) (dropdown self [:code-action istep] (or step.action :say) [:say :warp] x y 100))
|
||||
(set y (actions.edit step self x y 300 istep))
|
||||
(set y (+ y style.padding.y)))
|
||||
(when istep-to-delete (table.remove object.steps istep-to-delete))
|
||||
(let [(do-new y) (textbutton self "+ New Step" x (+ y style.padding.y))]
|
||||
(when do-new (table.insert object.steps {}))
|
||||
y))
|
||||
|
||||
(fn MapEditView.draw-object-advanced-editor [self object x y]
|
||||
(let [(func y) (textfield self "Word" object.func x y 100 200)
|
||||
(name y) (textfield self "Name" object.name x (+ y style.padding.y) 100 200)
|
||||
(linkword y) (textfield self "Link word" object.linkword x (+ y style.padding.y) 100 200)
|
||||
(do-unlink y) (if object.link (textbutton self "Unlink" x (+ y style.padding.y)) (values false y))
|
||||
(linkentity y) (if object.link (values object.linkentity y) (textfield self "Link entity" object.linkentity x (+ y style.padding.y) 100 200))]
|
||||
(lume.extend object {: func : name : linkword : linkentity})
|
||||
(when do-unlink (set object.link nil))
|
||||
y))
|
||||
|
||||
(fn MapEditView.draw-object-editor [self x y]
|
||||
(let [object (self:object)
|
||||
y (if object.advanced
|
||||
(self:draw-object-advanced-editor object x y)
|
||||
(self:draw-object-code-editor object x y))
|
||||
do-delete (textbutton self "Delete" x (+ y 40))
|
||||
(do-advanced y) (textbutton self (if object.advanced "Simple" "Advanced") (+ x 150) (+ y 40))]
|
||||
(when do-delete
|
||||
(move-object self.level.objects (+ self.iobject 1) self.iobject)
|
||||
(set self.iobject nil)))
|
||||
(set self.iobject nil))
|
||||
(when do-advanced (set object.advanced (not object.advanced)))
|
||||
y))
|
||||
|
||||
(fn MapEditView.reload [self]
|
||||
(MapEditView.super.reload self)
|
||||
|
@ -175,27 +199,28 @@
|
|||
(self:draw_background style.background)
|
||||
(self:draw_scrollbar)
|
||||
(love.graphics.setColor 1 1 1 1)
|
||||
(local ytop y)
|
||||
(self:draw-map-editor x y)
|
||||
(when self.iobject
|
||||
(self:draw-object-editor (+ x (* tilew mapw) 10) y))
|
||||
(set y (+ y (* tileh maph) 10))
|
||||
(set self.level.tickword (textfield self "Tick word" self.level.tickword x y 100 200))
|
||||
(set y (+ y 30))
|
||||
(set self.level.moveword (textfield self "Move word" self.level.moveword x y 100 200))
|
||||
(set y (+ y 30))
|
||||
(set self.level.loadword (textfield self "Load word" self.level.loadword x y 100 200))
|
||||
(set y (+ y 30))
|
||||
(when (checkbox self "Edit objects" (= self.itile nil) x y)
|
||||
(set y (+ y (* tileh maph) style.padding.y))
|
||||
(set y (+ y (self:draw-tile-selector x y (- self.size.x (* style.padding.x 2)))))
|
||||
|
||||
(set (self.level.tickword y) (textfield self "Tick word" self.level.tickword x (+ y style.padding.y) 100 200))
|
||||
(set (self.level.moveword y) (textfield self "Move word" self.level.moveword x (+ y style.padding.y) 100 200))
|
||||
(set (self.level.loadword y) (textfield self "Load word" self.level.loadword x (+ y style.padding.y) 100 200))
|
||||
(let [(checked y-new) (checkbox self "Edit objects" (= self.itile nil) x (+ y style.padding.y))
|
||||
_ (when checked
|
||||
(set self.itile nil)
|
||||
(set self.playerpos nil))
|
||||
(set y (+ y 30))
|
||||
(let [player :player]
|
||||
(when (checkbox self (.. "Position " player) (and (= self.itile nil) (= self.playerpos player)) x y)
|
||||
(checked y-new) (checkbox self (.. "Position " :player) (and (= self.itile nil) (= self.playerpos :player)) x (+ y-new style.padding.y))]
|
||||
(when checked
|
||||
(set self.itile nil)
|
||||
(set self.playerpos player))
|
||||
(set y (+ y 30)))
|
||||
(set y (+ y 30))
|
||||
(set y (+ y (self:draw-tile-selector x y (- self.size.x 20))))
|
||||
(set self.playerpos :player))
|
||||
(set y y-new))
|
||||
(when self.iobject
|
||||
(set y (math.max y (if (> self.size.x (+ (* tilew mapw) 300))
|
||||
(self:draw-object-editor (+ x (* tilew mapw) style.padding.x) ytop)
|
||||
(self:draw-object-editor x (+ y style.padding.y))))))
|
||||
|
||||
(set self.scrollheight (- y (+ self.position.y style.padding.y (- self.scroll.y)))))
|
||||
|
||||
(fn MapEditView.get_name [self] (.. "Map: " self.mapfilename))
|
||||
|
|
Loading…
Reference in a new issue