Skip to content

Commit

Permalink
support Capsule
Browse files Browse the repository at this point in the history
  • Loading branch information
turtle-insect committed May 21, 2023
1 parent ba32cf7 commit c5113f1
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 6 deletions.
15 changes: 15 additions & 0 deletions ZeldaTOTK/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ZeldaTOTK.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<ZeldaTOTK.Properties.Settings>
<setting name="lang" serializeAs="String">
<value>0</value>
</setting>
</ZeldaTOTK.Properties.Settings>
</userSettings>
</configuration>
26 changes: 26 additions & 0 deletions ZeldaTOTK/CapsuleIDNameConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Xml.Linq;

namespace ZeldaTOTK
{
internal class CapsuleIDNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var id = (String)value;
if (!Info.Instance().Capsule.ContainsKey(id)) return id;
return Info.Instance().Capsule[id].Name;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
52 changes: 52 additions & 0 deletions ZeldaTOTK/Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZeldaTOTK
{
internal class Info
{
private static Info? mThis;
public Dictionary<String, NameIDInfo> Capsule { get; private set; } = new Dictionary<String, NameIDInfo>();

private Info() { }
public static Info Instance()
{
if (mThis == null)
{
mThis = new Info();
mThis.Init();
}
return mThis;
}

private void Init()
{
AppendList(@"info\capsule.txt", Capsule);
}

private void AppendList<Type>(String filename, Dictionary<String, Type> items)
where Type : NameIDInfo, new()
{
if (!System.IO.File.Exists(filename)) return;
String[] lines = System.IO.File.ReadAllLines(filename);
foreach (String line in lines)
{
if (line.Length < 3) continue;
if (line[0] == '#') continue;
String[] values = line.Split('\t');
if (values.Length < 2) continue;
if (String.IsNullOrEmpty(values[0])) continue;
if (String.IsNullOrEmpty(values[1])) continue;

Type type = new Type();
if (type.Line(values))
{
items.Add(type.ID, type);
}
}
}
}
}
24 changes: 18 additions & 6 deletions ZeldaTOTK/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZeldaTOTK"
xmlns:prop="clr-namespace:ZeldaTOTK.Properties"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="Switch The Legend of Zelda Tears of the Kingdom SaveDate Editor" Height="450" Width="650">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Window.Resources>
<local:CapsuleIDNameConverter x:Key="CapsuleIDNameConverter"/>
</Window.Resources>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="Open" Command="{Binding FileOpenCommand}"/>
<MenuItem Header="Save" Command="{Binding FileSaveCommand}"/>
</MenuItem>
</Menu>
<ToolBar DockPanel.Dock="Top">
<ComboBox SelectedIndex="{Binding Path=lang, Source={x:Static prop:Settings.Default}}">
<ComboBoxItem Content="English"/>
<ComboBoxItem Content="日本語"/>
</ComboBox>
</ToolBar>
<TabControl>
<TabItem Header="Basic">
<TabItem.Resources>
Expand Down Expand Up @@ -145,7 +155,7 @@
<TabItem Header="Material">
<DockPanel>
<DockPanel DockPanel.Dock="Bottom">
<Label DockPanel.Dock="Left" Content="All Item"/>
<Label DockPanel.Dock="Left" Content="All Item Count"/>
<Button DockPanel.Dock="Right" Content="Execution"
Command="{Binding ChangeAllItemCountCommand}" CommandParameter="{Binding Materials}"/>
<TextBox Text="{Binding ItemCount}"/>
Expand All @@ -167,7 +177,7 @@
<TabItem Header="Food">
<DockPanel>
<DockPanel DockPanel.Dock="Bottom">
<Label DockPanel.Dock="Left" Content="All Item"/>
<Label DockPanel.Dock="Left" Content="All Item Count"/>
<Button DockPanel.Dock="Right" Content="Execution"
Command="{Binding ChangeAllItemCountCommand}" CommandParameter="{Binding Foods}"/>
<TextBox Text="{Binding ItemCount}"/>
Expand All @@ -189,19 +199,21 @@
<TabItem Header="Capsule">
<DockPanel>
<DockPanel DockPanel.Dock="Bottom">
<Label DockPanel.Dock="Left" Content="All Item"/>
<Label DockPanel.Dock="Left" Content="All Item Count"/>
<Button DockPanel.Dock="Right" Content="Execution"
Command="{Binding ChangeAllItemCountCommand}" CommandParameter="{Binding Capsules}"/>
<TextBox Text="{Binding ItemCount}"/>
</DockPanel>
<Button DockPanel.Dock="Bottom" Content="All Item"
Command="{Binding GetAllItemCommand}"
CommandParameter="{Binding Capsules}"/>
<ListBox ItemsSource="{Binding Capsules}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="Count"/>
<TextBox Text="{Binding Count, UpdateSourceTrigger=PropertyChanged}" Width="60"/>
<Label Content="ID"/>
<TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" Width="250"/>
<Label Content="{Binding Name, Converter={StaticResource CapsuleIDNameConverter}}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
Expand All @@ -211,7 +223,7 @@
<TabItem Header="KeyItem">
<DockPanel>
<DockPanel DockPanel.Dock="Bottom">
<Label DockPanel.Dock="Left" Content="All Item"/>
<Label DockPanel.Dock="Left" Content="All Item Count"/>
<Button DockPanel.Dock="Right" Content="Execution"
Command="{Binding ChangeAllItemCountCommand}" CommandParameter="{Binding KeyItems}"/>
<TextBox Text="{Binding ItemCount}"/>
Expand Down
38 changes: 38 additions & 0 deletions ZeldaTOTK/NameIDInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZeldaTOTK
{
internal class NameIDInfo
{
public String ID { get; set; } = "";
public String Name
{
get
{
if (Names.Count == 0) return "";

var index = Properties.Settings.Default.lang;
if (index >= Names.Count) return "";

var value = Names[index];
if (String.IsNullOrEmpty(value)) value = Names[0];
return value;
}
}
private List<String> Names { get; set; } = new List<String>();

public bool Line(String[] oneLine)
{
ID = oneLine[0];
for (int i = 1; i < oneLine.Length; i++)
{
Names.Add(oneLine[i]);
}
return true;
}
}
}
38 changes: 38 additions & 0 deletions ZeldaTOTK/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions ZeldaTOTK/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ZeldaTOTK.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="lang" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>
24 changes: 24 additions & 0 deletions ZeldaTOTK/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -11,6 +12,7 @@ namespace ZeldaTOTK
{
internal class ViewModel : INotifyPropertyChanged
{
public Info Info { get; private set; } = Info.Instance();
public uint ItemCount { get; set; } = 999;
public Basic? Basic { get; private set; } = new Basic();
public ObservableCollection<Item> Armors { get; private set; } = new ObservableCollection<Item>();
Expand All @@ -26,13 +28,15 @@ internal class ViewModel : INotifyPropertyChanged
public CommandAction? FileSaveCommand { get; private set; }
public CommandAction? IncrementLimitCountCommand { get; private set; }
public CommandAction? ChangeAllItemCountCommand { get; private set; }
public CommandAction? GetAllItemCommand { get; private set; }

public ViewModel()
{
FileOpenCommand = new CommandAction(LoadFile);
FileSaveCommand = new CommandAction(SaveFile);
IncrementLimitCountCommand = new CommandAction(IncrementLimitCount);
ChangeAllItemCountCommand = new CommandAction(ChangeAllItemCount);
GetAllItemCommand = new CommandAction(GetAllItem);
}

public event PropertyChangedEventHandler? PropertyChanged;
Expand Down Expand Up @@ -128,5 +132,25 @@ private void ChangeAllItemCount(Object? obj)
item.Count = ItemCount;
}
}

private void GetAllItem(Object? obj)
{
var items = obj as ObservableCollection<Item>;
if (items == null) return;
if (items != Capsules) return;

items.Clear();
uint count = 0x46184;
uint name = 0x9CBAC;
foreach (var info in Info.Instance().Capsule)
{
var item = new Item(count, name);
item.Count = ItemCount;
item.Name = info.Key;
items.Add(item);
count += 4;
name += 64;
}
}
}
}
15 changes: 15 additions & 0 deletions ZeldaTOTK/ZeldaTOTK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>

</Project>

0 comments on commit c5113f1

Please sign in to comment.