2012-05-06 00:24:42 +00:00
|
|
|
--[[------------------------------------------------
|
2012-09-29 23:20:41 +00:00
|
|
|
-- Love Frames - A GUI library for LOVE --
|
|
|
|
-- Copyright (c) 2012 Kenny Shields --
|
2012-05-06 00:24:42 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2012-09-02 21:13:13 +00:00
|
|
|
-- progressbar class
|
2012-05-06 00:24:42 +00:00
|
|
|
progressbar = class("progressbar", base)
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:initialize()
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
self.type = "progressbar"
|
|
|
|
self.width = 100
|
|
|
|
self.height = 25
|
|
|
|
self.min = 0
|
|
|
|
self.max = 10
|
|
|
|
self.value = 0
|
|
|
|
self.barwidth = 0
|
|
|
|
self.lerprate = 1000
|
|
|
|
self.lerpvalue = 0
|
|
|
|
self.lerpto = 0
|
|
|
|
self.lerpfrom = 0
|
|
|
|
self.completed = false
|
|
|
|
self.lerp = false
|
|
|
|
self.internal = false
|
|
|
|
self.OnComplete = nil
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:update(dt)
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local visible = self.visible
|
2012-05-22 07:10:18 +00:00
|
|
|
local alwaysupdate = self.alwaysupdate
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local lerp = self.lerp
|
|
|
|
local lerprate = self.lerprate
|
|
|
|
local lerpvalue = self.lerpvalue
|
|
|
|
local lerpto = self.lerpto
|
|
|
|
local lerpfrom = self.lerpfrom
|
|
|
|
local value = self.value
|
|
|
|
local completed = self.completed
|
|
|
|
local parent = self.parent
|
|
|
|
local base = loveframes.base
|
|
|
|
local update = self.Update
|
|
|
|
local oncomplete = self.OnComplete
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self:CheckHover()
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
-- caclulate barwidth
|
|
|
|
if lerp then
|
2012-05-06 00:24:42 +00:00
|
|
|
if lerpfrom < lerpto then
|
|
|
|
if lerpvalue < lerpto then
|
|
|
|
self.lerpvalue = lerpvalue + lerprate*dt
|
|
|
|
elseif lerpvalue > lerpto then
|
|
|
|
self.lerpvalue = lerpto
|
|
|
|
end
|
|
|
|
elseif lerpfrom > lerpto then
|
|
|
|
if lerpvalue > lerpto then
|
|
|
|
self.lerpvalue = lerpvalue - lerprate*dt
|
|
|
|
elseif lerpvalue < lerpto then
|
|
|
|
self.lerpvalue = lerpto
|
|
|
|
end
|
|
|
|
elseif lerpfrom == lerpto then
|
|
|
|
self.lerpvalue = lerpto
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
self.barwidth = self.lerpvalue/self.max * self.width
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
-- min check
|
|
|
|
if self.lerpvalue < self.min then
|
|
|
|
self.lerpvalue = self.min
|
|
|
|
end
|
|
|
|
|
|
|
|
-- max check
|
|
|
|
if self.lerpvalue > self.max then
|
|
|
|
self.lerpvalue = self.max
|
|
|
|
end
|
|
|
|
else
|
2012-09-29 23:20:41 +00:00
|
|
|
self.barwidth = value/self.max * self.width
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
-- min max check
|
|
|
|
if value < self.min then
|
2012-05-06 00:24:42 +00:00
|
|
|
self.value = self.min
|
2012-09-29 23:20:41 +00:00
|
|
|
elseif value > self.max then
|
2012-05-06 00:24:42 +00:00
|
|
|
self.value = self.max
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- move to parent if there is a parent
|
2012-09-29 23:20:41 +00:00
|
|
|
if parent ~= base then
|
2012-05-06 00:24:42 +00:00
|
|
|
self.x = self.parent.x + self.staticx
|
|
|
|
self.y = self.parent.y + self.staticy
|
|
|
|
end
|
|
|
|
|
|
|
|
-- completion check
|
2012-09-29 23:20:41 +00:00
|
|
|
if not completed then
|
2012-05-06 00:24:42 +00:00
|
|
|
if self.value >= self.max then
|
|
|
|
self.completed = true
|
2012-09-29 23:20:41 +00:00
|
|
|
if oncomplete then
|
|
|
|
oncomplete(self)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if update then
|
|
|
|
update(self, dt)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:draw()
|
|
|
|
|
2012-05-22 07:10:18 +00:00
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local skins = loveframes.skins.available
|
|
|
|
local skinindex = loveframes.config["ACTIVESKIN"]
|
|
|
|
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
|
|
|
local selfskin = self.skin
|
|
|
|
local skin = skins[selfskin] or skins[skinindex]
|
|
|
|
local drawfunc = skin.DrawProgressBar or skins[defaultskin].DrawProgressBar
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-10-22 14:19:02 +00:00
|
|
|
-- set the object's draw order
|
|
|
|
self:SetDrawOrder()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if draw then
|
|
|
|
draw(self)
|
2012-05-06 00:24:42 +00:00
|
|
|
else
|
2012-09-02 00:56:32 +00:00
|
|
|
drawfunc(self)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetMax(max)
|
|
|
|
- desc: sets the object's maximum value
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:SetMax(max)
|
|
|
|
|
|
|
|
self.max = max
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetMax()
|
|
|
|
- desc: gets the object's maximum value
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:GetMax()
|
|
|
|
|
|
|
|
return self.max
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetMin(min)
|
|
|
|
- desc: sets the object's minimum value
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:SetMin(min)
|
|
|
|
|
|
|
|
self.min = min
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetMin()
|
|
|
|
- desc: gets the object's minimum value
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:GetMin()
|
|
|
|
|
|
|
|
return self.min
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetMinMax()
|
|
|
|
- desc: sets the object's minimum and maximum values
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:SetMinMax(min, max)
|
|
|
|
|
|
|
|
self.min = min
|
|
|
|
self.max = max
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetMinMax()
|
|
|
|
- desc: gets the object's minimum and maximum values
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:GetMinMax()
|
|
|
|
|
|
|
|
return self.min, self.max
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetValue(value)
|
|
|
|
- desc: sets the object's value
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:SetValue(value)
|
|
|
|
|
|
|
|
local lerp = self.lerp
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if lerp then
|
2012-05-06 00:24:42 +00:00
|
|
|
self.lerpvalue = self.lerpvalue
|
|
|
|
self.lerpto = value
|
|
|
|
self.lerpfrom = self.lerpvalue
|
|
|
|
self.value = value
|
|
|
|
else
|
|
|
|
self.value = value
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetValue()
|
|
|
|
- desc: gets the object's value
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:GetValue()
|
|
|
|
|
|
|
|
return self.value
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetLerp(bool)
|
|
|
|
- desc: sets whether or not the object should lerp
|
|
|
|
when changing between values
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:SetLerp(bool)
|
|
|
|
|
|
|
|
self.lerp = bool
|
|
|
|
self.lerpto = self:GetValue()
|
|
|
|
self.lerpvalue = self:GetValue()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetLerp()
|
|
|
|
- desc: gets whether or not the object should lerp
|
|
|
|
when changing between values
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:GetLerp()
|
|
|
|
|
|
|
|
return self.lerp
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetLerpRate(rate)
|
|
|
|
- desc: sets the object's lerp rate
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:SetLerpRate(rate)
|
|
|
|
|
|
|
|
self.lerprate = rate
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetLerpRate()
|
|
|
|
- desc: gets the object's lerp rate
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:GetLerpRate()
|
|
|
|
|
|
|
|
return self.lerprate
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetCompleted()
|
2012-09-02 21:13:13 +00:00
|
|
|
- desc: gets whether or not the object has reached it's
|
|
|
|
maximum value
|
2012-09-02 00:56:32 +00:00
|
|
|
--]]---------------------------------------------------------
|
2012-09-02 21:13:13 +00:00
|
|
|
function progressbar:GetCompleted()
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
return self.completed
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetBarWidth()
|
|
|
|
- desc: gets the object's bar width
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function progressbar:GetBarWidth()
|
|
|
|
|
|
|
|
return self.barwidth
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|