ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Ask a simple question, get a simple answer (https://www.esoui.com/forums/showthread.php?t=2069)

unLeashed3k 08/06/14 04:15 PM

Ask a simple question, get a simple answer
 
The purpose of this thread is to ask simple questions about the API and not a How-to tutorial. I have so many questions that often can be resolved with a yes or no, or a link to something that this type of thread may be beneficial to others.

When asking a question preface it with a Q# and answer with an A#.

I have one! ~laughs~

Q1: Is there a way to reverse the fill direction of a <StatusBar> with an attribute from the standard default of left-to-right?

Harven 08/06/14 04:47 PM

Hey unLeashed3k,

A1: no, but you can do that like I did in my All Experience Bars addon. The function is called HarvensExperienceBar:SwitchBarTextureAlignment().

unLeashed3k 08/06/14 05:07 PM

R1: Darn!, was hoping it would be as easy as <StatusBar fill="REVERSE" /> or SetMinMax(-200, 0) then set values going down such as SetValue(-20) for 10% filled on the right side. So with your example, if I got it straight, is to grab the texture coordinates and pull it to the left then reset the anchor of the texture?

Harven 08/06/14 05:22 PM

R1: Hmm... I didn't try SetMinMax(-200, 0) with SetValue(-x) - but I don't think it will work since the arrow texture is pointing in the wrong direction. Yes, I switched horizontal texture coordinates to make a mirror texture and then reanchored it with the other end. But all the problems are gone when you use statusbars like in my Research Timers

Garkin 08/06/14 05:30 PM

Quote:

Originally Posted by unLeashed3k (Post 11220)
R1: Darn!, was hoping it would be as easy as <StatusBar fill="REVERSE" /> or SetMinMax(-200, 0) then set values going down such as SetValue(-20) for 10% filled on the right side. So with your example, if I got it straight, is to grab the texture coordinates and pull it to the left then reset the anchor of the texture?

If you want to do it in XML, try barAlignment="REVERSE":
xml Code:
  1. <StatusBar name="MyBar" inherits="ZO_PlayerAttributeStatusBar" barAlignment="REVERSE" />

unLeashed3k 08/06/14 05:40 PM

R1(Garkin): Works! I was using barAlignment="BAR_ALIGNMENT_REVERSE" because the WikiDocumentation told me so! Last time I listen to the Wiki! =)

Harven 08/07/14 04:11 AM

I was sure it will not work because that's the case with ZO_ArrowStatusBarWithBG. But looks like ZO_PlayerAttributeStatusBar is completly different... sorry for misleading you :)

unLeashed3k 08/08/14 01:01 PM

In the hopes of helping others [new to this API] I will self-answer my own question!

Q2: How do I hide my frame/window when I open my Inventory, Journal, Map, etc but not when I show my cursor?
A2: This tutorial explains all by Garkin.

unLeashed3k 08/08/14 03:06 PM

Q3: Is there a way to get any index (map, zone, subzone) that's reliable to where the character is actively standing in the world or must I set up my own 'key = value' table and check that table against GetPlayerLocationName (which seems to be the only dependable information about where the player is and not what map is being viewed)?

Garkin 08/08/14 04:11 PM

Quote:

Originally Posted by unLeashed3k (Post 11306)
Q3: Is there a way to get any index (map, zone, subzone) that's reliable to where the character is actively standing in the world or must I set up my own 'key = value' table and check that table against GetPlayerLocationName (which seems to be the only dependable information about where the player is and not what map is being viewed)?

A3: There are two functions which doesn't depend on WorldMap:
Lua Code:
  1. local mapName = GetPlayerLocationName()
  2. local zoneName = GetUnitZone("player")
However both function returns just a localized name which is not uinque. You will have to use something different:

