Skip to content

Commit

Permalink
Save settings
Browse files Browse the repository at this point in the history
  • Loading branch information
DAMcraft committed Jan 7, 2024
1 parent bdd600c commit 41a16bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ protected boolean isValueValid(Country value) {

@Override
protected NbtCompound save(NbtCompound tag) {
return null;
tag.putString("value", get().code);
return tag;
}

@Override
protected Country load(NbtCompound tag) {
return null;
return ServerSeeker.COUNTRY_MAP.get(tag.getString("value"));
}

public static class Builder extends SettingBuilder<Builder, Country, CountrySetting> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.nbt.NbtCompound;

import java.util.List;

import static de.damcraft.serverseeker.ServerSeeker.gson;

public class FindNewServersScreen extends WindowScreen {
public static NbtCompound savedSettings;
private int timer;
public WButton findButton;
private boolean threadHasFinished;
Expand Down Expand Up @@ -274,8 +276,11 @@ public FindNewServersScreen(MultiplayerScreen multiplayerScreen) {

@Override
public void initWidgets() {
loadSettings();
onClosed(this::saveSettings);
settingsContainer = add(theme.verticalList()).widget();
settingsContainer.add(theme.settings(settings));
add(theme.button("Reset all")).expandX().widget().action = this::resetSettings;
findButton = add(theme.button("Find")).expandX().widget();
findButton.action = () -> {
ServersRequest request = new ServersRequest();
Expand Down Expand Up @@ -486,4 +491,21 @@ private void handleThreadFinish() {

this.locked = false;
}

public void saveSettings() {
savedSettings = sg.toTag();
}

public void loadSettings() {
if (savedSettings == null) return;
sg.fromTag(savedSettings);
}

public void resetSettings() {
for (Setting<?> setting : sg) {
setting.reset();
}
saveSettings();
reload();
}
}

0 comments on commit 41a16bc

Please sign in to comment.