Begin basic HUDElement system

Need to allow moving and such by specifying a clickable area

Will probably have the element override getClickableArea() and return a default. We'll then set that to new values after being moved.
This commit is contained in:
Nicholas Ignoffo 2016-06-16 18:12:20 -07:00
parent f043eb0fde
commit 1d8a47ce1e
4 changed files with 155 additions and 49 deletions

View file

@ -0,0 +1,58 @@
package WayofTime.bloodmagic.client.hud;
import WayofTime.bloodmagic.util.handler.event.ClientHandler;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
@Getter
@Setter
public abstract class HUDElement {
private int xOffset;
private int yOffset;
private final int xOffsetDefault;
private final int yOffsetDefault;
private final RenderGameOverlayEvent.ElementType elementType;
public HUDElement(int xOffset, int yOffset, RenderGameOverlayEvent.ElementType elementType) {
this.xOffset = xOffset;
this.xOffsetDefault = xOffset;
this.yOffset = yOffset;
this.yOffsetDefault = yOffset;
this.elementType = elementType;
ClientHandler.hudElements.add(this);
}
public abstract void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks);
public abstract boolean shouldRender(Minecraft minecraft);
public void onPositionChanged() {
}
public void resetToDefault() {
this.xOffset = xOffsetDefault;
this.yOffset = yOffsetDefault;
}
public void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height) {
float f = 0.00390625F;
float f1 = 0.00390625F;
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexbuffer.pos((double)(x + 0), (double)(y + height), 0).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + height) * f1)).endVertex();
vertexbuffer.pos((double)(x + width), (double)(y + height), 0).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + height) * f1)).endVertex();
vertexbuffer.pos((double)(x + width), (double)(y + 0), 0).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + 0) * f1)).endVertex();
vertexbuffer.pos((double)(x + 0), (double)(y + 0), 0).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + 0) * f1)).endVertex();
tessellator.draw();
}
}

View file

@ -0,0 +1,89 @@
package WayofTime.bloodmagic.client.hud;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
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.minecraftforge.client.event.RenderGameOverlayEvent;
import javax.annotation.Nullable;
public class HUDElementHolding extends HUDElement {
public HUDElementHolding() {
super(0, 0, RenderGameOverlayEvent.ElementType.HOTBAR);
}
@Override
public void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks) {
ItemStack sigilHolding = minecraft.thePlayer.getHeldItemMainhand();
// TODO - Clean this mess
// Check mainhand for Sigil of Holding
if (sigilHolding == null)
return;
if (!(sigilHolding.getItem() instanceof ItemSigilHolding))
sigilHolding = minecraft.thePlayer.getHeldItemOffhand();
// Check offhand for Sigil of Holding
if (sigilHolding == null)
return;
if (!(sigilHolding.getItem() instanceof ItemSigilHolding))
return;
Gui ingameGui = minecraft.ingameGUI;
minecraft.getTextureManager().bindTexture(new ResourceLocation(Constants.Mod.MODID, "textures/gui/widgets.png"));
GlStateManager.color(1.0F, 1.0F, 1.0F);
ingameGui.drawTexturedModalRect(resolution.getScaledWidth() / 2 + 100 + getXOffset(), resolution.getScaledHeight() - 22 + getYOffset(), 0, 0, 102, 22);
int currentSlot = ItemSigilHolding.getCurrentItemOrdinal(sigilHolding);
ingameGui.drawTexturedModalRect(resolution.getScaledWidth() / 2 + 99 + (currentSlot * 20) + getXOffset(), resolution.getScaledHeight() - 23 + getYOffset(), 0, 22, 24, 24);
RenderHelper.enableGUIStandardItemLighting();
ItemStack[] holdingInv = ItemSigilHolding.getInternalInventory(sigilHolding);
int xOffset = 0;
if (holdingInv != null)
{
for (ItemStack sigil : holdingInv)
{
renderHotbarItem(resolution.getScaledWidth() / 2 + 103 + xOffset + getXOffset(), resolution.getScaledHeight() - 18 + getYOffset(), partialTicks, minecraft.thePlayer, sigil);
xOffset += 20;
}
}
RenderHelper.disableStandardItemLighting();
}
@Override
public boolean shouldRender(Minecraft minecraft) {
return true;
}
protected void renderHotbarItem(int x, int y, float partialTicks, EntityPlayer player, @Nullable ItemStack stack)
{
if (stack != null)
{
float animation = (float) stack.animationsToGo - partialTicks;
if (animation > 0.0F)
{
GlStateManager.pushMatrix();
float f1 = 1.0F + animation / 5.0F;
GlStateManager.translate((float) (x + 8), (float) (y + 12), 0.0F);
GlStateManager.scale(1.0F / f1, (f1 + 1.0F) / 2.0F, 1.0F);
GlStateManager.translate((float) (-(x + 8)), (float) (-(y + 12)), 0.0F);
}
Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(player, stack, x, y);
if (animation > 0.0F)
GlStateManager.popMatrix();
Minecraft.getMinecraft().getRenderItem().renderItemOverlays(Minecraft.getMinecraft().fontRendererObj, stack, x, y);
}
}
}