- If you use GetPlayerLocationName(), GetMapName() or GetUnitZone(unitTag) there are duplicate names (check map list on Esohead - http://www.esohead.com/map). Also there are issues with localized names.
- GetCurrentMapZoneIndex() - zone and subzone has the same zone index (subzone = city in the zone)
- GetCurrentMapIndex() works only for maps listed in WorldMap
- GetMapTileTexture() returns "Art/maps/stormhaven/wayrest_base_0.dds". As it is file name it must be unique. Bingo.

At first you have to reset map position, to be sure that you're checking correct location:
Lua Code:
  1. SetMapToPlayerLocation()
If map location is changed, you will probably need to redraw map, so better is:
Lua Code:
  1. if(SetMapToPlayerLocation() == SET_MAP_RESULT_MAP_CHANGED) then
  2.     CALLBACK_MANAGER:FireCallbacks("OnWorldMapChanged")
  3. end

And then use:
Lua Code:
  1. local zone, subzone = select(3,(GetMapTileTexture()):lower():find("maps/([%w%-]+)/([%w%-]+_%w+)"))
returns:
zone = "stormhaven"
subzone = "wayrest_base"

or if you want just single location name:
Lua Code:
  1. local zoneName = select(3,(GetMapTileTexture()):lower():find("maps/([%w%-]+/[%w%-]+_%w+)"))
returns:
zone = "stormhaven/wayrest_base"

Or if you are using LibMapPins library, then:
Lua Code:
  1. local LMP = LibStub("LibMapPins-1.0")
  2. local zone, subzone = LMP:GetZoneAndSubzone()
  3. local zoneName = LMP:GetZoneAndSubzone(true)

See topic: http://www.esoui.com/forums/showthread.php?t=1431

unLeashed3k 08/08/14 04:32 PM

R3: That is what I was looking for Garkin and wish I looked at the Wish List forums a little more careful before asking.

Also SetMapToPlayerLocation() is what I was using, and it did work, but I was having some odd after-results (weird zooming on the World Map) whenever I called it.
Lua Code:
  1. if(SetMapToPlayerLocation() == SET_MAP_RESULT_MAP_CHANGED) then
  2.       CALLBACK_MANAGER:FireCallbacks("OnWorldMapChanged")
  3. end

What I needed to make to make my function work. Thanks! I think I should start paying you to mentor me... seems I'm the only one asking the newbie questions. ~laughs~

sirinsidiator 08/09/14 04:50 PM

R3: I am not sure what exactly you plan to do, but you should probably also take a look at my LibGPS. It provides methods to get a global position (x,y) and solves a lot of these map changing issues internally.

unLeashed3k 08/10/14 01:51 PM

Quote:

Originally Posted by sirinsidiator (Post 11328)
R3: I am not sure what exactly you plan to do, but you should probably also take a look at my LibGPS. It provides methods to get a global position (x,y) and solves a lot of these map changing issues internally.

Get coordinates relevant to where the avatar is actively standing is all I wanted. Seems doable but their are no, for lack of a better phrasing, World Coordinates the server can echo back and seems all coordinates are based on client side mappings, and worse they're all based on ascending x, y coordinates. Was hoping the entire continent had a 0, 0 center World Coordinate and south/north and east/west could be determined simply based on -/+.

zgrssd 08/11/14 03:23 PM

I got two too (that might actualy be related):
Code:

ZO_SavedVars:New()
has one parameter described like this on the wiki:
Quote:

profile - Allows you to select a specific profile instead of the current character's default profile. Probably not necessary for most simple add-ons without robust profile management.
Q4: What would be the "default" profile. What exactly will that do? Is it another sublayer similar to namespace (except below the Account name, rather then above it)?
What exactly would be the use, since we can just seperate our saved table however we like in the first place?


The whole issues between 1.2.3 and 1.3.3 pointed me towards something interesting:
The saved variables do allow to share data OS user wide. It is just that the system seems to be hardcoded to use the result of GetDisplayName() and I don't want to overwrite this one (again). I need something more granular.

Q5: Is it possible to manually overwrite wich Zenimax account ZO_SavedVars:New() uses?
Specicially I would like to use the account "" or "[some constant string that is not likely to be mistaken for a real account name".

merlight 08/11/14 03:36 PM

Quote:

Originally Posted by zgrssd (Post 11373)
Q5: Is it possible to manually overwrite wich Zenimax account ZO_SavedVars:New() uses?
Specicially I would like to use the account "" or "[some constant string that is not likely to be mistaken for a real account name".

I tried that long ago, perhaps before 1.2. There was a function you could pass account name to (i.e. fake whatever you wanted, while maintaining their sv[profile][account][character] structure). I wanted to use that to read another account's settings, for example - but the function was bugged (and I reported that) in such a way that it didn't work at all - they forgot to pass that parameter down and it ended up in some kind of "nil argument" error.

After all the trouble with saved variables, I'd advise everyone to simply avoid ZO_SavedVars altogether.

Randactyl 08/11/14 07:29 PM

Quote:

Originally Posted by merlight (Post 11375)
After all the trouble with saved variables, I'd advise everyone to simply avoid ZO_SavedVars altogether.

I've seen this mentioned a couple of times. How does one avoid ZO_SavedVars in the first place?

Garkin 08/11/14 08:19 PM

Quote:

Originally Posted by Randactyl (Post 11386)
I've seen this mentioned a couple of times. How does one avoid ZO_SavedVars in the first place?

You can directly access saved variables table defined in manifest (.txt):

Code:

## SavedVariables: MyAddon_SavedVariables
Lua Code:
  1. local savedVars
  2. local defaults = {
  3.     key1 = "value1",
  4.     key2 = "value2",
  5. }
  6.  
  7. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED,
  8.     function(event, addon)
  9.         if addon ~= "MyAddon" then return end
  10.         EVENT_MANAGER:UnregisterForEvent("MyAddon", event)
  11.  
  12.         MyAddon_SavedVariables = MyAddon_SavedVariables or defaults
  13.         savedVars = MyAddon_SavedVariables
  14.     end)

