94 lines
2.6 KiB
Lua
94 lines
2.6 KiB
Lua
interfaceDialog = {type = "Dialog"}
|
|
|
|
-- centered buttons
|
|
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.values = {false,true}
|
|
o.value = 1
|
|
o.target_variable = o.values[o.value]
|
|
|
|
o.clicked = false
|
|
|
|
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:getVariable()
|
|
return self.target_variable
|
|
end
|
|
|
|
function AddElement(self)
|
|
table.insert(UIElement,self)
|
|
self.id = #UIElement
|
|
end
|
|
|
|
function interfaceDialog:checkConfirm()
|
|
if not self.clicked then
|
|
if Keybind:HasPressed(Keybind.menu.confirm) then
|
|
self.clicked = true
|
|
self.value = self.value + 1
|
|
if self.value > #self.values then
|
|
self.value = 1
|
|
end
|
|
self.target_variable = self.values[self.value]
|
|
end
|
|
else
|
|
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.style.content ~= nil then
|
|
love.graphics.printf(self.style.content[1],self.pos.x+10,self.pos.y+(self.size.h/2),100,"left")
|
|
love.graphics.printf(self.style.content[2],self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
|
|
love.graphics.printf(self.style.content[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
|