From c637ec15ffff1f33285fca7312403d0b7b6ed2e5 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 12 Jan 2020 20:01:32 -0500 Subject: [PATCH] Deployment dialog replaced --- core/src/mindustry/core/UI.java | 4 +- core/src/mindustry/game/MusicControl.java | 2 +- .../graphics/{Pgrid.java => PlanetGrid.java} | 43 +++++++++++++------ core/src/mindustry/graphics/PlanetMesh.java | 6 +-- .../mindustry/graphics/PlanetRenderer.java | 17 +++----- .../mindustry/ui/dialogs/DeployDialog.java | 3 +- .../mindustry/ui/dialogs/GameOverDialog.java | 2 +- .../mindustry/ui/dialogs/PlanetDialog.java | 29 +++++++++++++ .../mindustry/ui/dialogs/TechTreeDialog.java | 2 +- .../mindustry/ui/dialogs/ZoneInfoDialog.java | 4 +- .../ui/fragments/FadeInFragment.java | 14 +++--- .../mindustry/ui/fragments/MenuFragment.java | 4 +- .../mindustry/desktop/DesktopLauncher.java | 2 +- 13 files changed, 87 insertions(+), 45 deletions(-) rename core/src/mindustry/graphics/{Pgrid.java => PlanetGrid.java} (87%) create mode 100644 core/src/mindustry/ui/dialogs/PlanetDialog.java diff --git a/core/src/mindustry/core/UI.java b/core/src/mindustry/core/UI.java index f1b578cc9c..e25c9482b8 100644 --- a/core/src/mindustry/core/UI.java +++ b/core/src/mindustry/core/UI.java @@ -67,7 +67,7 @@ public class UI implements ApplicationListener, Loadable{ public TraceDialog traces; public DatabaseDialog database; public ContentInfoDialog content; - public DeployDialog deploy; + public PlanetDialog planet; public TechTreeDialog tech; //public MinimapDialog minimap; public SchematicsDialog schematics; @@ -235,7 +235,7 @@ public class UI implements ApplicationListener, Loadable{ traces = new TraceDialog(); maps = new MapsDialog(); content = new ContentInfoDialog(); - deploy = new DeployDialog(); + planet = new PlanetDialog(); tech = new TechTreeDialog(); mods = new ModsDialog(); schematics = new SchematicsDialog(); diff --git a/core/src/mindustry/game/MusicControl.java b/core/src/mindustry/game/MusicControl.java index 26a44876ac..05624dab15 100644 --- a/core/src/mindustry/game/MusicControl.java +++ b/core/src/mindustry/game/MusicControl.java @@ -48,7 +48,7 @@ public class MusicControl{ public void update(){ if(state.is(State.menu)){ silenced = false; - if(ui.deploy.isShown()){ + if(ui.planet.isShown()){ play(Musics.launch); }else if(ui.editor.isShown()){ play(Musics.editor); diff --git a/core/src/mindustry/graphics/Pgrid.java b/core/src/mindustry/graphics/PlanetGrid.java similarity index 87% rename from core/src/mindustry/graphics/Pgrid.java rename to core/src/mindustry/graphics/PlanetGrid.java index 44462981b4..83d942ba1e 100644 --- a/core/src/mindustry/graphics/Pgrid.java +++ b/core/src/mindustry/graphics/PlanetGrid.java @@ -4,7 +4,7 @@ import arc.math.*; import arc.math.geom.*; import arc.util.*; -class Pgrid{ +class PlanetGrid{ private static final float x = -0.525731112119133606f; private static final float z = -0.850650808352039932f; @@ -14,18 +14,20 @@ class Pgrid{ new Vec3(z, x, 0), new Vec3(-z, x, 0), new Vec3(z, -x, 0), new Vec3(-z, -x, 0) }; - private static final int[][] iTilesP = { + private static final int[][] iTilesP = { {9, 4, 1, 6, 11}, {4, 8, 10, 6, 0}, {11, 7, 3, 5, 9}, {2, 7, 10, 8, 5}, {9, 5, 8, 1, 0}, {2, 3, 8, 4, 9}, {0, 1, 10, 7, 11}, {11, 6, 10, 3, 2}, {5, 3, 10, 1, 4}, {2, 5, 4, 0, 11}, {3, 7, 6, 1, 8}, {7, 2, 9, 0, 6} }; + private static PlanetGrid[] cache = new PlanetGrid[10]; + int size; Ptile[] tiles; Corner[] corners; Edge[] edges; - Pgrid(int size){ + PlanetGrid(int size){ this.size = size; tiles = new Ptile[tileCount(size)]; @@ -44,16 +46,29 @@ class Pgrid{ } } - static Pgrid newGrid(int size){ - if(size == 0){ - return initialGrid(); - }else{ - return subdividedGrid(newGrid(size - 1)); + static PlanetGrid newGrid(int size){ + //cache grids between calls, since only ~5 different grids total are needed + if(size < cache.length && cache[size] != null){ + return cache[size]; } + + PlanetGrid result; + if(size == 0){ + result = initialGrid(); + }else{ + result = subdividedGrid(newGrid(size - 1)); + } + + //store grid in cache + if(size < cache.length){ + cache[size] = result; + } + + return result; } - static Pgrid initialGrid(){ - Pgrid grid = new Pgrid(0); + static PlanetGrid initialGrid(){ + PlanetGrid grid = new PlanetGrid(0); for(Ptile t : grid.tiles){ t.v = iTiles[t.id]; @@ -97,8 +112,8 @@ class Pgrid{ return grid; } - static Pgrid subdividedGrid(Pgrid prev){ - Pgrid grid = new Pgrid(prev.size + 1); + static PlanetGrid subdividedGrid(PlanetGrid prev){ + PlanetGrid grid = new PlanetGrid(prev.size + 1); int prevTiles = prev.tiles.length; int prevCorners = prev.corners.length; @@ -148,7 +163,7 @@ class Pgrid{ return grid; } - static void addCorner(int id, Pgrid grid, int t1, int t2, int t3){ + static void addCorner(int id, PlanetGrid grid, int t1, int t2, int t3){ Corner c = grid.corners[id]; Ptile[] t = {grid.tiles[t1], grid.tiles[t2], grid.tiles[t3]}; c.v = Tmp.v31.set(t[0].v).add(t[1].v).add(t[2].v).cpy().nor(); @@ -158,7 +173,7 @@ class Pgrid{ } } - static void addEdge(int id, Pgrid grid, int t1, int t2){ + static void addEdge(int id, PlanetGrid grid, int t1, int t2){ Edge e = grid.edges[id]; Ptile[] t = {grid.tiles[t1], grid.tiles[t2]}; Corner[] c = { diff --git a/core/src/mindustry/graphics/PlanetMesh.java b/core/src/mindustry/graphics/PlanetMesh.java index 7a5fe4fcd9..b3d77cd5ce 100644 --- a/core/src/mindustry/graphics/PlanetMesh.java +++ b/core/src/mindustry/graphics/PlanetMesh.java @@ -8,13 +8,13 @@ import arc.math.geom.*; import arc.util.ArcAnnotate.*; import arc.util.*; import arc.util.noise.*; -import mindustry.graphics.Pgrid.*; +import mindustry.graphics.PlanetGrid.*; public class PlanetMesh{ private float[] floats = new float[3 + 3 + 1]; private Vec3 center = new Vec3(0, 0, 0); private Mesh mesh; - private Pgrid grid; + private PlanetGrid grid; private float color; private boolean lines; @@ -27,7 +27,7 @@ public class PlanetMesh{ this.radius = radius; this.lines = lines; this.color = color.toFloatBits(); - this.grid = Pgrid.newGrid(divisions); + this.grid = PlanetGrid.newGrid(divisions); int vertices = grid.tiles.length * 12 * (3 + 3 + 1); diff --git a/core/src/mindustry/graphics/PlanetRenderer.java b/core/src/mindustry/graphics/PlanetRenderer.java index 7229599a12..0ab5fa3d31 100644 --- a/core/src/mindustry/graphics/PlanetRenderer.java +++ b/core/src/mindustry/graphics/PlanetRenderer.java @@ -7,13 +7,13 @@ import arc.graphics.g3d.*; import arc.input.*; import arc.math.geom.*; import arc.util.*; -import mindustry.graphics.Pgrid.*; +import mindustry.graphics.PlanetGrid.*; public class PlanetRenderer{ private Camera3D cam = new Camera3D(); private float lastX, lastY; - private PlanetMesh planet = new PlanetMesh(3, 1f, false, Color.royal); + private PlanetMesh planet = new PlanetMesh(4, 1f, false, Color.royal); private PlanetMesh outline = new PlanetMesh(3, 1.01f, true, Pal.accent); private VertexBatch3D batch = new VertexBatch3D(false, true, 0); @@ -24,8 +24,7 @@ public class PlanetRenderer{ public void draw(){ Draw.flush(); - Gl.clearColor(0, 0, 0, 1); - Gl.clear(Gl.depthBufferBit | Gl.colorBufferBit); + Gl.clear(Gl.depthBufferBit); Gl.enable(Gl.depthTest); input(); @@ -38,15 +37,13 @@ public class PlanetRenderer{ planet.render(cam.combined()); //outline.render(cam.combined()); - //Log.info(cam.position + " " + cam.getPickRay(Core.input.mouseX(), Core.input.mouseY())); - Ptile tile = outline.getTile(cam.getPickRay(Core.input.mouseX(), Core.input.mouseY())); if(tile != null){ - for(int i = 0; i < tile.corners.length + 1; i++){ - batch.color(Pal.accent); - batch.vertex(tile.corners[i % tile.corners.length].v); + for(int i = 0; i < tile.corners.length; i++){ + batch.color(1f, 1f, 1f, 0.5f); + batch.vertex(tile.corners[i].v); } - batch.flush(cam.combined(), Gl.lineStrip); + batch.flush(cam.combined(), Gl.triangleFan); } Gl.disable(Gl.depthTest); diff --git a/core/src/mindustry/ui/dialogs/DeployDialog.java b/core/src/mindustry/ui/dialogs/DeployDialog.java index 811caca161..f782d84824 100644 --- a/core/src/mindustry/ui/dialogs/DeployDialog.java +++ b/core/src/mindustry/ui/dialogs/DeployDialog.java @@ -29,6 +29,7 @@ import mindustry.ui.layout.TreeLayout.*; import static mindustry.Vars.*; +//TODO remove (legacy, no longer needed) public class DeployDialog extends FloatingDialog{ private final float nodeSize = Scl.scl(230f); private ObjectSet nodes = new ObjectSet<>(); @@ -105,7 +106,7 @@ public class DeployDialog extends FloatingDialog{ bounds.y += nodeSize*0.4f; } - public void setup(){ + void setup(){ platform.updateRPC(); cont.clear(); diff --git a/core/src/mindustry/ui/dialogs/GameOverDialog.java b/core/src/mindustry/ui/dialogs/GameOverDialog.java index bb9b4fcc8d..486b90eb8e 100644 --- a/core/src/mindustry/ui/dialogs/GameOverDialog.java +++ b/core/src/mindustry/ui/dialogs/GameOverDialog.java @@ -88,7 +88,7 @@ public class GameOverDialog extends FloatingDialog{ hide(); state.set(State.menu); logic.reset(); - ui.deploy.show(); + ui.planet.show(); }).size(130f, 60f); }else{ buttons.addButton("$menu", () -> { diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java new file mode 100644 index 0000000000..c41ca7b5ba --- /dev/null +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -0,0 +1,29 @@ +package mindustry.ui.dialogs; + +import mindustry.gen.*; +import mindustry.graphics.*; +import mindustry.ui.*; + +import static mindustry.Vars.ui; + +public class PlanetDialog extends FloatingDialog{ + private PlanetRenderer renderer = new PlanetRenderer(); + + public PlanetDialog(){ + super("", Styles.fullDialog); + + addCloseButton(); + buttons.addImageTextButton("$techtree", Icon.tree, () -> ui.tech.show()).size(230f, 64f); + + shown(this::setup); + } + + void setup(){ + cont.clear(); + titleTable.remove(); + + cont.addRect((x, y, w, h) -> { + renderer.draw(); + }).grow(); + } +} diff --git a/core/src/mindustry/ui/dialogs/TechTreeDialog.java b/core/src/mindustry/ui/dialogs/TechTreeDialog.java index 0d28af70c5..10a7c6f6eb 100644 --- a/core/src/mindustry/ui/dialogs/TechTreeDialog.java +++ b/core/src/mindustry/ui/dialogs/TechTreeDialog.java @@ -56,7 +56,7 @@ public class TechTreeDialog extends FloatingDialog{ treeLayout(); }); - hidden(ui.deploy::setup); + hidden(ui.planet::setup); addCloseButton(); diff --git a/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java b/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java index ed1584133c..266c53b014 100644 --- a/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java +++ b/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java @@ -152,10 +152,10 @@ public class ZoneInfoDialog extends FloatingDialog{ if(!data.isUnlocked(zone)){ Sounds.unlock.play(); data.unlockContent(zone); - ui.deploy.setup(); + ui.planet.setup(); setup(zone); }else{ - ui.deploy.hide(); + ui.planet.hide(); data.removeItems(zone.getLaunchCost()); hide(); control.playZone(zone); diff --git a/core/src/mindustry/ui/fragments/FadeInFragment.java b/core/src/mindustry/ui/fragments/FadeInFragment.java index ae20556af7..e34f234c46 100644 --- a/core/src/mindustry/ui/fragments/FadeInFragment.java +++ b/core/src/mindustry/ui/fragments/FadeInFragment.java @@ -1,14 +1,15 @@ package mindustry.ui.fragments; +import arc.*; +import arc.graphics.g2d.*; +import arc.math.*; import arc.scene.*; import arc.scene.event.*; -import mindustry.graphics.*; /** Fades in a black overlay.*/ public class FadeInFragment extends Fragment{ private static final float duration = 40f; float time = 0f; - PlanetRenderer rend = new PlanetRenderer(); @Override public void build(Group parent){ @@ -20,10 +21,9 @@ public class FadeInFragment extends Fragment{ @Override public void draw(){ - //Draw.color(0f, 0f, 0f, Mathf.clamp(1f - time)); - //Fill.crect(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight()); - //Draw.color(); - rend.draw(); + Draw.color(0f, 0f, 0f, Mathf.clamp(1f - time)); + Fill.crect(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight()); + Draw.color(); } @Override @@ -31,7 +31,7 @@ public class FadeInFragment extends Fragment{ super.act(delta); time += 1f / duration; if(time > 1){ - //remove(); + remove(); } } }); diff --git a/core/src/mindustry/ui/fragments/MenuFragment.java b/core/src/mindustry/ui/fragments/MenuFragment.java index 8737db0d9a..d68388ac69 100644 --- a/core/src/mindustry/ui/fragments/MenuFragment.java +++ b/core/src/mindustry/ui/fragments/MenuFragment.java @@ -100,7 +100,7 @@ public class MenuFragment extends Fragment{ container.defaults().size(size).pad(5).padTop(4f); MobileButton - play = new MobileButton(Icon.play2, "$campaign", () -> checkPlay(ui.deploy::show)), + play = new MobileButton(Icon.play2, "$campaign", () -> checkPlay(ui.planet::show)), custom = new MobileButton(Icon.playCustom, "$customgame", () -> checkPlay(ui.custom::show)), maps = new MobileButton(Icon.load, "$loadgame", () -> checkPlay(ui.load::show)), join = new MobileButton(Icon.add, "$joingame", () -> checkPlay(ui.join::show)), @@ -165,7 +165,7 @@ public class MenuFragment extends Fragment{ buttons(t, new Buttoni("$play", Icon.play2Small, - new Buttoni("$campaign", Icon.play2Small, () -> checkPlay(ui.deploy::show)), + new Buttoni("$campaign", Icon.play2Small, () -> checkPlay(ui.planet::show)), new Buttoni("$joingame", Icon.addSmall, () -> checkPlay(ui.join::show)), new Buttoni("$customgame", Icon.editorSmall, () -> checkPlay(ui.custom::show)), new Buttoni("$loadgame", Icon.loadSmall, () -> checkPlay(ui.load::show)), diff --git a/desktop/src/mindustry/desktop/DesktopLauncher.java b/desktop/src/mindustry/desktop/DesktopLauncher.java index c35adeef96..f3161ec1ba 100644 --- a/desktop/src/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/mindustry/desktop/DesktopLauncher.java @@ -262,7 +262,7 @@ public class DesktopLauncher extends ClientLauncher{ }else{ if(ui.editor != null && ui.editor.isShown()){ presence.state = "In Editor"; - }else if(ui.deploy != null && ui.deploy.isShown()){ + }else if(ui.planet != null && ui.planet.isShown()){ presence.state = "In Launch Selection"; }else{ presence.state = "In Menu";