mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-24 15:54:14 -05:00
Relocate bean logic to core
This commit is contained in:
62
PKHeX.Core/Saves/Substructures/BeanPouch.cs
Normal file
62
PKHeX.Core/Saves/Substructures/BeanPouch.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
public class BeanPouch
|
||||
{
|
||||
public const int Count = 15;
|
||||
public static readonly string[] BeanIndexNames = GetBeanList();
|
||||
|
||||
public static string[] GetBeanList()
|
||||
{
|
||||
var colors = Enum.GetNames(typeof(BeanColor));
|
||||
var beans = new List<string>();
|
||||
// 7 regular, 7 patterned, one rainbow
|
||||
beans.AddRange(colors.Select(z => $"{z} Bean"));
|
||||
beans.AddRange(colors.Select(z => $"{z} Patterned Bean"));
|
||||
beans.Add("Rainbow Bean");
|
||||
return beans.ToArray();
|
||||
}
|
||||
|
||||
private enum BeanColor
|
||||
{
|
||||
Red,
|
||||
Blue,
|
||||
LightBlue,
|
||||
Green,
|
||||
Yellow,
|
||||
Purple,
|
||||
Orange,
|
||||
}
|
||||
|
||||
private readonly SAV7 SAV;
|
||||
public BeanPouch(SAV7 sav) => SAV = sav;
|
||||
|
||||
public int[] Beans
|
||||
{
|
||||
get => GetBeanCounts();
|
||||
set => SetBeanCounts(value);
|
||||
}
|
||||
private int[] GetBeanCounts()
|
||||
{
|
||||
int[] beans = new int[Count];
|
||||
for (int i = 0; i < beans.Length; i++)
|
||||
beans[i] = SAV.GetPokebeanCount(i);
|
||||
return beans;
|
||||
}
|
||||
private void SetBeanCounts(IReadOnlyList<int> beans)
|
||||
{
|
||||
if (beans.Count != Count)
|
||||
return;
|
||||
for (int i = 0; i < beans.Count; i++)
|
||||
SAV.SetPokebeanCount(i, beans[i]);
|
||||
}
|
||||
public void SetCountAll(int val)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
SAV.SetPokebeanCount(i, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using PKHeX.Core;
|
||||
|
||||
@@ -13,66 +12,53 @@ public SAV_Pokebean(SaveFile sav)
|
||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||
SAV = (SAV7)(Origin = sav).Clone();
|
||||
|
||||
var colors = new[] {"Red", "Blue", "Light Blue", "Green", "Yellow", "Purple", "Orange"};
|
||||
var beans = new List<string>();
|
||||
foreach (var color in colors)
|
||||
{
|
||||
beans.Add($"{color} Bean");
|
||||
}
|
||||
foreach (var color in colors)
|
||||
{
|
||||
beans.Add($"{color} Patterned Bean");
|
||||
}
|
||||
beans.Add("Rainbow Bean");
|
||||
beanlist = beans.ToArray();
|
||||
|
||||
Setup();
|
||||
InitializeGrid();
|
||||
Pouch = new BeanPouch(SAV);
|
||||
LoadValues();
|
||||
}
|
||||
|
||||
private const int MaxBeanID = 14;
|
||||
private readonly BeanPouch Pouch;
|
||||
|
||||
private readonly SaveFile Origin;
|
||||
private readonly SAV7 SAV;
|
||||
private readonly string[] beanlist;
|
||||
private void Setup()
|
||||
private void LoadValues()
|
||||
{
|
||||
dgv.Rows.Clear();
|
||||
dgv.Columns.Clear();
|
||||
|
||||
DataGridViewColumn dgvBean = new DataGridViewTextBoxColumn();
|
||||
var beans = Pouch.Beans;
|
||||
dgv.Rows.Add(beans.Length);
|
||||
for (int i = 0; i < beans.Length; i++)
|
||||
{
|
||||
dgvBean.HeaderText = "Slot";
|
||||
dgvBean.DisplayIndex = 0;
|
||||
dgvBean.Width = 135;
|
||||
dgvBean.ReadOnly = true;
|
||||
dgvBean.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||||
}
|
||||
DataGridViewComboBoxColumn dgvCount = new DataGridViewComboBoxColumn
|
||||
{
|
||||
DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
|
||||
DisplayIndex = 0,
|
||||
Width = 135,
|
||||
FlatStyle = FlatStyle.Flat,
|
||||
ValueType = typeof(int)
|
||||
};
|
||||
{
|
||||
for (var i = 0; i < 256; i++)
|
||||
dgvCount.Items.Add(i);
|
||||
|
||||
dgvCount.DisplayIndex = 1;
|
||||
dgvCount.Width = 45;
|
||||
dgvCount.FlatStyle = FlatStyle.Flat;
|
||||
}
|
||||
dgv.Columns.Add(dgvBean);
|
||||
dgv.Columns.Add(dgvCount);
|
||||
|
||||
dgv.Rows.Add(MaxBeanID + 1);
|
||||
for (int i = 0; i <= MaxBeanID; i++)
|
||||
{
|
||||
dgv.Rows[i].Cells[0].Value = beanlist[i];
|
||||
dgv.Rows[i].Cells[1].Value = SAV.GetPokebeanCount(i);
|
||||
dgv.Rows[i].Cells[0].Value = BeanPouch.BeanIndexNames[i];
|
||||
dgv.Rows[i].Cells[1].Value = beans[i];
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeGrid()
|
||||
{
|
||||
var dgvBean = new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = "Slot",
|
||||
DisplayIndex = 0,
|
||||
Width = 135,
|
||||
ReadOnly = true,
|
||||
DefaultCellStyle = {Alignment = DataGridViewContentAlignment.MiddleCenter}
|
||||
};
|
||||
var dgvCount = new DataGridViewComboBoxColumn
|
||||
{
|
||||
DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
|
||||
FlatStyle = FlatStyle.Flat,
|
||||
ValueType = typeof(int),
|
||||
DisplayIndex = 1,
|
||||
Width = 45
|
||||
};
|
||||
for (var i = 0; i < 256; i++)
|
||||
dgvCount.Items.Add(i);
|
||||
|
||||
dgv.Columns.Add(dgvBean);
|
||||
dgv.Columns.Add(dgvCount);
|
||||
}
|
||||
|
||||
private static void DropClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex != 1) return;
|
||||
@@ -85,21 +71,23 @@ private void B_Cancel_Click(object sender, EventArgs e)
|
||||
}
|
||||
private void B_All_Click(object sender, EventArgs e)
|
||||
{
|
||||
for (int i = 0; i <= MaxBeanID; i++)
|
||||
SAV.SetPokebeanCount(i, 255);
|
||||
Setup();
|
||||
Pouch.SetCountAll(255);
|
||||
LoadValues();
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
private void B_None_Click(object sender, EventArgs e)
|
||||
{
|
||||
for (int i = 0; i <= MaxBeanID; i++)
|
||||
SAV.SetPokebeanCount(i, 0);
|
||||
Setup();
|
||||
Pouch.SetCountAll(0);
|
||||
LoadValues();
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
private void B_Save_Click(object sender, EventArgs e)
|
||||
{
|
||||
for (int i = 0; i <= MaxBeanID; i++)
|
||||
SAV.SetPokebeanCount(i, (int)dgv.Rows[i].Cells[1].Value);
|
||||
var beans = Pouch.Beans;
|
||||
for (int i = 0; i < beans.Length; i++)
|
||||
beans[i] = (int)dgv.Rows[i].Cells[1].Value;
|
||||
Pouch.Beans = beans;
|
||||
Origin.SetData(SAV.Data, 0);
|
||||
Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user