View Single Post
09/05/15, 08:34 AM   #11
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Argusus View Post
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.
Well, they have different row control template, default sort header, vastly different BuildMasterList, I think they deserve being separate classes. You can move a few things to a common base, like FilterScrollList and SortScrollList which are identical, and derive your special classes from that base.

Lua Code:
  1. local StuffListBase = ZO_SortFilterList:Subclass()
  2. local CustomerList = StuffListBase:Subclass()
  3. local XTradeItemsList = StuffListBase:Subclass()
  4. ...

My/TheirTradeItemsList look like they could be merged. Just pass the things that differ as additional arguments to initialize, and store them in the instance.

Lua Code:
  1. function XTradeItemsList:Initialize(control, itemsKey)
  2.     StuffListBase.Initialize(self, control)
  3.     self.itemsKey = itemsKey
  4.     ...
  5. end
  6.  
  7. function XTradeItemsList:BuildMasterList()
  8.     ...
  9.     for key, itemObject in pairs(selectedTrade[self.itemsKey]) do
  10.         ...
  11.     end
  12. end
  13.  
  14. TRADESMAN.MyTradeItemsList = XTradeItemsList:New(MyTradeItemsContainer, "MyItems")
  15. TRADESMAN.TheirTradeItemsList = XTradeItemsList:New(TheirTradeItemsContainer, "TheirItems")
  Reply With Quote