wave window

This commit is contained in:
sharlottes
2022-04-09 15:05:09 +09:00
parent 4a6da20a4b
commit d1ecbafa66
7 changed files with 150 additions and 148 deletions

View File

@@ -1,11 +1,6 @@
package UnitInfo.core; package UnitInfo.core;
import UnitInfo.ui.*; import UnitInfo.ui.windows.*;
import UnitInfo.ui.windows.CoreDisplay;
import UnitInfo.ui.windows.CoresItemsDisplay;
import UnitInfo.ui.windows.SchemDisplay;
import UnitInfo.ui.windows.WaveDisplay;
import arc.*; import arc.*;
import arc.graphics.*; import arc.graphics.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
@@ -38,8 +33,6 @@ public class HudUi {
public Table mainTable = new Table(); public Table mainTable = new Table();
public Table baseTable = new Table(); public Table baseTable = new Table();
public Table waveInfoTable = new Table(); public Table waveInfoTable = new Table();
public UnitDisplay unitTable;
public WaveDisplay waveTable;
public CoreDisplay itemTable; public CoreDisplay itemTable;
public SchemDisplay schemTable; public SchemDisplay schemTable;
@@ -80,10 +73,8 @@ public class HudUi {
float heat = 0; float heat = 0;
public void setEvents() { public void setEvents() {
Events.on(EventType.WaveEvent.class, e -> waveTable.rebuild());
Events.on(EventType.WorldLoadEvent.class, e -> itemTable.rebuild()); Events.on(EventType.WorldLoadEvent.class, e -> itemTable.rebuild());
Events.run(EventType.Trigger.update, ()->{ Events.run(EventType.Trigger.update, ()->{
if(unitTable!=null) unitTable.setEvent();
itemTable.setEvent(); itemTable.setEvent();
OverDrawer.target = getTarget(); OverDrawer.target = getTarget();
OverDrawer.locked = locked; OverDrawer.locked = locked;
@@ -294,9 +285,8 @@ public class HudUi {
label.setText(bundle.get(hud)); label.setText(bundle.get(hud));
table.removeChild(baseTable); table.removeChild(baseTable);
labelTable.setPosition(buttons.items[uiIndex].x, buttons.items[uiIndex].y); labelTable.setPosition(buttons.items[uiIndex].x, buttons.items[uiIndex].y);
waveTable = new WaveDisplay();
itemTable = new CoreDisplay(); itemTable = new CoreDisplay();
baseTable = table.table(tt -> tt.stack(waveTable, itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get(); baseTable = table.table(tt -> tt.stack(itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get();
a = 1f; a = 1f;
} }
@@ -329,9 +319,8 @@ public class HudUi {
t.row(); t.row();
} }
}); });
waveTable = new WaveDisplay();
itemTable = new CoreDisplay(); itemTable = new CoreDisplay();
baseTable = table.table(tt -> tt.stack(waveTable, itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get(); baseTable = table.table(tt -> tt.stack(itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get();
table.fillParent = true; table.fillParent = true;
table.visibility = () -> ui.hudfrag.shown && !ui.minimapfrag.shown(); table.visibility = () -> ui.hudfrag.shown && !ui.minimapfrag.shown();

View File

@@ -9,7 +9,7 @@ import mindustry.game.EventType.*;
import mindustry.mod.*; import mindustry.mod.*;
import static UnitInfo.SVars.*; import static UnitInfo.SVars.*;
import static UnitInfo.ui.UnitDisplay.getTarget; import static UnitInfo.ui.windows.UnitDisplay.getTarget;
import static arc.Core.*; import static arc.Core.*;
public class Main extends Mod { public class Main extends Mod {

View File

@@ -4,6 +4,7 @@ import arc.scene.*;
import mindustry.ui.fragments.*; import mindustry.ui.fragments.*;
import static UnitInfo.ui.windows.WindowTables.unitTable; import static UnitInfo.ui.windows.WindowTables.unitTable;
import static UnitInfo.ui.windows.WindowTables.waveTable;
public class HUDFragment extends Fragment{ public class HUDFragment extends Fragment{
@Override @Override
@@ -15,14 +16,18 @@ public class HUDFragment extends Fragment{
// windows (totally not a copyright violation) // windows (totally not a copyright violation)
t.center().right(); t.center().right();
t.add(unitTable).size(250f).visible(false); t.add(unitTable).size(250f).visible(false);
t.add(waveTable).size(250f).visible(false);
// sidebar // sidebar
t.add(new TaskbarTable( t.add(new TaskbarTable(
unitTable unitTable,
waveTable
)).visible(TaskbarTable.visibility); )).visible(TaskbarTable.visibility);
t.update(()->{ t.update(()->{
if(unitTable instanceof Updatable u) u.setEvent(); for (Element child : t.getChildren()) {
if(child instanceof Updatable u) u.setEvent();
}
}); });
}); });
}; };

View File

@@ -0,0 +1,37 @@
package UnitInfo.ui;
import arc.math.geom.Vec2;
import arc.scene.Element;
import arc.scene.ui.ScrollPane;
import static arc.Core.input;
import static arc.Core.scene;
public class OverScrollPane extends ScrollPane {
Vec2 scrollPos;
public OverScrollPane(Element widget, ScrollPaneStyle style, Vec2 scrollPos){
super(widget, style);
this.scrollPos = scrollPos;
update(() -> {
if (hasScroll()) {
Element result = scene.hit(input.mouseX(), input.mouseY(), true);
if (result == null || !result.isDescendantOf(this)) {
scene.setScrollFocus(null);
}
}
scrollPos.x = getScrollX();
scrollPos.y = getScrollY();
});
setOverscroll(false, false);
setScrollYForce(scrollPos.x);
setScrollYForce(scrollPos.y);
}
public OverScrollPane disableScroll(boolean x, boolean y) {
setScrollingDisabled(x, y);
return this;
}
}

View File

@@ -1,7 +1,10 @@
package UnitInfo.ui; package UnitInfo.ui.windows;
import UnitInfo.SVars; import UnitInfo.SVars;
import UnitInfo.core.BarInfo; import UnitInfo.core.BarInfo;
import UnitInfo.ui.SBar;
import UnitInfo.ui.SIcons;
import UnitInfo.ui.Updatable;
import UnitInfo.ui.windows.WindowTable; import UnitInfo.ui.windows.WindowTable;
import arc.Core; import arc.Core;
import arc.func.Prov; import arc.func.Prov;

View File

@@ -1,170 +1,138 @@
package UnitInfo.ui.windows; package UnitInfo.ui.windows;
import UnitInfo.SVars; import UnitInfo.ui.OverScrollPane;
import arc.Events;
import arc.graphics.Color; import arc.graphics.Color;
import arc.input.KeyCode; import arc.input.KeyCode;
import arc.math.Mathf; import arc.math.Mathf;
import arc.scene.Element; import arc.math.geom.Vec2;
import arc.scene.event.HandCursorListener; import arc.scene.event.HandCursorListener;
import arc.scene.style.NinePatchDrawable; import arc.scene.event.Touchable;
import arc.scene.ui.*; import arc.scene.ui.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import arc.struct.ObjectIntMap; import arc.struct.*;
import arc.struct.Seq; import arc.util.*;
import arc.util.Scaling;
import arc.util.Time;
import arc.util.Tmp;
import mindustry.content.StatusEffects; import mindustry.content.StatusEffects;
import mindustry.game.EventType;
import mindustry.game.SpawnGroup; import mindustry.game.SpawnGroup;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.Pal; import mindustry.graphics.Pal;
import mindustry.ui.*; import mindustry.ui.*;
import static UnitInfo.SVars.modUiScale;
import static arc.Core.*; import static arc.Core.*;
import static arc.Core.settings; import static arc.Core.settings;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class WaveDisplay extends Table { public class WaveDisplay extends WindowTable {
static float waveScrollPos; static Vec2 waveScrollPos = new Vec2(0, 0);
static Table table = new Table();
public WaveDisplay() { public WaveDisplay() {
fillParent = true; super("Wave Display", Icon.waves, t -> {});
visibility = () -> 1 == SVars.hud.uiIndex; }
defaults().size(Scl.scl(modUiScale) * 35 * 8f); @Override
table(Tex.button, t -> { public void build() {
ScrollPane pane = t.pane(Styles.nonePane, rebuild()).get(); top();
pane.update(() -> { topBar();
if (pane.hasScroll()) {
Element result = scene.hit(input.mouseX(), input.mouseY(), true); table(Styles.black8, t -> {
if (result == null || !result.isDescendantOf(pane)) { ScrollPane pane = new OverScrollPane(rebuild(), Styles.nonePane, waveScrollPos).disableScroll(true, false);
scene.setScrollFocus(null); t.add(pane).get().parent = null;
} Events.on(EventType.WorldLoadEvent.class, e -> {
} pane.clearChildren();
waveScrollPos = pane.getScrollY(); pane.setWidget(rebuild());
}); });
pane.setOverscroll(false, false); Events.on(EventType.WaveEvent.class, e -> {
pane.setScrollingDisabled(true, false); pane.clearChildren();
pane.setScrollYForce(waveScrollPos); pane.setWidget(rebuild());
update(() -> {
NinePatchDrawable patch = (NinePatchDrawable) Tex.button;
t.setBackground(patch.tint(Tmp.c1.set(patch.getPatch().getColor()).a(settings.getInt("uiopacity") / 100f)));
}); });
}).padRight(Scl.scl(modUiScale) * 70 * 8f); }).top().right().grow().get().parent = null;
}
resizeButton();
public Table rebuild(){
table.clear();
int winWave = state.isCampaign() && state.rules.winWave > 0 ? state.rules.winWave : Integer.MAX_VALUE;
for(int i = settings.getBool("pastwave") ? 0 : state.wave - 1; i <= Math.min(state.wave + settings.getInt("wavemax"), winWave - 2); i++){
final int j = i;
if(!settings.getBool("emptywave") && state.rules.spawns.find(g -> g.getSpawned(j) > 0) == null) continue;
table.table(table1 -> {
table1.stack(
new Table(t -> {
Label label = new Label(() -> "[#" + (state.wave == j ? Color.red.toString() : Pal.accent.toString()) + "]" + j + "[]");
label.setFontScale(Scl.scl(modUiScale));
t.add(label).padRight(Scl.scl(modUiScale) * 24 * 8f);
}),
new Table(Tex.underline, t -> {
t.marginLeft(Scl.scl(modUiScale) * 3 * 8f);
if(settings.getBool("emptywave") && state.rules.spawns.find(g -> g.getSpawned(j) > 0) == null) {
t.center();
Label label = new Label(bundle.get("empty"));
label.setFontScale(Scl.scl(modUiScale));
t.add(label);
return;
} }
public ObjectIntMap<SpawnGroup> getWaveGroup(int index) {
ObjectIntMap<SpawnGroup> groups = new ObjectIntMap<>(); ObjectIntMap<SpawnGroup> groups = new ObjectIntMap<>();
for(SpawnGroup group : state.rules.spawns) { for (SpawnGroup group : state.rules.spawns) {
if(group.getSpawned(j) <= 0) continue; if (group.getSpawned(index) <= 0) continue;
SpawnGroup sameTypeKey = groups.keys().toArray().find(g -> g.type == group.type && g.effect != StatusEffects.boss); SpawnGroup sameTypeKey = groups.keys().toArray().find(g -> g.type == group.type && g.effect != StatusEffects.boss);
if(sameTypeKey != null) groups.increment(sameTypeKey, sameTypeKey.getSpawned(j)); if (sameTypeKey != null) groups.increment(sameTypeKey, sameTypeKey.getSpawned(index));
else groups.put(group, group.getSpawned(j)); else groups.put(group, group.getSpawned(index));
} }
Seq<SpawnGroup> groupSorted = groups.keys().toArray().copy().sort((g1, g2) -> { Seq<SpawnGroup> groupSorted = groups.keys().toArray().copy().sort((g1, g2) -> {
int boss = Boolean.compare(g1.effect != StatusEffects.boss, g2.effect != StatusEffects.boss); int boss = Boolean.compare(g1.effect != StatusEffects.boss, g2.effect != StatusEffects.boss);
if(boss != 0) return boss; if (boss != 0) return boss;
int hitSize = Float.compare(-g1.type.hitSize, -g2.type.hitSize); int hitSize = Float.compare(-g1.type.hitSize, -g2.type.hitSize);
if(hitSize != 0) return hitSize; if (hitSize != 0) return hitSize;
return Integer.compare(-g1.type.id, -g2.type.id); return Integer.compare(-g1.type.id, -g2.type.id);
}); });
ObjectIntMap<SpawnGroup> groupsTmp = new ObjectIntMap<>(); ObjectIntMap<SpawnGroup> groupsTmp = new ObjectIntMap<>();
groupSorted.each(g -> groupsTmp.put(g, groups.get(g))); groupSorted.each(g -> groupsTmp.put(g, groups.get(g)));
return groupsTmp;
}
public Table rebuild(){
return new Table(table -> {
table.touchable = Touchable.enabled;
for (int i = settings.getBool("pastwave") ? 0 : state.wave - 1;
i <= Math.min(state.wave + settings.getInt("wavemax"), (state.isCampaign() && state.rules.winWave > 0 ? state.rules.winWave : Integer.MAX_VALUE) - 2);
i++) {
final int j = i;
table.stack(
new Table(t -> {
t.label(() -> "[#" + (state.wave == j ? Color.red.toString() : Pal.accent.toString()) + "]" + j + "[]").padRight(24 * 8f);
}),
new Table(Tex.underline, t -> {
if (settings.getBool("emptywave") && state.rules.spawns.find(g -> g.getSpawned(j) > 0) == null) {
t.add(bundle.get("empty")).center();
return;
}
ObjectIntMap<SpawnGroup> groups = getWaveGroup(j-2);
int row = 0; int row = 0;
for(SpawnGroup group : groupsTmp.keys()){ for (SpawnGroup group : groups.keys()) {
int spawners = state.rules.waveTeam.cores().size + (group.type.flying ? spawner.countFlyerSpawns() : spawner.countGroundSpawns()); int spawners = state.rules.waveTeam.cores().size + (group.type.flying ? spawner.countFlyerSpawns() : spawner.countGroundSpawns());
int amount = groupsTmp.get(group); int amount = groups.get(group);
t.table(tt -> { t.stack(
Image image = new Image(group.type.uiIcon).setScaling(Scaling.fit);
tt.stack(
new Table(ttt -> { new Table(ttt -> {
ttt.center(); ttt.center();
ttt.add(image).size(iconMed * Scl.scl(modUiScale)); ttt.image(group.type.uiIcon).size(iconMed);
ttt.pack(); ttt.pack();
}), }),
new Table(ttt -> { new Table(ttt -> {
ttt.bottom().left(); ttt.bottom().left();
Label label = new Label(() -> amount + ""); ttt.add(amount+"").padTop(2f).fontScale(0.9f);
label.setFontScale(Scl.scl(modUiScale) * 0.9f); ttt.add("[gray]x"+spawners).padTop(10f).fontScale(0.7f);
Label multi = new Label(() -> "[gray]x" + spawners);
multi.setFontScale(Scl.scl(modUiScale) * 0.7f);
ttt.add(label).padTop(2f);
ttt.add(multi).padTop(10f);
ttt.pack(); ttt.pack();
}), }),
new Table(ttt -> { new Table(ttt -> {
ttt.top().right(); ttt.top().right();
Image image1 = new Image(Icon.warning.getRegion()).setScaling(Scaling.fit); ttt.image(Icon.warning.getRegion()).update(img->img.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f)))).size(12f);
image1.update(() -> {
image1.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f)));
});
ttt.add(image1).size(Scl.scl(modUiScale) * 12f);
ttt.visible(() -> group.effect == StatusEffects.boss); ttt.visible(() -> group.effect == StatusEffects.boss);
ttt.pack(); ttt.pack();
}) })
).pad(2f * Scl.scl(modUiScale)); ).pad(2f).get().addListener(new Tooltip(to -> {
tt.clicked(() -> { to.background(Styles.black6);
if(input.keyDown(KeyCode.shiftLeft) && Fonts.getUnicode(group.type.name) != 0){
app.setClipboardText((char)Fonts.getUnicode(group.type.name) + "");
ui.showInfoFade("@copied");
}else{
ui.content.show(group.type);
}
});
if(!mobile){
HandCursorListener listener = new HandCursorListener();
tt.addListener(listener);
tt.update(() -> {
image.color.lerp(!listener.isOver() ? Color.lightGray : Color.white, Mathf.clamp(0.4f * Time.delta));
});
}
tt.addListener(new Tooltip(ttt -> ttt.table(Styles.black6, to -> {
to.margin(4f).left(); to.margin(4f).left();
to.add("[stat]" + group.type.localizedName + "[]").row(); to.add("[stat]" + group.type.localizedName + "[]").row();
to.row(); to.row();
to.add(bundle.format("shar-stat-waveAmount", amount + " [lightgray]x" + spawners + "[]")).row(); to.add(bundle.format("shar-stat-waveAmount", amount + " [lightgray]x" + spawners + "[]")).row();
to.add(bundle.format("shar-stat-waveShield", group.getShield(j))).row(); to.add(bundle.format("shar-stat-waveShield", group.getShield(j))).row();
if(group.effect != null && group.effect != StatusEffects.none) if (group.effect != null && group.effect != StatusEffects.none)
to.add(bundle.get("shar-stat.waveStatus") + group.effect.emoji() + "[stat]" + group.effect.localizedName).row(); to.add(bundle.get("shar-stat.waveStatus") + group.effect.emoji() + "[stat]" + group.effect.localizedName).row();
}))); }));
}); if (++row % 4 == 0) t.row();
if(++row % 4 == 0) t.row();
} }
}) })
); );
});
table.row(); table.row();
} }
});
return table;
} }
} }

View File

@@ -1,7 +1,7 @@
package UnitInfo.ui.windows; package UnitInfo.ui.windows;
import UnitInfo.ui.UnitDisplay;
public class WindowTables { public class WindowTables {
public static WindowTable unitTable = new UnitDisplay(); public static WindowTable
unitTable = new UnitDisplay(),
waveTable = new WaveDisplay();
} }