| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import com.google.common.base.Splitter;
|
| 4 | import com.google.common.collect.Lists;
|
| 5 | import com.google.common.collect.Sets;
|
| 6 | import java.awt.Toolkit;
|
| 7 | import java.awt.datatransfer.ClipboardOwner;
|
| 8 | import java.awt.datatransfer.DataFlavor;
|
| 9 | import java.awt.datatransfer.StringSelection;
|
| 10 | import java.awt.datatransfer.Transferable;
|
| 11 | import java.io.File;
|
| 12 | import java.io.IOException;
|
| 13 | import java.net.URI;
|
| 14 | import java.net.URISyntaxException;
|
| 15 | import java.util.Arrays;
|
| 16 | import java.util.List;
|
| 17 | import java.util.Set;
|
| 18 | import net.minecraft.client.Minecraft;
|
| 19 | import net.minecraft.client.gui.stream.GuiTwitchUserMode;
|
| 20 | import net.minecraft.client.renderer.GlStateManager;
|
| 21 | import net.minecraft.client.renderer.RenderHelper;
|
| 22 | import net.minecraft.client.renderer.Tessellator;
|
| 23 | import net.minecraft.client.renderer.WorldRenderer;
|
| 24 | import net.minecraft.client.renderer.entity.RenderItem;
|
| 25 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
| 26 | import net.minecraft.entity.EntityList;
|
| 27 | import net.minecraft.event.ClickEvent;
|
| 28 | import net.minecraft.event.HoverEvent;
|
| 29 | import net.minecraft.item.ItemStack;
|
| 30 | import net.minecraft.nbt.JsonToNBT;
|
| 31 | import net.minecraft.nbt.NBTBase;
|
| 32 | import net.minecraft.nbt.NBTException;
|
| 33 | import net.minecraft.nbt.NBTTagCompound;
|
| 34 | import net.minecraft.stats.Achievement;
|
| 35 | import net.minecraft.stats.StatBase;
|
| 36 | import net.minecraft.stats.StatList;
|
| 37 | import net.minecraft.util.ChatComponentTranslation;
|
| 38 | import net.minecraft.util.EnumChatFormatting;
|
| 39 | import net.minecraft.util.IChatComponent;
|
| 40 | import org.apache.commons.lang3.StringUtils;
|
| 41 | import org.apache.logging.log4j.LogManager;
|
| 42 | import org.apache.logging.log4j.Logger;
|
| 43 | import org.lwjgl.input.Keyboard;
|
| 44 | import org.lwjgl.input.Mouse;
|
| 45 | import tv.twitch.chat.ChatUserInfo;
|
| 46 |
|
| 47 | public abstract class GuiScreen extends Gui implements GuiYesNoCallback
|
| 48 | {
|
| 49 | private static final Logger LOGGER = LogManager.getLogger();
|
| 50 | private static final Set<String> PROTOCOLS = Sets.newHashSet(new String[] {"http", "https"});
|
| 51 | private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n');
|
| 52 |
|
| 53 | /** Reference to the Minecraft object. */
|
| 54 | protected Minecraft mc;
|
| 55 |
|
| 56 | /**
|
| 57 | * Holds a instance of RenderItem, used to draw the achievement icons on screen (is based on ItemStack)
|
| 58 | */
|
| 59 | protected RenderItem itemRender;
|
| 60 |
|
| 61 | /** The width of the screen object. */
|
| 62 | public int width;
|
| 63 |
|
| 64 | /** The height of the screen object. */
|
| 65 | public int height;
|
| 66 | protected List<GuiButton> buttonList = Lists.<GuiButton>newArrayList();
|
| 67 | protected List<GuiLabel> labelList = Lists.<GuiLabel>newArrayList();
|
| 68 | public boolean allowUserInput;
|
| 69 |
|
| 70 | /** The FontRenderer used by GuiScreen */
|
| 71 | protected FontRenderer fontRendererObj;
|
| 72 |
|
| 73 | /** The button that was just pressed. */
|
| 74 | private GuiButton selectedButton;
|
| 75 | private int eventButton;
|
| 76 | private long lastMouseEvent;
|
| 77 |
|
| 78 | /**
|
| 79 | * Tracks the number of fingers currently on the screen. Prevents subsequent fingers registering as clicks.
|
| 80 | */
|
| 81 | private int touchValue;
|
| 82 | private URI clickedLinkURI;
|
| 83 |
|
| 84 | /**
|
| 85 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 86 | */
|
| 87 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 88 | {
|
| 89 | for (int i = 0; i < this.buttonList.size(); ++i)
|
| 90 | {
|
| 91 | ((GuiButton)this.buttonList.get(i)).drawButton(this.mc, mouseX, mouseY);
|
| 92 | }
|
| 93 |
|
| 94 | for (int j = 0; j < this.labelList.size(); ++j)
|
| 95 | {
|
| 96 | ((GuiLabel)this.labelList.get(j)).drawLabel(this.mc, mouseX, mouseY);
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 | /**
|
| 101 | * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
|
| 102 | * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
|
| 103 | */
|
| 104 | protected void keyTyped(char typedChar, int keyCode) throws IOException
|
| 105 | {
|
| 106 | if (keyCode == 1)
|
| 107 | {
|
| 108 | this.mc.displayGuiScreen((GuiScreen)null);
|
| 109 |
|
| 110 | if (this.mc.currentScreen == null)
|
| 111 | {
|
| 112 | this.mc.setIngameFocus();
|
| 113 | }
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | /**
|
| 118 | * Returns a string stored in the system clipboard.
|
| 119 | */
|
| 120 | public static String getClipboardString()
|
| 121 | {
|
| 122 | try
|
| 123 | {
|
| 124 | Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents((Object)null);
|
| 125 |
|
| 126 | if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
|
| 127 | {
|
| 128 | return (String)transferable.getTransferData(DataFlavor.stringFlavor);
|
| 129 | }
|
| 130 | }
|
| 131 | catch (Exception var1)
|
| 132 | {
|
| 133 | ;
|
| 134 | }
|
| 135 |
|
| 136 | return "";
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * Stores the given string in the system clipboard
|
| 141 | */
|
| 142 | public static void setClipboardString(String copyText)
|
| 143 | {
|
| 144 | if (!StringUtils.isEmpty(copyText))
|
| 145 | {
|
| 146 | try
|
| 147 | {
|
| 148 | StringSelection stringselection = new StringSelection(copyText);
|
| 149 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringselection, (ClipboardOwner)null);
|
| 150 | }
|
| 151 | catch (Exception var2)
|
| 152 | {
|
| 153 | ;
|
| 154 | }
|
| 155 | }
|
| 156 | }
|
| 157 |
|
| 158 | protected void renderToolTip(ItemStack stack, int x, int y)
|
| 159 | {
|
| 160 | List<String> list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
|
| 161 |
|
| 162 | for (int i = 0; i < list.size(); ++i)
|
| 163 | {
|
| 164 | if (i == 0)
|
| 165 | {
|
| 166 | list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
|
| 167 | }
|
| 168 | else
|
| 169 | {
|
| 170 | list.set(i, EnumChatFormatting.GRAY + (String)list.get(i));
|
| 171 | }
|
| 172 | }
|
| 173 |
|
| 174 | this.drawHoveringText(list, x, y);
|
| 175 | }
|
| 176 |
|
| 177 | /**
|
| 178 | * Draws the text when mouse is over creative inventory tab. Params: current creative tab to be checked, current
|
| 179 | * mouse x position, current mouse y position.
|
| 180 | */
|
| 181 | protected void drawCreativeTabHoveringText(String tabName, int mouseX, int mouseY)
|
| 182 | {
|
| 183 | this.drawHoveringText(Arrays.<String>asList(new String[] {tabName}), mouseX, mouseY);
|
| 184 | }
|
| 185 |
|
| 186 | /**
|
| 187 | * Draws a List of strings as a tooltip. Every entry is drawn on a seperate line.
|
| 188 | */
|
| 189 | protected void drawHoveringText(List<String> textLines, int x, int y)
|
| 190 | {
|
| 191 | if (!textLines.isEmpty())
|
| 192 | {
|
| 193 | GlStateManager.disableRescaleNormal();
|
| 194 | RenderHelper.disableStandardItemLighting();
|
| 195 | GlStateManager.disableLighting();
|
| 196 | GlStateManager.disableDepth();
|
| 197 | int i = 0;
|
| 198 |
|
| 199 | for (String s : textLines)
|
| 200 | {
|
| 201 | int j = this.fontRendererObj.getStringWidth(s);
|
| 202 |
|
| 203 | if (j > i)
|
| 204 | {
|
| 205 | i = j;
|
| 206 | }
|
| 207 | }
|
| 208 |
|
| 209 | int l1 = x + 12;
|
| 210 | int i2 = y - 12;
|
| 211 | int k = 8;
|
| 212 |
|
| 213 | if (textLines.size() > 1)
|
| 214 | {
|
| 215 | k += 2 + (textLines.size() - 1) * 10;
|
| 216 | }
|
| 217 |
|
| 218 | if (l1 + i > this.width)
|
| 219 | {
|
| 220 | l1 -= 28 + i;
|
| 221 | }
|
| 222 |
|
| 223 | if (i2 + k + 6 > this.height)
|
| 224 | {
|
| 225 | i2 = this.height - k - 6;
|
| 226 | }
|
| 227 |
|
| 228 | this.zLevel = 300.0F;
|
| 229 | this.itemRender.zLevel = 300.0F;
|
| 230 | int l = -267386864;
|
| 231 | this.drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, l, l);
|
| 232 | this.drawGradientRect(l1 - 3, i2 + k + 3, l1 + i + 3, i2 + k + 4, l, l);
|
| 233 | this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 + k + 3, l, l);
|
| 234 | this.drawGradientRect(l1 - 4, i2 - 3, l1 - 3, i2 + k + 3, l, l);
|
| 235 | this.drawGradientRect(l1 + i + 3, i2 - 3, l1 + i + 4, i2 + k + 3, l, l);
|
| 236 | int i1 = 1347420415;
|
| 237 | int j1 = (i1 & 16711422) >> 1 | i1 & -16777216;
|
| 238 | this.drawGradientRect(l1 - 3, i2 - 3 + 1, l1 - 3 + 1, i2 + k + 3 - 1, i1, j1);
|
| 239 | this.drawGradientRect(l1 + i + 2, i2 - 3 + 1, l1 + i + 3, i2 + k + 3 - 1, i1, j1);
|
| 240 | this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 - 3 + 1, i1, i1);
|
| 241 | this.drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, j1, j1);
|
| 242 |
|
| 243 | for (int k1 = 0; k1 < textLines.size(); ++k1)
|
| 244 | {
|
| 245 | String s1 = (String)textLines.get(k1);
|
| 246 | this.fontRendererObj.drawStringWithShadow(s1, (float)l1, (float)i2, -1);
|
| 247 |
|
| 248 | if (k1 == 0)
|
| 249 | {
|
| 250 | i2 += 2;
|
| 251 | }
|
| 252 |
|
| 253 | i2 += 10;
|
| 254 | }
|
| 255 |
|
| 256 | this.zLevel = 0.0F;
|
| 257 | this.itemRender.zLevel = 0.0F;
|
| 258 | GlStateManager.enableLighting();
|
| 259 | GlStateManager.enableDepth();
|
| 260 | RenderHelper.enableStandardItemLighting();
|
| 261 | GlStateManager.enableRescaleNormal();
|
| 262 | }
|
| 263 | }
|
| 264 |
|
| 265 | /**
|
| 266 | * Draws the hover event specified by the given chat component
|
| 267 | *
|
| 268 | * @param component The IChatComponent to render
|
| 269 | * @param x The x position where to render
|
| 270 | * @param y The y position where to render
|
| 271 | */
|
| 272 | protected void handleComponentHover(IChatComponent component, int x, int y)
|
| 273 | {
|
| 274 | if (component != null && component.getChatStyle().getChatHoverEvent() != null)
|
| 275 | {
|
| 276 | HoverEvent hoverevent = component.getChatStyle().getChatHoverEvent();
|
| 277 |
|
| 278 | if (hoverevent.getAction() == HoverEvent.Action.SHOW_ITEM)
|
| 279 | {
|
| 280 | ItemStack itemstack = null;
|
| 281 |
|
| 282 | try
|
| 283 | {
|
| 284 | NBTBase nbtbase = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());
|
| 285 |
|
| 286 | if (nbtbase instanceof NBTTagCompound)
|
| 287 | {
|
| 288 | itemstack = ItemStack.loadItemStackFromNBT((NBTTagCompound)nbtbase);
|
| 289 | }
|
| 290 | }
|
| 291 | catch (NBTException var11)
|
| 292 | {
|
| 293 | ;
|
| 294 | }
|
| 295 |
|
| 296 | if (itemstack != null)
|
| 297 | {
|
| 298 | this.renderToolTip(itemstack, x, y);
|
| 299 | }
|
| 300 | else
|
| 301 | {
|
| 302 | this.drawCreativeTabHoveringText(EnumChatFormatting.RED + "Invalid Item!", x, y);
|
| 303 | }
|
| 304 | }
|
| 305 | else if (hoverevent.getAction() == HoverEvent.Action.SHOW_ENTITY)
|
| 306 | {
|
| 307 | if (this.mc.gameSettings.advancedItemTooltips)
|
| 308 | {
|
| 309 | try
|
| 310 | {
|
| 311 | NBTBase nbtbase1 = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());
|
| 312 |
|
| 313 | if (nbtbase1 instanceof NBTTagCompound)
|
| 314 | {
|
| 315 | List<String> list1 = Lists.<String>newArrayList();
|
| 316 | NBTTagCompound nbttagcompound = (NBTTagCompound)nbtbase1;
|
| 317 | list1.add(nbttagcompound.getString("name"));
|
| 318 |
|
| 319 | if (nbttagcompound.hasKey("type", 8))
|
| 320 | {
|
| 321 | String s = nbttagcompound.getString("type");
|
| 322 | list1.add("Type: " + s + " (" + EntityList.getIDFromString(s) + ")");
|
| 323 | }
|
| 324 |
|
| 325 | list1.add(nbttagcompound.getString("id"));
|
| 326 | this.drawHoveringText(list1, x, y);
|
| 327 | }
|
| 328 | else
|
| 329 | {
|
| 330 | this.drawCreativeTabHoveringText(EnumChatFormatting.RED + "Invalid Entity!", x, y);
|
| 331 | }
|
| 332 | }
|
| 333 | catch (NBTException var10)
|
| 334 | {
|
| 335 | this.drawCreativeTabHoveringText(EnumChatFormatting.RED + "Invalid Entity!", x, y);
|
| 336 | }
|
| 337 | }
|
| 338 | }
|
| 339 | else if (hoverevent.getAction() == HoverEvent.Action.SHOW_TEXT)
|
| 340 | {
|
| 341 | this.drawHoveringText(NEWLINE_SPLITTER.splitToList(hoverevent.getValue().getFormattedText()), x, y);
|
| 342 | }
|
| 343 | else if (hoverevent.getAction() == HoverEvent.Action.SHOW_ACHIEVEMENT)
|
| 344 | {
|
| 345 | StatBase statbase = StatList.getOneShotStat(hoverevent.getValue().getUnformattedText());
|
| 346 |
|
| 347 | if (statbase != null)
|
| 348 | {
|
| 349 | IChatComponent ichatcomponent = statbase.getStatName();
|
| 350 | IChatComponent ichatcomponent1 = new ChatComponentTranslation("stats.tooltip.type." + (statbase.isAchievement() ? "achievement" : "statistic"), new Object[0]);
|
| 351 | ichatcomponent1.getChatStyle().setItalic(Boolean.valueOf(true));
|
| 352 | String s1 = statbase instanceof Achievement ? ((Achievement)statbase).getDescription() : null;
|
| 353 | List<String> list = Lists.newArrayList(new String[] {ichatcomponent.getFormattedText(), ichatcomponent1.getFormattedText()});
|
| 354 |
|
| 355 | if (s1 != null)
|
| 356 | {
|
| 357 | list.addAll(this.fontRendererObj.listFormattedStringToWidth(s1, 150));
|
| 358 | }
|
| 359 |
|
| 360 | this.drawHoveringText(list, x, y);
|
| 361 | }
|
| 362 | else
|
| 363 | {
|
| 364 | this.drawCreativeTabHoveringText(EnumChatFormatting.RED + "Invalid statistic/achievement!", x, y);
|
| 365 | }
|
| 366 | }
|
| 367 |
|
| 368 | GlStateManager.disableLighting();
|
| 369 | }
|
| 370 | }
|
| 371 |
|
| 372 | /**
|
| 373 | * Sets the text of the chat
|
| 374 | */
|
| 375 | protected void setText(String newChatText, boolean shouldOverwrite)
|
| 376 | {
|
| 377 | }
|
| 378 |
|
| 379 | /**
|
| 380 | * Executes the click event specified by the given chat component
|
| 381 | *
|
| 382 | * @param component The ChatComponent to check for click
|
| 383 | */
|
| 384 | protected boolean handleComponentClick(IChatComponent component)
|
| 385 | {
|
| 386 | if (component == null)
|
| 387 | {
|
| 388 | return false;
|
| 389 | }
|
| 390 | else
|
| 391 | {
|
| 392 | ClickEvent clickevent = component.getChatStyle().getChatClickEvent();
|
| 393 |
|
| 394 | if (isShiftKeyDown())
|
| 395 | {
|
| 396 | if (component.getChatStyle().getInsertion() != null)
|
| 397 | {
|
| 398 | this.setText(component.getChatStyle().getInsertion(), false);
|
| 399 | }
|
| 400 | }
|
| 401 | else if (clickevent != null)
|
| 402 | {
|
| 403 | if (clickevent.getAction() == ClickEvent.Action.OPEN_URL)
|
| 404 | {
|
| 405 | if (!this.mc.gameSettings.chatLinks)
|
| 406 | {
|
| 407 | return false;
|
| 408 | }
|
| 409 |
|
| 410 | try
|
| 411 | {
|
| 412 | URI uri = new URI(clickevent.getValue());
|
| 413 | String s = uri.getScheme();
|
| 414 |
|
| 415 | if (s == null)
|
| 416 | {
|
| 417 | throw new URISyntaxException(clickevent.getValue(), "Missing protocol");
|
| 418 | }
|
| 419 |
|
| 420 | if (!PROTOCOLS.contains(s.toLowerCase()))
|
| 421 | {
|
| 422 | throw new URISyntaxException(clickevent.getValue(), "Unsupported protocol: " + s.toLowerCase());
|
| 423 | }
|
| 424 |
|
| 425 | if (this.mc.gameSettings.chatLinksPrompt)
|
| 426 | {
|
| 427 | this.clickedLinkURI = uri;
|
| 428 | this.mc.displayGuiScreen(new GuiConfirmOpenLink(this, clickevent.getValue(), 31102009, false));
|
| 429 | }
|
| 430 | else
|
| 431 | {
|
| 432 | this.openWebLink(uri);
|
| 433 | }
|
| 434 | }
|
| 435 | catch (URISyntaxException urisyntaxexception)
|
| 436 | {
|
| 437 | LOGGER.error((String)("Can\'t open url for " + clickevent), (Throwable)urisyntaxexception);
|
| 438 | }
|
| 439 | }
|
| 440 | else if (clickevent.getAction() == ClickEvent.Action.OPEN_FILE)
|
| 441 | {
|
| 442 | URI uri1 = (new File(clickevent.getValue())).toURI();
|
| 443 | this.openWebLink(uri1);
|
| 444 | }
|
| 445 | else if (clickevent.getAction() == ClickEvent.Action.SUGGEST_COMMAND)
|
| 446 | {
|
| 447 | this.setText(clickevent.getValue(), true);
|
| 448 | }
|
| 449 | else if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
|
| 450 | {
|
| 451 | this.sendChatMessage(clickevent.getValue(), false);
|
| 452 | }
|
| 453 | else if (clickevent.getAction() == ClickEvent.Action.TWITCH_USER_INFO)
|
| 454 | {
|
| 455 | ChatUserInfo chatuserinfo = this.mc.getTwitchStream().func_152926_a(clickevent.getValue());
|
| 456 |
|
| 457 | if (chatuserinfo != null)
|
| 458 | {
|
| 459 | this.mc.displayGuiScreen(new GuiTwitchUserMode(this.mc.getTwitchStream(), chatuserinfo));
|
| 460 | }
|
| 461 | else
|
| 462 | {
|
| 463 | LOGGER.error("Tried to handle twitch user but couldn\'t find them!");
|
| 464 | }
|
| 465 | }
|
| 466 | else
|
| 467 | {
|
| 468 | LOGGER.error("Don\'t know how to handle " + clickevent);
|
| 469 | }
|
| 470 |
|
| 471 | return true;
|
| 472 | }
|
| 473 |
|
| 474 | return false;
|
| 475 | }
|
| 476 | }
|
| 477 |
|
| 478 | /**
|
| 479 | * Used to add chat messages to the client's GuiChat.
|
| 480 | */
|
| 481 | public void sendChatMessage(String msg)
|
| 482 | {
|
| 483 | this.sendChatMessage(msg, true);
|
| 484 | }
|
| 485 |
|
| 486 | public void sendChatMessage(String msg, boolean addToChat)
|
| 487 | {
|
| 488 | if (addToChat)
|
| 489 | {
|
| 490 | this.mc.ingameGUI.getChatGUI().addToSentMessages(msg);
|
| 491 | }
|
| 492 |
|
| 493 | this.mc.thePlayer.sendChatMessage(msg);
|
| 494 | }
|
| 495 |
|
| 496 | /**
|
| 497 | * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
|
| 498 | */
|
| 499 | protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
|
| 500 | {
|
| 501 | if (mouseButton == 0)
|
| 502 | {
|
| 503 | for (int i = 0; i < this.buttonList.size(); ++i)
|
| 504 | {
|
| 505 | GuiButton guibutton = (GuiButton)this.buttonList.get(i);
|
| 506 |
|
| 507 | if (guibutton.mousePressed(this.mc, mouseX, mouseY))
|
| 508 | {
|
| 509 | this.selectedButton = guibutton;
|
| 510 | guibutton.playPressSound(this.mc.getSoundHandler());
|
| 511 | this.actionPerformed(guibutton);
|
| 512 | }
|
| 513 | }
|
| 514 | }
|
| 515 | }
|
| 516 |
|
| 517 | /**
|
| 518 | * Called when a mouse button is released. Args : mouseX, mouseY, releaseButton
|
| 519 | */
|
| 520 | protected void mouseReleased(int mouseX, int mouseY, int state)
|
| 521 | {
|
| 522 | if (this.selectedButton != null && state == 0)
|
| 523 | {
|
| 524 | this.selectedButton.mouseReleased(mouseX, mouseY);
|
| 525 | this.selectedButton = null;
|
| 526 | }
|
| 527 | }
|
| 528 |
|
| 529 | /**
|
| 530 | * Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY,
|
| 531 | * lastButtonClicked & timeSinceMouseClick.
|
| 532 | */
|
| 533 | protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick)
|
| 534 | {
|
| 535 | }
|
| 536 |
|
| 537 | /**
|
| 538 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 539 | */
|
| 540 | protected void actionPerformed(GuiButton button) throws IOException
|
| 541 | {
|
| 542 | }
|
| 543 |
|
| 544 | /**
|
| 545 | * Causes the screen to lay out its subcomponents again. This is the equivalent of the Java call
|
| 546 | * Container.validate()
|
| 547 | */
|
| 548 | public void setWorldAndResolution(Minecraft mc, int width, int height)
|
| 549 | {
|
| 550 | this.mc = mc;
|
| 551 | this.itemRender = mc.getRenderItem();
|
| 552 | this.fontRendererObj = mc.fontRendererObj;
|
| 553 | this.width = width;
|
| 554 | this.height = height;
|
| 555 | this.buttonList.clear();
|
| 556 | this.initGui();
|
| 557 | }
|
| 558 |
|
| 559 | /**
|
| 560 | * Set the gui to the specified width and height
|
| 561 | *
|
| 562 | * @param w The width of the screen
|
| 563 | * @param h The height of the screen
|
| 564 | */
|
| 565 | public void setGuiSize(int w, int h)
|
| 566 | {
|
| 567 | this.width = w;
|
| 568 | this.height = h;
|
| 569 | }
|
| 570 |
|
| 571 | /**
|
| 572 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 573 | * window resizes, the buttonList is cleared beforehand.
|
| 574 | */
|
| 575 | public void initGui()
|
| 576 | {
|
| 577 | }
|
| 578 |
|
| 579 | /**
|
| 580 | * Delegates mouse and keyboard input.
|
| 581 | */
|
| 582 | public void handleInput() throws IOException
|
| 583 | {
|
| 584 | if (Mouse.isCreated())
|
| 585 | {
|
| 586 | while (Mouse.next())
|
| 587 | {
|
| 588 | this.handleMouseInput();
|
| 589 | }
|
| 590 | }
|
| 591 |
|
| 592 | if (Keyboard.isCreated())
|
| 593 | {
|
| 594 | while (Keyboard.next())
|
| 595 | {
|
| 596 | this.handleKeyboardInput();
|
| 597 | }
|
| 598 | }
|
| 599 | }
|
| 600 |
|
| 601 | /**
|
| 602 | * Handles mouse input.
|
| 603 | */
|
| 604 | public void handleMouseInput() throws IOException
|
| 605 | {
|
| 606 | int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
| 607 | int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
| 608 | int k = Mouse.getEventButton();
|
| 609 |
|
| 610 | if (Mouse.getEventButtonState())
|
| 611 | {
|
| 612 | if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
|
| 613 | {
|
| 614 | return;
|
| 615 | }
|
| 616 |
|
| 617 | this.eventButton = k;
|
| 618 | this.lastMouseEvent = Minecraft.getSystemTime();
|
| 619 | this.mouseClicked(i, j, this.eventButton);
|
| 620 | }
|
| 621 | else if (k != -1)
|
| 622 | {
|
| 623 | if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
|
| 624 | {
|
| 625 | return;
|
| 626 | }
|
| 627 |
|
| 628 | this.eventButton = -1;
|
| 629 | this.mouseReleased(i, j, k);
|
| 630 | }
|
| 631 | else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
|
| 632 | {
|
| 633 | long l = Minecraft.getSystemTime() - this.lastMouseEvent;
|
| 634 | this.mouseClickMove(i, j, this.eventButton, l);
|
| 635 | }
|
| 636 | }
|
| 637 |
|
| 638 | /**
|
| 639 | * Handles keyboard input.
|
| 640 | */
|
| 641 | public void handleKeyboardInput() throws IOException
|
| 642 | {
|
| 643 | if (Keyboard.getEventKeyState())
|
| 644 | {
|
| 645 | this.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
|
| 646 | }
|
| 647 |
|
| 648 | this.mc.dispatchKeypresses();
|
| 649 | }
|
| 650 |
|
| 651 | /**
|
| 652 | * Called from the main game loop to update the screen.
|
| 653 | */
|
| 654 | public void updateScreen()
|
| 655 | {
|
| 656 | }
|
| 657 |
|
| 658 | /**
|
| 659 | * Called when the screen is unloaded. Used to disable keyboard repeat events
|
| 660 | */
|
| 661 | public void onGuiClosed()
|
| 662 | {
|
| 663 | }
|
| 664 |
|
| 665 | /**
|
| 666 | * Draws either a gradient over the background screen (when it exists) or a flat gradient over background.png
|
| 667 | */
|
| 668 | public void drawDefaultBackground()
|
| 669 | {
|
| 670 | this.drawWorldBackground(0);
|
| 671 | }
|
| 672 |
|
| 673 | public void drawWorldBackground(int tint)
|
| 674 | {
|
| 675 | if (this.mc.theWorld != null)
|
| 676 | {
|
| 677 | this.drawGradientRect(0, 0, this.width, this.height, -1072689136, -804253680);
|
| 678 | }
|
| 679 | else
|
| 680 | {
|
| 681 | this.drawBackground(tint);
|
| 682 | }
|
| 683 | }
|
| 684 |
|
| 685 | /**
|
| 686 | * Draws the background (i is always 0 as of 1.2.2)
|
| 687 | */
|
| 688 | public void drawBackground(int tint)
|
| 689 | {
|
| 690 | GlStateManager.disableLighting();
|
| 691 | GlStateManager.disableFog();
|
| 692 | Tessellator tessellator = Tessellator.getInstance();
|
| 693 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 694 | this.mc.getTextureManager().bindTexture(optionsBackground);
|
| 695 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 696 | float f = 32.0F;
|
| 697 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
| 698 | worldrenderer.pos(0.0D, (double)this.height, 0.0D).tex(0.0D, (double)((float)this.height / 32.0F + (float)tint)).color(64, 64, 64, 255).endVertex();
|
| 699 | worldrenderer.pos((double)this.width, (double)this.height, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)this.height / 32.0F + (float)tint)).color(64, 64, 64, 255).endVertex();
|
| 700 | worldrenderer.pos((double)this.width, 0.0D, 0.0D).tex((double)((float)this.width / 32.0F), (double)tint).color(64, 64, 64, 255).endVertex();
|
| 701 | worldrenderer.pos(0.0D, 0.0D, 0.0D).tex(0.0D, (double)tint).color(64, 64, 64, 255).endVertex();
|
| 702 | tessellator.draw();
|
| 703 | }
|
| 704 |
|
| 705 | /**
|
| 706 | * Returns true if this GUI should pause the game when it is displayed in single-player
|
| 707 | */
|
| 708 | public boolean doesGuiPauseGame()
|
| 709 | {
|
| 710 | return true;
|
| 711 | }
|
| 712 |
|
| 713 | public void confirmClicked(boolean result, int id)
|
| 714 | {
|
| 715 | if (id == 31102009)
|
| 716 | {
|
| 717 | if (result)
|
| 718 | {
|
| 719 | this.openWebLink(this.clickedLinkURI);
|
| 720 | }
|
| 721 |
|
| 722 | this.clickedLinkURI = null;
|
| 723 | this.mc.displayGuiScreen(this);
|
| 724 | }
|
| 725 | }
|
| 726 |
|
| 727 | private void openWebLink(URI url)
|
| 728 | {
|
| 729 | try
|
| 730 | {
|
| 731 | Class<?> oclass = Class.forName("java.awt.Desktop");
|
| 732 | Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
|
| 733 | oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {url});
|
| 734 | }
|
| 735 | catch (Throwable throwable)
|
| 736 | {
|
| 737 | LOGGER.error("Couldn\'t open link", throwable);
|
| 738 | }
|
| 739 | }
|
| 740 |
|
| 741 | /**
|
| 742 | * Returns true if either windows ctrl key is down or if either mac meta key is down
|
| 743 | */
|
| 744 | public static boolean isCtrlKeyDown()
|
| 745 | {
|
| 746 | return Minecraft.isRunningOnMac ? Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220) : Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157);
|
| 747 | }
|
| 748 |
|
| 749 | /**
|
| 750 | * Returns true if either shift key is down
|
| 751 | */
|
| 752 | public static boolean isShiftKeyDown()
|
| 753 | {
|
| 754 | return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54);
|
| 755 | }
|
| 756 |
|
| 757 | /**
|
| 758 | * Returns true if either alt key is down
|
| 759 | */
|
| 760 | public static boolean isAltKeyDown()
|
| 761 | {
|
| 762 | return Keyboard.isKeyDown(56) || Keyboard.isKeyDown(184);
|
| 763 | }
|
| 764 |
|
| 765 | public static boolean isKeyComboCtrlX(int keyID)
|
| 766 | {
|
| 767 | return keyID == 45 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
| 768 | }
|
| 769 |
|
| 770 | public static boolean isKeyComboCtrlV(int keyID)
|
| 771 | {
|
| 772 | return keyID == 47 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
| 773 | }
|
| 774 |
|
| 775 | public static boolean isKeyComboCtrlC(int keyID)
|
| 776 | {
|
| 777 | return keyID == 46 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
| 778 | }
|
| 779 |
|
| 780 | public static boolean isKeyComboCtrlA(int keyID)
|
| 781 | {
|
| 782 | return keyID == 30 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
|
| 783 | }
|
| 784 |
|
| 785 | /**
|
| 786 | * Called when the GUI is resized in order to update the world and the resolution
|
| 787 | *
|
| 788 | * @param w The width of the screen
|
| 789 | * @param h The height of the screen
|
| 790 | */
|
| 791 | public void onResize(Minecraft mcIn, int w, int h)
|
| 792 | {
|
| 793 | this.setWorldAndResolution(mcIn, w, h);
|
| 794 | }
|
| 795 | }
|
| 796 |
|