WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Drag'm drop and tooltip conflict (https://www.wowinterface.com/forums/showthread.php?t=59199)

Benalish 08-26-22 06:53 AM

Drag'm drop and tooltip conflict
 
The goal is to create a very simple addon able to keep track of the materials I want to farm. ATM, however, there are two contrasting effects: if I enable drag'n drop in the buttons (drag the item from the bag to the button, in order to keep track of it), the object tooltip is not displayed. By setting the "hidden" parameter to "true" in XML code, the tooltip becomes visible but it is no longer possible to drag 'n dop.
Is it possible to resolve this conflict?

LUA code:

Lua Code:
  1. function UnitFarm:barUpdate() -- Bar group creation
  2.     for b, key in ipairs(db.profile["Bars"]) do
  3.         local f = _G["UnitFarm_Frame"..b] or CreateFrame("Frame", "UnitFarm_Frame"..b, UIParent, "UnitFarm_BarTemplate", b)
  4.         local scale = db.profile["Bars"][b].dimension
  5.         if (b == 1) then
  6.             f:SetPoint("CENTER",nil,"CENTER")
  7.         else
  8.             local abscissa = (b - 1) * (64 * scale)
  9.             local ordinate = (b - 1) * (72 * scale)
  10.             f:SetPoint("LEFT", nil, "LEFT", abscissa, ordinate)
  11.         end
  12.         db.profile["Bars"][b]["name"] = "Icon bar\32"..b
  13.         f:SetScale(scale)
  14.         if (not db.profile.Bars[b]["anchor"]) then db.profile.Bars[b]["anchor"] = {} end
  15.         local a = db.profile.Bars[b].anchor
  16.         if a.dragged then
  17.             f:ClearAllPoints()
  18.             f:SetPoint(a.point, nil, a.relative, a.x, a.y)
  19.         end
  20.         local total = db.profile["Bars"][b].columns * db.profile["Bars"][b].rows
  21.         UnitFarm:iconUpdate(total, f)
  22.         UnitFarm:iconLocation(b)
  23.     end
  24. end
  25.  
  26. function UnitFarm:iconUpdate(total, frm)
  27.     local bar = frm:GetID()
  28.     for i = 1, total do
  29.         local f = UnitFarm:icon(bar, i) or CreateFrame("Button", frm:GetName().."UnitFarm_Icon"..i, frm, "UnitFarm_IconTemplate", i)
  30.         if (i == 1) then
  31.             f:SetPoint("LEFT",150,0)
  32.         else
  33.             local j = i - 1
  34.             f:SetPoint("TOPLEFT", UnitFarm:icon(j, bar) ,"TOPRIGHT",0,0)
  35.         end
  36.         f:RegisterForClicks("LeftButtonUp")
  37.  
  38.         local tooltip = f.tooltip
  39.         tooltip:SetScript("OnEnter", function(self, button)
  40.             GameTooltip:SetOwner(tooltip, "ANCHOR_CURSOR")
  41.             GameTooltip:AddLine(db.profile["Bars"][frm:GetID()][i].item)
  42.             GameTooltip:Show()
  43.             end
  44.         )
  45.         tooltip:SetScript("OnLeave", function(self, button)
  46.                 GameTooltip:Hide()
  47.             end
  48.         )
  49.         local function onReceive(self)
  50.             local infoType, arg1, arg2 = GetCursorInfo()
  51.             if infoType=="item" then
  52.             print(infoType, arg1, arg2)
  53.             local itemName, _, _, _, _, _, _, _, _, itemTexture = GetItemInfo(arg2)
  54.             db.profile["Bars"][frm:GetID()][i].item = itemName
  55.             ClearCursor()
  56.             end
  57.         end
  58.        
  59.         f:SetScript("OnReceiveDrag",onReceive)
  60.         f:SetScript("OnClick",onReceive)
  61.        
  62.         local columns = db.profile["Bars"][bar]["columns"]
  63.         local rows = db.profile["Bars"][bar]["rows"]
  64.         local width = (f:GetWidth() * columns) + (db.profile.Hspacing * (columns - 1)) - 1
  65.         local height = (f:GetHeight() * rows) - (db.profile.Vspacing * (rows - 1)) - 1
  66.         frm:SetClampRectInsets(0, width, 0, -height)
  67.         f.charge:SetFont("Fonts\\FRIZQT__.TTF", 24, "OUTLINE")
  68.         f.charge:SetTextColor(0.25,0.78,0.92)
  69.     end
  70. end

XML code:

Code:

