Back to Home

ESO Lua File v101041

ingame/timedactivities/keyboard/timedactivities_keyboard.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
ZO_TimedActivities_Keyboard = ZO_TimedActivities_Shared:Subclass()
local COMPLETE_ACTIVITY_ALPHA = 0.4
local INCOMPLETE_ACTIVITY_ALPHA = 1
function ZO_TimedActivities_Keyboard:RefreshCurrentActivityInfo()
    local timeRemainingString = self:GetCurrentActivityTypeTimeRemainingString()
    if timeRemainingString ~= "" then
        self.expirationHeader:SetText(zo_strformat(SI_TIMED_ACTIVITIES_ACTIVITY_EXPIRATION_HEADER, ZO_SELECTED_TEXT:Colorize(timeRemainingString)))
    else
        self.expirationHeader:SetText("")
    end
    local currentActivityType = self:GetCurrentActivityType()
    local numActivitiesCompleted, activityLimit = TIMED_ACTIVITIES_MANAGER:GetTimedActivityTypeLimitInfo(currentActivityType)
    self.limitHeader:SetText(zo_strformat(SI_TIMED_ACTIVITIES_ACTIVITY_LIMIT_HEADER, numActivitiesCompleted, activityLimit))
end
function ZO_TimedActivities_Keyboard:AddActivityRow(activityData)
    local activityRow = self.activityRowPool:AcquireObject()
    local anchorTo = self.nextActivityAnchorTo
    if anchorTo then
        activityRow:SetAnchor(TOPLEFT, anchorTo, BOTTOMLEFT)
        activityRow:SetAnchor(TOPRIGHT, anchorTo, BOTTOMRIGHT)
    else
        activityRow:SetAnchor(TOPLEFT, self.activitiesScrollChild)
        activityRow:SetAnchor(TOPRIGHT, self.activitiesScrollChild)
    end
    self.nextActivityAnchorTo = activityRow
    activityRow.nameLabel:SetText(activityData:GetName())
    activityRow.activityDescription = activityData:GetDescription()
    local maxProgress = activityData:GetMaxProgress()
    local progress = activityData:GetProgress()
    if maxProgress < 1 or progress >= maxProgress then
        progressPercent = 1
    else
        progressPercent = progress / maxProgress
    end
    activityRow.progressStatusBar:SetValue(progressPercent)
    if progressPercent < 1 then
        local progressString = zo_strformat(SI_TIMED_ACTIVITIES_ACTIVITY_COMPLETION_VALUES, progress, maxProgress)
        activityRow.progressStatusBarLabel:SetText(progressString)
        activityRow.progressStatusBarLabel:SetHidden(false)
        activityRow.completeIcon:SetHidden(true)
    else
        activityRow.progressStatusBarLabel:SetHidden(true)
        activityRow.completeIcon:SetHidden(false)
    end
    local completed = self.isAtActivityLimit or activityData:IsCompleted()
    activityRow:SetAlpha(completed and COMPLETE_ACTIVITY_ALPHA or INCOMPLETE_ACTIVITY_ALPHA)
    local CURRENCY_FORMAT_OPTIONS =
    {
        showCap = false,
        useShortFormat = true,
    }
    local nextRewardAnchorTo = nil
    local rewardList = activityData:GetRewardList()
    for rewardIndex, rewardData in ZO_NumericallyIndexedTableReverseIterator(rewardList) do
        local activityReward = self.activityRewardPool:AcquireObject()
        activityReward:SetParent(activityRow.rewardContainer)
        if nextRewardAnchorTo then
            activityReward:SetAnchor(BOTTOMRIGHT, nextRewardAnchorTo, BOTTOMLEFT)
        else
            activityReward:SetAnchor(BOTTOMRIGHT)
        end
        nextRewardAnchorTo = activityReward
        activityReward.amountLabel:SetText(rewardData:GetAbbreviatedQuantity())
        activityReward.iconTexture:SetTexture(rewardData:GetKeyboardIcon())
        activityReward.rewardData = rewardData
    end
end
-----
-- ZO_TimedActivities_Shared
-----
function ZO_TimedActivities_Keyboard:InitializeControls()
    self.emptyMessage = self.control:GetNamedChild("EmptyMessage")
    self.listControl = self.control:GetNamedChild("List")
    self.activitiesScroll = self.listControl:GetNamedChild("Activities")
    self.activitiesScrollChild = self.activitiesScroll:GetNamedChild("ScrollChild")
    self.expirationHeader = self.listControl:GetNamedChild("ExpirationHeader")
    self.limitHeader = self.listControl:GetNamedChild("LimitHeader")
    self.activityRowPool = ZO_ControlPool:New("ZO_TimedActivityRow_Keyboard", self.activitiesScrollChild, "ActivityRow")
    self.activityRewardPool = ZO_ControlPool:New("ZO_TimedActivityReward_Keyboard", self.activitiesScrollChild, "ActivityReward")
