Reply
Thread Tools Display Modes
Unread 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. **
unlimit is offline   Reply With Quote
Unread 01-30-12, 02:11 AM   #2
sigg
Featured Artist
 
sigg's Avatar
Featured
Join Date: Aug 2008
Posts: 1,229
You should move your icon function into the repaint code section.

The create code is call only one time.

Do not use a local variable name "unit". Because the repaint function has a unit argument.
I recommend to prefix all your local variables.
__________________
RDX manager
Sigg
sigg is offline   Reply With Quote
Unread 01-30-12, 02:45 AM   #3
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Hm, I don't quite understand, could you explain in a bit more detail if possible?

Edit: Nevermind! What you said worked out great! Thanks Sigg!

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


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

Last edited by unlimit : 01-30-12 at 05:34 AM.
unlimit is offline   Reply With Quote
Unread 01-31-12, 04:53 AM   #4
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Alrighty, so I got it ALL working except for a few tiny things.

I plan on GREATLY expanding the functionality of my rotation priority feature later on for all of the classes I play, so I wanted to be able to really customize the button skin and such on my feature. I pretty much copied the IconsCustom button system into my feature, except, it doesn't actually work like it should... everything shows up in the descriptor, but - for example - I'm not able to actually set the color of my buttonskin in the options even though it looks like I am, it just remains white on the unitframe.

Also, I am using "Hide Empty Button", just, whenever my icon isn't up (which is whenever I'm not targeting a hostile unit), it still displays the button skin.

Here are my two features, so you get the idea:

lua Code:
  1. function TRUESYS.PriorityHunterBeastMastery()
  2.     local gcd = 1.5
  3.     local level = UnitLevel("player")
  4.     local focus = UnitPower("player")
  5.     local duration, _
  6.  
  7.     if not UnitCanAttack("player", "target") then
  8.         return
  9.     end
  10.  
  11.     -- 1. If your pet is on the target, Kill Command.
  12.     if UnitExists("pet") and UnitHealth("pet") > 1 and IsSpellInRange(RDXSS.GetSpellBookId("Growl", BOOKTYPE_PET),"pet","pettarget") == 1 and focus > 50 then
  13.         _, duration = GetSpellCooldown("Kill Command")
  14.         if duration <= gcd then
  15.             return GetSpellTexture("Kill Command")
  16.         end
  17.     end
  18.  
  19.     -- 2. If the mob is going to live long enough, apply Serpent Sting.
  20.     if focus > 25 then
  21.         if not UnitDebuff("target", "Serpent Sting") then
  22.             _, duration = GetSpellCooldown("Serpent Sting")
  23.             if duration <= gcd then
  24.                 return GetSpellTexture("Serpent Sting")
  25.             end
  26.         end
  27.     end
  28.  
  29.     -- 3. If mob is below 20% health, Kill Shot.
  30.     _, duration = GetSpellCooldown("Kill Shot")
  31.     if duration <= gcd and ( UnitHealth("target") / UnitHealthMax("target") < 0.2 ) then
  32.         return GetSpellTexture("Kill Shot")
  33.     end
  34.  
  35.     -- 4. If you will have enough focus to use Kill Command on cooldown, use Arcane Shot
  36.     if focus > 85 then
  37.         return GetSpellTexture("Arcane Shot")
  38.     end
  39.  
  40.     -- 5. Cobra Shot or Steady Shot.
  41.     if level < 81 then
  42.         return GetSpellTexture("Steady Shot")
  43.     else
  44.         return GetSpellTexture("Cobra Shot")
  45.     end
  46. end
  47.  
  48. -- Hunter 4.3 Priorities for CLCinfo (modified for OpenRDX) by Phanx @ [url]http://www.wowinterface.com/forums/showpost.php?p=251728&postcount=2[/url]
  49. function TRUESYS.PriorityHunterSurvival()
  50.     local gcd = 1.5
  51.     local level = UnitLevel("player")
  52.     local focus = UnitPower("player")
  53.     local duration, _
  54.  
  55.     if not UnitCanAttack("player", "target") then
  56.         return
  57.     end
  58.  
  59.     -- 1. If the mob is going to live long enough, apply Serpent Sting.
  60.     if focus > 25 then
  61.         if not UnitDebuff("target", "Serpent Sting") then
  62.             _, duration = GetSpellCooldown("Serpent Sting")
  63.             if duration <= gcd then
  64.                 return GetSpellTexture("Serpent Sting")
  65.             end
  66.         end
  67.     end
  68.    
  69.     -- 2. Explosive Shot
  70.     if focus > 50 then
  71.         _, duration = GetSpellCooldown("Explosive Shot")
  72.         if duration <= gcd then
  73.             return GetSpellTexture("Explosive Shot")
  74.         end
  75.     end
  76.  
  77.     -- 3. If mob is below 20% health, Kill Shot.
  78.     _, duration = GetSpellCooldown("Kill Shot")
  79.     if duration <= gcd and ( UnitHealth("target") / UnitHealthMax("target") < 0.2 ) then
  80.         return GetSpellTexture("Kill Shot")
  81.     end
  82.  
  83.     -- 4. If mob will be alive long enough, Black Arrow.
  84.     if level < 61 and focus > 35 then
  85.         _, duration = GetSpellCooldown("Black Arrow")
  86.         if duration <= gcd and ( UnitHealth("target") / dps > 15 ) then
  87.             return GetSpellTexture("Black Arrow")
  88.         end
  89.     end
  90.  
  91.     -- 5. If you will have enough focus to use Explosive Shot and Black Arrow, use Arcane Shot.
  92.     if focus > 85 then
  93.         return GetSpellTexture("Arcane Shot")
  94.     end
  95.  
  96.     -- 6. Cobra Shot or Steady Shot.
  97.     if level < 81 then
  98.         return GetSpellTexture("Steady Shot")
  99.     else
  100.         return GetSpellTexture("Cobra Shot")
  101.     end
  102. end

