WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Message Box (https://www.wowinterface.com/forums/showthread.php?t=56924)

JDoubleU00 12-25-18 12:07 AM

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)


Fizzlemizz 12-25-18 02:02 AM

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

JDoubleU00 12-25-18 02:14 PM

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)


Fizzlemizz 12-25-18 02:52 PM

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)

JDoubleU00 12-25-18 04:14 PM

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.


All times are GMT -6. The time now is 02:38 AM.

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