- [NEW] (EDITOR) selector de items

- [WIP] borrat i creació de items segons s'eix o entra de les habitacions
- [FIX] Items indexats per número, per a poder-se guardar en un mapa
- [NEW] room.current()
- [NEW] resaltat del item seleccionat
This commit is contained in:
2025-11-13 12:08:43 +01:00
parent eefab3f9b0
commit cf103dd02c
6 changed files with 145 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
require "menu"
require "msgbox"
require "items"
editor = {
@@ -8,6 +9,7 @@ editor = {
selection=nil,
ants=0xc936,
modified = false,
item_selected=nil,
enable = function()
app.update = editor.update
@@ -32,40 +34,58 @@ editor = {
mx, my = tx<<3, ty<<3
if my>=0 then
if editor.selection then
local rx1,ry1,rx2,ry2=editor.selection.x1<<3,editor.selection.y1<<3,editor.selection.x2<<3,editor.selection.y2<<3
if rx1>rx2 then rx1,rx2=rx2,rx1 end
if ry1>ry2 then ry1,ry2=ry2,ry1 end
draw.pattern(editor.ants)
draw.rect(rx1-1, ry1-1, rx2-rx1+10, ry2-ry1+10, 28)
draw.pattern(0xffff)
if sys.beat() then
editor.ants = (editor.ants<<12) | (editor.ants>>4)
end
else
draw.rect(mx-1, my-1, editor.brush.w*8+2, editor.brush.h*8+2, 28)
draw.rect(mx, my, editor.brush.w*8, editor.brush.h*8, 1)
end
if mouse.down(mouse.LEFT) then
editor.stamp(tx,ty)
editor.modified = true
--map.tile(tx,ty,editor.brush.tiles[1])
end
if mouse.down(mouse.RIGHT) then
if editor.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then
if editor.selection then
editor.selection.x2=tx
editor.selection.y2=ty
local rx1,ry1,rx2,ry2=editor.selection.x1<<3,editor.selection.y1<<3,editor.selection.x2<<3,editor.selection.y2<<3
if rx1>rx2 then rx1,rx2=rx2,rx1 end
if ry1>ry2 then ry1,ry2=ry2,ry1 end
draw.pattern(editor.ants)
draw.rect(rx1-1, ry1-1, rx2-rx1+10, ry2-ry1+10, 28)
draw.pattern(0xffff)
if sys.beat() then
editor.ants = (editor.ants<<12) | (editor.ants>>4)
end
else
editor.selection={}
editor.selection.x1=tx
editor.selection.y1=ty
editor.selection.x2=tx
editor.selection.y2=ty
draw.rect(mx-1, my-1, editor.brush.w*8+2, editor.brush.h*8+2, 28)
draw.rect(mx, my, editor.brush.w*8, editor.brush.h*8, 1)
end
if mouse.down(mouse.LEFT) then
editor.stamp(tx,ty)
editor.modified = true
--map.tile(tx,ty,editor.brush.tiles[1])
end
if mouse.down(mouse.RIGHT) then
if editor.selection then
editor.selection.x2=tx
editor.selection.y2=ty
else
editor.selection={}
editor.selection.x1=tx
editor.selection.y1=ty
editor.selection.x2=tx
editor.selection.y2=ty
end
else
if editor.selection then
editor.create_stamp()
editor.selection=nil
end
end
else
if editor.selection then
editor.create_stamp()
editor.selection=nil
if mouse.press(mouse.LEFT) then
if editor.item_selected then
surf.target(rooms.surf_items)
surf.pixel(tx,ty,editor.item_selected)
editor.modified = true
surf.target(0)
end
end
if mouse.press(mouse.RIGHT) then
editor.item_selected = nil
end
if editor.item_selected then
local k = items[editor.item_selected]
draw.surf(k.visual.x, k.visual.y, k.visual.w, k.visual.h, mx, my)
end
end
end
@@ -85,7 +105,11 @@ editor = {
elseif key.press(key.UP) and rooms.pos.y > 0 then
rooms.pos.y = rooms.pos.y - 12
elseif key.press(key.TAB) or key.press(key.ESCAPE) then
editor.picker.show()
if editor.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then
editor.tilepicker.show()
else
editor.itempicker.show()
end
elseif key.press(key.P) then
sprites.hero.pos.x = tx*8-4
sprites.hero.pos.y = ty*8-9
@@ -166,10 +190,10 @@ editor = {
end
end,
picker = {
tilepicker = {
show = function()
app.push(editor.picker.update_tiles)
app.push(editor.tilepicker.update_tiles)
end,
update_tiles = function()
@@ -201,5 +225,39 @@ editor = {
end
end
},
itempicker = {
show = function()
app.push(editor.itempicker.update_items)
end,
update_items = function()
view.origin(0,0)
view.clip()
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.name*4)
local ox = (w-k.visual.w)/2
draw.text(k.name, x, y, 15)
draw.surf(k.visual.x, k.visual.y, k.visual.w, k.visual.h, x+ox, y+7)
if mx>x and mx<x+w and my>y and my<y+7+k.visual.h then
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()
end
end
x=x+w+4
end
if key.press(key.TAB) or key.press(key.ESCAPE) then
app.pop()
end
end
}
}