Add xmldoc

This commit is contained in:
Kurt
2025-05-23 20:44:06 -05:00
parent 1c03fc3e5b
commit 2f77b9c2aa
10 changed files with 195 additions and 42 deletions

View File

@@ -0,0 +1,21 @@
using System.Drawing;
using System.Runtime.CompilerServices;
using PKHeX.Core;
using PKHeX.Drawing.PokeSprite.Properties;
namespace PKHeX.WinForms.Controls;
public static class MoveDisplayState
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Bitmap? GetMoveImage(bool isIllegal, PKM pk, int index)
{
if (isIllegal)
return Resources.warn;
if (MoveInfo.IsDummiedMove(pk, index))
return Resources.hint;
return null;
}
}

View File

@@ -2,13 +2,11 @@
using PKHeX.Drawing;
using PKHeX.Drawing.Misc;
using PKHeX.Drawing.PokeSprite;
using PKHeX.Drawing.PokeSprite.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows.Forms;
using static PKHeX.Core.MessageStrings;
@@ -2299,18 +2297,3 @@ private void PB_MarkCured_Click(object sender, EventArgs e)
CB_PKRSStrain.DroppedDown = true;
}
}
public static class MoveDisplayState
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Bitmap? GetMoveImage(bool isIllegal, PKM pk, int index)
{
if (isIllegal)
return Resources.warn;
if (MoveInfo.IsDummiedMove(pk, index))
return Resources.hint;
return null;
}
}

View File

@@ -49,7 +49,7 @@ public void MouseClick(object? sender, MouseEventArgs e)
{
if (sender is null)
return;
if (!Drag.Info.DragDropInProgress)
if (!Drag.Info.IsDragDropInProgress)
SE.ClickSlot(sender, e);
}
@@ -58,7 +58,7 @@ public void MouseUp(object? sender, MouseEventArgs e)
if (sender is null)
return;
if (e.Button == MouseButtons.Left)
Drag.Info.LeftMouseIsDown = false;
Drag.Info.IsLeftMouseDown = false;
Drag.Info.Source = null;
}
@@ -68,7 +68,7 @@ public void MouseDown(object? sender, MouseEventArgs e)
return;
if (e.Button == MouseButtons.Left)
{
Drag.Info.LeftMouseIsDown = true;
Drag.Info.IsLeftMouseDown = true;
Drag.MouseDownPosition = Cursor.Position;
}
}
@@ -79,8 +79,8 @@ public void QueryContinueDrag(object? sender, QueryContinueDragEventArgs e)
return;
if (e.Action != DragAction.Cancel && e.Action != DragAction.Drop)
return;
Drag.Info.LeftMouseIsDown = false;
Drag.Info.DragDropInProgress = false;
Drag.Info.IsLeftMouseDown = false;
Drag.Info.IsDragDropInProgress = false;
}
public void DragEnter(object? sender, DragEventArgs e)
@@ -92,7 +92,7 @@ public void DragEnter(object? sender, DragEventArgs e)
else if (e.Data is not null) // within
e.Effect = DragDropEffects.Move;
if (Drag.Info.DragDropInProgress)
if (Drag.Info.IsDragDropInProgress)
Drag.SetCursor(((Control)sender).FindForm(), Drag.Info.Cursor);
}
@@ -144,7 +144,7 @@ private void HandleMovePKM(PictureBox pb, bool encrypt)
// Create a temporary PKM file to perform a drag drop operation.
// Set flag to prevent re-entering.
Drag.Info.DragDropInProgress = true;
Drag.Info.IsDragDropInProgress = true;
// Prepare Data
Drag.Info.Source = GetSlotInfo(pb);
@@ -163,7 +163,7 @@ private void HandleMovePKM(PictureBox pb, bool encrypt)
// Keep it to 20 seconds; Discord upload only stores the file path until you click Upload.
int delay = external ? 20_000 : 0;
DeleteAsync(newfile, delay);
if (Drag.Info.DragIsParty)
if (Drag.Info.IsDragParty)
SE.SetParty();
}
@@ -219,7 +219,7 @@ private bool TryMakeDragDropPKM(PictureBox pb, ReadOnlySpan<byte> data, string n
Drag.Info.CurrentPath = newfile;
var result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
var external = Drag.Info.Destination is null || result != DragDropEffects.Link;
if (external || Drag.Info.SameLocation) // not dropped to another box slot, restore img
if (external || Drag.Info.IsDragSameLocation) // not dropped to another box slot, restore img
{
pb.Image = img;
pb.BackgroundImage = LastSlot.OriginalBackground;
@@ -254,7 +254,7 @@ private void HandleDropPKM(PictureBox pb, DragEventArgs? e, DropModifier mod)
e.Effect = mod == DropModifier.Clone ? DragDropEffects.Copy : DragDropEffects.Link;
// file
if (Drag.Info.SameLocation)
if (Drag.Info.IsDragSameLocation)
{
e.Effect = DragDropEffects.Link;
return;
@@ -345,7 +345,7 @@ private bool TrySetPKMDestination(PictureBox pb, DropModifier mod)
TrySetPKMSource(mod);
// Copy from temp to destination slot.
var type = info.DragIsSwap ? SlotTouchType.Swap : SlotTouchType.Set;
var type = info.IsDragSwap ? SlotTouchType.Swap : SlotTouchType.Set;
Env.Slots.Set(info.Destination!.Slot, pk, type);
Drag.ResetCursor(pb.FindForm());
return true;
@@ -364,7 +364,7 @@ private bool TrySetPKMSource(DropModifier mod)
return true;
}
var type = info.DragIsSwap ? SlotTouchType.Swap : SlotTouchType.Set;
var type = info.IsDragSwap ? SlotTouchType.Swap : SlotTouchType.Set;
var pk = dest.ReadCurrent();
Env.Slots.Set(Drag.Info.Source!.Slot, pk, type);
return true;

View File

@@ -6,10 +6,21 @@
namespace PKHeX.WinForms.Controls;
/// <summary>
/// Provides functionality to play Pokémon cries using sound files.
/// </summary>
public sealed class CryPlayer
{
/// <summary>
/// The <see cref="SoundPlayer"/> instance used to play sound files.
/// </summary>
private readonly SoundPlayer Sounds = new();
/// <summary>
/// Plays the cry for the specified Pokémon species and form.
/// </summary>
/// <param name="pk">The Pokémon species and form information.</param>
/// <param name="context">The entity context (game generation).</param>
public void PlayCry(ISpeciesForm pk, EntityContext context)
{
if (pk.Species == 0)
@@ -24,6 +35,9 @@ public void PlayCry(ISpeciesForm pk, EntityContext context)
catch { Debug.WriteLine("Failed to play sound."); }
}
/// <summary>
/// Stops any currently playing cry.
/// </summary>
public void Stop()
{
if (string.IsNullOrWhiteSpace(Sounds.SoundLocation))
@@ -33,6 +47,13 @@ public void Stop()
catch { Debug.WriteLine("Failed to stop sound."); }
}
/// <summary>
/// Gets the file path for the cry sound file for the specified Pokémon.
/// </summary>
/// <param name="pk">The Pokémon species and form information.</param>
/// <param name="cryFolder">The folder containing cry sound files.</param>
/// <param name="context">The entity context (game generation).</param>
/// <returns>The file path to the cry sound file.</returns>
private static string GetCryPath(ISpeciesForm pk, string cryFolder, EntityContext context)
{
var name = GetCryFileName(pk, context);
@@ -42,6 +63,12 @@ private static string GetCryPath(ISpeciesForm pk, string cryFolder, EntityContex
return path;
}
/// <summary>
/// Gets the file name for the cry sound file for the specified Pokémon.
/// </summary>
/// <param name="pk">The Pokémon species and form information.</param>
/// <param name="context">The entity context (game generation).</param>
/// <returns>The file name for the cry sound file.</returns>
private static string GetCryFileName(ISpeciesForm pk, EntityContext context)
{
if (pk is { Species: (int)Species.Urshifu, Form: 1 }) // same sprite for both forms, but different cries

View File

@@ -2,7 +2,13 @@
namespace PKHeX.WinForms.Controls;
/// <summary>
/// Provides a DataGridView with double buffering enabled to reduce flicker.
/// </summary>
internal class DoubleBufferedDataGridView : DataGridView
{
/// <summary>
/// Initializes a new instance of the <see cref="DoubleBufferedDataGridView"/> class.
/// </summary>
public DoubleBufferedDataGridView() => SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}

View File

@@ -1,14 +1,35 @@
using System.Drawing;
using System.Drawing;
using System.Windows.Forms;
namespace PKHeX.WinForms.Controls;
/// <summary>
/// Manages drag-and-drop operations for slot controls.
/// </summary>
public sealed class DragManager
{
/// <summary>
/// Gets the current slot change information for drag-and-drop operations.
/// </summary>
public SlotChangeInfo<Cursor, PictureBox> Info { get; private set; } = new();
/// <summary>
/// Occurs when an external drag-and-drop operation is requested.
/// </summary>
public event DragEventHandler? RequestExternalDragDrop;
/// <summary>
/// Requests a drag-and-drop operation.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="e">The drag event arguments.</param>
public void RequestDD(object sender, DragEventArgs e) => RequestExternalDragDrop?.Invoke(sender, e);
/// <summary>
/// Sets the cursor for the specified form and updates the drag info.
/// </summary>
/// <param name="f">The form to set the cursor for.</param>
/// <param name="z">The cursor to set.</param>
public void SetCursor(Form? f, Cursor? z)
{
if (f is not null)
@@ -16,18 +37,35 @@ public void SetCursor(Form? f, Cursor? z)
Info.Cursor = z;
}
/// <summary>
/// Resets the cursor for the specified form to the default cursor.
/// </summary>
/// <param name="sender">The form to reset the cursor for.</param>
public void ResetCursor(Form? sender)
{
SetCursor(sender, Cursors.Default);
}
/// <summary>
/// Initializes the drag manager and resets the drag info.
/// </summary>
public void Initialize()
{
Info = new SlotChangeInfo<Cursor, PictureBox>();
}
/// <summary>
/// Resets the drag manager's slot change info.
/// </summary>
public void Reset() => Info.Reset();
/// <summary>
/// Gets or sets the mouse down position for drag detection.
/// </summary>
public Point MouseDownPosition { private get; set; }
public bool CanStartDrag => Info.LeftMouseIsDown && !Cursor.Position.Equals(MouseDownPosition);
/// <summary>
/// Gets a value indicating whether a drag operation can be started.
/// </summary>
public bool CanStartDrag => Info.IsLeftMouseDown && !Cursor.Position.Equals(MouseDownPosition);
}

View File

@@ -1,8 +1,20 @@
namespace PKHeX.WinForms.Controls;
/// <summary>
/// Specifies the modifier for a drag-and-drop operation.
/// </summary>
public enum DropModifier
{
/// <summary>
/// No modifier is applied.
/// </summary>
None,
/// <summary>
/// Overwrite the target slot.
/// </summary>
Overwrite,
/// <summary>
/// Clone the source slot.
/// </summary>
Clone,
}

View File

@@ -2,35 +2,67 @@
namespace PKHeX.WinForms.Controls;
/// <summary>
/// Represents information about a slot change during drag-and-drop operations.
/// </summary>
/// <typeparam name="TCursor">The type of the cursor object.</typeparam>
/// <typeparam name="TImageSource">The type of the image source object.</typeparam>
public sealed class SlotChangeInfo<TCursor, TImageSource>
where TCursor : class
where TImageSource : class
{
public bool LeftMouseIsDown { get; set; }
public bool DragDropInProgress { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the left mouse button is down.
/// </summary>
public bool IsLeftMouseDown { get; set; }
/// <summary>
/// Gets or sets a value indicating whether a drag-and-drop operation is in progress.
/// </summary>
public bool IsDragDropInProgress { get; set; }
/// <summary>
/// Gets or sets the current cursor.
/// </summary>
public TCursor? Cursor { get; set; }
/// <summary>
/// Gets or sets the current file path involved in the drag-and-drop operation.
/// </summary>
public string? CurrentPath { get; set; }
/// <summary>
/// Slot that is being dragged from.
/// </summary>
public SlotViewInfo<TImageSource>? Source { get; set; }
/// <summary>
/// Slot that is being dragged to.
/// </summary>
public SlotViewInfo<TImageSource>? Destination { get; set; }
/// <summary>
/// Resets the slot change information to its default state.
/// </summary>
public void Reset()
{
LeftMouseIsDown = DragDropInProgress = false;
IsLeftMouseDown = IsDragDropInProgress = false;
CurrentPath = null;
Cursor = null;
}
public bool SameLocation => (Destination is not null) && (Source?.Equals(Destination) ?? false);
private bool SourceIsParty => Source?.Slot is SlotInfoParty;
private bool DestinationIsParty => Destination?.Slot is SlotInfoParty;
private bool IsSourceParty => Source?.Slot is SlotInfoParty;
private bool IsDestinationParty => Destination?.Slot is SlotInfoParty;
/// <summary>
/// Used to indicate if the changes will alter the player's party data state.
/// </summary>
public bool DragIsParty => SourceIsParty || DestinationIsParty;
public bool IsDragParty => IsSourceParty || IsDestinationParty;
public bool DragIsSwap => Source is not null && Destination is not null;
/// <summary>
/// Used to indicate if the changes will involve two slots within the program.
/// </summary>
public bool IsDragSwap => Source is not null && Destination is not null;
/// <summary>
/// Used to indicate if the changes will involve two slots within the same location.
/// </summary>
public bool IsDragSameLocation => (Destination is not null) && (Source?.Equals(Destination) ?? false);
}

View File

@@ -12,7 +12,14 @@ namespace PKHeX.WinForms.Controls;
/// </summary>
public sealed class SlotHoverHandler : IDisposable
{
/// <summary>
/// Gets or sets the drawing configuration for the slot hover effect.
/// </summary>
public DrawConfig Draw { private get; set; } = new();
/// <summary>
/// Gets or sets a value indicating whether the hover effect should display a glow.
/// </summary>
public bool GlowHover { private get; set; } = true;
private readonly SummaryPreviewer Preview = new();
@@ -23,6 +30,11 @@ public sealed class SlotHoverHandler : IDisposable
private PictureBox? Slot;
private SlotTrackerImage? LastSlot;
/// <summary>
/// Starts the hover animation and preview for the specified slot.
/// </summary>
/// <param name="pb">The PictureBox representing the slot to animate.</param>
/// <param name="lastSlot">The last slot tracker image to update.</param>
public void Start(PictureBox pb, SlotTrackerImage lastSlot)
{
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<PictureBox>>(pb);
@@ -59,6 +71,9 @@ public void Start(PictureBox pb, SlotTrackerImage lastSlot)
Preview.Show(pb, pk);
}
/// <summary>
/// Stops the hover animation and restores the original slot background.
/// </summary>
public void Stop()
{
if (Slot is not null)
@@ -73,6 +88,9 @@ public void Stop()
Preview.Clear();
}
/// <summary>
/// Releases all resources used by the <see cref="SlotHoverHandler"/>.
/// </summary>
public void Dispose()
{
HoverWorker.Dispose();
@@ -80,6 +98,10 @@ public void Dispose()
Draw.Dispose();
}
/// <summary>
/// Updates the mouse position for the preview display.
/// </summary>
/// <param name="location">The current mouse location.</param>
public void UpdateMousePosition(Point location)
{
Preview.UpdatePreviewPosition(location);

View File

@@ -1,12 +1,24 @@
using System.Drawing;
using System.Drawing;
namespace PKHeX.WinForms.Controls;
/// <summary>
/// Tracks the background images for a slot, including the original and current backgrounds.
/// </summary>
public sealed class SlotTrackerImage
{
/// <summary>
/// Gets or sets the original background image of the slot.
/// </summary>
public Image? OriginalBackground { get; set; }
/// <summary>
/// Gets or sets the current background image of the slot.
/// </summary>
public Image? CurrentBackground { get; set; }
/// <summary>
/// Resets the background images to null.
/// </summary>
public void Reset()
{
OriginalBackground = CurrentBackground = null;