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. |
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? |
(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. |
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) 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 ); Code:
Data=Turbine.PluginData.Load( Turbine.DataScope.Character, "The Name of Your Plugin") |
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 ); I guess its off to borders to find an Lua book... |
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! |
I changed both of my Window values to self, but i am still getting the error;
attempt to index Global 'Data' (a nil value) |
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 ==. |
I was under the assumption that
Code:
Data = Turbine.PluginData.Load( Turbine.DataScope.Character, "SatchelData") Here is all of my code thus far... Code:
|
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 ); |
Wow, thanks. The only thing left is where to put;
Code:
Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", Data ); Code:
self.PositionChanged=function(sender,args) |
I'm going to help you cheat a bit here - but only because the original code that this was based off of was given to me by Pengoros
put this in your Main.lua script: Code:
pluginName="myPluginsName"; |
Thanks for all of the help. I did what you said and its not giving me an error but it isn't working either.
The end goal is that you could drag the window where ever you want it and when you start the game back up later it remembers its position. I really thought this would be as easy an writing to a file when you stopped dragging the window, but its definitely been an all day project trying to get this to work. I believe that my problem now is simply getting the plugin to save the lwindows location data. Everything else seems to be working fine. Here is the main.lua I have thus far. Code:
import "Turbine.UI"; |
I don't know if you did as Digitial Utopia suggested and declared Data in your satchel class as self.Data (since you only posted your main and didnt repost your Satchel class). But if you did, then when saving your data variable from your main you may need to go
Code:
Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", SatchelWindow.Data ); Code:
----SAVE WINDOW POSITION---- Code:
Plugins[pluginName].Unload = function(self,sender,args) |
1 Attachment(s)
You guys are awesome, but I think I am starting to get all of your advice mixed up. I am going to post both Lua scripts and see what you think. I am getting an error;
attempt to index Data a nil value main.lua Code:
Code:
I have attached the plugin in its current state for Lua help only, it is not advised for use by the common user. |
Quote:
Here: Code:
if (Plugins[pluginName] ~= nil) then Code:
Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", SatchelWindow.Data ); or the issue could possibly be here: Code:
----SAVE CURENT POSITION WHEN MOVED--- Code:
----LOAD PRIOR POSITION---- |
AWESOME!
That gives me tons to work with. It is now saving the position to the file, but when I click reload it still resets it to 100 x 100. But at least I have something to work for. Much appreciated everyone! |
Quote:
Code:
----SAVE CURENT POSITION WHEN MOVED--- Code:
self.resizeHandle.MouseUp = function( sender, args ) |
I tried to put that in place of
Code:
...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" |
Quote:
Code:
import "Turbine"; |
What I am trying to do is two fold. I want the window to have a default location and size when the addon is first installed. After that when the user moves or resizes the window, I want the window to save its size and location to a file so that the next time the user runs the game the window is in the same place and the same size that they left it in.
I tried your code and it does it still resets to 100 x 100 when I hit reload in plugin manager. I have to go to work now, but I will keep hammering away at it tomorrow. Thanks for all your help. |
Quote:
Also just noticed that you are loading from "SatchelData" and saving to "Satchel".... Didn't notice it before, but those save/load calls need to match. That was probably the problem in the first place so you may need to go back to the self.PositionChanged function and get rid of that line I had you add to self.resizeHandle.MouseDown. |
I changed the SatchelData, thanks for spotting that.
I am not "making" the windows movable...they just are...is that wrong? |
No it's not wrong. I was mistaken, didn't realize that a turbine.ui.window was already moveable if you have a title bar on it. Just my lack of experience showing threw :p
Sorry for leading you in the wrong direction yesterday. You were actually correct in the first place with your PositionChanged function. So make sure you change your resizeHandle.MouseUp function back to the way it was before I suggested you change it. Hope it all works out. |
For everyone that helped, THANK YOU!!!
Major break through today. The "save position" issue is resolved. It is now working properly and I have learned a ton in the process... My hat is off to you all. For anyone that is curious about the working code here it is. Code:
SatchelWindow = class( Turbine.UI.Window ); |
Updated to save position information as well,
Code:
SatchelWindow = class( Turbine.UI.Window ); |
All times are GMT -5. The time now is 05:17 AM. |
vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI