Search in sources :

Example 1 with Inventory

use of com.bladecoder.engine.model.Inventory in project bladecoder-adventure-engine by bladecoder.

the class VerbUI method createInventoryPanel.

private Table createInventoryPanel() {
    Table inventory = new Table();
    inventory.defaults().pad(MARGIN);
    for (int i = 0; i < INVENTORY_COLS * INVENTORY_ROWS; i++) {
        if (i % INVENTORY_COLS == 0)
            inventory.row();
        ImageButton.ImageButtonStyle s = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
        RendererDrawable r = new RendererDrawable();
        s.imageUp = r;
        ImageButton b = new ImageButton(s);
        inventory.add(b).fill().expand();
        b.setUserObject(i);
        inventorySlots.add(b);
        b.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                int i = (Integer) event.getListenerActor().getUserObject();
                Inventory inv = World.getInstance().getInventory();
                target = null;
                if (i < inv.getNumItems()) {
                    InteractiveActor actor = inv.get(i);
                    if (currentVerb.equals("use") || currentVerb.equals("give")) {
                        target = actor;
                    } else {
                        sceneScreen.runVerb(actor, currentVerb, null);
                    }
                }
            }
        });
        b.getImageCell().pad(MARGIN).expand().fill();
    }
    return inventory;
}
Also used : ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Inventory(com.bladecoder.engine.model.Inventory)

Example 2 with Inventory

use of com.bladecoder.engine.model.Inventory in project bladecoder-adventure-engine by bladecoder.

the class VerbUI method createArrowPanel.

private Table createArrowPanel() {
    Table arrows = new Table();
    arrows.defaults().pad(MARGIN);
    ImageButton.ImageButtonStyle s = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
    s.imageUp = style.upArrow;
    ImageButton up = new ImageButton(s);
    arrows.add(up).fillY().expandY();
    up.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            if (scroll > 0)
                scroll--;
        }
    });
    arrows.row();
    ImageButton.ImageButtonStyle s2 = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
    s2.imageUp = style.downArrow;
    ImageButton down = new ImageButton(s2);
    arrows.add(down).fillY().expandY();
    down.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            Inventory inv = World.getInstance().getInventory();
            int itemsLeft = inv.getNumItems() - scroll * INVENTORY_COLS;
            if (itemsLeft > inventorySlots.size())
                scroll++;
        }
    });
    return arrows;
}
Also used : ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Inventory(com.bladecoder.engine.model.Inventory)

Example 3 with Inventory

use of com.bladecoder.engine.model.Inventory in project bladecoder-adventure-engine by bladecoder.

the class VerbUI method act.

@Override
public void act(float delta) {
    super.act(delta);
    Inventory inv = World.getInstance().getInventory();
    // fill inventory
    for (int i = 0; i < inventorySlots.size(); i++) {
        RendererDrawable r = (RendererDrawable) inventorySlots.get(i).getImage().getDrawable();
        int pos = scroll * INVENTORY_COLS + i;
        if (pos < inv.getNumItems()) {
            r.setRenderer(inv.get(pos).getRenderer());
        } else {
            r.setRenderer(null);
        }
        inventorySlots.get(i).getImage().invalidate();
    }
}
Also used : Inventory(com.bladecoder.engine.model.Inventory)

Example 4 with Inventory

use of com.bladecoder.engine.model.Inventory in project bladecoder-adventure-engine by bladecoder.

the class InventoryUI method resize.

public void resize(int width, int height) {
    Inventory inventory = World.getInstance().getInventory();
    tileSize = (int) DPIUtils.getTouchMinSize() * 2;
    margin = (int) DPIUtils.getMarginSize();
    rowSpace = DPIUtils.getSpacing();
    int capacity = 0;
    do {
        int w = (int) (width * .7f / tileSize) * tileSize;
        int h = (int) (height * .7f / tileSize) * tileSize;
        if (autosize) {
            if (inventoryPos == InventoryPos.LEFT || inventoryPos == InventoryPos.RIGHT) {
                int w2 = tileSize * ((inventory.getNumItems() - 1) / (h / tileSize) + 1);
                if (w2 < w)
                    w = w2;
            } else {
                int h2 = tileSize * ((inventory.getNumItems() - 1) / (w / tileSize) + 1);
                if (h2 < h)
                    h = h2;
            }
        }
        cols = w / tileSize;
        rows = h / tileSize;
        setSize(w + (cols - 1) * rowSpace + margin * 2, h + (rows - 1) * rowSpace + margin * 2);
        capacity = cols * rows;
        if (inventory.getNumItems() > capacity) {
            tileSize *= .8;
        }
    } while (inventory.getNumItems() > capacity);
    if (inventory.getNumItems() > capacity)
        EngineLogger.error("Items in inventory excees the UI capacity");
    setVisible(false);
    if (inventoryPos == InventoryPos.TOP) {
        orgPos.set((width - getWidth()) / 2, height + getHeight());
        targetPos.set((width - getWidth()) / 2, height - getHeight() - DPIUtils.getSpacing());
    } else if (inventoryPos == InventoryPos.DOWN) {
        orgPos.set((width - getWidth()) / 2, -getHeight());
        targetPos.set((width - getWidth()) / 2, DPIUtils.getSpacing());
    } else if (inventoryPos == InventoryPos.LEFT) {
        orgPos.set(-getWidth(), (height - getHeight()) / 2);
        // TODO
        targetPos.set(DPIUtils.getSpacing(), (height - getHeight()) / 2);
    } else if (inventoryPos == InventoryPos.RIGHT) {
        // TODO
        orgPos.set(width + getWidth(), (height - getHeight()) / 2);
        // TODO
        targetPos.set(width - getWidth() - DPIUtils.getSpacing(), (height - getHeight()) / 2);
    } else {
        orgPos.set((width - getWidth()) / 2, -getHeight());
        targetPos.set((width - getWidth()) / 2, (height - getHeight()) / 2);
    }
    setX(orgPos.x);
    setY(orgPos.y);
    if (menuButton != null) {
        menuButton.setPosition(getWidth() - menuButton.getWidth() / 2, (getHeight() - menuButton.getHeight()) / 2);
        float iconSize = DPIUtils.getPrefButtonSize();
        menuButton.setSize(iconSize, iconSize);
    }
}
Also used : Inventory(com.bladecoder.engine.model.Inventory)

Example 5 with Inventory

use of com.bladecoder.engine.model.Inventory in project bladecoder-adventure-engine by bladecoder.

the class InventoryUI method draw.

@Override
public void draw(Batch batch, float alpha) {
    Inventory inventory = World.getInstance().getInventory();
    if (!inventory.isVisible()) {
        setVisible(false);
        return;
    }
    if (style.background != null) {
        style.background.draw(batch, getX(), getY(), getWidth(), getHeight());
    }
    // DRAW ITEMS
    int capacity = cols * rows;
    for (int i = 0; i < inventory.getNumItems() && i < capacity; i++) {
        SpriteActor a = inventory.get(i);
        ActorRenderer r = a.getRenderer();
        float size = (tileSize - rowSpace) / (r.getHeight() > r.getWidth() ? r.getHeight() : r.getWidth());
        float x = i % cols;
        float y = (rows - 1) - i / cols;
        if (style.itemBackground != null) {
            style.itemBackground.draw(batch, getX() + x * tileSize + x * rowSpace + margin, getY() + y * tileSize + y * rowSpace + margin, tileSize, tileSize);
        }
        r.draw((SpriteBatch) batch, getX() + x * tileSize + x * rowSpace + tileSize / 2 + margin, getY() + (tileSize - r.getHeight() * size) / 2 + y * tileSize + y * rowSpace + margin, size, 0f, a.getTint());
    }
    super.draw(batch, alpha);
}
Also used : SpriteActor(com.bladecoder.engine.model.SpriteActor) ActorRenderer(com.bladecoder.engine.model.ActorRenderer) Inventory(com.bladecoder.engine.model.Inventory)

Aggregations

Inventory (com.bladecoder.engine.model.Inventory)6 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)2 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 SpriteActor (com.bladecoder.engine.model.SpriteActor)1