Added fullscreen map screenshot

This commit is contained in:
Anuken
2018-11-25 20:43:45 -05:00
parent a7f7a09418
commit 54ad9ba243
9 changed files with 67 additions and 13 deletions

View File

@ -25,7 +25,7 @@ allprojects {
appName = 'Mindustry'
gdxVersion = '1.9.9'
roboVMVersion = '2.3.0'
uCoreVersion = '09e13f973a0769d971316d1d4f4a1eef3570926f'
uCoreVersion = '7610a9e20ebb0db62256b70f97e1783f5416e71d'
getVersionString = {
String buildVersion = getBuildVersion()

View File

@ -10,6 +10,7 @@ text.link.itch.io.description = itch.io page with PC downloads and web version
text.link.google-play.description = Google Play store listing
text.link.wiki.description = Official Mindustry wiki
text.linkfail = Failed to open link!\nThe URL has been copied to your clipboard.
text.screenshot = Screenshot saved to {0}
text.gameover = Game Over
text.gameover.pvp = The[accent] {0}[] team is victorious!
text.sector.gameover = This sector has been lost. Re-deploy?
@ -384,6 +385,7 @@ command.retreat = Retreat
command.patrol = Patrol
keybind.press = Press a key...
keybind.press.axis = Press an axis or key...
keybind.screenshot.name = Map Screenshot
keybind.move_x.name = Move x
keybind.move_y.name = Move y
keybind.select.name = Select/Shoot

View File

@ -12,7 +12,6 @@ precision highp int;
uniform sampler2D u_texture;
uniform vec2 u_texsize;
uniform float u_time;
uniform float u_scaling;
uniform float u_dp;
uniform vec2 u_offset;
@ -28,7 +27,7 @@ void main() {
vec2 T = v_texCoord.xy;
vec2 coords = (T * u_texsize) + u_offset;
T += vec2(sin(coords.y / 3.0 + u_time / 20.0) / 240.0, sin(coords.x / 3.0 + u_time / 20.0) / 240.0) * u_scaling;
T += vec2(sin(coords.y / 3.0 + u_time / 20.0), sin(coords.x / 3.0 + u_time / 20.0)) / u_texsize;
float si = sin(u_time / 20.0) / 8.0;
vec4 color = texture2D(u_texture, T);

View File

@ -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));

View File

@ -373,6 +373,10 @@ public class Control extends Module{
}
}
if(Inputs.keyTap("screenshot")){
renderer.takeMapScreenshot();
}
}else{
if(!state.isPaused()){
Timers.update();

View File

@ -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()));
}
}

View File

@ -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();

View File

@ -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());
}
}

View File

@ -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,