Thread Tools Display Modes
11-02-16, 07:56 AM   #1
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
need global Firering of MouseClick

1. What i want
===========
Open a Window when clicking a Merchats Item

I tried to:
========
WorldFrame:SetScript("OnMouseDown",BuyWin.Check)
- it is fired, when I click in teh World and the Merchant, but neither the Items nor the Merchant Window Itself

MerchantFrame:RegisterForClicks("LeftButtonDown", "RightButtonDown")
- is only Fired, when i click on the window of the Merchant, but not its Items
- it would be nice to get this with its childreen

My Only solution would be
to get each item an own handler
frame:RegisterEvent("MERCHANT_SHOW")
frame:SetScript("OnMouseDown",Merchant.Init)
function Merchant:Init(event,frame)
for i=1,frame:GetMerchantNumItems() do
.... Prozedur for it ...
mergant_item:SetScript("OnMouseDown",BuyWin.Check)
end
end

Is it able to find a smarter procedur ?

Well in global world i can get info everywhere with getMouseFocus():GetName(), so it should be able to get known if the MouseButton is pressed independent who i am.
  Reply With Quote
11-02-16, 08:42 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
You might be able to create a frame that covers the whole screen and set it to propagate mouse clicks. (or maybe that was for key presses only?)

What are you wanting to do with this? There might be a different solution.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
11-02-16, 08:50 AM   #3
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
There is a trader wehre you can only buy 1 Item and have to confirm another window.
If you want more. it will be a lot of clicks.

my code without windows is here:
Lua Code:
  1. SLASH_BUY1 = '/buy'
  2. local traderopen=false
  3. local version = "2016-10-27 14:06"
  4.  
  5. local frame = CreateFrame("Frame")
  6. frame:RegisterEvent("CHAT_MSG_SAY")
  7. frame:RegisterEvent("MERCHANT_SHOW")
  8. frame:RegisterEvent("MERCHANT_CLOSED")
  9.  
  10. frame:SetScript("OnEvent", function(self, event, arg1, arg2)
  11.     if (event=="MERCHANT_SHOW") then
  12.         -- print("MERCHANT_SHOW")
  13.         frame:MERCHANT_SHOW();
  14.     end
  15.     if (event=="MERCHANT_CLOSED") then
  16.         -- print("MERCHANT_CLOSED")
  17.         frame:MERCHANT_CLOSED();
  18.     end
  19. end)
  20. function frame:MERCHANT_CLOSED ()
  21.     -- print("Händler zu")
  22.     traderopen=false;
  23. end
  24. function frame:MERCHANT_SHOW ()
  25.     -- print("Händler offen")
  26.     traderopen=true;
  27. end
  28.  
  29. local function buy(count,name)
  30.     local found=false
  31.     for i=1,100 do
  32.         if name==GetMerchantItemInfo(i) then
  33.             BuyMerchantItem(i,count)
  34.             found=true
  35.         end
  36.     end
  37.     return found
  38. end
  39. function printinfo(text)
  40.     print ("------------------------")
  41.     print (text)
  42. end
  43.  
  44. function SlashCmdList.BUY(msg, editbox)
  45.     -- print("Buy Test")
  46.     if traderopen == false then
  47.         printinfo("Bitte erst einen Händler ansprechen.\nSyntax: /buy [Anzahl] [Name des Artikels]")
  48.         return
  49.     end
  50.     local count, rest = msg:match("^(%S*)%s*(.-)$")
  51.  
  52.     if (rest == "") or (count == "")  then
  53.         printinfo("Bitte eine gültige Anzahl und Namen der Waren angeben, die der Händler Verkauft.\n\nSyntax: /buy [Anzahl] [Name des Artikels]")
  54.     else
  55.         -- print "Starte Einkauf"
  56.         -- All mistakes testet , we can start
  57.         if buy(count,rest) == false then
  58.             printinfo("Den Namen der Ware \""..rest.."\" verkauft der Händler leider nicht.\n\nSyntax: /buy [Anzahl] [Name des Artikels]")
  59.         end
  60.     end
  61.    
  62. end

so I want to do my own window by SHIFT and Mousclick on one Iem

EDIT:
I have tried an Overlay window:
shown: you cannot click anything else anymore
hidden: like there is no window
and i have also seen WoldFrame is not the Screensize, only a part

Last edited by FreeXerxes : 11-02-16 at 09:53 AM.
  Reply With Quote
11-02-16, 10:16 AM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
You could hook MerchantItemButton_OnClick or MerchantItemButton_OnModifiedClick.

https://www.townlong-yak.com/framexm...ntFrame.xml#34
https://www.townlong-yak.com/framexm...tFrame.lua#442
https://www.townlong-yak.com/framexm...tFrame.lua#481
__________________
Grab your sword and fight the Horde!
  Reply With Quote
11-02-16, 10:31 AM   #5
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
OK Nice that works!
is it possible to continue with the original procedure ?

Answere is Easy: Save the orginal and return it.

Here my Solution:
lua Code:
  1. local org_MerchantItemButton_OnModifiedClick = MerchantItemButton_OnModifiedClick;
  2. function MerchantItemButton_OnModifiedClick(self,button)  
  3.     print("Clicked")
  4.     return org_MerchantItemButton_OnModifiedClick(self,button)
  5. end


Thank you for your fast help, it saved me more hundrets of hours

Can be Closed!

Last edited by FreeXerxes : 11-02-16 at 11:15 AM.
  Reply With Quote
11-02-16, 12:55 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
You should use hooksecurefunc() whenever possible to prevent spreading taint.
Code:
hooksecurefunc("MerchantItemButton_OnModifiedClick",function()
	print("Clicked");
end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-04-16, 09:03 AM   #7
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
@SDPhantom:
hooksecure procedure begins after the function is already finished,
so I will have 2 input windows, that is not what i want,
but it will help for maybe other functions.

For this example of course it works fine.
  Reply With Quote
11-04-16, 12:55 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
If you're looking to disable confirmation windows, you should modify each StaticPopupDialog entry instead.

Lua Code:
  1. local function AutoAccept(self,data)
  2.     local entry=StaticPopupDialogs[self.which];
  3.     if entry.OnAccept then
  4.         entry.OnAccept(self,data,self.data2);
  5.     elseif entry.OnCancel then
  6.         entry.OnCancel(self,data,"clcked");
  7.     end
  8.     self:Hide();
  9. end
  10.  
  11. StaticPopupDialogs.CONFIRM_PURCHASE_TOKEN_ITEM.OnShow=AutoAccept;
  12. StaticPopupDialogs.CONFIRM_PURCHASE_NONREFUNDABLE_ITEM.OnShow=AutoAccept;
  13. StaticPopupDialogs.CONFIRM_HIGH_COST_ITEM.OnShow=AutoAccept;



If you're complaining about the SplitStackFrame popping up, that's just your choice in using Shift-Click to bypass the confirmation windows as that's used to split stacks when the chat window isn't open.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-04-16 at 01:01 PM.
  Reply With Quote
11-05-16, 07:58 PM   #9
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
Thanks for the nice Code. but that is not what i want for my Addon.
Here my complete Code that works fine, that you see what I mean, SDPhantom


There is a trader, wehre you can only buy one item (or the given amount) and you cannot use the SHIFT Click on this trader. I want to enabele this with my own input Window.


Lua Code:
  1. --[[
  2. Lua Fenster erstellen
  3. --]]
  4. -------------------
  5. -- Global Variables
  6. -------------------
  7. SLASH_BUYWIN1 = '/buywin'
  8. SLASH_BUYWIN2 = '/bw'
  9.  
  10. BuyWin = {}
  11. local traderopen=false -- Händler ist offen
  12. local tradeitem=nil    -- Laufende nummer vom Händler
  13. -- local tradeitemtexture = nil -- angeklicktes Item
  14. local enabled=true      -- Addon ist Aktiv
  15.  
  16.  
  17. function BuyWin:GetDisplay(text)
  18.     local displays=
  19.     {
  20.         ["deDE"] = {
  21.             ["ok"] = "OK",
  22.             ["cancel"] = "Abbrechen",
  23.             ["active"] = "BuyWin ist jetzt aktiv!",
  24.             ["inactive"] = "BuyWin ist jetzt inaktiv!",
  25.             ["ver"] = "Du benutzt BuyWin Version ",
  26.             ["help"] = "schaltet das AddOn aus oder an"    
  27.         },
  28.         ["enGB"] = {
  29.             ["ok"] = "OK",
  30.             ["cancel"] = "Cancel",
  31.             ["active"] = "BuyWin is now active!",
  32.             ["inactive"] = "BuyWin is now inactive!",
  33.             ["ver"] = "Your are using BuyWin Version ",
  34.             ["help"] = "switches the AddOn off or on"  
  35.         }
  36.     }
  37.     lang=GetLocale()
  38.     if displays[lang]==nil then
  39.         lang="enGB"
  40.     end
  41.     return  displays[lang][text]
  42. end
  43.  
  44.  
  45. ------------------
  46. -- Display Window
  47. ------------------
  48. function BuyWin:CloseWindow()
  49.     edt_amount:SetText("")
  50.     BuyFrame:Hide()
  51. end
  52.  
  53. function BuyWin:OpenWindow()
  54.     BuyFrame:SetFrameStrata("HIGH")
  55.    
  56.     local x, y = BuyWin:GetFramePosition();    
  57.     BuyFrame:SetPoint("BOTTOMLEFT",x+20,y-120)
  58.    
  59.     BuyFrame:Show()
  60.  
  61. end
  62.  
  63. function BuyWin:GetFramePosition()
  64.     local x, y = GetCursorPosition();      
  65.     x=  x*UIParent:GetWidth()/WorldFrame:GetWidth()
  66.     y=  y*UIParent:GetHeight()/WorldFrame:GetHeight()
  67.     return x,y
  68. end
  69.  
  70. ------------------
  71. -- Setup
  72. ------------------
  73. function BuyWin:Init(event, addon)     
  74.     if event == "ADDON_LOADED" and addon == "BuyWin" then
  75.         BuyWin:CreateGUI(BuyFrame)
  76.     end
  77.     if event == "MERCHANT_SHOW" then
  78.         edt_amount:SetText("")
  79.         traderopen=true
  80.     end
  81.     if event=="MERCHANT_CLOSED" then
  82.         BuyWin:CloseWindow()
  83.         traderopen=false;
  84.     end
  85.    
  86.     return 
  87. end
  88.  
  89.  
  90.  
  91.  
  92. ------------------
  93. -- Hook Merchant
  94. ------------------
  95.  
  96. local org_MerchantItemButton_OnModifiedClick = MerchantItemButton_OnModifiedClick;
  97. function MerchantItemButton_OnModifiedClick(self,button)  -- Buttonframe, used Button: LeftButton/RightButton
  98.     if ( MerchantFrame.selectedTab == 1 ) and IsShiftKeyDown() and enabled and GetCurrentKeyBoardFocus()==nil then 
  99.         local mouseFocus=GetMouseFocus()
  100.         tradeitem     = mouseFocus:GetID() --Laufende Nummer
  101.         name, texture, price, quantity, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(tradeitem)
  102.         BuyWin:SetIcon(texture)
  103.         BuyWin:OpenWindow()
  104.  
  105.         return
  106.     end    
  107.     return org_MerchantItemButton_OnModifiedClick(self,button)
  108. end
  109.  
  110. ------------------
  111. -- Fenster
  112. ------------------
  113. function BuyWin:CreateGUI(f)
  114.     y=10
  115.     yd=y+30
  116.     local frame        = BuyWin:CreateWindow(f)
  117.  
  118.     local btn_OK       = BuyWin:CreateButton(frame, "btn_OK",BuyWin:GetDisplay("ok"),80,24,"BOTTOM",-50,y)
  119.     btn_OK:SetScript("OnClick",function(self) BuyWin:evt_BuyNow()  end)
  120.  
  121.     --local btn_break    = BuyWin:CreateButton(frame, "btn_break","Abbrechen",80,24,"BOTTOM",50,y)
  122.     local btn_break    = BuyWin:CreateButton(frame, "btn_break",BuyWin:GetDisplay("cancel"),80,24,"BOTTOM",50,y)
  123.     btn_break:SetScript("OnClick",function(self) BuyWin:CloseWindow() end)
  124.  
  125.     local btn_less     = BuyWin:CreateButton(frame, "btn_less","<",24,24,"BOTTOM",-80,yd)
  126.     btn_less:SetScript("OnClick",function(self) BuyWin:evt_ChangeAmount(-1) end)
  127.  
  128.     local btn_more     = BuyWin:CreateButton(frame, "btn_more",">",24,24,"BOTTOM",80,yd)
  129.     btn_more:SetScript("OnClick",function(self) BuyWin:evt_ChangeAmount(1) end)
  130.  
  131.     local edt_amount   = BuyWin:CreateEdit(frame, "edt_amount",100,24,"BOTTOM",0,yd)   
  132.    
  133.     local ico_item     = BuyWin:CreateIcon(frame, "ico_item","100",40,40,"TOP",0,y-20)
  134.     return frame
  135. end
  136.  
  137. function BuyWin:CreateWindow(frame)
  138.     frame:Hide()
  139.     frame:SetPoint("CENTER",0,0)    --Mittig setzen BOTTEMLEFT,TOPRIGHT / 0,0  = x und y verscheibung in negativ und Positiv richtung
  140.     frame:SetWidth(200)                   --Fenster breite
  141.     frame:SetHeight(120)                  --Fenster höhe
  142.     frame:SetBackdrop({
  143.         bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  144.         edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  145.         tile = true, tileSize = 16, edgeSize = 16,
  146.         insets = { left = 4, right = 4, top = 4, bottom = 4 }
  147.     });
  148.     frame:SetBackdropColor(0,0,0,1);    -- r,g,b, alpha (0-1)
  149.     return(frame)
  150. end
  151.  
  152.  
  153. function BuyWin:CreateButton(frame,name,text,width,height,position,x,y,template)
  154.     if position == nil then
  155.         position="TOPLEFT"
  156.     end
  157.    
  158.     if template == nil then
  159.         template="OptionsButtonTemplate"
  160.     end
  161.     if x == nil and y == nil then
  162.         position="CENTER"
  163.         x=0
  164.         y=0
  165.     elseif x == nil then
  166.         position="TOP"
  167.     elseif y == nil then
  168.         position="LEFT"
  169.     end
  170.    
  171.    
  172.    
  173.     local button=CreateFrame("Button",name,frame,template)
  174.     button:SetPoint(position,x,y)    --Mittig setzen BOTTEMLEFT,TOPRIGHT / 0,0  = x und y verscheibung in negativ und Positiv richtung
  175.     button:SetWidth(width)                   --Fenster breite
  176.     button:SetHeight(height)                  --Fenster höhe
  177.     button:SetText(text)
  178.     return (button)
  179. end
  180.  
  181. function BuyWin:CreateEdit(frame,name,width,height,position,x,y)
  182.     if position == nil then
  183.         position="TOPLEFT"
  184.     end
  185.    
  186.     if x == nil and y == nil then
  187.         position="CENTER"
  188.         x=0
  189.         y=0
  190.     elseif x == nil then
  191.         position="TOP"
  192.     elseif y == nil then
  193.         position="LEFT"
  194.     end
  195.        
  196.     local template = "InputBoxTemplate"
  197.     local edit = CreateFrame("EditBox",name,frame,template)
  198.    
  199.     edit:SetPoint(position,x,y)    --Mittig setzen BOTTEMLEFT,TOPRIGHT / 0,0  = x und y verscheibung in negativ und Positiv richtung
  200.     edit:SetWidth(width)                   --Fenster breite
  201.     edit:SetHeight(height)                  --Fenster höhe
  202.     edit:SetAutoFocus(false)
  203.     edit:Show()
  204.     return (edit)
  205. end
  206.  
  207. function BuyWin:CreateIcon(frame,name,icon,width,height,position,x,y)
  208.     if position == nil then
  209.         position="TOPLEFT"
  210.     end
  211.    
  212.     if x == nil and y == nil then
  213.         position="CENTER"
  214.         x=0
  215.         y=0
  216.     elseif x == nil then
  217.         position="TOP"
  218.     elseif y == nil then
  219.         position="LEFT"
  220.     end
  221.  
  222.     local t = frame:CreateTexture(nil,"HIGH")
  223.     -- t:SetTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Factions.blp")
  224.     t:SetPoint(position,x,y)    --Mittig setzen BOTTEMLEFT,TOPRIGHT / 0,0  = x und y verscheibung in negativ und Positiv richtung
  225.     t:SetWidth(width)                   --Fenster breite
  226.     t:SetHeight(height)                  --Fenster höhe
  227.     frame.texture = t
  228.    
  229.     return (t)
  230. end
  231.  
  232. function BuyWin:SetIcon(texture)
  233.     BuyFrame.texture:SetTexture(texture)
  234. end
  235.  
  236. -- ---------
  237. -- Events
  238. -- ---------
  239. function BuyWin:evt_ChangeAmount(operator)
  240.     local n=edt_amount:GetText()
  241.     if not string.match(n,"^[0-9]+$") then
  242.         edt_amount:SetText(0)
  243.     end
  244.    
  245.     if (edt_amount:GetText()+operator)<0 then
  246.         operator=0;
  247.     end
  248.    
  249.     edt_amount:SetText(edt_amount:GetText()+operator)
  250. end
  251.    
  252. function BuyWin:evt_BuyNow()
  253.  
  254.     local amount=edt_amount:GetText()
  255.     if not string.match(amount,"^[0-9]+$") then
  256.         return
  257.     end
  258.     if amount == "0" then
  259.         return
  260.     end
  261.     if tradeitem == nil then
  262.         return
  263.     end
  264.    
  265.     -- confirm 
  266.     local name=GetMerchantItemInfo(tradeitem)  
  267.     BuyMerchantItem(tradeitem,amount)
  268.     BuyWin:CloseWindow()
  269.     return found
  270.    
  271. end
  272.  
  273. -- --------------
  274. -- Events an/aus
  275. -- --------------
  276. function BuyWin:Toggle(b)
  277. -- print ("b=" .. b)
  278.  
  279.     -- Toggle ohne Parameter
  280.     if b == nil then
  281.         if enabled then
  282.             b=false
  283.         else
  284.             b=true
  285.         end
  286.     end
  287.  
  288.     enabled=b
  289.    
  290.     if b == true then
  291.         --Toggle
  292.         BuyFrame:RegisterEvent("MERCHANT_SHOW")
  293.         BuyFrame:RegisterEvent("MERCHANT_CLOSED")
  294.         -- print("BuyWin ist nun aktiv!")
  295.        
  296.         print(BuyWin:GetDisplay("active"))
  297.     else
  298.         -- Unegister
  299.         BuyFrame:UnregisterEvent("MERCHANT_SHOW")
  300.         BuyFrame:UnregisterEvent("MERCHANT_CLOSED")
  301.  
  302.         print(BuyWin:GetDisplay("inactive"))
  303.     end
  304. end
  305.  
  306. function SlashCmdList.BUYWIN(msg, editbox)
  307.     local cmd, rest = msg:match("^(%S*)%s*(.-)$")
  308.    
  309.     if cmd == "toggle" then
  310.         BuyWin:Toggle()
  311.     elseif cmd == "on" then
  312.         BuyWin:Toggle(true)
  313.     elseif cmd == "off" then
  314.         BuyWin:Toggle(false)
  315.     elseif cmd == "ver" then
  316.         name, title, notes, enabled, loadable, reason, security = GetAddOnInfo("BuyWin")
  317.         version = GetAddOnMetadata("BuyWin", "Version")
  318.         print(BuyWin:GetDisplay("ver") .. version)
  319.     else
  320.         print(BuyWin:GetDisplay("help"))
  321.         print("Syntax:")
  322.         print("/BW [toggle|on|off|ver]")
  323.         print("/BUYWIN [toggle|on|off|ver]")
  324.     end
  325.    
  326. end
  327.  
  328.  
  329. -- ---------
  330. -- Main Part
  331. -- ---------
  332.  
  333. local frame = CreateFrame("Frame","BuyFrame",UIParent)
  334. frame:SetScript("OnEvent",BuyWin.Init)
  335. frame:RegisterEvent("ADDON_LOADED") -- Beim Starten geladen
  336. frame:RegisterEvent("MERCHANT_SHOW")
  337. frame:RegisterEvent("MERCHANT_CLOSED")
  Reply With Quote
11-07-16, 01:43 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I didn't realize you're replacing the StackSplitFrame with your own to overcome the stack size limit. The main problem is the API doesn't like being given a number larger than the item's stack size and throws an internal error. One feature of the original StackSplitFrame is that it allows keybinds to pass through. However, this is done by calling a protected function, which will be tricky to preserve.

I believe the best course of action is to repurpose the original StackSplitFrame, but it will probably take heavy modifications to allow purchasing more than the stack limit. I'll see what I can come up with, but I'm not making any promises.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-07-16, 05:52 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I went with my own idea and decided to upload it. It ended up being a complete rewrite of Blizzard's StackSplitFrame. I was able to allow keybinds to run by switching frame:SetPropagateKeyboardInput() and I added a couple more control methods as well. It loops the callback to allow processing as many stacks as necessary, though there may be an undocumented limit to how many stacks can be purchased at once.

StackSplitPlus
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-07-16 at 05:55 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » need global Firering of MouseClick


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off