ui
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
package org.saturnclient.saturnclient.menus;
|
package org.saturnclient.saturnclient.menus;
|
||||||
|
|
||||||
import org.saturnclient.ui.SaturnAnimation;
|
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.Textures;
|
import org.saturnclient.ui.Textures;
|
||||||
|
import org.saturnclient.ui.animations.FadeIn;
|
||||||
|
import org.saturnclient.ui.animations.Slide;
|
||||||
import org.saturnclient.ui.widgets.SaturnButton;
|
import org.saturnclient.ui.widgets.SaturnButton;
|
||||||
import org.saturnclient.ui.widgets.SaturnImageButton;
|
import org.saturnclient.ui.widgets.SaturnImageButton;
|
||||||
import org.saturnclient.ui.widgets.SaturnTexture;
|
import org.saturnclient.ui.widgets.SaturnSprite;
|
||||||
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
@@ -22,9 +23,10 @@ public class MainMenu extends SaturnUi {
|
|||||||
draw(
|
draw(
|
||||||
new SaturnButton("Settings", () -> {
|
new SaturnButton("Settings", () -> {
|
||||||
client.setScreen(new SettingsMenu());
|
client.setScreen(new SettingsMenu());
|
||||||
}).setX((width - buttonWidth) / 2).setY((height - buttonHeight) / 2).setWidth(buttonWidth)
|
}).setX((width - buttonWidth) / 2).setY((height - buttonHeight) /
|
||||||
|
2).setWidth(buttonWidth)
|
||||||
.setHeight(buttonHeight)
|
.setHeight(buttonHeight)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE.offset(15).speed(0.1f)));
|
.setAnimations(new FadeIn(3)));
|
||||||
|
|
||||||
draw(
|
draw(
|
||||||
new SaturnImageButton(Textures.EMOTE, 14, 14,
|
new SaturnImageButton(Textures.EMOTE, 14, 14,
|
||||||
@@ -35,7 +37,7 @@ public class MainMenu extends SaturnUi {
|
|||||||
.setY((height - buttonHeight) / 2)
|
.setY((height - buttonHeight) / 2)
|
||||||
.setWidth(buttonHeight)
|
.setWidth(buttonHeight)
|
||||||
.setHeight(buttonHeight)
|
.setHeight(buttonHeight)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE.offset(15).speed(0.1f)));
|
.setAnimations(new FadeIn(3)));
|
||||||
|
|
||||||
draw(
|
draw(
|
||||||
new SaturnImageButton(Textures.COSMETICS, 14, 14,
|
new SaturnImageButton(Textures.COSMETICS, 14, 14,
|
||||||
@@ -46,16 +48,24 @@ public class MainMenu extends SaturnUi {
|
|||||||
.setY((height - buttonHeight) / 2)
|
.setY((height - buttonHeight) / 2)
|
||||||
.setWidth(buttonHeight)
|
.setWidth(buttonHeight)
|
||||||
.setHeight(buttonHeight)
|
.setHeight(buttonHeight)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE.offset(15).speed(0.1f)));
|
.setAnimations(new FadeIn(3)));
|
||||||
|
|
||||||
int logoSize = 40;
|
int logoSize = 49;
|
||||||
|
|
||||||
draw(
|
draw(
|
||||||
new SaturnTexture(Textures.LOGO)
|
new SaturnSprite(Textures.LOGO_TEXT)
|
||||||
.setX((width - logoSize) / 2)
|
.setX((width - logoSize) / 2)
|
||||||
.setY((height - logoSize) / 2 - logoSize - 10)
|
.setY((height - 8) / 2 - 23)
|
||||||
|
.setWidth(logoSize)
|
||||||
|
.setHeight(8)
|
||||||
|
.setAnimations(new FadeIn(3)));
|
||||||
|
|
||||||
|
draw(
|
||||||
|
new SaturnSprite(Textures.LOGO)
|
||||||
|
.setX((width - logoSize) / 2)
|
||||||
|
.setY(height / 2 - logoSize - 24)
|
||||||
.setWidth(logoSize)
|
.setWidth(logoSize)
|
||||||
.setHeight(logoSize)
|
.setHeight(logoSize)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
.setAnimations(new Slide(2, 14)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,9 @@ package org.saturnclient.saturnclient.menus;
|
|||||||
|
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.Textures;
|
import org.saturnclient.ui.Textures;
|
||||||
|
import org.saturnclient.ui.animations.FadeIn;
|
||||||
import org.saturnclient.ui.widgets.SaturnClickableImage;
|
import org.saturnclient.ui.widgets.SaturnClickableImage;
|
||||||
import org.saturnclient.ui.widgets.SaturnTexture;
|
import org.saturnclient.ui.widgets.SaturnImage;
|
||||||
import org.saturnclient.ui.SaturnAnimation;
|
|
||||||
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
@@ -20,22 +20,22 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
int modsX = (width - rectWidth) / 2;
|
int modsX = (width - rectWidth) / 2;
|
||||||
int modsY = (height - rectHeight) / 2;
|
int modsY = (height - rectHeight) / 2;
|
||||||
|
|
||||||
draw(new SaturnTexture(Textures.SETTINGS_BG)
|
draw(new SaturnImage(Textures.SETTINGS_BG)
|
||||||
.setX(modsX)
|
.setX(modsX)
|
||||||
.setY(modsY)
|
.setY(modsY)
|
||||||
.setWidth(rectWidth)
|
.setWidth(rectWidth)
|
||||||
.setHeight(rectHeight)
|
.setHeight(rectHeight)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
.setAnimations(new FadeIn(1)));
|
||||||
|
|
||||||
int tabsX = (width - 43) / 2;
|
int tabsX = (width - 43) / 2;
|
||||||
int tabsY = modsY - 17;
|
int tabsY = modsY - 17;
|
||||||
|
|
||||||
draw(new SaturnTexture(Textures.TABS)
|
draw(new SaturnImage(Textures.TABS)
|
||||||
.setX(tabsX)
|
.setX(tabsX)
|
||||||
.setY(tabsY)
|
.setY(tabsY)
|
||||||
.setWidth(43)
|
.setWidth(43)
|
||||||
.setHeight(15)
|
.setHeight(15)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
.setAnimations(new FadeIn(1)));
|
||||||
|
|
||||||
int tabSize = 9;
|
int tabSize = 9;
|
||||||
tabsX = (width - tabSize) / 2;
|
tabsX = (width - tabSize) / 2;
|
||||||
@@ -46,7 +46,7 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
.setHeight(tabSize)
|
.setHeight(tabSize)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
.setAnimations(new FadeIn(1)));
|
||||||
|
|
||||||
draw(new SaturnClickableImage(Textures.MODS_TAB, () -> {
|
draw(new SaturnClickableImage(Textures.MODS_TAB, () -> {
|
||||||
System.out.println("Pressed");
|
System.out.println("Pressed");
|
||||||
@@ -55,7 +55,7 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
.setHeight(tabSize)
|
.setHeight(tabSize)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
.setAnimations(new FadeIn(1)));
|
||||||
|
|
||||||
draw(new SaturnClickableImage(Textures.SEARCH, () -> {
|
draw(new SaturnClickableImage(Textures.SEARCH, () -> {
|
||||||
System.out.println("Pressed");
|
System.out.println("Pressed");
|
||||||
@@ -64,7 +64,7 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
.setHeight(tabSize)
|
.setHeight(tabSize)
|
||||||
.setAnimation(SaturnAnimation.FADE_SLIDE));
|
.setAnimations(new FadeIn(1)));
|
||||||
|
|
||||||
int modX = modsX + 15;
|
int modX = modsX + 15;
|
||||||
int modY = modsY + 10;
|
int modY = modsY + 10;
|
||||||
|
|||||||
@@ -1,41 +1,13 @@
|
|||||||
package org.saturnclient.ui;
|
package org.saturnclient.ui;
|
||||||
|
|
||||||
public enum SaturnAnimation {
|
public class SaturnAnimation {
|
||||||
FADE,
|
public int delay = 0;
|
||||||
SLIDE,
|
public int lastTick = 0;
|
||||||
FADE_SLIDE;
|
|
||||||
|
|
||||||
public int offset = 10;
|
public void init(SaturnWidget widget) {
|
||||||
public float speed = 0.05f;
|
|
||||||
|
|
||||||
public void apply(SaturnWidget widget) {
|
|
||||||
switch (this) {
|
|
||||||
case FADE:
|
|
||||||
widget.alpha = Math.min(widget.alpha + speed, 1.0f);
|
|
||||||
break;
|
|
||||||
case SLIDE:
|
|
||||||
if (offset > 0) {
|
|
||||||
widget.y--;
|
|
||||||
offset--;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case FADE_SLIDE:
|
|
||||||
widget.alpha = Math.min(widget.alpha + speed, 1.0f);
|
|
||||||
if (offset > 0) {
|
|
||||||
widget.y--;
|
|
||||||
offset--;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaturnAnimation offset(int offset) {
|
public boolean run(SaturnWidget widget, int tick) {
|
||||||
this.offset = offset;
|
return true;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SaturnAnimation speed(float speed) {
|
|
||||||
this.speed = speed;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.minecraft.text.Text;
|
|||||||
|
|
||||||
public class SaturnUi extends Screen {
|
public class SaturnUi extends Screen {
|
||||||
public List<SaturnWidget> widgets = new ArrayList<>();
|
public List<SaturnWidget> widgets = new ArrayList<>();
|
||||||
|
private int tick = 0;
|
||||||
|
|
||||||
public SaturnUi(Text title) {
|
public SaturnUi(Text title) {
|
||||||
super(title);
|
super(title);
|
||||||
@@ -31,14 +32,24 @@ public class SaturnUi extends Screen {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.animation != null) {
|
if (widget.animations != null) {
|
||||||
widget.animation.apply(widget);
|
for (SaturnAnimation animation : widget.animations) {
|
||||||
|
if (animation != null && tick - animation.lastTick == animation.delay) {
|
||||||
|
if (animation.run(widget, tick)) {
|
||||||
|
animation = null;
|
||||||
|
} else {
|
||||||
|
animation.lastTick = tick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isMouseInside = widget.x < mouseX && widget.x + widget.width > mouseX
|
boolean isMouseInside = widget.x < mouseX && widget.x + widget.width > mouseX
|
||||||
&& widget.y < mouseY && widget.y + widget.height > mouseY;
|
&& widget.y < mouseY && widget.y + widget.height > mouseY;
|
||||||
widget.render(context, isMouseInside, mouseX, mouseY);
|
widget.render(context, isMouseInside, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tick++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class SaturnWidget {
|
|||||||
public int width = 0;
|
public int width = 0;
|
||||||
public int height = 0;
|
public int height = 0;
|
||||||
public float alpha = 1.0f;
|
public float alpha = 1.0f;
|
||||||
public SaturnAnimation animation = null;
|
public SaturnAnimation[] animations = null;
|
||||||
public boolean visible = true;
|
public boolean visible = true;
|
||||||
|
|
||||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||||
@@ -48,10 +48,10 @@ public class SaturnWidget {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaturnWidget setAnimation(SaturnAnimation animation) {
|
public SaturnWidget setAnimations(SaturnAnimation... animations) {
|
||||||
this.animation = animation;
|
this.animations = animations;
|
||||||
if (this.animation == SaturnAnimation.FADE || this.animation == SaturnAnimation.FADE_SLIDE) {
|
for (SaturnAnimation anim : this.animations) {
|
||||||
this.alpha = 0.0f;
|
anim.init(this);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class Textures {
|
|||||||
public static final Identifier MODS_TAB = Identifier.of("saturnclient", "textures/gui/components/mods_tab.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",
|
public static final Identifier SETTINGS_TAB = Identifier.of("saturnclient",
|
||||||
"textures/gui/components/settings_tab.png");
|
"textures/gui/components/settings_tab.png");
|
||||||
public static final Identifier LOGO = Identifier.of("saturnclient", "icon.png");
|
public static final Identifier LOGO = Identifier.of("saturnclient", "textures/logo/logo.png");
|
||||||
public static final Identifier LOGO_TEXT = Identifier.of("saturnclient", "textures/logo/text.png");
|
public static final Identifier LOGO_TEXT = Identifier.of("saturnclient", "textures/logo/text.png");
|
||||||
|
|
||||||
// Widgets
|
// Widgets
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.saturnclient.ui.animations;
|
||||||
|
|
||||||
|
import org.saturnclient.ui.SaturnAnimation;
|
||||||
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
|
|
||||||
|
public class FadeIn extends SaturnAnimation {
|
||||||
|
public FadeIn(int delay) {
|
||||||
|
this.delay = delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(SaturnWidget widget) {
|
||||||
|
widget.alpha = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean run(SaturnWidget widget, int tick) {
|
||||||
|
widget.alpha += 0.05f;
|
||||||
|
|
||||||
|
return widget.alpha > 0.9f;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.saturnclient.ui.animations;
|
||||||
|
|
||||||
|
import org.saturnclient.ui.SaturnAnimation;
|
||||||
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
|
|
||||||
|
public class Slide extends SaturnAnimation {
|
||||||
|
private int offset;
|
||||||
|
|
||||||
|
public Slide(int delay, int offset) {
|
||||||
|
this.delay = delay;
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(SaturnWidget widget) {
|
||||||
|
widget.y += offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean run(SaturnWidget widget, int tick) {
|
||||||
|
widget.y--;
|
||||||
|
offset--;
|
||||||
|
|
||||||
|
return offset == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,8 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||||
|
|
||||||
|
int hoverColor = ((int) (alpha * 255) << 24) | (SaturnClient.COLOR & 0x00FFFFFF);
|
||||||
|
|
||||||
if (background) {
|
if (background) {
|
||||||
RenderSystem.setShaderTexture(0, Textures.BUTTON);
|
RenderSystem.setShaderTexture(0, Textures.BUTTON);
|
||||||
RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||||
@@ -42,7 +44,7 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
|
|
||||||
if (hovering) {
|
if (hovering) {
|
||||||
context.drawGuiTexture(RenderLayer::getGuiTextured, Textures.BUTTON_BORDER, this.x,
|
context.drawGuiTexture(RenderLayer::getGuiTextured, Textures.BUTTON_BORDER, this.x,
|
||||||
this.y, this.width, this.height, SaturnClient.COLOR);
|
this.y, this.width, this.height, hoverColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
context.drawText(minecraftClient.textRenderer, this.text,
|
context.drawText(minecraftClient.textRenderer, this.text,
|
||||||
this.x + ((this.width - minecraftClient.textRenderer.getWidth(this.text)) / 2),
|
this.x + ((this.width - minecraftClient.textRenderer.getWidth(this.text)) / 2),
|
||||||
this.y + ((this.height - minecraftClient.textRenderer.fontHeight + 1) / 2),
|
this.y + ((this.height - minecraftClient.textRenderer.fontHeight + 1) / 2),
|
||||||
hovering ? SaturnClient.COLOR : i | MathHelper.ceil(this.alpha * 255.0F) << 24, false);
|
hovering ? hoverColor : i | MathHelper.ceil(this.alpha * 255.0F) << 24, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -7,10 +7,10 @@ import net.minecraft.client.render.RenderLayer;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.ColorHelper;
|
import net.minecraft.util.math.ColorHelper;
|
||||||
|
|
||||||
public class SaturnTexture extends SaturnWidget {
|
public class SaturnImage extends SaturnWidget {
|
||||||
private final Identifier sprite;
|
private final Identifier sprite;
|
||||||
|
|
||||||
public SaturnTexture(Identifier sprite) {
|
public SaturnImage(Identifier sprite) {
|
||||||
this.sprite = sprite;
|
this.sprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,9 +31,12 @@ public class SaturnImageButton extends SaturnButton {
|
|||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||||
super.render(context, hovering, mouseX, mouseY);
|
super.render(context, hovering, mouseX, mouseY);
|
||||||
|
|
||||||
|
int hoverColor = ((int) (alpha * 255) << 24) | (SaturnClient.COLOR & 0x00FFFFFF);
|
||||||
|
|
||||||
context.drawTexture(RenderLayer::getGuiTextured, sprite, x + (width - imageWidth) / 2,
|
context.drawTexture(RenderLayer::getGuiTextured, sprite, x + (width - imageWidth) / 2,
|
||||||
y + (height - imageHeight) / 2, 0, 0, imageWidth, imageHeight, imageWidth,
|
y + (height - imageHeight) / 2, 0, 0, imageWidth, imageHeight, imageWidth,
|
||||||
imageHeight, hovering ? SaturnClient.COLOR : ColorHelper.getWhite(alpha));
|
imageHeight, hovering ? hoverColor : ColorHelper.getWhite(alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.saturnclient.ui.widgets;
|
||||||
|
|
||||||
|
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 SaturnSprite extends SaturnWidget {
|
||||||
|
private final Identifier sprite;
|
||||||
|
|
||||||
|
public SaturnSprite(Identifier sprite) {
|
||||||
|
this.sprite = sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
|
||||||
|
context.drawTexture(RenderLayer::getGuiTextured, sprite, x, y, 0, 0, width, height, width,
|
||||||
|
height, ColorHelper.getWhite(alpha));
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 874 B |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Reference in New Issue
Block a user