Added ConfigUI
Annotation
This commit is contained in:
parent
0adc5024f1
commit
8f9ff14fac
8 changed files with 240 additions and 95 deletions
|
@ -6,11 +6,17 @@ import net.minecraft.network.chat.TranslatableComponent;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.config.NamedPathConfig;
|
||||
import ru.bclib.config.NamedPathConfig.ConfigToken;
|
||||
import ru.bclib.config.NamedPathConfig.ConfigToken.Bool;
|
||||
import ru.bclib.config.NamedPathConfig.ConfigTokenDescription;
|
||||
import ru.bclib.config.NamedPathConfig.DependendConfigToken;
|
||||
import ru.bclib.gui.gridlayout.GridCheckboxCell;
|
||||
import ru.bclib.gui.gridlayout.GridColumn;
|
||||
import ru.bclib.gui.gridlayout.GridRow;
|
||||
import ru.bclib.gui.gridlayout.GridScreen;
|
||||
import ru.bclib.gui.gridlayout.GridWidgetWithEnabledState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MainScreen extends GridScreen{
|
||||
|
||||
|
@ -18,28 +24,42 @@ public class MainScreen extends GridScreen{
|
|||
super(parent, new TranslatableComponent("title.bclib.modmenu.main"));
|
||||
}
|
||||
|
||||
protected TranslatableComponent getComponent(NamedPathConfig config, ConfigToken.Bool token, String type){
|
||||
StringBuilder path = new StringBuilder();
|
||||
for (String p : token.getPath()){
|
||||
path.append(".")
|
||||
.append(p);
|
||||
|
||||
}
|
||||
path.append(".").append(token.getEntry());
|
||||
return new TranslatableComponent(type + ".config." + config.configID + path );
|
||||
protected <T> TranslatableComponent getComponent(NamedPathConfig config, ConfigTokenDescription<T> option, String type){
|
||||
return new TranslatableComponent(type + ".config." + config.configID + option.getPath() );
|
||||
}
|
||||
|
||||
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken token){
|
||||
if (token instanceof Bool){
|
||||
addRow(grid, config, (ConfigToken.Bool)token);
|
||||
Map<GridWidgetWithEnabledState, Supplier<Boolean>> dependentWidgets = new HashMap<>();
|
||||
protected void updateEnabledState(){
|
||||
dependentWidgets.forEach((cb, supl)->cb.setEnabled(supl.get()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T>void addRow(GridColumn grid, NamedPathConfig config, ConfigTokenDescription<T> option){
|
||||
if (Boolean.class.isAssignableFrom(option.token.type)) {
|
||||
addCheckbox(grid, config, (ConfigTokenDescription<Boolean>)option);
|
||||
}
|
||||
|
||||
grid.addSpacerRow(2);
|
||||
}
|
||||
|
||||
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken.Bool token){
|
||||
|
||||
protected void addCheckbox(GridColumn grid, NamedPathConfig config, ConfigTokenDescription<Boolean> option){
|
||||
if (option.topPadding>0){
|
||||
grid.addSpacerRow(option.topPadding);
|
||||
}
|
||||
GridRow row = grid.addRow();
|
||||
row.addCheckbox(getComponent(config, token, "title"), config.get(token), font, (state)-> config.set(token, state));
|
||||
if (option.leftPadding>0){
|
||||
row.addSpacer(option.leftPadding);
|
||||
}
|
||||
GridCheckboxCell cb = row.addCheckbox(getComponent(config, option, "title"), config.getRaw(option.token), font, (state)-> {
|
||||
config.set(option.token, state);
|
||||
updateEnabledState();
|
||||
});
|
||||
|
||||
if (option.token instanceof DependendConfigToken) {
|
||||
dependentWidgets.put(cb, ()->option.token.dependenciesTrue(config));
|
||||
cb.setEnabled(option.token.dependenciesTrue(config));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +71,7 @@ public class MainScreen extends GridScreen{
|
|||
protected void initLayout() {
|
||||
final int BUTTON_HEIGHT = 20;
|
||||
|
||||
Configs.CLIENT_CONFIG.getAllOptions().forEach(o -> addRow(grid, Configs.CLIENT_CONFIG, o));
|
||||
Configs.CLIENT_CONFIG.getAllOptions().stream().filter(o -> !o.hidden).forEach(o -> addRow(grid, Configs.CLIENT_CONFIG, o));
|
||||
|
||||
grid.addSpacerRow(15);
|
||||
GridRow row = grid.addRow();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue