Thread Tools Display Modes
03-26-16, 12:56 PM   #1
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Trying to restyle the MicroMenu buttons

So I've got the following code to restyle the MicroMenu buttons, after I saw that Blizzard does a similar thing in MainMenuBarMicroButtons.lua

Lua Code:
  1. local MicroMenuButtons = {
  2.         CharacterMicroButton,
  3.         SpellbookMicroButton,
  4.         TalentMicroButton,
  5.         AchievementMicroButton,
  6.         QuestLogMicroButton,
  7.         GuildMicroButton,
  8.         LFDMicroButton,
  9.         CollectionsMicroButton,
  10.         EJMicroButton,
  11.         StoreMicroButton,
  12.         MainMenuMicroButton,
  13.     }
  14.  
  15.     local MicroMenuFrame = CreateFrame("Frame","MicroMenuFrame",UIParent)
  16.     MicroMenuFrame:SetPoint("CENTER",UIParent,"CENTER")
  17.     MicroMenuFrame:SetSize(10,10)
  18.  
  19.     local width = 25
  20.     local height = 25
  21.     local offset = 0
  22.     local path = "Interface\\AddOns\\TestUI\\media\\microbutton\\"
  23.  
  24.     for i=1, #MicroMenuButtons do
  25.         local button = MicroMenuButtons[i]
  26.         local name = button:GetName()
  27.         print(name)
  28.  
  29.         button:ClearAllPoints()
  30.         button:SetParent(MicroMenuFrame)
  31.         button:SetPoint("LEFT",MicroMenuFrame,"LEFT",offset,0)
  32.         button:SetSize(width,height)
  33.         button:SetHitRectInsets(0,0,0,0) -- Override the cropped click region
  34.  
  35.         button:SetNormalTexture(path..name.."-Normal")
  36.         button:SetPushedTexture(path..name.."-Pushed")
  37.         button:SetDisabledTexture(path..name.."-Disabled")
  38.         button:SetHighlightTexture(path..name.."-Highlight")
  39.  
  40.         offset = offset + width + 4
  41.     end

In my case, though, it crashes the client with a ACCESS_VIOLATION error. Whoopsie. I'm pretty positive it is because I'm using variables to generate part of the texture path, though I did a printout of what the generated texture path would be and it seemed okay. They do match up with the file location in the addon folder.

https://i.gyazo.com/1336c828da869c56...7c46542d88.png

Also, does anyone have any general tips on styling the micromenu? I've noticed the MainMenuMicroButton resets to its standard textures upon login. I'm guessing it has to do with the fact that there's a StreamDL state it sometimes switches to, so I'd have to find and hook that function to override it? I'd like to avoid overriding the actual textures if I can, though I'm starting to that'd be waaaaaaaay easier than this. Either that or building the micromenu from scratch, but then I'd either have to rewrite the tooltip info or figure out how to reliably hook hold of it.
  Reply With Quote
03-26-16, 01:08 PM   #2
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Are you trying to use PNG textures or something? This code doesn't crash my client. You're likely using corrupted textures that are not of .BLP or .TGA format. Concatenating texture paths is not a problem, because you'd either get an error thrown at you for concatenating a string with a nil value or you'd just end up with an invalid texture path and render a neon green texture in its stead. Btw, you can use pairs to iterate over a table instead of extracting each element by its respective key. Like this:

Lua Code:
  1. local MicroMenuButtons = {
  2.      CharacterMicroButton,
  3.      SpellbookMicroButton,
  4.      TalentMicroButton,
  5.      AchievementMicroButton,
  6.      QuestLogMicroButton,
  7.      GuildMicroButton,
  8.      LFDMicroButton,
  9.      CollectionsMicroButton,
  10.      EJMicroButton,
  11.      StoreMicroButton,
  12.      MainMenuMicroButton,
  13. }
  14.  
  15. local MicroMenuFrame = CreateFrame("Frame","MicroMenuFrame",UIParent)
  16. MicroMenuFrame:SetPoint("CENTER",UIParent,"CENTER")
  17. MicroMenuFrame:SetSize(10,10)
  18.  
  19. local width = 25
  20. local height = 25
  21. local offset = 0
  22. local path = "Interface\\AddOns\\TestUI\\media\\microbutton\\"
  23.  
  24. for i, button in pairs(MicroMenuButtons) do
  25.      local name = button:GetName()
  26.      print(name)
  27.      
  28.      button:ClearAllPoints()
  29.      button:SetParent(MicroMenuFrame)
  30.      button:SetPoint("LEFT",MicroMenuFrame,"LEFT",offset,0)
  31.      button:SetSize(width,height)
  32.      button:SetHitRectInsets(0,0,0,0) -- Override the cropped click region
  33.      
  34.      button:SetNormalTexture(path..name.."-Normal")
  35.      button:SetPushedTexture(path..name.."-Pushed")
  36.      button:SetDisabledTexture(path..name.."-Disabled")
  37.      button:SetHighlightTexture(path..name.."-Highlight")
  38.      
  39.      offset = offset + width + 4
  40. end
__________________
  Reply With Quote
03-26-16, 01:23 PM   #3
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Thanks Munk! Honestly I keep forgetting about pair iteration, so it's nice with a reminder, haha.

