better ui
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.saturnclient.saturnclient;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import org.saturnclient.saturnclient.cloaks.Cloaks;
|
||||
import org.saturnclient.saturnclient.event.KeyInputHandler;
|
||||
import org.saturnclient.saturnclient.auth.SaturnApi;
|
||||
@@ -20,8 +21,8 @@ public class SaturnClient implements ModInitializer {
|
||||
LOGGER.info("Initializing " + MOD_ID);
|
||||
|
||||
// Attempt authentication before initializing other features
|
||||
KeyInputHandler.register();
|
||||
if (SaturnApi.authenticate()) {
|
||||
KeyInputHandler.register();
|
||||
Cloaks.initialize();
|
||||
LOGGER.info(MOD_ID + " initialization complete");
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,7 @@ public class CloakSelector extends Screen {
|
||||
int y = ((this.height - (35 * (Cloaks.availableCloaks.size()))) / 2);
|
||||
|
||||
for (String cloak : Cloaks.availableCloaks) {
|
||||
addDrawableChild(new SaturnButton(Text.literal(cloak), (__) -> {
|
||||
addDrawableChild(SaturnButton.builder(Text.literal(cloak), (__)->{
|
||||
String uuid = client.player.getUuidAsString().replace("-", "");
|
||||
Cloaks.setCloak(uuid, cloak);
|
||||
}, (this.width - 50) / 2, y, 50, 30));
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.saturnclient.saturnclient.menus;
|
||||
|
||||
import org.saturnclient.saturnclient.widgets.SaturnButton;
|
||||
import org.saturnclient.saturnclient.widgets.SaturnClientTexture;
|
||||
import org.saturnclient.saturnclient.widgets.SaturnText;
|
||||
import org.saturnclient.saturnclient.widgets.SaturnTexture;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.TextWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@@ -18,26 +18,34 @@ public class MainMenu extends Screen {
|
||||
super.init();
|
||||
int saturnClientSize = 40;
|
||||
int saturnClientX = (this.width - saturnClientSize) / 2;
|
||||
int saturnClientY = ((this.height - 110) - saturnClientSize) / 2;
|
||||
int saturnClientY = ((this.height - 105) - saturnClientSize) / 2;
|
||||
|
||||
TextWidget saturnClientText = new TextWidget(Text.literal("Saturn Client"), this.textRenderer);
|
||||
addDrawable(new SaturnText("Saturn Client")
|
||||
.position((this.width - this.textRenderer.getWidth("Saturn Client")) / 2,
|
||||
saturnClientY + saturnClientSize + 1)
|
||||
.setAlpha(0)
|
||||
.onRender(t -> {
|
||||
if (t.alpha < 1.0f) {
|
||||
t.alpha += 0.1f;
|
||||
}
|
||||
}));
|
||||
|
||||
saturnClientText.setX((this.width - saturnClientText.getWidth()) / 2);
|
||||
saturnClientText.setY(saturnClientY + saturnClientSize + 3);
|
||||
|
||||
addDrawable(saturnClientText);
|
||||
|
||||
addDrawable(SaturnClientTexture.builder(Identifier.of("saturnclient", "icon.png"))
|
||||
.dimensions(saturnClientX, saturnClientY, saturnClientSize, saturnClientSize));
|
||||
addDrawable(SaturnTexture.builder(Identifier.of("saturnclient", "icon.png"))
|
||||
.dimensions(saturnClientX, saturnClientY + 20, saturnClientSize, saturnClientSize).onRender(t -> {
|
||||
if (t.y > saturnClientY) {
|
||||
t.y -= 1;
|
||||
}
|
||||
}));
|
||||
|
||||
int buttonWidth = 50;
|
||||
int buttonHeight = 30;
|
||||
|
||||
addDrawableChild(
|
||||
new SaturnButton(Text.literal("Cloaks"), (_button) -> {
|
||||
if (client.player != null) {
|
||||
client.setScreen(new CloakSelector());
|
||||
}
|
||||
}, (this.width - buttonWidth) / 2, (this.height - buttonHeight) / 2, buttonWidth, buttonHeight));
|
||||
SaturnButton cloakButton = SaturnButton.builder(Text.literal("Cloaks"), (_button) -> {
|
||||
if (client.player != null) {
|
||||
client.setScreen(new CloakSelector());
|
||||
}
|
||||
}, (this.width - buttonWidth) / 2, (this.height - buttonHeight) / 2, buttonWidth, buttonHeight);
|
||||
|
||||
addDrawableChild(cloakButton);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,38 @@
|
||||
package org.saturnclient.saturnclient.widgets;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.ButtonTextures;
|
||||
import net.minecraft.client.gui.widget.TextWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class SaturnButton extends TexturedButtonWidget {
|
||||
private TextWidget textWidget;
|
||||
private static final ButtonTextures BUTTON_TEXTURES = new ButtonTextures(
|
||||
public class SaturnButton extends ButtonWidget {
|
||||
private static final ButtonTextures TEXTURES = new ButtonTextures(
|
||||
Identifier.ofVanilla("widget/saturn_button"), Identifier.ofVanilla("widget/saturn_button_disabled"),
|
||||
Identifier.ofVanilla("widget/saturn_button_highlighted"));
|
||||
|
||||
public SaturnButton(Text message, PressAction onPress, int x, int y, int width, int height) {
|
||||
super(x, y, width, height, BUTTON_TEXTURES, onPress);
|
||||
protected SaturnButton(int x, int y, int width, int height, Text message, PressAction onPress,
|
||||
NarrationSupplier narrationSupplier) {
|
||||
super(x, y, width, height, message, onPress, narrationSupplier);
|
||||
}
|
||||
|
||||
setMessage(message);
|
||||
|
||||
textWidget = new TextWidget(message,
|
||||
MinecraftClient.getInstance().textRenderer);
|
||||
public static SaturnButton builder(Text message, PressAction onPress, int x, int y, int width, int height) {
|
||||
return new SaturnButton(x, y, width, height, message, onPress, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.renderWidget(context, mouseX, mouseY, delta);
|
||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||
|
||||
context.drawText(MinecraftClient.getInstance().textRenderer, getMessage(),
|
||||
getX() + (getWidth() - textWidget.getWidth()) / 2,
|
||||
1 + getY() + (getHeight() - textWidget.getHeight()) / 2,
|
||||
Color.WHITE.getRGB(), false);
|
||||
context.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(this.active, this.isSelected()), this.getX(),
|
||||
this.getY(), this.getWidth(), this.getHeight(), ColorHelper.getWhite(this.alpha));
|
||||
|
||||
int i = this.active ? 16777215 : 10526880;
|
||||
|
||||
this.drawMessage(context, minecraftClient.textRenderer, i | MathHelper.ceil(this.alpha * 255.0F) << 24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.saturnclient.saturnclient.widgets;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
|
||||
/**
|
||||
* Represents a drawable text element in the Saturn Client UI.
|
||||
* Uses the builder pattern for flexible text creation and configuration.
|
||||
*/
|
||||
public class SaturnText implements Drawable {
|
||||
private String text;
|
||||
private Consumer<SaturnText> onRender;
|
||||
public int x;
|
||||
public int y;
|
||||
public float alpha;
|
||||
|
||||
/**
|
||||
* Creates a new text element with the specified string.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
public SaturnText(String text) {
|
||||
this.text = text;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.alpha = 1.0f;
|
||||
this.onRender = __ -> {
|
||||
};
|
||||
}
|
||||
|
||||
public SaturnText onRender(Consumer<SaturnText> onRender) {
|
||||
this.onRender = onRender;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SaturnText setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SaturnText setText(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new builder instance for the text.
|
||||
*
|
||||
* @param text The text content
|
||||
* @return A new SaturnText instance
|
||||
*/
|
||||
public static SaturnText builder(String text) {
|
||||
return new SaturnText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position of the text.
|
||||
*
|
||||
* @param x The x coordinate
|
||||
* @param y The y coordinate
|
||||
* @return This instance for method chaining
|
||||
*/
|
||||
public SaturnText position(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
onRender.accept(this);
|
||||
context.drawText(MinecraftClient.getInstance().textRenderer, text, x, y, ColorHelper.getWhite(alpha), false);
|
||||
}
|
||||
}
|
||||
+31
-11
@@ -1,35 +1,53 @@
|
||||
package org.saturnclient.saturnclient.widgets;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Drawable;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
|
||||
/**
|
||||
* Represents a drawable texture in the Saturn Client UI.
|
||||
* Uses the builder pattern for flexible texture creation and configuration.
|
||||
*/
|
||||
public class SaturnClientTexture implements Drawable {
|
||||
public class SaturnTexture implements Drawable {
|
||||
// Predefined textures
|
||||
public static final Identifier BOX_1_1 = Identifier.of("saturnclient", "textures/gui/box_1_1.png");
|
||||
|
||||
private final Identifier sprite;
|
||||
private int x;
|
||||
private int y;
|
||||
private int width;
|
||||
private int height;
|
||||
private Consumer<SaturnTexture> onRender;
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
public float alpha;
|
||||
|
||||
/**
|
||||
* Creates a new texture with the specified sprite.
|
||||
*
|
||||
* @param sprite The identifier for the texture sprite
|
||||
*/
|
||||
private SaturnClientTexture(Identifier sprite) {
|
||||
private SaturnTexture(Identifier sprite) {
|
||||
this.sprite = sprite;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.alpha = 1.0f;
|
||||
this.onRender = __ -> {
|
||||
};
|
||||
}
|
||||
|
||||
public SaturnTexture onRender(Consumer<SaturnTexture> onRender) {
|
||||
this.onRender = onRender;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SaturnTexture setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,8 +56,8 @@ public class SaturnClientTexture implements Drawable {
|
||||
* @param sprite The identifier for the texture sprite
|
||||
* @return A new SaturnClientTexture instance
|
||||
*/
|
||||
public static SaturnClientTexture builder(Identifier sprite) {
|
||||
return new SaturnClientTexture(sprite);
|
||||
public static SaturnTexture builder(Identifier sprite) {
|
||||
return new SaturnTexture(sprite);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +69,7 @@ public class SaturnClientTexture implements Drawable {
|
||||
* @param height The height of the texture
|
||||
* @return This instance for method chaining
|
||||
*/
|
||||
public SaturnClientTexture dimensions(int x, int y, int width, int height) {
|
||||
public SaturnTexture dimensions(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
@@ -65,12 +83,14 @@ public class SaturnClientTexture implements Drawable {
|
||||
* @param focused The focused state
|
||||
* @return This instance for method chaining
|
||||
*/
|
||||
public SaturnClientTexture setFocused(boolean focused) {
|
||||
public SaturnTexture setFocused(boolean focused) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
context.drawTexture(RenderLayer::getGuiTextured, sprite, x, y, 0, 0, width, height, width, height);
|
||||
onRender.accept(this);
|
||||
context.drawTexture(RenderLayer::getGuiTextured, sprite, x, y, 0, 0, width, height, width, height,
|
||||
ColorHelper.getWhite(alpha));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user