core window done

This commit is contained in:
sharlottes
2022-04-11 18:40:18 +09:00
parent 899baa2220
commit f500819d8f

View File

@@ -1,12 +1,11 @@
package UnitInfo.ui.windows; package UnitInfo.ui.windows;
import UnitInfo.ui.OverScrollPane; import UnitInfo.ui.*;
import UnitInfo.ui.SBar;
import UnitInfo.ui.Updatable;
import arc.Core; import arc.Core;
import arc.graphics.Color; import arc.graphics.Color;
import arc.math.Mathf; import arc.math.Mathf;
import arc.math.geom.Vec2; import arc.math.geom.Vec2;
import arc.scene.Element;
import arc.scene.event.HandCursorListener; import arc.scene.event.HandCursorListener;
import arc.scene.style.*; import arc.scene.style.*;
import arc.scene.ui.*; import arc.scene.ui.*;
@@ -29,11 +28,7 @@ import static mindustry.Vars.*;
public class CoreDisplay extends WindowTable implements Updatable { public class CoreDisplay extends WindowTable implements Updatable {
Vec2 scrollPos = new Vec2(0, 0); Vec2 scrollPos = new Vec2(0, 0);
ObjectMap<Team, ObjectSet<Item>> usedItems = new ObjectMap<>(); ObjectMap<Team, ItemData> itemData = new ObjectMap<>();
ObjectMap<Team, ObjectSet<UnitType>> usedUnits = new ObjectMap<>();
ObjectMap<Team, Seq<ItemStack>> prevItems = new ObjectMap<>();
ObjectMap<Team, Seq<ItemStack>> updateItems = new ObjectMap<>();
ObjectIntMap<Team> coreAmount = new ObjectIntMap<>();
float heat; float heat;
public CoreDisplay() { public CoreDisplay() {
@@ -49,12 +44,8 @@ public class CoreDisplay extends WindowTable implements Updatable {
topBar(); topBar();
table(Styles.black8, t -> { table(Styles.black8, t -> {
ScrollPane pane = new OverScrollPane(new Table(table -> { ScrollPane pane = new OverScrollPane(rebuild(), Styles.nonePane, scrollPos).disableScroll(true, false);
for(Team team : Team.baseTeams) { t.add(pane).name("core-pane");
table.add(setTable(team).background(((NinePatchDrawable)Tex.underline2).tint(team.color))).row();
}
}), Styles.nonePane, scrollPos).disableScroll(true, false);
t.add(pane);
}).top().right().grow().get().parent = null; }).top().right().grow().get().parent = null;
resizeButton(); resizeButton();
@@ -65,58 +56,38 @@ public class CoreDisplay extends WindowTable implements Updatable {
heat += Time.delta; heat += Time.delta;
if(heat >= 60f) { if(heat >= 60f) {
heat = 0f; heat = 0f;
for(Team team : Team.baseTeams) { ScrollPane pane = find("core-pane");
if(team==Team.sharded) Log.info(prevItems.get(Team.sharded)); pane.setWidget(rebuild());
updateItem(team); for(Team team : getTeams()) {
Log.info(prevItems.get(Team.sharded)); if(!itemData.containsKey(team)) itemData.put(team, new ItemData());
if(coreAmount.get(team) != team.cores().size){ itemData.get(team).updateItems(team);
coreAmount.put(team, team.cores().size);
}
} }
} }
} }
public Table rebuild() {
return new Table(table -> {
for(Team team : getTeams()) {
table.add(setTable(team).background(((NinePatchDrawable)Tex.underline2).tint(team.color))).row();
}
});
}
public Seq<Team> getTeams(){
return Seq.with(Team.all).filter(Team::active);
}
public void resetUsed(){ public void resetUsed(){
usedItems.clear(); for(Team team : getTeams()) {
usedUnits.clear(); itemData.put(team, new ItemData());
updateItems.clear();
prevItems.clear();
coreAmount.clear();
for(Team team : Team.baseTeams) {
usedItems.put(team, new ObjectSet<>());
usedUnits.put(team, new ObjectSet<>());
Seq<ItemStack> stacks = new Seq<>();
Vars.content.items().each(i -> stacks.add(new ItemStack(i, 0)));
updateItems.put(team, stacks);
prevItems.put(team, stacks);
coreAmount.put(team, team.cores().size);
} }
} }
public void updateItem(Team team){
CoreBlock.CoreBuild core = team.core();
Seq<ItemStack> prev = prevItems.get(team);
if (core != null) {
Seq<ItemStack> stack = updateItems.get(team);
if(stack.isEmpty()) Vars.content.items().each(i -> stack.add(new ItemStack(i, 0)));
for (Item item : Vars.content.items()) {
stack.get(item.id).set(item, core.items.get(item) - (prev != null ? prev.get(item.id).amount : 0));
if (prev != null) prev.get(item.id).set(item, core.items.get(item));
}
}
if (prev != null) prev.clear();
Seq<ItemStack> stacks = new Seq<>();
if(core != null) Vars.content.items().each(i -> stacks.add(new ItemStack(i, core.items.get(i))));
prevItems.put(team, stacks);
}
public Table setTable(Team team){ public Table setTable(Team team){
return new Table(table -> { return new Table(table -> {
table.label(() -> "[#" + team.color.toString() + "]" + team.name + "[]").row(); table.add(team.name).color(team.color).row();
table.table().update(coretable -> { table.table(coretable -> {
coretable.clear(); int row = 0;
final int[] i = {0};
for(CoreBlock.CoreBuild core : team.cores()) { for(CoreBlock.CoreBuild core : team.cores()) {
coretable.table(tt -> { coretable.table(tt -> {
tt.stack( tt.stack(
@@ -128,17 +99,16 @@ public class CoreDisplay extends WindowTable implements Updatable {
((DesktopInput) control.input).panning = true; ((DesktopInput) control.input).panning = true;
Core.camera.position.set(core.x, core.y); Core.camera.position.set(core.x, core.y);
}); });
if(!mobile) { HandCursorListener listener1 = new HandCursorListener();
HandCursorListener listener1 = new HandCursorListener(); image.addListener(listener1);
image.addListener(listener1); image.update(() -> {
image.update(() -> { image.color.lerp(!listener1.isOver() ? Color.lightGray : Color.white, Mathf.clamp(0.4f * Time.delta));
image.color.lerp(!listener1.isOver() ? Color.lightGray : Color.white, Mathf.clamp(0.4f * Time.delta));
});
}
s.add(image).size(iconLarge).tooltip(tool -> {
tool.background(Tex.button).label(() -> "([#" + Tmp.c1.set(Color.green).lerp(Color.red, 1 - core.healthf()).toString() + "]" + Strings.fixed(core.health, 2) + "[]/" + Strings.fixed(core.block.health, 2) + ")");
}); });
Tooltip.Tooltips option = new Tooltip.Tooltips();
option.animations=false;
s.add(image).size(iconLarge).get().addListener(new Tooltip(tool -> {
tool.background(Styles.black6).label(() -> "([#" + Tmp.c1.set(Color.green).lerp(Color.red, 1 - core.healthf()).toString() + "]" + Strings.fixed(core.health, 2) + "[]/" + Strings.fixed(core.block.health, 2) + ")");
}, option));
}), }),
new Table(h -> { new Table(h -> {
h.bottom().defaults().height(9f).width(iconLarge * 1.5f).growX(); h.bottom().defaults().height(9f).width(iconLarge * 1.5f).growX();
@@ -146,19 +116,21 @@ public class CoreDisplay extends WindowTable implements Updatable {
h.pack(); h.pack();
}) })
).row(); ).row();
Label label = new Label(() -> "(" + (int) core.x / 8 + ", " + (int) core.y / 8 + ")"); Label label = new Label(Strings.format("(@, @)",core.tileX(), core.tileY()));
label.setFontScale(0.75f); label.setFontScale(0.75f);
tt.add(label); tt.add(label);
}).padTop(2).padLeft(4).padRight(4); }).padTop(2).padLeft(4).padRight(4);
if(++i[0] % 4 == 0) coretable.row(); if(++row % 5 == 0) coretable.row();
} }
}).row(); }).row();
table.table().update(itemTable -> { table.table(itemTable -> {
itemTable.clear(); int row = 0;
final int[] i = {0};
CoreBlock.CoreBuild core = team.core(); CoreBlock.CoreBuild core = team.core();
if(core != null) for(Item item : Vars.content.items().copy().filter(item-> core.items.has(item))){ for(int i = 0; i < Vars.content.items().size; i++){
Item item = Vars.content.item(i);
if(!team.items().has(item)) return;
itemTable.stack( itemTable.stack(
new Table(ttt -> { new Table(ttt -> {
ttt.image(item.uiIcon).size(iconSmall).tooltip(tttt -> tttt.background(Styles.black6).add(item.localizedName).style(Styles.outlineLabel).margin(2f)); ttt.image(item.uiIcon).size(iconSmall).tooltip(tttt -> tttt.background(Styles.black6).add(item.localizedName).style(Styles.outlineLabel).margin(2f));
@@ -166,20 +138,20 @@ public class CoreDisplay extends WindowTable implements Updatable {
}), }),
new Table(ttt -> { new Table(ttt -> {
ttt.bottom().right(); ttt.bottom().right();
int amount = updateItems.get(team).isEmpty()?0:Mathf.floor(updateItems.get(team).get(item.id).amount); int amount = itemData.get(team).updateItems.isEmpty()?0:Mathf.floor(itemData.get(team).updateItems.get(item.id).amount);
Label label = new Label((amount > 0 ? "[green]+" : amount == 0 ? "[orange]" : "[red]") + amount + "/s[]"); Label label = new Label(amount + "/s");
label.setFontScale(0.65f); label.setFontScale(0.65f);
label.setColor(amount > 0 ? Color.green : amount == 0 ? Color.orange : Color.red);
ttt.add(label).bottom().right().padTop(16f); ttt.add(label).bottom().right().padTop(16f);
ttt.pack(); ttt.pack();
})).padRight(3).left(); })).padRight(3).left();
if(++i[0] % 5 == 0) itemTable.row(); if(++row % 5 == 0) itemTable.row();
} }
}).row(); }).row();
table.table().update(unitTable -> { table.table(unitTable -> {
unitTable.clear(); int row = 0;
final int[] i = {0};
for(UnitType unit : Vars.content.units()){ for(UnitType unit : Vars.content.units()){
if(unit != UnitTypes.block && Groups.unit.contains(u -> u.type == unit && u.team == team)){ if(unit != UnitTypes.block && Groups.unit.contains(u -> u.type == unit && u.team == team)){
unitTable.table(tt -> { unitTable.table(tt -> {
@@ -187,10 +159,39 @@ public class CoreDisplay extends WindowTable implements Updatable {
tt.image(unit.uiIcon).size(iconSmall).padRight(3).tooltip(ttt -> ttt.background(Styles.black6).add(unit.localizedName).style(Styles.outlineLabel).margin(2f)); tt.image(unit.uiIcon).size(iconSmall).padRight(3).tooltip(ttt -> ttt.background(Styles.black6).add(unit.localizedName).style(Styles.outlineLabel).margin(2f));
tt.add(UI.formatAmount(Groups.unit.count(u -> u.team == team && u.type == unit))).padRight(3).minWidth(5 * 8f).left(); tt.add(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(); if(++row % 5 == 0) unitTable.row();
} }
} }
}); });
}); });
} }
static class ItemData {
Seq<ItemStack> prevItems = new Seq<>();
Seq<ItemStack> updateItems = new Seq<>();
ItemData() {
resetItems();
}
public void resetItems(){
Seq<ItemStack> stacks = Vars.content.items().map(item -> new ItemStack(item, 0));
updateItems.clear().addAll(stacks);
prevItems.clear().addAll(stacks);
}
public void updateItems(Team team){
CoreBlock.CoreBuild core = team.core();
if (core != null) {
Seq<ItemStack> stack = updateItems;
if(stack.isEmpty()) Vars.content.items().each(i -> stack.add(new ItemStack(i, 0)));
for (Item item : Vars.content.items()) {
stack.get(item.id).set(item, core.items.get(item) - (prevItems != null ? prevItems.get(item.id).amount : 0));
if (prevItems != null) prevItems.get(item.id).set(item, core.items.get(item));
}
if(prevItems != null) prevItems.clear().addAll(Vars.content.items().map(i -> new ItemStack(i, core.items.get(i))));
}
}
}
} }