diff --git a/frontend/android/AndroidManifest.xml b/frontend/android/AndroidManifest.xml index c84955598781818383685ee4cb5ad9ca8628faac..8ff4dbcb71e56785d7c1b09aa370ec7f8e6a2fdb 100644 --- a/frontend/android/AndroidManifest.xml +++ b/frontend/android/AndroidManifest.xml @@ -12,7 +12,7 @@ android:theme="@style/GdxTheme" > <activity android:name="com.gameware.game.AndroidLauncher" - android:label="@string/app_name" + android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout"> <intent-filter> diff --git a/frontend/android/assets/glassy/raw/DimmingTexture.png b/frontend/android/assets/DimmingTexture.png similarity index 100% rename from frontend/android/assets/glassy/raw/DimmingTexture.png rename to frontend/android/assets/DimmingTexture.png diff --git a/frontend/android/assets/LoadingText.png b/frontend/android/assets/LoadingText.png new file mode 100644 index 0000000000000000000000000000000000000000..818bf297f5bf214509f5870cd611ef8e1747a9aa Binary files /dev/null and b/frontend/android/assets/LoadingText.png differ diff --git a/frontend/core/src/com/gameware/game/GameWare.java b/frontend/core/src/com/gameware/game/GameWare.java index 3364214f6f2f949f27ef44decefbff5249d95d34..aacb21b9466d2ddd099ac4374933412585c2efe6 100644 --- a/frontend/core/src/com/gameware/game/GameWare.java +++ b/frontend/core/src/com/gameware/game/GameWare.java @@ -70,6 +70,7 @@ public class GameWare extends ApplicationAdapter { music.setVolume(0.1f); toggleMusic(); + //gsm.push(new LoginState(gsm)); gsm.push(new LoginState(gsm)); // try{ diff --git a/frontend/core/src/com/gameware/game/sprites/LoadingText.java b/frontend/core/src/com/gameware/game/sprites/LoadingText.java new file mode 100644 index 0000000000000000000000000000000000000000..965300d0d514898fcb8f3819a232e6b7db1b895f --- /dev/null +++ b/frontend/core/src/com/gameware/game/sprites/LoadingText.java @@ -0,0 +1,59 @@ +package com.gameware.game.sprites; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; + +public class LoadingText extends Sprite { + private boolean isLoading = false; + private boolean firstUpdateFinished = false; + private Texture loadingText = new Texture(Gdx.files.internal("LoadingText.png")); + private Texture dimmingBackgroundTexture = new Texture(Gdx.files.internal("DimmingTexture.png")); + + @Override + public void reset() { + this.firstUpdateFinished = false; + this.isLoading = false; + } + + @Override + public void draw(SpriteBatch sb) { + if(this.isLoading) { + sb.begin(); + sb.draw(this.dimmingBackgroundTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + sb.draw(this.loadingText, Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 2, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 10); + sb.end(); + } + } + + @Override + public void update(float dt) { + + // If we've already completed the first call to this update method after isLoading was + // set to true (this means that the draw method has been called) and the loading text is + // visible we know that the loading has finished + if(this.isLoading && this.firstUpdateFinished){ + this.isLoading = false; + this.firstUpdateFinished = false; + } + + // We need to wait one iteration of update() for the screen to render the loading text first + else if(this.isLoading){ + this.firstUpdateFinished = true; + } + } + + @Override + public void dispose() { + this.dimmingBackgroundTexture.dispose(); + this.loadingText.dispose(); + } + + public void setLoading(){ + this.isLoading = true; + } + + public boolean textIsRendering(){ + return this.firstUpdateFinished && this.isLoading; + } +} diff --git a/frontend/core/src/com/gameware/game/states/BubbleWrapState.java b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java index 6983a16443faf94af7034dd70352165a17d11f3d..44f1377acf6598e1cc2a2ee9ad326631ca889ae2 100644 --- a/frontend/core/src/com/gameware/game/states/BubbleWrapState.java +++ b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java @@ -82,20 +82,19 @@ public class BubbleWrapState extends PlayStateTemplate { // Keeps score consistent this.setScore(this.poppedBubbles); - - // Checks if the pause button was pressed - super.checkPause(); } } @Override public void update(float dt) { + super.update(dt); + Gdx.input.setInputProcessor(stage); this.handleInput(); this.currentTime += dt; - timeLabel.setText("Time left: " + Math.round((totalTime - currentTime) * 100.0) / 100.0); + timeLabel.setText("Time left: " + Math.max(Math.round((totalTime - currentTime) * 100.0) / 100.0, 0.00)); // Game should finish if the time has run out if (this.currentTime >= this.totalTime) { @@ -116,9 +115,7 @@ public class BubbleWrapState extends PlayStateTemplate { public void render(SpriteBatch sb) { stage.draw(); - // Renders pause button - super.renderPauseButton(sb); - + super.render(sb); } private void createBubbles() { @@ -163,18 +160,19 @@ public class BubbleWrapState extends PlayStateTemplate { private void handleFinishedGame() { System.out.println("Game finished, starting new state"); this.setScore(this.poppedBubbles); - this.gameDone(); + super.setGameFinished(); return; } @Override public void dispose() { + super.dispose(); + stage.dispose(); this.unpopped.dispose(); this.popped1.dispose(); this.popped2.dispose(); this.popped3.dispose(); - super.pauseButton.dispose(); } @Override diff --git a/frontend/core/src/com/gameware/game/states/ColorRushState.java b/frontend/core/src/com/gameware/game/states/ColorRushState.java index c6693667febb8914562ff0d9a51b4f9e1591a9f4..4be8805ac224e019e3b15aa80866ab495913816c 100644 --- a/frontend/core/src/com/gameware/game/states/ColorRushState.java +++ b/frontend/core/src/com/gameware/game/states/ColorRushState.java @@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.gameware.game.GameWare; import com.gameware.game.sprites.ColorRushButton; import com.gameware.game.sprites.ColorRushTarget; -import com.gameware.game.sprites.PauseButton; import java.util.ArrayList; import java.util.Collections; @@ -103,23 +102,21 @@ public class ColorRushState extends PlayStateTemplate { // Keeps score consistent this.setScore(this.targetsHit); - - //Pauses the game if the user pressed the pause button - super.checkPause(); } } @Override public void update(float dt) { + super.update(dt); // Increases the current duration, used to keep track of the play duration and stop the game // after a while this.currentDuration += dt; - // Post score and exit if the game is over + // Set score and start rendering the loading text if the game is over if(this.currentDuration > this.totalGameDuration){ this.setScore(this.targetsHit); - this.gameDone(); + this.setGameFinished(); return; } @@ -171,14 +168,10 @@ public class ColorRushState extends PlayStateTemplate { sb.draw(this.background, 0, Gdx.graphics.getHeight()/5, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // Time left - this.font.draw(sb, String.valueOf(Math.round((this.totalGameDuration - this.currentDuration) * 100) / 100.0), Gdx.graphics.getWidth()/40,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/40); + this.font.draw(sb, String.valueOf(Math.max(Math.round((this.totalGameDuration - this.currentDuration) * 100), 0.00) / 100.0), Gdx.graphics.getWidth()/40,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/40); sb.end(); - - // Renders pause button - super.renderPauseButton(sb); - for (ColorRushButton button : this.buttons) { button.draw(sb); } @@ -191,11 +184,13 @@ public class ColorRushState extends PlayStateTemplate { target.draw(sb); } - + super.render(sb); } @Override public void dispose() { + super.dispose(); + for (ColorRushButton button : this.buttons) { button.dispose(); } @@ -215,7 +210,6 @@ public class ColorRushState extends PlayStateTemplate { this.font.dispose(); this.background.dispose(); this.disabledColorTexture.dispose(); - super.pauseButton.dispose(); } @Override diff --git a/frontend/core/src/com/gameware/game/states/LoginState.java b/frontend/core/src/com/gameware/game/states/LoginState.java index d4721acf8fbed35086a2a77a738598afab5f6ac5..5ac4493179a73f2a19b20c401720b4cb3e48d26d 100644 --- a/frontend/core/src/com/gameware/game/states/LoginState.java +++ b/frontend/core/src/com/gameware/game/states/LoginState.java @@ -1,6 +1,7 @@ package com.gameware.game.states; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; @@ -12,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.gameware.game.GameWare; import com.gameware.game.QueryIntermediate; import com.gameware.game.models.Player; +import com.gameware.game.sprites.LoadingText; import java.io.IOException; import java.util.NoSuchElementException; @@ -39,6 +41,12 @@ public class LoginState extends State { private String takenUsernameText = "Username already taken"; private String ioExceptionText = "Something went wrong with query"; + private LoadingText loadingText = new LoadingText(); + private boolean loginBtnClicked = false; + private boolean signUpBtnClicked = false; + + + public LoginState(GameStateManager gsm) { super(gsm); makeStage(); @@ -82,7 +90,7 @@ public class LoginState extends State { loginBtn.addListener(new ClickListener() { @Override public void clicked(InputEvent e, float x, float y){ - handleLoginBtnClick(); + setLoginBtnClicked(); } }); return loginBtn; @@ -93,7 +101,7 @@ public class LoginState extends State { signUpBtn.addListener(new ClickListener() { @Override public void clicked(InputEvent e, float x, float y){ - handleSignUpBtnClick(); + setSignUpBtnClicked(); } }); return signUpBtn; @@ -142,11 +150,23 @@ public class LoginState extends State { @Override public void update(float dt) { stage.act(dt); + + if(this.loginBtnClicked && this.loadingText.textIsRendering()){ + this.handleLoginBtnClick(); + } + + if(this.signUpBtnClicked && this.loadingText.textIsRendering()){ + this.handleSignUpBtnClick(); + } + + this.loadingText.update(dt); } @Override public void render(SpriteBatch sb) { stage.draw(); + + this.loadingText.draw(sb); } @Override @@ -160,6 +180,16 @@ public class LoginState extends State { passwordInputField.setText(passwordInputText); } + private void setLoginBtnClicked(){ + this.loginBtnClicked = true; + this.loadingText.setLoading(); + } + + private void setSignUpBtnClicked(){ + this.signUpBtnClicked = true; + this.loadingText.setLoading(); + } + private void handleLoginBtnClick(){ String username = usernameInputField.getText(); String password = passwordInputField.getText(); @@ -180,6 +210,8 @@ public class LoginState extends State { System.out.println(e); errorLabel.setText(e.getMessage()); } + + this.loginBtnClicked = false; } private void handleSignUpBtnClick(){ @@ -202,5 +234,7 @@ public class LoginState extends State { System.out.println(e); errorLabel.setText(e.getMessage()); } + + this.signUpBtnClicked = false; } } diff --git a/frontend/core/src/com/gameware/game/states/MenuState.java b/frontend/core/src/com/gameware/game/states/MenuState.java index ea9fa85f47a6b42fb24a39686900101de7dcc9e7..e6260a4c3f254b48a7153704caa4c5442ba2be04 100644 --- a/frontend/core/src/com/gameware/game/states/MenuState.java +++ b/frontend/core/src/com/gameware/game/states/MenuState.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.gameware.game.GameWare; +import com.gameware.game.sprites.LoadingText; public class MenuState extends State{ @@ -23,6 +24,10 @@ public class MenuState extends State{ private String optionBtnText = "Options"; private String logOutBtnText = "Log out"; + private boolean multiBtnClicked = false; + + private LoadingText loadingText = new LoadingText(); + public MenuState(GameStateManager gsm) { super(gsm); makeStage(); @@ -66,7 +71,7 @@ public class MenuState extends State{ TextButton multiPlayerBtn = new TextButton(multiPlayerBtnText, skin); multiPlayerBtn.addListener(new ClickListener() { @Override - public void clicked(InputEvent e, float x, float y){ handleMultiBtnClick(); } + public void clicked(InputEvent e, float x, float y){ setMultiBtnClicked(); } }); return multiPlayerBtn; } @@ -110,6 +115,11 @@ public class MenuState extends State{ @Override public void update(float dt) { + if(this.multiBtnClicked && this.loadingText.textIsRendering()){ + this.handleMultiBtnClick(); + } + this.loadingText.update(dt); + Gdx.input.setInputProcessor(stage); Gdx.input.setCatchBackKey(true); handleInput(); @@ -117,7 +127,10 @@ public class MenuState extends State{ } @Override - public void render(SpriteBatch sb) { stage.draw(); } + public void render(SpriteBatch sb) { + stage.draw(); + this.loadingText.draw(sb); + } @Override public void dispose() { stage.dispose(); } @@ -125,6 +138,11 @@ public class MenuState extends State{ @Override public void reset() { } + private void setMultiBtnClicked(){ + this.multiBtnClicked = true; + this.loadingText.setLoading(); + } + private void handleOptionsBtnClick(){ gsm.set(new OptionsState(gsm)); } diff --git a/frontend/core/src/com/gameware/game/states/PauseState.java b/frontend/core/src/com/gameware/game/states/PauseState.java index 8dccc6cd8c050b78bf8a3ec7420a1bdc766fb44d..f6a3e9b696d85fac1baf02f50e0a5b5419865216 100644 --- a/frontend/core/src/com/gameware/game/states/PauseState.java +++ b/frontend/core/src/com/gameware/game/states/PauseState.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.gameware.game.sprites.ConfirmationBox; +import com.gameware.game.sprites.LoadingText; import com.gameware.game.sprites.PauseCircle; import com.gameware.game.sprites.PauseMenuButton; @@ -22,18 +23,23 @@ public class PauseState extends State { private PauseMenuButton exitButton; private boolean needsConfirmation; private PlayStateTemplate pausedGame; + private LoadingText loadingText; + private boolean userExited; public PauseState(GameStateManager gsm, PlayStateTemplate pausedGame) { super(gsm); this.background = new Texture(Gdx.files.internal("glassy/raw/PauseBackground.jpg")); this.pauseText = new Texture(Gdx.files.internal("glassy/raw/PauseText.png")); - this.dimmingTexture = new Texture(Gdx.files.internal("glassy/raw/DimmingTexture.png")); + this.dimmingTexture = new Texture(Gdx.files.internal("DimmingTexture.png")); this.pauseCircles = new ArrayList<PauseCircle>(); this.pausedGame = pausedGame; + this.loadingText = new LoadingText(); + this.userExited = false; + int confirmationBoxWidth = Gdx.graphics.getWidth()*7/8; int confirmationBoxHeight = confirmationBoxWidth/2; this.confirmationBox = new ConfirmationBox(Gdx.graphics.getWidth()/2 - confirmationBoxWidth/2, Gdx.graphics.getHeight()/2 - confirmationBoxHeight/2, confirmationBoxWidth, confirmationBoxHeight); @@ -62,10 +68,11 @@ public class PauseState extends State { this.needsConfirmation = false; } - // User confirms the exit, posts the current score + // User confirms the exit, this will now render the loading text and then post the + // score and exit if(this.confirmationBox.yesPressed(touchX, touchY)) { - this.gsm.pop(); - this.pausedGame.gameDone(); + this.loadingText.setLoading(); + this.userExited = true; } } @@ -75,7 +82,7 @@ public class PauseState extends State { this.gsm.pop(); } - // First step of exitting; user now needs to confirm the exit via the popup + // First step of exiting; user now needs to confirm the exit via the popup if(this.exitButton.isPressed(touchX, touchY)){ this.needsConfirmation = true; } @@ -85,6 +92,12 @@ public class PauseState extends State { @Override public void update(float dt) { + if(this.userExited && this.loadingText.textIsRendering()){ + this.gsm.pop(); + this.pausedGame.gameDone(); + } + this.loadingText.update(dt); + this.handleInput(); for(PauseCircle pc : this.pauseCircles){ @@ -133,6 +146,7 @@ public class PauseState extends State { this.confirmationBox.draw(sb); } + this.loadingText.draw(sb); } @Override diff --git a/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java b/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java index 12c2656c505a82154e0f93d0ec0d52d6f1486498..447f255556d68923f48346711ca04b58e85f6829 100644 --- a/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java +++ b/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java @@ -9,6 +9,7 @@ import com.gameware.game.QueryIntermediate; import com.gameware.game.models.Round; import com.gameware.game.models.RoundCheck; import com.gameware.game.models.Tournament; +import com.gameware.game.sprites.LoadingText; import com.gameware.game.sprites.PauseButton; import java.io.IOException; @@ -19,8 +20,9 @@ public abstract class PlayStateTemplate extends State { private Round round = null; private Tournament tournament = null; private Round nextRound = null; - protected PauseButton pauseButton; + private PauseButton pauseButton; private Round updatedRound = null; + private LoadingText loadingText = new LoadingText(); protected float totalGameTime = 30f; protected Texture screenshot = null; @@ -31,10 +33,31 @@ public abstract class PlayStateTemplate extends State { this.pauseButton = new PauseButton(); } - public void renderPauseButton(SpriteBatch sb){ + public void update(float dt){ + // Updates the loading text; nothing happens if there is no loading + this.loadingText.update(dt); + + // Post score and exit if the game is over and the loading text is rendering + if(this.loadingText.textIsRendering()){ + this.gameDone(); + return; + } + + // Pause the game if the pause button was pressed + if(Gdx.input.justTouched() && this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ + this.gsm.push(new PauseState(this.gsm, this)); + } + } + + public void render(SpriteBatch sb){ + this.loadingText.draw(sb); this.pauseButton.draw(sb); } + public void setGameFinished(){ + this.loadingText.setLoading(); + } + public void setRound(Round r){ this.round = r; } @@ -104,13 +127,6 @@ public abstract class PlayStateTemplate extends State { } } - // Checks if the pause button was pressed, and pauses the minigame accordingly - public void checkPause(){ - if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ - this.gsm.push(new PauseState(this.gsm, this)); - } - } - // Changes the color of the pause button to white public void setPauseButtonWhite(){ this.pauseButton.setButtonWhite(); @@ -120,5 +136,10 @@ public abstract class PlayStateTemplate extends State { public void setPauseButtonBlack(){ this.pauseButton.setButtonBlack(); } + + public void dispose(){ + this.loadingText.dispose(); + this.pauseButton.dispose(); + } } diff --git a/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java b/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java index 05f25908c2670975c6e1b25dbff647062a58d67e..d08df0a3828307324f8927beb3da9ceb008992a7 100644 --- a/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java +++ b/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java @@ -19,6 +19,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.gameware.game.GameWare; import com.gameware.game.models.Game; +import com.gameware.game.sprites.LoadingText; + import java.io.IOException; public class ViewHighScoreState extends State { @@ -34,6 +36,10 @@ public class ViewHighScoreState extends State { private Label stateNameLabel = new Label("High Scores", skin, "big"); private Label secondStateNameLabel = new Label("Select game", skin, "big"); + private Game chosenGame = null; + + private LoadingText loadingText = new LoadingText(); + public ViewHighScoreState(GameStateManager gsm) { super(gsm); @@ -97,6 +103,12 @@ public class ViewHighScoreState extends State { @Override public void update(float dt) { + if(this.chosenGame != null && this.loadingText.textIsRendering()){ + this.handleGameBtnClick(this.chosenGame); + } + this.loadingText.update(dt); + + Gdx.input.setInputProcessor(stage); Gdx.input.setCatchBackKey(true); handleInput(); @@ -106,11 +118,13 @@ public class ViewHighScoreState extends State { @Override public void render(SpriteBatch sb) { stage.draw(); + this.loadingText.draw(sb); } @Override public void dispose() { stage.dispose(); + this.loadingText.dispose(); } @Override @@ -128,6 +142,11 @@ public class ViewHighScoreState extends State { return backBtn; } + private void setGameBtnClicked(Game game){ + this.chosenGame = game; + this.loadingText.setLoading(); + } + private void handleBackBtnClick(){ gsm.set(new MenuState(gsm)); } @@ -144,8 +163,8 @@ public class ViewHighScoreState extends State { } public void clicked(InputEvent event, float x, float y) { - handleGameBtnClick(game); - + setGameBtnClicked(game); }; } + } \ No newline at end of file