LoveFrames/objects/internal/multichoice/multichoicerow.lua

182 lines
4.1 KiB
Lua
Raw Normal View History

2012-05-06 00:24:42 +00:00
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
2014-01-14 11:29:11 +00:00
-- Copyright (c) 2012-2014 Kenny Shields --
2012-05-06 00:24:42 +00:00
--]]------------------------------------------------
-- multichoicerow class
local newobject = loveframes.NewObject("multichoicerow", "loveframes_object_multichoicerow", true)
2012-05-06 00:24:42 +00:00
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
2012-05-06 00:24:42 +00:00
self.type = "multichoicerow"
self.text = ""
self.width = 50
self.height = 25
self.hover = false
self.internal = true
self.down = false
self.canclick = false
2012-05-06 00:24:42 +00:00
-- 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
--]]---------------------------------------------------------
function newobject:update(dt)
2012-05-06 00:24:42 +00:00
local visible = self.visible
local alwaysupdate = self.alwaysupdate
if not visible then
if not alwaysupdate then
2012-05-06 00:24:42 +00:00
return
end
end
local parent = self.parent
local base = loveframes.base
local update = self.Update
2012-05-06 00:24:42 +00:00
self:CheckHover()
if not self.hover then
self.down = false
else
if loveframes.downobject == self then
self.down = true
end
end
if not self.down and loveframes.downobject == self then
self.hover = true
end
2012-05-06 00:24:42 +00:00
-- move to parent if there is a parent
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 update then
update(self, dt)
2012-05-06 00:24:42 +00:00
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function newobject:draw()
2012-05-06 00:24:42 +00:00
local visible = self.visible
if not visible then
return
end
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.DrawMultiChoiceRow or skins[defaultskin].DrawMultiChoiceRow
local draw = self.Draw
-- set the object's draw order
self:SetDrawOrder()
2012-05-06 00:24:42 +00:00
if draw then
draw(self)
2012-05-06 00:24:42 +00:00
else
drawfunc(self)
2012-05-06 00:24:42 +00:00
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function newobject:mousepressed(x, y, button)
2012-05-06 00:24:42 +00:00
local visible = self.visible
if not visible then
2012-05-06 00:24:42 +00:00
return
end
local hover = self.hover
if hover and button == "l" then
self.down = true
loveframes.downobject = self
end
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function newobject:mousereleased(x, y, button)
2012-05-06 00:24:42 +00:00
local visible = self.visible
if not visible then
2012-05-06 00:24:42 +00:00
return
end
local text = self.text
if self.hover and self.down and self.canclick and button == "l" then
self.parent.list:SelectChoice(text)
2012-05-06 00:24:42 +00:00
end
self.down = false
self.canclick = true
end
--[[---------------------------------------------------------
2014-04-03 22:55:46 +00:00
- func: keypressed(key, isrepeat)
- desc: called when the player presses a key
--]]---------------------------------------------------------
2014-04-03 22:55:46 +00:00
function newobject:keypressed(key, isrepeat)
local text = self.text
local selectedobject = loveframes.selectedobject
if key == "return" and selectedobject == self then
self.parent.list:SelectChoice(text)
end
end
--[[---------------------------------------------------------
- func: SetText(text)
- desc: sets the object's text
--]]---------------------------------------------------------
function newobject:SetText(text)
2012-05-06 00:24:42 +00:00
self.text = text
end
--[[---------------------------------------------------------
- func: GetText()
- desc: gets the object's text
--]]---------------------------------------------------------
function newobject:GetText()
return self.text
2012-05-06 00:24:42 +00:00
end