Custom Multiplayer Screen 40%

This commit is contained in:
kirillsaint 2023-08-26 13:33:13 +06:00
parent 037a325799
commit cc9608f99b
6 changed files with 544 additions and 0 deletions

View File

@ -91,6 +91,7 @@ public class GuiConnecting extends SilentScreen
}
catch (UnknownHostException unknownhostexception)
{
Client.logger.catching(unknownhostexception);
if (GuiConnecting.this.cancel)
{
return;
@ -101,6 +102,7 @@ public class GuiConnecting extends SilentScreen
}
catch (Exception exception)
{
Client.logger.catching(exception);
if (GuiConnecting.this.cancel)
{
return;

View File

@ -0,0 +1,279 @@
package net.silentclient.client.gui.multiplayer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.ServerList;
import net.minecraft.client.network.OldServerPinger;
import net.minecraft.client.renderer.GlStateManager;
import net.silentclient.client.Client;
import net.silentclient.client.gui.SilentScreen;
import net.silentclient.client.gui.animation.SimpleAnimation;
import net.silentclient.client.gui.elements.Button;
import net.silentclient.client.gui.elements.Input;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.minecraft.GuiConnecting;
import net.silentclient.client.gui.multiplayer.components.ServerComponent;
import net.silentclient.client.gui.theme.Theme;
import net.silentclient.client.utils.MouseCursorHandler;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
public class SilentMultiplayerGui extends SilentScreen {
private final OldServerPinger oldServerPinger = new OldServerPinger();
private int blockX = 0;
private int blockY = 0;
private int blockWidth = 0;
private int blockHeight = 0;
private GuiScreen parentScreen;
private ServerList savedServerList;
private Button btnEditServer;
private Button btnSelectServer;
private Button btnDeleteServer;
private boolean initialized;
private ArrayList<ServerComponent> servers = new ArrayList<>();
private SimpleAnimation scrollAnimation = new SimpleAnimation(0.0F);
private float scrollY = 0;
private int selectedServer = -1;
public SilentMultiplayerGui(GuiScreen parentScreen) {
this.parentScreen = parentScreen;
}
@Override
public void initGui() {
super.initGui();
defaultCursor = false;
Client.backgroundPanorama.updateWidthHeight(this.width, this.height);
blockWidth = 250;
blockHeight = height - 20;
blockX = (width / 2) - (blockWidth / 2);
blockY = 10;
if (!this.initialized) {
this.initialized = true;
this.savedServerList = new ServerList(this.mc);
this.savedServerList.loadServerList();
servers.clear();
for (int i = 0; i < savedServerList.countServers(); ++i)
{
ServerData serverData = savedServerList.getServerData(i);
servers.add(new ServerComponent(this, serverData));
}
}
this.silentInputs.clear();
this.buttonList.clear();
this.silentInputs.add(new Input("Search", ""));
this.createButtons();
}
public void createButtons()
{
this.buttonList.add(this.btnSelectServer = new Button(1, blockX + 5, blockY + blockHeight - 39, 77, 14, "Join Server"));
this.buttonList.add(new Button(4, blockX + 5 + 5 + 77, blockY + blockHeight - 39, 77, 14, "Direct Connect"));
this.buttonList.add(new Button(3, blockX + 5 + 5 + 77 + 5 + 77, blockY + blockHeight - 39, 77, 14, "Add Server"));
this.buttonList.add(this.btnEditServer = new Button(7, blockX + 5, blockY + blockHeight - 20, 56, 14, "Edit"));
this.buttonList.add(this.btnDeleteServer = new Button(2, blockX + 5 + 56 + 6, blockY + blockHeight - 20, 56, 14, "Delete"));
this.buttonList.add(new Button(8, blockX + 5 + 56 + 6 + 56 + 6, blockY + blockHeight - 20, 56, 14, "Refresh"));
this.buttonList.add(new Button(0, blockX + 5 + 56 + 6 + 56 + 6 + 56 + 5, blockY + blockHeight - 20, 56, 14, "Cancel"));
this.selectServer(-1);
}
public void selectServer(int index)
{
Client.logger.info("Selecting server " + index);
this.selectedServer = index;
this.btnSelectServer.enabled = false;
this.btnEditServer.enabled = false;
this.btnDeleteServer.enabled = false;
if(index != -1) {
ServerComponent serverComponent = this.servers.get(index);
if(serverComponent != null) {
this.btnSelectServer.enabled = true;
this.btnEditServer.enabled = true;
this.btnDeleteServer.enabled = true;
} else {
Client.logger.info("Server " + index + " not found!");
}
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
MouseCursorHandler.CursorType cursorType = getCursor(silentInputs, buttonList);
GlStateManager.disableAlpha();
Client.backgroundPanorama.renderSkybox(mouseX, mouseY, partialTicks);
GlStateManager.enableAlpha();
if(Client.getInstance().getGlobalSettings().isLite()) {
this.drawGradientRect(0, 0, this.width, this.height, new Color(0, 0, 0, 127).getRGB(), new Color(0, 0, 0, 200).getRGB());
} else {
this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
}
RenderUtils.drawRect(blockX, blockY, blockWidth, blockHeight, Theme.backgroundColor().getRGB());
Client.getInstance().getSilentFontRenderer().drawCenteredString("Play Multiplayer", blockX + blockWidth / 2, blockY + 3, 16, SilentFontRenderer.FontType.TITLE);
this.silentInputs.get(0).render(mouseX, mouseY, blockX + 5, blockY + 3 + 16 + 5, blockWidth - 10, true);
float serverY = blockY + 43 - scrollAnimation.getValue();
trimContentStart();
int serverIndex = -1;
for (ServerComponent serverComponent : servers)
{
serverIndex += 1;
if((!this.silentInputs.get(0).getValue().trim().equals("") && !serverComponent.getServer().serverName.toLowerCase().contains(this.silentInputs.get(0).getValue().trim().toLowerCase()) && !serverComponent.getServer().serverIP.toLowerCase().contains(this.silentInputs.get(0).getValue().trim().toLowerCase()))) {
continue;
}
if(MouseUtils.isInside(blockX + 5, (int) serverY, blockX + 5, blockY + 43, blockWidth - 10, blockHeight - 43 - 39) || MouseUtils.isInside(blockX + 5, (int) serverY + 38, blockX + 5, blockY + 43, blockWidth - 10, blockHeight - 43 - 39)) {
MouseCursorHandler.CursorType cursor = serverComponent.draw(mouseX, mouseY, blockX + 5, serverY, serverIndex == selectedServer);
if(cursor != null) {
cursorType = cursor;
}
}
serverY += 38;
}
trimContentEnd();
super.drawScreen(mouseX, mouseY, partialTicks);
Client.getInstance().getMouseCursorHandler().enableCursor(cursorType);
scrollAnimation.setAnimation(scrollY, 12);
}
public void connectToSelected() {
ServerData server = savedServerList.getServerData(selectedServer);
if(server != null) {
this.mc.displayGuiScreen(new GuiConnecting(this, this.mc, new ServerData(server.serverName, server.serverIP, false)));
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
super.actionPerformed(button);
switch (button.id) {
case 0:
mc.displayGuiScreen(parentScreen);
break;
case 1:
this.connectToSelected();
break;
case 2:
if(this.selectedServer != -1) {
this.savedServerList.removeServerData(this.selectedServer);
this.savedServerList.saveServerList();
this.selectServer(-1);
this.refreshServerList();
}
break;
case 8:
this.refreshServerList();
break;
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
this.silentInputs.get(0).onClick(mouseX, mouseY, blockX + 5, blockY + 3 + 16 + 5, blockWidth - 10, true);
float serverY = blockY + 43 - scrollAnimation.getValue();
int serverIndex = -1;
boolean isReset = true;
for (ServerComponent serverComponent : servers)
{
serverIndex += 1;
if((!this.silentInputs.get(0).getValue().trim().equals("") && !serverComponent.getServer().serverName.toLowerCase().contains(this.silentInputs.get(0).getValue().trim().toLowerCase()) && !serverComponent.getServer().serverIP.toLowerCase().contains(this.silentInputs.get(0).getValue().trim().toLowerCase()))) {
continue;
}
if((MouseUtils.isInside(blockX + 5, (int) serverY, blockX + 5, blockY + 43, blockWidth - 10, blockHeight - 43 - 39) || MouseUtils.isInside(blockX + 5, (int) serverY + 38, blockX + 5, blockY + 43, blockWidth - 10, blockHeight - 43 - 39)) && isReset) {
isReset = !serverComponent.mouseClicked(serverIndex, mouseX, mouseY, blockX + 5, serverY, serverIndex == selectedServer);
}
serverY += 38;
}
if(isReset) {
this.selectServer(-1);
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
super.keyTyped(typedChar, keyCode);
this.silentInputs.get(0).onKeyTyped(typedChar, keyCode);
}
@Override
public void updateScreen() {
super.updateScreen();
Client.backgroundPanorama.tickPanorama();
}
public void trimContentStart() {
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_SCISSOR_TEST);
ScaledResolution r = new ScaledResolution(Minecraft.getMinecraft());
int s = r.getScaleFactor();
int listHeight = blockHeight - 43 - 39;
int translatedY = r.getScaledHeight() - blockY - 43 - listHeight;
GL11.glScissor(0 * s, translatedY * s, width * s, listHeight * s);
}
public static void trimContentEnd() {
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GL11.glPopMatrix();
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
int dw = Mouse.getEventDWheel();
double newScrollY = this.scrollY;
if(dw != 0) {
if (dw > 0) {
dw = -1;
} else {
dw = 1;
}
float amountScrolled = (float) (dw * 10);
if (newScrollY + amountScrolled > 0)
newScrollY += amountScrolled;
else
newScrollY = 0;
if((newScrollY < blockHeight && (servers.size() * 38) > blockHeight - 39) || amountScrolled < 0) {
this.scrollY = (float) newScrollY;
if(this.scrollY < 0) {
this.scrollY = 0;
}
}
}
}
private void refreshServerList()
{
this.mc.displayGuiScreen(new SilentMultiplayerGui(this.parentScreen));
}
public OldServerPinger getOldServerPinger() {
return oldServerPinger;
}
public ServerList getServerList() {
return savedServerList;
}
}

View File

@ -0,0 +1,252 @@
package net.silentclient.client.gui.multiplayer.components;
import com.google.common.base.Charsets;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.base64.Base64;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.silentclient.client.Client;
import net.silentclient.client.gui.font.SilentFontRenderer;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui;
import net.silentclient.client.gui.theme.Theme;
import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.utils.MouseCursorHandler;
import org.apache.commons.lang3.Validate;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
public class ServerComponent {
private static final ThreadPoolExecutor field_148302_b = new ScheduledThreadPoolExecutor(5, (new ThreadFactoryBuilder()).setNameFormat("Server Pinger #%d").setDaemon(true).build());
private static final ResourceLocation UNKNOWN_SERVER = new ResourceLocation("textures/misc/unknown_server.png");
private static final ResourceLocation SERVER_SELECTION_BUTTONS = new ResourceLocation("textures/gui/server_selection.png");
private final SilentMultiplayerGui owner;
private final Minecraft mc;
private final ServerData server;
private final ResourceLocation serverIcon;
private String field_148299_g;
private DynamicTexture field_148305_h;
private long field_148298_f;
public ServerComponent(SilentMultiplayerGui p_i45048_1_, ServerData serverIn)
{
this.owner = p_i45048_1_;
this.server = serverIn;
this.mc = Minecraft.getMinecraft();
this.serverIcon = new ResourceLocation("servers/" + serverIn.serverIP + "/icon");
this.field_148305_h = (DynamicTexture)this.mc.getTextureManager().getTexture(this.serverIcon);
}
public MouseCursorHandler.CursorType draw(int mouseX, int mouseY, float x, float y, boolean isSelected) {
MouseCursorHandler.CursorType cursorType = null;
if (!this.server.field_78841_f)
{
this.server.field_78841_f = true;
this.server.pingToServer = -2L;
this.server.serverMOTD = "";
this.server.populationInfo = "";
field_148302_b.submit(new Runnable()
{
public void run()
{
try
{
ServerComponent.this.owner.getOldServerPinger().ping(ServerComponent.this.server);
}
catch (UnknownHostException var2)
{
ServerComponent.this.server.pingToServer = -1L;
ServerComponent.this.server.serverMOTD = EnumChatFormatting.DARK_RED + "Can\'t resolve hostname";
}
catch (Exception var3)
{
ServerComponent.this.server.pingToServer = -1L;
ServerComponent.this.server.serverMOTD = EnumChatFormatting.DARK_RED + "Can\'t connect to server.";
}
}
});
}
boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, y, 240, 35);
RenderUtil.drawRoundedOutline(x, y, 240, 35, 3, 1, Theme.borderColor().getRGB());
if(isHovered || isSelected) {
RenderUtil.drawRoundedRect(x, y, 240, 35, 3, new Color(255, 255, 255, 30).getRGB());
if(isHovered) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
}
if (this.server.getBase64EncodedIconData() != null && !this.server.getBase64EncodedIconData().equals(this.field_148299_g))
{
this.field_148299_g = this.server.getBase64EncodedIconData();
this.prepareServerIcon();
this.owner.getServerList().saveServerList();
}
RenderUtil.drawImage(this.field_148305_h != null ? serverIcon : UNKNOWN_SERVER, x + 2, y + 2, 31, 31, false);
mc.fontRendererObj.drawString(server.serverName, x + 2 + 31 + 3, (int) y + 3, -1, true);
List<String> list = this.mc.fontRendererObj.listFormattedStringToWidth(this.server.serverMOTD, 240 - 36);
for (int i = 0; i < Math.min(list.size(), 2); ++i)
{
this.mc.fontRendererObj.drawString((String)list.get(i), (int) x + 2 + 31 + 3, (int) y + 5 + this.mc.fontRendererObj.FONT_HEIGHT * (i + 1), -1);
}
boolean flag = this.server.version > 47;
boolean flag1 = this.server.version < 47;
boolean flag2 = flag || flag1;
String s2 = flag2 ? EnumChatFormatting.DARK_RED + this.server.gameVersion : this.server.populationInfo;
int j = this.mc.fontRendererObj.getStringWidth(s2);
this.mc.fontRendererObj.drawString(s2, (int) x + 240 - j - 15 - 2, (int) y + 3, -1);
int k = 0;
String s = null;
int l;
String s1;
if (flag2)
{
l = 5;
s1 = flag ? "Client out of date!" : "Server out of date!";
s = this.server.playerList;
}
else if (this.server.field_78841_f && this.server.pingToServer != -2L)
{
if (this.server.pingToServer < 0L)
{
l = 5;
}
else if (this.server.pingToServer < 150L)
{
l = 0;
}
else if (this.server.pingToServer < 300L)
{
l = 1;
}
else if (this.server.pingToServer < 600L)
{
l = 2;
}
else if (this.server.pingToServer < 1000L)
{
l = 3;
}
else
{
l = 4;
}
if (this.server.pingToServer < 0L)
{
s1 = "(no connection)";
}
else
{
s1 = this.server.pingToServer + "ms";
s = this.server.playerList;
}
}
else
{
k = 1;
l = (int)(Minecraft.getSystemTime() / 100L + (long)(1 * 2) & 7L);
if (l > 4)
{
l = 8 - l;
}
s1 = "Pinging...";
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Gui.icons);
Gui.drawModalRectWithCustomSizedTexture((int) x + 240 - 15, (int) y + 2, (float)(k * 10), (float)(176 + l * 8), 10, 8, 256.0F, 256.0F);
if(MouseUtils.isInside(mouseX, mouseY, x + 240 - 15, y + 2, 10, 8)) {
float toastWidth = Client.getInstance().getSilentFontRenderer().getStringWidth(s1, 10, SilentFontRenderer.FontType.TITLE) + 4;
float toastX = x + 240 - 15 + (10 / 2) - (toastWidth / 2);
RenderUtils.drawRect(toastX, y + 2 + 10 + 1, toastWidth, 14, Theme.backgroundColor().getRGB());
Client.getInstance().getSilentFontRenderer().drawString(s1, toastX + 2, y + 2 + 10 + 1 + 2, 10, SilentFontRenderer.FontType.TITLE);
}
return cursorType;
}
public boolean mouseClicked(int serverIndex, int mouseX, int mouseY, float x, float y, boolean isSelected) {
boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, y, 240, 35);
if(isHovered) {
Client.logger.info("Hey!");
if(!isSelected) {
this.owner.selectServer(serverIndex);
} else {
this.owner.connectToSelected();
}
}
return isHovered;
}
private void prepareServerIcon()
{
if (this.server.getBase64EncodedIconData() == null)
{
this.mc.getTextureManager().deleteTexture(this.serverIcon);
this.field_148305_h = null;
}
else
{
ByteBuf bytebuf = Unpooled.copiedBuffer((CharSequence)this.server.getBase64EncodedIconData(), Charsets.UTF_8);
ByteBuf bytebuf1 = Base64.decode(bytebuf);
BufferedImage bufferedimage;
label101:
{
try
{
bufferedimage = TextureUtil.readBufferedImage(new ByteBufInputStream(bytebuf1));
Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
break label101;
}
catch (Throwable throwable)
{
Client.logger.error("Invalid icon for server " + this.server.serverName + " (" + this.server.serverIP + ")", throwable);
this.server.setBase64EncodedIconData((String)null);
}
finally
{
bytebuf.release();
bytebuf1.release();
}
return;
}
if (this.field_148305_h == null)
{
this.field_148305_h = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
this.mc.getTextureManager().loadTexture(this.serverIcon, this.field_148305_h);
}
bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.field_148305_h.getTextureData(), 0, bufferedimage.getWidth());
this.field_148305_h.updateDynamicTexture();
}
}
public ServerData getServer() {
return server;
}
}

View File

@ -2,6 +2,7 @@ package net.silentclient.client.mixin.ducks;
public interface GuiMultiplayerExt {
void silent$setParentScreen(Object a);
Object silent$getParentScreen();
void silent$setDirectConnect(boolean a);
void silent$setSelectedServer(Object a);
Object silent$getSelectedServer();

View File

@ -34,6 +34,11 @@ public abstract class GuiMultiplayerMixin extends GuiScreen implements GuiMultip
this.parentScreen = (GuiScreen) a;
}
@Override
public Object silent$getParentScreen() {
return this.parentScreen;
}
@Override
public void silent$setDirectConnect(boolean a) {
this.directConnect = a;

View File

@ -21,9 +21,11 @@ import net.minecraft.world.WorldSettings;
import net.silentclient.client.Client;
import net.silentclient.client.event.impl.*;
import net.silentclient.client.gui.lite.LiteMainMenu;
import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui;
import net.silentclient.client.gui.silentmainmenu.MainMenuConcept;
import net.silentclient.client.gui.util.BackgroundPanorama;
import net.silentclient.client.hooks.MinecraftHook;
import net.silentclient.client.mixin.ducks.GuiMultiplayerExt;
import net.silentclient.client.mixin.ducks.MinecraftExt;
import net.silentclient.client.mods.player.ZoomMod;
import net.silentclient.client.mods.render.AnimationsMod;
@ -142,6 +144,9 @@ public abstract class MinecraftMixin implements MinecraftExt {
}
return;
}
if(guiScreenIn instanceof GuiMultiplayer) {
displayGuiScreen(new SilentMultiplayerGui((GuiScreen) ((GuiMultiplayerExt) guiScreenIn).silent$getParentScreen()));
}
if(guiScreenIn instanceof GuiIngameMenu) {
displayGuiScreen(new net.silentclient.client.gui.minecraft.GuiIngameMenu());
return;