lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
Thread Tools Display Modes
  #1  
Unread 09-26-2010, 08:45 AM
Olenn's Avatar
Olenn Olenn is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 47
Saving window position

I am trying to figure out how to save window position so that it is persistent through a reload.

I think that I should have it write its coordinates to a save file when it is being dragged and the mouse button is released, but I can not for the life of me figure out how to write that code.

Any help is greatly appreciated.
Reply With Quote
  #2  
Unread 09-26-2010, 10:14 AM
Wicked Mouse's Avatar
Wicked Mouse Wicked Mouse is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Feb 2008
Location: The Netherlands
Posts: 183
Isn't that what the "layout system" has brought into action for?

http://lorebook.lotro.com/wiki/Relea...ook_8_Official
# The client now has a /ui command that can be used to save the current layout of windows to an xml file and then load this layout.
# To save a ui layout type: /ui layout save <name>
# To load a previously saved layout: /ui layout load <name>
# In both cases the name is optional and if not specified it will just save to a file called Default_ appended with your current game window resolution. (e.q running in 800 x 600 results inDefault_800_600.layout)

Or were you talking about something else?
__________________
Author of: "Delving Hills"
Reply With Quote
  #3  
Unread 09-26-2010, 10:33 AM
Olenn's Avatar
Olenn Olenn is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 47
(Bear with me, still learning Lua)

When you press "Ctrl + \" it doesn't give a handle to set the Lua window position. I tried writing a function that basically says if the window changes position to save the coordinates to a file and when the window is recalled to load those coordinates .

I just haven't been successful as of yet.
Reply With Quote
  #4  
Unread 09-26-2010, 10:52 AM
MrJackdaw's Avatar
MrJackdaw MrJackdaw is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Feb 2009
Location: Lancaster, England
Posts: 249
Assuming the window is called "Window" and the place you want to store the data is a table called "Data";

Code:
Window.PositionChanged=function(sender,args)
	Data.x,Data.y=Window:GetPosition()
end
Will store the window position to the Data table whenever the window is moved.

Then, when you load the data - just use the Data.x and Data.y to load in the position.

Assumption: You are saving the data at some point with;

Code:
Turbine.PluginData.Save( Turbine.DataScope.Character, "The Name of Your Plugin", Data );
And loading it with;

Code:
Data=Turbine.PluginData.Load( Turbine.DataScope.Character, "The Name of Your Plugin")
or similar!
__________________
************************************************** ************************************************** **
"Our ideals may never be realised, But they indicate what we are trying to do." Dick Tahta
Reply With Quote
  #5  
Unread 09-26-2010, 12:37 PM
Olenn's Avatar
Olenn Olenn is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 47
Thanks, but I am still a little lost. What I have been trying to add is a code that looks to see if the data file exists and if it does use that position. If it doesn't then it uses a default set of values. I am still not sure where all of this goes.

I tried to start simple...this is what I have been trying (without the checking to see if the file exists or not)

Code:
SatchelWindow = class( Turbine.UI.Window );
Data = Turbine.PluginData.Load( Turbine.DataScope.Character, "SatchelData")

function SatchelWindow:Constructor()
----CREATE THE WINDOW----
	Turbine.UI.Lotro.Window.Constructor( self );
	self:SetText("Satchel");
	self:SetSize( 325, 275 );
	self:SetPosition( Data.x , Data.y );
----SAVE WINDOW POSITION----
	Window.PositionChanged=function(sender,args)
		Data.x,Data.y=Window:GetPosition()
	end
That is as far as I have (unsuccessfully) gotten. Does the file save on logoff or does it save when the code runs?


I guess its off to borders to find an Lua book...

Last edited by Olenn : 09-26-2010 at 12:39 PM.
Reply With Quote
  #6  
Unread 09-26-2010, 01:01 PM
MrJackdaw's Avatar
MrJackdaw MrJackdaw is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Feb 2009
Location: Lancaster, England
Posts: 249
Thinking on my feet but change the "Window" lines to "self" as "self" is the window. And don't waste money in Borders - I worked my way through the Turbine sample stuff stealing where I could, especially the combat bar on. Just as with learing the xml modification stuff, look at other peoples work and rip it apart... *grin* The excellent lessons on http://www.lua.org/pil/ helped me get a bit better!

I still wouldn't call myself any good - but the stuff works well enough for me!
__________________
************************************************** ************************************************** **
"Our ideals may never be realised, But they indicate what we are trying to do." Dick Tahta
Reply With Quote
  #7  
Unread 09-26-2010, 01:11 PM
Olenn's Avatar
Olenn Olenn is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 47
I changed both of my Window values to self, but i am still getting the error;

attempt to index Global 'Data' (a nil value)
Reply With Quote
  #8  
Unread 09-26-2010, 03:28 PM
MrJackdaw's Avatar
MrJackdaw MrJackdaw is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Feb 2009
Location: Lancaster, England
Posts: 249
Has Data been defined anywhere as a value? If there are no saved variables it becomes "nil" and effectively does not exist.

Add this after the load line;

if Data==nil then Data={} end

and that should sort it! Note the "==" not just "=". I always get that wrong! If you are defining it is a single =, if you are comparing it is a double ==.
__________________
************************************************** ************************************************** **
"Our ideals may never be realised, But they indicate what we are trying to do." Dick Tahta
Reply With Quote
  #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
  #10  
Unread 09-26-2010, 06:13 PM
Digital_Utopia's Avatar
Digital_Utopia Digital_Utopia is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 207
Send a message via MSN to Digital_Utopia Send a message via Yahoo to Digital_Utopia
Move your declaration of Data so that it's below the constructor lines

add "self." in front of Data

Code:
SatchelWindow = class( Turbine.UI.Window );
function SatchelWindow:Constructor()
     Turbine.UI.Lotro.Window.Constructor( self );

     self.Data = Turbine.PluginData.Load( Turbine.DataScope.Character,  "SatchelData")
     if (self.Data==nil)then 
           self:SetPosition(defaultx,defaulty);
     else
           self:SetPosition(self.Data.x,self.Data.y)
     end

...
end
Where defaultx and defaulty are whatever position you would give that window by default.
__________________

Lord of the Rings Online
75 Fourohfour | 75 Artemedis | 60 Whiskeytango Foxtrot | 50 Mistah Boombastic | 56 Appetizer | 25 Aggromi
61 Onepointtwentyone Gigawatts


World of Warcraft
90 Downlo 85 Gravetaxi 85 Ümad 85 Artemedis 85 Guthuros
Reply With Quote
Reply


Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Plugins Not Saving Settings Valdacil Interface Help (L) 13 09-10-2010 10:43 PM
Help me to position my xp bar please or to hide it Eili Interface Help (L) 6 06-29-2010 05:36 PM
position toolbar problems Bazzard XML modification help (L) 7 07-11-2007 02:08 AM
Saving UI Layout... Sythix Interface Help (L) 1 07-05-2007 11:15 PM
chat window not saving position... AstroCat Interface Help (L) 1 07-01-2007 11:12 AM


All times are GMT -5. The time now is 05:14 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui