turret ammo tooltips

This commit is contained in:
Boblet 2022-07-14 16:59:17 +02:00
parent 0bb05783ce
commit 11a83911a3
8 changed files with 300 additions and 29 deletions

View File

@ -1,11 +1,6 @@
package com.hbm.inventory.gui;
import java.util.ArrayList;
import java.util.List;
import com.hbm.items.ModItems;
import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry;
import com.hbm.packet.AuxButtonPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.turret.TileEntityTurretArty;
@ -14,7 +9,6 @@ import com.hbm.util.I18nUtil;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public class GUITurretArty extends GUITurretBase {
@ -37,7 +31,7 @@ public class GUITurretArty extends GUITurretBase {
this.drawHoveringText2(objects, mouseX, mouseY, this.fontRendererObj);*/
if(this.mc.thePlayer.inventory.getItemStack() == null && this.guiLeft + 79 <= mouseX && guiLeft + 79 + 54 > mouseX && guiTop + 62 < mouseY && guiTop + 62 + 54 >= mouseY) {
/*if(this.mc.thePlayer.inventory.getItemStack() == null && this.guiLeft + 79 <= mouseX && guiLeft + 79 + 54 > mouseX && guiTop + 62 < mouseY && guiTop + 62 + 54 >= mouseY) {
boolean draw = true;
for(int i = 0; i < 9; i++) {
@ -56,18 +50,9 @@ public class GUITurretArty extends GUITurretBase {
List<Object[]> lines = new ArrayList();
lines.add(list.toArray());
lines.add(new Object[] {I18nUtil.resolveKey(selected.getDisplayName())});
this.drawHoveringText2(lines, mouseX, mouseY, this.fontRendererObj);
/*List list = new ArrayList();
ModItems.ammo_arty.getSubItems(ModItems.ammo_arty, MainRegistry.weaponTab, list);
List<Object[]> lines = new ArrayList();
for(Object o : list) {
ItemStack stack = (ItemStack) o;
lines.add(new Object[] {stack, stack.getDisplayName()});
}
this.drawHoveringText2(lines, mouseX, mouseY, this.fontRendererObj);*/
this.drawStackText(lines, mouseX, mouseY, this.fontRendererObj);
}
}
}*/
TileEntityTurretArty arty = (TileEntityTurretArty) turret;
String mode = arty.mode == arty.MODE_ARTILLERY ? "artillery" : arty.mode == arty.MODE_CANNON ? "cannon" : "manual";

View File

