Refactoring of tooltips
This commit is contained in:
parent
941629e790
commit
9f3a3eb026
4 changed files with 30 additions and 48 deletions
|
@ -37,6 +37,7 @@ public class ContainerDestructoPack extends RebornContainer {
|
|||
private EntityPlayer player;
|
||||
private Inventory inv;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public ContainerDestructoPack(EntityPlayer player) {
|
||||
this.player = player;
|
||||
inv = new Inventory(1, "destructopack", 64, null);
|
||||
|
|
|
@ -42,6 +42,7 @@ import reborncore.api.tile.IUpgradeable;
|
|||
import reborncore.client.guibuilder.GuiBuilder;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.lib.ModInfo;
|
||||
import techreborn.proxies.ClientProxy;
|
||||
|
||||
|
@ -86,7 +87,7 @@ public class TRBuilder extends GuiBuilder {
|
|||
List<String> list = new ArrayList<>();
|
||||
TextFormatting powerColour = TextFormatting.GOLD;
|
||||
list.add(powerColour + PowerSystem.getLocaliszedPowerFormattedNoSuffix(energyStored) + "/" + PowerSystem.getLocaliszedPowerFormattedNoSuffix(maxEnergyStored) + " " + PowerSystem.getDisplayPower().abbreviation);
|
||||
list.add(getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Charged");
|
||||
list.add(StringUtils.getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Charged");
|
||||
if(gui.tile instanceof TilePowerAcceptor && GuiScreen.isShiftKeyDown()){
|
||||
((TilePowerAcceptor) gui.tile).addInfo(list, true);
|
||||
list.add("");
|
||||
|
@ -142,7 +143,7 @@ public class TRBuilder extends GuiBuilder {
|
|||
if (isInRect(x, y, direction.width, direction.height, mouseX, mouseY)) {
|
||||
int percentage = percentage(maxProgress, progress);
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(getPercentageColour(percentage) + "" + percentage + "%");
|
||||
list.add(StringUtils.getPercentageColour(percentage) + "" + percentage + "%");
|
||||
net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(list, mouseX, mouseY, gui.width, gui.height, -1, gui.mc.fontRenderer);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
|
@ -181,7 +182,7 @@ public class TRBuilder extends GuiBuilder {
|
|||
list.add(TextFormatting.GOLD + "Empty Tank");
|
||||
else
|
||||
list.add(TextFormatting.GOLD + "" + amount + "mB/" + maxCapacity + "mB " + fluid.getLocalizedName());
|
||||
list.add(getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Full");
|
||||
list.add(StringUtils.getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Full");
|
||||
net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(list, mouseX, mouseY, gui.width, gui.height, -1, gui.mc.fontRenderer);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
|
@ -344,7 +345,7 @@ public class TRBuilder extends GuiBuilder {
|
|||
int percentage = percentage(max, value);
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("" + TextFormatting.GOLD + value + "/" + max + suffix);
|
||||
list.add(getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Full");
|
||||
list.add(StringUtils.getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Full");
|
||||
|
||||
if (value > max) {
|
||||
list.add(TextFormatting.GRAY + "Yo this is storing more than it should be able to");
|
||||
|
@ -428,7 +429,7 @@ public class TRBuilder extends GuiBuilder {
|
|||
if (isInRect(x, y, 12, 12, mouseX, mouseY)) {
|
||||
int percentage = percentage(maxProgress, progress);
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(getPercentageColour(percentage) + "" + percentage + "%");
|
||||
list.add(StringUtils.getPercentageColour(percentage) + "" + percentage + "%");
|
||||
net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(list, mouseX, mouseY, gui.width, gui.height, -1, gui.mc.fontRenderer);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
|
@ -503,16 +504,6 @@ public class TRBuilder extends GuiBuilder {
|
|||
return (int) (((float) burnTime / (float) totalBurnTime) * scale);
|
||||
}
|
||||
|
||||
public TextFormatting getPercentageColour(int percentage) {
|
||||
if (percentage <= 10) {
|
||||
return TextFormatting.RED;
|
||||
} else if (percentage >= 75) {
|
||||
return TextFormatting.GREEN;
|
||||
} else {
|
||||
return TextFormatting.YELLOW;
|
||||
}
|
||||
}
|
||||
|
||||
public int percentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
|
|
|
@ -29,7 +29,6 @@ import net.minecraft.client.gui.GuiScreen;
|
|||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import reborncore.client.guibuilder.GuiBuilder;
|
||||
import reborncore.common.tile.TileLegacyMachineBase;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
|
@ -368,16 +367,6 @@ public class ElementBase {
|
|||
return (int) (((float) burnTime / (float) totalBurnTime) * scale);
|
||||
}
|
||||
|
||||
public TextFormatting getPercentageColour(int percentage) {
|
||||
if (percentage <= 10) {
|
||||
return TextFormatting.RED;
|
||||
} else if (percentage >= 75) {
|
||||
return TextFormatting.GREEN;
|
||||
} else {
|
||||
return TextFormatting.YELLOW;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPercentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
|
|
|
@ -37,11 +37,15 @@ import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
|||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.power.IEnergyItemInfo;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.Core;
|
||||
|
||||
public class StackToolTipEvent {
|
||||
|
@ -54,26 +58,18 @@ public class StackToolTipEvent {
|
|||
return;
|
||||
}
|
||||
Item item = event.getItemStack().getItem();
|
||||
if (item instanceof IListInfoProvider) {
|
||||
((IListInfoProvider) item).addInfo(event.getToolTip(), false);
|
||||
} else if (event.getItemStack().getItem() instanceof IEnergyItemInfo) {
|
||||
List<String> tooltip = event.getToolTip();
|
||||
|
||||
if (item instanceof IEnergyItemInfo) {
|
||||
IEnergyStorage capEnergy = event.getItemStack().getCapability(CapabilityEnergy.ENERGY, null);
|
||||
event.getToolTip().add(1,
|
||||
tooltip.add(1,
|
||||
TextFormatting.GOLD + PowerSystem.getLocaliszedPowerFormattedNoSuffix(capEnergy.getEnergyStored() / RebornCoreConfig.euPerFU)
|
||||
+ "/" + PowerSystem.getLocaliszedPowerFormattedNoSuffix(capEnergy.getMaxEnergyStored() / RebornCoreConfig.euPerFU)
|
||||
+ " " + PowerSystem.getDisplayPower().abbreviation);
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
|
||||
int percentage = percentage(capEnergy.getMaxEnergyStored(), capEnergy.getEnergyStored());
|
||||
TextFormatting color;
|
||||
if (percentage <= 10) {
|
||||
color = TextFormatting.RED;
|
||||
} else if (percentage >= 75) {
|
||||
color = TextFormatting.GREEN;
|
||||
} else {
|
||||
color = TextFormatting.YELLOW;
|
||||
}
|
||||
event.getToolTip().add(2, color + "" + percentage + "%" + TextFormatting.GRAY + " Charged");
|
||||
event.getToolTip().add(3,
|
||||
tooltip.add(2, StringUtils.getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Charged");
|
||||
tooltip.add(3,
|
||||
TextFormatting.GRAY + "I/O Rate: "
|
||||
+ TextFormatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted((int) ((IEnergyItemInfo) item).getMaxTransfer(event.getItemStack())));
|
||||
|
@ -82,12 +78,17 @@ public class StackToolTipEvent {
|
|||
else {
|
||||
try {
|
||||
Block block = Block.getBlockFromItem(item);
|
||||
if (block != null && (block instanceof BlockContainer || block instanceof ITileEntityProvider)
|
||||
&& block.getRegistryName().getResourceDomain().contains("techreborn")) {
|
||||
TileEntity tile = block.createTileEntity(Minecraft.getMinecraft().world,
|
||||
block.getStateFromMeta(event.getItemStack().getItemDamage()));
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
if (!block.getRegistryName().getResourceDomain().contains("techreborn")) {
|
||||
return;
|
||||
}
|
||||
if (block instanceof BlockContainer || block instanceof ITileEntityProvider) {
|
||||
TileEntity tile = block.createTileEntity(Minecraft.getMinecraft().world,
|
||||
block.getStateFromMeta(event.getItemStack().getItemDamage()));
|
||||
if (tile instanceof IListInfoProvider) {
|
||||
((IListInfoProvider) tile).addInfo(event.getToolTip(), false);
|
||||
((IListInfoProvider) tile).addInfo(tooltip, false);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
|
@ -96,10 +97,10 @@ public class StackToolTipEvent {
|
|||
}
|
||||
}
|
||||
|
||||
public int percentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
private int percentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue