mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
添加 保存和读取最近打开的内容
This commit is contained in:
parent
cfc81f7650
commit
45a9c5bed5
@ -1,20 +0,0 @@
|
|||||||
using LinePutScript.Converter;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace VPet.ModMaker.Models;
|
|
||||||
|
|
||||||
public class ModMakeHistory
|
|
||||||
{
|
|
||||||
[Line(ignoreCase: true)]
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
[Line(ignoreCase: true)]
|
|
||||||
public string Path { get; set; }
|
|
||||||
|
|
||||||
[Line(ignoreCase: true)]
|
|
||||||
public DateTime LastOpenTime { get; set; }
|
|
||||||
}
|
|
38
VPet.ModMaker/Models/ModMakerHistory.cs
Normal file
38
VPet.ModMaker/Models/ModMakerHistory.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using LinePutScript.Converter;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
namespace VPet.ModMaker.Models;
|
||||||
|
|
||||||
|
public class ModMakerHistory
|
||||||
|
{
|
||||||
|
public BitmapImage Image { get; set; }
|
||||||
|
|
||||||
|
[Line(ignoreCase: true)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
private string _path;
|
||||||
|
|
||||||
|
[Line(ignoreCase: true)]
|
||||||
|
public string SourcePath
|
||||||
|
{
|
||||||
|
get => _path;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_path = value;
|
||||||
|
var imagePath = Path.Combine(_path, "icon.png");
|
||||||
|
if (File.Exists(imagePath))
|
||||||
|
Image = Utils.LoadImageToMemoryStream(imagePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LastTimeString => LastTime.ToString("yyyy/MM/dd HH:mm:ss");
|
||||||
|
|
||||||
|
[Line(ignoreCase: true)]
|
||||||
|
public DateTime LastTime { get; set; }
|
||||||
|
}
|
@ -8,7 +8,6 @@ namespace VPet.ModMaker.Models;
|
|||||||
|
|
||||||
public static class ModMakerInfo
|
public static class ModMakerInfo
|
||||||
{
|
{
|
||||||
// TODO: 可修改的主要文化 ?
|
|
||||||
public const string MainCulture = "zh-Hans";
|
|
||||||
public const string BaseDirectory = nameof(ModMaker);
|
public const string BaseDirectory = nameof(ModMaker);
|
||||||
|
public const string HistoryFile = $"{BaseDirectory}\\history.lps";
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
<Compile Include="Models\I18nModel.cs" />
|
<Compile Include="Models\I18nModel.cs" />
|
||||||
<Compile Include="Models\LowTextModel.cs" />
|
<Compile Include="Models\LowTextModel.cs" />
|
||||||
<Compile Include="Models\ModLoader.cs" />
|
<Compile Include="Models\ModLoader.cs" />
|
||||||
<Compile Include="Models\ModMakeHistory.cs" />
|
<Compile Include="Models\ModMakerHistory.cs" />
|
||||||
<Compile Include="Models\ModMakerInfo.cs" />
|
<Compile Include="Models\ModMakerInfo.cs" />
|
||||||
<Compile Include="Models\PetModel.cs" />
|
<Compile Include="Models\PetModel.cs" />
|
||||||
<Compile Include="ViewModels\ModEdit\ClickTextEdit\ClickTextEditWindowVM.cs" />
|
<Compile Include="ViewModels\ModEdit\ClickTextEdit\ClickTextEditWindowVM.cs" />
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using HKW.HKWViewModels.SimpleObservable;
|
using HKW.HKWViewModels.SimpleObservable;
|
||||||
|
using LinePutScript;
|
||||||
|
using LinePutScript.Converter;
|
||||||
using LinePutScript.Localization.WPF;
|
using LinePutScript.Localization.WPF;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
@ -26,6 +28,8 @@ public class ModMakerWindowVM
|
|||||||
|
|
||||||
public ObservableCollection<ModInfoModel> ShowMods { get; set; }
|
public ObservableCollection<ModInfoModel> ShowMods { get; set; }
|
||||||
public ObservableCollection<ModInfoModel> Mods { get; } = new();
|
public ObservableCollection<ModInfoModel> Mods { get; } = new();
|
||||||
|
|
||||||
|
public ObservableCollection<ModMakerHistory> Histories { get; } = new();
|
||||||
#endregion
|
#endregion
|
||||||
#region Command
|
#region Command
|
||||||
public ObservableCommand CreateNewModCommand { get; } = new();
|
public ObservableCommand CreateNewModCommand { get; } = new();
|
||||||
@ -35,7 +39,7 @@ public class ModMakerWindowVM
|
|||||||
|
|
||||||
public ModMakerWindowVM(ModMakerWindow window)
|
public ModMakerWindowVM(ModMakerWindow window)
|
||||||
{
|
{
|
||||||
LoadMods();
|
LoadHistories();
|
||||||
ModMakerWindow = window;
|
ModMakerWindow = window;
|
||||||
ShowMods = Mods;
|
ShowMods = Mods;
|
||||||
CreateNewModCommand.ExecuteAction = CreateNewMod;
|
CreateNewModCommand.ExecuteAction = CreateNewMod;
|
||||||
@ -43,16 +47,49 @@ public class ModMakerWindowVM
|
|||||||
ModFilterText.ValueChanged += ModFilterText_ValueChanged;
|
ModFilterText.ValueChanged += ModFilterText_ValueChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadMods()
|
private void LoadHistories()
|
||||||
{
|
{
|
||||||
var dic = Directory.CreateDirectory(ModMakerInfo.BaseDirectory);
|
if (File.Exists(ModMakerInfo.HistoryFile) is false)
|
||||||
foreach (var modDic in dic.EnumerateDirectories())
|
return;
|
||||||
|
var lps = new LPS(File.ReadAllText(ModMakerInfo.HistoryFile));
|
||||||
|
foreach (var line in lps)
|
||||||
|
Histories.Add(LPSConvert.DeserializeObject<ModMakerHistory>(line));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveHistories()
|
||||||
{
|
{
|
||||||
var mod = new ModLoader(modDic);
|
if (File.Exists(ModMakerInfo.HistoryFile) is false)
|
||||||
if (mod.SuccessLoad is false)
|
File.Create(ModMakerInfo.HistoryFile).Close();
|
||||||
continue;
|
var lps = new LPS();
|
||||||
var modModel = new ModInfoModel(mod);
|
foreach (var history in Histories)
|
||||||
Mods.Add(modModel);
|
lps.Add(
|
||||||
|
new Line(nameof(history))
|
||||||
|
{
|
||||||
|
new Sub("Name", history.Name),
|
||||||
|
new Sub("SourcePath", history.SourcePath),
|
||||||
|
new Sub("LastTime", history.LastTimeString)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
File.WriteAllText(ModMakerInfo.HistoryFile, lps.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddHistories(ModInfoModel modInfo)
|
||||||
|
{
|
||||||
|
if (Histories.FirstOrDefault(h => h.Name == modInfo.Name.Value) is ModMakerHistory history)
|
||||||
|
{
|
||||||
|
history.SourcePath = modInfo.SourcePath.Value;
|
||||||
|
history.LastTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Histories.Add(
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Name = modInfo.Name.Value,
|
||||||
|
SourcePath = modInfo.SourcePath.Value,
|
||||||
|
LastTime = DateTime.Now,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,12 +104,15 @@ public class ModMakerWindowVM
|
|||||||
public void CreateNewMod()
|
public void CreateNewMod()
|
||||||
{
|
{
|
||||||
ModInfoModel.Current ??= new();
|
ModInfoModel.Current ??= new();
|
||||||
// I18nHelper.Current = new();
|
|
||||||
ModEditWindow = new();
|
ModEditWindow = new();
|
||||||
ModEditWindow.Show();
|
ModEditWindow.Show();
|
||||||
ModMakerWindow.Hide();
|
ModMakerWindow.Hide();
|
||||||
ModEditWindow.Closed += (s, e) =>
|
ModEditWindow.Closed += (s, e) =>
|
||||||
{
|
{
|
||||||
|
var modInfo = ModInfoModel.Current;
|
||||||
|
if (string.IsNullOrEmpty(modInfo.SourcePath.Value) is false)
|
||||||
|
AddHistories(modInfo);
|
||||||
|
SaveHistories();
|
||||||
ModMakerWindow.Close();
|
ModMakerWindow.Close();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<ListBox
|
<ListBox
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
d:ItemsSource="{d:SampleData ItemCount=5}"
|
d:ItemsSource="{d:SampleData ItemCount=5}"
|
||||||
ItemsSource="{Binding Mods}"
|
ItemsSource="{Binding Histories}"
|
||||||
Style="{StaticResource SideMenuListBoxStyle}">
|
Style="{StaticResource SideMenuListBoxStyle}">
|
||||||
<ListBox.ItemContainerStyle>
|
<ListBox.ItemContainerStyle>
|
||||||
<Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="ListBoxItem">
|
<Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="ListBoxItem">
|
||||||
@ -41,12 +41,12 @@
|
|||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate>
|
<ControlTemplate>
|
||||||
<Grid ToolTip="{Binding Summary.Value}">
|
<Grid Background="White">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition />
|
<ColumnDefinition />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Image Width="64" Source="{Binding Image.Value}" />
|
<Image Width="64" Source="{Binding Image}" />
|
||||||
<Grid Grid.Column="1">
|
<Grid Grid.Column="1">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
@ -54,12 +54,18 @@
|
|||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
d:Text="{ll:Str Mod名称}"
|
d:Text="{ll:Str Mod名称}"
|
||||||
Text="{Binding Name.Value}"
|
FontWeight="Bold"
|
||||||
|
Text="{Binding Name}"
|
||||||
TextWrapping="Wrap" />
|
TextWrapping="Wrap" />
|
||||||
|
<TextBlock
|
||||||
|
HorizontalAlignment="Right"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
Text="{Binding LastTimeString}" />
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
d:Text="{ll:Str Mod描述}"
|
d:Text="{ll:Str Mod描述}"
|
||||||
Text="{Binding Description.Value}"
|
Text="{Binding SourcePath}"
|
||||||
TextWrapping="Wrap" />
|
TextWrapping="Wrap" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using LinePutScript;
|
using LinePutScript;
|
||||||
|
using LinePutScript.Localization.WPF;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -39,7 +40,15 @@ public partial class ModMakerWindow : Window
|
|||||||
{
|
{
|
||||||
if (sender is not ListBoxItem item)
|
if (sender is not ListBoxItem item)
|
||||||
return;
|
return;
|
||||||
ModInfoModel.Current = (ModInfoModel)item.DataContext;
|
if (item.DataContext is not ModMakerHistory history)
|
||||||
|
return;
|
||||||
|
var loader = new ModLoader(new(history.SourcePath));
|
||||||
|
if (loader.SuccessLoad)
|
||||||
|
{
|
||||||
|
ModInfoModel.Current = new(loader);
|
||||||
ViewModel.CreateNewMod();
|
ViewModel.CreateNewMod();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
MessageBox.Show($"载入失败".Translate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user