From 8273198c56a488ba7b9546f47f8dd3dd738465af Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 1 Jun 2020 11:12:06 -0400 Subject: [PATCH] Bugfixes --- core/assets/bloomshaders/bloom.frag | 9 ++- core/src/mindustry/Vars.java | 6 ++ core/src/mindustry/ui/CoreItemsDisplay.java | 53 ++++++++++++++ .../mindustry/ui/dialogs/PlanetDialog.java | 70 +++++++++++++------ .../mindustry/ui/fragments/HudFragment.java | 6 ++ .../world/blocks/campaign/CoreLauncher.java | 11 +-- .../world/blocks/campaign/ResearchBlock.java | 5 ++ .../world/blocks/distribution/Conveyor.java | 1 - gradle.properties | 2 +- 9 files changed, 130 insertions(+), 33 deletions(-) create mode 100644 core/src/mindustry/ui/CoreItemsDisplay.java diff --git a/core/assets/bloomshaders/bloom.frag b/core/assets/bloomshaders/bloom.frag index 1196120cc3..9b7ac8aa51 100644 --- a/core/assets/bloomshaders/bloom.frag +++ b/core/assets/bloomshaders/bloom.frag @@ -14,9 +14,8 @@ uniform float OriginalIntensity; varying MED vec2 v_texCoords; void main(){ - - vec3 original = texture2D(u_texture0, v_texCoords).rgb; - vec3 bloom = texture2D(u_texture1, v_texCoords).rgb * BloomIntensity; - original = OriginalIntensity * (original - original * bloom); - gl_FragColor.rgb = original + bloom; + vec4 original = texture2D(u_texture0, v_texCoords) * OriginalIntensity; + vec4 bloom = texture2D(u_texture1, v_texCoords) * BloomIntensity; + original = original * (vec4(1.0) - bloom); + gl_FragColor = original + bloom; } \ No newline at end of file diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 959b0bc390..24fcc3ad77 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -5,6 +5,7 @@ import arc.*; import arc.assets.*; import arc.files.*; import arc.graphics.*; +import arc.graphics.g3d.*; import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.*; @@ -164,6 +165,7 @@ public class Vars implements Loadable{ /** list of all locales that can be switched to */ public static Locale[] locales; + public static Camera3D cam3; public static FileTree tree = new FileTree(); public static Net net; public static ContentLoader content; @@ -262,6 +264,10 @@ public class Vars implements Loadable{ mods.load(); maps.load(); + + if(!headless){ + cam3 = new Camera3D(); + } } public static void loadLogger(){ diff --git a/core/src/mindustry/ui/CoreItemsDisplay.java b/core/src/mindustry/ui/CoreItemsDisplay.java new file mode 100644 index 0000000000..11d0511376 --- /dev/null +++ b/core/src/mindustry/ui/CoreItemsDisplay.java @@ -0,0 +1,53 @@ +package mindustry.ui; + +import arc.scene.ui.layout.*; +import arc.struct.*; +import mindustry.*; +import mindustry.gen.*; +import mindustry.type.*; +import mindustry.world.blocks.storage.CoreBlock.*; + +import static mindustry.Vars.*; + +public class CoreItemsDisplay extends Table{ + private final ObjectSet usedItems = new ObjectSet<>(); + + public CoreItemsDisplay(){ + rebuild(); + } + + public void resetUsed(){ + usedItems.clear(); + } + + void rebuild(){ + clear(); + background(Tex.button); + + update(() -> { + CoreEntity core = Vars.player.team().core(); + + for(Item item : content.items()){ + if(core != null && core.items.get(item) > 0 && usedItems.add(item)){ + rebuild(); + break; + } + } + }); + + int i = 0; + + CoreEntity core = Vars.player.team().core(); + for(Item item : content.items()){ + if(usedItems.contains(item)){ + image(item.icon(Cicon.medium)).padRight(4); + label(() -> core == null ? "0" : ui.formatAmount(core.items.get(item))).padRight(4); + + if(++i % 2 == 0){ + row(); + } + } + } + + } +} diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 52fbb2cea0..4dd3c25cbd 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -44,7 +44,6 @@ public class PlanetDialog extends BaseDialog{ private final Planet solarSystem = Planets.sun; private final Mesh[] outlines = new Mesh[10]; - private final Camera3D cam = new Camera3D(); private final VertexBatch3D batch = new VertexBatch3D(10000, false, true, 0); private final PlaneBatch3D projector = new PlaneBatch3D(); private final Mat3D mat = new Mat3D(); @@ -101,7 +100,7 @@ public class PlanetDialog extends BaseDialog{ //buttons.button("Database", Icon.book, style, () -> ui.database.show()).margin(bmargin); //buttons.button("Resources", Icon.file, style, resources::show).margin(bmargin); - cam.fov = 60f; + cam3.fov = 60f; camRelative.set(0, 0f, camLength); projector.setScaling(1f / 150f); @@ -114,13 +113,13 @@ public class PlanetDialog extends BaseDialog{ //scale X speed depending on polar coordinate float speed = 1f - Math.abs(upV - 90) / 90f; - camRelative.rotate(cam.up, cx / xscale * speed); + camRelative.rotate(cam3.up, cx / xscale * speed); //prevent user from scrolling all the way up and glitching it out float amount = cy / yscale; amount = Mathf.clamp(upV + amount, margin, 180f - margin) - upV; - camRelative.rotate(Tmp.v31.set(cam.up).rotate(cam.direction, 90), amount); + camRelative.rotate(Tmp.v31.set(cam3.up).rotate(cam3.direction, 90), amount); }); scrolled(value -> { @@ -129,7 +128,7 @@ public class PlanetDialog extends BaseDialog{ update(() -> { if(planet.isLandable()){ - hovered = planet.getSector(cam.getMouseRay(), outlineRad); + hovered = planet.getSector(cam3.getMouseRay(), outlineRad); }else{ hovered = selected = null; } @@ -162,6 +161,14 @@ public class PlanetDialog extends BaseDialog{ } public void show(Sector selected, int range){ + this.selected = null; + this.hovered = null; + + //update view to sector + camRelative.set(Tmp.v33.set(selected.tile.v).rotate(Vec3.Y, -selected.planet.getRotation())); + zoom = smoothZoom = 1f; + + show(); //TODO } @@ -172,6 +179,27 @@ public class PlanetDialog extends BaseDialog{ cont.rect((x, y, w, h) -> render()).grow(); } + FrameBuffer buffer = new FrameBuffer(2, 2, true); + + @Override + public void draw(){ + boolean doBuffer = color.a < 0.99f; + + if(doBuffer){ + buffer.resize(Core.graphics.getWidth(), Core.graphics.getHeight()); + buffer.begin(Color.clear); + } + + super.draw(); + + if(doBuffer){ + buffer.end(); + Draw.color(color); + Draw.rect(Draw.wrap(buffer.getTexture()), Core.graphics.getWidth()/2f, Core.graphics.getHeight()/2f, Core.graphics.getWidth(), -Core.graphics.getHeight()); + Draw.color(); + } + } + private void render(){ Draw.flush(); Gl.clear(Gl.depthBufferBit); @@ -182,23 +210,23 @@ public class PlanetDialog extends BaseDialog{ Gl.cullFace(Gl.back); //lock to up vector so it doesn't get confusing - cam.up.set(Vec3.Y); + cam3.up.set(Vec3.Y); - cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight()); + cam3.resize(Core.graphics.getWidth(), Core.graphics.getHeight()); camRelative.setLength(planet.radius * camLength + (smoothZoom-1f) * planet.radius * 2); - cam.position.set(planet.position).add(camRelative); - cam.lookAt(planet.position); - cam.update(); + cam3.position.set(planet.position).add(camRelative); + cam3.lookAt(planet.position); + cam3.update(); //TODO hacky - Shaders.planet.camDir.set(cam.direction).rotate(Vec3.Y, planet.getRotation()); + Shaders.planet.camDir.set(cam3.direction).rotate(Vec3.Y, planet.getRotation()); - projector.proj(cam.combined); - batch.proj(cam.combined); + projector.proj(cam3.combined); + batch.proj(cam3.combined); beginBloom(); - skybox.render(cam.combined); + skybox.render(cam3.combined); renderPlanet(solarSystem); @@ -226,14 +254,14 @@ public class PlanetDialog extends BaseDialog{ if(selected != null){ addChild(stable); - Vec3 pos = cam.project(Tmp.v31.set(selected.tile.v).setLength(outlineRad).rotate(Vec3.Y, -planet.getRotation()).add(planet.position)); + Vec3 pos = cam3.project(Tmp.v31.set(selected.tile.v).setLength(outlineRad).rotate(Vec3.Y, -planet.getRotation()).add(planet.position)); stable.setPosition(pos.x, pos.y, Align.center); stable.toFront(); }else{ stable.remove(); } - cam.update(); + cam3.update(); } private void beginBloom(){ @@ -246,7 +274,7 @@ public class PlanetDialog extends BaseDialog{ private void renderPlanet(Planet planet){ //render planet at offsetted position in the world - planet.mesh.render(cam.combined, planet.getTransform(mat)); + planet.mesh.render(cam3.combined, planet.getTransform(mat)); renderOrbit(planet); @@ -257,7 +285,7 @@ public class PlanetDialog extends BaseDialog{ if(planet.parent != null && planet.hasAtmosphere && Core.settings.getBool("atmosphere")){ Blending.additive.apply(); - Shaders.atmosphere.camera = cam; + Shaders.atmosphere.camera = cam3; Shaders.atmosphere.planet = planet; Shaders.atmosphere.bind(); Shaders.atmosphere.apply(); @@ -330,11 +358,11 @@ public class PlanetDialog extends BaseDialog{ //render sector grid Mesh mesh = outline(planet.grid.size); Shader shader = Shaders.planetGrid; - Vec3 tile = planet.intersect(cam.getMouseRay(), outlineRad); + Vec3 tile = planet.intersect(cam3.getMouseRay(), outlineRad); Shaders.planetGrid.mouse.lerp(tile == null ? Vec3.Zero : tile.sub(planet.position).rotate(Vec3.Y, planet.getRotation()), 0.2f); shader.bind(); - shader.setUniformMatrix4("u_proj", cam.combined.val); + shader.setUniformMatrix4("u_proj", cam3.combined.val); shader.setUniformMatrix4("u_trans", planet.getTransform(mat).val); shader.apply(); mesh.render(shader, Gl.lines); @@ -476,7 +504,7 @@ public class PlanetDialog extends BaseDialog{ if(selected != null){ //fade out UI when not facing selected sector Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planet.getRotation()).scl(-1f).nor(); - float dot = cam.direction.dot(Tmp.v31); + float dot = cam3.direction.dot(Tmp.v31); stable.getColor().a = Math.max(dot, 0f)*2f; if(dot*2f <= -0.1f){ stable.remove(); diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java index 44eb0d4489..9879007ccb 100644 --- a/core/src/mindustry/ui/fragments/HudFragment.java +++ b/core/src/mindustry/ui/fragments/HudFragment.java @@ -35,6 +35,8 @@ public class HudFragment extends Fragment{ private Table lastUnlockLayout; private boolean shown = true; private float dsize = 47.2f; + //TODO implement + private CoreItemsDisplay coreItems = new CoreItemsDisplay(); private String hudText = ""; private boolean showHudText; @@ -54,6 +56,10 @@ public class HudFragment extends Fragment{ showToast("Sector[accent] captured[]!"); }); + Events.on(ResetEvent.class, e -> { + coreItems.resetUsed(); + }); + //TODO tear this all down //menu at top left parent.fill(cont -> { diff --git a/core/src/mindustry/world/blocks/campaign/CoreLauncher.java b/core/src/mindustry/world/blocks/campaign/CoreLauncher.java index a22c4a9e31..9d3d2c9df0 100644 --- a/core/src/mindustry/world/blocks/campaign/CoreLauncher.java +++ b/core/src/mindustry/world/blocks/campaign/CoreLauncher.java @@ -4,7 +4,10 @@ import mindustry.*; import mindustry.gen.*; import mindustry.world.*; +import static mindustry.Vars.state; + public class CoreLauncher extends Block{ + public int range = 1; public CoreLauncher(String name){ super(name); @@ -23,12 +26,10 @@ public class CoreLauncher extends Block{ @Override public boolean configTapped(){ - //TODO show w/ sector - Vars.ui.planet.show(); - + if(state.isCampaign()){ + Vars.ui.planet.show(state.rules.sector, range); + } return false; } - - } } diff --git a/core/src/mindustry/world/blocks/campaign/ResearchBlock.java b/core/src/mindustry/world/blocks/campaign/ResearchBlock.java index 1445820406..8f66048fc9 100644 --- a/core/src/mindustry/world/blocks/campaign/ResearchBlock.java +++ b/core/src/mindustry/world/blocks/campaign/ResearchBlock.java @@ -21,6 +21,11 @@ public class ResearchBlock extends Block{ configurable = true; } + @Override + public boolean outputsItems(){ + return false; + } + public class ResearchBlockEntity extends TileEntity{ public @Nullable UnlockableContent researching; diff --git a/core/src/mindustry/world/blocks/distribution/Conveyor.java b/core/src/mindustry/world/blocks/distribution/Conveyor.java index af7e0a414a..a2dae61ea5 100644 --- a/core/src/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/mindustry/world/blocks/distribution/Conveyor.java @@ -132,7 +132,6 @@ public class Conveyor extends Block implements Autotiler{ Draw.rect(regions[blendbits][frame], x, y, tilesize * blendsclx, tilesize * blendscly, rotation * 90); - //TODO is sprite Z layer clustering necessary? does it create garbage? Draw.z(Layer.blockOver); for(int i = 0; i < len; i++){ diff --git a/gradle.properties b/gradle.properties index 3d3084f59a..3109ca56c1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=f9cc0eb5711f3e2f640c59d63e3a50da29bca49d +archash=713b7e105ae8dde696c1ee8e25b4cc257ca1bf04