Quantcast Message Box - WoWInterface
Thread Tools Display Modes
12-25-18, 12:07 AM   #1
JDoubleU00
A Scalebane Royal Guard
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 423
Message Box

I'm trying to see if there are any other solutions for displaying a pop up message box other than message("xxx"). This addon displays a message box if you do not have any favorite mounts selected. I know favorite mounts are usually across characters, but I use an addon that lets me select favorites per character. Here is the code, any suggestions are appreciated.

Code:
--Addon will check to see if you have a favorite mount and remind you if you do not.

local JWNumMounts =  C_MountJournal.GetNumMounts();
local JWFav = 0
local JWNoFav = CreateFrame("Frame", "JWNoFav", UIParent)

JWNoFav:RegisterEvent("PLAYER_ENTERING_WORLD")

local function eventHandler(self, event, ...)
	for i = 1, JWNumMounts do
		if C_MountJournal.GetIsFavorite(i) then
			JWFav = JWFav + 1
		end
	end
	if JWFav == 0 then
		message("You do not have any mounts selected as a favorite.")
	end
end

JWNoFav:SetScript("OnEvent", eventHandler)
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-25-18, 02:02 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,134
You can create any frame you want to "popup/show()" your messages

Lua Code:
  1. local function ShowMessage(text)
  2.     if not JDoubleU00MessageBox then
  3.         local f = CreateFrame("Frame", "JDoubleU00MessageBox", UIParent)
  4.         --- Whatever your heart desires to see any messages plus a close (hide) button
  5.         function f:SetText(text)
  6.              -- Depends on your frame setup above how the text is "set"
  7.         end
  8.     end
  9.     JDoubleU00MessageBox:SetText(text)
  10.     if not JDoubleU00MessageBox:IsShown() then
  11.         JDoubleU00MessageBox:Show()
  12.     end
  13. end
  14. if JWFav == 0 then
  15.     ShowMessage("You do not have any mounts selected as a favorite.")
  16. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-25-18 at 02:55 AM.
  Reply With Quote
12-25-18, 02:14 PM   #3
JDoubleU00
A Scalebane Royal Guard
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 423
Thanks, this helps, but I must be doing something wrong with either frame creation or setting the text. I've merged my code with yours and nothing is displayed. I did make sure that I do not have any favorite mounts and I had print statements to show me if I had logic errors. No errors. I am confused on the SetText function. Why call a function and isn't there a potential conflict with the name of the function? What am I missing?

Code:
--Addon will check to see if you have a favorite mount and remind you if you do not.

local JWNumMounts =  C_MountJournal.GetNumMounts();
local JWFav = 0
JWNoFav = CreateFrame("Frame", "JWNoFav", UIParent)
JWNoFavFont = [[Interface\Addons\SharedMedia_MyMedia\font\Lato-Regular.ttf]]
JWNoFavFontSize = 18
JWNoFavFontFlags = "NONE"

local function ShowMessage(text)
        if not JDoubleU00MessageBox then
			local f = CreateFrame("Frame", "JDoubleU00MessageBox", UIParent)
            --- Whatever your heart desires to see any messages plus a close (hide) button
			 f:SetFrameStrata("BACKGROUND")
			 f:SetWidth(128)
			 f:SetHeight(64)
			 f:SetPoint("CENTER",0,0)
	  
            function f:SetText(text)
			-- Depends on your frame setup above how the text is "set"
				nfText = f:CreateFontString("JWNoFavText", "OVERLAY", "NumberFontNormal") --GameFontNormal
				nfText:SetFont(JWNoFavFont, JWNoFavFontSize, JWNoFavFontFlags)
				nfText:SetPoint("CENTER", JWNoFav, "CENTER",0,1)
				nfText:SetText(text)
		    end
        end
        JDoubleU00MessageBox:SetText(text)
        if not JDoubleU00MessageBox:IsShown() then
            JDoubleU00MessageBox:Show()
        end
