mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-20 00:13:21 +02:00
switch to otterlib config UI
This commit is contained in:
parent
3944881f22
commit
1783c04c87
8 changed files with 29 additions and 375 deletions
|
@ -1,27 +0,0 @@
|
|||
package one.oth3r.sit.screen;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ClickableImageWidget extends ButtonWidget {
|
||||
private final Identifier image;
|
||||
|
||||
public ClickableImageWidget(int x, int y, int width, int height, Tooltip tooltip, Identifier image, ButtonWidget.PressAction onPress) {
|
||||
super(x, y, width, height, Text.empty(), onPress, Supplier::get);
|
||||
this.image = image;
|
||||
this.setTooltip(tooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
context.drawTexture(RenderLayer::getGuiTextured, image,
|
||||
this.getX(), this.getY(), 0.0f, 0.0f, this.getWidth(), this.getHeight(), this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package one.oth3r.sit.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class ConfigScreen extends Screen {
|
||||
protected final Screen parent;
|
||||
|
||||
public ConfigScreen(Screen parent) {
|
||||
super(Text.translatable("sit!.screen.config"));
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
int startY = this.height / 4 + 48;
|
||||
int spacing = 36;
|
||||
TextureButtonWidget serverConfigButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("config.server"),
|
||||
(button) -> client.setScreen(new UnderConstructionScreen(this, FileData.getServerConfig())), false)
|
||||
.dimensions(250,30).texture(Identifier.of(Data.MOD_ID, "server_button"), 246, 26).build());
|
||||
serverConfigButton.setPosition(this.width / 2 - (serverConfigButton.getWidth()/2), startY);
|
||||
|
||||
TextureButtonWidget sittingConfigButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("config.sitting"),
|
||||
(button) -> client.setScreen(new UnderConstructionScreen(this, FileData.getSittingConfig())), false)
|
||||
.dimensions(250,30).texture(Identifier.of(Data.MOD_ID, "sitting_button"), 246, 26).build());
|
||||
sittingConfigButton.setPosition(this.width / 2 - (sittingConfigButton.getWidth()/2), startY+36);
|
||||
|
||||
|
||||
TextureButtonWidget issuesButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.issues"),
|
||||
ConfirmLinkScreen.opening(this, URI.create("https://github.com/Oth3r/Sit/issues")), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "issues"), 15, 15).build());
|
||||
issuesButton.setPosition(this.width / 2 - 125, startY + 72 + 12);
|
||||
|
||||
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.translatable("sit!.gui.button.website"),
|
||||
ConfirmLinkScreen.opening(this, URI.create("https://modrinth.com/mod/sit!"))
|
||||
).dimensions(this.width / 2 - 100, startY + 72 + 12, 98, 20).build());
|
||||
|
||||
this.addDrawableChild(ButtonWidget.builder(Text.translatable("gui.done"), (button) -> {
|
||||
close();
|
||||
}).dimensions(this.width / 2 + 2, startY + 72 + 12, 98, 20).build());
|
||||
|
||||
TextureButtonWidget donateButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.donate"),
|
||||
ConfirmLinkScreen.opening(this, URI.create("https://Ko-fi.com/oth3r")), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "donate"), 15, 15).build());
|
||||
donateButton.setPosition(this.width / 2 + 105, startY + 72 + 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
|
||||
// todo fade in like the title screen on first load?
|
||||
renderBanner(context,width/2 - 64,this.height / 4 -38,1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.client.setScreen(parent);
|
||||
}
|
||||
|
||||
private void renderBanner(DrawContext context, int x, int y, float alpha) {
|
||||
context.drawTexture(RenderLayer::getGuiTextured,Identifier.of(Data.MOD_ID, "textures/gui/banner.png"),
|
||||
x, y, 0.0f, 0.0f, 128, 72, 128, 72, ColorHelper.getWhite(alpha));
|
||||
}
|
||||
}
|
|
@ -2,10 +2,11 @@ package one.oth3r.sit.screen;
|
|||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import one.oth3r.sit.SitClient;
|
||||
|
||||
public class ModMenu implements ModMenuApi {
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return ConfigScreen::new;
|
||||
return SitClient::getConfigScreen;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
package one.oth3r.sit.screen;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TextureButtonWidget extends ButtonWidget {
|
||||
//todo gray support
|
||||
protected final Identifier texture;
|
||||
protected final int textureWidth;
|
||||
protected final int textureHeight;
|
||||
protected final boolean tooltip;
|
||||
|
||||
TextureButtonWidget(int width, int height, Text message, int textureWidth, int textureHeight, Identifier texture, ButtonWidget.PressAction onPress, @Nullable ButtonWidget.NarrationSupplier narrationSupplier, boolean tooltip) {
|
||||
super(0, 0, width, height, message, onPress, narrationSupplier == null ? DEFAULT_NARRATION_SUPPLIER : narrationSupplier);
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
this.texture = texture;
|
||||
this.tooltip = tooltip;
|
||||
if (tooltip) setTooltip(Tooltip.of(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.renderWidget(context, mouseX, mouseY, delta);
|
||||
int x = this.getX() + this.getWidth() / 2 - this.textureWidth / 2;
|
||||
int y = this.getY() + this.getHeight() / 2 - this.textureHeight / 2;
|
||||
context.drawGuiTexture(RenderLayer::getGuiTextured, this.texture, x, y, this.textureWidth, this.textureHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawMessage(DrawContext context, TextRenderer textRenderer, int color) {
|
||||
if (!this.tooltip) super.drawMessage(context, textRenderer, color);
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private final Text text;
|
||||
private final ButtonWidget.PressAction onPress;
|
||||
private final boolean hideText;
|
||||
private int width = 150;
|
||||
private int height = 20;
|
||||
@Nullable
|
||||
private Identifier texture;
|
||||
private int textureWidth;
|
||||
private int textureHeight;
|
||||
@Nullable
|
||||
ButtonWidget.NarrationSupplier narrationSupplier;
|
||||
|
||||
public Builder(Text text, ButtonWidget.PressAction onPress, boolean hideText) {
|
||||
this.text = text;
|
||||
this.onPress = onPress;
|
||||
this.hideText = hideText;
|
||||
}
|
||||
|
||||
public Builder dimensions(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder texture(Identifier texture, int width, int height) {
|
||||
this.texture = texture;
|
||||
this.textureWidth = width;
|
||||
this.textureHeight = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder narration(ButtonWidget.NarrationSupplier narrationSupplier) {
|
||||
this.narrationSupplier = narrationSupplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextureButtonWidget build() {
|
||||
if (this.texture == null) {
|
||||
throw new IllegalStateException("Sprite not set");
|
||||
}
|
||||
return new TextureButtonWidget(width,height,text,textureWidth,textureHeight,texture,onPress,narrationSupplier,hideText);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
package one.oth3r.sit.screen;
|
||||
|
||||
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import one.oth3r.sit.file.CustomFile;
|
||||
import one.oth3r.sit.file.SittingConfig;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
import one.oth3r.sit.utl.Utl;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class UnderConstructionScreen<T extends CustomFile<T>> extends Screen {
|
||||
protected final Screen parent;
|
||||
protected T file;
|
||||
|
||||
public UnderConstructionScreen(Screen parent, T file) {
|
||||
super(Text.translatable("sit!.screen.config"));
|
||||
this.parent = parent;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
int startY = this.height / 5-4;
|
||||
ButtonWidget foxPNG = this.addDrawableChild(new ClickableImageWidget(70,70,140,140, Tooltip.of(Text.of("Art by @bunnestbun")),
|
||||
Identifier.of(Data.MOD_ID, "textures/gui/fox.png"), ConfirmLinkScreen.opening(this, URI.create("https://www.instagram.com/bunnestbun/"))));
|
||||
foxPNG.setPosition(this.width / 2 - (foxPNG.getWidth()/2), startY-35);
|
||||
|
||||
ButtonWidget openFileButton = this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("sit!.gui.button.file"),
|
||||
(button) -> Util.getOperatingSystem().open(this.file.getFile()))
|
||||
.dimensions(0, 0, 118 ,20).build());
|
||||
openFileButton.setPosition(this.width / 2 - 70, startY+110);
|
||||
|
||||
TextureButtonWidget folderButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.folder"),
|
||||
(button) -> Util.getOperatingSystem().open(Paths.get(this.file.getFile().getParent())), true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "folder"), 15, 15).build());
|
||||
folderButton.setPosition(this.width / 2 + 50, startY + 110);
|
||||
|
||||
TextureButtonWidget resetButton = this.addDrawableChild(new TextureButtonWidget.Builder(Text.translatable("sit!.gui.button.reset"),
|
||||
(button) -> {
|
||||
this.file.reset();
|
||||
this.file.save();
|
||||
}, true)
|
||||
.dimensions(20,20).texture(Identifier.of(Data.MOD_ID, "reset_file"), 15, 15).build());
|
||||
resetButton.setPosition(this.width / 2 -70, startY + 135);
|
||||
|
||||
ButtonWidget revertButton = this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("sit!.gui.button.revert"),
|
||||
(button) -> this.file.save())
|
||||
.dimensions(0, 0, 118,20).build());
|
||||
revertButton.setPosition(this.width / 2 - 48, startY+135);
|
||||
|
||||
|
||||
ButtonWidget saveExitButton = this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("sit!.gui.button.save"),
|
||||
(button) -> {
|
||||
this.file.load();
|
||||
this.file.save();
|
||||
|
||||
// send the settings to the server if editing the sitting file and on a supported server
|
||||
if (this.file instanceof SittingConfig && Data.isSupportedServer()) {
|
||||
Utl.sendSettingsPackets();
|
||||
}
|
||||
|
||||
this.client.setScreen(parent);
|
||||
})
|
||||
.dimensions(0, 0, 140,20).build());
|
||||
saveExitButton.setPosition(this.width / 2 - 70, startY+168);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.client.setScreen(parent);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue