mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-08 00:01:45 -05:00
* Update to .NET 10 * Property fields * API signature updates * Extension method blocks * Completed dark mode support Outside of my control: - vertical tab control (pkm editor) - datetimepicker controls - lgpe event flags (no idea) - some control types having white-borders when they should really be gray Box background is 50% transparency to effectively darken the image. * Custom legality report popup * Event diff dialog, version select dialog * Add quick overwrite popup for export sav * Extension methods * Dark Mode: glow currently editing sprite * Add invalid encounter hint for trade evolutions * Extension properties * Append legality hint on hover card * Slot image loading: clear the screen-reader description if a slot is empty/invalid, rather than retain the previous description. Changing boxes would easily confuse users on this.
95 lines
3.4 KiB
C#
95 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Logic for creating a formatted text summary of an encounter.
|
|
/// </summary>
|
|
public static class EncounterText
|
|
{
|
|
private static EncounterDisplayContext GetContext(string language = GameLanguage.DefaultLanguage) => new()
|
|
{
|
|
Localization = EncounterDisplayLocalization.Get(language),
|
|
Strings = GameInfo.GetStrings(language),
|
|
};
|
|
|
|
extension(IEncounterInfo enc)
|
|
{
|
|
public IReadOnlyList<string> GetTextLines(bool verbose = false, string language = GameLanguage.DefaultLanguage) => enc.GetTextLines(GetContext(language), verbose);
|
|
|
|
public IReadOnlyList<string> GetTextLines(EncounterDisplayContext ctx, bool verbose = false)
|
|
{
|
|
var lines = new List<string>();
|
|
var loc = ctx.Localization;
|
|
var name = ctx.GetSpeciesName(enc);
|
|
lines.Add(string.Format(loc.Format, loc.EncounterType, name));
|
|
|
|
if (enc is MysteryGift mg)
|
|
{
|
|
lines.AddRange(mg.GetDescription());
|
|
}
|
|
else if (enc is IMoveset m)
|
|
{
|
|
var moves = m.Moves;
|
|
if (moves.HasMoves)
|
|
lines.Add(ctx.GetMoveset(moves));
|
|
}
|
|
|
|
var location = enc.GetEncounterLocation(enc.Generation, enc.Version);
|
|
if (!string.IsNullOrEmpty(location))
|
|
lines.Add(string.Format(loc.Format, loc.Location, location));
|
|
|
|
lines.Add(ctx.GetVersionDisplay(enc));
|
|
lines.Add(ctx.GetLevelDisplay(enc));
|
|
|
|
if (!verbose)
|
|
return lines;
|
|
|
|
// Record types! Can get a nice summary.
|
|
// Won't work neatly for Mystery Gift types since those aren't record types, plus they have way too many properties.
|
|
if (enc is not MysteryGift)
|
|
{
|
|
// ReSharper disable once ConstantNullCoalescingCondition
|
|
var raw = enc.ToString() ?? throw new ArgumentNullException(nameof(enc));
|
|
lines.AddRange(raw.Split(',', '}', '{'));
|
|
}
|
|
return lines;
|
|
}
|
|
}
|
|
}
|
|
|
|
public readonly record struct EncounterDisplayContext
|
|
{
|
|
public required EncounterDisplayLocalization Localization { get; init; }
|
|
public required GameStrings Strings { get; init; }
|
|
|
|
public string GetSpeciesName(IEncounterTemplate enc)
|
|
{
|
|
var encSpecies = enc.Species;
|
|
var str = Strings.Species;
|
|
var name = (uint)encSpecies < str.Count ? str[encSpecies] : encSpecies.ToString();
|
|
var EncounterName = $"{(enc is IEncounterable ie ? ie.LongName : "Special")} ({name})";
|
|
return EncounterName;
|
|
}
|
|
|
|
public string GetMoveset(Moveset moves) => moves.GetMovesetLine(Strings.movelist);
|
|
|
|
public string GetVersionDisplay(IEncounterTemplate enc)
|
|
{
|
|
var version = enc.Version;
|
|
var versionName = version.IsValidSavedVersion()
|
|
? Strings.gamelist[(int)version]
|
|
: version.ToString();
|
|
|
|
return string.Format(Localization.Format, Localization.Version, versionName);
|
|
}
|
|
|
|
public string GetLevelDisplay(IEncounterTemplate enc)
|
|
{
|
|
if (enc.LevelMin == enc.LevelMax)
|
|
return string.Format(Localization.Format, Localization.Level, enc.LevelMin);
|
|
return string.Format(Localization.FormatLevelRange, Localization.LevelRange, enc.LevelMin, enc.LevelMax);
|
|
}
|
|
}
|