All Downloads are FREE. Search and download functionalities are using the official Maven repository.

games.rednblack.h2d.extension.typinglabel.TypingLabelDrawableLogic Maven / Gradle / Ivy

There is a newer version: 0.1.4
Show newest version
package games.rednblack.h2d.extension.typinglabel;

import com.artemis.ComponentMapper;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import games.rednblack.editor.renderer.components.DimensionsComponent;
import games.rednblack.editor.renderer.components.ParentNodeComponent;
import games.rednblack.editor.renderer.components.TintComponent;
import games.rednblack.editor.renderer.components.TransformComponent;
import games.rednblack.editor.renderer.components.label.LabelComponent;
import games.rednblack.editor.renderer.systems.render.logic.DrawableLogic;
import games.rednblack.editor.renderer.utils.TransformMathUtils;

public class TypingLabelDrawableLogic implements DrawableLogic {

    protected ComponentMapper labelComponentMapper;
    protected ComponentMapper typingLabelComponentMapper;
    protected ComponentMapper tintComponentMapper;
    protected ComponentMapper dimensionsComponentMapper;
    protected ComponentMapper transformMapper;
    protected ComponentMapper parentNodeComponentComponentMapper;

    private final Color tmpColor = new Color();

    @Override
    public void draw(Batch batch, int entity, float parentAlpha, RenderingType renderingType) {
        TransformComponent entityTransformComponent = transformMapper.get(entity);
        LabelComponent labelComponent = labelComponentMapper.get(entity);
        DimensionsComponent dimensionsComponent = dimensionsComponentMapper.get(entity);
        TintComponent tint = tintComponentMapper.get(entity);
        TypingLabelComponent typingLabelComponent = typingLabelComponentMapper.get(entity);

        tmpColor.set(tint.color);

        if (labelComponent.style.background != null) {
            batch.setColor(tmpColor);
            labelComponent.style.background.draw(batch, entityTransformComponent.x, entityTransformComponent.y, dimensionsComponent.width, dimensionsComponent.height);
        }

        if(labelComponent.style.fontColor != null) tmpColor.mul(labelComponent.style.fontColor);
        tmpColor.a *= tintComponentMapper.get(parentNodeComponentComponentMapper.get(entity).parentEntity).color.a;

        TransformMathUtils.computeTransform(entityTransformComponent).mulLeft(batch.getTransformMatrix());
        TransformMathUtils.applyTransform(batch, entityTransformComponent);

        if (typingLabelComponent == null) {
            labelComponent.cache.tint(tmpColor);
            labelComponent.cache.draw(batch);
        } else if (typingLabelComponent.typingLabel != null) {
            typingLabelComponent.typingLabel.setColor(tmpColor);
            typingLabelComponent.typingLabel.draw(batch, 1);
        }

        TransformMathUtils.resetTransform(batch, entityTransformComponent);
    }

    @Override
    public void beginPipeline() {

    }

    @Override
    public void endPipeline() {

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy