From 96b1e750e4ae26faf2b4d83f38fb44461ac243fa Mon Sep 17 00:00:00 2001 From: lustlion Date: Fri, 11 Mar 2022 13:04:36 +0100 Subject: [PATCH] prompt box style, entity prompts improvement, killing entities and particles improvement --- code/editor.lua | 12 ++++++------ code/entity.lua | 2 +- code/keybind.lua | 7 ++++++- code/lights.lua | 2 +- code/spawn.lua | 39 ++++++++++++++++++++++++++++----------- code/ui/prompt.lua | 26 ++++++++++++++++++++++++-- 6 files changed, 66 insertions(+), 22 deletions(-) diff --git a/code/editor.lua b/code/editor.lua index 40ee603..48f4ddc 100644 --- a/code/editor.lua +++ b/code/editor.lua @@ -210,24 +210,24 @@ function doEditorEdit() and love.keyboard.isDown("lctrl") ~= true then if selecting_tile ~= nil then - if Keybind:checkDown(Keybind.generic.lclick) then + if Keybind:checkDown(Keybind.editor.tile_set) then setTile(vertical,horizontal,selecting_tile) - elseif Keybind:checkDown(Keybind.generic.rclick) then + elseif Keybind:checkDown(Keybind.editor.tile_remove) then setTile(vertical,horizontal,0) end reloadLevelTiles() else - if Keybind:checkDown(Keybind.generic.lclick) then + if Keybind:checkDown(Keybind.editor.entity_select) then deselectSpawns() selectSpawns(mouse_x,mouse_y) end - if Keybind:checkDown(Keybind.generic.rclick) then + if Keybind:checkDown(Keybind.editor.entity_move) then moveSpawns(mouse_x,mouse_y) end if Prompt.active_prompt == nil then - if Keybind:checkDown({keys={"t"}}) then + if Keybind:checkDown(Keybind.editor.entity_modify_archetype) then promptSpawnArchetype() - elseif Keybind:checkDown({keys={"d"}}) then + elseif Keybind:checkDown(Keybind.editor.entity_modify_data) then promptSpawnArgs() end end diff --git a/code/entity.lua b/code/entity.lua index 56f6852..b4f36b6 100644 --- a/code/entity.lua +++ b/code/entity.lua @@ -104,12 +104,12 @@ function Entity:kill() self.light:kill() end if self.id ~= nil then + table.remove(LoadedObjects.Entities,self.id) for _, e in pairs(LoadedObjects.Entities) do if e.id > self.id then e.id = e.id - 1 end end - table.remove(LoadedObjects.Entities,self.id) end self = nil end diff --git a/code/keybind.lua b/code/keybind.lua index 21bf7fb..2e14cf9 100644 --- a/code/keybind.lua +++ b/code/keybind.lua @@ -123,7 +123,12 @@ function Keybind:default() Keybind.editor.down = { keys = {"down", "s"}} Keybind.editor.palette_change = { keys = {"f1"}} Keybind.editor.save = { keys = {"f3"}} - + Keybind.editor.tile_set = { keys = {1}} + Keybind.editor.tile_remove = { keys = {2}} + Keybind.editor.entity_select = { keys = {1}} + Keybind.editor.entity_move = { keys = {2}} + Keybind.editor.entity_modify_archetype = { keys = {"t"}} + Keybind.editor.entity_modify_data = { keys = {"d"}} -- Generic Keybind.generic.lclick = { keys = {1}} Keybind.generic.rclick = { keys = {2}} diff --git a/code/lights.lua b/code/lights.lua index 9e717ec..f689735 100644 --- a/code/lights.lua +++ b/code/lights.lua @@ -26,12 +26,12 @@ end function Light:kill() if self.id ~= nil then + table.remove(LoadedObjects.Lights,self.id) for _, e in pairs(LoadedObjects.Lights) do if e.id > self.id then e.id = e.id - 1 end end - table.remove(LoadedObjects.Lights,self.id) end self = nil end diff --git a/code/spawn.lua b/code/spawn.lua index f6d09b8..da1989f 100644 --- a/code/spawn.lua +++ b/code/spawn.lua @@ -76,25 +76,35 @@ function promptSpawnArchetype() local f = loadstring("return "..prompt.input) if f ~= nil then local succ, arch = pcall(f) - print(succ, arch) + print("archetype changed --",succ) + print("from: ", spawn.archetype.type) if not succ or type(arch) ~= "table" or type(arch.type) ~= "string" then arch = spawn.archetype end - print(succ, arch) + print("to: ", arch.type) spawn.archetype = arch + else + print("invalid input for prompt "..prompt.name) end end, }) - prompt.pos.x = spawn.args[1] - Camera.pos.x - offset_x - prompt.pos.y = spawn.args[2] - Camera.pos.y - offset_y + prompt.pos.x = (spawn.args[1]-4)*game.scale - Camera.pos.x - offset_x + prompt.pos.y = (spawn.args[2]-20)*game.scale - Camera.pos.y - offset_y + prompt:activate() end end end +function checkArgsAreInvalid(args) + for _, arg in pairs(args) do + if arg == nil then return true end + end +end + function promptSpawnArgs() if Prompt.active_prompt then Prompt.active_prompt.canceled = true @@ -111,18 +121,25 @@ function promptSpawnArgs() name = "args", input = text, func = function(prompt) - local f = loadstring("return {"..prompt.input.."}") - - if f == nil then - spawn.args = arch + if f ~= nil then + local succ, args = pcall(f) + print("args changed --",succ) + print("from: ", unpack(args)) + if not succ + or checkArgsAreInvalid(args) + then + args = spawn.args + end + print("to: ", unpack(args)) + spawn.args = args else - spawn.args = f() + print("invalid input for prompt "..prompt.name) end end, }) - prompt.pos.x = spawn.args[1] - Camera.pos.x - offset_x - prompt.pos.y = spawn.args[2] - Camera.pos.y - offset_y + prompt.pos.x = (spawn.args[1]-4)*game.scale - Camera.pos.x - offset_x + prompt.pos.y = (spawn.args[2]-4)*game.scale - Camera.pos.y - offset_y prompt:activate() end end diff --git a/code/ui/prompt.lua b/code/ui/prompt.lua index 6b0b2a9..5937524 100644 --- a/code/ui/prompt.lua +++ b/code/ui/prompt.lua @@ -20,7 +20,8 @@ Prompt = { name = "input", canceled = false, closing = false, - + color = {1,1,1,1}, + background_color = {0,0,0,1}, active_prompt = nil, } @@ -52,7 +53,28 @@ function Prompt:textinput(text) end function Prompt:draw() - love.graphics.print(self.name .. ": " .. self.input, self.pos.x, self.pos.y) + local c1, c2, c3, a = love.graphics.getColor() + local text = self.name .. ": " .. self.input + local width = locale_font:getWidth(text) + local height = locale_font:getHeight(text) + local margin = 10 + love.graphics.setColor(unpack(self.color)) + love.graphics.rectangle("fill", + self.pos.x-margin-1, + self.pos.y-1, + width+margin*2+2, + height+margin+2 + ) + love.graphics.setColor(unpack(self.background_color)) + love.graphics.rectangle("fill", + self.pos.x-margin, + self.pos.y, + width+margin*2, + height+margin + ) + love.graphics.setColor(unpack(self.color)) + love.graphics.print(text, self.pos.x, self.pos.y) + love.graphics.setColor(c1,c2,c3,a) end function Prompt:activate()