The files are all .tga files, so if this is a crash caused by the image data not being as the client expects, it could be that the files were accidentally saved as a 24-bit .tga rather than 32-bit. Because for the WoW client to read a .tga file , it has to be a 32-bit one, doesn't it?
  Reply With Quote
03-26-16, 01:45 PM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by Folji View Post
The files are all .tga files, so if this is a crash caused by the image data not being as the client expects, it could be that the files were accidentally saved as a 24-bit .tga rather than 32-bit. Because for the WoW client to read a .tga file , it has to be a 32-bit one, doesn't it?
Not sure if it has to, but I always use 32-bit. This crash is most definitely due to corrupted textures. If you moved the textures into another folder, the crashing would stop. You should probably render them anew as 32-bit.
__________________
  Reply With Quote
03-26-16, 04:50 PM   #5
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Looks like the 24-bit structure of the .tga files was the culprit, yeah. Got it all sorted out now!

Though here's a question, is there any safe way to hook the event scripts of another frame? Found that the textures for the MainMenuMicroButton is hardcoded into its OnUpdate function in MainMenuBarMicroButtons.xml.

So theoretically I could use hooksecurefunc() to do what I need to do here. Just hook it and add a function that reapplies the textures I want it to have. But what am I looking for here, seeing as how the code is written in the XML template?

... If that's even a good idea. The implication would be that the addon tries to reapply the texture once every time the frame is rendered. Why does this button have to be so complicated. I've already got a backup in the way of a replacement button, for which I've copied the OnMouseDown from the original button. But I can't seem to see how they've done it with the tooltip showing latency, conenction info, addon memory usage, and so forth.

Last edited by Folji : 03-26-16 at 05:00 PM.
  Reply With Quote
03-26-16, 05:27 PM   #6
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Honestly, you might be better off creating your own secure buttons and hiding the standard ones. You can use a SecureActionButtonTemplate and then use the click type, this way you won't have to reproduce the functionality of each button.
Like this:

Lua Code:
  1. local button = CreateFrame("Button", "c00LButt0n", UIParent, "SecureActionButtonTemplate, ActionButtonTemplate")
  2. button:SetPoint("CENTER")
  3.  
  4. button:SetAttribute("type", "click")
  5. button:SetAttribute("clickbutton", SpellbookMicroButton)

The function that's being called when you hover the menu button is MainMenuBarPerformanceBarFrame_OnEnter and it's located in MainMenuBar.lua.
__________________

Last edited by MunkDev : 03-26-16 at 05:31 PM.
  Reply With Quote
03-26-16, 05:45 PM   #7
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Huh! had no idea I could do that! Could I hook and run every micro button in that fashion? Running the code as you wrote it there did work for SpellbookMicroButton, but changing it to MainMenuMicroButton didn't seem to do anything.

And I found that function earlier on yeah, heh. Had a look at the code for it, and tried to just do the following code on the alternate menu button I'd created for myself.

Lua Code:
  1. local function MenuMicroButton_OnEnter(self)
  2.         MainMenuBarPerformanceBarFrame_OnEnter(MainMenuMicroButton)
  3.         GameTooltip:SetOwner(self,"ANCHOR_TOPRIGHT")
  4.         GameTooltip:Show()
  5.     end

Of course, it didn't work. I'm guessing calling it straight-up like that isn't the right way to go about it? Overall I'm about 99% of the way there, all I'm really missing is the tooltip info for the main menu button! All the others I just restyled the actual button, and it's been going no trouble. But then of course the main menu button had to have texture changes hardcoded into its update function.

EDIT: Oh, right. So the tooltip change does work doing it like that. It's just immediately overridden by the fact that it gets a new owner immediately after.

Last edited by Folji : 03-26-16 at 05:54 PM.
  Reply With Quote
03-26-16, 06:41 PM   #8
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
You might have to read the fine print of that function and replicate it step by step.

A lot of the Lua scripting on those buttons can be found in the XML files, which is where I found that function reference. The way it seems to be happening is the micro button changes a value on itself (self.hover) whenever the mouse is over it, then it has an OnUpdate script that continuously calls the MainMenuBarPerformanceBarFrame_OnEnter function and passing itself as the frame argument. If you read the actual function, you'll see that it already repositions the tooltip and shows it at the end, which means you can probably remove that part from your code.
__________________
  Reply With Quote
04-02-16, 02:44 PM   #9
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
So it looks like trying to hook hold of the MicroMenu buttons becomes a bit of a problem with the override vehicle UI, as it essentially grabs the same buttons and repositions them. At least it tries to, but my code just fucks with it, haha. So that's a problem!

Does anyone know if it's possible to use a SecureActionButtonTemplate or some other secure template to entirely duplicate a button? Its tooltip, pushed button state, and all? I could live with having to post-hook Blizzard's MicroMenu functions to emulate the buttons being pushed depending on what frames are open, but seems altering these buttons directly is not much of an option.
  Reply With Quote
04-02-16, 03:12 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Have you taken a look at how nibMicroMenu does it?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-02-16, 03:39 PM   #11
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Hey that's a good shout, thanks Seerah! Just had a look at it, and it seems it essentially its own version of the update button state function for all the different UI frames, along with an OnEnter that just grabs the tooltip text variables from the original buttons, and beyond that they're all basically created with SetAttribute("clickbutton", Frame) as Munk posted earlier.

So now I definitely now how it'd be a good way to do this!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Trying to restyle the MicroMenu buttons


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