Skip to content

Commit

Permalink
Not overwriting gems anymore when clicking too fast
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsj02 committed May 18, 2024
1 parent 9008dbe commit f0da2e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ local function itemListInitializer(frame, data)
frame.Name:SetTextColor(rowColor:GetRGBA())
if isHeader then
local used, maxS = gemUtil:GetSocketsInfo(name)
local col = misc:getPercentColor(used / maxS * 100)
local col = misc:GetPercentColor(used / maxS * 100)
frame.Icon:SetDesaturated(false)
frame.Name:SetFontObject(const.FONT_OBJECTS.HEADING)
frame.Name:SetText(string.format("%s (%s%d/%d|r)", name, col:GenerateHexColorMarkup(), used, maxS))
Expand Down
32 changes: 20 additions & 12 deletions Misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
local Private = select(2, ...)
local const = Private.constants

local misc = {}
local misc = {
clickThrottles = {}
}
Private.Misc = misc

function misc:getPercentColor(percent)
---@param percent number
---@return ColorMixin
function misc:GetPercentColor(percent)
if percent == 100 then
return const.COLORS.POSITIVE
end
Expand All @@ -15,14 +19,18 @@ function misc:getPercentColor(percent)
return const.COLORS.NEGATIVE
end

function misc:MuteSounds() -- This doesn't seem to work on PlaySound() rn
MuteSoundFile(SOUNDKIT.IG_CHARACTER_INFO_OPEN)
MuteSoundFile(SOUNDKIT.IG_CHARACTER_INFO_CLOSE)
MuteSoundFile(SOUNDKIT.MAP_PING)
end

function misc:UnmuteSounds()
UnmuteSoundFile(SOUNDKIT.IG_CHARACTER_INFO_OPEN)
UnmuteSoundFile(SOUNDKIT.IG_CHARACTER_INFO_CLOSE)
UnmuteSoundFile(SOUNDKIT.MAP_PING)
---@param clickType any
---@return boolean
function misc:IsAllowedForClick(clickType)
local currentTime = GetTime()
if not self.clickThrottles[clickType] then
self.clickThrottles[clickType] = currentTime
return true
end
if self.clickThrottles[clickType] + .5 < currentTime then
self.clickThrottles[clickType] = currentTime
return true
end
UIErrorsFrame:AddExternalErrorMessage("You're clicking too fast")
return false
end
5 changes: 4 additions & 1 deletion UIElements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
local Private = select(2, ...)
local const = Private.constants
local gemUtil = Private.GemUtil
local misc = Private.Misc

local uiElements = {}
Private.UIElements = uiElements
local function extractPreClick(self)
if not misc:IsAllowedForClick("EXTRACT_PRECLICK") then return end
if not self.info then return end
local info = self.info
if info.locType == "SOCKET" then
Expand All @@ -19,6 +21,7 @@ local function extractPreClick(self)
end

local function extractPostClick(self)
if not misc:IsAllowedForClick("EXTRACT_POSTCLICK") then return end
if not self.info then return end
local info = self.info
if info.locType == "BAG" then
Expand All @@ -41,7 +44,7 @@ function uiElements:CreateExtractButton(parent)
extractButton:SetAllPoints()
extractButton:SetScript("PreClick", extractPreClick)
extractButton:SetScript("PostClick", extractPostClick)
extractButton:RegisterForClicks("AnyDown")
extractButton:RegisterForClicks("AnyDown", "AnyUp")
extractButton:SetAttribute("type", "macro")

function extractButton:UpdateInfo(newType, newIndex, newSlot, newGemType)
Expand Down

0 comments on commit f0da2e4

Please sign in to comment.