Created basic Mod Menu Integration and made different fog types toggleable
This commit is contained in:
@ -0,0 +1,88 @@
|
||||
package wtf.hak.survivalfabric.modmenu;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import wtf.hak.survivalfabric.config.client.ClientConfig;
|
||||
import wtf.hak.survivalfabric.config.client.ClientConfigManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ConfigScreen extends Screen {
|
||||
|
||||
private final Screen parent;
|
||||
|
||||
public ConfigScreen(Screen parent) {
|
||||
super(Text.literal("Survival Fabric - Client Config"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
int buttonWidth = 200;
|
||||
int buttonHeight = 20;
|
||||
int spacing = 5;
|
||||
int startY = 40;
|
||||
int i = 0;
|
||||
|
||||
for (Field field : ClientConfig.class.getFields()) {
|
||||
if (field.getType() == boolean.class) {
|
||||
int y = startY + i * (buttonHeight + spacing);
|
||||
try {
|
||||
boolean value = field.getBoolean(ClientConfigManager.getConfig());
|
||||
String label = formatFieldName(field.getName()) + ": " + (value ? "ON" : "OFF");
|
||||
|
||||
ButtonWidget button = ButtonWidget.builder(
|
||||
Text.literal(label),
|
||||
b -> {
|
||||
try {
|
||||
boolean current = field.getBoolean(ClientConfigManager.getConfig());
|
||||
field.setBoolean(ClientConfigManager.getConfig(), !current);
|
||||
b.setMessage(Text.literal(formatFieldName(field.getName()) + ": " + (!current ? "ON" : "OFF")));
|
||||
ClientConfigManager.save(); // Save if needed
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
).dimensions(this.width / 2 - buttonWidth / 2, y, buttonWidth, buttonHeight).build();
|
||||
|
||||
this.addDrawableChild(button);
|
||||
i++;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done button
|
||||
this.addDrawableChild(ButtonWidget.builder(
|
||||
Text.translatable("gui.done"),
|
||||
button -> this.client.setScreen(parent)
|
||||
).dimensions(this.width / 2 - 75, startY + i * (buttonHeight + spacing) + 10, 150, 20).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
context.fill(0, 0, this.width, this.height, 0xC0101010);
|
||||
|
||||
int titleX = (this.width / 2) - (this.textRenderer.getWidth(this.title) / 2);
|
||||
context.drawTextWithShadow(this.textRenderer, this.title, titleX, 20, 0xFFFFFF);
|
||||
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
private String formatFieldName(String rawName) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
char[] chars = rawName.toCharArray();
|
||||
result.append(Character.toUpperCase(chars[0]));
|
||||
for (int i = 1; i < chars.length; i++) {
|
||||
if (Character.isUpperCase(chars[i])) {
|
||||
result.append(' ');
|
||||
}
|
||||
result.append(chars[i]);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user