Skip to content

Commit

Permalink
update beamlength
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr.Abc committed Aug 5, 2024
1 parent 3c57a63 commit 317e8db
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 24 deletions.
8 changes: 7 additions & 1 deletion SPRView.Net/Assets/Lang/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"Shared_OK": "OK",
"Shared_Cancel": "Cancel",

"TaskBar_File": "_File",
"TaskBar_File_Create": "Create",
"TaskBar_File_Open": "Open(.spr)",
Expand Down Expand Up @@ -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."
}
8 changes: 7 additions & 1 deletion SPRView.Net/Assets/Lang/zh.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"Shared_OK": "好的",
"Shared_Cancel": "取消",

"TaskBar_File": "_文件",
"TaskBar_File_Create": "新建",
"TaskBar_File_Open": "打开(.spr)",
Expand Down Expand Up @@ -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可能无法在某些版本的引擎里使用"
}
22 changes: 15 additions & 7 deletions SPRView.Net/ViewModel/CreateNewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -142,6 +142,7 @@ private bool ResetPreview()
}
return false;
}
public int PlaySpeed { get; set; } = 24;
private Bitmap? m_previewImage;
public Bitmap? PreviewImage
{
Expand Down Expand Up @@ -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);

Check warning on line 187 in SPRView.Net/ViewModel/CreateNewViewModel.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu, x64)

Dereference of a possibly null reference.

Check warning on line 187 in SPRView.Net/ViewModel/CreateNewViewModel.cs

View workflow job for this annotation

GitHub Actions / build (windows, x64)

Dereference of a possibly null reference.

Check warning on line 187 in SPRView.Net/ViewModel/CreateNewViewModel.cs

View workflow job for this annotation

GitHub Actions / build (macos, x64)

Dereference of a possibly null reference.
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")
{
Expand All @@ -196,7 +204,7 @@ public async void SaveToSpr()
{
//量化
//降低一个维度,以便统一量化
Image<Rgba32> image = new(Export_Width * m_aryImagePaths.Count, Export_Height * m_aryImagePaths.Count);
using Image<Rgba32> 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];
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);

Check warning on line 308 in SPRView.Net/ViewModel/CreateNewViewModel.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu, x64)

Dereference of a possibly null reference.

Check warning on line 308 in SPRView.Net/ViewModel/CreateNewViewModel.cs

View workflow job for this annotation

GitHub Actions / build (windows, x64)

Dereference of a possibly null reference.

Check warning on line 308 in SPRView.Net/ViewModel/CreateNewViewModel.cs

View workflow job for this annotation

GitHub Actions / build (macos, x64)

Dereference of a possibly null reference.
box.Position = new Avalonia.PixelPoint(Parent.Position.X + (int)Parent.Width / 2, Parent.Position.Y + (int)Parent.Height / 2);
await box.ShowDialog(Parent);
}
Expand Down
6 changes: 6 additions & 0 deletions SPRView.Net/ViewModel/LangViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.";
}
22 changes: 13 additions & 9 deletions SPRView.Net/Window/CreateNew.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
<Button Content="{CompiledBinding Lang.CreateNew_RemoveImage}" Command="{CompiledBinding RemoveImage}" MinWidth="150"/>
<RepeatButton Content="{CompiledBinding Lang.CreateNew_MoveDownImage}" Command="{CompiledBinding MovedownImage}" MinWidth="150"/>
</UniformGrid>
<StackPanel MinWidth="300">
<TextBlock Margin="0 5" Text="{CompiledBinding Lang.CreateNew_PlaySpeed}"/>
<NumericUpDown Value="{CompiledBinding PlaySpeed}" Minimum="0" FormatString="0" ToolTip.Tip="{CompiledBinding Lang.CreateNew_PlaySpeed_WaterMarker}"/>
</StackPanel>

