Back to Home

ESO Lua File v100035

pregameandingame/zo_addonmanager/zo_addoneula.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
local g_dialogInfo
local g_addOnEULAFragment
local function AddOnEULADialogInitialize(dialogControl , eulaText, agreeText, disagreeText)
    g_dialogInfo =
    {
        customControl = dialogControl,
        mustChoose = true,
        title =
        {
            text = SI_WINDOW_TITLE_ADDON_EULA,
        },
        mainText =
        {
            text = eulaText,
        },
        buttons =
        {
            [1] =
            {
                control = GetControl(dialogControl, "Agree"),
                text = (#agreeText > 0) and agreeText or SI_EULA_BUTTON_AGREE,
                callback =  function(dialog)
                                AgreeToEULA(EULA_TYPE_ADDON_EULA)
                                SCENE_MANAGER:RemoveFragment(g_addOnEULAFragment)
                            end,
            },
        
            [2] =
            {
                control =   GetControl(dialogControl, "Disagree"),
                text =      (#disagreeText > 0) and disagreeText or SI_EULA_BUTTON_DISAGREE,
                callback =  function(dialog)
                                SCENE_MANAGER:RemoveFragment(g_addOnEULAFragment)
                            end,
            }
        }
    }
    ZO_Dialogs_RegisterCustomDialog("SHOW_ADDON_EULA", g_dialogInfo)
end
local function CheckEnableAgreeButton(agreeButton, scroll, verticalOffset)
    if(not agreeButton.enabledOnce) then
        if(verticalOffset == nil) then
            local _
            _, verticalOffset = scroll:GetScrollOffsets()
        end
        local _, verticalExtent = scroll:GetScrollExtents()
        agreeButton.enabledOnce = (verticalExtent == 0) or zo_floatsAreEqual(verticalOffset, verticalExtent, 0.01)
        agreeButton:SetEnabled(agreeButton.enabledOnce)
    end
end
local function DoInitialUpdate(agreeButton, scroll)
    local automaticEnableTime = GetFrameTimeMilliseconds() + 5000
    local function OnUpdate()
        local _, verticalExtent = scroll:GetScrollExtents()
        if(verticalExtent ~= 0) then
            CheckEnableAgreeButton(agreeButton, scroll)
            scroll:SetHandler("OnUpdate", nil)
        end
        if(GetFrameTimeMilliseconds() > automaticEnableTime) then
            agreeButton:SetEnabled(true)
            scroll:SetHandler("OnUpdate", nil)            
        end
    end
    agreeButton.enabledOnce = false
    agreeButton:SetEnabled(false)
    scroll:SetHandler("OnUpdate", OnUpdate)
end
--[[
Fragment Creation
--]]
local ZO_AddOnEULAFragment
do
    ZO_AddOnEULAFragment = ZO_FadeSceneFragment:Subclass()
    function ZO_AddOnEULAFragment:New(control)
        local fragment = ZO_FadeSceneFragment.New(self, control, 1500)
        fragment.dialog = control
        return fragment
    end
    function ZO_AddOnEULAFragment:Show()
        local dialog = self.dialog
        MarkEULAAsViewed(EULA_TYPE_ADDON_EULA)
        ZO_Dialogs_ShowDialog("SHOW_ADDON_EULA")
        dialog:GetNamedChild("ModalUnderlay"):SetColor(0, 0, 0, .55)
        DoInitialUpdate(GetControl(dialog, "Agree"), GetControl(dialog, "ContainerScroll"))
        -- Call base class for animations after everything has been tweaked
        ZO_FadeSceneFragment.Show(self)
    end
    function ZO_AddOnEULAFragment:OnHidden()
        ZO_Scroll_ScrollAbsolute(GetControl(self.dialog, "Container"), 0)
        
        ZO_FadeSceneFragment.OnHidden(self)
        CALLBACK_MANAGER:FireCallbacks("AddOnEULAHidden")
    end
    local function DisplayAddOnEULAIfNecessary()
        if(not HasAgreedToEULA(EULA_TYPE_ADDON_EULA)) then
            if(not ZO_AddOnEula) then
                CreateControlFromVirtual("ZO_AddOnEula", GuiRoot, "ZO_AddOnEulaTemplate")
            end
            SCENE_MANAGER:AddFragment(g_addOnEULAFragment)
        end
    end
    CALLBACK_MANAGER:RegisterCallback("ShowAddOnEULAIfNecessary", DisplayAddOnEULAIfNecessary)
end
--[[
Global Functions
--]]
    local eulaText, agreeText, disagreeText = GetEULADetails(EULA_TYPE_ADDON_EULA)
    if(not HasAgreedToEULA(EULA_TYPE_ADDON_EULA)) then
        local eulaDialog = self
        AddOnEULADialogInitialize(eulaDialog, eulaText, agreeText, disagreeText)
        eulaDialog:GetNamedChild("Title"):SetDimensions(870, 32)
                
        local function OnDocumentScrollChanged(self, horizontalOffset, verticalOffset)
            CheckEnableAgreeButton(eulaDialog:GetNamedChild("Agree"), self, verticalOffset)
        end
        local scroll = eulaDialog:GetNamedChild("ContainerScroll")
        scroll:SetHandler("OnScrollOffsetChanged", OnDocumentScrollChanged)
        g_addOnEULAFragment = ZO_AddOnEULAFragment:New(eulaDialog)
    else
        AgreeToEULA(EULA_TYPE_ADDON_EULA) -- cleanup
    end
end