From ecd6f4c1d24bfc6640d9866af7ac63dac11369f1 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 23 Mar 2016 14:48:29 +0100 Subject: [PATCH] Add flashing update notification icon made by @gigaherz, closes #2582 It is added to the "Mods" button in the main menu and to out-of-date mods in the mod list (there it replaces the "U"). Also fixes a little typo. --- .../client/gui/GuiMainMenu.java.patch | 32 ++++++- .../gui/NotificationModUpdateScreen.java | 83 ++++++++++++++++++ .../minecraftforge/common/ForgeVersion.java | 55 ++++++++++-- .../minecraftforge/fml/client/GuiModList.java | 7 +- .../fml/client/GuiSlotModList.java | 33 +++---- .../textures/gui/version_check_icons.png | Bin 0 -> 463 bytes 6 files changed, 181 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/minecraftforge/client/gui/NotificationModUpdateScreen.java create mode 100644 src/main/resources/assets/forge/textures/gui/version_check_icons.png diff --git a/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.java.patch b/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.java.patch index 08c531721..4ffa6d84a 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.java.patch +++ b/patches/minecraft/net/minecraft/client/gui/GuiMainMenu.java.patch @@ -1,16 +1,32 @@ --- ../src-base/minecraft/net/minecraft/client/gui/GuiMainMenu.java +++ ../src-work/minecraft/net/minecraft/client/gui/GuiMainMenu.java -@@ -216,7 +216,8 @@ +@@ -67,6 +67,8 @@ + private GuiButton field_175372_K; + private boolean field_183502_L; + private GuiScreen field_183503_M; ++ private GuiButton modButton; ++ private net.minecraftforge.client.gui.NotificationModUpdateScreen modUpdateNotification; + + public GuiMainMenu() + { +@@ -210,13 +212,15 @@ + this.field_183503_M.func_183500_a(this.field_146294_l, this.field_146295_m); + this.field_183503_M.func_73866_w_(); + } ++ modUpdateNotification = net.minecraftforge.client.gui.NotificationModUpdateScreen.init(this, modButton); + } + + private void func_73969_a(int p_73969_1_, int p_73969_2_) { this.field_146292_n.add(new GuiButton(1, this.field_146294_l / 2 - 100, p_73969_1_, I18n.func_135052_a("menu.singleplayer", new Object[0]))); this.field_146292_n.add(new GuiButton(2, this.field_146294_l / 2 - 100, p_73969_1_ + p_73969_2_ * 1, I18n.func_135052_a("menu.multiplayer", new Object[0]))); - this.field_146292_n.add(this.field_175372_K = new GuiButton(14, this.field_146294_l / 2 - 100, p_73969_1_ + p_73969_2_ * 2, I18n.func_135052_a("menu.online", new Object[0]))); + this.field_146292_n.add(this.field_175372_K = new GuiButton(14, this.field_146294_l / 2 + 2, p_73969_1_ + p_73969_2_ * 2, 98, 20, I18n.func_135052_a("menu.online", new Object[0]).replace("Minecraft", "").trim())); -+ this.field_146292_n.add(new GuiButton(6, this.field_146294_l / 2 - 100, p_73969_1_ + p_73969_2_ * 2, 98, 20, I18n.func_135052_a("fml.menu.mods"))); ++ this.field_146292_n.add(modButton = new GuiButton(6, this.field_146294_l / 2 - 100, p_73969_1_ + p_73969_2_ * 2, 98, 20, I18n.func_135052_a("fml.menu.mods"))); } private void func_73972_b(int p_73972_1_, int p_73972_2_) -@@ -264,6 +265,11 @@ +@@ -264,6 +268,11 @@ this.field_146297_k.func_71400_g(); } @@ -22,7 +38,7 @@ if (p_146284_1_.field_146127_k == 11) { this.field_146297_k.func_71371_a("Demo_World", "Demo_World", DemoWorldServer.field_73071_a); -@@ -512,7 +518,16 @@ +@@ -512,7 +521,16 @@ s = s + ("release".equalsIgnoreCase(this.field_146297_k.func_184123_d()) ? "" : "/" + this.field_146297_k.func_184123_d()); } @@ -40,3 +56,11 @@ String s1 = "Copyright Mojang AB. Do not distribute!"; this.func_73731_b(this.field_146289_q, s1, this.field_146294_l - this.field_146289_q.func_78256_a(s1) - 2, this.field_146295_m - 10, -1); +@@ -529,6 +547,7 @@ + { + this.field_183503_M.func_73863_a(p_73863_1_, p_73863_2_, p_73863_3_); + } ++ modUpdateNotification.func_73863_a(p_73863_1_, p_73863_2_, p_73863_3_); + } + + protected void func_73864_a(int p_73864_1_, int p_73864_2_, int p_73864_3_) throws IOException diff --git a/src/main/java/net/minecraftforge/client/gui/NotificationModUpdateScreen.java b/src/main/java/net/minecraftforge/client/gui/NotificationModUpdateScreen.java new file mode 100644 index 000000000..33f533c6c --- /dev/null +++ b/src/main/java/net/minecraftforge/client/gui/NotificationModUpdateScreen.java @@ -0,0 +1,83 @@ +package net.minecraftforge.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.ForgeModContainer; +import net.minecraftforge.common.ForgeVersion; +import net.minecraftforge.common.ForgeVersion.Status; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class NotificationModUpdateScreen extends GuiScreen +{ + + private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation("forge", "textures/gui/version_check_icons.png"); + + private final GuiButton modButton; + private Status showNotification = null; + private boolean hasCheckedForUpdates = false; + + public NotificationModUpdateScreen(GuiButton modButton) + { + this.modButton = modButton; + } + + @Override + public void initGui() + { + if (!hasCheckedForUpdates) + { + if (modButton != null) + { + for (ModContainer mod : Loader.instance().getModList()) + { + Status status = ForgeVersion.getResult(mod).status; + if (status == Status.OUTDATED || status == Status.BETA_OUTDATED) + { + // TODO: Needs better visualization, maybe stacked icons + // drawn in a terrace-like pattern? + showNotification = Status.OUTDATED; + } + } + } + hasCheckedForUpdates = true; + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) + { + if (showNotification == null || !showNotification.shouldDraw() || ForgeModContainer.disableVersionCheck) + { + return; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(VERSION_CHECK_ICONS); + GlStateManager.color(1, 1, 1, 1); + GlStateManager.pushMatrix(); + + int x = modButton.xPosition; + int y = modButton.yPosition; + int w = modButton.width; + int h = modButton.height; + + drawModalRectWithCustomSizedTexture(x + w - (h / 2 + 4), y + (h / 2 - 4), showNotification.getSheetOffset() * 8, (showNotification.isAnimated() && ((System.currentTimeMillis() / 800 & 1) == 1)) ? 8 : 0, 8, 8, 64, 16); + GlStateManager.popMatrix(); + } + + public static NotificationModUpdateScreen init(GuiMainMenu guiMainMenu, GuiButton modButton) + { + NotificationModUpdateScreen notificationModUpdateScreen = new NotificationModUpdateScreen(modButton); + notificationModUpdateScreen.setGuiSize(guiMainMenu.width, guiMainMenu.height); + notificationModUpdateScreen.initGui(); + return notificationModUpdateScreen; + } + +} diff --git a/src/main/java/net/minecraftforge/common/ForgeVersion.java b/src/main/java/net/minecraftforge/common/ForgeVersion.java index 966098900..13137562f 100644 --- a/src/main/java/net/minecraftforge/common/ForgeVersion.java +++ b/src/main/java/net/minecraftforge/common/ForgeVersion.java @@ -85,13 +85,54 @@ public class ForgeVersion public static enum Status { - PENDING, - FAILED, - UP_TO_DATE, - OUTDATED, - AHEAD, - BETA, - BETA_OUTDATED + PENDING(), + FAILED(), + UP_TO_DATE(), + OUTDATED(3, true), + AHEAD(), + BETA(), + BETA_OUTDATED(6, true); + + final int sheetOffset; + final boolean draw, animated; + + Status() + { + this(0, false, false); + } + + Status(int sheetOffset) + { + this(sheetOffset, true, false); + } + + Status(int sheetOffset, boolean animated) + { + this(sheetOffset, true, animated); + } + + Status(int sheetOffset, boolean draw, boolean animated) + { + this.sheetOffset = sheetOffset; + this.draw = draw; + this.animated = animated; + } + + public int getSheetOffset() + { + return sheetOffset; + } + + public boolean shouldDraw() + { + return draw; + } + + public boolean isAnimated() + { + return animated; + } + } public static class CheckResult diff --git a/src/main/java/net/minecraftforge/fml/client/GuiModList.java b/src/main/java/net/minecraftforge/fml/client/GuiModList.java index 0f67480e6..e8f6d2c6d 100644 --- a/src/main/java/net/minecraftforge/fml/client/GuiModList.java +++ b/src/main/java/net/minecraftforge/fml/client/GuiModList.java @@ -153,13 +153,14 @@ public class GuiModList extends GuiScreen @Override public void initGui() { + int slotHeight = 35; for (ModContainer mod : mods) { listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getName()) + 10); - listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 10); + listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 5 + slotHeight); } listWidth = Math.min(listWidth, 150); - this.modList = new GuiSlotModList(this, mods, listWidth); + this.modList = new GuiSlotModList(this, mods, listWidth, slotHeight); this.buttonList.add(new GuiButton(6, ((modList.right + this.width) / 2) - 100, this.height - 38, I18n.format("gui.done"))); configModButton = new GuiButton(20, 10, this.height - 49, this.listWidth, 20, "Config"); @@ -414,7 +415,7 @@ public class GuiModList extends GuiScreen lines.add("Child mods: " + selectedMod.getMetadata().getChildModList()); if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED) - lines.add("Update Avalible: " + (vercheck.url == null ? "" : vercheck.url)); + lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url)); lines.add(null); lines.add(selectedMod.getMetadata().description); diff --git a/src/main/java/net/minecraftforge/fml/client/GuiSlotModList.java b/src/main/java/net/minecraftforge/fml/client/GuiSlotModList.java index 90198e1d2..45bbb2e4f 100644 --- a/src/main/java/net/minecraftforge/fml/client/GuiSlotModList.java +++ b/src/main/java/net/minecraftforge/fml/client/GuiSlotModList.java @@ -14,8 +14,12 @@ package net.minecraftforge.fml.client; import java.util.ArrayList; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; import net.minecraftforge.common.ForgeVersion; import net.minecraftforge.common.ForgeVersion.CheckResult; @@ -29,12 +33,15 @@ import net.minecraftforge.fml.common.ModContainer; */ public class GuiSlotModList extends GuiScrollingList { + + private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation("forge", "textures/gui/version_check_icons.png"); + private GuiModList parent; private ArrayList mods; - public GuiSlotModList(GuiModList parent, ArrayList mods, int listWidth) + public GuiSlotModList(GuiModList parent, ArrayList mods, int listWidth, int slotHeight) { - super(parent.getMinecraftInstance(), listWidth, parent.height, 32, parent.height - 88 + 4, 10, 35, parent.width, parent.height); + super(parent.getMinecraftInstance(), listWidth, parent.height, 32, parent.height - 88 + 4, 10, slotHeight, parent.width, parent.height); this.parent = parent; this.mods = mods; } @@ -86,27 +93,23 @@ public class GuiSlotModList extends GuiScrollingList if (Loader.instance().getModState(mc) == ModState.DISABLED) { font.drawString(font.trimStringToWidth(name, listWidth - 10), this.left + 3 , top + 2, 0xFF2222); - font.drawString(font.trimStringToWidth(version, listWidth - 10), this.left + 3 , top + 12, 0xFF2222); + font.drawString(font.trimStringToWidth(version, listWidth - (5 + height)), this.left + 3 , top + 12, 0xFF2222); font.drawString(font.trimStringToWidth("DISABLED", listWidth - 10), this.left + 3 , top + 22, 0xFF2222); } else { font.drawString(font.trimStringToWidth(name, listWidth - 10), this.left + 3 , top + 2, 0xFFFFFF); - font.drawString(font.trimStringToWidth(version, listWidth - 10), this.left + 3 , top + 12, 0xCCCCCC); + font.drawString(font.trimStringToWidth(version, listWidth - (5 + height)), this.left + 3 , top + 12, 0xCCCCCC); font.drawString(font.trimStringToWidth(mc.getMetadata() != null ? mc.getMetadata().getChildModCountString() : "Metadata not found", listWidth - 10), this.left + 3 , top + 22, 0xCCCCCC); - switch(vercheck.status) //TODO: Change to icons? + if (vercheck.status.shouldDraw()) { - case BETA_OUTDATED: - case OUTDATED: - font.drawString("U", right - font.getCharWidth('U') - 1, top+height-font.FONT_HEIGHT+2, 0x22FF22); - break; - case AHEAD: - case BETA: - case FAILED: - case PENDING: - case UP_TO_DATE: - break; + //TODO: Consider adding more icons for visualization + Minecraft.getMinecraft().getTextureManager().bindTexture(VERSION_CHECK_ICONS); + GlStateManager.color(1, 1, 1, 1); + GlStateManager.pushMatrix(); + Gui.drawModalRectWithCustomSizedTexture(right - (height / 2 + 4), top + (height / 2 - 4), vercheck.status.getSheetOffset() * 8, (vercheck.status.isAnimated() && ((System.currentTimeMillis() / 800 & 1)) == 1) ? 8 : 0, 8, 8, 64, 16); + GlStateManager.popMatrix(); } } } diff --git a/src/main/resources/assets/forge/textures/gui/version_check_icons.png b/src/main/resources/assets/forge/textures/gui/version_check_icons.png new file mode 100644 index 0000000000000000000000000000000000000000..5d5f0fa294faae8783568e467e6123e5ad40b859 GIT binary patch literal 463 zcmV;=0WkiFP)vp|DPy ze?afP+q>}AADoYS-}!_jOdVMk0sym=!1yGMe29aOZ1RF7A`S+{Hx@qsdB@dyhB%!j zcE*VreM9i#hfG}ir)(4F-4YVR^GMDmfJi^EI0}gg|Jx6lc>A_9q zojqRhp2_wuaX7)~_LP<(c=e6!0SE4_uX}(O-}eDn3ziHP8*tx0dOaO=!bp#7z*@58 zzkOphXy