mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-04 23:38:28 +07:00
Added support for MonsterLabelManager to draw monster health
Added support for MonsterLabelManager to draw monster health Added percent and modal params to PaletteIndexedColorDrawable to allow use as a progress bar
This commit is contained in:
@ -13,9 +13,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.attributes.Attributes;
|
||||
import com.riiablo.attributes.Stat;
|
||||
import com.riiablo.camera.IsometricCamera;
|
||||
import com.riiablo.codec.excel.MonStats;
|
||||
import com.riiablo.engine.client.component.Hovered;
|
||||
import com.riiablo.engine.server.component.AttributesWrapper;
|
||||
import com.riiablo.engine.server.component.Monster;
|
||||
import com.riiablo.engine.server.component.Position;
|
||||
import com.riiablo.graphics.PaletteIndexedBatch;
|
||||
@ -28,6 +31,7 @@ import com.riiablo.widget.Label;
|
||||
@Exclude(com.riiablo.engine.client.component.Label.class)
|
||||
public class MonsterLabelManager extends BaseEntitySystem {
|
||||
protected ComponentMapper<Monster> mMonster;
|
||||
protected ComponentMapper<AttributesWrapper> mAttributesWrapper;
|
||||
|
||||
@Wire(name = "iso")
|
||||
protected IsometricCamera iso;
|
||||
@ -72,10 +76,12 @@ public class MonsterLabelManager extends BaseEntitySystem {
|
||||
Label name;
|
||||
Label type;
|
||||
StringBuilder typeBuilder = new StringBuilder(32);
|
||||
PaletteIndexedColorDrawable background;
|
||||
|
||||
MonsterLabel() {
|
||||
label = new Table();
|
||||
label.setBackground(new PaletteIndexedColorDrawable(Riiablo.colors.darkRed) {{
|
||||
label.setBackground(background = new PaletteIndexedColorDrawable(
|
||||
Riiablo.colors.darkRed, Riiablo.colors.modal50) {{
|
||||
setTopHeight(VERTICAL_PADDING);
|
||||
setBottomHeight(VERTICAL_PADDING);
|
||||
setLeftWidth(HORIZONTAL_PADDING);
|
||||
@ -106,6 +112,11 @@ public class MonsterLabelManager extends BaseEntitySystem {
|
||||
if (typeBuilder.length() > 0) typeBuilder.setLength(typeBuilder.length() - 1);
|
||||
type.setText(typeBuilder);
|
||||
//pack();
|
||||
|
||||
Attributes attrs = mAttributesWrapper.get(entityId).attrs;
|
||||
final float hitpoints = attrs.get(Stat.hitpoints).asFixed();
|
||||
final float maxhp = attrs.get(Stat.maxhp).asFixed();
|
||||
background.percent = hitpoints / maxhp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.riiablo.graphics;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
||||
|
||||
import com.riiablo.Riiablo;
|
||||
|
||||
public class PaletteIndexedColorDrawable extends TextureRegionDrawable {
|
||||
@ -15,10 +16,26 @@ public class PaletteIndexedColorDrawable extends TextureRegionDrawable {
|
||||
}};
|
||||
|
||||
public Color tint;
|
||||
public Color modal;
|
||||
public float percent = 1f;
|
||||
|
||||
public PaletteIndexedColorDrawable(Color color) {
|
||||
this(color, null);
|
||||
}
|
||||
|
||||
public PaletteIndexedColorDrawable(Color color, Color modal) {
|
||||
super(Riiablo.textures.white);
|
||||
this.tint = color;
|
||||
this.modal = modal;
|
||||
percent = 1f;
|
||||
}
|
||||
|
||||
public void setPercent(float percent) {
|
||||
this.percent = percent;
|
||||
}
|
||||
|
||||
public float percent() {
|
||||
return percent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,8 +71,12 @@ public class PaletteIndexedColorDrawable extends TextureRegionDrawable {
|
||||
}
|
||||
|
||||
PaletteIndexedBatch b = (PaletteIndexedBatch) batch;
|
||||
if (modal != null) {
|
||||
b.setBlendMode(BlendMode.SOLID, modal);
|
||||
super.draw(batch, x, y, width, height);
|
||||
}
|
||||
b.setBlendMode(BlendMode.SOLID, tint);
|
||||
super.draw(batch, x, y, width, height);
|
||||
super.draw(batch, x, y, width * percent, height);
|
||||
b.resetBlendMode();
|
||||
}
|
||||
|
||||
@ -69,8 +90,12 @@ public class PaletteIndexedColorDrawable extends TextureRegionDrawable {
|
||||
}
|
||||
|
||||
PaletteIndexedBatch b = (PaletteIndexedBatch) batch;
|
||||
if (modal != null) {
|
||||
b.setBlendMode(BlendMode.SOLID, modal);
|
||||
super.draw(batch, x, y, originX, originY, width, height, scaleX, scaleY, rotation);
|
||||
}
|
||||
b.setBlendMode(BlendMode.SOLID, tint);
|
||||
super.draw(batch, x, y, originX, originY, width, height, scaleX, scaleY, rotation);
|
||||
super.draw(batch, x, y, originX, originY, width * percent, height, scaleX, scaleY, rotation);
|
||||
b.resetBlendMode();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user