Thread Tools Display Modes
11/09/20, 06:34 PM   #1
Nant
Join Date: Nov 2020
Posts: 2
Help with Hiding Addon except in Main Window

Good day all.

I have followed the tutorials to create my first addon. I am making a simple pane that displays stats such as Max(Mag/Stam), Recovery, SP/WP, SC/WC, etc in real time. I plan on extending the functionality later on, as well as changing to templates for the controls, but for now, I just want the addon to not display unless the character is in the main window. Currently, when I access the game menu, the addon is still visible until I log out etc. Is there an event I need to register for to toggle the view?

I realize my code is pretty ugly at this point, but any help or guidance would be appreciated.

Current lua:
Code:
SimpleStats = {}

SimpleStats.name = "SimpleStats"

function SimpleStats.OnWindowMoveStop()

	SimpleStats.savedVariables.left = SimpleStatsWindow:GetLeft()
	SimpleStats.savedVariables.top = SimpleStatsWindow:GetTop()

end

function SimpleStats:RestorePosition()

	local left = self.savedVariables.left
	local top = self.savedVariables.top
	
	SimpleStatsWindow:ClearAnchors()
	SimpleStatsWindow:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)

end

function SimpleStats:Initialize()
	
	self.savedVariables = ZO_SavedVars:New("SimpleStatsSavedVariables", 1, nil, {})
	
	self:RestorePosition()

end

function SimpleStats.OnAddOnLoaded(event, addonName)

	if addonName == SimpleStats.name then
		SimpleStats:Initialize()
	end
	
end

EVENT_MANAGER:RegisterForEvent(SimpleStats.name, EVENT_ADD_ON_LOADED, SimpleStats.OnAddOnLoaded)
Current XML:
Code:
<GuiXml>
	<Controls>
		<TopLevelControl name="SimpleStatsWindow" mouseEnabled="true" movable="true" clampedToScreen="true">
			<Dimensions x="200" y="150" />
			<Anchor point="TOPLEFT" relativeTo="GuiRoot" relativePoint="TOPLEFT" offsetY="-150" />
			
			<OnMoveStop>
				SimpleStats.OnWindowMoveStop()
			</OnMoveStop>
			
			<Controls>
				<Backdrop name="$(parent)Bg" inherits="ZO_DefaultBackdrop" />
				<Label name="$(parent)Label-Max" width="100" height="5" font="ZoFontGameLarge" inheritAlpha="true" color="FFFFFF" wrapMode="TRUNCATE" text="Max">
					<Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" />
				</Label>
				<Label name="$(parent)Label-Rec" width="100" height="5" font="ZoFontGameLarge" inheritAlpha="true" color="FFFFFF" wrapMode="TRUNCATE" text="Rec">
					<Anchor point="TOPLEFT" relativeTo="$(parent)Label-Max" relativePoint="BOTTOMLEFT" />
				</Label>
				<Label name="$(parent)Label-Power" width="100" height="5" font="ZoFontGameLarge" inheritAlpha="true" color="FFFFFF" wrapMode="TRUNCATE" text="Pow">
					<Anchor point="TOPLEFT" relativeTo="$(parent)Label-Rec" relativePoint="BOTTOMLEFT" />
				</Label>
				<Label name="$(parent)Label-Crit" width="100" height="5" font="ZoFontGameLarge" inheritAlpha="true" color="FFFFFF" wrapMode="TRUNCATE" text="Cri">
					<Anchor point="TOPLEFT" relativeTo="$(parent)Label-Power" relativePoint="BOTTOMLEFT" />
				</Label>
				<Label name="$(parent)Label-Pen" width="100" height="5" font="ZoFontGameLarge" inheritAlpha="true" color="FFFFFF" wrapMode="TRUNCATE" text="Pen">
					<Anchor point="TOPLEFT" relativeTo="$(parent)Label-Crit" relativePoint="BOTTOMLEFT" />
				</Label>
			</Controls>
		</TopLevelControl>
	</Controls>
</GuiXml>
  Reply With Quote
11/10/20, 02:30 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
https://wiki.esoui.com/Main_Page
Lower bottom right -> Templates:
Scene Manager: On scene change
Fragments in a scene: On fragment state change (e.g. Hide control as menu opens)

