-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'team-2-ui' into team-2-sound
- Loading branch information
Showing
9 changed files
with
441 additions
and
1 deletion.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.csse3200.game.components.maingame; | ||
|
||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.scenes.scene2d.Actor; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Table; | ||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; | ||
import com.csse3200.game.GdxGame; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.entities.factories.PauseMenuFactory; | ||
import com.csse3200.game.ui.UIComponent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Displays a button to pause the game and bring up a pause menu. | ||
*/ | ||
public class MainGamePauseDisplay extends UIComponent { | ||
private static final Logger logger = LoggerFactory.getLogger(MainGamePauseDisplay.class); | ||
private static final float Z_INDEX = 2f; | ||
private Table table; | ||
|
||
private GdxGame game; | ||
|
||
public MainGamePauseDisplay(GdxGame screenSwitchHandle) { | ||
game = screenSwitchHandle; | ||
} | ||
|
||
@Override | ||
public void create() { | ||
super.create(); | ||
addActors(); | ||
} | ||
|
||
private void addActors() { | ||
table = new Table(); | ||
table.top().right(); | ||
table.setFillParent(true); | ||
|
||
TextButton mainMenuBtn = new TextButton("Pause", skin); | ||
|
||
// Spawns a pause menu when the button is pressed. | ||
mainMenuBtn.addListener( | ||
new ChangeListener() { | ||
@Override | ||
public void changed(ChangeEvent changeEvent, Actor actor) { | ||
logger.debug("Pause button clicked"); | ||
PauseMenuFactory.createPauseMenu(game, false); | ||
} | ||
}); | ||
|
||
table.add(mainMenuBtn).padTop(100f).padRight(10f); | ||
|
||
stage.addActor(table); | ||
} | ||
|
||
@Override | ||
public void draw(SpriteBatch batch) { | ||
// draw is handled by the stage | ||
} | ||
|
||
@Override | ||
public float getZIndex() { | ||
return Z_INDEX; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
table.clear(); | ||
super.dispose(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuContinueButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.csse3200.game.components.pausemenu; | ||
|
||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.scenes.scene2d.Actor; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Table; | ||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; | ||
import com.csse3200.game.components.maingame.MainGamePauseDisplay; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.entities.factories.PauseMenuFactory; | ||
import com.csse3200.game.ui.UIComponent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Displays a button in the pause menu to resume the game and put away the pause menu. | ||
*/ | ||
public class PauseMenuContinueButton extends UIComponent { | ||
private static final Logger logger = LoggerFactory.getLogger(PauseMenuContinueButton.class); | ||
private static final float Z_INDEX = 2f; | ||
private Table table; | ||
|
||
@Override | ||
public void create() { | ||
super.create(); | ||
addActors(); | ||
} | ||
|
||
private void addActors() { | ||
table = new Table(); | ||
table.top().right(); | ||
table.setFillParent(true); | ||
|
||
TextButton pauseMenuBtn = new TextButton("Continue", skin); | ||
|
||
// Triggers an event when the button is pressed. | ||
pauseMenuBtn.addListener( | ||
new ChangeListener() { | ||
@Override | ||
public void changed(ChangeEvent changeEvent, Actor actor) { | ||
logger.debug("Continue button clicked"); | ||
entity.dispose(); | ||
} | ||
}); | ||
|
||
table.add(pauseMenuBtn).padTop(300f).padRight(700f); | ||
|
||
stage.addActor(table); | ||
} | ||
|
||
@Override | ||
public void draw(SpriteBatch batch) { | ||
// draw is handled by the renderer component | ||
} | ||
|
||
@Override | ||
public float getZIndex() { | ||
return Z_INDEX; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
table.clear(); | ||
super.dispose(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuMainMenuButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.csse3200.game.components.pausemenu; | ||
|
||
import com.badlogic.gdx.Game; | ||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.scenes.scene2d.Actor; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Table; | ||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; | ||
import com.csse3200.game.GdxGame; | ||
import com.csse3200.game.ui.UIComponent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Displays a button in the pause menu to return to the main menu screen. | ||
*/ | ||
public class PauseMenuMainMenuButton extends UIComponent { | ||
private static final Logger logger = LoggerFactory.getLogger(PauseMenuMainMenuButton.class); | ||
private static final float Z_INDEX = 2f; | ||
private Table table; | ||
|
||
private final GdxGame game; | ||
|
||
public PauseMenuMainMenuButton(GdxGame screenSwitchHandle) { | ||
game = screenSwitchHandle; | ||
} | ||
@Override | ||
public void create() { | ||
super.create(); | ||
addActors(); | ||
} | ||
|
||
private void addActors() { | ||
table = new Table(); | ||
table.top().right(); | ||
table.setFillParent(true); | ||
|
||
TextButton pauseMenuBtn = new TextButton("Main Menu", skin); | ||
|
||
// Triggers an event when the button is pressed. | ||
pauseMenuBtn.addListener( | ||
new ChangeListener() { | ||
@Override | ||
public void changed(ChangeEvent changeEvent, Actor actor) { | ||
logger.debug("Main menu button clicked"); | ||
game.setScreen(GdxGame.ScreenType.MAIN_MENU); | ||
} | ||
}); | ||
|
||
table.add(pauseMenuBtn).padTop(400f).padRight(490f); | ||
|
||
stage.addActor(table); | ||
} | ||
|
||
@Override | ||
public void draw(SpriteBatch batch) { | ||
// draw is handled by the renderer component | ||
} | ||
|
||
@Override | ||
public float getZIndex() { | ||
return Z_INDEX; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
table.clear(); | ||
super.dispose(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuPlanetSelectButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.csse3200.game.components.pausemenu; | ||
|
||
import com.badlogic.gdx.Game; | ||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.scenes.scene2d.Actor; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Table; | ||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; | ||
import com.csse3200.game.GdxGame; | ||
import com.csse3200.game.ui.UIComponent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Displays a button in the pause menu to return to the planet select screen. | ||
*/ | ||
public class PauseMenuPlanetSelectButton extends UIComponent { | ||
private static final Logger logger = LoggerFactory.getLogger(PauseMenuPlanetSelectButton.class); | ||
private static final float Z_INDEX = 2f; | ||
private Table table; | ||
|
||
private final GdxGame game; | ||
|
||
public PauseMenuPlanetSelectButton(GdxGame screenSwitchHandle) { | ||
game = screenSwitchHandle; | ||
} | ||
@Override | ||
public void create() { | ||
super.create(); | ||
addActors(); | ||
} | ||
|
||
private void addActors() { | ||
table = new Table(); | ||
table.top().right(); | ||
table.setFillParent(true); | ||
|
||
TextButton pauseMenuBtn = new TextButton("Planet Select", skin); | ||
|
||
// Triggers an event when the button is pressed. | ||
pauseMenuBtn.addListener( | ||
new ChangeListener() { | ||
@Override | ||
public void changed(ChangeEvent changeEvent, Actor actor) { | ||
logger.debug("Planet select button clicked"); | ||
game.setScreen(GdxGame.ScreenType.LEVEL_SELECT); | ||
} | ||
}); | ||
|
||
table.add(pauseMenuBtn).padTop(400f).padRight(675f); | ||
|
||
stage.addActor(table); | ||
} | ||
|
||
@Override | ||
public void draw(SpriteBatch batch) { | ||
// draw is handled by the renderer component | ||
} | ||
|
||
@Override | ||
public float getZIndex() { | ||
return Z_INDEX; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
table.clear(); | ||
super.dispose(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuSettingsButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.csse3200.game.components.pausemenu; | ||
|
||
import com.badlogic.gdx.Game; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.scenes.scene2d.Actor; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Table; | ||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; | ||
import com.csse3200.game.GdxGame; | ||
import com.csse3200.game.ui.UIComponent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Displays a button in the pause menu to open the game settings. | ||
*/ | ||
public class PauseMenuSettingsButton extends UIComponent { | ||
private static final Logger logger = LoggerFactory.getLogger(PauseMenuSettingsButton.class); | ||
private static final float Z_INDEX = 2f; | ||
private Table table; | ||
|
||
private final GdxGame game; | ||
|
||
public PauseMenuSettingsButton(GdxGame screenSwitchHandle) { | ||
game = screenSwitchHandle; | ||
} | ||
|
||
@Override | ||
public void create() { | ||
super.create(); | ||
addActors(); | ||
} | ||
|
||
private void addActors() { | ||
table = new Table(); | ||
table.top().right(); | ||
table.setFillParent(true); | ||
|
||
TextButton pauseMenuBtn = new TextButton("Settings", skin); | ||
|
||
// Triggers an event when the button is pressed. | ||
pauseMenuBtn.addListener( | ||
new ChangeListener() { | ||
@Override | ||
public void changed(ChangeEvent changeEvent, Actor actor) { | ||
logger.debug("Settings button clicked"); | ||
game.setScreen(GdxGame.ScreenType.SETTINGS); | ||
} | ||
}); | ||
|
||
table.add(pauseMenuBtn).padTop(300f).padRight(500f); | ||
|
||
stage.addActor(table); | ||
} | ||
|
||
@Override | ||
public void draw(SpriteBatch batch) { | ||
// draw is handled by the renderer component | ||
} | ||
|
||
@Override | ||
public float getZIndex() { | ||
return Z_INDEX; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
table.clear(); | ||
super.dispose(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.csse3200.game.components.pausemenu; | ||
|
||
import com.csse3200.game.components.Component; | ||
import com.csse3200.game.entities.Entity; | ||
import com.badlogic.gdx.utils.Array; | ||
import com.csse3200.game.entities.factories.PauseMenuFactory; | ||
import com.csse3200.game.services.ServiceLocator; | ||
|
||
/** | ||
* Handles the pausing/resuming of time when the pause menu is brought up/put away. | ||
*/ | ||
public class PauseMenuTimeStopComponent extends Component { | ||
|
||
private Array<Entity> freezeList; | ||
public PauseMenuTimeStopComponent() { | ||
} | ||
|
||
/** | ||
* Handles the pausing of the game entities when the pause menu is made. | ||
*/ | ||
@Override | ||
public void create() { | ||
freezeList = ServiceLocator.getEntityService().getEntities(); | ||
for (Entity pauseTarget : freezeList) { | ||
if (pauseTarget.getId() != getEntity().getId()) { | ||
// ZA WARUDO! TOKI WO TOMARE! | ||
pauseTarget.setEnabled(false); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Handles the un-pausing of the game entities when the pause menu is closed. | ||
* Also notifies the pause menu factory that the pause menu is being disposed. | ||
*/ | ||
@Override | ||
public void dispose() { | ||
PauseMenuFactory.decrementPauseMenuCount(); | ||
for (Entity pauseTarget : freezeList) { | ||
pauseTarget.setEnabled(true); | ||
} | ||
} | ||
} |
Oops, something went wrong.