package com.yolp900.itsjustacharm.client.guis.huds;
import com.yolp900.itsjustacharm.reference.LibGuis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import java.util.List;
public class HudAffinityInfoPopup extends ModHud.ModTickingHud {
public static final int MAX_TIME = 100;
private Minecraft mc;
private List<String> popupStrings;
private int color;
private ResourceLocation affinityTexture;
private ItemStack stack;
private int time;
public HudAffinityInfoPopup() {
this.mc = Minecraft.getMinecraft();
popupStrings = null;
this.color = 0xffffff;
this.affinityTexture = null;
}
@Override
public void tick(ScaledResolution resolution, float partialTicks) {
float alpha = 0.0F;
boolean info = false;
if (time > 0 && time < 10) {
alpha = (float)(time-1)/(2*time);
} else if (time > 9 && time < 90) {
alpha = 0.5F;
info = true;
} else if (time > 89) {
int t = time - 89;
float a = t-1;
float b = 2*t;
float c = a/b;
alpha = (0.5F - c);
}
if (popupStrings != null && popupStrings.size() != 0) {
boolean affinityIcon = false;
if (affinityTexture != null) {
affinityIcon = true;
}
boolean stackIcon = false;
if (stack != null) {
stackIcon = true;
}
mc.renderEngine.bindTexture(LibGuis.LibHuds.AffinityInteraction.getTexture());
int height = 24;
int v = 0;
if (popupStrings.size() > 1) {
height = 48;
v = 24;
}
int x = 8;
int y = (resolution.getScaledHeight() / 2) - (height / 2);
GL11.glColor4f(1.0F, 1.0F, 1.0F, alpha);
drawTexturedModalRect(x, y, 0, v, 8, height);
x += 8;
if (affinityIcon || stackIcon) {
drawTexturedModalRect(x, y, 8, v, 16, height);
x += 16;
}
int textXPos = x;
int width = 0;
for (String string : popupStrings) {
if (width < mc.fontRendererObj.getStringWidth(string)) {
width = mc.fontRendererObj.getStringWidth(string);
}
}
drawTexturedModalRect(x, y, 8, v, width + 8, height);
x += (width + 8);
drawTexturedModalRect(x, y, 248, v, 8, height);
if (info) {
if (affinityIcon) {
mc.renderEngine.bindTexture(affinityTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F);
drawModalRectWithCustomSizedTexture(12, y + 4, 0, 0, 16, 16, 16, 16);
}
if (stackIcon) {
GlStateManager.color(1F, 1F, 1F, 1F);
RenderHelper.enableGUIStandardItemLighting();
mc.getRenderItem().renderItemIntoGUI(stack, 12, y + 28);
}
int stringHeight = 0;
for (String string : popupStrings) {
drawString(mc.fontRendererObj, string, textXPos + 4, y + 8 + (24 * stringHeight), color);
stringHeight++;
}
}
}
time++;
if (time > MAX_TIME) {
stopRendering();
}
}
@Override
public void startRendering(EntityPlayer player, World world) {
super.startRendering(player, world);
time = 0;
}
public void set(List<String> popup, int color, ResourceLocation affinityTexture, ItemStack stack) {
setPopupStrings(popup);
setColor(color);
setAffinityTexture(affinityTexture);
setBlock(stack);
}
public void setPopupStrings(List<String> popup) {
this.popupStrings = popup;
}
public void setColor(int color) {
this.color = color;
}
public void setAffinityTexture(ResourceLocation affinityTexture) {
this.affinityTexture = affinityTexture;
}
public void setBlock(ItemStack stack) {
this.stack = stack;
}
}