Originally Posted by merlight
Should've posted more concrete code -- but it was way too late, sorry -- to show why overriding New isn't needed at all thanks to how it's written (it passes all arguments to Initialize).
Lua Code:
function CustomerList:Initialize(control) ZO_SortFilterList.Initialize(self, control) self.masterList = {} ZO_ScrollList_AddDataType(self.list, 1, "CustomerUnitRow", 30, function(control, data) self:SetupUnitRow(control, data) end) ZO_ScrollList_EnableHighlight(self.list, "ZO_ThinListHighlight") self.sortFunction = function(listEntry1, listEntry2) return ZO_TableOrderingFunction(listEntry1.data, listEntry2.data, self.currentSortKey, CustomerList.SORT_KEYS, self.currentSortOrder) end self.sortHeaderGroup:SelectHeaderByKey("name") self:RefreshData() end TRADESMAN.CustomerList = CustomerList:New(CustomerListContainer)
This way CustomerListContainer is not hard-coded in the class, thus you could create multiple instances (on different container controls). Not really useful in your case, I know, but still cleaner IMO.
Another little suggestion that's good getting used to. In BuildMasterList(), don't create a new table, discarding the old one -- unless you have a million items in there and really want to free the memory and only insert a thousand -- just clear the existing table with
Lua Code:
ZO_ClearNumericallyIndexedTable(self.masterList)
|
I really like this suggestion. I have been wanting to clean up tradesman for a while now. I think making a reusable constructor would be a step in the right direction. Below is a shorter version of my "BuildMasterList"
Code:
function CustomerList:New()
local customers = ZO_SortFilterList.New(self, CustomerListContainer)
customers.masterList = {}
ZO_ScrollList_AddDataType(customers.list, 1, "CustomerUnitRow", 30, function(control, data) customers:SetupUnitRow(control, data) end)
ZO_ScrollList_EnableHighlight(customers.list, "ZO_ThinListHighlight")
customers.sortFunction = function(listEntry1, listEntry2) return ZO_TableOrderingFunction(listEntry1.data, listEntry2.data, customers.currentSortKey, CustomerList.SORT_KEYS, customers.currentSortOrder) end
customers.sortHeaderGroup:SelectHeaderByKey("name")
customers:RefreshData()
return customers
end
function CustomerList:BuildMasterList()
self.masterList = {}
local transactions = TRADESMAN.savedVariables.Transactions
table.insert(self.masterList, transactions)
end
end
Have you looked at the code for tradesman? I have 4-5 of these scroll lists, and basically the same code to create each except for the container control and the sort keys that are needed to be unique, then after that when buildmasterlist, I access the saved variables to populate the scroll lists. I wonder how I could have all of my scroll lists share the same initialization code but have unique sort keys, and build master list, passing in unique containers you explained well.