Skip to content

Commit

Permalink
Merge pull request #11 from Kirri777:Kirri777/issue10
Browse files Browse the repository at this point in the history
Show the loot frame when a classifiable item drops from any mob
  • Loading branch information
Kirri777 authored Oct 25, 2024
2 parents b9ea4d4 + 271041f commit 96f969e
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 23 deletions.
15 changes: 15 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# These are supported funding model platforms

github: Kirri777 # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
thanks_dev: # Replace with a single thanks.dev username
custom: https://buycoffee.to/kirri777 # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
166 changes: 148 additions & 18 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ AddOn.Entries = {}
AddOn.RaidMembers = {}
AddOn.Config = {}
AddOn.inspectCount = 1
AddOn.instanceType = 'none'
AddOn.eventsLoaded = false

function AddOn.Print(msg)
print("[|cff3399FFDYNT|r] " .. msg)
Expand Down Expand Up @@ -188,35 +190,55 @@ function AddOn:checkAddItem(itemLink, rarity, equipLoc, itemClass, itemSubClass,
return true, mog
end

--[[
Checks if an item is transmogable and returns its status.
If the CanIMogIt library is outdated, it will return false and a not transmogable icon.
If the item is not transmogable, it will return false and a not transmogable icon.
If the player knows the transmog, it will return false and a known icon.
If the player does not know the transmog, but another character knows it, it will return true and a known circle icon
if the user has enabled the option to check the source of the transmog.
If the player does not know the transmog and no other character knows it, it will return true and an unknown icon.
@param itemLink The link to the item to be checked.
@return checkTransmogable (bool) Whether the item is transmogable.
@return mog (string) The icon to be used to represent the state of the item.
--]]
function AddOn:checkAddItemTransmog(itemLink)
local mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\not_transmogable:0|t'

-- Check if the user has enabled the option to check if the item is transmogable
if not self.db.config.checkTransmogable then
self.Debug("checkTransmogable: false")
return false, mog
end

-- Check if the CanIMogIt library is outdated
local isTransmogable, isKnown, isOtherKnown, isOutdated = self:CanIMogItCheckItem(itemLink)

if isOutdated then
self.Debug("CanIMogIt - isOutdated: true")
return false, mog
end

-- Check if the item is transmogable
if not isTransmogable then
self.Debug("CanIMogIt - isTransmogable: false")
return false, mog
end

-- Check if the player knows the transmog
if isKnown then
mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\known:0|t'
self.Debug("CanIMogIt - isKnown: true")
return false, mog
end

-- Check if another character knows the transmog
if isOtherKnown then
mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\known_circle:0|t'

-- Check if the user has enabled the option to check the source of the transmog
if self.db.config.checkTransmogableSource then
self.Debug("CanIMogIt - isOtherKnown and checkTransmogableSource: true")
return true, mog
Expand All @@ -226,6 +248,7 @@ function AddOn:checkAddItemTransmog(itemLink)
return false, mog
end

-- If the player does not know the transmog and no other character knows it
mog = '|TInterface\\AddOns\\CanIMogIt\\Icons\\unknown:0|t'
return true, mog
end
Expand All @@ -238,12 +261,17 @@ end
@see https://wowpedia.fandom.com/wiki/DifficultyID
@see https://wowpedia.fandom.com/wiki/BOSS_KILL
@param encounterID The encounter ID of the boss that was killed.
@param encounterName The name of the boss that was killed.
@return void
--]]
function AddOn:BOSS_KILL(encounterID, encounterName)
self.Debug("BOSS_KILL")
self.Debug("encounterID:" .. encounterID)
self.Debug("encounterName:" .. encounterName)
-- function AddOn:BOSS_KILL(encounterID)
-- Dont open frame when you dont in group
if not self:checkInGroupOrRaid() then
self.Debug("checkInGroupOrRaid: false")
Expand All @@ -254,12 +282,10 @@ function AddOn:BOSS_KILL(encounterID, encounterName)
-- Clear all entries in the loot table
self:ClearEntries()

