Skip to content
This repository has been archived by the owner on Apr 22, 2019. It is now read-only.

Commit

Permalink
Add some color to the item tool tip for emc values, add a config opti…
Browse files Browse the repository at this point in the history
…on to allow players the choice of whether values always display or require holding shift (Default is to hold shift), added an enum with easy to reference unicode values for text colors
  • Loading branch information
pahimar committed Oct 7, 2016
1 parent eda68d5 commit 3619928
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
import com.pahimar.ee3.api.exchange.EnergyValue;
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
import com.pahimar.ee3.exchange.WrappedStack;
import com.pahimar.ee3.handler.ConfigurationHandler;
import com.pahimar.ee3.reference.Colors;
import com.pahimar.ee3.reference.Messages;
import com.pahimar.ee3.util.IOwnable;
import com.pahimar.ee3.util.ItemStackUtils;
import com.pahimar.ee3.util.SerializationHelper;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.common.UsernameCache;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -27,7 +25,7 @@ public class ItemTooltipEventHandler {
@SubscribeEvent
public void handleItemTooltipEvent(ItemTooltipEvent event) {

if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
if (shouldBeDisplayed()) {

WrappedStack wrappedItemStack = WrappedStack.build(event.getItemStack());
EnergyValue energyValue = EnergyValueRegistryProxy.getEnergyValue(wrappedItemStack);
Expand All @@ -36,43 +34,22 @@ public void handleItemTooltipEvent(ItemTooltipEvent event) {
if (energyValue != null && (BlacklistRegistryProxy.isExchangeable(wrappedItemStack) || BlacklistRegistryProxy.isLearnable(wrappedItemStack))) {

if (wrappedItemStack.getStackSize() > 1) {
event.getToolTip().add(String.format("\u00A7aEMC Value (Item)\u00A7a: %s", energyValue)); // TODO Localize
event.getToolTip().add(String.format("\u00A7aEMC Value (Stack of %s)\u00A7a: %s", event.getItemStack().stackSize, stackEnergyValue)); // TODO Localize
event.getToolTip().add(String.format("%sEMC Value (Item):%s %s", Colors.TextColor.YELLOW, Colors.TextColor.WHITE, energyValue)); // TODO Localize
event.getToolTip().add(String.format("%sEMC Value (Stack of %s):%s %s", Colors.TextColor.YELLOW, event.getItemStack().stackSize, Colors.TextColor.WHITE, stackEnergyValue)); // TODO Localize
}
else {

event.getToolTip().add(String.format("\u00A7aEMC Value: %s\u00A7a", stackEnergyValue)); // TODO Localize

// TODO Move away from deprecated FluidContainerRegistry
if (FluidContainerRegistry.getFluidForFilledItem(event.getItemStack()) != null) {

FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(event.getItemStack());
EnergyValue fluidStackEnergyValue = EnergyValueRegistryProxy.getEnergyValueForStack(fluidStack);

if (fluidStackEnergyValue != null) {
event.getToolTip().add(String.format(" - Exchange Energy (%smB of %s): %s", fluidStack.amount, fluidStack.getLocalizedName(), fluidStackEnergyValue)); // TODO Localize
event.getToolTip().add(String.format(" - Exchange Energy (Container): %s", new EnergyValue(energyValue.getValue() - fluidStackEnergyValue.getValue()))); // TODO Localize
}
}
event.getToolTip().add(String.format("%sEMC Value:%s %s", Colors.TextColor.YELLOW, Colors.TextColor.WHITE, stackEnergyValue)); // TODO Localize
}
}
else {
event.getToolTip().add("No Exchange Energy value"); // TODO Localize
}

if (PlayerKnowledgeRegistryProxy.doesPlayerKnow(event.getEntityPlayer(), event.getItemStack())) {
event.getToolTip().add("You know how to transmute this"); // TODO Localize with better phrasing
}

// TODO This is more of a debug thing to determine the new NBT stuff
event.getToolTip().add(SerializationHelper.GSON.toJson(event.getItemStack()));
event.getToolTip().add(event.getItemStack().getItem().getRegistryName().toString());
}

if (event.getItemStack().getItem() instanceof IOwnable) {

// TODO Add a helper to ItemStackUtils or something that when given an ItemStack returns a player name String
UUID playerUUID = ItemStackUtils.getOwnerUUID(event.getItemStack());

if (playerUUID != null && UsernameCache.containsUUID(playerUUID)) {
event.getToolTip().add(I18n.format(Messages.Tooltips.ITEM_BELONGS_TO, UsernameCache.getLastKnownUsername(playerUUID)));
}
Expand All @@ -81,4 +58,8 @@ else if (ItemStackUtils.getOwnerName(event.getItemStack()) != null) {
}
}
}

private static boolean shouldBeDisplayed() {
return !ConfigurationHandler.Settings.requireShiftToDisplayExtra || (ConfigurationHandler.Settings.requireShiftToDisplayExtra && (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)));
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/pahimar/ee3/handler/ConfigurationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ private static void loadConfiguration() {
I18n.translateToLocal(Settings.SERVER_SYNC_THRESHOLD_COMMENT),
Settings.SERVER_SYNC_THRESHOLD_LABEL);

Settings.requireShiftToDisplayExtra = configuration.getBoolean(
Settings.SHIFT_DISPLAYS_ENERGY_VALUE_NAME,
CATEGORY_ENERGY_VALUE,
Settings.SHIFT_DISPLAYS_ENERGY_VALUE_DEFAULT,
I18n.translateToLocal(Settings.SHIFT_DISPLAYS_ENERGY_VALUE_COMMENT),
Settings.SHIFT_DISPLAYS_ENERGY_VALUE_LABEL);

Settings.regenerateEnergyValuesWhen = ConfigurationUtils.getString(configuration,
Settings.ENERGY_VALUE_REGENERATE_WHEN_NAME,
CATEGORY_ENERGY_VALUE,
Expand Down Expand Up @@ -89,6 +96,12 @@ public static class Settings {
private static final String ENERGY_VALUE_REGENERATE_WHEN_DEFAULT = "As Needed";
private static final String[] ENERGY_VALUE_REGENERATE_WHEN_OPTIONS = new String[]{"As Needed", "Always"};

public static boolean requireShiftToDisplayExtra;
private static final String SHIFT_DISPLAYS_ENERGY_VALUE_NAME = "hold_shift_to_display_emc_value";
private static final String SHIFT_DISPLAYS_ENERGY_VALUE_LABEL = "energy_value.hold_shift_to_display_emc_value.label";
private static final String SHIFT_DISPLAYS_ENERGY_VALUE_COMMENT = "energy_value.hold_shift_to_display_emc_value.comment";
private static final boolean SHIFT_DISPLAYS_ENERGY_VALUE_DEFAULT = true;

public static boolean playerKnowledgeTemplateEnabled;
private static final String USE_PLAYER_KNOWLEDGE_TEMPLATE_NAME = "use_template";
private static final String USE_PLAYER_KNOWLEDGE_TEMPLATE_LABEL = "player_knowledge.use_template.label";
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/pahimar/ee3/reference/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ public enum TextColor {
public String getColor() {
return color;
}

@Override
public String toString() {
return color;
}
}
}
9 changes: 2 additions & 7 deletions src/main/resources/assets/ee3/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
energy_value=Energy Value Options
energy_value.regenerate_values_when.label=Regenerate Energy Values When
energy_value.regenerate_values_when.comment=When to regenerate energy values for objects. Options are "Always" (every time Minecraft starts) or "As Needed" (whenever the mod cannot the calculated energy values file).
energy_value.debug_logging_enabled.label=Enable Debug Logging
energy_value.debug_logging_enabled.comment=Additional debug logging for when energy values are calculated for objects

# Configuration (Sound Options)
sound=Sound Options
sound.mode.label=Play Sounds Only From
sound.mode.comment='All' plays mod sounds from all players, 'Self' only plays mod sounds from you, and 'None' does not play any mod sounds
energy_value.hold_shift_to_display_emc_value.label=Hold Shift To Display EMC Values
energy_value.hold_shift_to_display_emc_value.comment=Whether or not Shift must be pressed to display EMC values (true = Hold Shift, false = Always displayed)

# Configuration (Player Knowledge Options)
player_knowledge=Player Knowledge Options
Expand Down

0 comments on commit 3619928

Please sign in to comment.