mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
CpuStatus binding refactors. Target usage slider
This commit is contained in:
parent
75c48e5fe2
commit
ddbd1ef754
@ -19,7 +19,7 @@ using Wabbajack.UI;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class CompilerVM : ViewModel, IBackNavigatingVM
|
||||
public class CompilerVM : ViewModel, IBackNavigatingVM, ICpuStatusVM
|
||||
{
|
||||
public MainWindowVM MWVM { get; }
|
||||
|
||||
|
@ -25,7 +25,7 @@ using Wabbajack.UI;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class InstallerVM : ViewModel, IBackNavigatingVM
|
||||
public class InstallerVM : ViewModel, IBackNavigatingVM, ICpuStatusVM
|
||||
{
|
||||
public SlideShow Slideshow { get; }
|
||||
|
||||
|
16
Wabbajack/View Models/Interfaces/ICpuStatusVM.cs
Normal file
16
Wabbajack/View Models/Interfaces/ICpuStatusVM.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DynamicData.Binding;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public interface ICpuStatusVM : IReactiveObject
|
||||
{
|
||||
ObservableCollectionExtended<CPUDisplayVM> StatusList { get; }
|
||||
MainWindowVM MWVM { get; }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<UserControl
|
||||
<local:UserControlRx
|
||||
x:Class="Wabbajack.CpuView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
@ -8,42 +8,73 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:TypeArguments="local:ICpuStatusVM"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<Grid x:Name="ControlGrid" Background="Transparent">
|
||||
<Rectangle Fill="{StaticResource HeatedBorderBrush}" Opacity="{Binding ProgressPercent, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
|
||||
<ListBox
|
||||
HorizontalContentAlignment="Stretch"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="1"
|
||||
ItemsSource="{Binding StatusList}"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Background="{StaticResource WindowBackgroundBrush}">
|
||||
<mahapps:MetroProgressBar
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Foreground="{StaticResource DarkPrimaryVariantBrush}"
|
||||
Maximum="1"
|
||||
Opacity="{Binding ProgressPercent, Mode=OneWay}"
|
||||
Value="{Binding ProgressPercent, Mode=OneWay}" />
|
||||
<Grid Height="1" VerticalAlignment="Bottom">
|
||||
<Border BorderBrush="Transparent" BorderThickness="1" />
|
||||
<Grid Margin="1" Background="{StaticResource DarkBackgroundBrush}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox
|
||||
x:Name="CpuListControl"
|
||||
Grid.Row="0"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Background="{StaticResource WindowBackgroundBrush}">
|
||||
<mahapps:MetroProgressBar
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Foreground="{StaticResource DarkSecondaryBrush}"
|
||||
Foreground="{StaticResource DarkPrimaryVariantBrush}"
|
||||
Maximum="1"
|
||||
Opacity="{Binding ProgressPercent, Mode=OneWay}"
|
||||
Value="{Binding ProgressPercent, Mode=OneWay}" />
|
||||
<Grid Height="1" VerticalAlignment="Bottom">
|
||||
<mahapps:MetroProgressBar
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Foreground="{StaticResource DarkSecondaryBrush}"
|
||||
Maximum="1"
|
||||
Value="{Binding ProgressPercent, Mode=OneWay}" />
|
||||
</Grid>
|
||||
<TextBlock
|
||||
Margin="0,0,0,2"
|
||||
Text="{Binding Msg, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap"
|
||||
ToolTip="{Binding Msg, Mode=OneWay}" />
|
||||
</Grid>
|
||||
<TextBlock
|
||||
Margin="0,0,0,2"
|
||||
Text="{Binding Msg, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap"
|
||||
ToolTip="{Binding Msg, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Border
|
||||
x:Name="SettingsBar"
|
||||
Grid.Row="1"
|
||||
Background="{StaticResource BackgroundBrush}"
|
||||
BorderBrush="{StaticResource ButtonNormalBorder}"
|
||||
BorderThickness="0,1,0,0">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Margin="5,0"
|
||||
VerticalAlignment="Center"
|
||||
Text="Percent Usage" />
|
||||
<Slider
|
||||
x:Name="TargetPercentageSlider"
|
||||
Grid.Column="1"
|
||||
Margin="2,0,6,0"
|
||||
Maximum="1"
|
||||
Minimum="0.1"
|
||||
Orientation="Horizontal" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</local:UserControlRx>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@ -12,13 +13,18 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Lib;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CpuView.xaml
|
||||
/// </summary>
|
||||
public partial class CpuView : UserControl
|
||||
public partial class CpuView : UserControlRx<ICpuStatusVM>
|
||||
{
|
||||
public double ProgressPercent
|
||||
{
|
||||
@ -28,9 +34,39 @@ namespace Wabbajack
|
||||
public static readonly DependencyProperty ProgressPercentProperty = DependencyProperty.Register(nameof(ProgressPercent), typeof(double), typeof(CpuView),
|
||||
new FrameworkPropertyMetadata(default(double)));
|
||||
|
||||
public MainSettings SettingsHook
|
||||
{
|
||||
get => (MainSettings)GetValue(SettingsHookProperty);
|
||||
set => SetValue(SettingsHookProperty, value);
|
||||
}
|
||||
public static readonly DependencyProperty SettingsHookProperty = DependencyProperty.Register(nameof(SettingsHook), typeof(MainSettings), typeof(CpuView),
|
||||
new FrameworkPropertyMetadata(default(SettingsVM)));
|
||||
|
||||
private bool _ShowingSettings;
|
||||
public bool ShowingSettings { get => _ShowingSettings; set => this.RaiseAndSetIfChanged(ref _ShowingSettings, value); }
|
||||
|
||||
public CpuView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.WhenActivated(disposable =>
|
||||
{
|
||||
Observable.CombineLatest(
|
||||
this.WhenAny(x => x.ControlGrid.IsMouseOver),
|
||||
this.WhenAny(x => x.SettingsHook.Performance.Manual)
|
||||
.StartWith(true),
|
||||
resultSelector: (over, manual) => over && !manual)
|
||||
.Subscribe(showing =>
|
||||
{
|
||||
SettingsBar.Visibility = showing ? Visibility.Visible : Visibility.Collapsed;
|
||||
})
|
||||
.DisposeWith(disposable);
|
||||
|
||||
this.OneWayBindStrict(this.ViewModel, x => x.StatusList, x => x.CpuListControl.ItemsSource)
|
||||
.DisposeWith(disposable);
|
||||
|
||||
this.BindStrict(this.ViewModel, x => x.MWVM.Settings.Performance.TargetUsage, x => x.TargetPercentageSlider.Value)
|
||||
.DisposeWith(disposable);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,6 +307,8 @@
|
||||
<local:CpuView
|
||||
Grid.Column="2"
|
||||
ProgressPercent="{Binding PercentCompleted, Mode=OneWay}"
|
||||
SettingsHook="{Binding MWVM.Settings}"
|
||||
ViewModel="{Binding}"
|
||||
Visibility="{Binding ActiveGlobalUserIntervention, Converter={StaticResource IsNotNullVisibilityConverter}, ConverterParameter=False}" />
|
||||
<local:AttentionBorder Grid.Column="2" Visibility="{Binding ActiveGlobalUserIntervention, Converter={StaticResource IsNotNullVisibilityConverter}}">
|
||||
<local:AttentionBorder.DisplayContent>
|
||||
|
@ -422,6 +422,8 @@
|
||||
<local:CpuView
|
||||
Grid.Column="2"
|
||||
ProgressPercent="{Binding PercentCompleted, Mode=OneWay}"
|
||||
ViewModel="{Binding}"
|
||||
SettingsHook="{Binding MWVM.Settings}"
|
||||
Visibility="{Binding ActiveGlobalUserIntervention, Converter={StaticResource IsNotNullVisibilityConverter}, ConverterParameter=False}" />
|
||||
<local:AttentionBorder Grid.Column="2" Visibility="{Binding ActiveGlobalUserIntervention, Converter={StaticResource IsNotNullVisibilityConverter}}">
|
||||
<local:AttentionBorder.DisplayContent>
|
||||
|
@ -40,4 +40,28 @@ namespace Wabbajack
|
||||
control.RaisePropertyChanged(e.Property.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public class UserControlRx<TViewModel> : ReactiveUserControl<TViewModel>, IReactiveObject
|
||||
where TViewModel : class
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public event PropertyChangingEventHandler PropertyChanging;
|
||||
|
||||
public void RaisePropertyChanging(PropertyChangingEventArgs args)
|
||||
{
|
||||
PropertyChanging?.Invoke(this, args);
|
||||
}
|
||||
|
||||
public void RaisePropertyChanged(PropertyChangedEventArgs args)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
protected static void WireNotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(d is UserControlRx control)) return;
|
||||
if (Equals(e.OldValue, e.NewValue)) return;
|
||||
control.RaisePropertyChanged(e.Property.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,6 +180,7 @@
|
||||
<Compile Include="Converters\CommandConverter.cs" />
|
||||
<Compile Include="Converters\ConverterRegistration.cs" />
|
||||
<Compile Include="Extensions\IViewForExt.cs" />
|
||||
<Compile Include="View Models\Interfaces\ICpuStatusVM.cs" />
|
||||
<Compile Include="Views\Settings\LoginItemView.xaml.cs">
|
||||
<DependentUpon>LoginItemView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
Loading…
Reference in New Issue
Block a user