-- Don't open if its M+ (8 is Mythic Keystone)
-- if self.Config.openAfterEncounter and difficulty ~= 8 then
-- self.lootFrame:Show()
-- end
-- Don't open if its disabled or its not the right difficultyID
if self.Config.openAfterEncounter and (difficulty ~= 8 or self:isLastBossMythicPlus(encounterID)) then
self.lootFrame:Show()
self.db.lootWindowOpen = true
end
end

Expand All @@ -270,6 +296,8 @@ end
the option to open the frame after an encounter.
@see https://wowpedia.fandom.com/wiki/CHALLENGE_MODE_COMPLETED
@return void
--]]
function AddOn:CHALLENGE_MODE_COMPLETED()
self.Debug("CHALLENGE_MODE_COMPLETED")
Expand All @@ -286,8 +314,10 @@ function AddOn:CHALLENGE_MODE_COMPLETED()
-- Don't open if its disabled
if self.Config.openAfterEncounter then
self.lootFrame:Show()
self.db.lootWindowOpen = true
end
end

--[[
Checks if the given encounter ID corresponds to a last boss in a Mythic+ dungeon.
Expand All @@ -308,26 +338,89 @@ function AddOn:isLastBossMythicPlus(encounterId)
return false -- Return false if no match is found
end

--[[
Handles the PLAYER_ENTERING_WORLD event. This function is triggered when the player enters the world,
either by logging in, reloading the UI, or changing zones.
It determines the type of instance the player is in and decides whether to register or unregister events
based on the configuration settings and instance type.
@return void
--]]
function AddOn:PLAYER_ENTERING_WORLD()
-- Retrieve the current instance type
local _, instanceType = GetInstanceInfo()
self.Debug("PLAYER_ENTERING_WORLD - instanceType: " .. instanceType)
if instanceType == "none" then
-- self.Debug("Not in instance, unregistering events")
self.EventFrame:UnregisterEvent("CHAT_MSG_LOOT")
self.EventFrame:UnregisterEvent("BOSS_KILL")
self.EventFrame:UnregisterEvent("CHALLENGE_MODE_COMPLETED")
if self.InspectTimer then
self.InspectTimer:Cancel()
self.InspectTimer = nil
end
-- Store the instance type in the AddOn object
AddOn.instanceType = instanceType

-- Log the instance type for debugging purposes
self.Debug("PLAYER_ENTERING_WORLD - instanceType: " .. AddOn.instanceType)

-- Register events if the loot frame should be shown everywhere or if the player is in an instance
if self.db.config.chatShowLootFrame == "everywhere" or AddOn.instanceType ~= "none" then
AddOn:registerEvents()
return
end
self.Debug("In instance, registering events")

-- Unregister events if the conditions above are not met
AddOn:unregisterEvents()
end

--[[
Registers the necessary events for the AddOn and sets up a repeated timer to inspect group members.
This function ensures that events are only registered once and starts a timer for periodic inspection.
@return void
--]]
function AddOn:registerEvents()
self.Debug("registerEvents")

-- Check if events are already loaded to avoid duplicate registration
if AddOn.eventsLoaded then
return
end

-- Register events for loot messages, boss kills, and challenge mode completion
self.EventFrame:RegisterEvent("CHAT_MSG_LOOT")
self.EventFrame:RegisterEvent("BOSS_KILL")
self.EventFrame:RegisterEvent("CHALLENGE_MODE_COMPLETED")
-- Set repeated timer to check for raidmembers inventory

-- Set a repeated timer every 7 seconds to check the inventory of raid members
self.InspectTimer = C_Timer.NewTicker(7, function() self.InspectGroup() end)

-- Mark events as loaded to prevent re-registration
AddOn.eventsLoaded = true
end

--[[
Unregisters the events for the AddOn and cancels the repeated timer for inspection.
This function is the counterpart to registerEvents() and is called when the player is no longer
in a group or raid. It ensures that events are not registered multiple times and stops the timer
for periodic inspection to prevent excessive CPU usage.
@return void
--]]
function AddOn:unregisterEvents()
self.Debug("unregisterEvents")

-- Check if events are already unloaded to avoid duplicate unregistration
if not AddOn.eventsLoaded then
return
end

-- Unregister events for loot messages, boss kills, and challenge mode completion
self.EventFrame:UnregisterEvent("CHAT_MSG_LOOT")
self.EventFrame:UnregisterEvent("BOSS_KILL")
self.EventFrame:UnregisterEvent("CHALLENGE_MODE_COMPLETED")

-- Cancel the repeated timer for inspection
if self.InspectTimer then
self.InspectTimer:Cancel()
self.InspectTimer = nil
end

-- Mark events as unloaded to prevent re-registration
AddOn.eventsLoaded = false
end

function AddOn:ADDON_LOADED(addon)
Expand All @@ -345,6 +438,7 @@ function AddOn:ADDON_LOADED(addon)
debug = false,
checkTransmogable = true,
checkTransmogableSource = true,
chatShowLootFrame = 'disabled',
minDelta = 0,
},
minimap = {
Expand All @@ -360,6 +454,11 @@ function AddOn:ADDON_LOADED(addon)
self.db.config.minDelta = 0
end

-- Set chatShowLootFrameEverywhere default if its not a fresh install
if not self.db.config.chatShowLootFrame then
self.db.config.chatShowLootFrame = 'disabled'
end

self.createLootFrame()

-- Set window position
Expand Down Expand Up @@ -471,6 +570,9 @@ end
function AddOn:AddItemToLootTable(t)
-- Itemlink, Looter, Ilvl
self.Debug("Adding item to entries")

AddOn:ShowLootFrameFromChat()

local entry = self:GetEntry(t[1], t[2])
local _, _, _, equipLoc, _, _, itemSubClass = GetItemInfoInstant(t[1])
local character = t[2]:match("(.*)%-") or t[2]
Expand Down Expand Up @@ -518,6 +620,34 @@ function AddOn:AddItemToLootTable(t)
entry:Show()
end

function AddOn:ShowLootFrameFromChat()
self.Debug("ShowLootFrame")

-- check is opened
if self.db.lootWindowOpen or self.Config.chatShowLootFrame == "disabled" then
return
end

if not self:checkInGroupOrRaid() then
self.Debug("checkInGroupOrRaid: false")
return
end

if self.Config.chatShowLootFrame == "everywhere" then
self.lootFrame:Show()
self.db.lootWindowOpen = true
return
end

-- local _, instanceType = GetInstanceInfo()
self.Debug("ShowLootFrameFromChat - instanceType: " .. AddOn.instanceType)

if AddOn.instanceType ~= "none" then
self.lootFrame:Show()
self.db.lootWindowOpen = true
end
end

--[[
Sends a whisper message to a player with the provided item link.
Expand Down
2 changes: 1 addition & 1 deletion DoYouNeedThat.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Title: DoYouNeedThat?
## Author: Kraffs <Numinous-TarrenMill LootCouncil-TarrenMill>
## Version: 1.2.3
## Version: 1.2.4
## Notes: Pesters people for loot because Personal Loot is fun! (Kirri mod)
## OptionalDeps: CanIMogIt
## SavedVariables: DyntDB
Expand Down
38 changes: 36 additions & 2 deletions Frame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,45 @@ function AddOn.createOptionsFrame()
end
end)

local chatshowlootframe_options = {
['disabled'] = L["SELECT_OPTION_DISABLED"],
['only_dungeon_raid'] = L["SELECT_OPTION_ONLY_DUNGEON_RAID"],
['everywhere'] = L["SELECT_OPTION_EVERYWHERE"],
}

options.chatShowLootFrame = CreateFrame("Frame", "DYNT_Options_ChatShowLootFrame", options, "UIDropDownMenuTemplate")
options.chatShowLootFrame:SetPoint("TOPLEFT", options, "TOPLEFT", 3, -180)
-- options.chatShowLootFrame:SetWidth(150)
UIDropDownMenu_SetWidth(options.chatShowLootFrame, 150)
getglobal(options.chatShowLootFrame:GetName() .. 'Text'):SetText(chatshowlootframe_options[AddOn.db.config.chatShowLootFrame]);
options.chatShowLootFrame.initialize = function()
local info = {}
for key, value in pairs(chatshowlootframe_options) do
info.text = value
info.value = key
info.checked = key == AddOn.db.config.chatShowLootFrame
info.func = function(self)
AddOn.db.config.chatShowLootFrame = self.value
getglobal(options.chatShowLootFrame:GetName() .. 'Text'):SetText(self:GetText());
AddOn:PLAYER_ENTERING_WORLD()
end
UIDropDownMenu_AddButton(info)
end
end

options.chatShowLootFrame.labelText = options.chatShowLootFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
options.chatShowLootFrame.labelText:SetPoint("TOPLEFT", options.chatShowLootFrame, "TOPLEFT", 20, 15)
options.chatShowLootFrame.labelText:SetJustifyH("LEFT")
options.chatShowLootFrame.labelText:SetTextColor(1, 1, 1)
options.chatShowLootFrame.labelText:SetShadowColor(0, 0, 0)
options.chatShowLootFrame.labelText:SetShadowOffset(1, -1)
options.chatShowLootFrame.labelText:SetText(L["OPTIONS_CHECK_CHAT_SHOW_LOOT_FRAME"])

-- Whisper message
---@type table|BackdropTemplate|EditBox
options.whisperMessage = CreateFrame("EditBox", "DYNT_Options_WhisperMessage", options, "InputBoxTemplate")
options.whisperMessage:SetSize(200, 32)
options.whisperMessage:SetPoint("TOPLEFT", options, "TOPLEFT", 28, -190)
options.whisperMessage:SetPoint("TOPLEFT", options, "TOPLEFT", 28, -230)
options.whisperMessage:SetAutoFocus(false)
options.whisperMessage:SetMaxLetters(128)
AddOn.Debug(AddOn.Config.whisperMessage)
Expand All @@ -524,7 +558,7 @@ function AddOn.createOptionsFrame()
options.minDelta = CreateFrame("Slider", "DYNT_Options_MinDelta", options, "OptionsSliderTemplate")
options.minDelta:SetWidth(300)
options.minDelta:SetHeight(20)
options.minDelta:SetPoint("TOPLEFT", 28, -260)
options.minDelta:SetPoint("TOPLEFT", 28, -300)
options.minDelta:SetOrientation("HORIZONTAL")
options.minDelta:SetMinMaxValues(0, 100)
options.minDelta:SetValue(AddOn.Config.minDelta)
Expand Down
6 changes: 5 additions & 1 deletion Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ L["OPTIONS_DONT_CHECK_ISITEMUPGRADE"] = "Show all items for you (if checked then
L["OPTIONS_SHOW_EVERYWHERE"] = "Show everywhere (not only in instances)"
L["OPTIONS_CHECK_TRANSMOG"] = "Verify if the item is transmogable (Requires the CanIMogIt addon)"
L["OPTIONS_CHECK_TRANSMOG_OTHER_SOURCES"] = "Also show items that are learned from other sources (Requires CanIMogIt addon)"
L["CanIMogIt"] = "Mog"
L["OPTIONS_CHECK_CHAT_SHOW_LOOT_FRAME"] = "Show the loot frame when a classifiable item drops from any mob (not only bosses)"
L["CanIMogIt"] = "Mog"
L["SELECT_OPTION_DISABLED"] = "Disabled"
L["SELECT_OPTION_ONLY_DUNGEON_RAID"] = "Only in dungeon or raid"
L["SELECT_OPTION_EVERYWHERE"] = "Everywhere"
4 changes: 4 additions & 0 deletions Locales/zhCN.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ L["OPTIONS_DONT_CHECK_ISITEMUPGRADE"] =
L["OPTIONS_SHOW_EVERYWHERE"] = "Show everywhere (not only in instances)"
L["OPTIONS_CHECK_TRANSMOG"] = "Verify if the item is transmogable (Requires the CanIMogIt addon)"
L["OPTIONS_CHECK_TRANSMOG_OTHER_SOURCES"] = "Also show items that are learned from other sources (Requires CanIMogIt addon)"
L["OPTIONS_CHECK_CHAT_SHOW_LOOT_FRAME"] = "Show the loot frame when a classifiable item drops from any mob (not only bosses)"
L["CanIMogIt"] = "Mog"
L["SELECT_OPTION_DISABLED"] = "Disabled"
L["SELECT_OPTION_ONLY_DUNGEON_RAID"] = "Only in dungeon or raid"
L["SELECT_OPTION_EVERYWHERE"] = "Everywhere"
Loading

0 comments on commit 96f969e

Please sign in to comment.