Settings - UQcsse3200/2024-studio-3 GitHub Wiki
The provided game contains support for user settings, which are accessible through the Settings screen.
-
UserSettings
: Contains functionality for loading, storing, and applying settings. -
SettingsMenuDisplay
: Logic for the Settings screen, which shows how to work with UserSettings.
I changed my resolution and now I can't see the game! How do I get back?
You can manually modify your settings file. This is stored in your home directory under DECO2800Game/settings.json
.
On Windows, this would likely be C:/Users/[username]/DECO2800Game/settings.json
.
You can manually make changes in the file, or delete it to revert to default settings.
The game runs too slow on my computer, what should I do?
The purpose of the settings menu is to let you adjust your graphics to keep the game running smoothly. Try:
- Lowering the FPS cap to 30. This controls how fast the game tries to run.
- Lowering your resolution (if running in fullscreen).
Default settings are defined in the Settings class.
public static class Settings {
/**
* FPS cap of the game. Independant of screen FPS.
*/
public int fps = 60;
public boolean fullscreen = true;
public boolean vsync = true;
/**
* ui Scale. Currently unused, but can be implemented.
*/
public float uiScale = 1f;
public DisplaySettings displayMode = null;
/**
* Play input key binds
*/
public String interact = "E";
public String recipeNavLeft = "[";
public String recipeNavRight = "]";
}
The makeSettingsTable method generates a table structure that contains the different fields on the settings page. Create new labels and text fields and place these elements within the table as seen. You can adjust the size of the field or select a specific type of field eg. textbox, to match your needs.
private Table makeSettingsTable() {
UserSettings.Settings settings = UserSettings.get();
//...
Label interactLabel = new Label("Interact:", skin);
interactText = new TextField(settings.interact, skin);
//...
Table table = new Table();
//...
table.row().padTop(10f);
table.add(interactLabel).right().padRight(15f);
table.add(interactText).width(30).left();
//...
return table;
}
To save any changes made to the settings they must be applied in the applyChanges function. For keybinds specifically, the helper method setKey is used to validate whether keys can be selected for an action and will reject changes that are invalid.
private void applyChanges() {
UserSettings.Settings settings = UserSettings.get();
//...
Set<String> keys = new HashSet<>();
settings.interact = setKey(keys, interactText.getText(), settings.interact);
settings.recipeNavLeft = setKey(keys, recipeNavLeftText.getText(), settings.recipeNavLeft);
settings.recipeNavRight = setKey(keys, recipeNavRightText.getText(), settings.recipeNavRight);
UserSettings.set(settings, true);
}
For keybinds specifically, the helper method setKey is used to validate whether keys can be selected for an action and will reject changes that are invalid.
private String setKey(Set<String> keys, String newKey, String oldKey) {
if (newKey != null && newKey.length() == 1 && keys.add(newKey)) {
return newKey;
}
else {
keys.add(oldKey);
return oldKey;
}
}