end
function ZO_TimedActivities_Keyboard:InitializeActivityFinderCategory()
    TIMED_ACTIVITIES_FRAGMENT = self.sceneFragment
    local function OnDailyCategorySelected()
        self:SetCurrentActivityType(TIMED_ACTIVITY_TYPE_DAILY)
    end
    local function OnWeeklyCategorySelected()
        self:SetCurrentActivityType(TIMED_ACTIVITY_TYPE_WEEKLY)
    end
    local CATEGORY_PRIORITY = ZO_ACTIVITY_FINDER_SORT_PRIORITY.TIMED_ACTIVITIES
    local timedActivitiesCategoryData = 
    {
        priority = CATEGORY_PRIORITY,
        name = GetString(SI_ACTIVITY_FINDER_CATEGORY_TIMED_ACTIVITIES),
        normalIcon = "EsoUI/Art/LFG/LFG_indexIcon_timedActivities_up.dds",
        pressedIcon = "EsoUI/Art/LFG/LFG_indexIcon_timedActivities_down.dds",
        mouseoverIcon = "EsoUI/Art/LFG/LFG_indexIcon_timedActivities_over.dds",
        children =
        {
            {
                priority = CATEGORY_PRIORITY + 10,
                name = GetString("SI_TIMEDACTIVITYTYPE", TIMED_ACTIVITY_TYPE_DAILY),
                categoryFragment = self.sceneFragment,
                onTreeEntrySelected = OnDailyCategorySelected,
            },
            {
                priority = CATEGORY_PRIORITY + 20,
                name = GetString("SI_TIMEDACTIVITYTYPE", TIMED_ACTIVITY_TYPE_WEEKLY),
                categoryFragment = self.sceneFragment,
                onTreeEntrySelected = OnWeeklyCategorySelected,
            },
        },
    }
    GROUP_MENU_KEYBOARD:AddCategory(timedActivitiesCategoryData)
end
function ZO_TimedActivities_Keyboard:Refresh()
    ZO_ClearNumericallyIndexedTable(self.activitiesData)
    local currentActivityType = self:GetCurrentActivityType()
    local activityTypeFilters
    if currentActivityType == TIMED_ACTIVITY_TYPE_DAILY then
        activityTypeFilters = { ZO_TimedActivityData.IsDailyActivity }
    elseif currentActivityType == TIMED_ACTIVITY_TYPE_WEEKLY then
        activityTypeFilters = { ZO_TimedActivityData.IsWeeklyActivity }
    end
    for index, activityData in TIMED_ACTIVITIES_MANAGER:ActivitiesIterator(activityTypeFilters) do
        table.insert(self.activitiesData, activityData)
    end
    self.activityRewardPool:ReleaseAllObjects()
    self.activityRowPool:ReleaseAllObjects()
    self.nextActivityAnchorTo = nil
    self.isAtActivityLimit = TIMED_ACTIVITIES_MANAGER:IsAtTimedActivityTypeLimit(currentActivityType)
    for index, activityData in ipairs(self.activitiesData) do
        self:AddActivityRow(activityData)
    end
end
function ZO_TimedActivities_Keyboard:RefreshAvailability()
    local activityType = self:GetCurrentActivityType()
    local isAvailable = self:IsActivityTypeAvailable(activityType)
    if not isAvailable then
        local activityTypeName = GetString("SI_TIMEDACTIVITYTYPE", activityType)
        self.emptyMessage:SetText(zo_strformat(SI_TIMED_ACTIVITIES_EMPTY_LIST, activityTypeName))
    end
    self.emptyMessage:SetHidden(isAvailable)
    self.listControl:SetHidden(not isAvailable)
end
function ZO_TimedActivities_Keyboard:OnHidden()
    EVENT_MANAGER:UnregisterForUpdate("ZO_TimedActivities_Keyboard.RefreshCurrentActivityInfo")
end
function ZO_TimedActivities_Keyboard:OnShown()
    EVENT_MANAGER:RegisterForUpdate("ZO_TimedActivities_Keyboard.RefreshCurrentActivityInfo", 1000, function()
        self:RefreshCurrentActivityInfo()
    end)
    TriggerTutorial(TUTORIAL_TRIGGER_ENDEAVORS_OPENED)
end
-----
-- Global XML
-----
    TIMED_ACTIVITIES_KEYBOARD = ZO_TimedActivities_Keyboard:New(control)
end
    control.nameLabel = control:GetNamedChild("Name")
    control.rewardContainer = control:GetNamedChild("RewardContainer")
    control.progressStatusBar = control:GetNamedChild("ProgressBar")
    ZO_StatusBar_InitializeDefaultColors( control.progressStatusBar )
    control.progressStatusBarLabel = control.progressStatusBar:GetNamedChild("Progress")
    control.completeIcon = control:GetNamedChild("CompleteIcon")
end