actual drag and drop
This commit is contained in:
+1462
-1448
File diff suppressed because it is too large
Load Diff
+69
-40
@@ -1,8 +1,6 @@
|
|||||||
-- Guda Item Button
|
-- Local alias to the addon root table (must be defined before any usages below)
|
||||||
-- Handles item button display and interaction
|
|
||||||
|
|
||||||
local addon = Guda
|
local addon = Guda
|
||||||
|
|
||||||
-- Item button pool
|
-- Item button pool
|
||||||
local buttonPool = {}
|
local buttonPool = {}
|
||||||
local nextButtonID = 1
|
local nextButtonID = 1
|
||||||
@@ -11,6 +9,8 @@ local nextButtonID = 1
|
|||||||
local scanTooltip = CreateFrame("GameTooltip", "Guda_QuestScanTooltip", nil, "GameTooltipTemplate")
|
local scanTooltip = CreateFrame("GameTooltip", "Guda_QuestScanTooltip", nil, "GameTooltipTemplate")
|
||||||
scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
|
scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
|
||||||
|
|
||||||
|
-- (rollback) no custom drag-source tracking or target resolution; rely on Blizzard handlers
|
||||||
|
|
||||||
-- Check if an item is a quest item by scanning its tooltip
|
-- Check if an item is a quest item by scanning its tooltip
|
||||||
local function IsQuestItem(bagID, slotID)
|
local function IsQuestItem(bagID, slotID)
|
||||||
if not bagID or not slotID then return false end
|
if not bagID or not slotID then return false end
|
||||||
@@ -128,6 +128,10 @@ end
|
|||||||
function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCharName, matchesFilter, isReadOnly)
|
function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCharName, matchesFilter, isReadOnly)
|
||||||
self.bagID = bagID
|
self.bagID = bagID
|
||||||
self.slotID = slotID
|
self.slotID = slotID
|
||||||
|
-- Also set the Blizzard slot ID for compatibility with ContainerFrameItemButtonTemplate behavior
|
||||||
|
if self.SetID and slotID then
|
||||||
|
self:SetID(slotID)
|
||||||
|
end
|
||||||
self.itemData = itemData
|
self.itemData = itemData
|
||||||
self.isBank = isBank or false
|
self.isBank = isBank or false
|
||||||
self.otherChar = otherCharName
|
self.otherChar = otherCharName
|
||||||
@@ -138,14 +142,36 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
|
|||||||
matchesFilter = true
|
matchesFilter = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local countText = getglobal(self:GetName().."_Count")
|
-- Use Blizzard's default count fontstring (ContainerFrameItemButtonTemplate creates $parentCount)
|
||||||
|
local countText = getglobal(self:GetName().."Count")
|
||||||
local emptySlotBg = getglobal(self:GetName().."_EmptySlotBg")
|
local emptySlotBg = getglobal(self:GetName().."_EmptySlotBg")
|
||||||
|
|
||||||
-- Apply icon size setting
|
-- Apply icon size setting (nil-safe)
|
||||||
local iconSize = Guda.Modules.DB:GetSetting("iconSize") or addon.Constants.BUTTON_SIZE
|
local iconSize = 37
|
||||||
|
if addon and addon.Modules and addon.Modules.DB and addon.Modules.DB.GetSetting then
|
||||||
|
iconSize = addon.Modules.DB:GetSetting("iconSize") or iconSize
|
||||||
|
elseif Guda and Guda.Modules and Guda.Modules.DB and Guda.Modules.DB.GetSetting then
|
||||||
|
iconSize = Guda.Modules.DB:GetSetting("iconSize") or iconSize
|
||||||
|
end
|
||||||
|
if addon and addon.Constants and addon.Constants.BUTTON_SIZE then
|
||||||
|
iconSize = iconSize or addon.Constants.BUTTON_SIZE
|
||||||
|
end
|
||||||
self:SetWidth(iconSize)
|
self:SetWidth(iconSize)
|
||||||
self:SetHeight(iconSize)
|
self:SetHeight(iconSize)
|
||||||
|
|
||||||
|
-- Rollback behavior: drive visuals from cached itemData (DB) only
|
||||||
|
if itemData and itemData.texture then
|
||||||
|
self.hasItem = true
|
||||||
|
if SetItemButtonTexture then SetItemButtonTexture(self, itemData.texture) end
|
||||||
|
if SetItemButtonCount then SetItemButtonCount(self, itemData.count or 1) end
|
||||||
|
if emptySlotBg then emptySlotBg:Hide() end
|
||||||
|
else
|
||||||
|
self.hasItem = false
|
||||||
|
if SetItemButtonTexture then SetItemButtonTexture(self, nil) end
|
||||||
|
if SetItemButtonCount then SetItemButtonCount(self, 0) end
|
||||||
|
if emptySlotBg then emptySlotBg:Show() end
|
||||||
|
end
|
||||||
|
|
||||||
-- Resize empty slot background to match icon size (slightly larger to ensure coverage)
|
-- Resize empty slot background to match icon size (slightly larger to ensure coverage)
|
||||||
if emptySlotBg then
|
if emptySlotBg then
|
||||||
emptySlotBg:ClearAllPoints()
|
emptySlotBg:ClearAllPoints()
|
||||||
@@ -204,7 +230,12 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
|
|||||||
-- Apply icon font size setting to stack count text
|
-- Apply icon font size setting to stack count text
|
||||||
if countText and countText.GetFont then
|
if countText and countText.GetFont then
|
||||||
local font, _, flags = countText:GetFont()
|
local font, _, flags = countText:GetFont()
|
||||||
local fontSize = Guda.Modules.DB:GetSetting("iconFontSize") or 12
|
local fontSize = 12
|
||||||
|
if addon and addon.Modules and addon.Modules.DB and addon.Modules.DB.GetSetting then
|
||||||
|
fontSize = addon.Modules.DB:GetSetting("iconFontSize") or fontSize
|
||||||
|
elseif Guda and Guda.Modules and Guda.Modules.DB and Guda.Modules.DB.GetSetting then
|
||||||
|
fontSize = Guda.Modules.DB:GetSetting("iconFontSize") or fontSize
|
||||||
|
end
|
||||||
countText:SetFont(font, fontSize, flags)
|
countText:SetFont(font, fontSize, flags)
|
||||||
|
|
||||||
-- Adjust count text position based on icon size for better alignment
|
-- Adjust count text position based on icon size for better alignment
|
||||||
@@ -267,9 +298,15 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
|
|||||||
self.qualityBorder:SetBackdropBorderColor(0.2, 0.8, 1.0, 1)
|
self.qualityBorder:SetBackdropBorderColor(0.2, 0.8, 1.0, 1)
|
||||||
self.qualityBorder:Show()
|
self.qualityBorder:Show()
|
||||||
elseif itemData.quality and itemData.link then
|
elseif itemData.quality and itemData.link then
|
||||||
-- Check settings to determine if we should show borders
|
-- Check settings to determine if we should show borders (nil-safe)
|
||||||
local showEquipmentBorder = addon.Modules.DB:GetSetting("showQualityBorderEquipment")
|
local showEquipmentBorder, showOtherBorder
|
||||||
local showOtherBorder = addon.Modules.DB:GetSetting("showQualityBorderOther")
|
if addon and addon.Modules and addon.Modules.DB and addon.Modules.DB.GetSetting then
|
||||||
|
showEquipmentBorder = addon.Modules.DB:GetSetting("showQualityBorderEquipment")
|
||||||
|
showOtherBorder = addon.Modules.DB:GetSetting("showQualityBorderOther")
|
||||||
|
elseif Guda and Guda.Modules and Guda.Modules.DB and Guda.Modules.DB.GetSetting then
|
||||||
|
showEquipmentBorder = Guda.Modules.DB:GetSetting("showQualityBorderEquipment")
|
||||||
|
showOtherBorder = Guda.Modules.DB:GetSetting("showQualityBorderOther")
|
||||||
|
end
|
||||||
|
|
||||||
-- Default to true if settings not found
|
-- Default to true if settings not found
|
||||||
if showEquipmentBorder == nil then
|
if showEquipmentBorder == nil then
|
||||||
@@ -279,15 +316,25 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
|
|||||||
showOtherBorder = true
|
showOtherBorder = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if item is equipment
|
-- Check if item is equipment (nil-safe)
|
||||||
local isEquipment = addon.Modules.Utils:IsEquipment(itemData.link)
|
local isEquipment = false
|
||||||
|
if addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.IsEquipment then
|
||||||
|
isEquipment = addon.Modules.Utils:IsEquipment(itemData.link)
|
||||||
|
elseif Guda and Guda.Modules and Guda.Modules.Utils and Guda.Modules.Utils.IsEquipment then
|
||||||
|
isEquipment = Guda.Modules.Utils:IsEquipment(itemData.link)
|
||||||
|
end
|
||||||
|
|
||||||
-- Determine if we should show the border based on item type and settings
|
-- Determine if we should show the border based on item type and settings
|
||||||
local shouldShowBorder = (isEquipment and showEquipmentBorder) or (not isEquipment and showOtherBorder)
|
local shouldShowBorder = (isEquipment and showEquipmentBorder) or (not isEquipment and showOtherBorder)
|
||||||
|
|
||||||
if shouldShowBorder then
|
if shouldShowBorder then
|
||||||
-- Show colored border for all items (Poor, Common, Uncommon, Rare, Epic, etc.)
|
-- Show colored border for all items (Poor, Common, Uncommon, Rare, Epic, etc.)
|
||||||
local r, g, b = addon.Modules.Utils:GetQualityColor(itemData.quality)
|
local r, g, b = 1, 1, 1
|
||||||
|
if addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.GetQualityColor then
|
||||||
|
r, g, b = addon.Modules.Utils:GetQualityColor(itemData.quality)
|
||||||
|
elseif Guda and Guda.Modules and Guda.Modules.Utils and Guda.Modules.Utils.GetQualityColor then
|
||||||
|
r, g, b = Guda.Modules.Utils:GetQualityColor(itemData.quality)
|
||||||
|
end
|
||||||
self.qualityBorder:SetBackdropBorderColor(r, g, b, 1)
|
self.qualityBorder:SetBackdropBorderColor(r, g, b, 1)
|
||||||
self.qualityBorder:Show()
|
self.qualityBorder:Show()
|
||||||
else
|
else
|
||||||
@@ -519,23 +566,10 @@ function Guda_ItemButton_OnReceiveDrag(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Handle mouse-up to emulate Blizzard drop behavior on 1.12 where OnReceiveDrag may not always fire
|
-- Handle mouse-up to emulate Blizzard drop behavior on 1.12 where OnReceiveDrag may not always fire
|
||||||
function Guda_ItemButton_OnMouseUp(self, button)
|
-- (rollback) no custom OnMouseUp; rely on Blizzard default
|
||||||
-- Only handle left-button drops
|
|
||||||
if button ~= "LeftButton" then return end
|
|
||||||
|
|
||||||
-- Don't allow interaction with other characters' items or in read-only mode
|
-- OnMouseDown handler - pick up item when pressing mouse button (classic pattern)
|
||||||
if self.otherChar or self.isReadOnly then
|
-- (rollback) no custom OnMouseDown; rely on Blizzard default
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- If the cursor is holding an item, drop/swap into this slot
|
|
||||||
if CursorHasItem and CursorHasItem() then
|
|
||||||
PickupContainerItem(self.bagID, self.slotID)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Otherwise, normal click behavior is handled by OnClick
|
|
||||||
end
|
|
||||||
|
|
||||||
-- OnDragStop handler (optional cleanup)
|
-- OnDragStop handler (optional cleanup)
|
||||||
function Guda_ItemButton_OnDragStop(self)
|
function Guda_ItemButton_OnDragStop(self)
|
||||||
@@ -555,22 +589,18 @@ end
|
|||||||
-- OnClick handler
|
-- OnClick handler
|
||||||
function Guda_ItemButton_OnClick(self, button)
|
function Guda_ItemButton_OnClick(self, button)
|
||||||
-- Don't allow interaction with other characters' items or in read-only mode
|
-- Don't allow interaction with other characters' items or in read-only mode
|
||||||
if self.otherChar or self.isReadOnly then
|
if self.otherChar or self.isReadOnly then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Set the split callback
|
-- Set the split callback
|
||||||
self.SplitStack = ItemButton_SplitStack
|
self.SplitStack = ItemButton_SplitStack
|
||||||
|
|
||||||
-- Handle modified clicks first
|
-- Modified clicks
|
||||||
if IsShiftKeyDown() then
|
if IsShiftKeyDown() then
|
||||||
if button == "LeftButton" and self.hasItem then
|
if button == "LeftButton" and self.hasItem then
|
||||||
-- Shift+Left Click on stackable item: Show split stack dialog
|
-- Shift+Left Click on stackable item: Show split stack dialog
|
||||||
if self.itemData and self.itemData.count and self.itemData.count > 1 then
|
if self.itemData and self.itemData.count and self.itemData.count > 1 then
|
||||||
-- Get the actual stack count from the container
|
|
||||||
local _, count = GetContainerItemInfo(self.bagID, self.slotID)
|
local _, count = GetContainerItemInfo(self.bagID, self.slotID)
|
||||||
if count and count > 1 then
|
if count and count > 1 then
|
||||||
-- Open the stack split frame (positioned to the left)
|
|
||||||
OpenStackSplitFrame(count, self, "BOTTOMRIGHT", "TOPRIGHT")
|
OpenStackSplitFrame(count, self, "BOTTOMRIGHT", "TOPRIGHT")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -589,10 +619,9 @@ function Guda_ItemButton_OnClick(self, button)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Normal clicks - handle item pickup/placement
|
|
||||||
if button == "LeftButton" then
|
if button == "LeftButton" then
|
||||||
-- Pick up or place item
|
-- Left clicks are handled by MouseDown/MouseUp to prevent instant self-drop.
|
||||||
PickupContainerItem(self.bagID, self.slotID)
|
return
|
||||||
elseif button == "RightButton" then
|
elseif button == "RightButton" then
|
||||||
-- Right click: Use item (only if slot has an item)
|
-- Right click: Use item (only if slot has an item)
|
||||||
if self.hasItem then
|
if self.hasItem then
|
||||||
@@ -607,4 +636,4 @@ function Guda_ReleaseAllButtons()
|
|||||||
button:Hide()
|
button:Hide()
|
||||||
button:ClearAllPoints()
|
button:ClearAllPoints()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
+9
-28
@@ -1,7 +1,7 @@
|
|||||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
|
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
|
||||||
|
|
||||||
<!-- Item Button Template -->
|
<!-- Item Button Template (inherit Blizzard container item button for classic behavior/skins) -->
|
||||||
<Button name="Guda_ItemButtonTemplate" virtual="true" inherits="ItemButtonTemplate">
|
<Button name="Guda_ItemButtonTemplate" virtual="true" inherits="ContainerFrameItemButtonTemplate">
|
||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="37" y="37"/>
|
<AbsDimension x="37" y="37"/>
|
||||||
</Size>
|
</Size>
|
||||||
@@ -16,9 +16,8 @@
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
</Texture>
|
</Texture>
|
||||||
</Layer>
|
</Layer>
|
||||||
|
|
||||||
|
<!-- Custom item count (this intentionally co-exists with Blizzard's $parentCount in rollback state) -->
|
||||||
<!-- Item count -->
|
|
||||||
<Layer level="OVERLAY">
|
<Layer level="OVERLAY">
|
||||||
<FontString name="$parent_Count" inherits="NumberFontNormal" justifyH="RIGHT">
|
<FontString name="$parent_Count" inherits="NumberFontNormal" justifyH="RIGHT">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
@@ -34,31 +33,13 @@
|
|||||||
|
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnLoad>
|
<OnLoad>
|
||||||
|
-- Our visual setup
|
||||||
Guda_ItemButton_OnLoad(this)
|
Guda_ItemButton_OnLoad(this)
|
||||||
this:RegisterForDrag("LeftButton")
|
-- Ensure Blizzard default container item button behavior is active
|
||||||
this:RegisterForClicks("LeftButtonUp", "RightButtonUp")
|
if ContainerFrameItemButton_OnLoad then
|
||||||
|
ContainerFrameItemButton_OnLoad()
|
||||||
|
end
|
||||||
</OnLoad>
|
</OnLoad>
|
||||||
<OnEnter>
|
|
||||||
Guda_ItemButton_OnEnter(this)
|
|
||||||
</OnEnter>
|
|
||||||
<OnLeave>
|
|
||||||
Guda_ItemButton_OnLeave(this)
|
|
||||||
</OnLeave>
|
|
||||||
<OnClick>
|
|
||||||
Guda_ItemButton_OnClick(this, arg1)
|
|
||||||
</OnClick>
|
|
||||||
<OnMouseUp>
|
|
||||||
Guda_ItemButton_OnMouseUp(this, arg1)
|
|
||||||
</OnMouseUp>
|
|
||||||
<OnDragStart>
|
|
||||||
Guda_ItemButton_OnDragStart(this, arg1)
|
|
||||||
</OnDragStart>
|
|
||||||
<OnDragStop>
|
|
||||||
Guda_ItemButton_OnDragStop(this)
|
|
||||||
</OnDragStop>
|
|
||||||
<OnReceiveDrag>
|
|
||||||
Guda_ItemButton_OnReceiveDrag(this)
|
|
||||||
</OnReceiveDrag>
|
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user