Search in sources :

Example 16 with Polygon

use of com.badlogic.gdx.math.Polygon in project bladecoder-adventure-engine by bladecoder.

the class DefaultSceneScreen method drawHotspots.

private void drawHotspots(SpriteBatch batch) {
    final World world = World.getInstance();
    for (BaseActor a : world.getCurrentScene().getActors().values()) {
        if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer())
            continue;
        InteractiveActor ia = (InteractiveActor) a;
        if (!ia.canInteract())
            continue;
        Polygon p = a.getBBox();
        if (p == null) {
            EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId());
        }
        Rectangle r = a.getBBox().getBoundingRectangle();
        unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0);
        world.getSceneCamera().scene2screen(viewport, unprojectTmp);
        if (!showDesc || ia.getDesc() == null) {
            float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier();
            if (ia.getVerb("leave") != null) {
                TransformDrawable drawable = (TransformDrawable) getUI().getSkin().getDrawable("leave");
                drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size / 2, size / 2, size, size, 1.0f, 1.0f, calcLeaveArrowRotation(ia));
            } else {
                Drawable drawable = getUI().getSkin().getDrawable("hotspot");
                if (drawable != null)
                    drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size);
            }
        } else {
            BitmapFont font = getUI().getSkin().getFont("desc");
            String desc = ia.getDesc();
            if (desc.charAt(0) == I18N.PREFIX)
                desc = I18N.getString(desc.substring(1));
            textLayout.setText(font, desc);
            float textX = unprojectTmp.x - textLayout.width / 2;
            float textY = unprojectTmp.y + textLayout.height;
            RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK);
            font.draw(batch, textLayout, textX, textY);
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) Rectangle(com.badlogic.gdx.math.Rectangle) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Polygon(com.badlogic.gdx.math.Polygon) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 17 with Polygon

use of com.badlogic.gdx.math.Polygon in project bladecoder-adventure-engine by bladecoder.

the class RetroSceneScreen method drawHotspots.

private void drawHotspots(SpriteBatch batch) {
    final World world = World.getInstance();
    for (BaseActor a : world.getCurrentScene().getActors().values()) {
        if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer())
            continue;
        InteractiveActor ia = (InteractiveActor) a;
        if (!ia.canInteract())
            continue;
        Polygon p = a.getBBox();
        if (p == null) {
            EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId());
        }
        Rectangle r = a.getBBox().getBoundingRectangle();
        unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0);
        world.getSceneCamera().scene2screen(worldViewport, unprojectTmp);
        if (world.getInventory().isVisible()) {
        // unprojectTmp.y += verbUI.getHeight();
        }
        if (ia.getDesc() == null) {
            float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier();
            Drawable drawable = ((TextureRegionDrawable) getUI().getSkin().getDrawable("circle")).tint(Color.RED);
            drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size);
        } else {
            BitmapFont font = getUI().getSkin().getFont("desc");
            String desc = ia.getDesc();
            if (desc.charAt(0) == I18N.PREFIX)
                desc = I18N.getString(desc.substring(1));
            textLayout.setText(font, desc);
            float textX = unprojectTmp.x - textLayout.width / 2;
            float textY = unprojectTmp.y + textLayout.height;
            RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK);
            font.draw(batch, textLayout, textX, textY);
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Rectangle(com.badlogic.gdx.math.Rectangle) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Polygon(com.badlogic.gdx.math.Polygon) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Aggregations

Polygon (com.badlogic.gdx.math.Polygon)17 Vector2 (com.badlogic.gdx.math.Vector2)7 BaseActor (com.bladecoder.engine.model.BaseActor)7 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)6 AnchorActor (com.bladecoder.engine.model.AnchorActor)5 Rectangle (com.badlogic.gdx.math.Rectangle)4 SpriteActor (com.bladecoder.engine.model.SpriteActor)4 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)3 Scene (com.bladecoder.engine.model.Scene)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 MapObject (com.badlogic.gdx.maps.MapObject)2 EllipseMapObject (com.badlogic.gdx.maps.objects.EllipseMapObject)2 PolygonMapObject (com.badlogic.gdx.maps.objects.PolygonMapObject)2 RectangleMapObject (com.badlogic.gdx.maps.objects.RectangleMapObject)2 TiledMapTileMapObject (com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject)2 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)2 World (com.bladecoder.engine.model.World)2 MapLayer (com.badlogic.gdx.maps.MapLayer)1 PolylineMapObject (com.badlogic.gdx.maps.objects.PolylineMapObject)1