From 396a72ede8a57500c86ea41e2ca51e0fcc46f4d5 Mon Sep 17 00:00:00 2001 From: DarkShadow Date: Wed, 9 Oct 2024 01:37:09 +0300 Subject: [PATCH] Add new message box, do some cleanup, add PS Vita in swizzling options --- .../GUI/ViewModels/MainViewModel.cs | 63 +++++++++++-------- .../Utilities/MessageBoxes.cs | 28 +++++++++ 2 files changed, 65 insertions(+), 26 deletions(-) diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs index c0937a6..bddb7b2 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs @@ -19,7 +19,6 @@ using MsBox.Avalonia.Enums; using IImage = Avalonia.Media.IImage; using TelltaleTextureTool.DirectX; -using Avalonia.Data; using System.ComponentModel; using Avalonia.Data.Converters; using System.ComponentModel.DataAnnotations; @@ -98,7 +97,6 @@ public partial class MainViewModel : ViewModelBase private readonly ObservableCollection _otherTypes = [ - new FormatItemViewModel { Name = "DDS", ItemStatus = true }, new FormatItemViewModel { Name = "D3DTX", ItemStatus = true } ]; @@ -130,12 +128,6 @@ public partial class MainViewModel : ViewModelBase Patterns = ["*.ttarch", "*.ttarch2"] }; - [ObservableProperty] - private ObservableCollection? _columns = new ObservableCollection() - { - new DataGridTextColumn(){Header = "1", Binding = new Binding("KrnListValueId"){ Source = _workingDirectoryFiles }}, - }; - private readonly MainManager mainManager = MainManager.GetInstance(); private readonly Uri _assetsUri = new("avares://TelltaleTextureTool/Assets/"); private static readonly string ErrorSvgFilename = "error.svg"; @@ -147,17 +139,16 @@ public partial class MainViewModel : ViewModelBase ImageEffect.DEFAULT, ImageEffect.SWIZZLE_ABGR, ImageEffect.RESTORE_Z, - ImageEffect.REMOVE_Z]; + ImageEffect.REMOVE_Z + ]; public T3PlatformType[] SwizzlePlatforms { get; } = [ T3PlatformType.ePlatform_All, T3PlatformType.ePlatform_Xbox, - T3PlatformType.ePlatform_XBOne, T3PlatformType.ePlatform_PS3, T3PlatformType.ePlatform_PS4, T3PlatformType.ePlatform_NX, - T3PlatformType.ePlatform_Wii, - T3PlatformType.ePlatform_WiiU, + T3PlatformType.ePlatform_Vita ]; public TelltaleToolGame[] Games { get; } = [ @@ -170,6 +161,7 @@ public partial class MainViewModel : ViewModelBase TelltaleToolGame.BONE_THE_GREAT_COW_RACE, // LV11 TelltaleToolGame.CSI_HARD_EVIDENCE, // LV10 TelltaleToolGame.SAM_AND_MAX_BEYOND_TIME_AND_SPACE_OG, // LV9 + TelltaleToolGame.SAM_AND_MAX_BEYOND_TIME_AND_SPACE_NEW, TelltaleToolGame.STRONG_BADS_COOL_GAME_FOR_ATTRACTIVE_PEOPLE_101, // LV8 TelltaleToolGame.STRONG_BADS_COOL_GAME_FOR_ATTRACTIVE_PEOPLE_102, // LV8 TelltaleToolGame.STRONG_BADS_COOL_GAME_FOR_ATTRACTIVE_PEOPLE_103, // LV7 @@ -223,9 +215,8 @@ public partial class MainViewModel : ViewModelBase [ObservableProperty] private bool _chooseOutputDirectoryCheckboxStatus; [ObservableProperty] private bool _isMipSliderVisible; [ObservableProperty] private bool _isFaceSliderVisible; - [ObservableProperty] private bool _isImageInformationVisible; - [ObservableProperty] private bool _isDebugInformationVisible; - + [ObservableProperty] private bool _isImageInformationVisible = true; + [ObservableProperty] private bool _isDebugInformationVisible = false; [ObservableProperty] private string _debugInfo = string.Empty; [ObservableProperty] private uint _mipValue; [ObservableProperty] private uint _faceValue; @@ -233,7 +224,7 @@ public partial class MainViewModel : ViewModelBase [ObservableProperty] private uint _maxFaceCount; [ObservableProperty] private static ObservableCollection _workingDirectoryFiles = []; [ObservableProperty] private ObservableCollection _archiveFiles = []; - [ObservableProperty] private ImageData _imageData = new ImageData(); + [ObservableProperty] private ImageData _imageData = new(); [ObservableProperty] [NotifyCanExecuteChangedFor("ResetPanAndZoomCommand")] @@ -262,7 +253,7 @@ public MainViewModel() { Source = SvgSource.Load(ErrorSvgFilename, _assetsUri) }; - ImageAdvancedOptions = new ImageAdvancedOptions(this); + ImageAdvancedOptions = new ImageAdvancedOptions(this); } #region MAIN MENU BUTTONS ACTIONS @@ -649,7 +640,17 @@ public async Task ConvertButton_Click() } else if (Directory.Exists(textureFilePath)) { - Converter.ConvertBulk(textureFilePath, outputDirectoryPath, ImageAdvancedOptions, oldTextureType, newTextureType); + if (!ChooseOutputDirectoryCheckboxStatus) + { + outputDirectoryPath = textureFilePath; + } + + if (Converter.ConvertBulk(textureFilePath, outputDirectoryPath, ImageAdvancedOptions, oldTextureType, newTextureType)) + { + var mainWindow = GetMainWindow(); + var messageBox = MessageBoxes.GetSuccessBox("All textures have been converted successfully!"); + await MessageBoxManager.GetMessageBoxStandard(messageBox).ShowWindowDialogAsync(mainWindow); + } } } catch (Exception ex) @@ -659,7 +660,7 @@ public async Task ConvertButton_Click() var messageBox = MessageBoxes.GetErrorBox(ex.Message); await MessageBoxManager.GetMessageBoxStandard(messageBox).ShowWindowDialogAsync(mainWindow); - Logger.Instance().Log(ex); + Logger.Log(ex); } finally { @@ -713,7 +714,7 @@ public async Task DebugButton_Click() } else if (workingDirectoryFile.FileType == ".dds") { - debugInfo = DDS_DirectXTexNet.GetDDSDebugInfo(textureFilePath); + debugInfo = TextureManager.GetDDSDebugInfo(textureFilePath); } else { @@ -736,7 +737,7 @@ public async Task DebugButton_Click() /// private async Task UpdateUiAsync() { - // update our texture directory UI + // Update our texture directory UI try { DirectoryPath = mainManager.GetWorkingDirectoryPath(); @@ -777,6 +778,7 @@ public async Task ReturnDirectory_Click() if (Directory.GetParent(DirectoryPath) == null) return; WorkingDirectoryFiles.Clear(); await mainManager.SetWorkingDirectoryPath(Directory.GetParent(DirectoryPath).ToString()); + DataGridSelectedItem = null; } catch (Exception ex) { @@ -799,7 +801,7 @@ public async Task ContextMenuRefreshDirectoryCommand() #region HELPERS - private Window GetMainWindow() + private static Window GetMainWindow() { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) return lifetime.MainWindow; @@ -848,12 +850,12 @@ private void ChangeComboBoxItemsByItemExtension(string itemExtension) if (itemExtension != string.Empty) { - SelectedFromFormat = _folderTypes[GetFormatPosition(itemExtension)]; - IsFromSelectedComboboxEnable = false; + SelectedFromFormat = _folderTypes[GetFormatPosition(itemExtension)]; + IsFromSelectedComboboxEnable = false; } ConvertButtonStatus = true; - + // SelectedComboboxIndex = GetFormatPosition(itemExtension); // There is an issue in Avalonia relating to dynamic sources and binding indexes. // Github issue: https://github.com/AvaloniaUI/Avalonia/issues/13736 @@ -1001,6 +1003,14 @@ private void ResetUIElements() Source = SvgSource.Load(ErrorSvgFilename, _assetsUri) }; ImageNamePreview = string.Empty; + + ImageData.Reset(); + + MaxMipCount = ImageData.MaxMip; + MaxFaceCount = ImageData.MaxFace; + + IsFaceSliderVisible = MaxFaceCount != 0; + IsMipSliderVisible = MaxMipCount != 0; } [RelayCommand] @@ -1128,7 +1138,7 @@ protected override async void OnPropertyChanged(PropertyChangedEventArgs e) } } - private Task OpenFileExplorer(string path) + private static Task OpenFileExplorer(string path) { MainManager.OpenFileExplorer(path); return Task.CompletedTask; @@ -1144,6 +1154,7 @@ private async Task HandleImagePreviewErrorAsync(Exception ex) { await HandleExceptionAsync("Error during previewing image.\nError message: " + ex.Message); ImagePreview = new SvgImage { Source = SvgSource.Load(ErrorSvgFilename, _assetsUri) }; + ImageProperties = new ImageProperties(); } private async Task HandleExceptionAsync(string message) diff --git a/TelltaleTextureTool/TelltaleTextureTool/Utilities/MessageBoxes.cs b/TelltaleTextureTool/TelltaleTextureTool/Utilities/MessageBoxes.cs index 1cf3065..4a879b5 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/Utilities/MessageBoxes.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/Utilities/MessageBoxes.cs @@ -15,6 +15,34 @@ public static class MessageBoxes public const string ASSETS_DIRECTORY = "avares://TelltaleTextureTool/Assets/"; public const string APP_ICON = ASSETS_DIRECTORY + "main_icon.ico"; + /// + /// Creates and returns the error dialog. + /// + /// + /// + public static MessageBoxStandardParams GetSuccessBox(string message) + { + var bitmap = new Bitmap(AssetLoader.Open(new Uri(APP_ICON))); + + return new MessageBoxStandardParams + { + ButtonDefinitions = ButtonEnum.Ok, + ContentTitle = "Success", + ContentMessage = message, + Icon = Icon.Success, + WindowStartupLocation = WindowStartupLocation.CenterOwner, + WindowIcon = new WindowIcon(bitmap), + CanResize = false, + MaxWidth = 500, + MaxHeight = 800, + SizeToContent = SizeToContent.WidthAndHeight, + ShowInCenter = true, + Topmost = false, + EnterDefaultButton = ClickEnum.Ok, + EscDefaultButton = ClickEnum.Ok + }; + } + /// /// Creates and returns the error dialog. ///