Jump to content

Save Interface Status


Recommended Posts

  • Active+ Member

Hello,

As you may already be aware, the official source code that was leaked some time ago includes code for saving window status. The code is designed to save various window attributes such as visibility, minimized status, x and y coordinates, and height. However, I have made some adjustments to only save the x and y coordinates. Please note that the logic I have utilized is different from the original planned approach.


In order to ensure the proper functioning of the save function, it is imperative to address an issue where the function is called too late and the interfacehandler is null:

## 1. Open UserInterface/PythonSystem.cpp
## 1. Replace the following function:
void CPythonSystem::SaveInterfaceStatus()
{
	...
}
## 1. With:
void CPythonSystem::SaveInterfaceStatus()
{
	if(m_poInterfaceHandler) // This will always be null when this function is called
		PyCallClassMemberFunc(m_poInterfaceHandler, "OnSaveInterfaceStatus", Py_BuildValue("()"));

	FILE* File;

	File = fopen("interface.cfg", "wb");

	if(!File)
	{
		TraceError("Cannot open interface.cfg");
		return;
	}

	fwrite(m_WindowStatus, 1, sizeof(TWindowStatus) * WINDOW_MAX_NUM, File);
	fclose(File);
}


Now, let's explore how we can save window attributes, specifically for the inventory window as an example:
 

## 1. Go to interfaceModule.py:
## 1. Search:
		if self.wndInventory:
			self.wndInventory.Hide()
			self.wndInventory.Destroy()
## 1. Change it like this:
		if self.wndInventory:
			xInventory, yInventory = self.wndInventory.GetGlobalPosition()
			systemSetting.SaveWindowStatus(systemSetting.WINDOW_INVENTORY, False, True, xInventory, yInventory, 0)
			
			self.wndInventory.Hide()
			self.wndInventory.Destroy()
			
			
	
## 2. Now search:
		self.wndInventory = uiInventory.InventoryWindow()
		self.wndInventory.BindInterfaceClass(self)
## 2. Change it like this:
		self.wndInventory = uiInventory.InventoryWindow()
		self.wndInventory.BindInterfaceClass(self)
		
		(_, _, invX, invY, _) = systemSetting.GetWindowStatus(systemSetting.WINDOW_INVENTORY)
		if invX > 0 and invY > 0 and invX + self.wndInventory.GetWidth() < wndMgr.GetScreenWidth() and invY + self.wndInventory.GetHeight() < wndMgr.GetScreenHeight():
			self.wndInventory.SetPosition(invX, invY)


I hope you find this information useful. 🙂

  • Metin2 Dev 6
  • Good 1
  • Love 3
Link to comment
Share on other sites

  • 2 weeks later...
  • Premium

There is a small bug with this when you put an interface right at the edges (with the limit flag).

It can be fixed using >=0 and <= wndMgr.GetScreenWidth()/Heigth() although, this raises a new small "bug", where the first time the interfaces will open at 0,0 (and it might be fixed adding a new option to TWindowStatus like bool firstOpen and set it to true the first time the interface gets hidden)

Edited by Intel
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.