WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Minimap code help (https://www.wowinterface.com/forums/showthread.php?t=57355)

ChandlerJoseph 08-15-19 11:42 AM

Minimap code help
 
For context, when you hover over the minimap or buttons, the buttons appear. When you are not hovering over it, they are hidden.

I have created a short delay for when the buttons disappear for visual pleasure.

The problem lies with the last block of text, more specfically, "Minimap" and "MiniMapMailFrame".

When my cursor goes from the Minimap or the MiniMapMailFrame to any of the specified buttons. Instead of cancelling the delay as it should. It continues with the delay and hides the buttons even when my cursor is on top of one of the buttons.

Here is my code:

https://pastebin.com/Taj8G9is

pas06 08-15-19 12:47 PM

You could fix this by using a boolean variable for show/hide. set the value to true OnEnter and to false OnLeave. In your function in which you set the alpha value you check this variable and only set alpha to 0 if the value is false.

ChandlerJoseph 08-15-19 01:03 PM

would you mind showing me how to do so? Im new to coding so I just need an example to go off of if youre willing, thanks!

pas06 08-15-19 01:43 PM

I did a rewrite of your code, i could tell its really messy :D

Check it out and tell me if it works as desired, i kept your way of canceling the timers.

Code:

assert(LoadAddOn("Blizzard_TimeManager"))
local DHMB

local Minimap_Buttons = {
        GameTimeFrame,
        GarrisonLandingPageMinimapButton,
        GuildInstanceDifficulty,
        MiniMapChallengeMode,
        MiniMapInstanceDifficulty,
        MiniMapTracking,
        MiniMapTrackingButton,
        MiniMapWorldMapButton,
        MinimapZoneTextButton,
        MinimapZoomIn,
        MinimapZoomOut,
        QueueStatusMinimapButton,
        TimeManagerClockButton,
}


local function Stop_Minimap_Loop_Pulse_Anim()
        GarrisonLandingPageMinimapButton.MinimapLoopPulseAnim:Stop()
end

local function Hide_MinimapBorderTop_MinimapButtons()
        MinimapBorderTop:SetAlpha(0)
        for _, frame in pairs(Minimap_Buttons) do
                frame:SetAlpha(0)
        end
end

local function OnEnter()
        if DHMB then DHMB:Cancel() end
        for _, frame in pairs(Minimap_Buttons) do
                frame:SetAlpha(1)
        end
        MinimapBorderTop:SetAlpha(1)
        Stop_Minimap_Loop_Pulse_Anim()
end

local function OnLeave()
        DHMB = C_Timer.NewTimer(.25, Hide_MinimapBorderTop_MinimapButtons)
        Stop_Minimap_Loop_Pulse_Anim()
end

local function SetupHooks(frame)
        frame:HookScript("OnEnter", OnEnter)
        frame:HookScript("OnLeave", OnLeave)
end


SetupHooks(MiniMapMailFrame)
SetupHooks(Minimap)
MinimapBorderTop:SetAlpha(0)

for _, frame in pairs(Minimap_Buttons) do
        SetupHooks(frame):
        frame:SetAlpha(0)
end

Edit:
Something to point out, some mistakes you made:
  • HookScript only takes one function, you inserted multiple ones
  • many code parts got executed in the same situations as other, i combined this into one function to clean it up
  • you were running code that didn't use loop objects or variables in a loop which is unecessary (running Minimap:HookScript inside the loop over your minimap buttons.)
  • dont use global variables if you dont need to. (DHMB was global)

    Happy learning :)

ChandlerJoseph 08-15-19 02:16 PM

Thank you so much for the wonderfully written and detailed response! It started as me wanting to hide a few things on my screen cause the default UI feels so cluttered and it turned into such a long journey of foruming and api scavenging. Its quite overwhelming trying to code properly as well as finding all the bugs.


I get a lua error down at line 57 "SetupHooks(frame): ". I assume something should be added there.

pas06 08-15-19 02:21 PM

just delete the colon in this line then it should be fine. Sorry :)

ChandlerJoseph 08-15-19 02:28 PM

It works perfectly! Im sure ill be posting more on here about some other stuff. Im just making a (what I thought to be simple) addon that fades the micro menu, minimap buttons, and everything on the chat except the font string container. Would you be willing to give those a look when you have the time? If not I understand, you have already done so much.

pas06 08-15-19 02:47 PM

sure, i am always down to help.
just create a new topic in the forums. Since i dont check the forums every day feel free to write me a pm this way i cant miss it.

Kanegasi 08-15-19 03:46 PM

Keep posting publicly. It's really nice of pas06 to offer direct help, but it's better to keep your questions and issues public so that anyone can help. I've been in a similar situation before that turned into many PMs on another forum years ago, not that I'm suggesting you'll do that. It would've been better for that poster and me if the help was distributed around others willing to answer, along with any possible issues that would help someone later when they come across the thread.

pas06 08-16-19 12:30 PM

Exactly, this is why i said he should post in forum and just write me a PM so i notice it and will answer in public so everyone can benefit :)


All times are GMT -6. The time now is 06:36 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI