修复图片读取错误

This commit is contained in:
ZouJin 2024-03-15 13:18:05 +08:00
parent d7a7e0b674
commit 8a797fd4e4
7 changed files with 20 additions and 11 deletions

View File

@ -170,7 +170,7 @@ namespace VPet_Simulator.Windows.Interface
/// </summary>
public void LoadImageSource(IMainWindow imw)
{
ImageSource = imw.ImageSources.FindImage(Image ?? Name, "food");
ImageSource = imw.ImageSources.FindImage("food_" + (Image ?? Name), "food");
Star = imw.Set.BetterBuyData["star"].GetInfos().Contains(Name);
LoadEatTimeSource(imw);
}

View File

@ -53,17 +53,17 @@ namespace VPet_Simulator.Windows
public DateTime CacheDate;
public string ErrorMessage;
public static string INTtoVER(int ver) => ver < 10000 ? $"{ver / 100}.{ver % 100:00}" : $"{ver / 10000}.{ver % 10000 / 100}.{ver % 100:00}";
public static void LoadImage(MainWindow mw, DirectoryInfo di)
public static void LoadImage(MainWindow mw, DirectoryInfo di, string pre = "")
{
//加载其他放在文件夹的图片
foreach (FileInfo fi in di.EnumerateFiles("*.png"))
{
mw.ImageSources.AddSource(fi.Name.ToLower().Substring(0, fi.Name.Length - 4), fi.FullName);
mw.ImageSources.AddSource(pre + fi.Name.ToLower().Substring(0, fi.Name.Length - 4), fi.FullName);
}
//加载其他放在文件夹中文件夹的图片
foreach (DirectoryInfo fordi in di.EnumerateDirectories())
{
LoadImage(mw, fordi);
LoadImage(mw, fordi, pre + fordi.Name + "_");
}
//加载标志好的图片和图片设置
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))

View File

@ -29,7 +29,8 @@
<Button x:Name="btnStart" Grid.Row="1" Grid.Column="1" VerticalAlignment="Bottom" Margin="5" Height="30"
Content="{ll:Str 开始工作}" Background="{DynamicResource DARKPrimary}" BorderThickness="1"
pu:ButtonHelper.CornerRadius="5" BorderBrush="{DynamicResource DARKPrimaryDarker}"
Foreground="{DynamicResource DARKPrimaryText}" FontWeight="Bold" FontSize="20" IsEnabled="False" />
Foreground="{DynamicResource DARKPrimaryText}" FontWeight="Bold" FontSize="20" IsEnabled="False"
Click="btnStart_Click" />
<Label x:Name="lName" Background="{x:Null}" Grid.Column="1" VerticalAlignment="Bottom" Content="{ll:Str 请从侧边栏选择}" FontSize="24"
Foreground="{DynamicResource DARKPrimaryDark}" FontWeight="Bold" />
<TextBlock Grid.Column="1" VerticalAlignment="Top" Grid.Row="1" Margin="10,5,0,0" HorizontalAlignment="Left">

View File

@ -26,6 +26,7 @@ public partial class winWorkMenu : Window
List<Work> ws;
List<Work> ss;
List<Work> ps;
public void ShowImageDefault(Work.WorkType type) => WorkViewImage.Source = mw.ImageSources.FindImage(mw.Set.PetGraph + "_" + type.ToString(), "work");
public winWorkMenu(MainWindow mw, Work.WorkType type)
{
InitializeComponent();
@ -55,9 +56,11 @@ public partial class winWorkMenu : Window
}
tbc.SelectedIndex = (int)type;
ShowImageDefault(type);
}
private bool AllowChange = false;
Work nowwork;
Work nowworkdisplay;
public void ShowWork()
{
AllowChange = false;
@ -91,17 +94,14 @@ public partial class winWorkMenu : Window
}
public void ShowWork(Work work)
{
nowworkdisplay = work;
lName.Content = work.NameTrans;
//显示图像
string source = mw.ImageSources.FindSource(work.Graph);
if (source == null)
{
source = mw.ImageSources.FindSource(work.Name);
}
string source = mw.ImageSources.FindSource("work_" + work.Graph) ?? mw.ImageSources.FindSource("work_" + work.Name);
if (source == null)
{
//尝试显示默认图像
WorkViewImage.Source = Interface.ImageResources.NewSafeBitmapImage("pack://application:,,,/Res/img/error.png");
ShowImageDefault(work.Type);
}
else
{
@ -124,10 +124,12 @@ public partial class winWorkMenu : Window
sb.AppendLine('x' + (1 + work.FinishBonus).ToString("f2"));
sb.AppendLine('x' + wDouble.Value.ToString("f0"));
tbDisplay.Text = sb.ToString();
}
private void tbc_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ShowImageDefault((Work.WorkType)tbc.SelectedIndex);
switch (tbc.SelectedIndex)
{
case 0:
@ -170,4 +172,10 @@ public partial class winWorkMenu : Window
{
mw.winWorkMenu = null;
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
if (nowworkdisplay != null)
mw.Main.StartWork(nowworkdisplay);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 KiB