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

@@ -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);
}