resource display navbar

This commit is contained in:
sharlottes
2022-11-26 22:30:54 +09:00
parent 15e70821ce
commit 68c2b1048a

View File

@@ -1,16 +1,17 @@
package informatis.ui.dialogs;
import arc.Core;
import arc.func.Cons;
import arc.graphics.Color;
import arc.graphics.g2d.Font;
import arc.scene.Element;
import arc.scene.style.Drawable;
import arc.scene.style.Style;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.ObjectMap;
import arc.struct.Seq;
import arc.util.Align;
import arc.util.Log;
import arc.util.Scaling;
import mindustry.gen.Icon;
import mindustry.gen.Tex;
@@ -18,11 +19,11 @@ import mindustry.ui.Styles;
import mindustry.ui.dialogs.*;
import java.lang.reflect.Field;
import java.util.Arrays;
public class ResourcePreviewDialog extends BaseDialog {
boolean showName = false;
int currentTab = 0;
public ResourcePreviewDialog() {
super("resource previews");
@@ -31,40 +32,72 @@ public class ResourcePreviewDialog extends BaseDialog {
cont.table(t -> {
t.top().center();
t.table(Tex.underline, options -> {
options.top().center();
CheckBox box = new CheckBox("show resource with its name");
box.changed(() -> {
showName = !showName;
((ScrollPane) find("resource-pane")).setWidget(rebuildResourceList());
});
options.add(box);
}).padBottom(50f).growX().row();
t.pane(rebuildResourceList()).name("resource-pane").grow();
t.table(Tex.underline, tabTable -> {
String[] tabs = {"Textures", "Styles"};
for(int i = 0; i < tabs.length; i++) {
int j = i;
TextButton button = new TextButton(tabs[j], Styles.flatToggleMenut);
button.clicked(() -> {
currentTab = j;
button.toggle();
for(int elemI = 0; elemI < tabTable.getChildren().size; elemI++) {
((Button) tabTable.getChildren().get(elemI)).setChecked(currentTab == elemI);
}
refreshResourceTable();
});
tabTable.add(button).minHeight(50).grow();
}
}).grow().row();
t.table(tt -> tt.add(rebuildResourceList())).name("resource").grow();
}).grow();
}
void refreshResourceTable() {
Table resource = find("resource");
resource.clearChildren();
resource.add(rebuildResourceList());
}
float scrollY;
Table rebuildResourceList() {
return new Table(pane -> {
Cons[] builders = {
(Cons<Table>) ppane -> {
ppane.table(options -> {
options.top().left();
options.check("show resource with its name", showName, (checkBox) -> {
showName = !showName;
refreshResourceTable();
}).grow();
}).padBottom(20f).growX().row();
ScrollPane contentPane = new ScrollPane(new Table(content -> {
buildTitle(content, "Texture Resources").row();
buildTexResources(content).row();
buildTitle(content, "Icon Resources").row();
buildIconResources(content);
}));
contentPane.scrolled(y -> {
scrollY = contentPane.getScrollY();
});
contentPane.layout();
contentPane.setScrollY(scrollY);
ppane.add(contentPane).grow();
},
(Cons<Table>) ppane -> {
buildTitle(ppane, "Styles Resources").row();
ppane.pane(this::buildStyleResources).scrollX(true);
}
};
pane.table(ppane -> {
ppane.left().top();
buildTitle(ppane, "Texture Resources").row();
buildTexResources(ppane).row();
buildTitle(ppane, "Icon Resources").row();
buildIconResources(ppane);
}).grow().row();
pane.table(stylePane -> {
stylePane.left();
buildTitle(stylePane, "Styles Resources").row();
stylePane.pane(this::buildStyleResources).scrollX(true);
builders[currentTab].get(ppane);
}).grow();
});
}
Table buildTitle(Table table, String title) {
table.table(Tex.underline2, tex -> tex.add(title)).pad(30f, 0f, 30f, 0f).left();
return table;
}
@@ -118,7 +151,7 @@ public class ResourcePreviewDialog extends BaseDialog {
: "<empty>"
)
.color(value != null
? value.toString().matches("/[a-f|A-F|0-9]{8}/")
? value.toString().matches("/[a-f0-9]{8}/gi") //TODO - 이거 왜 안먹힘
? Color.valueOf(value.toString())
: Color.white
: Color.gray
@@ -145,8 +178,8 @@ public class ResourcePreviewDialog extends BaseDialog {
Table buildIconResources(Table table) {
int i = 0;
for(ObjectMap.Entry<String, TextureRegionDrawable> entry : Icon.icons.entries()) {
addResourceImage(table, entry.value, entry.key);
if(++i % (15 * (showName ? 0.5f : 1)) == 0) table.row();
addResourceImage(table, entry.value, entry.key, 0);
if(++i % 15 == 0) table.row();
}
return table;
}
@@ -156,8 +189,8 @@ public class ResourcePreviewDialog extends BaseDialog {
for(int i = 0; i < fields.length;) {
try {
Field field = fields[i];
addResourceImage(table, (Drawable) field.get(null), field.getName());
if(++i % (15 * (showName ? 0.5f : 1)) == 0) table.row();
addResourceImage(table, (Drawable) field.get(null), field.getName(), i);
if(++i % 15 == 0) table.row();
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
@@ -165,14 +198,30 @@ public class ResourcePreviewDialog extends BaseDialog {
return table;
}
void addResourceImage(Table table, Drawable res, String name) {
void addResourceImage(Table table, Drawable res, String name, int i) {
table.table(t -> {
t.center();
t.image(res).scaling(Scaling.bounded);
t.center().defaults();
Image image = new Image(res).setScaling(Scaling.bounded);
Label label = new Label(name);
label.setWidth(100);
label.setFontScale(0.75f);
label.setAlignment(Align.center);
if(showName) {
t.row();
t.add(name);
t.stack(
new Table(tt -> {
tt.center();
tt.add(image).size(100);
}),
new Table(tt -> {
tt.center();
tt.addChild(label);
label.setPosition(t.x + t.getWidth() / 2, label.y + (name.length() >= 13 && i % 2 == 0 ? -label.getHeight() * 0.9f : 0));
tt.pack();
})
).center().maxSize(100);
}
}).maxSize(100).pad(10).tooltip(name);
else t.add(image).size(100);
}).size(100).pad(10).tooltip(name);
}
}