mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-25 06:14:46 +00:00
Fix #524 Add config for Received letters HUD Placement
This commit is contained in:
1 parent
7e3b7acdef
commit
a49eb1c5f9
5 files changed
+70
-15
No files matched your search
@@ -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);
|
||||
|
||||
@@ -70,6 +70,37 @@ public class LocalizedConfiguration extends Configuration {
|
||||
return prop.getString();
|
||||
}
|
||||
|
||||
public <T extends Enum<T>> 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";
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user