Back to Home

ESO Lua File v101044

ingame/compass/compassframe.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
ZO_COMPASS_FRAME_HEIGHT_KEYBOARD = 39
ZO_COMPASS_FRAME_HEIGHT_GAMEPAD = 24
ZO_COMPASS_FRAME_HEIGHT_BOSSBAR_GAMEPAD = 23
local CompassFrame = ZO_Object:Subclass()
function CompassFrame:New(...)
    local compassFrame = ZO_Object.New(self)
    compassFrame:Initialize(...)
    return compassFrame
end
function CompassFrame:Initialize(control)
    self.control = control
    self.compassHidden = false
    self.bossBarHiddenReasons = ZO_HiddenReasons:New()
    self.compassReady = false
    self.bossBarReady = false  
    COMPASS_FRAME_FRAGMENT = ZO_HUDFadeSceneFragment:New(control)
    control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, function() self:OnPlayerActivated() end)
    control:RegisterForEvent(EVENT_SCREEN_RESIZED, function() self:UpdateWidth() end)
    self:ApplyStyle() -- Setup initial visual style based on current mode.
    self.control:RegisterForEvent(EVENT_GAMEPAD_PREFERRED_MODE_CHANGED, function() self:OnGamepadPreferredModeChanged() end)
end
function CompassFrame:ApplyStyle()
    local gamepadMode = IsInGamepadPreferredMode()
    local center = self.control:GetNamedChild("Center")
    center:GetNamedChild("TopMungeOverlay"):SetHidden(gamepadMode)
    center:GetNamedChild("BottomMungeOverlay"):SetHidden(gamepadMode)
    if gamepadMode then
        if self.bossBarReady and self.bossBarActive then
            local frame = self.control
            frame:SetHeight(ZO_COMPASS_FRAME_HEIGHT_BOSSBAR_GAMEPAD)
            frame:GetNamedChild("Left"):SetHeight(ZO_COMPASS_FRAME_HEIGHT_BOSSBAR_GAMEPAD)
            frame:GetNamedChild("Right"):SetHeight(ZO_COMPASS_FRAME_HEIGHT_BOSSBAR_GAMEPAD)
        end
    end
end
function CompassFrame:OnGamepadPreferredModeChanged()
    self:ApplyStyle()
end
local MIN_WIDTH = 400
local MAX_WIDTH = 800
function CompassFrame:UpdateWidth()
    local screenWidth = GuiRoot:GetWidth()
    self.control:SetWidth(zo_clamp(screenWidth * .35, MIN_WIDTH, MAX_WIDTH))
end
function CompassFrame:RefreshVisible()
    if(self.compassReady and self.bossBarReady) then
        local bossBarIsHidden = self.bossBarHiddenReasons:IsHidden() or not self.bossBarActive
        local compassIsHidden = self.compassHidden or not bossBarIsHidden
        
        local frameWasHidden = self.control:IsHidden()
        local frameIsHidden = bossBarIsHidden and compassIsHidden
        local frameChanged = frameWasHidden ~= frameIsHidden
        --if the frame is showing or hiding, or the frame isn't even shown, do the transition
        --between the boss bar and compass instantly
        if(frameChanged or frameIsHidden) then
            if(self.crossFadeTimeline) then
                self.crossFadeTimeline:Stop()
            end
            COMPASS_FRAME_FRAGMENT:SetHiddenForReason("contentsHidden", frameIsHidden)
            ZO_BossBar:SetAlpha(1)
            ZO_Compass:SetAlpha(1)
            ZO_BossBar:SetHidden(bossBarIsHidden)
            ZO_Compass:SetHidden(compassIsHidden)
        else
            --otherwise animate it if it changed
            local bossBarWasHidden = ZO_BossBar:IsHidden()
            local compassWasHidden = ZO_Compass:IsHidden()
            if(bossBarWasHidden ~= bossBarIsHidden or compassIsHidden ~= compassWasHidden) then
                if(not self.crossFadeTimeline) then
                    self.crossFadeTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("ZO_CompassFrameCrossFade")
                    self.crossFadeTimeline:GetAnimation(1):SetAnimatedControl(ZO_BossBar)
                    self.crossFadeTimeline:GetAnimation(2):SetAnimatedControl(ZO_Compass)
                end
                if(bossBarIsHidden) then
                    if(self.crossFadeTimeline:IsPlaying()) then
                        self.crossFadeTimeline:PlayForward()
                    else
                        self.crossFadeTimeline:PlayFromStart()
                    end
                else
                    if(self.crossFadeTimeline:IsPlaying()) then
                        self.crossFadeTimeline:PlayBackward()
                    else
                        self.crossFadeTimeline:PlayFromEnd()
                    end
                end
            end
        end        
    end
end
function CompassFrame:SetBossBarHiddenForReason(reason, hidden)
    if(self.bossBarHiddenReasons:SetHiddenForReason(reason, hidden)) then
        self:RefreshVisible()
    end
end
function CompassFrame:SetBossBarActive(active)
    self.bossBarActive = active
    self:ApplyStyle()
    self:RefreshVisible()
end
function CompassFrame:GetBossBarActive()
    return self.bossBarActive
end
function CompassFrame:SetCompassHidden(hidden)
    self.compassHidden = hidden
    self:RefreshVisible()
end
function CompassFrame:SetBossBarReady(ready)
    self.bossBarReady = ready
    ZO_BossBar:SetParent(self.control)
    self:RefreshVisible()
end
function CompassFrame:SetCompassReady(ready)
    self.compassReady = ready
    ZO_Compass:SetParent(self.control)
    self:RefreshVisible()
end
--Events
function CompassFrame:OnPlayerActivated()
    self:UpdateWidth()
    self:RefreshVisible()
end
--Global XML
    COMPASS_FRAME = CompassFrame:New(self)
end