mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 12:09:27 +02:00
fixed bar icon issue
This commit is contained in:
@@ -26,6 +26,17 @@ public class SBar extends Element{
|
|||||||
|
|
||||||
public boolean onedot = false;
|
public boolean onedot = false;
|
||||||
|
|
||||||
|
//static bar
|
||||||
|
public SBar(String name, Color color, float fraction){
|
||||||
|
this.fraction = ()->fraction;
|
||||||
|
this.name = Core.bundle.get(name, name);
|
||||||
|
this.blinkColor.set(color);
|
||||||
|
lastValue = value = fraction;
|
||||||
|
setColor(color);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
//dynamic bar
|
||||||
public SBar(Prov<String> name, Prov<Color> color, Floatp fraction){
|
public SBar(Prov<String> name, Prov<Color> color, Floatp fraction){
|
||||||
this.fraction = fraction;
|
this.fraction = fraction;
|
||||||
try{
|
try{
|
||||||
@@ -53,7 +64,6 @@ public class SBar extends Element{
|
|||||||
public SBar init(){
|
public SBar init(){
|
||||||
int h = Core.settings.getInt("barstyle");
|
int h = Core.settings.getInt("barstyle");
|
||||||
|
|
||||||
|
|
||||||
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barS"), 10, 10, 9, 9);
|
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barS"), 10, 10, 9, 9);
|
||||||
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barS-top"), 10, 10, 9, 9);
|
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barS-top"), 10, 10, 9, 9);
|
||||||
spriteWidth = Core.atlas.find("informatis-barS").width;
|
spriteWidth = Core.atlas.find("informatis-barS").width;
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package informatis.ui.window;
|
|||||||
|
|
||||||
import arc.Core;
|
import arc.Core;
|
||||||
import arc.scene.Element;
|
import arc.scene.Element;
|
||||||
|
import arc.scene.event.InputEvent;
|
||||||
|
import arc.scene.event.InputListener;
|
||||||
|
import arc.scene.utils.Disableable;
|
||||||
import informatis.core.*;
|
import informatis.core.*;
|
||||||
import informatis.ui.*;
|
import informatis.ui.*;
|
||||||
import arc.graphics.Color;
|
import arc.graphics.Color;
|
||||||
@@ -35,8 +38,6 @@ import static mindustry.Vars.*;
|
|||||||
|
|
||||||
class UnitWindow extends Window {
|
class UnitWindow extends Window {
|
||||||
final Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
|
final Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
|
||||||
Seq<Table> bars = new Seq<>(); //temp
|
|
||||||
Vec2 scrollPos = new Vec2(0, 0);
|
|
||||||
Teamc latestTarget = getTarget();
|
Teamc latestTarget = getTarget();
|
||||||
int barSize = 6;
|
int barSize = 6;
|
||||||
ScrollPane barPane;
|
ScrollPane barPane;
|
||||||
@@ -52,9 +53,6 @@ class UnitWindow extends Window {
|
|||||||
//TODO: add new UnitInfoDisplay(), new WeaponDisplay();
|
//TODO: add new UnitInfoDisplay(), new WeaponDisplay();
|
||||||
@Override
|
@Override
|
||||||
protected void build(Table table) {
|
protected void build(Table table) {
|
||||||
scrollPos = new Vec2(0, 0);
|
|
||||||
bars = new Seq<>();
|
|
||||||
|
|
||||||
table.top().background(Styles.black8);
|
table.top().background(Styles.black8);
|
||||||
table.table(tt -> {
|
table.table(tt -> {
|
||||||
tt.center();
|
tt.center();
|
||||||
@@ -120,7 +118,7 @@ class UnitWindow extends Window {
|
|||||||
table.add(addBar(i)).growX().get();
|
table.add(addBar(i)).growX().get();
|
||||||
table.row();
|
table.row();
|
||||||
}
|
}
|
||||||
table.add(new SBar(() -> "+", () -> Color.clear, () -> 0)).height(4 * 8f).growX().get().clicked(()->{
|
table.add(new SBar("+", Color.clear, 0)).height(4 * 8f).growX().get().clicked(()->{
|
||||||
barSize++;
|
barSize++;
|
||||||
barPane.setWidget(buildBarList());
|
barPane.setWidget(buildBarList());
|
||||||
});
|
});
|
||||||
@@ -129,57 +127,56 @@ class UnitWindow extends Window {
|
|||||||
|
|
||||||
Table addBar(int index) {
|
Table addBar(int index) {
|
||||||
return new Table(bar -> {
|
return new Table(bar -> {
|
||||||
bar.add(new SBar(
|
if(index >= BarInfo.data.size) {
|
||||||
() -> {
|
bar.add(new SBar("[lightgray]<Empty>[]", Color.clear, 0)).height(4 * 8f).growX();
|
||||||
BarInfo.BarData data = index >= BarInfo.data.size || index >= barSize ? null : BarInfo.data.get(index);
|
return;
|
||||||
return data == null ? "[lightgray]<Empty>[]" : data.name;
|
}
|
||||||
},
|
|
||||||
() -> {
|
bar.update(()->{
|
||||||
BarInfo.BarData data = index >= BarInfo.data.size || index >= barSize ? null : BarInfo.data.get(index);
|
BarInfo.BarData data = BarInfo.data.get(index);
|
||||||
if (index >= lastColors.size) lastColors.size = index+1;
|
if (index >= lastColors.size) lastColors.add(data.color);
|
||||||
if (data == null) return lastColors.get(index);
|
else lastColors.set(index, data.color);
|
||||||
if (data.color != Color.clear) lastColors.set(index, data.color);
|
});
|
||||||
return lastColors.get(index);
|
|
||||||
},
|
bar.add(new SBar(() -> BarInfo.data.get(index).name, () -> BarInfo.data.get(index).color, () -> BarInfo.data.get(index).number)).height(4 * 8f).growX();
|
||||||
() -> {
|
|
||||||
BarInfo.BarData data = index >= BarInfo.data.size || index >= barSize ? null : BarInfo.data.get(index);
|
|
||||||
return data == null ? 0 : data.number;
|
|
||||||
}
|
|
||||||
)).height(4 * 8f).growX();
|
|
||||||
Image icon = new Image(){
|
Image icon = new Image(){
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
validate();
|
validate();
|
||||||
|
|
||||||
float x = this.x;
|
float x = this.x + imageX;
|
||||||
float y = this.y;
|
float y = this.y + imageY;
|
||||||
float scaleX = this.scaleX;
|
float width = imageWidth * this.scaleX;
|
||||||
float scaleY = this.scaleY;
|
float height = imageHeight * this.scaleY;
|
||||||
Draw.color(Color.white);
|
Draw.color(Color.white);
|
||||||
Draw.alpha(parentAlpha * color.a);
|
Draw.alpha(parentAlpha * color.a);
|
||||||
if(index >= BarInfo.data.size || index >= barSize) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(hasMouse()) {
|
|
||||||
Icon.cancel.draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BarInfo.BarData data = BarInfo.data.get(index);
|
BarInfo.BarData data = BarInfo.data.get(index);
|
||||||
data.icon.draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
getDrawable().draw(x, y, width, height);
|
||||||
if(ScissorStack.push(Tmp.r1.set(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY * data.number))){
|
if (!hasMouse() && ScissorStack.push(Tmp.r1.set(ScissorStack.peek().x + x, ScissorStack.peek().y + y, width, height * data.number))) {
|
||||||
Draw.color(data.color);
|
Draw.color(data.color);
|
||||||
data.icon.draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
getDrawable().draw(x, y, width, height);
|
||||||
Log.info(Tmp.r1);
|
|
||||||
ScissorStack.pop();
|
ScissorStack.pop();
|
||||||
}
|
}
|
||||||
Draw.reset();
|
|
||||||
|
Log.info("----------------------");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
icon.addListener(new InputListener(){
|
||||||
|
@Override
|
||||||
|
public void enter(InputEvent event, float x, float y, int pointer, Element fromActor){
|
||||||
|
icon.setDrawable(Icon.cancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exit(InputEvent event, float x, float y, int pointer, Element fromActor){
|
||||||
|
icon.setDrawable(BarInfo.data.get(index).icon);
|
||||||
|
}
|
||||||
|
});
|
||||||
icon.clicked(()->{
|
icon.clicked(()->{
|
||||||
if(barSize > 0) barSize--;
|
if(barSize > 0) barSize--;
|
||||||
barPane.setWidget(buildBarList());
|
barPane.setWidget(buildBarList());
|
||||||
});
|
});
|
||||||
|
icon.setDrawable(BarInfo.data.get(index).icon);
|
||||||
bar.add(icon).size(iconMed * 0.75f).padLeft(8f);
|
bar.add(icon).size(iconMed * 0.75f).padLeft(8f);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user