Thread Tools Display Modes
12-14-09, 07:23 PM   #1
Ferous
Sheer Sense of Doom
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 863
oUF_TotemBar Question

Yes, it is me again with a crazy question! I was wondering how I could implement this function into the oUF_TotemBar.lua. I have no idea what else I should add... maybe someone can give me an idea on how to do this? :O Im trying to make it to where you right click and it destroys the totem, here is my code and its ugly and im not sure what else i have to add

Code:
OnClick = function(self,TotemBar)
			
			if button == "RightButton" then
			
			DestroyTotem(1);
			DestroyTotem(2);
			DestroyTotem(3);
			DestroyTotem(4);
			
			end
			
		end
Adding this to the oUF TotemBar and im trying, but its like i have to add something else to make it to where its not clicking through? THanks for any help and sorry for me being so bothersome with questions!
  Reply With Quote
12-14-09, 07:28 PM   #2
Ferous
Sheer Sense of Doom
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 863
I realized... would I need xml for this? Sorry for my noobness, but i realized it would make it a widget?
  Reply With Quote
12-15-09, 12:42 AM   #3
Rostok
A Flamescale Wyrmkin
Join Date: Jul 2008
Posts: 127
Is your statusbar frame clickable ?
Maybe a :EnableMouse(true) would do the trick.
  Reply With Quote
12-15-09, 01:19 AM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
As of 1.12 XML is only* needed for templates. What you most likely need to do is:
Lua Code:
  1. button:RegisterForClicks("LeftButtonUp", "RightButtonUp")

The frame is most likely a Button already, so no need to enable mouse on it.

* We were lacking quite a few widget function back then tho', and it still happens once in a while. A lot rarer now however; Last thing I can remember was the cooldown spiral icon in 2.4.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-15-09, 03:08 AM   #5
Ferous
Sheer Sense of Doom
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 863
Now I'm in a rut. I have something similar to this, i keep re-editing it with different things (experimenting if you will) and Im not exactly positive if there is anything else I may need to add to it or where exactly I can put it.. would I put it in my oUF Layout after my oUF TotemBar style or would I put it in the oUF totembar.lua itself? Sorry if Im asking too much questions but if maybe you guys can help resolve this possibly everyone will benefit from it and be able to right click their totems off from the totembar :P Sorry again for my noobness and Im still learning and thank you for putting up with me thus far! lol

Without further or do, here is the code i have so far:


Code:
OnClick = function(self,button)

			button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
			
			if button == "RightButton" then
			
			DestroyTotem(1);
			DestroyTotem(2);
			DestroyTotem(3);
			DestroyTotem(4);
			
			end
			
		end
  Reply With Quote
12-15-09, 03:26 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You have to register the button for clicks before it can receive click events, so with your code, your OnClick handler never gets called. Also, you need to actually set the OnClick handler to your OnClick function.

Code:
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")

button:SetScript("OnClick", function(self, mouseButton)
	if mouseButton == "RightButton" then
		DestroyTotem(1)
		DestroyTotem(2)
		DestroyTotem(3)
		DestroyTotem(4)
	end
end)
However, you might want to selectively destroy only the totem whose button was actually clicked on, though without seeing your actual code I couldn't tell you how to do that, since I don't know how your buttons are set up.
  Reply With Quote
12-15-09, 05:49 AM   #7
nin
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 213
this might be a little off, but for example sTotemtimers has that function.. might be a diff code for ouf_totembar don't know how the code looks and can't check from here unfortunately

here's the function in sTotemtimers, hope it's of any help :P

Code:
local function TotemOnClick(self, ...) 
         local buton = ...; 
         if ( buton == "RightButton" ) then 
                 DestroyTotem(self.slot); 
         end
  Reply With Quote
12-16-09, 01:35 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by nin View Post
Code:
local function TotemOnClick(self, ...) 
         local buton = ...;
Eww...

Code:
local function TotemOnClick(self, buton)
^ Much better.

That said, that function is almost exactly what's already been posted, and doesn't really help when we don't know how the OPs buttons are constructed.
  Reply With Quote
12-16-09, 02:16 AM   #9
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
To Phanx:
Code:
Midkemia /home/haste
123 ~ % echo 'function a(self, ...) end function b(self, button)' end | luac -l -p -      

main <stdin:0,0> (5 instructions, 20 bytes at 0x932fb30)
0+ params, 2 slots, 0 upvalues, 0 locals, 2 constants, 2 functions
	1	[1]	CLOSURE  	0 0	; 0x932fc58
	2	[1]	SETGLOBAL	0 -1	; a
	3	[1]	CLOSURE  	0 1	; 0x932fee8
	4	[1]	SETGLOBAL	0 -2	; b
	5	[1]	RETURN   	0 1

function <stdin:1,1> (1 instruction, 4 bytes at 0x932fc58)
1+ param, 2 slots, 0 upvalues, 2 locals, 0 constants, 0 functions
	1	[1]	RETURN   	0 1

function <stdin:1,1> (1 instruction, 4 bytes at 0x932fee8)
2 params, 2 slots, 0 upvalues, 2 locals, 0 constants, 0 functions
	1	[1]	RETURN   	0 1
In other words: doing local button = ...; is perfectly fine, and enforcing coding styles upon others is just... meh*.

* Unless you are planning on contributing to a project, then adopting the coding style of the project is recommended.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-16-09, 07:34 AM   #10
Soeters
A Warpwood Thunder Caller
 
Soeters's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 97
I added this option in the latest version which has just been updated.
Just add this in your layout to enable it
Code:
self.TotemBar.Destroy = true
__________________
  Reply With Quote
12-16-09, 07:48 AM   #11
Ferous
Sheer Sense of Doom
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 863
Originally Posted by Soeters View Post
I added this option in the latest version which has just been updated.
Just add this in your layout to enable it
Code:
self.TotemBar.Destroy = true
You are awesome Thanks :O THis ends my conundrum!
  Reply With Quote
12-17-09, 04:32 AM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by haste View Post
In other words: doing local button = ...; is perfectly fine
It's slower, according to various tests using for loops and os.clock. Why use the code that's slower and harder to read?
  Reply With Quote
12-17-09, 06:41 AM   #13
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by Phanx View Post
It's slower, according to various tests using for loops and os.clock. Why use the code that's slower and harder to read?
It's quite obvious that any static implementation will beat a dynamic one quite heavily outside a JIT compiler. In any regard, it's the OnClick handler of a button. Optimizing it is just a waste of time, and the lost readability is discussable into oblivion.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-18-09, 06:53 PM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Eh.. using varargs in a function where you are guaranteed to have exactly one argument 100% of the time is just mind boggling to me. It's not even primarily a code readability issue or a performance issue; I see it and I just can't imagine why on earth anyone would even think to write it that way. *shrug*
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » oUF_TotemBar Question


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