• 0

    posted a message on How to modify function in the standard wow ui

    Hello.

    I am trying to make an addon that can share and import macros between player in-game. I got most of the logic working, but i am now struggling with addon a shift+click function to the standard "MacroButtonX" buttons in the macro-frame. Any suggestions or ideas as to how i modify the function of a wow standard ui element such as the macro buttons?

    Thanks on advance!

     

    EDIT1: I've made some progress myself, but for some reason, i cannot get it to work properly.

    This is what i've added in the bottom of my script:

    local OldMacroButton_OnClick = MacroButton_OnClick 
    function MacroButton_OnClick(self, button) 
    	if ( IsShiftKeyDown() ) then 
    		print("Shift key is down!") 
    	else 
    		OldMacroButton_OnClick(self, button) 
    	end 
    end

     It works flawlessly when run ingame as a macro:

    /run local OldMacroButton_OnClick = MacroButton_OnClick function MacroButton_OnClick(self, button)  if ( IsShiftKeyDown() ) then print("Shift key is down!") else OldMacroButton_OnClick(self, button) end end

     but not when run in the code. Is it because the "Blizzard_MacroUI" addon is not fully loaded? And if, how do i check when it is? Thanks :)

     

    EDIT2:

    I've now figured out a "hack" that makes it work as intended, but really does not feel like this is the right way to approach it with an "OnUpdate" function. While i thought i could use OnEvent and the event "ADDON_LOADED" this seemed to not work for me.

    This is my current solution:

    function MacroHelper:OnUpdate(elapsed)
    	-- Executed every frame
    	timeSinceUpdate = timeSinceUpdate + elapsed
    	if (gotFunction == false and timeSinceUpdate > timeBetweenUpdates) then
    		if (MacroFrame ~= nil) then
    			OldMacroButton_OnClick = MacroButton_OnClick
    			MacroButton_OnClick = MH_MacroButton_OnClick
    			timeSinceUpdate = 0
    			gotFunction = true
    		end
    	end
    end

     As you can see, it's now handled in an "OnUpdate" - i would very much like to remove the "OnUpdate" function completely, and just use an EventHandler of some kind - any suggestions?

    Posted in: Need Help?
  • To post a comment, please or register a new account.