From 82f77ed6eed520dabd8c7df619b005915c928daf Mon Sep 17 00:00:00 2001 From: sharlotte Date: Mon, 20 Sep 2021 12:23:33 +0900 Subject: [PATCH] schem list --- src/UnitInfo/core/HudUi.java | 111 ++++++++++++++++++++++++++++++-- src/UnitInfo/core/Main.java | 1 + src/UnitInfo/core/SettingS.java | 2 +- 3 files changed, 106 insertions(+), 8 deletions(-) diff --git a/src/UnitInfo/core/HudUi.java b/src/UnitInfo/core/HudUi.java index ee52047..cec2f3d 100644 --- a/src/UnitInfo/core/HudUi.java +++ b/src/UnitInfo/core/HudUi.java @@ -1,5 +1,6 @@ package UnitInfo.core; +import UnitInfo.SUtils; import UnitInfo.ui.*; import arc.*; import arc.graphics.*; @@ -27,6 +28,7 @@ import mindustry.input.*; import mindustry.logic.Ranged; import mindustry.type.*; import mindustry.ui.*; +import mindustry.ui.dialogs.SchematicsDialog; import mindustry.world.*; import mindustry.world.blocks.*; import mindustry.world.blocks.defense.*; @@ -38,6 +40,8 @@ import mindustry.world.blocks.production.*; import mindustry.world.blocks.storage.*; import mindustry.world.blocks.units.*; +import java.util.regex.Pattern; + import static UnitInfo.SVars.*; import static arc.Core.*; import static mindustry.Vars.*; @@ -51,16 +55,20 @@ public class HudUi { Table waveTable = new Table(); Table itemTable = new Table(); Table waveInfoTable = new Table(); + Table schemListTable = new Table(); + Table notifs = new Table(); float waveScrollPos; float itemScrollPos; float weaponScrollPos; + float schemScrollPos; Teamc shotTarget; Teamc lockedTarget; ImageButton lockButton; boolean locked = false; - boolean waveShown; + boolean waveShown, schemShown; + private Schematic firstSchematic; float a; int uiIndex = 0; @@ -247,6 +255,100 @@ public class HudUi { }); } + public void addSchemTable() { + schemListTable = new Table(table -> { + table.right(); + table.button("Schemtic List", Icon.downOpen, Styles.squareTogglet, () -> { + schemShown = !schemShown; + rebuildList(); + }).width(160f).height(60f) + .checked(b -> { + Image image = (Image)b.getCells().first().get(); + image.setDrawable(schemShown ? Icon.upOpen : Icon.downOpen); + return schemShown; + }).row(); + table.collapser(t -> { + t.background(Styles.black8); + notifs = t; + rebuildList(); + }, true, () -> schemShown); + + }); + + Table table = (Table) scene.find("minimap/position"); + table.row(); + table.add(schemListTable); + } + + public void rebuildList() { + if(notifs == null) return; + + notifs.clear(); + notifs.defaults().maxHeight(72 * 8f); + ScrollPane pane = notifs.pane(Styles.nonePane, p -> { + firstSchematic = null; + + for(Schematic s : schematics.all()){ + //make sure *tags* fit + Seq seq = null; + try { + seq = (Seq) SUtils.invoke(ui.schematics, "selectedTags"); + } catch (IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } + if(seq != null && seq.any() && !s.labels.containsAll(seq)) continue; + if(firstSchematic == null) firstSchematic = s; + + Button[] sel = {null}; + sel[0] = p.button(b -> { + b.top(); + b.margin(0f); + b.stack(new SchematicsDialog.SchematicImage(s).setScaling(Scaling.fit), new Table(n -> { + n.top(); + n.table(Styles.black3, c -> { + Label label = c.add(s.name()).style(Styles.outlineLabel).color(Color.white).top().growX().maxWidth(200f - 8f).get(); + label.setEllipsis(true); + label.setAlignment(Align.center); + }).growX().margin(1).pad(4).maxWidth(Scl.scl(160f - 8f)).padBottom(0); + })).size(160f); + }, () -> { + if(sel[0].childrenPressed()) return; + if(state.isMenu()){ + try { + ((SchematicsDialog.SchematicInfoDialog)SUtils.invoke(ui.schematics, "info")).show(s); + } catch (IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } + }else{ + if(!Vars.state.rules.schematicsAllowed){ + ui.showInfo("@schematic.disabled"); + }else{ + control.input.useSchematic(s); + } + } + }).pad(4).style(Styles.cleari).get(); + + sel[0].getStyle().up = Tex.pane; + p.row(); + } + + if(firstSchematic == null){ + p.add("@none"); + } + }).grow().get(); + + pane.update(() -> { + Element result = scene.hit(input.mouseX(), input.mouseY(), true); + if(pane.hasScroll() && (result == null || !result.isDescendantOf(pane))) + scene.setScrollFocus(null); + schemScrollPos = pane.getScrollY(); + }); + + pane.setOverscroll(false, false); + pane.setScrollingDisabled(true, false); + pane.setScrollYForce(schemScrollPos); + } + public void addWaveInfoTable() { waveInfoTable = new Table(Tex.buttonEdge4, t -> { t.defaults().width(34 * 8f).center(); @@ -345,8 +447,8 @@ public class HudUi { } }); baseTable = table.table(tt -> tt.stack(unitTable, waveTable, itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get(); - table.fillParent = true; + table.fillParent = true; table.visibility = () -> ui.hudfrag.shown && !ui.minimapfrag.shown(); }); ui.hudGroup.addChild(mainTable); @@ -656,11 +758,6 @@ public class HudUi { tt.add(button).size(Scl.scl(modUiScale) * 3 * 8f); tt.add(lockButton); - tt.clicked(()->{ - if(getTarget() == null) return; - if(control.input instanceof DesktopInput d) d.panning = true; - Core.camera.position.set(getTarget().x(), getTarget().y()); - }); tt.addListener(new Tooltip(tool -> tool.background(Tex.button).table(to -> { to.table(Tex.underline2, tool2 -> { Label label2 = new Label(()->{ diff --git a/src/UnitInfo/core/Main.java b/src/UnitInfo/core/Main.java index 9eeab2f..367f472 100644 --- a/src/UnitInfo/core/Main.java +++ b/src/UnitInfo/core/Main.java @@ -31,6 +31,7 @@ public class Main extends Mod { hud.addUnitTable(); hud.addTable(); hud.addWaveInfoTable(); + hud.addSchemTable(); hud.setEvents(); OverDrawer.setEvent(); if(jsonGen) ContentJSON.save(); diff --git a/src/UnitInfo/core/SettingS.java b/src/UnitInfo/core/SettingS.java index 797c7d6..bf7c9c2 100644 --- a/src/UnitInfo/core/SettingS.java +++ b/src/UnitInfo/core/SettingS.java @@ -116,7 +116,7 @@ public class SettingS { addGraphicCheckSetting("emptywave", true, tapSeq); Seq rangeSeq = new Seq<>(); - addGraphicTypeSetting("rangeRadius", 0, 500, 20, true, () -> true, s -> s + "tiles", rangeSeq); + addGraphicTypeSetting("rangeRadius", 0, 500, 70, true, () -> true, s -> s + "tiles", rangeSeq); addGraphicCheckSetting("rangeNearby", true, rangeSeq); addGraphicCheckSetting("allTeamRange", false, rangeSeq); addGraphicCheckSetting("allTargetRange", false, rangeSeq);