Thread Tools Display Modes
03/23/15, 07:08 AM   #1
coolmodi
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 47
Added control in stat screen doesn't hide correctly

I made a addon to show me the mitigation from resistances, and someone wanted the same feature "MitigationValue" had to show it in the char screen too.

I basically used the same code that addon did for adding it to the stat screen:
Code:
function MitigationPercent:displayInCharScreen()
	
		ZO_StatsPanelPaneScrollChildStatsRow6:SetHeight(40)
		ZO_StatsPanelPaneScrollChildStatsRow6Stat1:SetAnchor(TOPLEFT, ZO_StatsPanelPaneScrollChildStatsRow6, TOPLEFT)
		ZO_StatsPanelPaneScrollChildStatsRow6Stat2:SetAnchor(TOPRIGHT, ZO_StatsPanelPaneScrollChildStatsRow6, TOPRIGHT)
		
		MitigationPercentSpell:SetParent(ZO_StatsPanel)
		local width = ZO_StatsPanelPaneScrollChildStatsRow6Stat1:GetWidth()
		width = width - ZO_StatsPanelPaneScrollChildStatsRow6Stat1DiminishingReturns:GetWidth()
		MitigationPercentSpell:SetWidth(width)
		MitigationPercentSpell:ClearAnchors()	
		MitigationPercentSpell:SetAnchor(TOPLEFT, ZO_StatsPanelPaneScrollChildStatsRow6Stat1, BOTTOMLEFT)
		MitigationPercentSpell:SetHidden(false)
		
		MitigationPercentPhys:SetParent(ZO_StatsPanel)
		width = ZO_StatsPanelPaneScrollChildStatsRow6Stat2:GetWidth()
		width = width - ZO_StatsPanelPaneScrollChildStatsRow6Stat2DiminishingReturns:GetWidth()
		MitigationPercentPhys:SetWidth(width)
		MitigationPercentPhys:ClearAnchors()	
		MitigationPercentPhys:SetAnchor(TOPLEFT, ZO_StatsPanelPaneScrollChildStatsRow6Stat2, BOTTOMLEFT)
		MitigationPercentPhys:SetHidden(false)
		
		MitigationPercent.OnStatsUpdated()
end
which is executed by
Code:
ZO_PreHook(ZO_Stats, "InitializeKeybindButtons", function() self:displayInCharScreen() end)
But while it mostly works as it should, it will not hide correctly the first time you close the stat screen and will only show and hide correctly after i open the map, use a buff, scroll in stat screen etc.

I have no clue why this is the case. I'm no programmer or anything (only do small things like this here), but i just can't see why it only works after one of those things happens. MitigationValue seems to have the same problem (now), so i think the game itself is at fault here, but i can't find a workaround that is possible to setup with the api tools i know of.

I hope someone here can help me

Edit:
Things i thought of but miss knowledge to do:
-Open and close the map (or any other thing that has the same effect, are there such functions?)
-showing and hiding my controls whenever the statscreen opens/closes (i can do hiding on close wit hthe popped event, but how can i check when it opens again?)

Last edited by coolmodi : 03/23/15 at 07:20 AM.
  Reply With Quote
03/23/15, 08:28 AM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
It would be much easier if you do not add new line, but just modify text already in there.
For example line:
Spell Resistance: 10000
becomes:
Spell Resistance: 10000 (15.63%)


Simple code how to do that:
Lua Code:
  1. local function GetDisplayValue(self)
  2.     local value = self:GetValue()
  3.     local percentage = value / ((GetUnitLevel("player") + GetUnitVeteranRank("player"))  * 10)
  4.  
  5.     return ("%d (%04.02f%%)"):format(value, percentage)
  6. end
  7.  
  8. local SetUpStat_Orig = ZO_Stats.SetUpStat
  9. local function SetUpStat(self, statEntry, statType)
  10.     SetUpStat_Orig(self, statEntry, statType)
  11.     if statType == STAT_SPELL_RESIST or statType == STAT_PHYSICAL_RESIST then
  12.         self.statEntries[statType].GetDisplayValue = GetDisplayValue
  13.     end
  14. end
  15. ZO_Stats.SetUpStat = SetUpStat
  Reply With Quote
03/23/15, 09:33 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Small hack how to add mitigation values:

Lua Code:
  1. local function GetDisplayValue(self)
  2.     local value = self:GetValue() / ((GetUnitLevel("player") + GetUnitVeteranRank("player")) * 10)
  3.     return zo_strformat(SI_STAT_VALUE_PERCENT, value)
  4. end
  5.  
  6. local CreateAttributesSection_Orig = ZO_Stats.CreateAttributesSection
  7. local function CreateAttributesSection(self)
  8.     CreateAttributesSection_Orig(self)
  9.     self:SetNextControlPadding(0)
  10.     self:AddStatRow(STAT_SPELL_MITIGATION, STAT_MITIGATION)
  11.     self.statEntries[STAT_SPELL_MITIGATION].name:SetText("Spell Resistance Value")
  12.     self.statEntries[STAT_SPELL_MITIGATION].value.statType = STAT_SPELL_RESIST
  13.     self.statEntries[STAT_SPELL_MITIGATION].GetDisplayValue = GetDisplayValue
  14.     self.statEntries[STAT_MITIGATION].name:SetText("Physical Resistance Value")
  15.     self.statEntries[STAT_MITIGATION].value.statType = STAT_PHYSICAL_RESIST
  16.     self.statEntries[STAT_MITIGATION].GetDisplayValue = GetDisplayValue
  17. end
  18. ZO_Stats.CreateAttributesSection = CreateAttributesSection

Result:

  Reply With Quote
03/23/15, 11:05 AM   #4
coolmodi
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 47
WOW thanks very much!
This really helps alot.

If i have time later i'll look into it and try to understand it
  Reply With Quote
03/23/15, 01:33 PM   #5
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Regarding your non-hiding issue, that's because you defined your controls as <TopLevelControl>. Those are not supposed to have a parent, and thus hide with it. Change that to <Control>.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Added control in stat screen doesn't hide correctly


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