--[[ |
POSSIBLE EVENTS: |
Mounted |
In town |
Spec (for dual spec) |
Stance/form |
Mana Regen(?) |
PvP --PLAYER_FLAGS_CHANGED, then check for arg1 == "player", then UnitIsPVP("player") |
... |
|
don't forget to get locals of the global Blizz stuff for performance tweaking |
]] |
|
local EventEquip = CreateFrame("Frame") |
local gmd = GearManagerDialog |
local GameTooltip = GameTooltip |
local tkDrop = LibStub("tekKonfig-Dropdown") |
local eventSelected, setSelected, previousGear |
local sets = {"None"} |
local events = {"Primary Talent Spec", |
"Secondary Talent Spec", |
"In Town", |
-- "Mounted", |
-- "PvP", |
} |
local defaults = { previousGear = {}, |
["Primary Talent Spec"] = "None", |
["Secondary Talent Spec"] = "None", |
["In Town"] = "None", |
["Mounted"] = "None", |
["PvP"] = "None", |
} |
|
local function CollectPrevious() |
for i=1,19 do |
EventEquipDB.previousGear[i] = GetInventoryItemLink("player", i) |
end |
end |
|
local function EquipPrevious() |
for i=1,19 do |
EquipItemByName(EventEquipDB.previousGear[i]) |
end |
end |
|
--[[EventEquip["Mounted"] = function() |
end |
|
EventEquip["PvP"] = function() |
end]]-- |
|
function EventEquip.PLAYER_UPDATE_RESTING() |
local set = EventEquipDB["In Town"] |
if IsResting() then |
CollectPrevious() |
EquipmentManager_EquipSet(set) |
else |
EquipPrevious() |
end |
end |
|
EventEquip["In Town"] = function() |
local set = EventEquipDB["In Town"] |
if set == "None" then |
EventEquip:UnregisterEvent("PLAYER_UPDATE_RESTING") |
return |
else --if not EventEquip:IsEventRegistered("PLAYER_UPDATE_RESTING") then |
EventEquip:RegisterEvent("PLAYER_UPDATE_RESTING") |
end |
end |
|
function EventEquip.UNIT_SPELLCAST_SUCCEEDED(unit, spell) |
if unit == "player" then |
if spell == "Activate Primary Spec" then |
EquipmentManager_EquipSet(EventEquipDB["Primary Talent Spec"]) |
elseif spell == "Activate Secondary Spec" then |
EquipmentManager_EquipSet(EventEquipDB["Secondary Talent Spec"]) |
end |
end |
end |
|
EventEquip["Primary Talent Spec"] = function() |
local set = EventEquipDB["Primary Talent Spec"] |
if set == "None" and EventEquipDB["Secondary Talent Spec"] == "None" then |
EventEquip:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED") |
return |
else |
EventEquip:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") |
end |
end |
|
EventEquip["Secondary Talent Spec"] = function() |
local set = EventEquipDB["Secondary Talent Spec"] |
if set == "None" and EventEquipDB["Primary Talent Spec"] == "None" then |
EventEquip:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED") |
return |
else |
EventEquip:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") |
end |
end |
|
local function CollectSets() |
sets = {"None"} |
local num = GetNumEquipmentSets() |
for i=1,num do |
sets[i+1] = GetEquipmentSetInfo(i) |
end |
return sets |
end |
|
local function OnEnter(self, text) |
GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT") |
GameTooltip:SetText(text) |
GameTooltip:Show() |
end |
|
local function OnLeave() |
GameTooltip:Hide() |
end |
|
local function SetUpOptions() |
local eeOpts = CreateFrame("Frame", "EEOptions", gmd) |
eeOpts:SetPoint("TOPLEFT", gmd, "BOTTOMLEFT", 3, 4) |
eeOpts:SetWidth(260) |
eeOpts:SetHeight(276) |
local eebg = eeOpts:CreateTexture("eebg") |
eebg:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-StatBackground") |
eebg:SetAllPoints(eeOpts) |
eebg:SetTexCoord(0,.92,0.01,.61) |
local header = eeOpts:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") |
header:SetParent(eeOpts) |
header:SetPoint("TOP", eeOpts, "TOP", 0,-15) |
header:SetText("EventEquip") |
local subheader = eeOpts:CreateFontString(nil, "ARTWORK", "GameFontHighlight") |
subheader:SetParent(eeOpts) |
subheader:SetPoint("TOPLEFT", eeOpts, "TOPLEFT", 15,-35) |
subheader:SetPoint("RIGHT", eeOpts, "RIGHT", -20,0) |
subheader:SetHeight(30) |
subheader:SetNonSpaceWrap(true) |
subheader:SetJustifyH("LEFT") |
subheader:SetText("Select an event and then a set to equip during that event.") |
local setsDrop, setsText = tkDrop.new(eeOpts, "Sets") |
setsDrop:SetPoint("CENTER", eeOpts, "CENTER", 0, -45) |
setsDrop:SetWidth(200) |
local function OnClick(self) |
UIDropDownMenu_SetSelectedValue(setsDrop, self.value) |
setSelected = sets[self.value] |
setsText:SetText(setSelected) |
end |
UIDropDownMenu_Initialize(setsDrop, function() |
local current, info = UIDropDownMenu_GetSelectedValue(setsDrop), UIDropDownMenu_CreateInfo() |
for k,v in pairs(CollectSets()) do |
info.text, info.value, info.func, info.checked = v, k, OnClick, v == current |
UIDropDownMenu_AddButton(info) |
end |
end) |
setsDrop:SetScript("OnEnter", function(self) OnEnter(self, "This is the set currently assigned to the above event.") end) |
setsDrop:SetScript("OnLeave", OnLeave) |
local setsLabel = setsDrop:CreateFontString(nil, "ARTWORK", "GameFontNormal") |
setsLabel:SetText("Sets") |
setsLabel:SetPoint("BOTTOM", setsDrop, "TOP", 0, 5) |
local eventDrop, eventText = tkDrop.new(eeOpts, "Event") |
eventDrop:SetPoint("CENTER", eeOpts, "CENTER", 0, 20) |
eventDrop:SetWidth(200) |
local function OnClick(self) |
UIDropDownMenu_SetSelectedValue(eventDrop, self.value) |
eventSelected = events[self.value] |
print(eventSelected, self.value) |
eventText:SetText(eventSelected) |
setsText:SetText(EventEquipDB[eventSelected]) |
end |
UIDropDownMenu_Initialize(eventDrop, function() |
local current, info = UIDropDownMenu_GetSelectedValue(eventDrop), UIDropDownMenu_CreateInfo() |
for k,v in pairs(events) do |
info.text, info.value, info.func, info.checked = v, k, OnClick, v == current |
UIDropDownMenu_AddButton(info) |
end |
end) |
eventDrop:SetScript("OnEnter", function(self) OnEnter(self, "Choose an event.") end) |
eventDrop:SetScript("OnLeave", OnLeave) |
local eventLabel = eventDrop:CreateFontString(nil, "ARTWORK", "GameFontNormal") |
eventLabel:SetText("Events") |
eventLabel:SetPoint("BOTTOM", eventDrop, "TOP", 0, 5) |
local saveButton = CreateFrame("Button", nil, eeOpts, "UIPanelButtonTemplate") |
saveButton:SetPoint("BOTTOM", eeOpts, "BOTTOM", 0, 30) |
saveButton:SetText("Save Event") |
saveButton:SetHeight(25) |
saveButton:SetWidth(125) |
saveButton:SetScript("OnEnter", function(self) |
OnEnter(self, "Click to save this set to this event.") |
end) |
saveButton:SetScript("OnLeave", OnLeave) |
saveButton:SetScript("OnClick", function() |
if eventSelected and setSelected or setsText:GetText() == EventEquipDB[eventSelected] then |
EventEquipDB[eventSelected] = setSelected or setsText:GetText() |
if setSelected == "None" or setsText:GetText() == "None" then |
DEFAULT_CHAT_FRAME:AddMessage("EventEquip: Set removed from Event -"..eventSelected.."-",.8,1,.2) |
else |
DEFAULT_CHAT_FRAME:AddMessage("EventEquip: Set -"..EventEquipDB[eventSelected].."- assigned to Event -"..eventSelected.."-",.8,1,.2) |
end |
else |
DEFAULT_CHAT_FRAME:AddMessage("EventEquip: You must select an event and a set to save!",.8,1,.2) |
end |
EventEquip[eventSelected]() |
end) |
end |
|
local function CreateButton() |
local eeButton = CreateFrame("Button", nil, gmd) |
eeButton:SetWidth(22) |
eeButton:SetHeight(22) |
eeButton:SetPoint("BOTTOM", gmd, "BOTTOM", 2,12) |
eeButton:SetNormalTexture("Interface\\Minimap\\Tracking\\Repair.blp") |
eeButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight.blp") |
eeButton:GetHighlightTexture():SetTexCoord(0,.64,0,.64) |
eeButton:SetScript("OnEnter", function(self) OnEnter(self, "Click to open the EventEquip window.") end) |
eeButton:SetScript("OnLeave", OnLeave) |
eeButton:SetScript("OnMouseDown", function() |
if not EEOptions then |
SetUpOptions() |
return |
end |
if EEOptions:IsShown() then |
EEOptions:Hide() |
else |
EEOptions:Show() |
end |
end) |
end |
|
local function SetScriptHook(frame, script, func) |
if frame:GetScript(script) then |
frame:HookScript(script, func) |
else |
frame:SetScript(script, func) |
end |
end |
|
function EventEquip.PLAYER_ENTERING_WORLD() |
EventEquipDB = EventEquipDB or {} |
for k,v in pairs(defaults) do |
if type(EventEquipDB[k]) == "nil" then |
EventEquipDB[k] = v |
end |
end |
|
CollectSets() |
CreateButton() |
|
for k,v in pairs(events) do |
EventEquip[v]() |
end |
|
SetScriptHook(GearManagerDialogSaveSet, "OnClick", function() |
if EEOptions then |
EEOptions:Hide() |
end |
end) |
|
EventEquip:UnregisterEvent("PLAYER_ENTERING_WORLD") |
end |
|
EventEquip:SetScript("OnEvent", function(self,event,...) |
return self[event](...) --just passing event args atm |
end) |
|
EventEquip:RegisterEvent("PLAYER_ENTERING_WORLD") |