mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 12:09:27 +02:00
improved resources tap
This commit is contained in:
@@ -698,6 +698,28 @@ public class HudUi {
|
|||||||
tt.add(label);
|
tt.add(label);
|
||||||
tt.add(button).size(Scl.scl(5 * 8f));
|
tt.add(button).size(Scl.scl(5 * 8f));
|
||||||
tt.add(lockButton).size(Scl.scl(3 * 8f));
|
tt.add(lockButton).size(Scl.scl(3 * 8f));
|
||||||
|
|
||||||
|
tt.clicked(()->{
|
||||||
|
if(getTarget() == null) return;
|
||||||
|
if(control.input instanceof DesktopInput)
|
||||||
|
((DesktopInput) control.input).panning = true;
|
||||||
|
Core.camera.position.set(getTarget().x(), getTarget().y());
|
||||||
|
});
|
||||||
|
tt.addListener(new Tooltip(tool -> tool.background(Tex.button).table(to -> {
|
||||||
|
to.table(Tex.underline2, tool2 -> {
|
||||||
|
tool2.label(()->{
|
||||||
|
if(getTarget() instanceof Unit u){
|
||||||
|
if(u.getPlayer() != null) return u.getPlayer().name;
|
||||||
|
else if(u.type != null) return u.type.localizedName;
|
||||||
|
}
|
||||||
|
else if(getTarget() instanceof Building b) return b.block.localizedName;
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
to.row();
|
||||||
|
to.label(()->getTarget() == null ? "(" + 0 + ", " + 0 + ")" : "(" + Strings.fixed(getTarget().x() / tilesize, 2) + ", " + Strings.fixed(getTarget().y() / tilesize, 2) + ")");
|
||||||
|
})));
|
||||||
});
|
});
|
||||||
t.row();
|
t.row();
|
||||||
t.table(tt -> {
|
t.table(tt -> {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package UnitInfo.ui;
|
package UnitInfo.ui;
|
||||||
|
|
||||||
|
import arc.scene.ui.Label;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import arc.util.Time;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
@@ -10,28 +12,53 @@ import mindustry.type.*;
|
|||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.blocks.storage.*;
|
import mindustry.world.blocks.storage.*;
|
||||||
|
|
||||||
import static mindustry.Vars.content;
|
import static mindustry.Vars.*;
|
||||||
import static mindustry.Vars.iconSmall;
|
|
||||||
|
|
||||||
public class CoresItemsDisplay {
|
public class CoresItemsDisplay {
|
||||||
private final ObjectSet<Item> usedItems = new ObjectSet<>();
|
private final ObjectMap<Team, ObjectSet<Item>> usedItems = new ObjectMap<>();
|
||||||
private final ObjectSet<UnitType> usedUnits = new ObjectSet<>();
|
private final ObjectMap<Team, ObjectSet<UnitType>> usedUnits = new ObjectMap<>();
|
||||||
private CoreBlock.CoreBuild core;
|
private CoreBlock.CoreBuild core;
|
||||||
public Team[] teams;
|
public Team[] teams;
|
||||||
public Seq<Table> tables = new Seq<>();
|
public Seq<Table> tables = new Seq<>();
|
||||||
|
public ObjectMap<Team, Seq<ItemStack>> prevItems = new ObjectMap<>();
|
||||||
|
public ObjectMap<Team, Seq<ItemStack>> updateItems = new ObjectMap<>();
|
||||||
|
float heat;
|
||||||
|
|
||||||
public CoresItemsDisplay(Team[] teams) {
|
public CoresItemsDisplay(Team[] teams) {
|
||||||
this.teams = teams;
|
this.teams = teams;
|
||||||
|
resetUsed();
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetUsed(){
|
public void resetUsed(){
|
||||||
usedItems.clear();
|
usedItems.clear();
|
||||||
usedUnits.clear();
|
usedUnits.clear();
|
||||||
|
updateItems.clear();
|
||||||
|
prevItems.clear();
|
||||||
|
for(Team team : teams) {
|
||||||
|
usedItems.put(team, new ObjectSet<>());
|
||||||
|
usedUnits.put(team, new ObjectSet<>());
|
||||||
|
Seq<ItemStack> stacks = new Seq();
|
||||||
|
content.items().each(i -> stacks.add(new ItemStack(i, 0)));
|
||||||
|
updateItems.put(team, stacks);
|
||||||
|
prevItems.put(team, stacks);
|
||||||
|
}
|
||||||
tables.each(t->t.background(null));
|
tables.each(t->t.background(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
void rebuild(){
|
public void updateItem(Team team){
|
||||||
|
if(prevItems.get(team) != null && core != null) for(Item item : content.items()){
|
||||||
|
updateItems.get(team).get(item.id).set(item, core.items.get(item) - prevItems.get(team).get(item.id).amount);
|
||||||
|
prevItems.get(team).get(item.id).set(item, core.items.get(item));
|
||||||
|
}
|
||||||
|
prevItems.clear();
|
||||||
|
Seq<ItemStack> stacks = new Seq();
|
||||||
|
if(core != null) content.items().each(i -> stacks.add(new ItemStack(i, core.items.get(i))));
|
||||||
|
prevItems.put(team, stacks);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rebuild(){
|
||||||
tables.clear();
|
tables.clear();
|
||||||
for(Team team : teams) {
|
for(Team team : teams) {
|
||||||
tables.add(new Table(t -> {
|
tables.add(new Table(t -> {
|
||||||
@@ -45,29 +72,59 @@ public class CoresItemsDisplay {
|
|||||||
t.update(() -> {
|
t.update(() -> {
|
||||||
core = team.core();
|
core = team.core();
|
||||||
|
|
||||||
if(content.items().contains(item -> core != null && core.items.get(item) > 0 && usedItems.add(item)) || content.units().contains(unit -> core != null && Groups.unit.count(u -> u.team == team) > 0 && usedUnits.add(unit))){
|
heat += Time.delta;
|
||||||
|
if(heat >= 60f) {
|
||||||
|
heat = 0;
|
||||||
|
updateItem(team);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(content.items().contains(item -> core != null &&
|
||||||
|
core.items.get(item) > 0 &&
|
||||||
|
usedItems.get(team).add(item)) ||
|
||||||
|
content.units().contains(unit -> core != null &&
|
||||||
|
Groups.unit.count(u -> u.type == unit && u.team == team) > 0 &&
|
||||||
|
usedUnits.get(team).add(unit))){
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
int i = 0;
|
final int[] i = {0};
|
||||||
for(Item item : content.items()){
|
t.table(itemTable -> {
|
||||||
if(usedItems.contains(item)){
|
itemTable.center();
|
||||||
t.image(item.uiIcon).size(iconSmall).padRight(3).tooltip(tt -> tt.background(Styles.black6).margin(2f).add(item.localizedName).style(Styles.outlineLabel));
|
for(Item item : content.items()){
|
||||||
t.label(() -> core == null ? "0" : UI.formatAmount(core.items.get(item))).padRight(3).minWidth(5 * 8f).left();
|
if(usedItems.get(team).contains(item)){
|
||||||
if(++i % 5 == 0) t.row();
|
itemTable.add(new Stack(){{
|
||||||
|
add(new Table(tt -> {
|
||||||
|
tt.image(item.uiIcon).size(iconSmall).tooltip(ttt -> ttt.background(Styles.black6).margin(2f).add(item.localizedName).style(Styles.outlineLabel));
|
||||||
|
tt.label(() -> core == null ? "0" : UI.formatAmount(core.items.get(item))).minWidth(5 * 8f).left();
|
||||||
|
}));
|
||||||
|
add(new Table(tt -> {
|
||||||
|
tt.bottom().right();
|
||||||
|
Label label = new Label(() -> {
|
||||||
|
int amount = updateItems.get(team).get(item.id).amount;
|
||||||
|
return (amount > 0 ? "[green]+" : amount == 0 ? "[orange]" : "[red]") + amount + "[]";
|
||||||
|
});
|
||||||
|
label.setFontScale(0.65f);
|
||||||
|
tt.add(label).bottom().right().padTop(16f);
|
||||||
|
tt.pack();
|
||||||
|
}));
|
||||||
|
}}).padRight(3).left();
|
||||||
|
if(++i[0] % 5 == 0) itemTable.row();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
t.row();
|
t.row();
|
||||||
i = 0;
|
i[0] = 0;
|
||||||
for(UnitType unit : content.units()){
|
t.table(unitTable -> {
|
||||||
if(unit == UnitTypes.block) continue;
|
unitTable.center();
|
||||||
if(usedUnits.contains(unit)){
|
for(UnitType unit : content.units()){
|
||||||
t.image(unit.uiIcon).size(iconSmall).padRight(3).tooltip(tt -> tt.background(Styles.black6).margin(2f).add(unit.localizedName).style(Styles.outlineLabel));
|
if(unit != UnitTypes.block && usedUnits.get(team).contains(unit)){
|
||||||
t.label(() -> core == null ? "0" : UI.formatAmount(Groups.unit.count(u -> u.team == team && u.type == unit))).padRight(3).minWidth(5 * 8f).left();
|
unitTable.image(unit.uiIcon).size(iconSmall).padRight(3).tooltip(tt -> tt.background(Styles.black6).margin(2f).add(unit.localizedName).style(Styles.outlineLabel));
|
||||||
if(++i % 5 == 0) t.row();
|
unitTable.label(() -> core == null ? "0" : UI.formatAmount(Groups.unit.count(u -> u.team == team && u.type == unit))).padRight(3).minWidth(5 * 8f).left();
|
||||||
|
if(++i[0] % 5 == 0) unitTable.row();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user