<Button name="UnitFarm_IconTemplate" virtual="true" enableMouse="true" enableKeyboard="true">
    <Size>
        <AbsDimension x="48" y="48"/>
    </Size>
    <Layers>
        <!-- <Layer level="HIGHLIGHT">
            <Texture name="$parentHighlight" parentKey="highlight" file="Interface\Buttons\CheckButtonHilight" alphaMode="ADD" setAllPoints="true">
                <Size>
                    <AbsDimension x="30" y="30"/>
                </Size>
            </Texture>
        </Layer> -->
                <Layer level="ARTWORK">
                                <Texture name="$parentIcon" parentKey="texture" file="Interface\PaperDoll\UI-Backpack-EmptySlot.blp" setAllPoints="true">
                                        <Anchor point="TOPLEFT" relativeTo="$parent" relativePoint="TOPLEFT"/>
                                </Texture>
                        </Layer>
                        <Layer level="OVERLAY">
                                <FontString name="$parentCharge" parentKey="charge" inherits="GameFontNormal" justifyH="RIGHT">
                                        <Anchors>
                                                <Anchor point="BOTTOMRIGHT" relativeTo="$parent" relativePoint="BOTTOMRIGHT">
                                                        <Offset>
                                                                <AbsDimension x="-2" y="2"/>
                                                        </Offset>
                                                </Anchor>
                                        </Anchors>
                                </FontString>
                        </Layer>
    </Layers>
    <Scripts>
                <OnLoad>
                        self:RegisterForDrag("LeftButton");
                </OnLoad>
        <OnDragStart>
            self:GetParent():StartMoving();
        </OnDragStart>
        <OnDragStop>
                        UnitFarm:OnDragStop(self, button);
        </OnDragStop>
        <OnMouseDown>
            UnitFarm_ButtonOnMouseDown(self, button);
        </OnMouseDown>
                <OnHide>
                    self:GetParent():StopMovingOrSizing();
        </OnHide>
    </Scripts>
    <Frames>
        <Frame name="$parent_UnitFarmDropDown" inherits="UIDropDownMenuTemplate" enableMouse="true" hidden="true">
            <Anchors>
                <Anchor point="TOP"/>
            </Anchors>
            <Scripts>
                <OnLoad>
                    UnitFarm_DropDownOnLoad(self)
                </OnLoad>
                <OnShow>
                    UnitFarm_DropDownOnLoad(self)
                </OnShow>
            </Scripts>
        </Frame>
                <Frame name="$parentTooltip" parentKey="tooltip" enableMouse="true" setAllPoints="true" hidden="true"/>
    </Frames>
        <!-- <HighlightTexture alphaMode="ADD" file="Interface\Buttons\ButtonHilight-Square"/> -->
</Button>


SDPhantom 08-26-22 01:02 PM

I would have your OnEnter handler check CursorHasItem() and show the tooltip if you're not holding one. Additionally have onReceive() show the tooltip when it's done processing the cursor.

Alternatively, you can just let the tooltip show what the button is already set to and have onReceive() update it.

Benalish 08-26-22 02:05 PM

Tooltip is not displayed yet

Lua Code:
  1. local tooltip = f.tooltip
  2. tooltip:SetScript("OnEnter", function(self, button)
  3.     if (CursorHasItem() == false) then
  4.         GameTooltip:SetOwner(tooltip, "ANCHOR_CURSOR")
  5.         GameTooltip:AddLine(db.profile["Bars"][frm:GetID()][i].item)
  6.         GameTooltip:Show()
  7.         end
  8.     end
  9.     )
  10. tooltip:SetScript("OnLeave", function(self, button)
  11.     GameTooltip:Hide()
  12. end)
  13.  
  14. local function onReceive(self)
  15.     GameTooltip:Show()
  16.     local infoType, arg1, arg2 = GetCursorInfo()
  17.     if infoType=="item" then
  18.     local itemName, _, _, _, _, _, _, _, _, itemTexture = GetItemInfo(arg2)    
  19.     db.profile["Bars"][frm:GetID()][i].item = itemName 
  20.     ClearCursor()  
  21.     end
  22. end

SDPhantom 08-27-22 09:01 AM

Quote:

Originally Posted by SDPhantom (Post 340914)
show the tooltip when it's done processing the cursor.

Code:

local function onReceive(self)
        GameTooltip:Show()
        local infoType, arg1, arg2 = GetCursorInfo()
        if infoType=="item" then
        local itemName, _, _, _, _, _, _, _, _, itemTexture = GetItemInfo(arg2)               
        db.profile["Bars"][frm:GetID()][i].item = itemName       
        ClearCursor()       
        end       
end

Lua Code:
  1. local function onReceive(self)
  2.     local infoType, arg1, arg2 = GetCursorInfo()
  3.     if infoType=="item" then
  4.         print(infoType, arg1, arg2)
  5.         local itemName, _, _, _, _, _, _, _, _, itemTexture = GetItemInfo(arg2)
  6.         db.profile["Bars"][frm:GetID()][i].item = itemName
  7.         ClearCursor()
  8.  
  9.         tooltip:GetScript("OnEnter")(tooltip, false);-- Calls your OnEnter handler above
  10.     end
  11. end
Note: See https://wowpedia.fandom.com/wiki/UIHANDLER_OnEnter for OnEnter handler args.


All times are GMT -6. The time now is 10:42 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI