Thread Tools Display Modes
05/05/15, 03:40 AM   #1
Glen348
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
want to remove XML file

im looking for a way to remove the xml file and make it work in lua only any ideals?
Lua Code:
  1. local function CreateIndexButton(indexPool)
  2.     local button = ZO_ObjectPool_CreateControl("NotebookIndex", indexPool, notebook.toc.scrollChild)
  3.     local anchorBtn = buttonCount == 1 and notebook.toc.scrollChild or indexPool:AcquireObject(buttonCount-1)
  4.         button:SetAnchor(TOPLEFT, anchorBtn, buttonCount == 1 and TOPLEFT or BOTTOMLEFT)
  5.         button:SetHorizontalAlignment(TEXT_ALIGN_LEFT)     
  6.         button:SetFont("ZoFontBookPaper")      
  7.         button:SetWidth(400)
  8.         button:SetNormalFontColor(0, 0, 0, 0.7)
  9.         button:SetPressedFontColor(0, 0, 0, 0.9)
  10.         button:SetMouseOverFontColor(0, 0, 0, 0.4)
  11.         button:SetClickSound() 
  12.         button:SetHandler("OnClicked", function(self)
  13.             currentlyViewing = self.id
  14.             notebook.titleEdit:SetText(UnprotectText(self.data.title))
  15.             notebook.edit:SetText(UnprotectText(self.data.text))
  16.             notebook.selectedpage:ClearAnchors()
  17.             notebook.selectedpage:SetAnchorFill(self)
  18.             PlaySound(SOUNDS.BOOK_PAGE_TURN)           
  19.         end)
  20.     buttonCount = buttonCount + 1
  21.     return button
  22. end
  23.  
  24.     PopulateScrollList()
  25.         if self.new then
  26.             notebook.selectedpage:SetAnchorFill(_G["NotebookIndex"..currentlyViewing])
  27.         end

Code:
<GuiXml>
	<Controls>
		<Button name="NotebookIndex" virtual="true" inherits="ZO_DefaultTextButton">
		</Button>
	</Controls>
</GuiXml>

Last edited by Glen348 : 05/06/15 at 01:16 AM.
  Reply With Quote
05/05/15, 08:40 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Hi.

Just by looking at the code you posted, I would say that your template "NotebookIndex" does not introduce something new. So you could just replace your template with "ZO_DefaultTextButton" and you are done.
Lua Code:
  1. local button = ZO_ObjectPool_CreateControl("ZO_DefaultTextButton", indexPool, notebook.toc.scrollChild)
Or did I miss something?
  Reply With Quote
05/06/15, 01:09 AM   #3
Glen348
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
Thanks a lot, I hate xml :P

Last edited by Glen348 : 05/06/15 at 02:31 AM.
  Reply With Quote
05/06/15, 03:00 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Glen348 View Post
Thanks a lot, I hate xml :P


just some notes:
ZO_ObjectPool_CreateControl is simply a shortcut to CreateControlFromVirtual which abuses TemplateName as NamePrefix:
Lua Code:
  1. function ZO_ObjectPool_CreateControl(templateName, objectPool, parentControl)
  2.     return CreateControlFromVirtual(templateName, parentControl, templateName, objectPool:GetNextControlId())
  3. end
So this may better:
Lua Code:
  1. local button = CreateControlFromVirtual("NotebookIndex", notebook.toc.scrollChild, "ZO_DefaultTextButton", indexPool:GetNextControlId())
CreateControlFromVirtual just does:
Lua Code:
  1. local button = WINDOW_MANAGER:CreateControlFromVirtual("NotebookIndex" .. indexPool:GetNextControlId(), notebook.toc.scrollChild, "ZO_DefaultTextButton")

By the way: Is "NotebookIndex" really unique enough?
Another thing you should ask yourself is: Why using a pool instance and counting on your own with buttonCount?
If you want to chain controls in a loop you may change the whole construct to use a variable "lastControl" which remembers the previous button to anchor to.
Why recreating the control's names and look into the global instead of saving a reference to the "right" button in notebook.selectedpage.button
And what, if this button already exists?

Good luck
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » want to remove XML file


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off