2012-05-06 00:24:42 +00:00
|
|
|
--[[------------------------------------------------
|
2012-09-29 23:20:41 +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
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
-- columnlistrow class
|
2012-11-24 22:42:16 +00:00
|
|
|
local newobject = loveframes.NewObject("columnlistrow", "loveframes_object_columnlistrow", true)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: intializes the element
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:initialize(parent, data)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
self.type = "columnlistrow"
|
|
|
|
self.parent = parent
|
2013-06-25 10:58:35 +00:00
|
|
|
self.state = parent.state
|
2012-12-28 12:19:02 +00:00
|
|
|
self.colorindex = self.parent.rowcolorindex
|
|
|
|
self.font = loveframes.basicfontsmall
|
|
|
|
self.width = 80
|
|
|
|
self.height = 25
|
|
|
|
self.textx = 5
|
|
|
|
self.texty = 5
|
2013-06-10 16:34:01 +00:00
|
|
|
self.selected = false
|
2012-12-28 12:19:02 +00:00
|
|
|
self.internal = true
|
2013-08-12 13:48:51 +00:00
|
|
|
self.columndata = {}
|
|
|
|
|
|
|
|
for k, v in ipairs(data) do
|
|
|
|
self.columndata[k] = tostring(v)
|
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-10-22 14:19:02 +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
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:update(dt)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2014-08-23 08:36:47 +00:00
|
|
|
if not self.visible then
|
|
|
|
if not self.alwaysupdate then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local parent = self.parent
|
|
|
|
local update = self.Update
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
self:CheckHover()
|
|
|
|
|
|
|
|
-- move to parent if there is a parent
|
2014-08-23 08:36:47 +00:00
|
|
|
if parent ~= loveframes.base then
|
2012-09-29 23:20:41 +00:00
|
|
|
self.x = parent.x + self.staticx
|
|
|
|
self.y = parent.y + self.staticy
|
2012-05-06 00:24:42 +00:00
|
|
|
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
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:draw()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2014-08-23 08:36:47 +00:00
|
|
|
if not self.visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +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.DrawColumnListRow or skins[defaultskin].DrawColumnListRow
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
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-09-02 00:56:32 +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-05-06 03:35:10 +00:00
|
|
|
|
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
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not self.visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-08-23 08:36:47 +00:00
|
|
|
if self.hover and button == "l" then
|
2012-05-06 00:24:42 +00:00
|
|
|
local baseparent = self:GetBaseParent()
|
|
|
|
if baseparent and baseparent.type == "frame" then
|
|
|
|
baseparent:MakeTop()
|
|
|
|
end
|
2014-08-23 08:36:47 +00:00
|
|
|
self:GetParent():GetParent():SelectRow(self, loveframes.util.IsCtrlDown())
|
2012-05-06 00:24:42 +00:00
|
|
|
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
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not self.visible then
|
2012-05-06 00:24:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-10 16:34:01 +00:00
|
|
|
if self.hover then
|
2014-08-23 08:36:47 +00:00
|
|
|
local parent = self:GetParent():GetParent()
|
2013-06-10 16:34:01 +00:00
|
|
|
if button == "l" then
|
2014-08-23 08:36:47 +00:00
|
|
|
local onrowclicked = parent.OnRowClicked
|
2013-06-10 16:34:01 +00:00
|
|
|
if onrowclicked then
|
2014-08-23 08:36:47 +00:00
|
|
|
onrowclicked(parent, self, self.columndata)
|
2013-06-10 16:34:01 +00:00
|
|
|
end
|
|
|
|
elseif button == "r" then
|
2014-08-23 08:36:47 +00:00
|
|
|
local onrowrightclicked = parent.OnRowRightClicked
|
2013-06-10 16:34:01 +00:00
|
|
|
if onrowrightclicked then
|
2014-08-23 08:36:47 +00:00
|
|
|
onrowrightclicked(parent, self, self.columndata)
|
2013-06-10 16:34:01 +00:00
|
|
|
end
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
2012-05-08 21:48:39 +00:00
|
|
|
- func: SetTextPos(x, y)
|
|
|
|
- desc: sets the positions of the object's text
|
2012-05-06 00:24:42 +00:00
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetTextPos(x, y)
|
2012-05-08 21:48:39 +00:00
|
|
|
|
|
|
|
self.textx = x
|
|
|
|
self.texty = y
|
2012-05-06 00:24:42 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetTextX()
|
|
|
|
- desc: gets the object's text x position
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetTextX()
|
2012-09-29 23:20:41 +00:00
|
|
|
|
|
|
|
return self.textx
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetTextY()
|
|
|
|
- desc: gets the object's text y position
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetTextY()
|
2012-09-29 23:20:41 +00:00
|
|
|
|
|
|
|
return self.texty
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
--[[---------------------------------------------------------
|
2012-05-08 21:48:39 +00:00
|
|
|
- func: SetFont(font)
|
|
|
|
- desc: sets the object's font
|
2012-05-06 00:24:42 +00:00
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetFont(font)
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-05-08 21:48:39 +00:00
|
|
|
self.font = font
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetFont()
|
|
|
|
- desc: gets the object's font
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetFont()
|
2012-05-08 21:48:39 +00:00
|
|
|
|
|
|
|
return self.font
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetColorIndex()
|
|
|
|
- desc: gets the object's color index
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetColorIndex()
|
2012-05-08 21:48:39 +00:00
|
|
|
|
|
|
|
return self.colorindex
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-06-10 16:34:01 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetColumnData(data)
|
|
|
|
- desc: sets the object's column data
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetColumnData(data)
|
|
|
|
|
|
|
|
self.columndata = data
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-05-08 21:48:39 +00:00
|
|
|
--[[---------------------------------------------------------
|
2012-09-29 23:20:41 +00:00
|
|
|
- func: GetColumnData()
|
|
|
|
- desc: gets the object's column data
|
2012-05-08 21:48:39 +00:00
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetColumnData()
|
2012-05-06 00:24:42 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
return self.columndata
|
|
|
|
|
2013-06-10 16:34:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetSelected(selected)
|
|
|
|
- desc: sets whether or not the object is selected
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetSelected(selected)
|
|
|
|
|
|
|
|
self.selected = true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetSelected()
|
|
|
|
- desc: gets whether or not the object is selected
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetSelected()
|
|
|
|
|
|
|
|
return self.selected
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|