2012-05-06 00:24:42 +00:00
|
|
|
--[[------------------------------------------------
|
2012-09-29 23:20:41 +00:00
|
|
|
-- Love Frames - A GUI library for LOVE --
|
2013-02-11 21:15:40 +00:00
|
|
|
-- Copyright (c) 2013 Kenny Shields --
|
2012-05-06 00:24:42 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
|
|
|
-- multichoicelist class
|
2012-11-24 22:42:16 +00:00
|
|
|
local newobject = loveframes.NewObject("multichoicelist", "loveframes_object_multichoicelist", true)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:initialize(object)
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
self.type = "multichoicelist"
|
|
|
|
self.parent = loveframes.base
|
|
|
|
self.list = object
|
|
|
|
self.x = object.x
|
|
|
|
self.y = object.y + self.list.height
|
|
|
|
self.width = self.list.width
|
|
|
|
self.height = 0
|
|
|
|
self.clickx = 0
|
|
|
|
self.clicky = 0
|
|
|
|
self.padding = self.list.listpadding
|
|
|
|
self.spacing = self.list.listspacing
|
|
|
|
self.buttonscrollamount = object.buttonscrollamount
|
2012-11-24 22:42:16 +00:00
|
|
|
self.mousewheelscrollamount = object.mousewheelscrollamount
|
2012-12-28 12:19:02 +00:00
|
|
|
self.offsety = 0
|
|
|
|
self.offsetx = 0
|
|
|
|
self.extrawidth = 0
|
|
|
|
self.extraheight = 0
|
|
|
|
self.canremove = false
|
2013-02-11 21:15:40 +00:00
|
|
|
self.dtscrolling = self.list.dtscrolling
|
2012-12-28 12:19:02 +00:00
|
|
|
self.internal = true
|
|
|
|
self.vbar = false
|
|
|
|
self.children = {}
|
|
|
|
self.internals = {}
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
for k, v in ipairs(object.choices) do
|
2012-11-24 22:42:16 +00:00
|
|
|
local row = loveframes.objects["multichoicerow"]:new()
|
2012-05-06 00:24:42 +00:00
|
|
|
row:SetText(v)
|
|
|
|
self:AddItem(row)
|
|
|
|
end
|
|
|
|
|
2012-10-22 14:19:02 +00:00
|
|
|
table.insert(loveframes.base.internals, self)
|
|
|
|
|
|
|
|
-- apply template properties to the object
|
|
|
|
loveframes.templates.ApplyToObject(self)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:update(dt)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +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-12-28 12:19:02 +00:00
|
|
|
local width = love.graphics.getWidth()
|
|
|
|
local height = love.graphics.getHeight()
|
|
|
|
local x, y = love.mouse.getPosition()
|
|
|
|
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
|
|
|
local parent = self.parent
|
|
|
|
local base = loveframes.base
|
|
|
|
local upadte = self.Update
|
2012-09-29 23:20:41 +00:00
|
|
|
local internals = self.internals
|
2012-12-28 12:19:02 +00:00
|
|
|
local children = self.children
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
-- move to parent if there is a parent
|
2012-09-29 23:20:41 +00:00
|
|
|
if parent ~= base then
|
|
|
|
self.x = parent.x + self.staticx
|
|
|
|
self.y = parent.y + self.staticy
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if self.x < 0 then
|
|
|
|
self.x = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.x + self.width > width then
|
|
|
|
self.x = width - self.width
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.y < 0 then
|
|
|
|
self.y = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.y + self.height > height then
|
|
|
|
self.y = height - self.height
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(internals) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:update(dt)
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:update(dt)
|
|
|
|
v:SetClickBounds(self.x, self.y, self.width, self.height)
|
|
|
|
v.y = (v.parent.y + v.staticy) - self.offsety
|
|
|
|
v.x = (v.parent.x + v.staticx) - self.offsetx
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if upadte then
|
|
|
|
upadte(self, dt)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:draw()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local visible = self.visible
|
2012-09-29 23:20:41 +00:00
|
|
|
|
|
|
|
if not visible then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
|
|
|
|
local stencil = love.graphics.newStencil(stencilfunc)
|
|
|
|
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.DrawMultiChoiceList or skins[defaultskin].DrawMultiChoiceList
|
|
|
|
local drawoverfunc = skin.DrawOverMultiChoiceList or skins[defaultskin].DrawOverMultiChoiceList
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
|
|
|
local internals = self.internals
|
|
|
|
local children = self.children
|
2012-09-29 23:20:41 +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
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(internals) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:draw()
|
|
|
|
end
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
love.graphics.setStencil(stencil)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
|
2012-09-29 23:20:41 +00:00
|
|
|
if col then
|
2012-05-06 00:24:42 +00:00
|
|
|
v:draw()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
love.graphics.setStencil()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not draw then
|
|
|
|
drawoverfunc(self)
|
2012-09-02 00:56:32 +00:00
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousepressed(x, y, button)
|
|
|
|
- desc: called when the player presses a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:mousepressed(x, y, button)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local visible = self.visible
|
|
|
|
|
|
|
|
if not visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
|
|
|
local toplist = self:IsTopList()
|
2012-09-29 23:20:41 +00:00
|
|
|
local internals = self.internals
|
2012-12-28 12:19:02 +00:00
|
|
|
local children = self.children
|
2012-11-24 22:42:16 +00:00
|
|
|
local scrollamount = self.mousewheelscrollamount
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not selfcol and self.canremove and button == "l" then
|
2012-05-06 00:24:42 +00:00
|
|
|
self:Close()
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if self.vbar and toplist then
|
2013-02-11 21:15:40 +00:00
|
|
|
local bar = internals[1].internals[1].internals[1]
|
|
|
|
local dtscrolling = self.dtscrolling
|
|
|
|
if dtscrolling then
|
|
|
|
local dt = love.timer.getDelta()
|
|
|
|
if button == "wu" then
|
|
|
|
bar:Scroll(-scrollamount * dt)
|
|
|
|
elseif button == "wd" then
|
|
|
|
bar:Scroll(scrollamount * dt)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if button == "wu" then
|
|
|
|
bar:Scroll(-scrollamount)
|
|
|
|
elseif button == "wd" then
|
|
|
|
bar:Scroll(scrollamount)
|
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(internals) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:mousepressed(x, y, button)
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:mousepressed(x, y, button)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousereleased(x, y, button)
|
|
|
|
- desc: called when the player releases a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:mousereleased(x, y, button)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local visible = self.visible
|
|
|
|
|
|
|
|
if not visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local internals = self.internals
|
2012-12-28 12:19:02 +00:00
|
|
|
local children = self.children
|
2012-09-29 23:20:41 +00:00
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
self.canremove = true
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(internals) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:mousereleased(x, y, button)
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
v:mousereleased(x, y, button)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: AddItem(object)
|
|
|
|
- desc: adds an item to the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:AddItem(object)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-26 12:45:33 +00:00
|
|
|
if object.type ~= "multichoicerow" then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
object.parent = self
|
|
|
|
table.insert(self.children, object)
|
|
|
|
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: RemoveItem(object)
|
|
|
|
- desc: removes an item from the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:RemoveItem(object)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local children = self.children
|
|
|
|
|
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
if v == object then
|
2012-09-29 23:20:41 +00:00
|
|
|
table.remove(children, k)
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self:CalculateSize()
|
|
|
|
self:RedoLayout()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: CalculateSize()
|
|
|
|
- desc: calculates the size of the object's children
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:CalculateSize()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self.height = self.padding
|
|
|
|
|
|
|
|
if self.list.listheight then
|
|
|
|
self.height = self.list.listheight
|
|
|
|
else
|
|
|
|
for k, v in ipairs(self.children) do
|
|
|
|
self.height = self.height + (v.height + self.spacing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.height > love.graphics.getHeight() then
|
|
|
|
self.height = love.graphics.getHeight()
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local numitems = #self.children
|
|
|
|
local height = self.height
|
|
|
|
local padding = self.padding
|
|
|
|
local spacing = self.spacing
|
2012-05-06 00:24:42 +00:00
|
|
|
local itemheight = self.padding
|
2012-12-28 12:19:02 +00:00
|
|
|
local vbar = self.vbar
|
|
|
|
local children = self.children
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
for k, v in ipairs(children) do
|
2012-05-06 00:24:42 +00:00
|
|
|
itemheight = itemheight + v.height + spacing
|
|
|
|
end
|
|
|
|
|
|
|
|
self.itemheight = (itemheight - spacing) + padding
|
|
|
|
|
|
|
|
if self.itemheight > height then
|
2012-10-22 14:19:02 +00:00
|
|
|
self.extraheight = self.itemheight - height
|
2012-09-29 23:20:41 +00:00
|
|
|
if not vbar then
|
2012-11-24 22:42:16 +00:00
|
|
|
local scroll = loveframes.objects["scrollbody"]:new(self, "vertical")
|
2012-05-06 00:24:42 +00:00
|
|
|
table.insert(self.internals, scroll)
|
|
|
|
self.vbar = true
|
|
|
|
end
|
|
|
|
else
|
2012-09-29 23:20:41 +00:00
|
|
|
if vbar then
|
2012-05-06 00:24:42 +00:00
|
|
|
self.internals[1]:Remove()
|
|
|
|
self.vbar = false
|
|
|
|
self.offsety = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: RedoLayout()
|
|
|
|
- desc: used to redo the layour of the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:RedoLayout()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
local children = self.children
|
2012-12-28 12:19:02 +00:00
|
|
|
local padding = self.padding
|
|
|
|
local spacing = self.spacing
|
|
|
|
local starty = padding
|
|
|
|
local vbar = self.vbar
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
if #children > 0 then
|
|
|
|
for k, v in ipairs(children) do
|
|
|
|
v.staticx = padding
|
|
|
|
v.staticy = starty
|
2012-09-29 23:20:41 +00:00
|
|
|
if vbar then
|
|
|
|
v.width = (self.width - self.internals[1].width) - padding * 2
|
2012-05-06 00:24:42 +00:00
|
|
|
self.internals[1].staticx = self.width - self.internals[1].width
|
|
|
|
self.internals[1].height = self.height
|
|
|
|
else
|
2012-09-29 23:20:41 +00:00
|
|
|
v.width = self.width - padding * 2
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
starty = starty + v.height
|
|
|
|
starty = starty + spacing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetPadding(amount)
|
|
|
|
- desc: sets the object's padding
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetPadding(amount)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self.padding = amount
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetSpacing(amount)
|
|
|
|
- desc: sets the object's spacing
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetSpacing(amount)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self.spacing = amount
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: Close()
|
|
|
|
- desc: closes the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:Close()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
self:Remove()
|
|
|
|
self.list.haslist = false
|
2012-12-28 12:19:02 +00:00
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|