Skip to content

Commit 06a0abd

Browse files
committed
优化多人游戏界面与交互
1 parent 7a847c8 commit 06a0abd

2 files changed

Lines changed: 17 additions & 30 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.List;
3131

3232
public class GuiMultiplayer extends ScaledGuiScreen {
33-
3433
private ServerData selectedServer;
3534
private static final Logger logger = LogManager.getLogger();
3635
private final List<ServerData> servers = Lists.newArrayList();
@@ -95,7 +94,7 @@ public class GuiMultiplayer extends ScaledGuiScreen {
9594
public void initGui() {
9695
super.initGui();
9796
loadServerList();
98-
selectedServer = servers.isEmpty() ? null : servers.get(0);
97+
selectedServer = null;
9998

10099
serverListInternet.clear();
101100
for (ServerData server : servers) {
@@ -183,14 +182,15 @@ public void render(int mouseX, int mouseY, float partialTicks) {
183182
if (rowVisible && mouseInViewport && Hover.is(rowX, y, rowWidth, rowHeight, mouseX, mouseY)) {
184183
if (consumePressInBounds(rowX, y, rowWidth, rowHeight, 0) != null) {
185184
selectedServer = server.getServerData();
185+
server.triggerClick();
186186
}
187187
Rects.rounded(Math.round(rowX), Math.round(y), Math.round(rowWidth), Math.round(rowHeight), new Color(0, 0, 0, 50));
188188
}
189189

190190
if (selectedServer != null && selectedServer == server.getServerData()) {
191191
Rects.rounded(Math.round(rowX), Math.round(y), Math.round(rowWidth), Math.round(rowHeight), new Color(255, 255, 255, 50));
192192
}
193-
server.drawEntry(0, (int) rowX, (int) y, (int) rowWidth, (int) rowHeight, mouseX, mouseY, false);
193+
server.drawEntry(0, (int) rowX, (int) y, (int) rowWidth, mouseX, mouseY);
194194
y += 58;
195195
}
196196
scrollContainer.setHeight(y - 50 - scrollContainer.getScroll());
@@ -214,7 +214,6 @@ public void updateScreen() {
214214
super.updateScreen();
215215
FMLClientHandler.instance().setupServerList();
216216
this.oldServerPinger.pingPendingNetworks();
217-
218217
}
219218

220219
@Override

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

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
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;
2423
import top.fpsmaster.FPSMaster;
2524
import top.fpsmaster.font.impl.UFontRenderer;
2625
import top.fpsmaster.utils.render.draw.Hover;
2726
import top.fpsmaster.utils.render.draw.Images;
28-
import top.fpsmaster.utils.render.draw.Rects;
29-
import top.fpsmaster.utils.render.gui.UiScale;
3027

3128
import java.awt.image.BufferedImage;
3229
import java.net.UnknownHostException;
@@ -39,17 +36,13 @@ public class ServerListEntry {
3936
private static final Logger logger = LogManager.getLogger();
4037
private static final ThreadPoolExecutor field_148302_b = new ScheduledThreadPoolExecutor(5, (new ThreadFactoryBuilder()).setNameFormat("Server Pinger #%d").setDaemon(true).build());
4138
private static final ResourceLocation UNKNOWN_SERVER = new ResourceLocation("textures/misc/unknown_server.png");
42-
private static final ResourceLocation SERVER_SELECTION_BUTTONS = new ResourceLocation("textures/gui/server_selection.png");
4339
private final Minecraft mc;
4440
private final ServerData server;
4541
private final ResourceLocation serverIcon;
4642
private String field_148299_g;
4743
private DynamicTexture field_148305_h;
48-
49-
50-
int x, y, width, height;
51-
52-
GuiMultiplayer owner;
44+
private final GuiMultiplayer owner;
45+
private long lastClick = 0;
5346

5447
protected ServerListEntry(GuiMultiplayer multiplayer, ServerData p_i45048_2_) {
5548
this.owner = multiplayer;
@@ -60,18 +53,13 @@ protected ServerListEntry(GuiMultiplayer multiplayer, ServerData p_i45048_2_) {
6053
}
6154

6255

63-
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
56+
public void drawEntry(int slotIndex, int x, int y, int listWidth, int mouseX, int mouseY) {
6457
if (!this.server.field_78841_f) {
6558
this.server.field_78841_f = true;
6659
this.server.pingToServer = -2L;
6760
this.server.serverMOTD = "";
6861
this.server.populationInfo = "";
6962

70-
this.x = x;
71-
this.y = y;
72-
this.width = listWidth;
73-
this.height = slotHeight;
74-
7563
field_148302_b.submit(() -> {
7664
try {
7765
owner.oldServerPinger.ping(ServerListEntry.this.server);
@@ -102,7 +90,6 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
10290
int j = text.getStringWidth(s2);
10391
text.drawString(s2, x + listWidth - j - 15 - 2 - 5, y + 1 + 5, -1);
10492
int k = 0;
105-
String s = null;
10693
int l;
10794
String s1;
10895
if (flag2) {
@@ -139,7 +126,7 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
139126
}
140127

141128
// 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);
129+
Images.drawUV(Gui.icons, x + listWidth - 18, y + 7, k * 10, 176 + l * 8, 10, 8, 256, 256,-1,false);
143130

144131
// 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);
145132
if (this.server.getBase64EncodedIconData() != null && !this.server.getBase64EncodedIconData().equals(this.field_148299_g)) {
@@ -166,19 +153,16 @@ public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight
166153
// this.owner.setHoveringText(s);
167154
// }
168155

169-
if (Hover.is(x + listWidth - 16, y + 4, 16, 12, mouseX, mouseY)) {
170-
text.drawString(s1, x + listWidth - 8, y + 4, -1);
156+
if (Hover.is(x + listWidth - 18, y + 7, 10, 8, mouseX, mouseY)) {
157+
text.drawString(s1, mouseX + 6, mouseY - 6, -1);
171158
}
172159
}
173160

174161
protected void drawTextureAt(int p_178012_1_, int p_178012_2_, ResourceLocation p_178012_3_) {
175162
Images.draw(p_178012_3_, p_178012_1_, p_178012_2_, 32, 32);
176163
}
177164

178-
private boolean func_178013_b() {
179-
return true;
180-
}
181-
165+
@SuppressWarnings("VulnerableCodeUsages")
182166
private void prepareServerIcon() {
183167
if (this.server.getBase64EncodedIconData() == null) {
184168
this.mc.getTextureManager().deleteTexture(this.serverIcon);
@@ -217,12 +201,16 @@ private void prepareServerIcon() {
217201

218202
}
219203

220-
public void clicked(int mouseX, int mouseY, int button) {
221-
}
222-
223204
public ServerData getServerData() {
224205
return this.server;
225206
}
207+
208+
public void triggerClick() {
209+
if (Minecraft.getSystemTime() - lastClick < 250L) {
210+
FMLClientHandler.instance().connectToServer(owner, getServerData());
211+
}
212+
lastClick = Minecraft.getSystemTime();
213+
}
226214
}
227215

228216

0 commit comments

Comments
 (0)