update tile selector to use horiz-wrapper layout
This commit is contained in:
parent
f81dd88a52
commit
8b646eac4b
|
@ -3,7 +3,7 @@
|
|||
(local tiledraw (require :editor.tiledraw))
|
||||
(local util (require :lib.util))
|
||||
(local files (require :game.files))
|
||||
(local {: attach-imstate : button : vert} (util.require :editor.imgui))
|
||||
(local {: attach-imstate : button : vert : horiz-wrapper} (util.require :editor.imgui))
|
||||
|
||||
(local GraphicsEditView (View:extend))
|
||||
|
||||
|
@ -40,25 +40,17 @@
|
|||
(love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale)
|
||||
(values (* (sprite:getWidth) self.sprite-scale) (* (sprite:getHeight) self.sprite-scale)))))
|
||||
|
||||
(fn tile-selector [{: view : x : y : w : scale &as form} chosen-itile ?key]
|
||||
(var tilex x)
|
||||
(var tiley y)
|
||||
(var selected-itile nil)
|
||||
(var (pixw pixh) (view:tilesize))
|
||||
(when (= files.game.platform :ii) (set pixw (* (/ pixw 8) 7)))
|
||||
(local tilew (* scale pixw))
|
||||
(local tileh (* scale pixh))
|
||||
(for [itile 1 (length view.tilecache.tiles)]
|
||||
(view:draw-sprite tilex tiley itile ?key)
|
||||
(when (= itile chosen-itile)
|
||||
(love.graphics.rectangle :line (- tilex 2) (- tiley 2) (+ tilew 4) (+ tileh 4)))
|
||||
(when (button {: view :tag [:tile itile] :x tilex :y tiley :w tilew :h tileh})
|
||||
(set selected-itile itile))
|
||||
(set tilex (+ tilex tilew 4))
|
||||
(when (>= (+ tilex tilew) (+ x w))
|
||||
(set tilex x)
|
||||
(set tiley (+ tiley tileh 4))))
|
||||
(set form.h (+ tiley tileh (- y)))
|
||||
(fn tile-selector [{: view &as form} selected-itile ?key]
|
||||
(var selected-itile selected-itile)
|
||||
(let [wrap (horiz-wrapper form)]
|
||||
(for [itile 1 (length view.tilecache.tiles)]
|
||||
(let [{: x : y} form
|
||||
(w h) (view:draw-sprite x y itile ?key)]
|
||||
(when (and w h)
|
||||
(when (= itile selected-itile)
|
||||
(love.graphics.rectangle :line (- x 2) (- y 2) (+ w 4) (+ h 4)))
|
||||
(when (wrap button {:tag [:tile itile] : w : h})
|
||||
(set selected-itile itile))))))
|
||||
selected-itile)
|
||||
|
||||
(fn GraphicsEditView.draw-tile-selector [self form ?key]
|
||||
|
|
|
@ -308,7 +308,7 @@
|
|||
(each [key (pairs form)]
|
||||
(when (= (. form-preserved-keys key) nil)
|
||||
(tset form key nil)))
|
||||
(lume.extend form overrides)
|
||||
(lume.extend form (or overrides {}))
|
||||
form)
|
||||
|
||||
(fn vert [form viewfn overrides ...]
|
||||
|
@ -326,7 +326,7 @@
|
|||
(fn [viewfn overrides ...]
|
||||
(let [result [(viewfn (prepare-form form overrides) ...)]]
|
||||
(set form.x (+ form.x (or form.w 0) (or form.xpad 0)))
|
||||
(when (> form.x (+ x w))
|
||||
(when (> (+ form.x (or form.w 0)) (+ x w))
|
||||
(set form.x x)
|
||||
(set form.y (+ form.y form.h (or form.ypad 0))))
|
||||
(table.unpack result))))
|
||||
|
|
Loading…
Reference in a new issue