Jump to content

[SOLVED] Saving GUI State


photo

Recommended Posts

Is there a mechanism for saving the parameters input into an editor window? Seems trivial and I looked into how it was done for the Materials and Properties dialogs but those only save engine values directly.

Link to comment

Ah nvm, I get it, engine.config class. Clever.

 

I guess a quick follow up is, how do you save the window position? Evidently getPositionX(), and getPositionY() mean something entirely different.

Link to comment

Hi Philip. Can you specify your problem case? What type of saving do you mean? It can be engine "save/restore" or your custom editor plugin window or your game with HUD or something else. For all this cases exists different solutions.

Link to comment

I personally use functions engine.config for the apllication/game or %UNIGINE_DIR%\data\core\editor\editor_config.h functions for Unigine Editor plugins.

//...

	int width = configGet("camera_width",window.getWidth());
	int height = configGet("camera_height",window.getHeight());
	int position_x = configGet("camera_position_x",window.getPositionX());
	int position_y = configGet("camera_position_y",window.getPositionY());

//...
Link to comment

The "configGet" and "configSet" functions declared in the "data/core/editor/editor_config.h" works with a "editor_config.cfg" file. All parameters saves in to the config file at editor shutdown only. This is a best way to save your any parameters when you working as a editor plugin.
 
If your code works as world logic and no depends from editor, then best way to save yours parameters is a using engine.config functions. This config always work when engine are started, and saves to a "engine_config.cfg" file at engine shutdown.
 
But you can always write yours config implementation and use custom config files.
For example, you can see as sample a data storage implementation for a "Game framework" in the "data/framework/game/game_data.h" file.

Link to comment
  • 2 months later...

I have to bring this up again since whatever solution I had, I lost and the current approach doesnt work. So what I'm trying to do is simply get my window position and save it to the config file so when the editor is reloaded, I don't have to move a particular window out of view. I can save the window width and height, but window.getPositionX() and getPositionY() always return values of zero. If I try to manually set a position, the UI is offset within its parent control resulting in a black box where the window would be. I don't understand the relationship, I'm assuming its like this:

  1. GUI
    1. Interface <- I think I want to move this?
      1. WidgetWindow <- Not this?
        1. Widget A
        2. Widget B
Link to comment

It's very simple. All I want the editor to do is remember the last screen position of the UI window when editor_reload is called.

 

init()

{

editorWindow(window);

 

width = int(configGet("WINDOW::width",width));

height = int(configGet("WINDOW::height",height));

int position_x = window.getPositionX());

int position_y = window.getPositionY());

lastTab = int(configGet("WINDOW::lastTab", lastTab));

 

log.message("" + width + "\n");

log.message("" + height + "\n");

log.message("" + position_x + "\n"); <-Returns zero

log.message("" + position_y + "\n"); <-Returns zero

 

DECLARE_WINDOW_INIT(MYWINDOW)

}

post-602-0-40908500-1407857443_thumb.png

Link to comment

Hey Philip,

 

You just need to save window position to config as you did with its size. Try to use this code sample (I'm assuming you have initialized window instance somewhere):

int init() {
	window.setWidth(configGet("window_width",0));
	window.setHeight(configGet("window_height",0));
	int position_x = configGet("window_position_x",128);
	int position_y = configGet("window_position_y",128);
	window.setPosition(position_x,position_y);
	
	return 1;
}

int shutdown() {
	configSet("window_width",window.getWidth());
	configSet("window_height",window.getHeight());
	configSet("window_position_x",window.getPositionX());
	configSet("window_position_y",window.getPositionY());
	
	return 1;
}

Another solution is to store your parameters in system script though it have other pros & cons.

Link to comment
×
×
  • Create New...