mirror of
https://github.com/kwsch/PKHeX
synced 2025-03-04 07:17:15 +00:00
https://github.com/kwsch/PKHeX/issues/3758#issuecomment-1417458988 Removes the Level textbox behavior that resets the text to "1" when the textbox is empty. Can be left empty, and will be treated as 1 when values are stored. Adds an accessibility label for the "Make Shiny" button Adds an accessibility description and enter/space keypress to toggle similar to the click event. For determining if something is shiny, if the Shiny button is not tab-able, it is shiny. I wasn't able to get the Shiny star/square indicator to be able to be tabbed to for some reason.
93 lines
2.3 KiB
C#
93 lines
2.3 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.Automation;
|
|
using static PKHeX.WinForms.Properties.Resources;
|
|
|
|
namespace PKHeX.WinForms.Controls;
|
|
|
|
public partial class GenderToggle : UserControl, IGenderToggle
|
|
{
|
|
public bool AllowClick { get; set; } = true;
|
|
|
|
private int Value = -1; // Initial load will trigger gender to appear (-1 => 0)
|
|
|
|
public int Gender
|
|
{
|
|
get => Value;
|
|
set => Value = SetGender(value);
|
|
}
|
|
|
|
public GenderToggle() => InitializeComponent();
|
|
|
|
private static readonly Image[] GenderImages =
|
|
{
|
|
gender_0,
|
|
gender_1,
|
|
gender_2,
|
|
};
|
|
|
|
private int SetGender(int value)
|
|
{
|
|
if ((uint)value > 2)
|
|
value = 2;
|
|
if (Value != value)
|
|
BackgroundImage = GenderImages[value];
|
|
return value;
|
|
}
|
|
|
|
private void GenderToggle_Click(object sender, EventArgs e)
|
|
{
|
|
if (!AllowClick)
|
|
return;
|
|
TryToggle();
|
|
}
|
|
|
|
private void GenderToggle_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode is not (Keys.Enter or Keys.Space))
|
|
return;
|
|
|
|
TryToggle();
|
|
}
|
|
|
|
private void TryToggle()
|
|
{
|
|
var result = ToggleGender();
|
|
if (!result.CanToggle)
|
|
{
|
|
AccessibilityObject.RaiseAutomationNotification(AutomationNotificationKind.Other,
|
|
AutomationNotificationProcessing.All, $"Cannot change gender. Current value is {Gender}.");
|
|
return;
|
|
}
|
|
|
|
AccessibilityObject.RaiseAutomationNotification(AutomationNotificationKind.Other,
|
|
AutomationNotificationProcessing.All, $"Gender changed to {Gender}.");
|
|
}
|
|
|
|
public (bool CanToggle, int Value) ToggleGender()
|
|
{
|
|
if ((uint)Gender < 2)
|
|
return (true, Gender ^= 1);
|
|
return (false, Gender);
|
|
}
|
|
}
|
|
|
|
public interface IGenderToggle
|
|
{
|
|
/// <summary>
|
|
/// Enables use of the built in click action.
|
|
/// </summary>
|
|
bool AllowClick { get; set; }
|
|
|
|
/// <summary>
|
|
/// Get or set the value the control displays.
|
|
/// </summary>
|
|
int Gender { get; set; }
|
|
|
|
/// <summary>
|
|
/// Manually flips the gender state if possible.
|
|
/// </summary>
|
|
/// <returns>True if can toggle, and the resulting value.</returns>
|
|
(bool CanToggle, int Value) ToggleGender();
|
|
}
|