Thread Tools Display Modes
08-17-18, 07:58 AM   #21
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Okay, this is the barest minimum I needed to get it to work. The fading code used is simply due to its simplicity. I am personally using animation fading in my big project so I'll leave any changes you require up to you.

<YourAddonName>.TOC
Code:
## Interface: 80000
## Title: <YourAddOnName>
## Notes: Shows a Splash Window
## Version: 1.0.7
## Author: Whoever wants to use it honest
## eMail: contactme@myemailaddress
## DefaultState: Enabled
## RequiredDeps: 
## LoadOnDemand: 0
## SavedVariables: 
## SavedVariablesPerCharacter:  PawDB

<YourAddOnName>.lua

<YourAddOnName>.lua
Lua Code:
  1. local addonName, addonData = ...
  2.  
  3. -- Create a new table if it is empty
  4. addonData = addonData or {}
  5.  
  6. -- Get this version of the addon
  7. addonData.version = GetAddOnMetadata(addonName, "Version")
  8.  
  9. -- Force initialisation in case there are no saved variables yet
  10. -- These should get overriden when the saved variables are loaded
  11. PawDB = {}
  12. PawDB.version = nil
  13.  
  14. -- Create the frame and set up its visual details, I've just created a white background
  15. -- By Default it will show so FadeOut immediately via the method you choose
  16. local InstallerLogo = CreateFrame("Frame", addonName.."ILogo", UIParent);
  17. InstallerLogo.Background = InstallerLogo:CreateTexture( "$parentBackground", "BACKGROUND" );
  18.  
  19. -- Create UI Elements
  20. InstallerLogo.Background:SetAllPoints()
  21.  
  22. -- Customize the Elements
  23. InstallerLogo.Background:SetColorTexture(1,1,1,1)
  24.  
  25. -- Fade Out the screen as we don't want to see it by default
  26. UIFrameFadeOut(InstallerLogo,1,1,0)
  27.  
  28. -- Event function
  29. local function OnEvent(self,event,...)
  30.    
  31.     -- if this is the first time entering the world
  32.     if event == "PLAYER_ENTERING_WORLD" then
  33.         local login,reload = ...
  34.        
  35.         -- Displays the two values in the chat frame so you can see what is being tested
  36.         --print(addonData.version, PawDB.version)
  37.  
  38.         -- Only process this block if this is the first time logging in and the version numbers are different
  39.         -- Addons will only know about a TOC change if the change was made before you logged into the game ( character screen is not enough, log right out to the beginning)
  40.         if login == true and addonData.version ~= PawDB.version then
  41.  
  42.             -- Set up the Splash Screens UI with its required data and any other changes not already made
  43.             InstallerLogo:SetSize(850, 480); -- the size of the splash
  44.             InstallerLogo:SetPoint("CENTER"); -- its position on the screen            
  45.  
  46.             -- Then fade it into view using your preferred method
  47.             UIFrameFadeIn(InstallerLogo,1,0,1);
  48.  
  49.             -- Then Update the saved variable table for the character with the new version
  50.             PawDB.version = addonData.version
  51.        end
  52.     end
  53.  end
  54.  
  55.  
  56. -- Create the frame that will monitor events and tell the other frames what to do
  57. local EventWatcher = CreateFrame("Frame")
  58. EventWatcher:RegisterEvent("PLAYER_ENTERING_WORLD");
  59. EventWatcher:SetScript("OnEvent", OnEvent)
__________________
  Reply With Quote
08-17-18, 08:55 AM   #22
candrid
Premium Member
 
candrid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 61
Thank you! I will get it a combing.
  Reply With Quote
08-18-18, 06:50 PM   #23
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Line 4:
addonData will never be empty or nil (unless there is serious issue with the WoW client, in which case you have greater worries than just your addon)

This -is- what you want to do when initializing your saved variables table, however. If it already exists, you don't want to overwrite it with an empty table. This also means that you have to wait until your addon's variables load (or later) to see if they exist yet and to do something with them if they do.

