View Single Post
  #20  
Unread 09-27-2010, 02:45 PM
Kragenwar Kragenwar is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 26
Post

Quote:
Originally Posted by Olenn
I tried to put that in place of

Code:
	self.PositionChanged=function(sender,args)
		self.Data.x,self.Data.y=self:GetPosition()
		Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", self.Data );
	end
but I keep getting this error;

...Rings Online\Plugins\Olenn\Satchel\SatchelWindow.lua:33: attempt to index field 'resizeHandle' (a nil value)

the odd part is that line 33 is just "end"
Yeah you shouldn't be replacing the self.PositionChanged part with the self.resizeHandle.MouseUp function. All you need to do is completlely remove the self.PositionChanged function. Then change your already existing self.resizeHandle.MouseUp by adding the line to set Data.x and Data.y. Here is the whole class with the change.

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

SatchelWindow = class( Turbine.UI.Window );

function SatchelWindow:Constructor()
----CREATE THE WINDOW----
	Turbine.UI.Lotro.Window.Constructor( self );
	self:SetText("Satchel");
	self:SetSize( 325, 300 );
----LOAD PRIOR POSITION----
	self.Data = Turbine.PluginData.Load( Turbine.DataScope.Character,  "SatchelData")
    if (self.Data==nil)then
		self.Data = { };
		self.Data.x = 100;
		self.Data.y = 100;
		self:SetPosition(100 , 100);
    else
		self:SetPosition(self.Data.x,self.Data.y)
    end

----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
		
----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 )
		if (sender.dragging) then
			self.Data.x, self.Data.y = self:GetPosition();
		end
		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();
	
----CREATE SETTINGS BUTTON----
	self.settingsButton = Turbine.UI.Lotro.Button();
	self.settingsButton:SetParent( self );

	self.settingsButton:SetSize(70,30);
	self.settingsButton:SetPosition(34, 37);
	self.settingsButton:SetFont(Turbine.UI.Lotro.Font.Verdana14);
	self.settingsButton:SetText("Settings");	
	self.settingsButton.Click = function(sender, args)
		settingsWindow:SetVisible( not SettingsWindow:IsVisible() );
	end
	
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 - 75;
	local itemsPerRow = listWidth / itemWidth;

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

end
This should work unless I'm totally misunderstanding your code or what you are trying to do with it.

Last edited by Kragenwar : 09-27-2010 at 02:59 PM.
Reply With Quote