Auto generate a simple Config Screen
This commit is contained in:
parent
d31425623d
commit
092e0a39e8
3 changed files with 33 additions and 6 deletions
|
@ -4,6 +4,11 @@ import net.minecraft.client.gui.screens.Screen;
|
|||
import net.minecraft.network.chat.CommonComponents;
|
||||
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.gui.gridlayout.GridColumn;
|
||||
import ru.bclib.gui.gridlayout.GridRow;
|
||||
import ru.bclib.gui.gridlayout.GridScreen;
|
||||
|
||||
|
@ -13,12 +18,36 @@ public class MainScreen extends GridScreen{
|
|||
super(parent, new TranslatableComponent("title.bclib.modmenu.main"));
|
||||
}
|
||||
|
||||
protected TranslatableComponent getComponent(NamedPathConfig config, ConfigToken.Bool token, String type){
|
||||
String path = "";
|
||||
for (String p : token.getPath()){
|
||||
path += "." + p;
|
||||
|
||||
}
|
||||
return new TranslatableComponent(type + ".config." + path );
|
||||
}
|
||||
|
||||
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken token){
|
||||
if (token instanceof Bool){
|
||||
addRow(grid, config, (ConfigToken.Bool)token);
|
||||
}
|
||||
|
||||
grid.addSpacerRow(2);
|
||||
}
|
||||
|
||||
protected void addRow(GridColumn grid, NamedPathConfig config, ConfigToken.Bool token){
|
||||
GridRow row = grid.addRow();
|
||||
row.addCheckbox(getComponent(config, token, "title"), config.get(token), 20);
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void initLayout() {
|
||||
final int BUTTON_HEIGHT = 20;
|
||||
grid.addSpacerRow(20);
|
||||
GridRow row = grid.addRow();
|
||||
|
||||
Configs.CLIENT_CONFIG.getAllOptions().forEach(o -> addRow(grid, Configs.CLIENT_CONFIG, o));
|
||||
|
||||
GridRow row = grid.addRow();
|
||||
row.addFiller();
|
||||
row.addButton(CommonComponents.GUI_BACK, BUTTON_HEIGHT, font, (button)->{
|
||||
onClose();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue