mirror of
https://github.com/yawaflua/Informatis.git
synced 2026-02-04 10:24:21 +02:00
resource display navbar
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
package informatis.ui.dialogs;
|
package informatis.ui.dialogs;
|
||||||
|
|
||||||
import arc.Core;
|
|
||||||
import arc.func.Cons;
|
import arc.func.Cons;
|
||||||
import arc.graphics.Color;
|
import arc.graphics.Color;
|
||||||
import arc.graphics.g2d.Font;
|
import arc.graphics.g2d.Font;
|
||||||
|
import arc.scene.Element;
|
||||||
import arc.scene.style.Drawable;
|
import arc.scene.style.Drawable;
|
||||||
import arc.scene.style.Style;
|
|
||||||
import arc.scene.style.TextureRegionDrawable;
|
import arc.scene.style.TextureRegionDrawable;
|
||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.struct.ObjectMap;
|
import arc.struct.ObjectMap;
|
||||||
import arc.struct.Seq;
|
import arc.struct.Seq;
|
||||||
|
import arc.util.Align;
|
||||||
|
import arc.util.Log;
|
||||||
import arc.util.Scaling;
|
import arc.util.Scaling;
|
||||||
import mindustry.gen.Icon;
|
import mindustry.gen.Icon;
|
||||||
import mindustry.gen.Tex;
|
import mindustry.gen.Tex;
|
||||||
@@ -18,11 +19,11 @@ import mindustry.ui.Styles;
|
|||||||
import mindustry.ui.dialogs.*;
|
import mindustry.ui.dialogs.*;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
|
|
||||||
public class ResourcePreviewDialog extends BaseDialog {
|
public class ResourcePreviewDialog extends BaseDialog {
|
||||||
boolean showName = false;
|
boolean showName = false;
|
||||||
|
int currentTab = 0;
|
||||||
|
|
||||||
public ResourcePreviewDialog() {
|
public ResourcePreviewDialog() {
|
||||||
super("resource previews");
|
super("resource previews");
|
||||||
@@ -31,40 +32,72 @@ public class ResourcePreviewDialog extends BaseDialog {
|
|||||||
|
|
||||||
cont.table(t -> {
|
cont.table(t -> {
|
||||||
t.top().center();
|
t.top().center();
|
||||||
|
t.table(Tex.underline, tabTable -> {
|
||||||
t.table(Tex.underline, options -> {
|
String[] tabs = {"Textures", "Styles"};
|
||||||
options.top().center();
|
for(int i = 0; i < tabs.length; i++) {
|
||||||
CheckBox box = new CheckBox("show resource with its name");
|
int j = i;
|
||||||
box.changed(() -> {
|
TextButton button = new TextButton(tabs[j], Styles.flatToggleMenut);
|
||||||
showName = !showName;
|
button.clicked(() -> {
|
||||||
((ScrollPane) find("resource-pane")).setWidget(rebuildResourceList());
|
currentTab = j;
|
||||||
});
|
button.toggle();
|
||||||
options.add(box);
|
for(int elemI = 0; elemI < tabTable.getChildren().size; elemI++) {
|
||||||
}).padBottom(50f).growX().row();
|
((Button) tabTable.getChildren().get(elemI)).setChecked(currentTab == elemI);
|
||||||
|
}
|
||||||
t.pane(rebuildResourceList()).name("resource-pane").grow();
|
refreshResourceTable();
|
||||||
|
});
|
||||||
|
tabTable.add(button).minHeight(50).grow();
|
||||||
|
}
|
||||||
|
}).grow().row();
|
||||||
|
t.table(tt -> tt.add(rebuildResourceList())).name("resource").grow();
|
||||||
}).grow();
|
}).grow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refreshResourceTable() {
|
||||||
|
Table resource = find("resource");
|
||||||
|
resource.clearChildren();
|
||||||
|
resource.add(rebuildResourceList());
|
||||||
|
}
|
||||||
|
|
||||||
|
float scrollY;
|
||||||
Table rebuildResourceList() {
|
Table rebuildResourceList() {
|
||||||
return new Table(pane -> {
|
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 -> {
|
pane.table(ppane -> {
|
||||||
ppane.left().top();
|
ppane.left().top();
|
||||||
buildTitle(ppane, "Texture Resources").row();
|
builders[currentTab].get(ppane);
|
||||||
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);
|
|
||||||
}).grow();
|
}).grow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Table buildTitle(Table table, String title) {
|
Table buildTitle(Table table, String title) {
|
||||||
table.table(Tex.underline2, tex -> tex.add(title)).pad(30f, 0f, 30f, 0f).left();
|
table.table(Tex.underline2, tex -> tex.add(title)).pad(30f, 0f, 30f, 0f).left();
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +151,7 @@ public class ResourcePreviewDialog extends BaseDialog {
|
|||||||
: "<empty>"
|
: "<empty>"
|
||||||
)
|
)
|
||||||
.color(value != null
|
.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.valueOf(value.toString())
|
||||||
: Color.white
|
: Color.white
|
||||||
: Color.gray
|
: Color.gray
|
||||||
@@ -145,8 +178,8 @@ public class ResourcePreviewDialog extends BaseDialog {
|
|||||||
Table buildIconResources(Table table) {
|
Table buildIconResources(Table table) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(ObjectMap.Entry<String, TextureRegionDrawable> entry : Icon.icons.entries()) {
|
for(ObjectMap.Entry<String, TextureRegionDrawable> entry : Icon.icons.entries()) {
|
||||||
addResourceImage(table, entry.value, entry.key);
|
addResourceImage(table, entry.value, entry.key, 0);
|
||||||
if(++i % (15 * (showName ? 0.5f : 1)) == 0) table.row();
|
if(++i % 15 == 0) table.row();
|
||||||
}
|
}
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
@@ -156,8 +189,8 @@ public class ResourcePreviewDialog extends BaseDialog {
|
|||||||
for(int i = 0; i < fields.length;) {
|
for(int i = 0; i < fields.length;) {
|
||||||
try {
|
try {
|
||||||
Field field = fields[i];
|
Field field = fields[i];
|
||||||
addResourceImage(table, (Drawable) field.get(null), field.getName());
|
addResourceImage(table, (Drawable) field.get(null), field.getName(), i);
|
||||||
if(++i % (15 * (showName ? 0.5f : 1)) == 0) table.row();
|
if(++i % 15 == 0) table.row();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -165,14 +198,30 @@ public class ResourcePreviewDialog extends BaseDialog {
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addResourceImage(Table table, Drawable res, String name) {
|
void addResourceImage(Table table, Drawable res, String name, int i) {
|
||||||
table.table(t -> {
|
table.table(t -> {
|
||||||
t.center();
|
t.center().defaults();
|
||||||
t.image(res).scaling(Scaling.bounded);
|
|
||||||
|
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) {
|
if(showName) {
|
||||||
t.row();
|
t.stack(
|
||||||
t.add(name);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user