rename package

This commit is contained in:
sharlottes
2022-05-22 23:58:18 +09:00
parent c94de34331
commit 45e7b84790
46 changed files with 272 additions and 257 deletions

View File

@@ -0,0 +1,28 @@
package informatis.ui;
import arc.scene.ui.layout.Table;
import arc.struct.Seq;
import informatis.ui.display.ElementDisplay;
import informatis.ui.display.SchemDisplay;
import informatis.ui.display.WaveInfoDisplay;
import static arc.Core.scene;
import static mindustry.Vars.ui;
public class DisplayManager {
public static void init() {
//layout debug
Seq.with(scene.root,
ui.picker, ui.editor, ui.controls, ui.restart, ui.join, ui.discord,
ui.load, ui.custom, ui.language, ui.database, ui.settings, ui.host,
ui.paused, ui.about, ui.bans, ui.admins, ui.traces, ui.maps, ui.content,
ui.planet, ui.research, ui.mods, ui.schematics, ui.logic
).each(dialog-> dialog.addChild(new ElementDisplay(dialog)));
//schem quick-slot
Table table = ((Table) scene.find("minimap/position")).row();
table.add(new SchemDisplay());
new WaveInfoDisplay().addWaveInfoTable();
}
}

View File

@@ -0,0 +1,118 @@
package informatis.ui;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.struct.*;
import mindustry.*;
import mindustry.entities.abilities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.blocks.payloads.Payload;
import static arc.Core.*;
import static mindustry.Vars.*;
public class FreeBar {
public static void draw(Unit unit){
if(unit.dead()) return;
Draw.z(Layer.flyingUnit + 1);
Bits statuses = new Bits();
Bits applied = unit.statusBits();
if(!statuses.equals(applied) && applied != null){
int i = 0;
int row = 0;
for(StatusEffect effect : content.statusEffects()){
if(applied.get(effect.id) && !effect.isHidden()){
Draw.rect(effect.uiIcon, unit.x - (unit.type.hitSize + 4)/2 + i * 4, unit.y - 4 + 4 * row, 4,4);
if(++i > 2 * (unit.type.hitSize + 4)) row++;
}
}
statuses.set(applied);
}
if(unit instanceof Payloadc payload && payload.payloads().any()){
int i = 0;
int row = 0;
for(Payload p : payload.payloads()){
Draw.rect(p.icon(), unit.x - (unit.type.hitSize + 4)/2 + i * 4, unit.y - 12 - 4 * row, 4,4);
if(++i > 2 * (unit.type.hitSize + 4)) row++;
}
}
Draw.color(0.1f, 0.1f, 0.1f, (settings.getInt("baropacity") / 100f));
float width = unit.type.hitSize + 4f;
float height = 2f;
float x = unit.x;
float y = unit.y - 8;
for(int i : Mathf.signs) {
for(int ii = 0; ii < 2; ii++){
float shadowx = x + ii * 0.25f;
float shadowy = y - ii * 0.5f;
Fill.poly(FloatSeq.with(
shadowx - (width / 2 + height), shadowy,
shadowx - width / 2, shadowy + i * height,
shadowx + width / 2, shadowy + i * height,
shadowx + (width / 2 + height), shadowy,
shadowx + width / 2, shadowy + i * -height,
shadowx - width / 2, shadowy + i * -height));
}
}
{
Draw.color(Pal.health.cpy().a((settings.getInt("baropacity") / 100f)));
float topWidth = - width / 2 + width * Mathf.clamp(unit.healthf());
float moser = topWidth + height;
if(unit.health <= 0) moser = (width / 2 + height) * (2 * Mathf.clamp(unit.healthf()) - 1);
for(int i : Mathf.signs) {
Fill.poly(FloatSeq.with(
x - (width / 2 + height), y,
x - width / 2, y + i * height,
x + topWidth, y + i * height,
x + moser, y,
x + topWidth, y + i * -height,
x - width / 2, y + i * -height));
}
}
if(Vars.state.rules.unitAmmo) {
float topWidth = - width / 2 + width * Mathf.clamp(unit.ammof());
float moser = topWidth + height;
if(unit.ammo <= 0) moser = (width / 2 + height) * (2 * Mathf.clamp(unit.ammof()) - 1);
Draw.color((unit.dead() || unit instanceof BlockUnitc ? Pal.ammo : unit.type.ammoType.color()).cpy().a((settings.getInt("baropacity") / 100f)));
Fill.poly(FloatSeq.with(
x - (width / 2 + height), y,
x - width / 2, y + height,
x + topWidth, y + height,
x + moser, y,
x + topWidth, y - height,
x - width / 2, y - height));
}
{
float max1 = ((ShieldRegenFieldAbility)content.units().copy().filter(ut -> ut.abilities.find(abil -> abil instanceof ShieldRegenFieldAbility) != null).sort(ut -> ((ShieldRegenFieldAbility)ut.abilities.find(abil -> abil instanceof ShieldRegenFieldAbility)).max).peek().abilities.find(abil -> abil instanceof ShieldRegenFieldAbility)).max;
float max2 = 0f;
if(unit.type.abilities.find(abil -> abil instanceof ForceFieldAbility) != null) max2 = ((ForceFieldAbility) unit.type.abilities.find(abil -> abil instanceof ForceFieldAbility)).max;
float max = Mathf.clamp(unit.shield / Math.max(max1, max2));
float topWidth = - width / 2 + width * max;
float moser = topWidth + height;
if(unit.shield <= 0) moser = (width / 2 + height) * (2 * max - 1);
Draw.color(Pal.surge.cpy().a((settings.getInt("baropacity") / 100f)));
Fill.poly(FloatSeq.with(
x - (width / 2 + height), y,
x - width / 2, y - height,
x + topWidth, y - height,
x + moser, y,
x + topWidth, y + height,
x - width / 2, y + height));
}
Draw.reset();
}
}

View File

@@ -0,0 +1,37 @@
package informatis.ui;
import arc.math.geom.Vec2;
import arc.scene.Element;
import arc.scene.ui.ScrollPane;
import static arc.Core.input;
import static arc.Core.scene;
public class OverScrollPane extends ScrollPane {
Vec2 scrollPos;
public OverScrollPane(Element widget, ScrollPaneStyle style, Vec2 scrollPos){
super(widget, style);
this.scrollPos = scrollPos;
update(() -> {
if (hasScroll()) {
Element result = scene.hit(input.mouseX(), input.mouseY(), true);
if (result == null || !result.isDescendantOf(this)) {
scene.setScrollFocus(null);
}
}
scrollPos.x = getScrollX();
scrollPos.y = getScrollY();
});
setOverscroll(false, false);
setScrollYForce(scrollPos.x);
setScrollYForce(scrollPos.y);
}
public OverScrollPane disableScroll(boolean x, boolean y) {
setScrollingDisabled(x, y);
return this;
}
}

142
src/informatis/ui/SBar.java Normal file
View File

@@ -0,0 +1,142 @@
package informatis.ui;
import informatis.SUtils;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.*;
import arc.scene.style.*;
import arc.util.Align;
import arc.util.Tmp;
import mindustry.graphics.*;
import mindustry.ui.Fonts;
public class SBar extends Element{
static final Rect scissor = new Rect();
Floatp fraction;
String name = "";
float value, lastValue, blink;
final Color blinkColor = new Color();
NinePatchDrawable bar, top;
float spriteWidth;
public boolean onedot = false;
public SBar(Prov<String> name, Prov<Color> color, Floatp fraction){
this.fraction = fraction;
try{
lastValue = value = Mathf.clamp(fraction.get());
}catch(Exception e){ //getting the fraction may involve referring to invalid data
lastValue = value = 0f;
}
update(() -> {
try{
this.name = name.get();
this.blinkColor.set(color.get());
setColor(color.get());
}catch(Exception e){ //getting the fraction may involve referring to invalid data
this.name = "";
}
});
init();
}
public SBar rect(){
onedot = true;
return this;
}
public SBar init(){
int h = Core.settings.getInt("barstyle");
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barS"), 10, 10, 9, 9);
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barS-top"), 10, 10, 9, 9);
spriteWidth = Core.atlas.find("informatis-barS").width;
if(onedot){
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-1dotbar"), 0,0,0,0);
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-1dotbar-top"),0,0,0,0);
spriteWidth = Core.atlas.find("informatis-1dotbar").width;
}
else if(h == 1){
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSS"), 14, 14, 19, 19);
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSS-top"), 14, 14, 19, 19);
spriteWidth = Core.atlas.find("informatis-barSS").width;
}
else if(h == 2){
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSS"), 25, 25, 17, 17);
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSS-top"), 25, 25, 17, 17);
spriteWidth = Core.atlas.find("informatis-barSSS").width;
}
else if(h == 3){
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSSS"), 25, 25, 17, 17);
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSSS-top"), 25, 25, 17, 17);
spriteWidth = Core.atlas.find("informatis-barSSSS").width;
}
else if(h == 4){
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSSSS"), 27, 27, 16, 16);
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSSSS-top"), 27, 27, 16, 16);
spriteWidth = Core.atlas.find("informatis-barSSSSS").width;
}
else if(h == 5){
bar = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSSSSS"), 32, 32, 16, 16);
top = (NinePatchDrawable) SUtils.getDrawable(Core.atlas.find("informatis-barSSSSSS-top"), 32, 32, 16, 16);
spriteWidth = Core.atlas.find("informatis-barSSSSSS").width;
}
return this;
}
@Override
public void draw(){
if(fraction == null) return;
float computed;
try{
computed = Mathf.clamp(fraction.get());
}catch(Exception e){ //getting the fraction may involve referring to invalid data
computed = 0f;
}
if(lastValue > computed){
blink = 1f;
lastValue = computed;
}
if(Float.isNaN(lastValue)) lastValue = 0;
if(Float.isInfinite(lastValue)) lastValue = 1f;
if(Float.isNaN(value)) value = 0;
if(Float.isInfinite(value)) value = 1f;
if(Float.isNaN(computed)) computed = 0;
if(Float.isInfinite(computed)) computed = 1f;
blink = Mathf.lerpDelta(blink, 0f, 0.2f);
value = Mathf.lerpDelta(value, computed, 0.05f);
Draw.colorl(0.1f);
bar.draw(x, y, width, height);
Draw.color(Tmp.c1.set(color).mul(Pal.lightishGray), blinkColor, blink);
float topWidth = width * value;
if(topWidth > spriteWidth){
top.draw(x, y, topWidth, height);
} else if(ScissorStack.push(scissor.set(x, y, topWidth, height))){
top.draw(x, y, spriteWidth, height);
ScissorStack.pop();
}
Draw.color(color, blinkColor, blink);
float topWidthReal = width * Math.min(value, computed);
if(topWidthReal > spriteWidth){
top.draw(x, y, topWidthReal, height);
} else if(ScissorStack.push(scissor.set(x, y, topWidthReal, height))){
top.draw(x, y, spriteWidth, height);
ScissorStack.pop();
}
Fonts.outline.draw(name, x + width / 2f, y + height * 0.75f, Color.white, 1, false, Align.center);
}
}

View File

@@ -0,0 +1,14 @@
package informatis.ui;
import arc.Core;
import arc.graphics.g2d.TextureRegion;
public class SIcons {
public static TextureRegion health = Core.atlas.find("informatis-health");
public static TextureRegion shield = Core.atlas.find("informatis-shield");
public static TextureRegion item = Core.atlas.find("informatis-item");
public static TextureRegion liquid = Core.atlas.find("informatis-liquid");
public static TextureRegion power = Core.atlas.find("informatis-power");
public static TextureRegion ammo = Core.atlas.find("informatis-ammo");
public static TextureRegion reload = Core.atlas.find("informatis-reload");
}

View File

@@ -0,0 +1,5 @@
package informatis.ui;
public interface Updatable {
void update();
}

View File