The game uses SCENES which are a kind of "visible tables storing controls and data", and each scene got 1 to n fragments attached.
You are able to react on the scenes and/or fragments as they are going to be shown (showing), are shown (shown), going to be hidden (hiding) or are hidden (hidden) again via a callback function.

If you register your own fragment, add your Top Level Control to it and thena dd this fragment to an exisitng scene like the hud or hud_ui the standard show/hide functions will handle the show/hide of your fragment as well, automatically.

Edit about your code:
You should not mix up the usage of . and : in your code.

https://wiki.esoui.com/SimpleNotebookTutorial/part5

function SimpleStats.OnWindowMoveStop()
function SimpleStats:RestorePosition

As your SimpleStats is ONLY a anormal table, defined via = {}, and it's not a kind of object or class defined via ZO_Object:Subclass() or ZO_Object:New() I'd go with the normal . instead of a :.

In this curren simple example it does not make a big difference.
But if you will use objects and "subclasses" one day you'll get into trouble if you only use . as the parameters of the functions do not automatically add the object (self) and you manually need to isert it as always 1st parameter.

Difference shown with an example:
Lua Code:
  1. local myClass = ZO_Object:Subclass()
  2. ... --function myClass:New() and maybe :Initialize() within :New here
  3. function myClass:Test(param1)
  4.  d("This is a test: " ..tostring(param1))
  5. end
  6.  
  7. local myObject = myClass:New()
  8. myObject:Test("YEAH!")
  9. --output: This is a test YEAH!
This was using a class and an object created from this class.
Classes within ESO lua are just tables using the setmetatable functions to "inherit data from the tables above", so no real classes lie within other languages.

Now an example where the created object will be calling the Test function without :, only by .
Lua Code:
  1. local myClass = ZO_Object:Subclass()
  2. ... --function myClass:New() and maybe :Initialize() within :New here
  3. function myClass:Test(param1)
  4.  d("This is a test: " ..tostring(param1))
  5.  --variable self is known and points to the created object of myClass -> see myObject below
  6. end
  7.  
  8. local myObject = myClass:New()
  9.  
  10. myObject.Test("YEAH!")
  11. --> Will fail as you use the . instead of : and this way self (pointer to myObject) is not given automatically. The function will take the 1st parameter "YEAH!" as your self object and fail.
  12.  
  13. myObject.Test(pointertToMyObject, "YEAH!")
  14. --output: This is a test YEAH!
  15. --Same as myObject:Test("YEAH!")



Now to the normal addon table approach
Lua Code:
  1. local myAddon = {} --Just a normal table
  2.  
  3. function myAddon.Test(param1)
  4.  d("This is a test: " ..tostring(param1))
  5. end
  6.  
  7. myAddon:Test("YEAH!")
  8. --> Will fail as :Test is not known and myAddon is not an object, just the pointer to your table.
  9.  
  10. myAddon.Test("YEAH!")
  11. --output: This is a test YEAH!

Last edited by Baertram : 12/16/20 at 10:51 AM.
  Reply With Quote
11/10/20, 06:53 PM   #3
Nant
Join Date: Nov 2020
Posts: 2
Baertram,

TYVM for the info and the explanation. I will look at that template page for direction.

As far as the difference in "." and ":", I was a little confused on that. I have never seen both being used, generally only one or the other based on language syntax.

If you look at https://wiki.esoui.com/Writing_your_first_addon, the "Basic Skeleton Code" section does exactly the flip-flop you mentioned. I haven't coded in Lua in over 10 years (not since I played WoW) and didn't feel comfortable deviating from the tutorial until I had a working framework that I could go back and break. But, I will revisit the lua.org manual for more guidance as it has been some time.

On a side note, what version of LUA is ESO using?
  Reply With Quote
11/11/20, 02:46 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
https://wiki.esoui.com/Esolua
https://wiki.esoui.com/SimpleNotebookTutorial/part5

Last edited by Baertram : 12/16/20 at 10:51 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Help with Hiding Addon except in Main Window

Thread Tools
Display Modes

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