Planet rendering refactoring
This commit is contained in:
@@ -322,10 +322,8 @@ public class Renderer implements ApplicationListener{
|
||||
}
|
||||
|
||||
var desc = assets.load(state.rules.backgroundTexture, Texture.class, new TextureParameter(){{
|
||||
wrapU = TextureWrap.mirroredRepeat;
|
||||
wrapV = TextureWrap.mirroredRepeat;
|
||||
magFilter = TextureFilter.linear;
|
||||
minFilter = TextureFilter.linear;
|
||||
wrapU = wrapV = TextureWrap.mirroredRepeat;
|
||||
magFilter = minFilter = TextureFilter.linear;
|
||||
}});
|
||||
|
||||
assets.finishLoadingAsset(desc);
|
||||
|
||||
@@ -95,6 +95,7 @@ public class Shaders{
|
||||
public Vec3 lightDir = new Vec3(1, 1, 1).nor();
|
||||
public Color ambientColor = Color.white.cpy();
|
||||
public Vec3 camDir = new Vec3();
|
||||
public Planet planet;
|
||||
|
||||
public PlanetShader(){
|
||||
super("planet", "planet");
|
||||
@@ -102,7 +103,7 @@ public class Shaders{
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
camDir.set(renderer.planets.cam.direction).rotate(Vec3.Y, renderer.planets.planet.getRotation());
|
||||
camDir.set(renderer.planets.cam.direction).rotate(Vec3.Y, planet.getRotation());
|
||||
|
||||
setUniformf("u_lightdir", lightDir);
|
||||
setUniformf("u_ambientColor", ambientColor.r, ambientColor.g, ambientColor.b);
|
||||
@@ -115,6 +116,7 @@ public class Shaders{
|
||||
public Color ambientColor = Color.white.cpy();
|
||||
public Vec3 camDir = new Vec3();
|
||||
public float alpha = 1f;
|
||||
public Planet planet;
|
||||
|
||||
public CloudShader(){
|
||||
super("planet", "clouds");
|
||||
@@ -122,7 +124,7 @@ public class Shaders{
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
camDir.set(renderer.planets.cam.direction).rotate(Vec3.Y, renderer.planets.planet.getRotation());
|
||||
camDir.set(renderer.planets.cam.direction).rotate(Vec3.Y, planet.getRotation());
|
||||
|
||||
setUniformf("u_alpha", alpha);
|
||||
setUniformf("u_lightdir", lightDir);
|
||||
|
||||
@@ -3,5 +3,5 @@ package mindustry.graphics.g3d;
|
||||
import arc.math.geom.*;
|
||||
|
||||
public interface GenericMesh{
|
||||
void render(Mat3D projection, Mat3D transform);
|
||||
void render(PlanetParams params, Mat3D projection, Mat3D transform);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ public class HexMesh extends PlanetMesh{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
public void preRender(PlanetParams params){
|
||||
Shaders.planet.planet = planet;
|
||||
Shaders.planet.lightDir.set(planet.solarSystem.position).sub(planet.position).rotate(Vec3.Y, planet.getRotation()).nor();
|
||||
Shaders.planet.ambientColor.set(planet.solarSystem.lightColor);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import arc.graphics.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
@@ -42,8 +41,8 @@ public class HexSkyMesh extends PlanetMesh{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
preRender();
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
preRender(params);
|
||||
shader.bind();
|
||||
shader.setUniformMatrix4("u_proj", projection.val);
|
||||
shader.setUniformMatrix4("u_trans", mat.setToTranslation(planet.position).rotate(Vec3.Y, planet.getRotation() + relRot()).val);
|
||||
@@ -52,9 +51,10 @@ public class HexSkyMesh extends PlanetMesh{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
public void preRender(PlanetParams params){
|
||||
Shaders.clouds.planet = planet;
|
||||
Shaders.clouds.lightDir.set(planet.solarSystem.position).sub(planet.position).rotate(Vec3.Y, planet.getRotation() + relRot()).nor();
|
||||
Shaders.clouds.ambientColor.set(planet.solarSystem.lightColor);
|
||||
Shaders.clouds.alpha = 1f - Vars.ui.planet.planets.orbitAlpha;
|
||||
Shaders.clouds.alpha = 1f - params.uiAlpha;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class MatMesh implements GenericMesh{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
mesh.render(projection, tmp.set(transform).mul(mat));
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
mesh.render(params, projection, tmp.set(transform).mul(mat));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ public class MultiMesh implements GenericMesh{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
for(var v : meshes){
|
||||
v.render(projection, transform);
|
||||
v.render(params, projection, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,15 @@ public abstract class PlanetMesh implements GenericMesh{
|
||||
|
||||
public PlanetMesh(){}
|
||||
|
||||
/** Should be overridden to set up any shader parameters such as planet position, normals, etc. */
|
||||
public abstract void preRender();
|
||||
/** Should be overridden to set up any shader parameters such as planet position, normals, etc.
|
||||
* @param params*/
|
||||
public void preRender(PlanetParams params){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Mat3D projection, Mat3D transform){
|
||||
preRender();
|
||||
public void render(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
preRender(params);
|
||||
shader.bind();
|
||||
shader.setUniformMatrix4("u_proj", projection.val);
|
||||
shader.setUniformMatrix4("u_trans", transform.val);
|
||||
|
||||
35
core/src/mindustry/graphics/g3d/PlanetParams.java
Normal file
35
core/src/mindustry/graphics/g3d/PlanetParams.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package mindustry.graphics.g3d;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.graphics.g3d.PlanetRenderer.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
/** Parameters for rendering a solar system. */
|
||||
public class PlanetParams{
|
||||
/** Camera direction relative to the planet. Length is determined by zoom. */
|
||||
public Vec3 camPos = new Vec3(0f, 0f, 4f);
|
||||
/** Camera up vector. */
|
||||
public Vec3 camUp = new Vec3(0f, 1f, 0f);
|
||||
/** the unit length direction vector of the camera **/
|
||||
public Vec3 camDir = new Vec3(0, 0, -1);
|
||||
/** The sun/main planet of the solar system from which everything is rendered. */
|
||||
public Planet solarSystem = Planets.sun;
|
||||
/** Planet being looked at. */
|
||||
public Planet planet = Planets.serpulo;
|
||||
/** Zoom relative to planet. */
|
||||
public float zoom = 1f;
|
||||
/** Alpha of orbit rings and other UI elements. */
|
||||
public float uiAlpha = 1f;
|
||||
/** If false, orbit and sector grid are not drawn. */
|
||||
public boolean drawUi = false;
|
||||
/** If true, a space skybox is drawn. */
|
||||
public boolean drawSkybox = true;
|
||||
/** Handles drawing details. */
|
||||
public @Nullable transient PlanetInterfaceRenderer renderer;
|
||||
|
||||
//TODO:
|
||||
//- blur
|
||||
//- transparent background
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.g3d.PlanetGrid.*;
|
||||
@@ -25,25 +24,15 @@ public class PlanetRenderer implements Disposable{
|
||||
|
||||
private static final Seq<Vec3> points = new Seq<>();
|
||||
|
||||
/** Camera direction relative to the planet. Length is determined by zoom. */
|
||||
public final Vec3 camPos = new Vec3();
|
||||
/** The sun/main planet of the solar system from which everything is rendered. */
|
||||
public final Planet solarSystem = Planets.sun;
|
||||
/** Planet being looked at. */
|
||||
public Planet planet = Planets.serpulo;
|
||||
/** Camera used for rendering. */
|
||||
public Camera3D cam = new Camera3D();
|
||||
public final Camera3D cam = new Camera3D();
|
||||
/** Raw vertex batch. */
|
||||
public final VertexBatch3D batch = new VertexBatch3D(20000, false, true, 0);
|
||||
|
||||
public float zoom = 1f;
|
||||
public float orbitAlpha = 1f;
|
||||
|
||||
private final Mesh[] outlines = new Mesh[10];
|
||||
public final PlaneBatch3D projector = new PlaneBatch3D();
|
||||
public final Mat3D mat = new Mat3D();
|
||||
public final FrameBuffer buffer = new FrameBuffer(2, 2, true);
|
||||
public PlanetInterfaceRenderer irenderer;
|
||||
|
||||
public final Bloom bloom = new Bloom(Core.graphics.getWidth()/4, Core.graphics.getHeight()/4, true, false){{
|
||||
setThreshold(0.8f);
|
||||
@@ -55,16 +44,13 @@ public class PlanetRenderer implements Disposable{
|
||||
public final CubemapMesh skybox = new CubemapMesh(new Cubemap("cubemaps/stars/"));
|
||||
|
||||
public PlanetRenderer(){
|
||||
camPos.set(0, 0f, camLength);
|
||||
projector.setScaling(1f / 150f);
|
||||
cam.fov = 60f;
|
||||
cam.far = 150f;
|
||||
}
|
||||
|
||||
/** Render the entire planet scene to the screen. */
|
||||
public void render(PlanetInterfaceRenderer irenderer){
|
||||
this.irenderer = irenderer;
|
||||
|
||||
public void render(PlanetParams params){
|
||||
Draw.flush();
|
||||
Gl.clear(Gl.depthBufferBit);
|
||||
Gl.enable(Gl.depthTest);
|
||||
@@ -73,14 +59,20 @@ public class PlanetRenderer implements Disposable{
|
||||
Gl.enable(Gl.cullFace);
|
||||
Gl.cullFace(Gl.back);
|
||||
|
||||
bloom.blending = !params.drawSkybox;
|
||||
|
||||
//lock to up vector so it doesn't get confusing
|
||||
cam.up.set(Vec3.Y);
|
||||
|
||||
cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||
camPos.setLength((planet.radius + planet.camRadius) * camLength + (zoom-1f) * (planet.radius + planet.camRadius) * 2);
|
||||
cam.position.set(planet.position).add(camPos);
|
||||
cam.lookAt(planet.position);
|
||||
params.camPos.setLength((params.planet.radius + params.planet.camRadius) * camLength + (params.zoom-1f) * (params.planet.radius + params.planet.camRadius) * 2);
|
||||
cam.position.set(params.planet.position).add(params.camPos);
|
||||
//cam.up.set(params.camUp); //TODO broken
|
||||
cam.lookAt(params.planet.position);
|
||||
cam.update();
|
||||
//write back once it changes.
|
||||
params.camUp.set(cam.up);
|
||||
params.camDir.set(cam.direction);
|
||||
|
||||
projector.proj(cam.combined);
|
||||
batch.proj(cam.combined);
|
||||
@@ -89,25 +81,26 @@ public class PlanetRenderer implements Disposable{
|
||||
|
||||
beginBloom();
|
||||
|
||||
//render skybox at 0,0,0
|
||||
Vec3 lastPos = Tmp.v31.set(cam.position);
|
||||
cam.position.setZero();
|
||||
cam.update();
|
||||
if(params.drawSkybox){
|
||||
//render skybox at 0,0,0
|
||||
Vec3 lastPos = Tmp.v31.set(cam.position);
|
||||
cam.position.setZero();
|
||||
cam.update();
|
||||
|
||||
Gl.depthMask(false);
|
||||
Gl.depthMask(false);
|
||||
|
||||
skybox.render(cam.combined);
|
||||
skybox.render(cam.combined);
|
||||
|
||||
Gl.depthMask(true);
|
||||
Gl.depthMask(true);
|
||||
|
||||
cam.position.set(lastPos);
|
||||
cam.update();
|
||||
cam.position.set(lastPos);
|
||||
cam.update();
|
||||
}
|
||||
|
||||
Events.fire(Trigger.universeDraw);
|
||||
|
||||
renderPlanet(solarSystem);
|
||||
|
||||
renderTransparent(solarSystem);
|
||||
renderPlanet(params.solarSystem, params);
|
||||
renderTransparent(params.solarSystem, params);
|
||||
|
||||
endBloom();
|
||||
|
||||
@@ -115,7 +108,9 @@ public class PlanetRenderer implements Disposable{
|
||||
|
||||
Gl.enable(Gl.blend);
|
||||
|
||||
irenderer.renderProjections(planet);
|
||||
if(params.renderer != null){
|
||||
params.renderer.renderProjections(params.planet);
|
||||
}
|
||||
|
||||
Gl.disable(Gl.cullFace);
|
||||
Gl.disable(Gl.depthTest);
|
||||
@@ -133,28 +128,28 @@ public class PlanetRenderer implements Disposable{
|
||||
}
|
||||
|
||||
|
||||
public void renderPlanet(Planet planet){
|
||||
public void renderPlanet(Planet planet, PlanetParams params){
|
||||
if(!planet.visible()) return;
|
||||
|
||||
cam.update();
|
||||
|
||||
if(cam.frustum.containsSphere(planet.position, planet.clipRadius)){
|
||||
//render planet at offsetted position in the world
|
||||
planet.draw(cam.combined, planet.getTransform(mat));
|
||||
planet.draw(params, cam.combined, planet.getTransform(mat));
|
||||
}
|
||||
|
||||
for(Planet child : planet.children){
|
||||
renderPlanet(child);
|
||||
renderPlanet(child, params);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderTransparent(Planet planet){
|
||||
public void renderTransparent(Planet planet, PlanetParams params){
|
||||
if(!planet.visible()) return;
|
||||
|
||||
planet.drawClouds(cam.combined, planet.getTransform(mat));
|
||||
planet.drawClouds(params, cam.combined, planet.getTransform(mat));
|
||||
|
||||
if(planet.hasGrid() && planet == this.planet){
|
||||
renderSectors(planet);
|
||||
if(planet.hasGrid() && planet == params.planet && params.drawUi){
|
||||
renderSectors(planet, params);
|
||||
}
|
||||
|
||||
if(cam.frustum.containsSphere(planet.position, planet.clipRadius) && planet.parent != null && planet.hasAtmosphere && Core.settings.getBool("atmosphere")){
|
||||
@@ -162,31 +157,35 @@ public class PlanetRenderer implements Disposable{
|
||||
}
|
||||
|
||||
for(Planet child : planet.children){
|
||||
renderTransparent(child);
|
||||
renderTransparent(child, params);
|
||||
}
|
||||
|
||||
batch.proj(cam.combined);
|
||||
|
||||
renderOrbit(planet);
|
||||
if(params.drawUi){
|
||||
renderOrbit(planet, params);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderOrbit(Planet planet){
|
||||
if(planet.parent == null || !planet.visible() || orbitAlpha <= 0.02f || !planet.drawOrbit) return;
|
||||
public void renderOrbit(Planet planet, PlanetParams params){
|
||||
if(planet.parent == null || !planet.visible() || params.uiAlpha <= 0.02f || !planet.drawOrbit) return;
|
||||
|
||||
Vec3 center = planet.parent.position;
|
||||
float radius = planet.orbitRadius;
|
||||
int points = (int)(radius * 10);
|
||||
Angles.circleVectors(points, radius, (cx, cy) -> batch.vertex(Tmp.v32.set(center).add(cx, 0, cy), Pal.gray.write(Tmp.c1).a(orbitAlpha)));
|
||||
Angles.circleVectors(points, radius, (cx, cy) -> batch.vertex(Tmp.v32.set(center).add(cx, 0, cy), Pal.gray.write(Tmp.c1).a(params.uiAlpha)));
|
||||
batch.flush(Gl.lineLoop);
|
||||
}
|
||||
|
||||
public void renderSectors(Planet planet){
|
||||
if(orbitAlpha <= 0.02f) return;
|
||||
public void renderSectors(Planet planet, PlanetParams params){
|
||||
if(params.uiAlpha <= 0.02f) return;
|
||||
|
||||
//apply transformed position
|
||||
batch.proj().mul(planet.getTransform(mat));
|
||||
|
||||
irenderer.renderSectors(planet);
|
||||
if(params.renderer != null){
|
||||
params.renderer.renderSectors(planet);
|
||||
}
|
||||
|
||||
//render sector grid
|
||||
Mesh mesh = outline(planet.grid.size);
|
||||
@@ -264,12 +263,12 @@ public class PlanetRenderer implements Disposable{
|
||||
}
|
||||
|
||||
public void setPlane(Sector sector){
|
||||
float rotation = -planet.getRotation();
|
||||
float rotation = -sector.planet.getRotation();
|
||||
float length = 0.01f;
|
||||
|
||||
projector.setPlane(
|
||||
//origin on sector position
|
||||
Tmp.v33.set(sector.tile.v).setLength(outlineRad + length).rotate(Vec3.Y, rotation).add(planet.position),
|
||||
Tmp.v33.set(sector.tile.v).setLength(outlineRad + length).rotate(Vec3.Y, rotation).add(sector.planet.position),
|
||||
//face up
|
||||
sector.plane.project(Tmp.v32.set(sector.tile.v).add(Vec3.Y)).sub(sector.tile.v).rotate(Vec3.Y, rotation).nor(),
|
||||
//right vector
|
||||
|
||||
@@ -8,9 +8,4 @@ public class ShaderSphereMesh extends PlanetMesh{
|
||||
public ShaderSphereMesh(Planet planet, Shader shader, int divisions){
|
||||
super(planet, MeshBuilder.buildIcosphere(divisions, planet.radius), shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,4 @@ public class SunMesh extends HexMesh{
|
||||
}
|
||||
}, divisions, Shaders.unlit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRender(){
|
||||
//do absolutely nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,8 +301,8 @@ public class Planet extends UnlockableContent{
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void draw(Mat3D projection, Mat3D transform){
|
||||
mesh.render(projection, transform);
|
||||
public void draw(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
mesh.render(params, projection, transform);
|
||||
}
|
||||
|
||||
public void drawAtmosphere(Mesh atmosphere, Camera3D cam){
|
||||
@@ -323,9 +323,9 @@ public class Planet extends UnlockableContent{
|
||||
Gl.depthMask(true);
|
||||
}
|
||||
|
||||
public void drawClouds(Mat3D projection, Mat3D transform){
|
||||
public void drawClouds(PlanetParams params, Mat3D projection, Mat3D transform){
|
||||
if(cloudMesh != null){
|
||||
cloudMesh.render(projection, transform);
|
||||
cloudMesh.render(params, projection, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.content.TechTree.*;
|
||||
import mindustry.core.*;
|
||||
@@ -24,8 +25,8 @@ import mindustry.game.SectorInfo.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.g3d.*;
|
||||
import mindustry.graphics.g3d.PlanetGrid.*;
|
||||
import mindustry.graphics.g3d.*;
|
||||
import mindustry.input.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.type.*;
|
||||
@@ -50,10 +51,11 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
public static float sectorShowDuration = 60f * 2.4f;
|
||||
|
||||
public final FrameBuffer buffer = new FrameBuffer(2, 2, true);
|
||||
public final PlanetRenderer planets = renderer.planets;
|
||||
public final LaunchLoadoutDialog loadouts = new LaunchLoadoutDialog();
|
||||
public final PlanetRenderer planets = renderer.planets;
|
||||
|
||||
public float zoom = 1f, selectAlpha = 1f;
|
||||
public PlanetParams state = new PlanetParams();
|
||||
public float zoom = 1f;
|
||||
public @Nullable Sector selected, hovered, launchSector;
|
||||
public Mode mode = look;
|
||||
public boolean launching;
|
||||
@@ -69,10 +71,13 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
|
||||
public PlanetDialog(){
|
||||
super("", Styles.fullDialog);
|
||||
|
||||
state.renderer = this;
|
||||
state.drawUi = true;
|
||||
|
||||
shouldPause = true;
|
||||
planets.planet = content.getByName(ContentType.planet, Core.settings.getString("lastplanet", "serpulo"));
|
||||
if(planets.planet == null) planets.planet = Planets.serpulo;
|
||||
state.planet = content.getByName(ContentType.planet, Core.settings.getString("lastplanet", "serpulo"));
|
||||
if(state.planet == null) state.planet = Planets.serpulo;
|
||||
|
||||
addListener(new InputListener(){
|
||||
@Override
|
||||
@@ -108,7 +113,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
newPresets.clear();
|
||||
}
|
||||
|
||||
Vec3 pos = planets.camPos;
|
||||
Vec3 pos = state.camPos;
|
||||
|
||||
float upV = pos.angle(Vec3.Y);
|
||||
float xscale = 9f, yscale = 10f;
|
||||
@@ -117,20 +122,20 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
//scale X speed depending on polar coordinate
|
||||
float speed = 1f - Math.abs(upV - 90) / 90f;
|
||||
|
||||
pos.rotate(planets.cam.up, cx / xscale * speed);
|
||||
pos.rotate(state.camUp, 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;
|
||||
|
||||
pos.rotate(Tmp.v31.set(planets.cam.up).rotate(planets.cam.direction, 90), amount);
|
||||
pos.rotate(Tmp.v31.set(state.camUp).rotate(state.camDir, 90), amount);
|
||||
});
|
||||
|
||||
addListener(new InputListener(){
|
||||
@Override
|
||||
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY){
|
||||
if(event.targetActor == PlanetDialog.this){
|
||||
zoom = Mathf.clamp(zoom + amountY / 10f, planets.planet.minZoom, 2f);
|
||||
zoom = Mathf.clamp(zoom + amountY / 10f, state.planet.minZoom, 2f);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -145,7 +150,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
lastZoom = zoom;
|
||||
}
|
||||
|
||||
zoom = (Mathf.clamp(initialDistance / distance * lastZoom, planets.planet.minZoom, 2f));
|
||||
zoom = (Mathf.clamp(initialDistance / distance * lastZoom, state.planet.minZoom, 2f));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -171,9 +176,9 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
launching = false;
|
||||
|
||||
zoom = 1f;
|
||||
planets.zoom = 1f;
|
||||
selectAlpha = 0f;
|
||||
launchSector = state.getSector();
|
||||
state.zoom = 1f;
|
||||
state.uiAlpha = 0f;
|
||||
launchSector = Vars.state.getSector();
|
||||
presetShow = 0f;
|
||||
showed = false;
|
||||
listener = s -> {};
|
||||
@@ -182,7 +187,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
|
||||
//announce new presets
|
||||
for(SectorPreset preset : content.sectors()){
|
||||
if(preset.unlocked() && !preset.alwaysUnlocked && !preset.sector.info.shown && !preset.sector.hasBase() && preset.planet == planets.planet){
|
||||
if(preset.unlocked() && !preset.alwaysUnlocked && !preset.sector.info.shown && !preset.sector.hasBase() && preset.planet == state.planet){
|
||||
newPresets.add(preset.sector);
|
||||
preset.sector.info.shown = true;
|
||||
preset.sector.saveInfo();
|
||||
@@ -190,14 +195,14 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
}
|
||||
|
||||
if(newPresets.any()){
|
||||
newPresets.add(planets.planet.getLastSector());
|
||||
newPresets.add(state.planet.getLastSector());
|
||||
}
|
||||
|
||||
newPresets.reverse();
|
||||
updateSelected();
|
||||
|
||||
if(planets.planet.getLastSector() != null){
|
||||
lookAt(planets.planet.getLastSector());
|
||||
if(state.planet.getLastSector() != null){
|
||||
lookAt(state.planet.getLastSector());
|
||||
}
|
||||
|
||||
return super.show();
|
||||
@@ -253,8 +258,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
|
||||
//update view to sector
|
||||
zoom = 1f;
|
||||
planets.zoom = 1f;
|
||||
selectAlpha = 0f;
|
||||
state.zoom = 1f;
|
||||
state.uiAlpha = 0f;
|
||||
|
||||
mode = planetLaunch;
|
||||
|
||||
@@ -270,8 +275,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
//update view to sector
|
||||
lookAt(sector);
|
||||
zoom = 1f;
|
||||
planets.zoom = 1f;
|
||||
selectAlpha = 0f;
|
||||
state.zoom = 1f;
|
||||
state.uiAlpha = 0f;
|
||||
launchSector = sector;
|
||||
|
||||
mode = select;
|
||||
@@ -282,7 +287,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
void lookAt(Sector sector){
|
||||
if(sector.tile == Ptile.empty) return;
|
||||
|
||||
planets.camPos.set(Tmp.v33.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation()));
|
||||
state.camPos.set(Tmp.v33.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation()));
|
||||
}
|
||||
|
||||
boolean canSelect(Sector sector){
|
||||
@@ -310,7 +315,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
launchFrom = to.near().find(Sector::hasBase);
|
||||
if(launchFrom == null && to.preset != null){
|
||||
if(launchSector != null) return launchSector;
|
||||
launchFrom = planets.planet.sectors.min(s -> !s.hasBase() ? Float.MAX_VALUE : s.tile.v.dst2(to.tile.v));
|
||||
launchFrom = state.planet.sectors.min(s -> !s.hasBase() ? Float.MAX_VALUE : s.tile.v.dst2(to.tile.v));
|
||||
if(!launchFrom.hasBase()) launchFrom = null;
|
||||
}
|
||||
}
|
||||
@@ -326,7 +331,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
public void renderSectors(Planet planet){
|
||||
|
||||
//draw all sector stuff
|
||||
if(selectAlpha > 0.01f){
|
||||
if(state.uiAlpha > 0.01f){
|
||||
for(Sector sec : planet.sectors){
|
||||
if(canSelect(sec) || sec.unlocked() || debugSelect){
|
||||
|
||||
@@ -339,15 +344,15 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
null;
|
||||
|
||||
if(color != null){
|
||||
planets.drawSelection(sec, Tmp.c1.set(color).mul(0.8f).a(selectAlpha), 0.026f, -0.001f);
|
||||
planets.drawSelection(sec, Tmp.c1.set(color).mul(0.8f).a(state.uiAlpha), 0.026f, -0.001f);
|
||||
}
|
||||
}else{
|
||||
planets.fill(sec, Tmp.c1.set(shadowColor).mul(1, 1, 1, selectAlpha), -0.001f);
|
||||
planets.fill(sec, Tmp.c1.set(shadowColor).mul(1, 1, 1, state.uiAlpha), -0.001f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sector current = state.getSector() != null && state.getSector().isBeingPlayed() && state.getSector().planet == planets.planet ? state.getSector() : null;
|
||||
Sector current = Vars.state.getSector() != null && Vars.state.getSector().isBeingPlayed() && Vars.state.getSector().planet == state.planet ? Vars.state.getSector() : null;
|
||||
|
||||
if(current != null){
|
||||
planets.fill(current, hoverColor, -0.001f);
|
||||
@@ -374,12 +379,12 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
}
|
||||
}
|
||||
|
||||
if(selectAlpha > 0.001f){
|
||||
if(state.uiAlpha > 0.001f){
|
||||
for(Sector sec : planet.sectors){
|
||||
if(sec.hasBase()){
|
||||
for(Sector enemy : sec.near()){
|
||||
if(enemy.hasEnemyBase()){
|
||||
planets.drawArc(planet, enemy.tile.v, sec.tile.v, Team.crux.color.write(Tmp.c2).a(selectAlpha), Color.clear, 0.24f, 110f, 25);
|
||||
planets.drawArc(planet, enemy.tile.v, sec.tile.v, Team.crux.color.write(Tmp.c2).a(state.uiAlpha), Color.clear, 0.24f, 110f, 25);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,11 +392,11 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
if(selected != null && selected != sec && selected.hasBase()){
|
||||
//imports
|
||||
if(sec.info.getRealDestination() == selected && sec.info.anyExports()){
|
||||
planets.drawArc(planet, sec.tile.v, selected.tile.v, Color.gray.write(Tmp.c2).a(selectAlpha), Pal.accent.write(Tmp.c3).a(selectAlpha), 0.4f, 90f, 25);
|
||||
planets.drawArc(planet, sec.tile.v, selected.tile.v, Color.gray.write(Tmp.c2).a(state.uiAlpha), Pal.accent.write(Tmp.c3).a(state.uiAlpha), 0.4f, 90f, 25);
|
||||
}
|
||||
//exports
|
||||
if(selected.info.getRealDestination() == sec && selected.info.anyExports()){
|
||||
planets.drawArc(planet, selected.tile.v, sec.tile.v, Pal.place.write(Tmp.c2).a(selectAlpha), Pal.accent.write(Tmp.c3).a(selectAlpha), 0.4f, 90f, 25);
|
||||
planets.drawArc(planet, selected.tile.v, sec.tile.v, Pal.place.write(Tmp.c2).a(state.uiAlpha), Pal.accent.write(Tmp.c3).a(state.uiAlpha), 0.4f, 90f, 25);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,7 +423,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
if(icon != null){
|
||||
planets.drawPlane(sec, () -> {
|
||||
//use white for content icons
|
||||
Draw.color(preficon == icon && sec.info.contentIcon != null ? Color.white : color, selectAlpha);
|
||||
Draw.color(preficon == icon && sec.info.contentIcon != null ? Color.white : color, state.uiAlpha);
|
||||
Draw.rect(icon, 0, 0, iw, iw * icon.height / icon.width);
|
||||
});
|
||||
}
|
||||
@@ -447,13 +452,13 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
boolean selectable(Planet planet){
|
||||
//TODO what if any sector is selectable?
|
||||
if(mode == planetLaunch) return launchSector != null && planet != launchSector.planet;
|
||||
return planet == planets.planet || (planet.alwaysUnlocked && planet.isLandable()) || planet.sectors.contains(Sector::hasBase);
|
||||
return planet == state.planet || (planet.alwaysUnlocked && planet.isLandable()) || planet.sectors.contains(Sector::hasBase);
|
||||
}
|
||||
|
||||
void setup(){
|
||||
searchText = "";
|
||||
zoom = planets.zoom = 1f;
|
||||
selectAlpha = 1f;
|
||||
zoom = state.zoom = 1f;
|
||||
state.uiAlpha = 1f;
|
||||
ui.minimapfrag.hide();
|
||||
|
||||
clearChildren();
|
||||
@@ -495,8 +500,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
planets.orbitAlpha = selectAlpha;
|
||||
planets.render(PlanetDialog.this);
|
||||
planets.render(state);
|
||||
}
|
||||
},
|
||||
//info text
|
||||
@@ -521,12 +525,12 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
pt.button(planet.localizedName, Styles.clearTogglet, () -> {
|
||||
selected = null;
|
||||
launchSector = null;
|
||||
if(renderer.planets.planet != planet){
|
||||
renderer.planets.planet = planet;
|
||||
if(state.planet != planet){
|
||||
state.planet = planet;
|
||||
rebuildList();
|
||||
}
|
||||
settings.put("lastplanet", planet.name);
|
||||
}).width(200).height(40).growX().update(bb -> bb.setChecked(renderer.planets.planet == planet));
|
||||
}).width(200).height(40).growX().update(bb -> bb.setChecked(state.planet == planet));
|
||||
pt.row();
|
||||
}
|
||||
}
|
||||
@@ -536,8 +540,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
|
||||
new Table(c -> {
|
||||
c.visible(() -> !(graphics.isPortrait() && mobile));
|
||||
if(planets.planet.sectors.contains(Sector::hasBase)){
|
||||
int attacked = planets.planet.sectors.count(Sector::isAttacked);
|
||||
if(state.planet.sectors.contains(Sector::hasBase)){
|
||||
int attacked = state.planet.sectors.count(Sector::isAttacked);
|
||||
|
||||
//sector notifications & search
|
||||
c.top().right();
|
||||
@@ -567,7 +571,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
|
||||
notifs.clear();
|
||||
|
||||
var all = planets.planet.sectors.select(Sector::hasBase);
|
||||
var all = state.planet.sectors.select(Sector::hasBase);
|
||||
all.sort(Structs.comps(Structs.comparingBool(s -> !s.isAttacked()), Structs.comparingInt(s -> s.save == null ? 0 : -(int)s.save.meta.timePlayed)));
|
||||
|
||||
notifs.pane(p -> {
|
||||
@@ -649,20 +653,20 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
}
|
||||
|
||||
public void lookAt(Sector sector, float alpha){
|
||||
float len = planets.camPos.len();
|
||||
planets.camPos.slerp(Tmp.v31.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation()).setLength(len), alpha);
|
||||
float len = state.camPos.len();
|
||||
state.camPos.slerp(Tmp.v31.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation()).setLength(len), alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta){
|
||||
super.act(delta);
|
||||
|
||||
if(hovered != null && !mobile && planets.planet.hasGrid()){
|
||||
if(hovered != null && !mobile && state.planet.hasGrid()){
|
||||
addChild(hoverLabel);
|
||||
hoverLabel.toFront();
|
||||
hoverLabel.touchable = Touchable.disabled;
|
||||
|
||||
Vec3 pos = planets.cam.project(Tmp.v31.set(hovered.tile.v).setLength(PlanetRenderer.outlineRad).rotate(Vec3.Y, -planets.planet.getRotation()).add(planets.planet.position));
|
||||
Vec3 pos = planets.cam.project(Tmp.v31.set(hovered.tile.v).setLength(PlanetRenderer.outlineRad).rotate(Vec3.Y, -state.planet.getRotation()).add(state.planet.position));
|
||||
hoverLabel.setPosition(pos.x - Core.scene.marginLeft, pos.y - Core.scene.marginBottom, Align.center);
|
||||
|
||||
hoverLabel.getText().setLength(0);
|
||||
@@ -707,13 +711,13 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
}
|
||||
}
|
||||
|
||||
if(planets.planet.hasGrid()){
|
||||
hovered = planets.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad);
|
||||
}else if(planets.planet.isLandable()){
|
||||
if(state.planet.hasGrid()){
|
||||
hovered = state.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad);
|
||||
}else if(state.planet.isLandable()){
|
||||
boolean wasNull = selected == null;
|
||||
//always have the first sector selected.
|
||||
//TODO better support for multiple sectors in gridless planets?
|
||||
hovered = selected = planets.planet.sectors.first();
|
||||
hovered = selected = state.planet.sectors.first();
|
||||
|
||||
//autoshow
|
||||
if(wasNull){
|
||||
@@ -723,8 +727,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
hovered = selected = null;
|
||||
}
|
||||
|
||||
planets.zoom = Mathf.lerpDelta(planets.zoom, zoom, 0.4f);
|
||||
selectAlpha = Mathf.lerpDelta(selectAlpha, Mathf.num(planets.zoom < 1.9f), 0.1f);
|
||||
state.zoom = Mathf.lerpDelta(state.zoom, zoom, 0.4f);
|
||||
state.uiAlpha = Mathf.lerpDelta(state.uiAlpha, Mathf.num(state.zoom < 1.9f), 0.1f);
|
||||
}
|
||||
|
||||
void displayItems(Table c, float scl, ObjectMap<Item, ExportStat> stats, String name){
|
||||
@@ -1009,11 +1013,11 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
if(launching){
|
||||
stable.color.sub(0, 0, 0, 0.05f * Time.delta);
|
||||
}else{
|
||||
if(!planets.planet.hasGrid()){
|
||||
if(!state.planet.hasGrid()){
|
||||
stable.color.a = 1f;
|
||||
}else{
|
||||
//fade out UI when not facing selected sector
|
||||
Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planets.planet.getRotation()).scl(-1f).nor();
|
||||
Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -state.planet.getRotation()).scl(-1f).nor();
|
||||
float dot = planets.cam.direction.dot(Tmp.v31);
|
||||
stable.color.a = Math.max(dot, 0f)*2f;
|
||||
if(dot*2f <= -0.1f){
|
||||
@@ -1046,7 +1050,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
boolean shouldHide = true;
|
||||
|
||||
//save before launch.
|
||||
if(control.saves.getCurrent() != null && state.isGame() && mode != select){
|
||||
if(control.saves.getCurrent() != null && Vars.state.isGame() && mode != select){
|
||||
try{
|
||||
control.saves.getCurrent().save();
|
||||
}catch(Throwable e){
|
||||
|
||||
Reference in New Issue
Block a user