Skip to content

Commit

Permalink
Fixed #4 - Added a button to restore the default FOV
Browse files Browse the repository at this point in the history
  • Loading branch information
trixnz committed Feb 2, 2016
1 parent 0d59dc9 commit 8daeee4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions JustFOV/JustFOV.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Util\RelayCommand.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
2 changes: 2 additions & 0 deletions JustFOV/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@

<TextBox Grid.Row="1" Grid.Column="0" Margin="5" Text="{Binding Fov, Mode=TwoWay}" x:Name="FOVText"></TextBox>
<Button Grid.Row="1" Grid.Column="1" Margin="5" Content="Set FOV" x:Name="SetFov"></Button>

<Button Grid.Row="1" Grid.Column="1" Margin="5,26.667,4.667,-16.333" Command="{Binding RestoreDefaultFOV}" Content="Default" />
</Grid>
</Window>
16 changes: 15 additions & 1 deletion JustFOV/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Runtime.CompilerServices;
using System.Windows;
using JustFOV.Annotations;
using JustFOV.Util;
using System.Windows.Input;

namespace JustFOV
{
Expand All @@ -15,6 +17,9 @@ public class Model : INotifyPropertyChanged

private readonly byte[] _originalCallBytes;

private ICommand _restoreDefaultFOVCommand;
private float _defaultFOV = 34.89f;

public Model()
{
var processes = Process.GetProcessesByName("JustCause3");
Expand Down Expand Up @@ -48,9 +53,18 @@ public float Fov
get { return GetFov()*RadToDeg; }
set
{
PatchFov(value*DegToRad);

OnPropertyChanged();
}
}

PatchFov(value*DegToRad);
public ICommand RestoreDefaultFOV
{
get
{
return _restoreDefaultFOVCommand ??
(_restoreDefaultFOVCommand = new RelayCommand(p => Fov = _defaultFOV));
}
}

Expand Down
54 changes: 54 additions & 0 deletions JustFOV/Util/RelayCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Diagnostics;
using System.Windows.Input;

namespace JustFOV.Util
{
public class RelayCommand : ICommand
{
#region Fields

readonly Action<object> _execute;
readonly Predicate<object> _canExecute;

#endregion // Fields

#region Constructors

public RelayCommand(Action<object> execute)
: this(execute, null)
{
}

public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");

_execute = execute;
_canExecute = canExecute;
}
#endregion // Constructors

#region ICommand Members

[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}

public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}

public void Execute(object parameter)
{
_execute(parameter);
}

#endregion // ICommand Members
}
}

0 comments on commit 8daeee4

Please sign in to comment.