Mothback/code/ui/dialog.lua

96 lines
2.7 KiB
Lua
Raw Permalink Normal View History

2022-02-01 14:05:36 +00:00
interfaceDialog = {type = "Dialog"}
-- dialog boxes
2022-02-01 14:05:36 +00:00
function interfaceDialog:New(style)
2022-02-27 02:40:41 +00:00
local o = {}
2022-02-27 03:29:13 +00:00
2022-02-26 02:56:53 +00:00
o.pos = {
x = 0,
y = game.height*80/100
}
o.size = {
w = game.width,
h = game.height*20/100
}
2022-02-01 14:05:36 +00:00
2022-02-26 02:56:53 +00:00
o.value = 0
o.target_value = 0
2022-02-01 14:05:36 +00:00
2022-02-26 02:56:53 +00:00
local style = {}
2022-02-01 14:05:36 +00:00
2022-02-26 02:56:53 +00:00
o.style = {
content = style.content or nil,
color = style.color or {1,1,1},
color2 = style.color2 or {0,0,0},
--color3 = style.color3 or style.color2 or {0,0,0},
alpha = style.alpha or 1,
scale = style.scale or 1,
scale_x = style.scale_x or 1,
scale_y = style.scale_y or 1,
scale_proportion = 1
}
2022-02-01 14:05:36 +00:00
2022-02-26 02:56:53 +00:00
AddElement(o)
2022-02-01 14:05:36 +00:00
2022-02-26 02:56:53 +00:00
setmetatable(o, self)
self.__index = self
return o
2022-02-01 14:05:36 +00:00
end
function interfaceDialog:updateContents()
2022-02-26 02:56:53 +00:00
if self.value < self.target_value then
self.contents = self.sequence[self.value]
if self.contents[1] == nil then self.contents[1] = "" end
if self.contents[2] == nil then self.contents[2] = "" end
if self.contents[3] == nil then self.contents[3] = "" end
end
2022-02-01 14:05:36 +00:00
end
function interfaceDialog:loadSequence(sequence)
2022-02-26 02:56:53 +00:00
self.sequence = sequence
self.value = 1
self.target_value = 1+#sequence
self:updateContents()
2022-02-01 14:05:36 +00:00
end
function interfaceDialog:checkConfirm()
2022-02-26 02:56:53 +00:00
if not self.clicked then
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
logPrint("Dialog: "..self.value.." of "..self.target_value)
self:updateContents()
end
elseif not love.mouse.isDown(1) then
self.clicked = false
end
2022-02-01 14:05:36 +00:00
end
function interfaceDialog:Draw()
2022-02-26 02:56:53 +00:00
local c1, c2, c3, a = love.graphics.getColor()
2022-02-01 14:05:36 +00:00
2022-02-26 02:56:53 +00:00
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
love.graphics.rectangle(
"fill",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
love.graphics.rectangle(
"line",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
2022-02-01 14:05:36 +00:00
2022-02-26 02:56:53 +00:00
if self.contents ~= nil then
love.graphics.printf(self.contents[2],self.pos.x+10,self.pos.y+(self.size.h/2),100,"left")
love.graphics.printf(self.contents[1],self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
love.graphics.printf(self.contents[3],self.pos.x+(self.size.w)-10,self.pos.y+(self.size.h/2),100,"right")
else
love.graphics.printf("ERROR",self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
end
2022-02-26 02:56:53 +00:00
love.graphics.setColor(c1,c2,c3,a)
2022-02-01 14:05:36 +00:00
end