Skip to content

Commit

Permalink
v1.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sharrlotte committed Nov 6, 2024
1 parent 2491805 commit eb7d719
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 199 deletions.
2 changes: 1 addition & 1 deletion mod.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ main: "mindytool.Main"

description: "A online schematic browser"

version: v1.8.5
version: v1.8.6

minGameVersion: 140

Expand Down
2 changes: 1 addition & 1 deletion src/mindytool/gui/SchematicDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private Cell<ScrollPane> SchematicScrollContainer(Table parent) {
}).growX().height(50f);

schematicPreview.row();
schematicPreview.stack(new SchematicImage(schematic), new Table(schematicName -> {
schematicPreview.stack(new SchematicImage(schematicData), new Table(schematicName -> {
schematicName.top();
schematicName.table(Styles.black3, c -> {
Label label = c.add(schematic.name()).style(Styles.outlineLabel).color(Color.white)
Expand Down
149 changes: 66 additions & 83 deletions src/mindytool/gui/SchematicImage.java
Original file line number Diff line number Diff line change
@@ -1,83 +1,66 @@
package mindytool.gui;

import arc.Core;
import arc.graphics.Color;
import arc.graphics.Texture;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Lines;
import arc.graphics.g2d.TextureRegion;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.Button;
import arc.scene.ui.Image;
import arc.scene.ui.layout.Scl;
import arc.util.Scaling;
import mindustry.game.Schematic;
import mindustry.gen.Icon;
import mindustry.gen.Tex;
import mindustry.graphics.Pal;

import static mindustry.Vars.*;

public class SchematicImage extends Image {
public float scaling = 16f;
public float thickness = 4f;
public Color borderColor = Pal.gray;

private Schematic schematic;
private Texture lastTexture;
boolean set;

public SchematicImage(Schematic s) {
super(Tex.clear);
setScaling(Scaling.fit);
schematic = s;

if (schematics.hasPreview(s)) {
setPreview();
set = true;
}
}

@Override
public void draw() {
boolean checked = parent.parent instanceof Button
&& ((Button) parent.parent).isOver();

boolean wasSet = set;
if (!set) {
Core.app.post(this::setPreview);
set = true;
} else if (lastTexture != null && lastTexture.isDisposed()) {
set = wasSet = false;
}

Texture background = Core.assets.get("sprites/schematic-background.png", Texture.class);
TextureRegion region = Draw.wrap(background);
float xr = width / scaling;
float yr = height / scaling;
region.setU2(xr);
region.setV2(yr);
Draw.color();
Draw.alpha(parentAlpha);
Draw.rect(region, x + width / 2f, y + height / 2f, width, height);

if (wasSet) {
super.draw();
} else {
Draw.rect(Icon.refresh.getRegion(), x + width / 2f, y + height / 2f, width / 4f, height / 4f);
}

Draw.color(checked ? Pal.accent : borderColor);
Draw.alpha(parentAlpha);
Lines.stroke(Scl.scl(thickness));
Lines.rect(x, y, width, height);
Draw.reset();
}

private void setPreview() {
TextureRegionDrawable draw = new TextureRegionDrawable(
new TextureRegion(lastTexture = schematics.getPreview(schematic)));
setDrawable(draw);
setScaling(Scaling.fit);
}
}
package mindytool.gui;

import arc.Core;
import arc.graphics.Color;
import arc.graphics.Pixmap;
import arc.graphics.Texture;
import arc.graphics.Texture.TextureFilter;
import arc.graphics.g2d.TextureRegion;
import arc.scene.ui.Image;
import arc.struct.ObjectMap;
import arc.util.Http;
import arc.util.Log;
import arc.util.Scaling;
import mindustry.gen.Tex;
import mindustry.graphics.Pal;
import mindytool.config.Config;
import mindytool.data.SchematicData;

public class SchematicImage extends Image {
public float scaling = 16f;
public float thickness = 4f;
public Color borderColor = Pal.gray;

private SchematicData schematicData;
private TextureRegion lastTexture;

private static ObjectMap<String, TextureRegion> textureCache = new ObjectMap<>();

public SchematicImage(SchematicData schematicData) {
super(Tex.clear);
setScaling(Scaling.fit);
this.schematicData = schematicData;
}

@Override
public void draw() {
super.draw();

// textures are only requested when the rendering happens; this assists with
// culling
if (!textureCache.containsKey(schematicData.id)) {
textureCache.put(schematicData.id, lastTexture = Core.atlas.find("nomap"));
Http.get(Config.IMAGE_URL + "schematics/" + schematicData.id + ".webp", res -> {
Pixmap pix = new Pixmap(res.getResult());
Core.app.post(() -> {
try {
var tex = new Texture(pix);
tex.setFilter(TextureFilter.linear);
textureCache.put(schematicData.id, new TextureRegion(tex));
pix.dispose();
} catch (Exception e) {
Log.err(e);
}
});
}, err -> {
Log.err(err);
});
}

var next = textureCache.get(schematicData.id);
if (lastTexture != next) {
lastTexture = next;
setDrawable(next);
}
}
}
224 changes: 110 additions & 114 deletions src/mindytool/gui/SchematicInfoDialog.java
Original file line number Diff line number Diff line change
@@ -1,114 +1,110 @@
package mindytool.gui;

import static mindustry.Vars.state;

import mindytool.data.ItemRequirement;
import mindytool.data.SchematicData;
import java.security.InvalidParameterException;

import arc.Core;
import arc.graphics.Color;
import arc.scene.ui.layout.Table;
import arc.struct.Seq;
import arc.util.Align;
import mindustry.Vars;
import mindustry.game.Schematic;
import mindustry.gen.Building;
import mindustry.gen.Icon;
import mindustry.gen.Tex;
import mindustry.type.ItemSeq;
import mindustry.type.ItemStack;
import mindustry.ui.dialogs.BaseDialog;

import static mindustry.Vars.*;

public class SchematicInfoDialog extends BaseDialog {

public SchematicInfoDialog() {
super("");

setFillParent(true);
addCloseListener();
}

public void show(Schematic schematic, SchematicData data) {
if (schematic == null) {
throw new InvalidParameterException("Schematic can not be null");
}
cont.clear();

title.setText("[[" + Core.bundle.get("schematic") + "] " + data.name);
cont.add(Core.bundle.format("message.like", data.like))
.color(Color.lightGray).row();
cont.add(new SchematicImage(schematic)).maxSize(800).row();
cont.table(tags -> buildTags(data, tags, false)).fillX().left().row();

ItemSeq arr = toItemSeq(data.requirement);
cont.table(r -> {
int i = 0;
for (ItemStack s : arr) {
r.image(s.item.uiIcon).left().size(iconMed);
r.label(() -> {
Building core = player.core();
if (core == null
|| state.isMenu()
|| state.rules.infiniteResources
|| core.items.has(s.item, s.amount))
return "[lightgray]" + s.amount;

return (core.items.has(s.item, s.amount) ? "[lightgray]" : "[scarlet]")
+ Math.min(core.items.get(s.item), s.amount) + "[lightgray]/" + s.amount;
}).padLeft(2).left().padRight(4);

if (++i % 4 == 0) {
r.row();
}
}
});
cont.row();
buttons.clearChildren();
buttons.defaults().size(Core.graphics.isPortrait() ? 150f : 210f, 64f);
buttons.button("@back", Icon.left, this::hide);
// buttons.button("@editor.export", Icon.upload, () -> showExport(schem));
// buttons.button("@edit", Icon.edit, () -> showEdit(schem));

show();
}

void buildTags(SchematicData schematic, Table container, boolean hasName) {
container.clearChildren();
container.left();

if (schematic.tags == null) {
return;
}

if (hasName)
container.add("@schematic.tags").padRight(4);

container.pane(scrollPane -> {
scrollPane.left();
scrollPane.defaults().pad(3).height(42);

for (var tag : schematic.tags)
scrollPane.table(Tex.button, i -> i.add(tag).padRight(4).height(42).labelAlign(Align.center));

}).fillX().left().height(42).scrollY(false);
}

public ItemSeq toItemSeq(ItemRequirement[] requirement) {
Seq<ItemStack> seq = new Seq<>();

if (requirement == null) {
return new ItemSeq(seq);
}

for (var req : requirement) {
seq.add(new ItemStack(
Vars.content.items().find(i -> i.name.toLowerCase().equals(req.name.toLowerCase())),
req.amount));
}

return new ItemSeq(seq);
}
}
package mindytool.gui;

import static mindustry.Vars.state;

import mindytool.data.ItemRequirement;
import mindytool.data.SchematicData;
import java.security.InvalidParameterException;

import arc.Core;
import arc.graphics.Color;
import arc.scene.ui.layout.Table;
import arc.struct.Seq;
import arc.util.Align;
import mindustry.Vars;
import mindustry.game.Schematic;
import mindustry.gen.Building;
import mindustry.gen.Icon;
import mindustry.gen.Tex;
import mindustry.type.ItemSeq;
import mindustry.type.ItemStack;
import mindustry.ui.dialogs.BaseDialog;

import static mindustry.Vars.*;

public class SchematicInfoDialog extends BaseDialog {

public SchematicInfoDialog() {
super("");

setFillParent(true);
addCloseListener();
}

public void show(Schematic schematic, SchematicData data) {
if (schematic == null) {
throw new InvalidParameterException("Schematic can not be null");
}
cont.clear();

title.setText("[[" + Core.bundle.get("schematic") + "] " + data.name);
cont.add(Core.bundle.format("message.like", data.like)).color(Color.lightGray).row();
cont.add(new SchematicImage(data)).maxSize(800).row();
cont.table(tags -> buildTags(data, tags, false)).fillX().left().row();

ItemSeq arr = toItemSeq(data.requirement);
cont.table(r -> {
int i = 0;
for (ItemStack s : arr) {
r.image(s.item.uiIcon).left().size(iconMed);
r.label(() -> {
Building core = player.core();
if (core == null || state.isMenu() || state.rules.infiniteResources
|| core.items.has(s.item, s.amount))
return "[lightgray]" + s.amount;

return (core.items.has(s.item, s.amount) ? "[lightgray]" : "[scarlet]")
+ Math.min(core.items.get(s.item), s.amount) + "[lightgray]/" + s.amount;
}).padLeft(2).left().padRight(4);

if (++i % 4 == 0) {
r.row();
}
}
});
cont.row();
buttons.clearChildren();
buttons.defaults().size(Core.graphics.isPortrait() ? 150f : 210f, 64f);
buttons.button("@back", Icon.left, this::hide);
// buttons.button("@editor.export", Icon.upload, () -> showExport(schem));
// buttons.button("@edit", Icon.edit, () -> showEdit(schem));

show();
}

void buildTags(SchematicData schematic, Table container, boolean hasName) {
container.clearChildren();
container.left();

if (schematic.tags == null) {
return;
}

if (hasName)
container.add("@schematic.tags").padRight(4);

container.pane(scrollPane -> {
scrollPane.left();
scrollPane.defaults().pad(3).height(42);

for (var tag : schematic.tags)
scrollPane.table(Tex.button, i -> i.add(tag).padRight(4).height(42).labelAlign(Align.center));

}).fillX().left().height(42).scrollY(false);
}

public ItemSeq toItemSeq(ItemRequirement[] requirement) {
Seq<ItemStack> seq = new Seq<>();

if (requirement == null) {
return new ItemSeq(seq);
}

for (var req : requirement) {
seq.add(new ItemStack(Vars.content.items().find(i -> i.name.toLowerCase().equals(req.name.toLowerCase())),
req.amount));
}

return new ItemSeq(seq);
}
}

0 comments on commit eb7d719

Please sign in to comment.