Advertisement
Guest User

Untitled

a guest
Aug 20th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.76 KB | None | 0 0
  1. local title = select(2, GetAddOnInfo((...)));
  2. local active, lasthp, guid = true, 1, nil;
  3. local backdrop = {
  4.   -- path to the background texture
  5.   bgFile = "Interface\DialogFrame\UI-DialogBox-Background",
  6.   -- path to the border texture
  7.   edgeFile = "Interface\DialogFrame\UI-DialogBox-Border",
  8.   -- true to repeat the background texture to fill the frame, false to scale it
  9.   tile = true,
  10.   -- size (width or height) of the square repeating background tiles (in pixels)
  11.   tileSize = 32,
  12.   -- thickness of edge segments and square size of edge corners (in pixels)
  13.   edgeSize = 32,
  14.   -- distance from the edges of the frame to those of the background texture (in pixels)
  15.   insets = {
  16.     left = 11,
  17.     right = 12,
  18.     top = 12,
  19.     bottom = 11,
  20.   },
  21. };
  22.  
  23. --  Localization
  24. local enabled, options, editBoxDescription;
  25. if (GetLocale()=="deDE") then
  26.     enabled = {[true] = "aktiviert", [false] = "deaktiviert",
  27.     ["alreadyActive"] = "ist bereits aktiviert", ["alreadyDeactive"] = "ist bereits deaktiviert"};
  28.     options = {["enable"] = "Aktiviert das Abspielen der Sounds", ["disable"] = "Deaktiviert das Abspielen der Sounds",
  29.         ["toggle"] = "Öffnet das Fenster für die Platzierung der eigenen Musik"};
  30.     editBoxDescription = {["executeTime"] = "spielt, wenn Target unter 20%", ["unitDied"] = "spielt, wenn Target stirbt",
  31.         ["playerDied"] = "spielt, wenn man selbst stirbt", ["havePost"] = "spielt, wenn man Post erhält"};
  32. else    
  33.     enabled = {[true] = "enabled", [false] = "disabled",
  34.     ["alreadyActive"] = "it's already activated", ["alreadyDeactive"] = "it's already deactivated"}; -- Default
  35.     options = {["enable"] = "activate the playing of sounds", ["disable"] = "deactivate the playing of sounds",
  36.     ["toggle"] = "Open the window to place your own music in it"};
  37.     editBoxDescription = {["executeTime"] = "plays, if target below 20%", ["unitDied"] = "plays, if target die",
  38.         ["playerDied"] = "plays, if yourself die", ["havePost"] = "plays, if you get mail"};
  39. end
  40.  
  41. ExecuteSoundTable = {
  42.     ["playerDied"] = "laugh",
  43.     ["unitDied"] = "fatality",
  44.     ["executeTime"] = "finish him",
  45.     ["havePost"] = "hallo post",
  46. }
  47.  
  48. local ExecuteSoundsFrame = CreateFrame("Frame", "ExecuteSoundsFrame", UIParent, "BasicFrameTemplate");
  49. local ExecuteSoundsRegion = ExecuteSoundsFrame:CreateTitleRegion();
  50. local ExecuteSoundsFontString = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString", "OVERLAY", "GameFontNormal");
  51. local ExecuteSoundsFontString1 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString1", "OVERLAY", "GameFontNormal");
  52. local ExecuteSoundsFontString2 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString2", "OVERLAY", "GameFontNormal");
  53. local ExecuteSoundsFontString3 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString3", "OVERLAY", "GameFontNormal");
  54. local ExecuteSoundsFontString4 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString4", "OVERLAY", "GameFontNormal");
  55. local ExecuteSoundsEditBox1 = CreateFrame("EditBox", "ExecuteSoundsEditBox1", nil, "InputBoxTemplate");
  56. local ExecuteSoundsEditBox2 = CreateFrame("EditBox", "ExecuteSoundsEditBox2", nil, "InputBoxTemplate");
  57. local ExecuteSoundsEditBox3 = CreateFrame("EditBox", "ExecuteSoundsEditBox3", nil, "InputBoxTemplate");
  58. local ExecuteSoundsEditBox4 = CreateFrame("EditBox", "ExecuteSoundsEditBox4", nil, "InputBoxTemplate");
  59.  
  60. ExecuteSoundsFrame:RegisterEvent("ADDON_LOADED");
  61. ExecuteSoundsFrame:RegisterEvent("PLAYER_TARGET_CHANGED");
  62. ExecuteSoundsFrame:RegisterEvent("UNIT_HEALTH");
  63. ExecuteSoundsFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
  64. ExecuteSoundsFrame:RegisterEvent("PLAYER_DEAD");
  65. ExecuteSoundsFrame:RegisterEvent("UPDATE_PENDING_MAIL");
  66. ExecuteSoundsFrame:SetScript("OnEvent", function(self, event, ...)
  67.     if (not active) then return; end
  68.  
  69.     if (event == "ADDON_LOADED") then
  70.         tinsert(UISpecialFrames, self:GetName());
  71.         if (... == "ExecuteSounds") then
  72.            
  73.         end
  74.     elseif (event == "PLAYER_TARGET_CHANGED") then
  75. --      Reset when changing targets
  76.         lasthp = 1;
  77.         if (UnitIsEnemy("target", "player")) then
  78.             guid = UnitGUID("target");
  79.         end
  80.         if (UnitIsEnemy("target", "player")) then
  81.             guid = UnitGUID("target");
  82.         end
  83.     elseif (event == "UNIT_HEALTH" and UnitIsUnit(..., "target")) then
  84.         if UnitCanAttack("player", "target") then
  85. --      Need to make sure this runs only once when entering the low HP range
  86.             local pcnt = UnitHealth("target")/UnitHealthMax("target");
  87.             if pcnt < 0.2 and lasthp > 0.2 then
  88.                 PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["executeTime"]..".mp3");
  89.             end
  90.         lasthp = pcnt;
  91.         end
  92.     elseif (event == "PLAYER_DEAD") then
  93.         PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["playerDied"]..".mp3");
  94.     elseif (event == "COMBAT_LOG_EVENT_UNFILTERED") then
  95.         local _, subevent,_,_,_,_,_, destguid = ...;
  96.         if (subevent == "UNIT_DIED" and destguid == guid) then
  97.             PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["unitDied"]..".mp3");
  98.         end
  99.     elseif (event == "UPDATE_PENDING_MAIL" and HasNewMail() ~= nil) then
  100.         PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["havePost"]..".mp3");
  101.     end
  102. end);
  103. ExecuteSoundsFrame:SetScript("OnLoad", ExecuteSoundsFrame_Hide);
  104. ExecuteSoundsFrame:SetPoint("CENTER");
  105. ExecuteSoundsFrame:SetSize(205, 230);
  106. ExecuteSoundsFrame:SetBackdrop(backdrop);
  107. ExecuteSoundsFrame:EnableMouse(true);
  108.  
  109. ExecuteSoundsRegion:SetPoint("TOP");
  110. ExecuteSoundsRegion:SetSize(100, 10);
  111.  
  112. ExecuteSoundsFontString:SetText("ExecuteSounds");
  113. ExecuteSoundsFontString:SetPoint("TOP", ExecuteSoundsRegion, nil, 0, -2);
  114. ExecuteSoundsFontString:SetSize(100, 20);
  115.  
  116. ExecuteSoundsEditBox1:SetParent(ExecuteSoundsFrame);
  117. ExecuteSoundsEditBox1:RegisterEvent("OnEnterPressed");
  118. ExecuteSoundsEditBox1:SetSize(150, 20);
  119. ExecuteSoundsEditBox1:SetPoint("TOP", ExecuteSoundsFrame, "TOP", 0, -50);
  120. ExecuteSoundsEditBox1:SetText(ExecuteSoundTable["executeTime"]);
  121. ExecuteSoundsEditBox1:SetScript("OnEnterPressed", function(self)
  122.     local file = ExecuteSoundsEditBox1:GetText();
  123.     if (file ~= nil) then
  124.         ExecuteSoundTable["executeTime"] = file;
  125.         ExecuteSoundsEditBox1:ClearFocus();
  126.         return ExecuteSoundsEditBox1:SetText(file);
  127.     end
  128.  end);
  129. ExecuteSoundsEditBox1:SetAutoFocus(false);
  130.  
  131. ExecuteSoundsFontString1:SetText(editBoxDescription["executeTime"]);
  132. ExecuteSoundsFontString1:SetPoint("TOP", ExecuteSoundsEditBox1, "TOP", 0, 20);
  133. ExecuteSoundsFontString1:SetSize(165, 20);
  134.  
  135. ExecuteSoundsEditBox2:SetParent(ExecuteSoundsFrame);
  136. ExecuteSoundsEditBox2:RegisterEvent("OnEnterPressed");
  137. ExecuteSoundsEditBox2:SetSize(150, 20);
  138. ExecuteSoundsEditBox2:SetPoint("CENTER", ExecuteSoundsFrame, "CENTER", 0, 10);
  139. ExecuteSoundsEditBox2:SetText(ExecuteSoundTable["unitDied"]);
  140. ExecuteSoundsEditBox2:SetScript("OnEnterPressed", function(self)
  141. local file = ExecuteSoundsEditBox2:GetText();
  142.     if (file ~= nil) then
  143.         ExecuteSoundTable["unitDied"] = file;
  144.         ExecuteSoundsEditBox2:ClearFocus();
  145.         return ExecuteSoundsEditBox2:SetText(file);
  146.     end
  147.  end);
  148. ExecuteSoundsEditBox2:SetAutoFocus(false);
  149.  
  150. ExecuteSoundsFontString2:SetText(editBoxDescription["unitDied"]);
  151. ExecuteSoundsFontString2:SetPoint("TOP", ExecuteSoundsEditBox2, "TOP", 0, 20);
  152. ExecuteSoundsFontString2:SetSize(150, 20);
  153.  
  154. ExecuteSoundsEditBox3:SetParent(ExecuteSoundsFrame);
  155. ExecuteSoundsEditBox3:RegisterEvent("OnEnterPressed");
  156. ExecuteSoundsEditBox3:SetSize(150, 20);
  157. ExecuteSoundsEditBox3:SetPoint("CENTER", ExecuteSoundsFrame, "CENTER", 0, -35);
  158. ExecuteSoundsEditBox3:SetText(ExecuteSoundTable["playerDied"]);
  159. ExecuteSoundsEditBox3:SetScript("OnEnterPressed", function(self)
  160. local file = ExecuteSoundsEditBox3:GetText();
  161.     if (file ~= nil) then
  162.         ExecuteSoundTable["playerDied"] = file;
  163.         ExecuteSoundsEditBox3:ClearFocus();
  164.         return ExecuteSoundsEditBox3:SetText(file);
  165.     end
  166.  end);
  167. ExecuteSoundsEditBox3:SetAutoFocus(false);
  168.  
  169. ExecuteSoundsFontString3:SetText(editBoxDescription["playerDied"]);
  170. ExecuteSoundsFontString3:SetPoint("TOP", ExecuteSoundsEditBox3, "TOP", 0, 20);
  171. ExecuteSoundsFontString3:SetSize(150, 20);
  172.  
  173. ExecuteSoundsEditBox4:SetParent(ExecuteSoundsFrame);
  174. ExecuteSoundsEditBox4:RegisterEvent("OnEnterPressed");
  175. ExecuteSoundsEditBox4:SetSize(150, 20);
  176. ExecuteSoundsEditBox4:SetPoint("BOTTOM", ExecuteSoundsFrame, "BOTTOM", 0, 20);
  177. ExecuteSoundsEditBox4:SetText(ExecuteSoundTable["havePost"]);
  178. ExecuteSoundsEditBox4:SetScript("OnEnterPressed", function(self)
  179. local file = ExecuteSoundsEditBox4:GetText();
  180.     if (file ~= nil) then
  181.         ExecuteSoundTable["havePost"] = file;
  182.         ExecuteSoundsEditBox4:ClearFocus();
  183.         return ExecuteSoundsEditBox4:SetText(file);
  184.     end
  185.  end);
  186. ExecuteSoundsEditBox4:SetAutoFocus(false);
  187.  
  188. ExecuteSoundsFontString4:SetText(editBoxDescription["havePost"]);
  189. ExecuteSoundsFontString4:SetPoint("TOP", ExecuteSoundsEditBox4, "TOP", 0, 20);
  190. ExecuteSoundsFontString4:SetSize(150, 20);
  191.  
  192. SlashCmdList["EXECUTESOUNDS"] = function(cmd, editbox)
  193.     cmd = string.lower(cmd);
  194.     local command, rest = cmd:match("^(%S*)%s*(.-)$");
  195.    
  196.     if (command == "enable") then
  197.         if (active) then
  198.             print(title, enabled["alreadyActive"]);
  199.         else
  200.             active = true;
  201.             print(title, enabled[active]);
  202.         end
  203.     elseif (command == "disable") then
  204.         if (not active) then
  205.             print(title, enabled["alreadyDeactive"]);
  206.         else
  207.             active = false;
  208.             print(title, enabled[active]);
  209.         end
  210.     elseif (command == "toggle") then
  211.         ExecuteSoundsFrame_Show();
  212.     else
  213.         print(title..": ", "ENABLE", options["enable"]);
  214.         print(title..": ", "DISABLE", options["disable"]);
  215.         print(title..": ", "TOGGLE", options["toggle"]);
  216.     end
  217. end
  218.  
  219. SLASH_EXECUTESOUNDS1 = "/executesounds";
  220. SLASH_EXECUTESOUNDS2 = "/exesounds";
  221. SLASH_EXECUTESOUNDS3 = "/es";
  222.  
  223. ExecuteSoundsFrame_Show = function()
  224.     ExecuteSoundsFrame:Show();
  225. end
  226.  
  227. ExecuteSoundsFrame_Hide = function()
  228.     ExecuteSoundsFrame:Hide();
  229. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement