diff --git a/BallanceTasEditor/BallanceTasEditor/Frontend/Converters/VisibilityConverter.cs b/BallanceTasEditor/BallanceTasEditor/Frontend/Converters/VisibilityConverter.cs new file mode 100644 index 0000000..32c5867 --- /dev/null +++ b/BallanceTasEditor/BallanceTasEditor/Frontend/Converters/VisibilityConverter.cs @@ -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; + } + } +} diff --git a/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs b/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs index 2211655..280c7cd 100644 --- a/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs +++ b/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/MainWindow.cs @@ -33,7 +33,6 @@ namespace BallanceTasEditor.Frontend.ViewModels { #region File Operation [ObservableProperty] - [NotifyPropertyChangedFor(nameof(WindowTitle))] private Models.TasFile tasFile; [ObservableProperty] [NotifyPropertyChangedFor(nameof(WindowTitle))] @@ -42,11 +41,16 @@ namespace BallanceTasEditor.Frontend.ViewModels { private void TasFile_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) { // YYC MARK: // 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(); OpenFileCommand.NotifyCanExecuteChanged(); SaveFileCommand.NotifyCanExecuteChanged(); SaveFileAsCommand.NotifyCanExecuteChanged(); + SaveFileThenRunGameCommand.NotifyCanExecuteChanged(); CloseFileCommand.NotifyCanExecuteChanged(); } @@ -159,6 +163,19 @@ namespace BallanceTasEditor.Frontend.ViewModels { #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 [RelayCommand] @@ -378,6 +395,14 @@ namespace BallanceTasEditor.Frontend.ViewModels { } } + public bool IsVisibleForLoadedFile { + get => TasFile.IsFileLoaded; + } + + public bool IsVisibleForNotLoadedFile { + get => TasFile.IsFileNotLoaded; + } + #endregion } diff --git a/BallanceTasEditor/BallanceTasEditor/Frontend/Views/MainWindow.xaml b/BallanceTasEditor/BallanceTasEditor/Frontend/Views/MainWindow.xaml index bd244c0..58a37dc 100644 --- a/BallanceTasEditor/BallanceTasEditor/Frontend/Views/MainWindow.xaml +++ b/BallanceTasEditor/BallanceTasEditor/Frontend/Views/MainWindow.xaml @@ -5,15 +5,15 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:BallanceTasEditor.Frontend.Views" xmlns:vm="clr-namespace:BallanceTasEditor.Frontend.ViewModels" + xmlns:conveter="clr-namespace:BallanceTasEditor.Frontend.Converters" xmlns:widget="clr-namespace:BallanceTasEditor.Frontend.Widgets" mc:Ignorable="d" d:DataContext="{d:DesignInstance vm:MainWindow}" 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"> + - @@ -45,14 +45,14 @@ - + - + @@ -82,31 +82,7 @@ - - - - - - - - - - - - - - - - - + @@ -114,46 +90,83 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +