So, I am trying to make an addon that on left click marks your target with the raid target marker and on right click will let you place a world marker.
Problem is I do not think, or have read actually, that there is an actual API for this and you have to use the drop down, so far I have gotten around this by the code below, except if I try to use the square world marker or after I have used the Clear world marker I get a message:
"has been blocked from an action only available to the Blizzard UI"
After doing some reading I recalled having this issue with my set focus on a different addon and that fix was to use HookScript but it doesnt work here.
[HTML]local f = CreateFrame("Frame","WorldMarkerFrame",UIParent)
f:SetWidth(150) -- Set these to whatever height/width is needed
f:SetHeight(100) -- for your Texture
local t = f:CreateTexture(nil,"BACKGROUND")
f.texture = t
local WMClear = CreateFrame("Button","WorldMarker6Clear",f)
local tclear = WMClear:CreateTexture(nil,"BACKGROUND")
Ok so a workaround is to use macros and use /wm 1 - /wm 6 /cwm and /clearworldmarker do not seem to work in lua tho. I will triple check i didnt do something like /cmw.
Example of what works:
[HTML]--Square Marks Raid Marker 6 World Marker 1
local WMSquare = CreateFrame("Button","WorldMarker1Square",f, "SecureActionButtonTemplate")
WMSquare:SetWidth(50) -- Set these to whatever height/width is needed
WMSquare:SetHeight(50) -- for your Texture
local t = WMSquare:CreateTexture(nil,"BACKGROUND")
WMSquare.texture = t
WMSquare:HookScript("OnClick", function(self, button)
WMSquare:SetAttribute("macrotext1", "/wm 1")
Also, setting the click attribute inside an OnClick script won't accomplish anything. For one, by the time the OnClick script runs, the click has already happened, so it's too late for the attributes to do anything. For another, if you set an OnClick script at all on a button with action attributes, your OnClick script will override the attributes, and only the OnClick script will happen; if you want to add insecure actions, use PreClick or PostClick scripts instead.
The "SecureActionsButtonTemplate" seems to inherently block the use of the button or perhaps the response to button clicks in combat.
I have tried a couple of other methods to use the dropdown menu such as RunMacro and the first example I have psoted here. Setting attributes is the only method that works. Doesn't that require "SecureActionsButtonTemplate" as per its template, as in you have to define attributes?
here is my code change. I set attributes outside of the OnClick and that solved the issue where I had to click twice, heh, once to set and once to use.
Also, if I do not try to use the world markers, IE make it for the target markers only, then it works in and out of combat. If I get rid of the "SecureActionsButtonTemplate" then I do not have anything to define. Should I use a different template?
WMDiamond:HookScript("OnClick", function(self, button)
KeyHeld = (keystate=="down")
if KeyHeld then
local X, Y = GetCursorPosition()
local Scale = UIParent:GetEffectiveScale()
DejaMarkFrame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", X / Scale, Y / Scale)
... if you set an OnClick script at all on a button with action attributes, your OnClick script will override the attributes, and only the OnClick script will happen; if you want to add insecure actions, use PreClick or PostClick scripts instead.
Also, your action attributes do not match. "type" catches any click, but "macrotext1" defines a left click action. Either change "type" to "type1" if you want the button to only respond to left-click, or change "macrotext1" to "macrotext" if you want the button to respond to any click.
Finally, you get errors in combat because -- in addition to using an insecure OnClick script that overrides the secure action attributes -- you're using insecure methods to show or hide the buttons. You cannot call :Show() or :Hide() on a secure frame, or on any ancestor (parent, grandparent, etc.) of a secure frame. You need to use secure methods to hide/show the frame. For example, this will cause you frame to be shown only while Ctrl is pressed, and hidden at all other times:
local DejaMarkFrame = CreateFrame("Frame", "DejaMarkFrame", UIParent[B], "SecureHandlerStateTemplate"[/B])
RegisterStateDriver(mover, "visibility", "[mod:ctrl]show;hide")
If you want more complex visibility states (on mouseover, with a non-modifier key, etc) you'll have to look at some other addons for examples. OPie is one that springs to mind. I've never worked with secure show/hide stuff much, so I won't be able to help you with that aspect.
Ok ok so I feel like an idiot now, if I have the frame shown and set up when I enter combat everything works fine and dandy I am marking away etc. It is the actual showing hiding of the frame in combat that I am looking at. Gah so stupid.