end

local function eventHandler(self, event, ...)
	for i = 1, JWNumMounts do
		if C_MountJournal.GetIsFavorite(i) then
			JWFav = JWFav + 1
		end
	end
	if JWFav == 0 then
		ShowMessage("You do not have any mounts selected as a favorite.")
	end
end

JWNoFav:RegisterEvent("PLAYER_ENTERING_WORLD")
JWNoFav:SetScript("OnEvent", eventHandler)
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-25-18, 02:52 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,134
Your message FontString has a SetPoint of CENTER to your event frame which has no SetPoint. The SetText function was an "if needed" thought you might add to JDoubleU00MessageBox frame to set the text of its child FontString.

Lua Code:
  1. --Addon will check to see if you have a favorite mount and remind you if you do not.
  2.  
  3. local JWNumMounts =  C_MountJournal.GetNumMounts();
  4. local JWFav = 0
  5. JWNoFav = CreateFrame("Frame", "JWNoFav", UIParent)
  6. JWNoFavFont = [[Interface\Addons\SharedMedia_MyMedia\font\Lato-Regular.ttf]]
  7. JWNoFavFontSize = 18
  8. JWNoFavFontFlags = "NONE"
  9.  
  10. local function ShowMessage(text)
  11.     if not JDoubleU00MessageBox then
  12.         local f = CreateFrame("Frame", "JDoubleU00MessageBox", UIParent)
  13.             --- Whatever your heart desires to see any messages plus a close (hide) button
  14.         f:SetFrameStrata("BACKGROUND")
  15.         f:SetHeight(64)
  16.         f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile="Interface/Tooltips/UI-Tooltip-Border", tile = true, tileSize = 8, insets = {left = 8, right = 8, top = 8, bottom = 8},})
  17.         f:SetBackdropColor(0.5, 1, 0.5)
  18.         f:SetBackdropBorderColor(1, 0, 0)
  19.         f:SetPoint("CENTER")
  20.  
  21.         f.Close = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
  22.         f.Close:SetSize(24, 24)
  23.         f.Close:SetPoint("TOPRIGHT", -8, -8)
  24.         f.Close:SetText("X")
  25.         f.Close:SetScript("OnClick", function(self) self:GetParent():Hide() end)
  26.  
  27.         f.nfText = f:CreateFontString("$parentText", "OVERLAY", "NumberFontNormal") --GameFontNormal
  28.         f.nfText:SetFont(JWNoFavFont, JWNoFavFontSize, JWNoFavFontFlags)
  29.         f.nfText:SetPoint("CENTER")
  30.     end
  31.     JDoubleU00MessageBox.nfText:SetText(text)
  32.     JDoubleU00MessageBox:SetWidth(JDoubleU00MessageBox.nfText:GetWidth() + 50)
  33.     if not JDoubleU00MessageBox:IsShown() then
  34.         JDoubleU00MessageBox:Show()
  35.     end
  36. end
  37.  
  38. local function eventHandler(self, event, ...)
  39.     for i = 1, JWNumMounts do
  40.         if C_MountJournal.GetIsFavorite(i) then
  41.             JWFav = JWFav + 1
  42.         end
  43.     end
  44.     if JWFav == 0 then
  45.         ShowMessage("You do not have any mounts selected as a favorite.")
  46.     end
  47. end
  48.  
  49. JWNoFav:RegisterEvent("PLAYER_ENTERING_WORLD")
  50. JWNoFav:SetScript("OnEvent", eventHandler)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-25-18 at 03:44 PM.
  Reply With Quote
12-25-18, 04:14 PM   #5
JDoubleU00
A Scalebane Royal Guard
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 423
Thank you so much, it worked perfectly! I learned a few things that I will need to remember for future frame creating. I had been trying to figure out the method you used for setting the message box width. I can use that in a couple of other addons of mine.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Message Box

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