fix localisation of colours in configurator mode changing

This commit is contained in:
Xander committed 2017-11-08 21:58:25 +08:00
1 parent f46bbb0635
commit 58c80cf150
3 files changed
+127 -23

No files matched your search

+35 -19
View File
@@ -1,6 +1,9 @@
package mekanism.api;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
/**
@@ -10,25 +13,25 @@ import net.minecraft.util.text.translation.I18n;
*/
public enum EnumColor implements IStringSerializable
{
BLACK("\u00a70", "black", "Black", new int[] {0, 0, 0}, 0),
DARK_BLUE("\u00a71", "darkBlue", "Blue", new int[] {0, 0, 170}, 4),
DARK_GREEN("\u00a72", "darkGreen", "Green", new int[] {0, 170, 0}, 2),
DARK_AQUA("\u00a73", "darkAqua", "Cyan", new int[] {0, 255, 255}, 6),
DARK_RED("\u00a74", "darkRed", null, new int[] {170, 0, 0}, -1),
PURPLE("\u00a75", "purple", "Purple", new int[] {170, 0, 170}, 5),
ORANGE("\u00a76", "orange", "Orange", new int[] {255, 170, 0}, 14),
GREY("\u00a77", "grey", "LightGray", new int[] {170, 170, 170}, 7),
DARK_GREY("\u00a78", "darkGrey", "Gray", new int[] {85, 85, 85}, 8),
INDIGO("\u00a79", "indigo", "LightBlue", new int[] {85, 85, 255}, 12),
BRIGHT_GREEN("\u00a7a", "brightGreen", "Lime", new int[] {85, 255, 85}, 10),
AQUA("\u00a7b", "aqua", null, new int[] {85, 255, 255}, -1),
RED("\u00a7c", "red", "Red", new int[] {255, 0, 0}, 1),
PINK("\u00a7d", "pink", "Magenta", new int[] {255, 85, 255}, 13),
YELLOW("\u00a7e", "yellow", "Yellow", new int[] {255, 255, 85}, 11),
WHITE("\u00a7f", "white", "White", new int[] {255, 255, 255}, 15),
BLACK("\u00a70", "black", "Black", new int[] {0, 0, 0}, 0, TextFormatting.BLACK),
DARK_BLUE("\u00a71", "darkBlue", "Blue", new int[] {0, 0, 170}, 4, TextFormatting.DARK_BLUE),
DARK_GREEN("\u00a72", "darkGreen", "Green", new int[] {0, 170, 0}, 2, TextFormatting.DARK_GREEN),
DARK_AQUA("\u00a73", "darkAqua", "Cyan", new int[] {0, 255, 255}, 6, TextFormatting.DARK_AQUA),
DARK_RED("\u00a74", "darkRed", null, new int[] {170, 0, 0}, -1, TextFormatting.DARK_RED),
PURPLE("\u00a75", "purple", "Purple", new int[] {170, 0, 170}, 5, TextFormatting.DARK_PURPLE),
ORANGE("\u00a76", "orange", "Orange", new int[] {255, 170, 0}, 14, TextFormatting.GOLD),
GREY("\u00a77", "grey", "LightGray", new int[] {170, 170, 170}, 7, TextFormatting.GRAY),
DARK_GREY("\u00a78", "darkGrey", "Gray", new int[] {85, 85, 85}, 8, TextFormatting.DARK_GRAY),
INDIGO("\u00a79", "indigo", "LightBlue", new int[] {85, 85, 255}, 12, TextFormatting.BLUE),
BRIGHT_GREEN("\u00a7a", "brightGreen", "Lime", new int[] {85, 255, 85}, 10, TextFormatting.GREEN),
AQUA("\u00a7b", "aqua", null, new int[] {85, 255, 255}, -1, TextFormatting.AQUA),
RED("\u00a7c", "red", "Red", new int[] {255, 0, 0}, 1, TextFormatting.RED),
PINK("\u00a7d", "pink", "Magenta", new int[] {255, 85, 255}, 13, TextFormatting.LIGHT_PURPLE),
YELLOW("\u00a7e", "yellow", "Yellow", new int[] {255, 255, 85}, 11, TextFormatting.YELLOW),
WHITE("\u00a7f", "white", "White", new int[] {255, 255, 255}, 15, TextFormatting.WHITE),
//Extras for dye-completeness
BROWN("\u00a76", "brown", "Brown", new int[] {150, 75, 0}, 3),
BRIGHT_PINK("\u00a7d", "brightPink", "Pink", new int[] {255, 192, 203}, 9);
BROWN("\u00a76", "brown", "Brown", new int[] {150, 75, 0}, 3, TextFormatting.GOLD),
BRIGHT_PINK("\u00a7d", "brightPink", "Pink", new int[] {255, 192, 203}, 9, TextFormatting.LIGHT_PURPLE);
public static EnumColor[] DYES = new EnumColor[] {BLACK, RED, DARK_GREEN, BROWN, DARK_BLUE, PURPLE, DARK_AQUA, GREY, DARK_GREY, BRIGHT_PINK, BRIGHT_GREEN, YELLOW, INDIGO, PINK, ORANGE, WHITE};
@@ -44,13 +47,16 @@ public enum EnumColor implements IStringSerializable
public String dyeName;
EnumColor(String s, String n, String dye, int[] rgb, int meta)
public final TextFormatting textFormatting;
EnumColor(String s, String n, String dye, int[] rgb, int meta, TextFormatting tf)
{
code = s;
unlocalizedName = n;
dyeName = dye;
rgbCode = rgb;
mcMeta = meta;
textFormatting = tf;
}
/**
@@ -62,6 +68,10 @@ public enum EnumColor implements IStringSerializable
return I18n.translateToLocal("color." + unlocalizedName);
}
public String getUnlocalizedName(){
return "color." + unlocalizedName;
}
public String getDyeName()
{
return I18n.translateToLocal("dye." + unlocalizedName);
@@ -81,6 +91,12 @@ public enum EnumColor implements IStringSerializable
return code + getLocalizedName();
}
public ITextComponent getTranslatedColouredComponent(){
ITextComponent t = new TextComponentTranslation(getUnlocalizedName());
t.getStyle().setColor(textFormatting);
return t;
}
public String getDyedName()
{
return code + getDyeName();
@@ -26,8 +26,8 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.transmitters.TransporterImpl;
import mekanism.common.transmitters.grid.InventoryNetwork;
import mekanism.common.util.CapabilityUtils;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TextComponentGroup;
import mekanism.common.util.TransporterUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@@ -36,7 +36,7 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.util.Constants.NBT;
@@ -351,7 +351,19 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<TileE
onPartChanged(null);
PathfinderCache.onChanged(new Coord4D(getPos(), getWorld()));
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(new Coord4D(getPos(), getWorld()), getNetworkedData(new ArrayList<>())), new Range4D(new Coord4D(getPos(), getWorld())));
player.sendMessage(new TextComponentString(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + LangUtils.localize("tooltip.configurator.toggleColor") + ": " + (getTransmitter().getColor() != null ? getTransmitter().getColor().getColoredName() : EnumColor.BLACK + LangUtils.localize("gui.none"))));
TextComponentGroup msg = new TextComponentGroup(TextFormatting.GRAY)
.string("[Mekanism] ", TextFormatting.DARK_BLUE)
.translation("tooltip.configurator.toggleColor")
.string(": " );
if (getTransmitter().getColor() != null)
{
msg.appendSibling(getTransmitter().getColor().getTranslatedColouredComponent());
} else {
msg.translation("gui.none", TextFormatting.BLACK);
}
player.sendMessage(msg);
return EnumActionResult.SUCCESS;
}
@@ -360,7 +372,17 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<TileE
public EnumActionResult onRightClick(EntityPlayer player, EnumFacing side)
{
super.onRightClick(player, side);
player.sendMessage(new TextComponentString(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + LangUtils.localize("tooltip.configurator.viewColor") + ": " + (getTransmitter().getColor() != null ? getTransmitter().getColor().getColoredName() : "None")));
TextComponentGroup msg = new TextComponentGroup(TextFormatting.GRAY)
.string("[Mekanism] ", TextFormatting.DARK_BLUE)
.translation("tooltip.configurator.viewColor");
if (getTransmitter().getColor() != null)
{
msg.appendSibling(getTransmitter().getColor().getTranslatedColouredComponent());
} else {
msg.translation("gui.none");
}
player.sendMessage(msg);
return EnumActionResult.SUCCESS;
}
@@ -0,0 +1,66 @@
package mekanism.common.util;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentBase;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
/**
* Created by Thiakil on 8/11/2017.
*/
public class TextComponentGroup extends TextComponentBase
{
public TextComponentGroup(){
}
public TextComponentGroup(TextFormatting color)
{
getStyle().setColor(color);
}
@Override
public String getUnformattedComponentText()
{
return "";
}
@Override
public ITextComponent createCopy()
{
TextComponentGroup textcomponentstring = new TextComponentGroup();
textcomponentstring.setStyle(this.getStyle().createShallowCopy());
for (ITextComponent itextcomponent : this.getSiblings())
{
textcomponentstring.appendSibling(itextcomponent.createCopy());
}
return textcomponentstring;
}
public TextComponentGroup string(String s){
this.appendSibling(new TextComponentString(s));
return this;
}
public TextComponentGroup string(String s, TextFormatting color){
ITextComponent t = new TextComponentString(s);
t.getStyle().setColor(color);
this.appendSibling(t);
return this;
}
public TextComponentGroup translation(String key){
this.appendSibling(new TextComponentTranslation(key));
return this;
}
public TextComponentGroup translation(String key, TextFormatting color){
ITextComponent t = new TextComponentTranslation(key);
t.getStyle().setColor(color);
this.appendSibling(t);
return this;
}
}