diff --git a/code/editor.lua b/code/editor.lua index 48f4ddc..27e8cb8 100644 --- a/code/editor.lua +++ b/code/editor.lua @@ -262,9 +262,14 @@ function drawSelectingPaletteTile() end function doEditorPalette() - local width = LevelData.tileset:getPixelWidth()/tile_properties.width local height = LevelData.tileset:getPixelHeight()/tile_properties.height + local mouse_x = love.mouse.getX() + local mouse_y = love.mouse.getY() + local hovering = nil + local hov_x = nil + local hov_y = nil + local output = "" love.graphics.setColor(0,0,0,1) love.graphics.rectangle( @@ -274,9 +279,8 @@ function doEditorPalette() 1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width), 1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height) ) - - love.graphics.setColor(1,1,1,1) + local position_x = 1 local position_y = 1 for i = 1, #TileIndex-width-1 do @@ -293,18 +297,17 @@ function doEditorPalette() 1, 1 ) - if Keybind:checkDown(Keybind.generic.lclick) then - local mouse_x = love.mouse.getX() - local mouse_y = love.mouse.getY() - if mouse_x > (tile_x) * game.scale - and mouse_x < (tile_x + tile_properties.width) * game.scale - and mouse_y > (tile_y) * game.scale - and mouse_y < (tile_y + tile_properties.height) * game.scale - then - selecting_tile = position_x + ((position_y-1) * width) - - love.graphics.print(selecting_tile .. " | " .. tile_x .. ", " .. tile_y, 0, 20) + if mouse_x > (tile_x) * game.scale + and mouse_x < (tile_x + tile_properties.width) * game.scale + and mouse_y > (tile_y) * game.scale + and mouse_y < (tile_y + tile_properties.height) * game.scale + then + hovering = position_x + ((position_y-1) * width) + hov_x = tile_x + hov_y = tile_y + if Keybind:checkDown(Keybind.generic.lclick) then + selecting_tile = hovering end end @@ -340,6 +343,22 @@ function doEditorPalette() 1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width), 1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height) ) + + local tile = "none" + if selecting_tile ~= nil then + tile = "#"..selecting_tile + end + output = output .. "Selected: " .. tile + + if hovering ~= nil then + output = output .. " \nHovering: #".. hovering .. "\nImage coords: " .. hov_x .. ", " .. hov_y + end + + drawTextBox( + output, + (palette_scroll_x + 1+width) * (tile_properties.width+1), + (palette_scroll_y + 1) * (tile_properties.height+1) + ) end diff --git a/code/ui.lua b/code/ui.lua index 94b4056..739c7f9 100644 --- a/code/ui.lua +++ b/code/ui.lua @@ -6,23 +6,30 @@ function addElement(self) end function drawTextBox(text,x,y,color,background_color) + local color = color or {1,1,1,1} + local background_color = background_color or {0,0,0,1} local c1, c2, c3, a = love.graphics.getColor() local width = locale_font:getWidth(text) local height = locale_font:getHeight(text) local margin = 5 + local lines = 1 + for i in text:gmatch("\n") do + lines = lines + 1 + end + love.graphics.setColor(unpack(color)) love.graphics.rectangle("fill", x-1, y-1, width+margin*2+2, - height+margin*2+2 + height*lines+margin*2+2 ) love.graphics.setColor(unpack(background_color)) love.graphics.rectangle("fill", x, y, width+margin*2, - height+margin*2 + height*lines+margin*2 ) love.graphics.setColor(unpack(color)) love.graphics.print(text, x+margin, y+margin)