Custom Multiplayer Screen 100%

This commit is contained in:
kirillsaint 2023-08-28 16:19:15 +06:00
parent 6488914cc1
commit fa082ed179
7 changed files with 78 additions and 2 deletions

View File

@ -141,7 +141,7 @@ public class SilentMultiplayerGui extends SilentScreen {
continue; 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)) { 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); MouseCursorHandler.CursorType cursor = serverComponent.draw(serverIndex, mouseX, mouseY, blockX + 5, serverY, serverIndex == selectedServer);
if(cursor != null) { if(cursor != null) {
cursorType = cursor; cursorType = cursor;
} }
@ -164,6 +164,54 @@ public class SilentMultiplayerGui extends SilentScreen {
} }
} }
public boolean canUpSwap(int index)
{
return index > 0;
}
public boolean canDownSwap(int index)
{
return index < this.savedServerList.countServers() - 1;
}
public void swapUp(int index, boolean fullSwap)
{
int i = fullSwap ? 0 : index - 1;
this.savedServerList.swapServers(index, i);
if (this.selectedServer == index)
{
this.selectServer(i);
}
servers.clear();
for (int i1 = 0; i1 < savedServerList.countServers(); ++i1)
{
ServerData serverData = savedServerList.getServerData(i1);
servers.add(new ServerComponent(this, serverData));
}
}
public void swapDown(int index, boolean fullSwap)
{
int i = fullSwap ? this.savedServerList.countServers() - 1 : index + 1;
this.savedServerList.swapServers(index, i);
if (this.selectedServer == index)
{
this.selectServer(i);
}
servers.clear();
for (int i1 = 0; i1 < savedServerList.countServers(); ++i1)
{
ServerData serverData = savedServerList.getServerData(i1);
servers.add(new ServerComponent(this, serverData));
}
}
@Override @Override
protected void actionPerformed(GuiButton button) throws IOException { protected void actionPerformed(GuiButton button) throws IOException {
super.actionPerformed(button); super.actionPerformed(button);
@ -247,6 +295,9 @@ public class SilentMultiplayerGui extends SilentScreen {
} }
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) { 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); isReset = !serverComponent.mouseClicked(serverIndex, mouseX, mouseY, blockX + 5, serverY, serverIndex == selectedServer);
if(!isReset) {
break;
}
} }
serverY += 38; serverY += 38;
} }

View File

@ -8,6 +8,7 @@ import io.netty.buffer.Unpooled;
import io.netty.handler.codec.base64.Base64; import io.netty.handler.codec.base64.Base64;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.renderer.texture.DynamicTexture;
@ -52,7 +53,7 @@ public class ServerComponent {
this.field_148305_h = (DynamicTexture)this.mc.getTextureManager().getTexture(this.serverIcon); 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) { public MouseCursorHandler.CursorType draw(int serverIndex, int mouseX, int mouseY, float x, float y, boolean isSelected) {
MouseCursorHandler.CursorType cursorType = null; MouseCursorHandler.CursorType cursorType = null;
if (!this.server.field_78841_f) if (!this.server.field_78841_f)
{ {
@ -96,6 +97,17 @@ public class ServerComponent {
} }
RenderUtil.drawImage(this.field_148305_h != null ? serverIcon : UNKNOWN_SERVER, x + 2, y + 2, 31, 31, false); RenderUtil.drawImage(this.field_148305_h != null ? serverIcon : UNKNOWN_SERVER, x + 2, y + 2, 31, 31, false);
if(MouseUtils.isInside(mouseX, mouseY, x + 2, y + 2, 31, 31)) {
if(this.owner.canUpSwap(serverIndex)) {
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/page-up.png"), x + 2 + (31 / 2) - (15 / 2), y + 2, 15, 15, true, MouseUtils.isInside(mouseX, mouseY, x + 2 + (31 / 2) - (15 / 2), y + 2, 15, 15) ? new Color(255, 255, 255).getRGB() : Theme.borderColor().getRGB());
}
if(this.owner.canDownSwap(serverIndex)) {
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/page-down.png"), x + 2 + (31 / 2) - (15 / 2), y + 2 + 31 - 16, 15, 15, true, MouseUtils.isInside(mouseX, mouseY, x + 2 + (31 / 2) - (15 / 2), y + 2 + 31 - 16, 15, 15) ? new Color(255, 255, 255).getRGB() : Theme.borderColor().getRGB());
}
}
mc.fontRendererObj.drawString(server.serverName, x + 2 + 31 + 3, (int) y + 3, -1, true); 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); List<String> list = this.mc.fontRendererObj.listFormattedStringToWidth(this.server.serverMOTD, 240 - 36);
@ -187,6 +199,19 @@ public class ServerComponent {
public boolean mouseClicked(int serverIndex, int mouseX, int mouseY, float x, float y, boolean isSelected) { 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); boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, y, 240, 35);
if(isHovered) { if(isHovered) {
if(MouseUtils.isInside(mouseX, mouseY, x + 2, y + 2, 31, 31)) {
if(this.owner.canUpSwap(serverIndex) && MouseUtils.isInside(mouseX, mouseY, x + 2 + (31 / 2) - (15 / 2), y + 2, 15, 15)) {
Client.logger.info("Swapping server " + serverIndex + " to up");
this.owner.swapUp(serverIndex, GuiScreen.isShiftKeyDown());
return isHovered;
}
if(this.owner.canDownSwap(serverIndex) && MouseUtils.isInside(mouseX, mouseY, x + 2 + (31 / 2) - (15 / 2), y + 2 + 31 - 16, 15, 15)) {
Client.logger.info("Swapping server " + serverIndex + " to down");
this.owner.swapDown(serverIndex, GuiScreen.isShiftKeyDown());
return isHovered;
}
}
if(!isSelected) { if(!isSelected) {
this.owner.selectServer(serverIndex); this.owner.selectServer(serverIndex);
} else { } else {

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B