forked from kwsch/PKHeX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Might trickle this out to the other editors that have gender toggles.
- Loading branch information
Showing
14 changed files
with
399 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
PKHeX.WinForms/Controls/PKM Editor/GenderToggle.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
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; | ||
|
||
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, System.EventArgs e) | ||
{ | ||
if (!AllowClick) | ||
return; | ||
ToggleGender(); | ||
} | ||
|
||
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.