@@ -0,0 +1,56 @@
package informatis.ui;
import arc.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.ui.*;
import informatis.ui.window.Window;
public class WindowManager {
public static Seq<Window> windows = new Seq<>();
public static void init(){
Log.info(windows.size);
Vars.ui.hudGroup.fill(t -> {
t.name = "Windows";
for(Window window : windows){
t.add(window);
}
});
Vars.ui.hudGroup.fill(t -> {
t.center().left();
t.table(Core.atlas.drawable("informatis-sidebar"), b -> {
b.name = "Window Buttons";
b.left();
for(Window window : windows){
b.button(window.icon, Styles.emptyi, () -> {
window.toggle();
// Disabling the parent's layout fixes issues with updating elements inside windows.
// However, it also disables the layout of all its children, so we need to re-enable them.
window.parent.setLayoutEnabled(false);
window.setLayoutEnabled(true);
for(Window w : windows){
w.setLayoutEnabled(true);
}
}).disabled(window.shown)
.size(40f)
.tooltip(tt -> {
tt.setBackground(Styles.black6);
tt.label(() -> Core.bundle.get("window."+window.name+".name")).pad(2f);
});
b.row();
}
}).left();
});
}
public static int register(Window window){
windows.add(window);
return windows.size - 1;
}
}

View File

@@ -0,0 +1,61 @@
package informatis.ui.display;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Lines;
import arc.scene.Element;
import arc.scene.Group;
import arc.scene.event.Touchable;
import arc.struct.SnapshotSeq;
import arc.util.Tmp;
import mindustry.graphics.Layer;
import mindustry.graphics.Pal;
import static arc.Core.scene;
import static arc.Core.settings;
public class ElementDisplay extends Element {
Group root;
public ElementDisplay() {
this(scene.root);
}
public ElementDisplay(Group root) {
this.root = root;
fillParent = true;
touchable = Touchable.disabled;
}
@Override
public void draw() {
super.draw();
if(!settings.getBool("elementdebug")) return;
Draw.z(Layer.max);
Lines.stroke(1);
addRect(root.getChildren());
}
void addRect(SnapshotSeq<Element> elements) {
elements.each(elem-> {
elem.updateVisibility();
if(elem.visible || settings.getBool("hiddenElem")) {
elem.localToStageCoordinates(Tmp.v1.set(0, 0));
if(elem.hasMouse()) {
Draw.color(Pal.accent);
Lines.stroke(3);
}
if(elem.hasScroll()) {
Draw.color(Pal.lancerLaser);
Lines.stroke(3);
}
if(elem.hasKeyboard()) {
Draw.color(Pal.sap);
Lines.stroke(5);
}
Lines.rect(Tmp.v1.x, Tmp.v1.y, elem.getWidth(), elem.getHeight());
Draw.color();
Lines.stroke(1);
if(elem instanceof Group group) addRect(group.getChildren());
}
});
}
}

View File

