tibia-client/modules/corelib/ui/uiradiogroup.lua

67 lines
1.6 KiB
Lua
Raw Normal View History

2012-06-26 00:13:30 +02:00
-- @docclass
UIRadioGroup = newclass("UIRadioGroup")
2012-02-08 00:06:52 +01:00
2012-06-26 00:13:30 +02:00
function UIRadioGroup.create()
local radiogroup = UIRadioGroup.internalCreate()
2012-02-08 00:06:52 +01:00
radiogroup.widgets = {}
radiogroup.selectedWidget = nil
2012-02-08 00:06:52 +01:00
return radiogroup
end
2012-06-26 00:13:30 +02:00
function UIRadioGroup:destroy()
2012-04-09 22:52:39 +02:00
for k,widget in pairs(self.widgets) do
widget.onClick = nil
2012-02-08 00:06:52 +01:00
end
2012-04-09 22:52:39 +02:00
self.widgets = {}
2012-02-08 00:06:52 +01:00
end
2012-06-26 00:13:30 +02:00
function UIRadioGroup:addWidget(widget)
2012-02-08 00:06:52 +01:00
table.insert(self.widgets, widget)
widget.onClick = function(widget) self:selectWidget(widget) end
2012-02-08 00:06:52 +01:00
end
2012-06-26 00:13:30 +02:00
function UIRadioGroup:removeWidget(widget)
2012-02-08 00:06:52 +01:00
if self.selectedWidget == widget then
self:selectWidget(nil)
end
widget.onClick = nil
2012-02-08 00:06:52 +01:00
table.removevalue(self.widgets, widget)
end
function UIRadioGroup:selectWidget(selectedWidget, dontSignal)
2012-02-08 00:06:52 +01:00
if selectedWidget == self.selectedWidget then return end
local previousSelectedWidget = self.selectedWidget
self.selectedWidget = selectedWidget
if previousSelectedWidget then
previousSelectedWidget:setChecked(false)
end
if selectedWidget then
selectedWidget:setChecked(true)
end
if not dontSignal then
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
end
2012-02-08 00:06:52 +01:00
end
function UIRadioGroup:clearSelected()
if not self.selectedWidget then return end
local previousSelectedWidget = self.selectedWidget
self.selectedWidget:setChecked(false)
self.selectedWidget = nil
signalcall(self.onSelectionChange, self, nil, previousSelectedWidget)
end
function UIRadioGroup:getSelectedWidget()
return self.selectedWidget
2013-01-31 02:44:57 +01:00
end
function UIRadioGroup:getFirstWidget()
return self.widgets[1]
end