Skip to content

Commit

Permalink
feat: 地图对话下载功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Icexbb committed Dec 30, 2024
1 parent 68e1061 commit fff0946
Show file tree
Hide file tree
Showing 13 changed files with 1,089 additions and 27 deletions.
8 changes: 8 additions & 0 deletions SekaiDataFetch/Data/Area.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ public class Area : ICloneable
public string DisplayTimelineType { get; set; } = "";
public string AdditionalAreaType { get; set; } = "";
public string Name { get; set; } = "";
public string SubName { get; set; } = "";
public int ReleaseConditionId { get; set; }

public string AreaName
{
get => Name + (SubName == "" ? "" : " " + SubName);
set => Name = value;
}

public object Clone()
{
return new Area
Expand All @@ -26,6 +33,7 @@ public object Clone()
DisplayTimelineType = DisplayTimelineType,
AdditionalAreaType = AdditionalAreaType,
Name = Name,
SubName = SubName,
ReleaseConditionId = ReleaseConditionId
};
}
Expand Down
48 changes: 41 additions & 7 deletions SekaiDataFetch/List/ListActionStory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ public class ListActionStory
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
"SekaiTools", "Data", "cache", "actionSets.json");

private static readonly string CachePathCharacter2ds =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
"SekaiTools", "Data", "cache", "character2ds.json");

private Fetcher Fetcher { get; }
public readonly List<AreaStory> Data = [];
public List<AreaStory> Data { get; set; } = [];
public List<Area> Areas { get; private set; } = [];

public List<Character2d> Character2ds { get; private set; } = [];

public ListActionStory(SourceType sourceType = SourceType.SiteBest, Proxy? proxy = null)
{
Expand All @@ -28,8 +35,10 @@ public async Task Refresh()
{
var stringActionSets = await Fetcher.Fetch(Fetcher.Source.ActionSets);
var stringAreas = await Fetcher.Fetch(Fetcher.Source.Areas);
var stringCharacter2ds = await Fetcher.Fetch(Fetcher.Source.Character2ds);
await File.WriteAllTextAsync(CachePathActionSets, stringActionSets);
await File.WriteAllTextAsync(CachePathAreas, stringAreas);
await File.WriteAllTextAsync(CachePathCharacter2ds, stringCharacter2ds);

Load();
}
Expand All @@ -38,37 +47,62 @@ private void Load()
{
Directory.CreateDirectory(Path.GetDirectoryName(CachePathActionSets)!);
Directory.CreateDirectory(Path.GetDirectoryName(CachePathAreas)!);
if (!File.Exists(CachePathActionSets) || !File.Exists(CachePathAreas)) return;
Directory.CreateDirectory(Path.GetDirectoryName(CachePathCharacter2ds)!);
if (!File.Exists(CachePathActionSets) ||
!File.Exists(CachePathAreas) ||
!File.Exists(CachePathCharacter2ds)) return;

var stringActionSets = File.ReadAllText(CachePathActionSets);
var stringAreas = File.ReadAllText(CachePathAreas);
var stringCharacter2ds = File.ReadAllText(CachePathCharacter2ds);

var areas = Utils.Deserialize<Area[]>(stringAreas);
var actionSets = Utils.Deserialize<ActionSet[]>(stringActionSets);
var character2ds = Utils.Deserialize<Character2d[]>(stringCharacter2ds);

if (actionSets == null || areas == null) throw new Exception("Json parse error");
GetData(actionSets, areas);
if (actionSets == null || areas == null || character2ds == null) throw new Exception("Json parse error");
GetData(actionSets, areas, character2ds);
}

private void GetData(ActionSet[] actionSets, Area[] areas)
private void GetData(ActionSet[] actionSets, Area[] areas, Character2d[] character2ds)
{
foreach (var actionSet in actionSets)
{
var area = areas.FirstOrDefault(area => area.Id == actionSet.AreaId);
if (area == null) continue;
if (actionSet.ScenarioId == "") continue;
var data = new AreaStory(actionSet);
var data = new AreaStory(actionSet)
{
CharacterIds = actionSet.CharacterIds
.Select(id => character2ds.First(c2d => c2d.Id == id).CharacterId)
.ToArray()
};

Data.Add(data);
}

Areas = areas.Select(area => (Area)area.Clone()).ToList();
Character2ds = character2ds.Select(character2d => (Character2d)character2d.Clone()).ToList();
}
}