@@ -0,0 +1,498 @@
package informatis.ui.display;
import informatis.SUtils;
import arc.Core;
import arc.func.Cons;
import arc.func.Floatf;
import arc.graphics.Color;
import arc.input.KeyCode;
import arc.scene.Element;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.scene.utils.Elem;
import arc.struct.Seq;
import arc.util.Align;
import arc.util.*;
import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.ui.Styles;
import mindustry.ui.dialogs.*;
import informatis.ui.Updatable;
import static arc.Core.*;
import static mindustry.Vars.*;
import static mindustry.Vars.ui;
public class SchemDisplay extends Table implements Updatable {
static float schemScrollPos, tagScrollPos;
static boolean schemShown;
static Schematic firstSchematic;
static final Seq<String> selectedTags = new Seq<>();
static Runnable rebuildList = () -> {};
float heat;
public SchemDisplay() {
setSchemTable();
}
@Override
public void update() {
heat += Time.delta;
if(heat>=60f) {
heat = 0;
setSchemTable();
}
}
public void setSchemTable() {
clear();
if(!settings.getBool(("schem"))) return;
right();
button(bundle.get("hud.schematic-list"), Icon.downOpen, Styles.squareTogglet, () -> schemShown = !schemShown).width(160f).height(60f).checked(b -> {
Image image = (Image)b.getCells().first().get();
image.setDrawable(schemShown ? Icon.upOpen : Icon.downOpen);
return schemShown;
}).row();
collapser(t -> {
t.background(Styles.black8).defaults().maxHeight(72 * 8f).maxWidth(160f);
rebuildList = () -> {
t.clearChildren();
ScrollPane pane1 = t.pane(Styles.noBarPane, p -> {
p.left().defaults().pad(2).height(42f);
try {
for(String tag : (Seq<String>)SUtils.invoke(ui.schematics, "tags")){
p.button(tag, Styles.togglet, () -> {
if(selectedTags.contains(tag)){
selectedTags.remove(tag);
}else{
selectedTags.add(tag);
}
rebuildList.run();
}).checked(selectedTags.contains(tag)).with(c -> c.getLabel().setWrap(false));
}
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
}).fillX().height(42f).get();
pane1.update(() -> {
Element result = scene.hit(input.mouseX(), input.mouseY(), true);
if(pane1.hasScroll() && (result == null || !result.isDescendantOf(pane1)))
scene.setScrollFocus(null);
tagScrollPos = pane1.getScrollX();
});
pane1.setOverscroll(false, false);
pane1.setScrollingDisabled(false, true);
pane1.setScrollXForce(tagScrollPos);
t.row();
ScrollPane pane = t.pane(Styles.noBarPane, p -> {
p.table(tt -> {
firstSchematic = null;
tt.button("@editor.import", Icon.download, this::showImport).width(160f).height(64f).row();
for(Schematic s : schematics.all()){
if(selectedTags.any() && !s.labels.containsAll(selectedTags)) continue;
if(firstSchematic == null) firstSchematic = s;
Button[] sel = {null};
sel[0] = tt.button(b -> {
b.top();
b.margin(0f);
b.table(buttons -> {
buttons.left();
buttons.defaults().size(162/4f);
ImageButton.ImageButtonStyle style = Styles.clearNonei;
buttons.button(Icon.info, style, () -> showInfo(s));
buttons.button(Icon.upload, style, () -> showExport(s));
buttons.button(Icon.pencil, style, () -> {
new Dialog("@schematic.rename"){{
setFillParent(true);
cont.margin(30);
cont.add("@schematic.tags").padRight(6f);
cont.table(tags -> buildTags(s, tags, false)).maxWidth(400f).fillX().left().row();
cont.margin(30).add("@name").padRight(6f);
TextField nameField = cont.field(s.name(), null).size(400f, 55f).left().get();
cont.row();
cont.margin(30).add("@editor.description").padRight(6f);
TextField descField = cont.area(s.description(), Styles.areaField, t -> {}).size(400f, 140f).left().get();
Runnable accept = () -> {
s.tags.put("name", nameField.getText());
s.tags.put("description", descField.getText());
s.save();
hide();
setSchemTable();
};
buttons.defaults().size(120, 54).pad(4);
buttons.button("@ok", accept).disabled(b -> nameField.getText().isEmpty());
buttons.button("@cancel", this::hide);
keyDown(KeyCode.enter, () -> {
if(!nameField.getText().isEmpty() && Core.scene.getKeyboardFocus() != descField){
accept.run();
}
});
keyDown(KeyCode.escape, this::hide);
keyDown(KeyCode.back, this::hide);
show();
}};
});
if(s.hasSteamID()){
buttons.button(Icon.link, style, () -> platform.viewListing(s));
}else{
buttons.button(Icon.trash, style, () -> {
if(s.mod != null){
ui.showInfo(Core.bundle.format("mod.item.remove", s.mod.meta.displayName()));
}else{
ui.showConfirm("@confirm", "@schematic.delete.confirm", () -> {
schematics.remove(s);
setSchemTable();
});
}
});
}
}).growX().height(50f);
b.row();
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;
control.input.useSchematic(s);
}).pad(4).style(Styles.cleari).get();
sel[0].getStyle().up = Tex.pane;
tt.row();
}
if(firstSchematic == null){
tt.add(bundle.get("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);
};
rebuildList.run();
}, true, () -> schemShown);
}
void showInfo(Schematic schematic){
try {
((SchematicsDialog.SchematicInfoDialog) SUtils.invoke(ui.schematics, "info")).show(schematic);
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
}
void checkTags(Schematic s){
boolean any = false;
Seq<String> seq = null;
try {
seq = (Seq<String>) SUtils.invoke(ui.schematics, "tags");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
if(seq == null) return;
for(var tag : s.labels){
if(!seq.contains(tag)){
seq.add(tag);
any = true;
}
}
if(any) setSchemTable();
}
void showImport(){
BaseDialog dialog = new BaseDialog("@editor.export");
dialog.cont.pane(p -> {
p.margin(10f);
p.table(Tex.button, t -> {
TextButton.TextButtonStyle style = Styles.cleart;
t.defaults().size(280f, 60f).left();
t.row();
t.button("@schematic.copy.import", Icon.copy, style, () -> {
dialog.hide();
try{
Schematic s = Schematics.readBase64(Core.app.getClipboardText());
s.removeSteamID();
schematics.add(s);
setSchemTable();
ui.showInfoFade("@schematic.saved");
checkTags(s);
showInfo(s);
}catch(Throwable e){
ui.showException(e);
}
}).marginLeft(12f).disabled(b -> Core.app.getClipboardText() == null || !Core.app.getClipboardText().startsWith(schematicBaseStart));
t.row();
t.button("@schematic.importfile", Icon.download, style, () -> platform.showFileChooser(true, schematicExtension, file -> {
dialog.hide();
try{
Schematic s = Schematics.read(file);
s.removeSteamID();
schematics.add(s);
setSchemTable();
showInfo(s);
checkTags(s);
}catch(Exception e){
ui.showException(e);
}
})).marginLeft(12f);
t.row();
if(steam){
t.button("@schematic.browseworkshop", Icon.book, style, () -> {
dialog.hide();
platform.openWorkshop();
}).marginLeft(12f);
}
});
});
dialog.addCloseButton();
dialog.show();
}
void showExport(Schematic s){
BaseDialog dialog = new BaseDialog("@editor.export");
dialog.cont.pane(p -> {
p.margin(10f);
p.table(Tex.button, t -> {
TextButton.TextButtonStyle style = Styles.cleart;
t.defaults().size(280f, 60f).left();
if(steam && !s.hasSteamID()){
t.button("@schematic.shareworkshop", Icon.book, style,
() -> platform.publish(s)).marginLeft(12f);
t.row();
dialog.hide();
}
t.button("@schematic.copy", Icon.copy, style, () -> {
dialog.hide();
ui.showInfoFade("@copied");
Core.app.setClipboardText(schematics.writeBase64(s));
}).marginLeft(12f);
t.row();
t.button("@schematic.exportfile", Icon.export, style, () -> {
dialog.hide();
platform.export(s.name(), schematicExtension, file -> Schematics.write(s, file));
}).marginLeft(12f);
});
});
dialog.addCloseButton();
dialog.show();
}
void tagsChanged(){
rebuildList.run();
Seq<String> tags = null;
try {
tags = (Seq<String>) SUtils.invoke(ui.schematics, "tags");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
if(tags == null) return;
Core.settings.putJson("schematic-tags", String.class, tags);
}
void addTag(Schematic s, String tag){
s.labels.add(tag);
s.save();
tagsChanged();
}
void removeTag(Schematic s, String tag){
s.labels.remove(tag);
s.save();
tagsChanged();
}
//shows a dialog for creating a new tag
void showNewTag(Cons<String> result){
Seq<String> tags = null;
try {
tags = (Seq<String>) SUtils.invoke(ui.schematics, "tags");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
if(tags == null) return;
Seq<String> finalTags = tags;
ui.showTextInput("@schematic.addtag", "", "", out -> {
if(finalTags.contains(out)){
ui.showInfo("@schematic.tagexists");
}else{
finalTags.add(out);
tagsChanged();
result.get(out);
}
});
}
void showNewIconTag(Cons<String> cons){
Seq<String> tags = null;
try {
tags = (Seq<String>) SUtils.invoke(ui.schematics, "tags");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
if(tags == null) return;
Seq<String> finalTags = tags;
new Dialog(){{
closeOnBack();
setFillParent(true);
cont.pane(t ->
resized(true, () -> {
t.clearChildren();
t.marginRight(19f);
t.defaults().size(48f);
int cols = (int)Math.min(20, Core.graphics.getWidth() / Scl.scl(52f));
for(ContentType ctype : defaultContentIcons){
t.row();
t.image().colspan(cols).growX().width(Float.NEGATIVE_INFINITY).height(3f).color(Pal.accent);
t.row();
int i = 0;
for(UnlockableContent u : content.getBy(ctype).<UnlockableContent>as()){
if(!u.isHidden() && u.unlockedNow() && u.hasEmoji() && !finalTags.contains(u.emoji())){
t.button(new TextureRegionDrawable(u.uiIcon), Styles.cleari, iconMed, () -> {
String out = u.emoji() + "";
finalTags.add(out);
tagsChanged();
cons.get(out);
hide();
});
if(++i % cols == 0) t.row();
}
}
}
})
);
buttons.button("@back", Icon.left, this::hide).size(210f, 64f);
}}.show();
}
void buildTags(Schematic schem, Table t, boolean name){
t.clearChildren();
t.left();
Seq<String> tags = null;
try {
tags = (Seq<String>) SUtils.invoke(ui.schematics, "tags");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
if(tags == null) return;
//sort by order in the main target array. the complexity of this is probably awful
Seq<String> finalTags = tags;
schem.labels.sort((Floatf<String>) finalTags::indexOf);
if(name) t.add("@schematic.tags").padRight(4);
t.pane(s -> {
s.left();
s.defaults().pad(3).height(42f);
for(var tag : schem.labels){
s.table(Tex.button, i -> {
i.add(tag).padRight(4).height(42f).labelAlign(Align.center);
i.button(Icon.cancelSmall, Styles.emptyi, () -> {
removeTag(schem, tag);
buildTags(schem, t, name);
}).size(42f).padRight(-9f).padLeft(-9f);
});
}
}).fillX().left().height(42f).scrollY(false);
Seq<String> finalTags1 = tags;
t.button(Icon.addSmall, () -> {
var dialog = new BaseDialog("@schematic.addtag");
dialog.addCloseButton();
dialog.cont.pane(p -> {
p.clearChildren();
float sum = 0f;
Table current = new Table().left();
for(var tag : finalTags1){
if(schem.labels.contains(tag)) continue;
var next = Elem.newButton(tag, () -> {
addTag(schem, tag);
buildTags(schem, t, name);
dialog.hide();
});
next.getLabel().setWrap(false);
next.pack();
float w = next.getPrefWidth() + Scl.scl(6f);
if(w + sum >= Core.graphics.getWidth() * (Core.graphics.isPortrait() ? 1f : 0.8f)){
p.add(current).row();
current = new Table();
current.left();
current.add(next).height(42f).pad(2);
sum = 0;
}else{
current.add(next).height(42f).pad(2);
}
sum += w;
}
if(sum > 0){
p.add(current).row();
}
Cons<String> handleTag = res -> {
dialog.hide();
addTag(schem, res);
buildTags(schem, t, name);
};
p.row();
p.table(v -> {
v.left().defaults().fillX().height(42f).pad(2);
v.button("@schematic.texttag", Icon.add, () -> showNewTag(handleTag)).wrapLabel(false).get().getLabelCell().padLeft(4);
v.button("@schematic.icontag", Icon.add, () -> showNewIconTag(handleTag)).wrapLabel(false).get().getLabelCell().padLeft(4);
});
});
dialog.show();
}).size(42f).tooltip("@schematic.addtag");
}
}

View File

@@ -0,0 +1,115 @@
package informatis.ui.display;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.ui.*;
import mindustry.world.Block;
import mindustry.world.Tile;
import mindustry.world.blocks.environment.Floor;
import static informatis.SUtils.*;
import static informatis.SVars.*;
import static arc.Core.*;
import static mindustry.Vars.*;
public class WaveInfoDisplay {
public boolean waveShown;
public void addWaveInfoTable() {
Table waveInfoTable = new Table(Tex.buttonEdge4, table -> {
table.center();
table.table(head -> {
head.table(image -> {
image.left();
image.image(() -> {
Tile tile = getTile();
if(tile == null) return clear;
Floor floor = tile.floor();
if(floor.uiIcon == error) return clear;
return floor.uiIcon;
}).size(iconSmall);
image.image(() -> {
Tile tile = getTile();
if(tile == null) return clear;
Floor floor = tile.overlay();
if(floor.uiIcon == error) return clear;
return floor.uiIcon;
}).size(iconSmall);
image.image(() -> {
Tile tile = getTile();
if(tile == null) return clear;
Block floor = tile.block();
if(floor.uiIcon == error) return clear;
return floor.uiIcon;
}).size(iconSmall);
});
head.label(() -> {
Tile tile = getTile();
if(tile == null) return "(NaN, NaN)";
return Strings.format("(@, @)", tile.x, tile.y);
}).center();
});
table.row();
table.image().height(4f).color(Pal.gray).growX().row();
/*
table.table(tttt -> {
tttt.center();
int[] i = {0};
content.units().each(type -> Groups.unit.contains(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && u.isBoss()), type -> {
tttt.table(stt ->
stt.stack(
new Table(ttt -> ttt.image(type.uiIcon).size(iconSmall)),
new Table(ttt -> {
ttt.right().bottom();
Label label = new Label(() -> Groups.unit.count(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && u.isBoss()) + "");
label.setFontScale(0.75f);
ttt.add(label);
ttt.pack();
}),
new Table(ttt -> {
ttt.top().right();
Image image = new Image(Icon.warning.getRegion()).setScaling(Scaling.fit);
image.update(() -> image.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f))));
ttt.add(image).size(12f);
ttt.pack();
})
).pad(6)
);
if(++i[0] % 6 == 0) tttt.row();
});
tttt.row();
i[0] = 0;
content.units().each(type -> Groups.unit.contains(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && !u.isBoss()), type -> {
tttt.table(ttt ->
ttt.add(new Stack() {{
add(new Table(ttt -> ttt.add(new Image(type.uiIcon)).size(iconSmall)));
add(new Table(ttt -> {
ttt.right().bottom();
Label label = new Label(() -> Groups.unit.count(u -> u.type == type &&(state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && !u.isBoss()) + "");
label.setFontScale(0.75f);
ttt.add(label);
ttt.pack();
}));
}}).pad(6)
);
if(++i[0] % 6 == 0) tttt.row();
});
});
*/
});
Table waveTable = (Table) scene.find("waves");
Table infoTable = (Table) scene.find("infotable");
waveTable.removeChild(infoTable);
waveTable.row();
waveTable.stack(
new Table(tt -> tt.collapser(t -> t.stack(waveInfoTable, infoTable).growX(), true, () -> waveShown).growX()).top(),
new Table(tt -> tt.button(Icon.downOpen, Styles.clearTogglei, () -> waveShown = !waveShown).size(4 * 8f).checked(b -> {
b.getImage().setDrawable(waveShown ? Icon.upOpen : Icon.downOpen);
return waveShown;
})).left().top()).fillX();
}
}

View File

@@ -0,0 +1,37 @@
package informatis.ui.draws;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Fill;
import arc.scene.style.TextureRegionDrawable;
import mindustry.gen.Groups;
import mindustry.graphics.Pal;
import static informatis.SUtils.*;
import static arc.Core.settings;
public class BlockDraw extends OverDraw {
BlockDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("blockStatus");
}
@Override
public void draw() {
super.draw();
Groups.build.each(b->{
if(isInCamera(b.x, b.y, b.block.size/2f) && settings.getBool("blockStatus") && enabled) {
if(b.block.consumers.length > 0) {
float multiplier = b.block.size > 1 ? 1.0F : 0.64F;
float brcx = b.x + (float)(b.block.size * 8) / 2.0F - 8.0F * multiplier / 2.0F;
float brcy = b.y - (float)(b.block.size * 8) / 2.0F + 8.0F * multiplier / 2.0F;
Draw.z(71.0F);
Draw.color(Pal.gray);
Fill.square(brcx, brcy, 2.5F * multiplier, 45.0F);
Draw.color(b.status().color);
Fill.square(brcx, brcy, 1.5F * multiplier, 45.0F);
Draw.color();
}
};
});
}
}

View File

@@ -0,0 +1,159 @@
package informatis.ui.draws;
import arc.graphics.Color;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Lines;
import arc.math.Angles;
import arc.math.Mathf;
import arc.scene.style.TextureRegionDrawable;
import arc.struct.IntSeq;
import arc.struct.Seq;
import arc.util.Time;
import arc.util.Tmp;
import mindustry.core.Renderer;
import mindustry.gen.Building;
import mindustry.gen.Groups;
import mindustry.graphics.Drawf;
import mindustry.graphics.Layer;
import mindustry.graphics.Pal;
import mindustry.world.blocks.distribution.MassDriver;
import mindustry.world.blocks.payloads.PayloadMassDriver;
import static arc.Core.atlas;
import static arc.Core.settings;
import static mindustry.Vars.*;
import static informatis.SVars.*;
public class LinkDraw extends OverDraw {
Seq<MassDriver.MassDriverBuild> linkedMasses = new Seq<>();
Seq<PayloadMassDriver.PayloadDriverBuild> linkedPayloadMasses = new Seq<>();
Seq<Building> linkedNodes = new Seq<>();
LinkDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("powerNode");
registerOption("massDriver");
}
@Override
public void draw() {
if(!enabled) return;
Draw.z(Layer.max);
if(target instanceof Building b){
if(settings.getBool("powerNode") && enabled) {
linkedNodes.clear();
drawNodeLink(b);
}
if(settings.getBool("massDriver") && enabled) {
if (target instanceof MassDriver.MassDriverBuild mass) {
linkedMasses.clear();
drawMassLink(mass);
} else if (target instanceof PayloadMassDriver.PayloadDriverBuild mass) {
linkedPayloadMasses.clear();
drawMassPayloadLink(mass);
}
}
}
}
void drawMassPayloadLink(PayloadMassDriver.PayloadDriverBuild from){
float sin = Mathf.absin(Time.time, 6f, 1f);
//call every mass drivers that link to this driver
for(Building b : Groups.build) {
if (b != from && b instanceof PayloadMassDriver.PayloadDriverBuild fromMass && world.build(fromMass.link) == from && !linkedPayloadMasses.contains(fromMass)) {
linkedPayloadMasses.add(fromMass);
drawMassPayloadLink(fromMass);
}
}
//get and draw line between this mass driver and linked one
Building target = world.build(from.link);
if(target instanceof PayloadMassDriver.PayloadDriverBuild targetDriver) {
Tmp.v1.set(from.x + from.block.offset, from.y + from.block.offset).sub(targetDriver.x, targetDriver.y).limit(from.block.size * tilesize + sin + 0.5f);
float x2 = from.x - Tmp.v1.x, y2 = from.y - Tmp.v1.y, x1 = targetDriver.x + Tmp.v1.x, y1 = targetDriver.y + Tmp.v1.y;
int segs = (int) (targetDriver.dst(from.x, from.y) / tilesize);
Lines.stroke(4f, Pal.gray);
Lines.dashLine(x1, y1, x2, y2, segs);
Lines.stroke(2f, Pal.placing);
Lines.dashLine(x1, y1, x2, y2, segs);
Lines.stroke(1f, Pal.accent);
Drawf.circles(from.x, from.y, (from.tile.block().size / 2f + 1) * tilesize + sin - 2f, Pal.accent);
Drawf.arrow(from.x, from.y, targetDriver.x, targetDriver.y, from.block.size * tilesize + sin, 4f + sin);
for (Building shooter : from.waitingShooters) {
Drawf.circles(shooter.x, shooter.y, (from.tile.block().size / 2f + 1) * tilesize + sin - 2f);
Drawf.arrow(shooter.x, shooter.y, from.x, from.y, from.block.size * tilesize + sin, 4f + sin);
}
//call method again when target links to another mass driver which isn't stored in array
if(!linkedPayloadMasses.contains(targetDriver)) {
linkedPayloadMasses.add(targetDriver);
drawMassPayloadLink(targetDriver);
}
}
}
void drawMassLink(MassDriver.MassDriverBuild from){
float sin = Mathf.absin(Time.time, 6f, 1f);
//call every mass drivers that link to this driver
for(Building b : Groups.build) {
if (b != from && b instanceof MassDriver.MassDriverBuild fromMass && world.build(fromMass.link) == from && !linkedMasses.contains(fromMass)) {
linkedMasses.add(fromMass);
drawMassLink(fromMass);
}
}
//get and draw line between this mass driver and linked one
Building target = world.build(from.link);
if(target instanceof MassDriver.MassDriverBuild targetDriver) {
Tmp.v1.set(from.x + from.block.offset, from.y + from.block.offset).sub(targetDriver.x, targetDriver.y).limit(from.block.size * tilesize + sin + 0.5f);
float x2 = from.x - Tmp.v1.x, y2 = from.y - Tmp.v1.y, x1 = targetDriver.x + Tmp.v1.x, y1 = targetDriver.y + Tmp.v1.y;
int segs = (int) (targetDriver.dst(from.x, from.y) / tilesize);
Lines.stroke(4f, Pal.gray);
Lines.dashLine(x1, y1, x2, y2, segs);
Lines.stroke(2f, Pal.placing);
Lines.dashLine(x1, y1, x2, y2, segs);
Lines.stroke(1f, Pal.accent);
Drawf.circles(from.x, from.y, (from.tile.block().size / 2f + 1) * tilesize + sin - 2f, Pal.accent);
Drawf.arrow(from.x, from.y, targetDriver.x, targetDriver.y, from.block.size * tilesize + sin, 4f + sin);
for (Building shooter : from.waitingShooters) {
Drawf.circles(shooter.x, shooter.y, (from.tile.block().size / 2f + 1) * tilesize + sin - 2f);
Drawf.arrow(shooter.x, shooter.y, from.x, from.y, from.block.size * tilesize + sin, 4f + sin);
}
//call method again when target links to another mass driver which isn't stored in array
if(!linkedMasses.contains(targetDriver)) {
linkedMasses.add(targetDriver);
drawMassLink(targetDriver);
}
}
}
IntSeq getPowerLinkedBuilds(Building build) {
IntSeq seq = new IntSeq(build.power.links);
seq.addAll(build.proximity().mapInt(Building::pos));
return seq;
}
void drawNodeLink(Building node) {
if(node.power == null) return;
if(!linkedNodes.contains(node)) {
linkedNodes.add(node);
int[] builds = getPowerLinkedBuilds(node).items;
for(int i : builds) {
Building other = world.build(i);
if(other == null || other.power == null) return;
float angle1 = Angles.angle(node.x, node.y, other.x, other.y),
vx = Mathf.cosDeg(angle1), vy = Mathf.sinDeg(angle1),
len1 = node.block.size * tilesize / 2f - 1.5f, len2 = other.block.size * tilesize / 2f - 1.5f;
Draw.color(Color.white, Color.valueOf("98ff98"), (1f - node.power.graph.getSatisfaction()) * 0.86f + Mathf.absin(3f, 0.1f));
Draw.alpha(Renderer.laserOpacity);
Drawf.laser(atlas.find("informatis-Slaser"), atlas.find("informatis-Slaser"), atlas.find("informatis-Slaser-end"), node.x + vx * len1, node.y + vy * len1, other.x - vx * len2, other.y - vy * len2, 0.25f);
drawNodeLink(other);
}
}
}
}

View File

@@ -0,0 +1,52 @@
package informatis.ui.draws;
import arc.scene.Element;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.CheckBox;
import arc.scene.ui.layout.Table;
import arc.struct.Seq;
import mindustry.ui.Styles;
import static arc.Core.bundle;
import static arc.Core.settings;
public class OverDraw {
public TextureRegionDrawable icon;
public String name;
public boolean enabled = false;
public Seq<String> options = new Seq<>();
OverDraw(String name, TextureRegionDrawable icon) {
this.name = name;
this.icon = icon;
}
public void displayStats(Table parent) {
if(options.isEmpty()) return;
parent.background(Styles.squarei.up);
options.each(name-> parent.check(bundle.get("setting."+name+".name"), settings.getBool(name), b->settings.put(name, b)).tooltip(t->t.background(Styles.black8).add(bundle.get("setting."+name+".description"))).disabled(!enabled).row());
}
public void draw() {}
public <T> void onEnabled(T param) {
if(param instanceof Table t) {
for (int i = 0; i < t.getChildren().size; i++) {
Element elem = t.getChildren().get(i);
if (elem instanceof CheckBox cb) cb.setDisabled(!enabled);
}
}
}
public void registerOption(String name) {
registerOption(name, settings.has(name) && settings.getBool(name));
}
public void registerOption(String name, boolean defaults) {
options.add(name);
settings.put(name, defaults);
}
}

View File

@@ -0,0 +1,17 @@
package informatis.ui.draws;
import mindustry.gen.Icon;
public class OverDraws {
public static OverDraw range, link, unit, block, util;
public static OverDraw[] all = {};
public static void init() {
range = new RangeDraw("Range Draws", Icon.commandRally);
link = new LinkDraw("Link Draws", Icon.line);
unit = new UnitDraw("Unit Draws", Icon.units);
block = new BlockDraw("Block Draws", Icon.crafting);
util = new UtilDraw("Utils", Icon.github);
all = new OverDraw[]{range, link, unit, block, util};
}
}

View File

@@ -0,0 +1,81 @@
package informatis.ui.draws;
import arc.graphics.Color;
import arc.graphics.g2d.*;
import arc.graphics.gl.FrameBuffer;
import arc.scene.style.TextureRegionDrawable;
import arc.struct.ObjectMap;
import arc.struct.Seq;
import mindustry.game.Team;
import mindustry.gen.*;
import mindustry.graphics.Drawf;
import mindustry.world.blocks.defense.turrets.BaseTurret;
import mindustry.world.blocks.defense.turrets.TractorBeamTurret;
import mindustry.world.blocks.defense.turrets.Turret;
import static informatis.SVars.turretRange;
import static informatis.SUtils.*;
import static arc.Core.*;
import static mindustry.Vars.player;
public class RangeDraw extends OverDraw {
FrameBuffer effectBuffer = new FrameBuffer();
ObjectMap<Team, Seq<BaseTurret.BaseTurretBuild>> turrets = new ObjectMap<>();
RangeDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("airRange");
registerOption("groundRange");
}
@Override
public void draw() {
if(!enabled) return;
effectBuffer.resize(graphics.getWidth(), graphics.getHeight());
Unit unit = player.unit();
turrets.clear();
for(Team team : Team.baseTeams) {
Draw.drawRange(166 + (Team.baseTeams.length-team.id) * 3, 1, () -> effectBuffer.begin(Color.clear), () -> {
effectBuffer.end();
effectBuffer.blit(turretRange);
});
turrets.put(team, new Seq<>());
}
Groups.build.each(b-> settings.getBool("aliceRange") || player.team() != b.team, b -> {
if(b instanceof BaseTurret.BaseTurretBuild turret) {
float range = turret.range();
if (isInCamera(b.x, b.y, range)) {
int index = b.team.id;
Draw.color(b.team.color);
boolean air = settings.getBool("airRange") && enabled;
boolean ground = settings.getBool("groundRange") && enabled;
boolean valid = false;
if (unit == null) valid = true;
else if (b instanceof Turret.TurretBuild build) {
Turret t = (Turret) build.block;
if(t.targetAir&&!air||t.targetGround&&!ground) return;
if((unit.isFlying() ? t.targetAir : t.targetGround) && build.hasAmmo() && build.canConsume()) valid = true;
} else if (b instanceof TractorBeamTurret.TractorBeamBuild build) {
TractorBeamTurret t = (TractorBeamTurret) build.block;
if(t.targetAir&&!air||t.targetGround&&!ground) return;
if((unit.isFlying() ? t.targetAir : t.targetGround) && build.canConsume()) valid = true;
}
if(!valid) index = 0;
if(b.team==player.team()) index = b.team.id;
Draw.color(Team.baseTeams[index].color);
if (settings.getBool("RangeShader")) {
Draw.z(166+(Team.baseTeams.length-index)*3);
Fill.poly(b.x, b.y, Lines.circleVertices(range), range);
} else Drawf.dashCircle(b.x, b.y, range, b.team.color);
}
}
});
}
}

View File

@@ -0,0 +1,111 @@
package informatis.ui.draws;
import informatis.ui.FreeBar;
import arc.graphics.g2d.Lines;
import arc.math.Angles;
import arc.math.Mathf;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.layout.Scl;
import arc.struct.Seq;
import arc.util.Align;
import arc.util.Tmp;
import mindustry.Vars;
import mindustry.ai.Pathfinder;
import mindustry.ai.RtsAI;
import mindustry.ai.types.*;
import mindustry.entities.units.UnitController;
import mindustry.game.Team;
import mindustry.gen.Groups;
import mindustry.graphics.Pal;
import mindustry.logic.LUnitControl;
import mindustry.ui.Fonts;
import mindustry.world.Tile;
import mindustry.world.blocks.storage.CoreBlock;
import java.util.Objects;
import static informatis.SUtils.*;
import static arc.Core.settings;
import static mindustry.Vars.*;
public class UnitDraw extends OverDraw {
Seq<Tile> pathTiles = new Seq<>();
int otherCores;
UnitDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("pathLine");
registerOption("logicLine");
registerOption("unitLine");
registerOption("unitItem");
registerOption("unitBar");
}
@Override
public void draw() {
if(!enabled) return;
Groups.unit.each(u-> isInCamera(u.x, u.y, u.hitSize), u -> {
UnitController c = u.controller();
RtsAI rts = u.team.data().rtsAi;
if(settings.getBool("logicLine") && c instanceof LogicAI ai && (ai.control == LUnitControl.approach || ai.control == LUnitControl.move)) {
Lines.stroke(1, u.team.color);
Lines.line(u.x(), u.y(), ai.moveX, ai.moveY);
Lines.stroke(0.5f + Mathf.absin(6f, 0.5f), Tmp.c1.set(Pal.logicOperations).lerp(Pal.sap, Mathf.absin(6f, 0.5f)));
Lines.line(u.x(), u.y(), ai.controller.x, ai.controller.y);
}
if(settings.getBool("unitLine") && !u.type.flying && !(c instanceof MinerAI || c instanceof BuilderAI || c instanceof RepairAI || c instanceof DefenderAI || c instanceof FlyingAI)) {
Lines.stroke(1, u.team.color);
otherCores = Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != u.team);
pathTiles.clear();
getNextTile(u.tileOn(), u.controller() instanceof SuicideAI ? 0 : u.pathType(), u.team, u.pathType());
pathTiles.filter(Objects::nonNull);
for(int i = 0; i < pathTiles.size-1; i++) {
Tile from = pathTiles.get(i);
Tile to = pathTiles.get(i + 1);
if(isOutCamera(from.worldx(), from.worldy())) continue;
Lines.line(from.worldx(), from.worldy(), to.worldx(), to.worldy());
}
}
if(settings.getBool("unitBar")) FreeBar.draw(u);
if(settings.getBool("unitItem") && !renderer.pixelator.enabled() && u.item() != null && u.itemTime > 0.01f)
Fonts.outline.draw(u.stack.amount + "",
u.x + Angles.trnsx(u.rotation + 180f, u.type.itemOffsetY),
u.y + Angles.trnsy(u.rotation + 180f, u.type.itemOffsetY) - 3,
Pal.accent, 0.25f * u.itemTime / Scl.scl(1f), false, Align.center);
});
if(settings.getBool("pathLine")) spawner.getSpawns().each(t -> {
Team enemyTeam = state.rules.waveTeam;
Lines.stroke(1, enemyTeam.color);
for(int p = 0; p < (Vars.state.rules.spawns.count(g->g.type.naval)>0?3:2); p++) {
pathTiles.clear();
otherCores = Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != enemyTeam);
getNextTile(t, p, enemyTeam, Pathfinder.fieldCore);
pathTiles.filter(Objects::nonNull);
for(int i = 0; i < pathTiles.size-1; i++) {
Tile from = pathTiles.get(i);
Tile to = pathTiles.get(i + 1);
if(isOutCamera(from.worldx(), from.worldy())) continue;
Lines.line(from.worldx(), from.worldy(), to.worldx(), to.worldy());
}
}
});
}
Tile getNextTile(Tile tile, int cost, Team team, int finder) {
Pathfinder.Flowfield field = pathfinder.getField(team, cost, Mathf.clamp(finder, 0, 0));
Tile tile1 = pathfinder.getTargetTile(tile, field);
pathTiles.add(tile1);
if(tile1 == tile || tile1 == null ||
(finder == 0 && (otherCores != Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != team) || tile1.build instanceof CoreBlock.CoreBuild)))
return tile1;
return getNextTile(tile1, cost, team, finder);
}
}

View File

@@ -0,0 +1,82 @@
package informatis.ui.draws;
import arc.input.KeyCode;
import arc.math.Angles;
import arc.math.geom.Geometry;
import arc.scene.style.TextureRegionDrawable;
import mindustry.entities.Units;
import mindustry.game.Team;
import mindustry.gen.*;
import mindustry.logic.Ranged;
import mindustry.world.blocks.ControlBlock;
import mindustry.world.blocks.defense.turrets.Turret;
import static arc.Core.*;
import static mindustry.Vars.*;
public class UtilDraw extends OverDraw {
Teamc shotTarget;
UtilDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("autoShooting");
}
@Override
public void draw() {
super.draw();
if(!enabled) return;
if(settings.getBool("autoShooting")) {
Unit unit = player.unit();
if (unit.type == null) return;
boolean omni = unit.type.omniMovement;
boolean validHealTarget = unit.type.canHeal && shotTarget instanceof Building b && b.isValid() && b.damaged() && shotTarget.team() == unit.team && shotTarget.within(unit, unit.type.range);
boolean boosted = (unit instanceof Mechc && unit.isFlying());
if ((unit.type != null && Units.invalidateTarget(shotTarget, unit, unit.type.range) && !validHealTarget) || state.isEditor()) {
shotTarget = null;
}
float mouseAngle = unit.angleTo(unit.aimX(), unit.aimY());
boolean aimCursor = omni && player.shooting && unit.type.hasWeapons() && unit.type.faceTarget && !boosted && unit.type.rotateToBuilding;
unit.lookAt(aimCursor ? mouseAngle : unit.prefRotation());
//update shooting if not building + not mining
if(!player.unit().activelyBuilding() && player.unit().mineTile == null) {
if(input.keyDown(KeyCode.mouseLeft)) {
player.shooting = !boosted;
unit.aim(player.mouseX = input.mouseWorldX(), player.mouseY = input.mouseWorldY());
} else if(shotTarget == null) {
player.shooting = false;
if(unit instanceof BlockUnitUnit b) {
if(b.tile() instanceof ControlBlock c && !c.shouldAutoTarget()) {
Building build = b.tile();
float range = build instanceof Ranged ? ((Ranged) build).range() : 0f;
boolean targetGround = build instanceof Turret.TurretBuild && ((Turret) build.block).targetAir;
boolean targetAir = build instanceof Turret.TurretBuild && ((Turret) build.block).targetGround;
shotTarget = Units.closestTarget(build.team, build.x, build.y, range, u -> u.checkTarget(targetAir, targetGround), u -> targetGround);
}
else shotTarget = null;
} else if(unit.type != null) {
float range = unit.hasWeapons() ? unit.range() : 0f;
shotTarget = Units.closestTarget(unit.team, unit.x, unit.y, range, u -> u.checkTarget(unit.type.targetAir, unit.type.targetGround), u -> unit.type.targetGround);
if(unit.type.canHeal && shotTarget == null) {
shotTarget = Geometry.findClosest(unit.x, unit.y, indexer.getDamaged(Team.sharded));
if (shotTarget != null && !unit.within(shotTarget, range)) {
shotTarget = null;
}
}
}
} else {
player.shooting = !boosted;
unit.rotation(Angles.angle(unit.x, unit.y, shotTarget.x(), shotTarget.y()));
unit.aim(shotTarget.x(), shotTarget.y());
}
}
unit.controlWeapons(player.shooting && !boosted);
}
}
}

View File

@@ -0,0 +1,206 @@
package informatis.ui.window;
import arc.Events;
import mindustry.game.EventType;
import informatis.ui.*;
import arc.Core;
import arc.graphics.Color;
import arc.math.Mathf;
import arc.math.geom.Vec2;
import arc.scene.event.HandCursorListener;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.struct.Seq;
import arc.util.*;
import mindustry.Vars;
import mindustry.content.UnitTypes;
import mindustry.core.UI;
import mindustry.game.Team;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.input.DesktopInput;
import mindustry.type.*;
import mindustry.ui.Styles;
import mindustry.world.blocks.storage.CoreBlock;
import static mindustry.Vars.*;
public class CoreWindow extends Window implements Updatable {
Vec2 scrollPos = new Vec2(0, 0);
Table window;
float heat;
ObjectMap<Team, ItemData> itemData = new ObjectMap<>();
public CoreWindow() {
super(Icon.list, "core");
resetUsed();
}
@Override
public void build(Table table) {
window = table;
scrollPos = new Vec2(0, 0);
table.background(Styles.black8).top();
table.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("core-pane");
Events.on(EventType.WorldLoadEvent.class, e -> resetUsed());
}
@Override
public void update() {
heat += Time.delta;
if(heat >= 60f) {
heat = 0f;
ScrollPane pane = find("core-pane");
pane.setWidget(rebuild());
for(Team team : getTeams()) {
if(!itemData.containsKey(team)) itemData.put(team, new ItemData());
itemData.get(team).updateItems(team);
}
}
}
Table rebuild() {
return new Table(table -> {
table.top();
for(Team team : getTeams()) {
table.table(row-> {
row.center();
row.add(setTable(team)).margin(8f).row();
row.image().height(4f).color(team.color).growX();
}).growX().row();
}
});
}
public Seq<Team> getTeams(){
return Seq.with(Team.all).filter(Team::active);
}
public void resetUsed(){
for(Team team : getTeams()) {
itemData.put(team, new ItemData());
}
}
public Table setTable(Team team){
return new Table(table -> {
table.add(team.name).color(team.color).row();
int max = Math.max(1, Math.round(window.getWidth()/2/60));
table.table(coretable -> {
int row = 0;
for(CoreBlock.CoreBuild core : team.cores()) {
coretable.table(tt -> {
tt.stack(
new Table(s -> {
s.center();
Image image = new Image(core.block.uiIcon);
image.clicked(() -> {
if(control.input instanceof DesktopInput)
((DesktopInput) control.input).panning = true;
Core.camera.position.set(core.x, core.y);
});
HandCursorListener listener1 = new HandCursorListener();
image.addListener(listener1);
image.update(() -> {
image.color.lerp(!listener1.isOver() ? Color.lightGray : Color.white, Mathf.clamp(0.4f * Time.delta));
});
Tooltip.Tooltips option = new Tooltip.Tooltips();
option.animations=false;
s.add(image).size(iconLarge).get().addListener(new Tooltip(tool -> {
tool.background(Styles.black6).label(() -> "([#" + Tmp.c1.set(Color.green).lerp(Color.red, 1 - core.healthf()).toString() + "]" + Strings.fixed(core.health, 2) + "[]/" + Strings.fixed(core.block.health, 2) + ")");
}, option));
}),
new Table(h -> {
h.bottom().defaults().height(9f).width(iconLarge * 1.5f).growX();
h.add(new SBar(() -> "", () -> Pal.health, () -> core.health / core.block.health).rect().init());
h.pack();
})
).row();
Label label = new Label(Strings.format("(@, @)",core.tileX(), core.tileY()));
label.setFontScale(0.75f);
tt.add(label);
}).padTop(2).padLeft(4).padRight(4);
if(row++ % max == max-1){
coretable.row();
}
}
}).row();
table.table(itemTable -> {
int row = 0;
CoreBlock.CoreBuild core = team.core();
for(int i = 0; i < Vars.content.items().size; i++){
Item item = Vars.content.item(i);
if(!team.items().has(item)) return;
itemTable.stack(
new Table(ttt -> {
ttt.image(item.uiIcon).size(iconSmall).tooltip(tttt -> tttt.background(Styles.black6).add(item.localizedName).style(Styles.outlineLabel).margin(2f));
ttt.add(UI.formatAmount(core.items.get(item))).minWidth(5 * 8f).left();
}),
new Table(ttt -> {
ttt.bottom().right();
int amount = itemData.get(team).updateItems.isEmpty()?0:Mathf.floor(itemData.get(team).updateItems.get(item.id).amount);
Label label = new Label(amount + "/s");
label.setFontScale(0.65f);
label.setColor(amount > 0 ? Color.green : amount == 0 ? Color.orange : Color.red);
ttt.add(label).bottom().right().padTop(16f);
ttt.pack();
})).padRight(3).left();
if(row++ % max == max-1){
itemTable.row();
}
}
}).row();
table.table(unitTable -> {
int row = 0;
for(UnitType unit : Vars.content.units()){
if(unit != UnitTypes.block && Groups.unit.contains(u -> u.type == unit && u.team == team)){
unitTable.table(tt -> {
tt.center();
tt.image(unit.uiIcon).size(iconSmall).padRight(3).tooltip(ttt -> ttt.background(Styles.black6).add(unit.localizedName).style(Styles.outlineLabel).margin(2f));
tt.add(UI.formatAmount(Groups.unit.count(u -> u.team == team && u.type == unit))).padRight(3).minWidth(5 * 8f).left();
});
if(row++ % max == max-1){
unitTable.row();
}
}
}
});
});
}
static class ItemData {
Seq<ItemStack> prevItems = new Seq<>();
Seq<ItemStack> updateItems = new Seq<>();
ItemData() {
resetItems();
}
public void resetItems(){
Seq<ItemStack> stacks = Vars.content.items().map(item -> new ItemStack(item, 0));
updateItems.clear().addAll(stacks);
prevItems.clear().addAll(stacks);
}
public void updateItems(Team team){
CoreBlock.CoreBuild core = team.core();
if (core != null) {
Seq<ItemStack> stack = updateItems;
if(stack.isEmpty()) Vars.content.items().each(i -> stack.add(new ItemStack(i, 0)));
for (Item item : Vars.content.items()) {
stack.get(item.id).set(item, core.items.get(item) - (prevItems != null ? prevItems.get(item.id).amount : 0));
if (prevItems != null) prevItems.get(item.id).set(item, core.items.get(item));
}
if(prevItems != null) prevItems.clear().addAll(Vars.content.items().map(i -> new ItemStack(i, core.items.get(i))));
}
}
}
}

View File

@@ -0,0 +1,473 @@
package informatis.ui.window;
import arc.Events;
import arc.graphics.g2d.*;
import arc.math.geom.Geometry;
import arc.scene.Element;
import arc.scene.style.Drawable;
import arc.struct.ObjectMap;
import mindustry.editor.MapEditor;
import mindustry.game.EventType;
import mindustry.graphics.Layer;
import informatis.core.EditorTool;
import informatis.ui.*;
import arc.Core;
import arc.func.*;
import arc.graphics.Color;
import arc.input.KeyCode;
import arc.math.Mathf;
import arc.math.geom.Vec2;
import arc.scene.event.Touchable;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.scene.utils.Elem;
import arc.struct.Seq;
import arc.util.*;
import mindustry.Vars;
import mindustry.content.Blocks;
import mindustry.game.Team;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.ui.Styles;
import mindustry.world.*;
import static mindustry.Vars.*;
public class MapEditorWindow extends Window implements Updatable {
Vec2 scrollPos = new Vec2(0, 0);
Table window;
TextField search;
EditorTool tool;
final Vec2[][] brushPolygons = new Vec2[MapEditor.brushSizes.length][0];
float heat;
float brushSize = -1;
boolean drawing;
int lastx, lasty;
float lastw, lasth;
public static Team drawTeam = Team.sharded;
public static Block drawBlock = Blocks.router;
public MapEditorWindow() {
super(Icon.map, "editor");
for(int i = 0; i < MapEditor.brushSizes.length; i++){
float size = MapEditor.brushSizes[i];
float mod = size % 1f;
brushPolygons[i] = Geometry.pixelCircle(size, (index, x, y) -> Mathf.dst(x, y, index - mod, index - mod) <= size - 0.5f);
}
Events.run(EventType.Trigger.draw, ()->{
float cx = Core.camera.position.x, cy = Core.camera.position.y;
float scaling = 8;
Draw.z(Layer.max);
if(Core.settings.getBool("grid")){
Lines.stroke(1f);
Draw.color(Pal.accent);
for(int i = (int)(-0.5f*Core.camera.height/8); i < (int)(0.5f*Core.camera.height/8); i++) {
Lines.line(Mathf.floor((cx-0.5f*Core.camera.width)/8)*8+4, Mathf.floor((cy + i*8)/8)*8+4, Mathf.floor((cx+0.5f*Core.camera.width)/8)*8+4,Mathf.floor((cy + i*8)/8)*8+4);
}
for(int i = (int)(-0.5f*Core.camera.width/8); i < (int)(0.5f*Core.camera.width/8); i++) {
Lines.line(Mathf.floor((cx + i*8)/8)*8+4, Mathf.floor((cy+0.5f*Core.camera.height)/8)*8+4, Mathf.floor((cx + i*8)/8)*8+4,Mathf.floor((cy-0.5f*Core.camera.height)/8)*8+4);
}
Draw.reset();
}
Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
if(tile == null || tool == null || brushSize < 1) return;
int index = 0;
for(int i = 0; i < MapEditor.brushSizes.length; i++){
if(brushSize == MapEditor.brushSizes[i]){
index = i;
break;
}
}
Lines.stroke(Scl.scl(2f), Pal.accent);
if((!drawBlock.isMultiblock() || tool == EditorTool.eraser) && tool != EditorTool.fill){
if(tool == EditorTool.line && drawing){
Lines.poly(brushPolygons[index], lastx, lasty, scaling);
Lines.poly(brushPolygons[index], tile.x*8, tile.y*8, scaling);
}
if((tool.edit || (tool == EditorTool.line && !drawing)) && (!mobile || drawing)){
if(tool == EditorTool.pencil && tool.mode == 1){
Lines.square(tile.x*8, tile.y*8, scaling * (brushSize + 0.5f));
}else{
Lines.poly(brushPolygons[index], tile.x*8-4, tile.y*8-4, scaling);
}
}
}else{
if((tool.edit || tool == EditorTool.line) && (!mobile || drawing)){
float offset = (drawBlock.size % 2 == 0 ? scaling / 2f : 0f);
Lines.square(
tile.x*8 + scaling / 2f + offset,
tile.y*8 + scaling / 2f + offset,
scaling * drawBlock.size / 2f);
}
}
});
}
@Override
public void build(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);
ObjectMap<Drawable, Element> displays = new ObjectMap<>();
displays.put(Icon.map, new Table(display -> {
display.table(t->{
t.left().background(Tex.underline2);
t.label(()-> drawBlock == null ? "[gray]None[]" : "[accent]" + drawBlock.localizedName + "[] "+ drawBlock.emoji());
t.add(search).growX().pad(8).name("search");
}).growX().row();
display.add(new OverScrollPane(rebuildEditor(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("editor-pane").row();
}));
displays.put(Icon.settings, new Table(display -> {
display.add(new OverScrollPane(rebuildRule(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("rule-pane").row();
}));
table.table(buttons -> {
buttons.top().left();
displays.each((icon, display) -> {
buttons.button(icon, Styles.clearTogglei, ()->{
Log.info(table.getChildren().get(table.getChildren().size-1));
if(table.getChildren().size > 1) table.getChildren().get(table.getChildren().size-1).remove();
table.add(display).grow();
}).row();
});
}).growY();
}
@Override
public void update() {
heat += Time.delta;
if(heat >= 60f) {
heat = 0f;
if(lastw != window.getWidth() || lasth != window.getHeight()) resetPane();
lastw = width;
lasth = height;
}
Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
if(tile == null || tool == null || brushSize < 1 || drawBlock == null || hasMouse()) return;
if(Core.input.isTouched()) {
if((tool == EditorTool.line && drawing) || (!mobile && !Core.input.keyDown(KeyCode.mouseLeft))) return;
drawing = true;
lastx = tile.x;
lasty = tile.y;
tool.touched(lastx, lasty);
}
else {
if(tool == EditorTool.line && drawing) tool.touchedLine(lastx, lasty, tile.x, tile.y);
drawing = false;
lastx = -1;
lasty = -1;
}
}
void resetPane() {
ScrollPane pane = find("editor-pane");
if(pane != null) pane.setWidget(rebuildEditor());
}
Table rebuildRule() {
return new Table(table -> {
table.top().left();
table.table(rules -> {
rules.top().left();
Label label = rules.add("Block Health: ").get();
Slider slider = new Slider(0, 100, 1, false);
slider.changed(() -> {
label.setText("Block Health: "+(int)slider.getValue()+"%");
});
slider.change();
slider.moved(hp->Groups.build.each(b->b.health(b.block.health*hp/100)));
rules.add(slider);
}).grow();
});
}
Table rebuildEditor() {
return new Table(table-> {
table.top();
Seq<Block> blocks = Vars.content.blocks().copy();
if(search.getText().length() > 0){
blocks.filter(p -> p.name.toLowerCase().contains(search.getText().toLowerCase())||p.localizedName.toLowerCase().contains(search.getText().toLowerCase()));
}
table.table(select-> this.buildBlockSelection(null, select, blocks, ()-> drawBlock, block-> drawBlock =block, false)).marginTop(16f).marginBottom(16f).row();
table.image().height(4f).color(Pal.gray).growX().row();
table.table(select-> this.buildTeamSelection(player.team(), select, Seq.with(Team.all), ()->drawTeam, block->drawTeam=block, false)).marginTop(16f).marginBottom(16f).row();
table.image().height(4f).color(Pal.gray).growX().row();
table.table(body-> {
body.table(tools -> {
tools.top().left();
tools.table(title -> title.left().background(Tex.underline2).add("Tools [accent]"+(tool==null?"":tool.name())+"[]")).growX().row();
tools.table(bt->{
Cons<EditorTool> addTool = tool -> {
ImageButton button = new ImageButton(ui.getIcon(tool.name()), Styles.clearTogglei);
button.clicked(() -> {
button.toggle();
if(this.tool==tool) this.tool = null;
else this.tool = tool;
resetPane();
});
button.update(()->button.setChecked(this.tool == tool));
Label mode = new Label("");
mode.setColor(Pal.remove);
mode.update(() -> mode.setText(tool.mode == -1 ? "" : "M" + (tool.mode + 1) + " "));
mode.setAlignment(Align.bottomRight, Align.bottomRight);
mode.touchable = Touchable.disabled;
bt.stack(button, mode);
};
addTool.get(EditorTool.line);
addTool.get(EditorTool.pencil);
addTool.get(EditorTool.eraser);
addTool.get(EditorTool.fill);
addTool.get(EditorTool.spray);
ImageButton grid = new ImageButton(Icon.grid, Styles.clearTogglei);
grid.clicked(() -> {
grid.toggle();
Core.settings.put("grid", !Core.settings.getBool("grid"));
});
grid.update(()->grid.setChecked(Core.settings.getBool("grid")));
bt.add(grid);
});
tools.row();
Slider slider = new Slider(0, MapEditor.brushSizes.length - 1, 1, false);
slider.moved(f -> brushSize = MapEditor.brushSizes[(int)f]);
for(int j = 0; j < MapEditor.brushSizes.length; j++){
if(MapEditor.brushSizes[j] == brushSize){
slider.setValue(j);
}
}
Label label = new Label("Brush: "+brushSize);
label.touchable = Touchable.disabled;
tools.stack(slider, label).width(getDisplayWidth()/5).center();
}).left().width(getDisplayWidth() / 2).margin(8f).growY();
body.image().width(4f).height(body.getHeight()).color(Pal.gray).growY();
body.table(options -> {
options.top().left();
options.table(title -> title.left().background(Tex.underline2).add("Options [accent]"+(tool!=null&&tool.mode>=0&&tool.mode<tool.altModes.length?tool.altModes[tool.mode]:"")+"[]")).growX().row();
options.table(option-> {
if(tool==null) return;
option.top().left();
for (int i = 0; i < tool.altModes.length; i++) {
int mode = i;
String name = tool.altModes[i];
option.button(b -> {
b.left().marginLeft(6);
b.setStyle(Styles.clearTogglei);
b.add(Core.bundle.get("toolmode." + name)).left().row();
b.add(Core.bundle.get("toolmode." + name + ".description")).color(Color.lightGray).left();
}, () -> tool.mode = (tool.mode == mode ? -1 : mode)).update(b -> b.setChecked(tool.mode == mode)).margin(12f).growX().row();
}
}).grow();
}).left().width(getDisplayWidth() / 2).margin(8f).growY();
}).grow();
});
}
<T extends Block> void buildBlockSelection(@Nullable Block block, Table table, Seq<T> items, Prov<T> holder, Cons<T> consumer, boolean closeSelect){
ButtonGroup<ImageButton> group = new ButtonGroup<>();
group.setMinCheckCount(0);
Table cont = new Table();
cont.defaults().size(40);
int i = 0;
int row = 4;
int max = Math.max(row, Math.round(getDisplayWidth()/2/8/row));
for(T item : items){
if(!item.unlockedNow()) continue;
ImageButton button = cont.button(Tex.whiteui, Styles.clearTogglei, 24, () -> {
if(closeSelect) control.input.config.hideConfig();
}).group(group).tooltip(t->t.background(Styles.black8).add(item.localizedName.replace(search.getText(), "[accent]"+search.getText()+"[]"))).get();
button.changed(() -> consumer.get(button.isChecked() ? item : null));
button.getStyle().imageUp = new TextureRegionDrawable(item.uiIcon);
button.update(() -> button.setChecked(holder.get() == item));
if(i++ % max == max-1){
cont.row();
}
}
//add extra blank spaces so it looks nice
if(i % max != 0){
int remaining = max - (i % max);
for(int j = 0; j < remaining; j++){
cont.image(Styles.black6);
}
}
ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
pane.setScrollingDisabled(true, false);
pane.setScrollYForce(blockScroll);
pane.update(() -> blockScroll = pane.getScrollY());
pane.setOverscroll(false, false);
table.add(pane).maxHeight(Scl.scl(row * 10 * 5));
}
float blockScroll;
<T extends Team> void buildTeamSelection(@Nullable Team team, Table table, Seq<T> items, Prov<T> holder, Cons<T> consumer, boolean closeSelect){
ButtonGroup<ImageButton> group = new ButtonGroup<>();
group.setMinCheckCount(0);
Table cont = new Table();
cont.defaults().size(40);
int i = 0;
int row = 2;
int max = Math.max(row, Math.round(getDisplayWidth()/2/8/row/2));
for(T item : items){
ImageButton button = cont.button(Tex.whiteui, Styles.clearTogglei, 24, () -> {
if(closeSelect) control.input.config.hideConfig();
}).group(group).tooltip(t->t.background(Styles.black8).add(item.localized().replace(search.getText(), "[accent]"+search.getText()+"[]"))).with(img -> img.getStyle().imageUpColor = item.color).get();
button.changed(() -> consumer.get(button.isChecked() ? item : null));
button.update(() -> button.setChecked(holder.get() == item));
if(i++ % max == max-1){
cont.row();
}
}
//add extra blank spaces so it looks nice
if(i % max != 0){
int remaining = max - (i % max);
for(int j = 0; j < remaining; j++){
cont.image(Styles.black6);
}
}
ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
pane.setScrollingDisabled(true, false);
pane.setScrollYForce(teamScroll);
pane.update(() -> teamScroll = pane.getScrollY());
pane.setOverscroll(false, false);
table.add(pane).maxHeight(Scl.scl(row * 10 * 5));
}
float teamScroll;
float getDisplayWidth() {
return window.getWidth() - (window.find("buttons") == null ? 1 : window.find("buttons").getWidth());
}
public void drawBlocksReplace(int x, int y){
drawBlocks(x, y, tile -> tile.block() != Blocks.air || drawBlock.isFloor());
}
public void drawBlocks(int x, int y){
drawBlocks(x, y, false, tile -> true);
}
public void drawBlocks(int x, int y, Boolf<Tile> tester){
drawBlocks(x, y, false, tester);
}
int rotation = 0;
public void drawBlocks(int x, int y, boolean square, Boolf<Tile> tester){
if(drawBlock.isMultiblock()){
x = Mathf.clamp(x, (drawBlock.size - 1) / 2, world.width() - drawBlock.size / 2 - 1);
y = Mathf.clamp(y, (drawBlock.size - 1) / 2, world.height() - drawBlock.size / 2 - 1);
if(!hasOverlap(x, y)){
world.tile(x, y).setBlock(drawBlock, drawTeam, rotation);
}
}else{
boolean isFloor = drawBlock.isFloor() && drawBlock != Blocks.air;
Cons<Tile> drawer = tile -> {
if(!tester.get(tile)) return;
if(isFloor){
tile.setFloor(drawBlock.asFloor());
}else if(!(tile.block().isMultiblock() && !drawBlock.isMultiblock())){
tile.setBlock(drawBlock, drawTeam, rotation);
}
};
if(square){
drawSquare(x, y, drawer);
}else{
drawCircle(x, y, drawer);
}
}
}
public void drawCircle(int x, int y, Cons<Tile> drawer){
int clamped = (int)brushSize;
for(int rx = -clamped; rx <= clamped; rx++){
for(int ry = -clamped; ry <= clamped; ry++){
if(Mathf.within(rx, ry, brushSize - 0.5f + 0.0001f)){
int wx = x + rx, wy = y + ry;
if(wx < 0 || wy < 0 || wx >= world.width() || wy >= world.height()){
continue;
}
drawer.get(world.tile(wx, wy));
}
}
}
}
public void drawSquare(int x, int y, Cons<Tile> drawer){
int clamped = (int)brushSize;
for(int rx = -clamped; rx <= clamped; rx++){
for(int ry = -clamped; ry <= clamped; ry++){
int wx = x + rx, wy = y + ry;
if(wx < 0 || wy < 0 || wx >= world.width() || wy >= world.height()){
continue;
}
drawer.get(world.tile(wx, wy));
}
}
}
boolean hasOverlap(int x, int y){
Tile tile = world.tile(x, y);
//allow direct replacement of blocks of the same size
if(tile != null && tile.isCenter() && tile.block() != drawBlock && tile.block().size == drawBlock.size && tile.x == x && tile.y == y){
return false;
}
//else, check for overlap
int offsetx = -(drawBlock.size - 1) / 2;
int offsety = -(drawBlock.size - 1) / 2;
for(int dx = 0; dx < drawBlock.size; dx++){
for(int dy = 0; dy < drawBlock.size; dy++){
int worldx = dx + offsetx + x;
int worldy = dy + offsety + y;
Tile other = world.tile(worldx, worldy);
if(other != null && other.block().isMultiblock()){
return true;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,121 @@
package informatis.ui.window;
import informatis.ui.OverScrollPane;
import informatis.ui.Updatable;
import arc.Core;
import arc.graphics.Color;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Lines;
import arc.math.geom.Vec2;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.scene.utils.Elem;
import arc.struct.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.input.DesktopInput;
import mindustry.ui.*;
import static mindustry.Vars.*;
public class PlayerWindow extends Window implements Updatable {
Vec2 scrollPos = new Vec2(0, 0);
TextField search;
ImageButton.ImageButtonStyle ustyle;
@Nullable Player target;
float heat;
public PlayerWindow() {
super(Icon.players, "player");
}
@Override
public void build(Table table) {
scrollPos = new Vec2(0, 0);
search = Elem.newField(null, f->{});
search.setMessageText(Core.bundle.get("players.search"));
ustyle = new ImageButton.ImageButtonStyle(){{
down = Styles.none;
up = Styles.none;
imageDownColor = Pal.accent;
imageUpColor = Color.white;
imageOverColor = Color.lightGray;
}};
table.background(Styles.black8).top();
table.label(()-> Core.bundle.format(Groups.player.size() == 1 ? "players.single" : "players", Groups.player.size())).row();
table.add(search).growX().pad(8).name("search").maxTextLength(maxNameLength).row();
table.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("player-pane");
}
@Override
public void update() {
heat += Time.delta;
if(heat >= 60f) {
heat = 0f;
ScrollPane pane = find("player-pane");
pane.setWidget(rebuild());
}
if(target!=null) {
if(control.input instanceof DesktopInput)
((DesktopInput) control.input).panning = true;
Core.camera.position.set(target.x, target.y);
}
}
public Table rebuild(){
return new Table(table -> {
float h = 74f;
Seq<Player> players = Groups.player.copy(new Seq<>());
players.sort(Structs.comps(Structs.comparing(Player::team), Structs.comparingBool(p -> !p.admin)));
if(search.getText().length() > 0){
players.filter(p -> Strings.stripColors(p.name().toLowerCase()).contains(search.getText().toLowerCase()));
}
if(players.isEmpty()){
table.add(Core.bundle.format("players.notfound")).center();
return;
}
for(Player user : players){
table.table(userTable-> {
userTable.left().margin(5).marginBottom(10);
Table table1 = new Table(){
@Override
public void draw(){
super.draw();
Draw.color(target==user?Pal.accent:Pal.gray);
Draw.alpha(parentAlpha);
Lines.stroke(Scl.scl(4f));
Lines.rect(x, y, width, height);
Draw.reset();
}
};
table1.margin(8);
table1.add(new Image(user.icon()).setScaling(Scaling.bounded)).grow();
table1.clicked(() -> {
if(target==user) target = null;
else target = user;
});
userTable.add(table1).size(h).name(user.name()); //unit icon
userTable.labelWrap(user.name()).color(user.color()).width(170f).pad(10); //name
userTable.image(Icon.admin).padRight(5).visible(()->user.admin); //admin
userTable.button(Icon.hammer, ustyle, () -> { //vote kick
ui.showConfirm("@confirm", Core.bundle.format("confirmvotekick", user.name()), () -> {
Call.sendChatMessage("/votekick " + user.name());
});
}).right().visible(()->user.team()==player.team()&&user!=player&&!user.admin);
}).padBottom(-6).maxHeight(h + 14).row();
table.image().height(4f).color(state.rules.pvp ? user.team().color : Pal.gray).growX().row();
}
});
}
}

View File

@@ -0,0 +1,74 @@
package informatis.ui.window;
import informatis.ui.OverScrollPane;
import informatis.ui.Updatable;
import informatis.ui.draws.OverDraw;
import informatis.ui.draws.OverDraws;
import arc.math.geom.Vec2;
import arc.scene.ui.ScrollPane;
import arc.scene.ui.layout.Table;
import arc.util.Time;
import mindustry.gen.Icon;
import mindustry.gen.Tex;
import mindustry.graphics.Pal;
import mindustry.ui.Styles;
public class ToolWindow extends Window implements Updatable {
Vec2 scrollPos = new Vec2(0, 0);
OverDraw selected;
float heat;
public ToolWindow() {
super(Icon.edit, "tool");
}
@Override
public void build(Table table) {
scrollPos = new Vec2(0, 0);
table.background(Styles.black8).top().left();
table.table(pane->{
pane.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).name("tool-pane");
}).top().marginLeft(4f).marginRight(12f);
table.table(stats->{
stats.top();
stats.add(rebuildStats()).name("tool-stats");
}).growY();
}
@Override
public void update() {
heat += Time.delta;
if(heat >= 60f) {
heat = 0f;
ScrollPane pane = find("tool-pane");
pane.setWidget(rebuild());
}
}
Table rebuild() {
return new Table(icons->{
for(OverDraw draw : OverDraws.all) {
icons.button(draw.icon, ()->{
selected=draw;
Table table = find("tool-stats");
table.clearChildren();
table.add(rebuildStats());
}).grow().tooltip(t->t.background(Styles.black8).add(draw.name).color(Pal.accent)).row();
}
});
}
Table rebuildStats() {
return new Table(tool->{
if(selected==null) return;
tool.top();
tool.table(Tex.underline2, label->label.add(selected.name).color(Pal.accent)).row();
tool.table(des-> selected.displayStats(des)).name("unit-stats").row();
tool.check("enable", selected.enabled, c->{
selected.enabled=c;
selected.onEnabled(find("unit-stats"));
});
});
}
}

View File

@@ -0,0 +1,253 @@
package informatis.ui.window;
import arc.math.Mathf;
import informatis.core.*;
import informatis.ui.*;
import arc.graphics.Color;
import arc.graphics.g2d.*;
import arc.math.geom.*;
import arc.scene.style.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.Bits;
import arc.struct.*;
import arc.util.*;
import mindustry.Vars;
import mindustry.core.UI;
import mindustry.entities.units.WeaponMount;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.type.StatusEffect;
import mindustry.type.Weapon;
import mindustry.ui.Styles;
import mindustry.world.blocks.ConstructBlock;
import mindustry.world.blocks.payloads.Payload;
import static informatis.SVars.*;
import static informatis.SUtils.*;
import static mindustry.Vars.*;
class UnitWindow extends Window {
final Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
final Rect scissor = new Rect();
Seq<Table> bars = new Seq<>(); //temp
Vec2 scrollPos = new Vec2(0, 0);
public UnitWindow() {
super(Icon.units, "unit");
for(int i = 0; i < 6; i++) addBar();
}
//TODO: add new UnitInfoDisplay(), new WeaponDisplay();
@Override
protected void build(Table table) {
scrollPos = new Vec2(0, 0);
table.top().background(Styles.black8);
table.table(tt -> {
tt.center();
Image image = new Image() {
@Override
public void draw() {
super.draw();
int offset = 8;
Draw.color(locked?Pal.accent:Pal.gray);
Draw.alpha(parentAlpha);
Lines.stroke(Scl.scl(3f));
Lines.rect(x-offset/2f, y-offset/2f, width+offset, height+offset);
Draw.reset();
}
};
image.update(()->{
TextureRegion region = clear;
if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
else if (target instanceof Building b) {
if (target instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon;
else if (b.block != null) region = b.block.uiIcon;
}
image.setDrawable(region);
});
image.clicked(()->{
if(target==getTarget()) locked = !locked;
target = getTarget();
});
tt.add(image).size(iconMed).padRight(12f);
tt.label(() -> {
if (target instanceof Unit u && u.type != null) return u.type.localizedName;
if (target instanceof Building b && b.block != null) {
if (target instanceof ConstructBlock.ConstructBuild cb) return cb.current.localizedName;
return b.block.localizedName;
}
return "";
}).color(Pal.accent);
}).tooltip((to -> {
to.background(Styles.black6);
to.label(() -> target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI").row();
to.label(() -> target == null ? "(" + 0 + ", " + 0 + ")" : "(" + Strings.fixed(target.x() / tilesize, 2) + ", " + Strings.fixed(target.y() / tilesize, 2) + ")").row();
to.label(() -> target instanceof Unit u ? "[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor" : "");
})).margin(12f).row();
table.image().height(4f).color((target==null?player.unit():target).team().color).growX().row();
table.add(new OverScrollPane(new Table(bars -> {
bars.top();
bars.table().update(t->{
t.clear();
this.bars.clear();
for(int i = 0; i < 6; i++) addBar();
for (Table bar : this.bars) {
t.add(bar).growX().row();
}
}).growX();
}), Styles.noBarPane, scrollPos).disableScroll(true, false)).growX().padTop(12f);
}
void addBar() {
int index = this.bars.size;
bars.add(new Table(bar -> {
bar.add(new SBar(
() -> {
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
return data == null ? "[lightgray]<Empty>[]" : data.name;
},
() -> {
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
if (index >= lastColors.size) lastColors.size = index+1;
if (data == null) return lastColors.get(index);
if (data.color != Color.clear) lastColors.set(index, data.color);
return lastColors.get(index);
},
() -> {
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
return data == null ? 0 : data.number;
}
)).height(4 * 8f).growX();
bar.add(new Image(){
@Override
public void draw() {
validate();
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
Draw.color(Color.white);
Draw.alpha(parentAlpha * color.a);
if(data == null) {
new TextureRegionDrawable(clear).draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
return;
}
TextureRegionDrawable region = new TextureRegionDrawable(data.icon);
region.draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
Draw.color(data.color);
if(ScissorStack.push(scissor.set(x, y, imageWidth * scaleX, imageHeight * scaleY * data.number))){
region.draw(x, y, imageWidth * scaleX, imageHeight * scaleY);
ScissorStack.pop();
}
}
}).size(iconMed * 0.75f).padLeft(8f);
}));
}
static class WeaponDisplay extends Table {
WeaponDisplay() {
table().update(tt -> {
tt.clear();
if(getTarget() instanceof Unit u && u.type != null && u.hasWeapons()) {
for(int r = 0; r < u.type.weapons.size; r++){
Weapon weapon = u.type.weapons.get(r);
WeaponMount mount = u.mounts[r];
int finalR = r;
tt.table(ttt -> {
ttt.left();
if((1 + finalR) % 4 == 0) ttt.row();
ttt.stack(
new Table(o -> {
o.left();
o.add(new Image(!weapon.name.equals("") && weapon.outlineRegion.found() ? weapon.outlineRegion : u.type.uiIcon){
@Override
public void draw(){
validate();
float x = this.x;
float y = this.y;
float scaleX = this.scaleX;
float scaleY = this.scaleY;
Draw.color(color);
Draw.alpha(parentAlpha * color.a);
if(getDrawable() instanceof TransformDrawable){
float rotation = getRotation();
if(scaleX != 1 || scaleY != 1 || rotation != 0){
getDrawable().draw(x + imageX, y + imageY, originX - imageX, originY - imageY, imageWidth, imageHeight, scaleX, scaleY, rotation);
return;
}
}
y -= (mount.reload) / weapon.reload * weapon.recoil;
if(getDrawable() != null)
getDrawable().draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
}
}).size(iconLarge);
}),
new Table(h -> {
h.defaults().growX().height(9f).width(iconLarge).padTop(18f);
h.add(new SBar(
() -> "",
() -> Pal.accent.cpy().lerp(Color.orange, mount.reload / weapon.reload),
() -> mount.reload / weapon.reload).rect().init());
h.pack();
})
);
}).pad(4);
}
}
});
}
}
static class UnitInfoDisplay extends Table {
UnitInfoDisplay() {
top();
float[] count = new float[]{-1};
table().update(t -> {
if(getTarget() instanceof Payloadc payload){
if(count[0] != payload.payloadUsed()){
t.clear();
t.top().left();
float pad = 0;
float items = payload.payloads().size;
if(8 * 2 * items + pad * items > 275f){
pad = (275f - (8 * 2) * items) / items;
}
int i = 0;
for(Payload p : payload.payloads()){
t.image(p.icon()).size(8 * 2).padRight(pad);
if(++i % 12 == 0) t.row();
}
count[0] = payload.payloadUsed();
}
}else{
count[0] = -1;
t.clear();
}
}).growX().visible(() -> getTarget() instanceof Payloadc p && p.payloadUsed() > 0).colspan(2).row();
Bits statuses = new Bits();
table().update(t -> {
t.left();
if(getTarget() instanceof Statusc st){
Bits applied = st.statusBits();
if(!statuses.equals(applied)){
t.clear();
if(applied != null){
for(StatusEffect effect : Vars.content.statusEffects()){
if(applied.get(effect.id) && !effect.isHidden()){
t.image(effect.uiIcon).size(iconSmall).get()
.addListener(new Tooltip(l -> l.label(() -> effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel)));
}
}
statuses.set(applied);
}
}
}
}).left();
}
}
}

View File

@@ -0,0 +1,207 @@
package informatis.ui.window;
import mindustry.Vars;
import mindustry.type.UnitType;
import informatis.ui.OverScrollPane;
import arc.Events;
import arc.graphics.Color;
import arc.math.Mathf;
import arc.math.geom.Vec2;
import arc.scene.event.Touchable;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.content.StatusEffects;
import mindustry.game.EventType;
import mindustry.game.SpawnGroup;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.ui.*;
import informatis.ui.Updatable;
import static arc.Core.*;
import static arc.Core.settings;
import static mindustry.Vars.*;
public class WaveWindow extends Window implements Updatable {
static Vec2 scrollPos = new Vec2(0, 0);
Table window;
float heat;
public WaveWindow() {
super(Icon.waves, "wave");
}
@Override
public void build(Table table) {
window = 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();
table.table(total -> {
total.left();
total.label(()->"~"+state.wave+"+");
total.field(""+settings.getInt("wavemax"), f->{
String str = f.replaceAll("\\D", "");
if(str.isEmpty()) settings.put("wavemax", 0);
else settings.put("wavemax", Integer.parseInt(str));
});
total.table().update(units->{
units.clear();
units.center();
if(Groups.unit.count(u->u.team==state.rules.waveTeam) <= 0) {
units.add("[lightgray]<Empty>[]");
return;
}
int row = 0;
int max = Math.max(1, Math.round(window.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;
units.stack(
new Table(ttt -> {
ttt.center();
ttt.image(unit.uiIcon).size(iconMed);
ttt.pack();
}),
new Table(ttt -> {
ttt.bottom().left();
ttt.add(amount + "").padTop(2f).fontScale(0.9f);
ttt.pack();
})
).pad(2f);
if(row++ % max == max-1){
units.row();
}
}
}).growX();
}).growX().row();
table.image().height(4f).color(Pal.gray).growX().row();
table.table(option->{
option.check("Show empty wave", settings.getBool("emptywave"), b->settings.put("emptywave", b)).margin(4f);
option.check("Show previous wave", settings.getBool("pastwave"), b->settings.put("pastwave", b)).margin(4f);
});
Events.on(EventType.WorldLoadEvent.class, e -> {
pane.clearChildren();
pane.setWidget(rebuild());
});
Events.on(EventType.WaveEvent.class, e -> {
pane.clearChildren();
pane.setWidget(rebuild());
});
}
@Override
public void update() {
heat += Time.delta;
if(heat >= 60f) {
heat = 0f;
ScrollPane pane = find("wave-pane");
pane.setWidget(rebuild());
}
}
public ObjectIntMap<SpawnGroup> getWaveGroup(int index) {
ObjectIntMap<SpawnGroup> groups = new ObjectIntMap<>();
for (SpawnGroup group : state.rules.spawns) {
if (group.getSpawned(index) <= 0) continue;
SpawnGroup sameTypeKey = groups.keys().toArray().find(g -> g.type == group.type && g.effect != StatusEffects.boss);
if (sameTypeKey != null) groups.increment(sameTypeKey, sameTypeKey.getSpawned(index));
else groups.put(group, group.getSpawned(index));
}
Seq<SpawnGroup> groupSorted = groups.keys().toArray().copy().sort((g1, g2) -> {
int boss = Boolean.compare(g1.effect != StatusEffects.boss, g2.effect != StatusEffects.boss);
if (boss != 0) return boss;
int hitSize = Float.compare(-g1.type.hitSize, -g2.type.hitSize);
if (hitSize != 0) return hitSize;
return Integer.compare(-g1.type.id, -g2.type.id);
});
ObjectIntMap<SpawnGroup> groupsTmp = new ObjectIntMap<>();
groupSorted.each(g -> groupsTmp.put(g, groups.get(g)));
return groupsTmp;
}
Table rebuild(){
return new Table(table -> {
table.touchable = Touchable.enabled;
table.table(body->{
body.center();
for (int i = settings.getBool("pastwave") ? 1 : state.wave; i <= Math.min(state.wave + settings.getInt("wavemax"), (state.isCampaign() && state.rules.winWave > 0 ? state.rules.winWave : Integer.MAX_VALUE)); i++) {
final int index = i;
if (state.rules.spawns.find(g -> g.getSpawned(index-1) > 0) == null && !settings.getBool("emptywave")) continue;
body.table(waveRow -> {
waveRow.left();
waveRow.add(index+"").update(label -> {
Color color = Pal.accent;
if (state.wave == index) color = Color.red;
else if (state.wave - 1 == index && state.enemies > 0) color = Color.red.cpy().shiftHue(Time.time);
label.setColor(color);
});
waveRow.table(unitTable -> {
unitTable.center();
if (state.rules.spawns.find(g -> g.getSpawned(index-1) > 0) == null) {
if (settings.getBool("emptywave")) unitTable.add(bundle.get("empty"));
return;
}
ObjectIntMap<SpawnGroup> groups = getWaveGroup(index-1);
int row = 0;
int max = Math.max(1, Math.round(window.getWidth()/2/8));
for (SpawnGroup group : groups.keys()) {
int spawners = state.rules.waveTeam.cores().size + (group.type.flying ? spawner.countFlyerSpawns() : spawner.countGroundSpawns());
int amount = groups.get(group);
unitTable.stack(
new Table(ttt -> {
ttt.center();
ttt.image(group.type.uiIcon).size(iconMed);
ttt.pack();
}),
new Table(ttt -> {
ttt.bottom().left();
ttt.add(amount + "").padTop(2f).fontScale(0.9f);
ttt.add("[gray]x" + spawners).padTop(10f).fontScale(0.7f);
ttt.pack();
}),
new Table(ttt -> {
ttt.top().right();
ttt.image(Icon.warning.getRegion()).update(img -> img.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f)))).size(12f);
ttt.visible(() -> group.effect == StatusEffects.boss);
ttt.pack();
})
).pad(2f).get().addListener(new Tooltip(to -> {
to.background(Styles.black6);
to.margin(4f).left();
to.add("[stat]" + group.type.localizedName + "[]").row();
to.row();
to.add(bundle.format("shar-stat-waveAmount", amount + " [lightgray]x" + spawners + "[]")).row();
to.add(bundle.format("shar-stat-waveShield", group.getShield(index-1))).row();
if (group.effect != null && group.effect != StatusEffects.none)
to.add(bundle.get("shar-stat.waveStatus") + group.effect.emoji() + "[stat]" + group.effect.localizedName).row();
}));
if(row++ % max == max-1){
unitTable.row();
}
}
}).growX().margin(12f);
}).growX().row();
body.image().height(4f).color(Pal.gray).growX().row();
}
}).grow().margin(40f);
});
}
}

View File

@@ -0,0 +1,135 @@
package informatis.ui.window;
import arc.*;
import arc.func.*;
import arc.input.*;
import arc.math.geom.*;
import arc.scene.event.*;
import arc.scene.style.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.ui.*;
import informatis.ui.WindowManager;
public class Window extends Table{
public TextureRegionDrawable icon;
public int id;
public Cons<Table> content;
public boolean shown = false;
public float minWindowWidth = 160, minWindowHeight = 60;
public float maxWindowWidth = Float.MAX_VALUE, maxWindowHeight = Float.MAX_VALUE;
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;
this.icon = icon;
titleBar();
pane(t -> {
t.setBackground(Styles.black5);
t.top().left();
build(t);
}).grow().top().left().get().setScrollingDisabled(true, true);
bottomBar();
setPosition(Core.graphics.getWidth() / 2f - getWidth() / 2f, Core.graphics.getHeight() / 2f - getHeight() / 2f);
id = WindowManager.register(this);
visible(() -> shown);
}
protected void build(Table t){
if(content != null) content.get(t);
}
protected void titleBar(){
table(t -> {
// icon and title
t.table(Tex.buttonEdge1, b -> {
b.top().left();
b.image(() -> icon == null ? Icon.none.getRegion() : icon.getRegion()).size(20f).padLeft(15).top().left();
b.pane(Styles.noBarPane, p -> {
p.top().left();
p.labelWrap(() -> Core.bundle.get("window."+name+".name")).padLeft(20).top().left().get().setAlignment(Align.topLeft);
}).left().height(40f).growX().get().setScrollingDisabled(true, true);
}).maxHeight(40f).grow();
// exit button
t.table(Tex.buttonEdge3, b -> {
b.button(Icon.cancel, Styles.emptyi, () -> shown = false);
}).maxHeight(40f).width(80f).growY();
// handles the dragging.
t.touchable = Touchable.enabled;
t.addListener(new InputListener(){
float lastX, lastY;
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button) {
Vec2 v = t.localToStageCoordinates(Tmp.v1.set(x, y));
lastX = v.x;
lastY = v.y;
toFront();
return true;
}
@Override
public void touchDragged(InputEvent event, float dx, float dy, int pointer) {
Vec2 v = t.localToStageCoordinates(Tmp.v1.set(dx, dy));
setPosition( x + (v.x - lastX), y + (v.y - lastY));
lastX = v.x;
lastY = v.y;
}
});
}).top().height(40f).growX();
row();
}
protected void bottomBar(){
row();
table(Styles.black5, t -> {
t.table().growX();
t.table(Icon.resizeSmall, r -> {
r.bottom().left();
r.touchable = Touchable.enabled;
r.addListener(new InputListener(){
float lastX, lastY;
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button) {
Vec2 v = r.localToStageCoordinates(Tmp.v1.set(x, y));
lastX = v.x;
lastY = v.y;
return true;
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
Vec2 v = r.localToStageCoordinates(Tmp.v1.set(x, y));
float w = v.x - lastX;
float h = v.y - lastY;
// will softlock if initial size is smaller than minimum
// so don't do that!
if(getWidth() + w < minWindowWidth || getWidth() + w > maxWindowWidth) w = 0;
if(getHeight() - h < minWindowHeight || getHeight() - h > maxWindowHeight) h = 0;
sizeBy(w, -h);
moveBy(0, h);
lastX = v.x;
lastY = v.y;
}
});
}).size(20f).left();
}).height(20f).growX();
}
public void toggle(){
shown = !shown;
}
}

View File

@@ -0,0 +1,14 @@
package informatis.ui.window;
public class Windows {
public static MapEditorWindow editorTable;
public static void load(){
new UnitWindow();
new WaveWindow();
new CoreWindow();
new PlayerWindow();
new ToolWindow();
editorTable = new MapEditorWindow();
}
}