Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.progrmor.tombstone.screens.screens;
- import java.io.IOException;
- import java.io.InputStream;
- import java.nio.ByteBuffer;
- import com.badlogic.gdx.*;
- import com.badlogic.gdx.audio.Sound;
- import com.badlogic.gdx.files.FileHandle;
- import com.badlogic.gdx.graphics.*;
- import com.badlogic.gdx.graphics.g2d.Animation;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.Sprite;
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
- import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
- import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
- import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
- import com.badlogic.gdx.input.GestureDetector;
- import com.badlogic.gdx.scenes.scene2d.Actor;
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Image;
- import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
- import com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle;
- import com.badlogic.gdx.scenes.scene2d.ui.Label;
- import com.badlogic.gdx.scenes.scene2d.ui.Skin;
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
- import com.badlogic.gdx.scenes.scene2d.ui.TextArea;
- import com.badlogic.gdx.scenes.scene2d.ui.TextField;
- import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
- import com.badlogic.gdx.scenes.scene2d.utils.*;
- import com.badlogic.gdx.utils.ObjectMap;
- import com.badlogic.gdx.utils.ScreenUtils;
- import com.badlogic.gdx.utils.StreamUtils;
- import com.badlogic.gdx.utils.viewport.Viewport;
- import com.badlogic.gdx.utils.viewport.StretchViewport;
- import com.badlogic.gdx.Input.TextInputListener;
- import com.progrmor.tombstone.TombStone;
- import com.progrmor.tombstone.helpers.Assets;
- import com.progrmor.tombstone.helpers.purchaseInterface;
- import static com.badlogic.gdx.Gdx.*;
- public class StoneScreen implements Screen, purchaseInterface {
- OrthographicCamera camera;
- Viewport view;
- final TombStone game;
- purchaseInterface pInt;
- Texture arrow, arrowDown,
- //TextField´s stuff
- private Stage stageButton;
- private Table table;
- private int counter= 1;
- String filePath = files.getLocalStoragePath() + "stoneIMG" + counter + ".png";
- private int backButtonW = 20;
- public Assets assets;
- public StoneScreen(TombStone gam) {
- this.game = gam;
- this.pInt = game.pi;
- assets = new Assets();
- camera = new OrthographicCamera();
- view = new StretchViewport(screenWidth, screenHeight,camera);
- view.apply();
- camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
- loadStandard();
- stageButton = new Stage(view);
- }
- public void loadStandard(){
- arrow = assets.manager.get(assets.arrow, Texture.class);
- arrowDown=assets.manager.get(assets.arrowDown, Texture.class);
- }
- @Override
- public void render(float delta) {
- Gdx.gl.glClearColor(0, 0, 0, 0);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- game.batch.setProjectionMatrix(camera.combined);
- camera.update();
- stageButton.act(graphics.getDeltaTime());
- stageButton.draw();
- }
- @Override
- public void resize(int width, int height) {
- stageButton.setViewport(view);
- stageButton.getViewport().update(width, height, true);
- camera.update();
- }
- @Override
- public void show() {
- table = new Table();
- ImageButtonStyle styleTwo = new ImageButtonStyle();
- TextureRegionDrawable arrowImage = new TextureRegionDrawable(new TextureRegion(arrowDown));
- TextureRegionDrawable arrowImageDown = new TextureRegionDrawable(new TextureRegion(arrow));
- styleTwo.up = skin.newDrawable(skin.newDrawable(arrowImage));
- styleTwo.down = skin.newDrawable(skin.newDrawable(arrowImageDown));
- //Back button
- btnArrow = new ImageButton(styleTwo);
- table.add(btnArrow).pad(170).size(130, 130);
- stageButton.addActor(table);
- //Backbutton takes us back to mainmenu and saves some prefs.
- btnArrow.addListener(new ChangeListener() {
- //photoshop "save" and "back" on arrow/back image to clarify.
- @Override
- public void changed(ChangeEvent event, Actor actor) {
- saveScreenshot();
- sharePhoto();
- }
- });
- }
- @Override
- public void hide() {
- // TODO Auto-generated method stub
- }
- @Override
- public void pause() {
- // TODO Auto-generated method stub
- }
- @Override
- public void resume() {
- // TODO Auto-generated method stub
- }
- @Override
- public void dispose() {
- }
- private void saveScreenshot() {
- try{
- FileHandle fh;
- do{
- fh = new FileHandle(files.getLocalStoragePath() + "screenshot" + ".png");
- }while(fh.exists());
- Pixmap pixmap = getScreenshot(0, 0, graphics.getWidth(), graphics.getHeight() - 130, true);
- PixmapIO.writePNG(fh, pixmap);
- pixmap.dispose();
- System.out.println(fh.toString());
- }catch(Exception e) {
- }
- }
- private Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown){
- final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
- w = pixmap.getWidth();
- h = pixmap.getHeight();
- if(yDown) {
- ByteBuffer pixels = pixmap.getPixels();
- int numBytes = w * h * 4;
- byte[] lines = new byte[numBytes];
- int numBytesPerLine = w * 4;
- for (int i = 0; i < h; i++) {
- pixels.position((h - i - 1) * numBytesPerLine);
- pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
- }
- pixels.clear();
- pixels.put(lines);
- }
- return pixmap;
- }
- @Override
- public void sharePhoto() {
- pInt.sharePhoto();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement