View Single Post
01-30-12, 12:12 AM   #1
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Icon Feature LUA Help

I'm trying to create an Icon Feature in RDX, but I don't really understand how to get it to work. I got it to work a little bit earlier, by making

btn._t:SetTexture("Interface\\InventoryItems\\WoWUnknownItem01.blp");

into

btn._t:SetTexture(prioicon);

However, that only worked a little bit... meaning, it wouldn't update itself in combat, it would ONLY show Kill Command.
lua Code:
  1. RDX.RegisterFeature({
  2.     name = "BM Priority Icon";
  3.     title = VFLI.i18n("Icon BM Priority");
  4.     category = VFLI.i18n("Textures");
  5.     test = true;
  6.     IsPossible = function(state)
  7.         if not state:Slot("DesignFrame") then return nil; end
  8.         if not state:Slot("Base") then return nil; end
  9.         return true;
  10.     end;
  11.     ExposeFeature = function(desc, state, errs)
  12.         if not RDXUI.DescriptorCheck(desc, state, errs) then return nil; end
  13.         if desc.owner == "Base" then desc.owner = "decor"; end
  14.         local flg = true;
  15.         flg = flg and RDXUI.UFFrameCheck_Proto("Frame_", desc, state, errs);
  16.         flg = flg and RDXUI.UFAnchorCheck(desc.anchor, state, errs);
  17.         flg = flg and RDXUI.UFOwnerCheck(desc.owner, state, errs);
  18.         if flg then state:AddSlot("Frame_" .. desc.name); end
  19.         return flg;
  20.     end;
  21.     ApplyFeature = function(desc, state)
  22.         local objname = "Frame_" .. desc.name;
  23.         local ebsflag, ebs, ebsos = "false", "bs_default", 0;
  24.         if desc.externalButtonSkin then
  25.             ebsflag = "true";
  26.             ebs = desc.externalButtonSkin;
  27.             if desc.ButtonSkinOffset then ebsos = desc.ButtonSkinOffset; end
  28.         end
  29.       ------------------ On frame creation
  30.         local createCode = [[
  31. function IconBMPriority()
  32. local gcd = 1.5
  33.  
  34. if not UnitCanAttack("player", "target") then
  35.     return
  36. end
  37.  
  38. local level = UnitLevel("player")
  39.  
  40. local inRange = 0
  41. local unit = "target"
  42. if UnitExists(unit) and UnitIsVisible(unit) then
  43.    inRange = IsSpellInRange("Kill Command",unit)
  44. end
  45.  
  46. local focus = UnitPower("player")
  47. local duration, _
  48.  
  49. -- 1. If your pet is on the target, Kill Command
  50. if inRange == 1 and focus > 50 then
  51.     _, duration = GetSpellCooldown("Kill Command")
  52.     if duration <= gcd then
  53.         return GetSpellTexture("Kill Command")
  54.     end
  55. end
  56.  
  57. -- 2. If the mob is going to live long enough, apply Serpent Sting.
  58. if focus > 35 then
  59.     _, duration = GetSpellCooldown("Serpent Sting")
  60.     if duration <= gcd then
  61.         return GetSpellTexture("Serpent Sting")
  62.     end
  63. end
  64.  
  65. -- 3. If mob is below 20% health, Kill Shot
  66. _, duration = GetSpellCooldown("Kill Shot")
  67. if duration <= gcd and ( UnitHealth("target") / UnitHealthMax("target") < 0.2 ) then
  68.     return GetSpellTexture("Kill Shot")
  69. end
  70.  
  71. -- 4. If you will have enough focus to use Explosive Shot and Black Arrow, use Arcane Shot
  72. if focus > 85 then
  73.     return GetSpellTexture("Arcane Shot")
  74. end
  75.  
  76. -- 5. Cobra Shot (or Steady Shot)
  77. if level < 81 then
  78.     return GetSpellTexture("Steady Shot")
  79. else
  80.     return GetSpellTexture("Cobra Shot")
  81. end
  82. end
  83.  
  84. prioicon = IconBMPriority();       
  85.  
  86. local btn, owner = nil, ]] .. RDXUI.ResolveFrameReference(desc.owner) .. [[;
  87. if ]] .. ebsflag .. [[ then
  88.     btn = VFLUI.SkinButton:new();
  89.     btn:SetButtonSkin("]] .. ebs ..[[", true, true, false, true, true, true, false, true, true, true);
  90. else
  91.     btn = VFLUI.AcquireFrame("Frame");
  92. end
  93. btn:SetParent(owner);
  94. btn:SetFrameLevel(owner:GetFrameLevel());
  95. btn:SetPoint(]] .. RDXUI.AnchorCodeFromDescriptor(desc.anchor) .. [[);
  96. btn:SetWidth(]] .. desc.w .. [[); btn:SetHeight(]] .. desc.h .. [[);
  97. btn._t = VFLUI.CreateTexture(btn);
  98. btn._t:SetDrawLayer("]] .. (desc.drawLayer or "ARTWORK") .. [[", 2);
  99. btn._t:SetPoint("CENTER", btn, "CENTER");
  100. btn._t:SetWidth(]] .. desc.w .. [[ - ]] .. ebsos .. [[); btn._t:SetHeight(]] .. desc.h .. [[ - ]] .. ebsos .. [[);
  101. btn._t:SetVertexColor(1,1,1,1);
  102. btn._t:SetTexture("Interface\\InventoryItems\\WoWUnknownItem01.blp");
  103. btn._t:Show();
  104. btn:Hide();
  105. frame.]] .. objname .. [[ = btn;
  106. ]];
  107.         state:Attach(state:Slot("EmitCreate"), true, function(code) code:AppendCode(createCode); end);
  108.  
  109.         ------------------ On frame destruction.
  110.         state:Attach(state:Slot("EmitDestroy"), true, function(code) code:AppendCode([[
  111. VFLUI.ReleaseRegion(frame.]] .. objname .. [[._t); frame.]] .. objname .. [[._t = nil;
  112. frame.]] .. objname .. [[:Destroy(); frame.]] .. objname .. [[ = nil;
  113. ]]); end);
  114.         state:Attach(state:Slot("EmitCleanup"), true, function(code) code:AppendCode([[
  115. frame.]] .. objname .. [[:Hide();
  116. ]]); end);
  117.  
  118.         ------------------ On paint.
  119.         state:Attach(state:Slot("EmitPaint"), true, function(code)
  120.         if desc.test then
  121.             code:AppendCode([[
  122. frame.]] .. objname .. [[:Show();
  123. ]]);
  124.         else
  125.             code:AppendCode([[
  126. frame.]] .. objname .. [[._t:SetTexture(prioicon);
  127. if UnitClass("player") = hunter then
  128.     frame.]] .. objname .. [[:Hide();
  129. else
  130.     frame.]] .. objname .. [[:Show();
  131. end;
  132. ]]);
  133.         end
  134.         end);
  135.         return true;
  136.     end;
  137.     UIFromDescriptor = function(desc, parent, state)
  138.         local ui = VFLUI.CompoundFrame:new(parent);
  139.        
  140.         -- Name/width/height
  141.         local ed_name, ed_width, ed_height = RDXUI.GenNameWidthHeightPortion(ui, desc, state);
  142.        
  143.         -- Owner
  144.         local owner = RDXUI.MakeSlotSelectorDropdown(ui, VFLI.i18n("Owner"), state, "Subframe_");
  145.         if desc and desc.owner then owner:SetSelection(desc.owner); end
  146.        
  147.         -- Drawlayer
  148.         local er = VFLUI.EmbedRight(ui, VFLI.i18n("Draw layer"));
  149.         local drawLayer = VFLUI.Dropdown:new(er, RDXUI.DrawLayerDropdownFunction);
  150.         drawLayer:SetWidth(100); drawLayer:Show();
  151.         if desc and desc.drawLayer then drawLayer:SetSelection(desc.drawLayer); else drawLayer:SetSelection("ARTWORK"); end
  152.         er:EmbedChild(drawLayer); er:Show();
  153.         ui:InsertFrame(er);
  154.        
  155.         -- Anchor
  156.         local anchor = RDXUI.UnitFrameAnchorSelector:new(ui); anchor:Show();
  157.         anchor:SetAFArray(RDXUI.ComposeAnchorList(state));
  158.         if desc and desc.anchor then anchor:SetAnchorInfo(desc.anchor); end
  159.         ui:InsertFrame(anchor);
  160.        
  161.         local chk_bs = VFLUI.CheckEmbedRight(ui, VFLI.i18n("Use Button Skin"));
  162.         local dd_buttonSkin = VFLUI.Dropdown:new(chk_bs, VFLUI.GetButtonSkinList);
  163.         dd_buttonSkin:SetWidth(150); dd_buttonSkin:Show();
  164.         if desc and desc.externalButtonSkin then
  165.             chk_bs:SetChecked(true);
  166.             dd_buttonSkin:SetSelection(desc.externalButtonSkin);
  167.         else
  168.             chk_bs:SetChecked();
  169.             dd_buttonSkin:SetSelection("bs_default");
  170.         end
  171.         chk_bs:EmbedChild(dd_buttonSkin); chk_bs:Show();
  172.         ui:InsertFrame(chk_bs);
  173.        
  174.         local ed_bs = VFLUI.LabeledEdit:new(ui, 50); ed_bs:Show();
  175.         ed_bs:SetText(VFLI.i18n("Button Skin Size Offset"));
  176.         if desc and desc.ButtonSkinOffset then ed_bs.editBox:SetText(desc.ButtonSkinOffset); end
  177.         ui:InsertFrame(ed_bs);
  178.        
  179.         function ui:GetDescriptor()
  180.         local name = ed_name.editBox:GetText();
  181.         local ebs = nil;
  182.         if chk_bs:GetChecked() then ebs = dd_buttonSkin:GetSelection(); end
  183.         return {
  184.             feature = "BM Priority Icon", name = name, owner = owner:GetSelection();
  185.             drawLayer = drawLayer:GetSelection();
  186.             w = ed_width:GetSelection();
  187.             h = ed_height:GetSelection();
  188.             anchor = anchor:GetAnchorInfo();
  189.             externalButtonSkin = ebs;
  190.             ButtonSkinOffset = VFL.clamp(ed_bs.editBox:GetNumber(), 0, 50);
  191.         };
  192.         end
  193.        
  194.         return ui;
  195.     end;
  196.     CreateDescriptor = function()
  197.         return {
  198.             feature = "BM Priority Icon", name = "bmpi", owner = "decor", drawLayer = "ARTWORK";
  199.             w = 14; h = 14;
  200.             anchor = { lp = "TOPLEFT", af = "Base", rp = "TOPLEFT", dx = 0, dy = 0};
  201.             ButtonSkinOffset = 5;
  202.         };
  203.     end;
  204. });
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote