I tried to write some
untested code for illustration. Careful with dot where colon should be -- control:GetParent()
edit: or look at LAM controls, they too have custom data:
control.panel is the panel it's contained in
control.data is the optionData it was created from
Code:
<Control name="EventExplorerRow" virtual="true">
<Dimensions y="45"/>
<Controls>
<Label name="$(parent)Id" font="ZoFontGame" horizontalAlignment="RIGHT">
<Anchor point="RIGHT" relativePoint="LEFT" offsetX="50"/>
</Label>
<Label name="$(parent)Name" font="ZoFontGame">
<!-- I don't know how, but it's definitely possible to make this clickable,
so that you can enable/disable events by cliking on the name (see "ZO_CheckButtonLabel") -->
<Anchor point="LEFT" relativeTo="$(parent)Id" relativePoint="RIGHT" offsetX="20"/>
</Label>
</Controls>
</Control>
Lua Code:
function EventExplorer:createRows()
local function onRowClicked(...)
self:onRowClicked(...)
end
self.rows = {}
for i = 1, NUM_PAGE_ROWS do
local row = CreateControlFromVirtual("$(parent)Row", self.pageScrollWindow, "EventExplorerRow", i)
row.data = {}
row:SetHandler("OnClicked", onRowClicked)
table.insert(self.rows, row)
end
end
function EventExplorer:onRowClicked(control, button)
-- this handler should be usable for both labels and even the parent row control
-- (which I think will be useful so that cliking in the empty space between labels works)
local row
if control.data then
row = control
else
row = control:GetParent()
end
local status = self:toggleEventEnabled(row.data.eventId)
row:SetEnabled(status)
end
Lua Code:
-- this method will be used to fill the page with event ids and labels;
-- you'd store all event ids returned from a filter in self.selectedEventIds;
-- after the search you'd fill the 1st page with self:setPage(1);
-- if there are more events than NUM_PAGE_ROWS, and you provide
-- a control for switching to the next page, it can call self:setPage(self.currentPage);
function EventExplorer:setPage(pageNumber)
local offset = math.min(0, pageNumber - 1) * NUM_PAGE_ROWS
for i, row in ipairs(self.rows) do
local eventId = self.selectedEventIds[i + offset]
local idLabel = row:GetNamedChild("Id")
local nameLabel = row:GetNamedChild("Name")
row.data.eventId = eventId
if eventId then
idLabel:SetText(tostring(eventId))
nameLabel:SetText(self:getEventName(eventId))
nameLabel:SetEnabled(self:isEventEnabled(eventId))
else
idLabel:SetText("")
nameLabel:SetText("")
nameLabel:SetEnabled(false)
end
end
end
-- toggleEventEnabled, isEventEnabled will work with an internal table
-- that will keep track of what events you have registered