mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
seven segment displays work!
This commit is contained in:
parent
e0fb379b53
commit
a06fff46ba
@ -34,9 +34,9 @@ public class GUIReactorResearch extends GuiInfoContainer {
|
|||||||
reactor = te;
|
reactor = te;
|
||||||
this.xSize = 176;
|
this.xSize = 176;
|
||||||
this.ySize = 222;
|
this.ySize = 222;
|
||||||
displays[0] = new NumberDisplay(14, 25).setDigitLength(4);
|
displays[0] = new NumberDisplay(14, 25, 0x08FF00).setDigitLength(4);
|
||||||
displays[1] = new NumberDisplay(12, 63).setDigitLength(3);
|
displays[1] = new NumberDisplay(12, 63, 0x08FF00).setDigitLength(3);
|
||||||
displays[2] = new NumberDisplay(5, 101).setDigitLength(3);
|
displays[2] = new NumberDisplay(5, 101, 0x08FF00).setDigitLength(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
package com.hbm.inventory.gui;
|
package com.hbm.inventory.gui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.annotation.Nonnegative;
|
import javax.annotation.Nonnegative;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
import com.hbm.lib.Library;
|
import com.hbm.lib.Library;
|
||||||
import com.hbm.lib.RefStrings;
|
import com.hbm.lib.RefStrings;
|
||||||
@ -21,7 +24,6 @@ import net.minecraft.util.ResourceLocation;
|
|||||||
public abstract class GuiInfoContainer extends GuiContainer {
|
public abstract class GuiInfoContainer extends GuiContainer {
|
||||||
|
|
||||||
static final ResourceLocation guiUtil = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_utility.png");
|
static final ResourceLocation guiUtil = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_utility.png");
|
||||||
protected static final ResourceLocation numDisplays = new ResourceLocation(RefStrings.MODID, "textures/gui/gauges/seven_segment.pn");
|
|
||||||
|
|
||||||
public GuiInfoContainer(Container p_i1072_1_) {
|
public GuiInfoContainer(Container p_i1072_1_) {
|
||||||
super(p_i1072_1_);
|
super(p_i1072_1_);
|
||||||
@ -103,10 +105,8 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
|||||||
private int displayX;
|
private int displayX;
|
||||||
/** The display's Y coordinate **/
|
/** The display's Y coordinate **/
|
||||||
private int displayY;
|
private int displayY;
|
||||||
/** The X coordinate of the reference **/
|
/** The display's color, in hexadecimal **/
|
||||||
private int referenceX = 10;
|
private int color;
|
||||||
/** The Y coordinate of the reference **/
|
|
||||||
private int referenceY = 18;
|
|
||||||
/** The amount of padding between digits, default 3 **/
|
/** The amount of padding between digits, default 3 **/
|
||||||
@Nonnegative
|
@Nonnegative
|
||||||
private byte padding = 3;
|
private byte padding = 3;
|
||||||
@ -134,12 +134,23 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
|||||||
* Construct a new number display
|
* Construct a new number display
|
||||||
* @param dX X coordinate of the display
|
* @param dX X coordinate of the display
|
||||||
* @param dY Y coordinate of the display
|
* @param dY Y coordinate of the display
|
||||||
* @param c Color to use, invalid enums will default to yellow
|
* @param c Enum Color to use, invalid enums will default to yellow
|
||||||
*/
|
*/
|
||||||
public NumberDisplay(int x, int y, EnumChatFormatting c)
|
public NumberDisplay(int x, int y, EnumChatFormatting c)
|
||||||
{
|
{
|
||||||
this(x, y);
|
this(x, y);
|
||||||
setupColor(c);
|
setColor(enumToColor(c));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Construct a new number display
|
||||||
|
* @param x X coordinate of the display
|
||||||
|
* @param y Y coordinate of the display
|
||||||
|
* @param color Color to use, valid hexadecimal value required
|
||||||
|
*/
|
||||||
|
public NumberDisplay(int x, int y, int color)
|
||||||
|
{
|
||||||
|
this(x, y);
|
||||||
|
setColor(color);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Construct a new number display, color is yellow
|
* Construct a new number display, color is yellow
|
||||||
@ -150,26 +161,62 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
|||||||
{
|
{
|
||||||
displayX = x;
|
displayX = x;
|
||||||
displayY = y;
|
displayY = y;
|
||||||
|
setColor(0xFFFF55);
|
||||||
}
|
}
|
||||||
public void setupColor(EnumChatFormatting c)
|
/**
|
||||||
|
* Returns a hexadecimal from EnumChatFormatting
|
||||||
|
* @param c Color to use
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int enumToColor(EnumChatFormatting c)
|
||||||
{
|
{
|
||||||
byte row = 4, column = 3;
|
int hex;
|
||||||
switch (c)
|
if(c.isColor())
|
||||||
{
|
switch(c)
|
||||||
case OBFUSCATED:
|
{
|
||||||
case RESET:
|
case AQUA:
|
||||||
case STRIKETHROUGH:
|
return 0x55FFFF;
|
||||||
case UNDERLINE:
|
case BLACK:
|
||||||
break;
|
return 0x000000;
|
||||||
default:
|
case BLUE:
|
||||||
column = (byte) (c.ordinal() % 4);
|
return 0x5555FF;
|
||||||
row = (byte) Math.floorDiv(c.ordinal(), 4);
|
case DARK_AQUA:
|
||||||
break;
|
return 0x00AAAA;
|
||||||
}
|
case DARK_BLUE:
|
||||||
// System.out.println(column);
|
return 0x0000AA;
|
||||||
// System.out.println(row);
|
case DARK_GRAY:
|
||||||
referenceY = 6 * row;
|
return 0x555555;
|
||||||
referenceX = 5 * column;
|
case DARK_GREEN:
|
||||||
|
return 0x00AA00;
|
||||||
|
case DARK_PURPLE:
|
||||||
|
return 0xAA00AA;
|
||||||
|
case DARK_RED:
|
||||||
|
return 0xAA0000;
|
||||||
|
case GOLD:
|
||||||
|
return 0xFFAA00;
|
||||||
|
case GRAY:
|
||||||
|
return 0xAAAAAA;
|
||||||
|
case GREEN:
|
||||||
|
return 0x55FF55;
|
||||||
|
case LIGHT_PURPLE:
|
||||||
|
return 0xFF55FF;
|
||||||
|
case RED:
|
||||||
|
return 0xFF5555;
|
||||||
|
case WHITE:
|
||||||
|
return 0xFFFFFF;
|
||||||
|
case YELLOW:
|
||||||
|
return 0xFFFF55;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xFFFF55;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets color
|
||||||
|
* @param color - The color in hexadecimal
|
||||||
|
**/
|
||||||
|
public void setColor(int color) {
|
||||||
|
this.color = color;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Draw custom number
|
* Draw custom number
|
||||||
@ -194,10 +241,6 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
|||||||
/** Draw the previously provided number **/
|
/** Draw the previously provided number **/
|
||||||
public void drawNumber()
|
public void drawNumber()
|
||||||
{
|
{
|
||||||
// System.out.println(referenceX);
|
|
||||||
// System.out.println(referenceY);
|
|
||||||
mc.getTextureManager().bindTexture(numDisplays);
|
|
||||||
|
|
||||||
if (isFloat)
|
if (isFloat)
|
||||||
formatForFloat();
|
formatForFloat();
|
||||||
drawNumber(toDisp);
|
drawNumber(toDisp);
|
||||||
@ -221,7 +264,6 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
|||||||
/** Draw a single character (requires dispOffset to be set) **/
|
/** Draw a single character (requires dispOffset to be set) **/
|
||||||
public void drawChar(char num)
|
public void drawChar(char num)
|
||||||
{
|
{
|
||||||
// System.out.println(num);
|
|
||||||
switch (num)
|
switch (num)
|
||||||
{
|
{
|
||||||
case '1':
|
case '1':
|
||||||
@ -313,40 +355,41 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
|||||||
private void drawHorizontal(int pos)
|
private void drawHorizontal(int pos)
|
||||||
{
|
{
|
||||||
byte offset = (byte) (pos * 6);
|
byte offset = (byte) (pos * 6);
|
||||||
renderSegment(guiLeft + displayX + dispOffset + 1, guiTop + displayY + offset, referenceX + 1, referenceY, 4, 1);
|
renderSegment(guiLeft + displayX + dispOffset + 1, guiTop + displayY + offset, 4, 1);
|
||||||
//System.out.println(referenceX + 1 + ", " + referenceY + ", " + pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawPeriod()
|
private void drawPeriod()
|
||||||
{
|
{
|
||||||
renderSegment(guiLeft + displayX + dispOffset + padding - (int) Math.ceil(padding / 2) + 5, guiTop + displayY + 12, referenceX + 1, referenceY, 1, 1);
|
renderSegment(guiLeft + displayX + dispOffset + padding - (int) Math.ceil(padding / 2) + 5, guiTop + displayY + 12, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawVertical(int posX, int posY)
|
private void drawVertical(int posX, int posY)
|
||||||
{
|
{
|
||||||
byte offsetX = (byte) (posX * 5);
|
byte offsetX = (byte) (posX * 5);
|
||||||
byte offsetY = (byte) (posY * 6);
|
byte offsetY = (byte) (posY * 6);
|
||||||
renderSegment(guiLeft + displayX + offsetX + dispOffset, guiTop + displayY + offsetY + 1, referenceX, referenceY + 1, 1, 5);
|
renderSegment(guiLeft + displayX + offsetX + dispOffset, guiTop + displayY + offsetY + 1, 1, 5);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* drawTexturedModalRect() for cool kids
|
* drawTexturedModalRect() for cool kids
|
||||||
* @param renX X coordinate to render the part
|
* @param renX X coordinate to render the part
|
||||||
* @param renY Y coordinate to render the part
|
* @param renY Y coordinate to render the part
|
||||||
* @param refX X coordinate of the reference
|
|
||||||
* @param refY Y coordinate of the reference
|
|
||||||
* @param width Relevant for horizontals
|
* @param width Relevant for horizontals
|
||||||
* @param height Relevant for verticals
|
* @param height Relevant for verticals
|
||||||
*/
|
*/
|
||||||
private void renderSegment(int renX, int renY, int refX, int refY, int width, int height)
|
private void renderSegment(int renX, int renY, int width, int height)
|
||||||
{
|
{
|
||||||
final Tessellator tess = Tessellator.instance;
|
final Tessellator tess = Tessellator.instance;
|
||||||
final float z = GuiInfoContainer.this.zLevel;
|
final float z = GuiInfoContainer.this.zLevel;
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||||
tess.startDrawingQuads();
|
tess.startDrawingQuads();
|
||||||
tess.addVertexWithUV(renX, renY + height, z, refX, (refY + height));
|
tess.setColorOpaque_I(color);
|
||||||
tess.addVertexWithUV(renX + width, renY + height, z, (refX + width), (refY + height));
|
tess.addVertex(renX, renY + height, z);
|
||||||
tess.addVertexWithUV(renX + width, renY + 0, z, (refX + width), refY);
|
tess.addVertex(renX + width, renY + height, z);
|
||||||
tess.addVertexWithUV(renX, renY, z, refX, refY);
|
tess.addVertex(renX + width, renY + 0, z);
|
||||||
|
tess.addVertex(renX, renY, z);
|
||||||
tess.draw();
|
tess.draw();
|
||||||
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumber(Number num)
|
public void setNumber(Number num)
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 656 B |
Loading…
x
Reference in New Issue
Block a user