Merge remote-tracking branch 'origin/UI' into UI

# Conflicts:
#	app/src/main/resources/assets/localization/localization_ka.properties
This commit is contained in:
ramollia
2025-10-06 23:26:07 +02:00
19 changed files with 98 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
package org.toop.app.layer.layers;
import javafx.application.Platform;
import org.toop.app.layer.Container;
import org.toop.app.layer.Layer;
import org.toop.app.layer.NodeBuilder;
@@ -26,12 +27,15 @@ public final class ConnectedLayer extends Layer {
this.clientId = clientId;
this.user = user;
reload();
new EventFlow().addPostEvent(new NetworkEvents.SendLogin(this.clientId, this.user)).postEvent();
new EventFlow().listen(this::handleReceivedChallenge);
new Thread(this::populatePlayerList).start();
Thread popThread = new Thread(this::populatePlayerList);
popThread.setDaemon(false);
popThread.start();
reload();
}
private void populatePlayerList() {
@@ -50,11 +54,12 @@ public final class ConnectedLayer extends Layer {
TimerTask task = new TimerTask() {
public void run() {
sendGetPlayerList.postEvent();
Platform.runLater(() -> reload());
}
};
Timer pollTimer = new Timer();
pollTimer.schedule(task, 0L, 5000L);
pollTimer.schedule(task, 0L, 5000L); // TODO: Block app exit, fix later
}
private void sendChallenge(String oppUsername, String gameType) {
@@ -75,9 +80,10 @@ public final class ConnectedLayer extends Layer {
ListView<Label> players = new ListView<>();
for (int i = 0; i < onlinePlayers.size(); i++) {
int finalI = i;
players.getItems().add(NodeBuilder.button(onlinePlayers.get(i), () -> {
// get clicked player name with: onlinePlayers.get(i)
// connection logic here
String clickedPlayer = onlinePlayers.get(finalI);
sendChallenge(clickedPlayer, "tic-tac-toe");
}));
}

View File

@@ -38,6 +38,9 @@ public final class OptionsPopup extends Popup {
final var volumeHeader = NodeBuilder.header(AppContext.getString("volume"));
final var volumeSeparator = NodeBuilder.separator();
final var fxVolumeHeader = NodeBuilder.header(AppContext.getString("fxVolume"));
final var fxVolumeSeparator = NodeBuilder.separator();
final var themeHeader = NodeBuilder.header(AppContext.getString("theme"));
final var themeSeparator = NodeBuilder.separator();
@@ -47,6 +50,7 @@ public final class OptionsPopup extends Popup {
final var optionsContainer = new VerticalContainer(5);
optionsContainer.addNodes(languageHeader, languageChoiceBox(), languageSeparator);
optionsContainer.addNodes(volumeHeader, volumeSlider(), volumeSeparator);
optionsContainer.addNodes(fxVolumeHeader, fxVolumeSlider(), fxVolumeSeparator);
optionsContainer.addNodes(themeHeader, themeChoiceBox(), themeSeparator);
optionsContainer.addNodes(layoutSizeHeader, layoutSizeChoiceBox(), layoutSizeSeparator);
optionsContainer.addNodes(fullscreenToggle());
@@ -104,6 +108,14 @@ public final class OptionsPopup extends Popup {
});
}
private Slider fxVolumeSlider() {
return NodeBuilder.slider(100, settings.getFxVolume(), (volume) -> {
settings.setFxVolume(volume);
new EventFlow().addPostEvent(new AudioEvents.ChangeFxVolume(volume.doubleValue())).asyncPostEvent();
});
}
private Label fullscreenToggle() {
return NodeBuilder.toggle(AppContext.getString("windowed"), AppContext.getString("fullscreen"), !isWindowed, (fullscreen) -> {
isWindowed = !fullscreen;

View File

@@ -75,8 +75,11 @@ public final class TicTacToeLayer extends Layer {
.addPostEvent(NetworkEvents.StartClient.class,
information.serverIP(),
Integer.parseInt(information.serverPort()))
.onResponse(NetworkEvents.StartClientResponse.class, event ->
new Thread(() -> serverGameThread(event)).start())
.onResponse(NetworkEvents.StartClientResponse.class, event -> {
Thread a = new Thread(() -> serverGameThread(event));
a.setDaemon(false);
a.start();
})
.postEvent();
}

View File

@@ -43,6 +43,7 @@ start=\u0627\u0628\u062f\u0623
theme=\u0627\u0644\u0645\u0648\u0636\u0648\u0639
tictactoe=\u062a\u064a\u0643 \u062a\u0627\u0643 \u062a\u0648
volume=\u0627\u0644\u0635\u0648\u062a
fxVolume=Fx Volume
windowed=\u0646\u0627\u0641\u0630\u064a
yes=\u0646\u0639\u0645

View File

@@ -43,6 +43,7 @@ start=Start
theme=Thema
tictactoe=Tic Tac Toe
volume=Lautst\u00e4rke
fxVolume=Fx Volume
windowed=Fenstermodus
yes=Ja

View File

@@ -43,6 +43,7 @@ start=Start
theme=Theme
tictactoe=Tic Tac Toe
volume=Volume
fxVolume=Fx Volume
windowed=Windowed
yes=Yes

View File

@@ -43,6 +43,7 @@ start=Iniciar
theme=Tema
tictactoe=Tres en Raya
volume=Volumen
fxVolume=Fx Volume
windowed=Ventana
yes=S\u00ed

View File

@@ -43,6 +43,7 @@ start=D\u00e9marrer
theme=Th\u00E8me
tictactoe=Morpion
volume=Volume
fxVolume=Fx Volume
windowed=Fen\u00eatre
yes=Oui

View File

@@ -44,6 +44,7 @@ start=\u092b\u093f\u0930\u0942
theme=\u0925\u0940\u092E
tictactoe=\u091f\u093f\u0915 \u091f\u0948\u0915 \u091f\u094b
volume=\u0935\u0949\u0932\u094d\u092f\u0947\u092e
fxVolume=Fx Volume
windowed=\u0915\u094d\u0930\u094d\u0939 \u092e\u0947\u0902
yes=\u0939\u093e\u0907

View File

@@ -43,6 +43,7 @@ start=Inizia
theme=Tema
tictactoe=Tic Tac Toe
volume=Volume
fxVolume=Fx Volume
windowed=Finestra
yes=S\u00ec

View File

@@ -43,6 +43,7 @@ start=\u59cb\u307e\u308a
theme=\u30C6\u30FC\u30DE
tictactoe=\u30bf\u30a4\u30af\u30bf\u30c3\u30c8\u30c8\u30a6
volume=\u30dc\u30ea\u30e5\u30fc\u30e0
fxVolume=Fx Volume
windowed=\u30a6\u30a3\u30f3\u30c9\u30a6
yes=\u306f\u3044

View File

@@ -43,6 +43,7 @@ start=\uc2dc\uc791
theme=\uC8FC\uC81C
tictactoe=\ud2f0\ud06c\ud0d0\ud1a0
volume=\ubcf4\ub7ec\uc6b4
fxVolume=Fx Volume
windowed=\ucc3d \ubaa8\ub4dc
yes=\ub124

View File

@@ -43,6 +43,7 @@ start=Start
theme=Thema
tictactoe=Boter Kaas en Eieren
volume=Volume
fxVolume=Fx Volume
windowed=Venstermodus
yes=Ja

View File

@@ -43,6 +43,7 @@ start=\u0421\u0442\u0430\u0440\u0442
theme=\u0442\u0435\u043C\u0430
tictactoe=\u041a\u0440\u0435\u0441\u0442\u0438\u043a\u0438
volume=\u0413\u0440\u0430\u043c\u043c\u043e\u0444\u043e\u043d
fxVolume=Fx Volume
windowed=\u041e\u043a\u043d\u043e
yes=\u0414\u0430

View File

@@ -43,6 +43,7 @@ start=\u5f00\u59cb
theme=\u4E3B\u9898
tictactoe=Tic Tac Toe
volume=\u97f3\u91cf
fxVolume=Fx Volume
windowed=\u7a97\u53e3\u6a21\u5f0f
yes=\u662f

View File

@@ -16,6 +16,10 @@ public class SettingsAsset extends JsonAsset<Settings> {
return getContent().volume;
}
public int getFxVolume() {
return getContent().fxVolume;
}
public Locale getLocale() {
return Locale.forLanguageTag(getContent().locale);
}
@@ -37,6 +41,11 @@ public class SettingsAsset extends JsonAsset<Settings> {
save();
}
public void setFxVolume(int fxVolume) {
getContent().fxVolume = fxVolume;
save();
}
public void setLocale(String locale) {
getContent().locale = locale;
save();

View File

@@ -25,6 +25,7 @@ public class SoundManager {
private final SnowflakeGenerator idGenerator = new SnowflakeGenerator(); // TODO: Don't create a new generator
private double volume = 1.0;
private double fxVolume = 1.0;
public SoundManager() {
// Get all Audio Resources and add them to a list.
@@ -40,7 +41,9 @@ public class SoundManager {
.listen(this::handleStopSound)
.listen(this::handleMusicStart)
.listen(this::handleVolumeChange)
.listen(this::handleFxVolumeChange)
.listen(this::handleGetCurrentVolume)
.listen(this::handleGetCurrentFxVolume)
.listen(AudioEvents.ClickButton.class, _ -> {
try {
playSound("medium-button-click.wav", false);
@@ -68,13 +71,20 @@ public class SoundManager {
this.audioResources.put(audioAsset.getName(), audioAsset.getResource());
}
private double limitVolume(double volume) {
if (volume > 1.0) return 1.0;
else return Math.max(volume, 0.0);
}
private void handleVolumeChange(AudioEvents.ChangeVolume event) {
double newVolume = event.newVolume() / 100;
if (newVolume > 1.0) this.volume = 1.0;
else this.volume = Math.max(newVolume, 0.0);
this.volume = limitVolume(event.newVolume() / 100);
for (MediaPlayer mediaPlayer : this.activeMusic) {
mediaPlayer.setVolume(this.volume);
}
}
private void handleFxVolumeChange(AudioEvents.ChangeFxVolume event) {
this.fxVolume = limitVolume(event.newVolume() / 100);
for (Clip clip : this.activeSoundEffects.values()){
updateClipVolume(clip);
}
@@ -85,14 +95,19 @@ public class SoundManager {
FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
float min = volumeControl.getMinimum();
float max = volumeControl.getMaximum();
float dB = (float) (Math.log10(Math.max(volume, 0.0001)) * 20.0); // convert linear to dB
float dB = (float) (Math.log10(Math.max(fxVolume, 0.0001)) * 20.0); // convert linear to dB
dB = Math.max(min, Math.min(max, dB));
volumeControl.setValue(dB);
}
}
private void handleGetCurrentVolume(AudioEvents.GetCurrentVolume event) {
new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeReponse(volume * 100, event.snowflakeId()))
new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeResponse(volume * 100, event.snowflakeId()))
.asyncPostEvent();
}
private void handleGetCurrentFxVolume(AudioEvents.GetCurrentFxVolume event) {
new EventFlow().addPostEvent(new AudioEvents.GetCurrentFxVolumeResponse(fxVolume * 100, event.snowflakeId()))
.asyncPostEvent();
}

View File

@@ -15,6 +15,7 @@ public class AudioEvents extends EventsBase {
public record StartBackgroundMusic() implements EventWithoutSnowflake {}
public record ChangeVolume(double newVolume) implements EventWithoutSnowflake {}
public record ChangeFxVolume(double newVolume) implements EventWithoutSnowflake {}
public record GetCurrentVolume(long snowflakeId) implements EventWithSnowflake {
@Override
public Map<String, Object> result() {
@@ -26,7 +27,7 @@ public class AudioEvents extends EventsBase {
return snowflakeId;
}
}
public record GetCurrentVolumeReponse(double currentVolume, long snowflakeId) implements EventWithSnowflake {
public record GetCurrentVolumeResponse(double currentVolume, long snowflakeId) implements EventWithSnowflake {
@Override
public Map<String, Object> result() {
return Map.of();
@@ -37,5 +38,30 @@ public class AudioEvents extends EventsBase {
return snowflakeId;
}
}
public record GetCurrentFxVolume(long snowflakeId) implements EventWithSnowflake {
@Override
public Map<String, Object> result() {
return Map.of();
}
@Override
public long eventSnowflake() {
return this.snowflakeId;
}
}
public record GetCurrentFxVolumeResponse(double currentVolume, long snowflakeId) implements EventWithSnowflake {
@Override
public Map<String, Object> result() {
return Map.of();
}
@Override
public long eventSnowflake() {
return this.snowflakeId;
}
}
public record ClickButton() implements EventWithoutSnowflake {}
}

View File

@@ -6,4 +6,5 @@ public class Settings {
public String theme = "dark";
public String layoutSize = "medium";
public int volume = 15;
public int fxVolume = 20;
}