Skip to content

Instantly share code, notes, and snippets.

@marchermans
Created January 24, 2015 13:26
Show Gist options
  • Save marchermans/b2f237d3988e178b4549 to your computer and use it in GitHub Desktop.
Save marchermans/b2f237d3988e178b4549 to your computer and use it in GitHub Desktop.
Ledger
protected abstract class Ledger
{
public int iCurrentXExtension = 24;
public int iCurrentYExtension = 24;
public int iLastXOrigin = 0;
public int iLastYOrigin = 0;
public Color iBackgroundColor = Colors.Ledgers.DEFAULT;
public IIcon iHeaderIcon;
public Color iHeaderTextColor;
public String iHeader = "";
public Boolean iOpen = false;
public LedgerDirection iDirection;
public int iLimitWidth = 128;
public int iLimitHeight = 128;
public int iMaxHeightOpen = 124;
public int iMaxHeightClosed = 24;
public int iMaxWidthOpen = 124;
public int iMaxWidthClosed = 24;
public ResourceLocation TEXTURELEFT = new ResourceLocation(Textures.Gui.Basic.LEDGERLEFT);
public ResourceLocation TEXTURERIGHT = new ResourceLocation(Textures.Gui.Basic.LEDGERRIGHT);
public void update()
{
if (iOpen && iCurrentXExtension < iMaxWidthOpen)
{
iCurrentXExtension += 4;
}
else if( !iOpen && iCurrentXExtension > iMaxWidthClosed)
{
iCurrentXExtension -= 4;
}
if (iOpen && iCurrentYExtension < iMaxHeightOpen)
{
iCurrentYExtension += 4;
}
else if(!iOpen && iCurrentYExtension > iMaxHeightClosed)
{
iCurrentYExtension -= 4;
}
}
public int getWidth()
{
if(iDirection == LedgerDirection.Left)
{
return iCurrentXExtension * -1;
}
return iCurrentXExtension;
}
public int getHeight()
{
return iCurrentYExtension;
}
/*
* parameter pX: always directly to the border of the Gui
* parameter pY: always directly under the last rendered Ledger
*/
public void drawBackGround(int pX, int pY)
{
GL11.glColor3f(iBackgroundColor.getColorRedFloat(), iBackgroundColor.getColorGreenFloat(), iBackgroundColor.getColorBlueFloat());
if(iDirection == LedgerDirection.Left)
{
mc.renderEngine.bindTexture(TEXTURELEFT);
}
else
{
mc.renderEngine.bindTexture(TEXTURERIGHT);
}
drawTexturedModalRect(pX + getWidth(), pY, 0, 0, iCurrentXExtension, 3);
drawTexturedModalRect(pX + getWidth(), pY + 3, 0, 3, iCurrentXExtension, iCurrentYExtension - 7);
drawTexturedModalRect(pX + getWidth(), pY + iCurrentYExtension - 4, 0, 252, iCurrentXExtension, 4);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
public void drawHeaderIcon(int pX, int pY)
{
drawTexturedModelRectFromIcon(pX + getWidth() + 4, pY + 4, iHeaderIcon, 16,16);
}
public void drawHeaderText(int pX, int pY, FontRenderer pFont)
{
drawCenteredString(pFont, iHeader, (iMaxWidthOpen - 48) / 2, 4, iHeaderTextColor.getColor());
}
public void draw(int pX, int pY)
{
drawBackGround(pX, pY);
drawHeaderIcon(pX, pY);
if (!iOpen)
{
return;
}
drawHeaderText(pX, pY, mc.fontRenderer);
drawForeGround(pX, pY);
iLastXOrigin = pX;
iLastYOrigin = pY;
}
public abstract void drawForeGround(int pX, int pY);
public void drawToolTips(int pMouseX, int pMouseY)
{
}
public void setFullyOpen()
{
iOpen = true;
iCurrentXExtension=iMaxWidthOpen;
iCurrentYExtension = iMaxHeightOpen;
}
public void toggleOpenState()
{
if(iOpen)
{
iOpen = false;
SessionVars.setLastOpenenedLedger(null);
}
else
{
iOpen = true;
SessionVars.setLastOpenenedLedger(this.getClass());
}
}
public boolean checkIfPointIsInLedger(int pTargetX, int pTargetY)
{
if ((iLastXOrigin <= pTargetX) && ((iLastXOrigin + getWidth()) >= pTargetX))
{
if((iLastYOrigin <= pTargetY) && ((iLastYOrigin + getHeight()) >= pTargetY))
{
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment