Mothback/data/scripts/ui/dialog.lua

98 lines
2.8 KiB
Lua

interfaceDialog = {type = "Dialog"}
-- dialog boxes
function interfaceDialog:New(style)
o = {}
o.pos = {
x = 0,
y = game.height*80/100
}
o.size = {
w = game.width,
h = game.height*20/100
}
o.value = 0
o.target_value = 0
local style = {}
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
}
AddElement(o)
setmetatable(o, self)
self.__index = self
return o
end
function interfaceDialog:updateContents()
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
end
function interfaceDialog:loadSequence(sequence)
self.sequence = sequence
self.value = 1
self.target_value = 1+#sequence
self:updateContents()
end
function interfaceDialog:checkConfirm()
if not self.clicked then
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
print(self.value.." of "..self.target_value)
self:updateContents()
end
elseif not love.mouse.isDown(1) then
self.clicked = false
end
end
function interfaceDialog:Draw()
local c1, c2, c3, a = love.graphics.getColor()
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)
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
love.graphics.setColor(c1,c2,c3,a)
end