Guest User

VaultWindow.lua

a guest
Jan 30th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.61 KB | None | 0 0
  1. -- VaultWindow.lua
  2. -- written by Habna
  3.  
  4.  
  5. function frmVault()
  6.     frmVT = true;
  7.     tvaultpack = vaultpack;
  8.     SelCN = PN;
  9.     import (AppClassD.."ComboBox");
  10.     VICB = HabnaPlugins.TitanBar.Class.ComboBox();
  11.  
  12.     -- **v Set some window stuff v**
  13.     wVault = Turbine.UI.Lotro.Window()
  14.     wVault:SetText( L["MVault"] );
  15.     wVault:SetPosition( VTWLeft, VTWTop );
  16.     wVault:SetWidth( 390 );
  17.     wVault:SetWantsKeyEvents( true );
  18.     wVault:SetVisible( true );
  19.     --wVault:SetZOrder( 2 );
  20.     --wVault:Activate();
  21.  
  22.     wVault.KeyDown = function( sender, args )
  23.         if ( args.Action == Turbine.UI.Lotro.Action.Escape ) then
  24.             wVault:Close();
  25.         elseif ( args.Action == 268435635 ) or ( args.Action == 268435579 ) then -- Hide if F12 key is press or reposition UI
  26.             wVault:SetVisible( not wVault:IsVisible() );
  27.         end
  28.     end
  29.  
  30.     wVault.MouseMove = function( sender, args )
  31.         if VICB.dropped then
  32.             local height = VICB:GetHeight();
  33.             local x, y = VICB:GetParent():PointToScreen(VICB:GetPosition());
  34.             VICB.dropDownWindow:SetPosition(x, y + height + 2);
  35.         end
  36.     end
  37.  
  38.     wVault.MouseUp = function( sender, args )
  39.         settings.Vault.L = string.format("%.0f", wVault:GetLeft());
  40.         settings.Vault.T = string.format("%.0f", wVault:GetTop());
  41.         VTWLeft, VTWTop = wVault:GetPosition();
  42.         SaveSettings( false );
  43.     end
  44.  
  45.     wVault.Closing = function( sender, args ) -- Function for the Upper right X icon
  46.         VICB.dropDownWindow:SetVisible(false);
  47.         wVault:SetWantsKeyEvents( false );
  48.         RemoveCallback( tvaultpack, "CountChanged" );
  49.         wVault = nil;
  50.         frmVT = nil;
  51.     end
  52.     -- **^
  53.     -- **v Create drop down box v**
  54.     VICB:SetParent( wVault );
  55.     VICB:SetSize( 159, 19 );
  56.     VICB:SetPosition( 15, 35 );
  57.     --VICB:SetVisible( true );
  58.  
  59.     VICB.ItemChanged = function(sender, args) -- The event that's executed when a menu item is clicked.
  60.         SelCN = VICB.label:GetText();
  61.         CountVIItems();
  62.     end
  63.  
  64.     CreateVIComboBox();
  65.  
  66.     local searchLabel = Turbine.UI.Label();
  67.     searchLabel:SetParent(wVault);
  68.     searchLabel:SetText("Search:");
  69.     searchLabel:SetPosition(15, 60);
  70.     searchLabel:SetWidth(50);
  71.     searchLabel:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
  72.     searchLabel:SetForeColor(Turbine.UI.Color.Khaki);
  73.  
  74.     wVault.SearchTextBox = Turbine.UI.Lotro.TextBox();
  75.     wVault.SearchTextBox:SetParent(wVault);
  76.     wVault.SearchTextBox:SetPosition(70, 60);
  77.     wVault.SearchTextBox:SetSize(wVault:GetWidth()-150, 18);
  78.     wVault.SearchTextBox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
  79.  
  80.     wVault.SearchTextBox.TextChanged = function(sender, args)
  81.         wVault.searchText = string.lower(wVault.SearchTextBox:GetText());
  82.         if wVault.searchText == "" then
  83.             wVault.searchText = nil;
  84.         end
  85.         CountVIItems();
  86.     end
  87.  
  88.     -- **^
  89.     -- **v Set the itemlistbox border v**
  90.     wVault.ListBoxBorder = Turbine.UI.Control();
  91.     wVault.ListBoxBorder:SetParent( wVault );
  92.     wVault.ListBoxBorder:SetPosition( 15, 80 );
  93.     wVault.ListBoxBorder:SetWidth( wVault:GetWidth()-30 );
  94.     wVault.ListBoxBorder:SetBackColor( Color["grey"] );
  95.     wVault.ListBoxBorder:SetVisible( true );
  96.     -- **^
  97.     -- **v Set the itemlistbox v**
  98.     wVault.ListBox = Turbine.UI.ListBox();
  99.     wVault.ListBox:SetParent( wVault );
  100.     wVault.ListBox:SetPosition( wVault.ListBoxBorder:GetLeft() + 2, wVault.ListBoxBorder:GetTop() + 2 );
  101.     wVault.ListBox:SetWidth( wVault.ListBoxBorder:GetWidth() - 4 );
  102.     wVault.ListBox:SetMaxItemsPerLine( 1 );
  103.     wVault.ListBox:SetOrientation( Turbine.UI.Orientation.Horizontal );
  104.     wVault.ListBox:SetBackColor( Color["black"] );
  105.     -- **^
  106.     -- **v Set the scrollbar v**
  107.     wVault.ListBoxScrollBar = Turbine.UI.Lotro.ScrollBar();
  108.     wVault.ListBoxScrollBar:SetParent( wVault );
  109.     wVault.ListBoxScrollBar:SetOrientation( Turbine.UI.Orientation.Vertical );
  110.     wVault.ListBox:SetVerticalScrollBar( wVault.ListBoxScrollBar );
  111.     wVault.ListBoxScrollBar:SetPosition( wVault:GetWidth()-28, wVault.ListBox:GetTop() + 2 );
  112.     wVault.ListBoxScrollBar:SetWidth( 10 );
  113.     -- **^
  114.     -- **v Delete character infos button v**
  115.     wVault.ButtonDelete = Turbine.UI.Lotro.Button();
  116.     wVault.ButtonDelete:SetParent( wVault );
  117.     wVault.ButtonDelete:SetText( L["ButDel"] );
  118.     wVault.ButtonDelete:SetSize( wVault.ButtonDelete:GetTextLength() * 11, 15 ); --Auto size with text lenght
  119.  
  120.     wVault.ButtonDelete.Click = function( sender, args )
  121.         PlayerVault[SelCN] = nil;
  122.         SavePlayerVault();
  123.         write(SelCN .. L["VTID"]);
  124.         SelCN = PN;
  125.         VICB.selection = -1;
  126.         CreateVIComboBox();
  127.         CountVIItems();
  128.     end
  129.     -- **^
  130.  
  131.     AddCallback(tvaultpack, "CountChanged",
  132.         function(sender, args)
  133.         if frmVT then
  134.             if SelCN == PN or SelCN == "-- All --" then
  135.                 CountVIItems();
  136.             end
  137.         end
  138.     end);
  139.  
  140.     CountVIItems();
  141. end
  142.  
  143. function CountVIItems()
  144.     vaultpackCount = 0;
  145.     wVault.ListBox:ClearItems();
  146.     itemCtl = {};
  147.  
  148.     if SelCN == "-- All --" then
  149.         for i in pairs(PlayerVault) do
  150.             AddVaultPack(i, true);
  151.         end
  152.     else
  153.         AddVaultPack(SelCN, false);
  154.     end
  155.  
  156.     if vaultPackCount == 0 then
  157.         SetEmptyVault();
  158.     end
  159.  
  160.     wVault.ButtonDelete:SetPosition( wVault:GetWidth()/2 - wVault.ButtonDelete:GetWidth()/2, wVault.ListBox:GetTop()+wVault.ListBox:GetHeight()+10 );
  161.  
  162.     -- Set window title
  163.     --wVault:SetText( L["MVault"] .. " - " .. L["VTFree"] .. ( vaultpackSize - vaultpackCount ) .. L["VTUsed"] .. vaultpackCount .. L["VTMax"] .. vaultpackSize );
  164. end
  165.  
  166. function CreateVIComboBox()
  167.     -- **v Create an array of character name, sort it, then use it as a reference - label & DropDown box v**
  168.     local newt = {}
  169.     for i in pairs(PlayerVault) do
  170.         if string.sub( i, 1, 1 ) == "~" then PlayerVault[i] = nil; else table.insert(newt,i); end --Delete session play character
  171.     end
  172.     table.sort(newt);
  173.     VICB.listBox:ClearItems();
  174.     VICB:AddItem("-- All --", 0);
  175.     for k,v in pairs(newt) do
  176.         VICB:AddItem(v, k);
  177.         if v == PN then VICB:SetSelection(k); end
  178.     end
  179.     -- **^
  180. end
  181.  
  182. function SetEmptyVault()
  183.     -- Item control
  184.     itemCtl = Turbine.UI.Control();
  185.     itemCtl:SetSize( wVault.ListBox:GetWidth(), 35 );
  186.  
  187.     local lblmgs = Turbine.UI.Label();
  188.     lblmgs:SetParent( itemCtl );
  189.     lblmgs:SetText( L["VTnd"] );
  190.     lblmgs:SetPosition( 0, 0 );
  191.     lblmgs:SetSize( itemCtl:GetWidth(), itemCtl:GetHeight() );
  192.     lblmgs:SetForeColor( Color["green"] );
  193.     lblmgs:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
  194.  
  195.     wVault.ListBox:SetHeight( lblmgs:GetHeight() );
  196.     wVault.ListBoxBorder:SetHeight( wVault.ListBox:GetHeight()+4 );
  197.     wVault:SetHeight( itemCtl:GetHeight()+85 );
  198.  
  199.     wVault.ListBox:AddItem( itemCtl );
  200.     wVault.ButtonDelete:SetVisible( false );
  201. end
  202.  
  203. function AddVaultPack(n, addCharacterName)
  204.     local count = 0;
  205.     if PlayerVault[n] ~= nil then for k, v in pairs(PlayerVault[n]) do count = count + 1; end end
  206.  
  207.     for i = 1, count do
  208.         local itemName = PlayerVault[n][tostring(i)].T;
  209.         if not wVault.searchText or string.find(string.lower(itemName), wVault.searchText, 1, true) then
  210.             vaultpackCount = vaultpackCount + 1;
  211.  
  212.             -- Item control
  213.             itemCtl[vaultpackCount] = Turbine.UI.Control();
  214.             itemCtl[vaultpackCount]:SetSize( wVault.ListBox:GetWidth()-12, 35 );
  215.  
  216.             -- Item Background/Underlay/Shadow/Image
  217.             local itemBG = Turbine.UI.Control();
  218.             itemBG:SetParent( itemCtl[vaultpackCount] );
  219.             itemBG:SetSize( 32, 32 );
  220.             itemBG:SetPosition( 3, 3 );
  221.             itemBG:SetBackground(tonumber(PlayerVault[n][tostring(i)].B));
  222.             itemBG:SetBlendMode( Turbine.UI.BlendMode.Overlay );
  223.        
  224.             local itemU = Turbine.UI.Control();
  225.             itemU:SetParent( itemCtl[vaultpackCount] );
  226.             itemU:SetSize( 32, 32 );
  227.             itemU:SetPosition( 3, 3 );
  228.             if PlayerVault[n][tostring(i)].U ~= "0" then itemU:SetBackground(tonumber(PlayerVault[n][tostring(i)].U)); end
  229.             itemU:SetBlendMode( Turbine.UI.BlendMode.Overlay );
  230.  
  231.             local itemS = Turbine.UI.Control();
  232.             itemS:SetParent( itemCtl[vaultpackCount] );
  233.             itemS:SetSize( 32, 32 );
  234.             itemS:SetPosition( 3, 3 );
  235.             if PlayerVault[n][tostring(i)].S ~= "0" then itemS:SetBackground(tonumber(PlayerVault[n][tostring(i)].S)); end
  236.             itemS:SetBlendMode( Turbine.UI.BlendMode.Overlay );
  237.  
  238.             local item = Turbine.UI.Control();
  239.             item:SetParent( itemCtl[vaultpackCount] );
  240.             item:SetSize( 32, 32 );
  241.             item:SetPosition( 3, 3 );
  242.             item:SetBackground(tonumber(PlayerVault[n][tostring(i)].I));
  243.             item:SetBlendMode( Turbine.UI.BlendMode.Overlay );
  244.  
  245.             -- Item Quantity
  246.             local itemQTE = Turbine.UI.Label();
  247.             itemQTE:SetParent( itemCtl[vaultpackCount] );
  248.             itemQTE:SetSize( 32, 15 );
  249.             itemQTE:SetPosition( -4, 16 );
  250.             itemQTE:SetFont( Turbine.UI.Lotro.Font.Verdana12 );
  251.             itemQTE:SetFontStyle( Turbine.UI.FontStyle.Outline );
  252.             itemQTE:SetOutlineColor( Color["black"] );
  253.             itemQTE:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );
  254.             itemQTE:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
  255.             itemQTE:SetForeColor( Color["nicegold"] );
  256.             itemQTE:SetText(tonumber(PlayerVault[n][tostring(i)].N));
  257.  
  258.             -- Item name
  259.             local itemLbl = Turbine.UI.Label();
  260.             itemLbl:SetParent( itemCtl[vaultpackCount] );
  261.             itemLbl:SetSize( itemCtl[vaultpackCount]:GetWidth() - 35, 35 );
  262.             itemLbl:SetPosition( 37, 2 );
  263.             itemLbl:SetFont( Turbine.UI.Lotro.Font.TrajanPro16 );
  264.             itemLbl:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleLeft );
  265.             itemLbl:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
  266.             itemLbl:SetForeColor( Color["white"] );
  267.             if addCharacterName then
  268.                 itemLbl:SetText( itemName .. " (" .. n .. ")");
  269.             else
  270.                 itemLbl:SetText( itemName );
  271.             end
  272.  
  273.             wVault.ListBox:AddItem( itemCtl[vaultpackCount] );
  274.             wVault.ButtonDelete:SetVisible( true );
  275.             if SelCN == PN then wVault.ButtonDelete:SetEnabled( false );
  276.             else wVault.ButtonDelete:SetEnabled( true ); end
  277.         end
  278.     end
  279.  
  280.     wVault.ListBoxBorder:SetHeight( 390 );
  281.     wVault.ListBox:SetHeight( wVault.ListBoxBorder:GetHeight() - 4 );
  282.     wVault.ListBoxScrollBar:SetHeight( wVault.ListBox:GetHeight() - 2 );
  283.     wVault:SetHeight( 520 );
  284. end
Advertisement
Add Comment
Please, Sign In to add comment