Suggested design/architecture for UI audio?
Looking at viewtopic.php?t=2098, I see PlaySoundAction and Interactivity, and the suggestion of potentially implementing a custom action, which I might do eventually for FMOD. But for now, I have more design-related questions from the XAML/UI POV.
1. How does one add this Interactivity/sound action to a XAML? Doesn't seem like it can be just dropped-in (missing assembly etc); I'll dig into this one as it's not exactly Noesis' fault.
EDIT: Looks like I can just use "xmlns:b="http://schemas.microsoft.com/xaml/behaviors"" directly, and other answers online are outdated.
2. Say I have a series of menu buttons that should share the same click/hover sounds - how should that be structured? It wouldn't make sense to have a copy of the full Play Sound / Interactivity code in each button in the XAML.
2a. If the solution is to instead drive it from code or some custom class, can I still go through the Noesis::PlayAudioCallback?
2b. Can the solution have these common sounds set up, but with an optional override? So all buttons on the menu use the same click/hover sounds, specified in one place, but one button might have its own distinct on-click sound.
3. Will specifying audio by string in my WPF/C# mock-up cause issues if that audio doesn't exist? Because it lives in FMOD audio banks, and exposing the raw audio to VS Blend just to please it would be a lot.
4. Stepping back, how is the audio+UI relationship definitely at scale in Noesis, typically? Maybe at the style level, with some resource dictionary xaml files which somehow set up the audio/sound effect strings/names? Working on something in the strategy space, so lots of icons and clicking and hovering, with potentially different reactions based on e.g. hovering ally vs enemy, which all sound like candidates for triggers in style + having some statics in the resources.xaml like "EnemyHoverSoundName" and a string for the FMOD audio effect.
Thanks!
1. How does one add this Interactivity/sound action to a XAML? Doesn't seem like it can be just dropped-in (missing assembly etc); I'll dig into this one as it's not exactly Noesis' fault.
EDIT: Looks like I can just use "xmlns:b="http://schemas.microsoft.com/xaml/behaviors"" directly, and other answers online are outdated.
2. Say I have a series of menu buttons that should share the same click/hover sounds - how should that be structured? It wouldn't make sense to have a copy of the full Play Sound / Interactivity code in each button in the XAML.
2a. If the solution is to instead drive it from code or some custom class, can I still go through the Noesis::PlayAudioCallback?
2b. Can the solution have these common sounds set up, but with an optional override? So all buttons on the menu use the same click/hover sounds, specified in one place, but one button might have its own distinct on-click sound.
3. Will specifying audio by string in my WPF/C# mock-up cause issues if that audio doesn't exist? Because it lives in FMOD audio banks, and exposing the raw audio to VS Blend just to please it would be a lot.
4. Stepping back, how is the audio+UI relationship definitely at scale in Noesis, typically? Maybe at the style level, with some resource dictionary xaml files which somehow set up the audio/sound effect strings/names? Working on something in the strategy space, so lots of icons and clicking and hovering, with potentially different reactions based on e.g. hovering ally vs enemy, which all sound like candidates for triggers in style + having some statics in the resources.xaml like "EnemyHoverSoundName" and a string for the FMOD audio effect.
Thanks!
Re: Suggested design/architecture for UI audio?
We did it by creating a Style and a custom TriggerAction
The custom TriggerAction is in C#, but it should be the same for C++.
Code: Select all
<Style x:Key="Style.TechBroButtonBase" BasedOn="{StaticResource Style.ButtonBase}" TargetType="ButtonBase">
<Setter Property="noesis:StyleInteraction.Triggers">
<Setter.Value>
<noesis:StyleTriggerCollection>
<b:EventTrigger EventName="Click">
<ta:PlayUISoundAction Sound="ButtonClick" />
</b:EventTrigger>
</noesis:StyleTriggerCollection>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource Style.TechBroButtonBase}" TargetType="Button" />
Code: Select all
public class PlayUISoundAction : TriggerAction<DependencyObject>
{
public UIAudio Sound { get; set; }
protected override void Invoke(object parameter)
{
var audioService = ServiceLocator.Instance.GetService<IAudioService>();
if (audioService != null)
audioService.PlayEffect(Sound);
}
}
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Suggested design/architecture for UI audio?
Hi,
1) As you found, you just have to use the behaviors namespace: xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
2) Thanks @nadjibus for the suggestion. As he mentioned you should use the StyleInteraction.Triggers along with the StyleTriggerCollection to specify the common Triggers/Actions for your button style. So no need to use code for this.
2b) If you create your own audio action, then you can define an attached property that can be set in a specific button to override the default sound (extending nadjibus PlayUISoundAction example):
3) No, your WPF/C# mock-up class will just do nothing with the incoming strings.
4) Using styles to define the basic control sounds seems like the best approach, and even defining extra sounds on specific xaml elements by just using the interaction triggers/actions there is fine too.
1) As you found, you just have to use the behaviors namespace: xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
2) Thanks @nadjibus for the suggestion. As he mentioned you should use the StyleInteraction.Triggers along with the StyleTriggerCollection to specify the common Triggers/Actions for your button style. So no need to use code for this.
2b) If you create your own audio action, then you can define an attached property that can be set in a specific button to override the default sound (extending nadjibus PlayUISoundAction example):
Code: Select all
<StackPanel>
<Button Style="{StaticResource Style.TechBroButtonBase}" Content="START"/>
<Button Style="{StaticResource Style.TechBroButtonBase}" ta:PlayUISoundAction.SoundOverride="ButtonExitClick" Content="EXIT"/>
</StackPanel>
4) Using styles to define the basic control sounds seems like the best approach, and even defining extra sounds on specific xaml elements by just using the interaction triggers/actions there is fine too.
Who is online
Users browsing this forum: Bing [Bot] and 2 guests