From: Frederick W. <fre...@us...> - 2012-01-30 19:04:25
|
LocalisedText.properties | 2 - rails/sound/SoundConfig.java | 1 rails/sound/SoundContext.java | 38 +++++++++++---------------------- rails/sound/SoundEventInterpreter.java | 4 ++- rails/sound/SoundPlayer.java | 38 +++++++++++++++------------------ rails/ui/swing/GameStatus.java | 4 +++ rails/ui/swing/GameUIManager.java | 11 ++++++--- rails/ui/swing/ORPanel.java | 36 ++++++++++++++++++++++++------- rails/ui/swing/hexmap/HexMapImage.java | 8 +----- 9 files changed, 77 insertions(+), 65 deletions(-) New commits: commit adee00213cca57e5b8b4a3290f226cb3148b2e6c Author: Frederick Weld <fre...@gm...> Date: Mon Jan 30 20:02:25 2012 +0100 Added selection sfx for stock market click field selections Buy/Sell sfx are still played upon confirmation ("ok") as before. diff --git a/LocalisedText.properties b/LocalisedText.properties index 137b73c..956079e 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -214,7 +214,7 @@ 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.pass=Pass -Config.label.sound.sfx.gen.select=Select (hex, start item) +Config.label.sound.sfx.gen.select=Select (hexes, click fields) Config.label.sound.sfx.str.bidStartItem=Bid on Start Item Config.label.sound.sfx.str.buyStartItem=Buy Start Item Config.label.sound.sfx.or.buyPrivate=Buy Private (as a company) diff --git a/rails/sound/SoundConfig.java b/rails/sound/SoundConfig.java index f1e1c2b..2cb1dc0 100644 --- a/rails/sound/SoundConfig.java +++ b/rails/sound/SoundConfig.java @@ -53,7 +53,7 @@ public class SoundConfig { (Arrays.asList( new String[] { KEY_SFX_GEN_Pass, KEY_SFX_GEN_Select, - KEY_SFX_OR_RotateTile, + KEY_SFX_OR_RotateTile })); //if set to true, sfx is reported not to be enabled irrespective of the configuration diff --git a/rails/sound/SoundEventInterpreter.java b/rails/sound/SoundEventInterpreter.java index 304c09a..28dfe13 100644 --- a/rails/sound/SoundEventInterpreter.java +++ b/rails/sound/SoundEventInterpreter.java @@ -219,7 +219,9 @@ public class SoundEventInterpreter { public void notifyOfClickFieldSelection(PossibleAction clickFieldAction) { if (SoundConfig.isSFXEnabled()) { if (clickFieldAction instanceof BidStartItem - || clickFieldAction instanceof BuyStartItem) { + || clickFieldAction instanceof BuyStartItem + || clickFieldAction instanceof BuyCertificate + || clickFieldAction instanceof SellShares) { player.playSFXByConfigKey(SoundConfig.KEY_SFX_GEN_Select); } } diff --git a/rails/ui/swing/GameStatus.java b/rails/ui/swing/GameStatus.java index b15bd42..dd8e00e 100644 --- a/rails/ui/swing/GameStatus.java +++ b/rails/ui/swing/GameStatus.java @@ -14,6 +14,7 @@ import rails.common.LocalText; import rails.game.*; import rails.game.action.*; import rails.game.correct.CashCorrectionAction; +import rails.sound.SoundManager; import rails.ui.swing.elements.*; import rails.ui.swing.hexmap.HexHighlightMouseListener; import rails.util.Util; @@ -614,6 +615,9 @@ public class GameStatus extends GridPanel implements ActionListener { gbc = gb.getConstraints(source); actions = ((ClickField) source).getPossibleActions(); + //notify sound manager that click field has been selected + SoundManager.notifyOfClickFieldSelection(actions.get(0)); + // Assume that we will have either sell or buy actions // under one ClickField, not both. This seems guaranteed. log.debug("Action is " + actions.get(0).toString()); commit bbf64f2ee3c94bc4a8570c5fcdae5c33aec4e42d Author: Frederick Weld <fre...@gm...> Date: Mon Jan 30 19:25:56 2012 +0100 Improved sfx/bgm ordering and further SoundPlayer refactoring SFX is now played in the logical order (eg., "buy share" -> "float"). For this purpose, notification of action processing has been placed before action processing itself (within GameUIManager). Furthermore, new BGM is now only played after completion of all SFX. On top of being desirable, this also removes the need for the more complex handling of the stock market opening bell - leading to deletion of that code fragment and further Sound Player streamlining. diff --git a/rails/sound/SoundConfig.java b/rails/sound/SoundConfig.java index 849be21..f1e1c2b 100644 --- a/rails/sound/SoundConfig.java +++ b/rails/sound/SoundConfig.java @@ -51,8 +51,9 @@ public class SoundConfig { */ public static final Set<String> KEYS_SFX_IMMEDIATE_PLAYING = new HashSet<String> (Arrays.asList( new String[] { + KEY_SFX_GEN_Pass, KEY_SFX_GEN_Select, - KEY_SFX_OR_RotateTile + KEY_SFX_OR_RotateTile, })); //if set to true, sfx is reported not to be enabled irrespective of the configuration diff --git a/rails/sound/SoundContext.java b/rails/sound/SoundContext.java index 9f4ac58..c38b334 100644 --- a/rails/sound/SoundContext.java +++ b/rails/sound/SoundContext.java @@ -69,14 +69,9 @@ public class SoundContext { + averageRevenue * (1 - slidingAverageAdjustmentFactor); } - /** - * @return true if new background music is played - */ - private boolean playBackgroundMusic() { - boolean isNewMusicPlayed = false; - + private void playBackgroundMusic() { //do nothing if music is not enabled - if (!SoundConfig.isBGMEnabled()) return false; + if (!SoundConfig.isBGMEnabled()) return; String currentRoundConfigKey = null; if (currentRound instanceof StartRound) { @@ -96,19 +91,9 @@ public class SoundContext { currentRoundConfigKey, currentPhaseName); if (!newBackgroundMusicFileName.equals(currentBackgroundMusicFileName)) { currentBackgroundMusicFileName = newBackgroundMusicFileName; - isNewMusicPlayed = true; - - //additionally play stock market opening bell if appropriate - if (SoundConfig.isSFXEnabled() && currentRound instanceof StockRound) { - player.playSFXByConfigKeyWithFollowupBGM( - SoundConfig.KEY_SFX_SR_OpeningBell, - newBackgroundMusicFileName); - } else { - player.playBGM(newBackgroundMusicFileName); - } + player.playBGM(newBackgroundMusicFileName); } } - return isNewMusicPlayed; } public void notifyOfPhase(PhaseI newPhase) { if (!newPhase.equals(currentPhase)) { @@ -119,15 +104,18 @@ public class SoundContext { public void notifyOfRound(RoundI newRound) { if (!newRound.equals(currentRound)) { - currentRound = newRound; - boolean isNewMusicPlayed = playBackgroundMusic(); - - //play stock market opening bell for stock rounds without new background music - //(e.g., if music is disabled but sfx is enabled) - if (!isNewMusicPlayed && SoundConfig.isSFXEnabled() - && currentRound instanceof StockRound) { + + //play stock market opening bell if stock round became current round + //and the round before was not + if (SoundConfig.isSFXEnabled() + && !(currentRound instanceof StockRound) + && newRound instanceof StockRound) { player.playSFXByConfigKey(SoundConfig.KEY_SFX_SR_OpeningBell); } + + currentRound = newRound; + + playBackgroundMusic(); } } public void notifyOfGameSetup() { diff --git a/rails/sound/SoundPlayer.java b/rails/sound/SoundPlayer.java index d35c783..be380d3 100644 --- a/rails/sound/SoundPlayer.java +++ b/rails/sound/SoundPlayer.java @@ -50,7 +50,7 @@ public class SoundPlayer { //wake the subsequent thread if there is one waiting synchronized (this) { - notify(); + notifyAll(); playingDone = true; } } @@ -125,11 +125,17 @@ public class SoundPlayer { private class LoopPlayerThread extends PlayerThread { boolean isStopped = false; Player player = null; + LoopPlayerThread previousLoopPlayerThread = null; public LoopPlayerThread(String fileName) { super(fileName); } public void play() { try { + //stop prior BGM music + if (previousLoopPlayerThread != null) { + previousLoopPlayerThread.interrupt(); + } + while (!isStopped) { FileInputStream fis = new FileInputStream(fileName); BufferedInputStream bis = new BufferedInputStream(fis); @@ -148,16 +154,8 @@ public class SoundPlayer { isStopped = true; if (player!=null) player.close(); } - } - private class PlayerThreadWithFollowupBGM extends PlayerThread { - private String bgmFileName; - public PlayerThreadWithFollowupBGM(String fileName, String bgmFileName) { - super(fileName); - this.bgmFileName = bgmFileName; - } - public void play() { - super.play(); - playBGM(bgmFileName); + public void setPreviousLoopPlayer(LoopPlayerThread previousLoopPlayerThread) { + this.previousLoopPlayerThread = previousLoopPlayerThread; } } @@ -226,19 +224,19 @@ public class SoundPlayer { } /** - * Plays the specified SFX and, after completing SFX play, the specified BGM - * is launched. + * Plays new background music and stops old BGM only after all currently playing + * sfx are finished. */ - public void playSFXByConfigKeyWithFollowupBGM(String sfxConfigKey,String bgmFileName) { - playSFX(new PlayerThreadWithFollowupBGM ( - SoundConfig.get(sfxConfigKey),bgmFileName), - SoundConfig.KEYS_SFX_IMMEDIATE_PLAYING.contains(sfxConfigKey)); - } - public void playBGM(String backgroundMusicFileName) { LoopPlayerThread newPlayerThread = new LoopPlayerThread(backgroundMusicFileName); LoopPlayerThread oldPlayerThread = adjustLastBGMThread(newPlayerThread); - if (oldPlayerThread != null) oldPlayerThread.interrupt(); + + //interrupt old bgm when starting the new bgm + newPlayerThread.setPreviousLoopPlayer(oldPlayerThread); + + //wait for playing new bgm until all sfx have finished playing + newPlayerThread.setPriorThread(lastSFXThread); + newPlayerThread.start(); } diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index 1a05e38..b081250 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -250,6 +250,13 @@ public class GameUIManager implements DialogOwner { Player oldPlayer = getCurrentPlayer(); boolean wasMyTurn = oldPlayer.getName().equals(localPlayerName); + // Notify the Sound Manager about this action, as it could lead to + // playing sfx or music. + // Notification has to be done before action processing so that + // resulting sfx are played in the correct order (first the action + // related sfx and then model-change related sfx) + SoundManager.notifyOfActionProcessing(gameManager, action); + // Process the action on the server result = previousResult = processOnServer (action); @@ -281,10 +288,6 @@ public class GameUIManager implements DialogOwner { } } - // Inform the Sound Manager about this action, as it could lead to - // playing sfx or music - SoundManager.notifyOfActionProcessing(gameManager, action); - // Check in which round we are now, // and make sure that the right window is active. updateUI(); diff --git a/rails/ui/swing/hexmap/HexMapImage.java b/rails/ui/swing/hexmap/HexMapImage.java index b8e95f4..fc934fb 100644 --- a/rails/ui/swing/hexmap/HexMapImage.java +++ b/rails/ui/swing/hexmap/HexMapImage.java @@ -2,13 +2,7 @@ package rails.ui.swing.hexmap; import java.awt.*; -import java.awt.event.*; import java.awt.geom.AffineTransform; -import java.awt.image.AffineTransformOp; -import java.awt.image.BufferedImage; -import java.io.File; - -import javax.swing.*; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; @@ -26,6 +20,8 @@ import rails.util.Util; */ public final class HexMapImage extends JSVGCanvas { + private static final long serialVersionUID = 1L; + protected static Logger log = Logger.getLogger(HexMapImage.class.getPackage().getName()); commit 1c68f09d713183272287f249aa80d47c2d127ef8 Author: Frederick Weld <fre...@gm...> Date: Mon Jan 30 19:24:43 2012 +0100 Added temporary workaround for avoiding exception prints for 0-revenue diff --git a/rails/ui/swing/ORPanel.java b/rails/ui/swing/ORPanel.java index 566b06b..cdaad11 100644 --- a/rails/ui/swing/ORPanel.java +++ b/rails/ui/swing/ORPanel.java @@ -741,7 +741,11 @@ implements ActionListener, KeyListener, RevenueListener { int revenueValue = ra.calculateRevenue(); log.debug("Revenue Value:" + revenueValue); log.debug("Revenue Run:" + ra.getOptimalRunPrettyPrint(true)); - ra.drawOptimalRunAsPath(orUIManager.getMap()); + + //try-catch clause temporary workaround as revenue adapter's + //convertRcRun might erroneously raise exceptions + try {revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap());} + catch (Exception e) {} if (!Game.getDevelop()) { //parent component is ORPanel so that dialog won't hide the routes painted on the map @@ -770,7 +774,12 @@ implements ActionListener, KeyListener, RevenueListener { //clean up the paths on the map orUIManager.getMap().setTrainPaths(null); //but retain paths already existing before - if (revenueAdapter != null) revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap()); + if (revenueAdapter != null) { + //try-catch clause temporary workaround as revenue adapter's + //convertRcRun might erroneously raise exceptions + try {revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap());} + catch (Exception e) {} + } } } @@ -798,7 +807,10 @@ implements ActionListener, KeyListener, RevenueListener { public void redrawRoutes() { if (revenueAdapter != null && isDisplayRoutes()) { - revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap()); + //try-catch clause temporary workaround as revenue adapter's + //convertRcRun might erroneously raise exceptions + try {revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap());} + catch (Exception e) {} } } @@ -1069,12 +1081,20 @@ implements ActionListener, KeyListener, RevenueListener { } if (finalResult) { orUIManager.getMap().setTrainPaths(null); - revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap()); - if (isRevenueValueToBeSet) { - orUIManager.setInformation("Best Run Value = " + bestRevenue + - " with " + Util.convertToHtml(revenueAdapter.getOptimalRunPrettyPrint(false))); - orUIManager.setDetail(Util.convertToHtml(revenueAdapter.getOptimalRunPrettyPrint(true))); + //try-catch clause temporary workaround as revenue adapter's + //convertRcRun might erroneously raise exceptions + //leaving on exception is admissible as exception only occur + //if revenue would be 0. + try { + revenueAdapter.drawOptimalRunAsPath(orUIManager.getMap()); + + if (isRevenueValueToBeSet) { + orUIManager.setInformation("Best Run Value = " + bestRevenue + + " with " + Util.convertToHtml(revenueAdapter.getOptimalRunPrettyPrint(false))); + orUIManager.setDetail(Util.convertToHtml(revenueAdapter.getOptimalRunPrettyPrint(true))); + } } + catch (Exception e) {} } } |