From 5371cb7fc22fb2377617e9be308dd5950fa14b30 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Wed, 16 Jul 2014 20:37:46 +0200 Subject: [PATCH] Added a config option for a minimal xp tooltip. Ironed out a few flaws. --- .../leveling/IguanaLevelingLogic.java | 1 + .../leveling/ToolTipHandler.java | 20 +++++++++---------- .../modifiers/IguanaModRedstone.java | 4 ++-- .../modifiers/IguanaModUpgrade.java | 4 ++++ .../reference/IguanaConfig.java | 13 ++++++++---- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaLevelingLogic.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaLevelingLogic.java index dd2970f..d65ee55 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaLevelingLogic.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/IguanaLevelingLogic.java @@ -41,6 +41,7 @@ public abstract class IguanaLevelingLogic { public static long getXp(NBTTagCompound tags) { return tags.getLong(TAG_EXP); } public static long getBoostXp(NBTTagCompound tags) { return tags.getLong(TAG_BOOST_EXP); } public static boolean isBoosted(NBTTagCompound tags) { return tags.getBoolean(TAG_IS_BOOSTED); } + public static boolean isMaxLevel(NBTTagCompound tags) { return getLevel(tags) >= MAX_LEVEL; } /** * Add the leveling specific NBT. diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/ToolTipHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/ToolTipHandler.java index 69af5bc..f1b08c0 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/ToolTipHandler.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/ToolTipHandler.java @@ -2,12 +2,9 @@ package iguanaman.iguanatweakstconstruct.leveling; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import iguanaman.iguanatweakstconstruct.reference.IguanaConfig; -import iguanaman.iguanatweakstconstruct.util.IguanaLog; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StatCollector; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import org.lwjgl.input.Keyboard; import tconstruct.items.tools.Hammer; @@ -36,7 +33,7 @@ public class ToolTipHandler { // does the user hold shift? boolean advanced = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); // only allow advanced (xp) tooltip if config option is set - advanced &= IguanaConfig.detailedXpTooltip; + advanced &= IguanaConfig.showTooltipXP; ToolCore tool = (ToolCore)event.itemStack.getItem(); @@ -49,14 +46,14 @@ public class ToolTipHandler { int hLevel = tags.getInteger("HarvestLevel"); String mLvl = IguanaLevelingTooltips.getMiningLevelTooltip(hLevel); // add minimal xp if config option is set - //if(!advanced && IguanaConfig.showTooltipXP) - //mLvl += " (123%)"; // todo: implement + if(!advanced && IguanaConfig.showMinimalTooltipXP && !IguanaLevelingLogic.isBoosted(tags)) + mLvl += " (" + IguanaLevelingTooltips.getBoostXpString(stack, tags, false) + ")"; inserter.add(mLvl); // advanced mining level boost progress info if(advanced && IguanaConfig.levelingPickaxeBoost && IguanaConfig.showTooltipXP) { - if(tags.hasKey(IguanaLevelingLogic.TAG_IS_BOOSTED)) + if(IguanaLevelingLogic.isBoosted(tags)) inserter.add(IguanaLevelingTooltips.getBoostedTooltip()); else inserter.add(IguanaLevelingTooltips.getBoostXpToolTip(stack, tags)); @@ -64,11 +61,14 @@ public class ToolTipHandler { } // add skill level - int level = tags.getInteger(IguanaLevelingLogic.TAG_LEVEL); - inserter.add(IguanaLevelingTooltips.getLevelTooltip(level)); + int level = IguanaLevelingLogic.getLevel(tags); + String lvl = IguanaLevelingTooltips.getLevelTooltip(level); + if(!advanced && IguanaConfig.showMinimalTooltipXP && !IguanaLevelingLogic.isMaxLevel(tags)) + lvl += " (" + IguanaLevelingTooltips.getXpString(stack, tags, false) + ")"; + inserter.add(lvl); // skill level progress - if(advanced && IguanaConfig.showTooltipXP) + if(advanced && IguanaConfig.showTooltipXP && !IguanaLevelingLogic.isMaxLevel(tags)) inserter.add(IguanaLevelingTooltips.getXpToolTip(stack, tags)); // since we added at least one line we'll add an empty spacing line at the end diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModRedstone.java b/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModRedstone.java index 9b41a21..e7810e5 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModRedstone.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModRedstone.java @@ -159,7 +159,7 @@ public class IguanaModRedstone extends ItemModifier { int level = tags.getInteger("ToolLevel"); if (level <= 5) { - tips.add(IguanaLevelingTooltips.getXpString(tool, false)); + //tips.add(IguanaLevelingTooltips.getXpString(tool, false)); modifierTips.add(""); } @@ -170,7 +170,7 @@ public class IguanaModRedstone extends ItemModifier { && !tags.hasKey("HarvestLevelModified") && (tool.getItem() instanceof Pickaxe || tool.getItem() instanceof Hammer)) { - tips.add(IguanaLevelingTooltips.getXpString(tool, true)); + //tips.add(IguanaLevelingTooltips.getXpString(tool, true)); modifierTips.add(""); } } diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModUpgrade.java b/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModUpgrade.java index aaa6360..08cc5f5 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModUpgrade.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/modifiers/IguanaModUpgrade.java @@ -283,12 +283,14 @@ public class IguanaModUpgrade extends ItemModifier { if (tags.hasKey("HeadEXP")) { + /* int requiredXp = IguanaLevelingLogic.getRequiredXp(tool, tags, true); long currentXp = tags.getLong("HeadEXP"); float xpPercentage = (float)currentXp / (float)requiredXp; int newRequiredXp = IguanaLevelingLogic.getRequiredXp(newTool, newTags, true); long newXp = Math.round(newRequiredXp * xpPercentage); tags.setLong("HeadEXP", newXp); + */ } @@ -400,6 +402,7 @@ public class IguanaModUpgrade extends ItemModifier { if (IguanaConfig.showTooltipXP) { + /* if (level <= 5) { tips.add(IguanaLevelingTooltips.getXpString(tool, false)); @@ -422,6 +425,7 @@ public class IguanaModUpgrade extends ItemModifier { modifierTips.add(""); } } + */ } //get and remove tooltips diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/reference/IguanaConfig.java b/src/main/java/iguanaman/iguanatweakstconstruct/reference/IguanaConfig.java index 19dedf9..a5f2277 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/reference/IguanaConfig.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/reference/IguanaConfig.java @@ -1,14 +1,14 @@ package iguanaman.iguanatweakstconstruct.reference; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; - public class IguanaConfig { @@ -30,6 +30,7 @@ public class IguanaConfig { public static int[] toolModifiersAtLevels; public static boolean toolLevelingRandomBonuses; public static boolean showTooltipXP; + public static boolean showMinimalTooltipXP; public static boolean showDebugXP; public static int xpRequiredToolsPercentage; public static int xpRequiredWeaponsPercentage; @@ -166,6 +167,10 @@ public class IguanaConfig { showTooltipXPProperty.comment = "Current XP is shown when hovering over a tool (requires 'toolLeveling=true')"; showTooltipXP = showTooltipXPProperty.getBoolean(true); + Property showMinimalTooltipXPProperty = config.get("leveling", "showMinimalTooltipXP", false); + showMinimalTooltipXPProperty.comment = "Current XP% is shown after the level (requires 'toolLeveling=true')"; + showMinimalTooltipXP = showMinimalTooltipXPProperty.getBoolean(true); + Property showDebugXPProperty = config.get("leveling", "showDebugXP", false); showDebugXPProperty.comment = "Current XP is shown as debug (F3) text (requires 'toolLeveling=true')"; showDebugXP = showDebugXPProperty.getBoolean(false);