Quantcast Minimap code help - WoWInterface
Thread Tools Display Modes
08-15-19, 11:42 AM   #1
ChandlerJoseph
A Deviate Faerie Dragon
Join Date: Aug 2019
Posts: 14
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

Last edited by ChandlerJoseph : 08-15-19 at 11:46 AM.
  Reply With Quote
08-15-19, 12:47 PM   #2
pas06
A Theradrim Guardian
Join Date: Apr 2009
Posts: 61
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.

Last edited by pas06 : 08-15-19 at 01:41 PM.
  Reply With Quote
08-15-19, 01:03 PM   #3
ChandlerJoseph
A Deviate Faerie Dragon
Join Date: Aug 2019
Posts: 14
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!
  Reply With Quote
08-15-19, 01:43 PM   #4
pas06
A Theradrim Guardian
Join Date: Apr 2009
Posts: 61
I did a rewrite of your code, i could tell its really messy

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

Last edited by pas06 : 08-15-19 at 01:50 PM.
  Reply With Quote
08-15-19, 02:16 PM   #5
ChandlerJoseph
A Deviate Faerie Dragon
Join Date: Aug 2019
Posts: 14
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.
  Reply With Quote
08-15-19, 02:21 PM   #6
pas06
A Theradrim Guardian
Join Date: Apr 2009
Posts: 61
just delete the colon in this line then it should be fine. Sorry
  Reply With Quote
08-15-19, 02:28 PM   #7
ChandlerJoseph
A Deviate Faerie Dragon
Join Date: Aug 2019
Posts: 14
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.
  Reply With Quote
08-15-19, 02:47 PM   #8
pas06
A Theradrim Guardian
Join Date: Apr 2009
Posts: 61
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.
  Reply With Quote
08-15-19, 03:46 PM   #9
Kanegasi
An Onyxian Warder
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 365
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.
  Reply With Quote
08-16-19, 12:30 PM   #10
pas06
A Theradrim Guardian
Join Date: Apr 2009
Posts: 61
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
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Minimap code help

Thread Tools
Display Modes

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