4
4
import com .badlogic .gdx .Gdx ;
5
5
import com .badlogic .gdx .Input ;
6
6
import com .badlogic .gdx .InputMultiplexer ;
7
+ import com .badlogic .gdx .files .FileHandle ;
7
8
import com .badlogic .gdx .graphics .*;
8
- import com .badlogic .gdx .graphics .g2d .TextureAtlas ;
9
9
import com .badlogic .gdx .graphics .g2d .TextureRegion ;
10
10
import com .badlogic .gdx .graphics .g3d .Material ;
11
11
import com .badlogic .gdx .graphics .g3d .ModelInstance ;
17
17
import com .badlogic .gdx .math .Vector2 ;
18
18
import com .badlogic .gdx .math .Vector3 ;
19
19
import com .badlogic .gdx .math .collision .Ray ;
20
- import com .badlogic .gdx .scenes .scene2d .InputEvent ;
21
20
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 ;
28
21
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 ;
31
23
import com .interrupt .doomtest .collisions .WorldIntersection ;
32
24
import com .interrupt .doomtest .collisions .WorldIntersector ;
33
- import com .interrupt .doomtest .editor .ui .TextureRegionPicker ;
25
+ import com .interrupt .doomtest .editor .ui .Hud ;
34
26
import com .interrupt .doomtest .gfx .Art ;
35
27
import com .interrupt .doomtest .gfx .renderer .RendererFrontend ;
36
28
import com .interrupt .doomtest .input .EditorCameraController ;
40
32
import com .interrupt .doomtest .levels .Sector ;
41
33
import com .interrupt .doomtest .levels .editor .Editor ;
42
34
43
- public class DoomTestEditor extends ApplicationAdapter {
35
+ public class DoomLikeEditor extends ApplicationAdapter {
44
36
45
37
Camera camera ;
46
38
EditorCameraController camController ;
47
39
ShapeRenderer lineRenderer ;
48
40
RendererFrontend renderer ;
49
41
50
- public Stage hudStage ;
51
- public Skin hudSkin ;
52
-
53
42
public Level level = new Level ();
54
43
public Editor editor = new Editor (level );
55
44
public Sector current ;
@@ -69,13 +58,13 @@ public class DoomTestEditor extends ApplicationAdapter {
69
58
Float editHeight = null ;
70
59
71
60
Sector hoveredSector = null ;
72
- Sector pickedSector = null ;
61
+ public Sector pickedSector = null ;
73
62
74
63
Vector2 hoveredPoint = null ;
75
64
Vector2 pickedPoint = null ;
76
65
77
66
Line hoveredLine = null ;
78
- Line pickedLine = null ;
67
+ public Line pickedLine = null ;
79
68
80
69
Vector2 lastMousePoint = new Vector2 ();
81
70
public float startHeightModeFloorHeight = 0 ;
@@ -96,8 +85,8 @@ public enum EditorModes { SECTOR, POINT, SPLIT };
96
85
97
86
public static float GRID_SNAP = 2f ;
98
87
99
- Image texturePickerButton ;
100
- TextureRegion currentTexture ;
88
+ public TextureRegion currentTexture ;
89
+ public Stage hudStage ;
101
90
102
91
@ Override
103
92
public void create () {
@@ -122,11 +111,15 @@ public void create () {
122
111
123
112
// Setup HUD
124
113
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" )));
128
114
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
130
123
EditorInput editorInput = new EditorInput () {
131
124
@ Override
132
125
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) {
139
132
input .addProcessor (hudStage );
140
133
input .addProcessor (editorInput );
141
134
input .addProcessor (camController );
142
-
143
135
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 );
151
136
}
152
137
153
138
public void refreshRenderer () {
@@ -746,48 +731,6 @@ public void renderGrid() {
746
731
lineRenderer .end ();
747
732
}
748
733
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
-
791
734
public Array <TextureRegion > loadTexturesFromAtlas (String filename ) {
792
735
Pixmap atlas = new Pixmap (Gdx .files .local (filename ));
793
736
int texSize = atlas .getWidth () / 4 ;
@@ -809,4 +752,15 @@ public Array<TextureRegion> loadTexturesFromAtlas(String filename) {
809
752
810
753
return textures ;
811
754
}
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
+ }
812
766
}
0 commit comments