mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
* Added new preference option to enable sound in game and other sounds separately.
This commit is contained in:
parent
d4592b2ee2
commit
81eaac46c7
20 changed files with 628 additions and 432 deletions
|
|
@ -52,7 +52,9 @@
|
|||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="10"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout"/>
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Container class="javax.swing.JToolBar" name="mageToolbar">
|
||||
<Properties>
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ import mage.client.remote.CallbackClientImpl;
|
|||
import mage.client.table.TablesPane;
|
||||
import mage.client.tournament.TournamentPane;
|
||||
import mage.client.util.EDTExceptionHandler;
|
||||
import mage.client.util.MusicPlayer;
|
||||
import mage.client.util.SettingsManager;
|
||||
import mage.client.util.audio.MusicPlayer;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
import mage.components.ImagePanel;
|
||||
import mage.interfaces.MageClient;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package mage.client.combat;
|
|||
import mage.cards.MagePermanent;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.game.PlayAreaPanel;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.SettingsManager;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
import mage.view.CardView;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import mage.client.components.ext.dlg.DialogManager;
|
|||
import mage.client.components.ext.dlg.DlgParams;
|
||||
import mage.client.components.ext.dlg.IDialogPanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.Command;
|
||||
import mage.client.util.SettingsManager;
|
||||
import mage.view.CardView;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import mage.client.MageFrame;
|
|||
import mage.client.cards.BigCard;
|
||||
import mage.client.components.HoverButton;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.Command;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.ImageHelper;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ import javax.swing.JLayeredPane;
|
|||
import javax.swing.JOptionPane;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.game.GamePanel;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.Format;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.gui.BufferedImageBuilder;
|
||||
|
|
|
|||
|
|
@ -66,13 +66,13 @@
|
|||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="main_card" alignment="1" max="32767" attributes="0"/>
|
||||
<Component id="main_game" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="main_gamelog" alignment="1" pref="533" max="32767" attributes="0"/>
|
||||
<Component id="main_game" alignment="0" pref="533" max="32767" attributes="0"/>
|
||||
<Component id="main_gamelog" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
|
@ -82,10 +82,10 @@
|
|||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="main_card" min="-2" pref="68" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="main_game" min="-2" pref="68" max="-2" attributes="0"/>
|
||||
<Component id="main_game" min="-2" pref="103" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="main_gamelog" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="188" max="32767" attributes="0"/>
|
||||
<Component id="main_gamelog" min="-2" pref="49" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="153" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
|
@ -171,7 +171,7 @@
|
|||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
<BorderConstraints direction="First"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
|
|
@ -184,6 +184,22 @@
|
|||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="showPlayerNamesPermanentlyActionPerformed"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Before"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="showAbilityPickerForSimpleAbilities">
|
||||
<Properties>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="text" type="java.lang.String" value="Show ability picker for abilities without costs"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="This prevents that you accidently activate abilities without costs that e.g. tap the permanent."/>
|
||||
<Property name="horizontalAlignment" type="int" value="2"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="showAbilityPickerForSimpleAbilitiesActionPerformed"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Last"/>
|
||||
|
|
@ -731,8 +747,8 @@
|
|||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="sounds_clips" max="32767" attributes="0"/>
|
||||
<Component id="sounds_backgroundMusic" alignment="1" max="32767" attributes="0"/>
|
||||
<Component id="sounds_clips" pref="533" max="32767" attributes="0"/>
|
||||
<Component id="sounds_backgroundMusic" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
|
|
@ -745,7 +761,7 @@
|
|||
<Component id="sounds_clips" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="sounds_backgroundMusic" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="254" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="229" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
|
@ -769,13 +785,13 @@
|
|||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JCheckBox" name="cbEnableSounds">
|
||||
<Component class="javax.swing.JCheckBox" name="cbEnableGameSounds">
|
||||
<Properties>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Sounds that will be played for certain actions (e.g. play land, attack, etc.)"/>
|
||||
<Property name="label" type="java.lang.String" value="Enable"/>
|
||||
<Property name="text" type="java.lang.String" value="Enable game sounds"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Sounds that will be played for certain actions (e.g. play land, attack, etc.) during the game."/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbEnableSoundsActionPerformed"/>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbEnableGameSoundsActionPerformed"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
|
|
@ -783,6 +799,20 @@
|
|||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="cbEnableOtherSounds">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Enable other sounds"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Sounds that will be played for actions outside of games (e.g. whisper, player joins your game, player submits a deck ...)."/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbEnableOtherSoundsActionPerformed"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Last"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="sounds_backgroundMusic">
|
||||
|
|
|
|||
|
|
@ -74,10 +74,13 @@ import org.apache.log4j.Logger;
|
|||
*/
|
||||
public class PreferencesDialog extends javax.swing.JDialog {
|
||||
|
||||
private static final transient Logger log = Logger.getLogger(PreferencesDialog.class);
|
||||
|
||||
public static final String KEY_SHOW_TOOLTIPS_ANY_ZONE = "showTooltipsInAnyZone";
|
||||
public static final String KEY_HAND_USE_BIG_CARDS = "handUseBigCards";
|
||||
public static final String KEY_PERMANENTS_IN_ONE_PILE = "nonLandPermanentsInOnePile";
|
||||
public static final String KEY_SHOW_PLAYER_NAMES_PERMANENTLY = "showPlayerNamesPermanently";
|
||||
public static final String KEY_SHOW_ABILITY_PICKER = "showAbilityPicker";
|
||||
public static final String KEY_GAME_LOG_AUTO_SAVE = "gameLogAutoSave";
|
||||
|
||||
public static final String KEY_CARD_IMAGES_USE_DEFAULT = "cardImagesUseDefault";
|
||||
|
|
@ -91,7 +94,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
public static final String KEY_BATTLEFIELD_IMAGE_RANDOM = "battlefieldImagerandom";
|
||||
public static final String KEY_BATTLEFIELD_IMAGE_DEFAULT = "battlefieldImageDefault";
|
||||
|
||||
public static final String KEY_SOUNDS_ON = "soundsOn";
|
||||
public static final String KEY_SOUNDS_GAME_ON = "soundsOn";
|
||||
public static final String KEY_SOUNDS_OTHER_ON = "soundsOtherOn";
|
||||
public static final String KEY_SOUNDS_MATCH_MUSIC_ON = "soundsMatchMusicOn";
|
||||
public static final String KEY_SOUNDS_MATCH_MUSIC_PATH = "soundsMatchMusicPath";
|
||||
|
||||
|
|
@ -173,17 +177,18 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
|
||||
public static final String KEY_AVATAR = "selectedId";
|
||||
|
||||
private static Map<String, String> cache = new HashMap<String, String>();
|
||||
private static final Map<String, String> cache = new HashMap<String, String>();
|
||||
|
||||
private static final Boolean UPDATE_CACHE_POLICY = Boolean.TRUE;
|
||||
|
||||
public static final String OPEN_CONNECTION_TAB = "Open-Connection-Tab";
|
||||
|
||||
private static final transient Logger log = Logger.getLogger(PreferencesDialog.class);
|
||||
|
||||
|
||||
public static final int DEFAULT_AVATAR_ID = 51;
|
||||
private static int selectedAvatarId = DEFAULT_AVATAR_ID;
|
||||
private static final Set<Integer> available_avatars = new HashSet<Integer>();
|
||||
private static Map<Integer, JPanel> panels = new HashMap<Integer, JPanel>();
|
||||
private static final Map<Integer, JPanel> panels = new HashMap<Integer, JPanel>();
|
||||
|
||||
private static final Border GREEN_BORDER = BorderFactory.createLineBorder(Color.GREEN, 3);
|
||||
private static final Border BLACK_BORDER = BorderFactory.createLineBorder(Color.BLACK, 3);
|
||||
|
|
@ -267,6 +272,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
main_game = new javax.swing.JPanel();
|
||||
nonLandPermanentsInOnePile = new javax.swing.JCheckBox();
|
||||
showPlayerNamesPermanently = new javax.swing.JCheckBox();
|
||||
showAbilityPickerForSimpleAbilities = new javax.swing.JCheckBox();
|
||||
main_gamelog = new javax.swing.JPanel();
|
||||
cbGameLogAutoSave = new javax.swing.JCheckBox();
|
||||
tabPhases = new javax.swing.JPanel();
|
||||
|
|
@ -313,7 +319,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
jLabel15 = new javax.swing.JLabel();
|
||||
tabSounds = new javax.swing.JPanel();
|
||||
sounds_clips = new javax.swing.JPanel();
|
||||
cbEnableSounds = new javax.swing.JCheckBox();
|
||||
cbEnableGameSounds = new javax.swing.JCheckBox();
|
||||
cbEnableOtherSounds = new javax.swing.JCheckBox();
|
||||
sounds_backgroundMusic = new javax.swing.JPanel();
|
||||
cbEnableBattlefieldBGM = new javax.swing.JCheckBox();
|
||||
jLabel16 = new javax.swing.JLabel();
|
||||
|
|
@ -390,7 +397,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
nonLandPermanentsInOnePileActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
main_game.add(nonLandPermanentsInOnePile, java.awt.BorderLayout.CENTER);
|
||||
main_game.add(nonLandPermanentsInOnePile, java.awt.BorderLayout.PAGE_START);
|
||||
nonLandPermanentsInOnePile.getAccessibleContext().setAccessibleName("nonLandPermanentsInOnePile");
|
||||
|
||||
showPlayerNamesPermanently.setSelected(true);
|
||||
|
|
@ -401,7 +408,18 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
showPlayerNamesPermanentlyActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
main_game.add(showPlayerNamesPermanently, java.awt.BorderLayout.PAGE_END);
|
||||
main_game.add(showPlayerNamesPermanently, java.awt.BorderLayout.LINE_START);
|
||||
|
||||
showAbilityPickerForSimpleAbilities.setSelected(true);
|
||||
showAbilityPickerForSimpleAbilities.setText("Show ability picker for abilities without costs");
|
||||
showAbilityPickerForSimpleAbilities.setToolTipText("This prevents that you accidently activate abilities without costs that e.g. tap the permanent.");
|
||||
showAbilityPickerForSimpleAbilities.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
|
||||
showAbilityPickerForSimpleAbilities.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
showAbilityPickerForSimpleAbilitiesActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
main_game.add(showAbilityPickerForSimpleAbilities, java.awt.BorderLayout.PAGE_END);
|
||||
|
||||
main_gamelog.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Game log"));
|
||||
main_gamelog.setLayout(new java.awt.BorderLayout());
|
||||
|
|
@ -423,8 +441,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.addContainerGap()
|
||||
.addGroup(tabMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(main_card, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(main_game, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(main_gamelog, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE))
|
||||
.addComponent(main_game, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE)
|
||||
.addComponent(main_gamelog, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
tabMainLayout.setVerticalGroup(
|
||||
|
|
@ -433,10 +451,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.addContainerGap()
|
||||
.addComponent(main_card, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(main_game, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(main_game, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(main_gamelog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(188, Short.MAX_VALUE))
|
||||
.addComponent(main_gamelog, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(153, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
main_card.getAccessibleContext().setAccessibleName("Game panel");
|
||||
|
|
@ -766,14 +784,23 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
sounds_clips.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Clips"));
|
||||
sounds_clips.setLayout(new java.awt.BorderLayout());
|
||||
|
||||
cbEnableSounds.setToolTipText("Sounds that will be played for certain actions (e.g. play land, attack, etc.)");
|
||||
cbEnableSounds.setLabel("Enable");
|
||||
cbEnableSounds.addActionListener(new java.awt.event.ActionListener() {
|
||||
cbEnableGameSounds.setText("Enable game sounds");
|
||||
cbEnableGameSounds.setToolTipText("Sounds that will be played for certain actions (e.g. play land, attack, etc.) during the game.");
|
||||
cbEnableGameSounds.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
cbEnableSoundsActionPerformed(evt);
|
||||
cbEnableGameSoundsActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
sounds_clips.add(cbEnableSounds, java.awt.BorderLayout.CENTER);
|
||||
sounds_clips.add(cbEnableGameSounds, java.awt.BorderLayout.CENTER);
|
||||
|
||||
cbEnableOtherSounds.setText("Enable other sounds");
|
||||
cbEnableOtherSounds.setToolTipText("Sounds that will be played for actions outside of games (e.g. whisper, player joins your game, player submits a deck ...).");
|
||||
cbEnableOtherSounds.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
cbEnableOtherSoundsActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
sounds_clips.add(cbEnableOtherSounds, java.awt.BorderLayout.PAGE_END);
|
||||
|
||||
sounds_backgroundMusic.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Music"));
|
||||
|
||||
|
|
@ -835,8 +862,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.addGroup(tabSoundsLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(tabSoundsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(sounds_clips, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(sounds_backgroundMusic, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addComponent(sounds_clips, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE)
|
||||
.addComponent(sounds_backgroundMusic, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
tabSoundsLayout.setVerticalGroup(
|
||||
|
|
@ -846,7 +873,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.addComponent(sounds_clips, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(sounds_backgroundMusic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(254, Short.MAX_VALUE))
|
||||
.addContainerGap(229, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
sounds_clips.getAccessibleContext().setAccessibleDescription("");
|
||||
|
|
@ -1288,6 +1315,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
save(prefs, dialog.displayBigCardsInHand, KEY_HAND_USE_BIG_CARDS, "true", "false", UPDATE_CACHE_POLICY);
|
||||
save(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true", "false", UPDATE_CACHE_POLICY);
|
||||
save(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true", "false", UPDATE_CACHE_POLICY);
|
||||
save(prefs, dialog.showAbilityPickerForSimpleAbilities, KEY_SHOW_ABILITY_PICKER, "true", "false", UPDATE_CACHE_POLICY);
|
||||
save(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY);
|
||||
|
||||
// Phases
|
||||
|
|
@ -1318,7 +1346,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
save(prefs, dialog.cbUseRandomBattleImage, KEY_BATTLEFIELD_IMAGE_RANDOM, "true", "false", UPDATE_CACHE_POLICY);
|
||||
|
||||
// sounds
|
||||
save(prefs, dialog.cbEnableSounds, KEY_SOUNDS_ON, "true", "false", UPDATE_CACHE_POLICY);
|
||||
save(prefs, dialog.cbEnableGameSounds, KEY_SOUNDS_GAME_ON, "true", "false", UPDATE_CACHE_POLICY);
|
||||
save(prefs, dialog.cbEnableOtherSounds, KEY_SOUNDS_OTHER_ON, "true", "false", UPDATE_CACHE_POLICY);
|
||||
save(prefs, dialog.cbEnableBattlefieldBGM, KEY_SOUNDS_MATCH_MUSIC_ON, "true", "false", UPDATE_CACHE_POLICY);
|
||||
saveSoundPath(prefs);
|
||||
|
||||
|
|
@ -1404,9 +1433,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_cbCheckForNewImagesActionPerformed
|
||||
|
||||
private void cbEnableSoundsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableSoundsActionPerformed
|
||||
private void cbEnableGameSoundsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableGameSoundsActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_cbEnableSoundsActionPerformed
|
||||
}//GEN-LAST:event_cbEnableGameSoundsActionPerformed
|
||||
|
||||
private void cbEnableBattlefieldBGMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableBattlefieldBGMActionPerformed
|
||||
if(cbEnableBattlefieldBGM.isSelected()){
|
||||
|
|
@ -1545,6 +1574,14 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
|
||||
}//GEN-LAST:event_showToolTipsInAnyZoneActionPerformed
|
||||
|
||||
private void showAbilityPickerForSimpleAbilitiesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAbilityPickerForSimpleAbilitiesActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_showAbilityPickerForSimpleAbilitiesActionPerformed
|
||||
|
||||
private void cbEnableOtherSoundsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableOtherSoundsActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_cbEnableOtherSoundsActionPerformed
|
||||
|
||||
private void showProxySettings() {
|
||||
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
|
||||
this.pnlProxy.setVisible(true);
|
||||
|
|
@ -1575,6 +1612,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
}
|
||||
final int openedTab = param;
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!dialog.isVisible()) {
|
||||
Preferences prefs = MageFrame.getPreferences();
|
||||
|
|
@ -1628,6 +1666,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
load(prefs, dialog.showToolTipsInAnyZone, KEY_SHOW_TOOLTIPS_ANY_ZONE, "true");
|
||||
load(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true");
|
||||
load(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true");
|
||||
load(prefs, dialog.showAbilityPickerForSimpleAbilities, KEY_SHOW_ABILITY_PICKER, "true");
|
||||
load(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true");
|
||||
}
|
||||
|
||||
|
|
@ -1682,11 +1721,17 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
}
|
||||
|
||||
private static void loadSoundSettings(Preferences prefs) {
|
||||
String prop = prefs.get(KEY_SOUNDS_ON, "true");
|
||||
String prop = prefs.get(KEY_SOUNDS_GAME_ON, "true");
|
||||
if (prop.equals("true")) {
|
||||
dialog.cbEnableSounds.setSelected(true);
|
||||
dialog.cbEnableGameSounds.setSelected(true);
|
||||
} else {
|
||||
dialog.cbEnableSounds.setSelected(false);
|
||||
dialog.cbEnableGameSounds.setSelected(false);
|
||||
}
|
||||
prop = prefs.get(KEY_SOUNDS_OTHER_ON, "true");
|
||||
if (prop.equals("true")) {
|
||||
dialog.cbEnableOtherSounds.setSelected(true);
|
||||
} else {
|
||||
dialog.cbEnableOtherSounds.setSelected(false);
|
||||
}
|
||||
|
||||
// Match music
|
||||
|
|
@ -1830,7 +1875,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
} else {
|
||||
Preferences prefs = MageFrame.getPreferences();
|
||||
String value = prefs.get(key, def);
|
||||
if (value == null) return null;
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
cache.put(key, value);
|
||||
return value;
|
||||
}
|
||||
|
|
@ -1877,8 +1924,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
for (JPanel panel : panels.values()) {
|
||||
panel.setBorder(BLACK_BORDER);
|
||||
}
|
||||
this.selectedAvatarId = id;
|
||||
panels.get(this.selectedAvatarId).setBorder(GREEN_BORDER);
|
||||
PreferencesDialog.selectedAvatarId = id;
|
||||
panels.get(PreferencesDialog.selectedAvatarId).setBorder(GREEN_BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1923,7 +1970,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
private javax.swing.JButton btnBrowseImageLocation;
|
||||
private javax.swing.JCheckBox cbCheckForNewImages;
|
||||
private javax.swing.JCheckBox cbEnableBattlefieldBGM;
|
||||
private javax.swing.JCheckBox cbEnableSounds;
|
||||
private javax.swing.JCheckBox cbEnableGameSounds;
|
||||
private javax.swing.JCheckBox cbEnableOtherSounds;
|
||||
private javax.swing.JCheckBox cbGameLogAutoSave;
|
||||
private javax.swing.JComboBox cbProxyType;
|
||||
private javax.swing.JCheckBox cbSaveToZipFiles;
|
||||
|
|
@ -1992,6 +2040,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
private javax.swing.JPanel pnlProxySettings;
|
||||
private javax.swing.JCheckBox rememberPswd;
|
||||
private javax.swing.JButton saveButton;
|
||||
private javax.swing.JCheckBox showAbilityPickerForSimpleAbilities;
|
||||
private javax.swing.JCheckBox showPlayerNamesPermanently;
|
||||
private javax.swing.JCheckBox showToolTipsInAnyZone;
|
||||
private javax.swing.JPanel sounds_backgroundMusic;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import mage.client.MageFrame;
|
|||
import mage.client.chat.ChatPanel;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.components.tray.MageTray;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.remote.Session;
|
||||
import mage.view.SeatView;
|
||||
import mage.view.TableView;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ import mage.cards.MagePermanent;
|
|||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.Permanent;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.Config;
|
||||
import mage.constants.CardType;
|
||||
import mage.view.PermanentView;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import mage.client.MageFrame;
|
|||
import mage.client.chat.ChatPanel;
|
||||
import mage.client.components.MageTextArea;
|
||||
import mage.client.dialog.MageDialog;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
import mage.remote.Session;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import mage.client.constants.Constants.DeckEditorMode;
|
|||
import mage.client.draft.DraftPanel;
|
||||
import mage.client.game.GamePanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.DeckUtil;
|
||||
import mage.client.util.GameManager;
|
||||
import mage.client.util.object.SaveObjectUtil;
|
||||
|
|
|
|||
|
|
@ -1,219 +0,0 @@
|
|||
package mage.client.util;
|
||||
|
||||
import java.io.File;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Manager class for playing audio files.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class AudioManager {
|
||||
|
||||
private static final Logger log = Logger.getLogger(AudioManager.class);
|
||||
|
||||
/**
|
||||
* AudioManager singleton.
|
||||
*/
|
||||
private static AudioManager audioManager = null;
|
||||
|
||||
|
||||
public static AudioManager getManager() {
|
||||
if (audioManager == null) {
|
||||
audioManager = new AudioManager();
|
||||
audioManager.nextPageClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav"); //sounds better than OnNextPage
|
||||
audioManager.prevPageClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav");
|
||||
audioManager.anotherTabClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav");
|
||||
audioManager.nextPhaseClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPhase.wav");
|
||||
audioManager.endTurnClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnEndTurn.wav");
|
||||
audioManager.tapPermanentClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnTapPermanent.wav");
|
||||
audioManager.summonClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnSummon.wav");
|
||||
audioManager.diedCreatureClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnSummon-.wav");
|
||||
audioManager.drawClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnDraw.wav");
|
||||
audioManager.buttonOkClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnButtonOk.wav");
|
||||
audioManager.buttonCancelClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnButtonCancel.wav");
|
||||
audioManager.attackClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAttack.wav");
|
||||
audioManager.blockClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnBlock.wav");
|
||||
audioManager.addPermanentClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAddPermanent.wav");
|
||||
audioManager.addArtifactClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAddArtifact.wav");
|
||||
audioManager.updateStackClip = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnStackNew.wav");
|
||||
audioManager.onHover = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnHover.wav");
|
||||
|
||||
audioManager.playerJoinedTable = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerJoinedTable.wav");
|
||||
audioManager.playerSubmittedDeck = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerSubmittedDeck.wav");
|
||||
audioManager.playerWhispered = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerWhispered.wav");
|
||||
audioManager.playerLeft = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerLeft.wav");
|
||||
audioManager.playerWon = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerWon.wav");
|
||||
audioManager.playerLost = audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerLost.wav");
|
||||
}
|
||||
return audioManager;
|
||||
}
|
||||
|
||||
public static void playNextPage() {
|
||||
checkAndPlayClip(getManager().nextPageClip);
|
||||
}
|
||||
|
||||
public static void playPrevPage() {
|
||||
checkAndPlayClip(getManager().prevPageClip);
|
||||
}
|
||||
|
||||
public static void playAnotherTab() {
|
||||
checkAndPlayClip(getManager().anotherTabClip);
|
||||
}
|
||||
|
||||
public static void playNextPhase() {
|
||||
checkAndPlayClip(getManager().nextPhaseClip);
|
||||
}
|
||||
|
||||
public static void playEndTurn() {
|
||||
checkAndPlayClip(getManager().endTurnClip);
|
||||
}
|
||||
|
||||
public static void playTapPermanent() {
|
||||
checkAndPlayClip(getManager().tapPermanentClip);
|
||||
}
|
||||
|
||||
public static void playSummon() {
|
||||
checkAndPlayClip(getManager().summonClip);
|
||||
}
|
||||
|
||||
public static void playDiedCreature() {
|
||||
checkAndPlayClip(getManager().diedCreatureClip);
|
||||
}
|
||||
|
||||
public static void playDraw() {
|
||||
checkAndPlayClip(getManager().drawClip);
|
||||
}
|
||||
|
||||
public static void playButtonOk() {
|
||||
checkAndPlayClip(getManager().buttonOkClip);
|
||||
}
|
||||
|
||||
public static void playButtonCancel() {
|
||||
checkAndPlayClip(getManager().buttonCancelClip);
|
||||
}
|
||||
|
||||
public static void playAttack() {
|
||||
checkAndPlayClip(getManager().attackClip);
|
||||
}
|
||||
|
||||
public static void playBlock() {
|
||||
checkAndPlayClip(getManager().blockClip);
|
||||
}
|
||||
|
||||
public static void playAddPermanent() {
|
||||
checkAndPlayClip(getManager().addPermanentClip);
|
||||
}
|
||||
|
||||
public static void playAddArtifact() {
|
||||
checkAndPlayClip(getManager().addArtifactClip);
|
||||
}
|
||||
|
||||
public static void playStackNew() {
|
||||
checkAndPlayClip(getManager().updateStackClip);
|
||||
}
|
||||
|
||||
public static void playOnHover() {
|
||||
checkAndPlayClip(getManager().onHover);
|
||||
}
|
||||
|
||||
public static void playPlayerJoinedTable() {
|
||||
checkAndPlayClip(getManager().playerJoinedTable);
|
||||
}
|
||||
|
||||
public static void playPlayerWhispered() {
|
||||
checkAndPlayClip(getManager().playerWhispered);
|
||||
}
|
||||
|
||||
public static void playPlayerSubmittedDeck() {
|
||||
checkAndPlayClip(getManager().playerSubmittedDeck);
|
||||
}
|
||||
|
||||
public static void playPlayerLeft() {
|
||||
checkAndPlayClip(getManager().playerLeft);
|
||||
}
|
||||
|
||||
public static void playPlayerLost() {
|
||||
checkAndPlayClip(getManager().playerLost);
|
||||
}
|
||||
|
||||
public static void playPlayerWon() {
|
||||
checkAndPlayClip(getManager().playerWon);
|
||||
}
|
||||
|
||||
private static void checkAndPlayClip(Clip clip) {
|
||||
try {
|
||||
if (clip != null) {
|
||||
String soundsOn = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_ON, "true");
|
||||
if (soundsOn.equals("true")) {
|
||||
audioManager.play(clip);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void play(final Clip clip) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
clip.setFramePosition(0);
|
||||
clip.start();
|
||||
}
|
||||
}).run();
|
||||
}
|
||||
|
||||
private Clip loadClip(String filename) {
|
||||
try {
|
||||
File soundFile = new File(filename);
|
||||
AudioInputStream soundIn = AudioSystem
|
||||
.getAudioInputStream(soundFile);
|
||||
AudioFormat format = new AudioFormat(
|
||||
AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED,
|
||||
16, 2, 4, AudioSystem.NOT_SPECIFIED, true);
|
||||
DataLine.Info info = new DataLine.Info(Clip.class, format);
|
||||
|
||||
Clip clip = (Clip) AudioSystem.getLine(info);
|
||||
clip.open(soundIn);
|
||||
|
||||
return clip;
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
log.error("Couldn't load sound: " + filename + ".");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Clip nextPageClip = null;
|
||||
private Clip prevPageClip = null;
|
||||
private Clip anotherTabClip = null;
|
||||
private Clip nextPhaseClip = null;
|
||||
private Clip endTurnClip = null;
|
||||
private Clip tapPermanentClip = null;
|
||||
private Clip summonClip = null;
|
||||
private Clip diedCreatureClip = null;
|
||||
private Clip drawClip = null;
|
||||
private Clip buttonOkClip = null;
|
||||
private Clip buttonCancelClip = null;
|
||||
private Clip attackClip = null;
|
||||
private Clip blockClip = null;
|
||||
private Clip addPermanentClip = null;
|
||||
private Clip addArtifactClip = null;
|
||||
private Clip updateStackClip = null;
|
||||
private Clip onHover = null;
|
||||
|
||||
private Clip playerJoinedTable = null;
|
||||
private Clip playerSubmittedDeck = null;
|
||||
private Clip playerWhispered = null;
|
||||
private Clip playerLeft = null;
|
||||
private Clip playerWon = null;
|
||||
private Clip playerLost = null;
|
||||
}
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
package mage.client.util;
|
||||
import java.io.File;
|
||||
import java.awt.List;
|
||||
import javax.sound.sampled.*;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author renli
|
||||
*/
|
||||
|
||||
public class MusicPlayer {
|
||||
private static final Logger log = Logger.getLogger(AudioManager.class);
|
||||
String filepath;
|
||||
String filename;
|
||||
List filelist = new List();
|
||||
static MusicPlayer player = null;
|
||||
|
||||
|
||||
//open file and add list
|
||||
private boolean open(){
|
||||
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_MATCH_MUSIC_PATH, "true");
|
||||
filepath = path + File.separator;
|
||||
if(path == null) filepath = Constants.BASE_MUSICS_PATH;
|
||||
filelist.removeAll();
|
||||
File filedir = new File(filepath);
|
||||
File[] fileread = filedir.listFiles();
|
||||
if(fileread == null) return false;
|
||||
if(fileread.length == 0)return false;
|
||||
String filename;
|
||||
for(File f:fileread){
|
||||
filename = f.getName().toLowerCase();
|
||||
if(filename.endsWith(".mp3") || filename.endsWith(".wav")){
|
||||
filelist.add(filename);
|
||||
}
|
||||
}
|
||||
if(filelist.getItemCount() == 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void playBGM(){
|
||||
stopBGM();
|
||||
if(player == null){
|
||||
player = new MusicPlayer();
|
||||
}
|
||||
if(player.open()){
|
||||
player.play();
|
||||
}
|
||||
}
|
||||
|
||||
public void play(){
|
||||
String soundsOn = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_MATCH_MUSIC_ON, "true");
|
||||
if(soundsOn.equals("true")){
|
||||
player.breaked = false;
|
||||
player.breaked_out = false;
|
||||
player.stopped = false;
|
||||
Thread player = new Thread(new playerThread());
|
||||
player.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopBGM(){
|
||||
if(player != null){
|
||||
player.stopped = true;
|
||||
player.breaked_out = true;
|
||||
player.breaked = true;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (Exception e) {
|
||||
log.error("Thread error: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public volatile boolean breaked = false;
|
||||
public volatile boolean breaked_out = false;
|
||||
public volatile boolean stopped = false;
|
||||
public volatile FloatControl volume;
|
||||
AudioInputStream audioInputStream;
|
||||
AudioFormat audioFormat;
|
||||
SourceDataLine sourceDataLine;
|
||||
|
||||
|
||||
class playerThread extends Thread{
|
||||
private void load(File file){
|
||||
try{
|
||||
audioInputStream = AudioSystem.getAudioInputStream(file);
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
// mp3 decode
|
||||
if (audioFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
|
||||
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
|
||||
audioFormat.getSampleRate(), 16, audioFormat.getChannels(), audioFormat.getChannels() * 2,
|
||||
audioFormat.getSampleRate(), false);
|
||||
audioInputStream = AudioSystem.getAudioInputStream(audioFormat, audioInputStream);
|
||||
}
|
||||
//output
|
||||
DataLine.Info dataLineInfo = new DataLine.Info(
|
||||
SourceDataLine.class, audioFormat,
|
||||
AudioSystem.NOT_SPECIFIED);
|
||||
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
|
||||
sourceDataLine.open(audioFormat);
|
||||
volume = (FloatControl)sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
sourceDataLine.start();
|
||||
}catch(Exception e){
|
||||
log.error("Couldn't load file: " + file + " " + e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void run(){
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
while(!stopped){
|
||||
int it = (int)Math.abs(Math.random()*(filelist.getItemCount()));
|
||||
File file = new File(filepath + filelist.getItem(it));
|
||||
load(file);
|
||||
Thread PlayThread = new Thread(new PlayThread());
|
||||
PlayThread.start();
|
||||
while (!(breaked || breaked_out)) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
log.error("Thread error: " + e);
|
||||
}
|
||||
}
|
||||
breaked = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PlayThread extends Thread{
|
||||
byte tempBuffer[] = new byte[320];
|
||||
public void run(){
|
||||
try{
|
||||
sourceDataLine.flush();
|
||||
int len;
|
||||
while ((len = audioInputStream.read(tempBuffer, 0,
|
||||
tempBuffer.length)) != -1){
|
||||
if(breaked_out) break;
|
||||
if(len > 0) sourceDataLine.write(tempBuffer, 0, len);
|
||||
}
|
||||
//breaked or stopped
|
||||
sourceDataLine.flush();
|
||||
sourceDataLine.close();
|
||||
breaked = true;
|
||||
}catch(Exception e){
|
||||
log.error("Thread error: " + e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package mage.client.util.audio;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public enum AudioGroup {
|
||||
GameSounds,
|
||||
OtherSounds;
|
||||
}
|
||||
|
|
@ -0,0 +1,256 @@
|
|||
package mage.client.util.audio;
|
||||
|
||||
import java.io.File;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Manager class for playing audio files.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class AudioManager {
|
||||
|
||||
private static final Logger log = Logger.getLogger(AudioManager.class);
|
||||
|
||||
private MageClip nextPageClip = null;
|
||||
private MageClip prevPageClip = null;
|
||||
private MageClip anotherTabClip = null;
|
||||
private MageClip nextPhaseClip = null;
|
||||
private MageClip endTurnClip = null;
|
||||
private MageClip tapPermanentClip = null;
|
||||
private MageClip summonClip = null;
|
||||
private MageClip diedCreatureClip = null;
|
||||
private MageClip drawClip = null;
|
||||
private MageClip buttonOkClip = null;
|
||||
private MageClip buttonCancelClip = null;
|
||||
private MageClip attackClip = null;
|
||||
private MageClip blockClip = null;
|
||||
private MageClip addPermanentClip = null;
|
||||
private MageClip addArtifactClip = null;
|
||||
private MageClip updateStackClip = null;
|
||||
private MageClip onHover = null;
|
||||
|
||||
private MageClip playerJoinedTable = null;
|
||||
private MageClip playerSubmittedDeck = null;
|
||||
private MageClip playerWhispered = null;
|
||||
private MageClip playerLeft = null;
|
||||
private MageClip playerWon = null;
|
||||
private MageClip playerLost = null;
|
||||
/**
|
||||
* AudioManager singleton.
|
||||
*/
|
||||
private static AudioManager audioManager = null;
|
||||
|
||||
|
||||
public static AudioManager getManager() {
|
||||
if (audioManager == null) {
|
||||
audioManager = new AudioManager();
|
||||
audioManager.nextPageClip =
|
||||
new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav"),
|
||||
AudioGroup.OtherSounds); //sounds better than OnNextPage
|
||||
audioManager.prevPageClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav"),
|
||||
AudioGroup.OtherSounds);
|
||||
audioManager.anotherTabClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav"),
|
||||
AudioGroup.OtherSounds);
|
||||
|
||||
audioManager.playerSubmittedDeck = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerSubmittedDeck.wav"),
|
||||
AudioGroup.OtherSounds);
|
||||
audioManager.playerWhispered = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerWhispered.wav"),
|
||||
AudioGroup.OtherSounds);
|
||||
audioManager.playerLeft = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerLeft.wav"),
|
||||
AudioGroup.OtherSounds);
|
||||
|
||||
// in games sounds
|
||||
audioManager.nextPhaseClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnNextPhase.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.endTurnClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnEndTurn.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.tapPermanentClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnTapPermanent.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.summonClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnSummon.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.diedCreatureClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnSummon-.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.drawClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnDraw.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.buttonOkClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnButtonOk.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.buttonCancelClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnButtonCancel.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.attackClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAttack.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.blockClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnBlock.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.addPermanentClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAddPermanent.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.addArtifactClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnAddArtifact.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.updateStackClip = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnStackNew.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.onHover = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnHover.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.playerWon = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerWon.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
audioManager.playerLost = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerLost.wav"),
|
||||
AudioGroup.GameSounds);
|
||||
}
|
||||
return audioManager;
|
||||
}
|
||||
|
||||
public static void playNextPage() {
|
||||
checkAndPlayClip(getManager().nextPageClip);
|
||||
}
|
||||
|
||||
public static void playPrevPage() {
|
||||
checkAndPlayClip(getManager().prevPageClip);
|
||||
}
|
||||
|
||||
public static void playAnotherTab() {
|
||||
checkAndPlayClip(getManager().anotherTabClip);
|
||||
}
|
||||
|
||||
public static void playNextPhase() {
|
||||
checkAndPlayClip(getManager().nextPhaseClip);
|
||||
}
|
||||
|
||||
public static void playEndTurn() {
|
||||
checkAndPlayClip(getManager().endTurnClip);
|
||||
}
|
||||
|
||||
public static void playTapPermanent() {
|
||||
checkAndPlayClip(getManager().tapPermanentClip);
|
||||
}
|
||||
|
||||
public static void playSummon() {
|
||||
checkAndPlayClip(getManager().summonClip);
|
||||
}
|
||||
|
||||
public static void playDiedCreature() {
|
||||
checkAndPlayClip(getManager().diedCreatureClip);
|
||||
}
|
||||
|
||||
public static void playDraw() {
|
||||
checkAndPlayClip(getManager().drawClip);
|
||||
}
|
||||
|
||||
public static void playButtonOk() {
|
||||
checkAndPlayClip(getManager().buttonOkClip);
|
||||
}
|
||||
|
||||
public static void playButtonCancel() {
|
||||
checkAndPlayClip(getManager().buttonCancelClip);
|
||||
}
|
||||
|
||||
public static void playAttack() {
|
||||
checkAndPlayClip(getManager().attackClip);
|
||||
}
|
||||
|
||||
public static void playBlock() {
|
||||
checkAndPlayClip(getManager().blockClip);
|
||||
}
|
||||
|
||||
public static void playAddPermanent() {
|
||||
checkAndPlayClip(getManager().addPermanentClip);
|
||||
}
|
||||
|
||||
public static void playAddArtifact() {
|
||||
checkAndPlayClip(getManager().addArtifactClip);
|
||||
}
|
||||
|
||||
public static void playStackNew() {
|
||||
checkAndPlayClip(getManager().updateStackClip);
|
||||
}
|
||||
|
||||
public static void playOnHover() {
|
||||
checkAndPlayClip(getManager().onHover);
|
||||
}
|
||||
|
||||
public static void playPlayerJoinedTable() {
|
||||
if (audioManager.playerJoinedTable == null) {
|
||||
audioManager.playerJoinedTable = new MageClip(audioManager.loadClip(Constants.BASE_SOUND_PATH + "OnPlayerJoinedTable.wav"),
|
||||
AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerJoinedTable);
|
||||
}
|
||||
|
||||
public static void playPlayerWhispered() {
|
||||
checkAndPlayClip(getManager().playerWhispered);
|
||||
}
|
||||
|
||||
public static void playPlayerSubmittedDeck() {
|
||||
checkAndPlayClip(getManager().playerSubmittedDeck);
|
||||
}
|
||||
|
||||
public static void playPlayerLeft() {
|
||||
checkAndPlayClip(getManager().playerLeft);
|
||||
}
|
||||
|
||||
public static void playPlayerLost() {
|
||||
checkAndPlayClip(getManager().playerLost);
|
||||
}
|
||||
|
||||
public static void playPlayerWon() {
|
||||
checkAndPlayClip(getManager().playerWon);
|
||||
}
|
||||
|
||||
private static void checkAndPlayClip(MageClip mageClip) {
|
||||
try {
|
||||
if (mageClip != null) {
|
||||
boolean playSound = false;
|
||||
switch (mageClip.getAudioGroup()) {
|
||||
case GameSounds:
|
||||
playSound = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_GAME_ON, "true").equals("true");
|
||||
break;
|
||||
case OtherSounds:
|
||||
playSound = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_OTHER_ON, "true").equals("true");
|
||||
}
|
||||
|
||||
if (playSound) {
|
||||
audioManager.play(mageClip.getClip());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(AudioManager.class).fatal("Error while playing sound clip.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void play(final Clip clip) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
clip.setFramePosition(0);
|
||||
clip.start();
|
||||
}
|
||||
}).run();
|
||||
}
|
||||
|
||||
private Clip loadClip(String filename) {
|
||||
try {
|
||||
File soundFile = new File(filename);
|
||||
AudioInputStream soundIn = AudioSystem
|
||||
.getAudioInputStream(soundFile);
|
||||
AudioFormat format = new AudioFormat(
|
||||
AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED,
|
||||
16, 2, 4, AudioSystem.NOT_SPECIFIED, true);
|
||||
DataLine.Info info = new DataLine.Info(Clip.class, format);
|
||||
|
||||
Clip clip = (Clip) AudioSystem.getLine(info);
|
||||
clip.open(soundIn);
|
||||
|
||||
return clip;
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
log.error("Couldn't load sound: " + filename + ".");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.client.util.audio;
|
||||
|
||||
import javax.sound.sampled.Clip;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class MageClip {
|
||||
|
||||
private final Clip clip;
|
||||
private final AudioGroup audioGroup;
|
||||
|
||||
public MageClip(Clip clip, AudioGroup audioGroup) {
|
||||
this.clip = clip;
|
||||
this.audioGroup = audioGroup;
|
||||
}
|
||||
|
||||
public Clip getClip() {
|
||||
return clip;
|
||||
}
|
||||
|
||||
public AudioGroup getAudioGroup() {
|
||||
return audioGroup;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
package mage.client.util.audio;
|
||||
|
||||
import java.io.File;
|
||||
import java.awt.List;
|
||||
import javax.sound.sampled.*;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author renli
|
||||
*/
|
||||
public class MusicPlayer {
|
||||
|
||||
private static final Logger log = Logger.getLogger(AudioManager.class);
|
||||
String filepath;
|
||||
String filename;
|
||||
List filelist = new List();
|
||||
static MusicPlayer player = null;
|
||||
|
||||
//open file and add list
|
||||
private boolean open() {
|
||||
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_MATCH_MUSIC_PATH, "true");
|
||||
filepath = path + File.separator;
|
||||
if (path == null) {
|
||||
filepath = Constants.BASE_MUSICS_PATH;
|
||||
}
|
||||
filelist.removeAll();
|
||||
File filedir = new File(filepath);
|
||||
File[] fileread = filedir.listFiles();
|
||||
if (fileread == null) {
|
||||
return false;
|
||||
}
|
||||
if (fileread.length == 0) {
|
||||
return false;
|
||||
}
|
||||
String filename;
|
||||
for (File f : fileread) {
|
||||
filename = f.getName().toLowerCase();
|
||||
if (filename.endsWith(".mp3") || filename.endsWith(".wav")) {
|
||||
filelist.add(filename);
|
||||
}
|
||||
}
|
||||
if (filelist.getItemCount() == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void playBGM() {
|
||||
stopBGM();
|
||||
if (player == null) {
|
||||
player = new MusicPlayer();
|
||||
}
|
||||
if (player.open()) {
|
||||
player.play();
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
String soundsOn = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SOUNDS_MATCH_MUSIC_ON, "true");
|
||||
if (soundsOn.equals("true")) {
|
||||
player.breaked = false;
|
||||
player.breaked_out = false;
|
||||
player.stopped = false;
|
||||
Thread player = new Thread(new playerThread());
|
||||
player.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopBGM() {
|
||||
if (player != null) {
|
||||
player.stopped = true;
|
||||
player.breaked_out = true;
|
||||
player.breaked = true;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (Exception e) {
|
||||
log.error("Thread error: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public volatile boolean breaked = false;
|
||||
public volatile boolean breaked_out = false;
|
||||
public volatile boolean stopped = false;
|
||||
public volatile FloatControl volume;
|
||||
AudioInputStream audioInputStream;
|
||||
AudioFormat audioFormat;
|
||||
SourceDataLine sourceDataLine;
|
||||
|
||||
class playerThread extends Thread {
|
||||
|
||||
private void load(File file) {
|
||||
try {
|
||||
audioInputStream = AudioSystem.getAudioInputStream(file);
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
// mp3 decode
|
||||
if (audioFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
|
||||
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
|
||||
audioFormat.getSampleRate(), 16, audioFormat.getChannels(), audioFormat.getChannels() * 2,
|
||||
audioFormat.getSampleRate(), false);
|
||||
audioInputStream = AudioSystem.getAudioInputStream(audioFormat, audioInputStream);
|
||||
}
|
||||
//output
|
||||
DataLine.Info dataLineInfo = new DataLine.Info(
|
||||
SourceDataLine.class, audioFormat,
|
||||
AudioSystem.NOT_SPECIFIED);
|
||||
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
|
||||
sourceDataLine.open(audioFormat);
|
||||
volume = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
sourceDataLine.start();
|
||||
} catch (Exception e) {
|
||||
log.error("Couldn't load file: " + file + " " + e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
while (!stopped) {
|
||||
int it = (int) Math.abs(Math.random() * (filelist.getItemCount()));
|
||||
File file = new File(filepath + filelist.getItem(it));
|
||||
load(file);
|
||||
Thread PlayThread = new Thread(new PlayThread());
|
||||
PlayThread.start();
|
||||
while (!(breaked || breaked_out)) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
log.error("Thread error: " + e);
|
||||
}
|
||||
}
|
||||
breaked = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PlayThread extends Thread {
|
||||
|
||||
byte tempBuffer[] = new byte[320];
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
sourceDataLine.flush();
|
||||
int len;
|
||||
while ((len = audioInputStream.read(tempBuffer, 0,
|
||||
tempBuffer.length)) != -1) {
|
||||
if (breaked_out) {
|
||||
break;
|
||||
}
|
||||
if (len > 0) {
|
||||
sourceDataLine.write(tempBuffer, 0, len);
|
||||
}
|
||||
}
|
||||
//breaked or stopped
|
||||
sourceDataLine.flush();
|
||||
sourceDataLine.close();
|
||||
breaked = true;
|
||||
} catch (Exception e) {
|
||||
log.error("Thread error: " + e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ import mage.cards.MagePermanent;
|
|||
import mage.cards.TextPopup;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.cards.action.TransferData;
|
||||
import mage.client.util.AudioManager;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.components.ImagePanel;
|
||||
import mage.constants.CardType;
|
||||
import mage.utils.CardUtil;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue