Thread Tools Display Modes
12-10-11, 08:31 PM   #1
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Fractional Currency

So I made a new feature for currency display, the only problem is that you are unable to automatically update the "maximum currency", so to remedy this, I added the option for you to be able to define your own limit.

http://www.wowpedia.org/API_GetCurrencyInfo <- Currency ID's

It requires you to be realistic, you can't set your max currency to 5000 for honor when you can only get 4000 in total. However, if you have a goal in between 0 and whatever the maximum is for your tracked currency, you could always do less, that way you know when you're there!

Optimize it if you can, I'm sloppy! I just threw everything together as best as I could.

lua Code:
  1. -- CID: Currency ID
  2. --- Available here: wowhead.com/currencies
  3.  
  4. -- CTA: Currency, Total Amount
  5. --- Manually specified cap,  e.g. 4000 maximum honor.
  6. ---- Unfortunately, "_,_,_,_,_,totalMax,_ = GetCurrencyInfo()" returns seem to be bugged, so an automatic cap
  7. ---- is impossible currently, unless someone has a better alternative or knows something I don't.
  8. ----- Confirmed here: wowinterface.com/forums/showthread.php?p=249103#post249103
  9.  
  10. function RDXDAL.Unit:FracCurrency(cid,cta)
  11.     local _,currentAmount,_,_,_,_,_ = GetCurrencyInfo(cid)
  12.     local a,b = currentAmount,cta;
  13.     local fractional
  14.     if(b<1) then fractional = 0; end
  15.     a=a/b;
  16.     if a<0 then fractional = 0 elseif a>1 then fractional = 1; else fractional = a; end
  17.     return currentAmount,fractional
  18. end
  19.  
  20. RDX.RegisterFeature({
  21.     name = "Variable: Fractional Currency";
  22.     title = "Vars Frac Currency";
  23.     category = VFLI.i18n("Variables");
  24.     test = true;
  25.     multiple = true;
  26.     IsPossible = function(state)
  27.         if not state:Slot("DesignFrame") then return nil; end
  28.         if not state:Slot("EmitPaintPreamble") then return nil; end
  29.         return true;
  30.     end;
  31.     ExposeFeature = function(desc, state, errs)
  32.         if not desc then VFL.AddError(errs, VFLI.i18n("No descriptor.")); return nil; end
  33.         if not RDX._CheckVariableNameValidity(desc.name, state, errs) then return nil; end
  34.         if not desc.name then desc.name = "cid"; end
  35.         if not desc.currencyid then desc.currencyid = "nil"; end
  36.         if not desc.currencytotalamount then desc.currencytotalamount = "nil"; end
  37.         state:AddSlot("Var_" .. desc.name);
  38.         state:AddSlot("FracVar_" .. desc.name);
  39.         state:AddSlot("TextData_" .. desc.name .. "txt");
  40.         return true;
  41.     end;
  42.     ApplyFeature = function(desc, state)
  43.         state:Attach(state:Slot("EmitPaintPreamble"), true, function(code)
  44.         code:AppendCode([[
  45. local currentAmount,fractional = unit:FracCurrency(]] .. desc.currencyid .. [[,]] .. desc.currencytotalamount .. [[);
  46. local ]] .. desc.name .. [[ = fractional
  47. local ]] .. desc.name .. [[txt = string.format("%0.0f%% | %s / %s", (currentAmount/]] .. desc.currencytotalamount .. [[)*100, currentAmount, ]] .. desc.currencytotalamount .. [[);
  48. ]]);
  49.         end);
  50.         local mux = state:GetContainingWindowState():GetSlotValue("Multiplexer");
  51.         mux:Event_MaskAll("CURRENCY_DISPLAY_UPDATE", 2);
  52.     end;
  53.  
  54.     UIFromDescriptor = function(desc, parent, state)
  55.         local ui = VFLUI.CompoundFrame:new(parent);
  56.  
  57.         local name = VFLUI.LabeledEdit:new(ui, 100); name:Show();
  58.         name:SetText(VFLI.i18n("Variable Name"));
  59.         if desc and desc.name then name.editBox:SetText(desc.name); else name.editBox:SetText("currencyid"); end
  60.         ui:InsertFrame(name);
  61.  
  62.         local currencyid = VFLUI.LabeledEdit:new(ui, 100); currencyid:Show();
  63.         currencyid:SetText(VFLI.i18n("Currency: ID"));
  64.         if desc and desc.currencyid then currencyid.editBox:SetText(desc.currencyid); else currencyid.editBox:SetText("392"); end
  65.         ui:InsertFrame(currencyid);
  66.        
  67.         local currencytotalamount = VFLUI.LabeledEdit:new(ui, 140); currencytotalamount:Show();
  68.         currencytotalamount:SetText(VFLI.i18n("Currency: Total Amount"));
  69.         if desc and desc.currencytotalamount then currencytotalamount.editBox:SetText(desc.currencytotalamount); else currencytotalamount.editBox:SetText("4000"); end
  70.         ui:InsertFrame(currencytotalamount);
  71.  
  72.         function ui:GetDescriptor()
  73.             return {
  74.                 feature = "Variable: Fractional Currency (cid)";
  75.                 name = name.editBox:GetText();
  76.                 currencyid = currencyid.editBox:GetText();
  77.                 currencytotalamount = currencytotalamount.editBox:GetText();
  78.             };
  79.         end
  80.  
  81.         return ui;
  82.     end;
  83.     CreateDescriptor = function() return { feature = "Variable: Fractional Currency (cid)"; name = "cid"; currencyid = "nil"; currencytotalamount = "nil" }; end
  84. });
__________________


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

Last edited by unlimit : 12-12-11 at 03:13 AM.
  Reply With Quote
12-12-11, 09:37 AM   #2
sigg
Featured Artist
 
sigg's Avatar
Featured
Join Date: Aug 2008
Posts: 1,251
Add into RDX

Thanks Unlimit.
__________________
RDX manager
Sigg
  Reply With Quote
12-12-11, 01:47 PM   #3
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Woops, my mistake, I made a change at the last minute and forgot to change the rest of it.

Changed the variable name from "Variable: Fractional Currency (cid)" into "Variable: Fractional Currency"


Change line 74 into
Code:
feature = "Variable: Fractional Currency";
Change line 83 into
Code:
CreateDescriptor = function() return { feature = "Variable: Fractional Currency"; name = "cid"; currencyid = "nil"; currencytotalamount = "nil" }; end
Sorry for the screw up! xD
__________________


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

Last edited by unlimit : 12-12-11 at 01:48 PM. Reason: Woops! Sorry!
  Reply With Quote
12-12-11, 01:57 PM   #4
sigg
Featured Artist
 
sigg's Avatar
Featured
Join Date: Aug 2008
Posts: 1,251
Fix in github
__________________
RDX manager
Sigg
  Reply With Quote

WoWInterface » Featured Projects » OpenRDX » OpenRDX Community » OpenRDX: Community Chat » Fractional Currency


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