Thread Tools Display Modes
08-12-13, 09:43 PM   #1
Lazare
An Aku'mai Servant
 
Lazare's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 36
worldmarker help

Back again with a new question and thanks all for the help on my macro question.

I am trying to add world marker buttons to my addon hosted here (Lei Shen Coordinator". I have looked at literally a dozen or so other addons for placing charms and markers but am so brain addled by looking at so much coding I am about to tear my hair out. Just for some background, I actually started out as a computer programmer back in the mid 70's and now am getting back into it thru xml / lua coding. I have spent hours looking things up on this website and via google until my eyes are sore.

I simply want a simple "press this button and world marker blue is on your cursor to place it." The same with green, purple and red (separate buttons and scripts for each).
I have many books in reg and PDF format but none deal with this and the addons that I have found make things so much more complicated to try to figure out which part is really doing the work of activating the marker for placement.

Thanks in advance for any help.
Lazare
  Reply With Quote
08-12-13, 10:13 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Lazare69 View Post
I simply want a simple "press this button and world marker blue is on your cursor to place it." The same with green, purple and red (separate buttons and scripts for each).
Placing world markers is a secure action, so you need a secure button:

Code:
local blue = CreateFrame("Button", "MyBlueWMButton", UIParent, "SecureActionButtonTemplate")

-- Set blue world marker on left-click:
blue:SetAttribute("type1", "worldmarker")
blue:SetAttribute("marker1", 1)
blue:SetAttribute("action1", "set")

-- Clear blue world marker on right-click:
blue:SetAttribute("type2", "worldmarker")
blue:SetAttribute("marker2", 1)
blue:SetAttribute("action2", "clear")
The above won't give you a visible button. If you want a visible button, you need to anchor and size the button, and add a texture/fontstring/etc.

To bind keys to "left-click" or "right-click" the button:

Code:
SetBinding("SHIFT-U", "CLICK MyBlueWMButton:LeftButton")
SetBinding("ALT-SHIFT-U", "CLICK MyBlueWMButton:RightButton")
To add entries to the key binding UI, add a Bindings.xml file to your addon:
Code:
<Bindings>
	<Binding name="CLICK MyBlueWMButton:LeftButton" header="MYWORLDMARKERS">
		-- Set blue marker
	</Binding>
	<Binding name="CLICK MyBlueWMButton:RightButton">
		-- Clear blue marker
	</Binding>
...and define the UI strings in Lua:
Code:
_G["BINDING_HEADER_MYWORLDMARKERS"] = "My World Markers"
_G["BINDING_NAME_CLICK MyBlueWMButton:LeftButton"] = "Set Blue Marker"
_G["BINDING_NAME_CLICK MyBlueWMButton:RightButton"] = "Clear Blue Marker"
See also FlareUP, which provides clickable and bindable buttons for all the world markers and some other features, and was the main source of the above example code snippets.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-13-13, 03:46 AM   #3
Lazare
An Aku'mai Servant
 
Lazare's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 36
Thanks for the quick reply. I kinda understand what you are saying but still in the dark somewhat on how to implement it. My buttons are defined (or made) thru XML which ties to functions in Lua, i.e.:
(The below are for my announcement buttons)
Code:
XML
<Button name="Button2a" inherits="UIPanelButtonTemplate" text="Blue">
				<Size>
					<AbsDimension x="50" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="25" y="-75" />
					</Anchor>
				</Anchors>
				  <FontHeight>
                <AbsValue val="12" />
              </FontHeight>
              <Color r="0" g="0" b="1" />
				<Scripts>
					<OnClick>Button2a_OnClick();</OnClick>
				</Scripts>
			</Button>


LUA:
function Button2a_OnClick()
	SendChatMessage('GRP 1 {square},  GRP 2 {cross}, GRP 3 {triangle}, GRP 4 {diamond}, GRP 5 SPREAD OUT' , "RAID", nil, id); 
end
So I am trying to figure out where to implement the code you provided. I really wish there was a better source of info on constructing addons than I have found so far. Trying to teach myself Lua/XML after not programming for 30 some years O.o Also, I am not worrying about trying to bind these to keys, so don't worry about that aspect of it to keep things simple.

Thanks again
  Reply With Quote
08-13-13, 06:54 AM   #4
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Define your buttons in XML like this:
Code:
<Button name="LeiShenCoordinator_BlueMarker" inherits="UIPanelButtonTemplate,SecureActionButtonTemplate" text="Blue">
	<Size>
		<AbsDimension x="50" y="23" />
	</Size>
	<Anchors>
		<Anchor point="TOPLEFT">
			<Offset x="25" y="-75" />
		</Anchor>
	</Anchors>
	<FontHeight>
		<AbsValue val="12" />
	</FontHeight>
	<Color r="0" g="0" b="1" />
	<Scripts>
		<OnLoad>
			LeiShenCoordinator_MarkerOnLoad(self, "bluesquare")
		</OnLoad>
	</Scripts>
</Button>
And your initialisation code in Lua like this:
lua Code:
  1. local markerIndexes = {
  2.     bluesquare = 1,
  3.     greentriangle = 2,
  4.     purplediamond = 3,
  5.     redcross = 4,
  6.     yellowstar = 5,
  7. }
  8.  
  9. function LeiShenCoordinator_MarkerOnLoad(self, marker)
  10.     local index = markerIndexes[marker]
  11.    
  12.     -- Set world marker on left-click:
  13.     self:SetAttribute("type1", "worldmarker")
  14.     self:SetAttribute("marker1", index)
  15.     self:SetAttribute("action1", "set")
  16.    
  17.     -- Clear world marker on right-click:
  18.     self:SetAttribute("type2", "worldmarker")
  19.     self:SetAttribute("marker2", index)
  20.     self:SetAttribute("action2", "clear")
  21. end
  Reply With Quote
08-13-13, 01:09 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Unless you're already working with XML on a regular basis in your day job, I would strongly advise you do not use XML for your WoW addons. It offers absolutely no benefit over creating your frames in pure Lua, and just clutters up the global namespace, and adds an additional (overly verbose) syntax for you to familiarize yourself with.

If you really want to keep using XML, at least give your global objects/functions/etc. distinct names -- so, don't name something Button2a_OnClick, as that name doesn't identify the function as belonging to your addon, and is so generic it's likely to collide with another addon's generically-named global.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-13-13, 10:07 PM   #6
Lazare
An Aku'mai Servant
 
Lazare's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 36
Thank you both very much, I will make the suggested changes and try to learn Lua much better than I currently do.
  Reply With Quote
08-14-13, 01:53 AM   #7
Lazare
An Aku'mai Servant
 
Lazare's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 36
Originally Posted by Choonstertwo View Post
Define your buttons in XML like this:
Code:
<Button name="LeiShenCoordinator_BlueMarker" inherits="UIPanelButtonTemplate,SecureActionButtonTemplate" text="Blue">
	<Size>
		<AbsDimension x="50" y="23" />
	</Size>
	<Anchors>
		<Anchor point="TOPLEFT">
			<Offset x="25" y="-75" />
		</Anchor>
	</Anchors>
	<FontHeight>
		<AbsValue val="12" />
	</FontHeight>
	<Color r="0" g="0" b="1" />
	<Scripts>
		<OnLoad>
			LeiShenCoordinator_MarkerOnLoad(self, "bluesquare")
		</OnLoad>
	</Scripts>
</Button>
And your initialisation code in Lua like this:
lua Code:
  1. local markerIndexes = {
  2.     bluesquare = 1,
  3.     greentriangle = 2,
  4.     purplediamond = 3,
  5.     redcross = 4,
  6.     yellowstar = 5,
  7. }
  8.  
  9. function LeiShenCoordinator_MarkerOnLoad(self, marker)
  10.     local index = markerIndexes[marker]
  11.    
  12.     -- Set world marker on left-click:
  13.     self:SetAttribute("type1", "worldmarker")
  14.     self:SetAttribute("marker1", index)
  15.     self:SetAttribute("action1", "set")
  16.    
  17.     -- Clear world marker on right-click:
  18.     self:SetAttribute("type2", "worldmarker")
  19.     self:SetAttribute("marker2", index)
  20.     self:SetAttribute("action2", "clear")
  21. end
Thanks again for this. I have it placed in my Lua just fine and placing markers works great. Using the right click to try to clear a marker does not work though. I have spent the last few hours trying find another way of clearing them all (including macrotext) but am getting stumped again sadly. I have made the changed to a better naming as was said by Phanx (TY!). But other than that it is bugging me.
Thanks
  Reply With Quote
08-14-13, 08:07 AM   #8
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
You probably need to register for the right click.
Buttons by default only respond to the left click (or the mouseup event)
  Reply With Quote
08-14-13, 06:39 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Lazare69 View Post
... I have spent the last few hours trying find another way of clearing them all ...
The following attributes will make the button clear all world markers when clicked:

Code:
button:SetAttribute("type", "worldmarker")
button:SetAttribute("marker", 0)
button:SetAttribute("action", "clear")
Again, this is taken directly from the FlareUP addon I linked earlier.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-14-13, 11:53 PM   #10
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
To register your button for right and left clicks, add this to the OnLoad function:
lua Code:
  1. self:RegisterForClicks("LeftButtonUp", "RightButtonUp")

If you were using pure Lua instead of XML, you'd just run the OnLoad code directly after creating the button.
  Reply With Quote
08-19-13, 02:55 AM   #11
Lazare
An Aku'mai Servant
 
Lazare's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 36
I would love to go pure XML, but most of the examples that I came across are a mix of Lua and Xml, thus why my addon is. I would love to convert this addon over to pure Lua and continue making addons this way.
  Reply With Quote
08-19-13, 06:07 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Lazare69 View Post
... most of the examples that I came across are a mix of Lua and Xml, thus why my addon is. I would love to convert this addon over to pure Lua and continue making addons this way.
I'm not sure which examples you're looking at, but 90% of the ~150 addons I currently have installed don't use any XML at all. Online tutorials tend to fall out of date quickly, and don't get updated often. You're generally better off looking at the code in use in some of the simpler addons you're already using, preferrably ones by well-known authors.

For example, here is how you can create all your buttons in pure Lua:

Code:
local function CreateWMButton(index, text, ...)
    local button = CreateFrame("Button", "MyWorldMarkerButton"..index, UIParent, "UIPanelButtonTemplate,SecureActionButtonTemplate")
    button:SetSize(50, 23)
    button:SetText(text)
    button:SetPoint(...)

    -- Set world marker on left-click:
    button:SetAttribute("type1", "worldmarker")
    button:SetAttribute("marker1", index)
    button:SetAttribute("action1", "set")
    
    -- Clear world marker on right-click:
    button:SetAttribute("type2", "worldmarker")
    button:SetAttribute("marker2", index)
    button:SetAttribute("action2", "clear")

    return button
end

local blue = CreateWMButton(1, "Blue", "TOPLEFT", UIParent, 25, -75)
local green = CreateWMButton(2, "Green", "TOP", blue, "BOTTOM", 0, -5)
-- Repeat for the other colors
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-20-13, 03:49 AM   #13
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I did sth similar in http://www.wowinterface.com/download...idManager.html
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » worldmarker help

Thread Tools
Display Modes

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