resource preview dialog seems hotter than i expected

This commit is contained in:
sharlottes
2022-11-26 11:42:20 +09:00
parent 4fd6d59753
commit 15e70821ce
12 changed files with 386 additions and 74 deletions

View File

@@ -1,15 +1,21 @@
package informatis;
import arc.input.KeyCode;
import arc.scene.ui.layout.Table;
import arc.util.Log;
import informatis.core.OverDrawer;
import informatis.core.Setting;
import informatis.draws.OverDraws;
import informatis.ui.SidebarSwitcher;
import informatis.ui.dialogs.DialogManager;
import informatis.ui.dialogs.ResourcePreviewDialog;
import informatis.ui.fragments.FragmentManager;
import informatis.ui.windows.*;
import arc.*;
import mindustry.*;
import mindustry.game.EventType.*;
import mindustry.gen.Icon;
import mindustry.gen.Tex;
import mindustry.mod.*;
import static arc.Core.*;
@@ -34,14 +40,21 @@ public class Informatis extends Mod {
});
Events.on(ClientLoadEvent.class, e -> {
Windows.load();
Setting.init();
WindowManager.init();
DialogManager.init();
new SidebarSwitcher(
WindowManager.body,
DialogManager.body,
new Table(Tex.buttonEdge4, t -> {
t.label(() -> "it's just label lmao");
})
).init();
FragmentManager.init();
OverDraws.init();
OverDrawer.init();
//TODO - SVars.init()?
SVars.pathfinder = new informatis.core.Pathfinder();
});
}

View File

@@ -0,0 +1,88 @@
package informatis.ui;
import arc.*;
import arc.math.*;
import arc.scene.*;
import arc.scene.actions.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.gen.*;
import mindustry.ui.*;
public class SidebarSwitcher {
int showIndex = 0;
final Element[] sidebars;
public SidebarSwitcher(Element ...sidebars) {
this.sidebars = sidebars;
}
void actShowMoveX(Element element, float from, float to) {
MoveToAction moveToAction = new MoveToAction();
moveToAction.setDuration(1);
moveToAction.setX(to);
moveToAction.setInterpolation(Interp.circleOut);
VisibleAction visibleAction = new VisibleAction();
visibleAction.setVisible(to >= 0);
element.setPosition(from, element.y);
if(to >= 0) element.actions(visibleAction, moveToAction);
else element.actions(moveToAction, visibleAction);
element.act(Core.graphics.getDeltaTime());
element.draw();
}
void actResizeWidth(Element element, float width) {
SizeToAction sizeToAction = new SizeToAction();
sizeToAction.setSize(width, element.getHeight());
sizeToAction.setDuration(1);
sizeToAction.setInterpolation(Interp.circleOut);
element.actions(sizeToAction);
element.act(Core.graphics.getDeltaTime());
element.draw();
}
public void init() {
Vars.ui.hudGroup.fill(t -> {
t.name = "informatis sidebar";
t.center().left();
t.table(body -> {
ImageButton button = new ImageButton();
button.clicked(() -> {
SnapshotSeq<Element> children = ((Group) body.getChildren().first()).getChildren();
Element currentSidebar = children.get(showIndex);
showIndex = (showIndex + 1) % children.size;
Element nextSidebar = children.get(showIndex);
actShowMoveX(currentSidebar, 0, -currentSidebar.getWidth());
actShowMoveX(nextSidebar, -nextSidebar.getWidth(),0);
actResizeWidth(button, nextSidebar.getWidth());
button.setDisabled(true);
Time.run(60, () -> button.setDisabled(false));
});
ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
style.up = Tex.buttonEdge4;
style.imageUp = Icon.right;
button.setStyle(style);
button.setWidth(sidebars[0].getWidth());
body.top().left()
.defaults().growY();
body.table(sides -> {
sides.top().left().defaults().growY();
for(int i = 0; i < sidebars.length; i++) {
Element elem = sidebars[i];
if(elem instanceof Table table) table.setBackground(Tex.buttonEdge3);
sides.add(elem).visible(i == 0);
}
}).row();
body.add(button).growX();
});
});
}
}

View File

@@ -0,0 +1,20 @@
package informatis.ui.dialogs;
import arc.scene.ui.Dialog;
import arc.scene.ui.layout.Table;
import mindustry.gen.Icon;
public class DialogManager {
public static Dialog resourcePreview;
public static Table body;
public static void init() {
resourcePreview = new ResourcePreviewDialog();
body = new Table(t -> {
t.button(Icon.file, () -> {
resourcePreview.show();
});
});
}
}

View File

