Coloring standard buttons
What is the best way ( or is there more than one ) to change a buttons color from the standard WoW red to green (or whatever) if the option it toggles is enabled or not... For example I have a list of people that is generated from the real-id / battle-tag friends list. The addon puts asterisks around the names that it is selected to alert for... I was wondering if I could change the button colors as well to make it easier to differentiate the enabled ones from the non-enabled? I searched the web and here but I don't think I found what I was looking for...
|
The button you are seeing isn't colored at all (well, technically, it's colored white). It's a texture. If you try to color it green, it will turn into some greenish-red color.
You can... change the color of the text on the button, change the texture of the button, or use some other method to display your info. (edit: unless you want the greenish-red color) |
OK... that is what I feared... lol I guess I will have to figure a way to change the textures when I update the text on them (it is a virtual scrolling list that activates and deactivates alerts on a per real-id / battle-tag basis) I suppose it is about time I figured out some more advanced stuff lol
|
ok... so I have these nice green button textures... (recolored red ones from wow) and they do not cover the whole button, and I cant tell wow to SetTexCoord them as they are set by SetPushedTexture, SetNormalTexture, SetHighlightTexture...
So, what am I missing... |
frame:GetNormalTexture():SetTexCoord(a,b,c,d)
|
sweet... you are a WoW Lua GOD and I kneel at your feet :)
|
2 Attachment(s)
so I have the buttons changing textures now... but it looks like in earlier versions of WoW when you made a large button (all stretched and miss formed)
default red button Attachment 7501 my green button Attachment 7500 am I doing something wrong here? or am I missing something? Lua Code:
|
You should just place the recolored texture file in the appropriate path in your WoW folder so it overwrites the default texture file automatically. See PinkButtons for an example.
|
I only want the button green some of the time... like to indicate when that option is enabled
|
Well, you've never specified which button(s) you want to recolor, but assuming they inherit from the UIPanelButtonTemplate, they don't use the normal texture and pushed texture. Instead, they have separate left/right/center texture regions (to accomodate different widths without distorting the texture too much) and the textures are swapped OnMouseDown and OnMouseUp.
See: http://wow.go-hero.net/framexml/1644...mplates.xml#18 You'd need to HookScript each method that sets textures, and set your own texture in the post-hook, or just overwrite the relevant methods (though you'd need to be careful to avoid tainting or breaking anything, so simple overwriting might not be an option for some buttons). |
OMG!!! Blizz is sick... Why not make a method that allows you to map the stretching portions of a texture... it would take 3 args... like HTexStretch( 15, 70, 15 ) telling it not to stretch the 1st and last % but it can stretch the middle %...
Guess I will copy that section of the XML... make a new file... and mod it a bit... and inherit it into my buttons and see what happens. I know I should just live with the stretched textures though lol |
Such a method would just be an alias for what Blizzard is already doing, similar to how frame:SetHighlightTexture(path) is basically just an alias for:
Code:
local highlight = frame:CreateTexture(nil, "HIGHLIGHT") |
so this is what I got... and it works :) you just inherit the template into your button and set the color by ButtonVar.color = "red" or ButtonVar.color = "green" I know I need to put some checks in for wrong colors
another thing... be gentle, this is my first xml lol and with your example, I see what you mean as you can customize the textures better in the longer method than trying to use a shortcut... I have to thank you again for your help Code:
<?xml version="1.0" encoding="utf-8"?> |
That's actually quite inefficient, for several reasons:
(1) You're using an OnUpdate script -- which runs every time a video frame is drawn, 25-100 or more times per second, depending on your system -- to check for something (the current skin) that changes rarely, or never, during any given session since most users do not sit around repeatedly changing the same option. OnUpdate scripts are very expensive in CPU terms, and should only be used for timers, animations, and other things that can't be done any other way. (2) You're creating a bunch of extra tables -- which cost memory -- for every button created. Also, you're creating your tables in the least efficient way possible, with tons of extra table lookups. Instead of doing: Code:
t = {} Code:
t = { (3) You're doing a bunch of table lookups on every mousedown/mouseup event, even though the result of any given lookup will almost always be the same. Instead of doing all this, you should either: (a) use the default template, and use the technique outlined in my previous post to change the textures when needed, or (b) use a custom template that starts out one color, and change the textures "by hand" instead of changing the "self.skin" value and letting an expensive OnUpdate function check if it should change the textures 25-100 times per second. Also, if you're not already using XML to define your frames -- and you shouldn't, unless you really really love XML, or you are writing secure templates for action buttons/unit frames/state drivers/etc. -- you don't need to use XML for this either. Rather than defining a template and inheriting it, just use a "factory" function to generate your frames: Code:
local ButtonTextures = { Then, instead of: local button = CreateFrame("Button", nil, SomeFrame, "UIPanelButtonTemplate")do: local button = NewButton(parent, "GREEN")When you want to change the skin, instead of doing button.skin = "RED" do button:SetSkin("RED"). If you want to check which skin the button is using, do button:GetSkin(). |
Thanks... I did the xml like that because I didn't know what I could access from lua outside the xml... never messed with it so I wasn't sure what the scope for everything would be. I prefer lua as it isn't as extremely verbose and I am used to using it. As for the OnUpdate bit, not knowing the scope of things from the xml, that was the only way I could think to be sure I could directly interact with it. That is why I didn't even use a timer to delay the loops as I thought that an equity check would be less of an impact than incrementing a value, then checking it. One operation instead of 2... I have not done much in the ways of GUIs in my addons... just some small frames and what not (except for control panel pages)
so, how bad was the xml since I never used it before anyways? |
All times are GMT -6. The time now is 09:52 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI