diff --git a/.gitmodules b/.gitmodules index fa922da5..e2471780 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = src/selene url = https://github.com/Vexatos/Selene.git branch = lua5.1 +[submodule "src/ui"] + path = src/ui + url = https://github.com/EverestAPI/OlympUI.git diff --git a/src/conf.lua b/src/conf.lua index dec52ba7..dc4c6a49 100644 --- a/src/conf.lua +++ b/src/conf.lua @@ -7,5 +7,5 @@ function love.conf(t) t.window.icon = "assets/logo-256.png" - t.window.vsync = true + t.window.vsync = false end \ No newline at end of file diff --git a/src/scenes/editor.lua b/src/scenes/editor.lua index efdc985f..c64acbf6 100644 --- a/src/scenes/editor.lua +++ b/src/scenes/editor.lua @@ -12,6 +12,202 @@ function editorScene:firstEnter() local inputDevice = require("input_device") local standardHotkeys = require("standard_hotkeys") + local filesystem = require("filesystem") + local loadedState = require("loaded_state") + local fileLocations = require("file_locations") + + local ui = require("ui") + local uie = require("ui.elements") + local uiu = require("ui.utils") + + --[[ + uiu.hook(uie.__label.__default, { + calcWidth = (orig, ... -> orig(...) * 3), + calcHeight = (orig, ... -> orig(...) * 3), + + draw = function(orig, self, ...) + love.graphics.setColor(self.style.color) + love.graphics.draw(self._text, self.screenX, self.screenY, 0, 3, 3) + end, + }) + --]] + uie.__label.__default.style.font = love.graphics.newFont(16) + + local root = uie.column({ + uie.topbar({ + { "File", { + { "New" }, + { }, + { "Open", (-> filesystem.openDialog(fileLocations.getCelesteDir(), nil, loadedState.loadFile)) }, + { "Recent", { + { "Totally" }, + { "Not A Dummy" }, + { "Nested Submenu" } + } }, + { }, + { "Save", (-> loadedState.filename and loadedState.saveFile(loadedState.filename)) }, + { "Save As...", (-> loadedState.side and filesystem.saveDialog(loadedState.filename, nil, loadedState.saveFile)) }, + { }, + { "Settings" }, + { }, + { "Quit", (-> love.event.quit()) } + }}, + + { "Edit", { + { "Undo" }, + { "Redo" } + }}, + + { "Map", { + { "Stylegrounds" }, + { "Metadata" }, + { "Save Map Image" } + }}, + + { "Room", { + { "Add" }, + { "Configure" } + }}, + + { "Help", { + { "Update" }, + { "About" } + }}, + + { "Debug", { + { "Uhh" } + }}, + }), + + uie.group({ + uie.scrollbox( + uie.list( + uiu.map(uiu.listRange(200, 1, -1), function(i) + return { text = string.format("%i%s", i, i % 7 == 0 and " (something)" or ""), data = i } + end) + ) + ):with({ + calcWidth = (el -> el.inner.width) + }):with(uiu.fillHeight), + + uie.column({ + uie.listH({ + { "A" }, + { "B" }, + { "C" }, + { "D" }, + { "E" } + }):with(uiu.hook{ + layoutLateLazy = function(orig, el) + local parentWidth = el.parent.innerWidth + if el.width < parentWidth then + el.width = parentWidth + el.innerWidth = parentWidth - el.style.padding * 2 + end + orig(el) + end + }), + + uie.field(""), + + uie.scrollbox( + uie.list( + uiu.map(uiu.listRange(200, 1, -1), function(i) + return { text = string.format("%i%s", i, i % 7 == 0 and " (something)" or ""), data = i } + end) + ):with(uiu.hook{ + layoutLateLazy = function(orig, el) + local parentWidth = el.parent.innerWidth + if el.width < parentWidth then + el.width = parentWidth + el.innerWidth = parentWidth - el.style.padding * 2 + end + orig(el) + end + }) + ):with(uiu.fillHeight(true)) + :with(uiu.hook{ + calcWidth = (orig, el -> el.inner.width), + layoutLateLazy = function(orig, el) + local parentWidth = el.parent.innerWidth + if el.width < parentWidth then + el.width = parentWidth + el.innerWidth = parentWidth - el.style.padding * 2 + end + orig(el) + end + }) + }):with(uiu.fillHeight):with(uiu.rightbound):with({ + style = { + padding = 0 + } + }), + + uie.window("Windowception", + uie.scrollbox( + uie.group({ + uie.window("Child 1", uie.column({ uie.label("Oh no") })):with({ x = 10, y = 10}), + uie.window("Child 2", uie.column({ uie.label("Oh no two") })):with({ x = 30, y = 30}) + }):with({ width = 200, height = 400 }) + ):with({ width = 200, height = 200 }) + ):with({ x = 50, y = 100 }), + + uie.window("Hello, World!", + uie.column({ + uie.label("This is a one-line label."), + + -- Labels use Löve2D Text objects under the hood. + uie.label({ { 1, 1, 1 }, "This is a ", { 1, 0, 0 }, "colored", { 0, 1, 1 }, " label."}), + + -- Multi-line labels aren't subjected to the parent element's spacing property. + uie.label("This is a two-line label.\nThe following label is updated dynamically."), + + -- Dynamically updated label. + uie.label():with({ + update = function(el) + el.text = "FPS: " .. love.timer.getFPS() + end + }), + + uie.button("This is a button.", function(btn) + if btn.counter == nil then + btn.counter = 0 + end + btn.counter = btn.counter + 1 + btn.text = "Pressed " .. tostring(btn.counter) .. " time" .. (btn.counter == 1 and "" or "s") + end), + + uie.button("Disabled"):with({ enabled = false }), + + uie.button("Useless"), + + uie.label("Select an item from the list below."):as("selected"), + uie.list(uiu.map(uiu.listRange(1, 3), function(i) + return { text = string.format("Item %i!", i), data = i } + end), function(list, item) + list.parent._selected.text = "Selected " .. tostring(item) + end) + + }) + ):with({ x = 200, y = 50 }):as("test"), + + }):with(uiu.fillWidth):with(uiu.fillHeight(true)), + }):with({ + style = { + bg = { bg = {} }, + padding = 0, + spacing = 0, + radius = 0 + }, + clip = false, + cacheable = false + }) + + ui.init(root, false) + inputDevice.newInputDevice(self.inputDevices, ui) + + self.ui = ui + local viewportHandler = require("viewport_handler") local hotkeyHandler = require("hotkey_handler") local mapLoaderDevice = require("input_devices.map_loader") diff --git a/src/selene b/src/selene index 7f5e3a18..893515d7 160000 --- a/src/selene +++ b/src/selene @@ -1 +1 @@ -Subproject commit 7f5e3a1868a4620336b34a23741990cab5a22d30 +Subproject commit 893515d728516985441232beb0c5015cd65887be diff --git a/src/structs/smart_drawing_batch.lua b/src/structs/smart_drawing_batch.lua index d544f79a..e64a29b1 100644 --- a/src/structs/smart_drawing_batch.lua +++ b/src/structs/smart_drawing_batch.lua @@ -259,8 +259,10 @@ end local function clearCanvasArea(batch, x, y) local sectionX, sectionY, cellWidth, cellHeight = getSectionStart(batch, x, y) + local previousScissorX, previousScissorY, previousScissorW, previousScissorH = love.graphics.getScissor() love.graphics.setScissor(sectionX, sectionY, cellWidth, cellHeight) love.graphics.clear(0.0, 0.0, 0.0, 0.0) + love.graphics.setScissor(previousScissorX, previousScissorY, previousScissorW, previousScissorH) end -- Assumes Canvas is set for performance reasons @@ -279,8 +281,10 @@ local function redrawCanvasArea(batch, x, y, meta, quad, drawX, drawX, drawY, ro local offsetX = ox or ((jx or 0.0) * meta.realWidth + meta.offsetX) local offsetY = oy or ((jy or 0.0) * meta.realHeight + meta.offsetY) + local previousScissorX, previousScissorY, previousScissorW, previousScissorH = love.graphics.getScissor() love.graphics.setScissor(sectionX, sectionY, cellWidth, cellHeight) love.graphics.clear(0.0, 0.0, 0.0, 0.0) + love.graphics.setScissor(previousScissorX, previousScissorY, previousScissorW, previousScissorH) love.graphics.draw(meta.image, quad, sectionX, sectionY, rot or 0, sx or 1, sy or 1, offsetX, offsetY) end diff --git a/src/tools/brush.lua b/src/tools/brush.lua index a74a1a9a..86b92b31 100644 --- a/src/tools/brush.lua +++ b/src/tools/brush.lua @@ -83,9 +83,11 @@ function tool.draw() local px, py = viewportHandler.getRoomCoordindates(room) local tx, ty = viewportHandler.pixelToTileCoordinates(px, py) + --[[ local hudText = string.format("Cursor: %s, %s (%s, %s)", tx + 1, ty + 1, px, py) love.graphics.printf(hudText, 20, 120, viewportHandler.viewport.width, "left", 0, fonts.fontScale, fonts.fontScale) + ]]-- viewportHandler.drawRelativeTo(room.x, room.y, function() drawing.callKeepOriginalColor(function() diff --git a/src/ui b/src/ui new file mode 160000 index 00000000..df0f4d39 --- /dev/null +++ b/src/ui @@ -0,0 +1 @@ +Subproject commit df0f4d393010aac8b57af766444a34b24590c1b3