From 95a114f9f57d8e5fde0cd4c46400c68084f0e52b Mon Sep 17 00:00:00 2001 From: Oliver Maus Date: Fri, 6 Oct 2023 01:01:50 +0200 Subject: [PATCH] 3.2.0 (#26) Implemented a preview of the Macro Priority in the Settings Page. Also added the ability to Include the shortest Cooldown in the reset Condition of Castsequence. !!USE CAREFULLY!! I would highly advise not to use it that way. --- AutoPotion.toc | 7 +- Bindings.lua | 1 - Bindings.xml | 3 - Core/DB.lua | 35 +++ Core/Player.lua | 70 +---- Core/Potions.lua | 11 +- Core/Spells.lua | 34 +++ FrameXML/InterfaceOptionsFrame.lua | 437 +++++++++++++---------------- code.lua | 112 +++++--- 9 files changed, 355 insertions(+), 355 deletions(-) create mode 100644 Core/DB.lua diff --git a/AutoPotion.toc b/AutoPotion.toc index 22a2281..8b6fc6d 100755 --- a/AutoPotion.toc +++ b/AutoPotion.toc @@ -1,17 +1,18 @@ ## Interface: 100107 ## Interface-Classic: 11404 ## Interface-WOTLKC: 30402 -## Version: 3.1.1 +## Version: 3.2.0 ## Title: Auto Potion ## Author: ollidiemaus ## Notes: Updates the Macro AutoPotion to use either Healthstone or the highest Potion found in Bags ## X-Curse-Project-ID: 312940 ## X-Wago-ID: yQKybBG7 ## SavedVariables: HAMDB -code.lua Core/Item.lua -Core/Player.lua Core/Potions.lua Core/Spells.lua +Core/DB.lua +Core/Player.lua +code.lua Bindings.lua FrameXML/InterfaceOptionsFrame.lua \ No newline at end of file diff --git a/Bindings.lua b/Bindings.lua index cdf5e22..f533527 100755 --- a/Bindings.lua +++ b/Bindings.lua @@ -1,2 +1 @@ -_G["BINDING_NAME_MACRO HAMHealthPot"] = "HAMHealthPot Macro" _G["BINDING_NAME_MACRO AutoPotion"] = "AutoPotion Macro" diff --git a/Bindings.xml b/Bindings.xml index dff3ef3..887a992 100755 --- a/Bindings.xml +++ b/Bindings.xml @@ -1,7 +1,4 @@ - - -- HAMHealthPot - -- AutoPotion diff --git a/Core/DB.lua b/Core/DB.lua new file mode 100644 index 0000000..7f465b4 --- /dev/null +++ b/Core/DB.lua @@ -0,0 +1,35 @@ +local addonName, ham = ... +ham.defaults = { + cdReset = false, + witheringPotion = false, + activatedSpells = { ham.renewal, ham.exhilaration, ham.fortitudeOfTheBear, ham.bitterImmunity, ham.desperatePrayer, + ham.healingElixir } +} + + +function ham.dbContains(id) + local found = false + for _, v in pairs(HAMDB.activatedSpells) do + if v == id then + found = true + end + end + return found +end + +function ham.removeFromDB(id) + local backup = {} + if ham.dbContains(id) then + for _, v in pairs(HAMDB.activatedSpells) do + if v ~= id then + table.insert(backup, v) + end + end + end + + HAMDB.activatedSpells = CopyTable(backup) +end + +function ham.insertIntoDB(id) + table.insert(HAMDB.activatedSpells, id) +end diff --git a/Core/Player.lua b/Core/Player.lua index d731f57..083fa4c 100755 --- a/Core/Player.lua +++ b/Core/Player.lua @@ -11,76 +11,12 @@ ham.Player.new = function() return end - --returns table with Spellnames {"", ""} function self.getHealingSpells() local spells = {} - if self.englishClass == "DRUID" then - if HAMDB.renewal then - if IsSpellKnown(ham.renewal) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.renewal) - table.insert(spells, name) - end - end - end - - if self.englishClass == "HUNTER" then - --NOTE: on GCD - if HAMDB.exhilaration then - if IsSpellKnown(ham.exhilaration) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.exhilaration) - table.insert(spells, name) - end - end - if HAMDB.fortitudeOfTheBear then - if IsSpellKnown(ham.fortitudeOfTheBear) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.fortitudeOfTheBear) - table.insert(spells, name) - end - end - end - - if self.englishClass == "MONK" then - if HAMDB.expelHarm then - if IsSpellKnown(ham.expelHarm) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.expelHarm) - table.insert(spells, name) - end - end - if HAMDB.healingElixir then - if IsSpellKnown(ham.healingElixir) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.healingElixir) - --Twice because it has two charges ?! - table.insert(spells, name) - table.insert(spells, name) - end - end - end - - if self.englishClass == "PRIEST" then - if HAMDB.desperatePrayer then - if IsSpellKnown(ham.desperatePrayer) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.desperatePrayer) - table.insert(spells, name) - end - end - end - - if self.englishClass == "ROGUE" then - if HAMDB.crimsonVial then - if IsSpellKnown(ham.crimsonVialSpell) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.crimsonVialSpell) - table.insert(spells, name) - end - end - end - - if self.englishClass == "WARRIOR" then - if HAMDB.bitterImmunity then - if IsSpellKnown(ham.bitterImmunity) then - local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(ham.bitterImmunity) - table.insert(spells, name) - end + for i, spell in ipairs(HAMDB.activatedSpells) do + if IsSpellKnown(spell) then + table.insert(spells, spell) end end diff --git a/Core/Potions.lua b/Core/Potions.lua index d88e614..65e9236 100644 --- a/Core/Potions.lua +++ b/Core/Potions.lua @@ -1,4 +1,5 @@ local addonName, ham = ... +local isRetail = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE) local isClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) local isWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC) @@ -67,7 +68,7 @@ ham.fel1 = ham.Item.new(36893, "Fel Healthstone") ham.fel2 = ham.Item.new(36894, "Fel Healthstone") function ham.getPots() - if isClassic == false and isWrath == false then + if isRetail then local pots = { ham.refreshingR3, ham.refreshingR2, @@ -103,7 +104,7 @@ function ham.getPots() return pots end - if isClassic == true then + if isClassic then return { ham.major, ham.superior, @@ -114,7 +115,7 @@ function ham.getPots() } end - if isWrath == true then + if isWrath then return { ham.runic, ham.superreju, @@ -135,7 +136,7 @@ function ham.getPots() end function ham.getHealthstonesClassic() - if isClassic == true then + if isClassic then return { ham.major2, ham.major1, @@ -155,7 +156,7 @@ function ham.getHealthstonesClassic() } end - if isWrath == true then + if isWrath then return { ham.fel2, ham.fel1, diff --git a/Core/Spells.lua b/Core/Spells.lua index 28f9ea6..015ae4c 100755 --- a/Core/Spells.lua +++ b/Core/Spells.lua @@ -8,3 +8,37 @@ ham.bitterImmunity = 383762 ham.desperatePrayer = 19236 ham.expelHarm = 322101 ham.healingElixir = 122281 + +ham.supportedSpells = {} +table.insert(ham.supportedSpells, ham.crimsonVialSpell) +table.insert(ham.supportedSpells, ham.renewal) +table.insert(ham.supportedSpells, ham.exhilaration) +table.insert(ham.supportedSpells, ham.fortitudeOfTheBear) +table.insert(ham.supportedSpells, ham.bitterImmunity) +table.insert(ham.supportedSpells, ham.desperatePrayer) +table.insert(ham.supportedSpells, ham.expelHarm) +table.insert(ham.supportedSpells, ham.healingElixir) + +ham.Spell = {} + +ham.Spell.new = function(id, name) + local self = {} + + self.id = id + self.name = name + self.cd = GetSpellBaseCooldown(id) + + function self.getId() + return self.id + end + + function self.getName() + return self.name + end + + function self.getCd() + return self.cd + end + + return self +end diff --git a/FrameXML/InterfaceOptionsFrame.lua b/FrameXML/InterfaceOptionsFrame.lua index 5d02534..9b95259 100644 --- a/FrameXML/InterfaceOptionsFrame.lua +++ b/FrameXML/InterfaceOptionsFrame.lua @@ -1,29 +1,24 @@ local addonName, ham = ... -local defaults = { - renewal = true, - exhilaration = true, - fortitudeOfTheBear = true, - bitterImmunity = true, - crimsonVial = false, - desperatePrayer = true, - expelHarm = false, - healingElixir = true, - witheringPotion = false, -} - -local panel = CreateFrame("Frame") local isClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) +local isWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC) +local panel = CreateFrame("Frame", "Auto Potion", InterfaceOptionsFramePanelContainer) +local ICON_SIZE = 50 +local PADDING_CATERGORY = 60 +local PADDING = 30 +local PADDING_HORIZONTAL = 200 +local PADDING_PRIO_CATEGORY = 130 +local classButtons = {} +local prioFrames = {} +local firstIcon = nil +local currentPrioTitle = nil function panel:OnEvent(event, addOnName) if addOnName == "AutoPotion" then - HAMDB = HAMDB or CopyTable(defaults) - self.db = HAMDB - self:InitializeOptions() - end - ---LEGACY - if addOnName == "HealthstoneAutoMacro" then - HAMDB = HAMDB or CopyTable(defaults) - self.db = HAMDB + HAMDB = HAMDB or CopyTable(ham.defaults) + if HAMDB.activatedSpells == nil then + print("The Settings of AutoPotion were reset due to breaking changes.") + HAMDB = CopyTable(ham.defaults) + end self:InitializeOptions() end end @@ -31,233 +26,205 @@ end panel:RegisterEvent("ADDON_LOADED") panel:SetScript("OnEvent", panel.OnEvent) +local function createPrioFrame(parentPanel, id, iconTexture, positionx, isSpell) + local icon = CreateFrame("Frame", nil, parentPanel, UIParent) + icon:SetFrameStrata("MEDIUM") + icon:SetWidth(ICON_SIZE) + icon:SetHeight(ICON_SIZE) + icon:HookScript("OnEnter", function(_, btn, down) + GameTooltip:SetOwner(icon, "ANCHOR_TOPRIGHT") + if isSpell == true then + GameTooltip:SetSpellByID(id) + else + GameTooltip:SetItemByID(id) + end + GameTooltip:Show() + end) + icon:HookScript("OnLeave", function(_, btn, down) + GameTooltip:Hide() + end) + local texture = icon:CreateTexture(nil, "BACKGROUND") + texture:SetTexture(iconTexture) + texture:SetAllPoints(icon) + icon.texture = texture + + if firstIcon == nil then + icon:SetPoint("BOTTOMLEFT", 0, PADDING_PRIO_CATEGORY - PADDING * 2) + firstIcon = icon + else + icon:SetPoint("TOPLEFT", firstIcon, positionx, 0) + end + icon:Show() + return icon +end + +local function updatePrio(parentPanel) + if next(prioFrames) ~= nil then + --remove drawn frames + for i, frame in pairs(prioFrames) do + frame:Hide() + end + end + ham.updateHeals() + local positionx = 0 + if next(ham.spellIDs) ~= nil then + for i, id in ipairs(ham.spellIDs) do + local name, rank, iconTexture, castTime, minRange, maxRange = GetSpellInfo(id) + local icon = createPrioFrame(parentPanel, id, iconTexture, positionx, true) + table.insert(prioFrames, icon) + positionx = positionx + (ICON_SIZE + (ICON_SIZE / 2)) + end + end + if next(ham.itemIdList) ~= nil then + for i, id in ipairs(ham.itemIdList) do + local itemID, itemType, itemSubType, itemEquipLoc, iconTexture, classID, subclassID = GetItemInfoInstant( + id) + local icon = createPrioFrame(parentPanel, id, iconTexture, positionx, false) + table.insert(prioFrames, icon) + positionx = positionx + (ICON_SIZE + (ICON_SIZE / 2)) + end + end +end + function panel:InitializeOptions() - self.panel = CreateFrame("Frame") + self.panel = CreateFrame("Frame", "Auto Potion", InterfaceOptionsFramePanelContainer) self.panel.name = "Auto Potion" - local title = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalLarge") - title:SetPoint("TOP") + ------------- HEADER ------------- + local title = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalHuge") + title:SetPoint("TOP", 0, -2) title:SetText("Auto Potion Settings") local subtitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - subtitle:SetPoint("TOPLEFT", 20, -30) + subtitle:SetPoint("TOPLEFT", 0, -PADDING) subtitle:SetText("Here you can configure the behaviour of the Addon eg. if you want to include class spells") - if isClassic == false then - --[[local dkTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - dkTitle:SetPoint("TOPLEFT", subtitle, 0, -50) - dkTitle:SetText("Death Knight") - - local dhTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - dhTitle:SetPoint("TOPLEFT", subtitle, 0, -50) - dhTitle:SetText("Demon Hunter")--]] - local druidTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - druidTitle:SetPoint("TOPLEFT", subtitle, 0, -30) - druidTitle:SetText("Druid") - - local renewalButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - renewalButton:SetPoint("TOPLEFT", druidTitle, 0, -15) - renewalButton.Text:SetText("Use Renewal") - renewalButton:HookScript("OnClick", function(_, btn, down) - self.db.renewal = renewalButton:GetChecked() - end) - renewalButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(renewalButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.renewal); - GameTooltip:Show() - end) - renewalButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - renewalButton:SetChecked(self.db.renewal) - --[[local evokerTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - evokerTitle:SetPoint("TOPLEFT", subtitle, 0, -50) - evokerTitle:SetText("Evoker")--]] - local hunterTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - hunterTitle:SetPoint("TOPLEFT", renewalButton, 0, -50) - hunterTitle:SetText("Hunter") - local exhilarationButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - exhilarationButton:SetPoint("TOPLEFT", hunterTitle, 0, -15) - exhilarationButton.Text:SetText("Use Exhilaration") - exhilarationButton:HookScript("OnClick", function(_, btn, down) - self.db.exhilaration = exhilarationButton:GetChecked() - end) - exhilarationButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(exhilarationButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.exhilaration); - GameTooltip:Show() - end) - exhilarationButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - exhilarationButton:SetChecked(self.db.exhilaration) - - local fortitudeOfTheBearButton = CreateFrame("CheckButton", nil, self.panel, - "InterfaceOptionsCheckButtonTemplate") - fortitudeOfTheBearButton:SetPoint("TOPLEFT", exhilarationButton, 200, 0) - fortitudeOfTheBearButton.Text:SetText("Use Fortitude of the Bear") - fortitudeOfTheBearButton:HookScript("OnClick", function(_, btn, down) - self.db.fortitudeOfTheBear = fortitudeOfTheBearButton:GetChecked() - end) - fortitudeOfTheBearButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(fortitudeOfTheBearButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.fortitudeOfTheBear); - GameTooltip:Show() - end) - fortitudeOfTheBearButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - fortitudeOfTheBearButton:SetChecked(self.db.fortitudeOfTheBear) - - --[[local mageTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - mageTitle:SetPoint("TOPLEFT", subtitle, 0, -50) - mageTitle:SetText("Mage")--]] - local monkTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - monkTitle:SetPoint("TOPLEFT", exhilarationButton, 0, -50) - monkTitle:SetText("Monk") - - local expelHarmButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - expelHarmButton:SetPoint("TOPLEFT", monkTitle, 0, -15) - expelHarmButton.Text:SetText("Use Expel Harm") - expelHarmButton:HookScript("OnClick", function(_, btn, down) - self.db.expelHarm = expelHarmButton:GetChecked() - end) - expelHarmButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(expelHarmButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.expelHarm); - GameTooltip:Show() - end) - expelHarmButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - expelHarmButton:SetChecked(self.db.expelHarm) - - local healingElixirButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - healingElixirButton:SetPoint("TOPLEFT", expelHarmButton, 200, 0) - healingElixirButton.Text:SetText("Use Healing Elixir") - healingElixirButton:HookScript("OnClick", function(_, btn, down) - self.db.healingElixir = healingElixirButton:GetChecked() - end) - healingElixirButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(healingElixirButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.healingElixir); - GameTooltip:Show() - end) - healingElixirButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - healingElixirButton:SetChecked(self.db.healingElixir) - - --[[local paladinTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - paladinTitle:SetPoint("TOPLEFT", subtitle, 0, -50) - paladinTitle:SetText("Paladin")--]] - local priestTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - priestTitle:SetPoint("TOPLEFT", expelHarmButton, 0, -50) - priestTitle:SetText("Priest") - - local desperatePrayerButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - desperatePrayerButton:SetPoint("TOPLEFT", priestTitle, 0, -15) - desperatePrayerButton.Text:SetText("Use Desperate Prayer") - desperatePrayerButton:HookScript("OnClick", function(_, btn, down) - self.db.desperatePrayer = desperatePrayerButton:GetChecked() - end) - desperatePrayerButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(desperatePrayerButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.desperatePrayer); - GameTooltip:Show() - end) - desperatePrayerButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - desperatePrayerButton:SetChecked(self.db.desperatePrayer) - - local rogueTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - rogueTitle:SetPoint("TOPLEFT", desperatePrayerButton, 0, -50) - rogueTitle:SetText("Rogue") - - local crimsonVialButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - crimsonVialButton:SetPoint("TOPLEFT", rogueTitle, 0, -15) - crimsonVialButton.Text:SetText("Use Crimson Vial") - crimsonVialButton:HookScript("OnClick", function(_, btn, down) - self.db.crimsonVial = crimsonVialButton:GetChecked() - end) - crimsonVialButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(crimsonVialButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.crimsonVialSpell); - GameTooltip:Show() - end) - crimsonVialButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - crimsonVialButton:SetChecked(self.db.crimsonVial) - - --[[local shamanTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - shamanTitle:SetPoint("TOPLEFT", subtitle, 0, -50) - shamanTitle:SetText("Shaman") - - local wlTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - wlTitle:SetPoint("TOPLEFT", subtitle, 0, -50) - wlTitle:SetText("Warlock")--]] - local warriorTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - warriorTitle:SetPoint("TOPLEFT", crimsonVialButton, 0, -50) - warriorTitle:SetText("Warrior") - local bitterImmunityButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - bitterImmunityButton:SetPoint("TOPLEFT", warriorTitle, 0, -15) - bitterImmunityButton.Text:SetText("Use Bitter Immunity") - bitterImmunityButton:HookScript("OnClick", function(_, btn, down) - self.db.bitterImmunity = bitterImmunityButton:GetChecked() - end) - bitterImmunityButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(bitterImmunityButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetSpellByID(ham.bitterImmunity); - GameTooltip:Show() - end) - bitterImmunityButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - bitterImmunityButton:SetChecked(self.db.bitterImmunity) - - local witheringPotTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormal") - witheringPotTitle:SetPoint("TOPLEFT", bitterImmunityButton, 0, -50) - witheringPotTitle:SetText("Withering Potions") + ------------- General ------------- + local behaviourTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalHuge") + behaviourTitle:SetPoint("TOPLEFT", subtitle, 0, -PADDING_CATERGORY) + behaviourTitle:SetText("Addon Behaviour") + + local cdResetButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") + cdResetButton:SetPoint("TOPLEFT", behaviourTitle, 0, -PADDING) + cdResetButton.Text:SetText( + "Includes the shortest Cooldown in the reset Condition of Castsequence. !!USE CAREFULLY!!") + cdResetButton:HookScript("OnClick", function(_, btn, down) + HAMDB.cdReset = cdResetButton:GetChecked() + updatePrio(self.panel) + end) + cdResetButton:SetChecked(HAMDB.cdReset) + + + + + ------------- CLASSES ------------- + local myClassTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalHuge") + myClassTitle:SetPoint("TOPLEFT", cdResetButton, 0, -PADDING_CATERGORY) + myClassTitle:SetText("Class Spells") + + local lastbutton = nil + local posy = -PADDING + if next(ham.supportedSpells) ~= nil then + local count = 0 + for i, spell in ipairs(ham.supportedSpells) do + if IsSpellKnown(spell) then + local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(spell) + local button = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") + + if count == 3 then + lastbutton = nil + count = 0 + posy = posy - PADDING + end + if lastbutton ~= nil then + button:SetPoint("TOPLEFT", lastbutton, PADDING_HORIZONTAL, 0) + else + button:SetPoint("TOPLEFT", myClassTitle, 0, posy) + end + button.Text:SetText("Use " .. name) + button:HookScript("OnClick", function(_, btn, down) + if button:GetChecked() then + ham.insertIntoDB(spell) + else + ham.removeFromDB(spell) + end + updatePrio(self.panel) + end) + button:HookScript("OnEnter", function(_, btn, down) + GameTooltip:SetOwner(button, "ANCHOR_TOPRIGHT") + GameTooltip:SetSpellByID(spell); + GameTooltip:Show() + end) + button:HookScript("OnLeave", function(_, btn, down) + GameTooltip:Hide() + end) + button:SetChecked(ham.dbContains(spell)) + table.insert(classButtons, spell, button) + lastbutton = button + count = count + 1 + end + end + end - local witheringPotionButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") - witheringPotionButton:SetPoint("TOPLEFT", witheringPotTitle, 0, -15) - witheringPotionButton.Text:SetText("Use Potion of Withering Vitality") - witheringPotionButton:HookScript("OnClick", function(_, btn, down) - self.db.witheringPotion = witheringPotionButton:GetChecked() - end) - witheringPotionButton:HookScript("OnEnter", function(_, btn, down) - GameTooltip:SetOwner(witheringPotionButton, "ANCHOR_TOPRIGHT") - GameTooltip:SetItemByID(ham.witheringR3.getId()) - GameTooltip:Show() - end) - witheringPotionButton:HookScript("OnLeave", function(_, btn, down) - GameTooltip:Hide() - end) - witheringPotionButton:SetChecked(self.db.witheringPotion) - local btn = CreateFrame("Button", nil, self.panel, "UIPanelButtonTemplate") - btn:SetPoint("TOPLEFT", witheringPotionButton, 0, -50) - btn:SetText("Reset to Default") - btn:SetWidth(120) - btn:SetScript("OnClick", function() - HAMDB = CopyTable(defaults) - self.db = HAMDB - renewalButton:SetChecked(self.db.renewal) - exhilarationButton:SetChecked(self.db.exhilaration) - fortitudeOfTheBearButton:SetChecked(self.db.fortitudeOfTheBear) - bitterImmunityButton:SetChecked(self.db.bitterImmunity) - crimsonVialButton:SetChecked(self.db.crimsonVial) - desperatePrayerButton:SetChecked(self.db.desperatePrayer) - expelHarmButton:SetChecked(self.db.expelHarm) - healingElixirButton:SetChecked(self.db.healingElixir) - witheringPotionButton:SetChecked(self.db.witheringPotion) - print("Reset successful!") - end) + ------------- ITEMS ------------- + local itemsTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalHuge") + if lastbutton ~= nil then + itemsTitle:SetPoint("TOPLEFT", myClassTitle, 0, posy - PADDING_CATERGORY) + else + itemsTitle:SetPoint("TOPLEFT", myClassTitle, 0, -PADDING_CATERGORY) end + + itemsTitle:SetText("Items") + + local witheringPotionButton = CreateFrame("CheckButton", nil, self.panel, "InterfaceOptionsCheckButtonTemplate") + witheringPotionButton:SetPoint("TOPLEFT", itemsTitle, 0, -PADDING) + witheringPotionButton.Text:SetText("Use Potion of Withering Vitality") + witheringPotionButton:HookScript("OnClick", function(_, btn, down) + HAMDB.witheringPotion = witheringPotionButton:GetChecked() + updatePrio(self.panel) + end) + witheringPotionButton:HookScript("OnEnter", function(_, btn, down) + GameTooltip:SetOwner(witheringPotionButton, "ANCHOR_TOPRIGHT") + GameTooltip:SetItemByID(ham.witheringR3.getId()) + GameTooltip:Show() + end) + witheringPotionButton:HookScript("OnLeave", function(_, btn, down) + GameTooltip:Hide() + end) + witheringPotionButton:SetChecked(HAMDB.witheringPotion) + + + ------------- CURRENT PRIORITY ------------- + currentPrioTitle = self.panel:CreateFontString("ARTWORK", nil, "GameFontNormalHuge") + currentPrioTitle:SetPoint("BOTTOMLEFT", 0, PADDING_PRIO_CATEGORY) + currentPrioTitle:SetText("Current Priority") + updatePrio(self.panel) + + + + ------------- RESET BUTTON ------------- + local btn = CreateFrame("Button", nil, self.panel, "UIPanelButtonTemplate") + btn:SetPoint("BOTTOMLEFT", 2, 3) + btn:SetText("Reset to Default") + btn:SetWidth(120) + btn:SetScript("OnClick", function() + HAMDB = CopyTable(ham.defaults) + + for spellID, button in pairs(classButtons) do + if ham.dbContains(spellID) then + button:SetChecked(true) + else + button:SetChecked(false) + end + end + cdResetButton:SetChecked(HAMDB.cdReset) + witheringPotionButton:SetChecked(HAMDB.witheringPotion) + updatePrio(self.panel) + print("Reset successful!") + end) InterfaceOptions_AddCategory(self.panel) end diff --git a/code.lua b/code.lua index 8416218..3a89e71 100755 --- a/code.lua +++ b/code.lua @@ -3,25 +3,15 @@ local macroName = "AutoPotion" local isClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) local isWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC) -local function addPlayerHealingSpellsIfAvailable() - local myPlayer = ham.Player.new() - ham.spellNameList = myPlayer.getHealingSpells() - ham.spellsMacroString = "" +ham.myPlayer = ham.Player.new() - if next(ham.spellNameList) ~= nil then - for i, v in ipairs(ham.spellNameList) do - if i == 1 then - ham.spellsMacroString = v; - else - ham.spellsMacroString = ham.spellsMacroString .. ", " .. v; - end - end - end -end +local spellsMacroString = '' +local itemsMacroString = '' +local macroStr = '' +local resetType = "combat" local function addPlayerHealingItemIfAvailable() - local myPlayer = ham.Player.new() - local playerResetType, item = myPlayer.getHealingItems() + local playerResetType, item = ham.myPlayer.getHealingItems() if item ~= nil then if item.getCount() > 0 then @@ -32,7 +22,7 @@ end local function addHealthstoneIfAvailable() if isClassic == true or isWrath == true then - for iterator, value in ipairs(ham.getHealthstonesClassic()) do + for i, value in ipairs(ham.getHealthstonesClassic()) do if value.getCount() > 0 then table.insert(ham.itemIdList, value.getId()) --we break because all Healthstones share a cd so we only want the highest healing one @@ -47,7 +37,7 @@ local function addHealthstoneIfAvailable() end local function addPotIfAvailable() - for iterator, value in ipairs(ham.getPots()) do + for i, value in ipairs(ham.getPots()) do if value.getCount() > 0 then table.insert(ham.itemIdList, value.getId()) --we break because all Pots share a cd so we only want the highest healing one @@ -57,10 +47,11 @@ local function addPotIfAvailable() end -local function updateAvailableHeals() +function ham.updateHeals() ham.itemIdList = {} - addPlayerHealingSpellsIfAvailable() + ham.spellIDs = ham.myPlayer.getHealingSpells() + addPlayerHealingItemIfAvailable() addHealthstoneIfAvailable() addPotIfAvailable() @@ -73,34 +64,73 @@ local function createMacroIfMissing() end end -local function updateMacro() - local resetType = "combat" - local itemsString = "" - if next(ham.itemIdList) == nil and next(ham.spellNameList) == nil then - ham.macroStr = "#showtooltip" - else - if next(ham.itemIdList) ~= nil then - for i, v in ipairs(ham.itemIdList) do - if i == 1 then - itemsString = "item:" .. v; - else - itemsString = itemsString .. ", " .. "item:" .. v; +local function buildSpellMacroString() + spellsMacroString = '' + + if next(ham.spellIDs) ~= nil then + local shortestCD = nil + for i, spell in ipairs(ham.spellIDs) do + local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(spell) + + if HAMDB.cdReset then + local cooldownMS, gcdMS = GetSpellBaseCooldown(spell) + local cd = cooldownMS / 1000 + if shortestCD == nil then + shortestCD = cd + end + if cd < shortestCD then + shortestCD = cd end end + --TODO HEALING Elixir Twice because it has two charges ?! kinda janky but will work for now + if spell == ham.healingElixir then + name = name .. ", " .. name + end + if i == 1 then + spellsMacroString = name; + else + spellsMacroString = spellsMacroString .. ", " .. name; + end + end + --add if ham.cdReset == true then combat/spelltime + if HAMDB.cdReset then + resetType = "combat/" .. shortestCD + end + end +end + +local function buildItemMacroString() + if next(ham.itemIdList) ~= nil then + for i, v in ipairs(ham.itemIdList) do + if i == 1 then + itemsMacroString = "item:" .. v; + else + itemsMacroString = itemsMacroString .. ", " .. "item:" .. v; + end end - ham.macroStr = "#showtooltip \n/castsequence reset=" .. resetType .. " " - if ham.spellsMacroString ~= "" then - ham.macroStr = ham.macroStr .. ham.spellsMacroString + end +end + +local function updateMacro() + if next(ham.itemIdList) == nil and next(ham.spellIDs) == nil then + macroStr = "#showtooltip" + else + resetType = "combat" + buildItemMacroString() + buildSpellMacroString() + macroStr = "#showtooltip \n/castsequence reset=" .. resetType .. " " + if spellsMacroString ~= "" then + macroStr = macroStr .. spellsMacroString end - if ham.spellsMacroString ~= "" and itemsString ~= "" then - ham.macroStr = ham.macroStr .. ", " + if spellsMacroString ~= "" and itemsMacroString ~= "" then + macroStr = macroStr .. ", " end - if itemsString ~= "" then - ham.macroStr = ham.macroStr .. itemsString + if itemsMacroString ~= "" then + macroStr = macroStr .. itemsMacroString end end createMacroIfMissing() - EditMacro(macroName, macroName, nil, ham.macroStr) + EditMacro(macroName, macroName, nil, macroStr) end local onCombat = true @@ -125,7 +155,7 @@ HealPotMacroIcon:SetScript("OnEvent", function(self, event, ...) end if onCombat == false then - updateAvailableHeals() + ham.updateHeals() updateMacro() end end)