<TextBlock Margin="0 5" Text="{CompiledBinding Lang.CreateNew_Type}"/>
<ComboBox SelectedIndex="{CompiledBinding Type}" MinWidth="300">
<ComboBoxItem Content="{CompiledBinding Lang.CreateNew_Type_ParallelUpright}"/>
Expand All @@ -61,6 +58,11 @@
<ComboBoxItem Content="{CompiledBinding Lang.CreateNew_Sync_Sync}"/>
<ComboBoxItem Content="{CompiledBinding Lang.CreateNew_Sync_Random}"/>
</ComboBox>
<Panel Margin="0 5">
<TextBlock Text="{CompiledBinding Lang.CreateNew_BeamLength}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Foreground="DarkKhaki" Margin="0 5" FontStyle="Italic" Text="{CompiledBinding Lang.CreateNew_BeamLength_Watermaker}" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Panel>
<NumericUpDown Value="{CompiledBinding BeamLength}" Minimum="0" Maximum="2147483647" FormatString="0.00" MinWidth="300"/>
</StackPanel>
</TabItem>
<TabItem Header="{CompiledBinding Lang.CreateNew_Tab_Preview}">
Expand All @@ -69,10 +71,12 @@
<Border BorderBrush="Gray" BorderThickness="1" Grid.Column="0">
<Image Source="{CompiledBinding PreviewImage}" Width="140" Height="140" Stretch="Fill"/>
</Border>
<StackPanel Grid.Column="1" MinWidth="140" Margin="5,0,0,0">
<TextBlock Text="{CompiledBinding Lang.CreateNew_Export_Frame}" Margin="5,10,0,0"/>
<NumericUpDown Value="{CompiledBinding Preview_Frame}" Minimum="0" Maximum="{CompiledBinding Preview_MaxFrame}" FormatString="0" Margin="0,8,0,0"/>
<Button Content="{CompiledBinding Lang.CreateNew_Export_Play}" Command="{CompiledBinding StartPreview}" Margin="0,10,0,0" MinWidth="140"/>
<StackPanel Grid.Column="1" MinWidth="140" Margin="2,0,0,0">
<TextBlock Text="{CompiledBinding Lang.CreateNew_Export_Frame}" Margin="2 2"/>
<NumericUpDown Value="{CompiledBinding Preview_Frame}" Minimum="0" Maximum="{CompiledBinding Preview_MaxFrame}" FormatString="0"/>
<TextBlock Margin="2 2" Text="{CompiledBinding Lang.CreateNew_PlaySpeed}"/>
<NumericUpDown Value="{CompiledBinding PlaySpeed}" Minimum="0" FormatString="0" ToolTip.Tip="{CompiledBinding Lang.CreateNew_PlaySpeed_WaterMarker}"/>
<Button Content="{CompiledBinding Lang.CreateNew_Export_Play}" Command="{CompiledBinding StartPreview}" Margin="0,2,0,0" MinWidth="140"/>
</StackPanel>
</Grid>
<Grid ColumnDefinitions="*,2*" Margin="0,10">
Expand All @@ -83,7 +87,7 @@
<TextBlock Text="{CompiledBinding Lang.CreateNew_Export_Height}" Grid.Column="0"/>
<NumericUpDown Value="{CompiledBinding Export_Height}" FormatString="0" Grid.Column="1"/>
</Grid>
<ProgressBar Margin="0,10" MinHeight="25" Value="{CompiledBinding Progress}" Maximum="200"/>
<ProgressBar Margin="0,10" MinHeight="25" Value="{CompiledBinding Progress}" Minimum="0" Maximum="200"/>
<Button MinWidth="300" MinHeight="60" Margin="0,2" Command="{CompiledBinding SaveToSpr}" IsEnabled="{CompiledBinding SaveValid}">
<TextBlock Text="{CompiledBinding Lang.CreateNew_Export_Save}" FontSize="24" FontStretch="Expanded" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Button>
Expand Down
14 changes: 8 additions & 6 deletions SPRView.Net/Window/MessageBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
Background="#60FFFFFF"
mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="60">
<Panel MinWidth="200" MinHeight="160">
<TextBlock Name="Title" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<TextBlock Name="Message" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"/>
<DockPanel Margin="5" HorizontalAlignment="Right" VerticalAlignment="Bottom">
<Button Name="OK" Content="OK" Click="Button_Click"/>
<Button Name="Cancel" Content="Cancel" Click="Button_Click"/>
</DockPanel>
<Panel>
<TextBlock Name="Title" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5"/>
<TextBlock Name="Message" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20"/>
<DockPanel Margin="5" HorizontalAlignment="Right" VerticalAlignment="Bottom">
<Button Name="OK" Content="OK" Click="Button_Click"/>
<Button Name="Cancel" Content="Cancel" Click="Button_Click"/>
</DockPanel>
</Panel>
</Panel>
</Window>

0 comments on commit 317e8db

Please sign in to comment.