| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import com.google.common.collect.ComparisonChain;
|
| 4 | import com.google.common.collect.Ordering;
|
| 5 | import com.mojang.authlib.GameProfile;
|
| 6 | import java.util.Comparator;
|
| 7 | import java.util.List;
|
| 8 | import net.minecraft.client.Minecraft;
|
| 9 | import net.minecraft.client.network.NetHandlerPlayClient;
|
| 10 | import net.minecraft.client.network.NetworkPlayerInfo;
|
| 11 | import net.minecraft.client.renderer.GlStateManager;
|
| 12 | import net.minecraft.entity.player.EntityPlayer;
|
| 13 | import net.minecraft.entity.player.EnumPlayerModelParts;
|
| 14 | import net.minecraft.scoreboard.IScoreObjectiveCriteria;
|
| 15 | import net.minecraft.scoreboard.ScoreObjective;
|
| 16 | import net.minecraft.scoreboard.ScorePlayerTeam;
|
| 17 | import net.minecraft.scoreboard.Scoreboard;
|
| 18 | import net.minecraft.util.EnumChatFormatting;
|
| 19 | import net.minecraft.util.IChatComponent;
|
| 20 | import net.minecraft.util.MathHelper;
|
| 21 | import net.minecraft.world.WorldSettings;
|
| 22 |
|
| 23 | public class GuiPlayerTabOverlay extends Gui
|
| 24 | {
|
| 25 | private static final Ordering<NetworkPlayerInfo> field_175252_a = Ordering.from(new GuiPlayerTabOverlay.PlayerComparator());
|
| 26 | private final Minecraft mc;
|
| 27 | private final GuiIngame guiIngame;
|
| 28 | private IChatComponent footer;
|
| 29 | private IChatComponent header;
|
| 30 |
|
| 31 | /**
|
| 32 | * The last time the playerlist was opened (went from not being renderd, to being rendered)
|
| 33 | */
|
| 34 | private long lastTimeOpened;
|
| 35 |
|
| 36 | /** Weither or not the playerlist is currently being rendered */
|
| 37 | private boolean isBeingRendered;
|
| 38 |
|
| 39 | public GuiPlayerTabOverlay(Minecraft mcIn, GuiIngame guiIngameIn)
|
| 40 | {
|
| 41 | this.mc = mcIn;
|
| 42 | this.guiIngame = guiIngameIn;
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Returns the name that should be renderd for the player supplied
|
| 47 | */
|
| 48 | public String getPlayerName(NetworkPlayerInfo networkPlayerInfoIn)
|
| 49 | {
|
| 50 | return networkPlayerInfoIn.getDisplayName() != null ? networkPlayerInfoIn.getDisplayName().getFormattedText() : ScorePlayerTeam.formatPlayerName(networkPlayerInfoIn.getPlayerTeam(), networkPlayerInfoIn.getGameProfile().getName());
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Called by GuiIngame to update the information stored in the playerlist, does not actually render the list,
|
| 55 | * however.
|
| 56 | */
|
| 57 | public void updatePlayerList(boolean willBeRendered)
|
| 58 | {
|
| 59 | if (willBeRendered && !this.isBeingRendered)
|
| 60 | {
|
| 61 | this.lastTimeOpened = Minecraft.getSystemTime();
|
| 62 | }
|
| 63 |
|
| 64 | this.isBeingRendered = willBeRendered;
|
| 65 | }
|
| 66 |
|
| 67 | /**
|
| 68 | * Renders the playerlist, its background, headers and footers.
|
| 69 | */
|
| 70 | public void renderPlayerlist(int width, Scoreboard scoreboardIn, ScoreObjective scoreObjectiveIn)
|
| 71 | {
|
| 72 | NetHandlerPlayClient nethandlerplayclient = this.mc.thePlayer.sendQueue;
|
| 73 | List<NetworkPlayerInfo> list = field_175252_a.<NetworkPlayerInfo>sortedCopy(nethandlerplayclient.getPlayerInfoMap());
|
| 74 | int i = 0;
|
| 75 | int j = 0;
|
| 76 |
|
| 77 | for (NetworkPlayerInfo networkplayerinfo : list)
|
| 78 | {
|
| 79 | int k = this.mc.fontRendererObj.getStringWidth(this.getPlayerName(networkplayerinfo));
|
| 80 | i = Math.max(i, k);
|
| 81 |
|
| 82 | if (scoreObjectiveIn != null && scoreObjectiveIn.getRenderType() != IScoreObjectiveCriteria.EnumRenderType.HEARTS)
|
| 83 | {
|
| 84 | k = this.mc.fontRendererObj.getStringWidth(" " + scoreboardIn.getValueFromObjective(networkplayerinfo.getGameProfile().getName(), scoreObjectiveIn).getScorePoints());
|
| 85 | j = Math.max(j, k);
|
| 86 | }
|
| 87 | }
|
| 88 |
|
| 89 | list = list.subList(0, Math.min(list.size(), 80));
|
| 90 | int l3 = list.size();
|
| 91 | int i4 = l3;
|
| 92 | int j4;
|
| 93 |
|
| 94 | for (j4 = 1; i4 > 20; i4 = (l3 + j4 - 1) / j4)
|
| 95 | {
|
| 96 | ++j4;
|
| 97 | }
|
| 98 |
|
| 99 | boolean flag = this.mc.isIntegratedServerRunning() || this.mc.getNetHandler().getNetworkManager().getIsencrypted();
|
| 100 | int l;
|
| 101 |
|
| 102 | if (scoreObjectiveIn != null)
|
| 103 | {
|
| 104 | if (scoreObjectiveIn.getRenderType() == IScoreObjectiveCriteria.EnumRenderType.HEARTS)
|
| 105 | {
|
| 106 | l = 90;
|
| 107 | }
|
| 108 | else
|
| 109 | {
|
| 110 | l = j;
|
| 111 | }
|
| 112 | }
|
| 113 | else
|
| 114 | {
|
| 115 | l = 0;
|
| 116 | }
|
| 117 |
|
| 118 | int i1 = Math.min(j4 * ((flag ? 9 : 0) + i + l + 13), width - 50) / j4;
|
| 119 | int j1 = width / 2 - (i1 * j4 + (j4 - 1) * 5) / 2;
|
| 120 | int k1 = 10;
|
| 121 | int l1 = i1 * j4 + (j4 - 1) * 5;
|
| 122 | List<String> list1 = null;
|
| 123 | List<String> list2 = null;
|
| 124 |
|
| 125 | if (this.header != null)
|
| 126 | {
|
| 127 | list1 = this.mc.fontRendererObj.listFormattedStringToWidth(this.header.getFormattedText(), width - 50);
|
| 128 |
|
| 129 | for (String s : list1)
|
| 130 | {
|
| 131 | l1 = Math.max(l1, this.mc.fontRendererObj.getStringWidth(s));
|
| 132 | }
|
| 133 | }
|
| 134 |
|
| 135 | if (this.footer != null)
|
| 136 | {
|
| 137 | list2 = this.mc.fontRendererObj.listFormattedStringToWidth(this.footer.getFormattedText(), width - 50);
|
| 138 |
|
| 139 | for (String s2 : list2)
|
| 140 | {
|
| 141 | l1 = Math.max(l1, this.mc.fontRendererObj.getStringWidth(s2));
|
| 142 | }
|
| 143 | }
|
| 144 |
|
| 145 | if (list1 != null)
|
| 146 | {
|
| 147 | drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list1.size() * this.mc.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE);
|
| 148 |
|
| 149 | for (String s3 : list1)
|
| 150 | {
|
| 151 | int i2 = this.mc.fontRendererObj.getStringWidth(s3);
|
| 152 | this.mc.fontRendererObj.drawStringWithShadow(s3, (float)(width / 2 - i2 / 2), (float)k1, -1);
|
| 153 | k1 += this.mc.fontRendererObj.FONT_HEIGHT;
|
| 154 | }
|
| 155 |
|
| 156 | ++k1;
|
| 157 | }
|
| 158 |
|
| 159 | drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + i4 * 9, Integer.MIN_VALUE);
|
| 160 |
|
| 161 | for (int k4 = 0; k4 < l3; ++k4)
|
| 162 | {
|
| 163 | int l4 = k4 / i4;
|
| 164 | int i5 = k4 % i4;
|
| 165 | int j2 = j1 + l4 * i1 + l4 * 5;
|
| 166 | int k2 = k1 + i5 * 9;
|
| 167 | drawRect(j2, k2, j2 + i1, k2 + 8, 553648127);
|
| 168 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 169 | GlStateManager.enableAlpha();
|
| 170 | GlStateManager.enableBlend();
|
| 171 | GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
| 172 |
|
| 173 | if (k4 < list.size())
|
| 174 | {
|
| 175 | NetworkPlayerInfo networkplayerinfo1 = (NetworkPlayerInfo)list.get(k4);
|
| 176 | String s1 = this.getPlayerName(networkplayerinfo1);
|
| 177 | GameProfile gameprofile = networkplayerinfo1.getGameProfile();
|
| 178 |
|
| 179 | if (flag)
|
| 180 | {
|
| 181 | EntityPlayer entityplayer = this.mc.theWorld.getPlayerEntityByUUID(gameprofile.getId());
|
| 182 | boolean flag1 = entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.CAPE) && (gameprofile.getName().equals("Dinnerbone") || gameprofile.getName().equals("Grumm"));
|
| 183 | this.mc.getTextureManager().bindTexture(networkplayerinfo1.getLocationSkin());
|
| 184 | int l2 = 8 + (flag1 ? 8 : 0);
|
| 185 | int i3 = 8 * (flag1 ? -1 : 1);
|
| 186 | Gui.drawScaledCustomSizeModalRect(j2, k2, 8.0F, (float)l2, 8, i3, 8, 8, 64.0F, 64.0F);
|
| 187 |
|
| 188 | if (entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.HAT))
|
| 189 | {
|
| 190 | int j3 = 8 + (flag1 ? 8 : 0);
|
| 191 | int k3 = 8 * (flag1 ? -1 : 1);
|
| 192 | Gui.drawScaledCustomSizeModalRect(j2, k2, 40.0F, (float)j3, 8, k3, 8, 8, 64.0F, 64.0F);
|
| 193 | }
|
| 194 |
|
| 195 | j2 += 9;
|
| 196 | }
|
| 197 |
|
| 198 | if (networkplayerinfo1.getGameType() == WorldSettings.GameType.SPECTATOR)
|
| 199 | {
|
| 200 | s1 = EnumChatFormatting.ITALIC + s1;
|
| 201 | this.mc.fontRendererObj.drawStringWithShadow(s1, (float)j2, (float)k2, -1862270977);
|
| 202 | }
|
| 203 | else
|
| 204 | {
|
| 205 | this.mc.fontRendererObj.drawStringWithShadow(s1, (float)j2, (float)k2, -1);
|
| 206 | }
|
| 207 |
|
| 208 | if (scoreObjectiveIn != null && networkplayerinfo1.getGameType() != WorldSettings.GameType.SPECTATOR)
|
| 209 | {
|
| 210 | int k5 = j2 + i + 1;
|
| 211 | int l5 = k5 + l;
|
| 212 |
|
| 213 | if (l5 - k5 > 5)
|
| 214 | {
|
| 215 | this.drawScoreboardValues(scoreObjectiveIn, k2, gameprofile.getName(), k5, l5, networkplayerinfo1);
|
| 216 | }
|
| 217 | }
|
| 218 |
|
| 219 | this.drawPing(i1, j2 - (flag ? 9 : 0), k2, networkplayerinfo1);
|
| 220 | }
|
| 221 | }
|
| 222 |
|
| 223 | if (list2 != null)
|
| 224 | {
|
| 225 | k1 = k1 + i4 * 9 + 1;
|
| 226 | drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list2.size() * this.mc.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE);
|
| 227 |
|
| 228 | for (String s4 : list2)
|
| 229 | {
|
| 230 | int j5 = this.mc.fontRendererObj.getStringWidth(s4);
|
| 231 | this.mc.fontRendererObj.drawStringWithShadow(s4, (float)(width / 2 - j5 / 2), (float)k1, -1);
|
| 232 | k1 += this.mc.fontRendererObj.FONT_HEIGHT;
|
| 233 | }
|
| 234 | }
|
| 235 | }
|
| 236 |
|
| 237 | protected void drawPing(int p_175245_1_, int p_175245_2_, int p_175245_3_, NetworkPlayerInfo networkPlayerInfoIn)
|
| 238 | {
|
| 239 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 240 | this.mc.getTextureManager().bindTexture(icons);
|
| 241 | int i = 0;
|
| 242 | int j = 0;
|
| 243 |
|
| 244 | if (networkPlayerInfoIn.getResponseTime() < 0)
|
| 245 | {
|
| 246 | j = 5;
|
| 247 | }
|
| 248 | else if (networkPlayerInfoIn.getResponseTime() < 150)
|
| 249 | {
|
| 250 | j = 0;
|
| 251 | }
|
| 252 | else if (networkPlayerInfoIn.getResponseTime() < 300)
|
| 253 | {
|
| 254 | j = 1;
|
| 255 | }
|
| 256 | else if (networkPlayerInfoIn.getResponseTime() < 600)
|
| 257 | {
|
| 258 | j = 2;
|
| 259 | }
|
| 260 | else if (networkPlayerInfoIn.getResponseTime() < 1000)
|
| 261 | {
|
| 262 | j = 3;
|
| 263 | }
|
| 264 | else
|
| 265 | {
|
| 266 | j = 4;
|
| 267 | }
|
| 268 |
|
| 269 | this.zLevel += 100.0F;
|
| 270 | this.drawTexturedModalRect(p_175245_2_ + p_175245_1_ - 11, p_175245_3_, 0 + i * 10, 176 + j * 8, 10, 8);
|
| 271 | this.zLevel -= 100.0F;
|
| 272 | }
|
| 273 |
|
| 274 | private void drawScoreboardValues(ScoreObjective p_175247_1_, int p_175247_2_, String p_175247_3_, int p_175247_4_, int p_175247_5_, NetworkPlayerInfo p_175247_6_)
|
| 275 | {
|
| 276 | int i = p_175247_1_.getScoreboard().getValueFromObjective(p_175247_3_, p_175247_1_).getScorePoints();
|
| 277 |
|
| 278 | if (p_175247_1_.getRenderType() == IScoreObjectiveCriteria.EnumRenderType.HEARTS)
|
| 279 | {
|
| 280 | this.mc.getTextureManager().bindTexture(icons);
|
| 281 |
|
| 282 | if (this.lastTimeOpened == p_175247_6_.func_178855_p())
|
| 283 | {
|
| 284 | if (i < p_175247_6_.func_178835_l())
|
| 285 | {
|
| 286 | p_175247_6_.func_178846_a(Minecraft.getSystemTime());
|
| 287 | p_175247_6_.func_178844_b((long)(this.guiIngame.getUpdateCounter() + 20));
|
| 288 | }
|
| 289 | else if (i > p_175247_6_.func_178835_l())
|
| 290 | {
|
| 291 | p_175247_6_.func_178846_a(Minecraft.getSystemTime());
|
| 292 | p_175247_6_.func_178844_b((long)(this.guiIngame.getUpdateCounter() + 10));
|
| 293 | }
|
| 294 | }
|
| 295 |
|
| 296 | if (Minecraft.getSystemTime() - p_175247_6_.func_178847_n() > 1000L || this.lastTimeOpened != p_175247_6_.func_178855_p())
|
| 297 | {
|
| 298 | p_175247_6_.func_178836_b(i);
|
| 299 | p_175247_6_.func_178857_c(i);
|
| 300 | p_175247_6_.func_178846_a(Minecraft.getSystemTime());
|
| 301 | }
|
| 302 |
|
| 303 | p_175247_6_.func_178843_c(this.lastTimeOpened);
|
| 304 | p_175247_6_.func_178836_b(i);
|
| 305 | int j = MathHelper.ceiling_float_int((float)Math.max(i, p_175247_6_.func_178860_m()) / 2.0F);
|
| 306 | int k = Math.max(MathHelper.ceiling_float_int((float)(i / 2)), Math.max(MathHelper.ceiling_float_int((float)(p_175247_6_.func_178860_m() / 2)), 10));
|
| 307 | boolean flag = p_175247_6_.func_178858_o() > (long)this.guiIngame.getUpdateCounter() && (p_175247_6_.func_178858_o() - (long)this.guiIngame.getUpdateCounter()) / 3L % 2L == 1L;
|
| 308 |
|
| 309 | if (j > 0)
|
| 310 | {
|
| 311 | float f = Math.min((float)(p_175247_5_ - p_175247_4_ - 4) / (float)k, 9.0F);
|
| 312 |
|
| 313 | if (f > 3.0F)
|
| 314 | {
|
| 315 | for (int l = j; l < k; ++l)
|
| 316 | {
|
| 317 | this.drawTexturedModalRect((float)p_175247_4_ + (float)l * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
|
| 318 | }
|
| 319 |
|
| 320 | for (int j1 = 0; j1 < j; ++j1)
|
| 321 | {
|
| 322 | this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
|
| 323 |
|
| 324 | if (flag)
|
| 325 | {
|
| 326 | if (j1 * 2 + 1 < p_175247_6_.func_178860_m())
|
| 327 | {
|
| 328 | this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 70, 0, 9, 9);
|
| 329 | }
|
| 330 |
|
| 331 | if (j1 * 2 + 1 == p_175247_6_.func_178860_m())
|
| 332 | {
|
| 333 | this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 79, 0, 9, 9);
|
| 334 | }
|
| 335 | }
|
| 336 |
|
| 337 | if (j1 * 2 + 1 < i)
|
| 338 | {
|
| 339 | this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 160 : 52, 0, 9, 9);
|
| 340 | }
|
| 341 |
|
| 342 | if (j1 * 2 + 1 == i)
|
| 343 | {
|
| 344 | this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 169 : 61, 0, 9, 9);
|
| 345 | }
|
| 346 | }
|
| 347 | }
|
| 348 | else
|
| 349 | {
|
| 350 | float f1 = MathHelper.clamp_float((float)i / 20.0F, 0.0F, 1.0F);
|
| 351 | int i1 = (int)((1.0F - f1) * 255.0F) << 16 | (int)(f1 * 255.0F) << 8;
|
| 352 | String s = "" + (float)i / 2.0F;
|
| 353 |
|
| 354 | if (p_175247_5_ - this.mc.fontRendererObj.getStringWidth(s + "hp") >= p_175247_4_)
|
| 355 | {
|
| 356 | s = s + "hp";
|
| 357 | }
|
| 358 |
|
| 359 | this.mc.fontRendererObj.drawStringWithShadow(s, (float)((p_175247_5_ + p_175247_4_) / 2 - this.mc.fontRendererObj.getStringWidth(s) / 2), (float)p_175247_2_, i1);
|
| 360 | }
|
| 361 | }
|
| 362 | }
|
| 363 | else
|
| 364 | {
|
| 365 | String s1 = EnumChatFormatting.YELLOW + "" + i;
|
| 366 | this.mc.fontRendererObj.drawStringWithShadow(s1, (float)(p_175247_5_ - this.mc.fontRendererObj.getStringWidth(s1)), (float)p_175247_2_, 16777215);
|
| 367 | }
|
| 368 | }
|
| 369 |
|
| 370 | public void setFooter(IChatComponent footerIn)
|
| 371 | {
|
| 372 | this.footer = footerIn;
|
| 373 | }
|
| 374 |
|
| 375 | public void setHeader(IChatComponent headerIn)
|
| 376 | {
|
| 377 | this.header = headerIn;
|
| 378 | }
|
| 379 |
|
| 380 | public void resetFooterHeader()
|
| 381 | {
|
| 382 | this.header = null;
|
| 383 | this.footer = null;
|
| 384 | }
|
| 385 |
|
| 386 | static class PlayerComparator implements Comparator<NetworkPlayerInfo>
|
| 387 | {
|
| 388 | private PlayerComparator()
|
| 389 | {
|
| 390 | }
|
| 391 |
|
| 392 | public int compare(NetworkPlayerInfo p_compare_1_, NetworkPlayerInfo p_compare_2_)
|
| 393 | {
|
| 394 | ScorePlayerTeam scoreplayerteam = p_compare_1_.getPlayerTeam();
|
| 395 | ScorePlayerTeam scoreplayerteam1 = p_compare_2_.getPlayerTeam();
|
| 396 | return ComparisonChain.start().compareTrueFirst(p_compare_1_.getGameType() != WorldSettings.GameType.SPECTATOR, p_compare_2_.getGameType() != WorldSettings.GameType.SPECTATOR).compare(scoreplayerteam != null ? scoreplayerteam.getRegisteredName() : "", scoreplayerteam1 != null ? scoreplayerteam1.getRegisteredName() : "").compare(p_compare_1_.getGameProfile().getName(), p_compare_2_.getGameProfile().getName()).result();
|
| 397 | }
|
| 398 | }
|
| 399 | }
|
| 400 |
|