@@ -0,0 +1,178 @@
package informatis.ui.dialogs;
import arc.Core;
import arc.func.Cons;
import arc.graphics.Color;
import arc.graphics.g2d.Font;
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.Scaling;
import mindustry.gen.Icon;
import mindustry.gen.Tex;
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;
public ResourcePreviewDialog() {
super("resource previews");
setFillParent(true);
addCloseButton();
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();
}).grow();
}
Table rebuildResourceList() {
return new Table(pane -> {
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);
}).grow();
});
}
Table buildTitle(Table table, String title) {
table.table(Tex.underline2, tex -> tex.add(title)).pad(30f, 0f, 30f, 0f).left();
return table;
}
Table buildStyleResources(Table table) {
Cons<Class<?>> build = classz -> {
String[] spliten = classz.getName().split("\\$");
buildTitle(table, spliten[spliten.length - 1]).marginLeft(20f).row();
table.table(t -> {
t.top().left().defaults().center().maxHeight(50).pad(10).grow();
if(classz.equals(Drawable.class)) {
for(Field field : Styles.class.getFields()) {
if (!field.getType().equals(Drawable.class)) continue;
t.table(tt -> {
tt.left();
try {
tt.add(field.getName());
tt.image((Drawable) field.get(null)).padLeft(40f);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}).growX().left().row();
}
t.row();
return;
}
t.add("\\");
Seq<Field> styles = Seq.with(classz.getFields());
styles.each(style -> t.add(style.getName()));
t.row();
for(Field field : Styles.class.getFields()) {
if(!field.getType().equals(classz)) continue;
t.add(field.getName());
try {
Object style = field.get(null);
styles.each(styleField -> {
styleField.setAccessible(true);
try {
Object value = styleField.get(style);
if(value instanceof Drawable drawable) t.image(drawable);
else t
.add(value != null
? value instanceof Font font
? font.getData().toString()
: value.toString()
: "<empty>"
)
.color(value != null
? value.toString().matches("/[a-f|A-F|0-9]{8}/")
? Color.valueOf(value.toString())
: Color.white
: Color.gray
);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
});
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
t.row();
}
}).grow().row();
};
build.get(Drawable.class);
build.get(Button.ButtonStyle.class);
build.get(TextButton.TextButtonStyle.class);
build.get(ImageButton.ImageButtonStyle.class);
return table;
}
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();
}
return table;
}
Table buildTexResources(Table table) {
Field[] fields = Tex.class.getDeclaredFields();
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();
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return table;
}
void addResourceImage(Table table, Drawable res, String name) {
table.table(t -> {
t.center();
t.image(res).scaling(Scaling.bounded);
if(showName) {
t.row();
t.add(name);
}
}).maxSize(100).pad(10).tooltip(name);
}
}

View File

