Config Optimizations

This commit is contained in:
Frank 2022-07-22 01:23:30 +02:00
parent 9cb54346a2
commit a7efcd25ba
15 changed files with 161 additions and 77 deletions

View file

@ -6,10 +6,7 @@ import org.betterx.bclib.config.Configs;
import org.betterx.bclib.config.NamedPathConfig;
import org.betterx.bclib.config.NamedPathConfig.ConfigTokenDescription;
import org.betterx.bclib.config.NamedPathConfig.DependendConfigToken;
import org.betterx.ui.layout.components.Checkbox;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import org.betterx.ui.layout.components.*;
import org.betterx.ui.vanilla.LayoutScreenWithIcon;
import net.minecraft.client.gui.screens.Screen;
@ -43,11 +40,33 @@ public class MainScreen extends LayoutScreenWithIcon {
protected <T> void addRow(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription<T> option) {
if (ConfigKeeper.BooleanEntry.class.isAssignableFrom(option.token.type)) {
addCheckbox(grid, config, (ConfigTokenDescription<Boolean>) option);
} else if (ConfigKeeper.FloatEntry.class.isAssignableFrom(option.token.type)) {
addFloat(grid, config, (ConfigTokenDescription<Float>) option);
}
grid.addSpacer(2);
}
protected void addFloat(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription<Float> option) {
if (option.topPadding > 0) {
grid.addSpacer(option.topPadding);
}
HorizontalStack row = grid.addRow();
if (option.leftPadding > 0) {
row.addSpacer(option.leftPadding);
}
Range<Float> cb = row.addRange(
fixed(200), fit(),
getComponent(config, option, "title"),
option.minRange,
option.maxRange,
config.getRaw(option.token)
).onChange(
(caller, state) -> {
config.set(option.token, state);
}
);
}
protected void addCheckbox(VerticalStack grid, NamedPathConfig config, ConfigTokenDescription<Boolean> option) {
if (option.topPadding > 0) {

View file

@ -2,6 +2,7 @@ package org.betterx.bclib.client.gui.screens;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import org.betterx.ui.layout.values.Value;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
@ -34,7 +35,7 @@ public class ConfirmRestartScreen extends BCLibLayoutScreen {
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill());
grid.addFiller();
grid.addMultilineText(fill(), fit(), this.description).centerHorizontal();
grid.addMultilineText(Value.relative(0.9), fit(), this.description).centerHorizontal();
grid.addSpacer(10);
grid.addButton(fit(), fit(), CommonComponents.GUI_PROCEED)
.onPress((button) -> listener.proceed())

View file

@ -80,14 +80,13 @@ public class UpdatesScreen extends BCLibLayoutScreen {
footer.addFiller();
footer.addCheckbox(
fit(),
fit(),
fit(), fit(),
Component.translatable("Disable Check"),
!Configs.MAIN_CONFIG.checkVersions()
!Configs.CLIENT_CONFIG.checkVersions()
)
.onChange((cb, state) -> {
Configs.MAIN_CONFIG.setCheckVersions(!state);
Configs.MAIN_CONFIG.saveChanges();
Configs.CLIENT_CONFIG.setCheckVersions(!state);
Configs.CLIENT_CONFIG.saveChanges();
});
footer.addSpacer(4);
footer.addButton(fit(), fit(), CommonComponents.GUI_DONE).onPress((bt -> {

View file

@ -1,9 +1,12 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.networking.VersionChecker;
import org.betterx.ui.ColorUtil;
import org.betterx.ui.layout.components.*;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
@ -37,19 +40,35 @@ public class WelcomeScreen extends BCLibLayoutScreen {
}
content.addHorizontalSeparator(48);
content.addCheckbox(fit(), fit(), translatable("bclib.welcome.updater.title"), true)
.onChange((cb, state) -> Configs.MAIN_CONFIG.setCheckVersions(state));
Checkbox check = content.addCheckbox(
fit(),
fit(),
translatable("bclib.welcome.updater.title"),
Configs.CLIENT_CONFIG.checkVersions()
)
.onChange((cb, state) -> {
Configs.CLIENT_CONFIG.setCheckVersions(state);
});
content.addSpacer(2);
content.indent(24)
.addMultilineText(fill(), fit(), translatable("bclib.welcome.updater.description"))
.setColor(ColorUtil.GRAY);
HorizontalStack dscBox = content.indent(24);
dscBox.addMultilineText(fill(), fit(), translatable("bclib.welcome.updater.description"))
.setColor(ColorUtil.GRAY);
dscBox.addSpacer(8);
content.addSpacer(16);
content.addButton(fit(), fit(), CommonComponents.GUI_PROCEED).onPress((bt) -> {
Configs.MAIN_CONFIG.setDidShowWelcomeScreen();
Configs.CLIENT_CONFIG.setDidShowWelcomeScreen();
Configs.CLIENT_CONFIG.setCheckVersions(check.isChecked());
Configs.CLIENT_CONFIG.saveChanges();
VersionChecker.startCheck(true);
onClose();
}).alignRight();
return VerticalScroll.create(fill(), fill(), content);
}
@Override
protected void renderBackground(PoseStack poseStack, int i, int j, float f) {
GuiComponent.fill(poseStack, 0, 0, width, height, 0xBD343444);
}
}