public class AreaStory(ActionSet actionSet)
public class AreaStory(ActionSet actionSet) : ICloneable
{
public ActionSet ActionSet { get; } = actionSet;
public string ScenarioId { get; } = actionSet.ScenarioId;
public int Group { get; } = actionSet.Id / 100;

public int[] CharacterIds { get; set; } = [];


public object Clone()
{
return new AreaStory(ActionSet)
{
CharacterIds = CharacterIds
};
}

public string Url(SourceType sourceType = SourceType.SiteBest)
{
return sourceType switch
Expand Down
Binary file added SekaiToolsGUI/Resource/Characters/chr_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 17 additions & 13 deletions SekaiToolsGUI/SekaiToolsGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x64</Platforms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>default</LangVersion>
<PackageProjectUrl>https://github.com/icexbb/sekaiTools</PackageProjectUrl>
<PackageIcon>Resource\icon.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -102,6 +105,8 @@
<Resource Include="Resource\Unit\logo_street.png"/>
<None Remove="Resource\Unit\logo_theme_park.png"/>
<Resource Include="Resource\Unit\logo_theme_park.png"/>
<None Remove="Resource\Characters\chr_0.png" />
<Resource Include="Resource\Characters\chr_0.png" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -176,29 +181,28 @@
<SubType>Designer</SubType>
</Page>
<Page Update="View\Download\Components\Event\EventStoryTab.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="View\Download\Components\Event\EventStoryEvent.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="View\Download\Components\Special\SpecialStoryTab.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="View\Download\Components\Unit\UnitStoryTab.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>

<ItemGroup>
<Folder Include="View\Download\Components\Action\" />
<Folder Include="View\Suppress\Components\"/>
<Folder Include="View\Utils\Componets\"/>
</ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions SekaiToolsGUI/View/Download/Components/Action/ActionStoryItem.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<UserControl x:Class="SekaiToolsGUI.View.Download.Components.Action.ActionStoryItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SekaiToolsGUI.View.Download.Components"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:DownloadItem}"
HorizontalAlignment="Stretch">
<ui:CardAction HorizontalAlignment="Stretch" Click="ButtonBase_OnClick">
<StackPanel Orientation="Vertical">
<ui:TextBlock Name="KeyText" Text="Key" />
<StackPanel Orientation="Horizontal" Name="Icons" Margin="0,5,0,0"/>
</StackPanel>
</ui:CardAction>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using SekaiDataFetch.List;

namespace SekaiToolsGUI.View.Download.Components.Action;

public partial class ActionStoryItem : UserControl
{
public static readonly DependencyProperty AreaStoryProperty = DependencyProperty.Register(
nameof(AreaStory), typeof(AreaStory), typeof(ActionStoryItem),
new PropertyMetadata(null, OnAreaStoryChanged));

public AreaStory AreaStory { get; set; } = null!;

private static void OnAreaStoryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ActionStoryItem control && e.NewValue is AreaStory areaStory) control.Initialize(areaStory);
}


public ActionStoryItem()
{
InitializeComponent();
}

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Dispatcher.Invoke(() =>
{
DependencyObject? parent = this;
while (parent != null && parent is not DownloadPage) parent = VisualTreeHelper.GetParent(parent);
(parent as DownloadPage)?.AddTask(AreaStory.ActionSet.ScriptId, AreaStory.Url());
});
}


private void Initialize(AreaStory areaStory)
{
AreaStory = areaStory;
Icons.Children.Clear();
var cIds = areaStory.CharacterIds.ToList();
cIds.Sort();
foreach (var id in cIds)
{
if (id is < 1 or > 31)
{
var text = new TextBlock
{
Text = $"L2d-{id}",
FontSize = 16,
Margin = new Thickness(5, 0, 5, 0)
};
Icons.Children.Add(text);
}
else
{
var url = $"pack://application:,,,/Resource/Characters/chr_{id}.png";
var icon = new Image
{
Source = new BitmapImage(new Uri(url)),
Width = 36,
Height = 36,
Margin = new Thickness(5, 0, 5, 0)
};
Icons.Children.Add(icon);
}
}

KeyText.Text = $"{areaStory.ActionSet.Id} {areaStory.ActionSet.ScenarioId}";
}
}
Loading

0 comments on commit fff0946

Please sign in to comment.