- [FIX] app.push() i app.pop() treballaven sobre mini.update, en compte de sobre app.update
- [FIX] tweening.update() ara es crida a nivell de aplicació - [NEW] tilepicker i itempicker adequats al nou disseny/sistema
This commit is contained in:
@@ -4,13 +4,13 @@ app = {
|
||||
stack = {},
|
||||
|
||||
push = function(func)
|
||||
table.insert(app.stack, mini.update)
|
||||
mini.update = func
|
||||
table.insert(app.stack, app.update)
|
||||
app.update = func
|
||||
end,
|
||||
|
||||
pop = function()
|
||||
if #app.stack > 0 then
|
||||
mini.update = table.remove(app.stack)
|
||||
app.update = table.remove(app.stack)
|
||||
end
|
||||
end,
|
||||
}
|
||||
@@ -23,7 +23,6 @@ editor = {
|
||||
end,
|
||||
|
||||
update = function()
|
||||
tweening.update(sys.delta())
|
||||
if sys.beat() then
|
||||
editor.ants = (editor.ants<<12) | (editor.ants>>4)
|
||||
end
|
||||
@@ -263,16 +262,48 @@ editor = {
|
||||
end,
|
||||
|
||||
tilepicker = {
|
||||
surf_back = nil,
|
||||
pos_y = 24,
|
||||
|
||||
show = function()
|
||||
if editor.tilepicker.surf_back == nil then editor.tilepicker.surf_back = surf.new(160,104) end
|
||||
surf.source(0)
|
||||
surf.target(editor.tilepicker.surf_back)
|
||||
view.origin(0,0)
|
||||
view.clip()
|
||||
draw.surf(0,0,160,104,0,0)
|
||||
app.push(editor.tilepicker.update_tiles)
|
||||
tweening.add(104,24,0.25,easing.easeOutCubic,function(value,n,finished)editor.tilepicker.pos_y=value end)
|
||||
end,
|
||||
|
||||
close = function()
|
||||
tweening.add(24,104,0.25,easing.easeInCubic,function(value,n,finished)editor.tilepicker.pos_y=value if finished then app.pop() end end)
|
||||
end,
|
||||
|
||||
update_tiles = function()
|
||||
surf.source(editor.tilepicker.surf_back)
|
||||
surf.target(0)
|
||||
view.origin(0,0)
|
||||
view.clip()
|
||||
draw.surf(0,0,160,104,0,0)
|
||||
|
||||
view.origin(8,editor.tilepicker.pos_y)
|
||||
draw.rrect(0,-1,144,84,3,17)
|
||||
draw.rrectf(0,0,144,84,3,20)
|
||||
draw.text("CHOOSE TILES:",8,2,17)
|
||||
|
||||
view.origin(16,editor.tilepicker.pos_y+8)
|
||||
|
||||
-- Pintar fondo quadrejat, per si la capa background està oculta
|
||||
for y=0,56,8 do
|
||||
for x=0,120,8 do
|
||||
local color = (((x+y)//8)%2==0) and 23 or 16
|
||||
draw.rectf(x, y, 8, 8, color);
|
||||
end
|
||||
end
|
||||
|
||||
surf.source(surf_tiles)
|
||||
surf.cls(1)
|
||||
--surf.cls(1)
|
||||
draw.surf(0,0,128,128,0,0)
|
||||
|
||||
local mx, my = mouse.pos()
|
||||
@@ -289,32 +320,57 @@ editor = {
|
||||
editor.brush.tiles={}
|
||||
editor.brush.tiles[1]=ty*16+tx
|
||||
end
|
||||
app.pop()
|
||||
editor.tilepicker.close()
|
||||
end
|
||||
|
||||
if key.press(key.TAB) or key.press(key.ESCAPE) then
|
||||
app.pop()
|
||||
editor.tilepicker.close()
|
||||
end
|
||||
|
||||
end
|
||||
},
|
||||
|
||||
itempicker = {
|
||||
surf_back = nil,
|
||||
pos_y = 24,
|
||||
scroll = 0,
|
||||
|
||||
show = function()
|
||||
if editor.itempicker.surf_back == nil then editor.itempicker.surf_back = surf.new(160,104) end
|
||||
surf.source(0)
|
||||
surf.target(editor.itempicker.surf_back)
|
||||
view.origin(0,0)
|
||||
view.clip()
|
||||
draw.surf(0,0,160,104,0,0)
|
||||
app.push(editor.itempicker.update_items)
|
||||
tweening.add(104,24,0.25,easing.easeOutCubic,function(value,n,finished)editor.itempicker.pos_y=value end)
|
||||
end,
|
||||
|
||||
close = function()
|
||||
tweening.add(24,104,0.25,easing.easeInCubic,function(value,n,finished)editor.itempicker.pos_y=value if finished then app.pop() end end)
|
||||
end,
|
||||
|
||||
update_items = function()
|
||||
surf.source(editor.itempicker.surf_back)
|
||||
surf.target(0)
|
||||
view.origin(0,0)
|
||||
view.clip()
|
||||
draw.surf(0,0,160,104,0,0)
|
||||
|
||||
view.origin(8,editor.itempicker.pos_y)
|
||||
draw.rrect(0,-1,144,84,3,17)
|
||||
draw.rrectf(0,0,144,84,3,20)
|
||||
draw.text("CHOOSE ITEM:",8,2,17)
|
||||
|
||||
view.origin(16,editor.itempicker.pos_y+8-editor.itempicker.scroll)
|
||||
view.clip(16,editor.itempicker.pos_y+8,128,64)
|
||||
|
||||
surf.source(surf_sprites)
|
||||
surf.cls(1)
|
||||
local mx, my = mouse.pos()
|
||||
local x,y = 0,0
|
||||
for i,k in pairs(items) do
|
||||
local w = math.max(k.visual.w, #k.label*4)
|
||||
if x+w > 160 then
|
||||
if x+w > 128 then
|
||||
y=y+32
|
||||
x=0
|
||||
end
|
||||
@@ -325,15 +381,36 @@ editor = {
|
||||
draw.rect(x+ox, y+7, k.visual.w, k.visual.h, 28)
|
||||
if mouse.press(mouse.LEFT) then
|
||||
editor.item_selected = i
|
||||
app.pop()
|
||||
editor.itempicker.close()
|
||||
end
|
||||
end
|
||||
x=x+w+4
|
||||
end
|
||||
y=y+32
|
||||
local lift_h = math.floor(4096/y)
|
||||
local lift_y = math.floor(((64-lift_h)*editor.itempicker.scroll)/(y-64))
|
||||
|
||||
view.origin(16,editor.itempicker.pos_y+8)
|
||||
view.clip()
|
||||
|
||||
draw.rrectf(124,0,5,64,1,17)
|
||||
draw.rrectf(124,lift_y,5,lift_h,1,2)
|
||||
|
||||
local mw = mouse.wheel()
|
||||
editor.itempicker.scroll = editor.itempicker.scroll - mw*8
|
||||
|
||||
if key.press(key.TAB) or key.press(key.ESCAPE) then
|
||||
app.pop()
|
||||
editor.itempicker.close()
|
||||
elseif key.press(key.UP) then
|
||||
editor.itempicker.scroll = editor.itempicker.scroll - 16
|
||||
elseif key.press(key.DOWN) then
|
||||
editor.itempicker.scroll = editor.itempicker.scroll + 16
|
||||
end
|
||||
|
||||
if editor.itempicker.scroll < 0 then editor.itempicker.scroll = 0 end
|
||||
if editor.itempicker.scroll > y-64 then editor.itempicker.scroll = y-64 end
|
||||
|
||||
draw.text(tostring(editor.itempicker.scroll),20,20,1)
|
||||
end
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ game = {
|
||||
end,
|
||||
|
||||
update = function()
|
||||
tweening.update(sys.delta())
|
||||
game.water_counter = game.water_counter + 0.05
|
||||
|
||||
if game.fade>0 then
|
||||
|
||||
@@ -30,6 +30,7 @@ function mini.init()
|
||||
end
|
||||
|
||||
function mini.update()
|
||||
tweening.update(sys.delta())
|
||||
app.update()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user