Skip to content

Commit

Permalink
Merge pull request #3 from Interrupt/texture-picker
Browse files Browse the repository at this point in the history
File menu with saving & loading
  • Loading branch information
Interrupt authored Jul 16, 2016
2 parents dfabcd4 + d4a3d89 commit 15f15f0
Show file tree
Hide file tree
Showing 10 changed files with 628 additions and 83 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ allprojects {
ext {
appName = "doom-engine-test"
gdxVersion = '1.9.3'
roboVMVersion = '2.1.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
lwjglVersion = '2.9.2'
}

repositories {
Expand Down Expand Up @@ -47,6 +44,7 @@ project(":core") {

dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "org.lwjgl.lwjgl:lwjgl_util:$lwjglVersion"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
Expand All @@ -17,20 +17,12 @@
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.Ray;
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.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.Json;
import com.interrupt.doomtest.collisions.WorldIntersection;
import com.interrupt.doomtest.collisions.WorldIntersector;
import com.interrupt.doomtest.editor.ui.TextureRegionPicker;
import com.interrupt.doomtest.editor.ui.Hud;
import com.interrupt.doomtest.gfx.Art;
import com.interrupt.doomtest.gfx.renderer.RendererFrontend;
import com.interrupt.doomtest.input.EditorCameraController;
Expand All @@ -40,16 +32,13 @@
import com.interrupt.doomtest.levels.Sector;
import com.interrupt.doomtest.levels.editor.Editor;

public class DoomTestEditor extends ApplicationAdapter {
public class DoomLikeEditor extends ApplicationAdapter {

Camera camera;
EditorCameraController camController;
ShapeRenderer lineRenderer;
RendererFrontend renderer;

public Stage hudStage;
public Skin hudSkin;

public Level level = new Level();
public Editor editor = new Editor(level);
public Sector current;
Expand All @@ -69,13 +58,13 @@ public class DoomTestEditor extends ApplicationAdapter {
Float editHeight = null;

Sector hoveredSector = null;
Sector pickedSector = null;
public Sector pickedSector = null;

Vector2 hoveredPoint = null;
Vector2 pickedPoint = null;

Line hoveredLine = null;
Line pickedLine = null;
public Line pickedLine = null;

Vector2 lastMousePoint = new Vector2();
public float startHeightModeFloorHeight = 0;
Expand All @@ -96,8 +85,8 @@ public enum EditorModes { SECTOR, POINT, SPLIT };

public static float GRID_SNAP = 2f;

Image texturePickerButton;
TextureRegion currentTexture;
public TextureRegion currentTexture;
public Stage hudStage;

@Override
public void create () {
Expand All @@ -122,11 +111,15 @@ public void create () {

// Setup HUD
OrthographicCamera hudCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
hudStage = new Stage(new ScreenViewport(hudCamera));
hudSkin = new Skin(Gdx.files.local("ui/HoloSkin/Holo-dark-ldpi.json"),
new TextureAtlas(Gdx.files.local("ui/HoloSkin/Holo-dark-ldpi.atlas")));

// Setup Input
// Load textures
Array<TextureRegion> textures = loadTexturesFromAtlas("textures/textures.png");
textures.add(new TextureRegion(Art.getTexture("textures/wall1.png")));

// Setup the menu / HUD
hudStage = Hud.create(textures, textures.get(textures.size - 1), this);

// Wire up the input sources
EditorInput editorInput = new EditorInput() {
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int btn) {
Expand All @@ -139,15 +132,7 @@ public boolean touchDown(int screenX, int screenY, int pointer, int btn) {
input.addProcessor(hudStage);
input.addProcessor(editorInput);
input.addProcessor(camController);

Gdx.input.setInputProcessor(input);

// Texture picker
Array<TextureRegion> textures = loadTexturesFromAtlas("textures/textures.png");
textures.add(new TextureRegion(Art.getTexture("textures/wall1.png")));

currentTexture = textures.get(textures.size - 1);
setupHud(textures, currentTexture);
}

public void refreshRenderer() {
Expand Down Expand Up @@ -746,48 +731,6 @@ public void renderGrid() {
lineRenderer.end();
}

private void setupHud(final Array<TextureRegion> textures, TextureRegion current) {
texturePickerButton = new Image(new TextureRegionDrawable(current));
texturePickerButton.setScaling(Scaling.stretch);

Table wallPickerLayoutTable = new Table();
wallPickerLayoutTable.setFillParent(true);
wallPickerLayoutTable.align(Align.left | Align.top).pad(20f).padTop(20f);

wallPickerLayoutTable.add(texturePickerButton).width(50f).height(50f).align(Align.left).padBottom(6f);
wallPickerLayoutTable.row();

texturePickerButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
TextureRegionPicker picker = new TextureRegionPicker("Pick Current Texture", hudSkin, textures) {
@Override
public void result(Integer value, TextureRegion region) {
setTexture(region);
texturePickerButton.setDrawable(new TextureRegionDrawable(region));
}
};
hudStage.addActor(picker);
picker.show(hudStage);
event.handle();
}
});

hudStage.addActor(wallPickerLayoutTable);
}

public void setTexture(TextureRegion texture) {
currentTexture = texture;

if(pickedLine != null) {
pickedLine.lowerMaterial.set(TextureAttribute.createDiffuse(texture));
}
else if(pickedSector != null) {
pickedSector.floorMaterial.set(TextureAttribute.createDiffuse(texture));
}
refreshRenderer();
}

public Array<TextureRegion> loadTexturesFromAtlas(String filename) {
Pixmap atlas = new Pixmap(Gdx.files.local(filename));
int texSize = atlas.getWidth() / 4;
Expand All @@ -809,4 +752,15 @@ public Array<TextureRegion> loadTexturesFromAtlas(String filename) {

return textures;
}

public void saveLevel(FileHandle file) {
Json json = new Json();
file.writeString(json.prettyPrint(level), false);
}

public void openLevel(FileHandle file) {
Json json = new Json();
String js = file.readString();
level = json.fromJson(Level.class, js);
}
}
Loading

0 comments on commit 15f15f0

Please sign in to comment.