Skip to content

Commit

Permalink
Add theme override, sound mute options + fix small bug in artennis
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Sep 13, 2022
1 parent 665e9f6 commit 331c3d9
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 8 deletions.
6 changes: 5 additions & 1 deletion LCDonald.Core/Controller/LCDLogicProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public LCDLogicProcessor(ILCDGame game, ILCDView view)
_gameAssetFolder = Path.Combine(appFolder, "GameAssets", _currentGame.ShortName);
}

public bool MuteSound { get; set; }

private void StartGame(object sender, EventArgs e)
{
_gameTimer?.Stop();
Expand Down Expand Up @@ -98,7 +100,9 @@ private void GameLoop()
_currentView.UpdateDisplay(_currentGame.GetVisibleGameElements());

// Sound
PlaySounds(_currentGame.GetSoundsToPlay());
var soundsToPlay = _currentGame.GetSoundsToPlay();
if (!MuteSound)
PlaySounds(soundsToPlay);
_soundsPlaying.RemoveAll(ss => !ss.IsPlaying);
}
System.Threading.Thread.Sleep(10);
Expand Down
2 changes: 1 addition & 1 deletion LCDonald.Core/Games/AmyRougeTennis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public override void HandleInputs(List<LCDGameInput> pressedInputs)
protected override void UpdateCore()
{
// Bounce ball back
if (_ballPosition > 40 && _ballPosition % 10 == _amyPosition && _batEngaged)
if (_ballPosition > 40 && _ballPosition % 10 == _amyPosition && _batEngaged && !_ballDirection)
{
_ballDirection = true;
QueueSound(new LCDGameSound("hit.ogg"));
Expand Down
13 changes: 13 additions & 0 deletions LCDonald/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public override void OnFrameworkInitializationCompleted()
var thm = AvaloniaLocator.Current.GetService<FluentAvaloniaTheme>();
thm?.ForceWin32WindowToTheme(desktop.MainWindow); // Window is the Window object you want to force


if (SettingsViewModel.CurrentSettings.ApplicationTheme == "System")
{
thm.PreferSystemTheme = true;
thm.RequestedTheme = null;
}
else
{
thm.PreferSystemTheme = false;
thm.RequestedTheme = SettingsViewModel.CurrentSettings.ApplicationTheme;
}


if (System.OperatingSystem.IsMacOS())
{
// Macify the styling a bit
Expand Down
3 changes: 3 additions & 0 deletions LCDonald/Controls/AvaloniaLCDView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ private void LoadGame()

private void DrawLayoutView(MAMEView view)
{
if (_logicProcessor != null)
_logicProcessor.MuteSound = SettingsViewModel.CurrentSettings.MuteSound;

_lcdCanvas?.Children.Clear();

foreach (var element in view.Elements)
Expand Down
53 changes: 51 additions & 2 deletions LCDonald/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using FluentAvalonia.Styling;

namespace LCDonald.ViewModels
{
public class Settings
{
public bool DarkenGameBackgrounds { get; set; }

public bool DarkenGameBackgrounds { get; set; } = true;
public bool MuteSound { get; set; }
public string ApplicationTheme { get; set; } = "System";
public bool DrawLCDShadows { get; set; }
}

Expand All @@ -28,10 +31,24 @@ public SettingsViewModel()

_darkenGameBackgrounds = CurrentSettings.DarkenGameBackgrounds;
_drawLCDShadows = CurrentSettings.DrawLCDShadows;
_muteSound = CurrentSettings.MuteSound;
_applicationTheme = CurrentSettings.ApplicationTheme switch
{
"System" => 0,
"Light" => 1,
"Dark" => 2,
_ => 0
};
}

[ObservableProperty]
private bool _darkenGameBackgrounds;

[ObservableProperty]
private bool _muteSound;

[ObservableProperty]
private int _applicationTheme;

[ObservableProperty]
private bool _drawLCDShadows;
Expand All @@ -42,6 +59,38 @@ partial void OnDarkenGameBackgroundsChanged(bool value)
SaveSettings();
}

partial void OnMuteSoundChanged(bool value)
{
CurrentSettings.MuteSound = value;
SaveSettings();
}

partial void OnApplicationThemeChanged(int value)
{
CurrentSettings.ApplicationTheme = value switch
{
0 => "System",
1 => "Light",
2 => "Dark",
_ => "System",
};

SaveSettings();

var thm = AvaloniaLocator.Current.GetService<FluentAvaloniaTheme>();

if (CurrentSettings.ApplicationTheme == "System")
{
thm.PreferSystemTheme = true;
thm.RequestedTheme = null;
}
else
{
thm.PreferSystemTheme = false;
thm.RequestedTheme = CurrentSettings.ApplicationTheme;
}
}

partial void OnDrawLCDShadowsChanged(bool value)
{
CurrentSettings.DrawLCDShadows = value;
Expand Down
22 changes: 18 additions & 4 deletions LCDonald/Views/SettingsPopup.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:svg="clr-namespace:Avalonia.Svg;assembly=Avalonia.Svg"
xmlns:controls="using:LCDonald.Controls"
xmlns:system="using:System"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"
x:Class="LCDonald.Views.SettingsPopup">

Expand All @@ -15,6 +16,19 @@

<StackPanel Spacing="8" >

<controls:OptionsDisplayItem Header="Application Theme"
Description="Choose your theme!"
Icon="ColorFill"
CornerRadius="{StaticResource ControlCornerRadius}">
<controls:OptionsDisplayItem.ActionButton>
<ComboBox SelectedIndex="{Binding ApplicationTheme}">
<ComboBoxItem>System</ComboBoxItem>
<ComboBoxItem>Hero</ComboBoxItem>
<ComboBoxItem>Dark</ComboBoxItem>
</ComboBox>
</controls:OptionsDisplayItem.ActionButton>
</controls:OptionsDisplayItem>

<controls:OptionsDisplayItem Header="Darken game backgrounds"
Description="This doesn't apply to Closeup views."
Icon="DarkTheme"
Expand All @@ -24,12 +38,12 @@
</controls:OptionsDisplayItem.ActionButton>
</controls:OptionsDisplayItem>

<controls:OptionsDisplayItem Header="Show shadows behind LCD elements"
Description="(I'm the coolest)"
Icon="Restore" IsVisible="False"
<controls:OptionsDisplayItem Header="Mute in-game sound"
Description="If I hear these beeps one more time i'm gonna flip"
Icon="Mute"
CornerRadius="{StaticResource ControlCornerRadius}">
<controls:OptionsDisplayItem.ActionButton>
<ToggleSwitch Margin="0,0,-80,0" IsChecked="{Binding DrawLCDShadows}"/>
<ToggleSwitch Margin="0,0,-80,0" IsChecked="{Binding MuteSound}"/>
</controls:OptionsDisplayItem.ActionButton>
</controls:OptionsDisplayItem>

Expand Down

0 comments on commit 331c3d9

Please sign in to comment.