Skip to content

Commit

Permalink
1.1.25-Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldpaw committed Oct 25, 2023
1 parent 2fcd64d commit e7b8ec4
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 5 deletions.
1 change: 1 addition & 0 deletions BlizzardBags_Garbage/BlizzardBags_Garbage.toc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## X-License: Custom

## OptionalDeps: TaintLess
## SavedVariables: BlizzardBags_Garbage_DB

embeds.xml
main.lua
1 change: 1 addition & 0 deletions BlizzardBags_Garbage/BlizzardBags_Garbage_Vanilla.toc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## X-License: Custom

## OptionalDeps: TaintLess
## SavedVariables: BlizzardBags_Garbage_DB

embeds.xml
main.lua
1 change: 1 addition & 0 deletions BlizzardBags_Garbage/BlizzardBags_Garbage_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## X-License: Custom

## OptionalDeps: TaintLess
## SavedVariables: BlizzardBags_Garbage_DB

embeds.xml
main.lua
92 changes: 87 additions & 5 deletions BlizzardBags_Garbage/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ local Addon, Private = ...
-- Lua API
local _G = _G
local ipairs = ipairs
local next = next
local string_find = string.find
local string_gsub = string.gsub
local string_lower = string.lower
local string_match = string.match
local string_split = string.split
local string_upper = string.upper
local tonumber = tonumber

-- WoW API
Expand All @@ -47,6 +51,13 @@ local C_Container_GetContainerItemInfo = C_Container and C_Container.GetContaine
local Cache = GP_ItemButtonInfoFrameCache or {}
GP_ItemButtonInfoFrameCache = Cache

-- Default settings
BlizzardBags_Garbage_DB = {
desaturate = true,
darken = true,
darkenAlpha = 1
}

-- Callbacks
-----------------------------------------------------------
-- Update an itembutton's garbage overlay
Expand All @@ -72,31 +83,41 @@ local Update = function(self, bag, slot)
end
end

if (garbage) then
local shouldDesaturate = BlizzardBags_Garbage_DB.desaturate
local shouldDarken = BlizzardBags_Garbage_DB.darken

-- Item is garbage and we have modifications enabled
if (garbage and (shouldDesaturate or shouldDarken)) then

-- Retrieve or create the button's info container.
local container = Cache[self]

-- Create the item container if needed
if (not container) then
container = CreateFrame("Frame", nil, self)
container:SetFrameLevel(self:GetFrameLevel() + 5)
container:SetAllPoints()
Cache[self] = container
end

-- Retrieve of create the garbage overlay
-- Create the garbage overlay if needed
if (not container.garbage) then
container.garbage = self:CreateTexture()
container.garbage.icon = self.Icon or self.icon or _G[self:GetName().."IconTexture"]

local layer,level = container.garbage.icon:GetDrawLayer()
container.garbage:SetDrawLayer(layer, (level or 6) + 1)
container.garbage:SetAllPoints(container.garbage.icon)
container.garbage:SetColorTexture((51/255)*.2, (17/255)*.2, (6/255)*.2, .6)
end

container.garbage:Show()
container.garbage.icon:SetDesaturated(true)
-- Adjust according to saved settings
container.garbage.icon:SetDesaturated(shouldDesaturate)
container.garbage:SetShown(shouldDarken)
container.garbage:SetAlpha(.35 + .65*BlizzardBags_Garbage_DB.darkenAlpha)

else

-- Item is not garbage, turn off our modifications.
local cache = Cache[self]
if (cache and cache.garbage) then
cache.garbage:Hide()
Expand Down Expand Up @@ -359,6 +380,67 @@ Private.OnEnable = function(self)
hooksecurefunc("SetItemButtonDesaturated", UpdateLock)
end

-- Parse chat input arguments
local parse = function(msg)
msg = string_gsub(msg, "^%s+", "") -- Remove spaces at the start.
msg = string_gsub(msg, "%s+$", "") -- Remove spaces at the end.
msg = string_gsub(msg, "%s+", " ") -- Replace all space characters with single spaces.
if (string_find(msg, "%s")) then
return string_split(" ", msg) -- If multiple arguments exist, split them into separate return values.
else
return msg
end
end

local command = "setgarbage"
local name = string_upper(Addon.."_CHATCOMMAND_"..command) -- Create a unique uppercase name for the command.
_G["SLASH_"..name.."1"] = "/"..command -- Register the chat command, keeping it lowercase.

-- Add the slash command function
_G.SlashCmdList[name] = function(msg, editBox)
local updateNeeded
local command, arg = parse(string_lower(msg))
if (command == "alpha") then
local alpha = tonumber(arg)
if (alpha and alpha >= 0 and alpha <= 1) then
local oldAlpha = BlizzardBags_Garbage_DB.darkenAlpha
if (alpha ~= oldAlpha) then
BlizzardBags_Garbage_DB.darkenAlpha = alpha
updateNeeded = true
end
end
elseif (command == "desaturate") then
local desaturate = BlizzardBags_Garbage_DB.desaturate
if (arg == "on") then
if (not desaturate) then
BlizzardBags_Garbage_DB.desaturate = true
updateNeeded = true
end
elseif (arg == "off") then
if (desaturate) then
BlizzardBags_Garbage_DB.desaturate = false
updateNeeded = true
end
end
elseif (command == "darken") then
local darken = BlizzardBags_Garbage_DB.darken
if (arg == "on") then
if (not darken) then
BlizzardBags_Garbage_DB.darken = true
updateNeeded = true
end
elseif (arg == "off") then
if (darken) then
BlizzardBags_Garbage_DB.darken = false
updateNeeded = true
end
end
end
if (updateNeeded) then
UpdateAll()
end
end

end

-- Setup the environment
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.25-Release] 2023-10-25
### Added
- Added chat commands to adjust garbage settings.
- `/setgarbage desaturate on` - turn desaturation on
- `/setgarbage desaturate off` - turn desaturation off
- `/setgarbage darken on` - turn garbage darkening layer on
- `/setgarbage darken off` - turn garbage darkening layer off
- `/setgarbage alpah n` - sets darkening layer opacity to `n` (replace with a number between 0 and 1)

## [1.0.24-Release] 2023-10-11
- Updated for WoW Client Patch 3.4.3.

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
This is a simple addon that tones down and desaturates garbage and vendor trash in your backpack, bank and bags.

## Chat Commands
- **/setgarbage desaturate on** _- Enable the garbage desaturation._
- **/setgarbage desaturate off** _- Disable the garbage desaturation._
- **/setgarbage darken on** _- Enable the garbage darkening._
- **/setgarbage darken off** _- Disable the garbage darkening._
- **/setgarbage alpha `n`** _- Sets the level of darkening to `n` (a number from 0 to 1)._

## Sponsor
- GitHub: [github.com/sponsors/goldpawsstuff](https://github.com/sponsors/goldpawsstuff)
- Patreon: [patreon.com/goldpawsstuff](https://www.patreon.com/goldpawsstuff)
Expand Down

0 comments on commit e7b8ec4

Please sign in to comment.