As an example check Wykkyd's or Seerah's addons.

Garkin 08/11/14 09:46 PM

Saved variables is just a table and you can define how its structure should look like.

Default structure is:
Lua Code:
  1. MyAddon_SavedVariables = {
  2.     profile = {
  3.         displayName = {
  4.             characterName = {
  5.                 namespace = {
  6.                     version = 1,
  7.                 },
  8.             },
  9.         },
  10.     },
  11. }

You can define all key names (except of displayName and characterName):
Lua Code:
  1. local namespaceTable = ZO_SavedVars:New(savedVariableTable, version, namespace, defaults, profile)

And if you don't like this structure, just use MyAddon_SavedVariables as any other table.


A4: What is the use for profiles? You can have for the same account name and character name stored more profiles. I have never used it, but I can imagine that it works this way:

Lua Code:
  1. local sv, profile
  2. local defaults = {}
  3. defaults.profile = {
  4.     name = "pve",
  5. }
  6. defaults.pve = {
  7.     key1 = true,
  8. }
  9. defaults.pvp = {
  10.     key1 = false,
  11. }
  12.  
  13. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED,
  14.     function(event, addon)
  15.         if addon ~= "MyAddon" then return end
  16.         EVENT_MANAGER:UnregisterForEvent("MyAddon", event)
  17.  
  18.         profile = ZO_SavedVars:New(MyAddon_SavedVars, 1, nil, defaults.profile)
  19.         sv = ZO_SavedVars:New(MyAddon_SavedVars, 1, nil, defaults[profile.name], profile.name)
  20.     end)
So just save name of active profile and reload UI.


A5: If you are asking if you can force ZO_SavedVars:New() to use user defined string instead of displayName, it can be done only if you redefine function GetDisplayName() (and GetUnitName(unitTag)), the same way as it does Display Name Fix addon.

zgrssd 08/12/14 06:25 AM

Quote:

Originally Posted by Randactyl (Post 11386)
I've seen this mentioned a couple of times. How does one avoid ZO_SavedVars in the first place?

All the manifest line "SavedVariable" says is:
Define a global variable of that name
Automatically write it to disk on UI unload/read it in from disk on UI load. The loading is finished just before the first OnLoaded Event is fired.

All ZO_SavedVars does is help you with structuring the data by account, character, namespaces, etc. It also provides built in versioning system (perhaps the most usefull part).
You can just as well treat it like any other table with subtables and write it directly. That way you avoid issues (the way ZO_SavedVars get's the account name is hardcoded wich lead to the issues between 1.2.3 and 1.3.3).

I started work on a really small library taht should deal with the main plumbing issues for you, as long as you tell it wich global variable to write too it takes care of the rest. Not yet finished, however.

unLeashed3k 08/12/14 01:35 PM

Q6: Does the provided API have the functionality to detect the [red circle, cylinder, cone] ground effects (the precursor to an upcoming ability) from your combative target(s)?


All times are GMT -6. The time now is 11:55 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI