diff --git a/assets/assets.txt b/assets/assets.txt index aa5bf10..2382ea9 100644 --- a/assets/assets.txt +++ b/assets/assets.txt @@ -3,3 +3,4 @@ fonts/Orbitron-Regular.ttf fonts/Oswald-Regular.ttf libgdx.png logo.png +settingsicon.png diff --git a/assets/settingsicon.png b/assets/settingsicon.png new file mode 100644 index 0000000..91f7101 Binary files /dev/null and b/assets/settingsicon.png differ diff --git a/core/src/main/java/group07/beatbattle/ui/components/SettingsButton.java b/core/src/main/java/group07/beatbattle/ui/components/SettingsButton.java new file mode 100644 index 0000000..270a6d9 --- /dev/null +++ b/core/src/main/java/group07/beatbattle/ui/components/SettingsButton.java @@ -0,0 +1,29 @@ +package group07.beatbattle.ui.components; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; + +public class SettingsButton extends ImageButton { + + public SettingsButton() { + super(createStyle()); + + getImage().setScaling(com.badlogic.gdx.utils.Scaling.fit); + } + + private static ImageButtonStyle createStyle() { + + Texture texture = new Texture(Gdx.files.internal("settingsicon.png")); + TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture)); + + ImageButtonStyle style = new ImageButtonStyle(); + style.imageUp = drawable; + + return style; + } + + +} diff --git a/core/src/main/java/group07/beatbattle/ui/components/StartGameButton.java b/core/src/main/java/group07/beatbattle/ui/components/StartGameButton.java new file mode 100644 index 0000000..276c56c --- /dev/null +++ b/core/src/main/java/group07/beatbattle/ui/components/StartGameButton.java @@ -0,0 +1,48 @@ +package group07.beatbattle.ui.components; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; + +public class StartGameButton extends TextButton { + + private static Texture sharedTexture; + + private static TextButtonStyle createStyle(BitmapFont font) { + Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); + + pixmap.setColor(0.23f, 0.23f, 0.34f, 1f); + pixmap.fill(); + + Texture texture = new Texture(pixmap); + pixmap.dispose(); + + TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture)); + + TextButtonStyle style = new TextButtonStyle(); + style.up = drawable; + style.down = drawable; + style.font = font; + style.fontColor = Color.WHITE; + + return style; + } + + public StartGameButton(BitmapFont font) { + super("Start Game", createStyle(font)); + + pad(40f, 80f, 40f, 80f); + } + + public static void disposeSharedResources() { + if (sharedTexture != null) { + sharedTexture.dispose(); + sharedTexture = null; + } + } + +} diff --git a/core/src/main/java/group07/beatbattle/view/LobbyView.java b/core/src/main/java/group07/beatbattle/view/LobbyView.java index a543e88..fac418a 100644 --- a/core/src/main/java/group07/beatbattle/view/LobbyView.java +++ b/core/src/main/java/group07/beatbattle/view/LobbyView.java @@ -1,21 +1,27 @@ package group07.beatbattle.view; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.ScreenAdapter; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Stage; -import com.badlogic.gdx.scenes.scene2d.ui.Label; -import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.*; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.badlogic.gdx.scenes.scene2d.utils.Drawable; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; +import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.viewport.ScreenViewport; import group07.beatbattle.BeatBattle; import group07.beatbattle.controller.LobbyController; import group07.beatbattle.model.GameMode; import group07.beatbattle.ui.components.BackButton; -import group07.beatbattle.ui.components.JoinCreateButton; +import group07.beatbattle.ui.components.SettingsButton; +import group07.beatbattle.ui.components.StartGameButton; public class LobbyView extends ScreenAdapter { @@ -28,6 +34,9 @@ public class LobbyView extends ScreenAdapter { private final String gamePin; private final String hostName; + private Label.LabelStyle infoStyle; + private Label.LabelStyle titleStyle; + public LobbyView(BeatBattle game, GameMode mode, LobbyController controller) { this(game, mode, "", "", "", controller); } @@ -41,23 +50,34 @@ public LobbyView(BeatBattle game, GameMode mode, String sessionId, String gamePi this.gamePin = gamePin; this.hostName = hostName; - Label.LabelStyle titleStyle = new Label.LabelStyle(); + // Styles + titleStyle = new Label.LabelStyle(); titleStyle.font = game.getOrbitronFont(); titleStyle.fontColor = Color.WHITE; - Label.LabelStyle infoStyle = new Label.LabelStyle(); + infoStyle = new Label.LabelStyle(); infoStyle.font = game.getMontserratFont(); infoStyle.fontColor = Color.WHITE; - Label title = new Label("Lobby", titleStyle); + Table root = new Table(); + root.setFillParent(true); - String pinText = gamePin.isEmpty() ? "Game Code: ----" : "Game Code: " + gamePin; - Label pinLabel = new Label(pinText, infoStyle); + root.top(); + root.add(createHeader()).expandX().fillX().padTop(20).row(); + root.add(createGameCodeSection()).expandX().top().padTop(60).row(); + root.add(createPartySection()).expand().center().padBottom(60).row(); + root.add(createFooter()).expandX().bottom().padBottom(40); - String hostText = hostName.isEmpty() ? "Host: -" : "Host: " + hostName; - Label hostLabel = new Label(hostText, infoStyle); + stage.addActor(root); + } + + private Table createHeader() { + Table header = new Table(); + + BackButton backButton = + new BackButton("Back", game.getMontserratFont()); - BackButton backButton = new BackButton("Back", game.getMontserratFont()); + SettingsButton settingsButton = new SettingsButton(); backButton.addListener(new ChangeListener() { @Override @@ -66,27 +86,127 @@ public void changed(ChangeEvent event, Actor actor) { } }); - JoinCreateButton startButton = - new JoinCreateButton("Start Game", game.getMontserratFont()); - - startButton.addListener(new ChangeListener() { + settingsButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { - controller.onStartGame(); + game.setScreen(new SettingsView(game, mode)); } }); - Table root = new Table(); - root.setFillParent(true); - root.center(); + header.add(backButton) + .width(200) + .height(100) + .expandX() + .left() + .padLeft(20); - root.add(title).padBottom(80).row(); - root.add(pinLabel).padBottom(25).row(); - root.add(hostLabel).padBottom(50).row(); - root.add(startButton).width(700).height(150).padBottom(40).row(); - root.add(backButton).width(500).height(120); + header.add(settingsButton) + .size(80) + .right() + .padRight(20); - stage.addActor(root); + return header; + } + + private Table createGameCodeSection() { + Table table = new Table(); + + String pinText = gamePin.isEmpty() ? "Game Code: ----" : "Game Code: " + gamePin; + + Label label = new Label("Gamecode", infoStyle); + label.setColor(Color.LIGHT_GRAY); + + Label value = new Label(pinText, titleStyle); + + table.add(label).padBottom(5).row(); + table.add(value); + + return table; + } + + private Table createPartySection() { + Table table = new Table(); + table.center(); + + Label partyLabel = new Label("Party", infoStyle); + Table partyBox = createPartyBox(); + + table.add(partyLabel).padBottom(20).row(); + table.add(partyBox) + .width(850) + .height(620); + + return table; + } + + private Table createPartyBox() { + int boxWidth = 850; + int boxHeight = 620; + int radius = 60; + + Table container = new Table(); + container.setBackground(createRoundedBackground(boxWidth, boxHeight, radius)); + + Table grid = new Table(); + + float cellWidth = 260f; + float cellHeight = 60f; + + grid.add(createPlayerLabel("Oda")).width(cellWidth).height(cellHeight).pad(15); + grid.add(createPlayerLabel("Lea")).width(cellWidth).height(cellHeight).pad(15).row(); + + grid.add(createPlayerLabel("Milos")).width(cellWidth).height(cellHeight).pad(15); + grid.add(createPlayerLabel("Karya")).width(cellWidth).height(cellHeight).pad(15); + + container.add(grid).pad(60); + + return container; + } + + private Label createPlayerLabel(String name) { + Label label = new Label(name, infoStyle); + label.setAlignment(Align.center); + return label; + } + + private Drawable createRoundedBackground(int width, int height, int radius) { + Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888); + pixmap.setColor(0.25f, 0.25f, 0.35f, 1f); + + pixmap.fillRectangle(radius, 0, width - 2 * radius, height); + pixmap.fillRectangle(0, radius, width, height - 2 * radius); + + pixmap.fillCircle(radius, radius, radius); + pixmap.fillCircle(width - radius, radius, radius); + pixmap.fillCircle(radius, height - radius, radius); + pixmap.fillCircle(width - radius, height - radius, radius); + + Texture texture = new Texture(pixmap); + pixmap.dispose(); + + return new TextureRegionDrawable(new TextureRegion(texture)); + } + + private Table createFooter() { + Table footer = new Table(); + + if (mode == GameMode.CREATE) { + StartGameButton startButton = + new StartGameButton(game.getMontserratFont()); + + startButton.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + controller.onStartGame(); + } + }); + + footer.add(startButton) + .width(800) + .height(150); + } + + return footer; } public String getSessionId() { diff --git a/core/src/main/java/group07/beatbattle/view/SettingsView.java b/core/src/main/java/group07/beatbattle/view/SettingsView.java index 34dabe1..919674c 100644 --- a/core/src/main/java/group07/beatbattle/view/SettingsView.java +++ b/core/src/main/java/group07/beatbattle/view/SettingsView.java @@ -1,4 +1,35 @@ package group07.beatbattle.view; -public class SettingsView { +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.ScreenAdapter; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.utils.viewport.ScreenViewport; + +import group07.beatbattle.BeatBattle; +import group07.beatbattle.model.GameMode; + +public class SettingsView extends ScreenAdapter { + + private final BeatBattle game; + private final GameMode mode; + private final Stage stage; + + public SettingsView(BeatBattle game, GameMode mode) { + this.game = game; + this.mode = mode; + this.stage = new Stage(new ScreenViewport()); + } + + @Override + public void show() { + Gdx.input.setInputProcessor(stage); + } + + @Override + public void render(float delta) { + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + stage.act(delta); + stage.draw(); + } }