Skip to content

Commit

Permalink
✨ 整理美化TeamsStatDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
way-zer committed Jan 8, 2025
1 parent 100c961 commit 94b2458
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/mindustryX/features/UIExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void init(){
teamsStatDisplay = new TeamsStatDisplay();
ui.hudGroup.fill(t -> {
t.name = "otherCore";
t.left().add(teamsStatDisplay);
t.left().add(teamsStatDisplay.wrapped());
t.visible(() -> ui.hudfrag.shown && Core.settings.getBool("showOtherTeamResource"));
});

Expand Down
152 changes: 76 additions & 76 deletions src/mindustryX/features/ui/TeamsStatDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import mindustry.content.*;
import mindustry.core.*;
import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
Expand All @@ -22,149 +23,148 @@
//moved from mindustry.arcModule.ui.OtherCoreItemDisplay
public class TeamsStatDisplay extends Table{
private final float fontScl = 0.8f;
private final SimpleCollapser teamsColl = new SimpleCollapser();
private final Interval timer = new Interval();

private final Seq<Teams.TeamData> forceShowTeam = new Seq<>();
public final Seq<Teams.TeamData> teams = new Seq<>();
private final Interval timer = new Interval();
public final Seq<Team> manualDeleted = new Seq<>();
private boolean showStat = true, showItem = true, showUnit = true;


public TeamsStatDisplay(){
table(buttons -> {
buttons.button("[red]+", flatTogglet, teamsColl::toggle).update(t -> {
t.setChecked(false);
t.setText(teamsColl.getCollapsed() ? "[red]+" : "[red]×");
}).size(40).row();
buttons.collapser(t -> {
t.button("T", flatTogglet, () -> UIExt.teamSelect.select(team -> teams.contains(team.data()), team -> {
if(forceShowTeam.contains(team.data())) forceShowTeam.remove(team.data());
else forceShowTeam.add(team.data());
teamsRebuild();
})).checked(gg -> false).size(40).row();
t.button(Blocks.worldProcessor.emoji(), flatTogglet, () -> {
showStat = !showStat;
teamsRebuild();
}).checked(a -> showStat).size(40).row();
t.button(content.items().get(0).emoji(), flatTogglet, () -> {
showItem = !showItem;
teamsRebuild();
}).checked(a -> showItem).size(40).row();
t.button(UnitTypes.mono.emoji(), flatTogglet, () -> {
showUnit = !showUnit;
teamsRebuild();
}).checked(a -> showUnit).size(40).row();
}, () -> !teamsColl.getCollapsed());
});
add(teamsColl).touchable(Touchable.disabled);
var teamsTable = teamsColl.getTable();
teamsTable.background(black6);
teamsTable.update(() -> {
if(timer.get(120f))
teamsRebuild();
background(black6);
update(() -> {
if(timer.get(120f)) rebuild();
});

Events.on(EventType.ResetEvent.class, e -> {
forceShowTeam.clear();
manualDeleted.clear();
teams.clear();
teamsTable.clearChildren();
clearChildren();
});
}

private void teamsRebuild(){
teams.clear();
teams.addAll(Vars.state.teams.getActive());
public Table wrapped(){
Table table = new Table();

table.button("编辑队伍", flatBordert, () -> UIExt.teamSelect.select(team -> teams.contains(team.data()), team -> {
manualDeleted.remove(team);
if(teams.contains(team.data())){
teams.remove(team.data());
manualDeleted.add(team);
}else teams.add(team.data());
rebuild();
})).fillX().row();
table.add(this).growX().touchable(Touchable.disabled).row();
table.table(buttons -> {
buttons.defaults().size(40);
buttons.button(Blocks.worldProcessor.emoji(), flatTogglet, () -> {
showStat = !showStat;
rebuild();
}).checked(a -> showStat);
buttons.button(content.items().get(0).emoji(), flatTogglet, () -> {
showItem = !showItem;
rebuild();
}).checked(a -> showItem);
buttons.button(UnitTypes.mono.emoji(), flatTogglet, () -> {
showUnit = !showUnit;
rebuild();
}).checked(a -> showUnit);
}).row();

return table;
}

private void rebuild(){
Vars.state.teams.getActive().each(teams::addUnique);
if(state.rules.waveTimer) teams.addUnique(state.rules.waveTeam.data());
forceShowTeam.each(teams::addUnique);
teams.removeAll(it -> manualDeleted.contains(it.team));
teams.sort(teamData -> -teamData.cores.size);

var teamsTable = teamsColl.getTable();
teamsTable.clear();

clearChildren();
//name + cores + units
addTeamData(teamsTable, Icon.players.getRegion(), team -> team.team.id < 6 ? team.team.localized() : String.valueOf(team.team.id));
addTeamData(teamsTable, Blocks.coreNucleus.uiIcon, team -> UI.formatAmount(team.cores.size));
addTeamData(teamsTable, UnitTypes.mono.uiIcon, team -> UI.formatAmount(team.units.size));
addTeamData(teamsTable, UnitTypes.gamma.uiIcon, team -> String.valueOf(team.players.size));
addTeamData(Icon.players.getRegion(), team -> team.team.id < 6 ? team.team.localized() : String.valueOf(team.team.id));
addTeamData(Blocks.coreNucleus.uiIcon, team -> UI.formatAmount(team.cores.size));
addTeamData(UnitTypes.mono.uiIcon, team -> UI.formatAmount(team.units.size));
addTeamData(UnitTypes.gamma.uiIcon, team -> String.valueOf(team.players.size));

if(showStat){
teamsTable.image().color(Pal.accent).fillX().height(1).colspan(999).padTop(3).padBottom(3).row();
addTeamDataCheckB(teamsTable, Blocks.siliconSmelter.uiIcon, team -> team.team.rules().cheat);
addTeamDataCheck(teamsTable, Blocks.arc.uiIcon, team -> state.rules.blockDamage(team.team));
addTeamDataCheck(teamsTable, Blocks.titaniumWall.uiIcon, team -> state.rules.blockHealth(team.team));
addTeamDataCheck(teamsTable, Blocks.buildTower.uiIcon, team -> state.rules.buildSpeed(team.team));
addTeamDataCheck(teamsTable, UnitTypes.corvus.uiIcon, team -> state.rules.unitDamage(team.team));
addTeamDataCheck(teamsTable, UnitTypes.oct.uiIcon, team -> state.rules.unitHealth(team.team));
addTeamDataCheck(teamsTable, UnitTypes.zenith.uiIcon, team -> state.rules.unitCrashDamage(team.team));
addTeamDataCheck(teamsTable, Blocks.tetrativeReconstructor.uiIcon, team -> state.rules.unitBuildSpeed(team.team));
addTeamDataCheck(teamsTable, Blocks.basicAssemblerModule.uiIcon, team -> state.rules.unitCost(team.team));
teamsTable.row();
image().color(Pal.accent).fillX().height(1).colspan(999).padTop(3).padBottom(3).row();
addTeamDataCheckB(Blocks.siliconSmelter.uiIcon, team -> team.team.rules().cheat);
addTeamDataCheck(Blocks.arc.uiIcon, team -> state.rules.blockDamage(team.team));
addTeamDataCheck(Blocks.titaniumWall.uiIcon, team -> state.rules.blockHealth(team.team));
addTeamDataCheck(Blocks.buildTower.uiIcon, team -> state.rules.buildSpeed(team.team));
addTeamDataCheck(UnitTypes.corvus.uiIcon, team -> state.rules.unitDamage(team.team));
addTeamDataCheck(UnitTypes.oct.uiIcon, team -> state.rules.unitHealth(team.team));
addTeamDataCheck(UnitTypes.zenith.uiIcon, team -> state.rules.unitCrashDamage(team.team));
addTeamDataCheck(Blocks.tetrativeReconstructor.uiIcon, team -> state.rules.unitBuildSpeed(team.team));
addTeamDataCheck(Blocks.basicAssemblerModule.uiIcon, team -> state.rules.unitCost(team.team));
}

if(showItem){
teamsTable.image().color(Pal.accent).fillX().height(1).colspan(999).padTop(3).padBottom(3).row();
image().color(Pal.accent).fillX().height(1).colspan(999).padTop(3).padBottom(3).row();
for(Item item : content.items()){
boolean show = false;
for(Teams.TeamData team : teams){
if(team.hasCore() && team.core().items.get(item) > 0)
show = true;
}
if(show){
addTeamData(teamsTable, item.uiIcon, team -> (team.hasCore() && team.core().items.get(item) > 0) ? UI.formatAmount(team.core().items.get(item)) : "-");
addTeamData(item.uiIcon, team -> (team.hasCore() && team.core().items.get(item) > 0) ? UI.formatAmount(team.core().items.get(item)) : "-");
}
}
}

if(showUnit){
teamsTable.image().color(Pal.accent).fillX().height(1).colspan(999).padTop(3).padBottom(3).row();
image().color(Pal.accent).fillX().height(1).colspan(999).padTop(3).padBottom(3).row();
for(UnitType unit : content.units()){
boolean show = false;
for(Teams.TeamData team : teams){
if(team.countType(unit) > 0)
show = true;
}
if(show){
addTeamData(teamsTable, unit.uiIcon, team -> team.countType(unit) > 0 ? String.valueOf(team.countType(unit)) : "-");
addTeamData(unit.uiIcon, team -> team.countType(unit) > 0 ? String.valueOf(team.countType(unit)) : "-");
}
}
}
}

private void addTeamDataCheck(Table table, TextureRegion icon, Floatf<Teams.TeamData> checked){
private void addTeamDataCheck(TextureRegion icon, Floatf<TeamData> checked){
if(teams.isEmpty() || teams.allMatch(it -> checked.get(it) == 1f)) return;
//check allSame
float value = checked.get(teams.get(0));
if(teams.allMatch(it -> checked.get(it) == value)){
addTeamData(table, icon, FormatDefault.format(value));
addTeamData(icon, FormatDefault.format(value));
return;
}
addTeamData(table, icon, team -> FormatDefault.format(checked.get(team)));
addTeamData(icon, team -> FormatDefault.format(checked.get(team)));
}

private void addTeamDataCheckB(Table table, TextureRegion icon, Boolf<Teams.TeamData> checked){
private void addTeamDataCheckB(TextureRegion icon, Boolf<TeamData> checked){
if(teams.isEmpty() || teams.allMatch(it -> !checked.get(it))) return;
//check allSame
boolean value = checked.get(teams.get(0));
if(teams.allMatch(it -> checked.get(it) == value)){
addTeamData(table, icon, value ? "+" : "x");
addTeamData(icon, value ? "+" : "x");
return;
}
addTeamData(table, icon, team -> checked.get(team) ? "+" : "×");
addTeamData(icon, team -> checked.get(team) ? "+" : "×");
}

private void addTeamData(Table table, TextureRegion icon, String value){
private void addTeamData(TextureRegion icon, String value){
// 只显示一个数值
table.image(icon).size(15, 15).left();
table.label(() -> "[#" + Pal.accent + "]" + value).align(Align.center).fontScale(fontScl).colspan(table.getColumns() - 1);
table.row();
image(icon).size(15, 15).left();
label(() -> "[#" + Pal.accent + "]" + value).align(Align.center).fontScale(fontScl).colspan(getColumns() - 1);
row();
}

private void addTeamData(Table table, TextureRegion icon, Func<Teams.TeamData,String> teamFunc){
private void addTeamData(TextureRegion icon, Func<TeamData, String> teamFunc){
// 通用情况
table.image(icon).size(15, 15).left();
image(icon).size(15, 15).left();
for(Teams.TeamData teamData : teams){
table.label(() -> "[#" + teamData.team.color + "]" + teamFunc.get(teamData)).fontScale(fontScl);
label(() -> "[#" + teamData.team.color + "]" + teamFunc.get(teamData))
.padLeft(2).uniformX().fontScale(fontScl);
}
table.row();
row();
}
}
5 changes: 2 additions & 3 deletions src/mindustryX/features/ui/toolTable/HudSettingsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
import mindustry.world.blocks.environment.*;
import mindustryX.features.Settings;
import mindustryX.features.*;
import mindustryX.features.ui.*;

import static arc.Core.*;
import static mindustry.Vars.*;
import static mindustry.ui.Styles.flatTogglet;

//moved from mindustry.arcModule.ui.quickTool.HudSettingsTable
public class HudSettingsTable extends ToolTableBase{
Expand All @@ -35,6 +33,7 @@ protected void rebuild(){
table(t -> {
t.defaults().size(30);
t.button("[cyan]信", Styles.flatBordert, () -> UIExt.arcMessageDialog.show()).tooltip("中央监控室");
t.button("[cyan]资", Styles.flatTogglet, () -> Settings.toggle("showOtherTeamResource")).tooltip("多队伍资源信息显示(左侧)").checked(a -> Core.settings.getBool("showOtherTeamResource"));
t.button("[cyan]S", Styles.flatBordert, () -> Call.sendChatMessage("/sync")).tooltip("同步一波");
t.button("[cyan]观", Styles.flatBordert, () -> Call.sendChatMessage("/ob")).tooltip("观察者模式");
t.button("[cyan]技", Styles.flatBordert, () -> Call.sendChatMessage("/skill")).tooltip("技能!");
Expand Down Expand Up @@ -74,7 +73,7 @@ protected void rebuild(){
control.input.logicCutscene = false;
ui.announce("已移除逻辑视角锁定");
}).checked(a -> Core.settings.getBool("removeLogicLock")).tooltip("逻辑锁定");
t.button(Blocks.worldMessage.emoji(), flatTogglet, () -> Settings.toggle("displayallmessage")).checked(a -> RenderExt.displayAllMessage).tooltip("开关信息板全显示");
t.button(Blocks.worldMessage.emoji(), Styles.flatTogglet, () -> Settings.toggle("displayallmessage")).checked(a -> RenderExt.displayAllMessage).tooltip("开关信息板全显示");
t.button("" + Iconc.itemCopper, Styles.flatBordert, this::floorStatisticDialog).tooltip("矿物信息");
t.button(Icon.fillSmall, Styles.flati, () -> EffectsDialog.withAllEffects().show()).tooltip("特效大全");
if(!mobile) t.button(Icon.starSmall, Styles.flati, this::uiTable).tooltip("ui大全");
Expand Down

0 comments on commit 94b2458

Please sign in to comment.