forked from ToroCraft/ToroHUD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting to refactor the GUI into different classes
- Loading branch information
Showing
8 changed files
with
393 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...orohealthmod/gui/GuiConfigToroHealth.java → ...healthmod/config/GuiConfigToroHealth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
java/net/torocraft/torohealthmod/display/EntityDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package net.torocraft.torohealthmod.display; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.client.renderer.OpenGlHelper; | ||
import net.minecraft.client.renderer.RenderHelper; | ||
import net.minecraft.client.renderer.entity.RenderManager; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityLiving; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.util.math.MathHelper; | ||
|
||
public class EntityDisplay implements ToroHealthDisplay { | ||
|
||
private static final int RENDER_HEIGHT = 20; | ||
|
||
private int x = 50; | ||
private int y = 50; | ||
|
||
private EntityLivingBase entity; | ||
private Entity leashedToEntity; | ||
private float prevYawOffset; | ||
private float prevYaw; | ||
private float prevPitch; | ||
private float prevYawHead; | ||
private float prevPrevYahHead; | ||
private int scale = 1; | ||
|
||
@Override | ||
public void setPosition(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public void setEntity(EntityLivingBase entity) { | ||
this.entity = entity; | ||
updateScale(); | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
try { | ||
pushEntityLeasedTo(); | ||
pushEntityRotations(); | ||
glDraw(); | ||
popEntityRotations(); | ||
popEntityLeasedTo(); | ||
} catch (Throwable ignore) { | ||
|
||
} | ||
} | ||
|
||
private void updateScale() { | ||
scale = MathHelper.ceil(RENDER_HEIGHT / entity.height); | ||
} | ||
|
||
private void glDraw() { | ||
GlStateManager.enableColorMaterial(); | ||
GlStateManager.pushMatrix(); | ||
|
||
GlStateManager.translate((float) x, (float) y, 50.0F); | ||
GlStateManager.scale((float) (-scale), (float) scale, (float) scale); | ||
GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); | ||
GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); | ||
GlStateManager.rotate(-100.0F, 0.0F, 1.0F, 0.0F); | ||
GlStateManager.rotate(0.0f, 1.0F, 0.0F, 0.0F); | ||
|
||
RenderHelper.enableStandardItemLighting(); | ||
|
||
GlStateManager.translate(0.0F, 0.0F, 0.0F); | ||
RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); | ||
rendermanager.setPlayerViewY(180.0F); | ||
rendermanager.setRenderShadow(false); | ||
rendermanager.doRenderEntity(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); | ||
rendermanager.setRenderShadow(true); | ||
|
||
GlStateManager.popMatrix(); | ||
RenderHelper.disableStandardItemLighting(); | ||
GlStateManager.disableRescaleNormal(); | ||
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); | ||
GlStateManager.disableTexture2D(); | ||
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); | ||
} | ||
|
||
private void popEntityLeasedTo() { | ||
if (entity instanceof EntityLiving && leashedToEntity != null) { | ||
((EntityLiving) entity).setLeashedToEntity(leashedToEntity, false); | ||
leashedToEntity = null; | ||
} | ||
} | ||
|
||
private void pushEntityLeasedTo() { | ||
if (entity instanceof EntityLiving) { | ||
if (((EntityLiving) entity).getLeashed()) { | ||
leashedToEntity = ((EntityLiving) entity).getLeashedToEntity(); | ||
((EntityLiving) entity).setLeashedToEntity(null, false); | ||
} | ||
} | ||
} | ||
|
||
private void popEntityRotations() { | ||
entity.renderYawOffset = prevYawOffset; | ||
entity.rotationYaw = prevYaw; | ||
entity.rotationPitch = prevPitch; | ||
entity.rotationYawHead = prevYawHead; | ||
entity.prevRotationYawHead = prevPrevYahHead; | ||
} | ||
|
||
private void pushEntityRotations() { | ||
prevYawOffset = entity.renderYawOffset; | ||
prevYaw = entity.rotationYaw; | ||
prevPitch = entity.rotationPitch; | ||
prevYawHead = entity.rotationYawHead; | ||
prevPrevYahHead = entity.prevRotationYawHead; | ||
entity.renderYawOffset = 0.0f; | ||
entity.rotationYaw = 0.0f; | ||
entity.rotationPitch = 0.0f; | ||
entity.rotationYawHead = 0.0f; | ||
entity.prevRotationYawHead = 0.0f; | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
java/net/torocraft/torohealthmod/display/HeartsDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package net.torocraft.torohealthmod.display; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.torocraft.torohealthmod.ToroHealthMod; | ||
import net.torocraft.torohealthmod.gui.GuiEntityStatus; | ||
|
||
public class HeartsDisplay implements ToroHealthDisplay { | ||
|
||
private static final ResourceLocation TEXTURE = new ResourceLocation(ToroHealthMod.MODID, "textures/gui/entityStatus.png"); | ||
private static final int WIDTH = 84; | ||
private static final int HEIGHT = 34; | ||
|
||
private final Minecraft mc; | ||
private final Gui gui; | ||
private int x, originX = 100; | ||
private int y, originY = 100; | ||
private EntityLivingBase entity; | ||
|
||
public HeartsDisplay(Minecraft mc, Gui gui) { | ||
this.mc = mc; | ||
this.gui = gui; | ||
} | ||
|
||
@Override | ||
public void setPosition(int x, int y) { | ||
originX = x; | ||
originY = y; | ||
resetToOrigin(); | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
if (entity == null) { | ||
return; | ||
} | ||
|
||
|
||
resetToOrigin(); | ||
mc.renderEngine.bindTexture(TEXTURE); | ||
Gui.drawModalRectWithCustomSizedTexture(x, y , 0.0f, 0.0f, WIDTH, HEIGHT, 200.0f, 200.0f); | ||
|
||
drawName(); | ||
drawHearts(); | ||
drawArmor(); | ||
} | ||
|
||
@Override | ||
public void setEntity(EntityLivingBase entity) { | ||
this.entity = entity; | ||
} | ||
|
||
private void resetToOrigin() { | ||
x = originX; | ||
y = originY; | ||
} | ||
|
||
private void drawName() { | ||
gui.drawString(mc.fontRendererObj, entity.getDisplayName().getFormattedText(), x, y, 0xFFFFFF); | ||
y += 10; | ||
} | ||
|
||
private int drawHearts() { | ||
mc.renderEngine.bindTexture(GuiEntityStatus.ICONS); | ||
int currentHealth = MathHelper.ceil(entity.getHealth()); | ||
|
||
int absorptionAmount = MathHelper.ceil(entity.getAbsorptionAmount()); | ||
int remainingAbsorption = absorptionAmount; | ||
|
||
float maxHealth = entity.getMaxHealth(); | ||
|
||
int numRowsOfHearts = MathHelper.ceil((maxHealth + (float) absorptionAmount) / 2.0F / 10.0F); | ||
int j2 = Math.max(10 - (numRowsOfHearts - 2), 3); | ||
|
||
for (int currentHeartBeingDrawn = MathHelper.ceil((maxHealth + (float) absorptionAmount) / 2.0F) | ||
- 1; currentHeartBeingDrawn >= 0; --currentHeartBeingDrawn) { | ||
int texturePosX = 16; | ||
int flashingHeartOffset = 0; | ||
|
||
int rowsOfHearts = MathHelper.ceil((float) (currentHeartBeingDrawn + 1) / 10.0F) - 1; | ||
int heartToDrawX = x + currentHeartBeingDrawn % 10 * 8; | ||
int heartToDrawY = y + rowsOfHearts * j2; | ||
|
||
int hardcoreModeOffset = 0; | ||
|
||
if (entity.world.getWorldInfo().isHardcoreModeEnabled()) { | ||
hardcoreModeOffset = 5; | ||
} | ||
|
||
gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, 16 + flashingHeartOffset * 9, 9 * hardcoreModeOffset, 9, 9); | ||
|
||
if (remainingAbsorption > 0) { | ||
if (remainingAbsorption == absorptionAmount && absorptionAmount % 2 == 1) { | ||
gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 153, 9 * hardcoreModeOffset, 9, 9); | ||
--remainingAbsorption; | ||
} else { | ||
gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 144, 9 * hardcoreModeOffset, 9, 9); | ||
remainingAbsorption -= 2; | ||
} | ||
} else { | ||
if (currentHeartBeingDrawn * 2 + 1 < currentHealth) { | ||
gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 36, 9 * hardcoreModeOffset, 9, 9); | ||
} | ||
|
||
if (currentHeartBeingDrawn * 2 + 1 == currentHealth) { | ||
gui.drawTexturedModalRect(heartToDrawX, heartToDrawY, texturePosX + 45, 9 * hardcoreModeOffset, 9, 9); | ||
} | ||
} | ||
} | ||
|
||
y += (numRowsOfHearts - 1) * j2 + 10; | ||
|
||
return remainingAbsorption; | ||
} | ||
|
||
private void drawArmor() { | ||
mc.renderEngine.bindTexture(GuiEntityStatus.ICONS); | ||
|
||
int armor = entity.getTotalArmorValue(); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
if (armor > 0) { | ||
int armorIconX = x + i * 8; | ||
|
||
/* | ||
* determines whether armor is full, half, or empty icon | ||
*/ | ||
if (i * 2 + 1 < armor) { | ||
gui.drawTexturedModalRect(armorIconX, y, 34, 9, 9, 9); | ||
} | ||
|
||
if (i * 2 + 1 == armor) { | ||
gui.drawTexturedModalRect(armorIconX, y, 25, 9, 9, 9); | ||
} | ||
|
||
if (i * 2 + 1 > armor) { | ||
gui.drawTexturedModalRect(armorIconX, y, 16, 9, 9, 9); | ||
} | ||
} | ||
} | ||
|
||
y += 10; | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
java/net/torocraft/torohealthmod/display/NumericDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package net.torocraft.torohealthmod.display; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.torocraft.torohealthmod.ToroHealthMod; | ||
|
||
public class NumericDisplay implements ToroHealthDisplay { | ||
|
||
private static final ResourceLocation TEXTURE = new ResourceLocation(ToroHealthMod.MODID, "textures/gui/entityStatus.png"); | ||
private static final int WIDTH = 100; | ||
private static final int HEIGHT = 34; | ||
|
||
private final Minecraft mc; | ||
private final Gui gui; | ||
private int x = 100; | ||
private int y = 140; | ||
private EntityLivingBase entity; | ||
|
||
public NumericDisplay(Minecraft mc, Gui gui) { | ||
this.mc = mc; | ||
this.gui = gui; | ||
} | ||
|
||
@Override | ||
public void setPosition(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
|
||
} | ||
|
||
@Override | ||
public void draw() { | ||
if (entity == null) { | ||
return; | ||
} | ||
|
||
mc.renderEngine.bindTexture(TEXTURE); | ||
|
||
/* | ||
* defines positions of each element from the top left position of | ||
* status display | ||
*/ | ||
int bgX = 0, bgY = 0, healthBarX = 2, healthBarY = 16, nameX = 50, nameY = 4, healthX = 50, healthY = 20; | ||
|
||
Gui.drawModalRectWithCustomSizedTexture(x + bgX, y + bgY, 0.0f, 0.0f, WIDTH, HEIGHT, 200.0f, 200.0f); | ||
|
||
Gui.drawModalRectWithCustomSizedTexture(x + healthBarX, y + healthBarY, 0.0f, 150.0f, 96, 16, 200.0f, 200.0f); | ||
|
||
int currentHealthWidth = (int) Math.ceil(96 * (entity.getHealth() / entity.getMaxHealth())); | ||
Gui.drawModalRectWithCustomSizedTexture(x + healthBarX, y + healthBarY, 0.0f, 100.0f, currentHealthWidth, 16, 200.0f, 200.0f); | ||
|
||
String name = entity.getDisplayName().getFormattedText(); | ||
|
||
gui.drawCenteredString(mc.fontRendererObj, name, x + nameX, y + nameY, 0xFFFFFF); | ||
gui.drawCenteredString(mc.fontRendererObj, (int) Math.ceil(entity.getHealth()) + "/" + (int) entity.getMaxHealth(), x + healthX, y + healthY, | ||
0xFFFFFF); | ||
} | ||
|
||
@Override | ||
public void setEntity(EntityLivingBase entity) { | ||
this.entity = entity; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
java/net/torocraft/torohealthmod/display/ToroHealthDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.torocraft.torohealthmod.display; | ||
|
||
import net.minecraft.entity.EntityLivingBase; | ||
|
||
public interface ToroHealthDisplay { | ||
void setEntity(EntityLivingBase entity); | ||
void setPosition(int x, int y); | ||
void draw(); | ||
} |
Oops, something went wrong.