From 183d9f132a28edacc0e66ff9018038cf51f27c7e Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Thu, 17 Jul 2014 20:58:40 +0200 Subject: [PATCH] Tic Tooltips support for the leveling tooltips --- .../leveling/handlers/ToolTipHandler.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java index 7b6bc9c..3afdf1e 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/ToolTipHandler.java @@ -1,9 +1,11 @@ package iguanaman.iguanatweakstconstruct.leveling.handlers; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import iguanaman.iguanatweakstconstruct.leveling.LevelingLogic; import iguanaman.iguanatweakstconstruct.leveling.LevelingTooltips; import iguanaman.iguanatweakstconstruct.reference.IguanaConfig; +import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -29,11 +31,15 @@ public class ToolTipHandler { if(!(event.itemStack.getItem() instanceof ToolCore)) return; + // don't display tooltip when CTRL is held (also tic tooltips compatibility) + if(ctrlHeld()) + return; + ItemStack stack = event.itemStack; // find spot to insert our tooltip data ListIterator inserter = findInsertSpot(event.toolTip); // does the user hold shift? - boolean advanced = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); + boolean advanced = shiftHeld(); // only allow advanced (xp) tooltip if config option is set advanced &= IguanaConfig.showTooltipXP; @@ -81,7 +87,7 @@ public class ToolTipHandler { inserter.add(""); // add info that you can hold shift for more details - if(!advanced && IguanaConfig.showTooltipXP) + if(!advanced && IguanaConfig.showTooltipXP && !Loader.isModLoaded("TiCTooltips")) // don't display if TicToolTips is installed event.toolTip.add(EnumChatFormatting.GRAY.toString() + EnumChatFormatting.ITALIC.toString() + "Hold SHIFT for XP"); } @@ -91,14 +97,39 @@ public class ToolTipHandler { // progress to the end, check if there's a "+ damage" stuff while(iterator.hasNext()) - if(iterator.next().startsWith(plusPrefix)) - { + { + String str = iterator.next(); + if (str.isEmpty() || str.startsWith(plusPrefix)) { iterator.previous(); break; } + else if(Loader.isModLoaded("TiCTooltips") && str.contains("Shift")) { + iterator.previous(); + break; + } + } + + // iterator.previous(); // we're either directly before the "+ damage" or at the end now return iterator; } + + // all hail ticTooltips for that information ;) + private boolean shiftHeld() + { + return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); + } + + private boolean ctrlHeld() + { + + // prioritize CONTROL, but allow OPTION as well on Mac (note: GuiScreen's isCtrlKeyDown only checks for the OPTION key on Mac) + boolean isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL); + if (!isCtrlKeyDown && Minecraft.isRunningOnMac) + isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA); + + return isCtrlKeyDown; + } }