From e93e9f41237f0bcb29e0c8446110d235d91ed7cc Mon Sep 17 00:00:00 2001 From: MinRi2 <2275045670@qq.com> Date: Sun, 7 Jul 2024 18:12:59 +0800 Subject: [PATCH] [Feature] SchematicList --- src/MinerTools/ui/tables/MembersTable.java | 18 +-- .../ui/tables/floats/ToolsFloatTable.java | 6 +- .../ui/tables/members/SchematicList.java | 104 ++++++++++++++++++ 3 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 src/MinerTools/ui/tables/members/SchematicList.java diff --git a/src/MinerTools/ui/tables/MembersTable.java b/src/MinerTools/ui/tables/MembersTable.java index 1b3188b..667fc41 100644 --- a/src/MinerTools/ui/tables/MembersTable.java +++ b/src/MinerTools/ui/tables/MembersTable.java @@ -14,7 +14,7 @@ public class MembersTable extends Table{ public MembersBuilder builder; private Table container; - private MemberTable showMember; + private MemberTable currentMember; public MembersTable(){ this(MembersBuilder.defaultBuilder); @@ -28,7 +28,7 @@ public void setContainer(Table container){ this.container = container; } - public void rebuildMembers(){ + public void rebuildCont(){ clearChildren(); builder.build(this); } @@ -39,7 +39,7 @@ public void addMember(MemberTable... members){ public void setMember(MemberTable member){ container.clear(); - showMember = member; + currentMember = member; if(member != null){ container.add(member).grow().padRight(2.0f); member.onSelected(); @@ -47,19 +47,19 @@ public void setMember(MemberTable member){ } public void toggleMember(MemberTable member){ - if(memberShowing(member)){ + if(isShowing(member)){ setMember(null); }else{ setMember(member); } } - public boolean memberShowing(){ - return showMember != null; + public boolean isShowing(){ + return currentMember != null; } - public boolean memberShowing(MemberTable memberTable){ - return showMember == memberTable; + public boolean isShowing(MemberTable memberTable){ + return currentMember == memberTable; } public Seq getMembers(){ @@ -85,7 +85,7 @@ public interface MembersBuilder extends TableBuilder{ buttons.button(member.icon, MStyles.clearToggleAccentb, () -> { table.toggleMember(member); - }).height(32f).padTop(4.0f).growX().checked(b -> table.memberShowing(member)); + }).height(32f).padTop(4.0f).growX().checked(b -> table.isShowing(member)); } }).growX().top(); diff --git a/src/MinerTools/ui/tables/floats/ToolsFloatTable.java b/src/MinerTools/ui/tables/floats/ToolsFloatTable.java index b8b2429..93ae625 100644 --- a/src/MinerTools/ui/tables/floats/ToolsFloatTable.java +++ b/src/MinerTools/ui/tables/floats/ToolsFloatTable.java @@ -12,13 +12,13 @@ public ToolsFloatTable(){ toolsTable = new MembersTable(); - toolsTable.addMember(new TeamsInfo(), new TeamChanger(), new PlayerList(), new AITable()); + toolsTable.addMember(new TeamsInfo(), new TeamChanger(), new PlayerList(), new SchematicList(), new AITable()); } @Override public void rebuild(){ - toolsTable.rebuildMembers(); - + toolsTable.rebuildCont(); + super.rebuild(); } diff --git a/src/MinerTools/ui/tables/members/SchematicList.java b/src/MinerTools/ui/tables/members/SchematicList.java new file mode 100644 index 0000000..5d5e49e --- /dev/null +++ b/src/MinerTools/ui/tables/members/SchematicList.java @@ -0,0 +1,104 @@ +package MinerTools.ui.tables.members; + +import MinerTools.ui.tables.MembersTable.*; +import arc.scene.ui.*; +import arc.scene.ui.layout.*; +import arc.struct.*; +import arc.util.*; +import mindustry.*; +import mindustry.game.*; +import mindustry.gen.*; +import mindustry.ui.dialogs.SchematicsDialog.*; + +import static MinerTools.ui.MUI.panes; +import static arc.graphics.Color.white; +import static arc.util.Align.center; +import static arc.util.Scaling.fit; +import static mindustry.Vars.ui; +import static mindustry.ui.Styles.*; + +public class SchematicList extends MemberTable{ + public static float imageSize = 85f; + + private final Table schematicsTable = new Table(black3); + private final Seq selectedTags = new Seq<>(); + private int selectedCount; + private Seq tags = new Seq<>(); + + private boolean isSetup = false; + + public SchematicList(){ + super(Icon.paste); + + background(black3); + } + + private void setup(){ + tags = Reflect.get(ui.schematics, "tags"); + + ScrollPane pane = pane(noBarPane, schematicsTable).maxHeight(imageSize * 2.5f).top().get(); + + ScrollPane pane2 = pane(noBarPane, tagsTable -> { + for(String tag : tags){ + tagsTable.button(tag, togglet, () -> { + if(selectedTags.contains(tag)) selectedTags.remove(tag); + else selectedTags.add(tag); + schematicsRebuild(); + }).checked(b -> selectedTags.contains(tag)).growY().maxWidth(35).maxHeight(35).get().getLabelCell().fontScale(0.95f); + + tagsTable.row(); + } + + schematicsRebuild(); + }).maxHeight(imageSize * 2.5f).right().get(); + + pane.setScrollingDisabled(true, false); + pane2.setScrollingDisabled(true, false); + + panes.add(pane); + panes.add(pane2); + } + + private void schematicsRebuild(){ + schematicsTable.clear(); + + schematicsTable.label(() -> selectedCount + "/" + Vars.schematics.all().size).row(); + + selectedCount = 0; + int i = 0; + for(Schematic schematic : Vars.schematics.all()){ + if(selectedTags.isEmpty() || schematic.labels.containsAll(selectedTags)){ + selectedCount++; + + schematicsTable.button(b -> { + b.stack( + new SchematicImage(schematic).setScaling(fit), + new Table(n -> { + n.top(); + n.table(black3, c -> { + Label l = c.add(schematic.name()).style(outlineLabel).color(white).top().growX().maxWidth(70 - 8).get(); + l.setEllipsis(true); + l.setAlignment(center); + }).growX().margin(1).pad(4).maxWidth(Scl.scl(imageSize - 8)).padBottom(0); + })).size(imageSize); + }, () -> { + if(Vars.state.rules.schematicsAllowed){ + Vars.control.input.useSchematic(schematic); + } + }); + + if(++i % 3 == 0) schematicsTable.row(); + } + } + } + + @Override + public void onSelected(){ + super.onSelected(); + + if(!isSetup){ + setup(); + isSetup = true; + } + } +}