Advertisement
Guest User

Dark Souls Death Screen fixed

a guest
Sep 1st, 2016
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.29 KB | None | 0 0
  1.  
  2. local print, strsplit, select, tonumber, tostring, wipe, remove
  3.     = print, strsplit, select, tonumber, tostring, wipe, table.remove
  4. local CreateFrame, GetSpellInfo, PlaySoundFile, UIParent, UnitBuff, C_Timer
  5.     = CreateFrame, GetSpellInfo, PlaySoundFile, UIParent, UnitBuff, C_Timer
  6.    
  7. local me = ...
  8.  
  9. local NUM_VERSIONS = 2
  10. local MEDIA_PATH = [[Interface\Addons\DarkSoulsDeathScreen\media\]]
  11. local YOU_DIED = MEDIA_PATH .. [[YOUDIED.tga]]
  12. local THANKS_OBAMA = MEDIA_PATH .. [[THANKSOBAMA.tga]]
  13. local YOU_DIED_SOUND = MEDIA_PATH .. [[YOUDIED.ogg]]
  14. local BONFIRE_LIT = MEDIA_PATH .. [[BONFIRELIT.tga]]
  15. local BONFIRE_LIT_BLUR = MEDIA_PATH .. [[BONFIRELIT_BLUR.tga]]
  16. local BONFIRE_LIT_SOUND = {
  17.     [1] = MEDIA_PATH .. [[BONFIRELIT.ogg]],
  18.     [2] = MEDIA_PATH .. [[BONFIRELIT2.ogg]],
  19. }
  20. local YOU_DIED_WIDTH_HEIGHT_RATIO = 0.32 -- width / height
  21. local BONFIRE_WIDTH_HEIGHT_RATIO = 0.36 -- w / h
  22.  
  23. local BG_STRATA = "HIGH"
  24. local TEXT_STRATA = "DIALOG"
  25.  
  26. local BG_END_ALPHA = {
  27.     [1] = 0.75, -- [0,1] alpha
  28.     [2] = 0.9, -- [0,1] alpha
  29. }
  30. local TEXT_END_ALPHA = 0.5 -- [0,1] alpha
  31. --local BONFIRE_TEXT_END_ALPHA = 0.8 -- [0,1] alpha
  32. local BONFIRE_TEXT_END_ALPHA = {
  33.     [1] = 0.7, -- [0,1] alpha
  34.     [2] = 0.9, -- [0,1] alpha
  35. }
  36. local BONFIRE_BLUR_TEXT_END_ALPHA = {
  37.     [1] = 0.63, -- [0,1] alpha
  38.     [2] = 0.75, -- [0,1] alpha
  39. }
  40. local TEXT_SHOW_END_SCALE = 1.25 -- scale factor
  41. local BONFIRE_START_SCALE = 1.15 -- scale factor
  42. local BONFIRE_END_SCALE_X = 2.5 -- scale factor
  43. local BONFIRE_END_SCALE_Y = 2.5 -- scale factor
  44. local BONFIRE_BLUR_END_SCALE_X = 1.5 -- scale factor
  45. local BONFIRE_BLUR_END_SCALE_Y = 1.5 -- scale factor
  46. local BONFIRE_FLARE_SCALE_X = {
  47.     [1] = 1.1, -- scale factor
  48.     [2] = 1.035, -- scale factor
  49. }
  50. local BONFIRE_FLARE_SCALE_Y = {
  51.     [1] = 1.065, -- scale factor
  52.     [2] = 1,
  53. }
  54. local BONFIRE_FLARE_OUT_TIME = {
  55.     [1] = 0.22, -- seconds
  56.     [2] = 1.4, -- seconds
  57. }
  58. local BONFIRE_FLARE_OUT_END_DELAY = {
  59.     [1] = 0.1, -- seconds
  60.     [2] = 0,
  61. }
  62. local BONFIRE_FLARE_IN_TIME = 0.6 -- seconds
  63. local TEXT_FADE_IN_DURATION = {
  64.     [1] = 0.15, -- seconds
  65.     [2] = 0.3, -- seconds
  66. }
  67. local FADE_IN_TIME = {
  68.     [1] = 0.45, -- in seconds
  69.     [2] = 0.13, -- seconds
  70. }
  71. local FADE_OUT_TIME = {
  72.     [1] = 0.3, -- in seconds
  73.     [2] = 0.16, -- seconds
  74. }
  75. local FADE_OUT_DELAY = 0.4 -- in seconds
  76. local BONFIRE_FADE_OUT_DELAY = {
  77.     [1] = 0.55, -- seconds
  78.     [2] = 0, -- seconds
  79. }
  80. local TEXT_END_DELAY = 0.5 -- in seconds
  81. local BONFIRE_END_DELAY = 0.05 -- in seconds
  82. local BACKGROUND_GRADIENT_PERCENT = 0.15 -- of background height
  83. local BACKGROUND_HEIGHT_PERCENT = 0.21 -- of screen height
  84. local TEXT_HEIGHT_PERCENT = 0.18 -- of screen height
  85.  
  86. local ScreenWidth, ScreenHeight = UIParent:GetSize()
  87. local db
  88.  
  89. local ADDON_COLOR = "ffFF6600"
  90. local function Print(msg)
  91.     print(("|c%sDSDS|r: %s"):format(ADDON_COLOR, msg))
  92. end
  93.  
  94. local function UnrecognizedVersion()
  95.     local msg = "[|cffFF0000Error|r] Unrecognized version flag, \"%s\"!"
  96.     Print(msg:format(tostring(db.version)))
  97.    
  98.     -- just correct the issue
  99.     db.version = 1
  100. end
  101.  
  102. -- ------------------------------------------------------------------
  103. -- Init
  104. -- ------------------------------------------------------------------
  105. local type = type
  106. local function OnEvent(self, event, ...)
  107.     if type(self[event]) == "function" then
  108.         self[event](self, event, ...)
  109.     end
  110. end
  111.  
  112. local DSFrame = CreateFrame("Frame") -- helper frame
  113. DSFrame:SetScript("OnEvent", OnEvent)
  114.  
  115. -- ----------
  116. -- BACKGROUND
  117. -- ----------
  118.  
  119. local UPDATE_TIME = 0.04
  120. local function BGFadeIn(self, e)
  121.     self.elapsed = (self.elapsed or 0) + e
  122.     local progress = self.elapsed / FADE_IN_TIME[self.version]
  123.     if progress <= 1 then
  124.         self:SetAlpha(progress * BG_END_ALPHA[self.version])
  125.     else
  126.         self:SetScript("OnUpdate", nil)
  127.         self.elapsed = nil
  128.         -- force the background to hit its final alpha in case 'e' is too small
  129.         self:SetAlpha(BG_END_ALPHA[self.version])
  130.     end
  131. end
  132.  
  133. local function BGFadeOut(self, e)
  134.     self.elapsed = (self.elapsed or 0) + e
  135.     local progress = 1 - (self.elapsed / FADE_OUT_TIME[self.version])
  136.     if progress >= 0 then
  137.         self:SetAlpha(progress * BG_END_ALPHA[self.version])
  138.     else
  139.         self:SetScript("OnUpdate", nil)
  140.         self.elapsed = nil
  141.         -- force the background to hide at the end of the animation
  142.         self:SetAlpha(0)
  143.     end
  144. end
  145.  
  146. local background = {} -- bg frames
  147.  
  148. local function GetBackground(version)
  149.     if not version then return nil end
  150.    
  151.     local frame = background[version]
  152.     if not frame then
  153.         frame = CreateFrame("Frame")
  154.         frame.version = version
  155.         background[version] = frame
  156.        
  157.         local bg = frame:CreateTexture()
  158.         bg:SetColorTexture(0, 0, 0)
  159.        
  160.         local top = frame:CreateTexture()
  161.         top:SetColorTexture(0, 0, 0)
  162.         top:SetGradientAlpha("VERTICAL", 0, 0, 0, 1, 0, 0, 0, 0) -- orientation, startR, startG, startB, startA, endR, endG, endB, endA (start = bottom, end = top)
  163.        
  164.         local btm = frame:CreateTexture()
  165.         btm:SetColorTexture(0, 0, 0)
  166.         btm:SetGradientAlpha("VERTICAL", 0, 0, 0, 0, 0, 0, 0, 1)
  167.        
  168.         -- size the frame
  169.         local height = BACKGROUND_HEIGHT_PERCENT * ScreenHeight
  170.         local bgHeight = BACKGROUND_GRADIENT_PERCENT * height
  171.         frame:SetSize(ScreenWidth, height)
  172.         frame:SetFrameStrata(BG_STRATA)
  173.        
  174.         --[[
  175.         1: bg positioned in center of screen
  176.         2: bg positioned 60% from top of screen
  177.         --]]
  178.         if version == 1 then
  179.             frame:SetPoint("CENTER", 0, 0)
  180.         elseif version == 2 then
  181.             local y = 0.6 * ScreenHeight - bgHeight
  182.             frame:SetPoint("TOP", 0, -y)
  183.         end
  184.        
  185.         -- size the background's constituent components
  186.         top:ClearAllPoints()
  187.         top:SetPoint("TOPLEFT", 0, 0)
  188.         top:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 0, -bgHeight)
  189.        
  190.         bg:ClearAllPoints()
  191.         bg:SetPoint("TOPLEFT", 0, -bgHeight)
  192.         bg:SetPoint("BOTTOMRIGHT", 0, bgHeight)
  193.        
  194.         btm:ClearAllPoints()
  195.         btm:SetPoint("BOTTOMLEFT", 0, 0)
  196.         btm:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT", 0, bgHeight)
  197.     end
  198.     return frame
  199. end
  200.  
  201. local function SpawnBackground(version)
  202.     local frame = GetBackground(version)
  203.     if frame then
  204.         frame:SetAlpha(0)
  205.         -- ideally this would use Animations, but they seem to set the alpha on all elements in the region which destroys the alpha gradient
  206.         -- ie, the background becomes just a solid-color rectangle
  207.         frame:SetScript("OnUpdate", BGFadeIn)
  208.     else
  209.         UnrecognizedVersion()
  210.     end
  211. end
  212.  
  213. local function HideBackgroundAfterDelay(self, e)
  214.     self.elapsed = (self.elapsed or 0) + e
  215.     if self.elapsed > (self:GetStartDelay() or 0) then
  216.         local bg = background[db.version or 0]
  217.         if bg then
  218.             bg:SetScript("OnUpdate", BGFadeOut)
  219.         else
  220.             UnrecognizedVersion()
  221.         end
  222.         self:SetScript("OnUpdate", nil)
  223.         self.elapsed = nil
  224.     end
  225. end
  226.  
  227. -- --------
  228. -- YOU DIED
  229. -- --------
  230.  
  231. local youDied = {} -- frames
  232.  
  233. -- "YOU DIED" text reveal from Dark Souls 2
  234. local function YouDiedReveal(self, e)
  235.     self.elapsed = (self.elapsed or 0) + e
  236.     local progress = self.elapsed / 0.5
  237.     if progress <= 1 then
  238.         -- set the texture size so it does not become distorted
  239.         self:SetSize(self.width, self.height * progress)
  240.         --self:SetSize(self.width, (1/self.height)^progress + self.height)
  241.         -- expand texcoords until the entire texture is shown
  242.         local y = 0.5 * progress
  243.         self.tex:SetTexCoord(0, 1, 0.5 - y, 0.5 + y)
  244.     else
  245.         self:SetScript("OnUpdate", nil)
  246.         self.elapsed = nil
  247.         -- ensure the entire texture is visible
  248.         self:SetSize(self.width, self.height)
  249.         self.tex:SetTexCoord(0, 1, 0, 1)
  250.     end
  251. end
  252.  
  253. local function GetYouDiedFrame(version)
  254.     if not version then return nil end
  255.    
  256.     local frame = youDied[version]
  257.     if not frame then
  258.         local parent = background[version]
  259.         frame = CreateFrame("Frame")
  260.         youDied[version] = frame
  261.         frame:SetPoint("CENTER", parent, 0, 0)
  262.        
  263.         local FADE_IN_TIME = FADE_IN_TIME[version]
  264.         local FADE_OUT_TIME = FADE_OUT_TIME[version]
  265.         local TEXT_FADE_IN_DURATION = TEXT_FADE_IN_DURATION[version]
  266.        
  267.         -- intial animation (fade-in + zoom)
  268.         local show = frame:CreateAnimationGroup()
  269.         local fadein = show:CreateAnimation("Alpha")
  270.         fadein:SetFromAlpha(0)
  271.         fadein:SetToAlpha(TEXT_END_ALPHA)
  272.         fadein:SetOrder(1)
  273.         fadein:SetStartDelay(FADE_IN_TIME)
  274.         fadein:SetDuration(FADE_IN_TIME + TEXT_FADE_IN_DURATION)
  275.         fadein:SetEndDelay(TEXT_END_DELAY)
  276.         local zoom = show:CreateAnimation("Scale")
  277.         zoom:SetOrigin("CENTER", 0, 0)
  278.         zoom:SetScale(TEXT_SHOW_END_SCALE, TEXT_SHOW_END_SCALE)
  279.         zoom:SetOrder(1)
  280.         zoom:SetDuration(1.3)
  281.         zoom:SetEndDelay(TEXT_END_DELAY)
  282.        
  283.         -- hide animation (fade-out + slower zoom)
  284.         local hide = frame:CreateAnimationGroup()
  285.         local fadeout = hide:CreateAnimation("Alpha")
  286.         fadeout:SetFromAlpha(TEXT_END_ALPHA)
  287.         fadeout:SetToAlpha(0)
  288.         fadeout:SetOrder(1)
  289.         fadeout:SetSmoothing("IN_OUT")
  290.         fadeout:SetStartDelay(FADE_OUT_DELAY)
  291.         fadeout:SetDuration(FADE_OUT_TIME + FADE_OUT_DELAY)
  292.        
  293.         frame:SetFrameStrata(TEXT_STRATA)
  294.        
  295.         frame.tex = frame:CreateTexture()
  296.         frame.tex:SetAllPoints()
  297.        
  298.         if version == 1 then
  299.             -- local y = (0.6 * ScreenHeight) + height
  300.             -- frame:SetPoint("TOP", 0, -y)
  301.        
  302.             local zoom = hide:CreateAnimation("Scale")
  303.             zoom:SetOrigin("CENTER", 0, 0)
  304.             zoom:SetScale(1.07, 1.038)
  305.             zoom:SetOrder(1)
  306.             zoom:SetDuration(FADE_OUT_TIME + FADE_OUT_DELAY + 0.3)
  307.         elseif version == 2 then
  308.             -- frame:SetPoint("CENTER", 0, -0.1 * ScreenHeight)
  309.             fadein:SetScript("OnPlay", function(self)
  310.                 self:SetScript("OnUpdate", function(this, e)
  311.                     if not this:IsDelaying() then
  312.                         -- wait out the start delay to begin revealing the YOU DIED texture
  313.                         frame:SetScript("OnUpdate", YouDiedReveal)
  314.                         this:SetScript("OnUpdate", nil)
  315.                     end
  316.                 end)
  317.             end)
  318.         end
  319.        
  320.         show:SetScript("OnFinished", function(self)
  321.             -- hide once the delay finishes
  322.             frame:SetAlpha(TEXT_END_ALPHA)
  323.             frame:SetScale(TEXT_SHOW_END_SCALE)
  324.             fadeout:SetScript("OnUpdate", HideBackgroundAfterDelay)
  325.             hide:Play()
  326.         end)
  327.         hide:SetScript("OnFinished", function(self)
  328.             -- reset to initial state
  329.             frame:SetAlpha(0)
  330.             frame:SetScale(1)
  331.         end)
  332.         frame.show = show
  333.     end
  334.     return frame
  335. end
  336.  
  337. local function YouDied(version)
  338.     local frame = GetYouDiedFrame(version)
  339.     if frame then
  340.         if frame.tex:GetTexture() ~= db.tex then
  341.             frame.tex:SetTexture(db.tex)
  342.         end
  343.         --frame.tex:SetTexture("greenboxerino")
  344.         frame:SetAlpha(0)
  345.         frame:SetScale(1)
  346.        
  347.         local height = TEXT_HEIGHT_PERCENT * ScreenHeight
  348.         frame:SetSize(height / YOU_DIED_WIDTH_HEIGHT_RATIO, height)
  349.         frame.width, frame.height = frame:GetSize()
  350.        
  351.         frame.show:Play()
  352.     else
  353.         UnrecognizedVersion()
  354.     end
  355. end
  356.  
  357. -- -----------
  358. -- BONFIRE LIT
  359. -- -----------
  360.  
  361. local bonfireIsLighting -- anim is running flag
  362. local bonfireLit = {} -- frames
  363.  
  364. local function GetBonfireLitFrame(version)
  365.     if not version then return nil end
  366.    
  367.     local frame = bonfireLit[version]
  368.     if not frame then
  369.         local parent = background[version]
  370.         frame = CreateFrame("Frame")
  371.         frame.version = version
  372.         bonfireLit[version] = frame
  373.         frame:SetPoint("CENTER", parent, 0, 0)
  374.        
  375.         local FADE_IN_TIME = FADE_IN_TIME[version]
  376.         local FADE_OUT_TIME = FADE_OUT_TIME[version]
  377.         local TEXT_FADE_IN_DURATION = TEXT_FADE_IN_DURATION[version]
  378.         local BONFIRE_TEXT_END_ALPHA = BONFIRE_TEXT_END_ALPHA[version]
  379.         local BONFIRE_BLUR_TEXT_END_ALPHA = BONFIRE_BLUR_TEXT_END_ALPHA[version]
  380.         local BONFIRE_FLARE_SCALE_X = BONFIRE_FLARE_SCALE_X[version]
  381.         local BONFIRE_FLARE_SCALE_Y = BONFIRE_FLARE_SCALE_Y[version]
  382.         local BONFIRE_FLARE_OUT_TIME = BONFIRE_FLARE_OUT_TIME[version]
  383.         local BONFIRE_FLARE_OUT_END_DELAY = BONFIRE_FLARE_OUT_END_DELAY[version]
  384.         local BONFIRE_FADE_OUT_DELAY = BONFIRE_FADE_OUT_DELAY[version]
  385.        
  386.         --[[
  387.         'static' BONFIRE LIT
  388.         --]]
  389.         frame.tex = frame:CreateTexture()
  390.         frame.tex:SetAllPoints()
  391.         frame.tex:SetTexture(BONFIRE_LIT)
  392.        
  393.         -- intial animation (fade-in)
  394.         local show = frame:CreateAnimationGroup()
  395.         local fadein = show:CreateAnimation("Alpha")
  396.         fadein:SetFromAlpha(0)
  397.         fadein:SetToAlpha(BONFIRE_TEXT_END_ALPHA)
  398.         fadein:SetOrder(1)
  399.         fadein:SetDuration(FADE_IN_TIME + TEXT_FADE_IN_DURATION)
  400.         fadein:SetEndDelay(TEXT_END_DELAY)
  401.        
  402.         -- hide animation (fade-out)
  403.         local hide = frame:CreateAnimationGroup()
  404.         local fadeout = hide:CreateAnimation("Alpha")
  405.         fadeout:SetFromAlpha(BONFIRE_TEXT_END_ALPHA)
  406.         fadeout:SetToAlpha(0)
  407.         fadeout:SetOrder(1)
  408.         fadeout:SetSmoothing("IN_OUT")
  409.         fadeout:SetStartDelay(BONFIRE_FADE_OUT_DELAY)
  410.         fadeout:SetDuration(FADE_OUT_TIME)
  411.         --fadeout:SetDuration(FADE_OUT_TIME + FADE_OUT_DELAY)
  412.        
  413.         frame:SetFrameStrata(TEXT_STRATA)
  414.        
  415.         if version == 1 then
  416.             fadein:SetScript("OnUpdate", function(self, e)
  417.                 self.elapsed = (self.elapsed or 0) + e
  418.                 local progress = self.elapsed / BONFIRE_FLARE_OUT_TIME
  419.                 if progress <= 1 then
  420.                     --frame.tex:SetVertexColor(progress, progress, progress, 1)
  421.                 else
  422.                     self:SetScript("OnUpdate", nil)
  423.                     self.elapsed = nil
  424.                     frame.tex:SetVertexColor(1, 1, 1, 1)
  425.                 end
  426.             end)
  427.         elseif version == 2 then
  428.             local zoom = hide:CreateAnimation("Scale")
  429.             zoom:SetScale(BONFIRE_END_SCALE_X, BONFIRE_END_SCALE_Y)
  430.             zoom:SetOrder(1)
  431.             zoom:SetSmoothing("IN")
  432.             zoom:SetStartDelay(BONFIRE_FADE_OUT_DELAY)
  433.             zoom:SetDuration(FADE_OUT_TIME)
  434.             --zoom:SetDuration(fadeout:GetDuration())
  435.         end
  436.        
  437.         show:SetScript("OnFinished", function(self)
  438.             frame:SetAlpha(BONFIRE_TEXT_END_ALPHA)
  439.         end)
  440.         hide:SetScript("OnFinished", function(self)
  441.             -- reset to initial state
  442.             frame:SetAlpha(0)
  443.             frame:SetScale(BONFIRE_START_SCALE)
  444.         end)
  445.         frame.show = show
  446.         frame.hide = hide
  447.        
  448.         --[[
  449.         'blurred' BONFIRE LIT
  450.         --]]
  451.         frame.blurred = CreateFrame("Frame")
  452.         frame.blurred:SetPoint("CENTER", parent, 0, 0)
  453.         frame.blurred:SetFrameStrata(TEXT_STRATA)
  454.    
  455.         -- blurred "BONFIRE LIT"
  456.         frame.blurred.tex = frame.blurred:CreateTexture()
  457.         frame.blurred.tex:SetAllPoints()
  458.         frame.blurred.tex:SetTexture(BONFIRE_LIT_BLUR)
  459.        
  460.         -- intial animation
  461.         local show = frame.blurred:CreateAnimationGroup()
  462.         local fadein = show:CreateAnimation("Alpha")
  463.         fadein:SetFromAlpha(0)
  464.         fadein:SetToAlpha(BONFIRE_BLUR_TEXT_END_ALPHA)
  465.         fadein:SetOrder(1)
  466.         fadein:SetSmoothing("IN")
  467.         -- delay the flare animation until the base texture is almost fully visible
  468.         if frame.version == 1 then
  469.             fadein:SetStartDelay(FADE_IN_TIME * 0.75)
  470.         elseif frame.version == 2 then
  471.             fadein:SetStartDelay(FADE_IN_TIME + TEXT_FADE_IN_DURATION * 0.9)
  472.         end
  473.         fadein:SetDuration(FADE_IN_TIME + TEXT_FADE_IN_DURATION + 0.25)
  474.         local flareOut = show:CreateAnimation("Scale")
  475.         flareOut:SetOrigin("CENTER", 0, 0)
  476.         flareOut:SetScale(BONFIRE_FLARE_SCALE_X, BONFIRE_FLARE_SCALE_Y) -- flare out
  477.         flareOut:SetOrder(1)
  478.         flareOut:SetSmoothing("OUT")
  479.         flareOut:SetStartDelay(FADE_IN_TIME + TEXT_FADE_IN_DURATION) -- TODO: v2 needs to wait
  480.         flareOut:SetEndDelay(BONFIRE_FLARE_OUT_END_DELAY)
  481.         flareOut:SetDuration(BONFIRE_FLARE_OUT_TIME)
  482.        
  483.         -- hide animation (fade-out)
  484.         local hide = frame.blurred:CreateAnimationGroup()
  485.         local fadeout = hide:CreateAnimation("Alpha")
  486.         fadeout:SetFromAlpha(BONFIRE_BLUR_TEXT_END_ALPHA)
  487.         fadeout:SetToAlpha(0)
  488.         fadeout:SetOrder(1)
  489.         fadeout:SetSmoothing("IN_OUT")
  490.         fadeout:SetStartDelay(BONFIRE_FADE_OUT_DELAY)
  491.         fadeout:SetDuration(FADE_OUT_TIME)
  492.         --fadeout:SetDuration(FADE_OUT_TIME + FADE_OUT_DELAY)
  493.        
  494.         -- set the end scale of the animation to prevent the frame
  495.         -- from snapping to its original scale
  496.         local function SetEndScale(self)
  497.             local xScale, yScale = self:GetScale()
  498.             local height = TEXT_HEIGHT_PERCENT * ScreenHeight
  499.             local width = height / BONFIRE_WIDTH_HEIGHT_RATIO
  500.             if frame.version == 1 then
  501.                 -- account for the flare-out scaling
  502.                 xScale = xScale * BONFIRE_FLARE_SCALE_X
  503.                 yScale = yScale * BONFIRE_FLARE_SCALE_Y
  504.             end
  505.            
  506.             frame.blurred:SetSize(width * xScale, height * yScale)
  507.         end
  508.        
  509.         if version == 1 then
  510.             local flareIn = show:CreateAnimation("Scale")
  511.             flareIn:SetOrigin("CENTER", 0, 0)
  512.             -- scale back down (just a little larger than the starting amount)
  513.             local xScale = (1 / BONFIRE_FLARE_SCALE_X) + 0.021
  514.             flareIn:SetScale(xScale, 1 / BONFIRE_FLARE_SCALE_Y)
  515.             flareIn:SetOrder(2)
  516.             flareIn:SetSmoothing("OUT")
  517.             flareIn:SetDuration(BONFIRE_FLARE_IN_TIME)
  518.             flareIn:SetEndDelay(BONFIRE_END_DELAY)
  519.            
  520.             flareIn:SetScript("OnFinished", SetEndScale)
  521.         elseif version == 2 then
  522.             --frame.blurred:SetPoint("CENTER", 0, -0.1 * ScreenHeight)
  523.            
  524.             local zoom = hide:CreateAnimation("Scale")
  525.             zoom:SetOrigin("CENTER", 0, 0)
  526.             zoom:SetScale(BONFIRE_BLUR_END_SCALE_X, BONFIRE_BLUR_END_SCALE_Y)
  527.             zoom:SetOrder(1)
  528.             zoom:SetSmoothing("IN")
  529.             zoom:SetStartDelay(BONFIRE_FADE_OUT_DELAY)
  530.             zoom:SetDuration(FADE_OUT_TIME)
  531.             --zoom:SetDuration(fadeout:GetDuration())
  532.            
  533.             flareOut:SetScript("OnFinished", SetEndScale)
  534.         end
  535.        
  536.         show:SetScript("OnFinished", function(self)
  537.             -- hide once the delay finishes
  538.             frame.blurred:SetAlpha(BONFIRE_BLUR_TEXT_END_ALPHA)
  539.            
  540.             fadeout:SetScript("OnUpdate", HideBackgroundAfterDelay)
  541.             frame.hide:Play() -- static hide
  542.             hide:Play() -- blurred hide
  543.         end)
  544.         hide:SetScript("OnFinished", function(self)
  545.             -- reset to initial state
  546.             frame.blurred:SetAlpha(0)
  547.             frame.blurred:SetScale(BONFIRE_START_SCALE)
  548.            
  549.             bonfireIsLighting = nil
  550.         end)
  551.         frame.blurred.show = show
  552.     end
  553.     return frame
  554. end
  555.  
  556. local function BonfireLit(version)
  557.     local frame = GetBonfireLitFrame(version)
  558.     frame:SetAlpha(0)
  559.     frame.blurred:SetAlpha(0)
  560.     frame:SetScale(BONFIRE_START_SCALE)
  561.     -- scale the blurred texture down a bit since it is larger than the static texture
  562.     frame.blurred:SetScale(BONFIRE_START_SCALE * 0.97)
  563.    
  564.     local height = TEXT_HEIGHT_PERCENT * ScreenHeight
  565.     frame:SetSize(height / BONFIRE_WIDTH_HEIGHT_RATIO, height)
  566.     frame.blurred:SetSize(height / BONFIRE_WIDTH_HEIGHT_RATIO, height)
  567.    
  568.     frame.show:Play()
  569.     frame.blurred.show:Play()
  570.     bonfireIsLighting = true
  571. end
  572.  
  573. -- ------------------------------------------------------------------
  574. -- Event handlers
  575. -- ------------------------------------------------------------------
  576. DSFrame:RegisterEvent("ADDON_LOADED")
  577. function DSFrame:ADDON_LOADED(event, name)
  578.     if name == me then
  579.         DarkSoulsDeathScreen = DarkSoulsDeathScreen or {
  580.             --[[
  581.             default db
  582.             --]]
  583.             enabled = true, -- addon enabled flag
  584.             sound = true, -- sound enabled flag
  585.             tex = YOU_DIED, -- death animation texture
  586.             version = 1, -- animation version
  587.         }
  588.         db = DarkSoulsDeathScreen
  589.         if not db.enabled then
  590.             self:SetScript("OnEvent", nil)
  591.         end
  592.         self.ADDON_LOADED = nil
  593.        
  594.         -- add the version flag to old SVs
  595.         db.version = db.version or 1
  596.     end
  597. end
  598.  
  599. local SpiritOfRedemption = GetSpellInfo(20711)
  600. local FeignDeath = GetSpellInfo(5384)
  601. DSFrame:RegisterEvent("PLAYER_DEAD")
  602. function DSFrame:PLAYER_DEAD(event)
  603.     local SOR = UnitBuff("player", SpiritOfRedemption)
  604.     local FD = UnitBuff("player", FeignDeath)
  605.     -- event==nil means a fake event
  606.     if not event or not (UnitBuff("player", SpiritOfRedemption) or UnitBuff("player", FeignDeath)) then
  607.    
  608.         -- TODO? cancel other anims (ie, bonfire lit)
  609.        
  610.         if db.sound then
  611.             PlaySoundFile(YOU_DIED_SOUND, "Master")
  612.         end
  613.        
  614.         SpawnBackground(db.version)
  615.         YouDied(db.version)
  616.     end
  617. end
  618.  
  619. local ENKINDLE_BONFIRE = 174723
  620. DSFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  621. function DSFrame:UNIT_SPELLCAST_SUCCEEDED(event, unit, spell, rank, lineId, spellId)
  622.     if (spellId == ENKINDLE_BONFIRE and unit == "player") or not event then
  623.         -- waiting for the full animation to run may skip some enkindle casts
  624.         -- (if the player is spam clicking the bonfire)
  625.         if not bonfireIsLighting then
  626.             if db.sound then
  627.                 local bonfireLitSound = BONFIRE_LIT_SOUND[db.version or 0]
  628.                 if bonfireLitSound then
  629.                     PlaySoundFile(bonfireLitSound, "Master")
  630.                 --[[
  631.                 else
  632.                     -- let the anim print the error message
  633.                 --]]
  634.                 end
  635.             end
  636.            
  637.             if db.version == 1 then
  638.                 -- begin the animation after the bonfire is actually lit (to mimic Dark Souls 1)
  639.                 C_Timer.After(0.6, function()
  640.                     SpawnBackground(1)
  641.                     BonfireLit(1)
  642.                     -- https://www.youtube.com/watch?v=HUS_5ao5WEQ&t=6m8s
  643.                 end)
  644.             else
  645.                 SpawnBackground(db.version)
  646.                 BonfireLit(db.version)
  647.             end
  648.        
  649.         end
  650.     end
  651. end
  652.  
  653. -- ------------------------------------------------------------------
  654. -- Slash cmd
  655. -- ------------------------------------------------------------------
  656. local slash = "/dsds"
  657. SLASH_DARKSOULSDEATHSCREEN1 = slash
  658.  
  659. local function OnOffString(bool)
  660.     return bool and "|cff00FF00enabled|r" or "|cffFF0000disabled|r"
  661. end
  662.  
  663. local split = {}
  664. local function pack(...)
  665.     wipe(split)
  666.  
  667.     local numArgs = select('#', ...)
  668.     for i = 1, numArgs do
  669.         split[i] = select(i, ...)
  670.     end
  671.     return split
  672. end
  673.  
  674. local commands = {}
  675. commands["enable"] = function(args)
  676.     db.enabled = true
  677.     DSFrame:SetScript("OnEvent", OnEvent)
  678.     Print(OnOffString(db.enabled))
  679. end
  680. commands["on"] = commands["enable"] -- enable alias
  681. commands["disable"] = function(args)
  682.     db.enabled = false
  683.     DSFrame:SetScript("OnEvent", nil)
  684.     Print(OnOffString(db.enabled))
  685. end
  686. commands["off"] = commands["disable"] -- disable alias
  687. local function GetValidVersions()
  688.     -- returns "1/2/3/.../k"
  689.     local result = "1"
  690.     for i = 2, NUM_VERSIONS do
  691.         result = ("%s/%d"):format(result, i)
  692.     end
  693.     return result
  694. end
  695. commands["version"] = function(args)
  696.     local doPrint = true
  697.     local ver = args[1]
  698.     if ver then
  699.         ver = tonumber(ver) or 0
  700.         if 0 < ver and ver <= NUM_VERSIONS then
  701.             db.version = ver
  702.         else
  703.             Print(("Usage: %s version [%s]"):format(slash, GetValidVersions()))
  704.             doPrint = false
  705.         end
  706.     else
  707.         -- cycle
  708.         db.version = (db.version % NUM_VERSIONS) + 1
  709.     end
  710.    
  711.     if doPrint then
  712.         Print(("Using Dark Souls %d animations"):format(db.version))
  713.     end
  714. end
  715. commands["ver"] = commands["version"]
  716. commands["sound"] = function(args)
  717.     local doPrint = true
  718.     local enable = args[1]
  719.     if enable then
  720.         if enable == "on" or enable == "true" then
  721.             db.sound = true
  722.         elseif enable == "off" or enable == "false" or enable == "nil" then
  723.             db.sound = false
  724.         else
  725.             Print(("Usage: %s sound [on/off]"):format(slash))
  726.             doPrint = false
  727.         end
  728.     else
  729.         -- toggle
  730.         db.sound = not db.sound
  731.     end
  732.    
  733.     if doPrint then
  734.         Print(("Sound %s"):format(OnOffString(db.sound)))
  735.     end
  736. end
  737. commands["tex"] = function(args)
  738.     local tex = args[1]
  739.     local currentTex = db.tex
  740.     if tex then
  741.         db.tex = tex
  742.     else
  743.         -- toggle
  744.         if currentTex == YOU_DIED then
  745.             db.tex = THANKS_OBAMA
  746.             tex = "THANKS OBAMA"
  747.         else
  748.             -- this will also default to "YOU DIED" if a custom texture path was set
  749.             db.tex = YOU_DIED
  750.             tex = "YOU DIED"
  751.         end
  752.     end
  753.     Print(("Texture set to '%s'"):format(tex))
  754. end
  755. commands["test"] = function(args)
  756.     local anim = args[1]
  757.     if anim == "b" or anim == "bonfire" then
  758.         DSFrame:UNIT_SPELLCAST_SUCCEEDED()
  759.     else
  760.         DSFrame:PLAYER_DEAD()
  761.     end
  762. end
  763.  
  764. local indent = "  "
  765. local usage = {
  766.     ("Usage: %s"):format(slash),
  767.     ("%s%s on/off: Enables/disables the death screen."),
  768.     ("%s%s version ["..GetValidVersions().."]: Cycles through animation versions (eg, Dark Souls 1/Dark Souls 2)."),
  769.     ("%s%s sound [on/off]: Enables/disables the death screen sound. Toggles if passed no argument."),
  770.     ("%s%s tex [path\\to\\custom\\texture]: Toggles between the 'YOU DIED' and 'THANKS OBAMA' textures. If an argument is supplied, the custom texture will be used instead."),
  771.     ("%s%s test [bonfire]: Runs the death animation or the bonfire animation if 'bonfire' is passed as an argument."),
  772.     ("%s%s help: Shows this message."),
  773. }
  774. do -- format the usage lines
  775.     for i = 2, #usage do
  776.         usage[i] = usage[i]:format(indent, slash)
  777.     end
  778. end
  779. commands["help"] = function(args)
  780.     for i = 1, #usage do
  781.         Print(usage[i])
  782.     end
  783. end
  784. commands["h"] = commands["help"] -- help alias
  785.  
  786. local delim = " "
  787. function SlashCmdList.DARKSOULSDEATHSCREEN(msg)
  788.     msg = msg and msg:lower()
  789.     local args = pack(strsplit(delim, msg))
  790.     local cmd = remove(args, 1)
  791.    
  792.     local exec = cmd and type(commands[cmd]) == "function" and commands[cmd] or commands["h"]
  793.     exec(args)
  794. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement