1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Generalized GamesViewModel and applied fixes to them, closing #27

This commit is contained in:
SpoinkyNL 2016-03-01 14:10:49 +01:00
parent 6ccfaf45d5
commit 8eb7ed2863
22 changed files with 215 additions and 255 deletions

View File

@ -17,7 +17,7 @@
<!-- Accent and AppTheme setting --> <!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Teal.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Teal.xaml" />
<ResourceDictionary <ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
<ResourceDictionary Source="/Resources/Icons.xaml" /> <ResourceDictionary Source="/Resources/Icons.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>

View File

@ -245,7 +245,8 @@
<Compile Include="Managers\KeyboardManager.cs" /> <Compile Include="Managers\KeyboardManager.cs" />
<Compile Include="Managers\MainManager.cs" /> <Compile Include="Managers\MainManager.cs" />
<Compile Include="Models\EffectModel.cs" /> <Compile Include="Models\EffectModel.cs" />
<Compile Include="Models\GamePointersCollectionModel.cs" /> <Compile Include="Models\EffectSettings.cs" />
<Compile Include="Models\GameSettings.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualization.Designer.cs"> <Compile Include="Modules\Effects\AudioVisualizer\AudioVisualization.Designer.cs">
<DependentUpon>AudioVisualization.settings</DependentUpon> <DependentUpon>AudioVisualization.settings</DependentUpon>
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
@ -291,7 +292,6 @@
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplayModel.cs" /> <Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplayModel.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerSettings.cs" /> <Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerSettings.cs" />
<Compile Include="Modules\Effects\Debug\DebugEffectSettings.cs" /> <Compile Include="Modules\Effects\Debug\DebugEffectSettings.cs" />
<Compile Include="Models\EffectSettings.cs" />
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplaySettings.cs" /> <Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplaySettings.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeagueSettings.cs" /> <Compile Include="Modules\Games\RocketLeague\RocketLeagueSettings.cs" />
<Compile Include="Modules\Effects\TypeWave\TypeWaveSettings.cs" /> <Compile Include="Modules\Effects\TypeWave\TypeWaveSettings.cs" />
@ -321,6 +321,7 @@
<Compile Include="Utilities\GameState\GameStateWebServer.cs" /> <Compile Include="Utilities\GameState\GameStateWebServer.cs" />
<Compile Include="Utilities\ImageUtilities.cs" /> <Compile Include="Utilities\ImageUtilities.cs" />
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" /> <Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\Memory\GamePointer.cs" />
<Compile Include="Utilities\Memory\Memory.cs" /> <Compile Include="Utilities\Memory\Memory.cs" />
<Compile Include="Utilities\Memory\MemoryHelpers.cs" /> <Compile Include="Utilities\Memory\MemoryHelpers.cs" />
<Compile Include="Utilities\Memory\Win32.cs" /> <Compile Include="Utilities\Memory\Win32.cs" />
@ -329,6 +330,7 @@
<Compile Include="Utilities\ShellLink.cs" /> <Compile Include="Utilities\ShellLink.cs" />
<Compile Include="Utilities\Updater.cs" /> <Compile Include="Utilities\Updater.cs" />
<Compile Include="ViewModels\Abstract\EffectViewModel.cs" /> <Compile Include="ViewModels\Abstract\EffectViewModel.cs" />
<Compile Include="ViewModels\Abstract\GameViewModel.cs" />
<Compile Include="ViewModels\EffectsViewModel.cs" /> <Compile Include="ViewModels\EffectsViewModel.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerViewModel.cs" /> <Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerViewModel.cs" />
<Compile Include="Modules\Effects\Debug\DebugEffectViewModel.cs" /> <Compile Include="Modules\Effects\Debug\DebugEffectViewModel.cs" />

View File

@ -52,8 +52,6 @@ namespace Artemis.Managers
if (!keyboardProvider.CanEnable()) if (!keyboardProvider.CanEnable())
{ {
_mainManager.DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText); _mainManager.DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
//MessageBox.Show(keyboardProvider.CantEnableText, "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK,
// MessageBoxIcon.Warning);
return; return;
} }

View File

@ -0,0 +1,7 @@
namespace Artemis.Models
{
public abstract class GameSettings : EffectSettings
{
public bool Enabled { get; set; }
}
}

View File

@ -18,7 +18,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer
// Create effect model and add it to MainManager // Create effect model and add it to MainManager
EffectModel = new AudioVisualizerModel(mainManager, (AudioVisualizerSettings) EffectSettings); EffectModel = new AudioVisualizerModel(mainManager, (AudioVisualizerSettings) EffectSettings);
MainManager.EffectManager.EffectModels.Add((AudioVisualizerModel) EffectModel); MainManager.EffectManager.EffectModels.Add(EffectModel);
} }
public static string Name => "Audio Visualizer"; public static string Name => "Audio Visualizer";

View File

@ -27,7 +27,7 @@ namespace Artemis.Modules.Effects.Debug
// Create effect model and add it to MainManager // Create effect model and add it to MainManager
EffectModel = new DebugEffectModel(mainManager, (DebugEffectSettings) EffectSettings); EffectModel = new DebugEffectModel(mainManager, (DebugEffectSettings) EffectSettings);
MainManager.EffectManager.EffectModels.Add((DebugEffectModel) EffectModel); MainManager.EffectManager.EffectModels.Add(EffectModel);
} }

View File

@ -15,7 +15,7 @@ namespace Artemis.Modules.Effects.TypeHole
// Create effect model and add it to MainManager // Create effect model and add it to MainManager
EffectModel = new TypeHoleModel(mainManager); EffectModel = new TypeHoleModel(mainManager);
MainManager.EffectManager.EffectModels.Add((TypeHoleModel) EffectModel); MainManager.EffectManager.EffectModels.Add(EffectModel);
} }
public static string Name => "Type Holes (NYI)"; public static string Name => "Type Holes (NYI)";

View File

@ -18,7 +18,7 @@ namespace Artemis.Modules.Effects.TypeWave
// Create effect model and add it to MainManager // Create effect model and add it to MainManager
EffectModel = new TypeWaveModel(mainManager, (TypeWaveSettings) EffectSettings); EffectModel = new TypeWaveModel(mainManager, (TypeWaveSettings) EffectSettings);
MainManager.EffectManager.EffectModels.Add((TypeWaveModel) EffectModel); MainManager.EffectManager.EffectModels.Add(EffectModel);
} }
public static string Name => "Type Waves"; public static string Name => "Type Waves";

View File

@ -3,14 +3,13 @@ using Artemis.Models;
namespace Artemis.Modules.Games.CounterStrike namespace Artemis.Modules.Games.CounterStrike
{ {
public class CounterStrikeSettings : EffectSettings public class CounterStrikeSettings : GameSettings
{ {
public CounterStrikeSettings() public CounterStrikeSettings()
{ {
Load(); Load();
} }
public bool Enabled { get; set; }
public string GameDirectory { get; set; } public string GameDirectory { get; set; }
public bool AmmoEnabled { get; set; } public bool AmmoEnabled { get; set; }

View File

@ -37,7 +37,7 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" /> <Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" />
<ToggleButton x:Name="EffectEnabled" Margin="0 3 0 0" Width="25" Height="25" <ToggleButton x:Name="EffectEnabled" Margin="0 3 0 0" Width="25" Height="25"
IsChecked="{Binding Path=CounterStrikeSettings.Enabled, Mode=TwoWay}" IsChecked="{Binding Path=GameSettings.Enabled, Mode=TwoWay}"
Style="{DynamicResource MetroCircleToggleButtonStyle}" Style="{DynamicResource MetroCircleToggleButtonStyle}"
cal:Message.Attach="[Event Click] = [Action ToggleEffect]" /> cal:Message.Attach="[Event Click] = [Action ToggleEffect]" />
</StackPanel> </StackPanel>
@ -50,7 +50,7 @@
Width="130" HorizontalAlignment="Left" /> Width="130" HorizontalAlignment="Left" />
<Grid> <Grid>
<TextBox x:Name="GameDirectory" Height="23" TextWrapping="Wrap" Margin="5,0,30,0" <TextBox x:Name="GameDirectory" Height="23" TextWrapping="Wrap" Margin="5,0,30,0"
Text="{Binding Path=CounterStrikeSettings.GameDirectory, Mode=TwoWay}" Text="{Binding Path=GameSettings.GameDirectory, Mode=TwoWay}"
cal:Message.Attach="[Event LostFocus] = [Action PlaceConfigFile]" /> cal:Message.Attach="[Event LostFocus] = [Action PlaceConfigFile]" />
<Button x:Name="BrowseDirectory" Content="..." RenderTransformOrigin="-0.039,-0.944" <Button x:Name="BrowseDirectory" Content="..." RenderTransformOrigin="-0.039,-0.944"
HorizontalAlignment="Right" Width="25" HorizontalAlignment="Right" Width="25"
@ -63,7 +63,7 @@
Height="16" Margin="0,10,0,9"> Height="16" Margin="0,10,0,9">
Display ammo on F-keys Display ammo on F-keys
</TextBlock> </TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.AmmoEnabled, Mode=TwoWay}" <controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.AmmoEnabled, Mode=TwoWay}"
Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" /> Margin="0,0,-5,0" Width="114" />
@ -73,7 +73,7 @@
Main ammo color Main ammo color
</TextBlock> </TextBlock>
<xctk:ColorPicker x:Name="MainColor" <xctk:ColorPicker x:Name="MainColor"
SelectedColor="{Binding Path=CounterStrikeSettings.AmmoMainColor, Mode=TwoWay}" SelectedColor="{Binding Path=GameSettings.AmmoMainColor, Mode=TwoWay}"
Grid.Row="3" Grid.Column="1" Width="110" HorizontalAlignment="Right" Grid.Row="3" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" /> VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -83,7 +83,7 @@
Secondary ammo color Secondary ammo color
</TextBlock> </TextBlock>
<xctk:ColorPicker x:Name="SecondaryColor" <xctk:ColorPicker x:Name="SecondaryColor"
SelectedColor="{Binding Path=CounterStrikeSettings.AmmoSecondaryColor, Mode=TwoWay}" SelectedColor="{Binding Path=GameSettings.AmmoSecondaryColor, Mode=TwoWay}"
Grid.Row="4" Grid.Column="1" Width="110" HorizontalAlignment="Right" Grid.Row="4" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" /> VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -92,7 +92,7 @@
Height="16" Margin="0,9,0,10"> Height="16" Margin="0,9,0,10">
Display smoked effect Display smoked effect
</TextBlock> </TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.SmokeEnabled, Mode=TwoWay}" <controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.SmokeEnabled, Mode=TwoWay}"
Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No" Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" /> Margin="0,0,-5,0" Width="114" />
@ -101,7 +101,7 @@
Height="16" Margin="0,10,0,9"> Height="16" Margin="0,10,0,9">
Display flashed effect Display flashed effect
</TextBlock> </TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.FlashEnabled, Mode=TwoWay}" <controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.FlashEnabled, Mode=TwoWay}"
Grid.Row="6" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No" Grid.Row="6" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" /> Margin="0,0,-5,0" Width="114" />
@ -110,7 +110,7 @@
Height="16" Margin="0,9,0,10"> Height="16" Margin="0,9,0,10">
Color keyboard according to team Color keyboard according to team
</TextBlock> </TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.TeamColorEnabled, Mode=TwoWay}" <controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.TeamColorEnabled, Mode=TwoWay}"
Grid.Row="7" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No" Grid.Row="7" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" /> Margin="0,0,-5,0" Width="114" />
@ -119,7 +119,7 @@
Height="16" Margin="0,10,0,9"> Height="16" Margin="0,10,0,9">
Color keyboard red on low HP Color keyboard red on low HP
</TextBlock> </TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=CounterStrikeSettings.LowHpEnabled, Mode=TwoWay}" <controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.LowHpEnabled, Mode=TwoWay}"
Grid.Row="8" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No" Grid.Row="8" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" /> Margin="0,0,-5,0" Width="114" />

View File

@ -2,92 +2,63 @@
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Properties; using Artemis.Properties;
using Screen = Caliburn.Micro.Screen; using Artemis.ViewModels.Abstract;
namespace Artemis.Modules.Games.CounterStrike namespace Artemis.Modules.Games.CounterStrike
{ {
public class CounterStrikeViewModel : Screen public class CounterStrikeViewModel : GameViewModel
{ {
private CounterStrikeSettings _counterStrikeSettings;
public CounterStrikeViewModel(MainManager mainManager) public CounterStrikeViewModel(MainManager mainManager)
{ {
MainManager = mainManager; MainManager = mainManager;
// Settings are loaded from file by class // Settings are loaded from file by class
CounterStrikeSettings = new CounterStrikeSettings(); GameSettings = new CounterStrikeSettings();
// Create effect model and add it to MainManager // Create effect model and add it to MainManager
CounterStrikeModel = new CounterStrikeModel(mainManager, CounterStrikeSettings); GameModel = new CounterStrikeModel(mainManager, (CounterStrikeSettings) GameSettings);
MainManager.EffectManager.EffectModels.Add(CounterStrikeModel); MainManager.EffectManager.EffectModels.Add(GameModel);
PlaceConfigFile(); PlaceConfigFile();
} }
public CounterStrikeSettings CounterStrikeSettings
{
get { return _counterStrikeSettings; }
set
{
if (Equals(value, _counterStrikeSettings)) return;
_counterStrikeSettings = value;
NotifyOfPropertyChange(() => CounterStrikeSettings);
}
}
public CounterStrikeModel CounterStrikeModel { get; set; }
public MainManager MainManager { get; set; }
public static string Name => "CS:GO"; public static string Name => "CS:GO";
public string Content => "Counter-Strike: GO Content"; public string Content => "Counter-Strike: GO Content";
public void SaveSettings()
{
CounterStrikeSettings?.Save();
}
public void ResetSettings()
{
// TODO: Confirmation dialog (Generic MVVM approach)
CounterStrikeSettings.ToDefault();
NotifyOfPropertyChange(() => CounterStrikeSettings);
SaveSettings();
}
public void ToggleEffect()
{
CounterStrikeModel.Enabled = _counterStrikeSettings.Enabled;
}
public void BrowseDirectory() public void BrowseDirectory()
{ {
var dialog = new FolderBrowserDialog {SelectedPath = CounterStrikeSettings.GameDirectory}; var dialog = new FolderBrowserDialog {SelectedPath = ((CounterStrikeSettings) GameSettings).GameDirectory};
var result = dialog.ShowDialog(); var result = dialog.ShowDialog();
if (result != DialogResult.OK) if (result != DialogResult.OK)
return; return;
CounterStrikeSettings.GameDirectory = dialog.SelectedPath; ((CounterStrikeSettings) GameSettings).GameDirectory = dialog.SelectedPath;
NotifyOfPropertyChange(() => CounterStrikeSettings); NotifyOfPropertyChange(() => GameSettings);
GameSettings.Save();
PlaceConfigFile(); PlaceConfigFile();
} }
public void PlaceConfigFile() public void PlaceConfigFile()
{ {
if (CounterStrikeSettings.GameDirectory == string.Empty) if (((CounterStrikeSettings) GameSettings).GameDirectory == string.Empty)
return; return;
if (Directory.Exists(CounterStrikeSettings.GameDirectory + "/csgo/cfg")) if (Directory.Exists(((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg"))
{ {
var cfgFile = Resources.gamestateConfiguration.Replace("{{port}}", var cfgFile = Resources.gamestateConfiguration.Replace("{{port}}",
MainManager.GameStateWebServer.Port.ToString()); MainManager.GameStateWebServer.Port.ToString());
File.WriteAllText(CounterStrikeSettings.GameDirectory + "/csgo/cfg/gamestate_integration_artemis.cfg", File.WriteAllText(
((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg/gamestate_integration_artemis.cfg",
cfgFile); cfgFile);
return; return;
} }
MessageBox.Show("Please select a valid CS:GO directory"); MainManager.DialogService.ShowErrorMessageBox("Please select a valid CS:GO directory\n\n" +
CounterStrikeSettings.GameDirectory = string.Empty; @"By default CS:GO is in \SteamApps\common\Counter-Strike Global Offensive");
NotifyOfPropertyChange(() => CounterStrikeSettings); ((CounterStrikeSettings) GameSettings).GameDirectory = string.Empty;
NotifyOfPropertyChange(() => GameSettings);
GameSettings.Save();
} }
} }
} }

View File

@ -20,8 +20,9 @@ namespace Artemis.Modules.Games.RocketLeague
private int _boostAmount; private int _boostAmount;
private bool _boostGrowing; private bool _boostGrowing;
private KeyboardRectangle _boostRect; private KeyboardRectangle _boostRect;
private bool _contextualColor;
private Memory _memory; private Memory _memory;
private GamePointersCollectionModel _pointer; private GamePointersCollection _pointer;
private int _previousBoost; private int _previousBoost;
public RocketLeagueModel(MainManager mainManager, RocketLeagueSettings settings) : base(mainManager) public RocketLeagueModel(MainManager mainManager, RocketLeagueSettings settings) : base(mainManager)
@ -37,7 +38,6 @@ namespace Artemis.Modules.Games.RocketLeague
public RocketLeagueSettings Settings { get; set; } public RocketLeagueSettings Settings { get; set; }
public int Scale { get; set; } public int Scale { get; set; }
public bool ContextualColor { get; set; }
public override void Dispose() public override void Dispose()
{ {
@ -49,7 +49,7 @@ namespace Artemis.Modules.Games.RocketLeague
{ {
Initialized = false; Initialized = false;
ContextualColor = Settings.ContextualColor; _contextualColor = Settings.ContextualColor;
_boostRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color> _boostRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color>
{ {
@ -58,7 +58,7 @@ namespace Artemis.Modules.Games.RocketLeague
}, LinearGradientMode.Horizontal); }, LinearGradientMode.Horizontal);
Updater.GetPointers(); Updater.GetPointers();
_pointer = JsonConvert.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague); _pointer = JsonConvert.DeserializeObject<GamePointersCollection>(Offsets.Default.RocketLeague);
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName); var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
_memory = new Memory(tempProcess); _memory = new Memory(tempProcess);
@ -89,7 +89,7 @@ namespace Artemis.Modules.Games.RocketLeague
_boostRect.Width = _boostRect.Width =
(int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); (int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount);
if (ContextualColor) if (_contextualColor)
{ {
if (_boostAmount < 33) if (_boostAmount < 33)
_boostRect.Colors = new List<Color> {Color.Red}; _boostRect.Colors = new List<Color> {Color.Red};
@ -98,15 +98,6 @@ namespace Artemis.Modules.Games.RocketLeague
else if (_boostAmount >= 66) else if (_boostAmount >= 66)
_boostRect.Colors = new List<Color> {Color.Lime}; _boostRect.Colors = new List<Color> {Color.Lime};
} }
else
{
_boostRect.Colors = new List<Color>
{
ColorHelpers.ToDrawingColor(Settings.MainColor),
ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
};
}
Task.Run(() => GrowIfHigher()); Task.Run(() => GrowIfHigher());
} }

View File

@ -3,14 +3,13 @@ using Artemis.Models;
namespace Artemis.Modules.Games.RocketLeague namespace Artemis.Modules.Games.RocketLeague
{ {
public class RocketLeagueSettings : EffectSettings public class RocketLeagueSettings : GameSettings
{ {
public RocketLeagueSettings() public RocketLeagueSettings()
{ {
Load(); Load();
} }
public bool Enabled { get; set; }
public Color MainColor { get; set; } public Color MainColor { get; set; }
public Color SecondaryColor { get; set; } public Color SecondaryColor { get; set; }
public bool ContextualColor { get; set; } public bool ContextualColor { get; set; }

View File

@ -34,7 +34,7 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" /> <Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" />
<ToggleButton x:Name="EffectEnabled" Margin="0 3 0 0" Width="25" Height="25" <ToggleButton x:Name="EffectEnabled" Margin="0 3 0 0" Width="25" Height="25"
IsChecked="{Binding Path=RocketLeagueSettings.Enabled, Mode=TwoWay}" IsChecked="{Binding Path=GameSettings.Enabled, Mode=TwoWay}"
Style="{DynamicResource MetroCircleToggleButtonStyle}" Style="{DynamicResource MetroCircleToggleButtonStyle}"
cal:Message.Attach="[Event Click] = [Action ToggleEffect]" /> cal:Message.Attach="[Event Click] = [Action ToggleEffect]" />
</StackPanel> </StackPanel>
@ -46,7 +46,7 @@
Main boost display color Main boost display color
</TextBlock> </TextBlock>
<xctk:ColorPicker x:Name="MainColor" <xctk:ColorPicker x:Name="MainColor"
SelectedColor="{Binding Path=RocketLeagueSettings.MainColor, Mode=TwoWay}" SelectedColor="{Binding Path=GameSettings.MainColor, Mode=TwoWay}"
Grid.Row="1" Grid.Column="1" Width="110" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" /> VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -56,7 +56,7 @@
Secondary boost display color Secondary boost display color
</TextBlock> </TextBlock>
<xctk:ColorPicker x:Name="SecondaryColor" <xctk:ColorPicker x:Name="SecondaryColor"
SelectedColor="{Binding Path=RocketLeagueSettings.SecondaryColor, Mode=TwoWay}" SelectedColor="{Binding Path=GameSettings.SecondaryColor, Mode=TwoWay}"
Grid.Row="2" Grid.Column="1" Width="110" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1" Width="110" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" /> VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
@ -65,7 +65,7 @@
Height="16" Margin="0,8"> Height="16" Margin="0,8">
Color bar according to boost amount Color bar according to boost amount
</TextBlock> </TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=RocketLeagueSettings.ContextualColor, Mode=TwoWay}" <controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.ContextualColor, Mode=TwoWay}"
Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" /> Margin="0,0,-5,0" Width="114" />

View File

@ -1,15 +1,14 @@
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models;
using Artemis.Settings; using Artemis.Settings;
using Artemis.Utilities; using Artemis.Utilities;
using Caliburn.Micro; using Artemis.Utilities.Memory;
using Artemis.ViewModels.Abstract;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Artemis.Modules.Games.RocketLeague namespace Artemis.Modules.Games.RocketLeague
{ {
public class RocketLeagueViewModel : Screen public class RocketLeagueViewModel : GameViewModel
{ {
private RocketLeagueSettings _rocketLeagueSettings;
private string _versionText; private string _versionText;
public RocketLeagueViewModel(MainManager mainManager) public RocketLeagueViewModel(MainManager mainManager)
@ -17,15 +16,17 @@ namespace Artemis.Modules.Games.RocketLeague
MainManager = mainManager; MainManager = mainManager;
// Settings are loaded from file by class // Settings are loaded from file by class
RocketLeagueSettings = new RocketLeagueSettings(); GameSettings = new RocketLeagueSettings();
// Create effect model and add it to MainManager // Create effect model and add it to MainManager
RocketLeagueModel = new RocketLeagueModel(mainManager, RocketLeagueSettings); GameModel = new RocketLeagueModel(mainManager, (RocketLeagueSettings) GameSettings);
MainManager.EffectManager.EffectModels.Add(RocketLeagueModel); MainManager.EffectManager.EffectModels.Add(GameModel);
SetVersionText(); SetVersionText();
} }
public static string Name => "Rocket League";
public string VersionText public string VersionText
{ {
get { return _versionText; } get { return _versionText; }
@ -37,22 +38,8 @@ namespace Artemis.Modules.Games.RocketLeague
} }
} }
public static string Name => "Rocket League";
public MainManager MainManager { get; set; }
public RocketLeagueModel RocketLeagueModel { get; set; } public RocketLeagueModel RocketLeagueModel { get; set; }
public RocketLeagueSettings RocketLeagueSettings
{
get { return _rocketLeagueSettings; }
set
{
if (Equals(value, _rocketLeagueSettings)) return;
_rocketLeagueSettings = value;
NotifyOfPropertyChange(() => RocketLeagueSettings);
}
}
private void SetVersionText() private void SetVersionText()
{ {
if (!General.Default.EnablePointersUpdate) if (!General.Default.EnablePointersUpdate)
@ -64,32 +51,10 @@ namespace Artemis.Modules.Games.RocketLeague
Updater.GetPointers(); Updater.GetPointers();
var version = JsonConvert var version = JsonConvert
.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague) .DeserializeObject<GamePointersCollection>(Offsets.Default.RocketLeague)
.GameVersion; .GameVersion;
VersionText = $"Note: Requires patch {version}. When a new patch is released Artemis downloads " + VersionText = $"Note: Requires patch {version}. When a new patch is released Artemis downloads " +
"new pointers for the latest version (unless disabled in settings)."; "new pointers for the latest version (unless disabled in settings).";
} }
public void SaveSettings()
{
if (RocketLeagueModel == null)
return;
RocketLeagueSettings.Save();
}
public void ResetSettings()
{
// TODO: Confirmation dialog (Generic MVVM approach)
RocketLeagueSettings.ToDefault();
NotifyOfPropertyChange(() => RocketLeagueSettings);
SaveSettings();
}
public void ToggleEffect()
{
RocketLeagueModel.Enabled = _rocketLeagueSettings.Enabled;
}
} }
} }

View File

@ -2,15 +2,13 @@
namespace Artemis.Modules.Games.Witcher3 namespace Artemis.Modules.Games.Witcher3
{ {
public class Witcher3Settings : EffectSettings public class Witcher3Settings : GameSettings
{ {
public Witcher3Settings() public Witcher3Settings()
{ {
Load(); Load();
} }
public bool Enabled { get; set; }
public sealed override void Load() public sealed override void Load()
{ {
Enabled = Witcher3.Default.Enabled; Enabled = Witcher3.Default.Enabled;

View File

@ -5,65 +5,27 @@ using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Properties; using Artemis.Properties;
using Screen = Caliburn.Micro.Screen; using Artemis.ViewModels.Abstract;
namespace Artemis.Modules.Games.Witcher3 namespace Artemis.Modules.Games.Witcher3
{ {
public class Witcher3ViewModel : Screen public class Witcher3ViewModel : GameViewModel
{ {
private Witcher3Settings _witcher3Settings;
public Witcher3ViewModel(MainManager mainManager) public Witcher3ViewModel(MainManager mainManager)
{ {
MainManager = mainManager; MainManager = mainManager;
// Settings are loaded from file by class // Settings are loaded from file by class
Witcher3Settings = new Witcher3Settings(); GameSettings = new Witcher3Settings();
// Create effect model and add it to MainManager // Create effect model and add it to MainManager
Witcher3Model = new Witcher3Model(mainManager, Witcher3Settings); GameModel = new Witcher3Model(mainManager, (Witcher3Settings) GameSettings);
MainManager.EffectManager.EffectModels.Add(Witcher3Model); MainManager.EffectManager.EffectModels.Add(GameModel);
} }
public static string Name => "The Witcher 3"; public static string Name => "The Witcher 3";
public MainManager MainManager { get; set; } public async void AutoInstall()
public Witcher3Model Witcher3Model { get; set; }
public Witcher3Settings Witcher3Settings
{
get { return _witcher3Settings; }
set
{
if (Equals(value, _witcher3Settings)) return;
_witcher3Settings = value;
NotifyOfPropertyChange(() => Witcher3Settings);
}
}
public void SaveSettings()
{
if (Witcher3Model == null)
return;
Witcher3Settings.Save();
}
public void ResetSettings()
{
// TODO: Confirmation dialog (Generic MVVM approach)
Witcher3Settings.ToDefault();
NotifyOfPropertyChange(() => Witcher3Settings);
SaveSettings();
}
public void ToggleEffect()
{
Witcher3Model.Enabled = _witcher3Settings.Enabled;
}
public void AutoInstall()
{ {
// Request The Witcher 3 folder // Request The Witcher 3 folder
var dialog = new FolderBrowserDialog var dialog = new FolderBrowserDialog
@ -77,15 +39,16 @@ namespace Artemis.Modules.Games.Witcher3
// If the subfolder doesn't contain witcher3.exe, it's the wrong folder. // If the subfolder doesn't contain witcher3.exe, it's the wrong folder.
if (!File.Exists(dialog.SelectedPath + @"\bin\x64\witcher3.exe")) if (!File.Exists(dialog.SelectedPath + @"\bin\x64\witcher3.exe"))
{ {
var error = MessageBox.Show("That's not a valid Witcher 3 directory\n\n" + var retry = await
"Default directories:\n" + MainManager.DialogService.ShowQuestionMessageBox("Installation error",
"Steam: C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Witcher 3\n" + "That's not a valid Witcher 3 directory\n\n" +
"GOG: C:\\GOG Games\\The Witcher 3 Wild Hunt", "Installation error", "Default directories:\n" +
MessageBoxButtons.RetryCancel); "Steam: \\SteamApps\\common\\The Witcher 3\n" +
if (error == DialogResult.Retry) "GOG: C:\\GOG Games\\The Witcher 3 Wild Hunt\n\n" +
"Retry?");
if (retry.Value)
AutoInstall(); AutoInstall();
else return;
return;
} }
// Look for any conflicting mods // Look for any conflicting mods
@ -99,17 +62,21 @@ namespace Artemis.Modules.Games.Witcher3
// Don't trip over our own mod // Don't trip over our own mod
if (!file.Contains("modArtemis")) if (!file.Contains("modArtemis"))
{ {
MessageBox.Show("Oh no, you have a conflicting mod!\n\n" + var viewHelp = await
"Conflicting file: " + file.Remove(0, dialog.SelectedPath.Length) + MainManager.DialogService.ShowQuestionMessageBox("Conflicting mod found",
"\n\nOnce you press OK you will be taken to an instructions page.", "Oh no, you have a conflicting mod!\n\n" +
"Conflicting mod found"); "Conflicting file: " + file.Remove(0, dialog.SelectedPath.Length) +
"\n\nWould you like to view instructions on how to manually install the mod?");
if (!viewHelp.Value)
return;
// Put the mod in the documents folder instead // Put the mod in the documents folder instead
// Create the directory structure // Create the directory structure
var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis"; var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis";
if ( if (
!Directory.Exists(folder + @"\Witcher3\mods\modArtemis\content\scripts\game\player")) !Directory.Exists(folder + @"\Witcher3\mods\modArtemis\content\scripts\game\player"))
Directory.CreateDirectory(folder + @"\Witcher3\mods\modArtemis\content\scripts\game\player"); Directory.CreateDirectory(folder +
@"\Witcher3\mods\modArtemis\content\scripts\game\player");
if ( if (
!Directory.Exists(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc")) !Directory.Exists(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc"))
Directory.CreateDirectory(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc"); Directory.CreateDirectory(folder + @"\Witcher3\bin\config\r4game\user_config_matrix\pc");
@ -122,7 +89,6 @@ namespace Artemis.Modules.Games.Witcher3
Resources.playerWitcherWs); Resources.playerWitcherWs);
Process.Start(new ProcessStartInfo("https://github.com/SpoinkyNL/Artemis/wiki/The-Witcher-3")); Process.Start(new ProcessStartInfo("https://github.com/SpoinkyNL/Artemis/wiki/The-Witcher-3"));
return; return;
} }
} }
@ -140,7 +106,7 @@ namespace Artemis.Modules.Games.Witcher3
File.WriteAllText(dialog.SelectedPath + @"\mods\modArtemis\content\scripts\game\player\playerWitcher.ws", File.WriteAllText(dialog.SelectedPath + @"\mods\modArtemis\content\scripts\game\player\playerWitcher.ws",
Resources.playerWitcherWs); Resources.playerWitcherWs);
MessageBox.Show("The mod was successfully installed!", "Success"); MainManager.DialogService.ShowMessageBox("Success", "The mod was successfully installed!");
} }
} }
} }

View File

@ -2,15 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Artemis.Models namespace Artemis.Utilities.Memory
{ {
public class GamePointersCollectionModel
{
public string Game { get; set; }
public string GameVersion { get; set; }
public List<GamePointer> GameAddresses { get; set; }
}
public class GamePointer public class GamePointer
{ {
public string Description { get; set; } public string Description { get; set; }
@ -23,4 +16,11 @@ namespace Artemis.Models
(current, offset) => current + $"+{offset.ToString("X")}"); (current, offset) => current + $"+{offset.ToString("X")}");
} }
} }
public class GamePointersCollection
{
public string Game { get; set; }
public string GameVersion { get; set; }
public List<GamePointer> GameAddresses { get; set; }
}
} }

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Artemis.Models; using Artemis.Models;
using Artemis.Services; using Artemis.Services;
using Artemis.Settings; using Artemis.Settings;
using Artemis.Utilities.Memory;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@ -86,7 +87,7 @@ namespace Artemis.Utilities
"https://raw.githubusercontent.com/SpoinkyNL/Artemis/master/pointers.json?random=" + rand.Next()); "https://raw.githubusercontent.com/SpoinkyNL/Artemis/master/pointers.json?random=" + rand.Next());
// Get a list of pointers // Get a list of pointers
var pointers = JsonConvert.DeserializeObject<List<GamePointersCollectionModel>>(json); var pointers = JsonConvert.DeserializeObject<List<GamePointersCollection>>(json);
// Assign each pointer to the settings file // Assign each pointer to the settings file
var rlPointers = JsonConvert.SerializeObject(pointers.FirstOrDefault(p => p.Game == "RocketLeague")); var rlPointers = JsonConvert.SerializeObject(pointers.FirstOrDefault(p => p.Game == "RocketLeague"));
if (rlPointers != null) if (rlPointers != null)

View File

@ -61,9 +61,15 @@ namespace Artemis.ViewModels.Abstract
MainManager.EffectManager.ChangeEffect(EffectModel, true); MainManager.EffectManager.ChangeEffect(EffectModel, true);
} }
public void ResetSettings() public async void ResetSettings()
{ {
// TODO: Confirmation dialog (Generic MVVM approach) var resetConfirm = await
MainManager.DialogService.ShowQuestionMessageBox("Reset effect settings",
"Are you sure you wish to reset this effect's settings? \nAny changes you made will be lost.");
if (!resetConfirm.Value)
return;
EffectSettings.ToDefault(); EffectSettings.ToDefault();
NotifyOfPropertyChange(() => EffectSettings); NotifyOfPropertyChange(() => EffectSettings);

View File

@ -0,0 +1,57 @@
using Artemis.Managers;
using Artemis.Models;
using Caliburn.Micro;
namespace Artemis.ViewModels.Abstract
{
public abstract class GameViewModel : Screen
{
private GameSettings _gameSettings;
public GameModel GameModel { get; set; }
public MainManager MainManager { get; set; }
public GameSettings GameSettings
{
get { return _gameSettings; }
set
{
if (Equals(value, _gameSettings)) return;
_gameSettings = value;
NotifyOfPropertyChange(() => GameSettings);
}
}
public bool GameEnabled => MainManager.EffectManager.ActiveEffect == GameModel;
public void ToggleEffect()
{
GameModel.Enabled = GameSettings.Enabled;
}
public void SaveSettings()
{
GameSettings?.Save();
if (!GameEnabled)
return;
// Restart the game if it's currently running to apply settings.
MainManager.EffectManager.ChangeEffect(GameModel, true);
}
public async void ResetSettings()
{
var resetConfirm = await
MainManager.DialogService.ShowQuestionMessageBox("Reset effect settings",
"Are you sure you wish to reset this effect's settings? \nAny changes you made will be lost.");
if (!resetConfirm.Value)
return;
GameSettings.ToDefault();
NotifyOfPropertyChange(() => GameSettings);
SaveSettings();
}
}
}