New Lite Main Menu

This commit is contained in:
kirillsaint 2023-08-06 14:00:10 +06:00
parent c8297dbdb9
commit ce02daf2e0

View File

@ -1,408 +1,133 @@
package net.silentclient.client.gui.lite;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.realms.RealmsBridge;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.demo.DemoWorldServer;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.WorldInfo;
import net.silentclient.client.Client;
import net.silentclient.client.cosmetics.gui.CosmeticsGui;
import net.silentclient.client.gui.animation.SimpleAnimation;
import net.silentclient.client.gui.elements.Button;
import net.silentclient.client.gui.elements.IconButton;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.silentmainmenu.MainMenuConcept;
import net.silentclient.client.gui.util.RenderUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GLContext;
import java.io.IOException;
import java.net.URI;
import java.util.Random;
public class LiteMainMenu extends GuiScreen implements GuiYesNoCallback
public class LiteMainMenu extends GuiScreen
{
private static final Logger logger = LogManager.getLogger();
private static final Random RANDOM = new Random();
private SimpleAnimation bannerAnimation;
/** Counts the number of screen updates. */
private float updateCounter;
/** The splash message. */
private String splashText;
private GuiButton buttonResetDemo;
/** Timer used to rotate the panorama, increases every tick. */
/**
* Texture allocated for the current viewport of the main menu's panorama background.
*/
/**
* The Object object utilized as a thread lock when performing non thread-safe operations
*/
private final Object threadLock = new Object();
/** OpenGL graphics card warning. */
private String openGLWarning1;
/** OpenGL graphics card warning. */
private String openGLWarning2;
/** Link to the Mojang Support about minimum requirements */
private String openGLWarningLink;
private static final ResourceLocation minecraftTitleTextures = new ResourceLocation("silentclient/logos/menu_logo.png");
/** An array of all the paths to the panorama pictures. */
public static final String field_96138_a = "Please click " + EnumChatFormatting.UNDERLINE + "here" + EnumChatFormatting.RESET + " for more information.";
private int field_92024_r;
private int field_92023_s;
private int field_92022_t;
private int field_92021_u;
private int field_92020_v;
private int field_92019_w;
private GuiButton singlePlayer;
private GuiButton multiPlayer;
private GuiButton options;
private GuiButton cosmetics;
/** Minecraft Realms button. */
private GuiButton realmsButton;
public LiteMainMenu() {
this.openGLWarning2 = field_96138_a;
this.splashText = "";
this.setUpdateCounter(RANDOM.nextFloat());
this.openGLWarning1 = "";
if (!GLContext.getCapabilities().OpenGL20 && !OpenGlHelper.areShadersSupported())
{
this.openGLWarning1 = I18n.format("title.oldgl1");
this.openGLWarning2 = I18n.format("title.oldgl2");
this.openGLWarningLink = "https://help.mojang.com/customer/portal/articles/325948?ref=game";
}
}
public LiteMainMenu(boolean firstTime)
{
this.openGLWarning2 = field_96138_a;
this.splashText = "";
this.setUpdateCounter(RANDOM.nextFloat());
this.openGLWarning1 = "";
if (!GLContext.getCapabilities().OpenGL20 && !OpenGlHelper.areShadersSupported())
{
this.openGLWarning1 = I18n.format("title.oldgl1");
this.openGLWarning2 = I18n.format("title.oldgl2");
this.openGLWarningLink = "https://help.mojang.com/customer/portal/articles/325948?ref=game";
}
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
Client.backgroundPanorama.tickPanorama();
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
public boolean doesGuiPauseGame()
{
return false;
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
int j = this.height / 4 + 48;
@Override
public void initGui() {
super.initGui();
this.bannerAnimation = new SimpleAnimation(0);
Client.backgroundPanorama.updateWidthHeight(this.width, this.height);
this.buttonList.add(new IconButton(88, 4, 5, new ResourceLocation("silentclient/icons/news.png")));
this.buttonList.add(cosmetics = new IconButton(87, 26, 5, new ResourceLocation("silentclient/icons/settings/cosmetics.png")));
this.buttonList.add(new IconButton(991, 48, 5, new ResourceLocation("silentclient/icons/store_icon.png")));
this.buttonList.add(new IconButton(992, 70, 5, new ResourceLocation("silentclient/icons/language.png")));
this.buttonList.add(new IconButton(89, 92, 5, new ResourceLocation("silentclient/icons/back.png")));
if (this.mc.isDemo())
{
this.addDemoButtons(j, 24);
}
else
{
this.addSingleplayerMultiplayerButtons(j, 24);
}
this.buttonList.add(options = new Button(0, this.width / 2 - 100, j + 52, 98, 20, "Options"));
this.buttonList.add(new Button(4, this.width / 2 + 2, j + 52, 98, 20, "Quit Game"));
this.buttonList.clear();
this.buttonList.add(new IconButton(1, 4, 5, new ResourceLocation("silentclient/icons/news.png")));
this.buttonList.add(new IconButton(2, 26, 5, new ResourceLocation("silentclient/icons/settings/cosmetics.png")));
this.buttonList.add(new IconButton(3, 48, 5, new ResourceLocation("silentclient/icons/store_icon.png")));
this.buttonList.add(new IconButton(4, 70, 5, new ResourceLocation("silentclient/icons/language.png")));
this.buttonList.add(new IconButton(5, 92, 5, new ResourceLocation("silentclient/icons/back.png")));
synchronized (this.threadLock)
{
this.field_92023_s = this.fontRendererObj.getStringWidth(this.openGLWarning1);
this.field_92024_r = this.fontRendererObj.getStringWidth(this.openGLWarning2);
int k = Math.max(this.field_92023_s, this.field_92024_r);
this.field_92022_t = (this.width - k) / 2;
this.field_92021_u = ((GuiButton)this.buttonList.get(0)).yPosition - 24;
this.field_92020_v = this.field_92022_t + k;
this.field_92019_w = this.field_92021_u + 24;
}
this.buttonList.add(new Button(6, this.width / 2 - 90, this.height / 2 - 18, 180, 18, "Singleplayer"));
this.buttonList.add(new Button(7, this.width / 2 - 90, this.height / 2 + 5, 180, 18, "Multiplayer"));
this.mc.setConnectedToRealms(false);
this.buttonList.add(new Button(8, this.width / 2 - 90, this.height / 2 + 28, 87, 18, "Options"));
this.buttonList.add(new Button(9, this.width / 2 + 2, this.height / 2 + 28, 88, 18, "Quit Game"));
}
/**
* Adds Singleplayer and Multiplayer buttons on Main Menu for players who have bought the game.
*/
private void addSingleplayerMultiplayerButtons(int p_73969_1_, int p_73969_2_)
{
this.buttonList.add(singlePlayer = new Button(1, this.width / 2 - 100, p_73969_1_, "Singleplayer"));
this.buttonList.add(multiPlayer = new Button(2, this.width / 2 - 100, p_73969_1_ + p_73969_2_ * 1, "Multiplayer"));
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
GuiNews.loadPanel();
GlStateManager.disableAlpha();
Client.backgroundPanorama.renderSkybox(mouseX, mouseY, partialTicks);
GlStateManager.enableAlpha();
this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
/**
* Adds Demo buttons on Main Menu for players who are playing Demo.
*/
private void addDemoButtons(int p_73972_1_, int p_73972_2_)
{
this.buttonList.add(new Button(11, this.width / 2 - 100, p_73972_1_, I18n.format("menu.playdemo", new Object[0])));
this.buttonList.add(this.buttonResetDemo = new Button(12, this.width / 2 - 100, p_73972_1_ + p_73972_2_ * 1, I18n.format("menu.resetdemo", new Object[0])));
ISaveFormat isaveformat = this.mc.getSaveLoader();
WorldInfo worldinfo = isaveformat.getWorldInfo("Demo_World");
RenderUtil.drawImage(new ResourceLocation("silentclient/logos/menu_logo.png"), this.width / 2 - 80, 20, 160, 70);
if (worldinfo == null)
{
this.buttonResetDemo.enabled = false;
}
}
Client.getInstance().getSilentFontRenderer().drawString(3, height - 14, "SLC Lite 1.8.9", 12, SilentFontRenderer.FontType.TITLE);
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if(button.id == 991) {
try {
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI("https://store.silentclient.net/")});
} catch (Throwable err) {
err.printStackTrace();
if(GuiNews.imageLocation != null) {
if(MouseUtils.isInside(mouseX, mouseY, this.width - 74, this.height - 42, 71, 40)) {
this.bannerAnimation.setAnimation(4, 12);
} else {
this.bannerAnimation.setAnimation(0, 12);
}
return;
RenderUtil.drawImage(GuiNews.imageLocation, this.width - 74 + (-this.bannerAnimation.getValue()), this.height - 42 + (-this.bannerAnimation.getValue()), 71, 40, false);
}
if(button.id == 992) {
mc.displayGuiScreen(new GuiLanguage(this, new GameSettings(), mc.getLanguageManager()));
return;
}
if (button.id == 0)
{
this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
}
if (button.id == 5)
{
this.mc.displayGuiScreen(new GuiLanguage(this, this.mc.gameSettings, this.mc.getLanguageManager()));
}
if (button.id == 1)
{
this.mc.displayGuiScreen(new GuiSelectWorld(this));
}
if (button.id == 2)
{
this.mc.displayGuiScreen(new GuiMultiplayer(this));
}
if(button.id == 89) {
Client.getInstance().getGlobalSettings().setLite(false);
Client.getInstance().getGlobalSettings().save();
mc.displayGuiScreen(new MainMenuConcept());
}
if (button.id == 14 && this.realmsButton.visible)
{
this.switchToRealms();
}
if (button.id == 4)
{
this.mc.shutdown();
}
if (button.id == 11)
{
this.mc.launchIntegratedServer("Demo_World", "Demo_World", DemoWorldServer.demoWorldSettings);
}
if (button.id == 12)
{
ISaveFormat isaveformat = this.mc.getSaveLoader();
WorldInfo worldinfo = isaveformat.getWorldInfo("Demo_World");
if (worldinfo != null)
{
GuiYesNo guiyesno = GuiSelectWorld.makeDeleteWorldYesNo(this, worldinfo.getWorldName(), 12);
this.mc.displayGuiScreen(guiyesno);
}
}
if(button.id == 87) {
this.mc.displayGuiScreen(new CosmeticsGui());
}
if(button.id == 88) {
this.mc.displayGuiScreen(new GuiNews());
}
}
private void switchToRealms()
{
RealmsBridge realmsbridge = new RealmsBridge();
realmsbridge.switchToRealms(this);
}
public void confirmClicked(boolean result, int id)
{
if (result && id == 12)
{
ISaveFormat isaveformat = this.mc.getSaveLoader();
isaveformat.flushCache();
isaveformat.deleteWorldDirectory("Demo_World");
this.mc.displayGuiScreen(this);
}
else if (id == 13)
{
if (result)
{
try
{
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI(this.openGLWarningLink)});
}
catch (Throwable throwable)
{
logger.error("Couldn\'t open link", throwable);
}
}
this.mc.displayGuiScreen(this);
}
}
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
GlStateManager.disableAlpha();
Client.backgroundPanorama.renderSkybox(mouseX, mouseY, partialTicks);
GlStateManager.enableAlpha();
Tessellator tessellator = Tessellator.getInstance();
tessellator.getWorldRenderer();
int i = 274;
int j = this.width / 2 - i / 2;
int k = 30;
this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
singlePlayer.visible = true;
multiPlayer.visible = true;
options.visible = true;
cosmetics.visible = true;
RenderUtil.drawImage(minecraftTitleTextures, j + 30, k - 25, 220, 95);
GlStateManager.pushMatrix();
GlStateManager.translate((float)(this.width / 2 + 90), 70.0F, 0.0F);
GlStateManager.rotate(-20.0F, 0.0F, 0.0F, 1.0F);
float f = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F);
f = f * 100.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32);
GlStateManager.scale(f, f, f);
GlStateManager.popMatrix();
String s = "SC Lite 1.8.9";
if (this.mc.isDemo())
{
s = s + " Demo";
}
Client.getInstance().getSilentFontRenderer().drawString(s, 2, this.height - 14, 14, SilentFontRenderer.FontType.TITLE);
if(GuiNews.imageLocation != null) {
RenderUtil.drawImage(new ResourceLocation(Client.getInstance().getAccount().discord_id != null ? GuiNews.imageLocation.getResourcePath() : "silentclient/images/discord.png"), this.width - 73, this.height - 42, 71, 40, false);
}
if (this.openGLWarning1 != null && this.openGLWarning1.length() > 0)
{
drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512);
this.drawString(this.fontRendererObj, this.openGLWarning1, this.field_92022_t, this.field_92021_u, -1);
this.drawString(this.fontRendererObj, this.openGLWarning2, (this.width - this.field_92024_r) / 2, ((GuiButton)this.buttonList.get(0)).yPosition - 12, -1);
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
if(MouseUtils.isInside(mouseX, mouseY, this.width - 73, this.height - 42, 71, 40) && GuiNews.news != null) {
try {
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI(Client.getInstance().getAccount().discord_id != null ? "https://silentclient.net/news/" + + GuiNews.news.getItem().id : "https://silentclient.net/news/4")});
} catch (Throwable err) {
err.printStackTrace();
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
super.actionPerformed(button);
switch (button.id) {
case 1:
mc.displayGuiScreen(new GuiNews());
break;
case 2:
mc.displayGuiScreen(new CosmeticsGui());
break;
case 3:
try {
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI("https://store.silentclient.net/")});
} catch (Throwable err) {
err.printStackTrace();
}
break;
case 4:
mc.displayGuiScreen(new GuiLanguage(this, mc.gameSettings, mc.getLanguageManager()));
break;
case 5:
Client.getInstance().getGlobalSettings().setLite(false);
Client.getInstance().getGlobalSettings().save();
mc.displayGuiScreen(new MainMenuConcept());
break;
case 6:
mc.displayGuiScreen(new GuiSelectWorld(this));
break;
case 7:
mc.displayGuiScreen(new GuiMultiplayer(this));
break;
case 8:
mc.displayGuiScreen(new GuiOptions( this, mc.gameSettings));
break;
case 9:
mc.shutdown();
break;
}
}
synchronized (this.threadLock)
{
if (this.openGLWarning1.length() > 0 && mouseX >= this.field_92022_t && mouseX <= this.field_92020_v && mouseY >= this.field_92021_u && mouseY <= this.field_92019_w)
{
GuiConfirmOpenLink guiconfirmopenlink = new GuiConfirmOpenLink(this, this.openGLWarningLink, 13, true);
guiconfirmopenlink.disableSecurityWarning();
this.mc.displayGuiScreen(guiconfirmopenlink);
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
if(MouseUtils.isInside(mouseX, mouseY, this.width - 74, this.height - 42, 71, 40)) {
try {
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI("https://silentclient.net/news/" + GuiNews.news.getItem().id)});
} catch (Throwable err) {
err.printStackTrace();
}
}
}
public float getUpdateCounter() {
return updateCounter;
}
@Override
public void updateScreen() {
super.updateScreen();
Client.backgroundPanorama.tickPanorama();
}
public void setUpdateCounter(float updateCounter) {
this.updateCounter = updateCounter;
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
}