mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-06-18 03:09:15 -05:00
Misc updates
add comboitem list to string[] add regions list as cached comboitem list lock resource cache on fetch extract alola time list generating
This commit is contained in:
parent
d681933a44
commit
82a40cb965
|
|
@ -1,4 +1,6 @@
|
|||
namespace PKHeX.Core
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Key Value pair for a displayed <see cref="string"/> and underlying <see cref="int"/> value.
|
||||
|
|
@ -8,4 +10,21 @@ public struct ComboItem
|
|||
public string Text { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public static class ComboItemExtensions
|
||||
{
|
||||
public static string[] GetArray(this IReadOnlyList<ComboItem> list)
|
||||
{
|
||||
var max = list[list.Count - 1].Value;
|
||||
return GetArray(list, max);
|
||||
}
|
||||
|
||||
public static string[] GetArray(this IEnumerable<ComboItem> list, int max)
|
||||
{
|
||||
var arr = new string[max + 1];
|
||||
foreach (var item in list)
|
||||
arr[item.Value] = item.Text;
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ public static string GetVersionName(GameVersion version)
|
|||
public static IReadOnlyList<ComboItem> HaXMoveDataSource => Strings.HaXMoveDataSource;
|
||||
public static IReadOnlyList<ComboItem> MoveDataSource => Strings.MoveDataSource;
|
||||
public static IReadOnlyList<ComboItem> EncounterTypeDataSource => Strings.EncounterTypeDataSource;
|
||||
public static IReadOnlyList<ComboItem> Regions => GameStrings.Regions;
|
||||
|
||||
public static IReadOnlyList<ComboItem> LanguageDataSource(int gen) => GameStrings.LanguageDataSource(gen);
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ public class GameStrings : IBasicStrings
|
|||
private string[] Get(string ident) => GameInfo.GetStrings(ident, lang);
|
||||
private const string NPC = "NPC";
|
||||
private static readonly string[] abilIdentifier = { " (1)", " (2)", " (H)" };
|
||||
public static readonly IReadOnlyList<ComboItem> Regions = Util.GetUnsortedCBList("regions3ds");
|
||||
private static readonly IReadOnlyList<ComboItem> LanguageList = Util.GetUnsortedCBList("languages");
|
||||
private static readonly string[] LanguageNames = LanguageList.GetArray();
|
||||
|
||||
public GameStrings(string l)
|
||||
{
|
||||
|
|
@ -84,7 +86,7 @@ public GameStrings(string l)
|
|||
wallpapernames = Get("wallpaper");
|
||||
encountertypelist = Get("encountertype");
|
||||
gamelist = Get("games");
|
||||
gamelanguages = Util.GetNulledStringArray(Util.GetStringList("languages"));
|
||||
gamelanguages = LanguageNames;
|
||||
|
||||
balllist = new string[Legal.Items_Ball.Length];
|
||||
for (int i = 0; i < balllist.Length; i++)
|
||||
|
|
|
|||
|
|
@ -79,8 +79,11 @@ public static partial class Util
|
|||
|
||||
public static string[] GetStringList(string f)
|
||||
{
|
||||
if (stringListCache.ContainsKey(f))
|
||||
return (string[])stringListCache[f].Clone();
|
||||
lock (getStringListLoadLock) // Make sure only one thread can read the cache
|
||||
{
|
||||
if (stringListCache.TryGetValue(f, out var result))
|
||||
return (string[])result.Clone();
|
||||
}
|
||||
|
||||
var txt = GetStringResource(f); // Fetch File, \n to list.
|
||||
if (txt == null)
|
||||
|
|
@ -100,18 +103,6 @@ public static string[] GetStringList(string f)
|
|||
|
||||
public static string[] GetStringList(string f, string l, string type = "text") => GetStringList($"{type}_{f}_{l}");
|
||||
|
||||
public static string[] GetNulledStringArray(string[] SimpleStringList)
|
||||
{
|
||||
int len = ToInt32(SimpleStringList.Last().Split(',')[0]) + 1;
|
||||
string[] newlist = new string[len];
|
||||
for (int i = 1; i < SimpleStringList.Length; i++)
|
||||
{
|
||||
var split = SimpleStringList[i].Split(',');
|
||||
newlist[ToInt32(split[0])] = split[1];
|
||||
}
|
||||
return newlist;
|
||||
}
|
||||
|
||||
public static byte[] GetBinaryResource(string name)
|
||||
{
|
||||
using (var resource = thisAssembly.GetManifestResourceStream(
|
||||
|
|
|
|||
|
|
@ -1760,7 +1760,7 @@ private void InitializeLanguage(SaveFile sav)
|
|||
{
|
||||
// Set the various ComboBox DataSources up with their allowed entries
|
||||
SetCountrySubRegion(CB_Country, "countries");
|
||||
CB_3DSReg.DataSource = Util.GetUnsortedCBList("regions3ds");
|
||||
CB_3DSReg.DataSource = GameInfo.Regions;
|
||||
|
||||
CB_EncounterType.DataSource = new BindingSource(GameInfo.EncounterTypeDataSource, null);
|
||||
CB_Nature.DataSource = new BindingSource(GameInfo.NatureDataSource, null);
|
||||
|
|
|
|||
|
|
@ -76,10 +76,8 @@ public SAV_Trainer(SaveFile sav)
|
|||
|
||||
private void GetComboBoxes()
|
||||
{
|
||||
var dsregion_list = Util.GetUnsortedCBList("regions3ds");
|
||||
|
||||
CB_3DSReg.InitializeBinding();
|
||||
CB_3DSReg.DataSource = dsregion_list;
|
||||
CB_3DSReg.DataSource = GameInfo.Regions;
|
||||
CB_Language.InitializeBinding();
|
||||
CB_Language.DataSource = GameInfo.LanguageDataSource(SAV.Generation);
|
||||
|
||||
|
|
|
|||
|
|
@ -54,20 +54,12 @@ public SAV_Trainer7(SaveFile sav)
|
|||
|
||||
private void GetComboBoxes()
|
||||
{
|
||||
var dsregion_list = Util.GetUnsortedCBList("regions3ds");
|
||||
|
||||
var alolatime_list = new[] { new { Text = "Sun Time", Value = 24*60*60 } };
|
||||
Array.Resize(ref alolatime_list, 24);
|
||||
for (int i = 1; i < 24; i++)
|
||||
alolatime_list[i] = new {Text = $"+{i:00} Hours", Value = i*60*60};
|
||||
alolatime_list[12] = new {Text = "Moon Time", Value = 12 * 60 * 60};
|
||||
|
||||
CB_3DSReg.InitializeBinding();
|
||||
CB_3DSReg.DataSource = dsregion_list;
|
||||
CB_3DSReg.DataSource = GameInfo.Regions;
|
||||
CB_Language.InitializeBinding();
|
||||
CB_Language.DataSource = GameInfo.LanguageDataSource(SAV.Generation);
|
||||
CB_AlolaTime.InitializeBinding();
|
||||
CB_AlolaTime.DataSource = alolatime_list;
|
||||
CB_AlolaTime.DataSource = GetAlolaTimeList();
|
||||
|
||||
CB_Country.InitializeBinding();
|
||||
CB_Region.InitializeBinding();
|
||||
|
|
@ -94,6 +86,16 @@ private void GetComboBoxes()
|
|||
LB_Stamps.Items.Add(t);
|
||||
}
|
||||
|
||||
private static ComboItem[] GetAlolaTimeList()
|
||||
{
|
||||
var alolatime_list = new ComboItem[24];
|
||||
for (int i = 1; i < alolatime_list.Length; i++)
|
||||
alolatime_list[i] = new ComboItem {Text = $"+{i:00} Hours", Value = i * 60 * 60};
|
||||
alolatime_list[0] = new ComboItem {Text = "Sun Time", Value = 24 * 60 * 60};
|
||||
alolatime_list[12] = new ComboItem {Text = "Moon Time", Value = 12 * 60 * 60};
|
||||
return alolatime_list;
|
||||
}
|
||||
|
||||
private void GetTextBoxes()
|
||||
{
|
||||
// Get Data
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user