mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 22:34:21 +00:00
Tooltip auto-scaling! All tooltips now have equal widths, even in different languages.
This commit is contained in:
1 parent
22bf688fbd
commit
f19a8f9e64
13 files changed
+235
-119
No files matched your search
@@ -1,10 +1,20 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import cofh.api.item.IToolHammer;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import ic2.api.energy.EnergyNet;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.api.Chunk3D;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
@@ -17,10 +27,24 @@ import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.api.util.UnitDisplayUtils;
|
||||
import mekanism.api.util.UnitDisplayUtils.ElectricUnit;
|
||||
import mekanism.api.util.UnitDisplayUtils.TemperatureUnit;
|
||||
import mekanism.common.*;
|
||||
import mekanism.common.Tier.*;
|
||||
import mekanism.common.base.*;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.MekanismBlocks;
|
||||
import mekanism.common.MekanismItems;
|
||||
import mekanism.common.OreDictCache;
|
||||
import mekanism.common.Tier.BaseTier;
|
||||
import mekanism.common.Tier.EnergyCubeTier;
|
||||
import mekanism.common.Tier.FactoryTier;
|
||||
import mekanism.common.Tier.InductionCellTier;
|
||||
import mekanism.common.Tier.InductionProviderTier;
|
||||
import mekanism.common.Upgrade;
|
||||
import mekanism.common.Version;
|
||||
import mekanism.common.base.IActiveState;
|
||||
import mekanism.common.base.IFactory;
|
||||
import mekanism.common.base.IFactory.RecipeType;
|
||||
import mekanism.common.base.IModule;
|
||||
import mekanism.common.base.IRedstoneControl;
|
||||
import mekanism.common.base.ISideConfiguration;
|
||||
import mekanism.common.base.IUpgradeTile;
|
||||
import mekanism.common.inventory.container.ContainerElectricChest;
|
||||
import mekanism.common.item.ItemBlockBasic;
|
||||
import mekanism.common.item.ItemBlockEnergyCube;
|
||||
@@ -31,6 +55,7 @@ import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
|
||||
import mekanism.common.tile.TileEntityBoundingBlock;
|
||||
import mekanism.common.tile.TileEntityElectricChest;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -49,18 +74,19 @@ import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import cofh.api.item.IToolHammer;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Utilities used by Mekanism. All miscellaneous methods are located here.
|
||||
@@ -1233,20 +1259,76 @@ public final class MekanismUtils
|
||||
{
|
||||
return "[" + obj.xCoord + ", " + obj.yCoord + ", " + obj.zCoord + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string of text into a list of new segments, using the splitter "!n."
|
||||
* @param s - string to split
|
||||
* @return split string
|
||||
*/
|
||||
public static List<String> splitLines(String s)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static List<String> splitTooltip(String s, ItemStack stack)
|
||||
{
|
||||
ArrayList ret = new ArrayList();
|
||||
|
||||
String[] split = s.split("!n");
|
||||
ret.addAll(Arrays.asList(split));
|
||||
|
||||
return ret;
|
||||
s = s.trim();
|
||||
|
||||
try {
|
||||
FontRenderer renderer = (FontRenderer)Mekanism.proxy.getFontRenderer();
|
||||
|
||||
if(stack != null && stack.getItem().getFontRenderer(stack) != null)
|
||||
{
|
||||
renderer = stack.getItem().getFontRenderer(stack);
|
||||
}
|
||||
|
||||
List<String> words = new ArrayList<String>();
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
String currentWord = "";
|
||||
|
||||
for(Character c : s.toCharArray())
|
||||
{
|
||||
if(c.equals(' '))
|
||||
{
|
||||
words.add(currentWord);
|
||||
currentWord = "";
|
||||
}
|
||||
else {
|
||||
currentWord += c;
|
||||
}
|
||||
}
|
||||
|
||||
if(!currentWord.isEmpty())
|
||||
{
|
||||
words.add(currentWord);
|
||||
}
|
||||
|
||||
String currentLine = "";
|
||||
|
||||
for(String word : words)
|
||||
{
|
||||
if(currentLine.isEmpty() || renderer.getStringWidth(currentLine + " " + word) <= 200)
|
||||
{
|
||||
if(currentLine.length() > 0)
|
||||
{
|
||||
currentLine += " ";
|
||||
}
|
||||
|
||||
currentLine += word;
|
||||
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
lines.add(currentLine);
|
||||
currentLine = word;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(!currentLine.isEmpty())
|
||||
{
|
||||
lines.add(currentLine);
|
||||
}
|
||||
|
||||
return lines;
|
||||
} catch(Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user