use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-api by Hugobros3.
the class InputText method render.
@Override
public void render(RenderingInterface renderer) {
String text = this.text;
if (password) {
String passworded = "";
for (@SuppressWarnings("unused") char c : text.toCharArray()) passworded += "*";
text = passworded;
}
Texture2D backgroundTexture = renderer.textures().getTexture(isFocused() ? "./textures/gui/textbox.png" : "./textures/gui/textboxnofocus.png");
if (this.isTransparent)
backgroundTexture = renderer.textures().getTexture(isFocused() ? "./textures/gui/textboxnofocustransp.png" : "./textures/gui/textboxtransp.png");
backgroundTexture.setLinearFiltering(false);
renderer.getGuiRenderer().drawCorneredBoxTiled(xPosition - 0 * scale(), yPosition - 0 * scale(), getWidth() + 0 * scale(), getHeight() + 0 * scale(), 4, backgroundTexture, 32, scale());
renderer.getFontRenderer().drawStringWithShadow(ttfFont, xPosition + 4 * scale(), yPosition + 1 * scale(), text + ((isFocused() && System.currentTimeMillis() % 1000 > 500) ? "|" : ""), scale(), scale(), new Vector4f(1.0f));
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-api by Hugobros3.
the class LargeButtonIcon method render.
@Override
public void render(RenderingInterface renderer) {
String localizedText = layer.getGameWindow().getClient().getContent().localization().localize(text);
Texture2D buttonTexture = renderer.textures().getTexture("./textures/gui/mainMenu.png");
if (isFocused() || isMouseOver())
buttonTexture = renderer.textures().getTexture("./textures/gui/mainMenuOver.png");
buttonTexture.setLinearFiltering(false);
renderer.getGuiRenderer().drawCorneredBoxTiled(xPosition, yPosition, getWidth(), getHeight(), 4 * scale(), buttonTexture, 32, scale());
Font font = layer.getGameWindow().getFontRenderer().getFont("LiberationSansNarrow-Bold__aa", 32f);
float a = 0.5f;
// a = 1;
float yPositionText = yPosition + 26 * scale();
float centering = getWidth() / 2 - font.getWidth(localizedText) * a * scale() / 2;
renderer.getFontRenderer().drawString(font, xPosition + centering + scale(), yPositionText - scale(), localizedText, a * scale(), new Vector4f(161 / 255f, 161 / 255f, 161 / 255f, 1));
renderer.getFontRenderer().drawString(font, xPosition + centering, yPositionText, localizedText, a * scale(), new Vector4f(38 / 255f, 38 / 255f, 38 / 255f, 1));
renderer.textures().getTexture("./textures/gui/icons/" + iconName + ".png").setLinearFiltering(false);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(xPosition + getWidth() / 2 - 16 * scale(), yPosition + getHeight() / 2 - 26 * scale(), 32 * scale(), 32 * scale(), 0, 1, 1, 0, renderer.textures().getTexture("./textures/gui/icons/" + iconName + ".png"), false, true, null);
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.
the class InventoryGridRenderer method drawInventory.
public void drawInventory(RenderingInterface renderer, int x, int y, int scale, boolean summary, int blankLines, int highlightSlot) {
Mouse mouse = renderer.getClient().getInputsManager().getMouse();
if (getInventory() == null)
return;
int cornerSize = 8 * scale;
int internalWidth = getInventory().getWidth() * 24 * scale;
int height = summary ? 1 : getInventory().getHeight();
int internalHeight = (height + (summary ? 0 : 1) + blankLines) * 24 * scale;
int slotSize = 24 * scale;
Texture2D inventoryTexture = renderer.textures().getTexture("./textures/gui/inventory/inventory.png");
inventoryTexture.setLinearFiltering(false);
Vector4f color = new Vector4f(1f, 1f, 1f, summary ? 0.5f : 1f);
// All 8 corners
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y + internalHeight + cornerSize, cornerSize, cornerSize, 0, 0.03125f, 0.03125f, 0, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y + internalHeight + cornerSize, internalWidth, cornerSize, 0.03125f, 0.03125f, 0.96875f, 0, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y + internalHeight + cornerSize, cornerSize, cornerSize, 0.96875f, 0.03125f, 1f, 0, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y, cornerSize, cornerSize, 0, 1f, 0.03125f, 248 / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y, internalWidth, cornerSize, 0.03125f, 1f, 0.96875f, 248 / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y, cornerSize, cornerSize, 0.96875f, 1f, 1f, 248 / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x, y + cornerSize, cornerSize, internalHeight, 0, 248f / 256f, 0.03125f, 8f / 256f, inventoryTexture, true, true, color);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + internalWidth, y + cornerSize, cornerSize, internalHeight, 248 / 256f, 248f / 256f, 1f, 8f / 256f, inventoryTexture, true, true, color);
// Actual inventory slots
int sumSlots2HL = 0;
selectedSlot = null;
for (int i = 0; i < getInventory().getWidth(); i++) {
for (int j = 0; j < height; j++) {
boolean mouseOver = mouse.getCursorX() > x + cornerSize + i * slotSize && mouse.getCursorX() <= x + cornerSize + i * slotSize + slotSize && mouse.getCursorY() > y + cornerSize + j * slotSize && mouse.getCursorY() <= y + cornerSize + j * slotSize + slotSize;
// Just a dirt hack to always keep selected slot values where we want them
if (mouseOver && selectedSlot == null) {
selectedSlot = new int[] { i, j };
}
ItemPile selectedPile = null;
if (selectedSlot != null)
selectedPile = getInventory().getItemPileAt(selectedSlot[0], selectedSlot[1]);
ItemPile thisPile = getInventory().getItemPileAt(i, j);
if (summary) {
ItemPile summaryBarSelected = getInventory().getItemPileAt(highlightSlot, 0);
if (summaryBarSelected != null && i == summaryBarSelected.getX()) {
sumSlots2HL = summaryBarSelected.getItem().getDefinition().getSlotsWidth();
}
if (sumSlots2HL > 0 || (summaryBarSelected == null && highlightSlot == i)) {
sumSlots2HL--;
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 32f / 256f, 176 / 256f, 56 / 256f, 152 / 256f, inventoryTexture, true, true, color);
} else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 176 / 256f, 32f / 256f, 152 / 256f, inventoryTexture, true, true, color);
} else {
if (mouseOver || (selectedPile != null && thisPile != null && selectedPile.getX() == thisPile.getX() && selectedPile.getY() == thisPile.getY())) {
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 32f / 256f, 176 / 256f, 56 / 256f, 152 / 256f, inventoryTexture, true, true, color);
} else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 176 / 256f, 32f / 256f, 152 / 256f, inventoryTexture, true, true, color);
}
}
}
// Blank part ( usefull for special inventories, ie player )
for (int j = getInventory().getHeight(); j < getInventory().getHeight() + blankLines; j++) {
for (int i = 0; i < getInventory().getWidth(); i++) {
if (j == getInventory().getHeight()) {
if (i == getInventory().getWidth() - 1)
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 224f / 256f, 152 / 256f, 248 / 256f, 128 / 256f, inventoryTexture, true, true, color);
else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 152 / 256f, 32f / 256f, 128 / 256f, inventoryTexture, true, true, color);
} else {
if (i == getInventory().getWidth() - 1)
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 224f / 256f, 56 / 256f, 248 / 256f, 32 / 256f, inventoryTexture, true, true, color);
else
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + j * slotSize, slotSize, slotSize, 8f / 256f, 56 / 256f, 32f / 256f, 32 / 256f, inventoryTexture, true, true, color);
}
}
}
// Top part
if (!summary) {
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 8f / 256f, 32f / 256f, 32f / 256f, 8f / 256f, inventoryTexture, true, true, color);
for (int i = 1; i < getInventory().getWidth() - 2; i++) {
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + i * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 32f / 256f, 32f / 256f, 56f / 256f, 8f / 256f, inventoryTexture, true, true, color);
}
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + (getInventory().getWidth() - 2) * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 200f / 256f, 32f / 256f, 224 / 256f, 8f / 256f, inventoryTexture, true, true, color);
closedButton = mouse.getCursorX() > x + cornerSize + (getInventory().getWidth() - 1) * slotSize && mouse.getCursorX() <= x + cornerSize + (getInventory().getWidth() - 1) * slotSize + slotSize && mouse.getCursorY() > y + cornerSize + internalHeight - slotSize && mouse.getCursorY() <= y + cornerSize + internalHeight;
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(x + cornerSize + (getInventory().getWidth() - 1) * slotSize, y + cornerSize + internalHeight - slotSize, slotSize, slotSize, 224f / 256f, 32f / 256f, 248f / 256f, 8f / 256f, inventoryTexture, true, true, color);
renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().getFont("LiberationSans-Bold", 12), x + cornerSize + 6, y + cornerSize + internalHeight - slotSize + 2 * scale, getInventory().getInventoryName(), scale, scale, new Vector4f(1, 1, 1, 1));
}
// Get rid of any remaining GUI elements or else they will draw on top of the
// items
renderer.getGuiRenderer().drawBuffer();
// Draw the actual items
for (ItemPile pile : getInventory()) {
int i = pile.getX();
int j = pile.getY();
if (pile != null && (!summary || j == 0)) {
int center = summary ? slotSize * (pile.getItem().getDefinition().getSlotsHeight() - 1) / 2 : 0;
pile.getItem().getDefinition().getRenderer().renderItemInInventory(renderer, pile, x + cornerSize + i * slotSize, y - center + cornerSize + j * slotSize, scale);
}
}
// )
for (ItemPile pile : getInventory()) {
int i = pile.getX();
int j = pile.getY();
if (pile != null && (!summary || j == 0)) {
int amountToDisplay = pile.getAmount();
// If we selected this item
if ((InventoryView.selectedItem != null && InventoryView.selectedItem.getInventory() != null && getInventory().equals(InventoryView.selectedItem.getInventory()) && InventoryView.selectedItem.getX() == i && InventoryView.selectedItem.getY() == j)) {
amountToDisplay -= InventoryView.selectedItemAmount;
}
// Draw amount of items in the pile
if (amountToDisplay > 1)
renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), x + cornerSize + ((pile.getItem().getDefinition().getSlotsWidth() - 1.0f) + i) * slotSize, y + cornerSize + j * slotSize, amountToDisplay + "", scale, scale, new Vector4f(1, 1, 1, 1));
}
}
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.
the class TrueTypeFont method getLinesHeight.
public int getLinesHeight(String whatchars, float clipX) {
if (whatchars == null)
return 0;
boolean clip = clipX != -1;
int lines = 1;
int i = 0;
char charCurrent;
Glyph glyph;
int totalwidth = 0;
while (i < whatchars.length()) {
charCurrent = whatchars.charAt(i);
Texture2D pageTexture = glTextures[charCurrent / 256];
if (pageTexture == null)
pageTexture = createPage(charCurrent / 256);
glyph = glyphs[charCurrent];
if (glyph != null) {
if (charCurrent == '#' && whatchars.length() - i - 1 >= 6 && (whatchars.toCharArray()[i + 1] != '#') && HexTools.isHexOnly(whatchars.substring(i + 1, i + 7))) {
if (!(i > 1 && whatchars.toCharArray()[i - 1] == '#')) {
i += 7;
continue;
}
} else if (charCurrent == '\n') {
totalwidth = 0;
lines++;
} else {
if (clip && (totalwidth + (glyph.width)) > clipX) {
lines++;
totalwidth = 0;
continue;
}
if (glyph.width < 3)
totalwidth += 1;
totalwidth += (glyph.width);
}
i++;
}
}
return lines;
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories-api by Hugobros3.
the class DefaultWorldEnvironment method getGrassTexture.
@Override
public Texture2D getGrassTexture(RenderingInterface renderer) {
Texture2D vegetationTexture = renderer.textures().getTexture(grassColorTexture);
vegetationTexture.setMipMapping(false);
vegetationTexture.setLinearFiltering(true);
return vegetationTexture;
}
Aggregations