diff --git a/lang b/lang index 51b8500f9..f0c46deb8 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 51b8500f98330f733c11a40aaffee254605d1c32 +Subproject commit f0c46deb80b0d2b0fbd72a9e0b4f70e3e1940b13 diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index 3e3451b28..ee1b292fa 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -30,6 +30,7 @@ import forestry.Forestry; import forestry.core.fluids.Fluids; import forestry.core.utils.Log; import forestry.core.utils.StringUtil; +import forestry.mail.gui.GuiMailboxInfo; public class Config { @@ -89,6 +90,8 @@ public class Config { // Mail public static boolean mailAlertEnabled = true; + public static GuiMailboxInfo.XPosition mailAlertXPosition = GuiMailboxInfo.XPosition.LEFT; + public static GuiMailboxInfo.YPosition mailAlertYPosition = GuiMailboxInfo.YPosition.TOP; // Gui tabs (Ledger) public static int guiTabSpeed = 8; @@ -138,7 +141,7 @@ public class Config { private static void loadConfigCommon(File configFileCommon) { - configCommon = new LocalizedConfiguration(configFileCommon, "1.1.0"); + configCommon = new LocalizedConfiguration(configFileCommon, "1.2.0"); gameMode = configCommon.getStringLocalized("difficulty", "game.mode", "EASY", new String[]{"OP, EASY, NORMAL, HARD"}); @@ -212,7 +215,13 @@ public class Config { enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply); - mailAlertEnabled = configCommon.getBooleanLocalized("tweaks.gui", "mail.alert", mailAlertEnabled); + // move legacy mail property + configCommon.moveProperty("tweaks.gui", "mail.alert", "tweaks.gui.mail.alert"); + configCommon.renameProperty("tweaks.gui.mail.alert", "mail.alert", "enabled"); + + mailAlertEnabled = configCommon.getBooleanLocalized("tweaks.gui.mail.alert", "enabled", mailAlertEnabled); + mailAlertXPosition = configCommon.getEnumLocalized("tweaks.gui.mail.alert", "xPosition", mailAlertXPosition, GuiMailboxInfo.XPosition.values()); + mailAlertYPosition = configCommon.getEnumLocalized("tweaks.gui.mail.alert", "yPosition", mailAlertYPosition, GuiMailboxInfo.YPosition.values()); guiTabSpeed = configCommon.getIntLocalized("tweaks.gui.tabs", "speed", guiTabSpeed, 1, 50); enableHints = configCommon.getBooleanLocalized("tweaks.gui.tabs", "hints", enableHints); diff --git a/src/main/java/forestry/core/config/LocalizedConfiguration.java b/src/main/java/forestry/core/config/LocalizedConfiguration.java index 8e92367d6..6758aa3e5 100644 --- a/src/main/java/forestry/core/config/LocalizedConfiguration.java +++ b/src/main/java/forestry/core/config/LocalizedConfiguration.java @@ -70,6 +70,37 @@ public class LocalizedConfiguration extends Configuration { return prop.getString(); } + public > T getEnumLocalized(String category, String name, T defaultValue, T[] validEnumValues) { + String langKey = "for.config." + category + '.' + name; + String commentKey = langKey + '.' + "comment"; + String comment = ""; + if (StatCollector.canTranslate(commentKey)) { + comment = StatCollector.translateToLocal(commentKey); + } + + Property prop = this.get(category, name, defaultValue.name()); + + String[] validValues = new String[validEnumValues.length]; + for (int i = 0; i < validEnumValues.length; i++) { + T enumValue = validEnumValues[i]; + validValues[i] = enumValue.name(); + } + + prop.setValidValues(validValues); + prop.setLanguageKey(langKey); + prop.comment = comment + " [default: " + defaultValue + "] [valid: " + Arrays.toString(prop.getValidValues()) + "]"; + String stringValue = prop.getString(); + + T enumValue = defaultValue; + for (int i = 0; i < validValues.length; i++) { + if (stringValue.equals(validValues[i])) { + enumValue = validEnumValues[i]; + } + } + + return enumValue; + } + public String[] getStringListLocalized(String category, String name, String[] defaultValue) { String langKey = "for.config." + category + '.' + name; String commentKey = langKey + '.' + "comment"; diff --git a/src/main/java/forestry/mail/TickHandlerMailClient.java b/src/main/java/forestry/mail/TickHandlerMailClient.java index ac560722d..88319eb8d 100755 --- a/src/main/java/forestry/mail/TickHandlerMailClient.java +++ b/src/main/java/forestry/mail/TickHandlerMailClient.java @@ -29,7 +29,7 @@ public class TickHandlerMailClient { } if (GuiMailboxInfo.instance.hasPOBoxInfo()) { - GuiMailboxInfo.instance.render(0, 0); + GuiMailboxInfo.instance.render(); } else { long time = System.currentTimeMillis(); if (time - lastInfoRequestTime > THROTTLE_TIME_MS) { diff --git a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java index 0c9aca1ba..9959032a7 100755 --- a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java +++ b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java @@ -10,8 +10,10 @@ ******************************************************************************/ package forestry.mail.gui; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @@ -24,7 +26,17 @@ import forestry.mail.POBoxInfo; public class GuiMailboxInfo extends Gui { - public final static GuiMailboxInfo instance = new GuiMailboxInfo(); + public enum XPosition { + LEFT, RIGHT; + } + + public enum YPosition { + TOP, BOTTOM; + } + + public static final GuiMailboxInfo instance = new GuiMailboxInfo(); + private static final int WIDTH = 98; + private static final int HEIGHT = 17; private final FontRenderer fontRendererObj; private POBoxInfo poInfo; @@ -34,24 +46,27 @@ public class GuiMailboxInfo extends Gui { fontRendererObj = Proxies.common.getClientInstance().fontRenderer; } - public void render(int x, int y) { - if (poInfo == null) { + public void render() { + if (poInfo == null || !Config.mailAlertEnabled || !poInfo.hasMail()) { return; } - if (Proxies.common.getRenderWorld() == null) { - return; + + int x = 0; + int y = 0; + + Minecraft minecraft = Minecraft.getMinecraft(); + ScaledResolution scaledresolution = new ScaledResolution(minecraft, minecraft.displayWidth, minecraft.displayHeight); + if (Config.mailAlertXPosition == XPosition.RIGHT) { + x = scaledresolution.getScaledWidth() - WIDTH; } - if (!Config.mailAlertEnabled) { - return; - } - if (!poInfo.hasMail()) { - return; + if (Config.mailAlertYPosition == YPosition.BOTTOM) { + y = scaledresolution.getScaledHeight() - HEIGHT; } GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Proxies.render.bindTexture(textureAlert); - this.drawTexturedModalRect(x, y, 0, 0, 98, 17); + this.drawTexturedModalRect(x, y, 0, 0, WIDTH, HEIGHT); fontRendererObj.drawString(Integer.toString(poInfo.playerLetters), x + 27 + getCenteredOffset(Integer.toString(poInfo.playerLetters), 22), y + 5, 0xffffff); fontRendererObj.drawString(Integer.toString(poInfo.tradeLetters), x + 75 + getCenteredOffset(Integer.toString(poInfo.tradeLetters), 22), y + 5, 0xffffff);