Added fullscreen map screenshot
This commit is contained in:
@@ -81,6 +81,8 @@ public class Vars{
|
||||
public static boolean android;
|
||||
//main data directory
|
||||
public static FileHandle dataDirectory;
|
||||
//subdirectory for screenshots
|
||||
public static FileHandle screenshotDirectory;
|
||||
//directory for user-created map data
|
||||
public static FileHandle customMapDirectory;
|
||||
//save file directory
|
||||
@@ -172,6 +174,7 @@ public class Vars{
|
||||
android = Gdx.app.getType() == ApplicationType.Android;
|
||||
|
||||
dataDirectory = Settings.getDataDirectory(appName);
|
||||
screenshotDirectory = dataDirectory.child("screenshots/");
|
||||
customMapDirectory = dataDirectory.child("maps/");
|
||||
saveDirectory = dataDirectory.child("saves/");
|
||||
baseCameraScale = Math.round(Unit.dp.scl(4));
|
||||
|
||||
@@ -373,6 +373,10 @@ public class Control extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
if(Inputs.keyTap("screenshot")){
|
||||
renderer.takeMapScreenshot();
|
||||
}
|
||||
|
||||
}else{
|
||||
if(!state.isPaused()){
|
||||
Timers.update();
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.PixmapIO;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.BufferUtils;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@@ -33,6 +39,7 @@ import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.graphics.Surface;
|
||||
import io.anuke.ucore.modules.RendererModule;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Pooling;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
@@ -378,4 +385,44 @@ public class Renderer extends RendererModule{
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(s * 2), Math.round(s * 5));
|
||||
}
|
||||
|
||||
public void takeMapScreenshot(){
|
||||
float vpW = Core.camera.viewportWidth, vpH = Core.camera.viewportHeight;
|
||||
int w = world.width()*tilesize, h = world.height()*tilesize;
|
||||
int pw = pixelSurface.width(), ph = pixelSurface.height();
|
||||
showFog = false;
|
||||
disableUI = true;
|
||||
pixelSurface.setSize(w, h, true);
|
||||
Graphics.getEffectSurface().setSize(w, h, true);
|
||||
Core.camera.viewportWidth = w;
|
||||
Core.camera.viewportHeight = h;
|
||||
Core.camera.position.x = w/2f;
|
||||
Core.camera.position.y = h/2f;
|
||||
|
||||
draw();
|
||||
|
||||
showFog = true;
|
||||
disableUI = false;
|
||||
Core.camera.viewportWidth = vpW;
|
||||
Core.camera.viewportHeight = vpH;
|
||||
|
||||
pixelSurface.getBuffer().begin();
|
||||
byte[] lines = ScreenUtils.getFrameBufferPixels(0, 0, w, h, true);
|
||||
for(int i = 0; i < lines.length; i+= 4){
|
||||
lines[i + 3] = (byte)255;
|
||||
}
|
||||
pixelSurface.getBuffer().end();
|
||||
|
||||
Pixmap fullPixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
|
||||
|
||||
BufferUtils.copy(lines, 0, fullPixmap.getPixels(), lines.length);
|
||||
FileHandle file = screenshotDirectory.child("screenshot-" + TimeUtils.millis() + ".png");
|
||||
PixmapIO.writePNG(file, fullPixmap);
|
||||
fullPixmap.dispose();
|
||||
|
||||
pixelSurface.setSize(pw, ph, false);
|
||||
Graphics.getEffectSurface().setSize(pw, ph, false);
|
||||
|
||||
ui.showInfoFade(Bundles.format("text.screenshot", file.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public enum CacheLayer{
|
||||
|
||||
protected void beginShader(){
|
||||
//renderer.getBlocks().endFloor();
|
||||
renderer.effectSurface.getBuffer().bind();
|
||||
renderer.effectSurface.getBuffer().begin();
|
||||
Graphics.clear(Color.CLEAR);
|
||||
//renderer.getBlocks().beginFloor();
|
||||
}
|
||||
@@ -73,7 +73,9 @@ public enum CacheLayer{
|
||||
public void endShader(Shader shader){
|
||||
renderer.blocks.endFloor();
|
||||
|
||||
renderer.pixelSurface.getBuffer().bind();
|
||||
renderer.effectSurface.getBuffer().end();
|
||||
|
||||
renderer.pixelSurface.getBuffer().begin();
|
||||
|
||||
Graphics.shader(shader);
|
||||
Graphics.begin();
|
||||
|
||||
@@ -175,17 +175,13 @@ public class Shaders{
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
float scaling = Core.cameraScale / 4f / Core.camera.zoom;
|
||||
|
||||
shader.setUniformf("u_dp", Unit.dp.scl(1f));
|
||||
//shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_time", Timers.time() / Unit.dp.scl(1f));
|
||||
shader.setUniformf("u_scaling", scaling);
|
||||
shader.setUniformf("u_offset",
|
||||
Core.camera.position.x - Core.camera.viewportWidth / 2 * Core.camera.zoom,
|
||||
Core.camera.position.y - Core.camera.viewportHeight / 2 * Core.camera.zoom);
|
||||
shader.setUniformf("u_texsize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
shader.setUniformf("u_texsize", Core.camera.viewportWidth * Core.camera.zoom,
|
||||
Core.camera.viewportHeight * Core.camera.zoom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,8 +196,8 @@ public class Shaders{
|
||||
shader.setUniformf("camerapos",
|
||||
Core.camera.position.x - Core.camera.viewportWidth / 2 * Core.camera.zoom,
|
||||
Core.camera.position.y - Core.camera.viewportHeight / 2 * Core.camera.zoom);
|
||||
shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
shader.setUniformf("screensize", Core.camera.viewportWidth* Core.camera.zoom,
|
||||
Core.camera.viewportHeight * Core.camera.zoom);
|
||||
shader.setUniformf("time", Timers.time());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class DefaultKeybinds{
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"toggle_menus", Input.C,
|
||||
"screenshot", Input.P,
|
||||
new Category("multiplayer"),
|
||||
"player_list", Input.TAB,
|
||||
"chat", Input.ENTER,
|
||||
|
||||
Reference in New Issue
Block a user