Search in sources :

Example 1 with BlockBar

use of io.anuke.mindustry.world.BlockBar in project Mindustry by Anuken.

the class Renderer method drawOverlay.

void drawOverlay() {
    // draw tutorial placement point
    if (world.getMap().name.equals("tutorial") && control.tutorial().showBlock()) {
        int x = world.getCore().x + control.tutorial().getPlacePoint().x;
        int y = world.getCore().y + control.tutorial().getPlacePoint().y;
        int rot = control.tutorial().getPlaceRotation();
        Lines.stroke(1f);
        Draw.color(Color.YELLOW);
        Lines.square(x * tilesize, y * tilesize, tilesize / 2f + Mathf.sin(Timers.time(), 4f, 1f));
        Draw.color(Color.ORANGE);
        Lines.stroke(2f);
        if (rot != -1) {
            Lines.lineAngle(x * tilesize, y * tilesize, rot * 90, 6);
        }
        Draw.reset();
    }
    // draw config selected block
    if (ui.configfrag.isShown()) {
        Tile tile = ui.configfrag.getSelectedTile();
        Draw.color(Colors.get("accent"));
        Lines.stroke(1f);
        Lines.square(tile.drawx(), tile.drawy(), tile.block().width * tilesize / 2f + 1f);
        Draw.reset();
    }
    int tilex = control.input().getBlockX();
    int tiley = control.input().getBlockY();
    if (android) {
        Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
        tilex = Mathf.scl2(vec.x, tilesize);
        tiley = Mathf.scl2(vec.y, tilesize);
    }
    InputHandler input = control.input();
    // draw placement box
    if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android) && control.input().drawPlace())) {
        input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
        Lines.stroke(1f);
        Draw.color(Color.SCARLET);
        for (SpawnPoint spawn : world.getSpawns()) {
            Lines.dashCircle(spawn.start.worldx(), spawn.start.worldy(), enemyspawnspace);
        }
        if (world.getCore() != null) {
            Draw.color(Color.LIME);
            Lines.poly(world.getSpawnX(), world.getSpawnY(), 4, 6f, Timers.time() * 2f);
        }
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
    } else if (input.breakMode.delete && control.input().drawPlace() && (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements)) && (input.placeMode.delete || input.breakMode.both || !android)) {
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
        else
            input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
    }
    if (ui.toolfrag.confirming) {
        ToolFragment t = ui.toolfrag;
        PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
    }
    Draw.reset();
    // draw selected block bars and info
    if (input.recipe == null && !ui.hasMouse()) {
        Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
        if (tile != null && tile.block() != Blocks.air) {
            Tile target = tile;
            if (tile.isLinked())
                target = tile.getLinked();
            if (showBlockDebug && target.entity != null) {
                Draw.color(Color.RED);
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Vector2 v = new Vector2();
                Draw.tcolor(Color.YELLOW);
                Draw.tscl(0.25f);
                Array<Object> arr = target.block().getDebugInfo(target);
                StringBuilder result = new StringBuilder();
                for (int i = 0; i < arr.size / 2; i++) {
                    result.append(arr.get(i * 2));
                    result.append(": ");
                    result.append(arr.get(i * 2 + 1));
                    result.append("\n");
                }
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.color(0f, 0f, 0f, 0.5f);
                Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.tscl(fontscale);
                Draw.reset();
            }
            if (Inputs.keyDown("block_info") && target.block().fullDescription != null) {
                Draw.color(Colors.get("accent"));
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Draw.color();
            }
            if (target.entity != null) {
                int bot = 0, top = 0;
                for (BlockBar bar : target.block().bars) {
                    float offset = Mathf.sign(bar.top) * (target.block().height / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) + (bar.top ? -1f : 0f);
                    float value = bar.value.get(target);
                    if (MathUtils.isEqual(value, -1f))
                        continue;
                    drawBar(bar.color, target.drawx(), target.drawy() + offset, value);
                    if (bar.top)
                        top++;
                    else
                        bot++;
                }
            }
            target.block().drawSelect(target);
        }
    }
    if ((!debug || showUI) && Settings.getBool("healthbars")) {
        // draw entity health bars
        for (Enemy entity : enemyGroup.all()) {
            drawHealth(entity);
        }
        for (Player player : playerGroup.all()) {
            if (!player.isDead() && !player.isAndroid)
                drawHealth(player);
        }
    }
}
Also used : InputHandler(io.anuke.mindustry.input.InputHandler) Player(io.anuke.mindustry.entities.Player) Tile(io.anuke.mindustry.world.Tile) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) ToolFragment(io.anuke.mindustry.ui.fragments.ToolFragment) Vector2(com.badlogic.gdx.math.Vector2) Enemy(io.anuke.mindustry.entities.enemies.Enemy) BlockBar(io.anuke.mindustry.world.BlockBar) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)1 Player (io.anuke.mindustry.entities.Player)1 Enemy (io.anuke.mindustry.entities.enemies.Enemy)1 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 ToolFragment (io.anuke.mindustry.ui.fragments.ToolFragment)1 BlockBar (io.anuke.mindustry.world.BlockBar)1 Tile (io.anuke.mindustry.world.Tile)1