Improvements to the Schematics UI (#8605)
* schematics UI improvements * better edit tags UI * visual tweaks * cleanup inline obsession cleanup again... another little bit of cleanup a little bit of cleanup minor cleanup
This commit is contained in:
@@ -15,7 +15,6 @@ import arc.scene.ui.layout.*;
|
||||
import arc.scene.utils.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -48,6 +47,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
shouldPause = true;
|
||||
addCloseButton();
|
||||
buttons.button("@schematic.import", Icon.download, this::showImport);
|
||||
makeButtonOverlay();
|
||||
shown(this::setup);
|
||||
onResize(this::setup);
|
||||
}
|
||||
@@ -70,6 +70,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
search = res;
|
||||
rebuildPane.run();
|
||||
}).growX().get();
|
||||
searchField.setMessageText("@schematic.search");
|
||||
}).fillX().padBottom(4);
|
||||
|
||||
cont.row();
|
||||
@@ -99,9 +100,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
rebuildTags.run();
|
||||
}).fillX().height(tagh).scrollY(false);
|
||||
|
||||
in.button(Icon.pencilSmall, () -> {
|
||||
showAllTags();
|
||||
}).size(tagh).pad(2).tooltip("@schematic.edittags");
|
||||
in.button(Icon.pencilSmall, this::showAllTags).size(tagh).pad(2).tooltip("@schematic.edittags");
|
||||
}).height(tagh).fillX();
|
||||
|
||||
cont.row();
|
||||
@@ -111,7 +110,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
|
||||
t.update(() -> {
|
||||
if(Core.input.keyTap(Binding.chat) && Core.scene.getKeyboardFocus() == searchField && firstSchematic != null){
|
||||
if(!Vars.state.rules.schematicsAllowed){
|
||||
if(!state.rules.schematicsAllowed){
|
||||
ui.showInfo("@schematic.disabled");
|
||||
}else{
|
||||
control.input.useSchematic(firstSchematic);
|
||||
@@ -144,58 +143,14 @@ public class SchematicsDialog extends BaseDialog{
|
||||
buttons.left();
|
||||
buttons.defaults().size(50f);
|
||||
|
||||
ImageButtonStyle style = Styles.clearNonei;
|
||||
ImageButtonStyle style = Styles.emptyi;
|
||||
|
||||
buttons.button(Icon.info, style, () -> {
|
||||
showInfo(s);
|
||||
});
|
||||
|
||||
buttons.button(Icon.upload, style, () -> {
|
||||
showExport(s);
|
||||
});
|
||||
|
||||
buttons.button(Icon.pencil, style, () -> {
|
||||
new BaseDialog("@schematic.rename"){{
|
||||
setFillParent(true);
|
||||
|
||||
cont.margin(30);
|
||||
|
||||
cont.add("@schematic.tags").padRight(6f);
|
||||
cont.table(tags -> buildTags(s, tags, false)).maxWidth(400f).fillX().left().row();
|
||||
|
||||
cont.margin(30).add("@name").padRight(6f);
|
||||
TextField nameField = cont.field(s.name(), null).size(400f, 55f).left().get();
|
||||
|
||||
cont.row();
|
||||
|
||||
cont.margin(30).add("@editor.description").padRight(6f);
|
||||
TextField descField = cont.area(s.description(), Styles.areaField, t -> {}).size(400f, 140f).left().get();
|
||||
|
||||
Runnable accept = () -> {
|
||||
s.tags.put("name", nameField.getText());
|
||||
s.tags.put("description", descField.getText());
|
||||
s.save();
|
||||
hide();
|
||||
rebuildPane.run();
|
||||
};
|
||||
|
||||
buttons.defaults().size(120, 54).pad(4);
|
||||
buttons.button("@ok", accept).disabled(b -> nameField.getText().isEmpty());
|
||||
buttons.button("@cancel", this::hide);
|
||||
|
||||
keyDown(KeyCode.enter, () -> {
|
||||
if(!nameField.getText().isEmpty() && Core.scene.getKeyboardFocus() != descField){
|
||||
accept.run();
|
||||
}
|
||||
});
|
||||
keyDown(KeyCode.escape, this::hide);
|
||||
keyDown(KeyCode.back, this::hide);
|
||||
show();
|
||||
}};
|
||||
});
|
||||
buttons.button(Icon.info, style, () -> showInfo(s)).tooltip("@info.title");
|
||||
buttons.button(Icon.upload, style, () -> showExport(s)).tooltip("@editor.export");
|
||||
buttons.button(Icon.pencil, style, () -> showEdit(s)).tooltip("@schematic.edit");
|
||||
|
||||
if(s.hasSteamID()){
|
||||
buttons.button(Icon.link, style, () -> platform.viewListing(s));
|
||||
buttons.button(Icon.link, style, () -> platform.viewListing(s)).tooltip("@view.workshop");
|
||||
}else{
|
||||
buttons.button(Icon.trash, style, () -> {
|
||||
if(s.mod != null){
|
||||
@@ -206,9 +161,8 @@ public class SchematicsDialog extends BaseDialog{
|
||||
rebuildPane.run();
|
||||
});
|
||||
}
|
||||
});
|
||||
}).tooltip("@save.delete");
|
||||
}
|
||||
|
||||
}).growX().height(50f);
|
||||
b.row();
|
||||
b.stack(new SchematicImage(s).setScaling(Scaling.fit), new Table(n -> {
|
||||
@@ -224,7 +178,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
if(state.isMenu()){
|
||||
showInfo(s);
|
||||
}else{
|
||||
if(!Vars.state.rules.schematicsAllowed){
|
||||
if(!state.rules.schematicsAllowed){
|
||||
ui.showInfo("@schematic.disabled");
|
||||
}else{
|
||||
control.input.useSchematic(s);
|
||||
@@ -241,7 +195,11 @@ public class SchematicsDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
if(firstSchematic == null){
|
||||
t.add("@none");
|
||||
if(!searchString.isEmpty() || selectedTags.any()){
|
||||
t.add("@none.found");
|
||||
}else{
|
||||
t.add("@none").color(Color.lightGray);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -254,7 +212,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
public void showImport(){
|
||||
BaseDialog dialog = new BaseDialog("@editor.export");
|
||||
BaseDialog dialog = new BaseDialog("@editor.import");
|
||||
dialog.cont.pane(p -> {
|
||||
p.margin(10f);
|
||||
p.table(Tex.button, t -> {
|
||||
@@ -307,9 +265,9 @@ public class SchematicsDialog extends BaseDialog{
|
||||
public void showExport(Schematic s){
|
||||
BaseDialog dialog = new BaseDialog("@editor.export");
|
||||
dialog.cont.pane(p -> {
|
||||
p.margin(10f);
|
||||
p.table(Tex.button, t -> {
|
||||
TextButtonStyle style = Styles.flatt;
|
||||
p.margin(10f);
|
||||
p.table(Tex.button, t -> {
|
||||
TextButtonStyle style = Styles.flatt;
|
||||
t.defaults().size(280f, 60f).left();
|
||||
if(steam && !s.hasSteamID()){
|
||||
t.button("@schematic.shareworkshop", Icon.book, style,
|
||||
@@ -334,6 +292,43 @@ public class SchematicsDialog extends BaseDialog{
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public void showEdit(Schematic s){
|
||||
new BaseDialog("@schematic.edit"){{
|
||||
setFillParent(true);
|
||||
addCloseListener();
|
||||
|
||||
cont.margin(30);
|
||||
|
||||
cont.add("@schematic.tags").padRight(6f);
|
||||
cont.table(tags -> buildTags(s, tags, false)).maxWidth(400f).fillX().left().row();
|
||||
|
||||
cont.margin(30).add("@name").padRight(6f);
|
||||
TextField nameField = cont.field(s.name(), null).size(400f, 55f).left().get();
|
||||
|
||||
cont.row();
|
||||
|
||||
cont.margin(30).add("@editor.description").padRight(6f);
|
||||
TextField descField = cont.area(s.description(), Styles.areaField, t -> {}).size(400f, 140f).left().get();
|
||||
|
||||
Runnable accept = () -> {
|
||||
s.tags.put("name", nameField.getText());
|
||||
s.tags.put("description", descField.getText());
|
||||
s.save();
|
||||
hide();
|
||||
rebuildPane.run();
|
||||
};
|
||||
|
||||
buttons.defaults().size(210f, 64f).pad(4);
|
||||
buttons.button("@ok", Icon.ok, accept).disabled(b -> nameField.getText().isEmpty());
|
||||
buttons.button("@cancel", Icon.cancel, this::hide);
|
||||
|
||||
keyDown(KeyCode.enter, () -> {
|
||||
if(!nameField.getText().isEmpty() && Core.scene.getKeyboardFocus() != descField){
|
||||
accept.run();
|
||||
}
|
||||
});
|
||||
}}.show();
|
||||
}
|
||||
|
||||
//adds all new tags to the global list of tags
|
||||
//alternatively, unknown tags could be discarded on import?
|
||||
@@ -406,35 +401,51 @@ public class SchematicsDialog extends BaseDialog{
|
||||
cont.pane(t -> {
|
||||
resized(true, () -> {
|
||||
t.clearChildren();
|
||||
t.marginRight(19f);
|
||||
t.marginRight(19f).marginLeft(12f);
|
||||
t.defaults().size(48f);
|
||||
|
||||
int cols = (int)Math.min(20, Core.graphics.getWidth() / Scl.scl(52f));
|
||||
|
||||
int i = 0;
|
||||
for(String icon : PlanetDialog.defaultIcons){
|
||||
String out = (char)Iconc.codes.get(icon) + "";
|
||||
if(tags.contains(out)) continue;
|
||||
|
||||
t.button(Icon.icons.get(icon), Styles.flati, iconMed, () -> {
|
||||
tags.add(out);
|
||||
tagsChanged();
|
||||
cons.get(out);
|
||||
hide();
|
||||
});
|
||||
|
||||
if(++i % cols == 0) t.row();
|
||||
}
|
||||
|
||||
for(ContentType ctype : defaultContentIcons){
|
||||
var all = content.getBy(ctype).<UnlockableContent>as().filter(u -> !u.isHidden() && u.unlockedNow() && u.hasEmoji());
|
||||
|
||||
t.row();
|
||||
t.image().colspan(cols).growX().width(Float.NEGATIVE_INFINITY).height(3f).color(Pal.accent);
|
||||
if(all.count(u -> !tags.contains(u.emoji())) > 0) t.image().colspan(cols).growX().width(Float.NEGATIVE_INFINITY).height(3f).color(Pal.accent);
|
||||
t.row();
|
||||
|
||||
int i = 0;
|
||||
for(UnlockableContent u : content.getBy(ctype).<UnlockableContent>as()){
|
||||
if(!u.isHidden() && u.unlockedNow() && u.hasEmoji() && !tags.contains(u.emoji())){
|
||||
t.button(new TextureRegionDrawable(u.uiIcon), Styles.flati, iconMed, () -> {
|
||||
String out = u.emoji() + "";
|
||||
i = 0;
|
||||
for(UnlockableContent u : all){
|
||||
if(tags.contains(u.emoji())) continue;
|
||||
t.button(new TextureRegionDrawable(u.uiIcon), Styles.flati, iconMed, () -> {
|
||||
String out = u.emoji() + "";
|
||||
|
||||
tags.add(out);
|
||||
tagsChanged();
|
||||
cons.get(out);
|
||||
tags.add(out);
|
||||
tagsChanged();
|
||||
cons.get(out);
|
||||
|
||||
hide();
|
||||
});
|
||||
hide();
|
||||
}).tooltip(u.localizedName);
|
||||
|
||||
if(++i % cols == 0) t.row();
|
||||
}
|
||||
if(++i % cols == 0) t.row();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}).scrollX(false);
|
||||
buttons.button("@back", Icon.left, this::hide).size(210f, 64f);
|
||||
}}.show();
|
||||
}
|
||||
@@ -446,66 +457,91 @@ public class SchematicsDialog extends BaseDialog{
|
||||
dialog.cont.pane(p -> {
|
||||
rebuild[0] = () -> {
|
||||
p.clearChildren();
|
||||
p.defaults().fillX().left();
|
||||
p.margin(12f).defaults().fillX().left();
|
||||
|
||||
float sum = 0f;
|
||||
Table current = new Table().left();
|
||||
|
||||
for(var tag : tags){
|
||||
|
||||
var next = new Table(Tex.button, n -> {
|
||||
n.add(tag).padRight(4);
|
||||
var next = new Table(n -> {
|
||||
n.table(Tex.pane, move -> {
|
||||
move.margin(2);
|
||||
|
||||
n.add().growX();
|
||||
n.defaults().size(30f);
|
||||
|
||||
//delete
|
||||
n.button(Icon.cancelSmall, Styles.emptyi, () -> {
|
||||
ui.showConfirm("@schematic.tagdelconfirm", () -> {
|
||||
for(Schematic s : schematics.all()){
|
||||
if(s.labels.any()){
|
||||
s.labels.remove(tag);
|
||||
s.save();
|
||||
}
|
||||
}
|
||||
selectedTags.remove(tag);
|
||||
tags.remove(tag);
|
||||
tagsChanged();
|
||||
rebuildPane.run();
|
||||
rebuild[0].run();
|
||||
});
|
||||
});
|
||||
//rename
|
||||
n.button(Icon.pencilSmall, Styles.emptyi, () -> {
|
||||
ui.showTextInput("@schematic.renametag", "@name", tag, result -> {
|
||||
//same tag, nothing was renamed
|
||||
if(result.equals(tag)) return;
|
||||
|
||||
if(tags.contains(result)){
|
||||
ui.showInfo("@schematic.tagexists");
|
||||
}else{
|
||||
for(Schematic s : schematics.all()){
|
||||
if(s.labels.any()){
|
||||
s.labels.replace(tag, result);
|
||||
s.save();
|
||||
}
|
||||
}
|
||||
selectedTags.replace(tag, result);
|
||||
tags.replace(tag, result);
|
||||
//move up
|
||||
move.button(Icon.upOpen, Styles.emptyi, () -> {
|
||||
int idx = tags.indexOf(tag);
|
||||
if(idx > 0){
|
||||
tags.swap(idx, idx - 1);
|
||||
tagsChanged();
|
||||
rebuild[0].run();
|
||||
}
|
||||
}).tooltip("@editor.moveup").row();
|
||||
//move down
|
||||
move.button(Icon.downOpen, Styles.emptyi, () -> {
|
||||
int idx = tags.indexOf(tag);
|
||||
if(idx < tags.size - 1){
|
||||
tags.swap(idx, idx + 1);
|
||||
tagsChanged();
|
||||
rebuild[0].run();
|
||||
}
|
||||
}).tooltip("@editor.movedown");
|
||||
}).fillY().margin(6f);
|
||||
|
||||
n.table(Tex.whiteui, t -> {
|
||||
t.setColor(Pal.gray);
|
||||
t.add(tag).left().row();
|
||||
t.add(Core.bundle.format("schematic.tagged", schematics.all().count(s -> s.labels.contains(tag)))).left()
|
||||
.update(b -> b.setColor(b.hasMouse() ? Pal.accent : Color.lightGray)).get().clicked(() -> {
|
||||
dialog.hide();
|
||||
selectedTags.clear().add(tag);
|
||||
rebuildTags.run();
|
||||
rebuildPane.run();
|
||||
});
|
||||
});
|
||||
//move
|
||||
n.button(Icon.upSmall, Styles.emptyi, () -> {
|
||||
int idx = tags.indexOf(tag);
|
||||
if(idx > 0){
|
||||
tags.swap(idx, idx - 1);
|
||||
tagsChanged();
|
||||
rebuild[0].run();
|
||||
}
|
||||
});
|
||||
}).growX().fillY().margin(8f);
|
||||
|
||||
n.table(Tex.pane, b -> {
|
||||
b.margin(2);
|
||||
|
||||
//rename tag
|
||||
b.button(Icon.pencil, Styles.emptyi, () -> {
|
||||
ui.showTextInput("@schematic.renametag", "@name", tag, result -> {
|
||||
//same tag, nothing was renamed
|
||||
if(result.equals(tag)) return;
|
||||
|
||||
if(tags.contains(result)){
|
||||
ui.showInfo("@schematic.tagexists");
|
||||
}else{
|
||||
for(Schematic s : schematics.all()){
|
||||
if(s.labels.any()){
|
||||
s.labels.replace(tag, result);
|
||||
s.save();
|
||||
}
|
||||
}
|
||||
selectedTags.replace(tag, result);
|
||||
tags.replace(tag, result);
|
||||
tagsChanged();
|
||||
rebuild[0].run();
|
||||
}
|
||||
});
|
||||
}).tooltip("@schematic.renametag").row();
|
||||
//delete tag
|
||||
b.button(Icon.trash, Styles.emptyi, () -> {
|
||||
ui.showConfirm("@schematic.tagdelconfirm", () -> {
|
||||
for(Schematic s : schematics.all()){
|
||||
if(s.labels.any()){
|
||||
s.labels.remove(tag);
|
||||
s.save();
|
||||
}
|
||||
}
|
||||
selectedTags.remove(tag);
|
||||
tags.remove(tag);
|
||||
tagsChanged();
|
||||
rebuildPane.run();
|
||||
rebuild[0].run();
|
||||
});
|
||||
}).tooltip("@save.delete");
|
||||
}).fillY().margin(6f);
|
||||
});
|
||||
|
||||
next.pack();
|
||||
@@ -515,10 +551,10 @@ public class SchematicsDialog extends BaseDialog{
|
||||
p.add(current).row();
|
||||
current = new Table();
|
||||
current.left();
|
||||
current.add(next).height(tagh).pad(2);
|
||||
current.add(next).minWidth(240).pad(4);
|
||||
sum = 0;
|
||||
}else{
|
||||
current.add(next).height(tagh).pad(2);
|
||||
current.add(next).minWidth(240).pad(4);
|
||||
}
|
||||
|
||||
sum += w;
|
||||
@@ -538,7 +574,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
};
|
||||
|
||||
resized(true, rebuild[0]);
|
||||
});
|
||||
}).scrollX(false);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@@ -574,6 +610,7 @@ public class SchematicsDialog extends BaseDialog{
|
||||
dialog.addCloseButton();
|
||||
dialog.cont.pane(p -> resized(true, () -> {
|
||||
p.clearChildren();
|
||||
p.defaults().fillX().left();
|
||||
|
||||
float sum = 0f;
|
||||
Table current = new Table().left();
|
||||
@@ -704,19 +741,16 @@ public class SchematicsDialog extends BaseDialog{
|
||||
SchematicInfoDialog(){
|
||||
super("");
|
||||
setFillParent(true);
|
||||
addCloseButton();
|
||||
addCloseListener();
|
||||
}
|
||||
|
||||
public void show(Schematic schem){
|
||||
cont.clear();
|
||||
title.setText("[[" + Core.bundle.get("schematic") + "] " +schem.name());
|
||||
|
||||
cont.add(Core.bundle.format("schematic.info", schem.width, schem.height, schem.tiles.size)).color(Color.lightGray);
|
||||
cont.row();
|
||||
cont.add(Core.bundle.format("schematic.info", schem.width, schem.height, schem.tiles.size)).color(Color.lightGray).row();
|
||||
cont.table(tags -> buildTags(schem, tags)).fillX().left().row();
|
||||
cont.row();
|
||||
cont.add(new SchematicImage(schem)).maxSize(800f);
|
||||
cont.row();
|
||||
cont.add(new SchematicImage(schem)).maxSize(800f).row();
|
||||
|
||||
ItemSeq arr = schem.requirements();
|
||||
cont.table(r -> {
|
||||
@@ -755,7 +789,13 @@ public class SchematicsDialog extends BaseDialog{
|
||||
});
|
||||
}
|
||||
|
||||
buttons.clearChildren();
|
||||
buttons.defaults().size(210f, 64f);
|
||||
buttons.button("@back", Icon.left, this::hide);
|
||||
buttons.button("@editor.export", Icon.upload, () -> showExport(schem));
|
||||
buttons.button("@schematic.edit", Icon.edit, () -> showEdit(schem));
|
||||
|
||||
show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user