Skip to content

Commit

Permalink
[Feature] SchematicList
Browse files Browse the repository at this point in the history
  • Loading branch information
MinRi2 committed Jul 7, 2024
1 parent 5949f32 commit e93e9f4
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/MinerTools/ui/tables/MembersTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -28,7 +28,7 @@ public void setContainer(Table container){
this.container = container;
}

public void rebuildMembers(){
public void rebuildCont(){
clearChildren();
builder.build(this);
}
Expand All @@ -39,27 +39,27 @@ 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();
}
}

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<MemberTable> getMembers(){
Expand All @@ -85,7 +85,7 @@ public interface MembersBuilder extends TableBuilder<MembersTable>{

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();

Expand Down
6 changes: 3 additions & 3 deletions src/MinerTools/ui/tables/floats/ToolsFloatTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
104 changes: 104 additions & 0 deletions src/MinerTools/ui/tables/members/SchematicList.java
Original file line number Diff line number Diff line change
@@ -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<String> selectedTags = new Seq<>();
private int selectedCount;
private Seq<String> 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;
}
}
}

0 comments on commit e93e9f4

Please sign in to comment.