Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- VaultWindow.lua
- -- written by Habna
- function frmVault()
- frmVT = true;
- tvaultpack = vaultpack;
- SelCN = PN;
- import (AppClassD.."ComboBox");
- VICB = HabnaPlugins.TitanBar.Class.ComboBox();
- -- **v Set some window stuff v**
- wVault = Turbine.UI.Lotro.Window()
- wVault:SetText( L["MVault"] );
- wVault:SetPosition( VTWLeft, VTWTop );
- wVault:SetWidth( 390 );
- wVault:SetWantsKeyEvents( true );
- wVault:SetVisible( true );
- --wVault:SetZOrder( 2 );
- --wVault:Activate();
- wVault.KeyDown = function( sender, args )
- if ( args.Action == Turbine.UI.Lotro.Action.Escape ) then
- wVault:Close();
- elseif ( args.Action == 268435635 ) or ( args.Action == 268435579 ) then -- Hide if F12 key is press or reposition UI
- wVault:SetVisible( not wVault:IsVisible() );
- end
- end
- wVault.MouseMove = function( sender, args )
- if VICB.dropped then
- local height = VICB:GetHeight();
- local x, y = VICB:GetParent():PointToScreen(VICB:GetPosition());
- VICB.dropDownWindow:SetPosition(x, y + height + 2);
- end
- end
- wVault.MouseUp = function( sender, args )
- settings.Vault.L = string.format("%.0f", wVault:GetLeft());
- settings.Vault.T = string.format("%.0f", wVault:GetTop());
- VTWLeft, VTWTop = wVault:GetPosition();
- SaveSettings( false );
- end
- wVault.Closing = function( sender, args ) -- Function for the Upper right X icon
- VICB.dropDownWindow:SetVisible(false);
- wVault:SetWantsKeyEvents( false );
- RemoveCallback( tvaultpack, "CountChanged" );
- wVault = nil;
- frmVT = nil;
- end
- -- **^
- -- **v Create drop down box v**
- VICB:SetParent( wVault );
- VICB:SetSize( 159, 19 );
- VICB:SetPosition( 15, 35 );
- --VICB:SetVisible( true );
- VICB.ItemChanged = function(sender, args) -- The event that's executed when a menu item is clicked.
- SelCN = VICB.label:GetText();
- CountVIItems();
- end
- CreateVIComboBox();
- local searchLabel = Turbine.UI.Label();
- searchLabel:SetParent(wVault);
- searchLabel:SetText("Search:");
- searchLabel:SetPosition(15, 60);
- searchLabel:SetWidth(50);
- searchLabel:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
- searchLabel:SetForeColor(Turbine.UI.Color.Khaki);
- wVault.SearchTextBox = Turbine.UI.Lotro.TextBox();
- wVault.SearchTextBox:SetParent(wVault);
- wVault.SearchTextBox:SetPosition(70, 60);
- wVault.SearchTextBox:SetSize(wVault:GetWidth()-150, 18);
- wVault.SearchTextBox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
- wVault.SearchTextBox.TextChanged = function(sender, args)
- wVault.searchText = string.lower(wVault.SearchTextBox:GetText());
- if wVault.searchText == "" then
- wVault.searchText = nil;
- end
- CountVIItems();
- end
- -- **^
- -- **v Set the itemlistbox border v**
- wVault.ListBoxBorder = Turbine.UI.Control();
- wVault.ListBoxBorder:SetParent( wVault );
- wVault.ListBoxBorder:SetPosition( 15, 80 );
- wVault.ListBoxBorder:SetWidth( wVault:GetWidth()-30 );
- wVault.ListBoxBorder:SetBackColor( Color["grey"] );
- wVault.ListBoxBorder:SetVisible( true );
- -- **^
- -- **v Set the itemlistbox v**
- wVault.ListBox = Turbine.UI.ListBox();
- wVault.ListBox:SetParent( wVault );
- wVault.ListBox:SetPosition( wVault.ListBoxBorder:GetLeft() + 2, wVault.ListBoxBorder:GetTop() + 2 );
- wVault.ListBox:SetWidth( wVault.ListBoxBorder:GetWidth() - 4 );
- wVault.ListBox:SetMaxItemsPerLine( 1 );
- wVault.ListBox:SetOrientation( Turbine.UI.Orientation.Horizontal );
- wVault.ListBox:SetBackColor( Color["black"] );
- -- **^
- -- **v Set the scrollbar v**
- wVault.ListBoxScrollBar = Turbine.UI.Lotro.ScrollBar();
- wVault.ListBoxScrollBar:SetParent( wVault );
- wVault.ListBoxScrollBar:SetOrientation( Turbine.UI.Orientation.Vertical );
- wVault.ListBox:SetVerticalScrollBar( wVault.ListBoxScrollBar );
- wVault.ListBoxScrollBar:SetPosition( wVault:GetWidth()-28, wVault.ListBox:GetTop() + 2 );
- wVault.ListBoxScrollBar:SetWidth( 10 );
- -- **^
- -- **v Delete character infos button v**
- wVault.ButtonDelete = Turbine.UI.Lotro.Button();
- wVault.ButtonDelete:SetParent( wVault );
- wVault.ButtonDelete:SetText( L["ButDel"] );
- wVault.ButtonDelete:SetSize( wVault.ButtonDelete:GetTextLength() * 11, 15 ); --Auto size with text lenght
- wVault.ButtonDelete.Click = function( sender, args )
- PlayerVault[SelCN] = nil;
- SavePlayerVault();
- write(SelCN .. L["VTID"]);
- SelCN = PN;
- VICB.selection = -1;
- CreateVIComboBox();
- CountVIItems();
- end
- -- **^
- AddCallback(tvaultpack, "CountChanged",
- function(sender, args)
- if frmVT then
- if SelCN == PN or SelCN == "-- All --" then
- CountVIItems();
- end
- end
- end);
- CountVIItems();
- end
- function CountVIItems()
- vaultpackCount = 0;
- wVault.ListBox:ClearItems();
- itemCtl = {};
- if SelCN == "-- All --" then
- for i in pairs(PlayerVault) do
- AddVaultPack(i, true);
- end
- else
- AddVaultPack(SelCN, false);
- end
- if vaultPackCount == 0 then
- SetEmptyVault();
- end
- wVault.ButtonDelete:SetPosition( wVault:GetWidth()/2 - wVault.ButtonDelete:GetWidth()/2, wVault.ListBox:GetTop()+wVault.ListBox:GetHeight()+10 );
- -- Set window title
- --wVault:SetText( L["MVault"] .. " - " .. L["VTFree"] .. ( vaultpackSize - vaultpackCount ) .. L["VTUsed"] .. vaultpackCount .. L["VTMax"] .. vaultpackSize );
- end
- function CreateVIComboBox()
- -- **v Create an array of character name, sort it, then use it as a reference - label & DropDown box v**
- local newt = {}
- for i in pairs(PlayerVault) do
- if string.sub( i, 1, 1 ) == "~" then PlayerVault[i] = nil; else table.insert(newt,i); end --Delete session play character
- end
- table.sort(newt);
- VICB.listBox:ClearItems();
- VICB:AddItem("-- All --", 0);
- for k,v in pairs(newt) do
- VICB:AddItem(v, k);
- if v == PN then VICB:SetSelection(k); end
- end
- -- **^
- end
- function SetEmptyVault()
- -- Item control
- itemCtl = Turbine.UI.Control();
- itemCtl:SetSize( wVault.ListBox:GetWidth(), 35 );
- local lblmgs = Turbine.UI.Label();
- lblmgs:SetParent( itemCtl );
- lblmgs:SetText( L["VTnd"] );
- lblmgs:SetPosition( 0, 0 );
- lblmgs:SetSize( itemCtl:GetWidth(), itemCtl:GetHeight() );
- lblmgs:SetForeColor( Color["green"] );
- lblmgs:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
- wVault.ListBox:SetHeight( lblmgs:GetHeight() );
- wVault.ListBoxBorder:SetHeight( wVault.ListBox:GetHeight()+4 );
- wVault:SetHeight( itemCtl:GetHeight()+85 );
- wVault.ListBox:AddItem( itemCtl );
- wVault.ButtonDelete:SetVisible( false );
- end
- function AddVaultPack(n, addCharacterName)
- local count = 0;
- if PlayerVault[n] ~= nil then for k, v in pairs(PlayerVault[n]) do count = count + 1; end end
- for i = 1, count do
- local itemName = PlayerVault[n][tostring(i)].T;
- if not wVault.searchText or string.find(string.lower(itemName), wVault.searchText, 1, true) then
- vaultpackCount = vaultpackCount + 1;
- -- Item control
- itemCtl[vaultpackCount] = Turbine.UI.Control();
- itemCtl[vaultpackCount]:SetSize( wVault.ListBox:GetWidth()-12, 35 );
- -- Item Background/Underlay/Shadow/Image
- local itemBG = Turbine.UI.Control();
- itemBG:SetParent( itemCtl[vaultpackCount] );
- itemBG:SetSize( 32, 32 );
- itemBG:SetPosition( 3, 3 );
- itemBG:SetBackground(tonumber(PlayerVault[n][tostring(i)].B));
- itemBG:SetBlendMode( Turbine.UI.BlendMode.Overlay );
- local itemU = Turbine.UI.Control();
- itemU:SetParent( itemCtl[vaultpackCount] );
- itemU:SetSize( 32, 32 );
- itemU:SetPosition( 3, 3 );
- if PlayerVault[n][tostring(i)].U ~= "0" then itemU:SetBackground(tonumber(PlayerVault[n][tostring(i)].U)); end
- itemU:SetBlendMode( Turbine.UI.BlendMode.Overlay );
- local itemS = Turbine.UI.Control();
- itemS:SetParent( itemCtl[vaultpackCount] );
- itemS:SetSize( 32, 32 );
- itemS:SetPosition( 3, 3 );
- if PlayerVault[n][tostring(i)].S ~= "0" then itemS:SetBackground(tonumber(PlayerVault[n][tostring(i)].S)); end
- itemS:SetBlendMode( Turbine.UI.BlendMode.Overlay );
- local item = Turbine.UI.Control();
- item:SetParent( itemCtl[vaultpackCount] );
- item:SetSize( 32, 32 );
- item:SetPosition( 3, 3 );
- item:SetBackground(tonumber(PlayerVault[n][tostring(i)].I));
- item:SetBlendMode( Turbine.UI.BlendMode.Overlay );
- -- Item Quantity
- local itemQTE = Turbine.UI.Label();
- itemQTE:SetParent( itemCtl[vaultpackCount] );
- itemQTE:SetSize( 32, 15 );
- itemQTE:SetPosition( -4, 16 );
- itemQTE:SetFont( Turbine.UI.Lotro.Font.Verdana12 );
- itemQTE:SetFontStyle( Turbine.UI.FontStyle.Outline );
- itemQTE:SetOutlineColor( Color["black"] );
- itemQTE:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );
- itemQTE:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
- itemQTE:SetForeColor( Color["nicegold"] );
- itemQTE:SetText(tonumber(PlayerVault[n][tostring(i)].N));
- -- Item name
- local itemLbl = Turbine.UI.Label();
- itemLbl:SetParent( itemCtl[vaultpackCount] );
- itemLbl:SetSize( itemCtl[vaultpackCount]:GetWidth() - 35, 35 );
- itemLbl:SetPosition( 37, 2 );
- itemLbl:SetFont( Turbine.UI.Lotro.Font.TrajanPro16 );
- itemLbl:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleLeft );
- itemLbl:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
- itemLbl:SetForeColor( Color["white"] );
- if addCharacterName then
- itemLbl:SetText( itemName .. " (" .. n .. ")");
- else
- itemLbl:SetText( itemName );
- end
- wVault.ListBox:AddItem( itemCtl[vaultpackCount] );
- wVault.ButtonDelete:SetVisible( true );
- if SelCN == PN then wVault.ButtonDelete:SetEnabled( false );
- else wVault.ButtonDelete:SetEnabled( true ); end
- end
- end
- wVault.ListBoxBorder:SetHeight( 390 );
- wVault.ListBox:SetHeight( wVault.ListBoxBorder:GetHeight() - 4 );
- wVault.ListBoxScrollBar:SetHeight( wVault.ListBox:GetHeight() - 2 );
- wVault:SetHeight( 520 );
- end
Advertisement
Add Comment
Please, Sign In to add comment