Skip to content

19 settings screen #38

Merged
merged 5 commits into from
Apr 10, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,79 @@
package group07.beatbattle.controller;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import group07.beatbattle.BeatBattle;
import group07.beatbattle.model.GameMode;
import group07.beatbattle.view.LobbyView;

public class SettingsController {

private final BeatBattle game;
private final GameMode mode;
private final String sessionId;
private final String gamePin;
private final String playerId;
private final String displayName;
private final boolean isHost;

public SettingsController(BeatBattle game) {
private String language;
private int turns;
private final Preferences prefs;


public SettingsController(
BeatBattle game,
GameMode mode,
String sessionId,
String gamePin,
String playerId,
String displayName,
boolean isHost
) {
this.game = game;
this.mode = mode;
this.sessionId = sessionId;
this.gamePin = gamePin;
this.playerId = playerId;
this.displayName = displayName;
this.isHost = isHost;

this.prefs = Gdx.app.getPreferences("settings");
this.language = prefs.getString("language", "EN");
}

public String getLanguage() {
return language;
}

public void onLanguageChanged(String language) {
this.language = language;
Gdx.app.log("Settings", "Language changed to: " + language);
}

public void onTurnsChanged(int turns) {
this.turns = turns;
}

// TODO: onLanguageChanged(String language)
// TODO: onTurnsChanged(int turns)
// TODO: onApply()
// TODO: onBack()
public void onApply() {
prefs.putString("language", language);
prefs.putInteger("turns", turns);
prefs.flush();
Gdx.app.log("Settings", "Settings saved");
onBack();
}

public void onBack() {
Gdx.app.log("Settings", "Back pressed");
game.setScreen(new LobbyView(
game,
mode,
sessionId,
gamePin,
playerId,
displayName,
isHost,
new LobbyController(game)
));
}
}
32 changes: 26 additions & 6 deletions core/src/main/java/group07/beatbattle/states/SettingsState.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
package group07.beatbattle.states;

import group07.beatbattle.BeatBattle;
import group07.beatbattle.controller.SettingsController;
import group07.beatbattle.model.GameMode;
import group07.beatbattle.view.SettingsView;


public class SettingsState extends State {

private final SettingsController settingsController;
private final SettingsView view;

public SettingsState(BeatBattle game, SettingsController settingsController) {
public SettingsState(
BeatBattle game,
GameMode mode,
String sessionId,
String gamePin,
String playerId,
String displayName,
boolean isHost
) {
super(game);
this.settingsController = settingsController;
this.view = new SettingsView(
game,
mode,
sessionId,
gamePin,
playerId,
displayName,
isHost
);
}

@Override
public void enter() {
// TODO: game.setScreen(new SettingsView(game, settingsController));
game.setScreen(view);
}

@Override
public void exit() {}
public void exit() {

}
}
Original file line number Diff line number Diff line change
@@ -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 ApplyButton 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); // same as StartGameButton
pixmap.fill();

sharedTexture = new Texture(pixmap);
pixmap.dispose();

TextureRegionDrawable drawable =
new TextureRegionDrawable(new TextureRegion(sharedTexture));

TextButtonStyle style = new TextButtonStyle();
style.up = drawable;
style.down = drawable;
style.font = font;
style.fontColor = Color.WHITE;

return style;
}

public ApplyButton(BitmapFont font) {
super("Apply", createStyle(font));

pad(40f, 80f, 40f, 80f);
}

public static void disposeSharedResources() {
if (sharedTexture != null) {
sharedTexture.dispose();
sharedTexture = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
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.Actor;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
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.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;

public class LanguageSelector {

private static final String DEFAULT_LANGUAGE = "EN";
private static final int VISIBLE_ROWS_HEIGHT = 200;
private static final float FIELD_HEIGHT = 96f;

private static Texture fieldBg;
private static Texture popupBg;
private static Texture selectionBg;
private static Texture scrollTrackBg;
private static Texture scrollKnobBg;

private final Table root;
private final TextButton valueButton;
private final List<String> list;
private final ScrollPane scrollPane;
private final Table popupContainer;

private boolean popupOpen = false;
private String selectedLanguage = DEFAULT_LANGUAGE;

public LanguageSelector(BitmapFont font, String initialLanguage) {
this.root = new Table();

ensureTextures();

Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = font;
labelStyle.fontColor = Color.LIGHT_GRAY;

Label label = new Label("Language", labelStyle);
label.setAlignment(Align.left);

TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle();
buttonStyle.up = new TextureRegionDrawable(new TextureRegion(fieldBg));
buttonStyle.down = new TextureRegionDrawable(new TextureRegion(selectionBg));
buttonStyle.over = new TextureRegionDrawable(new TextureRegion(selectionBg));
buttonStyle.font = font;
buttonStyle.fontColor = Color.WHITE;

this.selectedLanguage = initialLanguage;
this.valueButton = new TextButton(initialLanguage, buttonStyle);
this.valueButton.getLabel().setAlignment(Align.center);

List.ListStyle listStyle = new List.ListStyle();
listStyle.font = font;
listStyle.fontColorUnselected = Color.LIGHT_GRAY;
listStyle.fontColorSelected = Color.WHITE;
listStyle.background = new TextureRegionDrawable(new TextureRegion(popupBg));
listStyle.selection = new TextureRegionDrawable(new TextureRegion(selectionBg));

this.list = new List<>(listStyle);
this.list.setItems("EN", "NO");
this.list.setSelected(initialLanguage);

ScrollPane.ScrollPaneStyle scrollStyle = new ScrollPane.ScrollPaneStyle();
scrollStyle.background = new TextureRegionDrawable(new TextureRegion(popupBg));
scrollStyle.vScroll = new TextureRegionDrawable(new TextureRegion(scrollTrackBg));
scrollStyle.vScrollKnob = new TextureRegionDrawable(new TextureRegion(scrollKnobBg));

this.scrollPane = new ScrollPane(list, scrollStyle);
this.scrollPane.setScrollingDisabled(true, false);
this.scrollPane.setFadeScrollBars(false);

this.popupContainer = new Table();
this.popupContainer.setVisible(false);
this.popupContainer.setTouchable(Touchable.disabled);

valueButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
setPopupOpen(!popupOpen);
}
});

list.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
String sel = list.getSelected();
if (sel != null) {
selectedLanguage = sel;
valueButton.setText(sel);
}
setPopupOpen(false);
}
});

root.add(label).left().padBottom(8f).row();
root.add(valueButton).expandX().fillX().height(FIELD_HEIGHT).row();

popupContainer.add(scrollPane).expandX().fillX().height(VISIBLE_ROWS_HEIGHT);
root.add(popupContainer).expandX().fillX().padTop(8f).row();
}

public Actor getActor() {
return root;
}

public String getSelectedLanguage() {
return selectedLanguage;
}

private void setPopupOpen(boolean open) {
popupOpen = open;
popupContainer.setVisible(open);
popupContainer.setTouchable(open ? Touchable.enabled : Touchable.disabled);
if (open) {
scrollPane.layout();
scrollPane.setScrollPercentY(0f);
}
}

private static void ensureTextures() {
if (fieldBg == null) {
Pixmap p = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
p.setColor(0.16f, 0.16f, 0.24f, 1f);
p.fill();
fieldBg = new Texture(p);
p.dispose();
}
if (popupBg == null) {
Pixmap p = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
p.setColor(0.12f, 0.12f, 0.18f, 1f);
p.fill();
popupBg = new Texture(p);
p.dispose();
}
if (selectionBg == null) {
Pixmap p = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
p.setColor(0.30f, 0.30f, 0.55f, 1f);
p.fill();
selectionBg = new Texture(p);
p.dispose();
}
if (scrollTrackBg == null) {
Pixmap p = new Pixmap(14, 14, Pixmap.Format.RGBA8888);
p.setColor(0.20f, 0.20f, 0.28f, 1f);
p.fill();
scrollTrackBg = new Texture(p);
p.dispose();
}
if (scrollKnobBg == null) {
Pixmap p = new Pixmap(14, 14, Pixmap.Format.RGBA8888);
p.setColor(0.75f, 0.75f, 0.88f, 1f);
p.fill();
scrollKnobBg = new Texture(p);
p.dispose();
}
}
}
Loading
Loading