mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-04-25 08:10:48 -05:00
Add ShowLegalBallsFirst setting (default true)
Shows the legal (green background) balls before illegal (red background) balls. Little easier than hunting around for the green background balls :)
This commit is contained in:
parent
136f742299
commit
23d726e69a
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using PKHeX.Core;
|
||||
|
|
@ -14,45 +13,73 @@ public partial class BallBrowser : Form
|
|||
|
||||
public int BallChoice { get; private set; } = -1;
|
||||
|
||||
public void LoadBalls(Ball[] poss, ICollection<Ball> legal, IReadOnlyList<ComboItem> names)
|
||||
public void LoadBalls(PKM pk)
|
||||
{
|
||||
for (int i = 0; i < poss.Length; i++)
|
||||
var legal = BallApplicator.GetLegalBalls(pk);
|
||||
LoadBalls(legal, pk.MaxBallID + 1);
|
||||
}
|
||||
|
||||
private void LoadBalls(IEnumerable<Ball> legal, int max)
|
||||
{
|
||||
Span<bool> flags = stackalloc bool[max];
|
||||
foreach (var ball in legal)
|
||||
flags[(int)ball] = true;
|
||||
|
||||
int countLegal = 0;
|
||||
List<PictureBox> controls = new();
|
||||
var names = GameInfo.BallDataSource;
|
||||
for (int ballID = 1; ballID < flags.Length; ballID++)
|
||||
{
|
||||
var pb = GetBallView(poss[i], legal, names);
|
||||
flp.Controls.Add(pb);
|
||||
var name = GetBallName(ballID, names);
|
||||
var pb = GetBallView(ballID, name, flags[ballID]);
|
||||
if (Main.Settings.EntityEditor.ShowLegalBallsFirst && flags[ballID])
|
||||
controls.Insert(countLegal++, pb);
|
||||
else
|
||||
controls.Add(pb);
|
||||
}
|
||||
|
||||
int countInRow = 0;
|
||||
var container = flp.Controls;
|
||||
foreach (var pb in controls)
|
||||
{
|
||||
container.Add(pb);
|
||||
const int width = 5; // balls wide
|
||||
if (i % width == width - 1)
|
||||
flp.SetFlowBreak(pb, true);
|
||||
if (++countInRow != width)
|
||||
continue;
|
||||
flp.SetFlowBreak(pb, true);
|
||||
countInRow = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadBalls(PKM pk)
|
||||
private static string GetBallName(int ballID, IEnumerable<ComboItem> names)
|
||||
{
|
||||
var legal = BallApplicator.GetLegalBalls(pk).ToArray();
|
||||
var poss = ((Ball[])Enum.GetValues(typeof(Ball))).Skip(1)
|
||||
.TakeWhile(z => (int)z <= pk.MaxBallID).ToArray();
|
||||
var names = GameInfo.BallDataSource;
|
||||
LoadBalls(poss, legal, names);
|
||||
foreach (var x in names)
|
||||
{
|
||||
if (x.Value == ballID)
|
||||
return x.Text;
|
||||
}
|
||||
throw new ArgumentOutOfRangeException(nameof(ballID));
|
||||
}
|
||||
|
||||
private PictureBox GetBallView(Ball b, ICollection<Ball> legal, IReadOnlyList<ComboItem> names)
|
||||
private PictureBox GetBallView(int ballID, string name, bool valid)
|
||||
{
|
||||
var img = SpriteUtil.GetBallSprite((int)b);
|
||||
var img = SpriteUtil.GetBallSprite(ballID);
|
||||
var pb = new PictureBox
|
||||
{
|
||||
Size = img.Size,
|
||||
Image = img,
|
||||
BackgroundImage = legal.Contains(b) ? SpriteUtil.Spriter.Set : SpriteUtil.Spriter.Delete,
|
||||
BackgroundImage = valid ? SpriteUtil.Spriter.Set : SpriteUtil.Spriter.Delete,
|
||||
BackgroundImageLayout = ImageLayout.Tile,
|
||||
};
|
||||
pb.MouseEnter += (_, _) => Text = names.First(z => z.Value == (int)b).Text;
|
||||
pb.Click += (_, _) => SelectBall(b);
|
||||
|
||||
pb.MouseEnter += (_, _) => Text = name;
|
||||
pb.Click += (_, _) => SelectBall(ballID);
|
||||
return pb;
|
||||
}
|
||||
|
||||
private void SelectBall(Ball b)
|
||||
private void SelectBall(int b)
|
||||
{
|
||||
BallChoice = (int)b;
|
||||
BallChoice = b;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
|
@ -270,6 +270,9 @@ public sealed class EntityEditorSettings
|
|||
{
|
||||
[LocalizedDescription("When changing the Hidden Power type, automatically maximize the IVs to ensure the highest Base Power result. Otherwise, keep the IVs as close as possible to the original.")]
|
||||
public bool HiddenPowerOnChangeMaxPower { get; set; } = true;
|
||||
|
||||
[LocalizedDescription("When showing the list of balls to select, show the legal balls before the illegal balls rather than sorting by Ball ID.")]
|
||||
public bool ShowLegalBallsFirst { get; set; } = true;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user