ui
This commit is contained in:
@@ -27,27 +27,66 @@ public class SettingsMenu extends SaturnUi {
|
||||
.setHeight(rectHeight)
|
||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
||||
|
||||
int tabsX = (width - 43) / 2;
|
||||
int tabsY = modsY - 17;
|
||||
|
||||
draw(new SaturnTexture(Textures.TABS)
|
||||
.setX((width - 43) / 2)
|
||||
.setY(modsY - 16)
|
||||
.setX(tabsX)
|
||||
.setY(tabsY)
|
||||
.setWidth(43)
|
||||
.setHeight(15)
|
||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
||||
|
||||
int modX = modsX + 15;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
draw(new SaturnClickableImage(Textures.MOD, () -> {
|
||||
int tabSize = 9;
|
||||
tabsX = (width - tabSize) / 2;
|
||||
draw(new SaturnClickableImage(Textures.SETTINGS_TAB, () -> {
|
||||
System.out.println("Pressed");
|
||||
})
|
||||
.setBackground(false)
|
||||
.setX(modX)
|
||||
.setY(modsY + 10)
|
||||
.setWidth(86)
|
||||
.setHeight(20)
|
||||
.setAnimation(SaturnAnimation.FADE_SLIDE.offset(40)));
|
||||
.setX(tabsX)
|
||||
.setY(tabsY + 3)
|
||||
.setWidth(tabSize)
|
||||
.setHeight(tabSize)
|
||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
||||
|
||||
draw(new SaturnClickableImage(Textures.MODS_TAB, () -> {
|
||||
System.out.println("Pressed");
|
||||
})
|
||||
.setX(tabsX - 12)
|
||||
.setY(tabsY + 3)
|
||||
.setWidth(tabSize)
|
||||
.setHeight(tabSize)
|
||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
||||
|
||||
draw(new SaturnClickableImage(Textures.SEARCH, () -> {
|
||||
System.out.println("Pressed");
|
||||
})
|
||||
.setX(tabsX + 12)
|
||||
.setY(tabsY + 3)
|
||||
.setWidth(tabSize)
|
||||
.setHeight(tabSize)
|
||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
||||
|
||||
int modX = modsX + 15;
|
||||
int modY = modsY + 10;
|
||||
int col = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
draw(new SaturnClickableImage(Textures.MOD, (m) -> {
|
||||
})
|
||||
.setX(modX)
|
||||
.setY(modY)
|
||||
.setWidth(86)
|
||||
.setHeight(20));
|
||||
|
||||
col++;
|
||||
|
||||
if (col < 3) {
|
||||
modX += 86 + 15;
|
||||
} else {
|
||||
modX = modsX + 15;
|
||||
modY += 20 + 20;
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class SaturnUi extends Screen {
|
||||
|
||||
boolean isMouseInside = widget.x < mouseX && widget.x + widget.width > mouseX
|
||||
&& widget.y < mouseY && widget.y + widget.height > mouseY;
|
||||
widget.render(context, isMouseInside);
|
||||
widget.render(context, isMouseInside, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class SaturnWidget {
|
||||
public SaturnAnimation animation = null;
|
||||
public boolean visible = true;
|
||||
|
||||
public void render(DrawContext context, boolean hovering) {
|
||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||
}
|
||||
|
||||
public void click() {
|
||||
|
||||
@@ -8,6 +8,9 @@ public class Textures {
|
||||
public static final Identifier EMOTE = Identifier.of("saturnclient", "textures/gui/components/emote.png");
|
||||
public static final Identifier SEARCH = Identifier.of("saturnclient", "textures/gui/components/search.png");
|
||||
public static final Identifier CLOSE = Identifier.of("saturnclient", "textures/gui/components/close.png");
|
||||
public static final Identifier MODS_TAB = Identifier.of("saturnclient", "textures/gui/components/mods_tab.png");
|
||||
public static final Identifier SETTINGS_TAB = Identifier.of("saturnclient",
|
||||
"textures/gui/components/settings_tab.png");
|
||||
|
||||
// Widgets
|
||||
public static final Identifier BUTTON_BORDER = Identifier.ofVanilla("saturn/button_border");
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package org.saturnclient.ui.widgets;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui.SaturnWidget;
|
||||
import org.saturnclient.ui.Textures;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
@@ -16,16 +15,22 @@ import net.minecraft.util.math.MathHelper;
|
||||
public class SaturnButton extends SaturnWidget {
|
||||
public boolean active = true;
|
||||
public String text;
|
||||
public Runnable onPress;
|
||||
public Consumer<SaturnButton> onPress;
|
||||
public boolean background = true;
|
||||
|
||||
public SaturnButton(String text, Runnable onPress) {
|
||||
public SaturnButton(String text, Consumer<SaturnButton> onPress) {
|
||||
this.text = text;
|
||||
this.onPress = onPress;
|
||||
}
|
||||
|
||||
public SaturnButton(String text, Runnable onPress) {
|
||||
this(text, (b) -> {
|
||||
onPress.run();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, boolean hovering) {
|
||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||
|
||||
if (background) {
|
||||
@@ -50,6 +55,6 @@ public class SaturnButton extends SaturnWidget {
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
this.onPress.run();
|
||||
this.onPress.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,44 @@
|
||||
package org.saturnclient.ui.widgets;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui.SaturnWidget;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
|
||||
public class SaturnClickableImage extends SaturnButton {
|
||||
public class SaturnClickableImage extends SaturnWidget {
|
||||
public Identifier sprite;
|
||||
public boolean selected = false;
|
||||
public Consumer<SaturnClickableImage> onPress;
|
||||
|
||||
public SaturnClickableImage(Identifier sprite, Consumer<SaturnClickableImage> onPress) {
|
||||
this.sprite = sprite;
|
||||
this.onPress = onPress;
|
||||
}
|
||||
|
||||
public SaturnClickableImage(Identifier sprite, Runnable onPress) {
|
||||
super("", onPress);
|
||||
this.sprite = sprite;
|
||||
this(sprite, (m) -> {
|
||||
onPress.run();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, boolean hovering) {
|
||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||
context.drawTexture(RenderLayer::getGuiTextured, sprite, x, y, 0, 0, width, height, width,
|
||||
height, hovering || selected ? SaturnClient.COLOR : ColorHelper.getWhite(alpha));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
this.onPress.run();
|
||||
this.onPress.accept(this);
|
||||
}
|
||||
|
||||
public SaturnClickableImage setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SaturnClickableImage setBackground(boolean background) {
|
||||
this.background = background;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.saturnclient.ui.widgets;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
@@ -10,17 +11,26 @@ public class SaturnImageButton extends SaturnButton {
|
||||
public Identifier sprite;
|
||||
public int imageWidth;
|
||||
public int imageHeight;
|
||||
public Consumer<SaturnImageButton> onPress;
|
||||
|
||||
public SaturnImageButton(Identifier sprite, int imageWidth, int imageHeight, Runnable onPress) {
|
||||
super("", onPress);
|
||||
public SaturnImageButton(Identifier sprite, int imageWidth, int imageHeight, Consumer<SaturnImageButton> onPress) {
|
||||
super("", (b) -> {
|
||||
});
|
||||
this.sprite = sprite;
|
||||
this.imageWidth = imageWidth;
|
||||
this.imageHeight = imageHeight;
|
||||
this.onPress = onPress;
|
||||
}
|
||||
|
||||
public SaturnImageButton(Identifier sprite, int imageWidth, int imageHeight, Runnable onPress) {
|
||||
this(sprite, imageWidth, imageHeight, (b) -> {
|
||||
onPress.run();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, boolean hovering) {
|
||||
super.render(context, hovering);
|
||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||
super.render(context, hovering, mouseX, mouseY);
|
||||
context.drawTexture(RenderLayer::getGuiTextured, sprite, x + (width - imageWidth) / 2,
|
||||
y + (height - imageHeight) / 2, 0, 0, imageWidth, imageHeight, imageWidth,
|
||||
imageHeight, hovering ? SaturnClient.COLOR : ColorHelper.getWhite(alpha));
|
||||
@@ -28,7 +38,7 @@ public class SaturnImageButton extends SaturnButton {
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
this.onPress.run();
|
||||
this.onPress.accept(this);
|
||||
}
|
||||
|
||||
public SaturnImageButton setBackground(boolean background) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SaturnInputBox extends SaturnWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, boolean hovering) {
|
||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||
context.drawGuiTexture(RenderLayer::getGuiTextured, Textures.BUTTON, this.x,
|
||||
this.y, this.width, this.height, ColorHelper.getWhite(this.alpha));
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class SaturnText extends SaturnWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, boolean hovering) {
|
||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||
context.drawText(MinecraftClient.getInstance().textRenderer, text, x, y, ColorHelper.getWhite(alpha), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class SaturnTexture extends SaturnWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, boolean hovering) {
|
||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||
context.drawGuiTexture(RenderLayer::getGuiTextured, sprite, this.x,
|
||||
this.y, this.width, this.height, ColorHelper.getWhite(this.alpha));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user