-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGroupCalendar_Tradeskill.lua
More file actions
executable file
·109 lines (85 loc) · 3.87 KB
/
GroupCalendar_Tradeskill.lua
File metadata and controls
executable file
·109 lines (85 loc) · 3.87 KB
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
----------------------------------------
-- Group Calendar 5 Copyright (c) 2018 John Stephen
-- This software is licensed under the MIT license.
-- See the included LICENSE.txt file for more information.
----------------------------------------
local _
function GroupCalendar:InitializeTradeskill()
self.Tradeskill = GroupCalendar:New(GroupCalendar._Tradeskill)
end
----------------------------------------
GroupCalendar._Tradeskill = {}
----------------------------------------
function GroupCalendar._Tradeskill:Construct()
GroupCalendar.EventLib:RegisterEvent("TRADE_SKILL_SHOW", self.TradeSkillShow, self)
GroupCalendar.EventLib:RegisterEvent("TRADE_SKILL_CLOSE", self.TradeSkillClose, self)
end
function GroupCalendar._Tradeskill:TradeSkillShow()
self.TradeSkillOpen = true
self:UpdateCurrentTradeskillCooldown()
end
function GroupCalendar._Tradeskill:TradeSkillClose()
self:UpdateCurrentTradeskillCooldown()
self.TradeSkillOpen = false
if self.NewEvent then
if self.NewEvent:IsOpened() then
self.NewEvent:Save()
end
self.NewEvent = nil
end
end
function GroupCalendar._Tradeskill:UpdateCurrentTradeskillCooldown()
if GroupCalendar.Data.Prefs.DisableTradeskills then
return
end
local vServerDate, vServerTime = GroupCalendar.DateLib:GetServerDateTime()
local vRecipeIDs = C_TradeSkillUI.GetAllRecipeIDs()
for _, vRecipeID in ipairs(vRecipeIDs) do
local vRecipeInfo = C_TradeSkillUI.GetRecipeInfo(vRecipeID)
local vCooldown = C_TradeSkillUI.GetRecipeCooldown(vRecipeID)
if vCooldown and vCooldown > 0 then
local vCooldownID = "RECIPE_"..vRecipeID
local vCooldownDate, vCooldownTime = GroupCalendar.DateLib:AddOffsetToDateTime(vServerDate, vServerTime, vCooldown / 60)
local vMonth, vDay, vYear = GroupCalendar.DateLib:ConvertDateToMDY(vCooldownDate)
local vHour, vMinute = GroupCalendar.DateLib:ConvertTimeToHM(vCooldownTime)
-- Add an event for the new cooldown if there isn't already one
if not self:HasCooldownIDEvent(vCooldownID, vMonth, vDay, vYear) then
self.NewEvent = GroupCalendar.Calendars.PLAYER:NewEvent(vMonth, vDay, vYear, "PLAYER")
self.NewEvent:Open()
self.NewEvent:SetTitle(vRecipeInfo.name)
self.NewEvent:SetTitleTag(vCooldownID)
self.NewEvent:SetType(CALENDAR_EVENTTYPE_OTHER, 1)
self.NewEvent:SetTime(vHour, vMinute)
self.NewEvent:SetDuration(nil)
self.NewEvent:Save()
end -- if not HasCooldownIDEvent
-- Delete any older occurances of this cooldown
for vDate = vCooldownDate - 30, vCooldownDate - 1 do
local vMonth, vDay, vYear = GroupCalendar.DateLib:ConvertDateToMDY(vDate)
local vMonthOffset = GroupCalendar.WoWCalendar:GetMonthOffset(vMonth, vYear)
local vNumEvents = GroupCalendar.WoWCalendar:GetNumDayEvents(vMonthOffset, vDay)
for vEventIndex = 1, vNumEvents do
local vTitle, vHour, vMinute,
vCalendarType, vSequenceType, vEventType,
vTextureID,
vModStatus, vInviteStatus, vInvitedBy = GroupCalendar.WoWCalendar:GetDayEvent(vMonthOffset, vDay, vEventIndex)
local vTitleTag = GroupCalendar.WoWCalendar:EventGetTitleTag()
if vTitleTag == vCooldownID then
GroupCalendar.WoWCalendar:ContextMenuEventRemove(vMonthOffset, vDay, vEventIndex)
break
end
end -- for vEventIndex
end -- for vDate
end -- if vCooldown
end -- for vSkillIndex
end
function GroupCalendar._Tradeskill:HasCooldownIDEvent(pCooldownID, pMonth, pDay, pYear)
local vNumEvents = GroupCalendar.WoWCalendar:GetNumAbsDayEvents(pMonth, pDay, pYear)
for vEventIndex = 1, vNumEvents do
local vTitle, vHour, vMinute = GroupCalendar.WoWCalendar:GetAbsDayEvent(pMonth, pDay, pYear, vEventIndex)
local vTitleTag = GroupCalendar.WoWCalendar:EventGetTitleTag()
if vTitleTag == pCooldownID then
return true, vEventIndex
end
end
end