ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Added control in stat screen doesn't hide correctly (https://www.esoui.com/forums/showthread.php?t=4477)

coolmodi 03/23/15 07:08 AM

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?)

Garkin 03/23/15 08:28 AM

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

Garkin 03/23/15 09:33 AM

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:


coolmodi 03/23/15 11:05 AM

WOW thanks very much!
This really helps alot.

If i have time later i'll look into it and try to understand it :D

merlight 03/23/15 01:33 PM

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>.


All times are GMT -6. The time now is 12:51 AM.

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