Search in sources :

Example 6 with Texture2D

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));
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector4f(org.joml.Vector4f)

Example 7 with Texture2D

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);
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector4f(org.joml.Vector4f) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font)

Example 8 with Texture2D

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));
        }
    }
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Mouse(io.xol.chunkstories.api.input.Mouse) Vector4f(org.joml.Vector4f) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 9 with Texture2D

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;
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D)

Example 10 with Texture2D

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;
}
Also used : Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D)

Aggregations

Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)27 Shader (io.xol.chunkstories.api.rendering.shader.Shader)9 Vector4f (org.joml.Vector4f)6 Matrix4f (org.joml.Matrix4f)5 Vector3f (org.joml.Vector3f)5 Location (io.xol.chunkstories.api.Location)3 GameWindow (io.xol.chunkstories.api.rendering.GameWindow)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 ByteBuffer (java.nio.ByteBuffer)3 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)2 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)2 Player (io.xol.chunkstories.api.player.Player)2 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)2 CellData (io.xol.chunkstories.api.world.cell.CellData)2 DummyCell (io.xol.chunkstories.api.world.cell.DummyCell)2 MemFreeByteBuffer (io.xol.chunkstories.client.util.MemFreeByteBuffer)2 HeightmapImplementation (io.xol.chunkstories.world.summary.HeightmapImplementation)2 Vector2d (org.joml.Vector2d)2 Vector3dc (org.joml.Vector3dc)2 Entity (io.xol.chunkstories.api.entity.Entity)1