Skip to content

Commit 15f15f0

Browse files
authored
Merge pull request #3 from Interrupt/texture-picker
File menu with saving & loading
2 parents dfabcd4 + d4a3d89 commit 15f15f0

File tree

10 files changed

+628
-83
lines changed

10 files changed

+628
-83
lines changed

Diff for: build.gradle

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ allprojects {
1616
ext {
1717
appName = "doom-engine-test"
1818
gdxVersion = '1.9.3'
19-
roboVMVersion = '2.1.0'
20-
box2DLightsVersion = '1.4'
21-
ashleyVersion = '1.7.0'
22-
aiVersion = '1.8.0'
19+
lwjglVersion = '2.9.2'
2320
}
2421

2522
repositories {
@@ -47,6 +44,7 @@ project(":core") {
4744

4845
dependencies {
4946
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
47+
compile "org.lwjgl.lwjgl:lwjgl_util:$lwjglVersion"
5048
}
5149
}
5250

Diff for: core/src/com/interrupt/doomtest/DoomTestEditor.java renamed to core/src/com/interrupt/doomtest/DoomLikeEditor.java

+27-73
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.badlogic.gdx.Gdx;
55
import com.badlogic.gdx.Input;
66
import com.badlogic.gdx.InputMultiplexer;
7+
import com.badlogic.gdx.files.FileHandle;
78
import com.badlogic.gdx.graphics.*;
8-
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
99
import com.badlogic.gdx.graphics.g2d.TextureRegion;
1010
import com.badlogic.gdx.graphics.g3d.Material;
1111
import com.badlogic.gdx.graphics.g3d.ModelInstance;
@@ -17,20 +17,12 @@
1717
import com.badlogic.gdx.math.Vector2;
1818
import com.badlogic.gdx.math.Vector3;
1919
import com.badlogic.gdx.math.collision.Ray;
20-
import com.badlogic.gdx.scenes.scene2d.InputEvent;
2120
import com.badlogic.gdx.scenes.scene2d.Stage;
22-
import com.badlogic.gdx.scenes.scene2d.ui.Image;
23-
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
24-
import com.badlogic.gdx.scenes.scene2d.ui.Table;
25-
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
26-
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
27-
import com.badlogic.gdx.utils.Align;
2821
import com.badlogic.gdx.utils.Array;
29-
import com.badlogic.gdx.utils.Scaling;
30-
import com.badlogic.gdx.utils.viewport.ScreenViewport;
22+
import com.badlogic.gdx.utils.Json;
3123
import com.interrupt.doomtest.collisions.WorldIntersection;
3224
import com.interrupt.doomtest.collisions.WorldIntersector;
33-
import com.interrupt.doomtest.editor.ui.TextureRegionPicker;
25+
import com.interrupt.doomtest.editor.ui.Hud;
3426
import com.interrupt.doomtest.gfx.Art;
3527
import com.interrupt.doomtest.gfx.renderer.RendererFrontend;
3628
import com.interrupt.doomtest.input.EditorCameraController;
@@ -40,16 +32,13 @@
4032
import com.interrupt.doomtest.levels.Sector;
4133
import com.interrupt.doomtest.levels.editor.Editor;
4234

43-
public class DoomTestEditor extends ApplicationAdapter {
35+
public class DoomLikeEditor extends ApplicationAdapter {
4436

4537
Camera camera;
4638
EditorCameraController camController;
4739
ShapeRenderer lineRenderer;
4840
RendererFrontend renderer;
4941

50-
public Stage hudStage;
51-
public Skin hudSkin;
52-
5342
public Level level = new Level();
5443
public Editor editor = new Editor(level);
5544
public Sector current;
@@ -69,13 +58,13 @@ public class DoomTestEditor extends ApplicationAdapter {
6958
Float editHeight = null;
7059

7160
Sector hoveredSector = null;
72-
Sector pickedSector = null;
61+
public Sector pickedSector = null;
7362

7463
Vector2 hoveredPoint = null;
7564
Vector2 pickedPoint = null;
7665

7766
Line hoveredLine = null;
78-
Line pickedLine = null;
67+
public Line pickedLine = null;
7968

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

9786
public static float GRID_SNAP = 2f;
9887

99-
Image texturePickerButton;
100-
TextureRegion currentTexture;
88+
public TextureRegion currentTexture;
89+
public Stage hudStage;
10190

10291
@Override
10392
public void create () {
@@ -122,11 +111,15 @@ public void create () {
122111

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

129-
// Setup Input
115+
// Load textures
116+
Array<TextureRegion> textures = loadTexturesFromAtlas("textures/textures.png");
117+
textures.add(new TextureRegion(Art.getTexture("textures/wall1.png")));
118+
119+
// Setup the menu / HUD
120+
hudStage = Hud.create(textures, textures.get(textures.size - 1), this);
121+
122+
// Wire up the input sources
130123
EditorInput editorInput = new EditorInput() {
131124
@Override
132125
public boolean touchDown(int screenX, int screenY, int pointer, int btn) {
@@ -139,15 +132,7 @@ public boolean touchDown(int screenX, int screenY, int pointer, int btn) {
139132
input.addProcessor(hudStage);
140133
input.addProcessor(editorInput);
141134
input.addProcessor(camController);
142-
143135
Gdx.input.setInputProcessor(input);
144-
145-
// Texture picker
146-
Array<TextureRegion> textures = loadTexturesFromAtlas("textures/textures.png");
147-
textures.add(new TextureRegion(Art.getTexture("textures/wall1.png")));
148-
149-
currentTexture = textures.get(textures.size - 1);
150-
setupHud(textures, currentTexture);
151136
}
152137

153138
public void refreshRenderer() {
@@ -746,48 +731,6 @@ public void renderGrid() {
746731
lineRenderer.end();
747732
}
748733

749-
private void setupHud(final Array<TextureRegion> textures, TextureRegion current) {
750-
texturePickerButton = new Image(new TextureRegionDrawable(current));
751-
texturePickerButton.setScaling(Scaling.stretch);
752-
753-
Table wallPickerLayoutTable = new Table();
754-
wallPickerLayoutTable.setFillParent(true);
755-
wallPickerLayoutTable.align(Align.left | Align.top).pad(20f).padTop(20f);
756-
757-
wallPickerLayoutTable.add(texturePickerButton).width(50f).height(50f).align(Align.left).padBottom(6f);
758-
wallPickerLayoutTable.row();
759-
760-
texturePickerButton.addListener(new ClickListener() {
761-
@Override
762-
public void clicked(InputEvent event, float x, float y) {
763-
TextureRegionPicker picker = new TextureRegionPicker("Pick Current Texture", hudSkin, textures) {
764-
@Override
765-
public void result(Integer value, TextureRegion region) {
766-
setTexture(region);
767-
texturePickerButton.setDrawable(new TextureRegionDrawable(region));
768-
}
769-
};
770-
hudStage.addActor(picker);
771-
picker.show(hudStage);
772-
event.handle();
773-
}
774-
});
775-
776-
hudStage.addActor(wallPickerLayoutTable);
777-
}
778-
779-
public void setTexture(TextureRegion texture) {
780-
currentTexture = texture;
781-
782-
if(pickedLine != null) {
783-
pickedLine.lowerMaterial.set(TextureAttribute.createDiffuse(texture));
784-
}
785-
else if(pickedSector != null) {
786-
pickedSector.floorMaterial.set(TextureAttribute.createDiffuse(texture));
787-
}
788-
refreshRenderer();
789-
}
790-
791734
public Array<TextureRegion> loadTexturesFromAtlas(String filename) {
792735
Pixmap atlas = new Pixmap(Gdx.files.local(filename));
793736
int texSize = atlas.getWidth() / 4;
@@ -809,4 +752,15 @@ public Array<TextureRegion> loadTexturesFromAtlas(String filename) {
809752

810753
return textures;
811754
}
755+
756+
public void saveLevel(FileHandle file) {
757+
Json json = new Json();
758+
file.writeString(json.prettyPrint(level), false);
759+
}
760+
761+
public void openLevel(FileHandle file) {
762+
Json json = new Json();
763+
String js = file.readString();
764+
level = json.fromJson(Level.class, js);
765+
}
812766
}

0 commit comments

Comments
 (0)