Merge pull request #3265 from summetdev/editor/blocks-searchbar
[editor] Searchable Blocks Implementation
This commit is contained in:
@@ -42,6 +42,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
|||||||
private MapGenerateDialog generateDialog;
|
private MapGenerateDialog generateDialog;
|
||||||
private ScrollPane pane;
|
private ScrollPane pane;
|
||||||
private BaseDialog menu;
|
private BaseDialog menu;
|
||||||
|
private Table blockSelection;
|
||||||
private Rules lastSavedRules;
|
private Rules lastSavedRules;
|
||||||
private boolean saved = false;
|
private boolean saved = false;
|
||||||
private boolean shownWithMap = false;
|
private boolean shownWithMap = false;
|
||||||
@@ -665,9 +666,9 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
|||||||
ui.showConfirm("@confirm", "@editor.unsaved", this::hide);
|
ui.showConfirm("@confirm", "@editor.unsaved", this::hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBlockSelection(Table table){
|
private void addBlockSelection(Table cont){
|
||||||
Table content = new Table();
|
blockSelection = new Table();
|
||||||
pane = new ScrollPane(content);
|
pane = new ScrollPane(blockSelection);
|
||||||
pane.setFadeScrollBars(false);
|
pane.setFadeScrollBars(false);
|
||||||
pane.setOverscroll(true, false);
|
pane.setOverscroll(true, false);
|
||||||
pane.exited(() -> {
|
pane.exited(() -> {
|
||||||
@@ -675,9 +676,22 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
|||||||
Core.scene.setScrollFocus(view);
|
Core.scene.setScrollFocus(view);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
|
||||||
|
|
||||||
int i = 0;
|
cont.table(search -> {
|
||||||
|
search.image(Icon.zoom).padRight(8);
|
||||||
|
search.field("", this::rebuildBlockSelection)
|
||||||
|
.name("editor/search").maxTextLength(maxNameLength).get().setMessageText("@players.search");
|
||||||
|
}).pad(5);
|
||||||
|
cont.row();
|
||||||
|
cont.table(Tex.underline, extra -> extra.labelWrap(() -> editor.drawBlock.localizedName).width(200f).center()).growX();
|
||||||
|
cont.row();
|
||||||
|
cont.add(pane).expandY().top().left();
|
||||||
|
|
||||||
|
rebuildBlockSelection("");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rebuildBlockSelection(String searchText){
|
||||||
|
blockSelection.clear();
|
||||||
|
|
||||||
blocksOut.clear();
|
blocksOut.clear();
|
||||||
blocksOut.addAll(Vars.content.blocks());
|
blocksOut.addAll(Vars.content.blocks());
|
||||||
@@ -691,28 +705,32 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
|||||||
return Integer.compare(b1.id, b2.id);
|
return Integer.compare(b1.id, b2.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
for(Block block : blocksOut){
|
for(Block block : blocksOut){
|
||||||
TextureRegion region = block.icon(Cicon.medium);
|
TextureRegion region = block.icon(Cicon.medium);
|
||||||
|
|
||||||
if(!Core.atlas.isFound(region) || !block.inEditor || (block.buildVisibility == BuildVisibility.debugOnly)) continue;
|
if(!Core.atlas.isFound(region) || !block.inEditor
|
||||||
|
|| block.buildVisibility == BuildVisibility.debugOnly
|
||||||
|
|| (!searchText.isEmpty() && !block.localizedName.toLowerCase().contains(searchText.toLowerCase()))
|
||||||
|
) continue;
|
||||||
|
|
||||||
ImageButton button = new ImageButton(Tex.whiteui, Styles.clearTogglei);
|
ImageButton button = new ImageButton(Tex.whiteui, Styles.clearTogglei);
|
||||||
button.getStyle().imageUp = new TextureRegionDrawable(region);
|
button.getStyle().imageUp = new TextureRegionDrawable(region);
|
||||||
button.clicked(() -> editor.drawBlock = block);
|
button.clicked(() -> editor.drawBlock = block);
|
||||||
button.resizeImage(8 * 4f);
|
button.resizeImage(8 * 4f);
|
||||||
button.update(() -> button.setChecked(editor.drawBlock == block));
|
button.update(() -> button.setChecked(editor.drawBlock == block));
|
||||||
group.add(button);
|
blockSelection.add(button).size(50f).tooltip(block.localizedName);
|
||||||
content.add(button).size(50f).tooltip(block.localizedName);
|
|
||||||
|
if(i == 0) editor.drawBlock = block;
|
||||||
|
|
||||||
if(++i % 4 == 0){
|
if(++i % 4 == 0){
|
||||||
content.row();
|
blockSelection.row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
group.getButtons().get(2).setChecked(true);
|
if(i == 0){
|
||||||
|
blockSelection.add("@none").padLeft(80f).padTop(10f);
|
||||||
table.table(Tex.underline, extra -> extra.labelWrap(() -> editor.drawBlock.localizedName).width(200f).center()).growX();
|
}
|
||||||
table.row();
|
|
||||||
table.add(pane).growY().fillX();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user