Skip to content

Commit b7513b5

Browse files
authored
feat: Change ScreenManager to no longer reuse screen instances & improve GWT support. (#26)
1 parent 90afbe0 commit b7513b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+844
-1072
lines changed

.github/workflows/build-and-test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build & Test
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up JDK 11
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: '11'
23+
distribution: 'temurin'
24+
- name: Fix permissions
25+
run: chmod +x gradlew
26+
- name: Build with Gradle
27+
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0
28+
with:
29+
arguments: build

README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ This library is a screen manager for libGDX games. It allows comfortably changin
99
![](https://raw.githubusercontent.com/crykn/libgdx-screenmanager/master/showcase/gl_transitions_2.gif)
1010
> ###### A small example using different transitions. Look at the [showcases folder](https://github.com/crykn/libgdx-screenmanager/tree/master/showcase) for more gifs.
1111
12-
* Allows easily **changing the rendered screen**: `game.getScreenManager().pushScreen("screen_name", "transition_name")`
12+
* Allows easily **changing the rendered screen**: `game.getScreenManager().pushScreen(screen, transition)`
1313
* Adds **screen transition effects** for when a screen is changed. The included transitions can be found [here](https://github.com/crykn/libgdx-screenmanager/wiki/Available-transitions). Furthermore, transition shaders are supported as well. See the [GL Transitions](https://gl-transitions.com/gallery) project for a collection of some very well made ones.
1414
* **Automatically registers/unregisters** a screen's **input processors** whenever the screen is shown/hidden
15-
* There are `create()` methods for screens and transitions that are called _once_ before a screen/transition is shown. This allows easily initializing them, when everything else has already been loaded
1615
* The whole library is [well documented](https://github.com/crykn/libgdx-screenmanager/wiki) and includes [tests](https://github.com/crykn/libgdx-screenmanager/tree/master/src/test/java) for everything that isn't graphical
1716

1817
## Example code
1918

20-
The following example shows how to use libgdx-screenmanager in your code. You can find the full example [here](https://github.com/crykn/libgdx-screenmanager/tree/master/example).
19+
The following example shows how to use libgdx-screenmanager in your code. You can find the full example [here](https://github.com/crykn/libgdx-screenmanager/tree/master/src/example).
2120

22-
The library is very easy to use: The game has to extend `ManagedGame`, all screen have to inherit from `ManagedScreen`. Screens and transitions have to be registered with the screen manager before they can be used. To push a screen `game.getScreenManager().pushScreen("screen-name", "transition-name")` has to be called. If no transition should be used, just call `pushScreen("screen-name", null)`.
21+
The library is very easy to use: The game has to extend `ManagedGame`, all screen have to inherit from `ManagedScreen`. To push a screen, `game.getScreenManager().pushScreen(screen, transition)` has to be called. If no transition should be used, just call `pushScreen(screen, null)`.
2322

2423
```java
2524
public class MyGdxGame extends ManagedGame<ManagedScreen, ScreenTransition> {
@@ -31,18 +30,8 @@ public class MyGdxGame extends ManagedGame<ManagedScreen, ScreenTransition> {
3130
// Do some basic stuff
3231
this.batch = new SpriteBatch();
3332

34-
// Add screens
35-
this.screenManager.addScreen("green", new GreenScreen());
36-
this.screenManager.addScreen("blue", new BlueScreen());
37-
// ...
38-
39-
// Add transitions
40-
BlendingScreenTransition blendingTransition = new BlendingScreenTransition(batch, 1F);
41-
screenManager.addScreenTransition("blending_transition", blendingTransition);
42-
// ...
43-
4433
// Push the first screen using a blending transition
45-
this.screenManager.pushScreen("green", "blending_transition");
34+
this.screenManager.pushScreen(new GreenScreen(), new BlendingScreenTransition(batch, 1F));
4635

4736
Gdx.app.debug("Game", "Initialization finished.");
4837
}
@@ -52,7 +41,7 @@ public class MyGdxGame extends ManagedGame<ManagedScreen, ScreenTransition> {
5241

5342
**Some additional notes:**
5443

55-
* Input processors have to be added in a screen via `ManagedScreen#addInputProcessor(...)`. This is needed so the input processors can be automatically registered/unregistered when the screen is shown/hidden.
44+
* Input processors should be added in a screen via `ManagedScreen#addInputProcessor(...)`. This has the advantage that they are automatically registered/unregistered when the screen is shown/hidden.
5645

5746

5847
## Documentation

build.gradle

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
apply plugin: "java-library"
22
apply plugin: "eclipse"
33
apply plugin: "idea"
4-
apply plugin: "jacoco"
5-
apply plugin: "maven"
64

7-
version '0.6.9'
5+
version '0.7.0'
86

97
sourceCompatibility = 1.8
108
targetCompatibility = 1.8
119

10+
if (JavaVersion.current().isJava9Compatible()) {
11+
tasks.withType(Javadoc) {
12+
options.addStringOption("-release", "8");
13+
}
14+
}
15+
1216
repositories {
1317
mavenCentral()
1418
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
@@ -35,64 +39,56 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
3539
artifacts {
3640
archives sourcesJar
3741
archives javadocJar
38-
}
42+
}
3943

40-
install {
41-
repositories.mavenInstaller {
42-
pom.project {
43-
licenses {
44-
license {
45-
name "The Apache Software License, Version 2.0"
46-
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
47-
distribution "repo"
44+
// EXAMPLES
45+
sourceSets {
46+
example {
47+
compileClasspath += sourceSets.main.output
48+
runtimeClasspath += sourceSets.main.output
49+
java {
4850
}
49-
}
5051
}
51-
}
5252
}
5353

5454
// DEPENDENCIES
5555
ext {
56-
gdxVersion = "1.12.0"
57-
guacamoleVersion = "0.3.3"
56+
gdxVersion = "1.12.1"
57+
guacamoleVersion = "v0.3.5"
5858

5959
// Test dependencies
60-
junitVersion = "5.6.0"
61-
mockitoVersion = "3.4.4"
60+
junitVersion = "5.10.0"
61+
mockitoVersion = "4.11.0"
6262
}
6363

6464
dependencies {
6565
implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
6666
api "com.github.crykn.guacamole:gdx:$guacamoleVersion" // is exposed because of NestableFrameBuffer
6767

68-
//testCompile "org.junit.platform:junit-platform-launcher:1.2.0" // needed for a bug in older eclipse versions
69-
68+
testImplementation "org.junit.platform:junit-platform-launcher:1.2.0" // needed for a bug in older eclipse versions
7069
testImplementation "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
71-
testImplementation "org.mockito:mockito-core:$mockitoVersion"
70+
testImplementation "org.mockito:mockito-inline:$mockitoVersion"
7271
testImplementation "com.badlogicgames.gdx:gdx:$gdxVersion"
7372
testImplementation "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
7473
testImplementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
74+
75+
exampleImplementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
76+
exampleImplementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
7577
}
7678

77-
// TESTS & CI
79+
80+
// TESTS
7881
test {
82+
useJUnitPlatform()
7983
testLogging {
8084
events "failed"
8185
exceptionFormat "full"
8286
}
83-
84-
finalizedBy(tasks.jacocoTestReport)
8587
}
8688

87-
jacocoTestReport {
88-
reports {
89-
xml.enabled true
90-
html.enabled false
91-
}
92-
}
93-
94-
check.dependsOn jacocoTestReport
95-
89+
// Clearing Eclipse project data in root folder
9690
tasks.eclipse.doLast {
97-
delete ".project"
91+
delete '.project'
92+
delete '.classpath'
93+
delete '.settings/'
9894
}

codecov.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

gradle/wrapper/gradle-wrapper.jar

4.11 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
File renamed without changes.

example/BlankScreen.java renamed to src/example/java/com/mygame/BlankScreen.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1+
package com.mygame;
2+
13
import de.eskalon.commons.screen.ManagedScreen;
24

35
public class BlankScreen extends ManagedScreen {
46

5-
@Override
6-
protected void create() {
7-
// do nothing
8-
}
9-
10-
@Override
11-
public void hide() {
12-
// do nothing
13-
}
14-
157
@Override
168
public void render(float delta) {
179
// do nothing except having the screen cleared

example/BlueScreen.java renamed to src/example/java/com/mygame/BlueScreen.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package com.mygame;
2+
13
import com.badlogic.gdx.Gdx;
24
import com.badlogic.gdx.InputAdapter;
35
import com.badlogic.gdx.graphics.Color;
@@ -7,6 +9,9 @@
79
import com.badlogic.gdx.utils.viewport.Viewport;
810

911
import de.eskalon.commons.screen.ManagedScreen;
12+
import de.eskalon.commons.screen.transition.impl.HorizontalSlicingTransition;
13+
import de.eskalon.commons.screen.transition.impl.SlidingDirection;
14+
import de.eskalon.commons.screen.transition.impl.SlidingOutTransition;
1015

1116
public class BlueScreen extends ManagedScreen {
1217

@@ -16,24 +21,27 @@ public class BlueScreen extends ManagedScreen {
1621

1722
public BlueScreen() {
1823
this.game = (MyGdxGame) Gdx.app.getApplicationListener();
19-
}
2024

21-
@Override
22-
protected void create() {
2325
this.shapeRenderer = new ShapeRenderer();
2426
this.addInputProcessor(new InputAdapter() {
2527
@Override
26-
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
28+
public boolean touchDown(int screenX, int screenY, int pointer,
29+
int button) {
2730
/*
2831
* Switch using two transitions that are queued.
2932
*/
30-
game.getScreenManager().pushScreen("blank", "slicing_transition");
31-
game.getScreenManager().pushScreen("green", "sliding_out_transition");
33+
game.getScreenManager().pushScreen(new BlankScreen(),
34+
new HorizontalSlicingTransition(game.getBatch(), 5,
35+
1F));
36+
game.getScreenManager().pushScreen(new GreenScreen(),
37+
new SlidingOutTransition(game.getBatch(),
38+
SlidingDirection.DOWN, 0.35F));
3239
return true;
3340
}
3441
});
3542

36-
this.viewport = new ScreenViewport(); // a ScreenViewport provides the default behaviour
43+
this.viewport = new ScreenViewport(); // a ScreenViewport provides the
44+
// default behaviour
3745
}
3846

3947
@Override
@@ -46,24 +54,19 @@ public void render(float delta) {
4654
*/
4755
shapeRenderer.begin(ShapeType.Filled);
4856
shapeRenderer.setColor(Color.BLUE);
49-
shapeRenderer.triangle(50, 50, game.getWidth() - 50, 50, game.getWidth() / 2, game.getHeight() - 50);
57+
shapeRenderer.triangle(50, 50, Gdx.graphics.getWidth() - 50, 50,
58+
Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() - 50);
5059
shapeRenderer.end();
5160
}
5261

53-
@Override
54-
public void dispose() {
55-
if (isInitialized())
56-
shapeRenderer.dispose();
57-
}
58-
5962
@Override
6063
public void resize(int width, int height) {
6164
viewport.update(width, height, true);
6265
}
6366

6467
@Override
65-
public void hide() {
66-
// not needed
68+
public void dispose() {
69+
shapeRenderer.dispose();
6770
}
6871

6972
@Override

example/DesktopLauncher.java renamed to src/example/java/com/mygame/DesktopLauncher.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package com.mygame;
12

23
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
34
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
@@ -16,7 +17,9 @@ public static void main(String[] args) {
1617
// Start the game
1718
new Lwjgl3Application(new MyGdxGame(), config);
1819
} catch (Exception e) {
19-
System.err.println("An unexpected error occurred while starting the game: " + e.getLocalizedMessage());
20+
System.err.println(
21+
"An unexpected error occurred while starting the game:");
22+
e.printStackTrace();
2023
System.exit(-1);
2124
}
2225
}

0 commit comments

Comments
 (0)