Advertisement
Mordred

Untitled

Dec 5th, 2014
1,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.16 KB | None | 0 0
  1.  
  2. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  3. --                1     2  3  4  5    6      7                                                  8                                                       9          10           11         12        13
  4. --modelData: { sceneID, x, y, z, o, scale, alpha, [{ enabled[,omni,dirX,dirY,dirZ,ambIntensity[,ambR,ambG,ambB[,dirIntensity[,dirR,dirG,dirB]]]] }], sequence, widthSquish, heightSquish, path, [referenceID] }
  5. --[[ DOCUMENTATION:
  6.     sceneID:            number  - on which scene it's supposed to show up
  7.     x:                  number  - moves the model left and right  \
  8.     y:                  number  - moves the model up and down      |    if the model doesn't show up at all try moving it around sometimes it will show up | blue white box: wrong path | no texture: texture is set through dbc, needs to be hardcoded | green texture: no texture
  9.     z:                  number  - moves the model back and forth  /
  10.     o:                  number  - the orientation in which direction the model will face | number in radians | math.pi = 180° | math.pi * 2 = 360° | math.pi / 2 = 90°
  11.     scale:              number  - used to scale the model | 1 = normal size | does not scale particles of flames for example on no camera models, use width/heightSquish for that
  12.     alpha:              number  - opacity of the model | 1 = 100% , 0 = 0%
  13.     light:              table   - table containing light data (look in light documentation for further explanation) | is optional
  14.     sequence:           number  - the animation that should be played after the model is loaded
  15.     widthSquish:        number  - squishes the model on the X axis | 1 = normal
  16.     heightSquish:       number  - squishes the model on the Y axis | 1 = normal
  17.     path:               number  - the path to the model ends with .mdx
  18.     referenceID:        number  - mainly used for making changes while the scene is playing | example:
  19.    
  20.     local m = GetModel(1)   <- GetModel(referenceID) the [1] to use the first model with this referenceID without it it would be a table with all models inside
  21.     if m then
  22.         m = m[1]
  23.         local x,y,z = m:GetPosition()
  24.         m:SetPosition(x-0.1,y,z)                <- move the model -0.1 from it's current position on the x-axis
  25.     end
  26. ]]
  27. --[[ LIGHT:
  28.     enabled:            number  - appears to be 1 for lit and 0 for unlit
  29.     omni:               number  - ?? (default of 0)
  30.     dirX, dirY, dirZ:   numbers - vector from the origin to where the light source should face
  31.     ambIntensity:       number  - intensity of the ambient component of the light source
  32.     ambR, ambG, ambB:   numbers - color of the ambient component of the light source
  33.     dirIntensity:       number  - intensity of the direct component of the light source
  34.     dirR, dirG, dirB:   numbers - color of the direct component of the light source
  35. ]]
  36. --[[ METHODS:
  37.     GetModelData(referenceID / sceneID, (bool) get-all-scene-models)    table   - gets the model data table out of ModelList (returns a table with all model datas that have the same referenceID) or if bool is true from the scene
  38.     GetModel(referenceID / sceneID, (bool) get-all-scene-models)        table   - gets all models with the same referenceID or the same sceneID (if bool is true)
  39.     SetScene(sceneID)                                                   nil     - sets the current scene to the sceneID given to the function
  40.     GetScene()                                                          sceneID, sceneData, models, modeldatas  - gets all information of the scene
  41. ]]
  42. --[[ CREDITS:
  43.     Made by Mordred P.H.
  44.     Thanks to:
  45.     Soldan - helping me with all the model work
  46.     Chase - finding a method to copy cameras on the fly
  47.     Blizzard - for making it almost impossible to make it work properly
  48. ]]
  49. -------------------------------------------------------------------------
  50. --                   1                2
  51. --sceneData: {time_in_seconds, background_path}   --> (index is scene id)
  52.  
  53. local ModelList = {
  54.     max_scenes = 5,         -- number of scenes you use to shuffle through
  55.     fade_duration = 1,      -- fade animation duration in seconds (to next scene if more than 1 exists)
  56.     sceneData = {
  57.         {30,"Interface/LoginScreen/Background_1.blp"},  --30
  58.         {20,"Interface/LoginScreen/Background_2.blp"},  --20
  59.         {15,"Interface/LoginScreen/Background_3.blp"},  --15
  60.         {20,"Interface/LoginScreen/Background_4.blp"},  --notdone
  61.         {20,"Interface/LoginScreen/Background_5.blp"},  --20
  62.     },
  63.    
  64.     {1, 0, 0, 0, -math.pi/2, 0.7, 1, _, 4, 1, 1, "Creature\\Icecrownfleshbeast\\icecrownfleshbeast.mdx", 1},
  65.    
  66.     {2, 0, 0, 0, 1.3+math.pi/2, 1, 1, _, 0, 1, 1, "Creature\\Boneguard\\boneguard.mdx", 2},
  67.    
  68.     {3, -20, 0.5, -0.35, -2.5+math.pi, 1, 1, _, 0, 1, 1, "Creature\\Madscientist\\madscientist.mdx", 3},
  69.    
  70.     {4, 0, 0, 0, 0, 1, 1, _, 0, 1, 1, "Creature\\Skeletonmage\\skeletonmage.mdx", 4},
  71.     {4, 0, 0, 0, 0, 1, 1, _, 0, 1, 1, "Creature\\Skeletonmage\\skeletonmage.mdx", 6},
  72.     {4, 0, 0, 0, 0, 1, 1, _, 0, 1, 1, "Creature\\Skeletonmage\\skeletonmage.mdx", 5},
  73.     {4, 0, 0, 0, 0, 1, 1, _, 0, 1, 1, "Creature\\Skeletonmage\\skeletonmage.mdx", 6},
  74.     {4, 0, 0, 0, 0, 1, 1, _, 0, 1, 1, "Creature\\Skeletonmage\\skeletonmage.mdx", 4},
  75.    
  76.     {5, 0, 0, 0, -0.6, 0.4, 1, _, 0, 1, 1, "Creature\\CryptLord\\CryptLordHardcoded.mdx", 7}
  77. }
  78.  
  79. local use_random_starting_scene = false
  80. local shuffle_scenes_randomly = false
  81. local show_debug_button = true  -- for testing events instead timed based by just pressing a button. also let's you use fprint(...) for printing on the button text
  82.  
  83. local login_music_path = "Interface\\LoginScreen\\LoginMusic.wav"   -- path to the music (should be always the same if not using a wow song)
  84. local login_music_time_in_seconds = 303                             -- minutes * 60 + seconds
  85.  
  86. ----------------------------------------------------------------------------- end of configuration part ----------------------------------------------------------------------------------------------
  87. local width, height = GlueParent:GetSize()
  88. local current = 1
  89. PlayMusic(login_music_path)
  90.  
  91. function randomScene()
  92.     return math.random(time()) % ModelList.max_scenes + 1
  93. end
  94. if use_random_starting_scene then
  95.     current = randomScene()
  96. end
  97.  
  98. -- main frame for displaying and positioning of the whole loginscreen
  99. LoginScene = CreateFrame("Frame",nil,AccountLogin)
  100. LoginScene:SetSize(width, (width/16)*9)
  101. LoginScene:SetPoint("CENTER", AccountLogin, "CENTER", 0,0)
  102. LoginScene:SetFrameStrata("LOW")
  103.  
  104. -- main background that changes according to the scene
  105. LoginScreenBackground = LoginScene:CreateTexture(nil,"LOW")
  106. LoginScreenBackground:SetPoint("TOPRIGHT", LoginScene, "TOPRIGHT", 0, 125)
  107. LoginScreenBackground:SetPoint("BOTTOMLEFT", LoginScene, "BOTTOMLEFT", -1, -125)
  108.  
  109. LoginScreenBlackBoarderTOP:SetPoint("BOTTOMLEFT", LoginScene, "TOPLEFT", 0,0)
  110. LoginScreenBlackBoarderTOP:SetPoint("BOTTOMRIGHT", LoginScene, "TOPRIGHT", 0,0)
  111. LoginScreenBlackBoarderBOTTOM:SetPoint("TOPLEFT", LoginScene, "BOTTOMLEFT", 0,0)
  112. LoginScreenBlackBoarderBOTTOM:SetPoint("TOPRIGHT", LoginScene, "BOTTOMRIGHT", 0,0)
  113.  
  114. M = {}
  115. function newScene()
  116.     local s = {parent = CreateFrame("Frame",nil,LoginScene),
  117.                 background = ModelList.sceneData[#M+1 or 1][2],
  118.                 duration = ModelList.sceneData[#M+1 or 1][1]}
  119.     s.parent:SetSize(LoginScene:GetWidth(), LoginScene:GetHeight())
  120.     s.parent:SetPoint("CENTER")
  121.     s.parent:SetFrameStrata("MEDIUM")
  122.     table.insert(M, s)
  123.     return M[#M]
  124. end
  125.  
  126. function newModel(parent,alpha,light,wSquish,hSquish,path)
  127.     local mod = CreateFrame("Model",nil,parent)
  128.    
  129.     light = light or {1, 0, 0, -0.707, -0.707, 0.7, 1.0, 1.0, 1.0, 0.8, 1.0, 1.0, 0.8}
  130.     mod:SetModel("Character\\Human\\Male\\HumanMale.mdx")
  131.     mod:SetSize(LoginScene:GetWidth() / wSquish, LoginScene:GetHeight() / hSquish)
  132.     mod:SetPoint("CENTER")
  133.     mod:SetCamera(1)
  134.     mod:SetLight(unpack(light))
  135.     mod:SetAlpha(alpha)
  136.    
  137.     return mod
  138. end
  139.  
  140. function Generate_M()
  141.     ModelList.generate_scenes = #ModelList.sceneData
  142.     for i=1, ModelList.generate_scenes do
  143.         local s = newScene()
  144.        
  145.         for num, m in pairs(ModelList) do
  146.             if type(m)=="table" and num ~= "sceneData" then
  147.                 if m[1] == i then
  148.                     table.insert(s, num, newModel(s.parent, m[7], m[8], m[10], m[11], m[12]))
  149.                 end
  150.             end
  151.         end
  152.        
  153.         if i ~= current then
  154.             s.parent:Hide()
  155.         else
  156.             LoginScreenBackground:SetTexture(s.background)
  157.         end
  158.     end
  159. end
  160. Generate_M()
  161.  
  162. if show_debug_button then
  163.     testbutton:Show()
  164. end
  165.  
  166. function fprint(dat)
  167.     testbutton:SetText(width.." "..height)
  168. end
  169.  
  170. ------- updating and methods
  171.  
  172. local timed_update, nextC, nextCset
  173. local blend_timer, music_timer, blend_start = 0, 0, 0
  174. function LoginScreen_OnUpdate(self,dt)
  175.     if music_timer > login_music_time_in_seconds then       -- Music timer to loop the background music
  176.         PlayMusic(login_music_path)
  177.     else
  178.         music_timer = music_timer + dt
  179.     end
  180.    
  181.     if blend_start then             -- Start blend after the loginscreen loaded to hide the setting up frame
  182.         if blend_start < 0.5 then
  183.             LoginScreenBlend:SetAlpha( 1 - blend_start*2 )
  184.             blend_start = blend_start + dt
  185.         else
  186.             LoginScreenBlend:SetAlpha(0)
  187.             blend_start = false
  188.         end
  189.     end
  190.    
  191.     if timed_update == true then        -- 2 frames delayed update to hackfix some errors with blizzard masterrace code
  192.         for num, m in pairs(ModelList) do
  193.             if type(m)=="table" and num ~= "sceneData" and m[1] <= ModelList.max_scenes then
  194.                 local mod = M[m[1]][num]
  195.                 mod:SetModel(m[12])
  196.                 mod:SetPosition(m[4], m[2], m[3])
  197.                 mod:SetFacing(m[5])
  198.                 mod:SetModelScale(m[6])
  199.                 mod:SetSequence(m[9])
  200.             end
  201.         end
  202.         blend_start = 0
  203.         timed_update = false
  204.     elseif timed_update == nil then
  205.         timed_update = true
  206.     end
  207.    
  208.     local cur = M[current]
  209.     if cur.duration < blend_timer then      -- Scene and blend timer for next scene and blends between the scenes
  210.         if ModelList.max_scenes > 1 then
  211.             local blend = blend_timer - cur.duration
  212.             if blend < ModelList.fade_duration then
  213.                 LoginScreenBlend:SetAlpha( 1 - math.abs( 1 - (blend*2 / ModelList.fade_duration) ) )
  214.                
  215.                 if blend*2 > ModelList.fade_duration and not nextCset then
  216.                     nextC = randomScene()
  217.                     if shuffle_scenes_randomly then
  218.                         if current == nextC then
  219.                             nextC = ((current+1 > ModelList.max_scenes) and 1) or current + 1
  220.                         end
  221.                     else
  222.                         nextC = ((current+1 > ModelList.max_scenes) and 1) or current + 1
  223.                     end
  224.                     nextCset = true
  225.                    
  226.                     local new = M[nextC]
  227.                     cur.parent:Hide()
  228.                     new.parent:Show()
  229.                     LoginScreenBackground:SetTexture(new.background)
  230.                     Scene_OnEnd(current)
  231.                     Scene_OnStart(nextC)
  232.                 end
  233.                
  234.                 blend_timer = blend_timer + dt
  235.             else
  236.                 current = nextC
  237.                 nextCset = false
  238.                 blend_timer = 0
  239.                 LoginScreenBlend:SetAlpha(0)
  240.             end
  241.         else
  242.             blend_timer = 0
  243.             Scene_OnEnd(current)
  244.             Scene_OnStart(current)
  245.         end
  246.     else
  247.         blend_timer = blend_timer + dt
  248.     end
  249.    
  250.     SceneUpdate(dt, current, blend_timer, ModelList.sceneData[current][1])
  251. end
  252.  
  253. function SetScene(sceneID)
  254.     M[current].parent:Hide()
  255.     M[sceneID].parent:Show()
  256.     LoginScreenBackground:SetTexture(M[sceneID].background)
  257.     Scene_OnEnd(current)
  258.     Scene_OnStart(sceneID)
  259.     current = sceneID
  260. end
  261.  
  262. function GetScene()
  263.     return current, ModelList.sceneData[current], GetModel(current, true), GetModelData(current, true)
  264. end
  265.  
  266. function GetModelData(refID, allSceneModels)
  267.     local data, count = {}, 0
  268.     if allSceneModels then
  269.         for num, m in pairs(ModelList) do
  270.             if type(m)=="table" and num ~= "sceneData" then
  271.                 if m[1] == refID then
  272.                     table.insert(data, num, m)
  273.                     count = count + 1
  274.                 end
  275.             end
  276.         end
  277.         return (count > 0 and data) or false
  278.     else
  279.         for num, m in pairs(ModelList) do
  280.             if type(m)=="table" and num ~= "sceneData" then
  281.                 if m[13] == refID then
  282.                     table.insert(data, num, m)
  283.                     count = count + 1
  284.                 end
  285.             end
  286.         end
  287.         return (count > 0 and data) or false
  288.     end
  289. end
  290.  
  291. function GetModel(refID, allSceneModels)
  292.     local data, count = {} ,0
  293.     if allSceneModels then
  294.         for num, m in pairs(ModelList) do
  295.             if type(m)=="table" and num ~= "sceneData" then
  296.                 if m[1] == refID then
  297.                     table.insert(data, M[m[1]][num])
  298.                     count = count + 1
  299.                 end
  300.             end
  301.         end
  302.         return (count > 0 and data) or false
  303.     else
  304.         local mData = GetModelData(refID)
  305.         if mData then
  306.             for num, m in pairs(mData) do
  307.                 table.insert(data, M[m[1]][num])
  308.                 count = count + 1
  309.             end
  310.             return (count > 0 and data) or false
  311.         else
  312.             return false
  313.         end
  314.     end
  315. end
  316.  
  317. -- test button for debugging
  318. function test_click()
  319.     fprint(strlower(AccountLoginAccountEdit:GetText()))
  320. end
  321.  
  322. ------------------------------------------------------------------------------------------------------
  323. ------                                  SCENE SCRIPTING PART                                    ------
  324. ------------------------------------------------------------------------------------------------------
  325.  
  326. -- update function that gets called each frame
  327. local anim = false
  328. function SceneUpdate(dt, sceneID, timer, sceneTime)
  329.     if sceneID == 1 then
  330.         local m = GetModel(1)
  331.         if m then
  332.             m = m[1]
  333.             local way = 30/sceneTime
  334.             local x,y,z = m:GetPosition()
  335.             m:SetPosition(x,y - way*dt,z)
  336.         end
  337.     elseif sceneID == 2 then
  338.         local m = GetModel(2)
  339.         if m then
  340.             m = m[1]
  341.             if timer > 17.1 and timer < 17.6 then
  342.                 local turn = math.pi*((timer-17.1)*7)
  343.                 m:SetFacing(m:GetFacing() - turn*dt)
  344.             end
  345.             if timer > 17 and not anim then
  346.                 m:SetSequence(55)
  347.                 anim = true
  348.             end
  349.         end
  350.     elseif sceneID == 3 then
  351.         local m = GetModel(3)
  352.         if m then
  353.             m = m[1]
  354.             if timer >= 12.7 and timer < 12.8 and strlower(AccountLoginAccountEdit:GetText()) ~= "moonwalk" then
  355.                 m:SetFacing(-2.6)
  356.             end
  357.             if timer > 12.8 and timer < 16 then
  358.                 local way = 0.7*dt
  359.                 local x,y,z = m:GetPosition()
  360.                 m:SetPosition(x-way/2,y-way,z+way/8)
  361.                 m:SetSequenceTime(4, (timer-12.8)*700)
  362.             end
  363.         end
  364.     end
  365. end
  366.  
  367. -- on end function that gets called when the scene ends
  368. function Scene_OnEnd(sceneID)
  369.     if sceneID == 1 then
  370.         local m = GetModel(1)
  371.         if m then
  372.             m = m[1]
  373.             local mData = GetModelData(1)[1]
  374.             m:SetPosition(mData[4], mData[2], mData[3])
  375.         end
  376.     end
  377.     anim = false
  378. end
  379.  
  380. -- on start function that gets called when the scene starts
  381. function Scene_OnStart(sceneID)
  382.     anim = false
  383.     if sceneID == 2 then
  384.         local m = GetModel(2)
  385.         if m then
  386.             m = m[1]
  387.             m:SetFacing(1.3+math.pi/2)
  388.             m:SetSequence(0)
  389.         end
  390.     elseif sceneID == 3 then
  391.         local m = GetModel(3)
  392.         if m then
  393.             m = m[1]
  394.             m:SetFacing(-2.5+math.pi)
  395.             m:SetSequence(0)
  396.             m:SetPosition(-20, 0.5, -0.35)
  397.         end
  398.     end
  399. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement