Added Module Settings and removed test screen
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package de.fullrisk.citrusDev.UI;
|
||||
|
||||
import de.fullrisk.citrusDev.Config;
|
||||
import io.wispforest.owo.ui.base.BaseOwoScreen;
|
||||
import io.wispforest.owo.ui.component.UIComponents;
|
||||
import io.wispforest.owo.ui.container.FlowLayout;
|
||||
@@ -17,6 +18,7 @@ import de.fullrisk.citrusDev.UIHelper.ScaleValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.fullrisk.citrusDev.UI.Module_FPS.fpsContainer;
|
||||
import static de.fullrisk.citrusDev.UI.Module_FPS.toggle;
|
||||
|
||||
public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
@@ -44,11 +46,18 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
private static final int CONTENT_WIDTH = INNER_WIDTH - SIDEBAR_WIDTH - DIVIDER_SIZE;
|
||||
|
||||
private record TabDef(String label, Runnable onClick) {}
|
||||
private record SettingRow(String label, FlowLayout control) {}
|
||||
|
||||
private FlowLayout content;
|
||||
private final String initialModule;
|
||||
|
||||
public MyScreen() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public MyScreen(String initialModule) {
|
||||
super(Component.literal("Citrus Dev"));
|
||||
this.initialModule = initialModule;
|
||||
Minecraft.getInstance().getSoundManager().play(
|
||||
SimpleSoundInstance.forUI(SoundEvents.UI_TOAST_IN, 1.5F, 2)
|
||||
);
|
||||
@@ -96,7 +105,6 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
content.padding(Insets.of(4));
|
||||
content.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
content.verticalAlignment(VerticalAlignment.TOP);
|
||||
buildGeneralPanel(content);
|
||||
row.child(content);
|
||||
|
||||
panel.child(row);
|
||||
@@ -116,6 +124,13 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
panel.child(version);
|
||||
|
||||
rootComponent.child(panel);
|
||||
|
||||
// Now that content is attached to the tree, decide what to show.
|
||||
if ("FPS".equals(initialModule)) {
|
||||
openModuleSettings("FPS", fpsModuleSettings());
|
||||
} else {
|
||||
buildGeneralPanel(content);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildNavbar(FlowLayout navbar) {
|
||||
@@ -131,14 +146,20 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
List<TabDef> tabs = List.of(
|
||||
new TabDef("general", () -> {
|
||||
content.clearChildren();
|
||||
content.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
content.verticalAlignment(VerticalAlignment.TOP);
|
||||
buildGeneralPanel(content);
|
||||
}),
|
||||
new TabDef("modules", () -> {
|
||||
new TabDef("quests", () -> {
|
||||
content.clearChildren();
|
||||
buildModulesPanel(content);
|
||||
content.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
content.verticalAlignment(VerticalAlignment.TOP);
|
||||
buildQuestsPanel(content);
|
||||
}),
|
||||
new TabDef("settings", () -> {
|
||||
content.clearChildren();
|
||||
content.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
content.verticalAlignment(VerticalAlignment.TOP);
|
||||
buildSettingsPanel(content);
|
||||
})
|
||||
);
|
||||
@@ -264,7 +285,10 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
FLAT,
|
||||
Identifier.fromNamespaceAndPath("citrus-dev", "textures/icons/settings.png"),
|
||||
() -> {
|
||||
Minecraft.getInstance().setScreen(new MyScreen());
|
||||
Config.get().lastModule = "FPS";
|
||||
Config.get().save();
|
||||
|
||||
openModuleSettings("FPS", fpsModuleSettings());
|
||||
}
|
||||
);
|
||||
iconButton.child(settingsButton);
|
||||
@@ -289,36 +313,96 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
content.child(iconButton);
|
||||
}
|
||||
|
||||
private void buildModulesPanel(FlowLayout content) {
|
||||
content.child(UIComponents.label(Component.literal("Modules tab - coming soon")));
|
||||
private void buildQuestsPanel(FlowLayout content) {
|
||||
content.child(UIComponents.label(Component.literal("Quests - coming soon")));
|
||||
}
|
||||
|
||||
private void buildSettingsPanel(FlowLayout content) {
|
||||
content.child(UIComponents.label(Component.literal("Settings")));
|
||||
content.child(makeCyclingButton());
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a per-module settings view inside the "content" container,
|
||||
* replacing whatever was there before. A back arrow returns to General.
|
||||
*/
|
||||
private void openModuleSettings(String title, List<SettingRow> rows) {
|
||||
content.clearChildren();
|
||||
|
||||
// re-assert alignment explicitly - clearChildren can reset it
|
||||
content.horizontalAlignment(HorizontalAlignment.LEFT);
|
||||
content.verticalAlignment(VerticalAlignment.TOP);
|
||||
|
||||
FlowLayout header = UIContainers.horizontalFlow(Sizing.fixed(CONTENT_WIDTH - 8), Sizing.content());
|
||||
header.verticalAlignment(VerticalAlignment.CENTER);
|
||||
header.horizontalAlignment(HorizontalAlignment.LEFT);
|
||||
header.gap(6);
|
||||
|
||||
header.child(makeTextButton(FLAT, "<", () -> {
|
||||
content.clearChildren();
|
||||
content.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
content.verticalAlignment(VerticalAlignment.TOP);
|
||||
buildGeneralPanel(content);
|
||||
}));
|
||||
|
||||
header.child(UIComponents.label(Component.literal(title)
|
||||
.withStyle(style -> style.withFont(new FontDescription.Resource(MC_FIVE))))
|
||||
.color(Color.ofRgb(0xCCCCCC)));
|
||||
|
||||
content.child(header);
|
||||
|
||||
for (SettingRow row : rows) {
|
||||
content.child(makeSettingRow(row));
|
||||
}
|
||||
}
|
||||
|
||||
private FlowLayout makeSettingRow(SettingRow setting) {
|
||||
FlowLayout row = UIContainers.horizontalFlow(Sizing.fixed(CONTENT_WIDTH - 8), Sizing.content());
|
||||
row.verticalAlignment(VerticalAlignment.TOP);
|
||||
row.horizontalAlignment(HorizontalAlignment.LEFT);
|
||||
row.padding(Insets.of(2));
|
||||
row.gap(6);
|
||||
|
||||
row.child(UIComponents.label(Component.literal(setting.label()))
|
||||
.color(Color.ofRgb(0xa3a3ac)));
|
||||
row.child(UIComponents.spacer());
|
||||
row.child(setting.control());
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
private List<SettingRow> fpsModuleSettings() {
|
||||
return List.of(
|
||||
new SettingRow("Position", makeCyclingButton())
|
||||
);
|
||||
}
|
||||
|
||||
private record ButtonState(String label, Runnable onSelect) {}
|
||||
|
||||
private FlowLayout makeCyclingButton() { // muss ich noch fertig machen, bitte es geht mir nd gut, es ist 23:00
|
||||
private FlowLayout makeCyclingButton() {
|
||||
List<ButtonState> states = List.of(
|
||||
new ButtonState("Off", () -> {
|
||||
Module_FPS.setPosition(1, 1);
|
||||
|
||||
}),
|
||||
new ButtonState("Low", () -> {
|
||||
Module_FPS.setPosition(99, 1);
|
||||
|
||||
}),
|
||||
new ButtonState("Medium", () -> {
|
||||
Module_FPS.setPosition(99, 99);
|
||||
|
||||
}),
|
||||
new ButtonState("High", () -> {
|
||||
|
||||
Module_FPS.setPosition(1, 99);
|
||||
})
|
||||
);
|
||||
|
||||
int[] currentIndex = {0};
|
||||
|
||||
FlowLayout button = UIContainers.verticalFlow(Sizing.fixed(60), Sizing.fixed(20));
|
||||
FlowLayout button = UIContainers.verticalFlow(Sizing.fixed(50), Sizing.fixed(16));
|
||||
button.verticalAlignment(VerticalAlignment.CENTER);
|
||||
button.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
button.surface(FLAT);
|
||||
button.surface(GLASS_PANEL);
|
||||
|
||||
var label = UIComponents.label(Component.literal(states.get(0).label()))
|
||||
.color(Color.ofRgb(0xFFFFFF));
|
||||
@@ -337,7 +421,12 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
button.mouseEnter().subscribe(() -> {
|
||||
label.color(Color.ofRgb(0xFFFFFF));
|
||||
});
|
||||
button.mouseLeave().subscribe(() -> {
|
||||
label.color(Color.ofRgb(0xCCCCCC));
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -366,6 +455,30 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
|
||||
return button;
|
||||
}
|
||||
|
||||
private FlowLayout makeTextButton(Surface baseSurface, String text, Runnable onClick) {
|
||||
FlowLayout button = UIContainers.verticalFlow(Sizing.content(), Sizing.content());
|
||||
button.verticalAlignment(VerticalAlignment.CENTER);
|
||||
button.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
button.padding(Insets.of(2, 2, 4, 4));
|
||||
button.surface(baseSurface);
|
||||
button.child(UIComponents.label(Component.literal(text)).color(Color.ofRgb(0xFFFFFF)));
|
||||
|
||||
button.mouseEnter().subscribe(() -> button.surface(
|
||||
Surface.blur(5f, 15f).and(Surface.flat(0x70FFFFFF)).and(Surface.outline(0xFFFFFFFF))
|
||||
));
|
||||
button.mouseLeave().subscribe(() -> button.surface(baseSurface));
|
||||
|
||||
button.mouseDown().subscribe((click, doubled) -> {
|
||||
Minecraft.getInstance().getSoundManager().play(
|
||||
SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 2.0F, 2)
|
||||
);
|
||||
onClick.run();
|
||||
return true;
|
||||
});
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPauseScreen() {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user