mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
Enhance TechRecord editor
Closes #3888 Closes #3879 Adds type sprite indication and green if the flag is legal to be set. Allow sort by has-flag, index, type, and move name. Sorting by Type will sort by type->valid->name for a nicely ordered view.
This commit is contained in:
parent
61fbdfe5f6
commit
ae07937de6
2 changed files with 157 additions and 24 deletions
|
@ -28,13 +28,17 @@ namespace PKHeX.WinForms
|
|||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
B_Save = new System.Windows.Forms.Button();
|
||||
B_Cancel = new System.Windows.Forms.Button();
|
||||
B_None = new System.Windows.Forms.Button();
|
||||
B_All = new System.Windows.Forms.Button();
|
||||
tipName = new System.Windows.Forms.ToolTip(components);
|
||||
CLB_Flags = new System.Windows.Forms.CheckedListBox();
|
||||
dgv = new System.Windows.Forms.DataGridView();
|
||||
HasFlag = new System.Windows.Forms.DataGridViewCheckBoxColumn();
|
||||
Index = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
Type = new System.Windows.Forms.DataGridViewImageColumn();
|
||||
TypeInt = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
MoveName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)dgv).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// B_Save
|
||||
|
@ -85,22 +89,79 @@ namespace PKHeX.WinForms
|
|||
B_All.UseVisualStyleBackColor = true;
|
||||
B_All.Click += B_All_Click;
|
||||
//
|
||||
// CLB_Flags
|
||||
// dgv
|
||||
//
|
||||
CLB_Flags.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
|
||||
CLB_Flags.CheckOnClick = true;
|
||||
CLB_Flags.FormattingEnabled = true;
|
||||
CLB_Flags.Location = new System.Drawing.Point(14, 14);
|
||||
CLB_Flags.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
CLB_Flags.Name = "CLB_Flags";
|
||||
CLB_Flags.Size = new System.Drawing.Size(216, 328);
|
||||
CLB_Flags.TabIndex = 6;
|
||||
dgv.AllowUserToAddRows = false;
|
||||
dgv.AllowUserToDeleteRows = false;
|
||||
dgv.AllowUserToResizeColumns = false;
|
||||
dgv.AllowUserToResizeRows = false;
|
||||
dgv.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
|
||||
dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
|
||||
dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dgv.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { HasFlag, Index, Type, TypeInt, MoveName });
|
||||
dgv.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
|
||||
dgv.Location = new System.Drawing.Point(3, 1);
|
||||
dgv.MultiSelect = false;
|
||||
dgv.Name = "dgv";
|
||||
dgv.RowHeadersVisible = false;
|
||||
dgv.RowTemplate.Height = 25;
|
||||
dgv.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
dgv.ShowEditingIcon = false;
|
||||
dgv.Size = new System.Drawing.Size(240, 359);
|
||||
dgv.TabIndex = 6;
|
||||
dgv.CellClick += ClickCell;
|
||||
dgv.ColumnHeaderMouseClick += SortColumn;
|
||||
dgv.KeyDown += PressKeyCell;
|
||||
//
|
||||
// HasFlag
|
||||
//
|
||||
HasFlag.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
|
||||
HasFlag.Frozen = true;
|
||||
HasFlag.HeaderText = "";
|
||||
HasFlag.Name = "HasFlag";
|
||||
HasFlag.ReadOnly = true;
|
||||
HasFlag.Resizable = System.Windows.Forms.DataGridViewTriState.False;
|
||||
HasFlag.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
|
||||
HasFlag.Width = 19;
|
||||
//
|
||||
// Index
|
||||
//
|
||||
Index.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
|
||||
Index.HeaderText = "";
|
||||
Index.Name = "Index";
|
||||
Index.ReadOnly = true;
|
||||
Index.Width = 19;
|
||||
//
|
||||
// Type
|
||||
//
|
||||
Type.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader;
|
||||
Type.HeaderText = "";
|
||||
Type.ImageLayout = System.Windows.Forms.DataGridViewImageCellLayout.Zoom;
|
||||
Type.Name = "Type";
|
||||
Type.ReadOnly = true;
|
||||
Type.Resizable = System.Windows.Forms.DataGridViewTriState.False;
|
||||
Type.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic;
|
||||
Type.Width = 5;
|
||||
//
|
||||
// TypeInt
|
||||
//
|
||||
TypeInt.HeaderText = "";
|
||||
TypeInt.Name = "TypeInt";
|
||||
TypeInt.ReadOnly = true;
|
||||
TypeInt.Visible = false;
|
||||
//
|
||||
// MoveName
|
||||
//
|
||||
MoveName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||
MoveName.HeaderText = "";
|
||||
MoveName.Name = "MoveName";
|
||||
MoveName.ReadOnly = true;
|
||||
//
|
||||
// TechRecordEditor
|
||||
//
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
ClientSize = new System.Drawing.Size(245, 438);
|
||||
Controls.Add(CLB_Flags);
|
||||
Controls.Add(dgv);
|
||||
Controls.Add(B_None);
|
||||
Controls.Add(B_All);
|
||||
Controls.Add(B_Cancel);
|
||||
|
@ -112,6 +173,7 @@ namespace PKHeX.WinForms
|
|||
Name = "TechRecordEditor";
|
||||
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
Text = "TR Relearn Editor";
|
||||
((System.ComponentModel.ISupportInitialize)dgv).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
|
@ -120,7 +182,11 @@ namespace PKHeX.WinForms
|
|||
private System.Windows.Forms.Button B_Cancel;
|
||||
private System.Windows.Forms.Button B_None;
|
||||
private System.Windows.Forms.Button B_All;
|
||||
private System.Windows.Forms.ToolTip tipName;
|
||||
private System.Windows.Forms.CheckedListBox CLB_Flags;
|
||||
private System.Windows.Forms.DataGridView dgv;
|
||||
private System.Windows.Forms.DataGridViewCheckBoxColumn HasFlag;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn Index;
|
||||
private System.Windows.Forms.DataGridViewImageColumn Type;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn TypeInt;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn MoveName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using PKHeX.Core;
|
||||
using PKHeX.Drawing.Misc;
|
||||
|
||||
namespace PKHeX.WinForms;
|
||||
|
||||
|
@ -9,25 +12,49 @@ public partial class TechRecordEditor : Form
|
|||
private readonly ITechRecord Record;
|
||||
private readonly PKM Entity;
|
||||
|
||||
private const int ColumnHasFlag = 0;
|
||||
private const int ColumnIndex = 1;
|
||||
private const int ColumnTypeIcon = 2;
|
||||
private const int ColumnType = 3;
|
||||
private const int ColumnName = 4;
|
||||
|
||||
public TechRecordEditor(ITechRecord techRecord, PKM pk)
|
||||
{
|
||||
Record = techRecord;
|
||||
Entity = pk;
|
||||
InitializeComponent();
|
||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||
|
||||
PopulateRecords();
|
||||
PopulateRecords(pk.Context);
|
||||
LoadRecords();
|
||||
}
|
||||
|
||||
private void PopulateRecords()
|
||||
private void PopulateRecords(EntityContext context)
|
||||
{
|
||||
var names = GameInfo.Strings.Move;
|
||||
var indexes = Record.Permit.RecordPermitIndexes;
|
||||
var lines = new string[indexes.Length];
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
lines[i] = $"{i:00} - {names[indexes[i]]}";
|
||||
CLB_Flags.Items.AddRange(lines);
|
||||
// Add the records to the datagrid.
|
||||
dgv.Rows.Add(indexes.Length);
|
||||
for (int i = 0; i < indexes.Length; i++)
|
||||
{
|
||||
var move = indexes[i];
|
||||
var type = MoveInfo.GetType(move, context);
|
||||
var isValid = Record.Permit.IsRecordPermitted(i);
|
||||
var row = dgv.Rows[i];
|
||||
if (isValid)
|
||||
{
|
||||
var cell = row.Cells[ColumnHasFlag];
|
||||
cell.Style.BackColor = cell.Style.SelectionBackColor = Color.LightGreen;
|
||||
}
|
||||
else
|
||||
{
|
||||
var cell = row.Cells[ColumnHasFlag];
|
||||
cell.Style.SelectionBackColor = Color.Red;
|
||||
}
|
||||
row.Cells[ColumnIndex].Value = i.ToString("000");
|
||||
row.Cells[ColumnTypeIcon].Value = TypeSpriteUtil.GetTypeSpriteIcon(type);
|
||||
row.Cells[ColumnType].Value = type.ToString("00") + (isValid ? 0 : 1) + names[move]; // type -> valid -> name sorting
|
||||
row.Cells[ColumnName].Value = names[move];
|
||||
}
|
||||
}
|
||||
|
||||
private void B_Cancel_Click(object sender, EventArgs e) => Close();
|
||||
|
@ -42,14 +69,22 @@ public partial class TechRecordEditor : Form
|
|||
{
|
||||
var range = Record.Permit.RecordPermitIndexes;
|
||||
for (int i = 0; i < range.Length; i++)
|
||||
CLB_Flags.SetItemChecked(i, Record.GetMoveRecordFlag(i));
|
||||
{
|
||||
var row = dgv.Rows[i];
|
||||
var index = int.Parse(row.Cells[ColumnIndex].Value?.ToString() ?? "");
|
||||
row.Cells[ColumnHasFlag].Value = Record.GetMoveRecordFlag(index);
|
||||
}
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
var range = Record.Permit.RecordPermitIndexes;
|
||||
for (int i = 0; i < range.Length; i++)
|
||||
Record.SetMoveRecordFlag(i, CLB_Flags.GetItemChecked(i));
|
||||
{
|
||||
var row = dgv.Rows[i];
|
||||
var index = int.Parse(row.Cells[ColumnIndex].Value?.ToString() ?? "");
|
||||
Record.SetMoveRecordFlag(index, (bool)row.Cells[ColumnHasFlag].Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void B_All_Click(object sender, EventArgs e)
|
||||
|
@ -79,4 +114,36 @@ public partial class TechRecordEditor : Form
|
|||
Record.ClearRecordFlags();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ClickCell(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
var rowInd = e.RowIndex;
|
||||
if (rowInd < 0)
|
||||
return;
|
||||
var row = dgv.Rows[rowInd];
|
||||
|
||||
// Toggle the checkbox of cell 0
|
||||
var cell = row.Cells[ColumnHasFlag];
|
||||
cell.Value = !(bool)cell.Value;
|
||||
}
|
||||
|
||||
private void PressKeyCell(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode != Keys.Space)
|
||||
return;
|
||||
|
||||
var row = dgv.CurrentRow;
|
||||
if (row == null)
|
||||
return;
|
||||
|
||||
// Toggle the checkbox of cell 0
|
||||
var cell = row.Cells[ColumnHasFlag];
|
||||
cell.Value = !(bool)cell.Value;
|
||||
}
|
||||
|
||||
private void SortColumn(object sender, DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex == ColumnTypeIcon)
|
||||
dgv.Sort(TypeInt, ListSortDirection.Ascending);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue