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