From 317e8dbe1d7a1a28576c93d581e97fc9bef70604 Mon Sep 17 00:00:00 2001 From: "Dr.Abc" Date: Mon, 5 Aug 2024 19:12:43 +0800 Subject: [PATCH] update beamlength --- SPRView.Net/Assets/Lang/en.json | 8 +++++++- SPRView.Net/Assets/Lang/zh.json | 8 +++++++- SPRView.Net/ViewModel/CreateNewViewModel.cs | 22 ++++++++++++++------- SPRView.Net/ViewModel/LangViewModel.cs | 6 ++++++ SPRView.Net/Window/CreateNew.axaml | 22 ++++++++++++--------- SPRView.Net/Window/MessageBox.axaml | 14 +++++++------ 6 files changed, 56 insertions(+), 24 deletions(-) diff --git a/SPRView.Net/Assets/Lang/en.json b/SPRView.Net/Assets/Lang/en.json index df2a5ae..c1cdd2f 100644 --- a/SPRView.Net/Assets/Lang/en.json +++ b/SPRView.Net/Assets/Lang/en.json @@ -1,4 +1,7 @@ { + "Shared_OK": "OK", + "Shared_Cancel": "Cancel", + "TaskBar_File": "_File", "TaskBar_File_Create": "Create", "TaskBar_File_Open": "Open(.spr)", @@ -58,9 +61,12 @@ "CreateNew_Sync": "Synchronism:", "CreateNew_Sync_Sync": "Sync", "CreateNew_Sync_Random": "Random", + "CreateNew_BeamLength": "Beam Length:", + "CreateNew_BeamLength_Watermaker": "Optional,Useless in Half-Life", "CreateNew_Export_Frame": "Frame:", "CreateNew_Export_Play": "Play", "CreateNew_Export_Width": "Export Width", "CreateNew_Export_Height": "Export Height", - "CreateNew_Export_Save": "Export!" + "CreateNew_Export_Save": "Export!", + "CreateNew_Export_NotSQRTWarning": "The size you set cannot be divided by 2\nand it may not work in some versions of engine." } \ No newline at end of file diff --git a/SPRView.Net/Assets/Lang/zh.json b/SPRView.Net/Assets/Lang/zh.json index d2c0d25..8b8120b 100644 --- a/SPRView.Net/Assets/Lang/zh.json +++ b/SPRView.Net/Assets/Lang/zh.json @@ -1,4 +1,7 @@ { + "Shared_OK": "好的", + "Shared_Cancel": "取消", + "TaskBar_File": "_文件", "TaskBar_File_Create": "新建", "TaskBar_File_Open": "打开(.spr)", @@ -58,9 +61,12 @@ "CreateNew_Sync": "同步性:", "CreateNew_Sync_Sync": "一致", "CreateNew_Sync_Random": "随机", + "CreateNew_BeamLength": "射线宽度:", + "CreateNew_BeamLength_Watermaker": "选填,在Half-Life中无效", "CreateNew_Export_Frame": "帧", "CreateNew_Export_Play": "播放", "CreateNew_Export_Width": "导出长度", "CreateNew_Export_Height": "导出宽度", - "CreateNew_Export_Save": "导出保存!" + "CreateNew_Export_Save": "导出保存!", + "CreateNew_Export_NotSQRTWarning": "你设置的尺寸不能被2整除\n可能无法在某些版本的引擎里使用" } \ No newline at end of file diff --git a/SPRView.Net/ViewModel/CreateNewViewModel.cs b/SPRView.Net/ViewModel/CreateNewViewModel.cs index 399c670..52d477d 100644 --- a/SPRView.Net/ViewModel/CreateNewViewModel.cs +++ b/SPRView.Net/ViewModel/CreateNewViewModel.cs @@ -50,10 +50,10 @@ public string[] ImagePaths } #region Property - public int PlaySpeed { get; set; } = 24; public int Type { get; set; } = 0; public int Format { get; set; } = 0; public int Sync { get; set; } = 0; + public float BeamLength { get; set; } = 0; public async void AddImage() { @@ -142,6 +142,7 @@ private bool ResetPreview() } return false; } + public int PlaySpeed { get; set; } = 24; private Bitmap? m_previewImage; public Bitmap? PreviewImage { @@ -173,13 +174,20 @@ public int Preview_MaxFrame } public int Export_Width { get; set; } = 64; public int Export_Height { get; set; } = 64; - public int Progress { get; set; } = 0; + private int m_iProgress = 0; + public int Progress { get => m_iProgress; set { m_iProgress = value; OnPropertyChanged(nameof(Progress)); } } public bool SaveValid { get => m_aryImagePaths.Count > 0; } public async void SaveToSpr() { + if(Export_Width % 2==1|| Export_Height % 2==1) + { + var box = MessageBoxWindow.CreateMessageBox(Lang.CreateNew_Export_NotSQRTWarning, null, Lang.Shared_OK, Lang.Shared_Cancel); + box.Position = new Avalonia.PixelPoint(Parent.Position.X + (int)Parent.Width / 2, Parent.Position.Y + (int)Parent.Height / 2); + await box.ShowDialog(Parent); + } Progress = 0; FilePickerFileType Sprites = new("GoldSrc Sprites") { @@ -196,7 +204,7 @@ public async void SaveToSpr() { //量化 //降低一个维度,以便统一量化 - Image image = new(Export_Width * m_aryImagePaths.Count, Export_Height * m_aryImagePaths.Count); + using Image image = new(Export_Width * m_aryImagePaths.Count, Export_Height * m_aryImagePaths.Count); for (int i = 0; i < m_aryImagePaths.Count; i++) { var path = m_aryImagePaths[i]; @@ -247,7 +255,7 @@ public async void SaveToSpr() //Count writer.Write(m_aryImagePaths.Count); //BeamLength - writer.Write(0.0f); + writer.Write(BeamLength); //Sync writer.Write(Sync); Progress = 60; @@ -270,7 +278,7 @@ public async void SaveToSpr() //保存数据 for (int k = 0; k < m_aryImagePaths.Count; k++) { - Progress += k / m_aryImagePaths.Count * 100; + Progress += k * 100 / m_aryImagePaths.Count; //Group writer.Write(0x00000000); //OriginX @@ -296,8 +304,8 @@ public async void SaveToSpr() } } } - image.Dispose(); - var box = MessageBoxWindow.CreateMessageBox("☑︎🖻⏏💾", null, "🥰", "😠"); + Progress = 200; + var box = MessageBoxWindow.CreateMessageBox("☑︎🖻⏏💾", null, Lang.Shared_OK, Lang.Shared_Cancel); box.Position = new Avalonia.PixelPoint(Parent.Position.X + (int)Parent.Width / 2, Parent.Position.Y + (int)Parent.Height / 2); await box.ShowDialog(Parent); } diff --git a/SPRView.Net/ViewModel/LangViewModel.cs b/SPRView.Net/ViewModel/LangViewModel.cs index 6ae45fd..076417a 100644 --- a/SPRView.Net/ViewModel/LangViewModel.cs +++ b/SPRView.Net/ViewModel/LangViewModel.cs @@ -274,6 +274,9 @@ public string SpriteInfo_OriginY } } + public string Shared_OK { get; set; } = "OK"; + public string Shared_Cancel { get; set; } = "Cancel"; + public string FileManager_OpenSprite { get; set; } = "Open Sprite"; public string FileManager_SaveImage { get; set; } = "Save Image"; public string FileManager_SaveGIF { get; set; } = "Save GIF"; @@ -304,9 +307,12 @@ public string SpriteInfo_OriginY public string CreateNew_Sync { get; set; } = "Sync:"; public string CreateNew_Sync_Sync { get; set; } = "Sync"; public string CreateNew_Sync_Random { get; set; } = "Random"; + public string CreateNew_BeamLength { get; set; } = "Beam Length:"; + public string CreateNew_BeamLength_Watermaker { get; set; } = "Optional,Useless in Half-Life"; public string CreateNew_Export_Frame { get; set; } = "Frame:"; public string CreateNew_Export_Play { get; set; } = "Play"; public string CreateNew_Export_Width { get; set; } = "Export Width"; public string CreateNew_Export_Height { get; set; } = "Export Height"; public string CreateNew_Export_Save { get; set; } = "Export!"; + public string CreateNew_Export_NotSQRTWarning { get; set; } = "The size you set cannot be divided by 2, and it may not work in some versions of engine."; } diff --git a/SPRView.Net/Window/CreateNew.axaml b/SPRView.Net/Window/CreateNew.axaml index d85d4bb..d9a7b31 100644 --- a/SPRView.Net/Window/CreateNew.axaml +++ b/SPRView.Net/Window/CreateNew.axaml @@ -37,10 +37,7 @@ diff --git a/SPRView.Net/Window/MessageBox.axaml b/SPRView.Net/Window/MessageBox.axaml index 47f5f26..9dff9ee 100644 --- a/SPRView.Net/Window/MessageBox.axaml +++ b/SPRView.Net/Window/MessageBox.axaml @@ -11,11 +11,13 @@ Background="#60FFFFFF" mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="60"> - - - -