Added "Update available"-button to the booklet

This commit is contained in:
Ellpeck 2015-09-02 20:06:34 +02:00
parent 935ca93c0f
commit 0f641f424f
6 changed files with 131 additions and 60 deletions

View file

@ -40,6 +40,7 @@ import ellpeck.actuallyadditions.recipe.FuelHandler;
import ellpeck.actuallyadditions.recipe.HairyBallHandler;
import ellpeck.actuallyadditions.recipe.TreasureChestHandler;
import ellpeck.actuallyadditions.tile.TileEntityBase;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util;
// So that BuildCraft Oil always gets used
@ -64,6 +65,7 @@ public class ActuallyAdditions{
InitItems.init();
InitVillager.init();
FuelHandler.init();
new UpdateChecker().init();
proxy.preInit(event);
ModUtil.LOGGER.info("PreInitialization Finished.");

View file

@ -14,6 +14,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.booklet.page.IBookletPage;
import ellpeck.actuallyadditions.config.GuiConfiguration;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.util.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@ -51,17 +52,19 @@ public class GuiBooklet extends GuiScreen{
private GuiTextField searchField;
private static final int BUTTON_TWITTER_ID = -4;
private static final int BUTTON_FORUM_ID = -3;
private static final int BUTTON_ACHIEVEMENTS_ID = -2;
private static final int BUTTON_CONFIG_ID = -1;
private static final int BUTTON_FORWARD_ID = 0;
private static final int BUTTON_BACK_ID = 1;
private static final int BUTTON_RETURN_ID = 2;
private static final int CHAPTER_BUTTONS_START = 3;
private static final int BUTTONS_PER_PAGE = 13;
private static final int BUTTON_UPDATE_ID = CHAPTER_BUTTONS_START+BUTTONS_PER_PAGE;
private static final int BUTTON_TWITTER_ID = BUTTON_UPDATE_ID+1;
private static final int BUTTON_FORUM_ID = BUTTON_TWITTER_ID+1;
private static final int BUTTON_ACHIEVEMENTS_ID = BUTTON_FORUM_ID+1;
private static final int BUTTON_CONFIG_ID = BUTTON_ACHIEVEMENTS_ID+1;
private int cursorCounter;
private boolean mouseClicked;
public GuiBooklet(){
@ -73,6 +76,16 @@ public class GuiBooklet extends GuiScreen{
public void updateScreen(){
super.updateScreen();
this.searchField.updateCursorCounter();
boolean buttonThere = UpdateChecker.doneChecking && UpdateChecker.updateVersion > UpdateChecker.clientVersion;
this.getButton(BUTTON_UPDATE_ID).visible = buttonThere;
if(buttonThere){
this.cursorCounter++;
if(this.cursorCounter%8 == 0){
TexturedButton button = (TexturedButton)this.getButton(BUTTON_UPDATE_ID);
button.setTexturePos(245, button.texturePosY == 0 ? 22 : 0);
}
}
}
@SuppressWarnings("unchecked")
@ -125,18 +138,21 @@ public class GuiBooklet extends GuiScreen{
this.unicodeRenderer = new FontRenderer(this.mc.gameSettings, new ResourceLocation("textures/font/ascii.png"), this.mc.renderEngine, true);
this.buttonList.add(new TexturedButton(BUTTON_FORWARD_ID, this.guiLeft+this.xSize, this.guiTop+this.ySize+2, 164, 0, 18, 10));
this.buttonList.add(new TexturedButton(BUTTON_BACK_ID, this.guiLeft-18, this.guiTop+this.ySize+2, 146, 0, 18, 10));
this.buttonList.add(new TexturedButton(BUTTON_RETURN_ID, this.guiLeft+this.xSize/2-7, this.guiTop+this.ySize+2, 182, 0, 15, 10));
this.addButton(new TexturedButton(BUTTON_FORWARD_ID, this.guiLeft+this.xSize, this.guiTop+this.ySize+2, 164, 0, 18, 10));
this.addButton(new TexturedButton(BUTTON_BACK_ID, this.guiLeft-18, this.guiTop+this.ySize+2, 146, 0, 18, 10));
this.addButton(new TexturedButton(BUTTON_RETURN_ID, this.guiLeft+this.xSize/2-7, this.guiTop+this.ySize+2, 182, 0, 15, 10));
for(int i = 0; i < BUTTONS_PER_PAGE; i++){
this.buttonList.add(new IndexButton(this.unicodeRenderer, CHAPTER_BUTTONS_START+i, guiLeft+15, guiTop+10+(i*12), 110, 10, ""));
this.addButton(new IndexButton(this.unicodeRenderer, CHAPTER_BUTTONS_START+i, guiLeft+15, guiTop+10+(i*12), 110, 10, ""));
}
this.buttonList.add(new TexturedButton(BUTTON_ACHIEVEMENTS_ID, this.guiLeft+138, this.guiTop, 205, 0, 8, 8));
this.buttonList.add(new TexturedButton(BUTTON_CONFIG_ID, this.guiLeft+138, this.guiTop+10, 197, 0, 8, 8));
this.buttonList.add(new TexturedButton(BUTTON_TWITTER_ID, this.guiLeft, this.guiTop, 213, 0, 8, 8));
this.buttonList.add(new TexturedButton(BUTTON_FORUM_ID, this.guiLeft, this.guiTop+10, 221, 0, 8, 8));
this.addButton(new TexturedButton(BUTTON_UPDATE_ID, this.guiLeft-11, this.guiTop-11, 245, 0, 11, 11));
this.getButton(BUTTON_UPDATE_ID).visible = UpdateChecker.doneChecking && UpdateChecker.updateVersion > UpdateChecker.clientVersion;
this.addButton(new TexturedButton(BUTTON_TWITTER_ID, this.guiLeft, this.guiTop, 213, 0, 8, 8));
this.addButton(new TexturedButton(BUTTON_FORUM_ID, this.guiLeft, this.guiTop+10, 221, 0, 8, 8));
this.addButton(new TexturedButton(BUTTON_ACHIEVEMENTS_ID, this.guiLeft+138, this.guiTop, 205, 0, 8, 8));
this.addButton(new TexturedButton(BUTTON_CONFIG_ID, this.guiLeft+138, this.guiTop+10, 197, 0, 8, 8));
this.searchField = new GuiTextField(this.unicodeRenderer, guiLeft+148, guiTop+162, 66, 10);
this.searchField.setMaxStringLength(30);
@ -157,6 +173,16 @@ public class GuiBooklet extends GuiScreen{
}
}
@SuppressWarnings("unchecked")
private void addButton(GuiButton button){
if(this.buttonList.size() > button.id){
this.buttonList.set(button.id, button);
}
else{
this.buttonList.add(button.id, button);
}
}
private GuiButton getButton(int id){
return (GuiButton)this.buttonList.get(id);
}
@ -244,6 +270,16 @@ public class GuiBooklet extends GuiScreen{
if(x >= this.guiLeft && x <= this.guiLeft+7 && y >= this.guiTop+10 && y <= this.guiTop+10+7){
this.func_146283_a(Collections.singletonList(EnumChatFormatting.GOLD+"Open Minecraft Forum Post in Browser"), x, y);
}
//Update Checker Hover Text
if(x >= this.guiLeft-11 && x <= this.guiLeft-11+10 && y >= this.guiTop-11 && y <= this.guiTop-11+10){
if(UpdateChecker.doneChecking && UpdateChecker.updateVersion > UpdateChecker.clientVersion){
ArrayList list = new ArrayList();
list.add(EnumChatFormatting.GOLD+"There is an Update available!");
list.add(EnumChatFormatting.ITALIC+"You have: "+ModUtil.VERSION+", Newest: "+UpdateChecker.updateVersionS);
list.add("Click this button to visit the download page!");
this.func_146283_a(list, x, y);
}
}
if(this.mouseClicked) this.mouseClicked = false;
}
@ -276,14 +312,26 @@ public class GuiBooklet extends GuiScreen{
@Override
public void actionPerformed(GuiButton button){
if(button.id == BUTTON_TWITTER_ID){
if(button.id == BUTTON_UPDATE_ID){
if(UpdateChecker.doneChecking && UpdateChecker.updateVersion > UpdateChecker.clientVersion){
try{
if(Desktop.isDesktopSupported()){
Desktop.getDesktop().browse(new URI(UpdateChecker.DOWNLOAD_LINK));
}
}
catch(Exception e){
ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e);
}
}
}
else if(button.id == BUTTON_TWITTER_ID){
try{
if(Desktop.isDesktopSupported()){
Desktop.getDesktop().browse(new URI("https://twitter.com/ActAddMod"));
Desktop.getDesktop().browse(new URI("http://twitter.com/ActAddMod"));
}
}
catch(Exception e){
e.printStackTrace();
ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e);
}
}
else if(button.id == BUTTON_FORUM_ID){
@ -293,7 +341,7 @@ public class GuiBooklet extends GuiScreen{
}
}
catch(Exception e){
e.printStackTrace();
ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e);
}
}
else if(button.id == BUTTON_CONFIG_ID){
@ -458,8 +506,8 @@ public class GuiBooklet extends GuiScreen{
private static class TexturedButton extends GuiButton{
private int texturePosX;
private int texturePosY;
public int texturePosX;
public int texturePosY;
public TexturedButton(int id, int x, int y, int texturePosX, int texturePosY, int width, int height){
super(id, x, y, width, height, "");
@ -467,6 +515,11 @@ public class GuiBooklet extends GuiScreen{
this.texturePosY = texturePosY;
}
public void setTexturePos(int x, int y){
this.texturePosX = x;
this.texturePosY = y;
}
@Override
public void drawButton(Minecraft minecraft, int x, int y){
if(this.visible){
@ -474,6 +527,7 @@ public class GuiBooklet extends GuiScreen{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition+this.width && y < this.yPosition+this.height;
int k = this.getHoverState(this.field_146123_n);
if(k == 0) k = 1;
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

View file

@ -23,7 +23,7 @@ import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.event.RenderPlayerEventAA;
import ellpeck.actuallyadditions.tile.*;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.update.UpdateCheckerClientNotifier;
import ellpeck.actuallyadditions.util.AssetUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.PersistantVariables;
@ -41,10 +41,6 @@ public class ClientProxy implements IProxy{
public void preInit(FMLPreInitializationEvent event){
ModUtil.LOGGER.info("PreInitializing ClientProxy...");
if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled()){
new UpdateChecker().init();
}
PersistantVariables.setTheFile(new File(event.getModConfigurationDirectory().getParent(), ModUtil.MOD_ID+"Data.dat"));
}
@ -53,6 +49,10 @@ public class ClientProxy implements IProxy{
public void init(FMLInitializationEvent event){
ModUtil.LOGGER.info("Initializing ClientProxy...");
if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled()){
Util.registerEvent(new UpdateCheckerClientNotifier());
}
AssetUtil.COMPOST_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
AssetUtil.FISHING_NET_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
AssetUtil.FURNACE_SOLAR_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();

View file

@ -10,21 +10,13 @@
package ellpeck.actuallyadditions.update;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import ellpeck.actuallyadditions.util.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
public class UpdateChecker{
public static boolean doneChecking = false;
public static boolean checkFailed = false;
private static boolean notified = false;
public static String updateVersionS;
public static int updateVersion;
public static int clientVersion;
@ -37,32 +29,4 @@ public class UpdateChecker{
Util.registerEvent(this);
new ThreadUpdateChecker();
}
@SubscribeEvent(receiveCanceled = true)
public void onTick(TickEvent.ClientTickEvent event){
//Don't notify directly to prevent the Message getting lost in Spam on World Joining
if(Minecraft.getSystemTime() % 200 == 0 && !notified && doneChecking && Minecraft.getMinecraft().thePlayer != null){
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(checkFailed){
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.failed.desc")));
}
else{
if(updateVersion > clientVersion){
String notice1 = "info."+ModUtil.MOD_ID_LOWER+".update.generic.desc";
String notice2 = "info."+ModUtil.MOD_ID_LOWER+".update.versionComp.desc";
String notice3 = "info."+ModUtil.MOD_ID_LOWER+".update.changelog.desc";
String notice4 = "info."+ModUtil.MOD_ID_LOWER+".update.download.desc";
player.addChatComponentMessage(new ChatComponentText(""));
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localize(notice1)));
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted(notice2, ModUtil.VERSION, updateVersionS)));
player.addChatComponentMessage(new ChatComponentText(StringUtil.localizeFormatted(notice3, changelog)));
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted(notice4, DOWNLOAD_LINK)));
player.addChatComponentMessage(new ChatComponentText(""));
}
}
notified = true;
}
}
}

View file

@ -0,0 +1,51 @@
/*
* This file ("UpdateCheckerClientNotifier.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.update;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
public class UpdateCheckerClientNotifier{
private static boolean notified = false;
@SubscribeEvent(receiveCanceled = true)
public void onTick(TickEvent.ClientTickEvent event){
//Don't notify directly to prevent the Message getting lost in Spam on World Joining
if(Minecraft.getSystemTime() % 200 == 0 && !notified && UpdateChecker.doneChecking && Minecraft.getMinecraft().thePlayer != null){
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(UpdateChecker.checkFailed){
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.failed.desc")));
}
else{
if(UpdateChecker.updateVersion > UpdateChecker.clientVersion){
String notice1 = "info."+ModUtil.MOD_ID_LOWER+".update.generic.desc";
String notice2 = "info."+ModUtil.MOD_ID_LOWER+".update.versionComp.desc";
String notice3 = "info."+ModUtil.MOD_ID_LOWER+".update.changelog.desc";
String notice4 = "info."+ModUtil.MOD_ID_LOWER+".update.download.desc";
player.addChatComponentMessage(new ChatComponentText(""));
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localize(notice1)));
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted(notice2, ModUtil.VERSION, UpdateChecker.updateVersionS)));
player.addChatComponentMessage(new ChatComponentText(StringUtil.localizeFormatted(notice3, UpdateChecker.changelog)));
player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted(notice4, UpdateChecker.DOWNLOAD_LINK)));
player.addChatComponentMessage(new ChatComponentText(""));
}
}
notified = true;
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB