LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Lua Programming Help (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=50)
-   -   Saving window position (https://www.lotrointerface.com/forums/showthread.php?t=1089)

Olenn 09-27-2010 03:15 PM

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.

Kragenwar 09-27-2010 03:38 PM

Quote:

Originally Posted by Olenn (Post 4936)
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.

I think I realized my problem. The place where I had you put that code is actually for resizing the window i guess? Ill admit I didn't actually study the code thoroughly. It was just the only place where I seen something drag-gable. I can't seem to find where you are actually making the window moveable. So I am probably missing something.

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.

Olenn 09-28-2010 12:23 PM

I changed the SatchelData, thanks for spotting that.

I am not "making" the windows movable...they just are...is that wrong?

Kragenwar 09-28-2010 12:48 PM

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.

Olenn 09-30-2010 01:53 AM

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 );

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,  "Satchel")
    if (self.Data==nil)then
                self.Data = { };
                self.Data.x = Turbine.UI.Display.GetWidth() - 400;
                self.Data.y = Turbine.UI.Display.GetHeight() - 300;
                self:SetPosition(self.Data.x,self.Data.y);
    else
                self:SetPosition(self.Data.x,self.Data.y)
    end

----SATCHEL SAVES POSITION IF MOVED----
        self.PositionChanged=function(sender,args)
                self.Data.x,self.Data.y=self:GetPosition()
                Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", self.Data );
        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

Feel free to use and distribute it!

Olenn 10-01-2010 01:08 AM

Updated to save position information as well,

Code:

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 SIZE & POSITION----
        self.Data = Turbine.PluginData.Load( Turbine.DataScope.Character,  "Satchel")
    if (self.Data==nil)then
                self.Data = { };
                self.Data.x = Turbine.UI.Display.GetWidth() - 400;
                self.Data.y = Turbine.UI.Display.GetHeight() - 300;
                self.Data.sx = 325;
                self.Data.sy = 300;
                self:SetPosition(self.Data.x,self.Data.y);
                self:GetSize(self.Data.sx,self.Data.sy);
    else
                self:SetPosition(self.Data.x,self.Data.y)
                self:SetSize(self.Data.sx,self.Data.sy)
    end

----SATCHEL SAVES SIZE & POSITION IF MOVED----
        self.PositionChanged=function(sender,args)
                self.Data.x,self.Data.y=self:GetPosition()
                self.Data.sx,self.Data.sy=self:GetSize()
                Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", self.Data );
        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

Once again, thanks to everyone that helped over the past few days. It is great to be part of such an awesome community!


All times are GMT -5. The time now is 05:59 PM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI