feat: add converter for visibility
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace BallanceTasEditor.Frontend.Converters {
|
||||||
|
|
||||||
|
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||||
|
public class IsVisibleToVisibilityConverter : IValueConverter {
|
||||||
|
public static readonly IsVisibleToVisibilityConverter Instance = new IsVisibleToVisibilityConverter();
|
||||||
|
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||||
|
var susBool = value as bool?;
|
||||||
|
if (susBool is null) {
|
||||||
|
return Binding.DoNothing;
|
||||||
|
} else {
|
||||||
|
return susBool.Value ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||||
|
return Binding.DoNothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,6 @@ namespace BallanceTasEditor.Frontend.ViewModels {
|
|||||||
#region File Operation
|
#region File Operation
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
[NotifyPropertyChangedFor(nameof(WindowTitle))]
|
|
||||||
private Models.TasFile tasFile;
|
private Models.TasFile tasFile;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
[NotifyPropertyChangedFor(nameof(WindowTitle))]
|
[NotifyPropertyChangedFor(nameof(WindowTitle))]
|
||||||
@@ -42,11 +41,16 @@ namespace BallanceTasEditor.Frontend.ViewModels {
|
|||||||
private void TasFile_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) {
|
private void TasFile_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) {
|
||||||
// YYC MARK:
|
// YYC MARK:
|
||||||
// Due to the shitty limit of MVVM Toolkit,
|
// Due to the shitty limit of MVVM Toolkit,
|
||||||
// I was forced trigger these command manually.
|
// I was forced trigger these manually.
|
||||||
|
OnPropertyChanged(nameof(IsVisibleForLoadedFile));
|
||||||
|
OnPropertyChanged(nameof(WindowTitle));
|
||||||
|
OnPropertyChanged(nameof(IsVisibleForNotLoadedFile));
|
||||||
|
|
||||||
NewFileCommand.NotifyCanExecuteChanged();
|
NewFileCommand.NotifyCanExecuteChanged();
|
||||||
OpenFileCommand.NotifyCanExecuteChanged();
|
OpenFileCommand.NotifyCanExecuteChanged();
|
||||||
SaveFileCommand.NotifyCanExecuteChanged();
|
SaveFileCommand.NotifyCanExecuteChanged();
|
||||||
SaveFileAsCommand.NotifyCanExecuteChanged();
|
SaveFileAsCommand.NotifyCanExecuteChanged();
|
||||||
|
SaveFileThenRunGameCommand.NotifyCanExecuteChanged();
|
||||||
CloseFileCommand.NotifyCanExecuteChanged();
|
CloseFileCommand.NotifyCanExecuteChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +163,19 @@ namespace BallanceTasEditor.Frontend.ViewModels {
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Special Save with Running Game
|
||||||
|
|
||||||
|
[RelayCommand(CanExecute = nameof(CanSaveFileThenRunGame))]
|
||||||
|
private void SaveFileThenRunGame() {
|
||||||
|
SaveFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanSaveFileThenRunGame() {
|
||||||
|
return CanSaveFile() && true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Exit Stuff
|
#region Exit Stuff
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
@@ -378,6 +395,14 @@ namespace BallanceTasEditor.Frontend.ViewModels {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsVisibleForLoadedFile {
|
||||||
|
get => TasFile.IsFileLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsVisibleForNotLoadedFile {
|
||||||
|
get => TasFile.IsFileNotLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:BallanceTasEditor.Frontend.Views"
|
xmlns:local="clr-namespace:BallanceTasEditor.Frontend.Views"
|
||||||
xmlns:vm="clr-namespace:BallanceTasEditor.Frontend.ViewModels"
|
xmlns:vm="clr-namespace:BallanceTasEditor.Frontend.ViewModels"
|
||||||
|
xmlns:conveter="clr-namespace:BallanceTasEditor.Frontend.Converters"
|
||||||
xmlns:widget="clr-namespace:BallanceTasEditor.Frontend.Widgets"
|
xmlns:widget="clr-namespace:BallanceTasEditor.Frontend.Widgets"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DataContext="{d:DesignInstance vm:MainWindow}"
|
d:DataContext="{d:DesignInstance vm:MainWindow}"
|
||||||
WindowStartupLocation="CenterScreen"
|
WindowStartupLocation="CenterScreen"
|
||||||
Title="{Binding WindowTitle, Mode=OneWay}" Height="600" Width="800" Icon="/Frontend/Assets/App.ico">
|
Title="{Binding WindowTitle, Mode=OneWay}" Height="800" Width="600" Icon="/Frontend/Assets/App.ico">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="auto"/>
|
|
||||||
<RowDefinition Height="auto"/>
|
<RowDefinition Height="auto"/>
|
||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
<RowDefinition Height="auto"/>
|
<RowDefinition Height="auto"/>
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
<Separator/>
|
<Separator/>
|
||||||
<MenuItem Header="_Save File" Icon="{StaticResource IconSaveFile}" InputGestureText="Ctrl+S" Command="{Binding SaveFileCommand}"/>
|
<MenuItem Header="_Save File" Icon="{StaticResource IconSaveFile}" InputGestureText="Ctrl+S" Command="{Binding SaveFileCommand}"/>
|
||||||
<MenuItem Header="Save File as ..." Icon="{StaticResource IconSaveFileAs}" Command="{Binding SaveFileAsCommand}"/>
|
<MenuItem Header="Save File as ..." Icon="{StaticResource IconSaveFileAs}" Command="{Binding SaveFileAsCommand}"/>
|
||||||
<MenuItem Header="Save File then _Run Game" Icon="{StaticResource IconSaveFileThenRunGame}" InputGestureText="B"/>
|
<MenuItem Header="Save File then _Run Game" Icon="{StaticResource IconSaveFileThenRunGame}" InputGestureText="B" Command="{Binding SaveFileThenRunGameCommand}"/>
|
||||||
<Separator/>
|
<Separator/>
|
||||||
<MenuItem Header="Close File" Icon="{StaticResource IconCloseFile}" Command="{Binding CloseFileCommand}"/>
|
<MenuItem Header="Close File" Icon="{StaticResource IconCloseFile}" Command="{Binding CloseFileCommand}"/>
|
||||||
<MenuItem Header="Exit" Icon="{StaticResource IconExit}" Command="{Binding ExitCommand}"/>
|
<MenuItem Header="Exit" Icon="{StaticResource IconExit}" Command="{Binding ExitCommand}"/>
|
||||||
@@ -82,7 +82,23 @@
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
<Grid Grid.Row="1">
|
<Grid Grid.Row="1" Visibility="{Binding IsVisibleForNotLoadedFile, Mode=OneWay, Converter={x:Static conveter:IsVisibleToVisibilityConverter.Instance}}">
|
||||||
|
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" AllowDrop="True">
|
||||||
|
<Rectangle StrokeThickness="4" Stroke="Gray" StrokeDashArray="4 4" Fill="Transparent"/>
|
||||||
|
<StackPanel Orientation="Horizontal" Margin="20">
|
||||||
|
<Image Source="/Frontend/Assets/OpenFile.ico" Width="24" Height="24" Margin="5" VerticalAlignment="Center"/>
|
||||||
|
<TextBlock Margin="5" Text="Create, Open or Drop a TAS File in There for Editing" Foreground="Gray" FontSize="16" VerticalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid Grid.Row="1" Visibility="{Binding IsVisibleForLoadedFile, Mode=OneWay, Converter={x:Static conveter:IsVisibleToVisibilityConverter.Instance}}">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="auto"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Grid Grid.Row="0">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
<ColumnDefinition Width="auto"/>
|
<ColumnDefinition Width="auto"/>
|
||||||
@@ -91,30 +107,26 @@
|
|||||||
<StackPanel Orientation="Horizontal" Grid.Column="0">
|
<StackPanel Orientation="Horizontal" Grid.Column="0">
|
||||||
<widget:IconButton ButtonText="Select Mode"
|
<widget:IconButton ButtonText="Select Mode"
|
||||||
ButtonIcon="/Frontend/Assets/SelectMode.ico"
|
ButtonIcon="/Frontend/Assets/SelectMode.ico"
|
||||||
Margin="5" Padding="5"/>
|
Margin="5" Padding="5"
|
||||||
|
Command="{Binding SelectModeCommand}"/>
|
||||||
<widget:IconButton ButtonText="Fill Mode"
|
<widget:IconButton ButtonText="Fill Mode"
|
||||||
ButtonIcon="/Frontend/Assets/FillMode.ico"
|
ButtonIcon="/Frontend/Assets/FillMode.ico"
|
||||||
Margin="5" Padding="5"/>
|
Margin="5" Padding="5"
|
||||||
|
Command="{Binding FillModeCommand}"/>
|
||||||
<widget:IconButton ButtonText="Draw Mode"
|
<widget:IconButton ButtonText="Draw Mode"
|
||||||
ButtonIcon="/Frontend/Assets/DrawMode.ico"
|
ButtonIcon="/Frontend/Assets/DrawMode.ico"
|
||||||
Margin="5" Padding="5"/>
|
Margin="5" Padding="5"
|
||||||
|
Command="{Binding DrawModeCommand}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<widget:IconButton ButtonText="Save File then Run Game"
|
<widget:IconButton ButtonText="Save File then Run Game"
|
||||||
ButtonIcon="/Frontend/Assets/SaveFileThenRunGame.ico"
|
ButtonIcon="/Frontend/Assets/SaveFileThenRunGame.ico"
|
||||||
Grid.Column="1" Margin="5" Padding="5"/>
|
Grid.Column="1" Margin="5" Padding="5"
|
||||||
|
Command="{Binding SaveFileThenRunGameCommand}"/>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid Grid.Row="2">
|
<Grid Grid.Row="1">
|
||||||
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" AllowDrop="True">
|
|
||||||
<Rectangle StrokeThickness="4" Stroke="Gray" StrokeDashArray="4 4" Fill="Transparent"/>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="20">
|
|
||||||
<Image Source="/Frontend/Assets/OpenFile.ico" Width="24" Height="24" Margin="5" VerticalAlignment="Center"/>
|
|
||||||
<TextBlock Margin="5" Text="Create, Open or Drop a TAS File in There for Editing" Foreground="Gray" FontSize="16" VerticalAlignment="Center"/>
|
|
||||||
</StackPanel>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<local:TasViewer>
|
<local:TasViewer>
|
||||||
<local:TasViewer.ContextMenu>
|
<local:TasViewer.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
@@ -152,8 +164,9 @@
|
|||||||
</local:TasViewer.ContextMenu>
|
</local:TasViewer.ContextMenu>
|
||||||
</local:TasViewer>
|
</local:TasViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<StatusBar Grid.Row="3">
|
<StatusBar Grid.Row="2">
|
||||||
<!-- 这玩意要逆序排列才能达到我想要的需求也是奇葩 -->
|
<!-- 这玩意要逆序排列才能达到我想要的需求也是奇葩 -->
|
||||||
<StatusBarItem Content="v2.0 stable" DockPanel.Dock="Right" Foreground="Gray" FontStyle="Italic"/>
|
<StatusBarItem Content="v2.0 stable" DockPanel.Dock="Right" Foreground="Gray" FontStyle="Italic"/>
|
||||||
<Separator DockPanel.Dock="Right"/>
|
<Separator DockPanel.Dock="Right"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user