Hi there,
I have spent some time trying to figure out how StandardGame loads/saves the game settings (like resolution, fullscreen, etc) but I could not find out where the settings are stored.
My intention behind that is that I don't want to show the GameSettingsPanel on every start of my game.
I would like to have a functionality like the dialogBehaviour in AbstractGame so that the settings dialog shows once on the first start and never again (unless the settings file is deleted).
How can this be achieved?
Any help appreciated,
Sebastian
Well in my case I do it like this:
game = new StandardGame("Rise to the Stars");
if (args.length != 0){
logger.info("Command line argument: " + args[0]);
if ("config".equals(args[0])){
try{
GameSettingsPanel.prompt(game.getSettings());
game.shutdown();
System.exit(0);
}catch(Exception e){
e.printStackTrace();
}
}
}
game.getSettings();
game.start();
Basically I allow the user to specify that they want to change setting and in any case, I then just load the settings. In my code if there is no 'config' argument in the code, the previous settings are loaded.
If you want this behavior to be automatic, I guess you must just add another field to your custom properties implementation, that sets a field value to 'true' once the properties window has been displayed once. But I suggest you do not make it completely automatic, as the user could possibly make a bad configuration and would not be able to change it otherwise.
Where are the settings stored? Well it depends on the OS. It uses the regular JAVA properties system and in Windows you will probably have to go dig into the Registry. It is not made to be configures manually. Basically don't worry about where it is stored and just use it.
You would probably always want a mechanism to re-display the settings, but if you want to determine whether it is the first time the game has been run you simply need to check for a setting to determine if it has been set. For example, you could set an arbitrary setting to be referenced on later runs. The reason you can't find the settings is because by default it uses the Preferences object which, in Windows, stores all settings in the registry. So just instantiate StandardGame, then call game.getSettings() and then reference your arbitrary setting to determine if it has been saved previously.
Thank you both for the quick answers!
They should perfectly solve my problem.
I did not know that the properties are stored in the registry (on windows) - up to now I used the storeAsXML functionality.
For the sake of completeness:
The Settings are stored in the registry under HKEY_CURRENT_USERSoftwareJavaSoftPrefs