View Single Post
  #9  
Unread 09-26-2010, 05:20 PM
Olenn's Avatar
Olenn Olenn is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 47
I was under the assumption that

Code:
Data = Turbine.PluginData.Load( Turbine.DataScope.Character, "SatchelData")
declared the variable...this is the most frusteraiting thing ever...back to boarders, lol. It still isn't working...


Here is all of my code thus far...

Code:
import "Turbine";
import "Turbine.Gameplay";
import "Turbine.UI";
import "Turbine.UI.Extensions";
import "Turbine.UI.Lotro";
import "Turbine.Utils";

SatchelWindow = class( Turbine.UI.Window );
Data = Turbine.PluginData.Load( Turbine.DataScope.Character, "SatchelData")
if Data==nil then Data={} end


function SatchelWindow:Constructor()
----CREATE THE WINDOW----
	Turbine.UI.Lotro.Window.Constructor( self );
	self:SetText("Satchel");
	self:SetSize( 325, 275 );
	Data = Turbine.PluginData.Load( Turbine.DataScope.Character, "SatchelData")
	

----SATCHEL CLOSES WHEN ESC IS PRESSED----
	self:SetWantsKeyEvents( true );
	self.KeyDown = function( sender, args )
		if ( args.Action == Turbine.UI.Lotro.Action.Escape ) then
			sender:SetVisible( false ) 
		end

----SAVE WINDOW POSITION----
	self.PositionChanged=function(sender,args)
		Data.x,Data.y=self:GetPosition()
		
	end
	
		
----MAKE BAG BUTTONS ON THE TOOLBAR OPEN SATCHEL----
		if ( args.Action == Turbine.UI.Lotro.Action.ToggleBags or
		     args.Action == Turbine.UI.Lotro.Action.ToggleBag1 or
			 args.Action == Turbine.UI.Lotro.Action.ToggleBag2 or
			 args.Action == Turbine.UI.Lotro.Action.ToggleBag3 or
			 args.Action == Turbine.UI.Lotro.Action.ToggleBag4 or
			 args.Action == Turbine.UI.Lotro.Action.ToggleBag5 )
		then
			sender:SetVisible( not sender:IsVisible() ) 
		end
	end
	
	local satchel = self;
	local mainWindow = self;
	
	self.itemListBoxScrollBar = Turbine.UI.Lotro.ScrollBar();
	self.itemListBoxScrollBar:SetOrientation( Turbine.UI.Orientation.Vertical );
	self.itemListBoxScrollBar:SetParent( self );

	self.itemListBox = Turbine.UI.ListBox();
	self.itemListBox:SetParent( self );
	self.itemListBox:SetOrientation( Turbine.UI.Orientation.Horizontal );
	self.itemListBox:SetVerticalScrollBar( self.itemListBoxScrollBar );
	self.itemListBox:SetAllowDrop( true );
	
	self.itemListBox.DragDrop = function( sender, args )
		local shortcut = args.DragDropInfo:GetShortcut();
		if ( shortcut ~= nil ) then
		  local destinationItemControl = self.itemListBox:GetItemAt( args.X, args.Y );
		  local destinationIndex = self.itemListBox:IndexOfItem( destinationItemControl );
		  self.backpack:PerformShortcutDrop( shortcut, destinationIndex, Turbine.UI.Control.IsShiftKeyDown() );
		end
	end
----MAKE WINDOW RESIZABLE----
	self.resizeHandle = Turbine.UI.Control();
	self.resizeHandle:SetParent( self );
	self.resizeHandle:SetZOrder( 100 );
	self.resizeHandle:SetSize( 20, 20 );
	self.resizeHandle:SetPosition( self:GetWidth() - self.resizeHandle:GetWidth(), self:GetHeight() - self.resizeHandle:GetHeight() );

	self.resizeHandle.MouseDown = function( sender, args )
		sender.dragStartX = args.X;
		sender.dragStartY = args.Y;
		sender.dragging = true;
	end

	self.resizeHandle.MouseMove = function( sender, args )
		local width, height = mainWindow:GetSize();

		if ( sender.dragging ) then
			mainWindow:SetSize( width + ( args.X - sender.dragStartX ), height + ( args.Y - sender.dragStartY ) );
			sender:SetPosition( mainWindow:GetWidth() - sender:GetWidth(), mainWindow:GetHeight() - sender:GetHeight() )
			satchel:PerformLayout()
		end
	end

	self.resizeHandle.MouseUp = function( sender, args )
		sender.dragging = false;
	end
----CREATE CONAINER FOR ITEMS----
	self.items = { };

	local player = Turbine.Gameplay.LocalPlayer();
	self.backpack = player:GetBackpack();

	self.backpack.SizeChanged = function( sender, args )
		satchel:Refresh();
	end

	self.backpack.ItemAdded = function( sender, args )
		satchel.items[args.Index]:SetItem( satchel.backpack:GetItem( args.Index ) );
	end

	self.backpack.ItemRemoved = function( sender, args )
		satchel.items[args.Index]:SetItem( satchel.backpack:GetItem( args.Index ) );
	end

	self.backpack.ItemMoved = function( sender, args )
		satchel.items[args.OldIndex]:SetItem( satchel.backpack:GetItem( args.OldIndex ) );
		satchel.items[args.NewIndex]:SetItem( satchel.backpack:GetItem( args.NewIndex ) );
	end

	self:Refresh();

end

----FUNCTION TO REFRESH BAG CONTENTS----
function SatchelWindow:Refresh()
	local backpackSize = self.backpack:GetSize();

	for i = 1, backpackSize, 1 do
		if ( self.items[i] ) then
			self.items[i]:SetParent( nil );
		end
		
		self.items[i] = Turbine.UI.Lotro.ItemControl( self.backpack:GetItem( i ) );
		self.itemListBox:AddItem( self.items[i] );
	end

	self:PerformLayout();
end

function SatchelWindow:PerformLayout()
	self:Layout( { } )
end

function SatchelWindow:Layout( args )
	local width, height = self:GetSize();
	
	local itemWidth = 40;
	
	if ( self.items[1] ~= nil ) then
		itemWidth = self.items[1]:GetWidth()
	end

	local listWidth = width - 40;
	local listHeight = height - 50;
	local itemsPerRow = listWidth / itemWidth;

	self.itemListBox:SetPosition( 15, 35 );
	self.itemListBox:SetSize( listWidth, listHeight );
	self.itemListBox:SetMaxItemsPerLine( itemsPerRow );
	
	self.itemListBoxScrollBar:SetPosition( width - 25, 35 );
	self.itemListBoxScrollBar:SetSize( 10, listHeight );

end
I am about to just say screw it and it won't save its position, lol

Last edited by Olenn : 09-26-2010 at 05:27 PM.
Reply With Quote