Advertisement
Amanthul

Garrison report

Feb 10th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. local frame = CreateFrame("FRAME");
  2.  
  3. local defaults = {
  4.     x = 0,
  5.     y = 0,
  6.     p = "CENTER",
  7.     s = 40
  8. }
  9.  
  10. if GarrisonReportConf == nil then
  11. GarrisonReportConf = defaults
  12. end
  13.  
  14. local f = CreateFrame('Button', nil, UIParent)
  15. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  16. f:SetFrameStrata('LOW')
  17. f:SetScript("OnEvent", function(self, button)
  18.  
  19. f:SetSize(GarrisonReportConf.s, GarrisonReportConf.s)
  20. f:SetPoint(GarrisonReportConf.p, GarrisonReportConf.x, GarrisonReportConf.y)
  21. end)
  22. f:RegisterForClicks('Anyup')
  23.  
  24. f:SetNormalTexture('Interface\\ICONS\\ACHIEVEMENT_ARENA_2V2_1')
  25. f:GetNormalTexture():SetSize(GarrisonReportConf.s, GarrisonReportConf.s)
  26.  
  27. f:SetHighlightTexture('Interface\\AddOns\\GarrisonReport\\Highlight')
  28. f:GetHighlightTexture():SetAllPoints(f:GetNormalTexture())
  29.  
  30. SLASH_GARRISON1= '/gar';
  31. local GarrisonCommandTable = {
  32.  ["unlock"] = function()
  33.     f:SetMovable(true)
  34. f:SetScript("OnMouseDown", function(self, button)
  35.     if button == "LeftButton" and not self.isMoving then
  36.         local movable = f:IsMovable()
  37.         if movable == true then
  38.         self:StartMoving();
  39.         self.isMoving = true;
  40.         end
  41.     end
  42. end)
  43. f:SetScript("OnMouseUp", function(self, button)
  44.     if button == "LeftButton" and self.isMoving then
  45.         self:StopMovingOrSizing();
  46.         self.isMoving = false;
  47.     end
  48. end)
  49. f:SetScript('OnEnter', function(self) end)
  50.  
  51. f:SetScript('OnLeave', function() end)
  52.  
  53. end,
  54.  ["lock"] = function()
  55.     f:SetMovable(false)
  56.     GarrisonReportConf.p = "BOTTOMLEFT"
  57.     GarrisonReportConf.x = f:GetLeft()
  58.     GarrisonReportConf.y = f:GetBottom()
  59.     f:SetPoint(GarrisonReportConf.p, GarrisonReportConf.x, GarrisonReportConf.y)
  60.     f:SetScript('OnMouseDown', function(self)
  61.     self:GetNormalTexture():ClearAllPoints()
  62.     self:GetNormalTexture():SetPoint('CENTER', 1, -1)
  63. end)
  64.  
  65. f:SetScript('OnMouseUp', function(self, button)
  66.     self:GetNormalTexture():ClearAllPoints()
  67.     self:GetNormalTexture():SetPoint('CENTER')
  68.         if (self:IsMouseOver()) then
  69.         GarrisonLandingPageMinimapButton_OnClick()
  70.         end
  71.  
  72.     GameTooltip:Hide()
  73. end)
  74.  
  75. f:SetScript('OnEnter', function(self)
  76.     GameTooltip:SetOwner(self, 'ANCHOR_TOPLEFT', 25, -5)
  77.     GameTooltip:AddLine(GARRISON_LANDING_PAGE_TITLE)
  78.     GameTooltip:Show()
  79. end)
  80.  
  81. f:SetScript('OnLeave', function()
  82.     GameTooltip:Hide()
  83. end)
  84. end,
  85.   ["defaults"] = function()
  86.     GarrisonReportConf = defaults
  87.     f:SetSize(defaults.s, defaults.s)
  88.     f:SetPoint(defaults.p, defaults.x, defaults.y)
  89.     print("Resetted to defaults")
  90. end,
  91.   ["size"] = function(size)
  92.     f:SetSize(size, size)
  93.     f:GetNormalTexture():SetSize(size,size)
  94.     f:GetHighlightTexture():SetAllPoints(f:GetNormalTexture())
  95.     GarrisonReportConf.s = size
  96. end,
  97.   ["help"] = function()
  98.     print("Syntax: /gar (unlock|lock|defaults|size x)");
  99.  end
  100. }
  101.  
  102. local function DispatchCommand(msg, GarrisonCommandTable)
  103. local command, parameters = string.split(" ", msg, 2)
  104. local entry = GarrisonCommandTable[command:lower()]
  105. local which = type(entry)
  106. if which == "function" then
  107.     entry(parameters)
  108. elseif which == "table" then
  109.     DispatchCommand(parameters or "", entry)
  110. elseif which == "string" then
  111.     print(entry)
  112. elseif msg ~= "help" then
  113.     DispatchCommand("help", GarrisonCommandTable)
  114. end
  115. end
  116.  
  117. SlashCmdList["GARRISON"] = function(msg)
  118.     DispatchCommand(msg, GarrisonCommandTable)
  119. end
  120.  
  121.  
  122. f:SetScript('OnMouseDown', function(self)
  123.     self:GetNormalTexture():ClearAllPoints()
  124.     self:GetNormalTexture():SetPoint('CENTER', 1, -1)
  125.     --f:GetNormalTexture():SetSize(GarrisonReportConf.s, GarrisonReportConf.s)
  126. end)
  127.  
  128. f:SetScript('OnMouseUp', function(self, button)
  129.     self:GetNormalTexture():ClearAllPoints()
  130.     self:GetNormalTexture():SetPoint('CENTER')
  131.     --f:GetNormalTexture():SetSize(GarrisonReportConf.s, GarrisonReportConf.s)
  132.         if (self:IsMouseOver()) then
  133.         GarrisonLandingPageMinimapButton_OnClick()
  134.         end
  135.  
  136.     GameTooltip:Hide()
  137. end)
  138.  
  139. f:SetScript('OnEnter', function(self)
  140.     GameTooltip:SetOwner(self, 'ANCHOR_TOPLEFT', 25, -5)
  141.     GameTooltip:AddLine(GARRISON_LANDING_PAGE_TITLE)
  142.     GameTooltip:Show()
  143. end)
  144.  
  145. f:SetScript('OnLeave', function()
  146.     GameTooltip:Hide()
  147. end)
  148.  
  149. function GarrisonLandingPageMinimapButton_OnClick()
  150.     GarrisonLandingPage_Toggle();
  151. end
  152.  
  153. function GarrisonLandingPage_Toggle()
  154.     if (not GarrisonLandingPage) then
  155.         Garrison_LoadUI();
  156.     end
  157.     if (not GarrisonLandingPage:IsShown()) then
  158.         ShowUIPanel(GarrisonLandingPage);
  159.     else
  160.         HideUIPanel(GarrisonLandingPage);
  161.     end
  162. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement