Skip to content

Commit

Permalink
Bug fixes, made the whole frame draggable
Browse files Browse the repository at this point in the history
- Fixed weapon skills for Shamans and Druids
- Fixed a bug where it would still show learned spells on login
- Fixed a bug where the amount of rows were too many on login/reload ("phantom" rows)
- Fixed a bug where known weapon skills would still show
- Fixed a bug where lower rank spells still show as unlearned
- Made the whole frame draggable instead of only the title bar
  • Loading branch information
cloudbells committed Sep 3, 2019
1 parent 0f0c281 commit 864aeca
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 42 deletions.
12 changes: 7 additions & 5 deletions Database/WeaponSkills.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ local weapons = {
["id"] = 266
},
["one_handed_axes"] = {
["name"] = "One-Handed Axes",
["name"] = "Axes",
["rank"] = 1,
["cost"] = 1000,
["texture"] = "Interface/ICONS/inv_axe_01",
["id"] = 196
},
["one_handed_maces"] = {
["name"] = "One-Handed Maces",
["name"] = "Maces",
["rank"] = 1,
["cost"] = 1000,
["texture"] = "Interface/ICONS/inv_mace_01",
["id"] = 198
},
["one_handed_swords"] = {
["name"] = "One-Handed Swords",
["name"] = "Swords",
["rank"] = 1,
["cost"] = 1000,
["texture"] = "Interface/ICONS/ability_meleedamage",
Expand Down Expand Up @@ -165,11 +165,12 @@ FieldGuide.WEAPONS = {
FieldGuide.copy(weapons.wands)
},
[6] = { -- Shaman.
FieldGuide.copy(weapons.daggers),
FieldGuide.copy(weapons.one_handed_axes),
FieldGuide.copy(weapons.one_handed_maces),
FieldGuide.copy(weapons.staves),
FieldGuide.copy(weapons.two_handed_axes),
FieldGuide.copy(weapons.two_handed_maces)
FieldGuide.copy(weapons.two_handed_maces),
},
[7] = { -- Mage.
FieldGuide.copy(weapons.daggers),
Expand All @@ -185,8 +186,9 @@ FieldGuide.WEAPONS = {
},
[9] = { -- Druid.
FieldGuide.copy(weapons.daggers),
FieldGuide.copy(weapons.fist_weapons),
FieldGuide.copy(weapons.one_handed_maces),
FieldGuide.copy(weapons.staves),
FieldGuide.copy(weapons.wands)
FieldGuide.copy(weapons.two_handed_maces),
},
}
56 changes: 27 additions & 29 deletions FieldGuide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,16 @@ end
-- Iterates all weapon skills for the current class and shows/hides any known ones.
local function hideUnwantedWeapons()
local maxValue = 0
for index, class in ipairs(CLASSES) do
local nbrOfSpells = 0
for weaponIndex, weaponInfo in ipairs(FieldGuide.WEAPONS[CLASS_INDECES[class:upper()]]) do
if class == actualClass then
if not FieldGuideOptions.showKnownSpells and IsSpellKnown(weaponInfo.id) then
weaponInfo.hidden = true
else
weaponInfo.hidden = false
end
end
nbrOfSpells = not weaponInfo.hidden and nbrOfSpells + 1 or nbrOfSpells
local nbrOfSpells = 0
for weaponIndex, weaponInfo in ipairs(FieldGuide.WEAPONS[CLASS_INDECES[actualClass]]) do
if not FieldGuideOptions.showKnownSpells and FieldGuide.isWeaponKnown(weaponInfo.name) then
weaponInfo.hidden = true
else
weaponInfo.hidden = false
end
maxValue = nbrOfSpells > maxValue and nbrOfSpells or maxValue
nbrOfSpells = not weaponInfo.hidden and nbrOfSpells + 1 or nbrOfSpells
end
maxValue = nbrOfSpells > maxValue and nbrOfSpells or maxValue
setHorizontalSliderMaxValue(maxValue)
end

Expand Down Expand Up @@ -404,16 +400,20 @@ end

-- Hides all unwanted spells (known spells/talents/opposite faction spells). Also adjusts the horizontal slider appropriately.
local function hideUnwantedSpells()
local knownSpells = {}
local maxSpellIndex = 0
local currentSpellIndex = 0
local nbrOfHiddenRows = 0
lowestLevel = 52
for level = 2, 60, 2 do
for level = 60, 2, -2 do
local hiddenCounter = 0
for spellIndex, spellInfo in ipairs(FieldGuide[selectedClass][level]) do
if IsSpellKnown(spellInfo.id) then
knownSpells[spellInfo.name] = true
end
if spellInfo.empty then
spellInfo.hidden = true
elseif not FieldGuideOptions.showKnownSpells and ((selectedClass == "HUNTER_PETS" or selectedClass == "WARLOCK_PETS") and IsSpellKnown(spellInfo.id, true) or IsSpellKnown(spellInfo.id)) then
elseif not FieldGuideOptions.showKnownSpells and ((selectedClass == "HUNTER_PETS" or selectedClass == "WARLOCK_PETS") and IsSpellKnown(spellInfo.id, true) or knownSpells[spellInfo.name]) then
spellInfo.hidden = true
elseif not FieldGuideOptions.showEnemySpells and (isAlliance() and spellInfo.faction == 2 or (not isAlliance() and spellInfo.faction == 1)) then
spellInfo.hidden = true
Expand Down Expand Up @@ -462,7 +462,7 @@ local function resetScroll()
end

-- Changes the class to the given class.
local function setClass(dropdownButton, class)
local function setClass(_, class)
if class == "HUNTER_PETS" then
setBackground("HUNTER")
ToggleDropDownMenu(nil, nil, FieldGuideDropdownFrame)
Expand All @@ -471,8 +471,6 @@ local function setClass(dropdownButton, class)
setBackground("WARLOCK")
ToggleDropDownMenu(nil, nil, FieldGuideDropdownFrame)
UIDropDownMenu_SetText(FieldGuideDropdownFrame, CLASS_COLORS.WARLOCK .. "Demon spells")
elseif class ~= "WEAPONS" then
UIDropDownMenu_SetText(FieldGuideDropdownFrame, CLASS_COLORS[class] .. class:sub(1, 1) .. class:sub(2):lower())
else
UIDropDownMenu_SetText(FieldGuideDropdownFrame, CLASS_COLORS[class] .. class:sub(1, 1) .. class:sub(2):lower())
end
Expand Down Expand Up @@ -645,15 +643,12 @@ end
local function init()
tinsert(UISpecialFrames, FieldGuideFrame:GetName()) -- Allows us to close the window with escape.
initFrames()
selectedClass = actualClass
setBackground(selectedClass)
FieldGuide_ToggleButtons() -- Need to call this, or spells won't be hidden regardless of saved variables.
resetScroll()
setClass(nil, actualClass)
initDropdown()
initCheckboxes()
initMinimapButton()
initSlash()
FieldGuideFrameVerticalSlider:SetMinMaxValues(0, 30 - NBR_OF_SPELL_ROWS) -- If we show 5 spell rows, the scroll max value should be 25 (it scrolls to 25th row, and shows the last 5 already).
FieldGuide_ToggleButtons() -- Need to call this, or spells won't be hidden regardless of saved variables.
FieldGuideFrameVerticalSlider:SetValue(1)
FieldGuideFrameVerticalSlider:SetValue(0)
if not tomtom then
Expand Down Expand Up @@ -829,13 +824,13 @@ function FieldGuide_Scroll(delta, horizontal)
end

-- Shows or hides the talents (type == 1), enemy spells (type == 2), or known spells (type == 3).
function FieldGuide_ToggleButtons(type)
function FieldGuide_ToggleButtons(t)
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
if type == 3 then -- Known spells.
if t == 3 then -- Known spells.
FieldGuideOptions.showKnownSpells = not FieldGuideOptions.showKnownSpells
elseif type == 2 then -- Enemy spells.
elseif t == 2 then -- Enemy spells.
FieldGuideOptions.showEnemySpells = not FieldGuideOptions.showEnemySpells
elseif type == 1 then -- Talents.
elseif t == 1 then -- Talents.
FieldGuideOptions.showTalents = not FieldGuideOptions.showTalents
end
if selectedClass ~= "WEAPONS" then
Expand All @@ -845,7 +840,6 @@ function FieldGuide_ToggleButtons(type)
updateButtons()
else
hideUnwantedWeapons()
resetScroll()
updateWeapons()
end
end
Expand All @@ -855,6 +849,7 @@ function FieldGuide_OnLoad(self)
self:RegisterForDrag("LeftButton")
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("LEARNED_SPELL_IN_TAB")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
end

-- Called on each event the frame receives.
Expand All @@ -866,15 +861,14 @@ function FieldGuide_OnEvent(self, event, ...)
FieldGuideOptions = FieldGuideOptions or {}
FieldGuideOptions.pins = {}
end
print(not tomtom and "|cFFFFFF00Field Guide|r loaded! Type /fg help for commands and controls. By the way, it is highly recommended to use TomTom with Field Guide." or "|cFFFFFF00Field Guide|r loaded! Type /fg help for commands and controls.")
FieldGuideOptions = FieldGuideOptions or {}
FieldGuideOptions.showTalents = FieldGuideOptions.showTalents
FieldGuideOptions.showEnemySpells = FieldGuideOptions.showEnemySpells
FieldGuideOptions.showKnownSpells = FieldGuideOptions.showKnownSpells
FieldGuideOptions.unwantedSpells = FieldGuideOptions.unwantedSpells or {}
FieldGuideOptions.minimapTable = FieldGuideOptions.minimapTable or {}
FieldGuideOptions.pins = FieldGuideOptions.pins or {}
init()
print(not tomtom and "|cFFFFFF00Field Guide|r loaded! Type /fg help for commands and controls. By the way, it is highly recommended to use TomTom with Field Guide." or "|cFFFFFF00Field Guide|r loaded! Type /fg help for commands and controls.")
self:UnregisterEvent("ADDON_LOADED")
end
elseif event == "LEARNED_SPELL_IN_TAB" then
Expand All @@ -885,5 +879,9 @@ function FieldGuide_OnEvent(self, event, ...)
hideUnwantedWeapons()
updateWeapons()
end
elseif event == "PLAYER_ENTERING_WORLD" then
init()
FieldGuideFrame:Hide()
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
end
14 changes: 6 additions & 8 deletions FieldGuide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@
<Anchors>
<Anchor point="TOP" x="0" y="10" />
</Anchors>
<Scripts>
<OnMouseDown>
self:GetParent():StartMoving()
</OnMouseDown>
<OnMouseUp>
self:GetParent():StopMovingOrSizing()
</OnMouseUp>
</Scripts>
</Frame>
<Slider name="$parentVerticalSlider" orientation="VERTICAL" minValue="0" maxValue="0" defaultValue="0" valueStep="1">
<Size x="22" y="1" />
Expand Down Expand Up @@ -279,6 +271,12 @@
<OnHide>
PlaySound(SOUNDKIT.IG_SPELLBOOK_CLOSE)
</OnHide>
<OnDragStart>
self:StartMoving()
</OnDragStart>
<OnDragStop>
self:StopMovingOrSizing()
</OnDragStop>
<OnMouseWheel>
FieldGuide_Scroll(delta)
</OnMouseWheel>
Expand Down
11 changes: 11 additions & 0 deletions Util.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local _, FieldGuide = ...

local GetNumSkillLines, GetSkillLineInfo = GetNumSkillLines, GetSkillLineInfo

FieldGuide.factions = {
["darnassus"] = 69,
["darkspear_trolls"] = 530,
Expand Down Expand Up @@ -93,3 +95,12 @@ end
function FieldGuide.getContinent(map)
return continents[map]
end

function FieldGuide.isWeaponKnown(name)
for i = 1, GetNumSkillLines() do
if name == GetSkillLineInfo(i) then
return true
end
end
return false
end

0 comments on commit 864aeca

Please sign in to comment.