| 1 | package net.minecraft.client.gui.achievement;
|
| 2 |
|
| 3 | import net.minecraft.client.Minecraft;
|
| 4 | import net.minecraft.client.gui.Gui;
|
| 5 | import net.minecraft.client.gui.ScaledResolution;
|
| 6 | import net.minecraft.client.renderer.GlStateManager;
|
| 7 | import net.minecraft.client.renderer.RenderHelper;
|
| 8 | import net.minecraft.client.renderer.entity.RenderItem;
|
| 9 | import net.minecraft.client.resources.I18n;
|
| 10 | import net.minecraft.stats.Achievement;
|
| 11 | import net.minecraft.util.ResourceLocation;
|
| 12 |
|
| 13 | public class GuiAchievement extends Gui
|
| 14 | {
|
| 15 | private static final ResourceLocation achievementBg = new ResourceLocation("textures/gui/achievement/achievement_background.png");
|
| 16 | private Minecraft mc;
|
| 17 | private int width;
|
| 18 | private int height;
|
| 19 | private String achievementTitle;
|
| 20 | private String achievementDescription;
|
| 21 | private Achievement theAchievement;
|
| 22 | private long notificationTime;
|
| 23 | private RenderItem renderItem;
|
| 24 | private boolean permanentNotification;
|
| 25 |
|
| 26 | public GuiAchievement(Minecraft mc)
|
| 27 | {
|
| 28 | this.mc = mc;
|
| 29 | this.renderItem = mc.getRenderItem();
|
| 30 | }
|
| 31 |
|
| 32 | public void displayAchievement(Achievement ach)
|
| 33 | {
|
| 34 | this.achievementTitle = I18n.format("achievement.get", new Object[0]);
|
| 35 | this.achievementDescription = ach.getStatName().getUnformattedText();
|
| 36 | this.notificationTime = Minecraft.getSystemTime();
|
| 37 | this.theAchievement = ach;
|
| 38 | this.permanentNotification = false;
|
| 39 | }
|
| 40 |
|
| 41 | public void displayUnformattedAchievement(Achievement achievementIn)
|
| 42 | {
|
| 43 | this.achievementTitle = achievementIn.getStatName().getUnformattedText();
|
| 44 | this.achievementDescription = achievementIn.getDescription();
|
| 45 | this.notificationTime = Minecraft.getSystemTime() + 2500L;
|
| 46 | this.theAchievement = achievementIn;
|
| 47 | this.permanentNotification = true;
|
| 48 | }
|
| 49 |
|
| 50 | private void updateAchievementWindowScale()
|
| 51 | {
|
| 52 | GlStateManager.viewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
|
| 53 | GlStateManager.matrixMode(5889);
|
| 54 | GlStateManager.loadIdentity();
|
| 55 | GlStateManager.matrixMode(5888);
|
| 56 | GlStateManager.loadIdentity();
|
| 57 | this.width = this.mc.displayWidth;
|
| 58 | this.height = this.mc.displayHeight;
|
| 59 | ScaledResolution scaledresolution = new ScaledResolution(this.mc);
|
| 60 | this.width = scaledresolution.getScaledWidth();
|
| 61 | this.height = scaledresolution.getScaledHeight();
|
| 62 | GlStateManager.clear(256);
|
| 63 | GlStateManager.matrixMode(5889);
|
| 64 | GlStateManager.loadIdentity();
|
| 65 | GlStateManager.ortho(0.0D, (double)this.width, (double)this.height, 0.0D, 1000.0D, 3000.0D);
|
| 66 | GlStateManager.matrixMode(5888);
|
| 67 | GlStateManager.loadIdentity();
|
| 68 | GlStateManager.translate(0.0F, 0.0F, -2000.0F);
|
| 69 | }
|
| 70 |
|
| 71 | public void updateAchievementWindow()
|
| 72 | {
|
| 73 | if (this.theAchievement != null && this.notificationTime != 0L && Minecraft.getMinecraft().thePlayer != null)
|
| 74 | {
|
| 75 | double d0 = (double)(Minecraft.getSystemTime() - this.notificationTime) / 3000.0D;
|
| 76 |
|
| 77 | if (!this.permanentNotification)
|
| 78 | {
|
| 79 | if (d0 < 0.0D || d0 > 1.0D)
|
| 80 | {
|
| 81 | this.notificationTime = 0L;
|
| 82 | return;
|
| 83 | }
|
| 84 | }
|
| 85 | else if (d0 > 0.5D)
|
| 86 | {
|
| 87 | d0 = 0.5D;
|
| 88 | }
|
| 89 |
|
| 90 | this.updateAchievementWindowScale();
|
| 91 | GlStateManager.disableDepth();
|
| 92 | GlStateManager.depthMask(false);
|
| 93 | double d1 = d0 * 2.0D;
|
| 94 |
|
| 95 | if (d1 > 1.0D)
|
| 96 | {
|
| 97 | d1 = 2.0D - d1;
|
| 98 | }
|
| 99 |
|
| 100 | d1 = d1 * 4.0D;
|
| 101 | d1 = 1.0D - d1;
|
| 102 |
|
| 103 | if (d1 < 0.0D)
|
| 104 | {
|
| 105 | d1 = 0.0D;
|
| 106 | }
|
| 107 |
|
| 108 | d1 = d1 * d1;
|
| 109 | d1 = d1 * d1;
|
| 110 | int i = this.width - 160;
|
| 111 | int j = 0 - (int)(d1 * 36.0D);
|
| 112 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 113 | GlStateManager.enableTexture2D();
|
| 114 | this.mc.getTextureManager().bindTexture(achievementBg);
|
| 115 | GlStateManager.disableLighting();
|
| 116 | this.drawTexturedModalRect(i, j, 96, 202, 160, 32);
|
| 117 |
|
| 118 | if (this.permanentNotification)
|
| 119 | {
|
| 120 | this.mc.fontRendererObj.drawSplitString(this.achievementDescription, i + 30, j + 7, 120, -1);
|
| 121 | }
|
| 122 | else
|
| 123 | {
|
| 124 | this.mc.fontRendererObj.drawString(this.achievementTitle, i + 30, j + 7, -256);
|
| 125 | this.mc.fontRendererObj.drawString(this.achievementDescription, i + 30, j + 18, -1);
|
| 126 | }
|
| 127 |
|
| 128 | RenderHelper.enableGUIStandardItemLighting();
|
| 129 | GlStateManager.disableLighting();
|
| 130 | GlStateManager.enableRescaleNormal();
|
| 131 | GlStateManager.enableColorMaterial();
|
| 132 | GlStateManager.enableLighting();
|
| 133 | this.renderItem.renderItemAndEffectIntoGUI(this.theAchievement.theItemStack, i + 8, j + 8);
|
| 134 | GlStateManager.disableLighting();
|
| 135 | GlStateManager.depthMask(true);
|
| 136 | GlStateManager.enableDepth();
|
| 137 | }
|
| 138 | }
|
| 139 |
|
| 140 | public void clearAchievements()
|
| 141 | {
|
| 142 | this.theAchievement = null;
|
| 143 | this.notificationTime = 0L;
|
| 144 | }
|
| 145 | }
|
| 146 |
|