Thread Tools Display Modes
01/16/17, 11:03 AM   #1
myslex
Join Date: Apr 2014
Posts: 22
Get experience bar type?

Hello again Esoui!

Since I received such good help the last time I asked on these forums, I decided to ask again after getting stuck on writing this Experience Bar Addon.

I am interested in getting the current experience bar type (player experience, mages guild, fighters guild mainly) So that I can hook the "OnShow" event and show the bar values (current, max, gained) for each progress bar.

Is this possible?

I've looked through the lua code and there is a function in playerprogressbar.lua:

Lua Code:
  1. function PlayerProgressBar:GetBarTypeInfo()
  2.     return self.barTypes[self.barType]
  3. end

but I cannot seem to access this function from any control?

Appreciate any help!
MysLEX
  Reply With Quote
01/16/17, 11:10 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
Maybe your approach is not the correct one.
You'd need to find out each experience bar's name and then the control name of this bar, then use controlName:GetBarTypInfo(...) which is imo too much work.


Why don't you use events that give you the current and new XP + the reason why it was updated so you can easily see and get what you need?
http://wiki.esoui.com/Events#Experience

Check out here how events work (in this example it is the event for the combat state)
http://wiki.esoui.com/Writing_your_first_addon

Lua Code:
  1. EVENT_MANAGER:RegisterForEvent(myAddon.Name .. "_Event_Combat_State", EVENT_PLAYER_COMBAT_STATE, myAddon.OnPlayerCombatState)

In the callback function of the experience event that you use you can calculate the values you need and output them.

btw there should be several addons already doing this. Please search for "experience" in the forums or addons and just sniff the code before inventing the wheel new.

Last edited by Baertram : 01/16/17 at 11:14 AM.
  Reply With Quote
01/16/17, 11:24 AM   #3
myslex
Join Date: Apr 2014
Posts: 22
Originally Posted by Baertram View Post
Maybe your approach is not the correct one.
You'd need to find out each experience bar's name and then the control name of this bar, then use controlName:GetBarTypInfo(...) which is imo too much work.


Why don't you use events that give you the current and new XP + the reason why it was updated so you can easily see and get what you need?
http://wiki.esoui.com/Events#Experience
Thank you for your input Baertram!

That I noticed..

The problem Is that I'm already always showing the PlayerProgressBar, so any time I gain Mages Guild experience, or Fighters Guild experience the appropriate bar fades in, show the current progress and then fall back to showing the player experience bar.

The PlayerProgressBar has a shared total experience and experience gain label anchored to the bar and the gain label has a fade in/fade out effect that goes out of sync with the PlayerProgressBar fading in and out when I receive experience from different sources.

I have already registered to the different experience events, but I'm having trouble syncing my own fade effect with the default bar fade effect.
This Is roughly what I want:

Lua Code:
  1. local function OnProgressBarShow(control)
  2.   -- find out what type of bar this is and display the values
  3. end
  4.  
  5. local function OnProgressBarHide(control)
  6.   -- hide the labels
  7. end
  8.  
  9. ZO_PreHookHandler(PLAYER_PROGRESS_BAR.control, 'OnShow', OnProgressBarShow);
  10. ZO_PreHookHandler(PLAYER_PROGRESS_BAR.control, 'OnHide', OnProgressBarHide);

If you're interested you can see the source code here:
https://github.com/jwldnr/wProgressB...rogressBar.lua

Edit:
I understand that there are similar addons out there, doing roughly the same thing, but none of them handle "skill/guild experience" in a good way. The closest I can get is Harvens All Experience Bars but im having trouble adapting the code to suit my needs.

Another way to approach my problem would be to have individual experience labels for different skill lines, I already have a way of building the skill line index. (see code below)
The problem still remains: I don't know for how long the bar will be shown, so that I can switch back to player experience label once Mages Guild Progress is hidden again.

Lua Code:
  1. function Addon:UpdateSkillLines()
  2.   self.skills = {};
  3.  
  4.   for skillType = 1, GetNumSkillTypes() do
  5.     for skillIndex = 1, GetNumSkillLines(skillType) do
  6.       local lastRankXP, nextRankXP, currentXP = GetSkillLineXPInfo(skillType, skillIndex);
  7.       local current = GetPlayerSkillXP(currentXP, lastRankXP);
  8.  
  9.       local index = skillType .. skillIndex;
  10.  
  11.       self.skills[index] = {
  12.         gain = 0,
  13.         currentXP = current
  14.       };
  15.     end
  16.   end
  17. end

Last edited by myslex : 01/16/17 at 11:36 AM.
  Reply With Quote
01/16/17, 01:25 PM   #4
myslex
Join Date: Apr 2014
Posts: 22
I do realize I have a way of overthinking things. Anyone has any ideas on another angle to tackle the "problem"?

MysSL
  Reply With Quote
01/22/17, 02:23 AM   #5
myslex
Join Date: Apr 2014
Posts: 22
Turns out I was overthinking it.

I could just hook the player progress bare fade timeline like so:

Lua Code:
  1. function UpdateProgressLabel()
  2.   local barTypeInfo = PLAYER_PROGRESS_BAR:GetBarTypeInfo()
  3.  
  4.   local level = barTypeInfo:GetLevel()
  5.   local max = barTypeInfo:GetLevelSize(level) -- get max bar value
  6.   local current = barTypeInfo:GetCurrent() -- get current bar value
  7.  
  8.   -- set progress bar values
  9. end
  10.  
  11. local function OnPlayProgressBarFade(timeline)
  12.   if (timeline:IsPlayingBackward()) then return end
  13.  
  14.   UpdateProgressLabel()
  15. end
  16.  
  17. ZO_PreHookHandler(PLAYER_PROGRESS_BAR.fadeTimeline, "OnPlay", OnPlayProgressBarFade)

And then register the usual events EVENT_EXPERIENCE_UPDATE, EVENT_CHAMPION_POINT_UPDATE, EVENT_SKILL_XP_UPDATE and call UpdateProgressLabel() from there.

Adding this for future reference.

MsLX
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Get experience bar type?

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