Database dialog search bar

This commit is contained in:
Anuken
2021-08-10 17:11:22 -04:00
parent e7e64379dd
commit 9c626a17f0
3 changed files with 35 additions and 24 deletions

View File

@@ -20,6 +20,8 @@ import mindustry.world.*;
import static mindustry.Vars.*;
public class DatabaseDialog extends BaseDialog{
private TextField search;
private Table all = new Table();
public DatabaseDialog(){
super("@database");
@@ -28,28 +30,38 @@ public class DatabaseDialog extends BaseDialog{
addCloseButton();
shown(this::rebuild);
onResize(this::rebuild);
all.margin(20).marginTop(0f);
cont.table(s -> {
s.image(Icon.zoom).padRight(8);
search = s.field(null, text -> rebuild()).growX().get();
search.setMessageText(Core.bundle.get("players.search"));
}).fillX().padBottom(4).row();
cont.pane(all);
}
void rebuild(){
cont.clear();
Table table = new Table();
table.margin(20);
ScrollPane pane = new ScrollPane(table);
all.clear();
var text = search.getText();
Seq<Content>[] allContent = Vars.content.getContentMap();
for(int j = 0; j < allContent.length; j++){
ContentType type = ContentType.all[j];
Seq<Content> array = allContent[j].select(c -> c instanceof UnlockableContent u && (!u.isHidden() || u.node() != null));
Seq<Content> array = allContent[j]
.select(c -> c instanceof UnlockableContent u &&
(!u.isHidden() || u.node() != null) &&
(text.isEmpty() || u.localizedName.toLowerCase().contains(text.toLowerCase())));
if(array.size == 0) continue;
table.add("@content." + type.name() + ".name").growX().left().color(Pal.accent);
table.row();
table.image().growX().pad(5).padLeft(0).padRight(0).height(3).color(Pal.accent);
table.row();
table.table(list -> {
all.add("@content." + type.name() + ".name").growX().left().color(Pal.accent);
all.row();
all.image().growX().pad(5).padLeft(0).padRight(0).height(3).color(Pal.accent);
all.row();
all.table(list -> {
list.left();
int cols = (int)Mathf.clamp((Core.graphics.getWidth() - Scl.scl(30)) / Scl.scl(32 + 10), 1, 22);
@@ -94,10 +106,12 @@ public class DatabaseDialog extends BaseDialog{
}
}
}).growX().left().padBottom(10);
table.row();
all.row();
}
cont.add(pane);
if(all.getChildren().isEmpty()){
all.add("@none.found");
}
}
boolean unlocked(UnlockableContent content){