Added location overlay

This commit is contained in:
LemADEC 2017-07-29 18:26:05 +02:00
parent 6766631ea5
commit 1c8f66f494
9 changed files with 204 additions and 17 deletions

View file

@ -473,4 +473,11 @@ public class Commons {
return null;
}
public static int colorARGBtoInt(final int alpha, final int red, final int green, final int blue) {
return (clamp(0, 255, alpha) << 24)
+ (clamp(0, 255, red ) << 16)
+ (clamp(0, 255, green) << 8)
+ clamp(0, 255, blue );
}
}

View file

@ -138,6 +138,7 @@ import cr0s.warpdrive.render.RenderBlockOmnipanel;
import cr0s.warpdrive.render.RenderBlockStandard;
import cr0s.warpdrive.render.RenderOverlayAir;
import cr0s.warpdrive.render.RenderOverlayCamera;
import cr0s.warpdrive.render.RenderOverlayLocation;
import cr0s.warpdrive.world.BiomeSpace;
import cr0s.warpdrive.world.HyperSpaceWorldGenerator;
import cr0s.warpdrive.world.HyperSpaceWorldProvider;
@ -308,6 +309,7 @@ public class WarpDrive implements LoadingCallback {
if (event.getSide() == Side.CLIENT) {
MinecraftForge.EVENT_BUS.register(new RenderOverlayAir());
MinecraftForge.EVENT_BUS.register(new RenderOverlayCamera());
MinecraftForge.EVENT_BUS.register(new RenderOverlayLocation());
FMLCommonHandler.instance().bus().register(new ClientCameraHandler());

View file

@ -36,6 +36,7 @@ import cr0s.warpdrive.config.structures.StructureManager;
import cr0s.warpdrive.data.CelestialObject;
import cr0s.warpdrive.data.CelestialObjectManager;
import cr0s.warpdrive.data.EnumShipMovementType;
import cr0s.warpdrive.data.EnumDisplayAlignment;
import cr0s.warpdrive.network.PacketHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
@ -142,6 +143,17 @@ public class WarpDriveConfig {
public static boolean RECIPES_ENABLE_HARD_IC2 = false;
public static boolean RECIPES_ENABLE_VANILLA = false;
// Client
public static String CLIENT_LOCATION_FORMAT = "§l";
public static int CLIENT_LOCATION_COLOR = Commons.colorARGBtoInt(230, 192, 192, 240);
public static boolean CLIENT_LOCATION_HAS_SHADOW = true;
public static EnumDisplayAlignment CLIENT_LOCATION_SCREEN_ALIGNMENT = EnumDisplayAlignment.MIDDLE_RIGHT;
public static int CLIENT_LOCATION_SCREEN_OFFSET_X = -50;
public static int CLIENT_LOCATION_SCREEN_OFFSET_Y = 0;
public static EnumDisplayAlignment CLIENT_LOCATION_TEXT_ALIGNMENT = EnumDisplayAlignment.TOP_CENTER;
public static float CLIENT_LOCATION_WIDTH_RATIO = 0.0F;
public static int CLIENT_LOCATION_WIDTH_MIN = 90;
// Logging
public static boolean LOGGING_JUMP = false;
public static boolean LOGGING_JUMPBLOCKS = false;
@ -473,6 +485,27 @@ public class WarpDriveConfig {
RECIPES_ENABLE_IC2 = config.get("recipes", "enable_ic2", RECIPES_ENABLE_IC2, "Original recipes based on IndustrialCraft2 by Cr0s (you need to disable Dynamic recipes to use those, no longer updated)").getBoolean(false);
RECIPES_ENABLE_HARD_IC2 = config.get("recipes", "enable_hard_ic2", RECIPES_ENABLE_HARD_IC2, "Harder recipes based on IC2 by YuRaNnNzZZ (you need to disable Dynamic recipes to use those)").getBoolean(false);
// Client
CLIENT_LOCATION_FORMAT = config.get("client", "location_format", CLIENT_LOCATION_FORMAT,
"Format prefix for location title").getString();
String stringValue = config.get("client", "location_color", String.format("0x%6X", CLIENT_LOCATION_COLOR),
"Hexadecimal color code for location tile and description (0xAARRGGBB where AA is alpha, RR is Red, GG is Green and BB is Blue component)").getString();
CLIENT_LOCATION_COLOR = (int) ( Long.decode( stringValue ) & 0xFFFFFFFFL );
CLIENT_LOCATION_HAS_SHADOW = config.get("client", "location_has_shadow", CLIENT_LOCATION_HAS_SHADOW,
"Shadow casting option for current celestial object name").getBoolean(CLIENT_LOCATION_HAS_SHADOW);
CLIENT_LOCATION_SCREEN_ALIGNMENT = EnumDisplayAlignment.valueOf(config.get("client", "location_screen_alignment", CLIENT_LOCATION_SCREEN_ALIGNMENT.name(),
"Alignment on screen: TOP_LEFT, TOP_CENTER, TOP_RIGHT, MIDDLE_LEFT, MIDDLE_CENTER, MIDDLE_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER or BOTTOM_RIGHT").getString());
CLIENT_LOCATION_SCREEN_OFFSET_X = config.get("client", "location_offset_x", CLIENT_LOCATION_SCREEN_OFFSET_X,
"Horizontal offset on screen, increase to move to the right").getInt();
CLIENT_LOCATION_SCREEN_OFFSET_Y = config.get("client", "location_offset_y", CLIENT_LOCATION_SCREEN_OFFSET_Y,
"Vertical offset on screen, increase to move down").getInt();
CLIENT_LOCATION_TEXT_ALIGNMENT = EnumDisplayAlignment.valueOf(config.get("client", "location_text_alignment", CLIENT_LOCATION_TEXT_ALIGNMENT.name(),
"Text alignment: TOP_LEFT, TOP_CENTER, TOP_RIGHT, MIDDLE_LEFT, MIDDLE_CENTER, MIDDLE_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER or BOTTOM_RIGHT").getString());
CLIENT_LOCATION_WIDTH_RATIO = (float) config.get("client", "location_width_ratio", CLIENT_LOCATION_WIDTH_RATIO,
"Text width as a ratio of full screen width").getDouble();
CLIENT_LOCATION_WIDTH_MIN = config.get("client", "location_width_min", CLIENT_LOCATION_WIDTH_MIN,
"Text width as a minimum 'pixel' count").getInt();
// Logging
LOGGING_JUMP = config.get("logging", "enable_jump_logs", LOGGING_JUMP, "Basic jump logs, should always be enabled").getBoolean(true);
LOGGING_JUMPBLOCKS = config.get("logging", "enable_jumpblocks_logs", LOGGING_JUMPBLOCKS, "Detailed jump logs to help debug the mod, will spam your logs...").getBoolean(false);

View file

@ -156,7 +156,7 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
}
if (listElements.size() == 1) {
final Element elementName = listElements.get(0);
displayName = elementName.getNodeValue();
displayName = elementName.getTextContent();
} else {
displayName = id;
}
@ -170,7 +170,7 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
}
if (listElements.size() == 1) {
final Element elementName = listElements.get(0);
description = elementName.getNodeValue();
description = elementName.getTextContent();
} else {
description = "";
}
@ -185,7 +185,7 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
nbtTagCompound = null;
if (listElements.size() == 1) {
final Element elementName = listElements.get(0);
final String stringNBT = elementName.getNodeValue();
final String stringNBT = elementName.getTextContent();
if (!stringNBT.isEmpty()) {
try {
nbtTagCompound = (NBTTagCompound) JsonToNBT.func_150315_a(stringNBT);
@ -402,12 +402,12 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
@Override
public String getDisplayName() {
return displayName;
return displayName == null ? "" : displayName;
}
@Override
public String getDescription() {
return description;
return description == null ? "" : description;
}
@Override
@ -559,6 +559,9 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
borderRadiusX = nbtTagCompound.getInteger("borderRadiusX");
borderRadiusZ = nbtTagCompound.getInteger("borderRadiusZ");
displayName = nbtTagCompound.getString("displayName");
description = nbtTagCompound.getString("description");
isVirtual = nbtTagCompound.getBoolean("isVirtual");
if (isVirtual) {
dimensionId = 0;
@ -606,6 +609,13 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
nbtTagCompound.setInteger("borderRadiusX", borderRadiusX);
nbtTagCompound.setInteger("borderRadiusZ", borderRadiusZ);
if (displayName != null && !displayName.isEmpty()) {
nbtTagCompound.setString("displayName", displayName);
}
if (description != null && !description.isEmpty()) {
nbtTagCompound.setString("description", description);
}
nbtTagCompound.setBoolean("isVirtual", isVirtual);
if (!isVirtual) {
nbtTagCompound.setInteger("dimensionId", dimensionId);

View file

@ -169,9 +169,8 @@ public class CelestialObjectManager extends XmlFileManager {
// *** client side only ***
@SideOnly(Side.CLIENT)
public static void readClientSync(final NBTTagCompound nbtTagCompound) {
public static void readClientSync(final NBTTagList nbtTagList) {
clearForReload(true);
final NBTTagList nbtTagList = nbtTagCompound.getTagList("celestialObjects", NBT.TAG_COMPOUND);
if (nbtTagList != null && nbtTagList.tagCount() > 0) {
for (int index = 0; index < nbtTagList.tagCount(); index++) {
final CelestialObject celestialObject = new CelestialObject(nbtTagList.getCompoundTagAt(index));

View file

@ -0,0 +1,24 @@
package cr0s.warpdrive.data;
public enum EnumDisplayAlignment {
TOP_LEFT ("top_left" , 0.0F, 0.0F),
TOP_CENTER ("top_center" , 0.5F, 0.0F),
TOP_RIGHT ("top_right" , 1.0F, 0.0F),
MIDDLE_LEFT ("middle_left" , 0.0F, 0.5F),
MIDDLE_CENTER ("middle_center", 0.5F, 0.5F),
MIDDLE_RIGHT ("middle_right" , 1.0F, 0.5F),
BOTTOM_LEFT ("bottom_left" , 0.0F, 1.0F),
BOTTOM_CENTER ("bottom_center", 0.5F, 1.0F),
BOTTOM_RIGHT ("bottom_right" , 1.0F, 1.0F);
public final String unlocalizedName;
public final float xRatio;
public final float yRatio;
EnumDisplayAlignment(final String unlocalizedName, final float xRatio, final float yRatio) {
this.unlocalizedName = unlocalizedName;
this.xRatio = xRatio;
this.yRatio = yRatio;
}
}

View file

@ -60,7 +60,7 @@ public class MessageClientSync implements IMessage, IMessageHandler<MessageClien
}
try {
CelestialObjectManager.readClientSync(messageClientSync.nbtTagCompound.getCompoundTag("celestiaObjects"));
CelestialObjectManager.readClientSync(messageClientSync.nbtTagCompound.getTagList("celestialObjects", NBT.TAG_COMPOUND));
Dictionary.ITEMS_BREATHING_HELMET = Dictionary.readItemsFromNBT(messageClientSync.nbtTagCompound.getTagList("items_breathingHelmet", NBT.TAG_STRING));
Dictionary.ITEMS_FLYINSPACE = Dictionary.readItemsFromNBT(messageClientSync.nbtTagCompound.getTagList("items_flyInSpace" , NBT.TAG_STRING));
Dictionary.ITEMS_NOFALLDAMAGE = Dictionary.readItemsFromNBT(messageClientSync.nbtTagCompound.getTagList("items_noFallDamage" , NBT.TAG_STRING));

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.render;
import cr0s.warpdrive.Commons;
import cr0s.warpdrive.data.EnumDisplayAlignment;
import java.util.List;
@ -22,13 +23,6 @@ public class RenderCommons {
return Math.max(0, Math.min(255, start + Math.round(gradient * (end - start))));
}
protected static int colorARGBtoInt(final int alpha, final int red, final int green, final int blue) {
return (Commons.clamp(0, 255, alpha) << 24)
+ (Commons.clamp(0, 255, red ) << 16)
+ (Commons.clamp(0, 255, green) << 8)
+ Commons.clamp(0, 255, blue );
}
// from net.minecraft.client.gui.Gui
private static final float scaleUV = 0.00390625F; // 1/256
protected static void drawTexturedModalRect(final int x, final int y, final int u, final int v, final int sizeX, final int sizeY, final int zLevel) {
@ -56,7 +50,7 @@ public class RenderCommons {
minecraft.fontRenderer.drawString(textTitle,
scaledWidth / 4 - minecraft.fontRenderer.getStringWidth(textTitle) / 2,
y - minecraft.fontRenderer.FONT_HEIGHT,
colorARGBtoInt(230, 255, 32, 24),
Commons.colorARGBtoInt(230, 255, 32, 24),
true);
// normal message, multi-lines, centered, without shadows
@ -69,7 +63,7 @@ public class RenderCommons {
minecraft.fontRenderer.drawString(textLine,
scaledWidth / 4 - minecraft.fontRenderer.getStringWidth(textLine) / 2,
y,
colorARGBtoInt(alpha, 192, 64, 48),
Commons.colorARGBtoInt(alpha, 192, 64, 48),
false);
y += minecraft.fontRenderer.FONT_HEIGHT;
}
@ -78,4 +72,35 @@ public class RenderCommons {
GL11.glPopMatrix();
return alpha;
}
public static int drawText(final int scaledWidth, final int scaledHeight, final String text,
final String formatPrefix, final int colorText, final boolean hasShadow,
final EnumDisplayAlignment enumScreenAnchor, final int xOffset, final int yOffset,
final EnumDisplayAlignment enumTextAlignment, final float widthTextRatio, final int widthTextMin) {
// prepare the string box content and dimensions
final String textMessage = Commons.updateEscapeCodes(formatPrefix + StatCollector.translateToLocal(text));
final int widthText = Math.max(widthTextMin, Math.round(widthTextRatio * scaledWidth));
@SuppressWarnings("unchecked")
final List<String> listMessages = minecraft.fontRenderer.listFormattedStringToWidth(textMessage, widthText);
final int heightText = listMessages.size() * minecraft.fontRenderer.FONT_HEIGHT;
// compute the position
int x = Math.round(scaledWidth * enumScreenAnchor.xRatio + xOffset - enumTextAlignment.xRatio * widthText );
int y = Math.round(scaledHeight * enumScreenAnchor.yRatio + yOffset - enumTextAlignment.yRatio * heightText);
// start rendering
GL11.glPushMatrix();
GL11.glScalef(1.0F, 1.0F, 0.0F);
for (final String textLine : listMessages) {
minecraft.fontRenderer.drawString(textLine, x, y, colorText, hasShadow);
y += minecraft.fontRenderer.FONT_HEIGHT;
}
// close rendering
GL11.glPopMatrix();
return heightText;
}
}

View file

@ -0,0 +1,87 @@
package cr0s.warpdrive.render;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.CelestialObject;
import cr0s.warpdrive.data.CelestialObjectManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
@SideOnly(Side.CLIENT)
public class RenderOverlayLocation {
private static Minecraft minecraft = Minecraft.getMinecraft();
private void renderLocation(final int widthScreen, final int heightScreen) {
// get player
EntityPlayer entityPlayer = minecraft.thePlayer;
if (entityPlayer == null) {
return;
}
final int x = MathHelper.floor_double(entityPlayer.posX);
final int z = MathHelper.floor_double(entityPlayer.posZ);
// get celestial object
String name = entityPlayer.worldObj.provider.getDimensionName();
String description = "";
final CelestialObject celestialObject = CelestialObjectManager.get(entityPlayer.worldObj, x, z);
if (celestialObject != null) {
if (!celestialObject.getDisplayName().isEmpty()) {
name = celestialObject.getDisplayName();
}
description = celestialObject.getDescription();
}
// start rendering
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int yOffset = 0;
// show current location name in bold
yOffset += RenderCommons.drawText(widthScreen, heightScreen, name,
WarpDriveConfig.CLIENT_LOCATION_FORMAT,
WarpDriveConfig.CLIENT_LOCATION_COLOR,
WarpDriveConfig.CLIENT_LOCATION_HAS_SHADOW,
WarpDriveConfig.CLIENT_LOCATION_SCREEN_ALIGNMENT,
WarpDriveConfig.CLIENT_LOCATION_SCREEN_OFFSET_X,
WarpDriveConfig.CLIENT_LOCATION_SCREEN_OFFSET_Y + yOffset,
WarpDriveConfig.CLIENT_LOCATION_TEXT_ALIGNMENT,
WarpDriveConfig.CLIENT_LOCATION_WIDTH_RATIO,
WarpDriveConfig.CLIENT_LOCATION_WIDTH_MIN);
// show current location description
yOffset += RenderCommons.drawText(widthScreen, heightScreen, description,
"",
WarpDriveConfig.CLIENT_LOCATION_COLOR,
false,
WarpDriveConfig.CLIENT_LOCATION_SCREEN_ALIGNMENT,
WarpDriveConfig.CLIENT_LOCATION_SCREEN_OFFSET_X,
WarpDriveConfig.CLIENT_LOCATION_SCREEN_OFFSET_Y + yOffset,
WarpDriveConfig.CLIENT_LOCATION_TEXT_ALIGNMENT,
WarpDriveConfig.CLIENT_LOCATION_WIDTH_RATIO,
WarpDriveConfig.CLIENT_LOCATION_WIDTH_MIN);
// @TODO: show orbiting planet?
// close rendering
minecraft.getTextureManager().bindTexture(Gui.icons);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_BLEND);
}
@SubscribeEvent
public void onRender(RenderGameOverlayEvent.Pre event) {
if (event.type == ElementType.HOTBAR) {
renderLocation(event.resolution.getScaledWidth(), event.resolution.getScaledHeight());
}
}
}