View file

@ -5,6 +5,7 @@ import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.client.helper.ShaderHelper;
import WayofTime.bloodmagic.client.hud.HUDElementHolding;
import WayofTime.bloodmagic.client.render.*;
import WayofTime.bloodmagic.client.render.entity.BloodLightRenderFactory;
import WayofTime.bloodmagic.client.render.entity.SentientArrowRenderFactory;
@ -27,7 +28,6 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -116,7 +116,7 @@ public class ClientProxy extends CommonProxy
@Override
public void postInit()
{
new HUDElementHolding();
}
@Override

View file

@ -7,23 +7,20 @@ import WayofTime.bloodmagic.api.ritual.AreaDescriptor;
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
import WayofTime.bloodmagic.api.ritual.Ritual;
import WayofTime.bloodmagic.api.ritual.RitualComponent;
import WayofTime.bloodmagic.client.hud.HUDElement;
import WayofTime.bloodmagic.client.render.RenderFakeBlocks;
import WayofTime.bloodmagic.item.ItemRitualDiviner;
import WayofTime.bloodmagic.item.ItemRitualReader;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.SigilHoldingPacketProcessor;
import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
import WayofTime.bloodmagic.util.GhostItemHelper;
import WayofTime.bloodmagic.util.handler.BMKeyBinding;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
@ -43,7 +40,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import javax.annotation.Nullable;
@ -63,10 +59,8 @@ public class ClientHandler
public TextureAtlasSprite ritualStoneDusk;
public static Minecraft minecraft = Minecraft.getMinecraft();
public static final List<BMKeyBinding> keyBindings = new ArrayList<BMKeyBinding>();
public static final BMKeyBinding keyOpenSigilHolding = new BMKeyBinding("openSigilHolding", Keyboard.KEY_H, BMKeyBinding.Key.OPEN_SIGIL_HOLDING);
public static final List<HUDElement> hudElements = new ArrayList<HUDElement>();
@SubscribeEvent
public void onTooltipEvent(ItemTooltipEvent event)
@ -158,45 +152,10 @@ public class ClientHandler
}
@SubscribeEvent
public void onGuiRender(RenderGameOverlayEvent.Pre event)
{
if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR)
{
ItemStack sigilHolding = minecraft.thePlayer.getHeldItemMainhand();
// TODO - Clean this mess
// Check mainhand for Sigil of Holding
if (sigilHolding == null)
return;
if (sigilHolding.getItem() != ModItems.sigilHolding)
sigilHolding = minecraft.thePlayer.getHeldItemOffhand();
// Check offhand for Sigil of Holding
if (sigilHolding == null)
return;
if (sigilHolding.getItem() != ModItems.sigilHolding)
return;
Gui ingameGui = minecraft.ingameGUI;
minecraft.getTextureManager().bindTexture(new ResourceLocation(Constants.Mod.MODID, "textures/gui/widgets.png"));
GlStateManager.color(1.0F, 1.0F, 1.0F);
ingameGui.drawTexturedModalRect(event.getResolution().getScaledWidth() / 2 + 100, event.getResolution().getScaledHeight() - 22, 0, 0, 102, 22);
int currentSlot = ItemSigilHolding.getCurrentItemOrdinal(sigilHolding);
ingameGui.drawTexturedModalRect(event.getResolution().getScaledWidth() / 2 + 99 + (currentSlot * 20), event.getResolution().getScaledHeight() - 23, 0, 22, 24, 24);
RenderHelper.enableGUIStandardItemLighting();
ItemStack[] holdingInv = ItemSigilHolding.getInternalInventory(sigilHolding);
int xOffset = 0;
if (holdingInv != null)
{
for (ItemStack sigil : holdingInv)
{
renderHotbarItem(event.getResolution().getScaledWidth() / 2 + 103 + xOffset, event.getResolution().getScaledHeight() - 18, event.getPartialTicks(), minecraft.thePlayer, sigil);
xOffset += 20;
}
}
RenderHelper.disableStandardItemLighting();
}
public void onHudRender(RenderGameOverlayEvent.Pre event) {
for (HUDElement element : hudElements)
if (element.getElementType() == event.getType() && element.shouldRender(minecraft))
element.render(minecraft, event.getResolution(), event.getPartialTicks());
}
private void cycleSigil(ItemStack stack, EntityPlayer player, int dWheel)