2012-09-02 00:56:32 +00:00
|
|
|
--[[------------------------------------------------
|
2012-09-29 23:20:41 +00:00
|
|
|
-- Love Frames - A GUI library for LOVE --
|
|
|
|
-- Copyright (c) 2012 Kenny Shields --
|
2012-09-02 00:56:32 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
-- multichoice class
|
2012-09-02 00:56:32 +00:00
|
|
|
multichoice = class("multichoice", base)
|
|
|
|
multichoice:include(loveframes.templates.default)
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:initialize()
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
self.type = "multichoice"
|
|
|
|
self.choice = ""
|
|
|
|
self.text = "Select an option"
|
|
|
|
self.width = 200
|
|
|
|
self.height = 25
|
|
|
|
self.listpadding = 0
|
|
|
|
self.listspacing = 0
|
|
|
|
self.haslist = false
|
|
|
|
self.internal = false
|
|
|
|
self.choices = {}
|
|
|
|
self.listheight = nil
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:update(dt)
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local visible = self.visible
|
2012-09-02 00:56:32 +00:00
|
|
|
local alwaysupdate = self.alwaysupdate
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local parent = self.parent
|
|
|
|
local update = self.Update
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
self:CheckHover()
|
|
|
|
|
|
|
|
-- move to parent if there is a parent
|
2012-09-29 23:20:41 +00:00
|
|
|
if parent then
|
2012-09-02 00:56:32 +00:00
|
|
|
self.x = self.parent.x + self.staticx
|
|
|
|
self.y = self.parent.y + self.staticy
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if update then
|
|
|
|
update(self, dt)
|
2012-09-02 00:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:draw()
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-09-02 00:56:32 +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.DrawMultiChoice or skins[defaultskin].DrawMultiChoice
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
loveframes.drawcount = drawcount + 1
|
2012-09-02 00:56:32 +00:00
|
|
|
self.draworder = loveframes.drawcount
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if draw then
|
|
|
|
draw(self)
|
2012-09-02 00:56:32 +00:00
|
|
|
else
|
|
|
|
drawfunc(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousepressed(x, y, button)
|
|
|
|
- desc: called when the player presses a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:mousepressed(x, y, button)
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local hover = self.hover
|
2012-09-02 00:56:32 +00:00
|
|
|
local haslist = self.haslist
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if hover and not haslist and button == "l" then
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
local baseparent = self:GetBaseParent()
|
|
|
|
|
|
|
|
if baseparent and baseparent.type == "frame" then
|
|
|
|
baseparent:MakeTop()
|
|
|
|
end
|
|
|
|
|
|
|
|
self.haslist = true
|
|
|
|
self.list = multichoicelist:new(self)
|
|
|
|
loveframes.hoverobject = self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousereleased(x, y, button)
|
|
|
|
- desc: called when the player releases a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:mousereleased(x, y, button)
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: AddChoice(choice)
|
|
|
|
- desc: adds a choice to the current list of choices
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:AddChoice(choice)
|
|
|
|
|
|
|
|
local choices = self.choices
|
|
|
|
table.insert(choices, choice)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetChoice(choice)
|
|
|
|
- desc: sets the current choice
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:SetChoice(choice)
|
|
|
|
|
|
|
|
self.choice = choice
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SelectChoice(choice)
|
|
|
|
- desc: selects a choice
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:SelectChoice(choice)
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local onchoiceselected = self.OnChoiceSelected
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
self.choice = choice
|
|
|
|
self.list:Close()
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if onchoiceselected then
|
|
|
|
onchoiceselected(self, choice)
|
2012-09-02 00:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetListHeight(height)
|
|
|
|
- desc: sets the height of the list of choices
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:SetListHeight(height)
|
|
|
|
|
|
|
|
self.listheight = height
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetPadding(padding)
|
|
|
|
- desc: sets the padding of the list of choices
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:SetPadding(padding)
|
|
|
|
|
|
|
|
self.listpadding = padding
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetSpacing(spacing)
|
|
|
|
- desc: sets the spacing of the list of choices
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:SetSpacing(spacing)
|
|
|
|
|
|
|
|
self.listspacing = spacing
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetValue()
|
|
|
|
- desc: gets the value (choice) of the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:GetValue()
|
|
|
|
|
|
|
|
return self.choice
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetChoice()
|
|
|
|
- desc: gets the current choice (same as get value)
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:GetChoice()
|
|
|
|
|
|
|
|
return self.choice
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetText(text)
|
|
|
|
- desc: sets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:SetText(text)
|
|
|
|
|
|
|
|
self.text = text
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetText()
|
|
|
|
- desc: gets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function multichoice:GetText()
|
|
|
|
|
|
|
|
return self.text
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|