@@ -49,7 +49,7 @@ public class CoreWindow extends Window {
}
@Override
public void build(Table table) {
public void buildBody(Table table) {
window = table;
scrollPos = new Vec2(0, 0);

View File

@@ -118,7 +118,7 @@ public class MapEditorWindow extends Window {
if(heat >= 60f) {
heat = 0f;
if(lastw != window.getWidth() || lasth != window.getHeight()) resetPane();
if(lastw != getWidth() || lasth != getHeight()) resetPane();
lastw = width;
lasth = height;
}
@@ -142,11 +142,10 @@ public class MapEditorWindow extends Window {
}
@Override
public void build(Table table) {
public void buildBody(Table table) {
scrollPos = new Vec2(0, 0);
search = Elem.newField(null, f->{});
search.setMessageText(Core.bundle.get("players.search")+"...");
window = table;
table.left();
table.top().background(Styles.black8);
@@ -368,7 +367,7 @@ public class MapEditorWindow extends Window {
float teamScroll;
float getDisplayWidth() {
return window.getWidth() - (window.find("buttons") == null ? 1 : window.find("buttons").getWidth());
return getWidth() - (find("buttons") == null ? 1 : find("buttons").getWidth());
}
public void drawBlocksReplace(int x, int y){

View File

@@ -44,7 +44,7 @@ public class PlayerWindow extends Window {
}
@Override
public void build(Table table) {
public void buildBody(Table table) {
scrollPos = new Vec2(0, 0);
search = Elem.newField(null, f->{});
search.setMessageText(Core.bundle.get("players.search"));

View File

@@ -37,7 +37,7 @@ public class ToolWindow extends Window {
}
@Override
public void build(Table table) {
public void buildBody(Table table) {
scrollPos = new Vec2(0, 0);
table.background(Styles.black8)

View File

@@ -62,6 +62,11 @@ public class UnitWindow extends Window {
public UnitWindow() {
super(Icon.units, "unit");
currentWindow = this;
}
@Override
public void build() {
super.build();
Element titlePane = ((Table) ((ScrollPane) ((Table) getChildren().first()).getChildren().first()).getWidget()).getChildren().first();
titlePane.update(() -> titlePane.setColor(currentWindow == this ? Pal.accent : Color.white));
Events.run(EventType.Trigger.update, () -> {
@@ -76,7 +81,7 @@ public class UnitWindow extends Window {
}
@Override
protected void build(Table table) {
protected void buildBody(Table table) {
Image profileImage = new Image() {
final int size = 8;
@Override
@@ -192,9 +197,9 @@ public class UnitWindow extends Window {
return;
}
if(usedPayload == payloader.payloadUsed() && lastWidth == window.getWidth()) return;
if(usedPayload == payloader.payloadUsed() && lastWidth == getWidth()) return;
if(usedPayload != payloader.payloadUsed()) usedPayload = payloader.payloadUsed();
if(lastWidth != window.getWidth()) lastWidth = window.getWidth();
if(lastWidth != getWidth()) lastWidth = getWidth();
t.clear();
t.top().left();
@@ -206,7 +211,7 @@ public class UnitWindow extends Window {
image.hovered(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.lightGray, Mathf.clamp(Time.delta))));
image.exited(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.white, Mathf.clamp(Time.delta))));
t.add(image).size(iconSmall).tooltip(l -> l.label(() -> payload.content().localizedName).style(Styles.outlineLabel));
if ((i + 1) % Math.max(6, Math.round((window.getWidth() - 24) / iconSmall)) == 0) t.row();
if ((i + 1) % Math.max(6, Math.round((getWidth() - 24) / iconSmall)) == 0) t.row();
}
});
@@ -218,9 +223,9 @@ public class UnitWindow extends Window {
}
Bits applied = st.statusBits();
if((applied == null || statuses.equals(st.statusBits())) && lastWidth == window.getWidth()) return;
if((applied == null || statuses.equals(st.statusBits())) && lastWidth == getWidth()) return;
if(!statuses.equals(st.statusBits())) statuses.set(applied);
if(lastWidth != window.getWidth()) lastWidth = window.getWidth();
if(lastWidth != getWidth()) lastWidth = getWidth();
t.clear();
t.top().left();
@@ -233,7 +238,7 @@ public class UnitWindow extends Window {
image.hovered(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.lightGray, Mathf.clamp(Time.delta))));
image.exited(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.white, Mathf.clamp(Time.delta))));
t.add(image).size(iconSmall).tooltip(l -> l.label(() -> effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel));
if (i + 1 % Math.max(6, Math.round((window.getWidth() - 24) / iconSmall)) == 0) t.row();
if (i + 1 % Math.max(6, Math.round((getWidth() - 24) / iconSmall)) == 0) t.row();
}
}
});

View File

@@ -42,7 +42,7 @@ public class WaveWindow extends Window {
}
@Override
public void build(Table table) {
public void buildBody(Table table) {
table.top().background(Styles.black8);
ScrollPane pane = new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false);
table.add(pane).grow().name("wave-pane").row();
@@ -64,7 +64,7 @@ public class WaveWindow extends Window {
}
int row = 0;
int max = Math.max(1, Math.round(window.getWidth()/2/8/2));
int max = Math.max(1, Math.round(getWidth()/2/8/2));
for (UnitType unit : Vars.content.units()) {
int amount = Groups.unit.count(u->u.type==unit&&u.team==state.rules.waveTeam);
if(amount<=0) continue;
@@ -154,7 +154,7 @@ public class WaveWindow extends Window {
ObjectIntMap<SpawnGroup> groups = getWaveGroup(index-1);
int row = 0;
int max = Math.max(1, Math.round(window.getWidth()/64)-5);
int max = Math.max(1, Math.round(getWidth()/64)-5);
for (SpawnGroup group : groups.keys()) {
int spawners = state.rules.waveTeam.cores().size + (group.type.flying ? spawner.countFlyerSpawns() : spawner.countGroundSpawns());
int amount = groups.get(group);

View File

@@ -3,11 +3,10 @@ package informatis.ui.windows;
import arc.*;
import arc.func.*;
import arc.input.*;
import arc.math.Mathf;
import arc.math.geom.*;
import arc.scene.Element;
import arc.scene.event.*;
import arc.scene.style.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.gen.*;
@@ -17,65 +16,61 @@ public class Window extends Table {
public TextureRegionDrawable icon;
public Cons<Table> content;
public boolean shown = false, only = false;
public Table window;
public float minWindowWidth = 160, minWindowHeight = 60;
public float maxWindowWidth = Float.MAX_VALUE, maxWindowHeight = Float.MAX_VALUE;
float topBarHeight = 48f;
public Window(String name){
this(new TextureRegionDrawable(Core.atlas.find("clear")), name, null);
}
public Window(TextureRegionDrawable icon, String name){
this(icon, name, null);
}
public Window(TextureRegionDrawable icon, String name, Cons<Table> content){
this.content = content;
this.name = name;
public Window(TextureRegionDrawable icon, String name, Cons<Table> content) {
this.icon = icon;
window = this;
this.name = name;
this.content = content;
WindowManager.register(this);
}
titleBar();
row();
ScrollPane pane = new ScrollPane(new Table(t -> {
public void build() {
buildTitleBar().row();
pane(new Table(t -> {
t.setBackground(Styles.black5);
t.top().left();
build(t);
}), Styles.noBarPane);
pane.update(() -> {
if(pane.hasScroll()){
Element result = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
if(result == null || !result.isDescendantOf(pane)){
Core.scene.setScrollFocus(null);
}
}
});
pane.setScrollingDisabled(true, true);
add(pane).grow();
row();
bottomBar();
buildBody(t);
}))
.grow()
.row();
buildBottomBar();
visible(() -> shown);
update(() -> setPosition(
Math.max(0, Math.min(Core.graphics.getWidth() - getWidth(), x)),
Math.max(topBarHeight - getHeight(), Math.min(Core.graphics.getHeight() - getHeight(), y))
));
update(() -> {
setPosition(
Mathf.clamp(x, 0, Core.graphics.getWidth() - getWidth()),
Mathf.clamp(y, 0, Core.graphics.getHeight() - getHeight())
);
});
}
protected void build(Table t){
if(content != null) content.get(t);
}
protected void titleBar(){
protected Window buildTitleBar() {
table(t -> {
t.pane(b -> {
b.left();
b.setBackground(Tex.buttonEdge1);
b.image(icon.getRegion()).size(20f).padLeft(15);
b.add(Core.bundle.get("window."+name+".name")).padLeft(20);
}).touchable(Touchable.disabled).grow();
t.table(Tex.buttonEdge3, b -> b.button(Icon.cancel, Styles.emptyi, () -> {
shown = false;
if(!only) WindowManager.windows.get(getClass()).remove(this);
}).fill()).width(80f).growY();
})
.touchable(Touchable.disabled)
.grow();
t.table(b -> {
b.setBackground(Tex.buttonEdge3);
b.button(Icon.cancel, Styles.emptyi, () -> {
shown = false;
if(!only) WindowManager.windows.get(getClass()).remove(this);
}).fill();
})
.width(80f)
.growY();
// handles the dragging.
t.touchable = Touchable.enabled;
@@ -98,10 +93,16 @@ public class Window extends Table {
lastY = v.y;
}
});
}).height(topBarHeight).growX();
}).height(48f).growX();
return this;
}
protected void bottomBar(){
protected void buildBody(Table t){
if(content != null) content.get(t);
}
protected Window buildBottomBar() {
table(Styles.black5, t -> {
t.table().growX();
t.table(Icon.resizeSmall, r -> {
@@ -135,11 +136,11 @@ public class Window extends Table {
});
}).size(20f).left();
}).height(20f).growX();
return this;
}
public void toggle(){
shown = !shown;
}
public void update() { }
}

View File

@@ -3,6 +3,7 @@ package informatis.ui.windows;
import arc.*;
import arc.scene.ui.layout.Table;
import arc.struct.*;
import arc.util.Nullable;
import mindustry.*;
import mindustry.graphics.Pal;
import mindustry.ui.*;
@@ -11,8 +12,19 @@ import java.lang.reflect.InvocationTargetException;
public class WindowManager {
public static ObjectMap<Class<? extends Window>, Seq<Window>> windows = new ObjectMap<>();
@Nullable
/* WARNING: body field will be initialized before the client has been completely loaded. */
public static Table body;
public static void init(){
Windows.load();
for(Seq<Window> windows : windows.values()){
for(Window window : windows) {
window.build();
}
}
// windows place for dragging
Vars.ui.hudGroup.fill(t -> {
t.name = "Windows";
@@ -23,18 +35,16 @@ public class WindowManager {
}
});
Vars.ui.hudGroup.fill(t -> {
t.name = "window sidebar";
t.center().left();
t.table(Core.atlas.drawable("informatis-sidebar"), b -> {
b.name = "Window Buttons";
b.left();
// windows sidebar -> will be moved to sidebar switch button
body = new Table(t -> {
t.name = "Window Buttons";
t.left();
for(ObjectMap.Entry<Class<? extends Window>, Seq<Window>> windows : windows){
Class<? extends Window> key = windows.key;
Seq<Window> value = windows.value;
Window window = value.peek();
b.stack(
t.stack(
new Table(bt -> {
bt.button(window.icon, Styles.emptyi, () -> {
Window window1 = window;
@@ -65,12 +75,10 @@ public class WindowManager {
).row();
}
}).left();
});
}
public static void register(Window window){
Table table = Vars.ui.hudGroup.find("Windows");
if(table != null) table.add(window).height(window.getHeight()).width(window.getWidth());
if(!windows.containsKey(window.getClass())) windows.put(window.getClass(), Seq.with(window));
else windows.get(window.getClass()).add(window);
}