Lua Code:
  1. local addonName, addonTable = ...
  2.  
  3. local version = GetAddonMetadata(addonName, "Version")
  4.  
  5. local f = CreateFrame("Frame")
  6. f:RegisterEvent("VARIABLES_LOADED")
  7. f:SetScript("OnEvent", function(self, event, arg1)
  8.           if event == "VARIABLES_LOADED" and arg1 = addonName then
  9.                PawDB = PawDB or {}
  10.                if not PawDB.version or PawDB.version ~= version then
  11.                     --show your splash screen
  12.                end
  13.                PawDB.version = version
  14.           end
  15.      end)


(PS - If you want to do something only when the player logs in and not whenever they see a loading screen, there are 2 ways to do that.
  1. use PLAYER_LOGIN instead of PLAYER_ENTERING_WORLD
  2. unregister the PLAYER_ENTERING_WORLD event when it is no longer needed
)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-19-18, 12:52 AM   #24
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Someone mentioned that PLAYER_ENTERING_WORLD now returns two args that show if its a login or sth else.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-19-18, 11:57 AM   #25
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Thanks for your insight Seerah,

Originally Posted by Seerah View Post
Line 4:
addonData will never be empty or nil (unless there is serious issue with the WoW client, in which case you have greater worries than just your addon)
I suspected that might be the case. I just couldn't remember if it started as nil or {} I just used my rule of programming practice, make sure an item exists before trying to use it, either initialise it by default or validate it exists before using

Originally Posted by Seerah View Post
This -is- what you want to do when initializing your saved variables table, however. If it already exists, you don't want to overwrite it with an empty table. This also means that you have to wait until your addon's variables load (or later) to see if they exist yet and to do something with them if they do.

Lua Code:
  1. local addonName, addonTable = ...
  2.  
  3. local version = GetAddonMetadata(addonName, "Version")
  4.  
  5. local f = CreateFrame("Frame")
  6. f:RegisterEvent("VARIABLES_LOADED")
  7. f:SetScript("OnEvent", function(self, event, arg1)
  8.           if event == "VARIABLES_LOADED" and arg1 = addonName then
  9.                PawDB = PawDB or {}
  10.                if not PawDB.version or PawDB.version ~= version then
  11.                     --show your splash screen
  12.                end
  13.                PawDB.version = version
  14.           end
  15.      end)
Oh, great catch on checking if the PawDB.version variable exists, especially if you start with an empty table, which I didn't deal with as normal I don't have empty tables, I usually have it initialised to default values so it is never non existent. A good alternative nonetheless, although, I have personally found that VARIABLES_LOADED isn't consistent, so I either use it as a check point ( in case it is called at the right time ) and/or use the PLAYER_LOGIN/PLAYER_ENTERING_WORLD ( when arg1 == true ) events ensuring that one doesn't overwrite the other. Each addon use varies depending on how and what it needs to do with the data.

Your placement of SavedVariable setting up may well be a better place if, the saved variable file contains a nil table, which would then overwrite the initialised table at the start of the file then it would cause a problem. However, the only time I think it would be nil is when you are first creating the addon with that particular table and testing the settings back and forth. Simply deleting the wtf will fix that problem and your users shouldn't ever have the problem. I would suppose individual projects would have their own way of dealing with this and similar scenarios. But definitely a good thing to point out the other way of setting them up.

Originally Posted by Seerah View Post
(PS - If you want to do something only when the player logs in and not whenever they see a loading screen, there are 2 ways to do that.
  1. use PLAYER_LOGIN instead of PLAYER_ENTERING_WORLD
  2. unregister the PLAYER_ENTERING_WORLD event when it is no longer needed
)
This was the defacto way of dealing with PLAYER_ENTERING_WORLD when there were no parameters, and is still okay to use. But with the new parameters (firstLogin, uiReload), new addons/rewrites could utilise the new parameters and have one event deal with both initializing and refreshing of the addon UI and data accordingly. Of course, the addon developer choice is still there
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Fading Textures

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