mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
Extract trainer stat to interface / usercontrol
This commit is contained in:
parent
2e02ec9719
commit
e915cd170b
7 changed files with 337 additions and 10 deletions
|
@ -8,7 +8,7 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Generation 7 <see cref="SaveFile"/> object.
|
||||
/// </summary>
|
||||
public sealed class SAV7 : SaveFile
|
||||
public sealed class SAV7 : SaveFile, ITrainerStatRecord
|
||||
{
|
||||
// Save Data Attributes
|
||||
public override string BAKName => $"{FileName} [{OT} ({Version}) - {LastSavedTime}].bak";
|
||||
|
@ -727,8 +727,8 @@ namespace PKHeX.Core
|
|||
return Record + recordID*2 + 200; // first 100 are 4bytes, so bias the difference
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int GetRecordMax(int recordID, int[] maxes = null) => recordID < 200 ? RecordMax[(maxes ?? RecordMaxType_USUM)[recordID]] : 0;
|
||||
public int GetRecordMax(int recordID) => GetRecordMax(recordID, USUM ? RecordMaxType_USUM : RecordMaxType_SM);
|
||||
private static int GetRecordMax(int recordID, int[] maxes) => recordID < 200 ? RecordMax[(maxes ?? RecordMaxType_USUM)[recordID]] : 0;
|
||||
private static readonly int[] RecordMax = {999999999, 9999999, 999999, 99999, 65535, 9999, 999};
|
||||
private static readonly int[] RecordMaxType_SM =
|
||||
{
|
||||
|
|
10
PKHeX.Core/Saves/Substructures/ITrainerStatRecord.cs
Normal file
10
PKHeX.Core/Saves/Substructures/ITrainerStatRecord.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
public interface ITrainerStatRecord
|
||||
{
|
||||
int GetRecord(int recordID);
|
||||
int GetRecordOffset(int recordID);
|
||||
int GetRecordMax(int recordID);
|
||||
void SetRecord(int recordID, int value);
|
||||
}
|
||||
}
|
|
@ -557,6 +557,12 @@
|
|||
<Compile Include="Subforms\Save Editors\SAV_Wondercard.Designer.cs">
|
||||
<DependentUpon>SAV_Wondercard.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\Save Editors\TrainerStat.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\Save Editors\TrainerStat.Designer.cs">
|
||||
<DependentUpon>TrainerStat.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\SAV_Database.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -788,6 +794,9 @@
|
|||
<EmbeddedResource Include="Subforms\Save Editors\SAV_Wondercard.resx">
|
||||
<DependentUpon>SAV_Wondercard.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Subforms\Save Editors\TrainerStat.resx">
|
||||
<DependentUpon>TrainerStat.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Subforms\SAV_Database.resx">
|
||||
<DependentUpon>SAV_Database.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
|
|
@ -581,7 +581,7 @@ namespace PKHeX.WinForms
|
|||
{
|
||||
editing = true;
|
||||
int index = CB_Stats.SelectedIndex;
|
||||
NUD_Stat.Maximum = SAV7.GetRecordMax(index);
|
||||
NUD_Stat.Maximum = SAV.GetRecordMax(index);
|
||||
NUD_Stat.Value = SAV.GetRecord(index);
|
||||
|
||||
int offset = SAV.GetRecordOffset(index);
|
||||
|
@ -616,14 +616,15 @@ namespace PKHeX.WinForms
|
|||
if (RecordList.TryGetValue(index, out string tip))
|
||||
Tip3.SetToolTip(CB_Stats, tip);
|
||||
}
|
||||
private static string ConvertDateValueToString(int value, int refval = -1)
|
||||
private static string ConvertDateValueToString(int value, int secondsBias = -1)
|
||||
{
|
||||
string tip = "";
|
||||
if (value >= 86400)
|
||||
tip += value / 86400 + "d ";
|
||||
const int spd = 86400; // seconds per day
|
||||
string tip = string.Empty;
|
||||
if (value >= spd)
|
||||
tip += (value / spd) + "d ";
|
||||
tip += new DateTime(0).AddSeconds(value).ToString("HH:mm:ss");
|
||||
if (refval >= 0)
|
||||
tip += Environment.NewLine + $"Date: {new DateTime(2000, 1, 1).AddSeconds(refval + value)}";
|
||||
if (secondsBias >= 0)
|
||||
tip += Environment.NewLine + $"Date: {new DateTime(2000, 1, 1).AddSeconds(value + secondsBias)}";
|
||||
return tip;
|
||||
}
|
||||
|
||||
|
|
100
PKHeX.WinForms/Subforms/Save Editors/TrainerStat.Designer.cs
generated
Normal file
100
PKHeX.WinForms/Subforms/Save Editors/TrainerStat.Designer.cs
generated
Normal file
|
@ -0,0 +1,100 @@
|
|||
namespace PKHeX.WinForms.Subforms.Save_Editors
|
||||
{
|
||||
partial class TrainerStat
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.NUD_Stat = new System.Windows.Forms.NumericUpDown();
|
||||
this.L_Offset = new System.Windows.Forms.Label();
|
||||
this.L_Value = new System.Windows.Forms.Label();
|
||||
this.CB_Stats = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.NUD_Stat)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// NUD_Stat
|
||||
//
|
||||
this.NUD_Stat.Location = new System.Drawing.Point(40, 25);
|
||||
this.NUD_Stat.Name = "NUD_Stat";
|
||||
this.NUD_Stat.Size = new System.Drawing.Size(103, 20);
|
||||
this.NUD_Stat.TabIndex = 35;
|
||||
this.NUD_Stat.ValueChanged += new System.EventHandler(this.ChangeStatVal);
|
||||
//
|
||||
// L_Offset
|
||||
//
|
||||
this.L_Offset.Font = new System.Drawing.Font("Courier New", 8.25F);
|
||||
this.L_Offset.Location = new System.Drawing.Point(3, 48);
|
||||
this.L_Offset.Name = "L_Offset";
|
||||
this.L_Offset.Size = new System.Drawing.Size(140, 20);
|
||||
this.L_Offset.TabIndex = 34;
|
||||
this.L_Offset.Text = "(offset)";
|
||||
this.L_Offset.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||
//
|
||||
// L_Value
|
||||
//
|
||||
this.L_Value.AutoSize = true;
|
||||
this.L_Value.Location = new System.Drawing.Point(0, 27);
|
||||
this.L_Value.Name = "L_Value";
|
||||
this.L_Value.Size = new System.Drawing.Size(34, 13);
|
||||
this.L_Value.TabIndex = 32;
|
||||
this.L_Value.Text = "Value";
|
||||
//
|
||||
// CB_Stats
|
||||
//
|
||||
this.CB_Stats.DropDownHeight = 256;
|
||||
this.CB_Stats.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.CB_Stats.DropDownWidth = 200;
|
||||
this.CB_Stats.FormattingEnabled = true;
|
||||
this.CB_Stats.IntegralHeight = false;
|
||||
this.CB_Stats.Location = new System.Drawing.Point(3, 3);
|
||||
this.CB_Stats.Name = "CB_Stats";
|
||||
this.CB_Stats.Size = new System.Drawing.Size(140, 21);
|
||||
this.CB_Stats.TabIndex = 33;
|
||||
this.CB_Stats.SelectedIndexChanged += new System.EventHandler(this.ChangeStat);
|
||||
//
|
||||
// TrainerStat
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
this.Controls.Add(this.NUD_Stat);
|
||||
this.Controls.Add(this.L_Offset);
|
||||
this.Controls.Add(this.L_Value);
|
||||
this.Controls.Add(this.CB_Stats);
|
||||
this.Name = "TrainerStat";
|
||||
this.Size = new System.Drawing.Size(146, 72);
|
||||
((System.ComponentModel.ISupportInitialize)(this.NUD_Stat)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.NumericUpDown NUD_Stat;
|
||||
private System.Windows.Forms.Label L_Offset;
|
||||
private System.Windows.Forms.Label L_Value;
|
||||
private System.Windows.Forms.ComboBox CB_Stats;
|
||||
}
|
||||
}
|
87
PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs
Normal file
87
PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs
Normal file
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using PKHeX.Core;
|
||||
|
||||
namespace PKHeX.WinForms.Subforms.Save_Editors
|
||||
{
|
||||
public partial class TrainerStat : UserControl
|
||||
{
|
||||
public TrainerStat()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private bool Editing;
|
||||
private ITrainerStatRecord SAV;
|
||||
|
||||
public void LoadRecords(ITrainerStatRecord sav, Dictionary<int, string> records)
|
||||
{
|
||||
SAV = sav;
|
||||
RecordList = records;
|
||||
CB_Stats.Items.Clear();
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
if (!RecordList.TryGetValue(i, out string name))
|
||||
name = $"{i:D3}";
|
||||
|
||||
CB_Stats.Items.Add(name);
|
||||
}
|
||||
CB_Stats.SelectedIndex = RecordList.First().Key;
|
||||
}
|
||||
|
||||
private Dictionary<int, string> RecordList; // index, description
|
||||
|
||||
private void ChangeStat(object sender, EventArgs e)
|
||||
{
|
||||
Editing = true;
|
||||
int index = CB_Stats.SelectedIndex;
|
||||
NUD_Stat.Maximum = SAV.GetRecordMax(index);
|
||||
NUD_Stat.Value = SAV.GetRecord(index);
|
||||
|
||||
int offset = SAV.GetRecordOffset(index);
|
||||
L_Offset.Text = $"Offset: 0x{offset:X3}";
|
||||
UpdateTip(index, true);
|
||||
Editing = false;
|
||||
}
|
||||
private void ChangeStatVal(object sender, EventArgs e)
|
||||
{
|
||||
if (Editing)
|
||||
return;
|
||||
int index = CB_Stats.SelectedIndex;
|
||||
SAV.SetRecord(index, (int)NUD_Stat.Value);
|
||||
UpdateTip(index, false);
|
||||
}
|
||||
|
||||
private readonly ToolTip Tip3 = new ToolTip();
|
||||
public Func<int, string> GetToolTipText { private get; set; }
|
||||
private void UpdateTip(int index, bool updateStats)
|
||||
{
|
||||
if (GetToolTipText != null)
|
||||
UpdateToolTipSpecial(index, updateStats);
|
||||
else
|
||||
UpdateToolTipDefault(index, updateStats);
|
||||
}
|
||||
|
||||
private void UpdateToolTipSpecial(int index, bool updateStats)
|
||||
{
|
||||
var str = GetToolTipText(index);
|
||||
if (str != null)
|
||||
{
|
||||
Tip3.SetToolTip(NUD_Stat, str);
|
||||
return;
|
||||
}
|
||||
UpdateToolTipDefault(index, updateStats); // fallback
|
||||
}
|
||||
private void UpdateToolTipDefault(int index, bool updateStats)
|
||||
{
|
||||
if (!updateStats || !RecordList.TryGetValue(index, out string tip))
|
||||
{
|
||||
Tip3.RemoveAll();
|
||||
return;
|
||||
}
|
||||
Tip3.SetToolTip(CB_Stats, tip);
|
||||
}
|
||||
}
|
||||
}
|
120
PKHeX.WinForms/Subforms/Save Editors/TrainerStat.resx
Normal file
120
PKHeX.WinForms/Subforms/Save Editors/TrainerStat.resx
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
Reference in a new issue