package im.expensive.ui.mainmenu;
import com.mojang.blaze3d.matrix.MatrixStack;
import im.expensive.Expensive;
import im.expensive.utils.client.IMinecraft;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.font.Fonts;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.MultiplayerScreen;
import net.minecraft.client.gui.screen.OptionsScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.WorldSelectionScreen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import java.util.ArrayList;
import java.util.List;
public class MainScreen extends Screen implements IMinecraft {
private final ResourceLocation logo = new ResourceLocation("expensive/images/log.png");
private final List<Button> buttons = new ArrayList<>();
private final float NAV_OFFSET = 75f;
private final float NAV_GAP = 80f;
public MainScreen() {
super(ITextComponent.getTextComponentOrEmpty(""));
}
@Override
protected void init() {
buttons.clear();
float btnWidth = 230f;
float btnHeight = 30f;
float spacing = 8f;
float centerX = width / 2f - btnWidth / 2f;
float startY = height / 2f - 45;
buttons.add(new Button(centerX, startY, btnWidth, btnHeight, "Singleplayer", () -> mc.displayGuiScreen(new WorldSelectionScreen(this)), false));
buttons.add(new Button(centerX, startY + btnHeight + spacing, btnWidth, btnHeight, "Multiplayer", () -> mc.displayGuiScreen(new MultiplayerScreen(this)), false));
buttons.add(new Button(centerX, startY + (btnHeight + spacing) * 2 + 2, btnWidth, btnHeight, "Swap Accounts", () -> {
Expensive.getInstance().getAltWidget().open = true;
}, true));
}
@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
DisplayUtils.drawRect(0, 0, width, height, ColorUtils.rgb(10, 11, 14));
float centerX = width / 2f;
float centerY = height / 2f;
drawPlayerInfo(matrixStack);
float logoSize = 22;
DisplayUtils.drawImage(logo, centerX - logoSize / 2f, centerY - 115, logoSize, logoSize, -1);
String name = mc.getSession().getUsername();
Fonts.inter_wex.drawCenteredText(matrixStack, "Good time of day, " + name, centerX, centerY - 85, ColorUtils.rgb(210, 210, 215), 9.5f);
Fonts.inter_wex.drawCenteredText(matrixStack, "Welcome to Fallen, the best Minecraft client.", centerX, centerY - 72, ColorUtils.rgb(130, 131, 135), 7.5f);
buttons.forEach(btn -> btn.render(matrixStack, mouseX, mouseY));
renderNav(matrixStack, mouseX, mouseY, centerY + NAV_OFFSET);
float footerY = height - 25;
Fonts.inter_wex.drawCenteredText(matrixStack, "By logging into your account you agree to all of our policies,", centerX, footerY, ColorUtils.rgb(55, 56, 60), 6f);
Fonts.inter_wex.drawCenteredText(matrixStack, "including our Privacy Policy and Terms of Service", centerX, footerY + 9, ColorUtils.rgb(55, 56, 60), 6f);
if (Expensive.getInstance().getAltWidget().open) {
Expensive.getInstance().getAltWidget().render(matrixStack, mouseX, mouseY);
}
super.render(matrixStack, mouseX, mouseY, partialTicks);
}
@Override
public boolean charTyped(char codePoint, int modifiers) {
if (Expensive.getInstance().getAltWidget().open) {
Expensive.getInstance().getAltWidget().onChar(codePoint);
return true;
}
return super.charTyped(codePoint, modifiers);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (Expensive.getInstance().getAltWidget().open) {
if (keyCode == 256) {
Expensive.getInstance().getAltWidget().open = false;
return true;
}
Expensive.getInstance().getAltWidget().onKey(keyCode);
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (Expensive.getInstance().getAltWidget().open) {
Expensive.getInstance().getAltWidget().click((int) mouseX, (int) mouseY, button);
return true;
}
buttons.forEach(btn -> btn.click((int) mouseX, (int) mouseY));
float yNav = height / 2f + NAV_OFFSET;
if (mouseY > yNav - 6 && mouseY < yNav + 6) {
if (Math.abs(mouseX - (width / 2f - NAV_GAP)) < 30) mc.displayGuiScreen(new OptionsScreen(this, mc.gameSettings));
if (Math.abs(mouseX - (width / 2f + NAV_GAP)) < 30) mc.shutdown();
}
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
if (Expensive.getInstance().getAltWidget().open) {
Expensive.getInstance().getAltWidget().handleMouseScroll(delta);
return true;
}
return super.mouseScrolled(mouseX, mouseY, delta);
}
private void drawPlayerInfo(MatrixStack stack) {
float x = 12, y = 12, size = 18, round = 4;
ResourceLocation skin = mc.player != null ? mc.player.getLocationSkin() :
net.minecraft.client.resources.DefaultPlayerSkin.getDefaultSkin(mc.getSession().getProfile().getId());
im.expensive.utils.render.Stencil.initStencilToWrite();
DisplayUtils.drawRoundedRect(x, y, size, size, round, -1);
im.expensive.utils.render.Stencil.readStencilBuffer(1);
mc.getTextureManager().bindTexture(skin);
AbstractGui.blit(stack, (int)x, (int)y, (int)size, (int)size, 8, 8, 8, 8, 64, 64);
AbstractGui.blit(stack, (int)x, (int)y, (int)size, (int)size, 40, 8, 8, 8, 64, 64);
im.expensive.utils.render.Stencil.uninitStencilBuffer();
float textX = x + size + 6;
Fonts.inter_wex.drawText(stack, "Logged in as", textX, y + 1, ColorUtils.rgb(130, 131, 135), 5.5f);
Fonts.inter_wex.drawText(stack, mc.getSession().getUsername(), textX, y + 9, -1, 7.5f);
}
private void renderNav(MatrixStack stack, int mx, int my, float y) {
String[] labels = {"Options", "Proxies", "Exit"};
float startX = width / 2f - NAV_GAP;
for (int i = 0; i < labels.length; i++) {
float x = startX + (i * NAV_GAP);
boolean hovered = mx > x - 25 && mx < x + 25 && my > y - 6 && my < y + 6;
int color = hovered ? -1 : ColorUtils.rgb(90, 92, 98);
Fonts.inter_wex.drawCenteredText(stack, labels[i], x, y, color, 8f);
}
}
private class Button {
float x, y, w, h;
String text;
Runnable action;
boolean orange;
public Button(float x, float y, float w, float h, String text, Runnable action, boolean orange) {
this.x = x; this.y = y; this.w = w; this.h = h;
this.text = text; this.action = action; this.orange = orange;
}
public void render(MatrixStack stack, int mx, int my) {
boolean hovered = mx > x && mx < x + w && my > y && my < y + h;
int color = orange ? ColorUtils.rgb(212, 95, 12) : ColorUtils.rgb(20, 23, 29);
if (hovered) color = orange ? ColorUtils.rgb(235, 105, 15) : ColorUtils.rgb(28, 31, 38);
DisplayUtils.drawRoundedRect(x, y, w, h, 10f, color);
int txtColor = orange ? -1 : ColorUtils.rgb(150, 152, 158);
if (hovered && !orange) txtColor = -1;
Fonts.inter_wex.drawCenteredText(stack, text, x + w / 2f, y + h / 2f - 3.5f, txtColor, 7.5f);
}
public void click(int mx, int my) {
if (mx > x && mx < x + w && my > y && my < y + h) action.run();
}
}
}