@ -1,5 +1,6 @@
package com.hbm.inventory.gui;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Keyboard;
@ -18,6 +19,7 @@ import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
@ -61,6 +63,41 @@ public abstract class GUITurretBase extends GuiInfoContainer {
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 22, guiTop + 30, 10, 10, mouseX, mouseY, I18nUtil.resolveKeyArray("turret.animals", turret.targetAnimals ? on : off));
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 36, guiTop + 30, 10, 10, mouseX, mouseY, I18nUtil.resolveKeyArray("turret.mobs", turret.targetMobs ? on : off));
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 50, guiTop + 30, 10, 10, mouseX, mouseY, I18nUtil.resolveKeyArray("turret.machines", turret.targetMachines ? on : off));
if(this.mc.thePlayer.inventory.getItemStack() == null && this.guiLeft + 79 <= mouseX && guiLeft + 79 + 54 > mouseX && guiTop + 62 < mouseY && guiTop + 62 + 54 >= mouseY) {
boolean draw = true;
for(int i = 0; i < 9; i++) {
if(this.isMouseOverSlot(this.inventorySlots.getSlot(i), mouseX, mouseY) && this.inventorySlots.getSlot(i).getHasStack()) {
draw = false;
break;
}
}
if(draw) {
List<ItemStack> list = new ArrayList(turret.getAmmoTypesForDisplay());
List<Object[]> lines = new ArrayList();
ItemStack selected = list.get(0);
if(list.size() > 1) {
int cycle = (int) ((System.currentTimeMillis() % (1000 * list.size())) / 1000);
selected = ((ItemStack) list.get(cycle)).copy();
selected.stackSize = 0;
list.set(cycle, selected);
}
if(list.size() < 10) {
lines.add(list.toArray());
} else {
lines.add(list.subList(0, list.size() / 2).toArray());
lines.add(list.subList(list.size() / 2, list.size()).toArray());
}
lines.add(new Object[] {I18nUtil.resolveKey(selected.getDisplayName())});
this.drawStackText(lines, mouseX, mouseY, this.fontRendererObj);
}
}
}
protected void mouseClicked(int x, int y, int i) {

View File

@ -13,7 +13,9 @@ import com.hbm.util.BobMathUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
@ -87,9 +89,20 @@ public abstract class GuiInfoContainer extends GuiContainer {
public float getZLevel() {
return this.zLevel;
}
public void setZLevel(float level) {
this.zLevel = level;
}
public RenderItem getItemRenderer() {
return this.itemRender;
}
public FontRenderer getFontRenderer() {
return this.fontRendererObj;
}
//TODO: do the funny
protected void drawHoveringText2(List lines, int x, int y, FontRenderer font) {
protected void drawStackText(List lines, int x, int y, FontRenderer font) {
if(!lines.isEmpty()) {
GL11.glDisable(GL12.GL_RESCALE_NORMAL);

View File

@ -0,0 +1,186 @@
package com.hbm.module;
import java.util.Iterator;
import java.util.List;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import com.hbm.inventory.gui.GuiInfoContainer;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
public class ModuleRichTooltip {
private GuiInfoContainer gui;
protected int colorBg = 0xF0100010;
protected int color0 = 0x505000FF;
protected int color1 = (color0 & 0xFEFEFE) >> 1 | color0 & 0xFF000000;
public ModuleRichTooltip(GuiInfoContainer gui) {
this.gui = gui;
}
public ModuleRichTooltip setBG(int colorBg) {
this.colorBg = colorBg;
return this;
}
public ModuleRichTooltip setColors(int color0, int color1) {
this.color0 = color0;
this.color1 = color1;
return this;
}
protected void drawStackText(List lines, int x, int y, FontRenderer font) {
if(!lines.isEmpty()) {
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
int height = 0;
int longestline = 0;
Iterator iterator = lines.iterator();
while(iterator.hasNext()) {
Object[] line = (Object[]) iterator.next();
int lineWidth = 0;
boolean hasStack = false;
for(Object o : line) {
if(o instanceof String) {
lineWidth += font.getStringWidth((String) o);
} else {
lineWidth += 18;
hasStack = true;
}
}
if(hasStack) {
height += 18;
} else {
height += 10;
}
if(lineWidth > longestline) {
longestline = lineWidth;
}
}
int minX = x + 12;
int minY = y - 12;
if(minX + longestline > gui.width) {
minX -= 28 + longestline;
}
if(minY + height + 6 > gui.height) {
minY = gui.height - height - 6;
}
gui.setZLevel(300F);
gui.getItemRenderer().zLevel = 300.0F;
this.drawGradientRect(minX - 3, minY - 4, minX + longestline + 3, minY - 3, colorBg, colorBg);
this.drawGradientRect(minX - 3, minY + height + 3, minX + longestline + 3, minY + height + 4, colorBg, colorBg);
this.drawGradientRect(minX - 3, minY - 3, minX + longestline + 3, minY + height + 3, colorBg, colorBg);
this.drawGradientRect(minX - 4, minY - 3, minX - 3, minY + height + 3, colorBg, colorBg);
this.drawGradientRect(minX + longestline + 3, minY - 3, minX + longestline + 4, minY + height + 3, colorBg, colorBg);
this.drawGradientRect(minX - 3, minY - 3 + 1, minX - 3 + 1, minY + height + 3 - 1, color0, color1);
this.drawGradientRect(minX + longestline + 2, minY - 3 + 1, minX + longestline + 3, minY + height + 3 - 1, color0, color1);
this.drawGradientRect(minX - 3, minY - 3, minX + longestline + 3, minY - 3 + 1, color0, color0);
this.drawGradientRect(minX - 3, minY + height + 2, minX + longestline + 3, minY + height + 3, color1, color1);
for(int index = 0; index < lines.size(); ++index) {
Object[] line = (Object[]) lines.get(index);
int indent = 0;
boolean hasStack = false;
for(Object o : line) {
if(!(o instanceof String)) {
hasStack = true;
}
}
for(Object o : line) {
if(o instanceof String) {
font.drawStringWithShadow((String) o, minX + indent, minY + (hasStack ? 4 : 0), -1);
indent += font.getStringWidth((String) o) + 2;
} else {
ItemStack stack = (ItemStack) o;
GL11.glColor3f(1F, 1F, 1F);
gui.getItemRenderer().renderItemAndEffectIntoGUI(gui.getFontRenderer(), gui.mc.getTextureManager(), stack, minX + indent, minY);
gui.getItemRenderer().renderItemOverlayIntoGUI(gui.getFontRenderer(), gui.mc.getTextureManager(), stack, minX + indent, minY, stack.stackSize == 0 ? (EnumChatFormatting.RED + "_ _") : null);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_DEPTH_TEST);
indent += 18;
}
}
if(index == 0) {
minY += 2;
}
minY += hasStack ? 18 : 10;
}
gui.setZLevel(0F);
gui.getItemRenderer().zLevel = 0.0F;
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
RenderHelper.enableStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
}
protected void drawGradientRect(int minX, int minY, int maxX, int maxY, int colorTop, int colorBottom) {
float zLevel = gui.getZLevel();
float topA = (float) (colorTop >> 24 & 255) / 255.0F;
float topR = (float) (colorTop >> 16 & 255) / 255.0F;
float topG = (float) (colorTop >> 8 & 255) / 255.0F;
float topB = (float) (colorTop & 255) / 255.0F;
float bottomA = (float) (colorBottom >> 24 & 255) / 255.0F;
float bottomR = (float) (colorBottom >> 16 & 255) / 255.0F;
float bottomG = (float) (colorBottom >> 8 & 255) / 255.0F;
float bottomB = (float) (colorBottom & 255) / 255.0F;
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_ALPHA_TEST);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glShadeModel(GL11.GL_SMOOTH);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(topR, topG, topB, topA);
tessellator.addVertex((double) maxX, (double) minY, (double) zLevel);
tessellator.addVertex((double) minX, (double) minY, (double) zLevel);
tessellator.setColorRGBA_F(bottomR, bottomG, bottomB, bottomA);
tessellator.addVertex((double) minX, (double) maxY, (double) zLevel);
tessellator.addVertex((double) maxX, (double) maxY, (double) zLevel);
tessellator.draw();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
public static class TooltipLine {
protected int contentHeight = 0;
}
}

View File

@ -6,11 +6,11 @@ import java.util.List;
import com.hbm.blocks.BlockDummyable;
import com.hbm.entity.projectile.EntityArtilleryShell;
import com.hbm.handler.BulletConfigSyncingUtil;
import com.hbm.handler.BulletConfiguration;
import com.hbm.inventory.container.ContainerTurretBase;
import com.hbm.inventory.gui.GUITurretArty;
import com.hbm.items.ModItems;
import com.hbm.lib.Library;
import com.hbm.main.MainRegistry;
import com.hbm.packet.AuxParticlePacketNT;
import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.IGUIProvider;
@ -59,13 +59,11 @@ public class TileEntityTurretArty extends TileEntityTurretBaseNT implements IGUI
if(ammoStacks != null)
return ammoStacks;
for(Integer i : getAmmoList()) {
BulletConfiguration config = BulletConfigSyncingUtil.pullConfig(i);
if(config != null && config.ammo != null) {
ammoStacks.add(new ItemStack(config.ammo));
}
}
ammoStacks = new ArrayList();
List list = new ArrayList();
ModItems.ammo_arty.getSubItems(ModItems.ammo_arty, MainRegistry.weaponTab, list);
this.ammoStacks.addAll(list);
return ammoStacks;
}

View File

@ -750,6 +750,8 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
if(ammoStacks != null)
return ammoStacks;
ammoStacks = new ArrayList();
for(Integer i : getAmmoList()) {
BulletConfiguration config = BulletConfigSyncingUtil.pullConfig(i);

View File

@ -1,5 +1,6 @@
package com.hbm.tileentity.turret;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.BlockDummyable;
@ -15,6 +16,9 @@ import com.hbm.packet.PacketDispatcher;
import api.hbm.fluid.IFluidStandardReceiver;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
@ -37,6 +41,20 @@ public class TileEntityTurretFritz extends TileEntityTurretBaseNT implements IFl
protected List<Integer> getAmmoList() {
return null;
}
@SideOnly(Side.CLIENT)
public List<ItemStack> getAmmoTypesForDisplay() {
if(ammoStacks != null)
return ammoStacks;
ammoStacks = new ArrayList();
ammoStacks.add(new ItemStack(ModItems.fluid_icon, 1, Fluids.DIESEL.getID()));
ammoStacks.add(new ItemStack(ModItems.ammo_fuel));
return ammoStacks;
}
@Override
public double getDecetorRange() {

View File

@ -1,5 +1,6 @@
package com.hbm.tileentity.turret;
import java.util.ArrayList;
import java.util.List;
import com.hbm.items.ModItems;
@ -10,9 +11,12 @@ import com.hbm.potion.HbmPotion;
import com.hbm.util.EntityDamageUtil;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.Vec3;
@ -28,6 +32,34 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT {
protected List<Integer> getAmmoList() {
return null;
}
@SideOnly(Side.CLIENT)
public List<ItemStack> getAmmoTypesForDisplay() {
if(ammoStacks != null)
return ammoStacks;
ammoStacks = new ArrayList();
ammoStacks.add(new ItemStack(ModItems.upgrade_speed_1));
ammoStacks.add(new ItemStack(ModItems.upgrade_speed_2));
ammoStacks.add(new ItemStack(ModItems.upgrade_speed_3));
ammoStacks.add(new ItemStack(ModItems.upgrade_effect_1));
ammoStacks.add(new ItemStack(ModItems.upgrade_effect_2));
ammoStacks.add(new ItemStack(ModItems.upgrade_effect_3));
ammoStacks.add(new ItemStack(ModItems.upgrade_power_1));
ammoStacks.add(new ItemStack(ModItems.upgrade_power_2));
ammoStacks.add(new ItemStack(ModItems.upgrade_power_3));
ammoStacks.add(new ItemStack(ModItems.upgrade_afterburn_1));
ammoStacks.add(new ItemStack(ModItems.upgrade_afterburn_2));
ammoStacks.add(new ItemStack(ModItems.upgrade_afterburn_3));
ammoStacks.add(new ItemStack(ModItems.upgrade_overdrive_1));
ammoStacks.add(new ItemStack(ModItems.upgrade_overdrive_2));
ammoStacks.add(new ItemStack(ModItems.upgrade_overdrive_3));
ammoStacks.add(new ItemStack(ModItems.upgrade_5g));
return ammoStacks;
}
@Override
public double getAcceptableInaccuracy() {
@ -131,7 +163,7 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT {
if(item == ModItems.upgrade_overdrive_1) blackLevel += 1;
if(item == ModItems.upgrade_overdrive_2) blackLevel += 2;
if(item == ModItems.upgrade_overdrive_3) blackLevel += 3;
if(item == ModItems.upgrade_5g) _5g = true;;
if(item == ModItems.upgrade_5g) _5g = true;
}
}
}