Rebuild level editor sidebar with a fixed virtual-space layout
Replace the fraction-of-window positioning (which overlapped and didn't scale) with a small layout system: the sidebar is authored in one fixed virtual coordinate space and rendered at native panel resolution, so element sizes stay constant relative to the panel at any window size and fonts scale with it. - level_editor/layout.lua: sections, scrolling list (with clip + hit-test by point), scrollbar. Clip rects are scaled to real canvas pixels. - Room view split into non-overlapping divs: search/back header, a scrollable asset list (replaces the old row-paging + forward buttons), a status strip, and a compact bottom control cluster. - Mouse wheel scrolls the list; clicks map from window coords into the virtual space via the same transform used to render. - Sidebar canvas is panel-sized and blitted 1:1 (nearest filter, never averaged) to stay crisp; editorDraw runs under a scale transform. - Center text-only fields (level name) in their rect. Also carried in main.lua (share the file, can't split cleanly here): narrator require path fixed via love.filesystem.setRequirePath; sfxr static uses waveform=NOISE again after the field rename; low-pass + lower volume on the static loop. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
03532d29e4
commit
5b7ea9ec20
4 changed files with 336 additions and 144 deletions
40
main.lua
40
main.lua
|
|
@ -17,7 +17,10 @@ require "level_editor/editor"
|
|||
|
||||
-- Ink dialogue: ship the pre-parsed book (LÖVE has no lpeg to parse .ink at
|
||||
-- runtime; the narrator parser degrades to false without it, runtime is fine).
|
||||
package.path = package.path .. ";libs/narrator/?.lua"
|
||||
-- Use LOVE's require path (rooted at the game dir) so this resolves no matter
|
||||
-- what the shell's CWD is; plain package.path is CWD-relative and breaks when
|
||||
-- launched as `love /path/to/game` from elsewhere.
|
||||
love.filesystem.setRequirePath(love.filesystem.getRequirePath() .. ";libs/narrator/?.lua")
|
||||
narrator = require "narrator.narrator"
|
||||
startSignBook = require "stories.start_sign"
|
||||
|
||||
|
|
@ -101,9 +104,16 @@ function love.draw()
|
|||
love.graphics.draw(gameCanvas, 0, 0)
|
||||
love.graphics.setCanvas()
|
||||
|
||||
-- Render the sidebar at native panel resolution: the canvas is panel-sized,
|
||||
-- and editorDraw works in the fixed virtual space, scaled up by a transform.
|
||||
-- Blitting the canvas 1:1 afterwards means no rescaling of the final image
|
||||
-- (crisp, nearest-neighbor throughout — nothing is averaged).
|
||||
love.graphics.setCanvas(sideBarCanvas)
|
||||
love.graphics.clear()
|
||||
love.graphics.push()
|
||||
love.graphics.scale(editorRenderScale, editorRenderScale)
|
||||
editorDraw()
|
||||
love.graphics.pop()
|
||||
love.graphics.setCanvas()
|
||||
|
||||
love.graphics.setBlendMode("alpha")
|
||||
|
|
@ -164,6 +174,13 @@ function love.textinput(t)
|
|||
editorTextHandler(response)
|
||||
end
|
||||
|
||||
function love.wheelmoved(dx, dy)
|
||||
-- Scroll the editor's asset/folder list when the cursor is over the sidebar.
|
||||
if editorView == "room" and love.mouse.getX() > width then
|
||||
editorScrollRoomList(dy)
|
||||
end
|
||||
end
|
||||
|
||||
function love.resize(w, h)
|
||||
_computeDimensions()
|
||||
drawScale = width / gridWidth / 16
|
||||
|
|
@ -199,6 +216,21 @@ function _computeDimensions()
|
|||
end
|
||||
|
||||
sideBarBox = {x = width, y = 0, w = love.graphics.getWidth() - width, h = height}
|
||||
|
||||
-- The editor sidebar is authored in a fixed virtual space and scaled up to
|
||||
-- fill the real panel, so every element keeps the same size relative to the
|
||||
-- panel at any window size (and fonts scale with it). Width is constant;
|
||||
-- height follows the real panel's aspect ratio so the upscale is uniform
|
||||
-- (no stretching). `editorScale` is the constant sprite scale in that space.
|
||||
editorScale = 3
|
||||
local virtualW = 600
|
||||
local aspect = sideBarBox.w > 0 and (sideBarBox.h / sideBarBox.w) or 2
|
||||
sb = {w = virtualW, h = virtualW * aspect}
|
||||
|
||||
-- Factor that maps the virtual layout space onto real panel pixels. The
|
||||
-- sidebar is rasterized at this density (native res), so it stays crisp at
|
||||
-- any window size instead of scaling a fixed low-res canvas.
|
||||
editorRenderScale = sideBarBox.w > 0 and (sideBarBox.w / sb.w) or 1
|
||||
end
|
||||
|
||||
-- (Re)create the render targets at the current window size.
|
||||
|
|
@ -206,6 +238,7 @@ function _initCanvases()
|
|||
gameCanvas = love.graphics.newCanvas()
|
||||
finalCanvas = love.graphics.newCanvas()
|
||||
sideBarCanvas = love.graphics.newCanvas(math.max(1, sideBarBox.w), math.max(1, sideBarBox.h))
|
||||
sideBarCanvas:setFilter("nearest", "nearest") -- never average when sampled
|
||||
end
|
||||
|
||||
function _initGridVars()
|
||||
|
|
@ -222,13 +255,14 @@ end
|
|||
|
||||
function _initSounds()
|
||||
staticWave = sfxr.newSound()
|
||||
staticWave.wavetype = 3
|
||||
staticWave.waveform = sfxr.WAVEFORM.NOISE -- was `wavetype = 3`; field renamed in this sfxr
|
||||
staticWave.frequency.start = .1
|
||||
staticWave.envelope.release = 0
|
||||
staticWave.envelope.sustain = 1
|
||||
staticWave.envelope.decay = 0
|
||||
static = love.audio.newSource((staticWave:generateSoundData()))
|
||||
static:setLooping(true)
|
||||
static:setVolume(.15)
|
||||
static:setVolume(.04)
|
||||
static:setFilter({type = "lowpass", highgain = .25}) -- roll off highs + upper-mids
|
||||
static:play()
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue