View Single Post
01/31/24, 02:18 PM   #8
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,000
ZO_ComboBox changes

ZO_ComboBox changes
The ZO_ComboBox with API101041 will use a new TopLevelControl for the dropdown (the scroll list that opens below the combobox and shows the selectable entries) so that the dropdown overlays other controls properly.

Basically you should not see any difference and have nothing to do in your addons if you have not accessed your combobox/dropdown by
any internal references like combobox.m_dropdown or combobox.m_scroll

-> But if you are referecing/accessing those, please read below how to fix these missing references within API101041


What did ZOs do to fix the overlaying dropdowns?
For that purpose ZOs has added a new dropdownObject (with it's own class ZO_ComboBoxDropdown_Keyboard) which get's set at the ZO_ComboBox init function:

Lua Code:
  1. function ZO_ComboBox:Initialize(control)
  2. ...
  3. self:SetDropdownObject(ZO_COMBO_BOX_DROPDOWN_KEYBOARD)

The object ZO_COMBO_BOX_DROPDOWN_KEYBOARD will be passed in via the XML:
Code:
<TopLevelControl name="ZO_ComboBoxDropdown_Singleton_Keyboard" inherits="ZO_ComboBoxDropdown_Keyboard_Template">
            <OnInitialized name="ComboBoxSingleton">
                ZO_COMBO_BOX_DROPDOWN_KEYBOARD = self.object <!-- self.object will be set as the XML object get's created, see below -->
            </OnInitialized>
        </TopLevelControl>

Thix XML inherits from the other virtual XML ZO_ComboBoxDropdown_Keyboard_Template:
Code:
<TopLevelControl name="ZO_ComboBoxDropdown_Keyboard_Template" hidden="true" virtual="true" tier="HIGH" level="ZO_HIGH_TIER_KEYBOARD_COMBO_BOX_DROPDOWN" mouseEnabled="true" clampedToScreen="true">
            <Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" />
            <!-- Width will be set programmatically -->

            <OnInitialized>
                ZO_ComboBoxDropdown_Keyboard.InitializeFromControl(self)
            </OnInitialized>

OnInitialized calls:
Lua Code:
  1. ZO_ComboBoxDropdown_Keyboard.InitializeFromControl(control)
  2.    local dropdownObject = ZO_ComboBoxDropdown_Keyboard:New(control)
  3.     control.object = dropdownObject --here self.object will be set at the XML created object of

Attention: The object ZO_COMBO_BOX_DROPDOWN_KEYBOARD is a "singleton" so it is only craeted ONCE for ALL ZO_comboBoxes which makes it impossible to open 2 comboboxes at the same time (as the same TLC will be reused to show the list entries).

What do I have to do if my addon get nil errors (e.g. at .m_dropdown or .m_scroll)?
The difference to API 101040 is that ZO_ComboBox.m_dropdown and .m_scroll do not exist any longer! They moved to .m_dropdownObject


To implement current support for live AND PTS API101041 you can do something like
Lua Code:
  1. --ZO_ComboBox changes with API101041 -> ZO_ComboBox uses a TLC for the dropdown now -> dropdownObject
  2. local APIVersion = GetAPIVersion()
  3. local apiVersionUpdate3_8 = 101041
  4. local isUsingDropdownObject = (APIVersion >= apiVersionUpdate3_8 and true) or false

And in your code then use it like this:
Lua Code:
  1. --API101041+
  2. if isUsingDropdownObject then
  3.    comboBox:SetDropdownObject(MY_ADDONS_COMBO_BOX_DROPDOWN_KEYBOARD) --if you have defined your own dropdownObject XML template e.g. with name MY_ADDONS_COMBO_BOX_DROPDOWN_KEYBOARD -> Function will set comboBox.m_dropdownObject!
  4.   local dropdownObject = comboBox.m_dropdownObject
  5.   --Backwards compatibility with code before API101041 as m_dropdown and m_scroll do not exist in API101041 keyboard mode anylonger (were moved to m_dropdownObject!)
  6.   comboBox.m_dropdown = dropdownObject.control
  7.   comboBox.m_scroll = dropdownObject.scrollControl
  8. end
  9. ... --code of API101040


Entries at the combobox's dropdown changed from table to ZO_EntryData!!!
The function ZO_ComboBox:AddMenuItems will now simply call the combobox.m_dropdownObject:Show() function

Lua Code:
  1. function ZO_ComboBox:AddMenuItems()
  2.     self.m_dropdownObject:Show(self, self.m_sortedItems, self.m_containerWidth, self.m_height, self:GetSpacing())
  3. end
  4.  
  5. -> This Show function loops the m_sortedItems table of the ZO_ComboBox and builds ZO_EntryData entries then of it, adds them to a table "dataList" and then calculates height and width of the dropdown absed on the entries, and finally populates them at the ZO_ScrollList.
  6.  
  7. function ZO_ComboBoxDropdown_Keyboard:Show(comboBox, itemTable, minWidth, maxHeight, spacing)
  8.  ...
  9.  local numItems = #itemTable
  10.     local dataList = ZO_ScrollList_GetDataList(self.scrollControl)
  11.  
  12.     local largestEntryWidth = 0
  13.     local allItemsHeight = 0
  14.  
  15.     for i = 1, numItems do
  16.  ...
  17.       local entry = CreateScrollableComboBoxEntry(self, item, i, entryType)
  18.         table.insert(dataList, entry)
  19. ...
  20.     end
  21. end

Function CreateScrollableComboBoxEntry creates the ZO_DataEntry entries here.
If you need to manually add entries to your ZO_ComboBox you can copy that local function from ZOs code and reuse it that way at your ZO_ComboBox:AddMenuItems OR at your version of function MY_ADDONS_COMBO_BOX_DROPDOWN_KEYBOARD:Show(comboBox, itemTable, minWidth, maxHeight, spacing)

Here is the function's code:
Lua Code:
  1. local function CreateScrollableComboBoxEntry(self, item, index, entryType)
  2.     local entryData = ZO_EntryData:New(item)
  3.     entryData.m_index = index
  4.     entryData.m_owner = self.owner
  5.     entryData.m_dropdownObject = self
  6.     entryData:SetupAsScrollListDataEntry(entryType)
  7.     return entryData
  8. end


Edit:
Currently clicking the ZO_ComboBox control does not open the dropdown, only clicking the small v button does open it (and if that buttons DrawLevel is too low it hides behind the other controls so you might have to change the DrawLevel in your XML code to the same/higher than the combobox control's!).
Here is an info from code who realized that, and ZOs answer:

code65536
@(ZOS) DanBatson (ZOS) SethL There is a bug on PTS related to your refactor of ZO_ComboBox... specifically, the down arrow button will not open the dropdown... clicking on the dropdown box itself works, but if you target the arrow button, it won't actually work... I can confirm that this is a problem on the Feb. 19 PTS even with zero addons loaded

(ZOS) SethL
This has been fixed internally and is making its way up the chain. It should be fixed by the time we hit live

Last edited by Baertram : 03/10/24 at 07:12 AM.
  Reply With Quote