Bug 20: Rework and refactor the Screen class
This commit is contained in:
parent
7df3021ded
commit
95fed4c8a8
@ -23,7 +23,9 @@ import com.badlogic.gdx.Application;
|
||||
import static com.badlogic.gdx.Application.ApplicationType.Android;
|
||||
import static com.badlogic.gdx.Application.ApplicationType.Desktop;
|
||||
import static com.badlogic.gdx.Application.ApplicationType.WebGL;
|
||||
import static com.badlogic.gdx.Application.ApplicationType.iOS;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.pixelgamelibrary.api.GameI;
|
||||
import com.pixelgamelibrary.api.PixelException;
|
||||
import com.pixelgamelibrary.api.Platform;
|
||||
import com.pixelgamelibrary.api.interfaces.AppI;
|
||||
@ -37,6 +39,7 @@ public class AppLibGDXImpl implements AppI {
|
||||
private static final String DEFAULT_APP_NAME = "pixel-app";
|
||||
|
||||
private String appName = null;
|
||||
private GameI game;
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
@ -53,6 +56,8 @@ public class AppLibGDXImpl implements AppI {
|
||||
return Platform.ANDROID;
|
||||
case WebGL:
|
||||
return Platform.WEB;
|
||||
case iOS:
|
||||
return Platform.IOS;
|
||||
default:
|
||||
throw new PixelException("Unsupported platform: " + applicationType);
|
||||
}
|
||||
@ -106,4 +111,14 @@ public class AppLibGDXImpl implements AppI {
|
||||
return appName != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGame(GameI game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameI getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class GraphicsLibGDXImpl implements GraphicsI {
|
||||
|
||||
|
||||
@Override
|
||||
public String setDisplayMode(boolean fullscreen, boolean window) {
|
||||
public WindowMode setDisplayMode(boolean fullscreen, boolean window) {
|
||||
|
||||
if (fullscreen) {
|
||||
Graphics.Monitor currentMonitor = Gdx.graphics.getMonitor();
|
||||
|
@ -0,0 +1,32 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel: Game library.
|
||||
// Copyright (C) 2024 the original author or authors.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation, either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see
|
||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.pixelgamelibrary.backend.libgdx;
|
||||
|
||||
import com.pixelgamelibrary.api.interfaces.InternalI;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class InternalLibGDXImpl implements InternalI {
|
||||
|
||||
|
||||
|
||||
}
|
@ -24,6 +24,7 @@ import com.pixelgamelibrary.api.interfaces.AssetI;
|
||||
import com.pixelgamelibrary.api.interfaces.AudioI;
|
||||
import com.pixelgamelibrary.api.interfaces.GraphicsI;
|
||||
import com.pixelgamelibrary.api.interfaces.InputI;
|
||||
import com.pixelgamelibrary.api.interfaces.InternalI;
|
||||
import com.pixelgamelibrary.api.interfaces.UtilsI;
|
||||
import com.pixelgamelibrary.api.interfaces.StorageI;
|
||||
import com.pixelgamelibrary.api.interfaces.NetI;
|
||||
@ -43,7 +44,8 @@ public class PixelBackendLibGDX implements PixelBackend {
|
||||
private AssetI pixelAssetLibGdxImpl = null;
|
||||
private StorageI pixelStorageLibGdxImpl = null;
|
||||
private UtilsI pixelUtilsLibGdxImpl = null;
|
||||
|
||||
private InternalI pixelInternalLibGdxImpl = null;
|
||||
|
||||
|
||||
@Override
|
||||
public GraphicsI graphics() {
|
||||
@ -104,13 +106,24 @@ public class PixelBackendLibGDX implements PixelBackend {
|
||||
if (pixelUtilsLibGdxImpl == null) {
|
||||
pixelUtilsLibGdxImpl = new UtilsLibGDXImpl(app());
|
||||
}
|
||||
return pixelUtilsLibGdxImpl; }
|
||||
return pixelUtilsLibGdxImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppI app() {
|
||||
if (pixelAppLibGdxImpl == null) {
|
||||
pixelAppLibGdxImpl = new AppLibGDXImpl();
|
||||
}
|
||||
return pixelAppLibGdxImpl; }
|
||||
return pixelAppLibGdxImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalI internal() {
|
||||
|
||||
if (pixelInternalLibGdxImpl == null) {
|
||||
pixelInternalLibGdxImpl = new InternalLibGDXImpl();
|
||||
}
|
||||
return pixelInternalLibGdxImpl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,104 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel: Game library.
|
||||
// Copyright (C) 2024 the original author or authors.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation, either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see
|
||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.pixelgamelibrary.backend.libgdx.game;
|
||||
|
||||
import com.pixelgamelibrary.api.GameI;
|
||||
import com.pixelgamelibrary.api.GameWrapper;
|
||||
import com.pixelgamelibrary.api.OnSetScreenListener;
|
||||
import com.pixelgamelibrary.api.ScreenI;
|
||||
import com.pixelgamelibrary.backend.libgdx.screen.LibGdxScreen;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class LibGdxGame extends com.badlogic.gdx.Game implements OnSetScreenListener {
|
||||
|
||||
private final GameI game;
|
||||
|
||||
@Override
|
||||
public void onSetScreen(ScreenI screen) {
|
||||
setScreen(new LibGdxScreen(screen));
|
||||
System.out.println("LibGdxGame:onSetScreen");
|
||||
}
|
||||
|
||||
class LibGdxGameWrapper extends GameWrapper {
|
||||
|
||||
private final LibGdxGame libGdxGame;
|
||||
|
||||
public LibGdxGameWrapper(GameI gameI, LibGdxGame libGdxGame) {
|
||||
super(gameI);
|
||||
this.libGdxGame = libGdxGame;
|
||||
gameI.setOnSetScreenListener(libGdxGame);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void setScreen(ScreenI screen) {
|
||||
// System.out.println("LibGdxGame: setScreen");
|
||||
// libGdxGame.setScreen(new LibGdxScreen(screen));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ScreenI getScreen() {
|
||||
// System.out.println("LibGdxGame: getScreen");
|
||||
// LibGdxScreen screen = (LibGdxScreen) libGdxGame.getScreen();
|
||||
// return screen.getPixelScreen();
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
public LibGdxGame(GameI game) {
|
||||
this.game = new LibGdxGameWrapper(game, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
game.create();
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public void resize(int width, int height) {
|
||||
// game.resize(width, height);
|
||||
// }
|
||||
//private int i = 0;
|
||||
// @Override
|
||||
// public void render() {
|
||||
// i++;
|
||||
// System.out.println("Calling LibGdxGame.render " + i);
|
||||
// game.render();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void pause() {
|
||||
// game.pause();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void resume() {
|
||||
// game.resume();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void dispose() {
|
||||
// game.dispose();
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel: Game library.
|
||||
// Copyright (C) 2024 the original author or authors.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation, either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see
|
||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.pixelgamelibrary.backend.libgdx.screen;
|
||||
|
||||
import com.pixelgamelibrary.api.ScreenI;
|
||||
import com.pixelgamelibrary.api.ScreenWrapper;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class LibGdxScreen extends com.badlogic.gdx.ScreenAdapter {
|
||||
|
||||
@Getter
|
||||
private final ScreenI pixelScreen;
|
||||
|
||||
class LibGdxScreenWrapper extends ScreenWrapper {
|
||||
|
||||
private final LibGdxScreen libGdxScreen;
|
||||
|
||||
public LibGdxScreenWrapper(ScreenI screen, LibGdxScreen libGdxScreenIn) {
|
||||
super(screen);
|
||||
this.libGdxScreen = libGdxScreenIn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public LibGdxScreen(ScreenI screen) {
|
||||
this.pixelScreen = new LibGdxScreenWrapper(screen, this);
|
||||
System.out.println("aaaaaa");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
System.out.println("LibGdxScreen : render");
|
||||
pixelScreen.render(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
pixelScreen.resize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
pixelScreen.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
pixelScreen.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
pixelScreen.pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
pixelScreen.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
pixelScreen.dispose();
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package com.pixelgamelibrary.backend.libgdx.storage;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.pixelgamelibrary.api.GameI;
|
||||
import com.pixelgamelibrary.api.Pixel;
|
||||
import com.pixelgamelibrary.api.Platform;
|
||||
import com.pixelgamelibrary.api.interfaces.AppI;
|
||||
@ -9,6 +10,7 @@ import com.pixelgamelibrary.api.interfaces.AssetI;
|
||||
import com.pixelgamelibrary.api.interfaces.AudioI;
|
||||
import com.pixelgamelibrary.api.interfaces.GraphicsI;
|
||||
import com.pixelgamelibrary.api.interfaces.InputI;
|
||||
import com.pixelgamelibrary.api.interfaces.InternalI;
|
||||
import com.pixelgamelibrary.api.interfaces.NetI;
|
||||
import com.pixelgamelibrary.api.interfaces.PixelBackend;
|
||||
import com.pixelgamelibrary.api.interfaces.StorageI;
|
||||
@ -83,6 +85,16 @@ class DesktopAndroidStorageTest {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGame(GameI game) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameI getGame() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@ -120,6 +132,11 @@ class DesktopAndroidStorageTest {
|
||||
public UtilsI utils() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalI internal() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
};
|
||||
Pixel.initBackend(dummyPixelBackend);
|
||||
}
|
||||
|
Reference in New Issue
Block a user