Skip to content

Commit

Permalink
Add new message box, do some cleanup, add PS Vita in swizzling options
Browse files Browse the repository at this point in the history
  • Loading branch information
iMrShadow committed Oct 8, 2024
1 parent 783bd92 commit 396a72e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,7 +97,6 @@ public partial class MainViewModel : ViewModelBase

private readonly ObservableCollection<FormatItemViewModel> _otherTypes =
[
new FormatItemViewModel { Name = "DDS", ItemStatus = true },
new FormatItemViewModel { Name = "D3DTX", ItemStatus = true }
];

Expand Down Expand Up @@ -130,12 +128,6 @@ public partial class MainViewModel : ViewModelBase
Patterns = ["*.ttarch", "*.ttarch2"]
};

[ObservableProperty]
private ObservableCollection<DataGridColumn>? _columns = new ObservableCollection<DataGridColumn>()
{
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";
Expand All @@ -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; } = [
Expand All @@ -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
Expand Down Expand Up @@ -223,17 +215,16 @@ 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;
[ObservableProperty] private uint _maxMipCount;
[ObservableProperty] private uint _maxFaceCount;
[ObservableProperty] private static ObservableCollection<WorkingDirectoryFile> _workingDirectoryFiles = [];
[ObservableProperty] private ObservableCollection<WorkingDirectoryFile> _archiveFiles = [];
[ObservableProperty] private ImageData _imageData = new ImageData();
[ObservableProperty] private ImageData _imageData = new();

[ObservableProperty]
[NotifyCanExecuteChangedFor("ResetPanAndZoomCommand")]
Expand Down Expand Up @@ -262,7 +253,7 @@ public MainViewModel()
{
Source = SvgSource.Load(ErrorSvgFilename, _assetsUri)
};
ImageAdvancedOptions = new ImageAdvancedOptions(this);
ImageAdvancedOptions = new ImageAdvancedOptions(this);
}

#region MAIN MENU BUTTONS ACTIONS
Expand Down Expand Up @@ -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)
Expand All @@ -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
{
Expand Down Expand Up @@ -713,7 +714,7 @@ public async Task DebugButton_Click()
}
else if (workingDirectoryFile.FileType == ".dds")
{
debugInfo = DDS_DirectXTexNet.GetDDSDebugInfo(textureFilePath);
debugInfo = TextureManager.GetDDSDebugInfo(textureFilePath);
}
else
{
Expand All @@ -736,7 +737,7 @@ public async Task DebugButton_Click()
///</summary>
private async Task UpdateUiAsync()
{
// update our texture directory UI
// Update our texture directory UI
try
{
DirectoryPath = mainManager.GetWorkingDirectoryPath();
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions TelltaleTextureTool/TelltaleTextureTool/Utilities/MessageBoxes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Creates and returns the error dialog.
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
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
};
}

/// <summary>
/// Creates and returns the error dialog.
/// </summary>
Expand Down

0 comments on commit 396a72e

Please sign in to comment.