mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-14 01:37:36 +07:00
[QOL] Search Schematic (#2089)
* autofocus implementation * enter to select first schematic implementation * fix undeclared variable * fix import
This commit is contained in:
@ -386,6 +386,7 @@ public class DesktopInput extends InputHandler{
|
||||
ui.schematics.hide();
|
||||
}else{
|
||||
ui.schematics.show();
|
||||
ui.schematics.focusSearchField();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import arc.util.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.input.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
@ -21,7 +22,9 @@ import static mindustry.Vars.*;
|
||||
|
||||
public class SchematicsDialog extends FloatingDialog{
|
||||
private SchematicInfoDialog info = new SchematicInfoDialog();
|
||||
private Schematic firstSchematic;
|
||||
private String search = "";
|
||||
private TextField searchField;
|
||||
|
||||
public SchematicsDialog(){
|
||||
super("$schematics");
|
||||
@ -46,10 +49,10 @@ public class SchematicsDialog extends FloatingDialog{
|
||||
cont.table(s -> {
|
||||
s.left();
|
||||
s.image(Icon.zoom);
|
||||
s.field(search, res -> {
|
||||
searchField = s.field(search, res -> {
|
||||
search = res;
|
||||
rebuildPane[0].run();
|
||||
}).growX();
|
||||
}).growX().get();
|
||||
}).fillX().padBottom(4);
|
||||
|
||||
cont.row();
|
||||
@ -57,6 +60,14 @@ public class SchematicsDialog extends FloatingDialog{
|
||||
cont.pane(t -> {
|
||||
t.top();
|
||||
t.margin(20f);
|
||||
|
||||
t.update(() -> {
|
||||
if(Core.input.keyTap(Binding.chat) && Core.scene.getKeyboardFocus() == searchField && firstSchematic != null){
|
||||
control.input.useSchematic(firstSchematic);
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
rebuildPane[0] = () -> {
|
||||
t.clear();
|
||||
int i = 0;
|
||||
@ -65,8 +76,12 @@ public class SchematicsDialog extends FloatingDialog{
|
||||
t.add("$none");
|
||||
}
|
||||
|
||||
firstSchematic = null;
|
||||
|
||||
for(Schematic s : schematics.all()){
|
||||
if(!search.isEmpty() && !s.name().toLowerCase().contains(search.toLowerCase())) continue;
|
||||
if(firstSchematic == null)
|
||||
firstSchematic = s;
|
||||
|
||||
Button[] sel = {null};
|
||||
sel[0] = t.button(b -> {
|
||||
@ -231,6 +246,12 @@ public class SchematicsDialog extends FloatingDialog{
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public void focusSearchField(){
|
||||
if(searchField == null) return;
|
||||
|
||||
Core.scene.setKeyboardFocus(searchField);
|
||||
}
|
||||
|
||||
public static class SchematicImage extends Image{
|
||||
public float scaling = 16f;
|
||||
public float thickness = 4f;
|
||||
|
Reference in New Issue
Block a user