summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-20 15:51:29 +0000
committerubq323 <ubq323@ubq323.website>2023-02-20 15:51:29 +0000
commit447f46c1710f507622306a338cc8c82b1ce3aa5c (patch)
treec1230c42efa80ef8e0fd80c52a8ca4afef11a4d6
parent415ec81e72bbf85cc81a6d2ce0f8c19335c844ec (diff)
center some ui elements better
-rw-r--r--client/main.lua6
-rw-r--r--client/util.lua23
2 files changed, 15 insertions, 14 deletions
diff --git a/client/main.lua b/client/main.lua
index a6cc4b6..f74cfa9 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -261,7 +261,7 @@ function love.draw()
local hm = wm:to_hex()
love.graphics.origin()
- util.print_good(tostring(selected_tile), 400,10)
+ util.print_good(tostring(selected_tile), "center",10)
if _G.debugmode and local_player then
util.print_good(table.concat({
"ms "..tostring(sm),
@@ -279,13 +279,13 @@ function love.draw()
},"\n"),10,10)
end
if show_controls then
- util.print_good(help_text,300,200)
+ util.print_good(help_text,"center","center")
end
msgbox.draw()
if ui_mode ~= "normal" then
- util.print_good(ui_mode, 700,10)
+ util.print_good(ui_mode, -20,10)
end
if ui_mode == "chat" then
diff --git a/client/util.lua b/client/util.lua
index 8a18b96..efeac31 100644
--- a/client/util.lua
+++ b/client/util.lua
@@ -1,17 +1,18 @@
local font = love.graphics.getFont()
local text = love.graphics.newText(font)
-local function print_good(lines,x,y)
- if type(lines) ~= "table" then lines = {lines} end
- for _,line in ipairs(lines) do
- text:set(line)
- local w,h = text:getDimensions()
- love.graphics.setColor(0,0,0,0.8)
- love.graphics.rectangle("fill",x,y,w,h)
- love.graphics.setColor(1,1,1)
- love.graphics.draw(text,x,y)
- y = y + h
- end
+local function print_good(str,x,y)
+ text:set(str)
+ local w,h = text:getDimensions()
+ local W,H = love.graphics.getDimensions()
+ if x == "center" then x = (W/2)-(w/2) end
+ if y == "center" then y = (H/2)-(h/2) end
+ if x < 0 then x = W-w-(-x)+1 end
+ if y < 0 then y = H-h-(-y)+1 end
+ love.graphics.setColor(0,0,0,0.8)
+ love.graphics.rectangle("fill",x,y,w,h)
+ love.graphics.setColor(1,1,1)
+ love.graphics.draw(text,x,y)
end
return {