From: Frederick W. <fre...@us...> - 2012-01-31 13:56:50
|
LocalisedText.properties | 2 ++ data/Properties.xml | 1 + rails/game/GameManager.java | 4 ++++ rails/game/GameManagerI.java | 2 ++ rails/sound/SoundConfig.java | 1 + rails/sound/SoundEventInterpreter.java | 29 +++++++++++++++++++++++++++-- 6 files changed, 37 insertions(+), 2 deletions(-) New commits: commit 98248e796b9dfdcf8565f6395e46207051ccc8ca Author: Frederick Weld <fre...@gm...> Date: Tue Jan 31 14:52:02 2012 +0100 Added new sfx option (change of current player - player-dependent sfx) Users are able to define in the config window a sound on a per player basis and a default sound (for players that do not have any associated sounds). diff --git a/LocalisedText.properties b/LocalisedText.properties index 956079e..b8ff06d 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -177,6 +177,7 @@ Config.infoText.sound.backgroundMusic=The only music file type supported is mp3. Config.infoText.sound.backgroundMusic.stockRound=<html>Enter assignment of music files to phases.<ul><li>Separate the assignments by commas.<li>Each assignment has the syntax phaseName=complete file path<li>Default music is defined by omitting "phaseName=" in the assignment.</ul><strong>Examples:</strong><ul><li>Set default music: <br><code>c:\SR-default.mp3</code><li>Set phase-dependent music and a default (for trains above 6): <br><code>2=c:\SR-2.mp3,3=c:\SR-3.mp3,4=c:\SR-4.mp3,5=c:\SR-5.mp3,6=c:\SR-6.mp3,c:\SR-D.mp3</code></ul> </html> Config.infoText.sound.backgroundMusic.operatingRound=<html>Enter assignment of music files to phases.<ul><li>Separate the assignments by commas.<li>Each assignment has the syntax phaseName=complete file path<li>Default music is defined by omitting "phaseName=" in the assignment.</ul><strong>Examples:</strong><ul><li>Set default music: <br><code>c:\OR-default.mp3</code><li>Set phase-dependent music and a default (for trains above 6): <br><code>2=c:\OR-2.mp3,3=c:\OR-3.mp3,4=c:\OR-4.mp3,5=c:\OR-5.mp3,6=c:\OR-6.mp3,c:\OR-D.mp3</code></ul> </html> Config.infoText.sound.sfx=The only sound effects file type supported is mp3. +Config.infoText.sound.sfx.gen.newCurrentPlayer=<html>Enter assignment of sound effect files to player names.<br>The assigned sound is played if the player becomes the active one - meaning, the user interface is responsive for this player's commands.<ul><li>Separate the assignments by commas.<li>Each assignment has the syntax playerName=complete file path<li>Default sound effect is defined by omitting "playerName=" in the assignment.</ul><strong>Examples:</strong><ul><li>Set default sound effect: <br><code>c:\ChangeActivePlayer.mp3</code><li>Set player-dependent sound effect and a default (for all other players): <br><code>Tom=c:\ChangeActivePlayer_Tom.mp3,Sarah=c:\ChangeActivePlayer_Sarah.mp3,c:\ChangeActivePlayer_default.mp3</code></ul> </html> Config.infoText.sound.sfx.or.buyTrain=<html>Enter assignment of sound effect files to train types.<ul><li>Separate the assignments by commas.<li>Each assignment has the syntax trainName=complete file path<li>Default sound effect is defined by omitting "trainName=" in the assignment.</ul><strong>Examples:</strong><ul><li>Set default sound effect: <br><code>c:\BuyTrain-default.mp3</code><li>Set train-dependent sound effect and a default (for trains above 6): <br><code>2=c:\BuyTrain-2.mp3,3=c:\BuyTrain-3.mp3,4=c:\BuyTrain-4.mp3,5=c:\BuyTrain-5.mp3,6=c:\BuyTrain-6.mp3,c:\BuyTrain-D.mp3</code></ul> </html> Config.infoText.sound.sfx.or.setRevenue=<html><ul><li>Only the latter portion of this file is played.<ul><li>For an average revenue, the last third is played.</ul><li>The higher the company's revenue the longer this file is played.<ul><li>But the file is at most played once as a whole.</li></ul></html> Config.infoText.sound.sfx.sr.newPresident=This also includes becoming the president when buying the president share. @@ -213,6 +214,7 @@ Config.label.sound.backgroundMusic.startRound=Start Round Config.label.sound.backgroundMusic.stockRound=Stock Round (several files) Config.label.sound.backgroundMusic.operatingRound=Operating Round (several files) Config.label.sound.sfx=Sound Effects +Config.label.sound.sfx.gen.newCurrentPlayer=Change of active player Config.label.sound.sfx.gen.pass=Pass Config.label.sound.sfx.gen.select=Select (hexes, click fields) Config.label.sound.sfx.str.bidStartItem=Bid on Start Item diff --git a/data/Properties.xml b/data/Properties.xml index 43e64c2..a5b1e51 100644 --- a/data/Properties.xml +++ b/data/Properties.xml @@ -75,6 +75,7 @@ <Property name="sound.sfx" type="LIST" values="disabled,enabled" /> <Property name="sound.sfx.gen.pass" type="FILE" /> <Property name="sound.sfx.gen.select" type="FILE" /> + <Property name="sound.sfx.gen.newCurrentPlayer" type="STRING" /> <Property name="sound.sfx.str.bidStartItem" type="FILE" /> <Property name="sound.sfx.str.buyStartItem" type="FILE" /> <Property name="sound.sfx.sr.openingBell" type="FILE" /> diff --git a/rails/sound/SoundConfig.java b/rails/sound/SoundConfig.java index 2cb1dc0..4e86877 100644 --- a/rails/sound/SoundConfig.java +++ b/rails/sound/SoundConfig.java @@ -26,6 +26,7 @@ public class SoundConfig { public static final String KEY_SFX_Enabled = "sound.sfx"; public static final String KEY_SFX_GEN_Pass = "sound.sfx.gen.pass"; public static final String KEY_SFX_GEN_Select = "sound.sfx.gen.select"; + public static final String KEY_SFX_GEN_NewCurrentPlayer = "sound.sfx.gen.newCurrentPlayer"; public static final String KEY_SFX_STR_BidStartItem = "sound.sfx.str.bidStartItem"; public static final String KEY_SFX_STR_BuyStartItem = "sound.sfx.str.buyStartItem"; public static final String KEY_SFX_SR_OpeningBell = "sound.sfx.sr.openingBell"; diff --git a/rails/sound/SoundEventInterpreter.java b/rails/sound/SoundEventInterpreter.java index 28dfe13..ac6e640 100644 --- a/rails/sound/SoundEventInterpreter.java +++ b/rails/sound/SoundEventInterpreter.java @@ -11,15 +11,34 @@ import rails.ui.swing.ORUIManager; /** * Converts processed actions and model updates to triggers for playing sounds. * - * Model observers get their own inner classes since their constructors are parameterized + * Some model observers get their own inner classes since their constructors are parameterized * (needed to initialize member variables among others - especially important if game is - * loaded). + * loaded since game status will not be initial upon initialization of the sound framework). * * @author Frederick Weld * */ public class SoundEventInterpreter { + private class CurrentPlayerModelObserver implements Observer { + private Player formerCurrentPlayer = null; + private GameManagerI gm; + public CurrentPlayerModelObserver(GameManagerI gm) { + this.gm = gm; + if (gm != null) formerCurrentPlayer = gm.getCurrentPlayer(); + } + public void update(Observable o, Object arg) { + if (formerCurrentPlayer != gm.getCurrentPlayer()) { + formerCurrentPlayer = gm.getCurrentPlayer(); + if (SoundConfig.isSFXEnabled()) { + player.playSFXByConfigKey ( + SoundConfig.KEY_SFX_GEN_NewCurrentPlayer, + gm.getCurrentPlayer().getName()); + } + } + } + } + private class PresidentModelObserver implements Observer { private PublicCompanyI pc; private Player formerPresident = null; @@ -149,6 +168,12 @@ public class SoundEventInterpreter { } } public void notifyOfGameInit(GameManagerI gameManager) { + //subscribe to current player changes + if (gameManager.getCurrentPlayerModel() != null) { + gameManager.getCurrentPlayerModel().addObserver( + new CurrentPlayerModelObserver(gameManager)); + } + //subscribe to round changes if (gameManager.getCurrentRoundModel() != null) { gameManager.getCurrentRoundModel().addObserver( commit cba0274cf22b8feab79e0ab071fd037432e48835 Author: Frederick Weld <fre...@gm...> Date: Tue Jan 31 14:50:23 2012 +0100 Exposed CurrentPlayerModel in GameManager(I) - needed for SFX Model was already part of GameManager implementation - this is just about exposing it in the interface. diff --git a/rails/game/GameManager.java b/rails/game/GameManager.java index 791dd01..c4c2289 100644 --- a/rails/game/GameManager.java +++ b/rails/game/GameManager.java @@ -1428,6 +1428,10 @@ public class GameManager implements ConfigurableComponentI, GameManagerI { return currentRound; } + public ModelObject getCurrentPlayerModel() { + return currentPlayer; + } + /* (non-Javadoc) * @see rails.game.GameManagerI#getCurrentPlayerIndex() */ diff --git a/rails/game/GameManagerI.java b/rails/game/GameManagerI.java index c7bc6d7..f098de6 100644 --- a/rails/game/GameManagerI.java +++ b/rails/game/GameManagerI.java @@ -100,6 +100,8 @@ public interface GameManagerI extends MoveableHolder, ConfigurableComponentI { public abstract ModelObject getCurrentRoundModel(); + public abstract ModelObject getCurrentPlayerModel(); + /** * @return Returns the currentPlayerIndex. */ |