22using System . Collections . Generic ;
33using System . Drawing ;
44using System . Linq ;
5+ using System . Media ;
56using System . Windows . Forms ;
67
78using DarkUI . Controls ;
@@ -43,6 +44,10 @@ public partial class FrmAnimation : EditorForm
4344
4445 private bool mPlayUpper ;
4546
47+ private SoundPlayer soundPlayer = new ( ) ;
48+
49+ private bool loopSoundOnPreview ;
50+
4651 private RenderTarget2D mUpperDarkness ;
4752
4853 private int mUpperFrame ;
@@ -161,6 +166,7 @@ private void InitLocalization()
161166 lblName . Text = Strings . AnimationEditor . name ;
162167 lblSound . Text = Strings . AnimationEditor . sound ;
163168 chkCompleteSoundPlayback . Text = Strings . AnimationEditor . soundcomplete ;
169+ chkLoopSoundDuringPreview . Text = Strings . AnimationEditor . LoopSoundDuringPreview ;
164170 labelDarkness . Text = Strings . AnimationEditor . simulatedarkness . ToString ( scrlDarkness . Value ) ;
165171 btnSwap . Text = Strings . AnimationEditor . swap ;
166172
@@ -284,6 +290,11 @@ private void chkCompleteSoundPlayback_CheckedChanged(object sender, EventArgs e)
284290 mEditorItem . CompleteSound = chkCompleteSoundPlayback . Checked ;
285291 }
286292
293+ private void chkLoopSoundDuringPreview_CheckedChanged ( object sender , EventArgs e )
294+ {
295+ loopSoundOnPreview = chkLoopSoundDuringPreview . Checked ;
296+ }
297+
287298 private void cmbLowerGraphic_SelectedIndexChanged ( object sender , EventArgs e )
288299 {
289300 mEditorItem . Lower . Sprite = TextUtils . SanitizeNone ( cmbLowerGraphic ? . Text ) ;
@@ -294,6 +305,23 @@ private void cmbUpperGraphic_SelectedIndexChanged(object sender, EventArgs e)
294305 mEditorItem . Upper . Sprite = TextUtils . SanitizeNone ( cmbUpperGraphic ? . Text ) ;
295306 }
296307
308+ private void btnPlaySound_Click ( object sender , EventArgs e )
309+ {
310+ PlayAnimationSound ( ) ;
311+ }
312+
313+ private void PlayAnimationSound ( )
314+ {
315+ if ( cmbSound . SelectedIndex <= 0 )
316+ {
317+ return ;
318+ }
319+
320+ soundPlayer . SoundLocation = "resources/sounds/" + mEditorItem . Sound ;
321+
322+ soundPlayer . Play ( ) ;
323+ }
324+
297325 private void tmrLowerAnimation_Tick ( object sender , EventArgs e )
298326 {
299327 if ( mPlayLower )
@@ -303,6 +331,11 @@ private void tmrLowerAnimation_Tick(object sender, EventArgs e)
303331 {
304332 mLowerFrame = 0 ;
305333 }
334+
335+ if ( mLowerFrame == 1 && loopSoundOnPreview && ! mPlayUpper )
336+ {
337+ PlayAnimationSound ( ) ;
338+ }
306339 }
307340 }
308341
@@ -489,6 +522,11 @@ private void tmrUpperAnimation_Tick(object sender, EventArgs e)
489522 {
490523 mUpperFrame = 0 ;
491524 }
525+
526+ if ( mUpperFrame == 1 && loopSoundOnPreview && ( ! mPlayLower || ( mPlayLower && mPlayUpper ) ) )
527+ {
528+ PlayAnimationSound ( ) ;
529+ }
492530 }
493531 }
494532
@@ -535,6 +573,7 @@ private void btnPlayLower_Click(object sender, EventArgs e)
535573 {
536574 _tooltip . SetToolTip ( btnPlayLower , Strings . AnimationEditor . Play ) ;
537575 btnPlayLower . ImageKey = "sharp_play_arrow_white_48dp.png" ;
576+ soundPlayer . Stop ( ) ;
538577 }
539578 }
540579
@@ -562,6 +601,7 @@ private void btnPlayUpper_Click(object sender, EventArgs e)
562601 {
563602 _tooltip . SetToolTip ( btnPlayUpper , Strings . AnimationEditor . Play ) ;
564603 btnPlayUpper . ImageKey = "sharp_play_arrow_white_48dp.png" ;
604+ soundPlayer . Stop ( ) ;
565605 }
566606 }
567607
0 commit comments