Skip to content

Commit

Permalink
Add setting to enable/disable audio output
Browse files Browse the repository at this point in the history
This is useful when playing multiple games on the same host to have
audio only played once. To fit this on the home screen, I shifted the
graphics settings up by a bit.
  • Loading branch information
StenAL committed May 29, 2024
1 parent 7d67b17 commit a64bc49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
38 changes: 26 additions & 12 deletions client/src/main/java/agolf/LobbySelectPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.awt.Color;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand All @@ -34,6 +33,7 @@ public class LobbySelectPanel extends Panel implements ActionListener, MouseList
private ColorButton buttonQuit;
private ColorCheckbox checkboxPlayHidden;
private Choicer choicerGraphics;
private Choicer audioChoicer;
private int[] lobbyNumPlayers;
private LobbySelectRNOPspammer lobbySelectRNOP;
private static final String[] aStringArray544 = new String[22];
Expand Down Expand Up @@ -139,7 +139,12 @@ else if (evtSource == this.buttonDual) {
}

public void itemStateChanged(ItemEvent evt) {
this.gameContainer.graphicsQualityIndex = this.choicerGraphics.getSelectedIndex();
Object source = evt.getSource();
if (source == this.choicerGraphics) {
this.gameContainer.graphicsQualityIndex = this.choicerGraphics.getSelectedIndex();
} else if (source == this.audioChoicer) {
this.gameContainer.soundManager.audioChoicerIndex = this.audioChoicer.getSelectedIndex();
}
}

public static String getLobbySelectMessage(int lobbyId) {
Expand Down Expand Up @@ -209,7 +214,7 @@ protected void writeData(String var1) {
}

private void create() {
this.setLayout((LayoutManager) null);
this.setLayout(null);
this.checkboxPlayHidden = new ColorCheckbox(this.gameContainer.textManager.getGame("LobbySelect_PlayHidden"));
this.checkboxPlayHidden.setBounds(this.width / 6 - 75 - 10, this.height - 124, 220, 18);
this.checkboxPlayHidden.setBackground(GameApplet.colourGameBackground);
Expand All @@ -226,34 +231,43 @@ private void create() {
this.add(this.buttonSingleQuick);
}



//this.buttonDual = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_DualPlayer"));
this.buttonDual = new ColorButton("Coming soon...");
this.buttonDual.setBounds(this.width * 3 / 6 - 75, this.height - 150, 150, 25);
//this.buttonDual.addActionListener(this);
this.add(this.buttonDual);


this.buttonMulti = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_MultiPlayer"));
this.buttonMulti.setBounds(this.width * 5 / 6 - 75, this.height - 150, 150, 25);
this.buttonMulti.addActionListener(this);
this.add(this.buttonMulti);

this.buttonMultiQuick = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_QuickStart"));
this.buttonMultiQuick.setBackground(GameApplet.colourButtonBlue);
this.buttonMultiQuick.setBounds(this.width * 5 / 6 - 50, this.height - 95, 100, 20);
this.buttonMultiQuick.addActionListener(this);
this.add(this.buttonMultiQuick);
String text = this.gameContainer.textManager.getGame("LobbySelect_Gfx");

String graphicsOptionText = this.gameContainer.textManager.getGame("LobbySelect_Gfx");
this.choicerGraphics = new Choicer();
this.choicerGraphics.addItem(text + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx0"));
this.choicerGraphics.addItem(text + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx1"));
this.choicerGraphics.addItem(text + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx2"));
this.choicerGraphics.addItem(text + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx3"));
this.choicerGraphics.addItem(graphicsOptionText + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx0"));
this.choicerGraphics.addItem(graphicsOptionText + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx1"));
this.choicerGraphics.addItem(graphicsOptionText + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx2"));
this.choicerGraphics.addItem(graphicsOptionText + " " + this.gameContainer.textManager.getGame("LobbySelect_Gfx3"));
this.choicerGraphics.select(this.gameContainer.graphicsQualityIndex);
this.choicerGraphics.setBounds(this.width / 3 - 100, this.height - 10 - 20, 200, 20);
this.choicerGraphics.setBounds(this.width / 3 - 100, this.height - 10 - 50, 200, 20);
this.choicerGraphics.addItemListener(this);
this.add(this.choicerGraphics);

String audioOptionsText = "Audio:";
this.audioChoicer = new Choicer();
this.audioChoicer.addItem(audioOptionsText + " On");
this.audioChoicer.addItem(audioOptionsText + " Off");
this.audioChoicer.select(this.gameContainer.soundManager.audioChoicerIndex);
this.audioChoicer.setBounds(this.width / 3 - 100, this.height - 10 - 20, 200, 20);
this.audioChoicer.addItemListener(this);
this.add(this.audioChoicer);

this.buttonQuit = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_Quit"));
this.buttonQuit.setBackground(GameApplet.colourButtonRed);
this.buttonQuit.setBounds(this.width * 2 / 3 - 50, this.height - 10 - 20, 100, 20);
Expand Down
4 changes: 3 additions & 1 deletion client/src/main/java/com/aapeli/client/SoundManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class SoundManager implements Runnable {
private Hashtable<Integer, SoundClip> clientSounds;
private Hashtable<String, SoundClip> sharedSounds;
private boolean clipLoaderThreadRunning;
public int audioChoicerIndex;


public SoundManager(AApplet applet) {
Expand All @@ -33,6 +34,7 @@ public SoundManager(AApplet applet, boolean loadClipsOnRegister, boolean debug)
this.applet = applet;
this.loadSoundClipsOnRegister = loadClipsOnRegister;
this.debug = debug;
this.audioChoicerIndex = 0;
this.loadClientSounds();
this.sharedSoundDir = this.getClass().getResource("/sound/shared/");

Expand Down Expand Up @@ -231,7 +233,7 @@ private synchronized void loadAllSoundClips() {

private void playAudioClip(int id) {
SoundClip soundClip = this.clientSounds.get(new Integer(id));
if (soundClip != null) {
if (soundClip != null && this.audioChoicerIndex != 1) {
AudioClip audioClip = soundClip.getAudioClip();
if (audioClip != null) {
audioClip.play();
Expand Down

0 comments on commit a64bc49

Please sign in to comment.