diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index 6cf768ac0b..2eae60336f 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -62,7 +62,6 @@ public class UI extends SceneModule{ public ContentInfoDialog content; public SectorsDialog sectors; public MissionDialog missions; - public UnlockGraphDialog graph; private Locale lastLocale; diff --git a/core/src/io/anuke/mindustry/ui/GraphSimulation.java b/core/src/io/anuke/mindustry/ui/GraphSimulation.java deleted file mode 100644 index a45039911e..0000000000 --- a/core/src/io/anuke/mindustry/ui/GraphSimulation.java +++ /dev/null @@ -1,119 +0,0 @@ -package io.anuke.mindustry.ui; - -import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.utils.Array; -import io.anuke.ucore.util.Mathf; -import io.anuke.ucore.util.SafeArray; - -public class GraphSimulation{ - public Array> vertices = new SafeArray<>(); - public Array> edges = new SafeArray<>(); - public int frameWidth; - public int frameHeight; - public boolean equi = false; - public float criterion = 1000; - public float coolingRate = 0.065f; - - private static final float C = 1f; - - private int iteration = 0; - private float k; - private float t; - private boolean equilibriumReached = false; - - private Vector2 deltaPos = new Vector2(); - - public int startSimulation() { - - iteration = 0; - equilibriumReached = false; - - int area = Math.min(frameWidth * frameWidth, frameHeight * frameHeight); - k = C * Mathf.sqrt(area / vertices.size); - t = frameWidth / 10; - - if (equi) { - while (!equilibriumReached && iteration < 10000) { - simulateStep(); - } - } else { - for (int i = 0; i < criterion; i++) { - simulateStep(); - } - } - return iteration; - } - - private void simulateStep() { - for (Vertex v : vertices) { - v.disp.set(0, 0); - for (Vertex u : vertices) { - if (v != u) { - deltaPos.set(v.pos).sub(u.pos); - float length = deltaPos.len(); - deltaPos.setLength(forceRepulsive(length, k)); - v.disp.add(deltaPos); - } - } - } - - for (Edge e : edges) { - deltaPos.set(e.v.pos).sub(e.u.pos); - float length = deltaPos.len(); - deltaPos.setLength(forceAttractive(length, k)); - - e.v.disp.sub(deltaPos); - e.u.disp.add(deltaPos); - } - - equilibriumReached = true; - - for (Vertex v : vertices) { - - deltaPos.set(v.disp); - float length = deltaPos.len(); - - if (length > criterion) { - equilibriumReached = false; - } - - deltaPos.setLength(Math.min(length, t)); - - v.pos.add(deltaPos); - v.pos.x = Mathf.clamp(v.pos.x, 0, frameWidth); - v.pos.y = Mathf.clamp(v.pos.y, 0, frameHeight); - } - - t = Math.max(t * (1 - coolingRate), 1); - iteration++; - } - - private float forceAttractive(float d, float k) { - return d * d / k; - } - - private float forceRepulsive(float d, float k) { - return k * k /d; - } - - public static class Vertex{ - public Vector2 pos = new Vector2(); - public final T value; - - private Vector2 disp = new Vector2(); - - public Vertex(T value){ - this.value = value; - } - } - - public static class Edge { - public final Vertex v; - public final Vertex u; - - public Edge(Vertex v, Vertex u) { - this.v = v; - this.u = u; - } - } -} diff --git a/core/src/io/anuke/mindustry/ui/dialogs/UnlockGraphDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/UnlockGraphDialog.java deleted file mode 100644 index c308c81f8d..0000000000 --- a/core/src/io/anuke/mindustry/ui/dialogs/UnlockGraphDialog.java +++ /dev/null @@ -1,97 +0,0 @@ -package io.anuke.mindustry.ui.dialogs; - -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.utils.Array; -import com.badlogic.gdx.utils.ObjectMap; -import io.anuke.mindustry.Vars; -import io.anuke.mindustry.game.UnlockableContent; -import io.anuke.mindustry.type.Item; -import io.anuke.mindustry.type.ItemStack; -import io.anuke.mindustry.type.ItemType; -import io.anuke.mindustry.type.Recipe; -import io.anuke.mindustry.ui.GraphSimulation; -import io.anuke.mindustry.ui.GraphSimulation.Edge; -import io.anuke.mindustry.ui.GraphSimulation.Vertex; -import io.anuke.ucore.graphics.Draw; -import io.anuke.ucore.graphics.Lines; -import io.anuke.ucore.util.Mathf; - -public class UnlockGraphDialog extends FloatingDialog{ - int frameSize = 1000; - ObjectMap> map = new ObjectMap<>(); - Array> vertices; - Array> edges; - - public UnlockGraphDialog(){ - super("$text.unlocks"); - - rebuild(); - } - - public void rebuild(){ - content().clear(); - - GraphSimulation sim = new GraphSimulation<>(); - sim.frameWidth = frameSize; - sim.frameHeight = frameSize; - vertices = sim.vertices; - edges = sim.edges; - - for(Item item : Vars.content.items()){ - if(item.type != ItemType.material) continue; - put(item); - } - - for(Recipe recipe : Vars.content.recipes()){ - if(recipe.requirements.length == 0) continue; - put(recipe); - - for(Item item : Vars.content.items()){ - for(ItemStack stack : recipe.requirements){ - if(stack.item == item){ - link(item, recipe); - break; - } - } - } - } - - sim.startSimulation(); - - content().addRect((x, y, w, h) -> { - float cx = x + w/2f, cy = y + h/2f; - float ox = cx - frameSize/2f, oy = cy - frameSize/2f; - - Draw.color(Color.DARK_GRAY); - Lines.stroke(4f); - - for(Edge e : edges){ - if(e.v.value instanceof Item){ - Draw.color(((Item) e.v.value).color); - } - Lines.line(e.u.pos.x + ox, e.u.pos.y + oy, e.v.pos.x + ox, e.v.pos.y + oy); - } - - Draw.color(); - - for(Vertex v : vertices){ - Draw.rect(v.value.getContentIcon(), v.pos.x + ox, v.pos.y + oy, 16*2f, 16*2f); - } - }).grow(); - } - - private Vertex get(UnlockableContent c){ - return map.get(c); - } - - private void put(UnlockableContent c){ - Vertex v = new Vertex<>(c); - v.pos.set(frameSize/2f + Mathf.range(frameSize/2f), frameSize/2f + Mathf.range(frameSize/2f)); - map.put(c, v); - vertices.add(v); - } - - private void link(UnlockableContent a, UnlockableContent b){ - edges.add(new Edge<>(get(a), get(b))); - } -}