Advertisement
Dramiel

RIFT Rowdy UI Element

Nov 8th, 2011
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. Library.LibRowdy.Setup(...);
  2.  
  3. import "core";
  4. import "table";
  5. import "class";
  6. import "string";
  7. import "ui";
  8.  
  9. addonPackage "carla.ui";
  10.  
  11. local base, metatable, methods = nil, nil, { };
  12.  
  13. -- private members
  14.  
  15. -- public members
  16. methods.SetAura = function(self, aura)
  17.     local protected = self[AuraBar];
  18.  
  19.     protected.icon:SetTexture("Rift", aura.icon);
  20.  
  21.     if (aura.duration) then
  22.         local time, duration, remaining = _G.Inspect.Time.Frame(), aura.duration, aura.remaining;
  23.  
  24.         if (remaining == nil) then
  25.             remaining = 0;
  26.         end
  27.  
  28.         protected.progressBar:SetMinMaxValues(-(time + remaining), -(time - (duration - remaining)));
  29.         protected.progressBar:SetValue(-time);
  30.         self.Update = nil;
  31.         protected.endTime = time + remaining;
  32.     else
  33.         protected.progressBar:SetMinMaxValues(0, 1);
  34.         protected.progressBar:SetValue(1);
  35.         self.Update = dummy;
  36.         protected.endTime = 4294967295;
  37.     end
  38.  
  39.     local auraTitle = aura.name;
  40.  
  41.     if (type(aura.stack) == "number" and aura.stack > 1) then
  42.         auraTitle = tostring(aura.stack) .. "x " .. tostring(auraTitle);
  43.     end
  44.  
  45.     protected.text:SetText(auraTitle);
  46.  
  47.     protected.progressBar:Update();
  48. end
  49.  
  50. methods.Update = function(self)
  51.     local protected = self[AuraBar];
  52.  
  53.     local time = _G.Inspect.Time.Frame();
  54.  
  55.     protected.progressBar:SetValue(-time);
  56.     protected.progressBar:Update();
  57.  
  58.     if (protected.endTime ~= 4294967295 and protected.lastRemainingUpdate - time >= .1) then
  59.         local remaining = math.max(protected.endTime - time, 0);
  60.         local remainingText = strformat("%.1f", remaining);
  61.  
  62.         protected.remaining:SetText(remainingText);
  63.     end
  64. end
  65.  
  66. methods.UpdateLayout = function(self)
  67.     local protected = self[AuraBar];
  68.  
  69.     protected.progressBar:Update();
  70. end
  71.  
  72. methods.SetHeight = function(self, value)
  73.     local protected = self[AuraBar];
  74.  
  75.     base.SetHeight(self, value);
  76.     protected.icon:SetHeight(value);
  77.     protected.icon:SetWidth(value);
  78.  
  79.     protected.progressBar:SetPoint("LEFT", self, "LEFT", value, nil);
  80. end
  81.  
  82. methods.GetEndTime = function(self)
  83.     return self[AuraBar].endTime;
  84. end
  85.  
  86. -- constructor
  87. AuraBar = function(name, parent)
  88.     local self = UI.Frame(name, parent);
  89.     self:SetBackgroundColor(1, 1, 1, .5);
  90.  
  91.     local icon = UI.Texture(name .. "Icon", self);
  92.     icon:SetPoint("TOPLEFT", self, "TOPLEFT", 0, 0);
  93.  
  94.     local progressBar = UI.ProgressBar(name .. "ProgressBar", self);
  95.     progressBar:SetAllPoints(self);
  96.  
  97.     local text = UI.Text(name .. "Text", self);
  98.     text:SetPoint("CENTERLEFT", progressBar, "CENTERLEFT", 5, 0);
  99.     text:SetLayer(100);
  100.     text:SetAutoSize(true);
  101.     text:SetFontSize(13);
  102.  
  103.     local remaining = UI.Text(name .. "Remaining", self);
  104.     remaining:SetPoint("CENTERRIGHT", progressBar, "CENTERRIGHT", -5, 0);
  105.     remaining:SetLayer(100);
  106.     remaining:SetAutoSize(true);
  107.     remaining:SetFontSize(13);
  108.  
  109.     self[AuraBar] = {
  110.         icon = icon,
  111.         progressBar = progressBar,
  112.         text = text,
  113.         remaining = remaining,
  114.         lastRemainingUpdate = 0,
  115.     };
  116.  
  117.     base, metatable = class(base, metatable, methods, self, AuraBar);
  118.  
  119.     self:SetWidth(250);
  120.     self:SetHeight(25);
  121.  
  122.     return self;
  123. end
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement