-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 71 additions & 78 deletions
149
src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,79 @@ | ||
package io.ix0rai.rainglow.config; | ||
|
||
import io.ix0rai.rainglow.Rainglow; | ||
import io.ix0rai.rainglow.data.RainglowColour; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.screen.option.GameOptionsScreen; | ||
import net.minecraft.client.gui.widget.button.ButtonWidget; | ||
import net.minecraft.client.gui.widget.layout.GridWidget; | ||
import net.minecraft.client.gui.widget.layout.HeaderFooterLayoutWidget; | ||
import net.minecraft.client.gui.widget.layout.LayoutSettings; | ||
import net.minecraft.client.gui.widget.layout.LinearLayoutWidget; | ||
import net.minecraft.client.gui.widget.list.ButtonListWidget; | ||
import net.minecraft.client.gui.widget.text.TextWidget; | ||
import net.minecraft.client.option.Option; | ||
import net.minecraft.text.CommonTexts; | ||
import net.minecraft.text.Text; | ||
|
||
public class CustomModeScreen extends Screen { | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CustomModeScreen extends GameOptionsScreen { | ||
private final ButtonWidget saveButton; | ||
private final List<DeferredSaveOption<Boolean>> options = new ArrayList<>(); | ||
|
||
private static final Text TITLE = Rainglow.translatableText("config.custom"); | ||
|
||
public CustomModeScreen(Screen parent) { | ||
super(Text.of("fa")); | ||
super(parent, MinecraftClient.getInstance().options, TITLE); | ||
this.saveButton = ButtonWidget.builder(Rainglow.translatableText("config.save"), button -> { | ||
this.save(); | ||
this.closeScreen(); | ||
}).build(); | ||
this.saveButton.active = false; | ||
} | ||
|
||
private void createColourToggles() { | ||
this.options.clear(); | ||
|
||
for (RainglowColour colour : RainglowColour.values()) { | ||
this.options.add(DeferredSaveOption.createDeferredBoolean( | ||
"colour." + colour.getId(), | ||
null, | ||
Rainglow.CONFIG.getCustom().contains(colour), | ||
enabled -> { | ||
if (enabled) { | ||
Rainglow.CONFIG.getCustom().add(colour); | ||
} else { | ||
Rainglow.CONFIG.getCustom().remove(colour); | ||
} | ||
}, | ||
enabled -> this.saveButton.active = true | ||
)); | ||
} | ||
} | ||
|
||
private void save() { | ||
for (DeferredSaveOption<?> option : this.options) { | ||
option.save(); | ||
} | ||
} | ||
|
||
@Override | ||
public void init() { | ||
HeaderFooterLayoutWidget headerFooterWidget = new HeaderFooterLayoutWidget(this, 61, 33); | ||
headerFooterWidget.addToHeader(new TextWidget(TITLE, this.textRenderer), settings -> settings.alignHorizontallyCenter().setBottomPadding(28)); | ||
|
||
ButtonListWidget buttonListWidget = headerFooterWidget.addToContents(new ButtonListWidget(this.client, this.width, this.height, this)); | ||
createColourToggles(); | ||
buttonListWidget.addEntries(this.options.toArray(new Option<?>[0])); | ||
|
||
LinearLayoutWidget linearLayout = headerFooterWidget.addToFooter(LinearLayoutWidget.createHorizontal().setSpacing(8)); | ||
linearLayout.add(ButtonWidget.builder(CommonTexts.DONE, button -> this.closeScreen()).build()); | ||
linearLayout.add(this.saveButton); | ||
|
||
headerFooterWidget.visitWidgets(this::addDrawableSelectableElement); | ||
headerFooterWidget.arrangeElements(); | ||
} | ||
// private final SpruceOption clearOption; | ||
// private final SpruceOption saveOption; | ||
// private final SpruceBooleanOption[] colourToggles = new SpruceBooleanOption[RainglowColour.values().length]; | ||
// private final boolean[] toggleStates = new boolean[RainglowColour.values().length]; | ||
// | ||
// public CustomModeScreen(@Nullable Screen parent) { | ||
// super(parent, MinecraftClient.getInstance().options, Rainglow.translatableText("config.title"), | ||
// | ||
// ); | ||
// | ||
// // todo subclass option to allow saving via a save button | ||
// // ephemeral value, not saved until a specific method is called (will happen on save pressed) | ||
// | ||
// // create toggles for each colour | ||
// for (int i = 0; i < RainglowColour.values().length; i ++) { | ||
// final RainglowColour colour = RainglowColour.values()[i]; | ||
// final int index = i; | ||
// | ||
// toggleStates[index] = Rainglow.CONFIG.getCustom().contains(colour); | ||
// | ||
// colourToggles[index] = new SpruceBooleanOption(Rainglow.translatableTextKey("colour." + colour.getId()), | ||
// () -> toggleStates[index], | ||
// enable -> toggleStates[index] = enable, | ||
// null, | ||
// true | ||
// ); | ||
// } | ||
// | ||
// // toggles all colours to false | ||
// this.clearOption = SpruceSimpleActionOption.of(Rainglow.translatableTextKey("config.clear"), | ||
// btn -> { | ||
// for (int i = 0; i < RainglowColour.values().length; i ++) { | ||
// toggleStates[i] = false; | ||
// } | ||
// | ||
// MinecraftClient client = MinecraftClient.getInstance(); | ||
// this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight()); | ||
// }); | ||
// | ||
// // writes all the toggled colours to the config and reloads custom mode | ||
// this.saveOption = SpruceSimpleActionOption.of(Rainglow.translatableTextKey("config.save"), | ||
// buttonWidget -> { | ||
// List<RainglowColour> newCustom = new ArrayList<>(); | ||
// | ||
// for (int i = 0; i < RainglowColour.values().length; i ++) { | ||
// if (toggleStates[i]) { | ||
// newCustom.add(RainglowColour.values()[i]); | ||
// } | ||
// } | ||
// | ||
// Rainglow.CONFIG.setCustom(newCustom); | ||
// Rainglow.CONFIG.saveCustom(); | ||
// this.closeScreen(); | ||
// } | ||
// ); | ||
// } | ||
// | ||
// @Override | ||
// protected void init() { | ||
// super.init(); | ||
// | ||
// // create a list of toggles for each colour | ||
// SpruceOptionListWidget options = new SpruceOptionListWidget(Position.of(0, 22), this.width, this.height - (35 + 22)); | ||
// for (int i = 0; i < RainglowColour.values().length; i += 2) { | ||
// SpruceOption secondToggle = null; | ||
// if (i + 1 < RainglowColour.values().length) { | ||
// secondToggle = colourToggles[i + 1]; | ||
// } | ||
// options.addOptionEntry(colourToggles[i], secondToggle); | ||
// } | ||
// this.addDrawableSelectableElement(options); | ||
// | ||
// // save and clear buttons | ||
// this.addDrawableSelectableElement(this.clearOption.createWidget(Position.of(this, this.width / 2 - 155, this.height - 29), 150)); | ||
// this.addDrawableSelectableElement(this.saveOption.createWidget(Position.of(this, this.width / 2 - 155 + 160, this.height - 29), 150)); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters