Scrollable editors

This commit is contained in:
Jeremy Penner 2021-04-18 22:26:18 -04:00
parent fab335ce6a
commit b7637e5747
3 changed files with 13 additions and 5 deletions

View file

@ -13,7 +13,10 @@
(GraphicsEditView.super.new self)
(set self.tilecache (tiledraw.TileCache (tiles.loadgfx (self:filename)) (self:spritegen)))
(set self.itile 1)
(set self.scrollheight math.huge)
(set self.scrollable true)
(attach-imstate self))
(fn GraphicsEditView.get_scrollable_size [self] self.scrollheight)
(fn GraphicsEditView.spritegen [self] tiledraw.tile-to-sprite)
(fn GraphicsEditView.tilesize [self] (values 16 16))
(fn GraphicsEditView.tilebytelen [self] (let [(w h) (self:tilesize)] (/ (* w h) 8)))

View file

@ -170,9 +170,10 @@
(tset :map (self.level.map:tohex)))))
(fn MapEditView.draw [self]
(var x (+ self.position.x 10))
(var y (+ self.position.y 10))
(var x (+ self.position.x style.padding.x (- self.scroll.x)))
(var y (+ self.position.y style.padding.y (- self.scroll.y)))
(self:draw_background style.background)
(self:draw_scrollbar)
(love.graphics.setColor 1 1 1 1)
(self:draw-map-editor x y)
(when self.iobject
@ -194,7 +195,8 @@
(set self.playerpos player))
(set y (+ y 30)))
(set y (+ y 30))
(self:draw-tile-selector x y (- self.size.x 20)))
(set y (+ y (self:draw-tile-selector x y (- self.size.x 20))))
(set self.scrollheight (- y (+ self.position.y style.padding.y (- self.scroll.y)))))
(fn MapEditView.get_name [self] (.. "Map: " self.mapfilename))

View file

@ -89,13 +89,16 @@
(fn TileView.draw [self]
(self:draw_background style.background)
(local (x y) (values (+ self.position.x 10) (+ self.position.y 10)))
(self:draw_scrollbar)
(local (x y) (values (+ self.position.x style.padding.x (- self.scroll.x))
(+ self.position.y style.padding.y (- self.scroll.y))))
(local (editor-w editor-h) (self:draw-tile-editor (self:tile) x y))
(self:draw-tile-flags (+ x editor-w pixel-size) y)
(var selector-y (+ y editor-h pixel-size))
(each [_ key (ipairs (self:tilekeys))]
(local selector-h (self:draw-tile-selector x selector-y (- self.size.x 20) key))
(set selector-y (+ selector-y selector-h pixel-size))))
(set selector-y (+ selector-y selector-h pixel-size)))
(set self.scrollheight (- selector-y y)))
(fn TileView.get_name [self] "Tile Editor")