~repos /gdx-studio

#libgdx#java#desktop

git clone https://pyrossh.dev/repos/gdx-studio.git

An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop


a9b2a64a pyros2097

11 years ago
v0.7.1
Files changed (94) hide show
  1. .classpath +2 -5
  2. Panel/AndroidManifest.xml +0 -24
  3. Panel/ScenePanel.java +0 -539
  4. Panel/proguard.cfg +0 -40
  5. README.md +198 -3
  6. Stage/Actions3d.java +0 -1414
  7. Stage/Actor3d.java +0 -361
  8. Stage/Group3d.java +0 -146
  9. Stage/Scene.java +0 -80
  10. Stage/Scene3d.java +0 -5
  11. Stage/SpriteChar.java +0 -11
  12. Stage/Stage.java +0 -1272
  13. Stage/Stage3d.java +0 -488
  14. Type/EffectType.java +0 -10
  15. Type/GestureType.java +0 -19
  16. Type/MovedListener.java +0 -3
  17. Type/OnEventType.java +0 -5
  18. Type/TransitionType.java +0 -3
  19. icon/background.png +0 -0
  20. icon/style.png +0 -0
  21. shots/shot1.png +0 -0
  22. shots/shot2.png +0 -0
  23. shots/shot3.png +0 -0
  24. shots/shot4.png +0 -0
  25. shots/shot5.png +0 -0
  26. shots/shot6.png +0 -0
  27. {IDE → src/gdxstudio}/Content.java +16 -24
  28. {IDE → src/gdxstudio}/Editor.java +9 -8
  29. {IDE → src/gdxstudio}/Export.java +22 -16
  30. {IDE → src/gdxstudio}/Frame.java +24 -12
  31. IDE/Main.java → src/gdxstudio/GdxStudio.java +6 -1
  32. {IDE → src/gdxstudio}/Icon.java +4 -1
  33. src/gdxstudio/SceneEditor.java +263 -0
  34. {IDE → src/gdxstudio}/SearchBar.java +1 -0
  35. {IDE → src/gdxstudio}/StatusBar.java +22 -4
  36. {IDE → src/gdxstudio}/Style.java +27 -14
  37. {IDE → src/gdxstudio}/ToolBar.java +54 -65
  38. {IDE → src/gdxstudio}/Update.java +4 -3
  39. {Panel → src/gdxstudio/panel}/ActorPanel.java +39 -14
  40. {Panel → src/gdxstudio/panel}/AssetPanel.java +11 -48
  41. {Panel → src/gdxstudio/panel}/BaseList.java +10 -8
  42. {Panel → src/gdxstudio/panel}/BaseTable.java +34 -5
  43. {Panel → src/gdxstudio/panel}/ConsolePanel.java +38 -7
  44. src/gdxstudio/panel/DPanel.java +30 -0
  45. {Panel → src/gdxstudio/panel}/DashPanel.java +16 -2
  46. {Panel → src/gdxstudio/panel}/EffectPanel.java +9 -1
  47. {Panel → src/gdxstudio/panel}/EventPanel.java +12 -5
  48. src/gdxstudio/panel/MapPanel.java +16 -0
  49. {Panel → src/gdxstudio/panel}/OptionsPanel.java +60 -31
  50. {Panel → src/gdxstudio/panel}/ProjectPanel.java +6 -101
  51. src/gdxstudio/panel/ProjectSettingsPanel.java +121 -0
  52. {Panel → src/gdxstudio/panel}/PropertyPanel.java +23 -27
  53. {Panel → src/gdxstudio/panel}/ReplacePanel.java +1 -0
  54. {Panel → src/gdxstudio/panel}/SceneEffectPanel.java +42 -31
  55. src/gdxstudio/panel/ScenePanel.java +274 -0
  56. {Panel → src/gdxstudio/panel}/SceneTemplate.txt +11 -0
  57. {Panel → src/gdxstudio/panel}/StudioPanel.java +96 -30
  58. {Panel → src/gdxstudio/panel}/TablePanel.java +5 -1
  59. {Panel → src/gdxstudio/panel}/WidgetPanel.java +45 -11
  60. {Parser → src/gdxstudio/parser}/Java.g4 +0 -0
  61. {Parser → src/gdxstudio/parser}/Java.tokens +0 -0
  62. {Parser → src/gdxstudio/parser}/JavaBaseListener.java +1 -0
  63. {Parser → src/gdxstudio/parser}/JavaLexer.java +1 -0
  64. {Parser → src/gdxstudio/parser}/JavaLexer.tokens +0 -0
  65. {Parser → src/gdxstudio/parser}/JavaListener.java +1 -0
  66. {Parser → src/gdxstudio/parser}/JavaParser.java +1 -0
  67. {Stage → src/scene2d}/Asset.java +50 -41
  68. src/scene2d/Camera.java +284 -0
  69. {Stage → src/scene2d}/Config.java +2 -19
  70. {Stage → src/scene2d}/Effect.java +45 -103
  71. src/scene2d/EffectType.java +19 -0
  72. {Type → src/scene2d}/EventType.java +1 -0
  73. {Stage → src/scene2d}/ImageJson.java +3 -2
  74. {Type → src/scene2d}/InterpolationType.java +1 -0
  75. {Stage → src/scene2d}/Map.java +7 -6
  76. {Stage → src/scene2d}/MapActor.java +2 -53
  77. {Stage → src/scene2d}/Net.java +1 -0
  78. src/scene2d/Scene.java +921 -0
  79. {Stage → src/scene2d}/Serializer.java +19 -14
  80. {Stage → src/scene2d}/Sprite.java +2 -1
  81. Stage/MainActivity.java → src/scene2d/android/Main.java +9 -7
  82. src/scene2d/desktop/Main.java +38 -0
  83. test/config +5 -5
  84. test/scene +44 -48
  85. test/source/BasicDemo.java +35 -27
  86. test/source/Game.java +36 -31
  87. test/source/Game3d.java +56 -4
  88. test/source/GameOver.java +16 -13
  89. test/source/GameWin.java +16 -13
  90. test/source/Menu.java +16 -13
  91. test/source/Options.java +27 -20
  92. test/source/Splash.java +21 -16
  93. test/source/TicTacToe.java +26 -22
  94. test/test.apk +0 -0
.classpath CHANGED
@@ -1,10 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <classpath>
3
- <classpathentry kind="src" path="Panel"/>
4
- <classpathentry kind="src" path="Stage"/>
5
- <classpathentry kind="src" path="IDE"/>
3
+ <classpathentry kind="src" path="src"/>
6
- <classpathentry kind="src" path="Type"/>
7
- <classpathentry kind="src" path="Parser"/>
8
4
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
9
5
  <classpathentry kind="lib" path="libs/gdx-backend-lwjgl-natives.jar"/>
10
6
  <classpathentry kind="lib" path="libs/gdx-backend-lwjgl.jar"/>
@@ -18,6 +14,7 @@
18
14
  <classpathentry kind="lib" path="libs/antlr.jar"/>
19
15
  <classpathentry kind="lib" path="libs/ecj.jar"/>
20
16
  <classpathentry kind="lib" path="libs/weblaflite.jar"/>
17
+ <classpathentry kind="lib" path="libs/scene3d.jar"/>
21
18
  <classpathentry kind="src" path="theme"/>
22
19
  <classpathentry kind="src" path="icon"/>
23
20
  <classpathentry kind="src" path="src_libs"/>
Panel/AndroidManifest.xml DELETED
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
- package="com.pyros.main"
4
- android:versionCode="1"
5
- android:versionName="1.0" >
6
-
7
- <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="17" />
8
-
9
- <application
10
- android:icon="@drawable/icon"
11
- android:label="@string/app_name" >
12
- <activity
13
- android:name="sky.warsong.main.MainActivity"
14
- android:label="@string/app_name"
15
- android:screenOrientation="landscape"
16
- android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
17
- <intent-filter>
18
- <action android:name="android.intent.action.MAIN" />
19
- <category android:name="android.intent.category.LAUNCHER" />
20
- </intent-filter>
21
- </activity>
22
- </application>
23
-
24
- </manifest>
Panel/ScenePanel.java DELETED
@@ -1,539 +0,0 @@
1
- import java.awt.Cursor;
2
- import java.awt.Dimension;
3
- import java.awt.event.ActionEvent;
4
- import java.awt.event.ActionListener;
5
- import java.awt.event.ItemEvent;
6
- import java.awt.event.ItemListener;
7
- import java.io.File;
8
- import java.net.MalformedURLException;
9
- import java.net.URL;
10
- import java.net.URLClassLoader;
11
-
12
- import javax.swing.JButton;
13
- import javax.swing.JComboBox;
14
- import javax.swing.JOptionPane;
15
- import javax.swing.JPanel;
16
- import javax.swing.Timer;
17
- import javax.swing.event.ListSelectionEvent;
18
-
19
- import web.laf.lite.widget.CenterPanel;
20
-
21
- import com.badlogic.gdx.scenes.scene2d.Actor;
22
- import com.badlogic.gdx.scenes.scene2d.EventListener;
23
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
24
- import com.badlogic.gdx.scenes.scene2d.ui.List;
25
- import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
26
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
27
- import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
28
- import com.badlogic.gdx.scenes.scene2d.ui.TextField;
29
- import com.badlogic.gdx.scenes.scene2d.utils.Align;
30
- import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
31
- import com.badlogic.gdx.utils.Array;
32
- import com.badlogic.gdx.utils.Timer.Task;
33
-
34
- final public class ScenePanel extends BaseList {
35
- private static final long serialVersionUID = 1L;
36
-
37
- public static JComboBox<String> stateComboBox = BaseTable.createComboBox("Scenes", "Maps", "Actors");
38
- private static JButton addscene, updown ,delete, resume, pause;
39
-
40
- private static SceneState currentState = SceneState.SceneEditor;
41
- private final Timer saveTimer = new Timer(10000, new ActionListener(){
42
- @Override
43
- public void actionPerformed(ActionEvent arg0) {
44
- save();
45
- }
46
- });
47
-
48
- public ScenePanel(){
49
- super("Scenes", true);
50
- saveTimer.start();
51
- Serializer.registerSerializer(SceneEditor.class, new Serializer.SceneSerializer());
52
- initToolBar();
53
- add(scrollPane);
54
- stateComboBox.addItemListener(new ItemListener(){
55
- @Override
56
- public void itemStateChanged(ItemEvent e) {
57
- clear();
58
- switch(stateComboBox.getSelectedIndex()){
59
- case 0: header.setText("SCENES");break;
60
- case 1: header.setText("MAPS");break;
61
- case 2: header.setText("ACTORS");break;
62
- }
63
- update();
64
- }
65
- });
66
- }
67
-
68
- void initToolBar(){
69
- JPanel tools = Style.createButtonToolBarPanel();
70
- addscene = Style.createToolButton("New Scene", "newfile", this);
71
- updown = Style.createToolButton("ScenePriority", "updown", this);
72
- delete = Style.createToolButton("Delete", "trash", this);
73
- resume = Style.createToolButton("Resume", "resume", this);
74
- pause = Style.createToolButton("Pause", "pause", this);
75
- pause.setEnabled(false);
76
- tools.add(addscene);
77
- tools.add(updown);
78
- tools.add(delete);
79
- tools.add(resume);
80
- tools.add(pause);
81
- stateComboBox.setPreferredSize(new Dimension(65, 17));
82
- tools.add(new CenterPanel(stateComboBox, false, true));
83
- add(tools);
84
- }
85
-
86
-
87
- public void update(){
88
- lock();
89
- listModel.clear();
90
- for(String s: Scene.scenesMap.keys())
91
- listModel.addElement(s);
92
- if(Content.sceneFileExists()){
93
- if(listModel.contains(Content.getSceneFile()))
94
- list.setSelectedIndex(listModel.indexOf(Content.getSceneFile()));
95
- }
96
- if(!Content.sceneFileExists())
97
- if(listModel.get(0) != null || !listModel.get(0).isEmpty()){
98
- Content.setSceneFile(listModel.get(0));
99
- list.setSelectedIndex(0);
100
- }
101
- Frame.eventPanel.update();
102
- classPath = new File(Content.getProject()+"bin");
103
- unlock();
104
- }
105
-
106
- private void createSceneFile(){
107
- String text = JOptionPane.showInputDialog(Frame.getInstance(), "Create a New Scene", "New Scene",
108
- JOptionPane.OK_CANCEL_OPTION);
109
- if(text == null || text.isEmpty())
110
- return;
111
- String name = text.replace(".json", "").replace(".java", "");
112
- name = Stage.capitalize(name);
113
- if(listModel.contains(name)){
114
- JOptionPane.showConfirmDialog(null, "Error: File already exists: "+name, "Error",
115
- JOptionPane.OK_OPTION);
116
- return;
117
- }
118
- else{
119
- Export.writeFile("source/"+name+".java",
120
- Export.readFileFromClassPath("SceneTemplate.txt").replace("$$$", name));
121
- listModel.addElement(name);
122
- Scene.scenesMap.put(name, "");
123
- Frame.eventPanel.update();
124
- }
125
- list.setSelectedIndex(listModel.indexOf(name));
126
- SceneEditor.isDirty = true;
127
- save();
128
- }
129
-
130
- @Override
131
- public void actionPerformed(ActionEvent event) {
132
- switch(((JButton)event.getSource()).getToolTipText()){
133
- case "New Scene":
134
- createSceneFile();
135
- break;
136
- case "ScenePriority":
137
- int sceneindex = list.getSelectedIndex();
138
- if(sceneindex+1 < listModel.size()){
139
- lock();
140
- String selected = listModel.getElementAt(sceneindex);
141
- String selectedValue = Scene.scenesMap.getValueAt(sceneindex);
142
- String down = listModel.getElementAt(sceneindex+1);
143
- String downValue = Scene.scenesMap.getValueAt(sceneindex+1);
144
-
145
- /* Changing the model of List */
146
- listModel.setElementAt(selected, sceneindex+1);
147
- listModel.setElementAt(down, sceneindex);
148
-
149
- /* Changing the sceneMap of Stage */
150
- Scene.scenesMap.setKey(sceneindex+1, selected);
151
- Scene.scenesMap.setValue(sceneindex+1, selectedValue);
152
- Scene.scenesMap.setKey(sceneindex, down);
153
- Scene.scenesMap.setValue(sceneindex, downValue);
154
-
155
- list.setSelectedIndex(sceneindex+1);
156
- unlock();
157
- }
158
- break;
159
- case "Delete":
160
- int confirm = JOptionPane.showConfirmDialog(null,
161
- "Are you Sure you want to delete the Scene?", "Delete Scene",
162
- JOptionPane.YES_NO_OPTION);
163
- if(confirm == JOptionPane.YES_OPTION){
164
- lock();
165
- Export.deleteFile("source/"+list.getSelectedValue()+".java");
166
- Export.deleteFile("bin/"+list.getSelectedValue()+".class");
167
- Scene.scenesMap.removeKey(list.getSelectedValue());
168
- int index = listModel.indexOf(list.getSelectedValue())-1;
169
- if(index != -1){
170
- Content.setSceneFile(listModel.elementAt(index));
171
- Content.editor.load();
172
- if(Content.currentView.equals("Editor"))
173
- Content.toggleView(1);
174
- }
175
- listModel.removeElement(list.getSelectedValue());
176
- Frame.eventPanel.update();
177
- list.setSelectedValue(Content.getSceneFile(), true);
178
- showStudio();
179
- SceneEditor.isDirty = true;
180
- save();
181
- unlock();
182
- }
183
- break;
184
- case "Resume":
185
- save();
186
- currentState = SceneState.GameRunning;
187
- list.setEnabled(false);
188
- addscene.setEnabled(false);
189
- updown.setEnabled(false);
190
- delete.setEnabled(false);
191
- resume.setEnabled(false);
192
- pause.setEnabled(true);
193
- Frame.sceneEffectPanel.disable();
194
- Frame.propertyPanel.disable();
195
- Frame.effectPanel.disable();
196
- Frame.eventPanel.disable();
197
- Frame.widgetPanel.disable();
198
- Content.toggleView(2);
199
- runGame();
200
- break;
201
- case "Pause":
202
- currentState = SceneState.SceneEditor;
203
- Stage.cl = null;
204
- Stage.debug = true;
205
- list.setEnabled(true);
206
- addscene.setEnabled(true);
207
- updown.setEnabled(true);
208
- delete.setEnabled(true);
209
- resume.setEnabled(true);
210
- pause.setEnabled(false);
211
- Frame.sceneEffectPanel.enable();
212
- Frame.propertyPanel.enable();
213
- Frame.effectPanel.enable();
214
- Frame.eventPanel.enable();
215
- Frame.widgetPanel.enable();
216
- Scene.scenesMap.put("SceneEditor", "");
217
- Stage.setScene("SceneEditor");
218
- Content.toggleView(2);
219
- runStudio();
220
- break;
221
- }
222
- }
223
-
224
- @Override
225
- public void valueChanged(ListSelectionEvent e) {
226
- if (e.getValueIsAdjusting() == false) {
227
- if(list.getSelectedValue() == null)
228
- return;
229
- if(resume.isEnabled())
230
- runStudio();
231
- Frame.actorPanel.setHeaderText(list.getSelectedValue());
232
- }
233
- }
234
-
235
- public void runStudio(){
236
- ConsolePanel.clear();
237
- Content.editor.clearIcons();
238
- Content.editor.save();
239
- save();
240
- Content.setSceneFile(list.getSelectedValue());
241
- showStudio();
242
- Content.editor.load();
243
- }
244
-
245
- public void showStudio(){
246
- Frame.actorPanel.clear();
247
- Stage.getRoot().clearChildren();
248
- Stage.clearAllHud();
249
- Stage.followActor(null);
250
- Stage.resetCamera();
251
- if(Content.sceneFileExists()){
252
- //load(Content.getSceneFile());
253
- Stage.getScene().load(Content.getSceneFile());
254
- for(Actor child: Stage.getChildren()){
255
- if(Stage.isValidActor(child)){
256
- Frame.actorPanel.addActor(child.getName());
257
- for(EventListener l: child.getListeners())
258
- child.removeListener(l);
259
- }
260
- }
261
- }
262
- Frame.sceneEffectPanel.update();
263
- }
264
-
265
- private static File classPath = new File(Content.getProject()+"bin/");
266
- public void runGame() {
267
- try {
268
- ConsolePanel.clear();
269
- Frame.actorPanel.clear();
270
- URL url = classPath.toURI().toURL();
271
- URLClassLoader cl = URLClassLoader.newInstance(new URL[]{url});
272
- Stage.cl = cl;
273
- Stage.debug = false;
274
- Stage.setScene(list.getSelectedValue());
275
- } catch (MalformedURLException me) {
276
- me.printStackTrace();
277
- }
278
- }
279
-
280
- private void save(){
281
- if(currentState != SceneState.SceneEditor)
282
- return;
283
- if(!SceneEditor.isDirty)
284
- return;
285
- Stage.getScene().save(Content.getSceneFile());
286
- SceneEditor.isDirty = false;
287
- }
288
- }
289
-
290
- enum SceneState{
291
- SceneEditor, MapEditor, ActorEditor, GameRunning
292
- }
293
-
294
- class SceneEditor extends Scene {
295
- public static Actor selectedActor = null;
296
- public static boolean reloadAssets = false;
297
- static AddField addField;
298
-
299
- public SceneEditor(){
300
- super();
301
- if(reloadAssets){
302
- Asset.loadBlocking(); // this is the first time this Scene is created by the Stage
303
- Content.assetPanel.updateAsset();
304
- com.badlogic.gdx.utils.Timer.schedule(new Task(){
305
- @Override
306
- public void run() {
307
- Frame.scenePanel.showStudio();
308
- Scene.scenesMap.removeKey("SceneEditor");
309
- Frame.scenePanel.update();
310
- }
311
- }, 1f);
312
- reloadAssets = false;
313
- addField = new AddField();
314
- }
315
- else{
316
- Frame.scenePanel.showStudio();
317
- Scene.scenesMap.removeKey("SceneEditor");
318
- Stage.addActor(this);
319
- }
320
- Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
321
- }
322
-
323
- public static void doClick(Actor actor){
324
- addField.remove();
325
- Frame.actorPanel.lock();
326
- Frame.propertyPanel.clear();
327
- Frame.effectPanel.clear();
328
- Frame.eventPanel.clear();
329
- selectedActor = actor;
330
- Stage.outline(actor);
331
- Frame.actorPanel.list.setSelectedIndex(Frame.actorPanel.indexOf(actor.getName()));
332
- StatusBar.updateSelected(actor.getName());
333
- Frame.dashPanel.update();
334
- Frame.propertyPanel.update();
335
- Frame.effectPanel.update();
336
- Frame.eventPanel.update();
337
- Frame.actorPanel.unlock();
338
- if(selectedActor instanceof List || selectedActor instanceof SelectBox){
339
- addField.setPosition(actor.getX(), actor.getY() - addField.getHeight());
340
- Stage.addActor(addField);
341
- }
342
- }
343
-
344
-
345
- @Override
346
- public void onClick(Actor actor) {
347
- doClick(actor);
348
- }
349
-
350
- boolean dragging;
351
- int edge;
352
- float startX, startY, lastX, lastY;
353
- public static boolean isDirty = false;
354
- @Override
355
- public void onTouchDown(Actor actor) {
356
- if (Stage.button == 0) {
357
- edge = 0;
358
- float x = Stage.mouse.x;
359
- float y = Stage.mouse.y;
360
- if (x > actor.getX() + actor.getWidth() - 10) edge |= Align.right;
361
- if (y > actor.getY() + actor.getHeight() - 10) edge |= Align.top;
362
- if (x < actor.getX() + 20 && y < actor.getY() + 20) edge = Align.left;
363
- dragging = edge != 0;
364
- startX = x;
365
- startY = y;
366
- lastX = x;
367
- lastY = y;
368
- }
369
- }
370
-
371
- @Override
372
- public void onTouchUp() {
373
- dragging = false;
374
- Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
375
- }
376
-
377
- @Override
378
- public void onDragged() {
379
- if(Stage.isValidActor(selectedActor)){
380
- if(!dragging){
381
- selectedActor.setPosition(Stage.mouse.x, Stage.mouse.y);
382
- Frame.propertyPanel.updateProperty("X", ""+selectedActor.getX(), 0);
383
- Frame.propertyPanel.updateProperty("Y", ""+selectedActor.getY(), 0);
384
- StatusBar.updateXY(Stage.mouse.x, Stage.mouse.y);
385
-
386
- }
387
- else
388
- {
389
- float x = Stage.mouse.x;
390
- float y = Stage.mouse.y;
391
- float width = selectedActor.getWidth(), height = selectedActor.getHeight();
392
- float windowX = selectedActor.getX(), windowY = selectedActor.getY();
393
- if ((edge & Align.right) != 0) {
394
- width += x - lastX;
395
- }
396
- if ((edge & Align.top) != 0) {
397
- height += y - lastY;
398
- }
399
- if ((edge & Align.top) != 0 && (edge & Align.right) != 0) {
400
- width += x - lastX;
401
- height += y - lastY;
402
- }
403
- if (edge == Align.left){
404
- float rot = Stage.getAngle(selectedActor.getX()+selectedActor.getOriginX(),
405
- selectedActor.getY()+selectedActor.getOriginY(), x, y)
406
- - selectedActor.getRotation();
407
- selectedActor.rotate(rot);
408
- }
409
- lastX = x;
410
- lastY = y;
411
- selectedActor.setBounds(Math.round(windowX), Math.round(windowY), Math.round(width), Math.round(height));
412
- Frame.propertyPanel.updateProperty("Width", ""+width, 0);
413
- Frame.propertyPanel.updateProperty("Height", ""+height, 0);
414
- }
415
- SceneEditor.isDirty = true;
416
- }
417
- }
418
-
419
- @Override
420
- public void onGesture(GestureType type) {
421
- }
422
-
423
- private boolean isHand = true;
424
- private boolean isRight = false;
425
- private boolean isTop = false;
426
-
427
- @Override
428
- public void act(float delta){
429
- if(Stage.isValidActor(selectedActor)){
430
- isRight = false;
431
- isTop = false;
432
- //Stage.log("my"+Stage.mouse.y+"top"+selectedActor.getTop());
433
- if (Stage.mouse.x > selectedActor.getRight() - 10 && Stage.mouse.x < selectedActor.getRight()) {
434
- Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
435
- isHand = false;
436
- isRight = true;
437
- }
438
- if(Stage.mouse.y > selectedActor.getTop() - 10 && Stage.mouse.y < selectedActor.getTop()){
439
- Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
440
- isHand = false;
441
- isTop = true;
442
- }
443
- if (isRight && isTop) {
444
- Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
445
- isHand = false;
446
- }
447
- if (!isRight && !isTop){
448
- if(!isHand){
449
- Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
450
- isHand = true;
451
- }
452
- }
453
- }
454
- }
455
-
456
- @Override
457
- public void onKeyTyped(char key) {};
458
- @Override
459
- public void onKeyUp(int keycode){};
460
- @Override
461
- public void onKeyDown(int keycode){};
462
- @Override
463
- public void onPause(){};
464
- @Override
465
- public void onResume(){};
466
- @Override
467
- public void onDispose(){};
468
- }
469
-
470
- class AddField extends Table {
471
- TextField tf;
472
- TextButton addBtn;
473
- TextButton removeBtn;
474
-
475
- public AddField(){
476
- super(Asset.skin);
477
- setBackground(Asset.skin.getDrawable("dialogDim"));
478
- tf = new TextField("", Asset.skin);
479
- addBtn = new TextButton("Add", Asset.skin);
480
- removeBtn = new TextButton("Remove", Asset.skin);
481
- add(tf);
482
- add(addBtn);
483
- add(removeBtn);
484
- pack();
485
- addBtn.addListener(new ClickListener(){
486
- @Override
487
- public void clicked(InputEvent event, float x, float y){
488
- super.clicked(event, x, y);
489
- if(!tf.getText().isEmpty()){
490
- if(SceneEditor.selectedActor instanceof List){
491
- List list = (List) SceneEditor.selectedActor;
492
- Array<String> arr = new Array<String>(list.getItems());
493
- arr.add(tf.getText());
494
- list.setItems(arr.toArray());
495
- list.pack();
496
- AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
497
- }
498
- if(SceneEditor.selectedActor instanceof SelectBox){
499
- SelectBox list = (SelectBox) SceneEditor.selectedActor;
500
- Array<String> arr = new Array<String>(list.getItems());
501
- arr.add(tf.getText());
502
- list.setItems(arr.toArray());
503
- list.pack();
504
- AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
505
- }
506
-
507
- }
508
- }
509
- });
510
- removeBtn.addListener(new ClickListener(){
511
- @Override
512
- public void clicked(InputEvent event, float x, float y){
513
- super.clicked(event, x, y);
514
- if(SceneEditor.selectedActor instanceof List){
515
- List list = (List) SceneEditor.selectedActor;
516
- if(list.getItems().length == 0)
517
- return;
518
- Array<String> arr = new Array<String>(list.getItems());
519
- list.setSelectedIndex(list.getItems().length-1);
520
- arr.removeIndex(list.getSelectedIndex());
521
- list.setItems(arr.toArray());
522
- list.pack();
523
- AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
524
- }
525
- if(SceneEditor.selectedActor instanceof SelectBox){
526
- SelectBox list = (SelectBox) SceneEditor.selectedActor;
527
- if(list.getItems().length == 0)
528
- return;
529
- Array<String> arr = new Array<String>(list.getItems());
530
- list.setSelection(list.getItems().length-1);
531
- arr.removeIndex(list.getSelectionIndex());
532
- list.setItems(arr.toArray());
533
- list.pack();
534
- AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
535
- }
536
- }
537
- });
538
- }
539
- }
Panel/proguard.cfg DELETED
@@ -1,40 +0,0 @@
1
- -optimizationpasses 5
2
- -dontusemixedcaseclassnames
3
- -dontskipnonpubliclibraryclasses
4
- -dontpreverify
5
- -verbose
6
- -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7
-
8
- -keep public class * extends android.app.Activity
9
- -keep public class * extends android.app.Application
10
- -keep public class * extends android.app.Service
11
- -keep public class * extends android.content.BroadcastReceiver
12
- -keep public class * extends android.content.ContentProvider
13
- -keep public class * extends android.app.backup.BackupAgentHelper
14
- -keep public class * extends android.preference.Preference
15
- -keep public class com.android.vending.licensing.ILicensingService
16
-
17
- -keepclasseswithmembernames class * {
18
- native <methods>;
19
- }
20
-
21
- -keepclasseswithmembers class * {
22
- public <init>(android.content.Context, android.util.AttributeSet);
23
- }
24
-
25
- -keepclasseswithmembers class * {
26
- public <init>(android.content.Context, android.util.AttributeSet, int);
27
- }
28
-
29
- -keepclassmembers class * extends android.app.Activity {
30
- public void *(android.view.View);
31
- }
32
-
33
- -keepclassmembers enum * {
34
- public static **[] values();
35
- public static ** valueOf(java.lang.String);
36
- }
37
-
38
- -keep class * implements android.os.Parcelable {
39
- public static final android.os.Parcelable$Creator *;
40
- }
README.md CHANGED
@@ -6,7 +6,7 @@ Texture Packer, SceneEditor, MapEditor, ActorEditor, ImagingTools are already bu
6
6
  It also has a powerful Game Framework based on libGDX inbuilt which allows the game coder
7
7
  to concentrate on the logic of the game and not bother about setting up assets or configuration.
8
8
  It has Automatic Asset Loading including Atlas, TextureRegions, BitmapFonts, Music, Sound.
9
- It has the Latest Nightly Version of libGdx inside it so you don't need to download the libGdx at all,
9
+ It has the Latest Stable Version of libGdx inside it so you don't need to download the libGdx at all,
10
10
  when exporting your game to jar for desktop it automatically loads these libraries into it.
11
11
 
12
12
  >**Disclaimer** This is not an official libdgx project so don't ask them for bug fixes
@@ -43,7 +43,41 @@ for different platforms and exporting is done automatically.(android and ios not
43
43
  <p>You can edit your scenes and add logic to your game and at the same time see the outcome in the studio.
44
44
  Your source files are automatically compiled and loaded into the class loader and displayed in the studio.
45
45
  So your don't need to follow the monotonous approach compile->build->run exe. This saves a lot of time.<p>
46
+
47
+
46
-
48
+ Using
49
+ ------
50
+ ```java
51
+ //This is our first Scene and it shows the libgdx logo until all the assets are loaded
52
+ //then it automatically switches to the Menu scene
53
+ public class Splash extends Scene {
54
+
55
+ public Splash() {
56
+ splashDuration = 5f; // This will make my splash scene to wait 5 seconds after assets are all loaded
57
+ final Texture bg1 = new Texture("splash/libgdx.png");
58
+ final Image imgbg1 = new Image(bg1);
59
+ imgbg1.setFillParent(true);
60
+ addActor(imgbg1);
61
+ }
62
+ }
63
+
64
+ //This is Scene gets called once the assets are loaded
65
+ public class Menu extends Scene {
66
+
67
+ public Menu() {
68
+ //create some actors
69
+ // if you used sink studio and create a scene like Menu.json then
70
+ // it will automatically call load("Menu") it will populate your scene after parsing the json file
71
+
72
+ //you can access these objects like this
73
+ TextButton btn = (TextButton) findActor("TextButton1");
74
+ Image img = (Image) findActor("Image5");
75
+
76
+ // these actors are loaded from the json file and are give names which allows
77
+ // easy access to them
78
+ }
79
+ }
80
+ ```
47
81
  Todo
48
82
  -----
49
83
  1. MapEditor
@@ -63,4 +97,165 @@ Thanks to all these awesome frameworks
63
97
  [EclipseCompiler](http://download.eclipse.org/eclipse/downloads/)
64
98
  [ANTLR](http://www.antlr.org/)
65
99
  [ProGuard](http://proguard.sourceforge.net)
100
+
66
-
101
+ Screenshots
102
+ -----------
103
+ ![alt text](https://github.com/pyros2097/GdxStudio/raw/master/shots/shot2.png)
104
+ ![alt text](https://github.com/pyros2097/GdxStudio/raw/master/shots/shot3.png)
105
+ ![alt text](https://github.com/pyros2097/GdxStudio/raw/master/shots/shot4.png)
106
+ ![alt text](https://github.com/pyros2097/GdxStudio/raw/master/shots/shot5.png)
107
+ ![alt text](https://github.com/pyros2097/GdxStudio/raw/master/shots/shot6.png)
108
+
109
+ Documentation
110
+ -------------
111
+ Scene
112
+ -----
113
+ <p>
114
+ It consists of a single Stage2d, Stage3d, Camera2d, and Camera3d which are all initialized based on the config file.
115
+ The root of the stage can be accessed in a statically {@link Scene#getRoot()} and methods related to camera like moveTo, moveBy,
116
+ are also accessed the same way.<br>
117
+ It has extra things like stateTime, gameUptime, pauseState<br>
118
+
119
+ It has automatic asset unloading and disposing and you can use {@link #exit()} to quit your game safely
120
+
121
+ Note: Your TMX maps have to be unloaded manually as they can be huge resources needing to be freed early.
122
+
123
+ It has static methods which can be used for panning the camera using mouse, keyboard, drag.. etc.
124
+ It can also automatically follow a actor by using followActor(Actor actor)<br>
125
+
126
+ This class will register all your scenes based on your scene.json file and then you can switch you scenes by using {@link #setScene}
127
+ method with the sceneClassName.<br>
128
+ All your assets are loaded in the background(asynchronously) in the first scene and then automatically
129
+ the next scene in the list is set.
130
+ You can stop the stage from switching to the next scene by setting Asset.loadAsynchronous = false in your first scene but then
131
+ you have to load all the assets by using the blocking call Asset.loadBlocking()
132
+
133
+ If you want to display your splash screen for more time after the assets have loaded then you can change
134
+ Stage.splashDuration to the amount of time you want you splash screen to show. By default the splash screen's
135
+ lifetime is finished once the assets are loaded and then the next scene is set.
136
+ </p>
137
+
138
+ Camera
139
+ ------
140
+ ```java
141
+ /*
142
+ * This is to set the offsets of camera position when following the actor
143
+ * When the camera follows the actor its (x,y) position is set to actor's (x,y) position
144
+ * based on followSpeed. The offsets are used to position the camera in such a way that the actor
145
+ * doesn't need to be at the center of the camera always
146
+ */
147
+ public static Rectangle followOffset;
148
+ public static boolean usePan;
149
+ public static boolean useDrag;
150
+
151
+ /*
152
+ * This sets the boundary of the camera till what position can it move or pan in the
153
+ * directions left, right, top, down. This is to prevent is from panning overboard the game area.
154
+ * Usually the bounds of the camera is like a rectangle. This must be calculated carefully
155
+ * as the camera's position is based on its center.
156
+ */
157
+ public static Rectangle bounds;
158
+
159
+ /*
160
+ * Moves the camera to x,y over a time duration
161
+ */
162
+ public void moveTo(float x, float y, float duration);
163
+
164
+ /*
165
+ * Moves the camera by amountX, amountY over a time duration
166
+ */
167
+ public static void moveBy (float amountX, float amountY, float duration);
168
+
169
+ /*
170
+ * Moves the camera by amountX, amountY over a time duration and interpolation interp
171
+ */
172
+ public static void moveBy (float amountX, float amountY, float dur, Interpolation interp);
173
+ /*
174
+ * This makes the camera follow the actor once and only once. Once the camera reaches its
175
+ * target, it stops following the actor.
176
+ */
177
+ public static void followActor(Actor actor);
178
+ /*
179
+ * This makes the camera follow the actor continuously, even after the camera reaches its
180
+ * target, it keeps following the if the actor changes its position.
181
+ */
182
+ public static void followActorContinuously(Actor actor);
183
+ /*
184
+ * Sets the speed at which the camera follows the actor. By default it moves 1px for a duration of 1f
185
+ * so its speed is 1px/f. So reduce the duration to increase its speed.
186
+ * ex: setPanSpeed(0.5) will change its speed to 2px/f
187
+ * Here: f can/maybe also indicate seconds
188
+ */
189
+ public static void setFollowSpeed(float duration);
190
+
191
+ /*
192
+ * Sets the speed at which the camera pans. By default it moves 1px for a duration a 1f
193
+ * so its speed is 1px/f. So reduce the duration to increase its speed.
194
+ * ex: setPanSpeed(0.5) will change its speed to 2px/f
195
+ * Here: f can/maybe also indicate seconds
196
+ */
197
+ public void setPanSpeed(float duration);
198
+
199
+ /* If you want to make any elements/actors to move along with the camera
200
+ * like HUD's add them using this method */
201
+ public static void addHud(Actor actor);
202
+
203
+ /* If you want to any elements/actors which was a Hud the use this */
204
+ public static void removeHud(Actor actor);
205
+
206
+ /*
207
+ * Clears all hud's registerd with the camera
208
+ */
209
+ public static void clearAllHud();
210
+
211
+ /*
212
+ * Returns the x postion of the camera
213
+ */
214
+ public static float getX();
215
+ /*
216
+ * Returns the y postion of the camera
217
+ */
218
+ public static float getY();
219
+ ```
220
+ Asset
221
+ -----
222
+ <b>#Important </b> <br>
223
+ All asset files must be lowercase only.. otherwise it causes problems with android <br>
224
+ Automatic Asset Loading the directory Structure should be like this <br>
225
+ This class automatically loads all the assets in the prescribed folders into the appropriate
226
+ class types. All This can be accessed using an neat api.
227
+
228
+ icon.png --- your game icon to be displayed on the window<br>
229
+ atlas/ --- all your Texture Atlas files .atlas and .png go here<br>
230
+ font/ --- all your BitmapFont files .fnt and .png go here<br>
231
+ music/ --- all your Music files .mp3 go here<br>
232
+ sound/ --- all your Music files .mp3 go here<br>
233
+ particle/ --- all your Particle files .part go here<br>
234
+ map/ --- all your TMX map files along with tilesets go here<br>
235
+ pack/ --- all your image files which are to be packed are to be stored here<br>
236
+ so that they are automatically packed by the texture packer and stored in
237
+ the atlas folder
238
+
239
+ All the assets are read from their particular folders and an asset.json file is created with
240
+ the filenames:
241
+ ex: asset.json
242
+ {
243
+ "font": "arial.fnt, font1",
244
+ "atlas": "image.atlas",
245
+ "sound": "click.mp3,gg.mp3",
246
+ "music": "title.mp3,"bg.mp3",
247
+ }
248
+ ```java
249
+ //All assets are accessed this way, To load TextureRegion
250
+ TextureRegion cat = Asset.tex("cat");
251
+
252
+ //To load Animation
253
+ Animation catAnim = Asset.anim("cat");
254
+ BitmapFont font1 = Asset.font("font1");
255
+
256
+ //The music and sound files are automatically cached and can be played by invoking:
257
+ Asset.musicPlay("musicname");
258
+ Asset.soundPlay("soundname");
259
+
260
+ //The asset functions will return null for Font, TextureRegion and Animation if the asset cannot be found
261
+ ```
Stage/Actions3d.java DELETED
@@ -1,1414 +0,0 @@
1
- import com.badlogic.gdx.math.Interpolation;
2
- import com.badlogic.gdx.utils.Array;
3
- import com.badlogic.gdx.utils.Pool;
4
- import com.badlogic.gdx.utils.Pools;
5
- import com.badlogic.gdx.utils.Pool.Poolable;
6
-
7
- public class Actions3d {
8
-
9
- /** Returns a new or pooled action of the specified type. */
10
- static public <T extends Action3d> T action (Class<T> type) {
11
- Pool<T> pool = Pools.get(type);
12
- T action = pool.obtain();
13
- action.setPool(pool);
14
- return action;
15
- }
16
-
17
- static public AddAction addAction (Action3d action) {
18
- AddAction addAction = action(AddAction.class);
19
- addAction.setAction(action);
20
- return addAction;
21
- }
22
-
23
- static public AddAction addAction (Action3d action, Actor3d targetActor) {
24
- AddAction addAction = action(AddAction.class);
25
- addAction.setTargetActor(targetActor);
26
- addAction.setAction(action);
27
- return addAction;
28
- }
29
-
30
- static public RemoveAction removeAction (Action3d action) {
31
- RemoveAction removeAction = action(RemoveAction.class);
32
- removeAction.setAction(action);
33
- return removeAction;
34
- }
35
-
36
- static public RemoveAction removeAction (Action3d action, Actor3d targetActor) {
37
- RemoveAction removeAction = action(RemoveAction.class);
38
- removeAction.setTargetActor(targetActor);
39
- removeAction.setAction(action);
40
- return removeAction;
41
- }
42
-
43
- /** Moves the actor instantly. */
44
- static public MoveToAction moveTo (float x, float y, float z) {
45
- return moveTo(x, y, z, 0, null);
46
- }
47
-
48
- static public MoveToAction moveTo (float x, float y, float z, float duration) {
49
- return moveTo(x, y, z, duration, null);
50
- }
51
-
52
- static public MoveToAction moveTo (float x, float y, float z ,float duration, Interpolation interpolation) {
53
- MoveToAction action = action(MoveToAction.class);
54
- action.setPosition(x, y, z);
55
- action.setDuration(duration);
56
- action.setInterpolation(interpolation);
57
- return action;
58
- }
59
-
60
- /** Moves the actor instantly. */
61
- static public MoveByAction moveBy (float amountX, float amountY, float amountZ) {
62
- return moveBy(amountX, amountY, amountZ, 0, null);
63
- }
64
-
65
- static public MoveByAction moveBy (float amountX, float amountY, float amountZ, float duration) {
66
- return moveBy(amountX, amountY, amountZ, duration, null);
67
- }
68
-
69
- static public MoveByAction moveBy (float amountX, float amountY, float amountZ, float duration, Interpolation interpolation) {
70
- MoveByAction action = action(MoveByAction.class);
71
- action.setAmount(amountX, amountY, amountZ);
72
- action.setDuration(duration);
73
- action.setInterpolation(interpolation);
74
- return action;
75
- }
76
-
77
- /** Scales the actor instantly. */
78
- static public ScaleToAction scaleTo (float x, float y, float z) {
79
- return scaleTo(x, y, z, 0, null);
80
- }
81
-
82
- static public ScaleToAction scaleTo (float x, float y, float z, float duration) {
83
- return scaleTo(x, y, z, duration, null);
84
- }
85
-
86
- static public ScaleToAction scaleTo (float x, float y, float z, float duration, Interpolation interpolation) {
87
- ScaleToAction action = action(ScaleToAction.class);
88
- action.setScale(x, y, z);
89
- action.setDuration(duration);
90
- action.setInterpolation(interpolation);
91
- return action;
92
- }
93
-
94
- /** Scales the actor instantly. */
95
- static public ScaleByAction scaleBy (float amountX, float amountY, float amountZ) {
96
- return scaleBy(amountX, amountY, amountZ, 0, null);
97
- }
98
-
99
- static public ScaleByAction scaleBy (float amountX, float amountY, float amountZ, float duration) {
100
- return scaleBy(amountX, amountY, amountZ, duration, null);
101
- }
102
-
103
- static public ScaleByAction scaleBy (float amountX, float amountY, float amountZ, float duration, Interpolation interpolation) {
104
- ScaleByAction action = action(ScaleByAction.class);
105
- action.setAmount(amountX, amountY, amountZ);
106
- action.setDuration(duration);
107
- action.setInterpolation(interpolation);
108
- return action;
109
- }
110
-
111
- /** Rotates the actor instantly. */
112
- static public RotateToAction rotateTo (float rotation) {
113
- return rotateTo(rotation, 0, null);
114
- }
115
-
116
- static public RotateToAction rotateTo (float rotation, float duration) {
117
- return rotateTo(rotation, duration, null);
118
- }
119
-
120
- static public RotateToAction rotateTo (float rotation, float duration, Interpolation interpolation) {
121
- RotateToAction action = action(RotateToAction.class);
122
- action.setRotation(rotation);
123
- action.setDuration(duration);
124
- action.setInterpolation(interpolation);
125
- return action;
126
- }
127
-
128
- /** Rotates the actor instantly. */
129
- static public RotateByAction rotateBy (float rotationAmount) {
130
- return rotateBy(rotationAmount, 0, null);
131
- }
132
-
133
- static public RotateByAction rotateBy (float rotationAmount, float duration) {
134
- return rotateBy(rotationAmount, duration, null);
135
- }
136
-
137
- static public RotateByAction rotateBy (float rotationAmount, float duration, Interpolation interpolation) {
138
- RotateByAction action = action(RotateByAction.class);
139
- action.setAmount(rotationAmount);
140
- action.setDuration(duration);
141
- action.setInterpolation(interpolation);
142
- return action;
143
- }
144
-
145
-
146
-
147
- static public VisibleAction show () {
148
- return visible(true);
149
- }
150
-
151
- static public VisibleAction hide () {
152
- return visible(false);
153
- }
154
-
155
- static public VisibleAction visible (boolean visible) {
156
- VisibleAction action = action(VisibleAction.class);
157
- action.setVisible(visible);
158
- return action;
159
- }
160
-
161
- static public RemoveActorAction removeActor (Actor3d removeActor) {
162
- RemoveActorAction action = action(RemoveActorAction.class);
163
- action.setRemoveActor(removeActor);
164
- return action;
165
- }
166
-
167
- static public DelayAction delay (float duration) {
168
- DelayAction action = action(DelayAction.class);
169
- action.setDuration(duration);
170
- return action;
171
- }
172
-
173
- static public DelayAction delay (float duration, Action3d delayedAction) {
174
- DelayAction action = action(DelayAction.class);
175
- action.setDuration(duration);
176
- action.setAction(delayedAction);
177
- return action;
178
- }
179
-
180
- static public TimeScaleAction timeScale (float scale, Action3d scaledAction) {
181
- TimeScaleAction action = action(TimeScaleAction.class);
182
- action.setScale(scale);
183
- action.setAction(scaledAction);
184
- return action;
185
- }
186
-
187
- static public SequenceAction sequence (Action3d action1) {
188
- SequenceAction action = action(SequenceAction.class);
189
- action.addAction(action1);
190
- return action;
191
- }
192
-
193
- static public SequenceAction sequence (Action3d action1, Action3d action2) {
194
- SequenceAction action = action(SequenceAction.class);
195
- action.addAction(action1);
196
- action.addAction(action2);
197
- return action;
198
- }
199
-
200
- static public SequenceAction sequence (Action3d action1, Action3d action2, Action3d action3) {
201
- SequenceAction action = action(SequenceAction.class);
202
- action.addAction(action1);
203
- action.addAction(action2);
204
- action.addAction(action3);
205
- return action;
206
- }
207
-
208
- static public SequenceAction sequence (Action3d action1, Action3d action2, Action3d action3, Action3d action4) {
209
- SequenceAction action = action(SequenceAction.class);
210
- action.addAction(action1);
211
- action.addAction(action2);
212
- action.addAction(action3);
213
- action.addAction(action4);
214
- return action;
215
- }
216
-
217
- static public SequenceAction sequence (Action3d action1, Action3d action2, Action3d action3, Action3d action4, Action3d action5) {
218
- SequenceAction action = action(SequenceAction.class);
219
- action.addAction(action1);
220
- action.addAction(action2);
221
- action.addAction(action3);
222
- action.addAction(action4);
223
- action.addAction(action5);
224
- return action;
225
- }
226
-
227
- static public SequenceAction sequence (Action3d... actions) {
228
- SequenceAction action = action(SequenceAction.class);
229
- for (int i = 0, n = actions.length; i < n; i++)
230
- action.addAction(actions[i]);
231
- return action;
232
- }
233
-
234
- static public SequenceAction sequence () {
235
- return action(SequenceAction.class);
236
- }
237
-
238
- static public ParallelAction parallel (Action3d action1) {
239
- ParallelAction action = action(ParallelAction.class);
240
- action.addAction(action1);
241
- return action;
242
- }
243
-
244
- static public ParallelAction parallel (Action3d action1, Action3d action2) {
245
- ParallelAction action = action(ParallelAction.class);
246
- action.addAction(action1);
247
- action.addAction(action2);
248
- return action;
249
- }
250
-
251
- static public ParallelAction parallel (Action3d action1, Action3d action2, Action3d action3) {
252
- ParallelAction action = action(ParallelAction.class);
253
- action.addAction(action1);
254
- action.addAction(action2);
255
- action.addAction(action3);
256
- return action;
257
- }
258
-
259
- static public ParallelAction parallel (Action3d action1, Action3d action2, Action3d action3, Action3d action4) {
260
- ParallelAction action = action(ParallelAction.class);
261
- action.addAction(action1);
262
- action.addAction(action2);
263
- action.addAction(action3);
264
- action.addAction(action4);
265
- return action;
266
- }
267
-
268
- static public ParallelAction parallel (Action3d action1, Action3d action2, Action3d action3, Action3d action4, Action3d action5) {
269
- ParallelAction action = action(ParallelAction.class);
270
- action.addAction(action1);
271
- action.addAction(action2);
272
- action.addAction(action3);
273
- action.addAction(action4);
274
- action.addAction(action5);
275
- return action;
276
- }
277
-
278
- static public ParallelAction parallel (Action3d... actions) {
279
- ParallelAction action = action(ParallelAction.class);
280
- for (int i = 0, n = actions.length; i < n; i++)
281
- action.addAction(actions[i]);
282
- return action;
283
- }
284
-
285
- static public ParallelAction parallel () {
286
- return action(ParallelAction.class);
287
- }
288
-
289
- static public RepeatAction repeat (int count, Action3d repeatedAction) {
290
- RepeatAction action = action(RepeatAction.class);
291
- action.setCount(count);
292
- action.setAction(repeatedAction);
293
- return action;
294
- }
295
-
296
- static public RepeatAction forever (Action3d repeatedAction) {
297
- RepeatAction action = action(RepeatAction.class);
298
- action.setCount(RepeatAction.FOREVER);
299
- action.setAction(repeatedAction);
300
- return action;
301
- }
302
-
303
- static public RunnableAction run (Runnable runnable) {
304
- RunnableAction action = action(RunnableAction.class);
305
- action.setRunnable(runnable);
306
- return action;
307
- }
308
-
309
- static public AfterAction after (Action3d action) {
310
- AfterAction afterAction = action(AfterAction.class);
311
- afterAction.setAction(action);
312
- return afterAction;
313
- }
314
-
315
- public static class AddAction extends Action3d {
316
- private Actor3d targetActor;
317
- private Action3d action;
318
-
319
- @Override
320
- public boolean act (float delta) {
321
- (targetActor != null ? targetActor : actor3d).addAction3d(action);
322
- return true;
323
- }
324
-
325
- public Actor3d getTargetActor() {
326
- return targetActor;
327
- }
328
-
329
- /** Sets the actor to add an action to. If null (the default), the {@link #getActor() actor} will be used. */
330
- public void setTargetActor(Actor3d actor) {
331
- this.targetActor = actor;
332
- }
333
-
334
- public Action3d getAction () {
335
- return action;
336
- }
337
-
338
- public void setAction(Action3d action) {
339
- this.action = action;
340
- }
341
-
342
- public void restart () {
343
- if (action != null) action.restart();
344
- }
345
-
346
- @Override
347
- public void reset () {
348
- super.reset();
349
- targetActor = null;
350
- action = null;
351
- }
352
- }
353
-
354
- /** Executes an action only after all other actions on the actor at the time this action was added have finished.
355
- * @author Nathan Sweet */
356
- public static class AfterAction extends DelegateAction {
357
- private Array<Action3d> waitForActions = new Array<Action3d>(false, 4);
358
-
359
- @Override
360
- public void setActor3d(Actor3d actor3d) {
361
- if (actor3d != null) waitForActions.addAll(actor3d.getActions3d());
362
- super.setActor3d(actor3d);
363
- }
364
-
365
- @Override
366
- public void restart () {
367
- super.restart();
368
- waitForActions.clear();
369
- }
370
-
371
- @Override
372
- protected boolean delegate (float delta) {
373
- Array<Action3d> currentActions = actor3d.getActions3d();
374
- if (currentActions.size == 1) waitForActions.clear();
375
- for (int i = waitForActions.size - 1; i >= 0; i--) {
376
- Action3d action = waitForActions.get(i);
377
- int index = currentActions.indexOf(action, true);
378
- if (index == -1) waitForActions.removeIndex(i);
379
- }
380
- if (waitForActions.size > 0) return false;
381
- return action.act(delta);
382
- }
383
- }
384
-
385
- /** Delays execution of an action or inserts a pau
386
- *
387
- * se in a {@link SequenceAction}.
388
- * @author Nathan Sweet */
389
- public static class DelayAction extends DelegateAction {
390
- private float duration, time;
391
-
392
- public DelayAction () {
393
- }
394
-
395
- public DelayAction (float duration) {
396
- this.duration = duration;
397
- }
398
-
399
- @Override
400
- protected boolean delegate (float delta) {
401
- if (time < duration) {
402
- time += delta;
403
- if (time < duration) return false;
404
- delta = time - duration;
405
- }
406
- if (action == null) return true;
407
- return action.act(delta);
408
- }
409
-
410
- /** Causes the delay to be complete. */
411
- public void finish () {
412
- time = duration;
413
- }
414
-
415
- @Override
416
- public void restart () {
417
- super.restart();
418
- time = 0;
419
- }
420
-
421
- /** Gets the time spent waiting for the delay. */
422
- public float getTime () {
423
- return time;
424
- }
425
-
426
- /** Sets the time spent waiting for the delay. */
427
- public void setTime (float time) {
428
- this.time = time;
429
- }
430
-
431
- public float getDuration () {
432
- return duration;
433
- }
434
-
435
- /** Sets the length of the delay in seconds. */
436
- public void setDuration (float duration) {
437
- this.duration = duration;
438
- }
439
- }
440
-
441
- /** Base class for an action that wraps another action.
442
- * @author Nathan Sweet */
443
- abstract public static class DelegateAction extends Action3d {
444
- protected Action3d action;
445
-
446
- /** Sets the wrapped action. */
447
- public void setAction (Action3d action) {
448
- this.action = action;
449
- }
450
-
451
- public Action3d getAction () {
452
- return action;
453
- }
454
-
455
- abstract protected boolean delegate (float delta);
456
-
457
- @Override
458
- public final boolean act (float delta) {
459
- Pool pool = getPool();
460
- setPool(null); // Ensure this action can't be returned to the pool inside the delegate action.
461
- try {
462
- return delegate(delta);
463
- } finally {
464
- setPool(pool);
465
- }
466
- }
467
-
468
- @Override
469
- public void restart () {
470
- if (action != null) action.restart();
471
- }
472
-
473
- @Override
474
- public void reset () {
475
- super.reset();
476
- action = null;
477
- }
478
-
479
- @Override
480
- public void setActor3d (Actor3d actor3d) {
481
- if (action != null) action.setActor3d(actor3d);
482
- super.setActor3d(actor3d);
483
- }
484
-
485
- @Override
486
- public String toString () {
487
- return super.toString() + (action == null ? "" : "(" + action + ")");
488
- }
489
- }
490
-
491
- public static class FloatAction extends TemporalAction {
492
- private float start, end;
493
- private float value;
494
-
495
- /** Creates a FloatAction that transitions from 0 to 1. */
496
- public FloatAction () {
497
- start = 0;
498
- end = 1;
499
- }
500
-
501
- /** Creates a FloatAction that transitions from start to end. */
502
- public FloatAction (float start, float end) {
503
- this.start = start;
504
- this.end = end;
505
- }
506
-
507
- @Override
508
- protected void begin () {
509
- value = start;
510
- }
511
-
512
- @Override
513
- protected void update (float percent) {
514
- value = start + (end - start) * percent;
515
- }
516
-
517
- /** Gets the current float value. */
518
- public float getValue () {
519
- return value;
520
- }
521
-
522
- /** Sets the current float value. */
523
- public void setValue (float value) {
524
- this.value = value;
525
- }
526
-
527
- public float getStart () {
528
- return start;
529
- }
530
-
531
- /** Sets the value to transition from. */
532
- public void setStart (float start) {
533
- this.start = start;
534
- }
535
-
536
- public float getEnd () {
537
- return end;
538
- }
539
-
540
- /** Sets the value to transition to. */
541
- public void setEnd (float end) {
542
- this.end = end;
543
- }
544
- }
545
-
546
- /** An action that has an int, whose value is transitioned over time.
547
- * @author Nathan Sweet */
548
- public static class IntAction extends TemporalAction {
549
- private int start, end;
550
- private int value;
551
-
552
- /** Creates an IntAction that transitions from 0 to 1. */
553
- public IntAction () {
554
- start = 0;
555
- end = 1;
556
- }
557
-
558
- /** Creates an IntAction that transitions from start to end. */
559
- public IntAction (int start, int end) {
560
- this.start = start;
561
- this.end = end;
562
- }
563
-
564
- @Override
565
- protected void begin () {
566
- value = start;
567
- }
568
-
569
- @Override
570
- protected void update (float percent) {
571
- value = (int)(start + (end - start) * percent);
572
- }
573
-
574
- /** Gets the current int value. */
575
- public int getValue () {
576
- return value;
577
- }
578
-
579
- /** Sets the current int value. */
580
- public void setValue (int value) {
581
- this.value = value;
582
- }
583
-
584
- public int getStart () {
585
- return start;
586
- }
587
-
588
- /** Sets the value to transition from. */
589
- public void setStart (int start) {
590
- this.start = start;
591
- }
592
-
593
- public int getEnd () {
594
- return end;
595
- }
596
-
597
- /** Sets the value to transition to. */
598
- public void setEnd (int end) {
599
- this.end = end;
600
- }
601
- }
602
-
603
- /** Moves an actor to a relative position.
604
- * @author Nathan Sweet */
605
- public static class MoveByAction extends RelativeTemporalAction {
606
- private float amountX, amountY, amountZ;
607
-
608
- @Override
609
- protected void updateRelative (float percentDelta) {
610
- actor3d.translate(amountX * percentDelta, amountY * percentDelta, amountZ * percentDelta);
611
- }
612
-
613
- public void setAmount (float x, float y, float z) {
614
- amountX = x;
615
- amountY = y;
616
- amountZ = z;
617
- }
618
-
619
- public float getAmountX () {
620
- return amountX;
621
- }
622
-
623
- public void setAmountX (float x) {
624
- amountX = x;
625
- }
626
-
627
- public float getAmountY () {
628
- return amountY;
629
- }
630
-
631
- public void setAmountY (float y) {
632
- amountY = y;
633
- }
634
-
635
- public float getAmountZ () {
636
- return amountZ;
637
- }
638
-
639
- public void setAmountZ (float z) {
640
- amountZ = z;
641
- }
642
- }
643
-
644
- public static class MoveToAction extends TemporalAction {
645
- private float startX, startY, startZ;
646
- private float endX, endY, endZ;
647
-
648
- @Override
649
- protected void begin () {
650
- if(actor3d != null){
651
- startX = actor3d.getX();
652
- startY = actor3d.getY();
653
- startZ = actor3d.getZ();
654
- }
655
- }
656
-
657
- @Override
658
- protected void update (float percent) {
659
- if(actor3d != null){
660
- actor3d.setPosition(startX + (endX - startX) * percent, startY + (endY - startY) * percent,
661
- startZ + (endZ - startZ) * percent);
662
- }
663
- }
664
-
665
-
666
- public void setPosition (float x, float y, float z) {
667
- endX = x;
668
- endY = y;
669
- endZ = z;
670
- }
671
-
672
- public float getX () {
673
- return endX;
674
- }
675
-
676
- public void setX (float x) {
677
- endX = x;
678
- }
679
-
680
- public float getY () {
681
- return endY;
682
- }
683
-
684
- public void setY (float y) {
685
- endY = y;
686
- }
687
-
688
- public float getZ () {
689
- return endZ;
690
- }
691
-
692
- public void setZ (float z) {
693
- endZ = z;
694
- }
695
- }
696
-
697
- /** Executes a number of actions at the same time.
698
- * @author Nathan Sweet */
699
- public static class ParallelAction extends Action3d {
700
- Array<Action3d> actions = new Array<Action3d>(4);
701
- private boolean complete;
702
-
703
- public ParallelAction () {
704
- }
705
-
706
- public ParallelAction (Action3d action1) {
707
- addAction(action1);
708
- }
709
-
710
- public ParallelAction (Action3d action1, Action3d action2) {
711
- addAction(action1);
712
- addAction(action2);
713
- }
714
-
715
- public ParallelAction (Action3d action1, Action3d action2, Action3d action3) {
716
- addAction(action1);
717
- addAction(action2);
718
- addAction(action3);
719
- }
720
-
721
- public ParallelAction (Action3d action1, Action3d action2, Action3d action3, Action3d action4) {
722
- addAction(action1);
723
- addAction(action2);
724
- addAction(action3);
725
- addAction(action4);
726
- }
727
-
728
- public ParallelAction (Action3d action1, Action3d action2, Action3d action3, Action3d action4, Action3d action5) {
729
- addAction(action1);
730
- addAction(action2);
731
- addAction(action3);
732
- addAction(action4);
733
- addAction(action5);
734
- }
735
-
736
- @Override
737
- public boolean act (float delta) {
738
- if (complete) return true;
739
- complete = true;
740
- Pool pool = getPool();
741
- setPool(null); // Ensure this action can't be returned to the pool while executing.
742
- try {
743
- Array<Action3d> actions = this.actions;
744
- for (int i = 0, n = actions.size; i < n && actor3d != null; i++) {
745
- if (!actions.get(i).act(delta)) complete = false;
746
- if (actor3d == null) return true; // This action was removed.
747
- }
748
- return complete;
749
- } finally {
750
- setPool(pool);
751
- }
752
- }
753
-
754
- @Override
755
- public void restart () {
756
- complete = false;
757
- Array<Action3d> actions = this.actions;
758
- for (int i = 0, n = actions.size; i < n; i++)
759
- actions.get(i).restart();
760
- }
761
-
762
- @Override
763
- public void reset () {
764
- super.reset();
765
- actions.clear();
766
- }
767
-
768
- public void addAction (Action3d action) {
769
- actions.add(action);
770
- if (actor3d != null)
771
- action.setActor3d(actor3d);
772
- }
773
-
774
- @Override
775
- public void setActor3d(Actor3d actor) {
776
- Array<Action3d> actions = this.actions;
777
- for (int i = 0, n = actions.size; i < n; i++)
778
- actions.get(i).setActor3d(actor);
779
- super.setActor3d(actor);
780
- }
781
-
782
- public Array<Action3d> getActions () {
783
- return actions;
784
- }
785
-
786
- @Override
787
- public String toString () {
788
- StringBuilder buffer = new StringBuilder(64);
789
- buffer.append(super.toString());
790
- buffer.append('(');
791
- Array<Action3d> actions = this.actions;
792
- for (int i = 0, n = actions.size; i < n; i++) {
793
- if (i > 0) buffer.append(", ");
794
- buffer.append(actions.get(i));
795
- }
796
- buffer.append(')');
797
- return buffer.toString();
798
- }
799
- }
800
-
801
- /** Base class for actions that transition over time using the percent complete since the last frame.
802
- * @author Nathan Sweet */
803
- abstract public static class RelativeTemporalAction extends TemporalAction {
804
- private float lastPercent;
805
-
806
- @Override
807
- protected void begin () {
808
- lastPercent = 0;
809
- }
810
-
811
- @Override
812
- protected void update (float percent) {
813
- updateRelative(percent - lastPercent);
814
- lastPercent = percent;
815
- }
816
-
817
- abstract protected void updateRelative (float percentDelta);
818
- }
819
-
820
- /** Removes an action from an actor.
821
- * @author Nathan Sweet */
822
- public static class RemoveAction extends Action3d {
823
- private Actor3d targetActor;
824
- private Action3d action;
825
-
826
- @Override
827
- public boolean act (float delta) {
828
- (targetActor != null ? targetActor : actor3d).removeAction3d(action);
829
- return true;
830
- }
831
-
832
- public Actor3d getTargetActor () {
833
- return targetActor;
834
- }
835
-
836
- /** Sets the actor to remove an action from. If null (the default), the {@link #getActor() actor} will be used. */
837
- public void setTargetActor (Actor3d actor) {
838
- this.targetActor = actor;
839
- }
840
-
841
- public Action3d getAction () {
842
- return action;
843
- }
844
-
845
- public void setAction(Action3d action) {
846
- this.action = action;
847
- }
848
-
849
- @Override
850
- public void reset () {
851
- super.reset();
852
- targetActor = null;
853
- action = null;
854
- }
855
- }
856
-
857
- /** Removes an actor from the stage.
858
- * @author Nathan Sweet */
859
- public static class RemoveActorAction extends Action3d {
860
- private Actor3d removeActor;
861
- private boolean removed;
862
-
863
- @Override
864
- public boolean act (float delta) {
865
- if (!removed) {
866
- removed = true;
867
- (removeActor != null ? removeActor : actor3d).remove();
868
- }
869
- return true;
870
- }
871
-
872
- @Override
873
- public void restart () {
874
- removed = false;
875
- }
876
-
877
- @Override
878
- public void reset () {
879
- super.reset();
880
- removeActor = null;
881
- }
882
-
883
- public Actor3d getRemoveActor () {
884
- return removeActor;
885
- }
886
-
887
- /** Sets the actor to remove. If null (the default), the {@link #getActor() actor} will be used. */
888
- public void setRemoveActor (Actor3d removeActor) {
889
- this.removeActor = removeActor;
890
- }
891
- }
892
-
893
- /** Repeats an action a number of times or forever.
894
- * @author Nathan Sweet */
895
- public static class RepeatAction extends DelegateAction {
896
- static public final int FOREVER = -1;
897
-
898
- private int repeatCount, executedCount;
899
- private boolean finished;
900
-
901
- @Override
902
- protected boolean delegate (float delta) {
903
- if (executedCount == repeatCount) return true;
904
- if (action.act(delta)) {
905
- if (finished) return true;
906
- if (repeatCount > 0) executedCount++;
907
- if (executedCount == repeatCount) return true;
908
- if (action != null) action.restart();
909
- }
910
- return false;
911
- }
912
-
913
- /** Causes the action to not repeat again. */
914
- public void finish () {
915
- finished = true;
916
- }
917
-
918
- @Override
919
- public void restart () {
920
- super.restart();
921
- executedCount = 0;
922
- finished = false;
923
- }
924
-
925
- /** Sets the number of times to repeat. Can be set to {@link #FOREVER}. */
926
- public void setCount (int count) {
927
- this.repeatCount = count;
928
- }
929
-
930
- public int getCount () {
931
- return repeatCount;
932
- }
933
- }
934
-
935
- /** Sets the actor's rotation from its current value to a relative value.
936
- * @author Nathan Sweet */
937
- public static class RotateByAction extends RelativeTemporalAction {
938
- private float amount;
939
-
940
- @Override
941
- protected void updateRelative (float percentDelta) {
942
- actor3d.rotate(amount * percentDelta);
943
- }
944
-
945
- public float getAmount () {
946
- return amount;
947
- }
948
-
949
- public void setAmount (float rotationAmount) {
950
- amount = rotationAmount;
951
- }
952
- }
953
-
954
- /** Sets the actor's rotation from its current value to a specific value.
955
- * @author Nathan Sweet */
956
- public static class RotateToAction extends TemporalAction {
957
- private float start, end;
958
-
959
- @Override
960
- protected void begin () {
961
- start = actor3d.getRotation();
962
- }
963
-
964
- @Override
965
- protected void update (float percent) {
966
- actor3d.setRotation(start + (end - start) * percent);
967
- }
968
-
969
- public float getRotation () {
970
- return end;
971
- }
972
-
973
- public void setRotation (float rotation) {
974
- this.end = rotation;
975
- }
976
- }
977
-
978
- /** An action that runs a {@link Runnable}. Alternatively, the {@link #run()} method can be overridden instead of setting a
979
- * runnable.
980
- * @author Nathan Sweet */
981
- public static class RunnableAction extends Action3d {
982
- private Runnable runnable;
983
- private boolean ran;
984
-
985
- @Override
986
- public boolean act (float delta) {
987
- if (!ran) {
988
- ran = true;
989
- run();
990
- }
991
- return true;
992
- }
993
-
994
- /** Called to run the runnable. */
995
- public void run () {
996
- Pool pool = getPool();
997
- setPool(null); // Ensure this action can't be returned to the pool inside the runnable.
998
- try {
999
- runnable.run();
1000
- } finally {
1001
- setPool(pool);
1002
- }
1003
- }
1004
-
1005
- @Override
1006
- public void restart () {
1007
- ran = false;
1008
- }
1009
-
1010
- @Override
1011
- public void reset () {
1012
- super.reset();
1013
- runnable = null;
1014
- }
1015
-
1016
- public Runnable getRunnable () {
1017
- return runnable;
1018
- }
1019
-
1020
- public void setRunnable (Runnable runnable) {
1021
- this.runnable = runnable;
1022
- }
1023
- }
1024
-
1025
- /** Scales an actor's scale to a relative size.
1026
- * @author Nathan Sweet */
1027
- public static class ScaleByAction extends RelativeTemporalAction {
1028
- private float amountX, amountY, amountZ;
1029
-
1030
- @Override
1031
- protected void updateRelative (float percentDelta) {
1032
- actor3d.scale(amountX * percentDelta, amountY * percentDelta, amountZ * percentDelta);
1033
- }
1034
-
1035
- public void setAmount (float x, float y, float z) {
1036
- amountX = x;
1037
- amountY = y;
1038
- amountZ = z;
1039
- }
1040
-
1041
- public void setAmount (float scale) {
1042
- amountX = scale;
1043
- amountY = scale;
1044
- amountZ = scale;
1045
- }
1046
-
1047
- public float getAmountX () {
1048
- return amountX;
1049
- }
1050
-
1051
- public void setAmountX (float x) {
1052
- this.amountX = x;
1053
- }
1054
-
1055
- public float getAmountY () {
1056
- return amountY;
1057
- }
1058
-
1059
- public void setAmountY (float y) {
1060
- this.amountY = y;
1061
- }
1062
-
1063
- public float getAmountZ () {
1064
- return amountZ;
1065
- }
1066
-
1067
- public void setAmountZ (float z) {
1068
- this.amountZ = z;
1069
- }
1070
-
1071
- }
1072
-
1073
- /** Sets the actor's scale from its current value to a specific value.
1074
- * @author Nathan Sweet */
1075
- public static class ScaleToAction extends TemporalAction {
1076
- private float startX, startY, startZ;
1077
- private float endX, endY, endZ;
1078
-
1079
- @Override
1080
- protected void begin () {
1081
- startX = actor3d.getScaleX();
1082
- startY = actor3d.getScaleY();
1083
- startZ = actor3d.getScaleZ();
1084
- }
1085
-
1086
- @Override
1087
- protected void update (float percent) {
1088
- actor3d.setScale(startX + (endX - startX) * percent, startY + (endY - startY) * percent,
1089
- startZ + (endZ - startZ) * percent);
1090
- }
1091
-
1092
- public void setScale (float x, float y, float z) {
1093
- endX = x;
1094
- endY = y;
1095
- endZ = z;
1096
- }
1097
-
1098
- public void setScale (float scale) {
1099
- endX = scale;
1100
- endY = scale;
1101
- endZ = scale;
1102
- }
1103
-
1104
- public float getX () {
1105
- return endX;
1106
- }
1107
-
1108
- public void setX (float x) {
1109
- this.endX = x;
1110
- }
1111
-
1112
- public float getY () {
1113
- return endY;
1114
- }
1115
-
1116
- public void setY (float y) {
1117
- this.endY = y;
1118
- }
1119
-
1120
- public float getZ () {
1121
- return endZ;
1122
- }
1123
-
1124
- public void setZ (float z) {
1125
- this.endZ = z;
1126
- }
1127
- }
1128
-
1129
- /** Executes a number of actions one at a time.
1130
- * @author Nathan Sweet */
1131
- public static class SequenceAction extends ParallelAction {
1132
- private int index;
1133
-
1134
- public SequenceAction () {
1135
- }
1136
-
1137
- public SequenceAction (Action3d action1) {
1138
- addAction(action1);
1139
- }
1140
-
1141
- public SequenceAction (Action3d action1, Action3d action2) {
1142
- addAction(action1);
1143
- addAction(action2);
1144
- }
1145
-
1146
- public SequenceAction (Action3d action1, Action3d action2, Action3d action3) {
1147
- addAction(action1);
1148
- addAction(action2);
1149
- addAction(action3);
1150
- }
1151
-
1152
- public SequenceAction (Action3d action1, Action3d action2, Action3d action3, Action3d action4) {
1153
- addAction(action1);
1154
- addAction(action2);
1155
- addAction(action3);
1156
- addAction(action4);
1157
- }
1158
-
1159
- public SequenceAction (Action3d action1, Action3d action2, Action3d action3, Action3d action4, Action3d action5) {
1160
- addAction(action1);
1161
- addAction(action2);
1162
- addAction(action3);
1163
- addAction(action4);
1164
- addAction(action5);
1165
- }
1166
-
1167
- @Override
1168
- public boolean act (float delta) {
1169
- if (index >= actions.size) return true;
1170
- Pool<Action3d> pool = getPool();
1171
- setPool(null); // Ensure this action can't be returned to the pool while executings.
1172
- try {
1173
- if (actions.get(index).act(delta)) {
1174
- if (actor3d == null) return true; // This action was removed.
1175
- index++;
1176
- if (index >= actions.size) return true;
1177
- }
1178
- return false;
1179
- } finally {
1180
- setPool(pool);
1181
- }
1182
- }
1183
-
1184
- @Override
1185
- public void restart () {
1186
- super.restart();
1187
- index = 0;
1188
- }
1189
- }
1190
-
1191
- /** Base class for actions that transition over time using the percent complete.
1192
- * @author Nathan Sweet */
1193
- abstract public static class TemporalAction extends Action3d {
1194
- private float duration, time;
1195
- private Interpolation interpolation;
1196
- private boolean reverse, began, complete;
1197
-
1198
- public TemporalAction () {
1199
- }
1200
-
1201
- public TemporalAction (float duration) {
1202
- this.duration = duration;
1203
- }
1204
-
1205
- public TemporalAction (float duration, Interpolation interpolation) {
1206
- this.duration = duration;
1207
- this.interpolation = interpolation;
1208
- }
1209
-
1210
- @Override
1211
- public boolean act (float delta) {
1212
- if (complete) return true;
1213
- Pool pool = getPool();
1214
- setPool(null); // Ensure this action can't be returned to the pool while executing.
1215
- try {
1216
- if (!began) {
1217
- begin();
1218
- began = true;
1219
- }
1220
- time += delta;
1221
- complete = time >= duration;
1222
- float percent;
1223
- if (complete)
1224
- percent = 1;
1225
- else {
1226
- percent = time / duration;
1227
- if (interpolation != null) percent = interpolation.apply(percent);
1228
- }
1229
- update(reverse ? 1 - percent : percent);
1230
- if (complete) end();
1231
- return complete;
1232
- } finally {
1233
- setPool(pool);
1234
- }
1235
- }
1236
-
1237
- /** Called the first time {@link #act(float)} is called. This is a good place to query the {@link #actor actor's} starting
1238
- * state. */
1239
- protected void begin () {
1240
- }
1241
-
1242
- /** Called the last time {@link #act(float)} is called. */
1243
- protected void end () {
1244
- }
1245
-
1246
- /** Called each frame.
1247
- * @param percent The percentage of completion for this action, growing from 0 to 1 over the duration. If
1248
- * {@link #setReverse(boolean) reversed}, this will shrink from 1 to 0. */
1249
- abstract protected void update (float percent);
1250
-
1251
- /** Skips to the end of the transition. */
1252
- public void finish () {
1253
- time = duration;
1254
- }
1255
-
1256
- @Override
1257
- public void restart () {
1258
- time = 0;
1259
- began = false;
1260
- complete = false;
1261
- }
1262
-
1263
- @Override
1264
- public void reset () {
1265
- super.reset();
1266
- reverse = false;
1267
- interpolation = null;
1268
- }
1269
-
1270
- /** Gets the transition time so far. */
1271
- public float getTime () {
1272
- return time;
1273
- }
1274
-
1275
- /** Sets the transition time so far. */
1276
- public void setTime (float time) {
1277
- this.time = time;
1278
- }
1279
-
1280
- public float getDuration () {
1281
- return duration;
1282
- }
1283
-
1284
- /** Sets the length of the transition in seconds. */
1285
- public void setDuration (float duration) {
1286
- this.duration = duration;
1287
- }
1288
-
1289
- public Interpolation getInterpolation () {
1290
- return interpolation;
1291
- }
1292
-
1293
- public void setInterpolation (Interpolation interpolation) {
1294
- this.interpolation = interpolation;
1295
- }
1296
-
1297
- public boolean isReverse () {
1298
- return reverse;
1299
- }
1300
-
1301
- /** When true, the action's progress will go from 100% to 0%. */
1302
- public void setReverse (boolean reverse) {
1303
- this.reverse = reverse;
1304
- }
1305
- }
1306
-
1307
- /** Multiplies the delta of an action.
1308
- * @author Nathan Sweet */
1309
- public static class TimeScaleAction extends DelegateAction {
1310
- private float scale;
1311
-
1312
- @Override
1313
- protected boolean delegate (float delta) {
1314
- if (action == null) return true;
1315
- return action.act(delta * scale);
1316
- }
1317
-
1318
- public float getScale () {
1319
- return scale;
1320
- }
1321
-
1322
- public void setScale (float scale) {
1323
- this.scale = scale;
1324
- }
1325
- }
1326
-
1327
- /** Sets the actor's {@link Actor#setVisible(boolean) visibility}.
1328
- * @author Nathan Sweet */
1329
- public static class VisibleAction extends Action3d {
1330
- private boolean visible;
1331
-
1332
- @Override
1333
- public boolean act (float delta) {
1334
- actor3d.setVisible(visible);
1335
- return true;
1336
- }
1337
-
1338
- public boolean isVisible () {
1339
- return visible;
1340
- }
1341
-
1342
- public void setVisible (boolean visible) {
1343
- this.visible = visible;
1344
- }
1345
- }
1346
- }
1347
-
1348
- abstract class Action3d implements Poolable {
1349
- /** The actor this action is attached to, or null if it is not attached. */
1350
- protected Actor3d actor3d;
1351
-
1352
- private Pool<Action3d> pool;
1353
-
1354
- /** Updates the action based on time. Typically this is called each frame by {@link Actor#act(float)}.
1355
- * @param delta Time in seconds since the last frame.
1356
- * @return true if the action is done. This method may continue to be called after the action is done. */
1357
- abstract public boolean act (float delta);
1358
-
1359
- /** Sets the state of the action so it can be run again. */
1360
- public void restart () {
1361
- }
1362
-
1363
- /** @return null if the action is not attached to an actor. */
1364
- public Actor3d getActor3d() {
1365
- return actor3d;
1366
- }
1367
-
1368
- /** Sets the actor this action will be used for. This is called automatically when an action is added to an actor. This is also
1369
- * called with null when an action is removed from an actor. When set to null, if the action has a {@link #setPool(Pool) pool}
1370
- * then the action is {@link Pool#free(Object) returned} to the pool (which calls {@link #reset()}) and the pool is set to null.
1371
- * If the action does not have a pool, {@link #reset()} is not called.
1372
- * <p>
1373
- * This method is not typically a good place for a subclass to query the actor's state because the action may not be executed
1374
- * for some time, eg it may be {@link DelayAction delayed}. The actor's state is best queried in the first call to
1375
- * {@link #act(float)}. For a {@link TemporalAction}, use TemporalAction#begin(). */
1376
- public void setActor3d(Actor3d actor) {
1377
- this.actor3d = actor;
1378
- if (actor == null) {
1379
- if (pool != null) {
1380
- pool.free(this);
1381
- pool = null;
1382
- }
1383
- }
1384
- }
1385
-
1386
- /** Resets the optional state of this action to as if it were newly created, allowing the action to be pooled and reused. State
1387
- * required to be set for every usage of this action or computed during the action does not need to be reset.
1388
- * <p>
1389
- * The default implementation calls {@link #restart()}.
1390
- * <p>
1391
- * If a subclass has optional state, it must override this method, call super, and reset the optional state. */
1392
- public void reset () {
1393
- restart();
1394
- }
1395
-
1396
- public Pool getPool () {
1397
- return pool;
1398
- }
1399
-
1400
- /** Sets the pool that the action will be returned to when removed from the actor.
1401
- * @param pool May be null.
1402
- * @see #setActor(Actor) */
1403
- public void setPool (Pool pool) {
1404
- this.pool = pool;
1405
- }
1406
-
1407
- public String toString () {
1408
- String name = getClass().getName();
1409
- int dotIndex = name.lastIndexOf('.');
1410
- if (dotIndex != -1) name = name.substring(dotIndex + 1);
1411
- if (name.endsWith("Action")) name = name.substring(0, name.length() - 6);
1412
- return name;
1413
- }
1414
- }
Stage/Actor3d.java DELETED
@@ -1,361 +0,0 @@
1
- import com.badlogic.gdx.graphics.Color;
2
- import com.badlogic.gdx.graphics.g3d.Material;
3
- import com.badlogic.gdx.graphics.g3d.Model;
4
- import com.badlogic.gdx.graphics.g3d.ModelInstance;
5
- import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
6
- import com.badlogic.gdx.math.collision.BoundingBox;
7
- import com.badlogic.gdx.scenes.scene2d.Group;
8
- import com.badlogic.gdx.utils.Array;
9
- import com.badlogic.gdx.utils.DelayedRemovalArray;
10
-
11
-
12
- public class Actor3d extends ModelInstance {
13
- private Stage3d stage3d;
14
- private Group3d parent;
15
-
16
- private final DelayedRemovalArray<Event3dListener> listeners = new DelayedRemovalArray<Event3dListener>(0);
17
- private final Array<Action3d> actions3d = new Array<Action3d>(0);
18
-
19
- private String name;
20
- private boolean visible = true;
21
-
22
- private float x, y, z;
23
- private float originX, originY, originZ;
24
- private float scaleX = 1, scaleY = 1, scaleZ = 1;
25
- private float rotation = 0;
26
-
27
- private BoundingBox boundBox;
28
-
29
- public Actor3d(){
30
- super(new Model());
31
- setPosition(0,0,0);
32
- setOrigin(0,0,0);
33
- }
34
-
35
- public Actor3d(Model model){
36
- super(model);
37
- setPosition(0,0,0);
38
- boundBox = model.meshes.get(0).calculateBoundingBox();
39
- setOrigin(boundBox.max.x, boundBox.max.y, boundBox.max.z);
40
- }
41
-
42
- public Actor3d(Model model, float x, float y, float z){
43
- super(model);
44
- setPosition(x,y,z);
45
- boundBox = model.meshes.get(0).calculateBoundingBox();
46
- setOrigin(boundBox.max.x, boundBox.max.y, boundBox.max.z);
47
- }
48
-
49
- /** Updates the actor3d based on time. Typically this is called each frame by {@link Stage3d#act(float)}.
50
- * <p>
51
- * The default implementation calls {@link Action3d#act(float)} on each action and removes actions that are complete.
52
- * @param delta Time in seconds since the last frame. */
53
- public void act (float delta) {
54
- for (int i = 0; i < actions3d.size; i++) {
55
- Action3d action3d = actions3d.get(i);
56
- if (action3d.act(delta) && i < actions3d.size) {
57
- actions3d.removeIndex(i);
58
- action3d.setActor3d(null);
59
- i--;
60
- }
61
- }
62
- }
63
-
64
- public Actor3d hit (float x, float y) {
65
- return null;
66
- }
67
-
68
- /** Removes this actor3d from its parent, if it has a parent.
69
- * @see Group#removeActor3d(Actor3d) */
70
- public boolean remove () {
71
- if (parent != null) return parent.removeActor3d(this);
72
- return false;
73
- }
74
-
75
- /** Add a listener to receive events that {@link #hit(float, float, boolean) hit} this actor3d. See {@link #fire(Event)}.
76
- *
77
- * @see InputListener
78
- * @see ClickListener */
79
- public boolean addListener(Event3dListener listener) {
80
- if (!listeners.contains(listener, true)) {
81
- listeners.add(listener);
82
- return true;
83
- }
84
- return false;
85
- }
86
-
87
- public boolean removeListener (Event3dListener listener) {
88
- return listeners.removeValue(listener, true);
89
- }
90
-
91
- public Array<Event3dListener> getListeners () {
92
- return listeners;
93
- }
94
-
95
- public void addAction3d (Action3d action) {
96
- action.setActor3d(this);
97
- actions3d.add(action);
98
- }
99
-
100
- public void removeAction3d (Action3d action) {
101
- if (actions3d.removeValue(action, true)) action.setActor3d(null);
102
- }
103
-
104
- public Array<Action3d> getActions3d () {
105
- return actions3d;
106
- }
107
-
108
- /** Removes all actions on this actor3d. */
109
- public void clearActions3d () {
110
- for (int i = actions3d.size - 1; i >= 0; i--)
111
- actions3d.get(i).setActor3d(null);
112
- actions3d.clear();
113
- }
114
-
115
- /** Removes all listeners on this actor3d. */
116
- public void clearListeners () {
117
- listeners.clear();
118
- }
119
-
120
- /** Removes all actions and listeners on this actor3d. */
121
- public void clear () {
122
- clearActions3d();
123
- clearListeners();
124
- }
125
-
126
- /** Called by the framework when this actor3d or any parent is added to a group that is in the stage3d.
127
- * @param stage3d May be null if the actor3d or any parent is no longer in a stage. */
128
- protected void setStage3d(Stage3d stage3d) {
129
- this.stage3d = stage3d;
130
- }
131
-
132
- /** Returns the stage3d that this actor3d is currently in, or null if not in a stage. */
133
- public Stage3d getStage3d() {
134
- return stage3d;
135
- }
136
-
137
- /** Returns true if this actor3d is the same as or is the descendant of the specified actor3d. */
138
- public boolean isDescendantOf (Actor3d actor3d) {
139
- if (actor3d == null) throw new IllegalArgumentException("actor3d cannot be null.");
140
- Actor3d parent = this;
141
- while (true) {
142
- if (parent == null) return false;
143
- if (parent == actor3d) return true;
144
- parent = parent.parent;
145
- }
146
- }
147
-
148
- /** Returns true if this actor3d is the same as or is the ascendant of the specified actor3d. */
149
- public boolean isAscendantOf (Actor3d actor3d) {
150
- if (actor3d == null) throw new IllegalArgumentException("actor3d cannot be null.");
151
- while (true) {
152
- if (actor3d == null) return false;
153
- if (actor3d == this) return true;
154
- actor3d = actor3d.parent;
155
- }
156
- }
157
-
158
- /** Returns true if the actor3d's parent is not null. */
159
- public boolean hasParent () {
160
- return parent != null;
161
- }
162
-
163
- /** Returns the parent actor3d, or null if not in a stage. */
164
- public Group3d getParent () {
165
- return parent;
166
-
167
- }
168
-
169
- /** Called by the framework when an actor3d is added to or removed from a group.
170
- * @param parent May be null if the actor3d has been removed from the parent. */
171
- protected void setParent (Group3d parent) {
172
- this.parent = parent;
173
- }
174
-
175
- public boolean isVisible () {
176
- return visible;
177
-
178
- }
179
- /** If false, the actor3d will not be drawn and will not receive touch events. Default is true. */
180
- public void setVisible (boolean visible) {
181
- this.visible = visible;
182
- }
183
-
184
- /* Sets the originx , originy and originz used for rotation */
185
- public void setOrigin (float originX, float originY, float originZ) {
186
- this.originX = originX;
187
- this.originY = originY;
188
- this.originZ = originZ;
189
- }
190
-
191
- public void setPosition(float x, float y, float z) {
192
- this.x = x;
193
- this.y = y;
194
- this.z = z;
195
- transform.setToTranslationAndScaling(this.x, this.y, this.z, scaleX, scaleY, scaleZ);
196
- }
197
-
198
- public void translate(float x, float y, float z) {
199
- this.x += x;
200
- this.y += y;
201
- this.z += z;
202
- transform.setToTranslationAndScaling(this.x, this.y, this.z, scaleX, scaleY, scaleZ);
203
- }
204
-
205
- public void setRotation(float degrees) {
206
- this.rotation = degrees;
207
- this.rotate(degrees);
208
- transform.setToRotation(originX, originY, originZ, rotation);
209
- }
210
-
211
- public void rotate (float degrees) {
212
- rotation += degrees;
213
- setPosition(x, y, z);
214
- transform.setToRotation(originX, originY, originZ, rotation);
215
- }
216
-
217
- public void setScale(float scaleX, float scaleY, float scaleZ) {
218
- this.scaleX = scaleX;
219
- this.scaleY = scaleY;
220
- this.scaleZ = scaleZ;
221
- transform.setToScaling(scaleX, scaleY, scaleZ);
222
- }
223
-
224
- public void setScale(float scale) {
225
- this.scaleX = scale;
226
- this.scaleY = scale;
227
- this.scaleZ = scale;
228
- transform.setToScaling(scaleX, scaleY, scaleZ);
229
- }
230
-
231
- /** Adds the specified scale to the current scale. */
232
- public void scale(float scale) {
233
- scaleX += scale;
234
- scaleY += scale;
235
- scaleZ += scale;
236
- transform.scl(scale); // re-implement this
237
- }
238
-
239
- public void scale(float scaleX, float scaleY, float scaleZ) {
240
- this.scaleX += scaleX;
241
- this.scaleY += scaleY;
242
- this.scaleZ += scaleZ;
243
- transform.scl(scaleX, scaleY, scaleZ); // re-implement this
244
- }
245
-
246
-
247
- public void setX (float x) {
248
- this.x = x;
249
- transform.setToTranslation(x, y, z);
250
- }
251
-
252
- public float getX () {
253
- return x;
254
- }
255
-
256
- public void setY (float y) {
257
- this.y = y;
258
- transform.setToTranslation(x, y, z);
259
- }
260
-
261
- public float getY () {
262
- return y;
263
- }
264
-
265
- public void setZ (float z) {
266
- this.z = z;
267
- transform.setToTranslation(x, y, z);
268
- }
269
-
270
- public float getZ (){
271
- return z;
272
- }
273
-
274
- public void setOriginX (float originX) {
275
- this.originX = originX;
276
- }
277
-
278
- public float getOriginX () {
279
- return originX;
280
- }
281
-
282
- public void setOriginY (float originY) {
283
- this.originY = originY;
284
- }
285
-
286
- public float getOriginY () {
287
- return originY;
288
- }
289
-
290
- public void setOriginZ (float originZ) {
291
- this.originZ = originZ;
292
- }
293
-
294
- public float getOriginZ () {
295
- return originZ;
296
- }
297
-
298
- public void setScaleX (float scaleX) {
299
- this.scaleX = scaleX;
300
- transform.scale(scaleX, scaleY, scaleZ);
301
- }
302
-
303
- public float getScaleX () {
304
- return scaleX;
305
- }
306
-
307
- public float getRotation () {
308
- return rotation;
309
- }
310
-
311
- public void setScaleY (float scaleY) {
312
- this.scaleY = scaleY;
313
- transform.scale(scaleX, scaleY, scaleZ);
314
- }
315
-
316
- public float getScaleY () {
317
- return scaleY;
318
- }
319
-
320
- public void setScaleZ (float scaleZ) {
321
- this.scaleY = scaleZ;
322
- transform.scale(scaleX, scaleY, scaleZ);
323
- }
324
-
325
- public float getScaleZ () {
326
- return scaleZ;
327
- }
328
-
329
- /** Sets a name for easier identification of the actor3d in application code.
330
- * @see Group#findActor(String) */
331
- public void setName (String name) {
332
- this.name = name;
333
-
334
- }
335
- public String getName () {
336
- return name;
337
- }
338
-
339
- public String toString () {
340
- String name = this.name;
341
- if (name == null) {
342
- name = getClass().getName();
343
- int dotIndex = name.lastIndexOf('.');
344
- if (dotIndex != -1) name = name.substring(dotIndex + 1);
345
- }
346
- return name;
347
- }
348
-
349
- public Color getColor(){
350
- return ((ColorAttribute)getMaterial("Color").get(ColorAttribute.Diffuse)).color;
351
- }
352
-
353
- public void setColor(Color color){
354
- ColorAttribute ca = new ColorAttribute(ColorAttribute.Diffuse, color);
355
- if(getMaterial("Color") != null)
356
- getMaterial("Color").set(ca);
357
- else
358
- materials.add(new Material("Color", ca));
359
- model.materials.add(new Material("Color", ca));
360
- }
361
- }
Stage/Group3d.java DELETED
@@ -1,146 +0,0 @@
1
- import com.badlogic.gdx.graphics.g3d.Environment;
2
- import com.badlogic.gdx.graphics.g3d.Model;
3
- import com.badlogic.gdx.graphics.g3d.ModelBatch;
4
- import com.badlogic.gdx.utils.Array;
5
- import com.badlogic.gdx.utils.SnapshotArray;
6
-
7
- public class Group3d extends Actor3d{
8
- private final SnapshotArray<Actor3d> children = new SnapshotArray<Actor3d>(true, 4, Actor3d.class);
9
-
10
- public Group3d(){
11
- super();
12
- }
13
-
14
- public Group3d(Model model){
15
- super(model);
16
- }
17
-
18
- public void act (float delta) {
19
- super.act(delta);
20
- Actor3d[] actors = children.begin();
21
- for (int i = 0, n = children.size; i < n; i++)
22
- actors[i].act(delta);
23
- children.end();
24
- }
25
-
26
- public void drawChildren(ModelBatch modelBatch, Environment environment){
27
- modelBatch.render(this, environment);
28
- modelBatch.render(children, environment);
29
- for(Actor3d a: children){
30
- if(a instanceof Group3d){
31
- ((Group3d) a).drawChildren(modelBatch, environment);
32
- }
33
- }
34
- }
35
-
36
- /** Adds an actor as a child of this group. The actor is first removed from its parent group, if any.
37
- * @see #remove() */
38
- public void addActor3d(Actor3d actor3d) {
39
- actor3d.remove();
40
- children.add(actor3d);
41
- actor3d.setParent(this);
42
- actor3d.setStage3d(getStage3d());
43
- childrenChanged();
44
- }
45
-
46
- /** Removes an actor from this group. If the actor will not be used again and has actions, they should be
47
- * {@link Actor#clearActions3d() cleared} so the actions will be returned to their
48
- * {@link Action#setPool(com.badlogic.gdx.utils.Pool) pool}, if any. This is not done automatically. */
49
- public boolean removeActor3d(Actor3d actor3d) {
50
- if (!children.removeValue(actor3d, true)) return false;
51
- Stage3d stage = getStage3d();
52
- if (stage != null) stage.unfocus(actor3d);
53
- actor3d.setParent(null);
54
- actor3d.setStage3d(null);
55
- childrenChanged();
56
- return true;
57
- }
58
-
59
- @Override
60
- public void addAction3d(Action3d action3d){
61
- super.addAction3d(action3d);
62
- Actor3d[] actors = children.begin();
63
- for (int i = 0, n = children.size; i < n; i++)
64
- actors[i].addAction3d(action3d);
65
- children.end();
66
- }
67
-
68
- @Override
69
- public void removeAction3d(Action3d action3d) {
70
- super.removeAction3d(action3d);
71
- Actor3d[] actors = children.begin();
72
- for (int i = 0, n = children.size; i < n; i++)
73
- actors[i].removeAction3d(action3d);
74
- children.end();
75
- }
76
-
77
- /** Called when actors are added to or removed from the group. */
78
- protected void childrenChanged () {
79
- }
80
-
81
- /** Removes all actors from this group. */
82
- public void clearChildren () {
83
- Actor3d[] actors = children.begin();
84
- for (int i = 0, n = children.size; i < n; i++) {
85
- Actor3d child = actors[i];
86
- child.setStage3d(null);
87
- child.setParent(null);
88
- }
89
- children.end();
90
- children.clear();
91
- childrenChanged();
92
- }
93
-
94
- /** Removes all children, actions, and listeners from this group. */
95
- public void clear () {
96
- super.clear();
97
- clearChildren();
98
- }
99
-
100
- /** Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the group. */
101
- public Actor3d findActor3d(String name) {
102
- Array<Actor3d> children = this.children;
103
- for (int i = 0, n = children.size; i < n; i++)
104
- if (name.equals(children.get(i).getName())) return children.get(i);
105
- for (int i = 0, n = children.size; i < n; i++) {
106
- Actor3d child = children.get(i);
107
- if (child instanceof Group3d) {
108
- Actor3d actor = ((Group3d)child).findActor3d(name);
109
- if (actor != null) return actor;
110
- }
111
- }
112
- return null;
113
- }
114
-
115
- @Override
116
- protected void setStage3d(Stage3d stage3d) {
117
- super.setStage3d(stage3d);
118
- Array<Actor3d> children = this.children;
119
- for (int i = 0, n = children.size; i < n; i++)
120
- children.get(i).setStage3d(stage3d);
121
- }
122
-
123
- /** Returns an ordered list of child actors in this group. */
124
- public SnapshotArray<Actor3d> getChildren () {
125
- return children;
126
- }
127
-
128
- public boolean hasChildren () {
129
- return children.size > 0;
130
- }
131
-
132
- /** Prints the actor hierarchy recursively for debugging purposes. */
133
- public void print () {
134
- print("");
135
- }
136
-
137
- private void print (String indent) {
138
- Actor3d[] actors = children.begin();
139
- for (int i = 0, n = children.size; i < n; i++) {
140
- System.out.println(indent + actors[i]);
141
- if (actors[i] instanceof Group3d) ((Group3d)actors[i]).print(indent + "| ");
142
- }
143
- children.end();
144
- }
145
-
146
- }
Stage/Scene.java DELETED
@@ -1,80 +0,0 @@
1
- import com.badlogic.gdx.Gdx;
2
- import com.badlogic.gdx.scenes.scene2d.Actor;
3
- import com.badlogic.gdx.utils.ArrayMap;
4
- import com.badlogic.gdx.utils.StringBuilder;
5
-
6
- abstract public class Scene extends Actor {
7
- /* The array map containing all the scenes data of the game*/
8
- public static final ArrayMap<String, String> scenesMap = new ArrayMap<String, String>();
9
-
10
- private String sceneName = "";
11
- public String sceneBackground = "None";
12
- public String sceneMusic = "None";
13
- public String sceneTransition = "None";
14
- public float sceneDuration = 0;
15
- public InterpolationType sceneInterpolationType = InterpolationType.Linear;
16
-
17
- public Scene(){
18
- setPosition(0, 0);
19
- setSize(0, 0);
20
- setBounds(0,0, 0, 0);
21
- sceneName = this.getClass().getName();
22
- setName(sceneName);
23
- Stage.log("Current Scene: "+sceneName);
24
- load(sceneName);
25
- }
26
-
27
- public abstract void onClick(Actor actor);
28
- public abstract void onTouchDown(Actor actor);
29
- public abstract void onTouchUp();
30
- public abstract void onDragged();
31
- public abstract void onGesture(GestureType gestureType);
32
- public abstract void onKeyTyped(char key);
33
- public abstract void onKeyUp(int keycode);
34
- public abstract void onKeyDown(int keycode);
35
- public abstract void onPause();
36
- public abstract void onResume();
37
- public abstract void onDispose();
38
-
39
- public void load(String sceneName){
40
- Stage.log("Load");
41
- String[] lines = Scene.scenesMap.get(sceneName).split("\n");
42
- for(String line: lines){
43
- if(line.trim().isEmpty())
44
- continue;
45
- Stage.addActor(Stage.json.fromJson(Actor.class, line));
46
- }
47
- if(!sceneBackground.equals("None"))
48
- Stage.setBackground(sceneBackground);
49
- if(!sceneMusic.equals("None"))
50
- Asset.musicPlay(sceneMusic);
51
- if(!sceneTransition.equals("None"))
52
- Effect.transition(TransitionType.valueOf(sceneTransition),
53
- Stage.getRoot(), sceneDuration, sceneInterpolationType);
54
- }
55
-
56
- protected void save(){
57
- save(sceneName);
58
- }
59
-
60
- public void save(String sceneName){
61
- Stage.log("Save");
62
- StringBuilder sb = new StringBuilder();
63
- Stage.removeActor("Shape");
64
- for(Actor actor: Stage.getChildren()){
65
- if(Stage.isValidActor(actor)){
66
- //Stage.log(actor.getName());
67
- sb.append(Stage.json.toJson(actor));
68
- sb.append("\n");
69
- }
70
- }
71
- scenesMap.put(sceneName, sb.toString());
72
- Gdx.files.local(Asset.basePath+"scene").writeString(Stage.json.toJson(scenesMap, ArrayMap.class,
73
- String.class), false);
74
- sb = null;
75
- }
76
-
77
- public String getSceneName(){
78
- return sceneName;
79
- }
80
- }
Stage/Scene3d.java DELETED
@@ -1,5 +0,0 @@
1
-
2
- public class Scene3d {
3
-
4
- }
5
-
Stage/SpriteChar.java DELETED
@@ -1,11 +0,0 @@
1
- import com.badlogic.gdx.graphics.g2d.Animation;
2
- import com.badlogic.gdx.graphics.g2d.Batch;
3
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
4
- import com.badlogic.gdx.scenes.scene2d.Actor;
5
-
6
- public class SpriteChar extends Actor {
7
-
8
- public SpriteChar(){
9
-
10
- }
11
- }
Stage/Stage.java DELETED
@@ -1,1272 +0,0 @@
1
- import java.awt.Dimension;
2
- import java.awt.Toolkit;
3
-
4
- import com.badlogic.gdx.ApplicationListener;
5
- import com.badlogic.gdx.Gdx;
6
- import com.badlogic.gdx.Files.FileType;
7
- import com.badlogic.gdx.InputMultiplexer;
8
- import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
9
- import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
10
- import com.badlogic.gdx.graphics.Color;
11
- import com.badlogic.gdx.graphics.GL20;
12
- import com.badlogic.gdx.graphics.OrthographicCamera;
13
- import com.badlogic.gdx.graphics.PerspectiveCamera;
14
- import com.badlogic.gdx.graphics.g2d.Batch;
15
- import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
16
- import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
17
- import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
18
- import com.badlogic.gdx.math.Interpolation;
19
- import com.badlogic.gdx.math.Intersector;
20
- import com.badlogic.gdx.math.MathUtils;
21
- import com.badlogic.gdx.math.Rectangle;
22
- import com.badlogic.gdx.math.Vector2;
23
- import com.badlogic.gdx.math.Vector3;
24
- import com.badlogic.gdx.scenes.scene2d.Action;
25
- import com.badlogic.gdx.scenes.scene2d.Actor;
26
- import com.badlogic.gdx.scenes.scene2d.Group;
27
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
28
- import com.badlogic.gdx.scenes.scene2d.Touchable;
29
- import com.badlogic.gdx.scenes.scene2d.actions.Actions;
30
- import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
31
- import com.badlogic.gdx.scenes.scene2d.ui.Image;
32
- import com.badlogic.gdx.scenes.scene2d.ui.Label;
33
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
34
- import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
35
- import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
36
- import com.badlogic.gdx.utils.Array;
37
- import com.badlogic.gdx.utils.Json;
38
- import com.badlogic.gdx.utils.JsonReader;
39
- import com.badlogic.gdx.utils.JsonValue;
40
- import com.badlogic.gdx.utils.Scaling;
41
- import com.badlogic.gdx.utils.SnapshotArray;
42
- import com.badlogic.gdx.utils.Timer;
43
- import com.badlogic.gdx.utils.Timer.Task;
44
-
45
- /** The Main Entry Point for the Game is the Stage class
46
- * <p>
47
- * It consists of a single Stage2d, Stage3d, Camera2d, and Camera3d which are all initialized based on the config file.
48
- * The root of the stage can be accessed in a statically {@link #getRoot()} and methods related to camera like moveTo, moveBy,
49
- * are also accessed the same way.<br>
50
- * It has extra things like stateTime, gameUptime, pauseState, PauseListeners, ResumeListeners, DisposeListeners.<br>
51
- *
52
- * It has automatic asset unloading and disposing and you can use {@link #exit()} to quit your game safely
53
- *
54
- * Note: Your TMX maps have to be unloaded manually as they can be huge resources needing to be freed early.
55
- *
56
- * It has static methods which can be used for panning the camera using mouse, keyboard, drag.. etc.
57
- * It can also automatically follow a actor by using followActor(Actor actor)<br>
58
- *
59
- * This class will register all your scenes based on your scene.json file and then you can switch you scenes by using {@link #setScene}
60
- * method with the sceneClassName.<br>
61
- *
62
- * Run the Desktop Game by using Stage class as it contains the static main declaration.<br>
63
- * Your first sceneName in the config.json file gets shown first automatically and once and all your assets <br>
64
- * are loaded in the background(asynchronously) in the first scene and then automatically the next scene in the list is set.
65
- * You can stop the stage from switching to the next scene by setting Asset.loadAsynchronous = false in your first scene but then
66
- * you have to load all the assets by using the blocking call Asset.loadBlocking()
67
- *
68
- * If you want to display your splash screen for more time after the assets have loaded then you can change
69
- * Stage.splashDuration to the amount of time you want you splash screen to show. By default the splash screen's
70
- * lifetime is finished once the assets are loaded and then the next scene is set.
71
- *
72
- * <p>
73
- * @ex
74
- * <pre>
75
- * <code>
76
- //This is our first Scene and it shows the libgdx logo until all the assets are loaded
77
- //then it automatically switches to the Menu scene
78
- public class Splash extends Scene {
79
-
80
- public Splash() {
81
- Stage.splashDuration = 5f; // This will make my splash scene to wait 5 seconds after assets are all loaded
82
- final Texture bg1 = new Texture("splash/libgdx.png");
83
- final Image imgbg1 = new Image(bg1);
84
- imgbg1.setFillParent(true);
85
- Stage.addActor(imgbg1);
86
- }
87
- }
88
-
89
- //This is Scene gets called once the assets are loaded
90
- public class Menu extends Scene {
91
-
92
- public Menu() {
93
- //create some actors
94
- // if you used sink studio and create a scene like Menu.json then
95
- // it will automatically call load("Menu") it will populate your scene after parsing the json file
96
-
97
- //you can access these objects like this
98
- TextButton btn = (TextButton) Stage.findActor("TextButton1");
99
- Image img = (Image) Stage.findActor("Image5");
100
-
101
- // these actors are loaded from the json file and are give names which allows
102
- // easy access to them
103
- }
104
- }
105
- </code>
106
- </pre>
107
- * @author pyros2097 */
108
-
109
- public final class Stage implements ApplicationListener {
110
- private static Stage instance;
111
- public static float stateTime = 0;
112
- public static float gameUptime = 0;
113
- private float startTime = System.nanoTime();
114
-
115
- public static final Json json = new Json();
116
- public static final JsonReader jsonReader = new JsonReader();
117
- public static JsonValue configJson = null;
118
-
119
- private static com.badlogic.gdx.scenes.scene2d.Stage stage2d;
120
- private static OrthographicCamera camera;
121
- private static Label fpsLabel;
122
- private static Stage3d stage3d;
123
- public static InputMultiplexer inputMux = new InputMultiplexer();
124
- private static CameraInputController camController;
125
- public static boolean use3d = true;
126
-
127
- private static Scene currentScene = null;
128
- private static int sceneIndex = 0;
129
- private static final Array<Actor> hudActors = new Array<Actor>();
130
-
131
- /*Important:
132
- * The Target Width and Target Height refer to the nominal width and height of the game for the
133
- * graphics which are created for this width and height, this allows for the Stage to scale this
134
- * graphics for all screen width and height. Therefore your game will work on all screen sizes
135
- * but maybe blurred or look awkward on some devices.
136
- * ex:
137
- * My Game targetWidth = 800 targetHeight = 480
138
- * Then my game works perfectly for SCREEN_WIDTH = 800 SCREEN_HEIGHT = 480
139
- * and on others screen sizes it is just zoomed/scaled but works fine thats all
140
- */
141
- public static float targetWidth = 800;
142
- public static float targetHeight = 480;
143
- public static boolean pauseState = false;
144
- public static float splashDuration = 0f;
145
- public static Color bgColor = new Color(1f,1f,1f,1f);
146
-
147
- //Studio Related Stuff
148
- /* Selected Actor can never be null as when the stage is clicked it may return an actor or the root actor */
149
- private static ShapeRenderer shapeRenderer;
150
- public static boolean debug = false;
151
- public static ClassLoader cl = null;
152
-
153
- public static int dots = 40;
154
- public static int xlines;
155
- public static int ylines;
156
-
157
- public final static Vector2 mouse = new Vector2();
158
- public static int pointer = 0;
159
- public static int button = 0;
160
- private final static Actor selectionBox = new Actor(){
161
- @Override
162
- public void draw(Batch batch, float alpha){
163
- batch.end();
164
- shapeRenderer.begin(ShapeType.Line);
165
- shapeRenderer.setColor(Color.GREEN);
166
- shapeRenderer.rect(getX(), getY(),
167
- getWidth(),getHeight());
168
- shapeRenderer.end();
169
- batch.begin();
170
- }
171
- };
172
- static {
173
- selectionBox.setTouchable(Touchable.disabled);
174
- selectionBox.setName("Shape");
175
- };
176
-
177
- /** The Main Launcher for Stage Game
178
- * <p>
179
- * Just specify the Stage class as the Main file and when you export your game to jar add
180
- * the manifest entry Main-Class: Stage for it to work.
181
- */
182
- public static void main(String[] argc) {
183
- final LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
184
- configJson = jsonReader.parse(Stage.class.getClassLoader().getResourceAsStream("config"));
185
- if(configJson.getBoolean("hasIcon"))
186
- cfg.addIcon("icon.png", FileType.Internal);
187
- String[] screen = configJson.getString("screenSize").split("x");
188
- String[] target = configJson.getString("targetSize").split("x");
189
- cfg.width = Integer.parseInt(screen[0]);
190
- cfg.height = Integer.parseInt(screen[1]);
191
- Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
192
- cfg.x = (int) ((dimension.getWidth() - cfg.width) / 2);
193
- cfg.y = (int) ((dimension.getHeight() - cfg.height) / 2);
194
- cfg.resizable = configJson.getBoolean("resize");
195
- cfg.forceExit = configJson.getBoolean("forceExit");
196
- cfg.fullscreen = configJson.getBoolean("fullScreen");
197
- cfg.useGL20 = configJson.getBoolean("useGL20");
198
- cfg.vSyncEnabled = configJson.getBoolean("vSync");
199
- cfg.audioDeviceBufferCount = configJson.getInt("audioBufferCount");
200
- LwjglApplicationConfiguration.disableAudio = configJson.getBoolean("disableAudio");
201
- targetWidth = Integer.parseInt(target[0]);
202
- targetHeight = Integer.parseInt(target[1]);
203
- new LwjglApplication(Stage.getInstance(), cfg);
204
- }
205
-
206
- /*
207
- * Singleton Pattern
208
- */
209
- private Stage(){}
210
-
211
- public static Stage getInstance(){
212
- if(instance == null)
213
- instance = new Stage();
214
- return instance;
215
- }
216
-
217
- /*
218
- * This is where the stage and camera are created and the scenes are created
219
- * dynamically
220
- */
221
- @Override
222
- public final void create() {
223
- log("Created");
224
- Config.setup();
225
- stage2d = new com.badlogic.gdx.scenes.scene2d.Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
226
- configJson.getBoolean("keepAspectRatio"));
227
- stage2d.getRoot().setName("Root");
228
- stage2d.getRoot().setTouchable(Touchable.childrenOnly);
229
- camera = new OrthographicCamera();
230
- camera.setToOrtho(false, targetWidth, targetHeight);
231
- camera.position.set(targetWidth/2, targetHeight/2, 0);
232
- stage2d.setCamera(camera);
233
- inputMux.addProcessor(stage2d);
234
- stage2d.addListener(touchInput);
235
- if(use3d){
236
- stage3d = new Stage3d();
237
- camController = new CameraInputController(stage3d.getCamera());
238
- inputMux.addProcessor(stage3d);
239
- inputMux.addProcessor(camController);
240
- }
241
- shapeRenderer = new ShapeRenderer();
242
- Serializer.initialize();
243
- JsonValue sv = jsonReader.parse(Gdx.files.internal(Asset.basePath+"scene"));
244
- for(JsonValue jv: sv.iterator())
245
- Scene.scenesMap.put(jv.name, jv.asString());
246
- setScene(Scene.scenesMap.firstKey());
247
- xlines = (int)Gdx.graphics.getWidth()/dots;
248
- ylines = (int)Gdx.graphics.getHeight()/dots;
249
- Gdx.input.setCatchBackKey(true);
250
- Gdx.input.setCatchMenuKey(true);
251
- Gdx.input.setInputProcessor(inputMux);
252
- }
253
-
254
- /*
255
- * This is the main rendering call that updates the time, updates the stage,
256
- * loads assets asynchronously, updates the camera and FPS text.
257
- */
258
- @Override
259
- public final void render(){
260
- if (System.nanoTime() - startTime >= 1000000000) {
261
- gameUptime +=1 ;
262
- startTime = System.nanoTime();
263
- }
264
- stateTime += Gdx.graphics.getDeltaTime();
265
- Gdx.gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
266
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT |GL20.GL_DEPTH_BUFFER_BIT);
267
- Asset.load();
268
- if(use3d){
269
- stage3d.act();
270
- stage3d.draw();
271
- camController.update();
272
- }
273
- stage2d.act();//Gdx.graphics.getDeltaTime();
274
- stage2d.draw();
275
- updateController();
276
- if(debug){
277
- shapeRenderer.begin(ShapeType.Point);
278
- shapeRenderer.setColor(Color.BLACK);
279
- for(int i = 0; i<=xlines; i++)
280
- for(int j = 0; j<=ylines; j++)
281
- shapeRenderer.point(2+i*dots, j*dots, 0);
282
- shapeRenderer.end();
283
- }
284
- if (fpsLabel != null && configJson.getBoolean("showFps"))
285
- fpsLabel.setText("Fps: " + Gdx.graphics.getFramesPerSecond());
286
- }
287
-
288
- public static void outline(Actor actor){
289
- selectionBox.setPosition(actor.getX(), actor.getY());
290
- selectionBox.setSize(actor.getWidth(), actor.getHeight());
291
- Stage.addActor(selectionBox);
292
- }
293
- /*
294
- * This will resize the stage accordingly to fit to your target width and height
295
- */
296
- @Override
297
- public final void resize(int width, int height) {
298
- log("Resize");
299
- stage2d.setViewport(targetWidth, targetHeight, configJson.getBoolean("keepAspectRatio"));
300
- if(use3d)
301
- stage3d.setViewport(targetWidth, targetHeight, configJson.getBoolean("keepAspectRatio"));
302
- }
303
-
304
- /*
305
- * This will pause any music and stop any sound being played
306
- * and will fire the Pause event
307
- */
308
- @Override
309
- public final void pause() {
310
- log("Pause");
311
- Asset.musicPause();
312
- Asset.soundStop();
313
- pauseState = true;
314
- currentScene.onPause();
315
- }
316
-
317
- /*
318
- * This will resume any music currently being played
319
- * and will fire the Resume event
320
- */
321
- @Override
322
- public final void resume() {
323
- log("Resume");
324
- Asset.musicResume();
325
- pauseState = false;
326
- currentScene.onResume();
327
- }
328
-
329
- /*
330
- * When disposed is called
331
- * It will automatically unload all your assets and dispose the stage
332
- */
333
- @Override
334
- public final void dispose() {
335
- log("Disposing");
336
- currentScene.onDispose();
337
- stage2d.dispose();
338
- Asset.unloadAll();
339
- Config.writeTotalTime(gameUptime);
340
- Gdx.app.exit();
341
- }
342
-
343
- /*
344
- * Use this to exit your game safely
345
- * It will automatically unload all your assets and dispose the stage
346
- */
347
- public static final void exit(){
348
- log("Disposing and Exiting");
349
- currentScene.onDispose();
350
- stage2d.dispose();
351
- Asset.unloadAll();
352
- Config.writeTotalTime(gameUptime);
353
- Gdx.app.exit();
354
- }
355
-
356
- public static void log(String log) {
357
- if(configJson.getBoolean("loggingEnabled"))
358
- Gdx.app.log("Stage ", log);
359
- }
360
-
361
- public static Group getRoot(){
362
- return stage2d.getRoot();
363
- }
364
-
365
- /**
366
- * Get screen time from start in format of HH:MM:SS. It is calculated from
367
- * "secondsTime" parameter.
368
- * */
369
- public static String toScreenTime(float secondstime) {
370
- int seconds = (int)(secondstime % 60);
371
- int minutes = (int)((secondstime / 60) % 60);
372
- int hours = (int)((secondstime / 3600) % 24);
373
- return new String(addZero(hours) + ":" + addZero(minutes) + ":" + addZero(seconds));
374
- }
375
-
376
- private static String addZero(int value){
377
- String str = "";
378
- if(value < 10)
379
- str = "0" + value;
380
- else
381
- str = "" + value;
382
- return str;
383
- }
384
-
385
- /***********************************************************************************************************
386
- * Scene Related Functions *
387
- ************************************************************************************************************/
388
- /**
389
- * Set the current scene to be displayed
390
- * @param className The scene's Class Name
391
- **/
392
- public static void setScene(String className){
393
- if(!Scene.scenesMap.containsKey(className)){
394
- log(className+": Scene Does not Exist");
395
- return;
396
- }
397
- /*
398
- * Every time the scene Changes disable panning/following/listening as it can cause the
399
- * camera to move around aimlessly, thus abrupting the scene and clear
400
- * all the listeners/huds that were registered in the previous scene
401
- */
402
- sceneIndex = Scene.scenesMap.keys().toArray().indexOf(className, false);
403
- if(currentScene != null)
404
- currentScene.onDispose();
405
- clear();
406
- clear3d();
407
- stage2d.addListener(touchInput);
408
- stage2d.getRoot().setPosition(0, 0);
409
- stage2d.getRoot().setSize(targetWidth, targetHeight);
410
- stage2d.getRoot().setBounds(0,0,targetWidth,targetHeight);
411
- stage2d.getRoot().setCullingArea(getBounds(stage2d.getRoot()));
412
- stage2d.getRoot().setColor(1f, 1f, 1f, 1f);
413
- stage2d.getRoot().setVisible(true);
414
- stage3d.getRoot().setPosition(0, 0, 0);
415
- stage3d.getRoot().setVisible(true);
416
- try {
417
- if(cl != null)
418
- currentScene = (Scene) cl.loadClass(className).newInstance();
419
- else
420
- currentScene = (Scene) Class.forName(className).newInstance();
421
- //addActor(currentScene);
422
- } catch (InstantiationException e) {
423
- log("Scene cannot be created , Check if scene class constructor is empty");
424
- e.printStackTrace();
425
- } catch (IllegalAccessException e) {
426
- log("Scene cannot be created , Check if scene class can be found");
427
- e.printStackTrace();
428
- } catch (ClassNotFoundException e) {
429
- log("Scene cannot be created , Check if scene class can be found");
430
- e.printStackTrace();
431
- }
432
- if (fpsLabel != null && configJson.getBoolean("showFPS")){
433
- fpsLabel.setPosition(targetWidth - 80, targetHeight - 20);
434
- addHud(fpsLabel);
435
- }
436
- }
437
-
438
- /**
439
- * Set the current scene to be displayed with an amount of delay
440
- * @param className The registered scene's name
441
- **/
442
- public static void setSceneWithDelay(final String className, float delay){
443
- Timer.schedule(new Task(){
444
- @Override
445
- public void run() {
446
- setScene(className);
447
- }
448
- }, delay);
449
- }
450
-
451
- /**
452
- * Returns the current scene being Displayed on stage
453
- **/
454
- public static Scene getScene(){
455
- return currentScene;
456
- }
457
-
458
- /**
459
- * Changes to the next scene in the scnesList
460
- **/
461
- public static void nextScene(){
462
- if(sceneIndex <= Scene.scenesMap.size)
463
- sceneIndex++;
464
- setScene(Scene.scenesMap.getKeyAt(sceneIndex));
465
- }
466
-
467
- /**
468
- * Changes to the previous scene in the scnesList
469
- **/
470
- public static void prevScene(){
471
- if(sceneIndex >= 0)
472
- sceneIndex--;
473
- setScene(Scene.scenesMap.getKeyAt(sceneIndex));
474
- }
475
-
476
- /**
477
- * Changes to the next scene in the scnesList
478
- **/
479
- public static void nextSceneWithDelay(float delay){
480
- if(sceneIndex <= Scene.scenesMap.size)
481
- sceneIndex++;
482
- setSceneWithDelay(Scene.scenesMap.getKeyAt(sceneIndex), delay);
483
- }
484
-
485
- /**
486
- * Changes to the previous scene in the scnesList
487
- **/
488
- public static void prevSceneWithDelay(float delay){
489
- if(sceneIndex >= 0)
490
- sceneIndex--;
491
- setSceneWithDelay(Scene.scenesMap.getKeyAt(sceneIndex), delay);
492
- }
493
-
494
- /**
495
- * This loads the fonts for fps and logPane from the skin file. This is called by Asset once the
496
- * assets are done loading
497
- * */
498
- static void setup(){
499
- fpsLabel = new Label("", Asset.skin);
500
- fpsLabel.setName("Fps");
501
- }
502
-
503
- public static void addActor(Actor actor){
504
- if(actor != null)
505
- stage2d.addActor(actor);
506
- }
507
-
508
- public static void addActor(Actor actor, float x, float y){
509
- if(actor != null){
510
- actor.setPosition(x, y);
511
- stage2d.addActor(actor);
512
- }
513
- }
514
-
515
- public static void addActorWithDelay(final Actor actor, float delay){
516
- Timer.schedule(new Task(){
517
- @Override
518
- public void run() {
519
- addActor(actor);
520
- }
521
- }, delay);
522
- }
523
-
524
- /* If you want to make any elements/actors to move along with the camera
525
- * like HUD's add them using this method */
526
- public static void addHud(Actor actor){
527
- if(actor != null){
528
- addActor(actor);
529
- hudActors.add(actor);
530
- }
531
- }
532
-
533
- /* If you want to any elements/actors which was a Hud the use this */
534
- public static void removeHud(Actor actor){
535
- removeActor(actor);
536
- hudActors.removeValue(actor, false);
537
- }
538
-
539
- public static void clearAllHud(){
540
- hudActors.clear();
541
- }
542
-
543
- public static boolean removeActor(Actor actor){
544
- return stage2d.getRoot().removeActor(actor);
545
- }
546
-
547
- public static boolean removeActor(String actorName){
548
- return removeActor(findActor(actorName));
549
- }
550
-
551
- public static void removeActorWithDelay(Actor actor, float delay){
552
- addAction(Actions.sequence(Actions.delay(delay), Actions.removeActor(actor)));
553
- }
554
-
555
- public static void addAction(Action action) {
556
- stage2d.addAction(action);
557
- }
558
-
559
- public static void removeAction(Action action) {
560
- stage2d.getRoot().removeAction(action);
561
- }
562
-
563
- public static Actor findActor(String actorName){
564
- return stage2d.getRoot().findActor(actorName);
565
- }
566
-
567
- /*
568
- * This method makes sure the actor is not null and actors's name is not null
569
- * or actor is not root/fps/shape
570
- */
571
- public static boolean isValidActor(Actor actor){
572
- if(actor != null){
573
- String name = actor.getName();
574
- if(name != null){
575
- if(name.equals("Root") && name.equals("Fps") && name.equals("Shape")){
576
- return false;
577
- }
578
- else{
579
- return true;
580
- }
581
- }
582
- }
583
- return false;
584
- }
585
-
586
- public static SnapshotArray<Actor> getChildren(){
587
- return stage2d.getRoot().getChildren();
588
- }
589
-
590
- public static Actor hit(float x, float y){
591
- return stage2d.getRoot().hit(x, y, true);
592
- }
593
-
594
- public static void clear(){
595
- if(currentScene != null)
596
- currentScene.onDispose();
597
- usePan = false;
598
- followActor(null);
599
- hudActors.clear();
600
- resetCamera();
601
- stage2d.clear();
602
- }
603
-
604
- private static Image imgbg = null;
605
- public static void setBackground(String texName) {
606
- if(imgbg != null)
607
- removeBackground();
608
- if(Asset.tex(texName) != null){
609
- imgbg = new Image(new TextureRegionDrawable(Asset.tex(texName)), Scaling.stretch);
610
- imgbg.setFillParent(true);
611
- stage2d.addActor(imgbg);
612
- imgbg.toBack();
613
- }
614
- }
615
-
616
- public static void removeBackground() {
617
- stage2d.getRoot().removeActor(imgbg);
618
- }
619
-
620
- public static void showToast(String message, float duration){
621
- Table table = new Table(Asset.skin);
622
- table.add(" "+message+" ");
623
- table.setBackground(Asset.skin.getDrawable("dialogDim"));
624
- table.pack();
625
- table.setPosition(targetWidth/2 - table.getWidth(), targetHeight/2 - table.getHeight());
626
- addActor(table);
627
- table.addAction(Actions.sequence(Actions.delay(duration), Actions.removeActor(table)));
628
- }
629
-
630
- public static void showMessageDialog(String title, String message){
631
- Dialog dialog = new Dialog(title, Asset.skin);
632
- dialog.getContentTable().add(message);
633
- dialog.button("OK", "OK");
634
- dialog.pack();
635
- dialog.show(stage2d);
636
- }
637
-
638
- public static boolean showConfirmDialog(String title, String message){
639
- Dialog dialog = new Dialog(title, Asset.skin);
640
- dialog.button("Yes", "Yes");
641
- dialog.button("No", "No");
642
- dialog.pack();
643
- dialog.show(stage2d);
644
- //if(dialog.result().equals("Yes")) FIXME update Gdx
645
- // return true;
646
- return false;
647
- }
648
-
649
- /***********************************************************************************************************
650
- * Camera Related Functions *
651
- ************************************************************************************************************/
652
- private static float duration;
653
- private static float time;
654
- private static Interpolation interpolation;
655
- private static boolean moveCompleted;
656
- private static float lastPercent;
657
- private static float percentDelta;
658
- private static float panSpeedX, panSpeedY;
659
-
660
- public void moveTo(float x, float y) {
661
- moveTo(x, y, 0f);
662
- }
663
-
664
- public void moveTo(float x, float y, float duration) {
665
- moveBy(x-camera.position.x, y-camera.position.y, duration);
666
- }
667
-
668
- public static void moveBy (float amountX, float amountY) {
669
- moveBy(amountX, amountY, 0, null);
670
- }
671
-
672
- public static void moveBy (float amountX, float amountY, float duration) {
673
- moveBy(amountX, amountY, duration, null);
674
- }
675
-
676
- public static void moveBy (float amountX, float amountY, float dur, Interpolation interp) {
677
- duration = dur;
678
- interpolation = interp;
679
- panSpeedX = amountX;
680
- panSpeedY = amountY;
681
- lastPercent = 0;
682
- time = 0;
683
- moveCompleted = false;
684
- }
685
-
686
- private void moveByAction(float delta){
687
- time += delta;
688
- moveCompleted = time >= duration;
689
- float percent;
690
- if (moveCompleted)
691
- percent = 1;
692
- else {
693
- percent = time / duration;
694
- if (interpolation != null) percent = interpolation.apply(percent);
695
- }
696
- percentDelta = percent - lastPercent;
697
- camera.translate(panSpeedX * percentDelta, panSpeedY * percentDelta, 0);
698
- for(Actor actor: Stage.hudActors)
699
- actor.setPosition(actor.getX()+panSpeedX * percentDelta, actor.getY()+panSpeedY * percentDelta);
700
- lastPercent = percent;
701
- if (moveCompleted) interpolation = null;
702
- }
703
-
704
- public static void resetCamera(){
705
- camera.position.set(targetWidth/2, targetHeight/2, 0);
706
- }
707
-
708
- public static OrthographicCamera getCamera(){
709
- return camera;
710
- }
711
-
712
- public static float getCameraWidth(){
713
- return camera.viewportWidth;
714
- }
715
-
716
- public static float getCameraHeight(){
717
- return camera.viewportHeight;
718
- }
719
-
720
- public static float getCameraX(){
721
- return camera.position.x;
722
- }
723
-
724
- public static float getCameraY(){
725
- return camera.position.y;
726
- }
727
-
728
- private static Actor followedActor = null;
729
- private static float followSpeed = 1f;
730
- private static float followTopOffset = 60;
731
- private static float followLeftOffset = 10;
732
- private static float followBotOffset = 70;
733
- private static float followRightOffset = 10;
734
- private static boolean followContinous = false;
735
-
736
- /*
737
- * This makes the camera follow the actor once and only once. Once the camera reaches its
738
- * target, it stops following the actor.
739
- */
740
- public static void followActor(Actor actor){
741
- followedActor = actor;
742
- followContinous = false;
743
- }
744
-
745
- /*
746
- * This makes the camera follow the actor continuously, even after the camera reaches its
747
- * target, it keeps following the if the actor changes its position.
748
- */
749
- public static void followActorContinuously(Actor actor){
750
- followedActor = actor;
751
- followContinous = true;
752
- }
753
-
754
- /*
755
- * This is to set the offsets of camera position when following the actor
756
- * When the camera follows the actor its (x,y) position is set to actor's (x,y) position
757
- * based on followSpeed. The offsets are used to position the camera in such a way that the actor
758
- * doesn't need to be at the center of the camera always
759
- */
760
- public static void setFollowActorOffset(float top, float left, float bot, float right){
761
- followTopOffset = top;
762
- followLeftOffset = left;
763
- followBotOffset = bot;
764
- followRightOffset = right;
765
- }
766
-
767
- /*
768
- * Sets the speed at which the camera follows the actor. By default it moves 1px for a duration of 1f
769
- * so its speed is 1px/f. So reduce the duration to increase its speed.
770
- * ex: setPanSpeed(0.5) will change its speed to 2px/f
771
- * Here: f can/maybe also indicate seconds
772
- */
773
- public static void setFollowSpeed(float duration){
774
- followSpeed = duration;
775
- }
776
-
777
- private void follow(){
778
- //if(camera.position.x == followedActor.getX()+followLeftOffset &&
779
- // camera.position.y == followedActor.getY()+followTopOffset)
780
- //return;
781
- //moveTo(followedActor.getX()+followLeftOffset, followedActor.getY()+followTopOffset, 100f);
782
- if(camera.position.x < followedActor.getX() - followLeftOffset) moveBy(1f, 0, followSpeed);
783
- else if(camera.position.x > followedActor.getX() + followRightOffset) moveBy(-1f, 0, followSpeed);
784
- else if(camera.position.y < followedActor.getY() - followBotOffset) moveBy(0, 1f, followSpeed);
785
- else if(camera.position.y > followedActor.getY() - followTopOffset) moveBy(0, -1f, followSpeed);
786
- else {
787
- if(!followContinous)
788
- followedActor = null;
789
- }
790
- }
791
-
792
- private void updateController(){
793
- mouse.x = Gdx.input.getX();
794
- mouse.y = Gdx.graphics.getHeight() - Gdx.input.getY();
795
- if(!moveCompleted)
796
- moveByAction(stateTime);
797
- if(usePan)
798
- panCameraWithMouse();
799
- if(followedActor != null)
800
- follow();
801
- }
802
-
803
- /***********************************************************************************************************
804
- * 2d Controller Related Functions *
805
- ************************************************************************************************************/
806
- public static boolean usePan;
807
- private float panSpeed = 5f;
808
- private float panXLeftOffset = 100;
809
- private float panXRightOffset = 0;//Gdx.graphics.getWidth() - 100;
810
- private float panYUpOffset = 70;
811
- private float panYDownOffset = 0;//Gdx.graphics.getHeight() - 70;
812
- public static float camOffsetX = 160f;
813
- public static float camOffsetYTop = 110f;
814
- public static float camOffsetYBot = 65f;
815
- public static float mapOffsetX = 0;
816
- public static float mapOffsetY = 0;
817
-
818
-
819
- /*
820
- * Sets the speed at which the camera pans. By default it moves 1px for a duration a 1f
821
- * so its speed is 1px/f. So reduce the duration to increase its speed.
822
- * ex: setPanSpeed(0.5) will change its speed to 2px/f
823
- * Here: f can/maybe also indicate seconds
824
- */
825
- public void setPanSpeed(float duration){
826
- panSpeed = duration;
827
- }
828
-
829
- /*
830
- * This sets the boundary of the camera till what position can it move or pan in the
831
- * directions left, right, top, down. This is to prevent is from panning overboard the game area.
832
- * Usually the bounds of the camera is like a rectangle. This mus be calculated carefully
833
- * as the camera's position is based on its center.
834
- */
835
- public void setCameraBoundary(float xLeft, float xRight, float yUp, float dDown){
836
- panXLeftOffset = xLeft;
837
- panXRightOffset = xRight;
838
- panYUpOffset = yUp;
839
- panYDownOffset = dDown;
840
- }
841
-
842
- public void setCamOffset(float xOffset, float yOffsetTop, float yOffsetBot){
843
- camOffsetX = xOffset;
844
- camOffsetYTop = yOffsetTop;
845
- camOffsetYBot = yOffsetBot;
846
- }
847
-
848
- private void panCameraWithMouse(){
849
- if(mouse.x > panXRightOffset && camera.position.x < mapOffsetX - 5) moveBy(1f, 0, panSpeed);
850
- else if(mouse.x < panXLeftOffset && camera.position.x > camOffsetX +5) moveBy(-1f, 0, panSpeed);
851
- else if(mouse.y < panYUpOffset && camera.position.y < mapOffsetY -5) moveBy(0, 1f, panSpeed);
852
- else if(mouse.y > panYDownOffset && camera.position.y > camOffsetYBot +5) moveBy(0, -1f, panSpeed);
853
- }
854
-
855
- /*
856
- * Gesture related
857
- */
858
- public static float touchDragIntervalRange = 200f; // 200px drag for a gesture event
859
- public static float touchInitialX = 0.0f, touchInitialY = 0.0f;
860
- public static float touchCurrentX = 0.0f, touchCurrentY = 0.0f;
861
- public static float difX;
862
- public static float difY;
863
- public static float prevDifX;
864
- public static float prevDifY;
865
- public static float touchDifX;
866
- public static float touchDifY;
867
-
868
- public boolean isTouchDragInterval() {
869
- difX = java.lang.Math.abs(touchInitialX - touchCurrentX);
870
- difY = java.lang.Math.abs(touchInitialY - touchCurrentY);
871
- if (difX > touchDragIntervalRange || difY > touchDragIntervalRange)
872
- return true;
873
- else
874
- return false;
875
- }
876
-
877
- public static GestureType getGestureDirection() {
878
- prevDifX = difX;
879
- prevDifY = difY;
880
- difX = java.lang.Math.abs(touchInitialX - touchCurrentX);
881
- difY = java.lang.Math.abs(touchInitialY - touchCurrentY);
882
- /**
883
- * Get minimal changes on drag
884
- * <p> checkMomentumChanges
885
- * EXAMPLE<br>
886
- * User drags finger to left, suddenly dragging to right without removing
887
- * his finger from the screen
888
- * */
889
- if (prevDifX > difX || prevDifY > difY) {
890
- touchInitialX = touchCurrentX;
891
- touchInitialY = touchCurrentY;
892
- //
893
- difX = 0.0f;
894
- difY = 0.0f;
895
- prevDifX = 0.0f;
896
- prevDifY = 0.0f;
897
-
898
- /**
899
- * Set touch differences, optional, if you need amount of change from
900
- * initial touch to drag, USE THIS: on touchDrag, pan or similar mthods
901
- * */
902
- touchDifX = java.lang.Math.abs(touchInitialX - touchCurrentX);
903
- touchDifY = java.lang.Math.abs(touchInitialY - touchCurrentY);
904
- }
905
- if (touchInitialY < touchCurrentY && difY > difX) {
906
- return GestureType.Up;
907
- } else if (touchInitialY > touchCurrentY && difY > difX) {
908
- return GestureType.Down;
909
- } else if (touchInitialX < touchCurrentX && difY < difX) {
910
- return GestureType.Right;
911
- } else if (touchInitialX > touchCurrentX && difY < difX) {
912
- return GestureType.Left;
913
- } else {
914
- return GestureType.None;
915
- }
916
- }
917
-
918
- /* Dragging Camera Related */
919
- private final static Vector3 curr = new Vector3();
920
- private final static Vector3 last = new Vector3(-1, -1, -1);
921
- private final static Vector3 deltaDrag = new Vector3();
922
- private static float deltaCamX = 0;
923
- private static float deltaCamY = 0;
924
-
925
- private static void dragCam(int x, int y){
926
- camera.unproject(curr.set(x, y, 0));
927
- if (!(last.x == -1 && last.y == -1 && last.z == -1)) {
928
- camera.unproject(deltaDrag.set(last.x, last.y, 0));
929
- deltaDrag.sub(curr);
930
- deltaCamX = deltaDrag.x + camera.position.x;
931
- deltaCamY = deltaDrag.y + camera.position.y;
932
- if(deltaCamX > camOffsetX && deltaCamX < mapOffsetX)
933
- moveBy(deltaDrag.x, 0);
934
- if(deltaCamY > camOffsetYBot && deltaCamY < mapOffsetY)
935
- moveBy(0, deltaDrag.y);
936
- }
937
- last.set(x, y, 0);
938
- }
939
-
940
- static boolean gestureStarted = false;
941
- static Actor validActor = null;
942
- private final static ClickListener touchInput = new ClickListener(){
943
- @Override
944
- public void clicked(InputEvent event, float x, float y){
945
- super.clicked(event, x, y);
946
- mouse.set(x, y);
947
- validActor = hit(x,y);
948
- if(isValidActor(validActor))
949
- currentScene.onClick(validActor);
950
- }
951
-
952
- @Override
953
- public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
954
- mouse.set(x, y);
955
- Stage.pointer = pointer;
956
- Stage.button = button;
957
- touchInitialX = x;
958
- touchInitialY = y;
959
- gestureStarted = true;
960
- validActor = hit(x,y);
961
- if(isValidActor(validActor))
962
- currentScene.onTouchDown(validActor);
963
- return super.touchDown(event, x, y, pointer, button);
964
- }
965
-
966
-
967
- @Override
968
- public void touchDragged(InputEvent event, float x, float y, int pointer){
969
- super.touchDragged(event, x, y, pointer);
970
- mouse.set(x, y);
971
- Stage.pointer = pointer;
972
- currentScene.onDragged();
973
- if(gestureStarted == true){
974
- touchCurrentX = x;
975
- touchCurrentY = y;
976
- if(getGestureDirection() != GestureType.None){
977
- gestureStarted = false;
978
- currentScene.onGesture(getGestureDirection());
979
- }
980
- }
981
- if(Config.useDrag)
982
- dragCam((int)x, (int)-y);
983
- }
984
-
985
- @Override
986
- public void touchUp(InputEvent event, float x, float y, int pointer, int button){
987
- super.touchUp(event, x, y, pointer, button);
988
- mouse.set(x, y);
989
- Stage.pointer = pointer;
990
- Stage.button = button;
991
- // reset Gesture
992
- difX = 0.0f;
993
- difY = 0.0f;
994
- touchInitialX = 0.0f;
995
- touchInitialY = 0.0f;
996
- touchCurrentX = 0.0f;
997
- touchCurrentY = 0.0f;
998
- touchDifX = 0.0f;
999
- touchDifY = 0.0f;
1000
- prevDifX = 0.0f;
1001
- prevDifY = 0.0f;
1002
- // reset Gesture
1003
- currentScene.onTouchUp();
1004
- last.set(-1, -1, -1);
1005
- gestureStarted = false;
1006
- }
1007
-
1008
- @Override
1009
- public boolean keyTyped(InputEvent event, char key) {
1010
- currentScene.onKeyTyped(key);
1011
- return super.keyUp(event, key);
1012
- }
1013
-
1014
- @Override
1015
- public boolean keyUp(InputEvent event, int keycode) {
1016
- currentScene.onKeyUp(keycode);
1017
- return super.keyUp(event, keycode);
1018
- }
1019
- @Override
1020
- public boolean keyDown(InputEvent event, int keycode) {
1021
- currentScene.onKeyDown(keycode);
1022
- return super.keyDown(event, keycode);
1023
- }
1024
- };
1025
-
1026
- /***********************************************************************************************************
1027
- * 3d Related Functions *
1028
- ************************************************************************************************************/
1029
-
1030
- public static void addActor3d(Actor3d actor3d){
1031
- stage3d.addActor3d(actor3d);
1032
- }
1033
-
1034
- public static void removeActor3d(Actor3d actor3d){
1035
- stage3d.getRoot().removeActor3d(actor3d);
1036
- }
1037
-
1038
- public static void clear3d(){
1039
- stage3d.clear();
1040
- }
1041
-
1042
- public static void getChildren3d(){
1043
- stage3d.getActors3d();
1044
- }
1045
-
1046
- public static void removeActor3d(String actor3dName){
1047
- stage3d.getRoot().removeActor3d(stage3d.getRoot().findActor3d(actor3dName));
1048
- }
1049
-
1050
- public static void resetCamera3d(){
1051
- stage3d.getCamera().position.set(10f, 10f, 10f);
1052
- stage3d.getCamera().lookAt(0,0,0);
1053
- stage3d.getCamera().near = 0.1f;
1054
- stage3d.getCamera().far = 300f;
1055
- }
1056
-
1057
- public static PerspectiveCamera getCamera3d(){
1058
- return stage3d.getCamera();
1059
- }
1060
-
1061
- /***********************************************************************************************************
1062
- * Utilities Related Functions *
1063
- ************************************************************************************************************/
1064
-
1065
- /*
1066
- * The the angle in degrees of the inclination of a line
1067
- * @param cx, cy The center point x, y
1068
- * @param tx, ty The target point x, y
1069
- */
1070
- public static float getAngle(float cx, float cy, float tx, float ty) {
1071
- float angle = (float) Math.toDegrees(MathUtils.atan2(tx - cx, ty - cy));
1072
- //if(angle < 0){
1073
- // angle += 360;
1074
- //}
1075
- return angle;
1076
- }
1077
-
1078
- private static Vector2 distVector = new Vector2();
1079
- public static final float getDistance(Actor a, Actor b){
1080
- distVector.set(a.getX(), a.getY());
1081
- return distVector.dst(b.getX(), b.getY());
1082
- }
1083
-
1084
- public static final float getDistance(float x1, float y1, float x2, float y2){
1085
- distVector.set(x1, y1);
1086
- return distVector.dst(x2, y2);
1087
- }
1088
-
1089
- /*
1090
- * Capitalizes the First Letter of a String
1091
- */
1092
- public static String capitalize(String text){
1093
- if(text != null && text != "")
1094
- return (text.substring(0, 1)).toUpperCase() + text.substring(1);
1095
- else
1096
- return "";
1097
- }
1098
-
1099
- /*
1100
- * UnCapitalizes the First Letter of a String
1101
- */
1102
- public static String uncapitalize(String text){
1103
- return text.substring(0, 1).toLowerCase()+text.substring(1);
1104
- }
1105
-
1106
- public static Rectangle getBounds(Actor actor) {
1107
- float posX = actor.getX();
1108
- float posY = actor.getY();
1109
- float width = actor.getWidth();
1110
- float height = actor.getHeight();
1111
- return new Rectangle(posX, posY, width, height);
1112
- }
1113
-
1114
- public static boolean collides(Actor actor, float x, float y) {
1115
- Rectangle rectA1 = getBounds(actor);
1116
- Rectangle rectA2 = new Rectangle(x, y, 5, 5);
1117
- // Check if rectangles collides
1118
- if (Intersector.overlaps(rectA1, rectA2)) {
1119
- return true;
1120
- } else {
1121
- return false;
1122
- }
1123
- }
1124
-
1125
- public static boolean collides(Actor actor1, Actor actor2) {
1126
- Rectangle rectA1 = getBounds(actor1);
1127
- Rectangle rectA2 = getBounds(actor2);
1128
- // Check if rectangles collides
1129
- if (Intersector.overlaps(rectA1, rectA2)) {
1130
- return true;
1131
- } else {
1132
- return false;
1133
- }
1134
- }
1135
-
1136
- /*
1137
- * TEA Encryption and Decryption
1138
- */
1139
- public static String encryptKey = "Default";
1140
- private static final int encryptDelta = 0x9E3779B9;
1141
- private static final int MX(int sum, int y, int z, int p, int e, int[] k) {
1142
- return (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
1143
- }
1144
-
1145
- public static final byte[] encrypt(String data) {
1146
- return encrypt(data.getBytes(), encryptKey.getBytes());
1147
- }
1148
-
1149
- public static final byte[] decrypt(String data) {
1150
- return decrypt(data.getBytes(), encryptKey.getBytes());
1151
- }
1152
-
1153
- public static final byte[] encrypt(String data, String key) {
1154
- return encrypt(data.getBytes(), key.getBytes());
1155
- }
1156
-
1157
- public static final byte[] decrypt(String data, String key) {
1158
- return decrypt(data.getBytes(), key.getBytes());
1159
- }
1160
-
1161
- private static final byte[] encrypt(byte[] data, byte[] key) {
1162
- if (data.length == 0)
1163
- return data;
1164
- return toByteArray(encrypt(toIntArray(data, true), toIntArray(key, false)), false);
1165
- }
1166
-
1167
-
1168
- private static final byte[] decrypt(byte[] data, byte[] key) {
1169
- if (data.length == 0)
1170
- return data;
1171
- return toByteArray(decrypt(toIntArray(data, false), toIntArray(key, false)), true);
1172
- }
1173
-
1174
- private static final int[] encrypt(int[] v, int[] k) {
1175
- int n = v.length - 1;
1176
- if (n < 1) {
1177
- return v;
1178
- }
1179
- if (k.length < 4) {
1180
- int[] key = new int[4];
1181
-
1182
- System.arraycopy(k, 0, key, 0, k.length);
1183
- k = key;
1184
- }
1185
- int z = v[n], y = v[0], sum = 0, e;
1186
- int p, q = 6 + 52 / (n + 1);
1187
-
1188
- while (q-- > 0) {
1189
- sum = sum + encryptDelta;
1190
- e = sum >>> 2 & 3;
1191
- for (p = 0; p < n; p++) {
1192
- y = v[p + 1];
1193
- z = v[p] += MX(sum, y, z, p, e, k);
1194
- }
1195
- y = v[0];
1196
- z = v[n] += MX(sum, y, z, p, e, k);
1197
- }
1198
- return v;
1199
- }
1200
-
1201
- private static final int[] decrypt(int[] v, int[] k) {
1202
- int n = v.length - 1;
1203
-
1204
- if (n < 1) {
1205
- return v;
1206
- }
1207
- if (k.length < 4) {
1208
- int[] key = new int[4];
1209
-
1210
- System.arraycopy(k, 0, key, 0, k.length);
1211
- k = key;
1212
- }
1213
- int z = v[n], y = v[0], sum, e;
1214
- int p, q = 6 + 52 / (n + 1);
1215
-
1216
- sum = q * encryptDelta;
1217
- while (sum != 0) {
1218
- e = sum >>> 2 & 3;
1219
- for (p = n; p > 0; p--) {
1220
- z = v[p - 1];
1221
- y = v[p] -= MX(sum, y, z, p, e, k);
1222
- }
1223
- z = v[n];
1224
- y = v[0] -= MX(sum, y, z, p, e, k);
1225
- sum = sum - encryptDelta;
1226
- }
1227
- return v;
1228
- }
1229
-
1230
-
1231
- private static final int[] toIntArray(byte[] data, boolean includeLength) {
1232
- int n = (((data.length & 3) == 0)
1233
- ? (data.length >>> 2)
1234
- : ((data.length >>> 2) + 1));
1235
- int[] result;
1236
-
1237
- if (includeLength) {
1238
- result = new int[n + 1];
1239
- result[n] = data.length;
1240
- }
1241
- else {
1242
- result = new int[n];
1243
- }
1244
- n = data.length;
1245
- for (int i = 0; i < n; i++) {
1246
- result[i >>> 2] |= (0x000000ff & data[i]) << ((i & 3) << 3);
1247
- }
1248
- return result;
1249
- }
1250
-
1251
-
1252
- private static final byte[] toByteArray(int[] data, boolean includeLength) {
1253
- int n = data.length << 2;
1254
-
1255
- if (includeLength) {
1256
- int m = data[data.length - 1];
1257
-
1258
- if (m > n) {
1259
- return null;
1260
- }
1261
- else {
1262
- n = m;
1263
- }
1264
- }
1265
- byte[] result = new byte[n];
1266
-
1267
- for (int i = 0; i < n; i++) {
1268
- result[i] = (byte) ((data[i >>> 2] >>> ((i & 3) << 3)) & 0xff);
1269
- }
1270
- return result;
1271
- }
1272
- }
Stage/Stage3d.java DELETED
@@ -1,488 +0,0 @@
1
- import com.badlogic.gdx.Gdx;
2
- import com.badlogic.gdx.InputAdapter;
3
- import com.badlogic.gdx.graphics.Camera;
4
- import com.badlogic.gdx.graphics.PerspectiveCamera;
5
- import com.badlogic.gdx.graphics.g3d.Environment;
6
- import com.badlogic.gdx.graphics.g3d.ModelBatch;
7
- import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
8
- import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
9
- import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
10
- import com.badlogic.gdx.math.Vector3;
11
- import com.badlogic.gdx.scenes.scene2d.Group;
12
- import com.badlogic.gdx.utils.Array;
13
- import com.badlogic.gdx.utils.Disposable;
14
- import com.badlogic.gdx.utils.Pool.Poolable;
15
-
16
- public class Stage3d extends InputAdapter implements Disposable {
17
- private float width, height;
18
- private ModelBatch modelBatch;
19
- private Environment environment;
20
-
21
- public ModelBuilder modelBuilder;
22
-
23
- private PerspectiveCamera camera;
24
- private Group3d root;
25
- private Actor3d scrollFocus;
26
- private Actor3d keyboardFocus;
27
-
28
- /** Creates a stage with a {@link #setViewport(float, float, boolean) viewport} equal to the device screen resolution. The stage
29
- * will use its own {@link SpriteBatch}. */
30
- public Stage3d () {
31
- this(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
32
- }
33
-
34
- /** Creates a stage with the specified {@link #setViewport(float, float, boolean) viewport} that doesn't keep the aspect ratio.
35
- * The stage will use its own {@link SpriteBatch}, which will be disposed when the stage is disposed. */
36
- public Stage3d (float width, float height) {
37
- this(width, height, false);
38
- }
39
-
40
- /** Creates a stage with the specified {@link #setViewport(float, float, boolean) viewport}. The stage will use its own
41
- * {@link SpriteBatch}, which will be disposed when the stage is disposed. */
42
- public Stage3d (float width, float height, boolean keepAspectRatio) {
43
- this.width = width;
44
- this.height = height;
45
-
46
- root = new Group3d();
47
- root.setStage3d(this);
48
-
49
- modelBatch = new ModelBatch();
50
-
51
- camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
52
- camera.position.set(10f, 10f, 10f);
53
- camera.lookAt(0,0,0);
54
- camera.near = 0.1f;
55
- camera.far = 300f;
56
- camera.update();
57
- environment = new Environment();
58
- environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
59
- environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
60
-
61
- setViewport(width, height, keepAspectRatio);
62
- modelBuilder = new ModelBuilder();
63
- }
64
-
65
- /** Sets up the stage size using a viewport that fills the entire screen without keeping the aspect ratio.
66
- * @see #setViewport(float, float, boolean, float, float, float, float) */
67
- public void setViewport (float width, float height) {
68
- setViewport(width, height, false, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
69
- }
70
-
71
- /** Sets up the stage size using a viewport that fills the entire screen.
72
- * @see #setViewport(float, float, boolean, float, float, float, float) */
73
- public void setViewport (float width, float height, boolean keepAspectRatio) {
74
- setViewport(width, height, keepAspectRatio, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
75
- }
76
-
77
- /** Sets up the stage size and viewport. The viewport is the glViewport position and size, which is the portion of the screen
78
- * used by the stage. The stage size determines the units used within the stage, depending on keepAspectRatio:
79
- * <p>
80
- * If keepAspectRatio is false, the stage is stretched to fill the viewport, which may distort the aspect ratio.
81
- * <p>
82
- * If keepAspectRatio is true, the stage is first scaled to fit the viewport in the longest dimension. Next the shorter
83
- * dimension is lengthened to fill the viewport, which keeps the aspect ratio from changing. The {@link #getGutterWidth()} and
84
- * {@link #getGutterHeight()} provide access to the amount that was lengthened.
85
- * @param viewportX The top left corner of the viewport in glViewport coordinates (the origin is bottom left).
86
- * @param viewportY The top left corner of the viewport in glViewport coordinates (the origin is bottom left).
87
- * @param viewportWidth The width of the viewport in pixels.
88
- * @param viewportHeight The height of the viewport in pixels. */
89
- public void setViewport (float stageWidth, float stageHeight, boolean keepAspectRatio, float viewportX, float viewportY,
90
- float viewportWidth, float viewportHeight) {
91
- if (keepAspectRatio) {
92
- if (viewportHeight / viewportWidth < stageHeight / stageWidth) {
93
- float toViewportSpace = viewportHeight / stageHeight;
94
- float toStageSpace = stageHeight / viewportHeight;
95
- float deviceWidth = stageWidth * toViewportSpace;
96
- float lengthen = (viewportWidth - deviceWidth) * toStageSpace;
97
- this.width = stageWidth + lengthen;
98
- this.height = stageHeight;
99
- } else {
100
- float toViewportSpace = viewportWidth / stageWidth;
101
- float toStageSpace = stageWidth / viewportWidth;
102
- float deviceHeight = stageHeight * toViewportSpace;
103
- float lengthen = (viewportHeight - deviceHeight) * toStageSpace;
104
- this.height = stageHeight + lengthen;
105
- this.width = stageWidth;
106
- }
107
- } else {
108
- this.width = stageWidth;
109
- this.height = stageHeight;
110
- }
111
-
112
- camera.viewportWidth = this.width;
113
- camera.viewportHeight = this.height;
114
- }
115
-
116
- public void draw(){
117
- camera.update();
118
- if (!root.isVisible()) return;
119
- modelBatch.begin(camera);
120
- root.drawChildren(modelBatch, environment);
121
- modelBatch.end();
122
- }
123
-
124
- /** Calls {@link #act(float)} with {@link Graphics#getDeltaTime()}. */
125
- public void act () {
126
- act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
127
- }
128
-
129
- /** Calls the {@link Actor#act(float)} method on each actor in the stage. Typically called each frame. This method also fires
130
- * enter and exit events.
131
- * @param delta Time in seconds since the last frame. */
132
- public void act(float delta) {
133
- root.act(delta);
134
- }
135
-
136
- /** Adds an actor to the root of the stage.
137
- * @see Group#addActor(Actor)
138
- * @see Actor#remove() */
139
- public void addActor3d(Actor3d actor3d) {
140
- root.addActor3d(actor3d);
141
- }
142
-
143
- /** Adds an action to the root of the stage.
144
- * @see Group#addAction3d(Action) */
145
- public void addAction3d(Action3d action3d) {
146
- root.addAction3d(action3d);
147
- }
148
-
149
- /** Returns the root's child actors.
150
- * @see Group#getChildren() */
151
- public Array<Actor3d> getActors3d() {
152
- return root.getChildren();
153
- }
154
-
155
- /** Adds a listener to the root.
156
- * @see Actor#addListener(EventListener) */
157
- public boolean addListener (Event3dListener listener) {
158
- return root.addListener(listener);
159
- }
160
-
161
- /** Removes a listener from the root.
162
- * @see Actor#removeListener(EventListener) */
163
- public boolean removeListener (Event3dListener listener) {
164
- return root.removeListener(listener);
165
- }
166
-
167
- /** Removes the root's children, actions, and listeners. */
168
- public void clear () {
169
- unfocusAll();
170
- root.clear();
171
- }
172
-
173
- /** Removes the touch, keyboard, and scroll focused actors. */
174
- public void unfocusAll () {
175
- scrollFocus = null;
176
- keyboardFocus = null;
177
- //cancelTouchFocus();
178
- }
179
-
180
- /** Removes the touch, keyboard, and scroll focus for the specified actor and any descendants. */
181
- public void unfocus(Actor3d actor) {
182
- if (scrollFocus != null && scrollFocus.isDescendantOf(actor)) scrollFocus = null;
183
- if (keyboardFocus != null && keyboardFocus.isDescendantOf(actor)) keyboardFocus = null;
184
- }
185
-
186
- /** Sets the actor that will receive key events.
187
- * @param actor May be null. */
188
- public void setKeyboardFocus (Actor3d actor) {
189
- if (keyboardFocus == actor) return;
190
- }
191
-
192
- /** Gets the actor that will receive key events.
193
- * @return May be null. */
194
- public Actor3d getKeyboardFocus () {
195
- return keyboardFocus;
196
- }
197
-
198
- /** Sets the actor that will receive scroll events.
199
- * @param actor May be null. */
200
- public void setScrollFocus(Actor3d actor) {
201
- if (scrollFocus == actor) return;
202
- }
203
-
204
- /** Gets the actor that will receive scroll events.
205
- * @return May be null. */
206
- public Actor3d getScrollFocus () {
207
- return scrollFocus;
208
- }
209
-
210
- public ModelBatch getModelBatch () {
211
- return modelBatch;
212
- }
213
-
214
- public PerspectiveCamera getCamera () {
215
- return camera;
216
- }
217
-
218
- /** Sets the stage's camera. The camera must be configured properly or {@link #setViewport(float, float, boolean)} can be called
219
- * after the camera is set. {@link Stage#draw()} will call {@link Camera#update()} and use the {@link Camera#combined} matrix
220
- * for the SpriteBatch {@link SpriteBatch#setProjectionMatrix(com.badlogic.gdx.math.Matrix4) projection matrix}. */
221
- public void setCamera (PerspectiveCamera camera) {
222
- this.camera = camera;
223
- }
224
-
225
- /** Returns the root group which holds all actors in the stage. */
226
- public Group3d getRoot () {
227
- return root;
228
- }
229
-
230
- public Environment getEnvironment(){
231
- return environment;
232
- }
233
-
234
- @Override
235
- public void dispose() {
236
- clear();
237
- modelBatch.dispose();
238
- }
239
- }
240
-
241
- class Event3d implements Poolable {
242
- private Stage3d stage;
243
- private Actor3d targetActor;
244
- private Actor3d listenerActor;
245
- private boolean capture; // true means event occurred during the capture phase
246
- private boolean bubbles = true; // true means propagate to target's parents
247
- private boolean handled; // true means the event was handled (the stage will eat the input)
248
- private boolean stopped; // true means event propagation was stopped
249
- private boolean cancelled; // true means propagation was stopped and any action that this event would cause should not happen
250
-
251
- /** Marks this event as handled. This does not affect event propagation inside scene2d, but causes the {@link Stage}
252
- * event methods to return false, which will eat the event so it is not passed on to the application under the stage. */
253
- public void handle () {
254
- handled = true;
255
- }
256
-
257
- /** Marks this event cancelled. This {@link #handle() handles} the event and {@link #stop() stops} the event
258
- * propagation. It also cancels any default action that would have been taken by the code that fired the event. Eg, if the
259
- * event is for a checkbox being checked, cancelling the event could uncheck the checkbox. */
260
- public void cancel () {
261
- cancelled = true;
262
- stopped = true;
263
- handled = true;
264
- }
265
-
266
- /** Marks this event has being stopped. This halts event propagation. Any other listeners on the {@link #getListenerActor()
267
- * listener actor} are notified, but after that no other listeners are notified. */
268
- public void stop () {
269
- stopped = true;
270
- }
271
-
272
- public void reset () {
273
- stage = null;
274
- targetActor = null;
275
- listenerActor = null;
276
- capture = false;
277
- bubbles = true;
278
- handled = false;
279
- stopped = false;
280
- cancelled = false;
281
- }
282
-
283
- /** Returns the actor that the event originated from. */
284
- public Actor3d getTarget () {
285
- return targetActor;
286
- }
287
-
288
- public void setTarget (Actor3d targetActor) {
289
- this.targetActor = targetActor;
290
- }
291
-
292
- /** Returns the actor that this listener is attached to. */
293
- public Actor3d getListenerActor () {
294
- return listenerActor;
295
- }
296
-
297
- public void setListenerActor (Actor3d listenerActor) {
298
- this.listenerActor = listenerActor;
299
- }
300
-
301
- public boolean getBubbles () {
302
- return bubbles;
303
- }
304
-
305
- /** If true, after the event is fired on the target actor, it will also be fired on each of the parent actors, all the way to
306
- * the root. */
307
- public void setBubbles (boolean bubbles) {
308
- this.bubbles = bubbles;
309
- }
310
-
311
- /** {@link #handle()} */
312
- public boolean isHandled () {
313
- return handled;
314
- }
315
-
316
- /** @see #stop() */
317
- public boolean isStopped () {
318
- return stopped;
319
- }
320
-
321
- /** @see #cancel() */
322
- public boolean isCancelled () {
323
- return cancelled;
324
- }
325
-
326
- public void setCapture (boolean capture) {
327
- this.capture = capture;
328
- }
329
-
330
- /** If true, the event was fired during the capture phase.
331
- * @see Actor#fire(Event) */
332
- public boolean isCapture () {
333
- return capture;
334
- }
335
-
336
- public void setStage (Stage3d stage) {
337
- this.stage = stage;
338
- }
339
-
340
- /** The stage for the actor the event was fired on. */
341
- public Stage3d getStage () {
342
- return stage;
343
- }
344
- }
345
-
346
- interface Event3dListener {
347
- public boolean handle (Event3d event);
348
- }
349
-
350
- class InputEvent3d extends Event3d {
351
- private Type type;
352
- private float stageX, stageY, stageZ;
353
- private int pointer, button, keyCode, scrollAmount;
354
- private char character;
355
- private Actor3d relatedActor;
356
-
357
- public void reset () {
358
- super.reset();
359
- relatedActor = null;
360
- button = -1;
361
- }
362
-
363
- /** The stage x coordinate where the event occurred. Valid for: touchDown, touchDragged, touchUp, mouseMoved, enter, and exit. */
364
- public float getStageX () {
365
- return stageX;
366
- }
367
-
368
- public void setStageX (float stageX) {
369
- this.stageX = stageX;
370
- }
371
-
372
- /** The stage x coordinate where the event occurred. Valid for: touchDown, touchDragged, touchUp, mouseMoved, enter, and exit. */
373
- public float getStageY () {
374
- return stageY;
375
- }
376
-
377
- public void setStageY (float stageY) {
378
- this.stageY = stageY;
379
- }
380
-
381
- /** The type of input event. */
382
- public Type getType () {
383
- return type;
384
- }
385
-
386
- public void setType (Type type) {
387
- this.type = type;
388
- }
389
-
390
- /** The pointer index for the event. The first touch is index 0, second touch is index 1, etc. Always -1 on desktop. Valid for:
391
- * touchDown, touchDragged, touchUp, enter, and exit. */
392
- public int getPointer () {
393
- return pointer;
394
- }
395
-
396
- public void setPointer (int pointer) {
397
- this.pointer = pointer;
398
- }
399
-
400
- /** The index for the mouse button pressed. Always 0 on Android. Valid for: touchDown and touchUp.
401
- * @see Buttons */
402
- public int getButton () {
403
- return button;
404
- }
405
-
406
- public void setButton (int button) {
407
- this.button = button;
408
- }
409
-
410
- /** The key code of the key that was pressed. Valid for: keyDown and keyUp. */
411
- public int getKeyCode () {
412
- return keyCode;
413
- }
414
-
415
- public void setKeyCode (int keyCode) {
416
- this.keyCode = keyCode;
417
- }
418
-
419
- /** The character for the key that was type. Valid for: keyTyped. */
420
- public char getCharacter () {
421
- return character;
422
- }
423
-
424
- public void setCharacter (char character) {
425
- this.character = character;
426
- }
427
-
428
- /** The amount the mouse was scrolled. Valid for: scrolled. */
429
- public int getScrollAmount () {
430
- return scrollAmount;
431
- }
432
-
433
- public void setScrollAmount (int scrollAmount) {
434
- this.scrollAmount = scrollAmount;
435
- }
436
-
437
- /** The actor related to the event. Valid for: enter and exit. For enter, this is the actor being exited, or null. For exit,
438
- * this is the actor being entered, or null. */
439
- public Actor3d getRelatedActor () {
440
- return relatedActor;
441
- }
442
-
443
- /** @param relatedActor May be null. */
444
- public void setRelatedActor (Actor3d relatedActor) {
445
- this.relatedActor = relatedActor;
446
- }
447
-
448
- /** Sets actorCoords to this event's coordinates relative to the specified actor.
449
- * @param actorCoords Output for resulting coordinates. */
450
- public Vector3 toCoordinates (Actor3d actor, Vector3 actorCoords) {
451
- actorCoords.set(stageX, stageY, stageZ);
452
- //actor.stageToLocalCoordinates(actorCoords);
453
- return actorCoords;
454
- }
455
-
456
- /** Returns true of this event is a touchUp triggered by {@link Stage#cancelTouchFocus()}. */
457
- public boolean isTouchFocusCancel () {
458
- return stageX == Integer.MIN_VALUE || stageY == Integer.MIN_VALUE;
459
- }
460
-
461
- public String toString () {
462
- return type.toString();
463
- }
464
-
465
- /** Types of low-level input events supported by stage2d. */
466
- static public enum Type {
467
- /** A new touch for a pointer on the stage was detected */
468
- touchDown,
469
- /** A pointer has stopped touching the stage. */
470
- touchUp,
471
- /** A pointer that is touching the stage has moved. */
472
- touchDragged,
473
- /** The mouse pointer has moved (without a mouse button being active). */
474
- mouseMoved,
475
- /** The mouse pointer or an active touch have entered (i.e., {@link Actor#hit(float, float, boolean) hit}) an actor. */
476
- enter,
477
- /** The mouse pointer or an active touch have exited an actor. */
478
- exit,
479
- /** The mouse scroll wheel has changed. */
480
- scrolled,
481
- /** A keyboard key has been pressed. */
482
- keyDown,
483
- /** A keyboard key has been released. */
484
- keyUp,
485
- /** A keyboard key has been pressed and released. */
486
- keyTyped
487
- }
488
- }
Type/EffectType.java DELETED
@@ -1,10 +0,0 @@
1
- public enum EffectType {
2
- None,
3
- ScaleInOut, ScaleInOutLooping, ScaleInOutRemoveActor,
4
- ShakeInOut, ShakeInOutLooping, ShakeInOutRemoveActor,
5
- FadeInOut, FadeInOutLooping, FadeInOutRemoveActor,
6
- FadeOutIn, FadeOutInLooping, FadeOutInRemoveActor,
7
- ScaleToThenFadeOut, ScaleAndFadeOut, ScaleAndFadeIn,
8
- PatrolX, PatrolY;
9
-
10
- }
Type/GestureType.java DELETED
@@ -1,19 +0,0 @@
1
- /*******************************************************************************
2
- * Copyright 2013 pyros2097
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- ******************************************************************************/
16
-
17
- public enum GestureType {
18
- None, Up, Down, Left, Right
19
- }
Type/MovedListener.java DELETED
@@ -1,3 +0,0 @@
1
- public interface MovedListener {
2
- public void onMoved();
3
- }
Type/OnEventType.java DELETED
@@ -1,5 +0,0 @@
1
-
2
- public enum OnEventType {
3
- DoEffect,
4
- SetScene
5
- }
Type/TransitionType.java DELETED
@@ -1,3 +0,0 @@
1
- public enum TransitionType {
2
- None, leftToRight, rightToLeft, upToDown, downToUp ,FadeIn, FadeOut, ScaleIn, ScaleOut
3
- }
icon/background.png DELETED
Binary file
icon/style.png DELETED
Binary file
shots/shot1.png ADDED
Binary file
shots/shot2.png ADDED
Binary file
shots/shot3.png ADDED
Binary file
shots/shot4.png ADDED
Binary file
shots/shot5.png ADDED
Binary file
shots/shot6.png ADDED
Binary file
{IDE → src/gdxstudio}/Content.java RENAMED
@@ -1,3 +1,10 @@
1
+ package gdxstudio;
2
+ import gdxstudio.panel.AssetPanel;
3
+ import gdxstudio.panel.ConsolePanel;
4
+ import gdxstudio.panel.ReplacePanel;
5
+ import gdxstudio.panel.StudioPanel;
6
+ import gdxstudio.panel.WidgetPanel;
7
+
1
8
  import java.awt.BorderLayout;
2
9
  import java.awt.CardLayout;
3
10
  import java.awt.Insets;
@@ -30,19 +37,12 @@ final public class Content extends JPanel {
30
37
  public static StudioPanel studioPanel;
31
38
  private static ReplacePanel replacePanel;
32
39
  public static AssetPanel assetPanel;
40
+ public static WidgetPanel widgetPanel;
33
41
  private static ConsolePanel consolePanel;
34
42
 
35
- private static String sceneFile = null;
36
- private static Register sceneRegister;
37
-
38
- private static Register viewRegister;
39
-
40
43
  public static void initProjects(){
41
44
  projectRegister = new Register(105);
42
45
  projectFile = Register.getString(projectRegister);
43
- sceneRegister = new Register(107);
44
- sceneFile = Register.getString(sceneRegister);
45
- viewRegister = new Register(109);
46
46
  }
47
47
 
48
48
  public Content(){
@@ -72,6 +72,10 @@ final public class Content extends JPanel {
72
72
  assetPanel = new AssetPanel();
73
73
  consolePanel = new ConsolePanel();
74
74
  assetPanel.setVisible(false);
75
+ widgetPanel = new WidgetPanel();
76
+ widgetPanel.setVisible(false);
77
+
78
+ vert.add(widgetPanel);
75
79
  vert.add(assetPanel);
76
80
  vert.add(consolePanel);
77
81
  add(vert, BorderLayout.SOUTH);
@@ -134,12 +138,15 @@ final public class Content extends JPanel {
134
138
  consolePanel.setVisible(!consolePanel.isVisible());
135
139
  }
136
140
 
141
+ public static void toggleWidget(){
142
+ widgetPanel.setVisible(!widgetPanel.isVisible());
143
+ }
144
+
137
145
  private static void showContent(String contentName){
138
146
  if(currentView.equals(contentName))
139
147
  return;
140
148
  ((CardLayout) card.getLayout()).show(card, contentName);
141
149
  currentView = contentName;
142
- Register.putString(viewRegister, contentName);
143
150
  }
144
151
 
145
152
  public static boolean projectExists(){
@@ -157,19 +164,4 @@ final public class Content extends JPanel {
157
164
  Register.putString(projectRegister, prjName);
158
165
  projectFile = prjName;
159
166
  }
160
-
161
- public static boolean sceneFileExists(){
162
- if(getSceneFile() == null || getSceneFile().isEmpty())
163
- return false;
164
- return true;
165
- }
166
-
167
- public static String getSceneFile(){
168
- return sceneFile;
169
- }
170
-
171
- public static void setSceneFile(String sceneName){
172
- Register.putString(sceneRegister, sceneName);
173
- sceneFile = sceneName;
174
- }
175
167
  }
{IDE → src/gdxstudio}/Editor.java RENAMED
@@ -1,3 +1,6 @@
1
+ package gdxstudio;
2
+ import gdxstudio.panel.ConsolePanel;
3
+
1
4
  import java.awt.Color;
2
5
  import java.awt.Insets;
3
6
  import java.awt.event.ActionEvent;
@@ -50,9 +53,7 @@ final public class Editor extends TextEditorPane {
50
53
  setLineWrap(true);
51
54
  setWrapStyleWord(true);
52
55
  setTabsEmulated(true);
53
- if(Content.projectExists())
54
- if(Content.sceneFileExists())
55
- load();
56
+ load();
56
57
  setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
57
58
  LanguageSupportFactory lsf = LanguageSupportFactory.get();
58
59
  LanguageSupport support = lsf.getSupportFor(SYNTAX_STYLE_JAVA);
@@ -95,8 +96,8 @@ final public class Editor extends TextEditorPane {
95
96
  }
96
97
 
97
98
  public void load(){
98
- if(Content.sceneFileExists()){
99
+ if(Frame.scenePanel.selectedValueExists()){
99
- setText(Export.readFile("source/"+Content.getSceneFile()+".java"));
100
+ setText(Export.readFile("source/"+Frame.scenePanel.getSelectedValue()+".java"));
100
101
  setCaretPosition(0);
101
102
  setDirty(false);
102
103
  }
@@ -105,9 +106,9 @@ final public class Editor extends TextEditorPane {
105
106
  @Override
106
107
  public void save(){
107
108
  if(isDirty()){
108
- if(Content.sceneFileExists()){
109
+ if(Frame.scenePanel.selectedValueExists()){
109
- Export.writeFile("source/"+Content.getSceneFile()+".java", getText());
110
+ Export.writeFile("source/"+Frame.scenePanel.getSelectedValue()+".java", getText());
110
- ConsolePanel.compile();
111
+ ConsolePanel.compile(Frame.scenePanel.getSelectedValue());
111
112
  setDirty(false);
112
113
  }
113
114
  }
{IDE → src/gdxstudio}/Export.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio;
1
2
  import java.io.BufferedReader;
2
3
  import java.io.File;
3
4
  import java.io.FileInputStream;
@@ -19,14 +20,14 @@ import java.util.zip.ZipFile;
19
20
 
20
21
  import javax.swing.JOptionPane;
21
22
 
23
+ import scene2d.Scene;
24
+
22
25
  import com.badlogic.gdx.utils.ArrayMap;
23
26
 
24
27
  public class Export {
25
28
 
26
29
  private static final String[] frameWorkClasses = {
27
- "Actions3d", "Action3d", "Actor3d", "Group3d", "Event3d", "InputEvent3d", "Scene3d", "Stage3d",
28
- "Asset", "Config", "Effect", "ImageJson", "Map", "MapActor", "Net", "Scene", "Serializer",
29
- "Sprite", "Stage", "Type", "Listener",
30
+ "scene2d", "scene3d",
30
31
 
31
32
  "com/badlogic", "com/esotericsoftware", "gdx",
32
33
 
@@ -36,7 +37,8 @@ public class Export {
36
37
  };
37
38
 
38
39
  private static final String[] excludeClasses = {
39
- "org/fife", "org/eclipse" , "com/threerings", "Panel", "tools", "web/laf"
40
+ "org/fife", "org/eclipse" , "com/threerings", "gdxstudio", "tools", "web/laf",
41
+ "android", "antlr"
40
42
  };
41
43
 
42
44
  private static final String eclipse_project =
@@ -83,7 +85,7 @@ public class Export {
83
85
 
84
86
 
85
87
  public static void createProject(String foldername){
86
- Main.log("Creating Project: "+Content.getProject());
88
+ GdxStudio.log("Creating Project: "+Content.getProject());
87
89
  Content.setProject(foldername);
88
90
  new File(Content.getProject()+"atlas").mkdir();
89
91
  new File(Content.getProject()+"font").mkdir();
@@ -113,14 +115,14 @@ public class Export {
113
115
  map.put("Version", "");
114
116
  map.put("Target", "");
115
117
  File prjFile = new File(Content.getProject());
116
- Export.writeFile("config", Stage.json.toJson(map, ArrayMap.class));
118
+ Export.writeFile("config", Scene.json.toJson(map, ArrayMap.class));
117
119
  Export.writeFile(".project", eclipse_project.replace("$$$", prjFile.getName()));
118
120
  Frame.setEnabledProject();
119
121
  createJar();
120
122
  }
121
123
 
122
124
  public static void openProject(String foldername){
123
- Main.log("Opening Project: "+foldername);
125
+ GdxStudio.log("Opening Project: "+foldername);
124
126
  Content.setProject(foldername);
125
127
  Frame.setEnabledProject();
126
128
  }
@@ -128,7 +130,7 @@ public class Export {
128
130
  public static void writeFile(String filename, String data){
129
131
  if(!Content.projectExists())
130
132
  return;
131
- Main.log("Writing File: "+filename);
133
+ GdxStudio.log("Writing File: "+filename);
132
134
  File file = new File(Content.getProject()+filename);
133
135
  try {
134
136
  file.createNewFile();
@@ -145,7 +147,7 @@ public class Export {
145
147
  public static String readFile(String filename){
146
148
  if(!Content.projectExists())
147
149
  return "";
148
- Main.log("Reading File: "+filename);
150
+ GdxStudio.log("Reading File: "+filename);
149
151
  StringBuffer sb = new StringBuffer();
150
152
  File file = new File(Content.getProject()+filename);
151
153
  if(!file.exists())
@@ -196,7 +198,7 @@ public class Export {
196
198
  public static void deleteFile(String filename){
197
199
  if(!Content.projectExists())
198
200
  return;
199
- Main.log("Deleting File: "+filename);
201
+ GdxStudio.log("Deleting File: "+filename);
200
202
  try {
201
203
  Files.delete(new File(Content.getProject()+filename).toPath());
202
204
  } catch (IOException e) {
@@ -210,7 +212,7 @@ public class Export {
210
212
  static{
211
213
  manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
212
214
  manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, ". ");
213
- manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, "Stage");
215
+ manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, "scene2d.desktop.Main");
214
216
  manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VENDOR, "pyros2097");
215
217
  }
216
218
 
@@ -220,7 +222,7 @@ public class Export {
220
222
  String filename = Export.class.getProtectionDomain().getCodeSource().getLocation().getFile();
221
223
  if(!filename.endsWith(".jar"))
222
224
  return;
223
- Main.log("Exporting Project: "+Content.getProject());
225
+ GdxStudio.log("Exporting Project: "+Content.getProject());
224
226
  fileList.clear();
225
227
  prjFile = new File(Content.getProject());
226
228
  generateFileList(prjFile);
@@ -255,13 +257,16 @@ public class Export {
255
257
 
256
258
  private static void generateFileList(File node){
257
259
  if(node.isFile()){
258
- if(!node.getName().contains("pack") && !node.getName().equals(prjFile.getName()+".jar")){
260
+ if(!node.getName().endsWith(".java") && !node.getName().equals(prjFile.getName()+".jar")
261
+ && !node.getName().equals(prjFile.getName()+".apk")){
259
262
  fileList.add(node);
260
263
  }
261
264
  }
262
265
  else{
263
- for(String filename : node.list())
266
+ for(String filename : node.list()){
267
+ if(!filename.equals("pack"))
264
- generateFileList(new File(node, filename));
268
+ generateFileList(new File(node, filename));
269
+ }
265
270
  }
266
271
  }
267
272
 
@@ -282,8 +287,9 @@ public class Export {
282
287
  if(!entryName.contains(excludeClasses[0]) && !entryName.contains(excludeClasses[1])
283
288
  && !entryName.contains(excludeClasses[2]) && !entryName.contains(excludeClasses[3])
284
289
  && !entryName.contains(excludeClasses[4]) && !entryName.contains(excludeClasses[5])
290
+ && !entryName.contains(excludeClasses[6]) && !entryName.contains(excludeClasses[7])
285
291
  && entryName.contains(name)) {
286
- Main.log(entryName);
292
+ //GdxStudio.log(entryName);
287
293
  ZipEntry newEntry = new ZipEntry(entryName);
288
294
  jos.putNextEntry(newEntry);
289
295
  InputStream in = jf.getInputStream(je);
{IDE → src/gdxstudio}/Frame.java RENAMED
@@ -1,3 +1,19 @@
1
+ package gdxstudio;
2
+
3
+ import gdxstudio.panel.ActorPanel;
4
+ import gdxstudio.panel.BaseList;
5
+ import gdxstudio.panel.BaseTable;
6
+ import gdxstudio.panel.ConsolePanel;
7
+ import gdxstudio.panel.DashPanel;
8
+ import gdxstudio.panel.EffectPanel;
9
+ import gdxstudio.panel.EventPanel;
10
+ import gdxstudio.panel.ProjectPanel;
11
+ import gdxstudio.panel.ProjectSettingsPanel;
12
+ import gdxstudio.panel.PropertyPanel;
13
+ import gdxstudio.panel.SceneEffectPanel;
14
+ import gdxstudio.panel.ScenePanel;
15
+ import gdxstudio.panel.StudioPanel;
16
+
1
17
  import java.awt.BorderLayout;
2
18
  import java.awt.Component;
3
19
  import java.awt.event.WindowEvent;
@@ -9,6 +25,8 @@ import javax.swing.JLabel;
9
25
  import javax.swing.JList;
10
26
  import javax.swing.JPanel;
11
27
 
28
+ import scene2d.Asset;
29
+ import scene2d.Scene;
12
30
  import web.laf.lite.layout.VerticalFlowLayout;
13
31
  import web.laf.lite.utils.UIUtils;
14
32
 
@@ -28,7 +46,6 @@ final public class Frame extends JFrame implements WindowListener{
28
46
  public static ActorPanel actorPanel;
29
47
 
30
48
  public static DashPanel dashPanel;
31
- public static WidgetPanel widgetPanel;
32
49
  public static PropertyPanel propertyPanel;
33
50
  public static EffectPanel effectPanel;
34
51
  public static EventPanel eventPanel;
@@ -57,7 +74,6 @@ final public class Frame extends JFrame implements WindowListener{
57
74
  rightSideBar = new JPanel(new VerticalFlowLayout(0, 10));
58
75
  UIUtils.setUndecorated(rightSideBar, true);
59
76
  dashPanel = new DashPanel();
60
- widgetPanel = new WidgetPanel();
61
77
  propertyPanel = new PropertyPanel();
62
78
  effectPanel = new EffectPanel();
63
79
  eventPanel = new EventPanel();
@@ -66,7 +82,6 @@ final public class Frame extends JFrame implements WindowListener{
66
82
  //rightSideBar.add(new TablePanel("TT"));
67
83
  rightSideBar.add(effectPanel);
68
84
  rightSideBar.add(eventPanel);
69
- rightSideBar.add(widgetPanel);
70
85
 
71
86
  leftSideBar = new JPanel(new VerticalFlowLayout(0, 10));
72
87
  UIUtils.setUndecorated(leftSideBar, true);
@@ -106,20 +121,16 @@ final public class Frame extends JFrame implements WindowListener{
106
121
 
107
122
  public static void toggleLeftSideBar(){
108
123
  leftSideBar.setVisible(!leftSideBar.isVisible());
124
+ if(Content.studioPanel != null)
125
+ Content.studioPanel.revalidateScreenPosition();
109
126
  }
110
127
 
111
128
  public static void toggleRightSideBar(){
112
129
  rightSideBar.setVisible(!rightSideBar.isVisible());
130
+ if(Content.studioPanel != null)
131
+ Content.studioPanel.revalidateScreenPosition();
113
132
  }
114
133
 
115
- public static void showRightSideBar(){
116
- rightSideBar.setVisible(true);
117
- }
118
-
119
- public static void toggleEditor(){
120
- content.setVisible(!content.isVisible());
121
- }
122
-
123
134
  private static void updateProject(){
124
135
  Asset.loadAsynchronous = false;
125
136
  Asset.setBasePath(Content.getProject());
@@ -258,8 +269,9 @@ final public class Frame extends JFrame implements WindowListener{
258
269
  @Override
259
270
  public void windowClosing(WindowEvent arg0) {
260
271
  Content.editor.save();
272
+ Scene.getCurrentScene().save(scenePanel.getSelectedValue());
261
273
  if(Content.studioPanel.canvas != null)
262
- Stage.clear();
274
+ Scene.getRoot().clear();
263
275
  //Stage.exit();
264
276
  //Content.studioPanel.destroyCanvas();
265
277
  dispose();
IDE/Main.java → src/gdxstudio/GdxStudio.java RENAMED
@@ -1,3 +1,7 @@
1
+ package gdxstudio;
2
+ import gdxstudio.panel.ConsolePanel;
3
+ import gdxstudio.panel.StudioPanel;
4
+
1
5
  import java.awt.AlphaComposite;
2
6
  import java.awt.Color;
3
7
  import java.awt.Dimension;
@@ -10,9 +14,10 @@ import javax.swing.JFrame;
10
14
  import javax.swing.SwingUtilities;
11
15
  import javax.swing.UIManager;
12
16
 
17
+ import scene2d.Asset;
13
18
  import web.laf.lite.widget.Register;
14
19
 
15
- public class Main {
20
+ public class GdxStudio {
16
21
  public static final String version = "0.7.1";
17
22
 
18
23
  public static void main(String[] args) {
{IDE → src/gdxstudio}/Icon.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio;
1
2
  import java.io.IOException;
2
3
  import java.io.InputStream;
3
4
  import java.net.URL;
@@ -7,12 +8,14 @@ import javax.swing.ImageIcon;
7
8
 
8
9
  import org.fife.ui.rsyntaxtextarea.Theme;
9
10
 
11
+ import scene2d.Asset;
12
+
10
13
  public class Icon {
11
14
 
12
15
  static String[] iconsList = new String[]{
13
16
  "icon", "vs", "eclipse", "dark", "idea",
14
17
  "trash", "help", "szoomout", "szoomin",
15
- "sweblaf", "update", "style", "stexturepacker", "sparticle", "snuke",
18
+ "sweblaf", "update", "stexturepacker", "sparticle", "snuke",
16
19
  "slibGDX", "shierologo", "shiero", "search", "screen", "sabout",
17
20
  "packer", "options", "newprj", "newpack", "newfile", "lib", "level",
18
21
  "high", "font", "find", "esource", "epackage",
src/gdxstudio/SceneEditor.java ADDED
@@ -0,0 +1,263 @@
1
+ package gdxstudio;
2
+
3
+ import java.awt.Cursor;
4
+
5
+ import scene2d.Asset;
6
+ import scene2d.Scene;
7
+
8
+ import com.badlogic.gdx.scenes.scene2d.Actor;
9
+ import com.badlogic.gdx.scenes.scene2d.InputEvent;
10
+ import com.badlogic.gdx.scenes.scene2d.ui.List;
11
+ import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
12
+ import com.badlogic.gdx.scenes.scene2d.ui.Table;
13
+ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
14
+ import com.badlogic.gdx.scenes.scene2d.ui.TextField;
15
+ import com.badlogic.gdx.scenes.scene2d.utils.Align;
16
+ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
17
+ import com.badlogic.gdx.utils.Array;
18
+ import com.badlogic.gdx.utils.Timer.Task;
19
+
20
+ public class SceneEditor extends Scene {
21
+ public static Actor selectedActor = null;
22
+ public static boolean reloadAssets = false;
23
+ static AddField addField;
24
+
25
+ public SceneEditor(){
26
+ super();
27
+ if(reloadAssets){
28
+ Asset.loadBlocking(); // this is the first time this Scene is created by the Stage
29
+ Content.assetPanel.updateAsset();
30
+ com.badlogic.gdx.utils.Timer.schedule(new Task(){
31
+ @Override
32
+ public void run() {
33
+ Frame.scenePanel.showStudio();
34
+ Scene.scenesMap.removeKey("gdxstudio.SceneEditor");
35
+ Frame.scenePanel.update();
36
+ }
37
+ }, 1f);
38
+ reloadAssets = false;
39
+ addField = new AddField();
40
+ }
41
+ else{
42
+ Frame.scenePanel.showStudio();
43
+ Scene.scenesMap.removeKey("gdxstudio.SceneEditor");
44
+ }
45
+ Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
46
+ }
47
+
48
+ public static void doClick(Actor actor){
49
+ addField.remove();
50
+ Frame.actorPanel.lock();
51
+ Frame.propertyPanel.clear();
52
+ Frame.effectPanel.clear();
53
+ Frame.eventPanel.clear();
54
+ selectedActor = actor;
55
+ Scene.getCurrentScene().outline(actor);
56
+ Frame.actorPanel.list.setSelectedIndex(Frame.actorPanel.indexOf(actor.getName()));
57
+ StatusBar.updateSelected(actor.getName());
58
+ Frame.dashPanel.update();
59
+ Frame.propertyPanel.update();
60
+ Frame.effectPanel.update();
61
+ Frame.eventPanel.update();
62
+ Frame.actorPanel.unlock();
63
+ if(selectedActor instanceof List || selectedActor instanceof SelectBox){
64
+ addField.setPosition(actor.getX(), actor.getY() - addField.getHeight());
65
+ Scene.getRoot().addActor(addField);
66
+ }
67
+ }
68
+
69
+
70
+ @Override
71
+ public void onClick(Actor actor) {
72
+ doClick(actor);
73
+ }
74
+
75
+ boolean dragging;
76
+ int edge;
77
+ float startX, startY, lastX, lastY;
78
+ @Override
79
+ public void onTouchDown(Actor actor) {
80
+ if (Scene.mouseButton == 0) {
81
+ edge = 0;
82
+ float x = Scene.mouse.x;
83
+ float y = Scene.mouse.y;
84
+ if (x > actor.getX() + actor.getWidth() - 10) edge |= Align.right;
85
+ if (y > actor.getY() + actor.getHeight() - 10) edge |= Align.top;
86
+ //if (x < actor.getX() + 20 && y < actor.getY() + 20) edge = Align.left; no rotation
87
+ dragging = edge != 0;
88
+ startX = x;
89
+ startY = y;
90
+ lastX = x;
91
+ lastY = y;
92
+ }
93
+ }
94
+
95
+ @Override
96
+ public void onTouchUp() {
97
+ dragging = false;
98
+ Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
99
+ }
100
+
101
+ @Override
102
+ public void onDragged() {
103
+ if(selectedActor != null){
104
+ if(!dragging){
105
+ selectedActor.setPosition(Scene.mouse.x, Scene.mouse.y);
106
+ Frame.propertyPanel.updateProperty("X", ""+selectedActor.getX(), 0);
107
+ Frame.propertyPanel.updateProperty("Y", ""+selectedActor.getY(), 0);
108
+ StatusBar.updateXY(Scene.mouse.x, Scene.mouse.y);
109
+
110
+ }
111
+ else
112
+ {
113
+ float x = Scene.mouse.x;
114
+ float y = Scene.mouse.y;
115
+ float width = selectedActor.getWidth(), height = selectedActor.getHeight();
116
+ float windowX = selectedActor.getX(), windowY = selectedActor.getY();
117
+ if ((edge & Align.right) != 0) {
118
+ width += x - lastX;
119
+ }
120
+ if ((edge & Align.top) != 0) {
121
+ height += y - lastY;
122
+ }
123
+ if ((edge & Align.top) != 0 && (edge & Align.right) != 0) {
124
+ width += x - lastX;
125
+ height += y - lastY;
126
+ }
127
+ if (edge == Align.left){
128
+ float rot = getAngle(selectedActor.getX()+selectedActor.getOriginX(),
129
+ selectedActor.getY()+selectedActor.getOriginY(), x, y)
130
+ - selectedActor.getRotation();
131
+ selectedActor.rotate(rot);
132
+ }
133
+ lastX = x;
134
+ lastY = y;
135
+ selectedActor.setBounds(Math.round(windowX), Math.round(windowY), Math.round(width), Math.round(height));
136
+ Frame.propertyPanel.updateProperty("Width", ""+width, 0);
137
+ Frame.propertyPanel.updateProperty("Height", ""+height, 0);
138
+ }
139
+ Scene.isDirty = true;
140
+ }
141
+ }
142
+
143
+ @Override
144
+ public void onGesture(GestureType type) {
145
+ }
146
+
147
+ private boolean isHand = true;
148
+ private boolean isRight = false;
149
+ private boolean isTop = false;
150
+
151
+ @Override
152
+ public void act(float delta){
153
+ if(selectedActor != null){
154
+ isRight = false;
155
+ isTop = false;
156
+ //Stage.log("my"+Stage.mouse.y+"top"+selectedActor.getTop());
157
+ if (Scene.mouse.x > selectedActor.getRight() - 10 && Scene.mouse.x < selectedActor.getRight()) {
158
+ Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
159
+ isHand = false;
160
+ isRight = true;
161
+ }
162
+ if(Scene.mouse.y > selectedActor.getTop() - 10 && Scene.mouse.y < selectedActor.getTop()){
163
+ Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
164
+ isHand = false;
165
+ isTop = true;
166
+ }
167
+ if (isRight && isTop) {
168
+ Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
169
+ isHand = false;
170
+ }
171
+ if (!isRight && !isTop){
172
+ if(!isHand){
173
+ Content.studioPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
174
+ isHand = true;
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ @Override
181
+ public void onKeyTyped(char key) {};
182
+ @Override
183
+ public void onKeyUp(int keycode){};
184
+ @Override
185
+ public void onKeyDown(int keycode){};
186
+ @Override
187
+ public void onPause(){};
188
+ @Override
189
+ public void onResume(){};
190
+ @Override
191
+ public void onDispose(){};
192
+ }
193
+
194
+ class AddField extends Table {
195
+ TextField tf;
196
+ TextButton addBtn;
197
+ TextButton removeBtn;
198
+
199
+ public AddField(){
200
+ super(Asset.skin);
201
+ setBackground(Asset.skin.getDrawable("dialogDim"));
202
+ tf = new TextField("", Asset.skin);
203
+ addBtn = new TextButton("Add", Asset.skin);
204
+ removeBtn = new TextButton("Remove", Asset.skin);
205
+ add(tf);
206
+ add(addBtn);
207
+ add(removeBtn);
208
+ pack();
209
+ addBtn.addListener(new ClickListener(){
210
+ @Override
211
+ public void clicked(InputEvent event, float x, float y){
212
+ super.clicked(event, x, y);
213
+ if(!tf.getText().isEmpty()){
214
+ if(SceneEditor.selectedActor instanceof List){
215
+ List list = (List) SceneEditor.selectedActor;
216
+ Array<String> arr = new Array<String>(list.getItems());
217
+ arr.add(tf.getText());
218
+ list.setItems(arr.toArray());
219
+ list.pack();
220
+ AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
221
+ }
222
+ if(SceneEditor.selectedActor instanceof SelectBox){
223
+ SelectBox list = (SelectBox) SceneEditor.selectedActor;
224
+ Array<String> arr = new Array<String>(list.getItems());
225
+ arr.add(tf.getText());
226
+ list.setItems(arr.toArray());
227
+ list.pack();
228
+ AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
229
+ }
230
+
231
+ }
232
+ }
233
+ });
234
+ removeBtn.addListener(new ClickListener(){
235
+ @Override
236
+ public void clicked(InputEvent event, float x, float y){
237
+ super.clicked(event, x, y);
238
+ if(SceneEditor.selectedActor instanceof List){
239
+ List list = (List) SceneEditor.selectedActor;
240
+ if(list.getItems().length == 0)
241
+ return;
242
+ Array<String> arr = new Array<String>(list.getItems());
243
+ list.setSelectedIndex(list.getItems().length-1);
244
+ arr.removeIndex(list.getSelectedIndex());
245
+ list.setItems(arr.toArray());
246
+ list.pack();
247
+ AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
248
+ }
249
+ if(SceneEditor.selectedActor instanceof SelectBox){
250
+ SelectBox list = (SelectBox) SceneEditor.selectedActor;
251
+ if(list.getItems().length == 0)
252
+ return;
253
+ Array<String> arr = new Array<String>(list.getItems());
254
+ list.setSelection(list.getItems().length-1);
255
+ arr.removeIndex(list.getSelectionIndex());
256
+ list.setItems(arr.toArray());
257
+ list.pack();
258
+ AddField.this.setPosition(list.getX(), list.getY()-AddField.this.getHeight());
259
+ }
260
+ }
261
+ });
262
+ }
263
+ }
{IDE → src/gdxstudio}/SearchBar.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio;
1
2
  import java.awt.Dimension;
2
3
  import java.awt.event.ActionEvent;
3
4
  import java.awt.event.ActionListener;
{IDE → src/gdxstudio}/StatusBar.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio;
1
2
  import java.awt.Color;
2
3
  import java.awt.Graphics;
3
4
  import java.awt.Graphics2D;
@@ -38,10 +39,10 @@ final public class StatusBar extends JPanel {
38
39
  add(caret, ToolbarLayout.START);
39
40
  addSpace();
40
41
  addSeparator();
41
- addSpace();
42
+ //addSpace();
42
- add(selected, ToolbarLayout.START);
43
+ //add(selected, ToolbarLayout.START);
43
- addSpace();
44
+ //addSpace();
44
- addSeparator();
45
+ //addSeparator();
45
46
 
46
47
  addSpace();
47
48
  add(xy, ToolbarLayout.START);
@@ -71,6 +72,12 @@ final public class StatusBar extends JPanel {
71
72
  initAsset();
72
73
  addSpace();
73
74
 
75
+ addSeparator();
76
+
77
+ addSpace();
78
+ initWidget();
79
+ addSpace();
80
+
74
81
  addSeparator();
75
82
 
76
83
  //initUpdate();
@@ -135,6 +142,17 @@ final public class StatusBar extends JPanel {
135
142
  add(asset);
136
143
  }
137
144
 
145
+ void initWidget(){
146
+ final JButton widget = Style.createMenuButton("<html><b>Widgets</b>");
147
+ widget.addActionListener(new ActionListener(){
148
+ @Override
149
+ public void actionPerformed(ActionEvent arg0) {
150
+ Content.toggleWidget();
151
+ }
152
+ });
153
+ add(widget);
154
+ }
155
+
138
156
  void initZoomIn(){
139
157
  add(Style.createToolPanel("ZoomIn", "szoomin", new ActionListener(){
140
158
  @Override
{IDE → src/gdxstudio}/Style.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio;
1
2
  import java.awt.Color;
2
3
  import java.awt.FlowLayout;
3
4
  import java.awt.GradientPaint;
@@ -90,22 +91,32 @@ public enum Style {
90
91
  private static GradientPaint headerBgPaint;
91
92
 
92
93
  private static final int margin = 15;
93
- private static final int marginsub5 = 10;
94
- private static final int margin5 = 20;
94
+ private static int screenX = 0;
95
+ private static int screenY = 0;
95
- private static final int targetW = 800+55;
96
+ private static int screenW = 0;
96
- private static final int targetH = 480;
97
+ private static int screenH = 0;
98
+
99
+ public static void setScreenPosition(int x, int y){
100
+ screenX = x - 5;
101
+ screenY = y + 5;
102
+ }
103
+
104
+ public static void setScreenSize(int width, int height){
105
+ screenW = width + 40;
106
+ screenH = height + 25;
107
+ }
97
108
 
98
- final public static void drawScreen(Graphics g, int width, int height){
109
+ public static void drawScreen(Graphics g, int width, int height){
99
110
  g.setColor(Style.canvasBg);
100
111
  g.fillRect(0, 0, width, height); //bg
101
112
  g.setColor(Color.black);
102
- g.fillRoundRect(5, marginsub5, targetW+marginsub5, targetH+10, 10, 10);
113
+ g.fillRoundRect(screenX, screenY, screenW, screenH, 10, 10);
103
114
  g.setColor(Style.canvasShadowBot);
104
- g.drawLine(margin, targetH+margin5, targetW+marginsub5, targetH+margin5);//hoz shadow y same
115
+ g.drawLine(screenX+5, screenY+screenH, screenX+screenW-5, screenY+screenH);//hoz shadow y same
105
- g.drawLine(targetW+margin, margin, targetW+margin, targetH+margin);// vert shadow x same
116
+ g.drawLine(screenX+screenW, screenY+5, screenX+screenW, screenY+screenH-5);// vert shadow x same
106
117
  g.setColor(Style.canvasBox);
107
- g.fillRect(0, targetH+3*margin, width, 2);
118
+ g.fillRect(0, screenH+3*margin, width, 2);
108
- g.fillRect(0, targetH+3*margin+3, width, height-targetH+3*margin-3);
119
+ g.fillRect(0, screenH+3*margin+3, width, height-screenH+3*margin-3);
109
120
  }
110
121
 
111
122
  public static Color tableHeaderTopLineColor = new Color ( 232, 234, 235 );
@@ -184,6 +195,11 @@ public enum Style {
184
195
  setHorizontalAlignment(JLabel.CENTER);
185
196
  setForeground(Style.headerFg);
186
197
  }
198
+ public TitleLabel(String text, String icon){
199
+ this(text);
200
+ setIcon(Icon.icon(icon));
201
+ setHorizontalTextPosition(JLabel.RIGHT);
202
+ }
187
203
  @Override
188
204
  public void setText(String text){
189
205
  super.setText(text.toUpperCase());
@@ -221,9 +237,6 @@ public enum Style {
221
237
  if(al != null)
222
238
  addActionListener(al);
223
239
  }
224
- public TitleButton(String text){
225
- this(text, null);
226
- }
227
240
  @Override
228
241
  public void setText(String text){
229
242
  super.setText(text.toUpperCase());
@@ -305,7 +318,7 @@ public enum Style {
305
318
  JButton btn = new JButton(text,Icon.icon(ic));
306
319
  UIUtils.setDrawFocus(btn, false);
307
320
  UIUtils.setShadeWidth(btn, 0);
308
- //UIUtils.setRound(btn, 0);
321
+ UIUtils.setRound(btn, 0);
309
322
  viewGroup.add(btn);
310
323
  btn.addActionListener(new ActionListener(){
311
324
  @Override
{IDE → src/gdxstudio}/ToolBar.java RENAMED
@@ -1,3 +1,8 @@
1
+ package gdxstudio;
2
+ import gdxstudio.panel.ConsolePanel;
3
+ import gdxstudio.panel.OptionsPanel;
4
+ import gdxstudio.panel.ProjectPanel;
5
+
1
6
  import java.awt.BorderLayout;
2
7
  import java.awt.Dimension;
3
8
  import java.awt.FileDialog;
@@ -15,18 +20,20 @@ import javax.swing.BorderFactory;
15
20
  import javax.swing.JButton;
16
21
  import javax.swing.JDialog;
17
22
  import javax.swing.JLabel;
23
+ import javax.swing.JOptionPane;
18
24
  import javax.swing.JPanel;
19
25
  import javax.swing.JSeparator;
20
- import javax.swing.JToggleButton;
21
26
  import javax.swing.SwingConstants;
22
27
 
28
+ import com.badlogic.gdx.tools.imagepacker.TexturePacker2;
29
+ import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings;
30
+
23
31
  import web.laf.lite.layout.HorizontalFlowLayout;
24
32
  import web.laf.lite.layout.ToolbarLayout;
25
33
  import web.laf.lite.layout.VerticalFlowLayout;
26
34
  import web.laf.lite.popup.ButtonPopup;
27
35
  import web.laf.lite.popup.PopupWay;
28
36
  import web.laf.lite.utils.UIUtils;
29
- import web.laf.lite.widget.Register;
30
37
  import web.laf.lite.widget.WebButtonGroup;
31
38
 
32
39
  final public class ToolBar extends JPanel {
@@ -41,11 +48,23 @@ final public class ToolBar extends JPanel {
41
48
  initAbout();
42
49
  initProject();
43
50
  initOpen();
51
+ initPack();
44
52
  initExport();
45
53
  addSeparator();
46
54
  initOptions();
47
- initStyle();
48
55
  addSeparator();
56
+ add(Style.createToolPanel("Build", "esource", new ActionListener(){
57
+ @Override
58
+ public void actionPerformed(ActionEvent arg0) {
59
+ ConsolePanel.build();
60
+ }
61
+ }));
62
+ add(Style.createToolPanel("Compile", "esource", new ActionListener(){
63
+ @Override
64
+ public void actionPerformed(ActionEvent arg0) {
65
+ Content.editor.save();
66
+ }
67
+ }));
49
68
  add(Style.createToolPanel("Run", "go", new ActionListener(){
50
69
  @Override
51
70
  public void actionPerformed(ActionEvent arg0) {
@@ -94,7 +113,7 @@ final public class ToolBar extends JPanel {
94
113
  final JButton licenseBtn = new JButton("Apache License v2.0");
95
114
  final JPanel author = new JPanel(new HorizontalFlowLayout());
96
115
  final JPanel hoz = new JPanel(new HorizontalFlowLayout());
97
- popupContent.add(UIUtils.setBoldFont(new JLabel("GdxStudio v"+Main.version)));
116
+ popupContent.add(UIUtils.setBoldFont(new JLabel("GdxStudio v"+GdxStudio.version)));
98
117
  popupContent.add(new JSeparator(SwingConstants.HORIZONTAL));
99
118
  author.setOpaque(false);
100
119
  author.add(new JLabel("Created by: pyros2097"));
@@ -213,6 +232,31 @@ final public class ToolBar extends JPanel {
213
232
  add(open);
214
233
  }
215
234
 
235
+ void initPack(){
236
+ JButton packButton = Style.createMenuButton("Pack");
237
+ packButton.setIcon(Icon.icon("epackage"));
238
+ packButton.addActionListener(new ActionListener(){
239
+ @Override
240
+ public void actionPerformed(ActionEvent arg0) {
241
+ Settings settings = new Settings();
242
+ settings.maxWidth = 2048;
243
+ settings.maxHeight = 2048;
244
+ settings.paddingX = 0;
245
+ settings.paddingY = 0;
246
+ TexturePacker2.process(settings, Content.getProject()+File.separator+"pack",
247
+ Content.getProject()+"atlas/", "pack.atlas");
248
+ for(File f: new File(Content.getProject()+File.separator+"pack").listFiles()){
249
+ if(f.isDirectory()){
250
+ TexturePacker2.process(settings, f.getPath(), Content.getProject()+"atlas/", f.getName());
251
+ JOptionPane.showMessageDialog(null, "Packed Texture: "+f.getName(), "Texture Packer",
252
+ JOptionPane.INFORMATION_MESSAGE);
253
+ }
254
+ }
255
+ }
256
+ });
257
+ add(packButton);
258
+ }
259
+
216
260
  void initExport(){
217
261
  JButton export = Style.createMenuButton("Export");
218
262
  export.setIcon(Icon.icon("export"));
@@ -238,7 +282,7 @@ final public class ToolBar extends JPanel {
238
282
  dialog.getContentPane().setLayout(new BorderLayout());
239
283
  dialog.getContentPane().add(optionsPanel);
240
284
  dialog.pack();
241
- dialog.setSize(525, 500);
285
+ dialog.setSize(525, 525);
242
286
  Dimension Size = Toolkit.getDefaultToolkit().getScreenSize();
243
287
  dialog.setLocation(new Double((Size.getWidth()/2) - (dialog.getWidth()/2)).intValue(),
244
288
  new Double((Size.getHeight()/2) - (dialog.getHeight()/2)).intValue());
@@ -248,63 +292,20 @@ final public class ToolBar extends JPanel {
248
292
  }));
249
293
  }
250
294
 
251
- void initStyle(){
252
- add(Style.createToolPanel("Style", "style", null));
253
- UIUtils.setRound(Style.btnMap.get("style"), 10);
254
- final ButtonPopup wbp = new ButtonPopup(Style.btnMap.get("style"), PopupWay.downRight);
255
- wbp.setRound(0);
256
- UIUtils.setRound(wbp, 0);
257
- JPanel editorStyles = new JPanel ( new VerticalFlowLayout (5, 5) );
258
- editorStyles.setOpaque(false);
259
- UIUtils.setRound(editorStyles, 0);
260
- UIUtils.setUndecorated(editorStyles, true);
261
- ThemeButton[] themeButtons = {
262
- createThemeItem("IntelliJ IDEA", "idea"),
263
- createThemeItem("Dark", "dark"),
264
- createThemeItem("Visual Studio", "vs"),
265
- createThemeItem("Eclipse", "eclipse")
266
- };
267
- WebButtonGroup themeGroup = new WebButtonGroup(WebButtonGroup.VERTICAL, true, themeButtons);
268
- themeGroup.setButtonsDrawFocus(false);
269
- themeGroup.setButtonsDrawFocus(false);
270
- editorStyles.add(themeGroup);
271
- wbp.setContent (editorStyles);
272
- }
273
-
274
- ThemeButton createThemeItem(String title, String iconname){
275
- final ThemeButton themeButton = new ThemeButton(title, iconname);
276
- if(Register.getTheme().equals(iconname))
277
- themeButton.setSelected(true);
278
- themeButton .addActionListener (new ActionListener (){
279
- public void actionPerformed (ActionEvent e){
280
- Register.setTheme(themeButton.iconame);
281
- Content.theme = Icon.loadTheme(themeButton.iconame);
282
- Content.theme.apply(Content.editor);
283
- }
284
- });
285
- return themeButton;
286
- }
287
-
288
295
  void initView(){
289
- JPanel pan = new JPanel(new VerticalFlowLayout(FlowLayout.CENTER, 0, 0));
290
- UIUtils.setUndecorated(pan, true);
291
- UIUtils.setShadeWidth(pan, 0);
292
- UIUtils.setRound(pan, 0);
293
- UIUtils.setDrawSides(pan, false, false, false, false);
294
296
  Style.viewButton("Editor", "editor");
295
297
  Style.viewButton("Studio", "studio");
296
298
  Style.viewButton("Hiero", "shiero");
297
299
  Style.viewButton("Particle", "sparticle");
298
- WebButtonGroup textGroup = new WebButtonGroup(true,Style.viewGroup.toArray(new JButton[Style.viewGroup.size()]));
300
+ WebButtonGroup textGroup = new WebButtonGroup(true, Style.viewGroup.get(0), Style.viewGroup.get(1),
301
+ Style.viewGroup.get(2), Style.viewGroup.get(3));
299
302
  textGroup.setButtonsDrawFocus(false);
300
303
  UIUtils.setUndecorated(textGroup, true);
301
- UIUtils.setShadeWidth(textGroup, 1);
304
+ UIUtils.setShadeWidth(textGroup, 0);
302
- UIUtils.setMargin(textGroup, new Insets(1, 0, 1, 0));
305
+ UIUtils.setMargin(textGroup, new Insets(0, 0, -1, 0));
303
306
  UIUtils.setRound(textGroup, 0);
304
307
  UIUtils.setDrawSides(textGroup, false, false, false, false);
305
- pan.setOpaque(false);
306
- pan.add(textGroup);
308
+ add(textGroup);
307
- add(pan, ToolbarLayout.MIDDLE);
308
309
  }
309
310
 
310
311
  public void addSpace(){
@@ -314,16 +315,4 @@ final public class ToolBar extends JPanel {
314
315
  public void addSeparator(){
315
316
  add(new JSeparator(SwingConstants.VERTICAL), ToolbarLayout.START);
316
317
  }
317
- }
318
-
319
- final class ThemeButton extends JToggleButton{
320
- private static final long serialVersionUID = 1L;
321
- String iconame;
322
- ThemeButton(String text, String ic){
323
- super(text, Icon.icon(ic));
324
- iconame = ic;
325
- setVerticalTextPosition(SwingConstants.BOTTOM);
326
- setHorizontalTextPosition(SwingConstants.CENTER);
327
- setFocusable(false);
328
- }
329
318
  }
{IDE → src/gdxstudio}/Update.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio;
1
2
  import java.io.BufferedReader;
2
3
  import java.io.File;
3
4
  import java.io.FileOutputStream;
@@ -123,7 +124,7 @@ public class Update extends JFrame implements PropertyChangeListener, ActionList
123
124
  progressBar.setValue(0);
124
125
  int serverFileLength = getContentLength("https://github.com/pyros2097/Scene3d/raw/master/libs/"+file);
125
126
  long localFileLength = new File(workDir+"libs/"+file).length();
126
- Main.log("serverFileLength:"+serverFileLength+" localFileLength:"+localFileLength);
127
+ GdxStudio.log("serverFileLength:"+serverFileLength+" localFileLength:"+localFileLength);
127
128
  if(serverFileLength == localFileLength)
128
129
  return;//continue;
129
130
  AsyncDownloader as = new AsyncDownloader("https://github.com/pyros2097/Scene3d/raw/master/libs/", file);
@@ -141,7 +142,7 @@ public class Update extends JFrame implements PropertyChangeListener, ActionList
141
142
  String line = "";
142
143
  HttpURLConnection httpConn = openConnection("https://github.com/pyros2097/GdxStudio/raw/master/README.md");
143
144
  if(httpConn == null)
144
- return Main.version;
145
+ return GdxStudio.version;
145
146
  if(isOK(httpConn)) {
146
147
  try {
147
148
  BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
@@ -193,7 +194,7 @@ public class Update extends JFrame implements PropertyChangeListener, ActionList
193
194
  }
194
195
 
195
196
  private boolean checkNewVersion(){
196
- String[] vals1 = Main.version.split("\\.");
197
+ String[] vals1 = GdxStudio.version.split("\\.");
197
198
  String[] vals2 = getNewVersion().split("\\.");
198
199
  int i=0;
199
200
  while(i<vals1.length && i<vals2.length && vals1[i].equals(vals2[i])) {
{Panel → src/gdxstudio/panel}/ActorPanel.java RENAMED
@@ -1,3 +1,11 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Content;
3
+ import gdxstudio.Frame;
4
+ import gdxstudio.SceneEditor;
5
+ import gdxstudio.StatusBar;
6
+ import gdxstudio.Style;
7
+
8
+ import java.awt.Component;
1
9
  import java.awt.Dimension;
2
10
  import java.awt.event.ActionEvent;
3
11
 
@@ -6,6 +14,7 @@ import javax.swing.JComboBox;
6
14
  import javax.swing.JPanel;
7
15
  import javax.swing.event.ListSelectionEvent;
8
16
 
17
+ import scene2d.Scene;
9
18
  import web.laf.lite.widget.CenterPanel;
10
19
 
11
20
  import com.badlogic.gdx.scenes.scene2d.Actor;
@@ -20,6 +29,8 @@ public class ActorPanel extends BaseList {
20
29
 
21
30
  public static Actor copiedActor = null;
22
31
  public static Actor cutActor = null;
32
+ public Component paste;
33
+
23
34
 
24
35
  public ActorPanel(){
25
36
  super("Actors", "");
@@ -29,8 +40,10 @@ public class ActorPanel extends BaseList {
29
40
  tools.add(new CenterPanel(groupCombo, false, true));
30
41
  add(tools);
31
42
  add(scrollPane);
32
- if(Content.sceneFileExists())
43
+ if(Frame.scenePanel.selectedValueExists())
33
- setHeaderText(Content.getSceneFile());
44
+ setHeaderText(Frame.scenePanel.getSelectedValue());
45
+ paste = tools.getComponent(2);
46
+ paste.setEnabled(false);
34
47
  }
35
48
 
36
49
  public void addActor(String actorName){
@@ -78,7 +91,7 @@ public class ActorPanel extends BaseList {
78
91
  @Override
79
92
  public void valueChanged(ListSelectionEvent e) {
80
93
  if (e.getValueIsAdjusting() == false) {
81
- SceneEditor.doClick(Stage.findActor(list.getSelectedValue()));
94
+ SceneEditor.doClick(Scene.getCurrentScene().findActor(list.getSelectedValue()));
82
95
  }
83
96
  }
84
97
 
@@ -87,33 +100,45 @@ public class ActorPanel extends BaseList {
87
100
  lock();
88
101
  switch(((JButton)e.getSource()).getToolTipText()){
89
102
  case "Cut":
103
+ if(list.getSelectedIndex() != -1){
90
- cutActor = SceneEditor.selectedActor;
104
+ cutActor = SceneEditor.selectedActor;
91
- copiedActor = null;
105
+ copiedActor = null;
92
- listModel2.removeElement(SceneEditor.selectedActor.getName());
106
+ listModel2.removeElement(SceneEditor.selectedActor.getName());
93
- Stage.removeActor(SceneEditor.selectedActor);
107
+ Scene.getCurrentScene().removeActor(SceneEditor.selectedActor);
108
+ paste.setEnabled(true);
109
+ }
94
110
  break;
95
111
 
96
112
  case "Copy":
113
+ if(list.getSelectedIndex() != -1){
97
- String line = Stage.json.toJson(SceneEditor.selectedActor);
114
+ String line = Scene.json.toJson(SceneEditor.selectedActor);
98
- copiedActor = Stage.json.fromJson(Actor.class, line);
115
+ copiedActor = Scene.json.fromJson(Actor.class, line);
99
- cutActor = null;
116
+ cutActor = null;
117
+ paste.setEnabled(true);
118
+ }
100
119
  break;
101
120
 
102
121
  case "Paste":
103
122
  if(cutActor != null){
104
123
  Content.studioPanel.setName(cutActor);
105
124
  cutActor = null;
125
+ paste.setEnabled(false);
106
126
  }
107
127
  if(copiedActor != null){
108
- copiedActor = Stage.json.fromJson(Actor.class, Stage.json.toJson(SceneEditor.selectedActor));
128
+ copiedActor = Scene.json.fromJson(Actor.class, Scene.json.toJson(SceneEditor.selectedActor));
109
129
  Content.studioPanel.setName(copiedActor);
110
130
  }
131
+ Scene.isDirty = true;
111
132
  break;
112
133
 
113
134
  case "Delete":
135
+ if(list.getSelectedIndex() != -1){
114
- Stage.removeActor(Stage.findActor(list.getSelectedValue()));
136
+ Scene.getCurrentScene().removeActor(SceneEditor.selectedActor);
115
- StatusBar.updateSelected("None");
137
+ StatusBar.updateSelected("None");
138
+ if(contains(SceneEditor.selectedActor.getName()))
116
- listModel2.removeElement(list.getSelectedValue());
139
+ listModel2.removeElement(SceneEditor.selectedActor.getName());
140
+ Scene.isDirty = true;
141
+ }
117
142
  break;
118
143
  }
119
144
  unlock();
{Panel → src/gdxstudio/panel}/AssetPanel.java RENAMED
@@ -1,13 +1,8 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Style;
3
+
1
4
  import java.awt.Dimension;
2
- import java.awt.datatransfer.StringSelection;
3
- import java.awt.dnd.DnDConstants;
4
- import java.awt.dnd.DragGestureEvent;
5
- import java.awt.dnd.DragGestureListener;
6
5
  import java.awt.dnd.DragSource;
7
- import java.awt.dnd.DragSourceDragEvent;
8
- import java.awt.dnd.DragSourceDropEvent;
9
- import java.awt.dnd.DragSourceEvent;
10
- import java.awt.dnd.DragSourceListener;
11
6
  import java.awt.event.ActionEvent;
12
7
  import java.awt.event.ItemEvent;
13
8
  import java.awt.event.ItemListener;
@@ -17,12 +12,14 @@ import javax.swing.JList;
17
12
  import javax.swing.JPanel;
18
13
  import javax.swing.event.ListSelectionEvent;
19
14
 
15
+ import scene2d.Asset;
20
16
  import web.laf.lite.widget.CenterPanel;
21
17
 
22
- final public class AssetPanel extends BaseList implements DragSourceListener, DragGestureListener{
18
+ final public class AssetPanel extends BaseList {
23
19
  private static final long serialVersionUID = 1L;
24
20
 
25
- private static String[] comboText = new String[]{"Font", "Texture", "Animation", "Music", "Sound", "Particle"};
21
+ private static String[] comboText = new String[]{"Font", "Texture", "Animation", "Music", "Sound", "Particle",
22
+ "Model"};
26
23
  private static JComboBox<String> combo = new JComboBox<String>(comboText);
27
24
 
28
25
  String[] btns = new String[]{
@@ -39,8 +36,6 @@ final public class AssetPanel extends BaseList implements DragSourceListener, Dr
39
36
  pan.add(new CenterPanel(combo, false, true));
40
37
  add(pan);
41
38
  add(scrollPane);
42
- dragSource.addDragSourceListener(this);
43
- dragSource.createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_MOVE, this);
44
39
  combo.addItemListener(new ItemListener(){
45
40
  @Override
46
41
  public void itemStateChanged(ItemEvent e) {
@@ -72,6 +67,10 @@ final public class AssetPanel extends BaseList implements DragSourceListener, Dr
72
67
  // for(String names: Asset.musicMap.keys())
73
68
  // assetModel.addElement(names);
74
69
  // break;
70
+ case "Model":
71
+ for(Object names: Asset.modelMap.toArray())
72
+ listModel2.addElement(names.toString());
73
+ break;
75
74
  }
76
75
  }
77
76
 
@@ -80,42 +79,6 @@ final public class AssetPanel extends BaseList implements DragSourceListener, Dr
80
79
  this.setVisible(false);
81
80
  }
82
81
 
83
- @Override
84
- public void dragGestureRecognized(DragGestureEvent event) {
85
- StringSelection text = new StringSelection(combo.getSelectedItem().toString());
86
- dragSource.startDrag( event, DragSource.DefaultMoveDrop, text, this);
87
- }
88
-
89
- @Override
90
- public void dragDropEnd(DragSourceDropEvent arg0) {
91
- // TODO Auto-generated method stub
92
-
93
- }
94
-
95
- @Override
96
- public void dragEnter(DragSourceDragEvent arg0) {
97
- // TODO Auto-generated method stub
98
-
99
- }
100
-
101
- @Override
102
- public void dragExit(DragSourceEvent arg0) {
103
- // TODO Auto-generated method stub
104
-
105
- }
106
-
107
- @Override
108
- public void dragOver(DragSourceDragEvent arg0) {
109
- // TODO Auto-generated method stub
110
-
111
- }
112
-
113
- @Override
114
- public void dropActionChanged(DragSourceDragEvent arg0) {
115
- // TODO Auto-generated method stub
116
-
117
- }
118
-
119
82
  @Override
120
83
  public void valueChanged(ListSelectionEvent arg0) {
121
84
  // TODO Auto-generated method stub
{Panel → src/gdxstudio/panel}/BaseList.java RENAMED
@@ -1,3 +1,6 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Style;
3
+
1
4
  import java.awt.Dimension;
2
5
  import java.awt.event.ActionEvent;
3
6
  import java.awt.event.ActionListener;
@@ -10,7 +13,6 @@ import java.util.TreeSet;
10
13
  import javax.swing.AbstractListModel;
11
14
  import javax.swing.BorderFactory;
12
15
  import javax.swing.DefaultListModel;
13
- import javax.swing.JLabel;
14
16
  import javax.swing.JList;
15
17
  import javax.swing.JPanel;
16
18
  import javax.swing.JScrollPane;
@@ -22,11 +24,11 @@ import web.laf.lite.utils.UIUtils;
22
24
 
23
25
  public abstract class BaseList extends JPanel implements ListSelectionListener, ActionListener {
24
26
  private static final long serialVersionUID = 1L;
25
- protected JList<String> list;
27
+ public JList<String> list;
26
28
  protected DefaultListModel<String> listModel;
27
29
  protected SortedListModel listModel2;
28
30
  protected JScrollPane scrollPane;
29
- protected final JLabel header;
31
+ protected final Style.TitleButton header;
30
32
 
31
33
  BaseList(String title){
32
34
  super(new VerticalFlowLayout());
@@ -37,7 +39,7 @@ public abstract class BaseList extends JPanel implements ListSelectionListener,
37
39
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
38
40
  list.addListSelectionListener(this);
39
41
  UIUtils.setDecorateSelection(list, false);
40
- header = new Style.TitleLabel(title);
42
+ header = new Style.TitleButton(title, this);
41
43
  add(header);
42
44
  scrollPane = new JScrollPane(list);
43
45
  scrollPane.setPreferredSize(new Dimension(200, 175));
@@ -54,7 +56,7 @@ public abstract class BaseList extends JPanel implements ListSelectionListener,
54
56
  list = new JList<String>(listModel);
55
57
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
56
58
  list.addListSelectionListener(this);
57
- header = new Style.TitleLabel(title);
59
+ header = new Style.TitleButton(title, this);
58
60
  add(header);
59
61
  scrollPane = new JScrollPane(list);
60
62
  scrollPane.setPreferredSize(new Dimension(200, 175));
@@ -70,7 +72,7 @@ public abstract class BaseList extends JPanel implements ListSelectionListener,
70
72
  list = new JList<String>(items);
71
73
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
72
74
  list.addListSelectionListener(this);
73
- header = new Style.TitleLabel(title);
75
+ header = new Style.TitleButton(title, this);
74
76
  add(header);
75
77
  scrollPane = new JScrollPane(list);
76
78
  scrollPane.setPreferredSize(new Dimension(200, 175));
@@ -88,7 +90,7 @@ public abstract class BaseList extends JPanel implements ListSelectionListener,
88
90
  list = new JList<String>(listModel2);
89
91
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90
92
  list.addListSelectionListener(this);
91
- header = new Style.TitleLabel(title);
93
+ header = new Style.TitleButton(title, this);
92
94
  add(header);
93
95
  scrollPane = new JScrollPane(list);
94
96
  scrollPane.setPreferredSize(new Dimension(200, 175));
@@ -120,7 +122,7 @@ public abstract class BaseList extends JPanel implements ListSelectionListener,
120
122
 
121
123
  @Override
122
124
  public void actionPerformed(ActionEvent arg0) {
123
- scrollPane.setVisible(!scrollPane.isVisible());
125
+ setVisible(false);
124
126
  validate();
125
127
  repaint();
126
128
  }
{Panel → src/gdxstudio/panel}/BaseTable.java RENAMED
@@ -1,3 +1,6 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Style;
3
+
1
4
  import java.awt.Color;
2
5
  import java.awt.Component;
3
6
  import java.awt.Dimension;
@@ -28,6 +31,8 @@ import javax.swing.JTextField;
28
31
  import javax.swing.ListSelectionModel;
29
32
  import javax.swing.SpinnerNumberModel;
30
33
  import javax.swing.event.CellEditorListener;
34
+ import javax.swing.event.ChangeEvent;
35
+ import javax.swing.event.ChangeListener;
31
36
  import javax.swing.event.TableModelEvent;
32
37
  import javax.swing.event.TableModelListener;
33
38
  import javax.swing.table.DefaultTableCellRenderer;
@@ -58,7 +63,7 @@ public abstract class BaseTable extends JPanel implements ActionListener, TableM
58
63
  return false;
59
64
  }
60
65
  };
61
- protected final JTable table = new JTable(tableModel){
66
+ public final JTable table = new JTable(tableModel){
62
67
  private static final long serialVersionUID = 1L;
63
68
 
64
69
  public TableCellEditor getCellEditor(int row, int column)
@@ -184,6 +189,29 @@ public abstract class BaseTable extends JPanel implements ActionListener, TableM
184
189
  repaint();
185
190
  }
186
191
 
192
+
193
+ public SpinnerIntegerEditor createIntegerSpinner(final String key){
194
+ final SpinnerIntegerEditor editor = new SpinnerIntegerEditor();
195
+ editor.spinner.addChangeListener(new ChangeListener(){
196
+ @Override
197
+ public void stateChanged(ChangeEvent arg0) {
198
+ setProperty(key, editor.spinner.getValue().toString());
199
+ }
200
+ });
201
+ return editor;
202
+ }
203
+
204
+ public SpinnerFloatEditor createFloatSpinner(final String key){
205
+ final SpinnerFloatEditor editor = new SpinnerFloatEditor();
206
+ editor.spinner.addChangeListener(new ChangeListener(){
207
+ @Override
208
+ public void stateChanged(ChangeEvent arg0) {
209
+ setProperty(key, editor.spinner.getValue().toString());
210
+ }
211
+ });
212
+ return editor;
213
+ }
214
+
187
215
  public static JSpinner createSpinnerInteger(){
188
216
  JSpinner spinner = new JSpinner(new SpinnerNumberModel(new Integer(0), new Integer(-99999),
189
217
  new Integer(99999), new Integer(1)));
@@ -251,12 +279,12 @@ public abstract class BaseTable extends JPanel implements ActionListener, TableM
251
279
  }
252
280
 
253
281
  public static DefaultCellEditor createBooleanEditor(){
254
- return new DefaultCellEditor(new JComboBox<String>(new String[]{"false", "true"}));
282
+ return new DefaultCellEditor(createComboBox("false", "true"));
255
283
  }
256
284
 
257
285
  public static DefaultCellEditor createTouchableEditor(){
258
- return new DefaultCellEditor(new JComboBox<String>(new String[]{Touchable.enabled.toString()
286
+ return new DefaultCellEditor(createComboBox(Touchable.enabled.toString()
259
- , Touchable.disabled.toString(), Touchable.childrenOnly.toString()}));
287
+ , Touchable.disabled.toString(), Touchable.childrenOnly.toString()));
260
288
  }
261
289
 
262
290
  public static TableCellEditor createCheckBoxEditor(){
@@ -507,7 +535,8 @@ class SpinnerIntegerEditor extends AbstractCellEditor implements TableCellEditor
507
535
  // Prepares the spinner component and returns it.
508
536
  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
509
537
  int row, int column) {
510
- spinner.setValue((Integer)Integer.parseInt(value.toString()));
538
+ float f = (Float) Float.parseFloat(value.toString());
539
+ spinner.setValue((int) f);
511
540
  return spinner;
512
541
  }
513
542
 
{Panel → src/gdxstudio/panel}/ConsolePanel.java RENAMED
@@ -1,3 +1,10 @@
1
+ package gdxstudio.panel;
2
+
3
+ import gdxstudio.Content;
4
+ import gdxstudio.GdxStudio;
5
+ import gdxstudio.StatusBar;
6
+ import gdxstudio.Style;
7
+
1
8
  import java.awt.Color;
2
9
  import java.awt.Dimension;
3
10
  import java.awt.Insets;
@@ -20,6 +27,8 @@ import javax.swing.SwingUtilities;
20
27
 
21
28
 
22
29
 
30
+
31
+
23
32
  import web.laf.lite.layout.VerticalFlowLayout;
24
33
  import web.laf.lite.utils.UIUtils;
25
34
 
@@ -42,7 +51,7 @@ public class ConsolePanel extends JPanel implements ActionListener {
42
51
  UIUtils.setFontName(consoleArea, Content.editor.getFont().getFontName());
43
52
  UIUtils.setMargin(this, new Insets(0,0,0,0));
44
53
  UIUtils.setUndecorated(this, true);
45
- consoleAreaPane.setPreferredSize(new Dimension(500, 250));
54
+ consoleAreaPane.setPreferredSize(new Dimension(500, 200));
46
55
  add(new Style.TitleButton("Console", this));
47
56
  setVisible(false);
48
57
  add(consoleAreaPane);
@@ -52,7 +61,7 @@ public class ConsolePanel extends JPanel implements ActionListener {
52
61
 
53
62
  public static void updateCompiler(){
54
63
  String filename = ConsolePanel.class.getProtectionDomain().getCodeSource().getLocation().getFile();
55
- Main.log(filename);
64
+ GdxStudio.log(filename);
56
65
  if(filename.endsWith(".jar"))
57
66
  classPath = filename;
58
67
  else
@@ -125,15 +134,15 @@ public class ConsolePanel extends JPanel implements ActionListener {
125
134
  public void write(byte[] b, int off, int len) throws IOException {
126
135
  errString = new String(b, off, len);
127
136
  consoleArea.setText("");
128
- Main.log(errString);
137
+ GdxStudio.log(errString);
129
138
  for(String line: errString.split(System.lineSeparator())){
130
- if(line.contains(Content.getSceneFile()) && line.contains("warning")){
139
+ if(line.contains("warning")){
131
140
  String[] warningLine = line.split(":");
132
141
  warningCount++;
133
142
  Content.editor.addWarning(Integer.parseInt(warningLine[warningLine.length-3]),
134
143
  warningLine[warningLine.length-1]);
135
144
  }
136
- if(line.contains(Content.getSceneFile()) && line.contains("error")){
145
+ if(line.contains("error")){
137
146
  String[] errorLine = line.split(":");
138
147
  errorCount++;
139
148
  Content.editor.addError(Integer.parseInt(errorLine[errorLine.length-3]),
@@ -164,7 +173,8 @@ public class ConsolePanel extends JPanel implements ActionListener {
164
173
  }
165
174
  });
166
175
 
167
- public static void compile() {
176
+ public static void compile(final String file) {
177
+ clear();
168
178
  Content.editor.clearIcons();
169
179
  StatusBar.error.setForeground(Color.black);
170
180
  StatusBar.error.setText("Errors");
@@ -172,7 +182,27 @@ public class ConsolePanel extends JPanel implements ActionListener {
172
182
  StatusBar.warning.setText("Warnings");
173
183
  errorCount = 0;
174
184
  warningCount = 0;
185
+ consoleArea.append("Compiling... "+file+".java"+System.lineSeparator());
175
- final String buildArgs = Content.getProject()+"source/"+ Content.getSceneFile()+".java"
186
+ final String buildArgs = Content.getProject()+"source/"+ file+".java"
187
+ +" -cp "+classPath
188
+ +" -d "+Content.getProject()+"bin"
189
+ +" -1.7"
190
+ +" -Xemacs";
191
+ Thread t = new Thread(new Runnable(){
192
+ @Override
193
+ public void run() {
194
+ BatchCompiler.compile(buildArgs, compilerWriter, compilerWriter, prog);
195
+ consoleArea.append("Finished Compiling... "+file+".java"+System.lineSeparator());
196
+ System.gc();
197
+ }
198
+ });
199
+ t.start();
200
+ }
201
+
202
+ public static void build() {
203
+ clear();
204
+ consoleArea.append("Building.. "+Content.getProject()+System.lineSeparator());
205
+ final String buildArgs = Content.getProject()+"source/"
176
206
  +" -cp "+classPath
177
207
  +" -d "+Content.getProject()+"bin"
178
208
  +" -1.7"
@@ -181,6 +211,7 @@ public class ConsolePanel extends JPanel implements ActionListener {
181
211
  @Override
182
212
  public void run() {
183
213
  BatchCompiler.compile(buildArgs, compilerWriter, compilerWriter, prog);
214
+ System.gc();
184
215
  }
185
216
  });
186
217
  t.start();
src/gdxstudio/panel/DPanel.java ADDED
@@ -0,0 +1,30 @@
1
+ package gdxstudio.panel;
2
+ import java.io.File;
3
+
4
+ import javax.swing.JTree;
5
+ import javax.swing.tree.DefaultMutableTreeNode;
6
+ import javax.swing.tree.DefaultTreeModel;
7
+
8
+ import scene2d.Asset;
9
+
10
+ public class DPanel extends JTree {
11
+ private static final long serialVersionUID = 1L;
12
+ DefaultTreeModel treeModel;
13
+ DefaultMutableTreeNode root;
14
+ DefaultMutableTreeNode atlas;
15
+ DefaultMutableTreeNode font;
16
+ DefaultMutableTreeNode music;
17
+ DefaultMutableTreeNode sound;
18
+ DefaultMutableTreeNode model;
19
+ DefaultMutableTreeNode skin;
20
+
21
+ DPanel() {
22
+ root = new DefaultMutableTreeNode();
23
+ treeModel = new DefaultTreeModel(root);
24
+
25
+ for(File file: new File(Asset.basePath+"font").listFiles())
26
+ root.add(new DefaultMutableTreeNode(file.getName()));
27
+ }
28
+
29
+
30
+ }
{Panel → src/gdxstudio/panel}/DashPanel.java RENAMED
@@ -1,6 +1,14 @@
1
+ package gdxstudio.panel;
2
+
3
+ import gdxstudio.Content;
4
+ import gdxstudio.Icon;
5
+ import gdxstudio.SceneEditor;
6
+ import gdxstudio.Style;
7
+
1
8
  import java.awt.AWTException;
2
9
  import java.awt.Color;
3
10
  import java.awt.Dimension;
11
+ import java.awt.Image;
4
12
  import java.awt.Rectangle;
5
13
  import java.awt.Robot;
6
14
  import java.awt.image.BufferedImage;
@@ -25,8 +33,10 @@ public class DashPanel extends JPanel {
25
33
 
26
34
  public DashPanel(){
27
35
  super(new VerticalFlowLayout());
36
+ UIUtils.setUndecorated(this, true);
28
37
  UIUtils.setShadeWidth(this, 0);
29
38
  UIUtils.setRound(this, 0);
39
+ UIUtils.setDrawSides(this, false, false, false, false);
30
40
  setBackground(Color.black);
31
41
  add(new Style.TitleButton("DashBoard", null));
32
42
  label = new JLabel();
@@ -50,7 +60,7 @@ public class DashPanel extends JPanel {
50
60
  }
51
61
 
52
62
  public void update(){
53
- screenRect.x = 210+(int)SceneEditor.selectedActor.getX();
63
+ screenRect.x = Content.studioPanel.getLocationOnScreen().x+(int)SceneEditor.selectedActor.getX();
54
64
  screenRect.y = Gdx.graphics.getHeight()-(int)SceneEditor.selectedActor.getY()-15;
55
65
  screenRect.width = (int)SceneEditor.selectedActor.getWidth();
56
66
  screenRect.height = (int)SceneEditor.selectedActor.getHeight();
@@ -62,7 +72,7 @@ public class DashPanel extends JPanel {
62
72
  screenRect.y -= (100 - DashPanel.screenRect.height)/4;
63
73
  screenRect.height = 100;
64
74
  }
65
- setIcon(DashPanel.robot.createScreenCapture(screenRect));
75
+ setIcon(robot.createScreenCapture(screenRect).getScaledInstance(200, 100, Image.SCALE_DEFAULT));
66
76
  }
67
77
 
68
78
  public void setIcon(String iconname){
@@ -73,6 +83,10 @@ public class DashPanel extends JPanel {
73
83
  label.setIcon(new ImageIcon(image));
74
84
  }
75
85
 
86
+ public void setIcon(Image image){
87
+ label.setIcon(new ImageIcon(image));
88
+ }
89
+
76
90
  public void setTextureRegion(String texName){
77
91
  }
78
92
  }
{Panel → src/gdxstudio/panel}/EffectPanel.java RENAMED
@@ -1,6 +1,14 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.SceneEditor;
3
+
1
4
  import javax.swing.DefaultCellEditor;
2
5
  import javax.swing.JComboBox;
3
6
 
7
+ import scene2d.Effect;
8
+ import scene2d.EffectType;
9
+ import scene2d.ImageJson;
10
+ import scene2d.InterpolationType;
11
+ import scene2d.Scene;
4
12
  import web.laf.lite.utils.UIUtils;
5
13
 
6
14
 
@@ -67,7 +75,7 @@ public class EffectPanel extends BaseTable {
67
75
  case "Interpolation":img.interpolationType = InterpolationType.valueOf(value);break;
68
76
  }
69
77
  Effect.createEffect(img);
70
- SceneEditor.isDirty = true;
78
+ Scene.isDirty = true;
71
79
  }
72
80
  }
73
81
  }
{Panel → src/gdxstudio/panel}/EventPanel.java RENAMED
@@ -1,6 +1,13 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.SceneEditor;
3
+
1
4
  import javax.swing.DefaultCellEditor;
2
5
  import javax.swing.JComboBox;
3
6
 
7
+ import scene2d.EventType;
8
+ import scene2d.ImageJson;
9
+ import scene2d.Scene;
10
+
4
11
  public class EventPanel extends BaseTable {
5
12
  private static final long serialVersionUID = 1L;
6
13
 
@@ -15,7 +22,7 @@ public class EventPanel extends BaseTable {
15
22
  editors.add(new DefaultCellEditor(sceneComboBox));
16
23
  for(EventType event: EventType.values())
17
24
  eventComboBox.addItem(event.toString());
18
- for(OnEventType onEvent: OnEventType.values())
25
+ for(Scene.OnEventType onEvent: Scene.OnEventType.values())
19
26
  onEventComboBox.addItem(onEvent.toString());
20
27
  for(String scene: Scene.scenesMap.keys())
21
28
  sceneComboBox.addItem(scene);
@@ -54,7 +61,7 @@ public class EventPanel extends BaseTable {
54
61
  onEventComboBox.setEnabled(false);
55
62
  }
56
63
  else if(img.evtType == EventType.SceneCreated){
57
- onEventComboBox.setSelectedItem(OnEventType.DoEffect.toString());
64
+ onEventComboBox.setSelectedItem(Scene.OnEventType.DoEffect.toString());
58
65
  onEventComboBox.setEnabled(false);
59
66
  }
60
67
  else{
@@ -63,8 +70,8 @@ public class EventPanel extends BaseTable {
63
70
 
64
71
  break;
65
72
  case "onEvent":
66
- img.onEvtType = OnEventType.valueOf(value);
73
+ img.onEvtType = Scene.OnEventType.valueOf(value);
67
- if(img.onEvtType == OnEventType.DoEffect){
74
+ if(img.onEvtType == Scene.OnEventType.DoEffect){
68
75
  sceneComboBox.setEnabled(false);
69
76
  }
70
77
  else{
@@ -73,7 +80,7 @@ public class EventPanel extends BaseTable {
73
80
  break;
74
81
  case "Scene": img.eventScene = value;break;
75
82
  }
76
- SceneEditor.isDirty = true;
83
+ Scene.isDirty = true;
77
84
  }
78
85
  }
79
86
  }
src/gdxstudio/panel/MapPanel.java ADDED
@@ -0,0 +1,16 @@
1
+ package gdxstudio.panel;
2
+ import javax.swing.event.ListSelectionEvent;
3
+
4
+
5
+ public class MapPanel extends BaseList {
6
+
7
+ MapPanel() {
8
+ super("");
9
+ }
10
+
11
+ private static final long serialVersionUID = 1L;
12
+
13
+ @Override
14
+ public void valueChanged(ListSelectionEvent arg0) {
15
+ }
16
+ }
{Panel → src/gdxstudio/panel}/OptionsPanel.java RENAMED
@@ -1,19 +1,22 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Content;
3
+ import gdxstudio.Editor;
4
+ import gdxstudio.Frame;
5
+ import gdxstudio.Icon;
6
+ import gdxstudio.Style;
7
+
1
8
  import java.awt.Component;
2
9
  import java.awt.Font;
3
10
  import java.awt.event.ActionEvent;
4
11
  import java.awt.event.ActionListener;
5
- import java.io.File;
6
12
 
7
13
  import javax.swing.BorderFactory;
8
- import javax.swing.JButton;
9
14
  import javax.swing.JComboBox;
10
15
  import javax.swing.JLabel;
11
- import javax.swing.JOptionPane;
12
16
  import javax.swing.JPanel;
17
+ import javax.swing.JToggleButton;
13
18
  import javax.swing.SpringLayout;
14
-
15
- import com.badlogic.gdx.tools.imagepacker.TexturePacker2;
19
+ import javax.swing.SwingConstants;
16
- import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings;
17
20
 
18
21
  import web.laf.lite.layout.HorizontalFlowLayout;
19
22
  import web.laf.lite.layout.ToolbarLayout;
@@ -21,6 +24,8 @@ import web.laf.lite.layout.VerticalFlowLayout;
21
24
  import web.laf.lite.popup.AlignPanel;
22
25
  import web.laf.lite.utils.SpringUtils;
23
26
  import web.laf.lite.utils.UIUtils;
27
+ import web.laf.lite.widget.Register;
28
+ import web.laf.lite.widget.WebButtonGroup;
24
29
  import web.laf.lite.widget.WebSwitch;
25
30
 
26
31
  public class OptionsPanel extends JPanel implements ActionListener {
@@ -37,8 +42,6 @@ public class OptionsPanel extends JPanel implements ActionListener {
37
42
 
38
43
  JPanel conten5Border = new JPanel(new VerticalFlowLayout());
39
44
  JPanel content5 = new JPanel(new SpringLayout());
40
-
41
- JButton packButton;
42
45
 
43
46
  public OptionsPanel(){
44
47
  super(new VerticalFlowLayout(0, 10));
@@ -160,28 +163,7 @@ public class OptionsPanel extends JPanel implements ActionListener {
160
163
  SpringUtils.makeCompactGrid(content5, 6, 4, 10, 0, 10, 5);
161
164
  conten5Border.add(content5);
162
165
  add(conten5Border);
163
-
164
- packButton = new JButton("Pack All Textures");
165
- packButton.addActionListener(new ActionListener(){
166
- @Override
167
- public void actionPerformed(ActionEvent arg0) {
168
- Settings settings = new Settings();
169
- settings.maxWidth = 2048;
170
- settings.maxHeight = 2048;
171
- settings.paddingX = 0;
172
- settings.paddingY = 0;
173
- TexturePacker2.process(settings, Content.getProject()+File.separator+"pack",
174
- Content.getProject()+"atlas/", "pack.atlas");
175
- for(File f: new File(Content.getProject()+File.separator+"pack").listFiles()){
176
- if(f.isDirectory()){
166
+ initStyle();
177
- TexturePacker2.process(settings, f.getPath(), Content.getProject()+"atlas/", f.getName());
178
- JOptionPane.showMessageDialog(null, "Packed Texture: "+f.getName(), "Texture Packer",
179
- JOptionPane.INFORMATION_MESSAGE);
180
- }
181
- }
182
- }
183
- });
184
- add(packButton);
185
167
  // add(menuItem(tabSlider, "Tab Size"));
186
168
  //setMarginLineColor(Color.black);
187
169
  //setMarkOccurrences(true);
@@ -257,13 +239,60 @@ public class OptionsPanel extends JPanel implements ActionListener {
257
239
  }
258
240
 
259
241
  void createHeader(JPanel content, String title){
260
- //content.setBackground(Color.white);
261
242
  content.add(new Style.TitleLabel(title));
262
243
  content.setBorder(BorderFactory.createLineBorder(Style.border));
263
244
  }
245
+
246
+ void createHeader(JPanel content, String title, String icon){
247
+ content.add(new Style.TitleLabel(title, icon));
248
+ content.setBorder(BorderFactory.createLineBorder(Style.border));
249
+ }
250
+
251
+ void initStyle(){
252
+ JPanel vert = new JPanel(new VerticalFlowLayout());
253
+ createHeader(vert, "Styles");
254
+ ThemeButton[] themeButtons = {
255
+ createThemeItem("IntelliJ IDEA", "idea"),
256
+ createThemeItem("Dark", "dark"),
257
+ createThemeItem("Visual Studio", "vs"),
258
+ createThemeItem("Eclipse", "eclipse")
259
+ };
260
+ WebButtonGroup themeGroup = new WebButtonGroup(WebButtonGroup.HORIZONTAL, true, themeButtons);
261
+ themeGroup.setButtonsDrawFocus(false);
262
+ themeGroup.setButtonsDrawFocus(false);
263
+ vert.add(themeGroup);
264
+ add(vert);
265
+ }
266
+
267
+ ThemeButton createThemeItem(String title, String iconname){
268
+ final ThemeButton themeButton = new ThemeButton(title, iconname);
269
+ if(Register.getTheme().equals(iconname))
270
+ themeButton.setSelected(true);
271
+ themeButton .addActionListener (new ActionListener (){
272
+ public void actionPerformed (ActionEvent e){
273
+ Register.setTheme(themeButton.iconame);
274
+ Content.theme = Icon.loadTheme(themeButton.iconame);
275
+ Content.theme.apply(Content.editor);
276
+ }
277
+ });
278
+ return themeButton;
279
+ }
264
280
 
265
281
  @Override
266
282
  public void actionPerformed(ActionEvent e) {
267
283
  setVisible(false);
268
284
  }
269
285
  }
286
+
287
+
288
+ final class ThemeButton extends JToggleButton{
289
+ private static final long serialVersionUID = 1L;
290
+ String iconame;
291
+ ThemeButton(String text, String ic){
292
+ super(text, Icon.icon(ic));
293
+ iconame = ic;
294
+ setVerticalTextPosition(SwingConstants.BOTTOM);
295
+ setHorizontalTextPosition(SwingConstants.CENTER);
296
+ setFocusable(false);
297
+ }
298
+ }
{Panel → src/gdxstudio/panel}/ProjectPanel.java RENAMED
@@ -1,3 +1,9 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Content;
3
+ import gdxstudio.Frame;
4
+ import gdxstudio.Icon;
5
+ import gdxstudio.Style;
6
+
1
7
  import java.awt.Color;
2
8
  import java.awt.Dimension;
3
9
  import java.awt.Insets;
@@ -23,9 +29,6 @@ import javax.swing.event.TableModelListener;
23
29
  import javax.swing.table.DefaultTableModel;
24
30
  import javax.swing.table.TableCellEditor;
25
31
 
26
- import com.badlogic.gdx.utils.JsonReader;
27
- import com.badlogic.gdx.utils.JsonValue;
28
-
29
32
  import web.laf.lite.layout.HorizontalFlowLayout;
30
33
  import web.laf.lite.layout.VerticalFlowLayout;
31
34
  import web.laf.lite.utils.UIUtils;
@@ -183,102 +186,4 @@ public class ProjectPanel extends JPanel implements ActionListener, TableModelLi
183
186
  public void actionPerformed(ActionEvent e) {
184
187
  propTable.setVisible(!propTable.isVisible());
185
188
  }
186
- }
187
-
188
- class ProjectSettingsPanel extends BaseTable {
189
- private static final long serialVersionUID = 1L;
190
- String[] screenSizes = {
191
- "320x240", "480x320", "800x480", "852x480", "960x540", "1280x720", "1980x1080", "860x650"
192
- };
193
- String[] targetSizes = {
194
- "800x480"
195
- };
196
- JComboBox<String> screenCombo = createComboBox(screenSizes);
197
- JComboBox<String> targetCombo = createComboBox(targetSizes);
198
-
199
- ProjectSettingsPanel(){
200
- super("Settings");
201
- editors.add(createTextFieldEditor());
202
- editors.add(new DefaultCellEditor(targetCombo));
203
- editors.add(new DefaultCellEditor(screenCombo));
204
- editors.add(createNumberField());
205
- editors.add(createCheckBoxEditor());
206
- editors.add(createCheckBoxEditor());
207
- editors.add(createCheckBoxEditor());
208
- editors.add(createCheckBoxEditor());
209
- editors.add(createCheckBoxEditor());
210
- editors.add(createCheckBoxEditor());
211
- editors.add(createCheckBoxEditor());
212
- editors.add(createCheckBoxEditor());
213
- editors.add(createCheckBoxEditor());
214
- editors.add(createCheckBoxEditor());
215
- editors.add(createCheckBoxEditor());
216
- if(Content.projectExists())
217
- update();
218
- }
219
-
220
- @Override
221
- public void clear(String... items){
222
- super.clear("", "" ,"" ,"" ,"", "", "", "", "", "", "", "", "");
223
- }
224
-
225
- private static JsonValue jsonValue;
226
- JsonReader jsonReader = new JsonReader();
227
- @Override
228
- public void update(String... items){
229
- super.update();
230
- String text = Export.readFile("config");
231
- if(text.isEmpty())
232
- return;
233
- jsonValue = jsonReader.parse(text);
234
- addRow("Title", jsonValue.getString("title"));
235
- addRow("TargetSize", jsonValue.getString("targetSize"));
236
- addRow("ScreenSize", jsonValue.getString("screenSize"));
237
- addRow("AudioBufferCount", jsonValue.getString("audioBufferCount"));
238
- addRow("Resize", jsonValue.getBoolean("resize"));
239
- addRow("ForceExit", jsonValue.getBoolean("forceExit"));
240
- addRow("FullScreen", jsonValue.getBoolean("fullScreen"));
241
- addRow("UseGL20", jsonValue.getBoolean("useGL20"));
242
- addRow("VSync", jsonValue.getBoolean("vSync"));
243
- addRow("DisableAudio", jsonValue.getBoolean("disableAudio"));
244
- addRow("KeepAspectRatio", jsonValue.getBoolean("keepAspectRatio"));
245
- addRow("ShowFPS", jsonValue.getBoolean("showFPS"));
246
- addRow("LoggingEnabled", jsonValue.getBoolean("loggingEnabled"));
247
- ProjectPanel.updateProperty("Version", jsonValue.getString("version"));
248
- ProjectPanel.updateProperty("Target", jsonValue.getString("target"));
249
- /*createRow(content3, "Use Accelerometer", new WebSwitch());
250
- createRow(content3, "Use Compass", new WebSwitch());
251
- createRow(content3, "Use WakeLock", new WebSwitch());
252
- createRow(content3, "Hide Status Bar", new WebSwitch());*/
253
- }
254
-
255
- @Override
256
- public void setProperty(String key, String value) {
257
- if(key.isEmpty() && value.isEmpty()){
258
- return;
259
- }
260
- jsonValue.get("hasIcon").set(new File(Content.getProject()+"icon.png").exists());
261
- jsonValue.get(Stage.uncapitalize(key)).set(value);
262
- Export.writeFile("config", jsonValue.toString());
263
- }
264
-
265
- public void updateVersion(String version){
266
- jsonValue.get("version").set(version);
267
- Export.writeFile("config", jsonValue.toString());
268
- }
269
-
270
- public void updateTarget(String target){
271
- jsonValue.get("target").set(target);
272
- Export.writeFile("config", jsonValue.toString());
273
- }
274
-
275
- static String jsonizeArray(Object[] array){
276
- StringBuilder sb = new StringBuilder();
277
- for(Object s: array){
278
- sb.append(s.toString().trim());
279
- sb.append(",");
280
- }
281
- sb.deleteCharAt(sb.lastIndexOf(","));
282
- return sb.toString();
283
- }
284
189
  }
src/gdxstudio/panel/ProjectSettingsPanel.java ADDED
@@ -0,0 +1,121 @@
1
+ package gdxstudio.panel;
2
+
3
+ import gdxstudio.Content;
4
+ import gdxstudio.Export;
5
+
6
+ import java.awt.event.ItemEvent;
7
+ import java.awt.event.ItemListener;
8
+ import java.io.File;
9
+
10
+ import javax.swing.DefaultCellEditor;
11
+ import javax.swing.JComboBox;
12
+
13
+ import scene2d.Scene;
14
+
15
+ import com.badlogic.gdx.utils.JsonReader;
16
+ import com.badlogic.gdx.utils.JsonValue;
17
+
18
+ public class ProjectSettingsPanel extends BaseTable {
19
+ private static final long serialVersionUID = 1L;
20
+ String[] screenSizes = {
21
+ "320x240", "480x320", "800x480", "852x480", "960x540", "1280x720", "1980x1080"
22
+ };
23
+ String[] targetSizes = {
24
+ "800x480"
25
+ };
26
+ JComboBox<String> screenCombo = createComboBox(screenSizes);
27
+ JComboBox<String> targetCombo = createComboBox(targetSizes);
28
+
29
+ public ProjectSettingsPanel(){
30
+ super("Settings");
31
+ editors.add(createTextFieldEditor());
32
+ editors.add(new DefaultCellEditor(targetCombo));
33
+ editors.add(new DefaultCellEditor(screenCombo));
34
+ editors.add(createNumberField());
35
+ editors.add(createCheckBoxEditor());
36
+ editors.add(createCheckBoxEditor());
37
+ editors.add(createCheckBoxEditor());
38
+ editors.add(createCheckBoxEditor());
39
+ editors.add(createCheckBoxEditor());
40
+ editors.add(createCheckBoxEditor());
41
+ editors.add(createCheckBoxEditor());
42
+ editors.add(createCheckBoxEditor());
43
+ editors.add(createCheckBoxEditor());
44
+ editors.add(createCheckBoxEditor());
45
+ editors.add(createCheckBoxEditor());
46
+ if(Content.projectExists())
47
+ update();
48
+ screenCombo.addItemListener(new ItemListener(){
49
+ @Override
50
+ public void itemStateChanged(ItemEvent e) {
51
+ //String val[] = screenCombo.getSelectedItem().toString().split("x");
52
+ //Content.studioPanel.setGdxScreenSize(Integer.parseInt(val[0]), Integer.parseInt(val[1]));
53
+ }
54
+ });
55
+ }
56
+
57
+ @Override
58
+ public void clear(String... items){
59
+ super.clear("", "" ,"" ,"" ,"", "", "", "", "", "", "", "", "");
60
+ }
61
+
62
+ private static JsonValue jsonValue;
63
+ JsonReader jsonReader = new JsonReader();
64
+ @Override
65
+ public void update(String... items){
66
+ super.update();
67
+ String text = Export.readFile("config");
68
+ if(text.isEmpty())
69
+ return;
70
+ jsonValue = jsonReader.parse(text);
71
+ addRow("Title", jsonValue.getString("title"));
72
+ addRow("TargetSize", jsonValue.getString("targetSize"));
73
+ addRow("ScreenSize", jsonValue.getString("screenSize"));
74
+ addRow("AudioBufferCount", jsonValue.getString("audioBufferCount"));
75
+ addRow("Resize", jsonValue.getBoolean("resize"));
76
+ addRow("ForceExit", jsonValue.getBoolean("forceExit"));
77
+ addRow("FullScreen", jsonValue.getBoolean("fullScreen"));
78
+ addRow("UseGL20", jsonValue.getBoolean("useGL20"));
79
+ addRow("VSync", jsonValue.getBoolean("vSync"));
80
+ addRow("DisableAudio", jsonValue.getBoolean("disableAudio"));
81
+ addRow("KeepAspectRatio", jsonValue.getBoolean("keepAspectRatio"));
82
+ addRow("ShowFPS", jsonValue.getBoolean("showFPS"));
83
+ addRow("LoggingEnabled", jsonValue.getBoolean("loggingEnabled"));
84
+ ProjectPanel.updateProperty("Version", jsonValue.getString("version"));
85
+ ProjectPanel.updateProperty("Target", jsonValue.getString("target"));
86
+ /*createRow(content3, "Use Accelerometer", new WebSwitch());
87
+ createRow(content3, "Use Compass", new WebSwitch());
88
+ createRow(content3, "Use WakeLock", new WebSwitch());
89
+ createRow(content3, "Hide Status Bar", new WebSwitch());*/
90
+ }
91
+
92
+ @Override
93
+ public void setProperty(String key, String value) {
94
+ if(key.isEmpty() && value.isEmpty()){
95
+ return;
96
+ }
97
+ jsonValue.get("hasIcon").set(new File(Content.getProject()+"icon.png").exists());
98
+ jsonValue.get(Scene.uncapitalize(key)).set(value);
99
+ Export.writeFile("config", jsonValue.toString());
100
+ }
101
+
102
+ public void updateVersion(String version){
103
+ jsonValue.get("version").set(version);
104
+ Export.writeFile("config", jsonValue.toString());
105
+ }
106
+
107
+ public void updateTarget(String target){
108
+ jsonValue.get("target").set(target);
109
+ Export.writeFile("config", jsonValue.toString());
110
+ }
111
+
112
+ static String jsonizeArray(Object[] array){
113
+ StringBuilder sb = new StringBuilder();
114
+ for(Object s: array){
115
+ sb.append(s.toString().trim());
116
+ sb.append(",");
117
+ }
118
+ sb.deleteCharAt(sb.lastIndexOf(","));
119
+ return sb.toString();
120
+ }
121
+ }
{Panel → src/gdxstudio/panel}/PropertyPanel.java RENAMED
@@ -1,3 +1,7 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Frame;
3
+ import gdxstudio.SceneEditor;
4
+
1
5
  import java.awt.Component;
2
6
  import java.awt.Insets;
3
7
 
@@ -6,9 +10,12 @@ import javax.swing.DefaultCellEditor;
6
10
  import javax.swing.JComboBox;
7
11
  import javax.swing.JPanel;
8
12
  import javax.swing.JTable;
9
- import javax.swing.event.ChangeEvent;
10
- import javax.swing.event.ChangeListener;
11
13
 
14
+ import scene2d.Asset;
15
+ import scene2d.ImageJson;
16
+ import scene2d.Scene;
17
+ import scene2d.Serializer;
18
+ import scene2d.Sprite;
12
19
  import web.laf.lite.layout.ToolbarLayout;
13
20
  import web.laf.lite.utils.UIUtils;
14
21
 
@@ -52,17 +59,6 @@ public class PropertyPanel extends BaseTable {
52
59
  editors.add(createTextFieldEditor());
53
60
  }
54
61
 
55
- public SpinnerIntegerEditor createIntegerSpinner(final String key){
56
- final SpinnerIntegerEditor editor = new SpinnerIntegerEditor();
57
- editor.spinner.addChangeListener(new ChangeListener(){
58
- @Override
59
- public void stateChanged(ChangeEvent arg0) {
60
- setProperty(key, editor.spinner.getValue().toString());
61
- }
62
- });
63
- return editor;
64
- }
65
-
66
62
  @Override
67
63
  public void clear(String... names){
68
64
  super.clear("Name", "X", "Y", "Width", "Height", "OriginX", "OriginY", "Rotation", "Z-Index", "Color", "Touchable", "Visible", "", "", "", "");
@@ -71,11 +67,11 @@ public class PropertyPanel extends BaseTable {
71
67
  @Override
72
68
  public void update(String... names){
73
69
  rowCount = 0;
74
- super.update("Name", ""+SceneEditor.selectedActor.getName(), "X", ""+(int)SceneEditor.selectedActor.getX(),
70
+ super.update("Name", ""+SceneEditor.selectedActor.getName(), "X", ""+SceneEditor.selectedActor.getX(),
75
- "Y", ""+(int)SceneEditor.selectedActor.getY(), "Width", ""+(int)SceneEditor.selectedActor.getWidth(),
71
+ "Y", ""+SceneEditor.selectedActor.getY(), "Width", ""+SceneEditor.selectedActor.getWidth(),
76
- "Height", ""+(int)SceneEditor.selectedActor.getHeight(), "OriginX",""+(int)SceneEditor.selectedActor.getOriginX(),
72
+ "Height", ""+SceneEditor.selectedActor.getHeight(), "OriginX",""+SceneEditor.selectedActor.getOriginX(),
77
- "OriginY",""+(int)SceneEditor.selectedActor.getOriginY(),"Rotation",""+(int)SceneEditor.selectedActor.getRotation(),
73
+ "OriginY",""+SceneEditor.selectedActor.getOriginY(),"Rotation",""+SceneEditor.selectedActor.getRotation(),
78
- "Z-Index", ""+(int)SceneEditor.selectedActor.getZIndex(),
74
+ "Z-Index", ""+SceneEditor.selectedActor.getZIndex(),
79
75
  "Color", ""+SceneEditor.selectedActor.getColor().toString(),
80
76
  "Touchable", ""+SceneEditor.selectedActor.getTouchable().toString(),
81
77
  "Visible", ""+SceneEditor.selectedActor.isVisible()
@@ -159,7 +155,7 @@ public class PropertyPanel extends BaseTable {
159
155
  return ;
160
156
  switch(key){
161
157
  case "Name":
162
- for(Actor actor: Stage.getChildren())
158
+ for(Actor actor: Scene.getCurrentScene().getChildren())
163
159
  if(actor != null)
164
160
  if(actor.getName() != null)
165
161
  if(actor.getName().equals(value)){
@@ -179,10 +175,10 @@ public class PropertyPanel extends BaseTable {
179
175
  case "Rotation": SceneEditor.selectedActor.setRotation(Float.parseFloat(value));break;
180
176
  case "Z-Index":
181
177
  int z = Integer.parseInt(value);
182
- if(!(z<0) && !(z>Stage.getRoot().getChildren().size))
178
+ if(z>0 && z<Scene.getCurrentScene().getChildren().size){
183
179
  SceneEditor.selectedActor.setZIndex(z);
184
- else
180
+ }
185
- updateProperty("Z-Index", ""+SceneEditor.selectedActor.getZIndex(), 0);
181
+ //updateProperty("Z-Index", ""+SceneEditor.selectedActor.getZIndex(), 0);
186
182
  break;
187
183
  case "Color":
188
184
  if(value.length() == 8 && value.matches("[0-9A-Fa-f]+"))
@@ -250,8 +246,8 @@ public class PropertyPanel extends BaseTable {
250
246
  else
251
247
  newimg.setZIndex(img.getZIndex());
252
248
  newimg.setColor(img.getColor());
253
- Stage.removeActor(img);
249
+ Scene.getCurrentScene().removeActor(img);
254
- Stage.addActor(newimg);
250
+ Scene.getCurrentScene().addActor(newimg);
255
251
  newimg.pack();
256
252
  SceneEditor.selectedActor = newimg;
257
253
  break;
@@ -279,8 +275,8 @@ public class PropertyPanel extends BaseTable {
279
275
  ((Sprite)SceneEditor.selectedActor).isAnimationLooping = Boolean.parseBoolean(value);
280
276
  break;
281
277
  }
282
- SceneEditor.isDirty = true;
278
+ Scene.isDirty = true;
283
- Stage.outline(SceneEditor.selectedActor);
279
+ Scene.getCurrentScene().outline(SceneEditor.selectedActor);
284
280
  Frame.dashPanel.update();
285
281
  }
286
282
 
@@ -311,7 +307,7 @@ class PropertyRenderer extends BaseRenderer {
311
307
  return checkBox;
312
308
  }*/
313
309
  //try {
314
- Boolean.parseBoolean(value.toString());
310
+ // Boolean.parseBoolean(value.toString());
315
311
  // } catch ( java.text.ParseException e ) {
316
312
  // e.printStackTrace();
317
313
  // }
{Panel → src/gdxstudio/panel}/ReplacePanel.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio.panel;
1
2
  import javax.swing.JButton;
2
3
  import javax.swing.JLabel;
3
4
  import javax.swing.JPanel;
{Panel → src/gdxstudio/panel}/SceneEffectPanel.java RENAMED
@@ -1,35 +1,33 @@
1
+ package gdxstudio.panel;
2
+
3
+ import java.awt.Component;
1
4
  import javax.swing.DefaultCellEditor;
2
5
  import javax.swing.JComboBox;
6
+ import javax.swing.JTable;
7
+
8
+ import scene2d.Asset;
9
+ import scene2d.Effect;
10
+ import scene2d.EffectType;
11
+ import scene2d.InterpolationType;
12
+ import scene2d.Scene;
3
13
 
4
14
  public class SceneEffectPanel extends BaseTable {
5
15
  private static final long serialVersionUID = 1L;
6
16
 
7
-
8
- static String[] durations =
9
- {
10
- "0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9",
11
- "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9",
12
- "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "2.9",
13
- "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9",
14
- "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6", "4.7", "4.8", "4.9",
15
- "5.0"
16
- };
17
-
18
17
  static JComboBox<String> bgComboBox = createComboBox();
19
18
  static JComboBox<String> musicComboBox = createComboBox();
20
19
  static JComboBox<String> transitionComboBox = createComboBox();
21
- static JComboBox<String> durationComboBox = createComboBox(durations);
22
20
  static JComboBox<String> interpolationComboBox = createComboBox();
23
21
 
24
22
  public SceneEffectPanel(){
25
- super("Properties");
23
+ super("Properties", null, new SceneEffectRenderer());
26
24
  editors.add(new DefaultCellEditor(bgComboBox));
27
25
  editors.add(new DefaultCellEditor(musicComboBox));
28
26
  editors.add(new DefaultCellEditor(transitionComboBox));
29
- editors.add(new DefaultCellEditor(durationComboBox));
27
+ editors.add(createFloatSpinner("Duration"));
30
28
  editors.add(new DefaultCellEditor(interpolationComboBox));
31
- for(TransitionType transition: TransitionType.values())
29
+ for(EffectType effect: EffectType.values())
32
- transitionComboBox.addItem(transition.toString());
30
+ transitionComboBox.addItem(effect.toString());
33
31
  for(InterpolationType interpolation: InterpolationType.values())
34
32
  interpolationComboBox.addItem(interpolation.toString());
35
33
  }
@@ -41,9 +39,7 @@ public class SceneEffectPanel extends BaseTable {
41
39
 
42
40
  @Override
43
41
  public void update(String... values){
44
- if(Stage.getScene() == null)
45
- return;
46
- Scene scene = Stage.getScene();
42
+ Scene scene = Scene.getCurrentScene();
47
43
  super.update("Background", scene.sceneBackground, "Music", scene.sceneMusic,
48
44
  "Transition", scene.sceneTransition, "Duration", ""+scene.sceneDuration,
49
45
  "Interpolation", scene.sceneInterpolationType.toString());
@@ -61,16 +57,14 @@ public class SceneEffectPanel extends BaseTable {
61
57
  public void setProperty(String key, String value){
62
58
  if(key.isEmpty() || value.isEmpty())
63
59
  return ;
64
- if(Stage.getScene() == null)
65
- return;
66
- Scene scene = Stage.getScene();
60
+ Scene scene = Scene.getCurrentScene();
67
61
  switch(key){
68
62
  case "Background":
69
63
  scene.sceneBackground = value;
70
64
  if(!scene.sceneBackground.equals("None"))
71
- Stage.setBackground(scene.sceneBackground);
65
+ Scene.getCurrentScene().setBackground(scene.sceneBackground);
72
66
  else
73
- Stage.removeBackground();
67
+ Scene.getCurrentScene().removeBackground();
74
68
  break;
75
69
  case "Music":
76
70
  scene.sceneMusic = value;
@@ -79,20 +73,37 @@ public class SceneEffectPanel extends BaseTable {
79
73
  break;
80
74
  case "Transition":
81
75
  scene.sceneTransition = value;
82
- Effect.transition(TransitionType.valueOf(scene.sceneTransition),
83
- Stage.getRoot(),scene.sceneDuration, scene.sceneInterpolationType);
84
76
  break;
85
77
  case "Duration":
86
78
  scene.sceneDuration = Float.parseFloat(value);
87
- Effect.transition(TransitionType.valueOf(scene.sceneTransition),
88
- Stage.getRoot(),scene.sceneDuration, scene.sceneInterpolationType);
89
79
  break;
90
80
  case "Interpolation":
91
81
  scene.sceneInterpolationType = InterpolationType.valueOf(value);
92
- Effect.transition(TransitionType.valueOf(scene.sceneTransition),
93
- Stage.getRoot(),scene.sceneDuration, scene.sceneInterpolationType);
94
82
  break;
95
83
  }
84
+ Effect.createEffect(Scene.getRoot(), EffectType.valueOf(scene.sceneTransition), 1f,
85
+ scene.sceneDuration, scene.sceneInterpolationType);
96
- SceneEditor.isDirty = true;
86
+ Scene.isDirty = true;
97
87
  }
88
+ }
89
+
90
+ class SceneEffectRenderer extends BaseRenderer {
91
+ private static final long serialVersionUID = 1L;
92
+
93
+ @Override
94
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
95
+ setBorder(noFocusBorder);
96
+ if(column == 0)
97
+ return new HeaderLabel(value.toString());
98
+ else {
99
+ if(row == 3){
100
+ if(!value.toString().isEmpty())
101
+ spinnerFloat.setValue(Float.parseFloat(value.toString()));
102
+ else
103
+ spinnerFloat.setValue(new Float(0.0));
104
+ return spinnerFloat;
105
+ }
106
+ }
107
+ return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
108
+ }
98
109
  }
src/gdxstudio/panel/ScenePanel.java ADDED
@@ -0,0 +1,274 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.Content;
3
+ import gdxstudio.Export;
4
+ import gdxstudio.Frame;
5
+ import gdxstudio.SceneEditor;
6
+ import gdxstudio.Style;
7
+
8
+ import java.awt.Dimension;
9
+ import java.awt.event.ActionEvent;
10
+ import java.awt.event.ActionListener;
11
+ import java.awt.event.ItemEvent;
12
+ import java.awt.event.ItemListener;
13
+ import java.io.File;
14
+ import java.net.MalformedURLException;
15
+ import java.net.URL;
16
+ import java.net.URLClassLoader;
17
+
18
+ import javax.swing.JButton;
19
+ import javax.swing.JComboBox;
20
+ import javax.swing.JOptionPane;
21
+ import javax.swing.JPanel;
22
+ import javax.swing.Timer;
23
+ import javax.swing.event.ListSelectionEvent;
24
+
25
+ import scene2d.Camera;
26
+ import scene2d.Scene;
27
+ import scene2d.Serializer;
28
+ import web.laf.lite.widget.CenterPanel;
29
+
30
+ import com.badlogic.gdx.scenes.scene2d.Actor;
31
+ import com.badlogic.gdx.scenes.scene2d.EventListener;
32
+
33
+ final public class ScenePanel extends BaseList {
34
+ private static final long serialVersionUID = 1L;
35
+
36
+ public static JComboBox<String> stateComboBox = BaseTable.createComboBox("Scenes", "Maps", "Actors",
37
+ "Assets");
38
+ private static JButton addscene, updown ,delete, resume, pause;
39
+
40
+ private final Timer saveTimer = new Timer(20000, new ActionListener(){
41
+ @Override
42
+ public void actionPerformed(ActionEvent arg0) {
43
+ Scene.getCurrentScene().save(getSelectedValue());
44
+ }
45
+ });
46
+ private static File classPath;
47
+
48
+ public ScenePanel(){
49
+ super("Scenes", true);
50
+ saveTimer.start();
51
+ Serializer.registerSerializer(SceneEditor.class, new Serializer.SceneSerializer());
52
+ initToolBar();
53
+ add(scrollPane);
54
+ stateComboBox.addItemListener(new ItemListener(){
55
+ @Override
56
+ public void itemStateChanged(ItemEvent e) {
57
+ clear();
58
+ switch(stateComboBox.getSelectedIndex()){
59
+ case 0: header.setText("SCENES");break;
60
+ case 1: header.setText("MAPS");break;
61
+ case 2: header.setText("ACTORS");break;
62
+ }
63
+ update();
64
+ }
65
+ });
66
+ }
67
+
68
+ void initToolBar(){
69
+ JPanel tools = Style.createButtonToolBarPanel();
70
+ addscene = Style.createToolButton("New Scene", "newfile", this);
71
+ updown = Style.createToolButton("ScenePriority", "updown", this);
72
+ delete = Style.createToolButton("Delete", "trash", this);
73
+ resume = Style.createToolButton("Resume", "resume", this);
74
+ pause = Style.createToolButton("Pause", "pause", this);
75
+ pause.setEnabled(false);
76
+ tools.add(addscene);
77
+ tools.add(updown);
78
+ tools.add(delete);
79
+ tools.add(resume);
80
+ tools.add(pause);
81
+ stateComboBox.setPreferredSize(new Dimension(65, 17));
82
+ tools.add(new CenterPanel(stateComboBox, false, true));
83
+ add(tools);
84
+ }
85
+
86
+
87
+ public void update(){
88
+ lock();
89
+ listModel.clear();
90
+ for(String s: Scene.scenesMap.keys())
91
+ listModel.addElement(s.replace(Scene.basePackage, ""));
92
+ if(listModel.getSize()>0 && listModel.get(0) != null || !listModel.get(0).isEmpty())
93
+ list.setSelectedIndex(0);
94
+ Frame.eventPanel.update();
95
+ classPath = new File(Content.getProject()+"bin/");
96
+ unlock();
97
+ }
98
+
99
+ private void createSceneFile(){
100
+ String text = JOptionPane.showInputDialog(Frame.getInstance(), "Create a New Scene", "New Scene",
101
+ JOptionPane.OK_CANCEL_OPTION);
102
+ if(text == null || text.isEmpty())
103
+ return;
104
+ String name = text.replace(".json", "").replace(".java", "");
105
+ name = Scene.capitalize(name);
106
+ if(listModel.contains(name)){
107
+ JOptionPane.showConfirmDialog(null, "Error: File already exists: "+name, "Error",
108
+ JOptionPane.OK_OPTION);
109
+ return;
110
+ }
111
+ else{
112
+ Export.writeFile("source/"+name+".java",
113
+ Export.readFileFromClassPath("SceneTemplate.txt").replace("$$$", name));
114
+ listModel.addElement(name);
115
+ Scene.scenesMap.put(name, "");
116
+ Frame.eventPanel.update();
117
+ }
118
+ list.setSelectedIndex(listModel.indexOf(name));
119
+ Scene.isDirty = true;
120
+ Scene.getCurrentScene().save(getSelectedValue());
121
+ }
122
+
123
+ @Override
124
+ public void actionPerformed(ActionEvent event) {
125
+ switch(((JButton)event.getSource()).getToolTipText()){
126
+ case "New Scene":
127
+ createSceneFile();
128
+ break;
129
+ case "ScenePriority":
130
+ int sceneindex = list.getSelectedIndex();
131
+ if(sceneindex+1 < listModel.size()){
132
+ lock();
133
+ String selected = listModel.getElementAt(sceneindex);
134
+ String selectedValue = Scene.scenesMap.getValueAt(sceneindex);
135
+ String down = listModel.getElementAt(sceneindex+1);
136
+ String downValue = Scene.scenesMap.getValueAt(sceneindex+1);
137
+
138
+ /* Changing the model of List */
139
+ listModel.setElementAt(selected, sceneindex+1);
140
+ listModel.setElementAt(down, sceneindex);
141
+
142
+ /* Changing the sceneMap of Stage */
143
+ Scene.scenesMap.setKey(sceneindex+1, selected);
144
+ Scene.scenesMap.setValue(sceneindex+1, selectedValue);
145
+ Scene.scenesMap.setKey(sceneindex, down);
146
+ Scene.scenesMap.setValue(sceneindex, downValue);
147
+
148
+ list.setSelectedIndex(sceneindex+1);
149
+ unlock();
150
+ }
151
+ break;
152
+ case "Delete":
153
+ int confirm = JOptionPane.showConfirmDialog(null,
154
+ "Are you Sure you want to delete the Scene?", "Delete Scene",
155
+ JOptionPane.YES_NO_OPTION);
156
+ if(confirm == JOptionPane.YES_OPTION){
157
+ lock();
158
+ Export.deleteFile("source/"+list.getSelectedValue()+".java");
159
+ Export.deleteFile("bin/"+list.getSelectedValue()+".class");
160
+ Scene.scenesMap.removeKey(list.getSelectedValue());
161
+ int index = listModel.indexOf(list.getSelectedValue())-1;
162
+ if(index != -1){
163
+ Content.editor.load();
164
+ if(Content.currentView.equals("Editor"))
165
+ Content.toggleView(1);
166
+ }
167
+ listModel.removeElement(list.getSelectedValue());
168
+ Frame.eventPanel.update();
169
+ list.setSelectedValue(listModel.elementAt(index), true);
170
+ showStudio();
171
+ Scene.isDirty = true;
172
+ Scene.getCurrentScene().save(getSelectedValue());
173
+ unlock();
174
+ }
175
+ break;
176
+ case "Resume":
177
+ Scene.getCurrentScene().save(getSelectedValue());
178
+ list.setEnabled(false);
179
+ addscene.setEnabled(false);
180
+ updown.setEnabled(false);
181
+ delete.setEnabled(false);
182
+ resume.setEnabled(false);
183
+ pause.setEnabled(true);
184
+ Frame.sceneEffectPanel.disable();
185
+ Frame.propertyPanel.disable();
186
+ Frame.effectPanel.disable();
187
+ Frame.eventPanel.disable();
188
+ Content.widgetPanel.disable();
189
+ Content.toggleView(2);
190
+ runGame();
191
+ break;
192
+ case "Pause":
193
+ Scene.cl = null;
194
+ Scene.debug = true;
195
+ list.setEnabled(true);
196
+ addscene.setEnabled(true);
197
+ updown.setEnabled(true);
198
+ delete.setEnabled(true);
199
+ resume.setEnabled(true);
200
+ pause.setEnabled(false);
201
+ Frame.sceneEffectPanel.enable();
202
+ Frame.propertyPanel.enable();
203
+ Frame.effectPanel.enable();
204
+ Frame.eventPanel.enable();
205
+ Content.widgetPanel.enable();
206
+ Scene.scenesMap.put("gdxstudio.SceneEditor", "");
207
+ Scene.setScene("gdxstudio.SceneEditor");
208
+ Content.toggleView(2);
209
+ showStudio();
210
+ break;
211
+ }
212
+ }
213
+
214
+ private String prevScene = "";
215
+ @Override
216
+ public void valueChanged(ListSelectionEvent e) {
217
+ if (e.getValueIsAdjusting() == false) {
218
+ ConsolePanel.clear();
219
+ Content.editor.clearIcons();
220
+ Content.editor.save();
221
+ Scene.getCurrentScene().save(prevScene);//Warning Only Change
222
+ if(list.getSelectedValue() == null)
223
+ return;
224
+ prevScene = list.getSelectedValue();
225
+ if(resume.isEnabled())
226
+ showStudio();
227
+ Content.editor.load();
228
+ Frame.actorPanel.setHeaderText(list.getSelectedValue());
229
+ }
230
+ }
231
+
232
+ public void showStudio(){
233
+ Frame.actorPanel.clear();
234
+ Scene.getRoot().clearChildren();
235
+ Scene.getCurrentScene().clear();
236
+ Camera.clearAllHud();
237
+ Camera.followActor(null);
238
+ Camera.reset();
239
+ if(selectedValueExists()){
240
+ Scene.getCurrentScene().load(getSelectedValue());
241
+ for(Actor child: Scene.getCurrentScene().getChildren()){
242
+ Frame.actorPanel.addActor(child.getName());
243
+ for(EventListener l: child.getListeners())
244
+ child.removeListener(l);
245
+ }
246
+ Scene.getRoot().addActor(Scene.getCurrentScene());
247
+ }
248
+ Frame.sceneEffectPanel.update();
249
+ }
250
+
251
+ public void runGame() {
252
+ try {
253
+ ConsolePanel.clear();
254
+ Frame.actorPanel.clear();
255
+ URL url = classPath.toURI().toURL();
256
+ URLClassLoader cl = URLClassLoader.newInstance(new URL[]{url});
257
+ Scene.cl = cl;
258
+ Scene.debug = false;
259
+ Scene.setScene(list.getSelectedValue());
260
+ } catch (MalformedURLException me) {
261
+ me.printStackTrace();
262
+ }
263
+ }
264
+
265
+ public boolean selectedValueExists(){
266
+ if(list.getSelectedValue() != null && !list.getSelectedValue().isEmpty())
267
+ return true;
268
+ return false;
269
+ }
270
+
271
+ public String getSelectedValue(){
272
+ return list.getSelectedValue();
273
+ }
274
+ }
{Panel → src/gdxstudio/panel}/SceneTemplate.txt RENAMED
@@ -1,12 +1,23 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
2
4
  import com.badlogic.gdx.scenes.scene2d.Group;
3
5
  import com.badlogic.gdx.scenes.scene2d.ui.Image;
4
6
  import com.badlogic.gdx.scenes.scene2d.ui.Label;
7
+ import com.badlogic.gdx.Input.Keys;
8
+
9
+ import scene2d.*;
10
+ import scene3d.*;
5
11
 
6
12
  public class $$$ extends Scene {
7
13
 
8
14
  public $$$(){
9
15
  }
16
+
17
+ @Override
18
+ public void act(float delta){
19
+ super.act(delta);
20
+ }
10
21
 
11
22
  @Override
12
23
  public void onClick(Actor actor){
{Panel → src/gdxstudio/panel}/StudioPanel.java RENAMED
@@ -1,3 +1,11 @@
1
+ package gdxstudio.panel;
2
+
3
+ import gdxstudio.Content;
4
+ import gdxstudio.Frame;
5
+ import gdxstudio.GdxStudio;
6
+ import gdxstudio.Style;
7
+
8
+ import java.awt.Color;
1
9
  import java.awt.Dimension;
2
10
  import java.awt.Graphics;
3
11
  import java.awt.Image;
@@ -8,18 +16,30 @@ import java.awt.dnd.DnDConstants;
8
16
  import java.awt.dnd.DropTarget;
9
17
  import java.awt.dnd.DropTargetDropEvent;
10
18
  import java.io.File;
11
- import java.io.IOException;
12
19
  import java.nio.ByteBuffer;
13
20
 
14
- import javax.imageio.ImageIO;
15
21
  import javax.swing.JPanel;
16
22
  import javax.swing.JScrollPane;
17
23
 
24
+ import org.lwjgl.LWJGLException;
25
+ import org.lwjgl.opengl.GLContext;
26
+
27
+ import scene2d.Asset;
28
+ import scene2d.Effect;
29
+ import scene2d.EffectType;
30
+ import scene2d.ImageJson;
31
+ import scene2d.InterpolationType;
32
+ import scene2d.Map;
33
+ import scene2d.Scene;
34
+ import scene2d.Sprite;
35
+ import web.laf.lite.layout.HorizontalFlowLayout;
18
36
  import web.laf.lite.layout.VerticalFlowLayout;
19
37
  import web.laf.lite.utils.UIUtils;
38
+ import web.laf.lite.widget.CenterPanel;
20
39
 
21
40
  import com.badlogic.gdx.Gdx;
22
41
  import com.badlogic.gdx.backends.lwjgl.LwjglAWTCanvas;
42
+ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
23
43
  import com.badlogic.gdx.backends.lwjgl.LwjglCanvas;
24
44
  import com.badlogic.gdx.files.FileHandle;
25
45
  import com.badlogic.gdx.graphics.GL20;
@@ -48,17 +68,23 @@ import com.badlogic.gdx.utils.Timer.Task;
48
68
  final public class StudioPanel extends JPanel {
49
69
  private static final long serialVersionUID = 1L;
50
70
  LwjglCanvas can;
51
- LwjglAWTCanvas canvas;
71
+ public LwjglAWTCanvas canvas;
72
+ JPanel hbox;
73
+ CenterPanel centerPanel;
74
+ JScrollPane scrollPane;
75
+ LwjglApplicationConfiguration config2 = new LwjglApplicationConfiguration();
52
76
 
53
77
  Image img;
54
78
  public StudioPanel(){
55
79
  super(new VerticalFlowLayout());
56
- try {
80
+ hbox = new JPanel(new HorizontalFlowLayout());
57
- img = ImageIO.read(Icon.getResourceAsStream("background.png"));
81
+ hbox.add(new HeaderLabel("Screen Size"));
58
- } catch (IOException e) {
82
+ hbox.add(new HeaderLabel("Target Size"));
59
- e.printStackTrace();
60
- }
61
83
  UIUtils.setMargin(this, new Insets(15,15,15,15));
84
+ config2.width = 640;
85
+ config2.height = 320;
86
+ config2.fullscreen = false;
87
+ config2.useGL20 = false;
62
88
  }
63
89
 
64
90
 
@@ -104,21 +130,25 @@ final public class StudioPanel extends JPanel {
104
130
 
105
131
  public void createStudioCanvas(){
106
132
  removeAll();
107
- Main.log("Creating Studio Canvas");
133
+ GdxStudio.log("Creating Studio Canvas");
108
134
  try{
109
- Stage.configJson = Stage.jsonReader.parse(config);
135
+ Scene.configJson = Scene.jsonReader.parse(config);
110
- Stage.targetWidth = 800; // Once designed in this don't change only change the screen width
111
- Stage.targetHeight = 480;// Once designed in this don't change only change the screen height
112
- Stage.debug = true;
136
+ Scene.debug = true;
113
137
  Scene.scenesMap.clear();
114
- Scene.scenesMap.put("SceneEditor", "");
138
+ Scene.scenesMap.put("gdxstudio.SceneEditor", "");
115
- //can = new LwjglCanvas(stage, false);
116
139
  setOpaque(false);
117
- canvas = new LwjglAWTCanvas(Stage.getInstance() , false);
140
+ canvas = new LwjglAWTCanvas(Scene.app , false);
118
- JScrollPane scrollPane = new JScrollPane(canvas.getCanvas());
141
+ scrollPane = new JScrollPane(canvas.getCanvas());
119
142
  scrollPane.setPreferredSize(new Dimension(800, 480));
120
143
  UIUtils.setDrawBorder(scrollPane, false);
144
+ Style.setScreenSize(scrollPane.getPreferredSize().width, scrollPane.getPreferredSize().height);
145
+ centerPanel = new CenterPanel(scrollPane, true, false);
146
+ centerPanel.setBackground(Color.black);
147
+ UIUtils.setUndecorated(centerPanel, true);
148
+ UIUtils.setMargin(centerPanel, new Insets(0,0,0,0));
121
- add(scrollPane);
149
+ add(centerPanel);
150
+ validate();
151
+ Style.setScreenPosition(scrollPane.getLocation().x, scrollPane.getLocation().y);
122
152
  canvas.getCanvas().setDropTarget(new DropTarget() {
123
153
  private static final long serialVersionUID = 1L;
124
154
  public synchronized void drop(DropTargetDropEvent event) {
@@ -146,8 +176,38 @@ final public class StudioPanel extends JPanel {
146
176
  }
147
177
  }
148
178
 
179
+ public void setGdxScreenSize(int width, int height){
180
+ removeAll();
181
+ canvas.getCanvas().setSize(width, height);
182
+ scrollPane = new JScrollPane(canvas.getCanvas());
183
+ scrollPane.setPreferredSize(new Dimension(width, height));
184
+ UIUtils.setDrawBorder(scrollPane, false);
185
+ Style.setScreenSize(scrollPane.getPreferredSize().width, scrollPane.getPreferredSize().height);
186
+ scrollPane.setPreferredSize(new Dimension(width, height));
187
+ centerPanel = new CenterPanel(scrollPane, true, false);
188
+ centerPanel.setBackground(Color.black);
189
+ UIUtils.setUndecorated(centerPanel, true);
190
+ UIUtils.setMargin(centerPanel, new Insets(0,0,0,0));
191
+ add(centerPanel);
192
+ validate();
193
+ Style.setScreenPosition(scrollPane.getLocation().x, scrollPane.getLocation().y);
194
+ canvas.makeCurrent();
195
+ try {
196
+ GLContext.useContext(canvas);
197
+ } catch (LWJGLException e) {
198
+ e.printStackTrace();
199
+ }
200
+ }
201
+
202
+ public void revalidateScreenPosition(){
203
+ if(scrollPane != null){
204
+ validate();
205
+ Style.setScreenPosition(canvas.getCanvas().getLocation().x, canvas.getCanvas().getLocation().y);
206
+ }
207
+ }
208
+
149
209
  public void destroyCanvas(){
150
- Main.log("Destroying Scene Canvas");
210
+ GdxStudio.log("Destroying Scene Canvas");
151
211
  if(canvas != null){
152
212
  remove(canvas.getCanvas());
153
213
  canvas.stop();
@@ -157,7 +217,7 @@ final public class StudioPanel extends JPanel {
157
217
 
158
218
  private int getNameCount(Actor actor){
159
219
  int count = 1;
160
- for(Actor child: Stage.getChildren())
220
+ for(Actor child: Scene.getCurrentScene().getChildren())
161
221
  if(actor.getClass().equals(child.getClass())) count++;
162
222
  return count;
163
223
  }
@@ -168,15 +228,15 @@ final public class StudioPanel extends JPanel {
168
228
  @Override
169
229
  public void run() {
170
230
  String name = actor.getClass().getSimpleName()+getNameCount(actor);
171
- if(Stage.findActor(name) == null)
231
+ if(Scene.getCurrentScene().findActor(name) == null)
172
232
  actor.setName(name);
173
233
  else
174
234
  actor.setName(name+"_1");
175
- actor.setX(Stage.mouse.x-actor.getWidth()/2);
235
+ actor.setX(Scene.mouse.x-actor.getWidth()/2);
176
- actor.setY(Stage.mouse.y-actor.getHeight()/2);
236
+ actor.setY(Scene.mouse.y-actor.getHeight()/2);
177
- Stage.addActor(actor);
237
+ Scene.getCurrentScene().addActor(actor);
178
238
  Frame.actorPanel.addActor(actor.getName());
179
- SceneEditor.isDirty = true;
239
+ Scene.isDirty = true;
180
240
  Effect.createEffect(actor, EffectType.ScaleInOut, 1.5f, 0.5f, InterpolationType.Linear);
181
241
  }
182
242
  }, 0.1f);
@@ -215,7 +275,6 @@ final public class StudioPanel extends JPanel {
215
275
  case "Dialog":setName(new Dialog("Title", Asset.skin));break;
216
276
  case "Touchpad":setName(new Touchpad(5, Asset.skin));break;
217
277
  case "Map":setName(new Map(1, 24));break;
218
-
219
278
  case "None":break;
220
279
  default:break;
221
280
  }
@@ -225,7 +284,7 @@ final public class StudioPanel extends JPanel {
225
284
  StringBuilder sb = new StringBuilder();
226
285
  for(String filename: new File(Asset.basePath+"font").list()){
227
286
  if(filename.endsWith(".fnt")){
228
- Main.log("Loading :"+filename);
287
+ GdxStudio.log("Loading :"+filename);
229
288
  sb.append(filename);
230
289
  sb.append(",");
231
290
  }
@@ -234,7 +293,7 @@ final public class StudioPanel extends JPanel {
234
293
  sb = new StringBuilder();
235
294
  for(String filename: new File(Asset.basePath+"atlas").list()){
236
295
  if(filename.endsWith(".atlas")){
237
- Main.log("Loading :"+filename);
296
+ GdxStudio.log("Loading :"+filename);
238
297
  sb.append(filename);
239
298
  sb.append(",");
240
299
  }
@@ -243,7 +302,7 @@ final public class StudioPanel extends JPanel {
243
302
  sb = new StringBuilder();
244
303
  for(String filename: new File(Asset.basePath+"sound").list()){
245
304
  if(filename.endsWith(".mp3")){
246
- Main.log("Loading :"+filename);
305
+ GdxStudio.log("Loading :"+filename);
247
306
  sb.append(filename);
248
307
  sb.append(",");
249
308
  }
@@ -252,12 +311,19 @@ final public class StudioPanel extends JPanel {
252
311
  sb = new StringBuilder();
253
312
  for(String filename: new File(Asset.basePath+"music").list()){
254
313
  if(filename.endsWith(".mp3")){
255
- Main.log("Loading :"+filename);
314
+ GdxStudio.log("Loading :"+filename);
256
315
  sb.append(filename);
257
316
  sb.append(",");
258
317
  }
259
318
  }
260
319
  Asset.assetMap.put("music", sb.toString());
320
+ sb = new StringBuilder();
321
+ for(String filename: new File(Asset.basePath+"model").list()){
322
+ if(filename.endsWith(".obj") || filename.endsWith(".g3db")){
323
+ GdxStudio.log("Loading :"+filename);
324
+ Asset.modelMap.add(filename);
325
+ }
326
+ }
261
327
  }
262
328
 
263
329
  private static int counter = 1;
{Panel → src/gdxstudio/panel}/TablePanel.java RENAMED
@@ -1,3 +1,7 @@
1
+ package gdxstudio.panel;
2
+ import gdxstudio.GdxStudio;
3
+ import gdxstudio.Style;
4
+
1
5
  import java.awt.Component;
2
6
  import java.awt.Insets;
3
7
  import java.awt.event.ActionEvent;
@@ -40,7 +44,7 @@ public class TablePanel extends JPanel implements ActionListener {
40
44
  //createProperty("OX ", createSpinner() , "OY ", createSpinner());
41
45
  createProperty("Width", createSpinner(), "Height", createSpinner());
42
46
  //createProperty("Height", createSpinner());
43
- Main.log("COMPK"+getProperty("Y"));
47
+ GdxStudio.log("COMPK"+getProperty("Y"));
44
48
  setProperty("X", 500);
45
49
  }
46
50
 
{Panel → src/gdxstudio/panel}/WidgetPanel.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio.panel;
1
2
  import java.awt.Dimension;
2
3
  import java.awt.datatransfer.StringSelection;
3
4
  import java.awt.dnd.DnDConstants;
@@ -10,8 +11,13 @@ import java.awt.dnd.DragSourceEvent;
10
11
  import java.awt.dnd.DragSourceListener;
11
12
  import java.awt.event.ActionEvent;
12
13
 
14
+ import javax.swing.JList;
15
+ import javax.swing.JPanel;
13
16
  import javax.swing.event.ListSelectionEvent;
14
17
 
18
+ import web.laf.lite.layout.HorizontalFlowLayout;
19
+ import web.laf.lite.utils.UIUtils;
20
+
15
21
  public class WidgetPanel extends BaseList implements DragSourceListener, DragGestureListener {
16
22
  private static final long serialVersionUID = 1L;
17
23
 
@@ -19,14 +25,26 @@ public class WidgetPanel extends BaseList implements DragSourceListener, DragGes
19
25
  String[] btns = new String[]{
20
26
  "New Widget", "new","Delete", "trash"
21
27
  };
28
+ private JPanel hbox = new JPanel(new HorizontalFlowLayout());
29
+ StyleList sl = new StyleList();
30
+ StyleTable st = new StyleTable();
31
+
22
32
 
23
33
  public WidgetPanel(){
24
34
  super("Widgets", "Label","Image", "Sprite", "Button","TextButton", "CheckBox",
25
35
  "List", "SelectBox", "Slider", "TextField",
26
- "Table", "Dialog", "Touchpad", "Map");
36
+ "Table", "Dialog", "Touchpad", "Model");
27
- scrollPane.setPreferredSize(new Dimension(200, 50));
37
+ list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
28
38
  dragSource.addDragSourceListener(this);
29
39
  dragSource.createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_MOVE, this);
40
+ hbox.add(list);
41
+ hbox.add(sl);
42
+ hbox.add(st);
43
+ //this.remove(scrollPane);
44
+ UIUtils.setDrawBorder(scrollPane, true);
45
+ scrollPane.setPreferredSize(new Dimension(200, 150));
46
+ scrollPane.setViewportView(hbox);
47
+ add(scrollPane);
30
48
  }
31
49
 
32
50
  @Override
@@ -36,32 +54,23 @@ public class WidgetPanel extends BaseList implements DragSourceListener, DragGes
36
54
 
37
55
  @Override
38
56
  public void dragEnter(DragSourceDragEvent arg0) {
39
- // TODO Auto-generated method stub
40
-
41
57
  }
42
58
 
43
59
 
44
60
  @Override
45
61
  public void dragExit(DragSourceEvent arg0) {
46
- // TODO Auto-generated method stub
47
-
48
62
  }
49
63
 
50
64
 
51
65
  @Override
52
66
  public void dragOver(DragSourceDragEvent arg0) {
53
- // TODO Auto-generated method stub
54
-
55
67
  }
56
68
 
57
69
 
58
70
  @Override
59
71
  public void dropActionChanged(DragSourceDragEvent arg0) {
60
- // TODO Auto-generated method stub
61
-
62
72
  }
63
73
 
64
-
65
74
  @Override
66
75
  public void dragGestureRecognized(DragGestureEvent event) {
67
76
  StringSelection text = new StringSelection(list.getSelectedValue());
@@ -76,3 +85,28 @@ public class WidgetPanel extends BaseList implements DragSourceListener, DragGes
76
85
  public void actionPerformed(ActionEvent arg0) {
77
86
  }
78
87
  }
88
+
89
+ class StyleList extends BaseList {
90
+ private static final long serialVersionUID = 1L;
91
+
92
+ public StyleList(){
93
+ super("Styles", "LabelStyle", "ButtonStyle");
94
+ }
95
+
96
+ @Override
97
+ public void valueChanged(ListSelectionEvent arg0) {
98
+ }
99
+ }
100
+
101
+ class StyleTable extends BaseTable {
102
+ private static final long serialVersionUID = 1L;
103
+
104
+ public StyleTable(){
105
+ super("Properties");
106
+ }
107
+
108
+ @Override
109
+ public void clear(String... items){
110
+ super.clear("StyleName", "", "", "", "");
111
+ }
112
+ }
{Parser → src/gdxstudio/parser}/Java.g4 RENAMED
File without changes
{Parser → src/gdxstudio/parser}/Java.tokens RENAMED
File without changes
{Parser → src/gdxstudio/parser}/JavaBaseListener.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio.parser;
1
2
  // Generated from Java.g4 by ANTLR 4.2
2
3
 
3
4
  import org.antlr.v4.runtime.ParserRuleContext;
{Parser → src/gdxstudio/parser}/JavaLexer.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio.parser;
1
2
  // Generated from Java.g4 by ANTLR 4.2
2
3
  import org.antlr.v4.runtime.Lexer;
3
4
  import org.antlr.v4.runtime.CharStream;
{Parser → src/gdxstudio/parser}/JavaLexer.tokens RENAMED
File without changes
{Parser → src/gdxstudio/parser}/JavaListener.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio.parser;
1
2
  // Generated from Java.g4 by ANTLR 4.2
2
3
  import org.antlr.v4.runtime.misc.NotNull;
3
4
  import org.antlr.v4.runtime.tree.ParseTreeListener;
{Parser → src/gdxstudio/parser}/JavaParser.java RENAMED
@@ -1,3 +1,4 @@
1
+ package gdxstudio.parser;
1
2
  // Generated from Java.g4 by ANTLR 4.2
2
3
  import org.antlr.v4.runtime.atn.*;
3
4
  import org.antlr.v4.runtime.dfa.DFA;
{Stage → src/scene2d}/Asset.java RENAMED
@@ -1,3 +1,6 @@
1
+ package scene2d;
2
+ import scene3d.Actor3d;
3
+
1
4
  import com.badlogic.gdx.Gdx;
2
5
  import com.badlogic.gdx.assets.AssetManager;
3
6
  import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
@@ -11,6 +14,7 @@ import com.badlogic.gdx.graphics.g3d.Model;
11
14
  import com.badlogic.gdx.maps.tiled.TiledMap;
12
15
  import com.badlogic.gdx.maps.tiled.TmxMapLoader;
13
16
  import com.badlogic.gdx.scenes.scene2d.ui.Skin;
17
+ import com.badlogic.gdx.utils.Array;
14
18
  import com.badlogic.gdx.utils.ArrayMap;
15
19
  import com.badlogic.gdx.utils.JsonValue;
16
20
 
@@ -26,14 +30,14 @@ import com.badlogic.gdx.utils.JsonValue;
26
30
  * 2. Automatic Asset Loading the directory Structure should be like this <br>
27
31
  *
28
32
  * <p>
29
- * assets/icon.png --- your game icon to be displayed on the window<br>
33
+ * icon.png --- your game icon to be displayed on the window<br>
30
- * assets/atlas/ --- all your Texture Atlas files .atlas and .png go here<br>
34
+ * atlas/ --- all your Texture Atlas files .atlas and .png go here<br>
31
- * assets/font/ --- all your BitmapFont files .fnt and .png go here<br>
35
+ * font/ --- all your BitmapFont files .fnt and .png go here<br>
32
- * assets/music/ --- all your Music files .mp3 go here<br>
36
+ * music/ --- all your Music files .mp3 go here<br>
33
- * assets/sound/ --- all your Music files .mp3 go here<br>
37
+ * sound/ --- all your Music files .mp3 go here<br>
34
- * assets/particle/ --- all your Particle files .part go here<br>
38
+ * particle/ --- all your Particle files .part go here<br>
35
- * assets/map/ --- all your TMX map files along with tilesets go here<br>
39
+ * map/ --- all your TMX map files along with tilesets go here<br>
36
- * assets/pack/ --- all your image files which are to be packed are to be stored here<br>
40
+ * pack/ --- all your image files which are to be packed are to be stored here<br>
37
41
  * so that they are automatically packed by the texture packer and stored in
38
42
  * the atlas folder
39
43
  *
@@ -79,6 +83,8 @@ public final class Asset {
79
83
  public final static ArrayMap<String, Sound> soundMap = new ArrayMap<String, Sound>();
80
84
  public final static ArrayMap<String, BitmapFont> fontMap = new ArrayMap<String, BitmapFont>();
81
85
  public final static ArrayMap<String, TextureRegion> texMap = new ArrayMap<String, TextureRegion>();
86
+ public final static ArrayMap<String, TextureRegion> particleMap = new ArrayMap<String, TextureRegion>();
87
+ public final static Array<String> modelMap = new Array<String>();
82
88
 
83
89
  private static Music currentMusic = null;
84
90
  public static String currentMusicName = ""; //Only file name no prefix or suffix
@@ -88,7 +94,7 @@ public final class Asset {
88
94
  private static boolean updatinglock = false;
89
95
 
90
96
  /* This is to be used by Gdx Studio */
91
- static String basePath = "";
97
+ public static String basePath = "";
92
98
 
93
99
  public static boolean musicOn = true;
94
100
  public static boolean soundOn = false;
@@ -98,8 +104,10 @@ public final class Asset {
98
104
  assetMap.clear();
99
105
  fontMap.clear();
100
106
  texMap.clear();
107
+ particleMap.clear();
101
108
  musicMap.clear();
102
109
  soundMap.clear();
110
+ modelMap.clear();
103
111
  }
104
112
 
105
113
  public static void load(){
@@ -138,16 +146,16 @@ public final class Asset {
138
146
  assetMan.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
139
147
  getAssets();
140
148
  updatinglock = true;
141
- if(Stage.splashDuration != 0)
149
+ if(Scene.splashDuration != 0)
142
- Stage.nextSceneWithDelay(Stage.splashDuration);
150
+ Scene.nextSceneWithDelay(Scene.splashDuration);
143
151
  else
144
- Stage.nextScene();
152
+ Scene.nextScene();
145
153
  }
146
154
  return updatinglock;
147
155
  }
148
156
 
149
157
  public static void loadAssets(){
150
- JsonValue sv = Stage.jsonReader.parse(Gdx.files.internal(Asset.basePath+"asset"));
158
+ JsonValue sv = Scene.jsonReader.parse(Gdx.files.internal(Asset.basePath+"asset"));
151
159
  for(JsonValue jv: sv.iterator())
152
160
  assetMap.put(jv.name, jv.asString());
153
161
  for(String font: assetMap.get("font").split(",")){
@@ -189,7 +197,8 @@ public final class Asset {
189
197
  musicMap.put(ext(music), assetMan.get(basePath+"music/"+music, Music.class));
190
198
  }
191
199
  skin = assetMan.get(basePath+"skin/uiskin.json", Skin.class);
200
+ if(Scene.configJson.getBoolean("showFPS"))
192
- Stage.setup();
201
+ Scene.setupFps();
193
202
  }
194
203
 
195
204
  private static String ext(String file){
@@ -197,7 +206,7 @@ public final class Asset {
197
206
  }
198
207
 
199
208
  public static void save(){
200
- Gdx.files.local(Asset.basePath+"asset").writeString(Stage.json.toJson(assetMap, ArrayMap.class, String.class), false);
209
+ Gdx.files.local(Asset.basePath+"asset").writeString(Scene.json.toJson(assetMap, ArrayMap.class, String.class), false);
201
210
  }
202
211
 
203
212
  /***********************************************************************************************************
@@ -216,7 +225,7 @@ public final class Asset {
216
225
  else
217
226
  musicStop();
218
227
  if(musicMap.containsKey(filename)){
219
- Stage.log("Music: playing "+filename);
228
+ Scene.log("Music: playing "+filename);
220
229
  currentMusic = musicMap.get(filename);//Gdx.audio.newMusic(Gdx.files.internal("music/"+filename));
221
230
  currentMusic.setVolume(Config.volMusic);
222
231
  currentMusic.setLooping(true);
@@ -224,7 +233,7 @@ public final class Asset {
224
233
  currentMusicName = filename;
225
234
  }
226
235
  else{
227
- Stage.log("Music File Not Found: "+filename);
236
+ Scene.log("Music File Not Found: "+filename);
228
237
  }
229
238
  }
230
239
  }
@@ -233,7 +242,7 @@ public final class Asset {
233
242
  public static void musicPause(){
234
243
  if(currentMusic != null)
235
244
  if(currentMusic.isPlaying()){
236
- Stage.log("Music: pausing "+currentMusicName);
245
+ Scene.log("Music: pausing "+currentMusicName);
237
246
  currentMusic.pause();
238
247
  }
239
248
  }
@@ -242,7 +251,7 @@ public final class Asset {
242
251
  public static void musicResume(){
243
252
  if(currentMusic != null)
244
253
  if(!currentMusic.isPlaying()){
245
- Stage.log("Music: resuming "+currentMusicName);
254
+ Scene.log("Music: resuming "+currentMusicName);
246
255
  currentMusic.play();
247
256
  }
248
257
  else
@@ -252,7 +261,7 @@ public final class Asset {
252
261
  /** Stops the current music file being played */
253
262
  public static void musicStop(){
254
263
  if(currentMusic != null){
255
- Stage.log("Music: stoping "+currentMusicName);
264
+ Scene.log("Music: stoping "+currentMusicName);
256
265
  currentMusic.stop();
257
266
  currentMusic = null;
258
267
  }
@@ -284,10 +293,10 @@ public final class Asset {
284
293
  long id = currentSound.play(Config.volSound);
285
294
  currentSound.setLooping(id, false);
286
295
  currentSound.setPriority(id, 99);
287
- Stage.log("Sound:"+"Play "+ filename);
296
+ Scene.log("Sound:"+"Play "+ filename);
288
297
  }
289
298
  else{
290
- Stage.log("Music File Not Found: "+filename);
299
+ Scene.log("Music File Not Found: "+filename);
291
300
  }
292
301
  }
293
302
  }
@@ -299,34 +308,34 @@ public final class Asset {
299
308
  long id = currentSound.play(Config.volSound);
300
309
  currentSound.setLooping(id, false);
301
310
  currentSound.setPriority(id, 99);
302
- Stage.log("Sound:"+"Play "+ "click");
311
+ Scene.log("Sound:"+"Play "+ "click");
303
312
  }
304
313
  }
305
314
 
306
315
  /** Pauses the current sound file being played */
307
316
  public static void soundPause(){
308
- Stage.log("Sound:"+"Pausing");
317
+ Scene.log("Sound:"+"Pausing");
309
318
  if(currentSound != null)
310
319
  currentSound.pause();
311
320
  }
312
321
 
313
322
  /** Resumes the current sound file being played */
314
323
  public static void soundResume(){
315
- Stage.log("Sound:"+"Resuming");
324
+ Scene.log("Sound:"+"Resuming");
316
325
  if(currentSound != null)
317
326
  currentSound.resume();
318
327
  }
319
328
 
320
329
  /** Stops the current sound file being played */
321
330
  public static void soundStop(){
322
- Stage.log("Sound:"+"Stopping");
331
+ Scene.log("Sound:"+"Stopping");
323
332
  if(currentSound != null)
324
333
  currentSound.stop();
325
334
  }
326
335
 
327
336
  /** Disposes the current sound file being played */
328
337
  public static void soundDispose(){
329
- Stage.log("Sound:"+"Disposing Sound");
338
+ Scene.log("Sound:"+"Disposing Sound");
330
339
  if(currentSound != null)
331
340
  currentSound.dispose();
332
341
  }
@@ -346,7 +355,7 @@ public final class Asset {
346
355
  return fontMap.get(fontname);
347
356
  }
348
357
  else{
349
- Stage.log("Font File Not Found: "+fontname);
358
+ Scene.log("Font File Not Found: "+fontname);
350
359
  return null;
351
360
  }
352
361
  }
@@ -364,7 +373,7 @@ public final class Asset {
364
373
  return texMap.get(textureregionName);
365
374
  }
366
375
  else{
367
- Stage.log("TextureRegion Not Found: "+textureregionName);
376
+ Scene.log("TextureRegion Not Found: "+textureregionName);
368
377
  return null;
369
378
  }
370
379
  }
@@ -556,40 +565,40 @@ public final class Asset {
556
565
  * Logs all the TextureRegions that are loaded and cached
557
566
  */
558
567
  public static void logTextures(){
559
- Stage.log("BEGIN logging Textures------------------");
568
+ Scene.log("BEGIN logging Textures------------------");
560
569
  for(String na: texMap.keys())
561
- Stage.log(na);
570
+ Scene.log(na);
562
- Stage.log("END logging Textures------------------");
571
+ Scene.log("END logging Textures------------------");
563
572
  }
564
573
 
565
574
  /*
566
575
  * Logs all the BitmapFonts that are loaded and cached
567
576
  */
568
577
  public static void logFonts(){
569
- Stage.log("BEGIN logging Fonts------------------");
578
+ Scene.log("BEGIN logging Fonts------------------");
570
579
  for(String na: fontMap.keys())
571
- Stage.log(na);
580
+ Scene.log(na);
572
- Stage.log("END logging Fonts------------------");
581
+ Scene.log("END logging Fonts------------------");
573
582
  }
574
583
 
575
584
  /*
576
585
  * Logs all the Sounds that are loaded and cached
577
586
  */
578
587
  public static void logSounds(){
579
- Stage.log("BEGIN logging Sounds------------------");
588
+ Scene.log("BEGIN logging Sounds------------------");
580
589
  for(String na: soundMap.keys())
581
- Stage.log(na);
590
+ Scene.log(na);
582
- Stage.log("END logging Sounds------------------");
591
+ Scene.log("END logging Sounds------------------");
583
592
  }
584
593
 
585
594
  /*
586
595
  * Logs all the Music that are loaded and cached
587
596
  */
588
597
  public static void logMusics(){
589
- Stage.log("BEGIN logging Musics------------------");
598
+ Scene.log("BEGIN logging Musics------------------");
590
599
  for(String na: musicMap.keys())
591
- Stage.log(na);
600
+ Scene.log(na);
592
- Stage.log("END logging Musics------------------");
601
+ Scene.log("END logging Musics------------------");
593
602
  }
594
603
 
595
604
  /*
src/scene2d/Camera.java ADDED
@@ -0,0 +1,284 @@
1
+ package scene2d;
2
+ import com.badlogic.gdx.Gdx;
3
+ import com.badlogic.gdx.graphics.OrthographicCamera;
4
+ import com.badlogic.gdx.math.Interpolation;
5
+ import com.badlogic.gdx.math.Vector3;
6
+ import com.badlogic.gdx.scenes.scene2d.Actor;
7
+ import com.badlogic.gdx.utils.Array;
8
+ import com.badlogic.gdx.math.Rectangle;
9
+
10
+ public class Camera extends OrthographicCamera {
11
+ private static Camera instance;
12
+ private static float duration;
13
+ private static float time;
14
+ private static Interpolation interpolation;
15
+ private static boolean moveCompleted;
16
+ private static float lastPercent;
17
+ private static float percentDelta;
18
+ private static float panSpeedX, panSpeedY;
19
+ private static final Array<Actor> hudActors = new Array<Actor>();
20
+
21
+
22
+ private static Actor followedActor = null;
23
+ private static float followSpeed = 1f;
24
+ /*
25
+ * This is to set the offsets of camera position when following the actor
26
+ * When the camera follows the actor its (x,y) position is set to actor's (x,y) position
27
+ * based on followSpeed. The offsets are used to position the camera in such a way that the actor
28
+ * doesn't need to be at the center of the camera always
29
+ */
30
+ public static Rectangle followOffset = new Rectangle(10,70,10,60);
31
+ private static boolean followContinous = false;
32
+
33
+
34
+ public static boolean usePan = false;
35
+ public static boolean useDrag = false;
36
+ /*
37
+ * Sets the speed at which the camera pans. By default it moves 1px for a duration a 1f
38
+ * so its speed is 1px/f. So reduce the duration to increase its speed.
39
+ * ex: setPanSpeed(0.5) will change its speed to 2px/f
40
+ * Here: f can/maybe also indicate seconds
41
+ */
42
+ public static float panSpeed = 5f;
43
+ public static Rectangle panSize;
44
+
45
+ /*
46
+ * This sets the boundary of the camera till what position can it move or pan in the
47
+ * directions left, right, top, down. This is to prevent is from panning overboard the game area.
48
+ * Usually the bounds of the camera is like a rectangle. This must be calculated carefully
49
+ * as the camera's position is based on its center.
50
+ */
51
+ public static Rectangle bounds = new Rectangle(0,0,999,999);
52
+
53
+
54
+ Camera(){
55
+ setToOrtho(false, Scene.targetWidth, Scene.targetHeight);
56
+ position.set(Scene.targetWidth/2, Scene.targetHeight/2, 0);
57
+ instance = this;
58
+ panSize = new Rectangle(10, 10, Scene.targetWidth-10, Scene.targetHeight - 10);
59
+ }
60
+
61
+ /*
62
+ * Moves the camera to x,y over a time duration
63
+ */
64
+ public void moveTo(float x, float y, float duration) {
65
+ moveBy(x-position.x, y-position.y, duration);
66
+ }
67
+
68
+ /*
69
+ * Moves the camera by amountX, amountY over a time duration
70
+ */
71
+ public static void moveBy (float amountX, float amountY, float duration) {
72
+ moveBy(amountX, amountY, duration, null);
73
+ }
74
+
75
+ /*
76
+ * Moves the camera by amountX, amountY over a time duration and interpolation interp
77
+ */
78
+ public static void moveBy (float amountX, float amountY, float dur, Interpolation interp) {
79
+ duration = dur;
80
+ interpolation = interp;
81
+ panSpeedX = amountX;
82
+ panSpeedY = amountY;
83
+ lastPercent = 0;
84
+ time = 0;
85
+ moveCompleted = false;
86
+ }
87
+
88
+ private static Rectangle cullRect = new Rectangle();
89
+ private void moveByAction(float delta){
90
+ time += delta;
91
+ moveCompleted = time >= duration;
92
+ float percent;
93
+ if (moveCompleted)
94
+ percent = 1;
95
+ else {
96
+ percent = time / duration;
97
+ if (interpolation != null) percent = interpolation.apply(percent);
98
+ }
99
+ percentDelta = percent - lastPercent;
100
+ if(Scene.cullingEnabled){
101
+ cullRect.set(getXLeft(), getYBot(), Scene.targetWidth, Scene.targetHeight);
102
+ Scene.getCurrentScene().setCullingArea(cullRect);
103
+ }
104
+ translate(panSpeedX * percentDelta, panSpeedY * percentDelta, 0);
105
+ for(Actor actor: hudActors)
106
+ actor.setPosition(actor.getX()+panSpeedX * percentDelta, actor.getY()+panSpeedY * percentDelta);
107
+ lastPercent = percent;
108
+ if (moveCompleted) interpolation = null;
109
+ }
110
+
111
+ public void resetCamera(){
112
+ position.set(Scene.targetWidth/2, Scene.targetHeight/2, 0);
113
+ }
114
+
115
+ /*
116
+ * This makes the camera follow the actor once and only once. Once the camera reaches its
117
+ * target, it stops following the actor.
118
+ */
119
+ public static void followActor(Actor actor){
120
+ followedActor = actor;
121
+ followContinous = false;
122
+ }
123
+
124
+ /*
125
+ * This makes the camera follow the actor continuously, even after the camera reaches its
126
+ * target, it keeps following the if the actor changes its position.
127
+ */
128
+ public static void followActorContinuously(Actor actor){
129
+ followedActor = actor;
130
+ followContinous = true;
131
+ }
132
+
133
+
134
+
135
+ /*
136
+ * Sets the speed at which the camera follows the actor. By default it moves 1px for a duration of 1f
137
+ * so its speed is 1px/f. So reduce the duration to increase its speed.
138
+ * ex: setPanSpeed(0.5) will change its speed to 2px/f
139
+ * Here: f can/maybe also indicate seconds
140
+ */
141
+ public static void setFollowSpeed(float duration){
142
+ followSpeed = duration;
143
+ }
144
+
145
+ private void follow(){
146
+ //if(camera.position.x == followedActor.getX()+followLeftOffset &&
147
+ // camera.position.y == followedActor.getY()+followTopOffset)
148
+ //return;
149
+ //moveTo(followedActor.getX()+followLeftOffset, followedActor.getY()+followTopOffset, 100f);
150
+ if(position.x < followedActor.getX() - followOffset.x) moveBy(1f, 0, followSpeed);
151
+ else if(position.x > followedActor.getX() + followOffset.width) moveBy(-1f, 0, followSpeed);
152
+ else if(position.y < followedActor.getY() - followOffset.y) moveBy(0, 1f, followSpeed);
153
+ else if(position.y > followedActor.getY() - followOffset.height) moveBy(0, -1f, followSpeed);
154
+ else {
155
+ if(!followContinous)
156
+ followedActor = null;
157
+ }
158
+ }
159
+
160
+ @Override
161
+ public void update(){
162
+ super.update();
163
+ Scene.mouse.x = Gdx.input.getX();
164
+ Scene.mouse.y = Gdx.graphics.getHeight() - Gdx.input.getY();
165
+ if(!moveCompleted)
166
+ moveByAction(Scene.stateTime);//FIXME
167
+ if(usePan)
168
+ panCameraWithMouse();
169
+ if(followedActor != null)
170
+ follow();
171
+ }
172
+
173
+ private void panCameraWithMouse(){
174
+ if(Scene.mouse.x > panSize.width && getXLeft() < bounds.width) moveBy(1f, 0, panSpeed);
175
+ else if(Scene.mouse.x < panSize.x && getXLeft() > bounds.x) moveBy(-1f, 0, panSpeed);
176
+ else if(Scene.mouse.y < panSize.y && getYBot() > bounds.y) moveBy(0, -1f, panSpeed);
177
+ else if(Scene.mouse.y > panSize.height && getYBot() < bounds.height) moveBy(0, 1f, panSpeed);
178
+ }
179
+
180
+ private final static Vector3 curr = new Vector3();
181
+ private final static Vector3 last = new Vector3(-1, -1, -1);
182
+ private final static Vector3 deltaDrag = new Vector3();
183
+ private static float deltaCamX = 0;
184
+ private static float deltaCamY = 0;
185
+ public static void dragCam(int x, int y){
186
+ instance.unproject(curr.set(x, y, 0));
187
+ if (!(last.x == -1 && last.y == -1 && last.z == -1)) {
188
+ instance.unproject(deltaDrag.set(last.x, last.y, 0));
189
+ deltaDrag.sub(curr);
190
+ deltaCamX = deltaDrag.x + instance.position.x;
191
+ deltaCamY = deltaDrag.y + instance.position.y;
192
+ if(deltaCamX > bounds.x && deltaCamX < bounds.x+bounds.width)
193
+ moveBy(deltaDrag.x, 0f, 0f);
194
+ if(deltaCamY > bounds.y && deltaCamY < bounds.y+bounds.height)
195
+ moveBy(0f, deltaDrag.y, 0f);
196
+ }
197
+ last.set(x, y, 0);
198
+ }
199
+
200
+ public static void resetDrag(){
201
+ last.set(-1, -1, -1);
202
+ }
203
+
204
+ public static void reset(){
205
+ usePan = false;
206
+ followActor(null);
207
+ clearAllHud();
208
+ instance.position.set(Scene.targetWidth/2, Scene.targetHeight/2, 0);
209
+ }
210
+
211
+ /* If you want to make any elements/actors to move along with the camera
212
+ * like HUD's add them using this method */
213
+ public static void addHud(Actor actor){
214
+ if(actor != null){
215
+ Scene.getCurrentScene().addActor(actor);
216
+ hudActors.add(actor);
217
+ }
218
+ }
219
+
220
+ /* If you want to make any elements/actors to move along with the camera
221
+ * like HUD's add them using this method */
222
+ public static void addHud(String actorName){
223
+ if(actorName != null && !actorName.isEmpty()){
224
+ Actor actor = Scene.getCurrentScene().findActor(actorName);
225
+ Scene.getCurrentScene().addActor(actor);
226
+ hudActors.add(actor);
227
+ }
228
+ }
229
+
230
+
231
+ /* If you want to any elements/actors which was a Hud the use this */
232
+ public static void removeHud(Actor actor){
233
+ Scene.getCurrentScene().removeActor(actor);
234
+ hudActors.removeValue(actor, true);
235
+ }
236
+
237
+ /* If you want to any elements/actors which was a Hud the use this */
238
+ public static void removeHud(String actorName){
239
+ if(actorName != null && !actorName.isEmpty()){
240
+ Actor actor = Scene.getCurrentScene().findActor(actorName);
241
+ Scene.getCurrentScene().removeActor(actor);
242
+ hudActors.removeValue(actor, true);
243
+ }
244
+ }
245
+
246
+
247
+
248
+ /*
249
+ * Clears all hud's registered with the camera
250
+ */
251
+ public static void clearAllHud(){
252
+ hudActors.clear();
253
+ }
254
+
255
+ /*
256
+ * Returns the x position of the camera
257
+ */
258
+ public static float getX(){
259
+ return instance.position.x;
260
+ }
261
+
262
+ /*
263
+ * Returns the y position of the camera
264
+ */
265
+ public static float getY(){
266
+ return instance.position.y;
267
+ }
268
+
269
+ public static float getXLeft(){
270
+ return instance.position.x - Scene.targetWidth/2;
271
+ }
272
+
273
+ public static float getYBot(){
274
+ return instance.position.y - Scene.targetHeight/2;
275
+ }
276
+
277
+ public static float getWidth(){
278
+ return instance.viewportWidth;
279
+ }
280
+
281
+ public static float getHeight(){
282
+ return instance.viewportHeight;
283
+ }
284
+ }
{Stage → src/scene2d}/Config.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.Gdx;
2
3
  import com.badlogic.gdx.Preferences;
3
4
 
@@ -20,8 +21,6 @@ public final class Config {
20
21
  static final String CURRENT_LEVEL = "currentlevel";
21
22
  static final String SAVEDATA= "savedata";
22
23
  static final String TOTAL_TIME= "totaltime";
23
- static final String PANSCROLL = "panscroll";
24
- static final String DRAGSCROLL = "dragscroll";
25
24
  static final String PANSPEED = "panspeed";
26
25
  static final String DRAGSPEED = "dragspeed";
27
26
  static final String KEYBOARD = "keyboard";
@@ -35,7 +34,6 @@ public final class Config {
35
34
  public static float volMusic;
36
35
  public static float volSound;
37
36
 
38
- public static boolean useDrag;
39
37
  public static boolean useKeyboard;
40
38
 
41
39
  public static float speedPan;
@@ -44,15 +42,13 @@ public final class Config {
44
42
  private static int score;
45
43
 
46
44
  static void setup(){
47
- prefs = Gdx.app.getPreferences(Stage.configJson.getString("title"));
45
+ prefs = Gdx.app.getPreferences(Scene.configJson.getString("title"));
48
46
  isMusic = prefs.getBoolean(MUSIC, true);
49
47
  isSound = prefs.getBoolean(SOUND, true);
50
48
 
51
49
  volMusic = prefs.getFloat(VOLUME_MUSIC, 1f);
52
50
  volSound = prefs.getFloat(VOLUME_SOUND, 1f);
53
51
 
54
- Stage.usePan = prefs.getBoolean(PANSCROLL, true);
55
- useDrag = prefs.getBoolean(DRAGSCROLL, true);
56
52
  useKeyboard = prefs.getBoolean(KEYBOARD, true);
57
53
 
58
54
  speedPan = prefs.getFloat(PANSPEED, 5f);
@@ -127,19 +123,6 @@ public final class Config {
127
123
  prefs.flush();
128
124
  }
129
125
 
130
-
131
- public static void setPanScroll(boolean ue){
132
- prefs.putBoolean(PANSCROLL, ue);
133
- prefs.flush();
134
- Stage.usePan = ue ;
135
- }
136
-
137
- public static void setDragScroll(boolean ue){
138
- prefs.putBoolean(DRAGSCROLL, ue);
139
- prefs.flush();
140
- useDrag = ue;
141
- }
142
-
143
126
  public static void setPanSpeed(float ue){
144
127
  prefs.putFloat(PANSPEED, ue);
145
128
  prefs.flush();
{Stage → src/scene2d}/Effect.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.graphics.Color;
2
3
  import com.badlogic.gdx.math.Interpolation;
3
4
  import com.badlogic.gdx.scenes.scene2d.Action;
@@ -17,38 +18,12 @@ public class Effect {
17
18
  if(actor == null)
18
19
  return;
19
20
  Interpolation interp = InterpolationType.getInterpolation(type);
21
+ float x = 0;//actor.getX();
22
+ float y = 0;//actor.getY();
20
23
  switch(effectType){
21
- case FadeInOut:
22
- actor.addAction(fadeInOut(value, duration, interp));
23
- break;
24
- case FadeInOutLooping:
25
- actor.addAction(Actions.forever(fadeInOut(value, duration, interp)));
26
- break;
27
- case FadeInOutRemoveActor:
28
- break;
29
- case ScaleInOut:
30
- actor.addAction(scaleInOut(value, duration, interp));
31
- break;
32
- case ScaleInOutLooping:
33
- actor.addAction(Actions.forever(scaleInOut(value, duration, interp)));
34
- break;
35
- case ScaleInOutRemoveActor:
36
- actor.addAction(Actions.sequence(scaleInOut(value, duration, interp), Actions.removeActor(actor)));
37
- break;
38
- case ShakeInOut:
39
- actor.addAction(shakeInOut(value, duration, interp));
40
- break;
41
- case ShakeInOutLooping:
42
- actor.addAction(Actions.forever(shakeInOut(value, duration, interp)));
43
- break;
44
- case ShakeInOutRemoveActor:
45
- actor.addAction(Actions.sequence(shakeInOut(value, duration, interp), Actions.removeActor(actor)));
46
- break;
47
-
48
24
  case ScaleToThenFadeOut:
49
25
  actor.addAction(Actions.sequence(Actions.scaleTo(value, value, duration, interp)));
50
26
  break;
51
-
52
27
  case PatrolX:
53
28
  actor.addAction(Actions.forever(Actions.sequence(Actions.moveBy(value, 0, duration, interp),
54
29
  Actions.moveBy(-value, 0, duration, interp))));
@@ -59,6 +34,48 @@ public class Effect {
59
34
  Actions.moveBy(0, -value, duration, interp))));
60
35
  break;
61
36
 
37
+ case SlideLeft:
38
+ actor.setPosition(999, y);
39
+ actor.addAction(Actions.moveTo(x, y, duration, interp));
40
+ break;
41
+ case SlideRight:
42
+ actor.setPosition(-999, y);
43
+ actor.addAction(Actions.moveTo(x, y, duration, interp));
44
+ break;
45
+ case SlideUp:
46
+ actor.setPosition(x, -999);
47
+ actor.addAction(Actions.moveTo(x, y, duration, interp));
48
+ break;
49
+ case SlideDown:
50
+ actor.setPosition(x, 999);
51
+ actor.addAction(Actions.moveTo(x, y, duration, interp));
52
+ break;
53
+ case FadeIn:
54
+ Color color = actor.getColor();
55
+ color.a = 0f;
56
+ actor.setColor(color);
57
+ actor.addAction(Actions.fadeIn(duration, interp));
58
+ break;
59
+ case FadeOut:
60
+ Color color2 = actor.getColor();
61
+ color2.a = 1f;
62
+ actor.setColor(color2);
63
+ actor.addAction(Actions.fadeOut(duration, interp));
64
+ break;
65
+ case FadeInOut:
66
+ actor.addAction(fadeInOut(value, duration, interp));
67
+ break;
68
+ case ScaleIn:
69
+ actor.setScale(0, 0);
70
+ actor.addAction(Actions.scaleTo(1, 1, duration, interp));
71
+ break;
72
+ case ScaleOut:
73
+ actor.setScale(1, 1);
74
+ actor.addAction(Actions.scaleTo(0, 0, duration, interp));
75
+ break;
76
+ case ScaleInOut:
77
+ actor.addAction(scaleInOut(value, duration, interp));
78
+ break;
62
79
  case None:
63
80
  break;
64
81
  default:
@@ -152,79 +169,4 @@ public class Effect {
152
169
  Interpolation.sine, Interpolation.sineIn, Interpolation.sineOut,
153
170
  Interpolation.swing, Interpolation.swingIn, Interpolation.swingOut,
154
171
  };
155
-
156
- /***********************************************************************************************************
157
- * Transition Related Functions *
158
- ************************************************************************************************************/
159
-
160
- public static void transition(TransitionType transitionType, Actor actor, float duration,
161
- InterpolationType interptype){
162
- switch(transitionType){
163
- case None: break;
164
- case leftToRight: transitionLeftToRight(actor, duration, interptype);break;
165
- case rightToLeft: transitionRightToLeft(actor, duration, interptype);break;
166
- case upToDown: transitionUpToDown(actor, duration, interptype);break;
167
- case downToUp: transitionDownToUp(actor, duration, interptype);break;
168
- case FadeIn: transitionFadeIn(actor, duration, interptype);break;
169
- case FadeOut: transitionFadeOut(actor, duration, interptype);break;
170
- case ScaleIn: transitionScaleIn(actor, duration, interptype);break;
171
- case ScaleOut: transitionScaleOut(actor, duration, interptype);break;
172
- }
173
- }
174
-
175
- private static void transitionLeftToRight(Actor actor, float duration, InterpolationType interptype){
176
- actor.setPosition(-999, 0);
177
- actor.addAction(Actions.moveTo(0, 0, duration, InterpolationType.getInterpolation(interptype)));
178
- }
179
-
180
- private static void transitionRightToLeft(Actor actor, float duration, InterpolationType interptype){
181
- actor.setPosition(999, 0);
182
- actor.addAction(Actions.moveTo(0, 0, duration, InterpolationType.getInterpolation(interptype)));
183
- }
184
-
185
- private static void transitionUpToDown(Actor actor, float duration, InterpolationType interptype){
186
- actor.setPosition(0, 999);
187
- actor.addAction(Actions.moveTo(0, 0, duration, InterpolationType.getInterpolation(interptype)));
188
- }
189
-
190
- private static void transitionDownToUp(Actor actor, float duration, InterpolationType interptype){
191
- actor.setPosition(0, -999);
192
- actor.addAction(Actions.moveTo(0, 0, duration, InterpolationType.getInterpolation(interptype)));
193
- }
194
-
195
- private static void transitionFadeIn(Actor actor, float duration, InterpolationType interptype){
196
- Color color = actor.getColor();
197
- color.a = 0f;
198
- actor.setColor(color);
199
- actor.addAction(Actions.fadeIn(duration, InterpolationType.getInterpolation(interptype)));
200
- }
201
-
202
- private static void transitionFadeOut(Actor actor, float duration, InterpolationType interptype){
203
- Action action2 = new Action(){
204
- @Override
205
- public boolean act(float delta){
206
- Color color = actor.getColor();
207
- color.a = 1f;
208
- actor.setColor(color);
209
- return true;
210
- }
211
- };
212
- actor.addAction(Actions.sequence(Actions.fadeOut(duration, InterpolationType.getInterpolation(interptype)), action2));
213
- }
214
-
215
- private static void transitionScaleIn(Actor actor, float duration, InterpolationType interptype){
216
- actor.setScale(0, 0);
217
- actor.addAction(Actions.scaleTo(1, 1, duration, InterpolationType.getInterpolation(interptype)));
218
- }
219
-
220
- private static void transitionScaleOut(Actor actor, float duration, InterpolationType interptype){
221
- Action action2 = new Action(){
222
- @Override
223
- public boolean act(float delta){
224
- actor.scale(1f);
225
- return true;
226
- }
227
- };
228
- actor.addAction(Actions.sequence(Actions.scaleTo(1, 1, duration, InterpolationType.getInterpolation(interptype)), action2));
229
- }
230
172
  }
src/scene2d/EffectType.java ADDED
@@ -0,0 +1,19 @@
1
+ package scene2d;
2
+
3
+ public enum EffectType {
4
+ None,
5
+ ScaleIn, ScaleOut, ScaleInOut, ScaleTo, ScaleToBack,
6
+ ShakeIn, ShakeOut, ShakeInOut, ShakeTo, ShakeToBack,
7
+ FadeIn, FadeOut, FadeInOut, FadeTo, FadeToBack,
8
+ ScaleToThenFadeOut, ScaleAndFadeOut, ScaleAndFadeIn,
9
+
10
+ SlideRight, SlideLeft, SlideUp, SlideDown,
11
+ PatrolX, PatrolY;
12
+ }
13
+
14
+ enum EffectDuration {
15
+ Once,
16
+ OnceToAndBack,
17
+ Looping,
18
+ LoopingToAndBack
19
+ }
{Type → src/scene2d}/EventType.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  public enum EventType {
2
3
  None,
3
4
  SceneCreated,
{Stage → src/scene2d}/ImageJson.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.scenes.scene2d.ui.Image;
2
3
  import com.badlogic.gdx.utils.Json;
3
4
  import com.badlogic.gdx.utils.JsonValue;
@@ -13,7 +14,7 @@ public class ImageJson extends Image implements Json.Serializer<ImageJson> {
13
14
  public float addEffectDelay = 0f;
14
15
 
15
16
  public EventType evtType = EventType.None;
16
- public OnEventType onEvtType = OnEventType.DoEffect;
17
+ public Scene.OnEventType onEvtType = Scene.OnEventType.DoEffect;
17
18
  public String eventScene = "";
18
19
 
19
20
 
@@ -41,7 +42,7 @@ public class ImageJson extends Image implements Json.Serializer<ImageJson> {
41
42
  image.addEffectDelay = jv.getFloat("addEffectDelay");
42
43
 
43
44
  image.evtType = EventType.valueOf(jv.getString("event"));
44
- image.onEvtType = OnEventType.valueOf(jv.getString("onEvent"));
45
+ image.onEvtType = Scene.OnEventType.valueOf(jv.getString("onEvent"));
45
46
  image.eventScene = jv.getString("eventScene");
46
47
  createEvent(image);
47
48
  return image;
{Type → src/scene2d}/InterpolationType.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.math.Interpolation;
2
3
 
3
4
 
{Stage → src/scene2d}/Map.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.graphics.g2d.TextureRegion;
2
3
  import com.badlogic.gdx.maps.MapLayer;
3
4
  import com.badlogic.gdx.maps.MapLayers;
@@ -44,12 +45,12 @@ public class Map extends Group{
44
45
  }
45
46
 
46
47
  public void loadLayer(int layerNo){
47
- Stage.log("Tiles Layer no: "+layerNo);
48
+ Scene.log("Tiles Layer no: "+layerNo);
48
49
  TiledMapTileLayer layer = (TiledMapTileLayer)mlayers.get(layerNo);
49
50
  NoOfColumns = layer.getWidth();
50
- Stage.log("MapColumns: "+NoOfColumns);
51
+ Scene.log("MapColumns: "+NoOfColumns);
51
52
  NoOfRows = layer.getHeight();
52
- Stage.log("MapRows: "+NoOfRows);
53
+ Scene.log("MapRows: "+NoOfRows);
53
54
  tiles .add(new MapActor[NoOfRows][NoOfColumns]);
54
55
  for(int i=0; i<NoOfRows; i++)
55
56
  for(int j=0; j<NoOfColumns; j++){
@@ -66,12 +67,12 @@ public class Map extends Group{
66
67
  }
67
68
  mapWidth = tileSize * NoOfColumns;
68
69
  mapHeight = tileSize * NoOfRows;
69
- Stage.mapOffsetX = mapWidth - Stage.camOffsetX;
70
+ //Stage.mapOffsetX = mapWidth - Stage.camOffsetX;
70
- Stage.mapOffsetY = mapHeight - Stage.camOffsetYTop;
71
+ //Stage.mapOffsetY = mapHeight - Stage.camOffsetYTop;
71
72
  }
72
73
 
73
74
  public void loadObjects(int no){
74
- Stage.log("Objects Layer no: "+no);
75
+ Scene.log("Objects Layer no: "+no);
75
76
  MapLayer layer1 = mlayers.get(no);
76
77
  mobjects = layer1.getObjects();
77
78
  }
{Stage → src/scene2d}/MapActor.java RENAMED
@@ -1,14 +1,10 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.Gdx;
2
3
  import com.badlogic.gdx.graphics.g2d.Animation;
3
4
  import com.badlogic.gdx.graphics.g2d.Batch;
4
5
  import com.badlogic.gdx.graphics.g2d.ParticleEffect;
5
6
  import com.badlogic.gdx.graphics.g2d.TextureRegion;
6
- import com.badlogic.gdx.scenes.scene2d.Action;
7
7
  import com.badlogic.gdx.scenes.scene2d.Actor;
8
- import com.badlogic.gdx.scenes.scene2d.actions.Actions;
9
- import com.badlogic.gdx.scenes.scene2d.actions.MoveByAction;
10
- import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
11
- import com.badlogic.gdx.utils.Array;
12
8
 
13
9
  /** The MapActor Class
14
10
  * <p>
@@ -44,8 +40,6 @@ public class MapActor extends Actor {
44
40
  public float particlePosX = 0.0f;
45
41
  public float particlePosY = 0.0f;
46
42
  public boolean isParticleEffectActive;
47
-
48
- private Array<MovedListener> movedListeners = new Array<MovedListener>();
49
43
 
50
44
  // When tiles coords row and column are directly specified
51
45
  public MapActor(int row, int col, int tileSize){
@@ -80,7 +74,7 @@ public class MapActor extends Actor {
80
74
  batch.draw(tileImage, getX(), getY(), tileSize, tileSize);
81
75
  //font("normal").draw(batch, ""+index, getX(), getY()+tileSize);
82
76
  if (isAnimationActive && animation != null) {
83
- keyFrame = animation.getKeyFrame(Stage.stateTime, isAnimationLooping);
77
+ keyFrame = animation.getKeyFrame(Scene.stateTime, isAnimationLooping);
84
78
  batch.draw(keyFrame, getX(), getY(), tileSize, tileSize);
85
79
  }
86
80
  drawParticleEffect(batch);
@@ -159,42 +153,6 @@ public class MapActor extends Actor {
159
153
  this.col = (int)this.getX()/tileSize;
160
154
  }
161
155
 
162
- public void moveTo(float x, float y, float duration) {
163
- // Move to a specific position by time
164
- MoveToAction move = new MoveToAction();
165
- move.setPosition(x, y);
166
- if (duration > 0.0f) {
167
- move.setDuration(duration);
168
- }
169
- Action over = new Action() {
170
- @Override
171
- public boolean act(final float it) {
172
- setPosition(this.getActor().getX(), this.getActor().getY());
173
- fireMovedEvent();
174
- return true;
175
- }
176
- };
177
- addAction(Actions.sequence(move, over));
178
- }
179
-
180
- public void moveBy(float x, float y, float duration) {
181
- // Move towards a direction during given time (NON-STOP)
182
- MoveByAction move = new MoveByAction();
183
- move.setAmount(x, y);
184
- if (duration > 0.0f) {
185
- move.setDuration(duration);
186
- }
187
- Action over = new Action() {
188
- @Override
189
- public boolean act(final float it) {
190
- setPosition(this.getActor().getX(), this.getActor().getY());
191
- fireMovedEvent();
192
- return true;
193
- }
194
- };
195
- addAction(Actions.sequence(move, over));
196
- }
197
-
198
156
  /**
199
157
  * Translate actor in a direction of speed without stopping. Actor moves in
200
158
  * constants speed set without acceleration
@@ -240,13 +198,4 @@ public class MapActor extends Actor {
240
198
  public Animation getAnimation(){
241
199
  return animation;
242
200
  }
243
-
244
- public void addListener(MovedListener ml){
245
- movedListeners.add(ml);
246
- }
247
-
248
- public void fireMovedEvent(){
249
- for(MovedListener ml: movedListeners)
250
- ml.onMoved();
251
- }
252
201
  }
{Stage → src/scene2d}/Net.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  /*
2
3
  import java.io.IOException;
3
4
  import java.io.InputStream;
src/scene2d/Scene.java ADDED
@@ -0,0 +1,921 @@
1
+ package scene2d;
2
+ import scene3d.Actor3d;
3
+ import scene3d.Group3d;
4
+ import scene3d.Stage3d;
5
+
6
+ import com.badlogic.gdx.ApplicationListener;
7
+ import com.badlogic.gdx.Gdx;
8
+ import com.badlogic.gdx.InputMultiplexer;
9
+ import com.badlogic.gdx.graphics.Color;
10
+ import com.badlogic.gdx.graphics.GL20;
11
+ import com.badlogic.gdx.graphics.PerspectiveCamera;
12
+ import com.badlogic.gdx.graphics.g2d.Batch;
13
+ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
14
+ import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
15
+ import com.badlogic.gdx.math.Intersector;
16
+ import com.badlogic.gdx.math.MathUtils;
17
+ import com.badlogic.gdx.math.Rectangle;
18
+ import com.badlogic.gdx.math.Vector2;
19
+ import com.badlogic.gdx.scenes.scene2d.Actor;
20
+ import com.badlogic.gdx.scenes.scene2d.Group;
21
+ import com.badlogic.gdx.scenes.scene2d.InputEvent;
22
+ import com.badlogic.gdx.scenes.scene2d.Touchable;
23
+ import com.badlogic.gdx.scenes.scene2d.actions.Actions;
24
+ import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
25
+ import com.badlogic.gdx.scenes.scene2d.ui.Image;
26
+ import com.badlogic.gdx.scenes.scene2d.ui.Label;
27
+ import com.badlogic.gdx.scenes.scene2d.ui.Table;
28
+ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
29
+ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
30
+ import com.badlogic.gdx.utils.ArrayMap;
31
+ import com.badlogic.gdx.utils.Json;
32
+ import com.badlogic.gdx.utils.JsonReader;
33
+ import com.badlogic.gdx.utils.JsonValue;
34
+ import com.badlogic.gdx.utils.Scaling;
35
+ import com.badlogic.gdx.utils.StringBuilder;
36
+ import com.badlogic.gdx.utils.Timer;
37
+ import com.badlogic.gdx.utils.Timer.Task;
38
+
39
+ abstract public class Scene extends Group {
40
+ /* The array map containing all the scenes data of the game*/
41
+ public static final ArrayMap<String, String> scenesMap = new ArrayMap<String, String>();
42
+ private String sceneName = "";
43
+ public String sceneBackground = "None";
44
+ public String sceneMusic = "None";
45
+ public String sceneTransition = "None";
46
+ public float sceneDuration = 0;
47
+ public InterpolationType sceneInterpolationType = InterpolationType.Linear;
48
+
49
+ public static Color bgColor = new Color(1f,1f,1f,1f);
50
+ public static JsonValue configJson = null;
51
+ public static final JsonReader jsonReader = new JsonReader();
52
+ public static final Json json = new Json();
53
+ public static float splashDuration = 0f;
54
+ public static boolean pauseState = false;
55
+ /*Important:
56
+ * The Target Width and Target Height refer to the nominal width and height of the game for the
57
+ * graphics which are created for this width and height, this allows for the Stage to scale this
58
+ * graphics for all screen width and height. Therefore your game will work on all screen sizes
59
+ * but maybe blurred or look awkward on some devices.
60
+ * ex:
61
+ * My Game targetWidth = 800 targetHeight = 480
62
+ * Then my game works perfectly for SCREEN_WIDTH = 800 SCREEN_HEIGHT = 480
63
+ * and on others screen sizes it is just zoomed/scaled but works fine thats all
64
+ */
65
+ public static float targetWidth = 800;
66
+ public static float targetHeight = 480;
67
+ public static boolean debug = false;
68
+ public final static Vector2 mouse = new Vector2();
69
+
70
+ private static Scene currentScene = null;
71
+ private static int sceneIndex = 0;
72
+
73
+ public static ClassLoader cl = null;
74
+ public static com.badlogic.gdx.scenes.scene2d.Stage stage2d;
75
+ public static Stage3d stage3d;
76
+ private static Label fpsLabel;
77
+ private static InputMultiplexer inputMux;
78
+
79
+ public static int mousePointer = 0;
80
+ public static int mouseButton = 0;
81
+ public static boolean cullingEnabled = false;
82
+ public static boolean isDirty = false;
83
+ public static String basePackage = "source.";
84
+
85
+ public Scene(){
86
+ setTouchable(Touchable.childrenOnly);
87
+ Camera.reset();
88
+ stage2d.clear();
89
+ stage3d.clear();
90
+ stage2d.addListener(touchInput);
91
+ setSize(targetWidth, targetHeight);
92
+ setBounds(0,0, targetWidth, targetHeight);
93
+ setColor(1f, 1f, 1f, 1f);
94
+ setVisible(true);
95
+ stage2d.getRoot().setPosition(0, 0);
96
+ stage2d.getRoot().setVisible(true);
97
+ stage3d.getRoot().setPosition(0, 0, 0);
98
+ stage3d.getRoot().setVisible(true);
99
+ sceneName = this.getClass().getName();
100
+ setName(sceneName);
101
+ Scene.log("Current Scene: "+sceneName);
102
+ currentScene = this;
103
+ load(sceneName);
104
+ cullingEnabled = true;
105
+ }
106
+
107
+ @Override
108
+ public void act(float delta){
109
+ super.act(delta);
110
+ if (fpsLabel != null)
111
+ fpsLabel.setText("Fps: " + Gdx.graphics.getFramesPerSecond());
112
+ }
113
+
114
+ public abstract void onClick(Actor actor);
115
+ public abstract void onTouchDown(Actor actor);
116
+ public abstract void onTouchUp();
117
+ public abstract void onDragged();
118
+ public abstract void onGesture(GestureType gestureType);
119
+ public abstract void onKeyTyped(char key);
120
+ public abstract void onKeyUp(int keycode);
121
+ public abstract void onKeyDown(int keycode);
122
+ /*
123
+ * This will pause any music and stop any sound being played
124
+ * and will fire the Pause event
125
+ */
126
+ public abstract void onPause();
127
+ /*
128
+ * This will resume any music currently being played
129
+ * and will fire the Resume event
130
+ */
131
+ public abstract void onResume();
132
+ public abstract void onDispose();
133
+
134
+ public void load(String sceneName){
135
+ log("Load "+sceneName);
136
+ if(!sceneName.contains(basePackage) && !sceneName.contains("gdxstudio"))
137
+ sceneName = basePackage+sceneName;
138
+ String[] lines = scenesMap.get(sceneName).split("\n");
139
+ for(String line: lines){
140
+ if(line.trim().isEmpty())
141
+ continue;
142
+ json.fromJson(null, line);
143
+ //log(line);
144
+ }
145
+ if(!sceneBackground.equals("None"))
146
+ setBackground(sceneBackground);
147
+ if(!sceneMusic.equals("None"))
148
+ Asset.musicPlay(sceneMusic);
149
+ if(!sceneTransition.equals("None"))
150
+ Effect.createEffect(Scene.getRoot(), EffectType.valueOf(sceneTransition), 1f,
151
+ sceneDuration, sceneInterpolationType);
152
+ }
153
+
154
+ protected void save(){
155
+ save(sceneName);
156
+ }
157
+
158
+ public void save(String sceneName){
159
+ if(!isDirty)
160
+ return;
161
+ if(sceneName == null || sceneName.isEmpty())
162
+ return;
163
+ Scene.log("Save "+sceneName);
164
+ if(!sceneName.contains(basePackage) && !sceneName.contains("gdxstudio"))
165
+ sceneName = basePackage+sceneName;
166
+ StringBuilder sb = new StringBuilder();
167
+ for(Actor actor: getChildren()){
168
+ sb.append(json.toJson(actor));
169
+ sb.append("\n");
170
+ }
171
+ sb.append(json.toJson(getRoot().findActor(this.sceneName)));//??Warning
172
+ scenesMap.put(sceneName, sb.toString());
173
+ Gdx.files.local(Asset.basePath+"scene").writeString(json.toJson(scenesMap, ArrayMap.class,
174
+ String.class), false);
175
+ sb = null;
176
+ isDirty = false;
177
+ }
178
+
179
+ /**
180
+ * Set the current scene to be displayed
181
+ * @param className The scene's Class Name
182
+ **/
183
+ public static void setScene(String className){
184
+ if(!className.contains(basePackage) && !className.contains("gdxstudio"))
185
+ className = basePackage+className;
186
+ if(!scenesMap.containsKey(className)){
187
+ log(className+": Scene Does not Exist");
188
+ return;
189
+ }
190
+ /*
191
+ * Every time the scene Changes disable panning/following/listening as it can cause the
192
+ * camera to move around aimlessly, thus abrupting the scene and clear
193
+ * all the listeners/huds that were registered in the previous scene
194
+ */
195
+ sceneIndex = Scene.scenesMap.keys().toArray().indexOf(className, false);
196
+ if(currentScene != null)
197
+ currentScene.onDispose();
198
+ try {
199
+ if(cl != null)
200
+ cl.loadClass(className).newInstance();
201
+ else
202
+ Class.forName(className).newInstance();
203
+ } catch (InstantiationException e) {
204
+ log("Scene cannot be created , Check if scene class constructor is empty");
205
+ e.printStackTrace();
206
+ } catch (IllegalAccessException e) {
207
+ log("Scene cannot be created , Check if scene class can be found");
208
+ e.printStackTrace();
209
+ } catch (ClassNotFoundException e) {
210
+ log("Scene cannot be created , Check if scene class can be found");
211
+ e.printStackTrace();
212
+ }
213
+ //if (fpsLabel != null && configJson.getBoolean("showFPS")){
214
+ // fpsLabel.setPosition(targetWidth - 80, targetHeight - 20);
215
+ // Camera.addHud(fpsLabel);
216
+ //}
217
+ }
218
+
219
+ /**
220
+ * Set the current scene to be displayed with an amount of delay
221
+ * @param className The registered scene's name
222
+ **/
223
+ public static void setSceneWithDelay(final String className, float delay){
224
+ Timer.schedule(new Task(){
225
+ @Override
226
+ public void run() {
227
+ setScene(className);
228
+ }
229
+ }, delay);
230
+ }
231
+
232
+ /**
233
+ * Returns the current scene being Displayed on stage
234
+ **/
235
+ public static Scene getCurrentScene(){
236
+ return currentScene;
237
+ }
238
+
239
+ /**
240
+ * Changes to the next scene in the scnesList
241
+ **/
242
+ public static void nextScene(){
243
+ if(sceneIndex <= scenesMap.size)
244
+ sceneIndex++;
245
+ setScene(scenesMap.getKeyAt(sceneIndex));
246
+ }
247
+
248
+ /**
249
+ * Changes to the previous scene in the scnesList
250
+ **/
251
+ public static void prevScene(){
252
+ if(sceneIndex >= 0)
253
+ sceneIndex--;
254
+ setScene(scenesMap.getKeyAt(sceneIndex));
255
+ }
256
+
257
+ /**
258
+ * Changes to the next scene in the scnesList
259
+ **/
260
+ public static void nextSceneWithDelay(float delay){
261
+ if(sceneIndex <= scenesMap.size)
262
+ sceneIndex++;
263
+ setSceneWithDelay(Scene.scenesMap.getKeyAt(sceneIndex), delay);
264
+ }
265
+
266
+ /**
267
+ * Changes to the previous scene in the scnesList
268
+ **/
269
+ public static void prevSceneWithDelay(float delay){
270
+ if(sceneIndex >= 0)
271
+ sceneIndex--;
272
+ setSceneWithDelay(scenesMap.getKeyAt(sceneIndex), delay);
273
+ }
274
+
275
+ private static Image imgbg = null;
276
+ public void setBackground(String texName) {
277
+ if(imgbg != null)
278
+ removeBackground();
279
+ if(Asset.tex(texName) != null){
280
+ imgbg = new Image(new TextureRegionDrawable(Asset.tex(texName)), Scaling.stretch);
281
+ imgbg.setFillParent(true);
282
+ stage2d.addActor(imgbg);
283
+ imgbg.toBack();
284
+ }
285
+ }
286
+
287
+ public void removeBackground() {
288
+ getRoot().removeActor(imgbg);
289
+ }
290
+
291
+ public static Group getRoot(){
292
+ return stage2d.getRoot();
293
+ }
294
+
295
+ public void addActor(Actor actor, float x, float y){
296
+ if(actor != null){
297
+ actor.setPosition(x, y);
298
+ addActor(actor);
299
+ }
300
+ }
301
+
302
+ public void addActorWithDelay(final Actor actor, float delay){
303
+ Timer.schedule(new Task(){
304
+ @Override
305
+ public void run() {
306
+ addActor(actor);
307
+ }
308
+ }, delay);
309
+ }
310
+
311
+ public boolean removeActor(String actorName){
312
+ return removeActor(findActor(actorName));
313
+ }
314
+
315
+ public void removeActorWithDelay(Actor actor, float delay){
316
+ addAction(Actions.sequence(Actions.delay(delay), Actions.removeActor(actor)));
317
+ }
318
+
319
+ public Actor hit(float x, float y){
320
+ return hit(x, y, true);
321
+ }
322
+
323
+
324
+ /* Dragging Camera Related */
325
+ static boolean gestureStarted = false;
326
+ static Actor validActor = null;
327
+ private final ClickListener touchInput = new ClickListener(){
328
+ @Override
329
+ public void clicked(InputEvent event, float x, float y){
330
+ super.clicked(event, x, y);
331
+ mouse.set(x, y);
332
+ validActor = hit(x,y);
333
+ if(validActor != null && validActor.getName() != null)
334
+ Scene.getCurrentScene().onClick(validActor);
335
+ }
336
+
337
+ @Override
338
+ public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
339
+ mouse.set(x, y);
340
+ mousePointer = pointer;
341
+ mouseButton = button;
342
+ touchInitialX = x;
343
+ touchInitialY = y;
344
+ gestureStarted = true;
345
+ validActor = hit(x,y);
346
+ if(validActor != null && validActor.getName() != null)
347
+ Scene.getCurrentScene().onTouchDown(validActor);
348
+ return super.touchDown(event, x, y, pointer, button);
349
+ }
350
+
351
+
352
+ @Override
353
+ public void touchDragged(InputEvent event, float x, float y, int pointer){
354
+ super.touchDragged(event, x, y, pointer);
355
+ mouse.set(x, y);
356
+ mousePointer = pointer;
357
+ Scene.getCurrentScene().onDragged();
358
+ if(gestureStarted == true){
359
+ touchCurrentX = x;
360
+ touchCurrentY = y;
361
+ if(getGestureDirection() != GestureType.None){
362
+ gestureStarted = false;
363
+ Scene.getCurrentScene().onGesture(getGestureDirection());
364
+ }
365
+ }
366
+ if(Camera.useDrag)
367
+ Camera.dragCam((int)x, (int)-y);
368
+ }
369
+
370
+ @Override
371
+ public void touchUp(InputEvent event, float x, float y, int pointer, int button){
372
+ super.touchUp(event, x, y, pointer, button);
373
+ mouse.set(x, y);
374
+ mousePointer = pointer;
375
+ mouseButton = button;
376
+ // reset Gesture
377
+ difX = 0.0f;
378
+ difY = 0.0f;
379
+ touchInitialX = 0.0f;
380
+ touchInitialY = 0.0f;
381
+ touchCurrentX = 0.0f;
382
+ touchCurrentY = 0.0f;
383
+ touchDifX = 0.0f;
384
+ touchDifY = 0.0f;
385
+ prevDifX = 0.0f;
386
+ prevDifY = 0.0f;
387
+ // reset Gesture
388
+ Scene.getCurrentScene().onTouchUp();
389
+ Camera.resetDrag();
390
+ gestureStarted = false;
391
+ }
392
+
393
+ @Override
394
+ public boolean keyTyped(InputEvent event, char key) {
395
+ Scene.getCurrentScene().onKeyTyped(key);
396
+ return super.keyUp(event, key);
397
+ }
398
+
399
+ @Override
400
+ public boolean keyUp(InputEvent event, int keycode) {
401
+ Scene.getCurrentScene().onKeyUp(keycode);
402
+ return super.keyUp(event, keycode);
403
+ }
404
+ @Override
405
+ public boolean keyDown(InputEvent event, int keycode) {
406
+ Scene.getCurrentScene().onKeyDown(keycode);
407
+ return super.keyDown(event, keycode);
408
+ }
409
+ };
410
+
411
+ /*
412
+ * Gesture related
413
+ */
414
+ public static float touchDragIntervalRange = 200f; // 200px drag for a gesture event
415
+ public static float touchInitialX = 0.0f, touchInitialY = 0.0f;
416
+ public static float touchCurrentX = 0.0f, touchCurrentY = 0.0f;
417
+ public static float difX;
418
+ public static float difY;
419
+ public static float prevDifX;
420
+ public static float prevDifY;
421
+ public static float touchDifX;
422
+ public static float touchDifY;
423
+
424
+ public boolean isTouchDragInterval() {
425
+ difX = java.lang.Math.abs(touchInitialX - touchCurrentX);
426
+ difY = java.lang.Math.abs(touchInitialY - touchCurrentY);
427
+ if (difX > touchDragIntervalRange || difY > touchDragIntervalRange)
428
+ return true;
429
+ else
430
+ return false;
431
+ }
432
+
433
+ public static GestureType getGestureDirection() {
434
+ prevDifX = difX;
435
+ prevDifY = difY;
436
+ difX = java.lang.Math.abs(touchInitialX - touchCurrentX);
437
+ difY = java.lang.Math.abs(touchInitialY - touchCurrentY);
438
+ /**
439
+ * Get minimal changes on drag
440
+ * <p> checkMomentumChanges
441
+ * EXAMPLE<br>
442
+ * User drags finger to left, suddenly dragging to right without removing
443
+ * his finger from the screen
444
+ * */
445
+ if (prevDifX > difX || prevDifY > difY) {
446
+ touchInitialX = touchCurrentX;
447
+ touchInitialY = touchCurrentY;
448
+ //
449
+ difX = 0.0f;
450
+ difY = 0.0f;
451
+ prevDifX = 0.0f;
452
+ prevDifY = 0.0f;
453
+
454
+ /**
455
+ * Set touch differences, optional, if you need amount of change from
456
+ * initial touch to drag, USE THIS: on touchDrag, pan or similar mthods
457
+ * */
458
+ touchDifX = java.lang.Math.abs(touchInitialX - touchCurrentX);
459
+ touchDifY = java.lang.Math.abs(touchInitialY - touchCurrentY);
460
+ }
461
+ if (touchInitialY < touchCurrentY && difY > difX) {
462
+ return GestureType.Up;
463
+ } else if (touchInitialY > touchCurrentY && difY > difX) {
464
+ return GestureType.Down;
465
+ } else if (touchInitialX < touchCurrentX && difY < difX) {
466
+ return GestureType.Right;
467
+ } else if (touchInitialX > touchCurrentX && difY < difX) {
468
+ return GestureType.Left;
469
+ } else {
470
+ return GestureType.None;
471
+ }
472
+ }
473
+
474
+ /*
475
+ * Dialog Methods
476
+ */
477
+ public void showToast(String message, float duration){
478
+ Table table = new Table(Asset.skin);
479
+ table.add(" "+message+" ");
480
+ table.setBackground(Asset.skin.getDrawable("dialogDim"));
481
+ table.pack();
482
+ table.setPosition(Scene.targetWidth/2 - table.getWidth(), Scene.targetHeight/2 - table.getHeight());
483
+ addActor(table);
484
+ table.addAction(Actions.sequence(Actions.delay(duration), Actions.removeActor(table)));
485
+ }
486
+
487
+ public void showMessageDialog(String title, String message){
488
+ Dialog dialog = new Dialog(title, Asset.skin);
489
+ dialog.getContentTable().add(message);
490
+ dialog.button("OK", "OK");
491
+ dialog.pack();
492
+ dialog.show(getStage());
493
+ }
494
+
495
+ public boolean showConfirmDialog(String title, String message){
496
+ Dialog dialog = new Dialog(title, Asset.skin);
497
+ dialog.button("Yes", "Yes");
498
+ dialog.button("No", "No");
499
+ dialog.pack();
500
+ dialog.show(getStage());
501
+ //if(dialog.result().equals("Yes")) FIXME update Gdx
502
+ // return true;
503
+ return false;
504
+ }
505
+
506
+ public void outline(Actor actor){
507
+ selectionBox.setPosition(actor.getX(), actor.getY());
508
+ selectionBox.setSize(actor.getWidth(), actor.getHeight());
509
+ stage2d.addActor(selectionBox);
510
+ }
511
+
512
+ /***********************************************************************************************************
513
+ * 3d Related Functions *
514
+ ************************************************************************************************************/
515
+
516
+ public static void addActor3d(Actor3d actor3d){
517
+ stage3d.addActor3d(actor3d);
518
+ }
519
+
520
+ public static void removeActor3d(Actor3d actor3d){
521
+ stage3d.getRoot().removeActor3d(actor3d);
522
+ }
523
+
524
+ public static void removeActor3d(String actor3dName){
525
+ getRoot3d().removeActor3d(stage3d.getRoot().findActor(actor3dName));
526
+ }
527
+
528
+ public static Group3d getRoot3d(){
529
+ return stage3d.getRoot();
530
+ }
531
+
532
+ public static void getChildren3d(){
533
+ stage3d.getActors3d();
534
+ }
535
+
536
+ public static void resetCamera3d(){
537
+ stage3d.getCamera().position.set(10f, 10f, 10f);
538
+ stage3d.getCamera().lookAt(0,0,0);
539
+ stage3d.getCamera().near = 0.1f;
540
+ stage3d.getCamera().far = 300f;
541
+ }
542
+
543
+ public static PerspectiveCamera getCamera3d(){
544
+ return stage3d.getCamera();
545
+ }
546
+
547
+
548
+ public static void log(String log) {
549
+ if(Scene.configJson.getBoolean("loggingEnabled"))
550
+ Gdx.app.log("Stage ", log);
551
+ }
552
+
553
+
554
+ /***********************************************************************************************************
555
+ * Utilities Related Functions *
556
+ ************************************************************************************************************/
557
+ /*
558
+ * The the angle in degrees of the inclination of a line
559
+ * @param cx, cy The center point x, y
560
+ * @param tx, ty The target point x, y
561
+ */
562
+ public static float getAngle(float cx, float cy, float tx, float ty) {
563
+ float angle = (float) Math.toDegrees(MathUtils.atan2(tx - cx, ty - cy));
564
+ //if(angle < 0){
565
+ // angle += 360;
566
+ //}
567
+ return angle;
568
+ }
569
+
570
+ private static Vector2 distVector = new Vector2();
571
+ public static final float getDistance(Actor a, Actor b){
572
+ distVector.set(a.getX(), a.getY());
573
+ return distVector.dst(b.getX(), b.getY());
574
+ }
575
+
576
+ public static final float getDistance(float x1, float y1, float x2, float y2){
577
+ distVector.set(x1, y1);
578
+ return distVector.dst(x2, y2);
579
+ }
580
+
581
+ /*
582
+ * Capitalizes the First Letter of a String
583
+ */
584
+ public static String capitalize(String text){
585
+ if(text != null && text != "")
586
+ return (text.substring(0, 1)).toUpperCase() + text.substring(1);
587
+ else
588
+ return "";
589
+ }
590
+
591
+ /*
592
+ * UnCapitalizes the First Letter of a String
593
+ */
594
+ public static String uncapitalize(String text){
595
+ return text.substring(0, 1).toLowerCase()+text.substring(1);
596
+ }
597
+
598
+ public static Rectangle getBounds(Actor actor) {
599
+ float posX = actor.getX();
600
+ float posY = actor.getY();
601
+ float width = actor.getWidth();
602
+ float height = actor.getHeight();
603
+ return new Rectangle(posX, posY, width, height);
604
+ }
605
+
606
+ public static boolean collides(Actor actor, float x, float y) {
607
+ Rectangle rectA1 = getBounds(actor);
608
+ Rectangle rectA2 = new Rectangle(x, y, 5, 5);
609
+ // Check if rectangles collides
610
+ if (Intersector.overlaps(rectA1, rectA2)) {
611
+ return true;
612
+ } else {
613
+ return false;
614
+ }
615
+ }
616
+
617
+ public static boolean collides(Actor actor1, Actor actor2) {
618
+ Rectangle rectA1 = getBounds(actor1);
619
+ Rectangle rectA2 = getBounds(actor2);
620
+ // Check if rectangles collides
621
+ if (Intersector.overlaps(rectA1, rectA2)) {
622
+ return true;
623
+ } else {
624
+ return false;
625
+ }
626
+ }
627
+
628
+
629
+ /**
630
+ * Get screen time from start in format of HH:MM:SS. It is calculated from
631
+ * "secondsTime" parameter.
632
+ * */
633
+ public static String toScreenTime(float secondstime) {
634
+ int seconds = (int)(secondstime % 60);
635
+ int minutes = (int)((secondstime / 60) % 60);
636
+ int hours = (int)((secondstime / 3600) % 24);
637
+ return new String(addZero(hours) + ":" + addZero(minutes) + ":" + addZero(seconds));
638
+ }
639
+
640
+ private static String addZero(int value){
641
+ String str = "";
642
+ if(value < 10)
643
+ str = "0" + value;
644
+ else
645
+ str = "" + value;
646
+ return str;
647
+ }
648
+
649
+ /*
650
+ * TEA Encryption and Decryption
651
+ */
652
+ public static String encryptKey = "Default";
653
+ private static final int encryptDelta = 0x9E3779B9;
654
+ private static final int MX(int sum, int y, int z, int p, int e, int[] k) {
655
+ return (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
656
+ }
657
+
658
+ public static final byte[] encrypt(String data) {
659
+ return encrypt(data.getBytes(), encryptKey.getBytes());
660
+ }
661
+
662
+ public static final byte[] decrypt(String data) {
663
+ return decrypt(data.getBytes(), encryptKey.getBytes());
664
+ }
665
+
666
+ public static final byte[] encrypt(String data, String key) {
667
+ return encrypt(data.getBytes(), key.getBytes());
668
+ }
669
+
670
+ public static final byte[] decrypt(String data, String key) {
671
+ return decrypt(data.getBytes(), key.getBytes());
672
+ }
673
+
674
+ private static final byte[] encrypt(byte[] data, byte[] key) {
675
+ if (data.length == 0)
676
+ return data;
677
+ return toByteArray(encrypt(toIntArray(data, true), toIntArray(key, false)), false);
678
+ }
679
+
680
+
681
+ private static final byte[] decrypt(byte[] data, byte[] key) {
682
+ if (data.length == 0)
683
+ return data;
684
+ return toByteArray(decrypt(toIntArray(data, false), toIntArray(key, false)), true);
685
+ }
686
+
687
+ private static final int[] encrypt(int[] v, int[] k) {
688
+ int n = v.length - 1;
689
+ if (n < 1) {
690
+ return v;
691
+ }
692
+ if (k.length < 4) {
693
+ int[] key = new int[4];
694
+
695
+ System.arraycopy(k, 0, key, 0, k.length);
696
+ k = key;
697
+ }
698
+ int z = v[n], y = v[0], sum = 0, e;
699
+ int p, q = 6 + 52 / (n + 1);
700
+
701
+ while (q-- > 0) {
702
+ sum = sum + encryptDelta;
703
+ e = sum >>> 2 & 3;
704
+ for (p = 0; p < n; p++) {
705
+ y = v[p + 1];
706
+ z = v[p] += MX(sum, y, z, p, e, k);
707
+ }
708
+ y = v[0];
709
+ z = v[n] += MX(sum, y, z, p, e, k);
710
+ }
711
+ return v;
712
+ }
713
+
714
+ private static final int[] decrypt(int[] v, int[] k) {
715
+ int n = v.length - 1;
716
+
717
+ if (n < 1) {
718
+ return v;
719
+ }
720
+ if (k.length < 4) {
721
+ int[] key = new int[4];
722
+
723
+ System.arraycopy(k, 0, key, 0, k.length);
724
+ k = key;
725
+ }
726
+ int z = v[n], y = v[0], sum, e;
727
+ int p, q = 6 + 52 / (n + 1);
728
+
729
+ sum = q * encryptDelta;
730
+ while (sum != 0) {
731
+ e = sum >>> 2 & 3;
732
+ for (p = n; p > 0; p--) {
733
+ z = v[p - 1];
734
+ y = v[p] -= MX(sum, y, z, p, e, k);
735
+ }
736
+ z = v[n];
737
+ y = v[0] -= MX(sum, y, z, p, e, k);
738
+ sum = sum - encryptDelta;
739
+ }
740
+ return v;
741
+ }
742
+
743
+
744
+ private static final int[] toIntArray(byte[] data, boolean includeLength) {
745
+ int n = (((data.length & 3) == 0)
746
+ ? (data.length >>> 2)
747
+ : ((data.length >>> 2) + 1));
748
+ int[] result;
749
+
750
+ if (includeLength) {
751
+ result = new int[n + 1];
752
+ result[n] = data.length;
753
+ }
754
+ else {
755
+ result = new int[n];
756
+ }
757
+ n = data.length;
758
+ for (int i = 0; i < n; i++) {
759
+ result[i >>> 2] |= (0x000000ff & data[i]) << ((i & 3) << 3);
760
+ }
761
+ return result;
762
+ }
763
+
764
+
765
+ private static final byte[] toByteArray(int[] data, boolean includeLength) {
766
+ int n = data.length << 2;
767
+
768
+ if (includeLength) {
769
+ int m = data[data.length - 1];
770
+
771
+ if (m > n) {
772
+ return null;
773
+ }
774
+ else {
775
+ n = m;
776
+ }
777
+ }
778
+ byte[] result = new byte[n];
779
+
780
+ for (int i = 0; i < n; i++) {
781
+ result[i] = (byte) ((data[i >>> 2] >>> ((i & 3) << 3)) & 0xff);
782
+ }
783
+ return result;
784
+ }
785
+
786
+ private static ShapeRenderer shapeRenderer;
787
+ private final static Actor selectionBox = new Actor(){
788
+ @Override
789
+ public void draw(Batch batch, float alpha){
790
+ batch.end();
791
+ shapeRenderer.begin(ShapeType.Line);
792
+ shapeRenderer.setColor(Color.GREEN);
793
+ shapeRenderer.rect(getX(), getY(),
794
+ getWidth(),getHeight());
795
+ shapeRenderer.end();
796
+ batch.begin();
797
+ }
798
+ };
799
+
800
+ static void setupFps(){
801
+ fpsLabel = new Label("", Asset.skin);
802
+ fpsLabel.setName("Fps");
803
+ }
804
+ public static float stateTime = 0;
805
+ public static float gameUptime = 0;
806
+ private static float startTime = System.nanoTime();
807
+ /*
808
+ * The main application listener for the game
809
+ */
810
+ public static ApplicationListener app = new ApplicationListener() {
811
+ public int dots = 40;
812
+ public int xlines;
813
+ public int ylines;
814
+ @Override
815
+ public final void create() {
816
+ log("Create");
817
+ Config.setup();
818
+ Serializer.setup();
819
+ stage2d = new com.badlogic.gdx.scenes.scene2d.Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
820
+ Scene.configJson.getBoolean("keepAspectRatio"));
821
+ stage2d.getRoot().setName("Root");
822
+ stage2d.getRoot().setTouchable(Touchable.childrenOnly);
823
+ stage2d.setCamera(new Camera());
824
+ inputMux = new InputMultiplexer();
825
+ inputMux.addProcessor(stage2d);
826
+ stage3d = new Stage3d();
827
+ //camController = new CameraInputController(stage3d.getCamera());
828
+ //inputMux.addProcessor(stage3d);
829
+ //inputMux.addProcessor(camController);
830
+ shapeRenderer = new ShapeRenderer();
831
+ selectionBox.setTouchable(Touchable.disabled);
832
+ selectionBox.setName("Shape");
833
+ JsonValue sv = Scene.jsonReader.parse(Gdx.files.internal(Asset.basePath+"scene"));
834
+ for(JsonValue jv: sv.iterator())
835
+ scenesMap.put(jv.name, jv.asString());
836
+ setScene(scenesMap.firstKey());
837
+ Gdx.input.setCatchBackKey(true);
838
+ Gdx.input.setCatchMenuKey(true);
839
+ Gdx.input.setInputProcessor(inputMux);
840
+ xlines = (int)Gdx.graphics.getWidth()/dots;
841
+ ylines = (int)Gdx.graphics.getHeight()/dots;
842
+ }
843
+ /*
844
+ * This is the main rendering call that updates the time, updates the stage,
845
+ * loads assets asynchronously, updates the camera and FPS text.
846
+ */
847
+ @Override
848
+ public final void render(){
849
+ Gdx.gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
850
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT |GL20.GL_DEPTH_BUFFER_BIT);
851
+ if (System.nanoTime() - startTime >= 1000000000) {
852
+ gameUptime +=1 ;
853
+ startTime = System.nanoTime();
854
+ }
855
+ stateTime += Gdx.graphics.getDeltaTime();
856
+ Asset.load();
857
+ stage3d.act();
858
+ stage3d.draw();
859
+ //camController.update();
860
+ Scene.stage2d.act();//Gdx.graphics.getDeltaTime();
861
+ Scene.stage2d.draw();
862
+ if(debug){
863
+ shapeRenderer.begin(ShapeType.Point);
864
+ shapeRenderer.setColor(Color.BLACK);
865
+ for(int i = 0; i<=xlines; i++)
866
+ for(int j = 0; j<=ylines; j++)
867
+ shapeRenderer.point(2+i*dots, j*dots, 0);
868
+ shapeRenderer.end();
869
+ }
870
+ }
871
+ @Override
872
+ public final void resize(int width, int height) {
873
+ log("Resize");
874
+ stage2d.setViewport(targetWidth, targetHeight, configJson.getBoolean("keepAspectRatio"));
875
+ stage3d.setViewport(targetWidth, targetHeight, configJson.getBoolean("keepAspectRatio"));
876
+ }
877
+ @Override
878
+ public final void pause() {
879
+ log("Pause");
880
+ Asset.musicPause();
881
+ Asset.soundStop();
882
+ Scene.pauseState = true;
883
+ Scene.getCurrentScene().onPause();
884
+ }
885
+ @Override
886
+ public final void resume() {
887
+ log("Resume");
888
+ Asset.musicResume();
889
+ Scene.pauseState = false;
890
+ Scene.getCurrentScene().onResume();
891
+ }
892
+ @Override
893
+ public final void dispose() {
894
+ log("Dispose");
895
+ Scene.getCurrentScene().onDispose();
896
+ Scene.stage2d.dispose();
897
+ Asset.unloadAll();
898
+ Gdx.app.exit();
899
+ }
900
+ };
901
+
902
+ public static final void exit(){
903
+ log("Disposing and Exiting");
904
+ getCurrentScene().onDispose();
905
+ stage2d.dispose();
906
+ stage3d.dispose();
907
+ Asset.unloadAll();
908
+ Gdx.app.exit();
909
+ }
910
+
911
+
912
+ public enum GestureType {
913
+ None, Up, Down, Left, Right
914
+ }
915
+
916
+ public enum OnEventType {
917
+ DoEffect,
918
+ SetScene
919
+ }
920
+
921
+ }
{Stage → src/scene2d}/Serializer.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.graphics.Color;
2
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
3
4
  import com.badlogic.gdx.scenes.scene2d.Group;
@@ -26,11 +27,11 @@ import com.badlogic.gdx.utils.JsonValue;
26
27
 
27
28
  public class Serializer {
28
29
 
29
- public static void registerSerializer(Class clazz, Json.Serializer serializer){
30
+ public static void registerSerializer(Class<?> clazz, Json.Serializer serializer){
30
- Stage.json.setSerializer(clazz, serializer);
31
+ Scene.json.setSerializer(clazz, serializer);
31
32
  }
32
33
 
33
- public static void initialize(){
34
+ public static void setup(){
34
35
  registerSerializer(Actor.class, new ActorSerializer());
35
36
  registerSerializer(Scene.class, new SceneSerializer());
36
37
  registerSerializer(ImageJson.class, new ImageJson());
@@ -82,10 +83,11 @@ public class Serializer {
82
83
  actor.setOriginX(jv.getFloat("ox"));
83
84
  actor.setOriginY(jv.getFloat("oy"));
84
85
  actor.setRotation(jv.getFloat("rotation"));
85
- //actor.setZIndex(jv.getInt("zindex"));
86
86
  actor.setColor(Color.valueOf(jv.getString("color")));
87
87
  actor.setTouchable(Touchable.valueOf(jv.getString("touchable")));
88
88
  actor.setVisible(jv.getBoolean("visible"));
89
+ Scene.getCurrentScene().addActor(actor);
90
+ actor.setZIndex(jv.getInt("zindex"));
89
91
  }
90
92
 
91
93
  public static void writeActor(Json json, Actor actor){
@@ -109,12 +111,14 @@ public class Serializer {
109
111
  public static class SceneSerializer extends ActorSerializer {
110
112
  @Override
111
113
  public Actor read(Json json, JsonValue jv, Class arg2) {
112
- Scene scene = Stage.getScene();
114
+ Scene scene = Scene.getCurrentScene();
113
115
  scene.sceneBackground = jv.getString("background");
114
116
  scene.sceneMusic = jv.getString("music");
115
117
  scene.sceneTransition = jv.getString("transition");
116
118
  scene.sceneDuration = jv.getFloat("duration");
117
119
  scene.sceneInterpolationType = InterpolationType.valueOf(jv.getString("interpolation"));
120
+ Scene.log(Scene.getCurrentScene().getName());
121
+ Scene.getRoot().addActor(scene);
118
122
  return scene;
119
123
  }
120
124
 
@@ -122,7 +126,7 @@ public class Serializer {
122
126
  public void write(Json json, Actor label, Class arg2) {
123
127
  json.writeObjectStart();
124
128
  Scene scene = (Scene) label;
125
- json.writeValue("class", "Scene");
129
+ json.writeValue("class", Scene.class.getName());
126
130
  json.writeValue("background", scene.sceneBackground);
127
131
  json.writeValue("music", scene.sceneMusic);
128
132
  json.writeValue("transition", scene.sceneTransition);
@@ -176,14 +180,14 @@ public class Serializer {
176
180
  @Override
177
181
  public Actor read(Json json, JsonValue jv, Class arg2) {
178
182
  CheckBox check = new CheckBox(jv.getString("text"), Asset.skin);
179
- ActorSerializer.readActor(jv, check);
183
+ readActor(jv, check);
180
184
  return check;
181
185
  }
182
186
 
183
187
  @Override
184
188
  public void write(Json json, Actor check, Class arg2) {
185
189
  json.writeObjectStart();
186
- ActorSerializer.writeActor(json, check);
190
+ writeActor(json, check);
187
191
  json.writeValue("text", ((CheckBox)check).getText().toString());
188
192
  json.writeObjectEnd();
189
193
  }
@@ -240,14 +244,14 @@ public class Serializer {
240
244
  @Override
241
245
  public Actor read(Json json, JsonValue jv, Class arg2) {
242
246
  List list = new List(jv.getString("text").split(","), Asset.skin);
243
- ActorSerializer.readActor(jv, list);
247
+ readActor(jv, list);
244
248
  return list;
245
249
  }
246
250
 
247
251
  @Override
248
252
  public void write(Json json, Actor list, Class arg2) {
249
253
  json.writeObjectStart();
250
- ActorSerializer.writeActor(json, list);
254
+ writeActor(json, list);
251
255
  String items = "";
252
256
  for(String s: ((List)list).getItems())
253
257
  items+=s+",";
@@ -263,14 +267,14 @@ public class Serializer {
263
267
  public Actor read(Json json, JsonValue jv, Class arg2) {
264
268
  Touchpad tp = new Touchpad(jv.getFloat("deadzoneRadius"), Asset.skin);
265
269
  deadZoneRadius = jv.getFloat("deadzoneRadius");
266
- ActorSerializer.readActor(jv, tp);
270
+ readActor(jv, tp);
267
271
  return tp;
268
272
  }
269
273
 
270
274
  @Override
271
275
  public void write(Json json, Actor tp, Class arg2) {
272
276
  json.writeObjectStart();
273
- ActorSerializer.writeActor(json, tp);
277
+ writeActor(json, tp);
274
278
  json.writeValue("deadzoneRadius", deadZoneRadius);
275
279
  json.writeObjectEnd();
276
280
  }
@@ -326,9 +330,10 @@ public class Serializer {
326
330
  else{
327
331
  sprite = new Sprite(jv.getFloat("duration"), jv.getString("textures").split(","));
328
332
  }
329
- ActorSerializer.readActor(jv, sprite);
333
+
330
334
  sprite.isAnimationActive = jv.getBoolean("active");
331
335
  sprite.isAnimationLooping = jv.getBoolean("looping");
336
+ ActorSerializer.readActor(jv, sprite);
332
337
  return sprite;
333
338
  }
334
339
 
@@ -393,10 +398,10 @@ public class Serializer {
393
398
  @Override
394
399
  public Actor read(Json json, JsonValue jv, Class arg2) {
395
400
  Dialog dialog = new Dialog(jv.getString("title"), Asset.skin);
396
- readActor(jv, dialog);
397
401
  dialog.setModal(jv.getBoolean("modal"));
398
402
  dialog.setMovable(jv.getBoolean("move"));
399
403
  dialog.setResizable(jv.getBoolean("resize"));
404
+ readActor(jv, dialog);
400
405
  return dialog;
401
406
  }
402
407
 
{Stage → src/scene2d}/Sprite.java RENAMED
@@ -1,3 +1,4 @@
1
+ package scene2d;
1
2
  import com.badlogic.gdx.graphics.g2d.Animation;
2
3
  import com.badlogic.gdx.graphics.g2d.Batch;
3
4
  import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -40,7 +41,7 @@ public class Sprite extends Actor {
40
41
  public void draw(Batch batch, float parentAlpha) {
41
42
  super.draw(batch, parentAlpha);
42
43
  if (isAnimationActive && animation != null) {
43
- keyFrame = animation.getKeyFrame(Stage.stateTime, isAnimationLooping);
44
+ keyFrame = animation.getKeyFrame(Scene.stateTime, isAnimationLooping);
44
45
  batch.draw(keyFrame, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
45
46
  getScaleX(), getScaleY(), getRotation());
46
47
  }
Stage/MainActivity.java → src/scene2d/android/Main.java RENAMED
@@ -1,23 +1,25 @@
1
+ package scene2d.android;
2
+ import scene2d.Scene;
1
3
  import android.os.Bundle;
2
4
 
3
5
  import com.badlogic.gdx.backends.android.AndroidApplication;
4
6
  import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
5
7
 
6
- public class MainActivity extends AndroidApplication {
8
+ public class Main extends AndroidApplication {
7
9
 
8
10
  @Override
9
11
  public void onCreate(Bundle savedInstanceState) {
10
12
  super.onCreate(savedInstanceState);
11
- Stage.configJson = Stage.jsonReader.parse(this.getClass().getClassLoader().getResourceAsStream("config"));
13
+ Scene.configJson = Scene.jsonReader.parse(this.getClass().getClassLoader().getResourceAsStream("config"));
12
- String[] target = Stage.configJson.getString("targetSize").split("x");
14
+ String[] target = Scene.configJson.getString("targetSize").split("x");
13
- Stage.targetWidth = Integer.parseInt(target[0]);
15
+ Scene.targetWidth = Integer.parseInt(target[0]);
14
- Stage.targetHeight = Integer.parseInt(target[1]);
16
+ Scene.targetHeight = Integer.parseInt(target[1]);
15
17
  AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
16
18
  cfg.useAccelerometer = false;
17
- cfg.useGL20 = Stage.configJson.getBoolean("useGL20");
19
+ cfg.useGL20 = Scene.configJson.getBoolean("useGL20");
18
20
  cfg.useCompass = false;
19
21
  cfg.hideStatusBar = true;
20
22
  cfg.useWakelock = true;
21
- initialize(Stage.getInstance(), cfg);
23
+ initialize(Scene.app, cfg);
22
24
  }
23
25
  }
src/scene2d/desktop/Main.java ADDED
@@ -0,0 +1,38 @@
1
+ package scene2d.desktop;
2
+
3
+ import java.awt.Dimension;
4
+ import java.awt.Toolkit;
5
+
6
+ import scene2d.Scene;
7
+
8
+ import com.badlogic.gdx.Files.FileType;
9
+ import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
10
+ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
11
+
12
+ public class Main {
13
+
14
+ public static void main(String[] argc) {
15
+ final LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
16
+ Scene.configJson = Scene.jsonReader.parse(Main.class.getClassLoader().getResourceAsStream("config"));
17
+ if(Scene.configJson.getBoolean("hasIcon"))
18
+ cfg.addIcon("icon.png", FileType.Internal);
19
+ String[] screen = Scene.configJson.getString("screenSize").split("x");
20
+ String[] target = Scene.configJson.getString("targetSize").split("x");
21
+ cfg.width = Integer.parseInt(screen[0]);
22
+ cfg.height = Integer.parseInt(screen[1]);
23
+ Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
24
+ cfg.x = (int) ((dimension.getWidth() - cfg.width) / 2);
25
+ cfg.y = (int) ((dimension.getHeight() - cfg.height) / 2);
26
+ cfg.resizable = Scene.configJson.getBoolean("resize");
27
+ cfg.forceExit = Scene.configJson.getBoolean("forceExit");
28
+ cfg.fullscreen = Scene.configJson.getBoolean("fullScreen");
29
+ cfg.useGL20 = Scene.configJson.getBoolean("useGL20");
30
+ cfg.vSyncEnabled = Scene.configJson.getBoolean("vSync");
31
+ cfg.audioDeviceBufferCount = Scene.configJson.getInt("audioBufferCount");
32
+ LwjglApplicationConfiguration.disableAudio = Scene.configJson.getBoolean("disableAudio");
33
+ Scene.targetWidth = Integer.parseInt(target[0]);
34
+ Scene.targetHeight = Integer.parseInt(target[1]);
35
+ new LwjglApplication(Scene.app, cfg);
36
+ }
37
+ }
38
+
test/config CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  title: Game1,
3
- version: "0.45",
3
+ version: "0.5.5",
4
4
  hasIcon: true,
5
5
  targetSize: "800x480",
6
- screenSize: "800x480",
6
+ screenSize: "852x480",
7
7
  audioBufferCount: "10",
8
- resize: "false",
8
+ resize: "true",
9
9
  forceExit: "false",
10
10
  fullScreen: "false",
11
11
  useGL20: "false",
12
- vSync: "false",
12
+ vSync: "true",
13
- disableAudio: "false",
13
+ disableAudio: "true",
14
14
  keepAspectRatio: "false",
15
15
  showFPS: "true",
16
16
  loggingEnabled: "true",
test/scene CHANGED
@@ -1,57 +1,53 @@
1
- {Splash:"{class:Scene,background:\"None\",music:\"None\",transition:\"None\",duration:1.0,interpolation:Bounce}
2
- ",Menu:"{class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Play,x:286.79245,y:402,width:199.86148,height:84,ox:0,oy:0,rotation:0,zindex:1,color:ffccccff,touchable:enabled,visible:true,text:Play,fontName:font2}
3
- {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Exit,x:305.66037,y:84.999985,width:159,height:84,ox:0,oy:0,rotation:0,zindex:2,color:\"000000ff\",touchable:enabled,visible:true,text:Exit,fontName:font1}
4
- {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Options,x:221.69812,y:257,width:329,height:73,ox:0,oy:0,rotation:0,zindex:3,color:ccccffff,touchable:enabled,visible:true,text:Options,fontName:font2}
5
- {class:ImageJson,name:Image1,x:1103.2814,y:82,width:60,height:68.125,ox:30,oy:30,rotation:30,zindex:4,color:ffffffff,touchable:enabled,visible:true,texName:porgarett,effect:PatrolX,value:50,duration:0.7,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:SceneCreated,onEvent:DoEffect,eventScene:None}
6
- {class:ImageJson,name:ImageJson3,x:486.79248,y:403,width:325,height:60,ox:0,oy:0,rotation:0,zindex:5,color:ffffffff,touchable:enabled,visible:true,texName:anim_green_santa,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:Clicked,onEvent:SetScene,eventScene:Options}
7
- {class:ImageJson,name:ImageJson5,x:583.9623,y:329,width:40,height:40,ox:0,oy:0,rotation:0,zindex:6,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
8
- {class:ImageJson,name:ImageJson6,x:209.43396,y:11,width:325,height:60,ox:0,oy:0,rotation:0,zindex:7,color:ffffffff,touchable:enabled,visible:true,texName:anim_black_ghost,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
9
- {class:ImageJson,name:ImageJson7,x:624.5283,y:196,width:40,height:40,ox:0,oy:0,rotation:0,zindex:8,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
10
- {class:ImageJson,name:ImageJson8,x:564.15094,y:9828.126,width:40,height:40,ox:0,oy:0,rotation:0,zindex:9,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:PatrolY,value:600,duration:4,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:SceneCreated,onEvent:DoEffect,eventScene:\"\"}
11
- {class:ImageJson,name:ImageJson4,x:607.84314,y:263,width:40,height:40,ox:0,oy:0,rotation:0,zindex:10,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
12
- {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label3,x:287.73584,y:154,width:180,height:84,ox:0,oy:0,rotation:0,zindex:11,color:\"0707beff\",touchable:enabled,visible:true,text:Help,fontName:font1}
13
- {class:Sprite,name:Sprite1,x:40,y:236,width:60,height:60,ox:0,oy:0,rotation:0,zindex:12,color:ffffffff,touchable:enabled,visible:true,textures:\"porgarett,portiberon\",duration:0.5,active:true,looping:true,frameCount:1}
14
- {class:ImageJson,name:ImageJson2,x:NaN,y:NaN,width:125,height:146,ox:0,oy:0,rotation:0,zindex:13,color:ffffffff,touchable:enabled,visible:true,texName:img_btn_pause,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
15
- {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Play3d,x:244.33963,y:336,width:307,height:67,ox:0,oy:0,rotation:0,zindex:14,color:ffcc00ff,touchable:enabled,visible:true,text:Play3d,fontName:font1}
16
- {class:Scene,background:img_obj_soil_1_,music:None,transition:rightToLeft,duration:1,interpolation:Circle}
17
- ",Options:"{class:ImageJson,name:Image1,x:57.54715,y:308,width:58.013855,height:69,ox:0,oy:0,rotation:0,zindex:1,color:ffffffff,touchable:enabled,visible:true,texName:porgarett,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
18
- {class:com.badlogic.gdx.scenes.scene2d.ui.SelectBox,name:SelectBox1,x:618.62744,y:66,width:76,height:33,ox:0,oy:0,rotation:0,zindex:2,color:ffffffff,touchable:enabled,visible:true,text:\"First,Second,Third,Next,Next,\"}
19
- {class:com.badlogic.gdx.scenes.scene2d.ui.List,name:List1,x:583.3334,y:209,width:100,height:100,ox:0,oy:0,rotation:0,zindex:3,color:ffffffff,touchable:enabled,visible:true,text:\"Menu,Options,Exit,\"}
20
- {class:com.badlogic.gdx.scenes.scene2d.ui.CheckBox,name:CheckBox1,x:599.213,y:448,width:58,height:25,ox:0,oy:0,rotation:0,zindex:4,color:ffffffff,touchable:enabled,visible:true,text:Check}
21
- {class:com.badlogic.gdx.scenes.scene2d.ui.CheckBox,name:CheckBox2,x:596.836,y:407.62714,width:58,height:25,ox:0,oy:0,rotation:0,zindex:5,color:ffffffff,touchable:enabled,visible:true,text:Check}
22
- {class:com.badlogic.gdx.scenes.scene2d.ui.CheckBox,name:CheckBox3,x:598.82214,y:368.56702,width:58,height:25,ox:0,oy:0,rotation:0,zindex:6,color:ffffffff,touchable:enabled,visible:true,text:Check}
23
- {class:com.badlogic.gdx.scenes.scene2d.ui.CheckBox,name:CheckBox4,x:595.84296,y:330.50848,width:58,height:25,ox:0,oy:0,rotation:0,zindex:7,color:ffffffff,touchable:enabled,visible:true,text:Check}
24
- {class:ImageJson,name:Image2,x:57.54715,y:394,width:60,height:60,ox:0,oy:0,rotation:0,zindex:8,color:ffffffff,touchable:enabled,visible:true,texName:poralfador,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
25
- {class:com.badlogic.gdx.scenes.scene2d.ui.TextButton,name:TextButton2,x:457.80597,y:404.6225,width:87,height:27,ox:0,oy:0,rotation:0,zindex:9,color:ffffffff,touchable:enabled,visible:true,text:TextButton}
26
- {class:com.badlogic.gdx.scenes.scene2d.ui.TextButton,name:TextButton3,x:455.87964,y:363,width:87,height:27,ox:0,oy:0,rotation:0,zindex:10,color:ffffffff,touchable:enabled,visible:true,text:TextButton}
27
- {class:com.badlogic.gdx.scenes.scene2d.ui.TextButton,name:TextButton4,x:452.83017,y:316,width:87,height:27,ox:0,oy:0,rotation:0,zindex:11,color:\"00ff00ff\",touchable:enabled,visible:true,text:TextButton}
28
- {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Button1,x:300.9434,y:313,width:107.94458,height:51,ox:0,oy:0,rotation:0,zindex:12,color:ffffffff,touchable:enabled,visible:true}
29
- {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Button2,x:306.60376,y:370,width:101.986176,height:63,ox:0,oy:0,rotation:0,zindex:13,color:ff0000ff,touchable:enabled,visible:true}
30
- {class:com.badlogic.gdx.scenes.scene2d.ui.List,name:List2,x:698.12933,y:218,width:88.77136,height:100,ox:0,oy:0,rotation:0,zindex:14,color:ffffffff,touchable:enabled,visible:true,text:\"First,New,Third,Options,\"}
31
- {class:com.badlogic.gdx.scenes.scene2d.ui.Touchpad,name:Touchpad1,x:8.937653,y:21,width:200,height:200,ox:0,oy:0,rotation:0,zindex:15,color:ffffffff,touchable:enabled,visible:true,deadzoneRadius:5}
32
- {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Back,x:320.7547,y:23,width:180,height:84,ox:0,oy:0,rotation:0,zindex:16,color:ffffffff,touchable:enabled,visible:true,text:Back,fontName:font1}
33
- {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Button3,x:625.4902,y:154,width:50,height:50,ox:0,oy:0,rotation:0,zindex:17,color:ffffffff,touchable:enabled,visible:true}
34
- {class:com.badlogic.gdx.scenes.scene2d.ui.Dialog,name:Dialog1,x:308.49057,y:105,width:150,height:150,ox:0,oy:0,rotation:0,zindex:18,color:ffffffff,touchable:enabled,visible:true,title:Title,modal:false,move:true,resize:false}
35
- {class:Scene,background:img_bg_1_,music:None,transition:upToDown,duration:1,interpolation:Circle}
36
- ",Game:"{class:Scene,background:\"None\",music:\"None\",transition:\"None\",duration:1.0,interpolation:Exp10In}
37
- {class:ImageJson,name:Player,x:131.13208,y:280,width:60,height:60,ox:0,oy:0,rotation:0,zindex:0,color:ffffffff,touchable:enabled,visible:true,texName:baldarov00,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
1
+ {source.Splash:"{class:scene2d.Scene,background:None,music:None,transition:None,duration:1,interpolation:Linear}",source.Menu:"{class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Play,x:286.79245,y:402,width:199.86148,height:84,ox:0,oy:0,rotation:0,zindex:0,color:ffccccff,touchable:enabled,visible:true,text:Play,fontName:font2}
2
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Exit,x:292,y:88,width:159,height:84,ox:0,oy:0,rotation:0,zindex:1,color:\"000000ff\",touchable:enabled,visible:true,text:Exit,fontName:font1}
3
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Options,x:224,y:249,width:329,height:73,ox:0,oy:0,rotation:0,zindex:2,color:ccccffff,touchable:enabled,visible:true,text:Options,fontName:font2}
4
+ {class:scene2d.ImageJson,name:scene2d.ImageJson3,x:488,y:412,width:325,height:60,ox:0,oy:0,rotation:0,zindex:3,color:ffffffff,touchable:enabled,visible:true,texName:anim_green_santa,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:Clicked,onEvent:SetScene,eventScene:Options}
5
+ {class:scene2d.ImageJson,name:scene2d.ImageJson5,x:668,y:354,width:40,height:40,ox:0,oy:0,rotation:16.657846,zindex:4,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
6
+ {class:scene2d.ImageJson,name:scene2d.ImageJson6,x:213.00002,y:11,width:325,height:60,ox:0,oy:0,rotation:0,zindex:5,color:ffffffff,touchable:enabled,visible:true,texName:anim_black_ghost,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
7
+ {class:scene2d.ImageJson,name:scene2d.ImageJson7,x:659,y:269,width:40,height:40,ox:0,oy:0,rotation:0,zindex:6,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
8
+ {class:scene2d.ImageJson,name:scene2d.ImageJson8,x:564.15094,y:15621.421,width:40,height:40,ox:0,oy:0,rotation:0,zindex:7,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:PatrolY,value:600,duration:4,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:SceneCreated,onEvent:DoEffect,eventScene:\"\"}
9
+ {class:scene2d.ImageJson,name:scene2d.ImageJson4,x:659,y:320,width:40,height:40,ox:0,oy:0,rotation:0,zindex:8,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
10
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label3,x:286,y:164,width:180,height:80,ox:0,oy:0,rotation:0,zindex:9,color:\"0707beff\",touchable:enabled,visible:true,text:Help,fontName:font1}
11
+ {class:scene2d.Sprite,name:Sprite1,x:42,y:405,width:60,height:60,ox:0,oy:0,rotation:0,zindex:10,color:ffffffff,touchable:enabled,visible:true,textures:\"porgarett,portiberon\",duration:0.5,active:true,looping:true,frameCount:1}
12
+ {class:scene2d.ImageJson,name:scene2d.ImageJson2,x:NaN,y:NaN,width:125,height:146,ox:0,oy:0,rotation:0,zindex:11,color:ffffffff,touchable:enabled,visible:true,texName:img_btn_pause,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
13
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Play3d,x:230,y:331,width:307,height:67,ox:0,oy:0,rotation:0,zindex:12,color:ffcc00ff,touchable:enabled,visible:true,text:Play3d,fontName:font1}
14
+ {class:scene2d.ImageJson,name:Image1,x:81,y:124.99999,width:120,height:120,ox:0,oy:0,rotation:0,zindex:13,color:ffffffff,touchable:enabled,visible:true,texName:img_btn_play,effect:PatrolX,value:200,duration:2,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:SceneCreated,onEvent:DoEffect,eventScene:\"\"}
15
+ {class:scene2d.Scene,background:img_bg_1_,music:None,transition:SlideRight,duration:1.1,interpolation:Linear}",source.Options:"{class:scene2d.ImageJson,name:scene2d.ImageJson5,x:110,y:411,width:40,height:40,ox:0,oy:0,rotation:42.40813,zindex:0,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
16
+ {class:scene2d.ImageJson,name:scene2d.ImageJson7,x:669,y:401,width:40,height:40,ox:0,oy:0,rotation:0,zindex:1,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
17
+ {class:scene2d.ImageJson,name:scene2d.ImageJson8,x:564.15094,y:15621.421,width:40,height:40,ox:0,oy:0,rotation:0,zindex:2,color:ffffffff,touchable:enabled,visible:true,texName:img_obj_snowflake,effect:PatrolY,value:600,duration:4,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:SceneCreated,onEvent:DoEffect,eventScene:\"\"}
18
+ {class:scene2d.ImageJson,name:scene2d.ImageJson2,x:NaN,y:NaN,width:125,height:146,ox:0,oy:0,rotation:0,zindex:3,color:ffffffff,touchable:enabled,visible:true,texName:img_btn_pause,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
19
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label1,x:281,y:407,width:294,height:84,ox:0,oy:0,rotation:0,zindex:4,color:\"009999ff\",touchable:enabled,visible:true,text:Options,fontName:font1}
20
+ {class:com.badlogic.gdx.scenes.scene2d.ui.CheckBox,name:CheckBox1,x:618,y:331,width:94,height:25,ox:0,oy:0,rotation:0,zindex:5,color:\"000000ff\",touchable:enabled,visible:true,text:\" Music On\"}
21
+ {class:com.badlogic.gdx.scenes.scene2d.ui.SelectBox,name:SelectBox1,x:391,y:242,width:85,height:33,ox:0,oy:0,rotation:-117.64598,zindex:6,color:ccccffff,touchable:enabled,visible:true,text:\"Easy,Medium,Hard,\"}
22
+ {class:com.badlogic.gdx.scenes.scene2d.ui.TextField,name:TextField1,x:385,y:330,width:150,height:31,ox:0,oy:0,rotation:0,zindex:7,color:ccccffff,touchable:enabled,visible:true,text:pyros2097}
23
+ {class:com.badlogic.gdx.scenes.scene2d.ui.CheckBox,name:CheckBox4,x:618,y:291,width:95,height:25,ox:0,oy:0,rotation:0,zindex:8,color:ccccffff,touchable:enabled,visible:true,text:\" Sound On\"}
24
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label2,x:44,y:314,width:322,height:81,ox:0,oy:0,rotation:0,zindex:9,color:ccccffff,touchable:enabled,visible:true,text:\"Player Name\",fontName:font3}
25
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label5,x:86,y:225,width:268,height:81,ox:0,oy:0,rotation:0,zindex:10,color:ccccffff,touchable:enabled,visible:true,text:\"Game Mode\",fontName:font3}
26
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Back,x:289,y:9,width:180,height:84,ox:0,oy:0,rotation:0,zindex:11,color:\"009999ff\",touchable:enabled,visible:true,text:Back,fontName:font1}
27
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Slider,name:Slider1,x:592,y:236,width:140,height:18,ox:0,oy:0,rotation:0,zindex:12,color:ffffffff,touchable:enabled,visible:true,min:0,max:10,step:1,value:7}
28
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Slider,name:Slider2,x:597,y:196,width:140,height:18,ox:0,oy:0,rotation:0,zindex:13,color:ccccffff,touchable:enabled,visible:true,min:0,max:10,step:1,value:6}
29
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label5_1,x:122,y:124.99999,width:193,height:81,ox:0,oy:0,rotation:0,zindex:14,color:ccccffff,touchable:enabled,visible:true,text:Episode,fontName:font3}
30
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Button1,x:385,y:97,width:120,height:105,ox:0,oy:0,rotation:171.93307,zindex:15,color:ccccffff,touchable:disabled,visible:true}
31
+ {class:com.badlogic.gdx.scenes.scene2d.ui.List,name:List1,x:413,y:101,width:68,height:100,ox:0,oy:0,rotation:0,zindex:16,color:ffffffff,touchable:enabled,visible:true,text:\"Episode 1,Episode 2,Episode 3,Episode 4,\"}
32
+ {class:scene2d.Scene,background:img_bg_1_,music:None,transition:SlideRight,duration:2.1000001,interpolation:ElasticOut}",source.Game:"{class:scene2d.ImageJson,name:Player,x:131.13208,y:280,width:60,height:60,ox:0,oy:0,rotation:0,zindex:0,color:ffffffff,touchable:enabled,visible:true,texName:baldarov00,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
38
33
  {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Right,x:208.82353,y:107,width:70.85452,height:50,ox:0,oy:0,rotation:0,zindex:1,color:ffffffff,touchable:enabled,visible:true}
39
34
  {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Back,x:335.29413,y:10,width:180,height:84,ox:0,oy:0,rotation:0,zindex:2,color:ffffffff,touchable:enabled,visible:true,text:Back,fontName:font1}
40
35
  {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Timer,x:30.392181,y:405,width:245,height:84,ox:0,oy:0,rotation:0,zindex:3,color:ffffffff,touchable:enabled,visible:true,text:\"Timer:\",fontName:font1}
41
36
  {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Left,x:21.568634,y:98,width:66.61896,height:58,ox:0,oy:0,rotation:0,zindex:4,color:ffffffff,touchable:enabled,visible:true}
42
37
  {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Up,x:115.68628,y:162,width:69.59813,height:59,ox:0,oy:0,rotation:0,zindex:5,color:ffffffff,touchable:enabled,visible:true}
43
38
  {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Down,x:110.7843,y:25,width:73.57042,height:57.999985,ox:0,oy:0,rotation:0,zindex:6,color:ffffffff,touchable:enabled,visible:true}
44
- {class:ImageJson,name:Enemy,x:613.72546,y:681.9183,width:70.61896,height:59,ox:0,oy:0,rotation:0,zindex:7,color:ffffffff,touchable:enabled,visible:true,texName:lord00,effect:PatrolY,value:200,duration:1.5,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:SceneCreated,onEvent:DoEffect,eventScene:\"\"}
39
+ {class:scene2d.ImageJson,name:Enemy,x:582.07544,y:211.232,width:70.61896,height:59,ox:0,oy:0,rotation:0,zindex:7,color:ffffffff,touchable:enabled,visible:true,texName:lord00,effect:PatrolY,value:200,duration:1.5,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:SceneCreated,onEvent:DoEffect,eventScene:\"\"}
45
40
  {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Fire,x:651.9608,y:114.99999,width:66.6189,height:47.00003,ox:0,oy:0,rotation:0,zindex:8,color:ff6666ff,touchable:enabled,visible:true}
46
41
  {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label3,x:31.372559,y:375,width:473,height:31,ox:0,oy:0,rotation:0,zindex:9,color:\"000000ff\",touchable:enabled,visible:true,text:\"Collide with enemy within 30 seconds\",fontName:arial}
47
- ",GameWin:"{class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label1,x:216.98112,y:329,width:294,height:84,ox:0,oy:0,rotation:0,zindex:1,color:ffffffff,touchable:enabled,visible:true,text:\"You Win\",fontName:font1}
48
- {class:Scene,background:img_bg_1_,music:None,transition:rightToLeft,duration:1,interpolation:Exp10In}
49
- ",GameOver:"{class:Scene,background:img_bg_1_,music:None,transition:FadeOut,duration:3,interpolation:Exp10In}
50
- {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label1,x:205.66037,y:338,width:339,height:84,ox:0,oy:0,rotation:0,zindex:2,color:ffffffff,touchable:enabled,visible:true,text:\"You Lose\",fontName:font1}
51
- ",Game3d:"{class:Scene,background:None,music:None,transition:FadeIn,duration:1,interpolation:Bounce}
52
- {class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Button1,x:81.13208,y:126.99999,width:50,height:50,ox:0,oy:0,rotation:45,zindex:1,color:ffffffff,touchable:enabled,visible:true}
53
- ",TicTacToe:"{class:Scene,background:\"None\",music:\"None\",transition:\"None\",duration:1.0,interpolation:Exp10In}
42
+ {class:scene2d.Scene,background:None,music:None,transition:None,duration:1.6,interpolation:Exp10In}",source.GameWin:"{class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label1,x:216.98112,y:329,width:294,height:84,ox:0,oy:0,rotation:0,zindex:0,color:ffffffff,touchable:enabled,visible:true,text:\"You Win\",fontName:font1}
43
+ {class:scene2d.Scene,background:img_bg_1_,music:None,transition:SlideRight,duration:2.1,interpolation:Exp10In}",source.GameOver:"{class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label1,x:205.66037,y:338,width:339,height:84,ox:0,oy:0,rotation:0,zindex:0,color:ffffffff,touchable:enabled,visible:true,text:\"You Lose\",fontName:font1}
44
+ {class:scene2d.Scene,background:img_bg_1_,music:None,transition:ShakeToBack,duration:0.4,interpolation:Exp10In}",source.Game3d:"{class:com.badlogic.gdx.scenes.scene2d.ui.Button,name:Button1,x:81.13208,y:126.99999,width:50,height:50,ox:0,oy:0,rotation:45,zindex:0,color:ffffffff,touchable:enabled,visible:true}
45
+ {class:scene2d.Scene,background:None,music:None,transition:FadeIn,duration:1,interpolation:Bounce}",source.TicTacToe:"{class:scene2d.Scene,background:\"None\",music:\"None\",transition:\"None\",duration:1.0,interpolation:Exp10In}
54
46
  {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label1,x:117.92453,y:429,width:128,height:31,ox:0,oy:0,rotation:0,zindex:0,color:\"000000ff\",touchable:enabled,visible:true,text:TicTacToe,fontName:arial}
55
- ",BasicDemo:"{class:Scene,background:\"img_bg_1_\",music:\"None\",transition:\"FadeIn\",duration:1.0,interpolation:Exp10In}
56
- {class:ImageJson,name:PauseButton,x:354.71698,y:346,width:120,height:120,ox:0,oy:0,rotation:0,zindex:1,color:ffffffff,touchable:enabled,visible:true,texName:img_btn_pause,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
57
- "}
47
+ ",source.BasicDemo:"{class:scene2d.ImageJson,name:PauseButton,x:650,y:341,width:120,height:120,ox:0,oy:0,rotation:0,zindex:0,color:ffffffff,touchable:enabled,visible:true,texName:img_btn_pause,effect:None,value:0,duration:0,interpolation:Linear,addActorDelay:0,addEffectDelay:0,event:None,onEvent:DoEffect,eventScene:\"\"}
48
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Label1,x:217,y:401,width:347,height:35,ox:0,oy:0,rotation:0,zindex:1,color:\"000000ff\",touchable:enabled,visible:true,text:\"Try Panning with the mouse\",fontName:arial}
49
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Left,x:25,y:227,width:87,height:31,ox:0,oy:0,rotation:0,zindex:2,color:\"000000ff\",touchable:enabled,visible:true,text:\"Left 10\",fontName:arial}
50
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Right,x:679,y:237,width:104,height:31,ox:0,oy:0,rotation:0,zindex:3,color:\"000000ff\",touchable:enabled,visible:true,text:\"Right 10\",fontName:arial}
51
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Bot,x:330,y:48,width:81,height:31,ox:0,oy:0,rotation:-16.24288,zindex:4,color:\"000000ff\",touchable:enabled,visible:true,text:\"Bot 10\",fontName:arial}
52
+ {class:com.badlogic.gdx.scenes.scene2d.ui.Label,name:Top,x:329,y:442,width:74,height:31,ox:0,oy:0,rotation:-16.24288,zindex:5,color:\"000000ff\",touchable:enabled,visible:true,text:Top10,fontName:arial}
53
+ {class:scene2d.Scene,background:img_bg_1_,music:None,transition:FadeIn,duration:1,interpolation:Exp10In}"}
test/source/BasicDemo.java CHANGED
@@ -1,15 +1,19 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
4
+
2
5
  import com.badlogic.gdx.math.Interpolation;
3
6
  import com.badlogic.gdx.scenes.scene2d.Touchable;
4
7
  import com.badlogic.gdx.scenes.scene2d.actions.Actions;
5
8
  import com.badlogic.gdx.scenes.scene2d.ui.Image;
6
9
 
10
+ import scene2d.*;
11
+
7
12
  /** A Basic Demo Game Scene
8
13
  * <p>
9
- * This Scene showcases all the different features of the inbuilt Stage framework
14
+ * This Scene showcases all the different features of the inbuilt Scene framework
10
15
  * <p>
11
16
  * @author pyros2097 */
12
-
13
17
  public class BasicDemo extends Scene {
14
18
  Image pauseImage;
15
19
  Image pauseBtn;
@@ -19,18 +23,22 @@ public class BasicDemo extends Scene {
19
23
  //map = new Map(1, 24);
20
24
  //map.loadLayer(0);
21
25
  //map.loadLayer(1);
22
- //Stage.addActor(map);
23
26
  pauseImage = new Image(Asset.skin.getRegion("default"));
24
- pauseBtn = (Image) Stage.findActor("PauseButton");
27
+ pauseBtn = (Image) findActor("PauseButton");
28
+ Camera.addHud("PauseButton");
29
+ Camera.addHud("Label1");
30
+ Camera.addHud("Top");
25
- Stage.addHud(pauseBtn);
31
+ Camera.addHud("Bot");
32
+ Camera.addHud("Left");
33
+ Camera.addHud("Right");
26
- Stage.enablePanning();
34
+ Camera.usePan = true;
27
35
  }
28
36
 
29
37
  @Override
30
38
  public void onClick(Actor actor){
31
39
  if(actor.getName().equals("PauseButton")){
32
- Stage.log("Clicked");
40
+ log("Clicked");
33
- if(!Stage.pauseState){
41
+ if(!pauseState){
34
42
  onPause();
35
43
  }
36
44
  else{
@@ -50,38 +58,38 @@ public class BasicDemo extends Scene {
50
58
 
51
59
  @Override
52
60
  public void onGesture(GestureType type){}
53
-
61
+
54
- @Override
62
+ @Override
55
- public void onKeyTyped(char key){
63
+ public void onKeyTyped(char key){
56
- }
64
+ }
57
-
65
+
58
- @Override
66
+ @Override
59
- public void onKeyUp(int keycode){
67
+ public void onKeyUp(int keycode){
60
- }
68
+ }
61
-
69
+
62
- @Override
70
+ @Override
63
- public void onKeyDown(int keycode){
71
+ public void onKeyDown(int keycode){
64
- }
72
+ }
65
73
 
66
74
  @Override
67
75
  public void onPause() {
68
- Stage.pauseState = true;
76
+ pauseState = true;
69
77
  pauseImage.setFillParent(true);
70
78
  pauseImage.setTouchable(Touchable.disabled);
71
79
  pauseImage.setColor(1, 1, 1, 0);
72
80
  pauseImage.addAction(Actions.alpha(0.6f, 0.7f, Interpolation.linear));
73
- pauseImage.setPosition(Stage.getCameraX() - Stage.targetWidth/2,
81
+ pauseImage.setPosition(Camera.getX() - targetWidth/2,
74
- Stage.getCameraY() - Stage.targetHeight/2);
82
+ Camera.getY() - targetHeight/2);
75
- Stage.addActor(pauseImage);
83
+ addActor(pauseImage);
76
- Stage.disablePanning();
84
+ Camera.usePan = false;
77
85
  }
78
86
 
79
87
  @Override
80
88
  public void onResume() {
81
- Stage.pauseState = false;
89
+ pauseState = false;
82
90
  pauseImage.addAction(Actions.sequence(Actions.alpha(0f, 0.6f, Interpolation.linear),
83
91
  Actions.removeActor(pauseImage)));
84
- Stage.enablePanning();
92
+ Camera.usePan = true;
85
93
  }
86
94
 
87
95
  @Override
test/source/Game.java CHANGED
@@ -1,6 +1,9 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
2
4
  import com.badlogic.gdx.scenes.scene2d.ui.Label;
3
5
  import com.badlogic.gdx.scenes.scene2d.actions.Actions;
6
+ import scene2d.*;
4
7
 
5
8
  /** A Basic Game Scene for the Game
6
9
  * <p>
@@ -20,24 +23,25 @@ public class Game extends Scene {
20
23
  String btnName = "";
21
24
 
22
25
  public Game(){
23
- Stage.addHud(Stage.findActor("Up"));
26
+ Camera.addHud("Up");
24
- Stage.addHud(Stage.findActor("Right"));
27
+ Camera.addHud("Right");
25
- Stage.addHud(Stage.findActor("Left"));
28
+ Camera.addHud("Left");
26
- Stage.addHud(Stage.findActor("Down"));
29
+ Camera.addHud("Down");
27
- Stage.addHud(Stage.findActor("Timer"));
30
+ Camera.addHud("Timer");
28
- Stage.addHud(Stage.findActor("Label3"));
31
+ Camera.addHud("Label3");
29
- Stage.addHud(Stage.findActor("Fire"));
32
+ Camera.addHud("Fire");
30
33
 
31
- Stage.setFollowSpeed(0.33f);
34
+ Camera.setFollowSpeed(1f);
32
- player = (ImageJson) Stage.findActor("Player");
35
+ player = (ImageJson) findActor("Player");
33
- enemy = (ImageJson) Stage.findActor("Enemy");
36
+ enemy = (ImageJson) findActor("Enemy");
34
- Stage.followActorContinuously(player);
37
+ Camera.followActorContinuously(player);
35
- timer = (Label)Stage.findActor("Timer");
38
+ timer = (Label)findActor("Timer");
36
- startTime = Stage.gameUptime;
39
+ startTime = gameUptime;
37
40
  }
38
41
 
39
42
  @Override
40
43
  public void onTouchDown(Actor actor){
44
+ log(actor.getName());
41
45
  touchedDown = true;
42
46
  btnName = actor.getName();
43
47
  }
@@ -45,7 +49,7 @@ public class Game extends Scene {
45
49
  @Override
46
50
  public void onClick(Actor actor){
47
51
  if(actor.getName().equals("Back"))
48
- Stage.setScene("Menu");
52
+ setScene("Menu");
49
53
  if(actor.getName().equals("Fire"))
50
54
  doFire();
51
55
  }
@@ -55,17 +59,18 @@ public class Game extends Scene {
55
59
  bullet.setPosition(player.getX() + 50, player.getY() + 50);
56
60
  bullet.setSize(25, 25);
57
61
  bullet.addAction(Actions.sequence(Actions.moveBy(500, 0, 1f), Actions.removeActor(bullet)));
58
- Stage.addActor(bullet);
62
+ addActor(bullet);
59
63
  }
60
64
 
61
65
  @Override
62
66
  public void act(float delta){
67
+ super.act(delta);
63
- diff = Stage.gameUptime - startTime;
68
+ diff = gameUptime - startTime;
64
69
  timer.setText("Timer: "+diff);
65
70
  if(diff>=30)
66
- Stage.setScene("GameOver");
71
+ setScene("GameOver");
67
- if(Stage.collides(player, enemy))
72
+ if(collides(player, enemy))
68
- Stage.setScene("GameWin");
73
+ setScene("GameWin");
69
74
  //player.clearActions();
70
75
  switch(btnName){
71
76
  case "Right": player.addAction(Actions.moveBy(playerSpeed, 0, 0.1f)); break;
@@ -86,18 +91,18 @@ public class Game extends Scene {
86
91
 
87
92
  @Override
88
93
  public void onGesture(GestureType type){}
89
-
94
+
90
- @Override
95
+ @Override
91
- public void onKeyTyped(char key){
96
+ public void onKeyTyped(char key){
92
- }
97
+ }
93
-
98
+
94
- @Override
99
+ @Override
95
- public void onKeyUp(int keycode){
100
+ public void onKeyUp(int keycode){
96
- }
101
+ }
97
-
102
+
98
- @Override
103
+ @Override
99
- public void onKeyDown(int keycode){
104
+ public void onKeyDown(int keycode){
100
- }
105
+ }
101
106
 
102
107
  @Override
103
108
  public void onPause(){
test/source/Game3d.java CHANGED
@@ -1,3 +1,5 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
2
4
  import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder;
3
5
  import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
@@ -5,6 +7,12 @@ import com.badlogic.gdx.graphics.VertexAttributes.Usage;
5
7
  import com.badlogic.gdx.graphics.g3d.Material;
6
8
  import com.badlogic.gdx.graphics.GL20;
7
9
  import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
10
+ import scene3d.Actor3d;
11
+ import scene3d.Camera3d;
12
+ import scene3d.actions.Actions3d;
13
+ import com.badlogic.gdx.math.MathUtils;
14
+ import com.badlogic.gdx.Input.Keys;
15
+ import scene2d.*;
8
16
 
9
17
  public class Game3d extends Scene {
10
18
  Actor3d ship;
@@ -28,9 +36,42 @@ public class Game3d extends Scene {
28
36
  }
29
37
  floor = new Actor3d(builder.end());
30
38
  floor.materials.get(0).set(TextureAttribute.createDiffuse(Asset.tex("concrete").getTexture()));
39
+ knight = Asset.loadModel("knight");
40
+ knight.setPosition(-20f, 18f, 0f);
41
+ knight.setPitch(-90f);
31
- Stage.addActor3d(floor);
42
+ addActor3d(floor);
32
- Stage.addActor3d(skydome);
43
+ addActor3d(skydome);
33
- Stage.addActor3d(ship);
44
+ addActor3d(ship);
45
+ addActor3d(knight);
46
+ stage3d.getCamera().position.set(knight.getX()+ 13f, knight.getY() + 24f, knight.getZ() + 45f);
47
+ //Camera3d.followOffset(20f, 20f, -20f);
48
+ // Camera3d.followActor3d(knight, false);
49
+ }
50
+
51
+ float angle, angle2;
52
+ @Override
53
+ public void act(float delta){
54
+ super.act(delta);
55
+ angle = MathUtils.cosDeg(knight.getYaw() - 90); //90 degrees is correction factor
56
+ angle2 = -MathUtils.sinDeg(knight.getYaw() - 90);
57
+ if (upKey) {
58
+ knight.addAction3d(Actions3d.moveBy(angle, 0f, angle2, 1f));
59
+ stage3d.getCamera().translate(angle, 0f, angle2);
60
+ }
61
+ else if (downKey) {
62
+ knight.addAction3d(Actions3d.moveBy(-angle, 0f, -angle2, 1f));
63
+ stage3d.getCamera().translate(angle, 0f, angle2);
64
+ }
65
+ else if (rightKey) {
66
+ knight.rotateYaw(-2f);
67
+ if(stage3d.getCamera().direction.z > -0.76f)
68
+ Camera3d.rotateBy(-2f, 0f, 0f, 0f);
69
+ }
70
+ else if (leftKey) {
71
+ knight.rotateYaw(2f);
72
+ if(stage3d.getCamera().direction.z > -0.76f)
73
+ Camera3d.rotateBy(-2f, 0f, 0f, 0f);
74
+ }
34
75
  }
35
76
 
36
77
  @Override
@@ -55,12 +96,23 @@ public class Game3d extends Scene {
55
96
  public void onKeyTyped(char key){
56
97
  }
57
98
 
99
+ boolean rightKey, leftKey, upKey, downKey, spaceKey;
58
100
  @Override
59
101
  public void onKeyUp(int keycode){
102
+ if (keycode == Keys.LEFT) leftKey = false;
103
+ if (keycode == Keys.RIGHT) rightKey = false;
104
+ if (keycode == Keys.UP) upKey = false;
105
+ if (keycode == Keys.DOWN) downKey = false;
106
+ if (keycode == Keys.SPACE) spaceKey = false;
60
107
  }
61
108
 
62
109
  @Override
63
110
  public void onKeyDown(int keycode){
111
+ if (keycode == Keys.LEFT) leftKey = true;
112
+ if (keycode == Keys.RIGHT) rightKey = true;
113
+ if (keycode == Keys.UP) upKey = true;
114
+ if (keycode == Keys.DOWN) downKey = true;
115
+ if (keycode == Keys.SPACE) spaceKey = true;
64
116
  }
65
117
 
66
118
  @Override
@@ -74,4 +126,4 @@ public class Game3d extends Scene {
74
126
  @Override
75
127
  public void onDispose(){
76
128
  }
77
- }
129
+ }
test/source/GameOver.java CHANGED
@@ -1,4 +1,7 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
4
+ import scene2d.*;
2
5
 
3
6
  /** A Basic Game Over Scene for the Game
4
7
  * <p>
@@ -8,7 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
8
11
  public class GameOver extends Scene{
9
12
 
10
13
  public GameOver(){
11
- Stage.setSceneWithDelay("Menu", 3f);
14
+ setSceneWithDelay("Menu", 3f);
12
15
  }
13
16
 
14
17
  @Override
@@ -25,18 +28,18 @@ public class GameOver extends Scene{
25
28
 
26
29
  @Override
27
30
  public void onGesture(GestureType type){}
28
-
31
+
29
- @Override
32
+ @Override
30
- public void onKeyTyped(char key){
33
+ public void onKeyTyped(char key){
31
- }
34
+ }
32
-
35
+
33
- @Override
36
+ @Override
34
- public void onKeyUp(int keycode){
37
+ public void onKeyUp(int keycode){
35
- }
38
+ }
36
-
39
+
37
- @Override
40
+ @Override
38
- public void onKeyDown(int keycode){
41
+ public void onKeyDown(int keycode){
39
- }
42
+ }
40
43
 
41
44
  @Override
42
45
  public void onPause(){
test/source/GameWin.java CHANGED
@@ -1,4 +1,7 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
4
+ import scene2d.*;
2
5
 
3
6
  /** A Basic Game Win Scene for the Game
4
7
  * <p>
@@ -8,7 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
8
11
  public class GameWin extends Scene {
9
12
 
10
13
  public GameWin(){
11
- Stage.setSceneWithDelay("Menu", 3f);
14
+ setSceneWithDelay("Menu", 3f);
12
15
  }
13
16
 
14
17
  @Override
@@ -25,18 +28,18 @@ public class GameWin extends Scene {
25
28
 
26
29
  @Override
27
30
  public void onGesture(GestureType type){}
28
-
31
+
29
- @Override
32
+ @Override
30
- public void onKeyTyped(char key){
33
+ public void onKeyTyped(char key){
31
- }
34
+ }
32
-
35
+
33
- @Override
36
+ @Override
34
- public void onKeyUp(int keycode){
37
+ public void onKeyUp(int keycode){
35
- }
38
+ }
36
-
39
+
37
- @Override
40
+ @Override
38
- public void onKeyDown(int keycode){
41
+ public void onKeyDown(int keycode){
39
- }
42
+ }
40
43
 
41
44
  @Override
42
45
  public void onPause(){
test/source/Menu.java CHANGED
@@ -1,29 +1,32 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
4
+ import scene2d.*;
2
5
 
3
6
  /** A Basic Main Menu for the Game
4
7
  * <p>
5
8
  * The Main Menu Displays all the scenes to which the game can switch too. Based on which button or
6
- * image or widget pressed the scene can be switched.
9
+ * image or widget pressed the scene can be switched.
7
10
 
8
11
  * <p>
9
12
  * @author pyros2097 */
10
13
  public class Menu extends Scene {
11
14
 
12
15
  public Menu(){
13
- Stage.log("Hello World");
16
+ log("Hello World");
14
- Stage.log("new dat");
17
+ log("new dat");
15
- Stage.showToast("Toasting", 2f);
18
+ showToast("Toasting", 2f);
16
19
  }
17
20
 
18
21
  @Override
19
22
  public void onClick(Actor actor){
20
23
  if(actor.getName().equals("Play"))
21
- Stage.setScene("Game");
24
+ setScene("Game");
22
25
  if(actor.getName().equals("Play3d"))
23
- Stage.setScene("Game3d");
26
+ setScene("Game3d");
24
27
  if(actor.getName().equals("Options"))
25
- Stage.setScene("Options");
28
+ setScene("Options");
26
29
  if(actor.getName().equals("Exit"))
27
- Stage.showMessageDialog("Exit", " Are you sure you want \n to Quit the Game ");
30
+ showMessageDialog("Exit", " Are you sure you want \n to Quit the Game ");
28
31
  }
29
32
 
30
33
  @Override
@@ -39,22 +42,22 @@ public class Menu extends Scene {
39
42
  @Override
40
43
  public void onGesture(GestureType type){
41
44
  if(type == GestureType.Up)
42
- Stage.log("Up");
45
+ log("Up");
43
46
  else if(type == GestureType.Down)
44
- Stage.log("Down");
47
+ log("Down");
45
48
  }
46
49
 
47
50
  @Override
48
51
  public void onKeyTyped(char key){
49
- }
52
+ }
50
53
 
51
54
  @Override
52
55
  public void onKeyUp(int keycode){
53
- }
56
+ }
54
57
 
55
58
  @Override
56
59
  public void onKeyDown(int keycode){
57
- }
60
+ }
58
61
 
59
62
  @Override
60
63
  public void onPause(){
test/source/Options.java CHANGED
@@ -1,26 +1,28 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
4
+ import scene2d.*;
2
5
 
3
- /** A Basic Options Scene for the Game
6
+ /** A Basic Main Menu for the Game
4
7
  * <p>
5
- * The Options Scene displays the necessary settings which can be modified by the user like
8
+ * The Main Menu Displays all the scenes to which the game can switch too. Based on which button or
6
- * musicOn, soundOn, panCamera, battleAnimations etc. The widgets once changed must persist
7
- * the changes to the preferences which can be accessed by Config.prefs
9
+ * image or widget pressed the scene can be switched.
8
10
 
9
11
  * <p>
10
12
  * @author pyros2097 */
11
13
  public class Options extends Scene {
12
14
 
13
15
  public Options(){
14
- Stage.log("Hello From Options");
15
16
  }
16
17
 
17
18
  @Override
18
19
  public void onClick(Actor actor){
19
20
  if(actor.getName().equals("Back"))
20
- Stage.setScene("Menu");
21
+ setScene("Menu");
21
22
  }
22
23
 
23
24
  @Override
24
- public void onTouchDown(Actor actor){}
25
+ public void onTouchDown(Actor actor){
26
+ }
25
27
 
26
28
  @Override
27
29
  public void onTouchUp(){}
@@ -29,21 +31,26 @@ public class Options extends Scene {
29
31
  public void onDragged(){}
30
32
 
31
33
  @Override
32
- public void onGesture(GestureType type){}
34
+ public void onGesture(GestureType type){
33
-
34
- @Override
35
+ if(type == GestureType.Up)
36
+ log("Up");
35
- public void onKeyTyped(char key){
37
+ else if(type == GestureType.Down)
38
+ log("Down");
36
- }
39
+ }
37
-
38
- @Override
39
- public void onKeyUp(int keycode){
40
- }
41
-
42
- @Override
43
- public void onKeyDown(int keycode){
44
- }
45
40
 
46
41
  @Override
42
+ public void onKeyTyped(char key){
43
+ }
44
+
45
+ @Override
46
+ public void onKeyUp(int keycode){
47
+ }
48
+
49
+ @Override
50
+ public void onKeyDown(int keycode){
51
+ }
52
+
53
+ @Override
47
54
  public void onPause(){
48
55
  }
49
56
 
test/source/Splash.java CHANGED
@@ -1,4 +1,7 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.Gdx;
4
+
2
5
  import com.badlogic.gdx.graphics.Color;
3
6
  import com.badlogic.gdx.graphics.Texture;
4
7
  import com.badlogic.gdx.scenes.scene2d.Actor;
@@ -8,6 +11,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image;
8
11
  import com.badlogic.gdx.scenes.scene2d.ui.Label;
9
12
  import com.badlogic.gdx.scenes.scene2d.ui.Skin;
10
13
 
14
+ import scene2d.*;
15
+
11
16
  /** A Basic SplashScreen for the Game
12
17
  * <p>
13
18
  * The SplashScene loads all the splash assets to be shown directly from the file system
@@ -33,10 +38,10 @@ public class Splash extends Scene {
33
38
  loadingLabel = new Label(loadingText, Asset.skin);
34
39
  loadingLabel.setColor(Color.BLACK);
35
40
  loadingLabel.setFontScale(3f);
36
- Stage.addActor(imgbg1);
41
+ addActor(imgbg1);
37
- Stage.addActor(imgbg2);
42
+ addActor(imgbg2);
38
- Stage.addActor(loadingLabel, Stage.targetWidth/2, 23f);
43
+ addActor(loadingLabel, targetWidth/2, 23f);
39
- Stage.addAction(Actions.sequence(Actions.delay(4f), Actions.removeActor(imgbg1)
44
+ addAction(Actions.sequence(Actions.delay(4f), Actions.removeActor(imgbg1)
40
45
  , Actions.delay(4f), Actions.removeActor(imgbg2)));
41
46
 
42
47
  loadingLabel.addAction(Actions.forever(Actions.forever(Actions.sequence(
@@ -72,18 +77,18 @@ public class Splash extends Scene {
72
77
 
73
78
  @Override
74
79
  public void onGesture(GestureType type){}
75
-
80
+
76
- @Override
81
+ @Override
77
- public void onKeyTyped(char key){
82
+ public void onKeyTyped(char key){
78
- }
83
+ }
79
-
84
+
80
- @Override
85
+ @Override
81
- public void onKeyUp(int keycode){
86
+ public void onKeyUp(int keycode){
82
- }
87
+ }
83
-
88
+
84
- @Override
89
+ @Override
85
- public void onKeyDown(int keycode){
90
+ public void onKeyDown(int keycode){
86
- }
91
+ }
87
92
 
88
93
  @Override
89
94
  public void onPause(){
test/source/TicTacToe.java CHANGED
@@ -1,3 +1,5 @@
1
+ package source;
2
+
1
3
  import com.badlogic.gdx.scenes.scene2d.Actor;
2
4
  import com.badlogic.gdx.scenes.scene2d.Group;
3
5
  import com.badlogic.gdx.scenes.scene2d.ui.Image;
@@ -6,6 +8,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
6
8
 
7
9
  import java.util.Random;
8
10
 
11
+ import scene2d.*;
12
+
9
13
  /**
10
14
  * A Basic TicTacToe Game
11
15
  Scene
@@ -26,7 +30,7 @@ public class TicTacToe extends Scene {
26
30
  for(int j = 0;j < 3;j++){
27
31
  Box box = new Box(i, j);
28
32
  boxes[i][j] = box;
29
- Stage.addActor(box, box.getWidth()*j, box.getHeight()*i);
33
+ addActor(box, box.getWidth()*j, box.getHeight()*i);
30
34
  }
31
35
  }
32
36
  }
@@ -41,22 +45,22 @@ public class TicTacToe extends Scene {
41
45
 
42
46
  public static void setMode(GameMode gm){
43
47
  gameMode = gm;
44
- Stage.log("Game Mode: " + gameMode.toString());
48
+ log("Game Mode: " + gameMode.toString());
45
49
  }
46
50
 
47
51
  public void reset(){
48
- Stage.log("Reset");
52
+ log("Reset");
49
53
  turnCounter = 0;
50
- Stage.setScene("TicTacToe");
54
+ setScene("TicTacToe");
51
55
  }
52
56
 
53
57
  public void playerWin(){
54
- Stage.log("Player Win");
58
+ log("Player Win");
55
59
  reset();
56
60
  }
57
61
 
58
62
  public void computerWin(){
59
- Stage.log("Computer Win");
63
+ log("Computer Win");
60
64
  reset();
61
65
  }
62
66
 
@@ -66,7 +70,7 @@ public class TicTacToe extends Scene {
66
70
  void AI(){
67
71
  if(mode(GameMode.SINGLE_PLAYER_VS_COMPUTER)){
68
72
  if(currentTurn == Turn.Computer){
69
- Stage.log("AI");
73
+ log("AI");
70
74
  random1 = rand.nextInt(3);
71
75
  random2 = rand.nextInt(3);
72
76
  if(!boxes[random1][random2].isMarked){
@@ -126,7 +130,7 @@ public class TicTacToe extends Scene {
126
130
  checkForDiagonal();
127
131
  }
128
132
  else{
129
- Stage.log("Draw Match");
133
+ log("Draw Match");
130
134
  reset();
131
135
  }
132
136
  }
@@ -145,18 +149,18 @@ public class TicTacToe extends Scene {
145
149
 
146
150
  @Override
147
151
  public void onGesture(GestureType type){}
148
-
152
+
149
- @Override
153
+ @Override
150
- public void onKeyTyped(char key){
154
+ public void onKeyTyped(char key){
151
- }
155
+ }
152
-
156
+
153
- @Override
157
+ @Override
154
- public void onKeyUp(int keycode){
158
+ public void onKeyUp(int keycode){
155
- }
159
+ }
156
-
160
+
157
- @Override
161
+ @Override
158
- public void onKeyDown(int keycode){
162
+ public void onKeyDown(int keycode){
159
- }
163
+ }
160
164
 
161
165
  @Override
162
166
  public void onPause(){
@@ -199,7 +203,7 @@ class Box extends Group{
199
203
  else if(TicTacToe.mode(GameMode.SINGLE_PLAYER_VS_COMPUTER))
200
204
  if(TicTacToe.currentTurn == Turn.Player)
201
205
  markByPlayer();
202
- Stage.log("Box Clicked "+Box.this.row+Box.this.col);
206
+ Scene.log("Box Clicked "+Box.this.row+Box.this.col);
203
207
  }
204
208
  }
205
209
  });
@@ -238,4 +242,4 @@ enum GameMode {
238
242
  SINGLE_PLAYER,
239
243
  SINGLE_PLAYER_VS_COMPUTER,
240
244
  MULTI_PLAYER,
241
- }
245
+ }
test/test.apk DELETED
Binary file