lua Code:
  1. RDX.RegisterFeature({
  2.     name = "(True) Hunter Priority Icon";
  3.     title = VFLI.i18n("(True) Priority Icon");
  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.         if not desc.usebkd then desc.usebs = true; end
  15.         local flg = true;
  16.         flg = flg and RDXUI.UFFrameCheck_Proto("Frame_", desc, state, errs);
  17.         flg = flg and RDXUI.UFAnchorCheck(desc.anchor, state, errs);
  18.         flg = flg and RDXUI.UFOwnerCheck(desc.owner, state, errs);
  19.         if flg then state:AddSlot("Frame_" .. desc.name); end
  20.         return flg;
  21.     end;
  22.     ApplyFeature = function(desc, state)
  23.         local objname = "Frame_" .. desc.name;
  24.         local usebs = "false"; if desc.usebs then usebs = "true"; end
  25.         local ebs = desc.externalButtonSkin or "bs_default";
  26.         local usebkd = "false"; if desc.usebkd then usebkd = "true"; end
  27.         local bkd = desc.bkd or VFLUI.defaultBackdrop; 
  28.         local os = 0;
  29.         if desc.usebs then
  30.             os = desc.ButtonSkinOffset or 0;
  31.         elseif desc.usebkd then
  32.             if desc.bkd and desc.bkd.insets and desc.bkd.insets.left then os = desc.bkd.insets.left or 0; end
  33.         end
  34.         local showgloss = "nil"; if desc.showgloss then showgloss = "true"; end
  35.         local bsdefault = desc.bsdefault or _white;
  36.         local hidebs = "nil"; if desc.hidebs then hidebs = "true"; end
  37.       ------------------ On frame creation
  38.         local createCode = [[      
  39. local btn, owner = nil, ]] .. RDXUI.ResolveFrameReference(desc.owner) .. [[;
  40. if ]] .. usebs .. [[ then
  41.     btn = VFLUI.SkinButton:new();
  42.     btn:SetButtonSkin("]] .. ebs ..[[", true, true, false, true, true, true, false, true, true, ]] .. showgloss ..[[);
  43. elseif ]] .. usebkd .. [[ then
  44.     btn = VFLUI.AcquireFrame("Button");
  45.     VFLUI.SetBackdrop(btn, ]] .. Serialize(bkd) .. [[);
  46. else
  47.     btn = VFLUI.AcquireFrame("Frame");
  48. end
  49. btn:SetParent(owner);
  50. btn:SetFrameLevel(owner:GetFrameLevel());
  51. btn:SetPoint(]] .. RDXUI.AnchorCodeFromDescriptor(desc.anchor) .. [[);
  52. btn:SetWidth(]] .. desc.w .. [[); btn:SetHeight(]] .. desc.h .. [[);
  53. btn._t = VFLUI.CreateTexture(btn);
  54. btn._t:SetDrawLayer("]] .. (desc.drawLayer or "ARTWORK") .. [[", 2);
  55. btn._t:SetPoint("CENTER", btn, "CENTER");
  56. btn._t:SetWidth(]] .. desc.w .. [[ - ]] .. os .. [[); btn._t:SetHeight(]] .. desc.h .. [[ - ]] .. os .. [[);
  57. btn._t:Show();
  58. btn:Hide();
  59. frame.]] .. objname .. [[ = btn;
  60. ]];
  61.         state:Attach(state:Slot("EmitCreate"), true, function(code) code:AppendCode(createCode); end);
  62.  
  63.         ------------------ On frame destruction.
  64.         state:Attach(state:Slot("EmitDestroy"), true, function(code) code:AppendCode([[
  65. VFLUI.ReleaseRegion(frame.]] .. objname .. [[._t); frame.]] .. objname .. [[._t = nil;
  66. frame.]] .. objname .. [[:Destroy(); frame.]] .. objname .. [[ = nil;
  67. ]]); end);
  68.         state:Attach(state:Slot("EmitCleanup"), true, function(code) code:AppendCode([[
  69. frame.]] .. objname .. [[:Hide();
  70. ]]); end);
  71.  
  72.         ------------------ On paint.
  73.         state:Attach(state:Slot("EmitPaint"), true, function(code)
  74.         if desc.test then
  75.             code:AppendCode([[
  76. frame.]] .. objname .. [[._t:SetTexture(GetSpellTexture("Kill Command"));
  77. frame.]] .. objname .. [[:Show();
  78. ]]);
  79.         else
  80.             code:AppendCode([[
  81. frame.]] .. objname .. [[._t:SetTexture(TRUESYS.PriorityHunterBeastMastery());
  82. frame.]] .. objname .. [[:Show();
  83. ]]);
  84.         end
  85.         end);
  86.         return true;
  87.     end;
  88.     UIFromDescriptor = function(desc, parent, state)
  89.         local ui = VFLUI.CompoundFrame:new(parent);
  90.        
  91.         -- Name/width/height
  92.         local ed_name, ed_width, ed_height = RDXUI.GenNameWidthHeightPortion(ui, desc, state);
  93.        
  94.         -- Owner
  95.         local owner = RDXUI.MakeSlotSelectorDropdown(ui, VFLI.i18n("Owner"), state, "Subframe_");
  96.         if desc and desc.owner then owner:SetSelection(desc.owner); end
  97.        
  98.         -- Drawlayer
  99.         local er = VFLUI.EmbedRight(ui, VFLI.i18n("Draw layer"));
  100.         local drawLayer = VFLUI.Dropdown:new(er, RDXUI.DrawLayerDropdownFunction);
  101.         drawLayer:SetWidth(100); drawLayer:Show();
  102.         if desc and desc.drawLayer then drawLayer:SetSelection(desc.drawLayer); else drawLayer:SetSelection("ARTWORK"); end
  103.         er:EmbedChild(drawLayer); er:Show();
  104.         ui:InsertFrame(er);
  105.        
  106.         -- Anchor
  107.         local anchor = RDXUI.UnitFrameAnchorSelector:new(ui); anchor:Show();
  108.         anchor:SetAFArray(RDXUI.ComposeAnchorList(state));
  109.         if desc and desc.anchor then anchor:SetAnchorInfo(desc.anchor); end
  110.         ui:InsertFrame(anchor);
  111.        
  112.         -------------- Display
  113.         ui:InsertFrame(VFLUI.Separator:new(ui, VFLI.i18n("Button Skin parameters")));
  114.        
  115.         local chk_bs = VFLUI.CheckEmbedRight(ui, VFLI.i18n("Use Button Skin"));
  116.         local dd_buttonSkin = VFLUI.Dropdown:new(chk_bs, VFLUI.GetButtonSkinList);
  117.         dd_buttonSkin:SetWidth(150); dd_buttonSkin:Show();
  118.         dd_buttonSkin:SetSelection(desc.externalButtonSkin);
  119.         if desc and desc.usebs then
  120.             chk_bs:SetChecked(true);
  121.         else
  122.             chk_bs:SetChecked();
  123.         end
  124.         chk_bs:EmbedChild(dd_buttonSkin); chk_bs:Show();
  125.         ui:InsertFrame(chk_bs);
  126.        
  127.         local ed_bs = VFLUI.LabeledEdit:new(ui, 50); ed_bs:Show();
  128.         ed_bs:SetText(VFLI.i18n("Button Skin Size Offset"));
  129.         if desc and desc.ButtonSkinOffset then ed_bs.editBox:SetText(desc.ButtonSkinOffset); end
  130.         ui:InsertFrame(ed_bs);
  131.        
  132.         local chk_showgloss = VFLUI.Checkbox:new(ui); chk_showgloss:Show();
  133.         chk_showgloss:SetText(VFLI.i18n("Button Skin Show Gloss"));
  134.         if desc and desc.showgloss then chk_showgloss:SetChecked(true); else chk_showgloss:SetChecked(); end
  135.         ui:InsertFrame(chk_showgloss);
  136.        
  137.         local color_bsdefault = RDXUI.GenerateColorSwatch(ui, VFLI.i18n("Button Skin default color"));
  138.         if desc and desc.bsdefault then color_bsdefault:SetColor(VFL.explodeRGBA(desc.bsdefault)); end
  139.        
  140.         local chk_bkd = VFLUI.CheckEmbedRight(ui, VFLI.i18n("Use Backdrop"));
  141.         local dd_backdrop = VFLUI.MakeBackdropSelectButton(chk_bkd, desc.bkd);
  142.         dd_backdrop:Show();
  143.         if desc and desc.usebkd then
  144.             chk_bkd:SetChecked(true);
  145.         else
  146.             chk_bkd:SetChecked();
  147.         end
  148.         chk_bkd:EmbedChild(dd_backdrop); chk_bkd:Show();
  149.         ui:InsertFrame(chk_bkd);
  150.        
  151.         local chk_hidebs = VFLUI.Checkbox:new(ui); chk_hidebs:Show();
  152.         chk_hidebs:SetText(VFLI.i18n("Hide empty button"));
  153.         if desc and desc.hidebs then chk_hidebs:SetChecked(true); else chk_hidebs:SetChecked(); end
  154.         ui:InsertFrame(chk_hidebs);
  155.        
  156.         function ui:GetDescriptor()
  157.         local name = ed_name.editBox:GetText();
  158.         local ebs = nil;
  159.         if chk_bs:GetChecked() then ebs = dd_buttonSkin:GetSelection(); end
  160.         return {
  161.             feature = "(True) Hunter Priority Icon", name = name, owner = owner:GetSelection();
  162.             drawLayer = drawLayer:GetSelection();
  163.             w = ed_width:GetSelection();
  164.             h = ed_height:GetSelection();
  165.             anchor = anchor:GetAnchorInfo();
  166.             -- display
  167.             usebs = chk_bs:GetChecked();
  168.             externalButtonSkin = dd_buttonSkin:GetSelection();
  169.             ButtonSkinOffset = VFL.clamp(ed_bs.editBox:GetNumber(), 0, 50);
  170.             showgloss = chk_showgloss:GetChecked();
  171.             bsdefault = color_bsdefault:GetColor();
  172.             usebkd = chk_bkd:GetChecked();
  173.             bkd = dd_backdrop:GetSelectedBackdrop();
  174.             hidebs = chk_hidebs:GetChecked();
  175.         };
  176.         end
  177.        
  178.         return ui;
  179.     end;
  180.     CreateDescriptor = function()
  181.         return {
  182.             feature = "(True) Hunter Priority Icon", name = "bmpi", owner = "decor", drawLayer = "ARTWORK";
  183.             w = 14; h = 14;
  184.             anchor = { lp = "TOPLEFT", af = "Base", rp = "TOPLEFT", dx = 0, dy = 0};
  185.             externalButtonSkin = "bs_default";
  186.             ButtonSkinOffset = 0;
  187.             bkd = VFL.copy(VFLUI.defaultBackdrop);
  188.         };
  189.     end;
  190. });

Honestly, except for the button skin, I'm 100% happy with the outcome of my work on these. They're exactly what I wanted. c.c
__________________


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

Last edited by unlimit : 01-31-12 at 05:18 AM.
unlimit is offline   Reply With Quote
Reply

Go BackWoWInterface » Featured Projects » OpenRDX » OpenRDX Support » OpenRDX: Bug/Error Reports » Icon Feature LUA Help

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off