Skip to content

Commit 4035ea0

Browse files
committed
fix: multiplayer
1 parent b6ad74d commit 4035ea0

File tree

3 files changed

+87
-46
lines changed

3 files changed

+87
-46
lines changed

src/main/java/top/fpsmaster/ui/mc/GuiMultiplayer.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
import net.minecraftforge.fml.client.FMLClientHandler;
1414
import org.apache.logging.log4j.LogManager;
1515
import org.apache.logging.log4j.Logger;
16+
import org.lwjgl.opengl.GL11;
1617
import top.fpsmaster.FPSMaster;
1718
import top.fpsmaster.font.impl.UFontRenderer;
19+
import top.fpsmaster.ui.click.component.ScrollContainer;
1820
import top.fpsmaster.ui.common.GuiButton;
1921
import top.fpsmaster.ui.screens.mainmenu.MainMenu;
22+
import top.fpsmaster.utils.render.draw.Hover;
23+
import top.fpsmaster.utils.render.draw.Rects;
2024
import top.fpsmaster.utils.render.gui.ScaledGuiScreen;
2125
import top.fpsmaster.utils.render.gui.Backgrounds;
26+
import top.fpsmaster.utils.render.gui.Scissor;
2227

2328
import java.awt.*;
2429
import java.io.File;
@@ -30,6 +35,8 @@ public class GuiMultiplayer extends ScaledGuiScreen {
3035
private static final Logger logger = LogManager.getLogger();
3136
private final List<ServerData> servers = Lists.newArrayList();
3237
public final OldServerPinger oldServerPinger = new OldServerPinger();
38+
private final List<ServerListEntry> serverListDisplay = Lists.newArrayList();
39+
private final List<ServerListEntry> serverListInternet = Lists.newArrayList();
3340

3441
String action = "";
3542

@@ -89,6 +96,13 @@ public void initGui() {
8996
super.initGui();
9097
loadServerList();
9198
selectedServer = servers.isEmpty() ? null : servers.get(0);
99+
100+
serverListInternet.clear();
101+
for (ServerData server : servers) {
102+
this.serverListInternet.add(new ServerListEntry(this, server));
103+
}
104+
serverListDisplay.clear();
105+
serverListDisplay.addAll(serverListInternet);
92106
}
93107

94108
@Override
@@ -136,14 +150,45 @@ public void saveServerList() {
136150

137151
}
138152

153+
ScrollContainer scrollContainer = new ScrollContainer();
154+
155+
139156
@Override
140157
public void render(int mouseX, int mouseY, float partialTicks) {
141158
super.render(mouseX, mouseY, partialTicks);
142159
Backgrounds.draw((int) (guiWidth * scaleFactor), (int) (guiHeight * scaleFactor), mouseX, mouseY, partialTicks, (int) zLevel);
143160

144161
UFontRenderer title = FPSMaster.fontManager.s22;
145162
title.drawCenteredString(FPSMaster.i18n.get("multiplayer.title"), guiWidth / 2f, 16, -1);
146-
163+
GL11.glPushMatrix();
164+
GL11.glEnable(GL11.GL_SCISSOR_TEST);
165+
Scissor.apply((guiWidth - 400) / 2f, 60f, 400f, guiHeight - 120);
166+
scrollContainer.draw((guiWidth - 400) / 2f, 60, 396, guiHeight - 120, mouseX, mouseY, () -> {
167+
float y = 70 + scrollContainer.getScroll();
168+
Rects.rounded(Math.round((guiWidth - 400) / 2f), Math.round(y - 10), 400, Math.round(guiHeight - y), 5, new Color(0, 0, 0, 70).getRGB());
169+
for (ServerListEntry server : serverListDisplay) {
170+
if (server.getServerData() == null) {
171+
return;
172+
}
173+
Rects.rounded(Math.round((guiWidth - 340) / 2f), Math.round(y), 340, 54, new Color(0, 0, 0, 120));
174+
if (Hover.is((guiWidth - 340) / 2f, y, 340, 54, mouseX, mouseY)) {
175+
if (hasPendingClick(0)){
176+
selectedServer = server.getServerData();
177+
consumePendingClick();
178+
}
179+
Rects.rounded(Math.round((guiWidth - 340) / 2f), Math.round(y), 340, 54, new Color(0, 0, 0, 50));
180+
}
181+
182+
if (selectedServer != null && selectedServer == server.getServerData()) {
183+
Rects.rounded(Math.round((guiWidth - 340) / 2f), Math.round(y), 340, 54, new Color(255, 255, 255, 50));
184+
}
185+
server.drawEntry(0, (int) ((guiWidth - 340) / 2), (int) y, 340, 54, mouseX, mouseY, false);
186+
y += 58;
187+
}
188+
scrollContainer.setHeight(y - 50 - scrollContainer.getScroll());
189+
});
190+
GL11.glDisable(GL11.GL_SCISSOR_TEST);
191+
GL11.glPopMatrix();
147192

148193
join.renderInScreen(this, (guiWidth - 400) / 2f + 20, guiHeight - 56, 380f / 3 - 20, 20, mouseX, mouseY);
149194
connect.renderInScreen(this, (guiWidth - 400) / 2f + 20 + 380f / 3, guiHeight - 56, 380f / 3 - 20, 20, mouseX, mouseY);

src/main/java/top/fpsmaster/ui/mc/ServerListEntry.java

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
import org.apache.commons.lang3.Validate;
2121
import org.apache.logging.log4j.LogManager;
2222
import org.apache.logging.log4j.Logger;
23+
import org.lwjgl.opengl.GL11;
2324
import top.fpsmaster.FPSMaster;
2425
import top.fpsmaster.font.impl.UFontRenderer;
2526
import top.fpsmaster.utils.render.draw.Hover;
27+
import top.fpsmaster.utils.render.draw.Images;
28+
import top.fpsmaster.utils.render.draw.Rects;
29+
import top.fpsmaster.utils.render.gui.UiScale;
2630

2731
import java.awt.image.BufferedImage;
2832
import java.net.UnknownHostException;
@@ -84,7 +88,6 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
8488
UFontRenderer title = FPSMaster.fontManager.s18;
8589
UFontRenderer text = FPSMaster.fontManager.s16;
8690

87-
8891
boolean flag = this.server.version > 47;
8992
boolean flag1 = this.server.version < 47;
9093
boolean flag2 = flag || flag1;
@@ -135,9 +138,10 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
135138
s1 = "Pinging...";
136139
}
137140

138-
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
139-
this.mc.getTextureManager().bindTexture(Gui.icons);
140-
Gui.drawModalRectWithCustomSizedTexture(x + listWidth - 15 - 5, y + 5, (float) (k * 10), (float) (176 + l * 8), 10, 8, 256.0F, 256.0F);
141+
// this.mc.getTextureManager().bindTexture(Gui.icons);
142+
Images.drawUV(Gui.icons, x + listWidth - 15 - 5, y + 5, k * 10, 176 + l * 8, 10, 8, 256, 256,-1,false);
143+
144+
// Gui.drawModalRectWithCustomSizedTexture(UiScale.scale(x + listWidth - 15 - 5), UiScale.scale(y + 5), (float) (k * 10), (float) (176 + l * 8), 10, 8, 256.0F, 256.0F);
141145
if (this.server.getBase64EncodedIconData() != null && !this.server.getBase64EncodedIconData().equals(this.field_148299_g)) {
142146
this.field_148299_g = this.server.getBase64EncodedIconData();
143147
this.prepareServerIcon();
@@ -149,9 +153,10 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
149153
} else {
150154
this.drawTextureAt(x + 10, y + 10, UNKNOWN_SERVER);
151155
}
152-
153-
int i1 = mouseX - x;
154-
int j1 = mouseY - y;
156+
GlStateManager.enableTexture2D();
157+
GlStateManager.disableBlend();
158+
// int i1 = mouseX - x;
159+
// int j1 = mouseY - y;
155160
// String tooltip = FMLClientHandler.instance().enhanceServerListEntry(this, this.server, x, listWidth, y, i1, j1);
156161
// if (tooltip != null) {
157162
// this.owner.setHoveringText(tooltip);
@@ -161,48 +166,13 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
161166
// this.owner.setHoveringText(s);
162167
// }
163168

164-
if (Hover.is(x + listWidth - text.getStringWidth(s1), y + 4, 10, 10, mouseX, mouseY)) {
165-
text.drawString(s1, x + listWidth - text.getStringWidth(s1) + 12, y + 4, -1);
169+
if (Hover.is(x + listWidth - 16, y + 4, 16, 12, mouseX, mouseY)) {
170+
text.drawString(s1, x + listWidth - 8, y + 4, -1);
166171
}
167-
168-
if (this.mc.gameSettings.touchscreen || isSelected) {
169-
this.mc.getTextureManager().bindTexture(SERVER_SELECTION_BUTTONS);
170-
Gui.drawRect(x, y, x + 32, y + 32, -1601138544);
171-
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
172-
int k1 = mouseX - x;
173-
int l1 = mouseY - y;
174-
if (this.func_178013_b()) {
175-
if (k1 < 32 && k1 > 16) {
176-
Gui.drawModalRectWithCustomSizedTexture(x, y, 0.0F, 32.0F, 32, 32, 256.0F, 256.0F);
177-
} else {
178-
Gui.drawModalRectWithCustomSizedTexture(x, y, 0.0F, 0.0F, 32, 32, 256.0F, 256.0F);
179-
}
180-
}
181-
182-
// if (this.owner.func_175392_a(this, slotIndex)) {
183-
// if (k1 < 16 && l1 < 16) {
184-
// Gui.drawModalRectWithCustomSizedTexture(x, y, 96.0F, 32.0F, 32, 32, 256.0F, 256.0F);
185-
// } else {
186-
// Gui.drawModalRectWithCustomSizedTexture(x, y, 96.0F, 0.0F, 32, 32, 256.0F, 256.0F);
187-
// }
188-
// }
189-
//
190-
// if (this.owner.func_175394_b(this, slotIndex)) {
191-
// if (k1 < 16 && l1 > 16) {
192-
// Gui.drawModalRectWithCustomSizedTexture(x, y, 64.0F, 32.0F, 32, 32, 256.0F, 256.0F);
193-
// } else {
194-
// Gui.drawModalRectWithCustomSizedTexture(x, y, 64.0F, 0.0F, 32, 32, 256.0F, 256.0F);
195-
// }
196-
// }
197-
}
198-
199172
}
200173

201174
protected void drawTextureAt(int p_178012_1_, int p_178012_2_, ResourceLocation p_178012_3_) {
202-
this.mc.getTextureManager().bindTexture(p_178012_3_);
203-
GlStateManager.enableBlend();
204-
Gui.drawModalRectWithCustomSizedTexture(p_178012_1_, p_178012_2_, 0.0F, 0.0F, 32, 32, 32.0F, 32.0F);
205-
GlStateManager.disableBlend();
175+
Images.draw(p_178012_3_, p_178012_1_, p_178012_2_, 32, 32);
206176
}
207177

208178
private boolean func_178013_b() {

src/main/java/top/fpsmaster/utils/render/draw/Images.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package top.fpsmaster.utils.render.draw;
22

3+
import org.lwjgl.opengl.GL11;
34
import top.fpsmaster.utils.render.draw.Colors;
45

56
import net.minecraft.client.Minecraft;
@@ -89,6 +90,31 @@ public static void draw(ResourceLocation res, int x, int y, int width, int heigh
8990
}
9091
}
9192

93+
public static void drawUV(ResourceLocation res, int x, int y, int u, int v, int width, int height,int tw, int th, int color, boolean rawImage) {
94+
x = UiScale.scale(x);
95+
y = UiScale.scale(y);
96+
// width = UiScale.scale(width);
97+
// height = UiScale.scale(height);
98+
if (!rawImage) {
99+
glDisable(GL_DEPTH_TEST);
100+
glEnable(GL_BLEND);
101+
glDepthMask(false);
102+
GL14.glBlendFuncSeparate(org.lwjgl.opengl.GL11.GL_SRC_ALPHA, org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA, org.lwjgl.opengl.GL11.GL_ONE, org.lwjgl.opengl.GL11.GL_ZERO);
103+
glColor(color);
104+
}
105+
Minecraft.getMinecraft().getTextureManager().bindTexture(res);
106+
GL11.glTranslatef(x, y, 0);
107+
GL11.glScalef(UiScale.getScale(), UiScale.getScale(), 0);
108+
Gui.drawModalRectWithCustomSizedTexture(0, 0, u, v, width, height, tw, th);
109+
GL11.glScalef(1 / UiScale.getScale(), 1 / UiScale.getScale(), 0);
110+
GL11.glTranslatef(-x, -y, 0);
111+
if (!rawImage) {
112+
glDepthMask(true);
113+
glDisable(GL_BLEND);
114+
glEnable(GL_DEPTH_TEST);
115+
}
116+
}
117+
92118
public static void playerHead(AbstractClientPlayer player, float x, float y, int w, int h) {
93119
Minecraft.getMinecraft().getTextureManager().bindTexture(player.getLocationSkin());
94120
int sx = UiScale.scale(Math.round(x));

0 commit comments

Comments
 (0)