Constants.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Newtonsoft.Json;
  6. using MyRoomCustom;
  7. using UnityEngine;
  8. using wf;
  9. namespace COM3D2.MeidoPhotoStudio.Plugin
  10. {
  11. using static MenuFileUtility;
  12. internal class Constants
  13. {
  14. private static bool beginHandItemInit;
  15. public static readonly string customPosePath;
  16. public static readonly string scenesPath;
  17. public static readonly string kankyoPath;
  18. public static readonly string configPath;
  19. public static readonly int mainWindowID = 765;
  20. public static readonly int messageWindowID = 961;
  21. public static readonly int sceneManagerWindowID = 876;
  22. public static readonly int sceneManagerModalID = 283;
  23. public static readonly int dropdownWindowID = 777;
  24. public enum Window
  25. {
  26. Call, Pose, Face, BG, BG2, Main, Message, Save, SaveModal
  27. }
  28. public enum Scene
  29. {
  30. Daily = 3, Edit = 5
  31. }
  32. public static readonly List<string> PoseGroupList = new List<string>();
  33. public static readonly Dictionary<string, List<string>> PoseDict = new Dictionary<string, List<string>>();
  34. public static readonly List<string> CustomPoseGroupList = new List<string>();
  35. public static readonly Dictionary<string, List<string>> CustomPoseDict = new Dictionary<string, List<string>>();
  36. public static readonly List<string> FaceBlendList = new List<string>();
  37. public static readonly List<string> BGList = new List<string>();
  38. public static readonly List<KeyValuePair<string, string>> MyRoomCustomBGList
  39. = new List<KeyValuePair<string, string>>();
  40. public static readonly List<string> DoguCategories = new List<string>();
  41. public static readonly Dictionary<string, List<string>> DoguDict = new Dictionary<string, List<string>>();
  42. public static readonly List<string> MyRoomPropCategories = new List<string>();
  43. public static readonly Dictionary<string, List<MyRoomItem>> MyRoomPropDict
  44. = new Dictionary<string, List<MyRoomItem>>();
  45. public static readonly Dictionary<string, List<ModItem>> ModPropDict
  46. = new Dictionary<string, List<ModItem>>(StringComparer.InvariantCultureIgnoreCase);
  47. public static int CustomPoseGroupsIndex { get; private set; } = -1;
  48. public static int MyRoomCustomBGIndex { get; private set; } = -1;
  49. public static bool HandItemsInitialized { get; private set; } = false;
  50. public static bool MenuFilesInitialized { get; private set; } = false;
  51. public static event EventHandler<MenuFilesEventArgs> MenuFilesChange;
  52. public enum DoguCategory
  53. {
  54. Other, Mob, Desk, HandItem, BGSmall
  55. }
  56. public static readonly Dictionary<DoguCategory, string> customDoguCategories =
  57. new Dictionary<DoguCategory, string>()
  58. {
  59. [DoguCategory.Other] = "other",
  60. [DoguCategory.Mob] = "mob",
  61. [DoguCategory.Desk] = "desk",
  62. [DoguCategory.HandItem] = "handItem",
  63. [DoguCategory.BGSmall] = "bgSmall"
  64. };
  65. static Constants()
  66. {
  67. string modsPath = Path.Combine(BepInEx.Paths.GameRootPath, @"Mod\MeidoPhotoStudio");
  68. customPosePath = Path.Combine(modsPath, "Custom Poses");
  69. scenesPath = Path.Combine(modsPath, "Scenes");
  70. kankyoPath = Path.Combine(modsPath, "Environments");
  71. configPath = Path.Combine(BepInEx.Paths.ConfigPath, "MeidoPhotoStudio");
  72. foreach (string directory in new[] { customPosePath, scenesPath, kankyoPath, configPath })
  73. {
  74. if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
  75. }
  76. }
  77. public static void Initialize()
  78. {
  79. InitializePoses();
  80. InitializeFaceBlends();
  81. InitializeBGs();
  82. InitializeDogu();
  83. InitializeMyRoomProps();
  84. }
  85. public static void InitializePoses()
  86. {
  87. // Load Poses
  88. string poseListJson = File.ReadAllText(Path.Combine(configPath, "mm_pose_list.json"));
  89. List<SerializePoseList> poseLists = JsonConvert.DeserializeObject<List<SerializePoseList>>(poseListJson);
  90. foreach (SerializePoseList poseList in poseLists)
  91. {
  92. PoseDict[poseList.UIName] = poseList.PoseList;
  93. PoseGroupList.Add(poseList.UIName);
  94. }
  95. // Get Other poses that'll go into Normal 2 and Ero 2
  96. string[] com3d2MotionList = GameUty.FileSystem.GetList("motion", AFileSystemBase.ListType.AllFile);
  97. if (com3d2MotionList != null && com3d2MotionList.Length > 0)
  98. {
  99. HashSet<string> poseSet = new HashSet<string>();
  100. foreach (List<string> poses in PoseDict.Values)
  101. {
  102. poseSet.UnionWith(poses);
  103. }
  104. List<string> editPoseList = new List<string>();
  105. List<string> otherPoseList = new List<string>();
  106. List<string> eroPoseList = new List<string>();
  107. foreach (string path in com3d2MotionList)
  108. {
  109. if (Path.GetExtension(path) == ".anm")
  110. {
  111. string file = Path.GetFileNameWithoutExtension(path);
  112. if (!poseSet.Contains(file))
  113. {
  114. if (file.StartsWith("edit_"))
  115. {
  116. editPoseList.Add(file);
  117. }
  118. else if (file != "dance_cm3d2_001_zoukin" && file != "dance_cm3d2_001_mop"
  119. && file != "aruki_1_idougo_f" && file != "sleep2" && file != "stand_akire2"
  120. && !file.EndsWith("_3_") && !file.EndsWith("_5_") && !file.StartsWith("vr_")
  121. && !file.StartsWith("dance_mc") && !file.Contains("_kubi_") && !file.Contains("a01_")
  122. && !file.Contains("b01_") && !file.Contains("b02_") && !file.EndsWith("_m2")
  123. && !file.EndsWith("_m2_once_") && !file.StartsWith("h_") && !file.StartsWith("event_")
  124. && !file.StartsWith("man_") && !file.EndsWith("_m") && !file.Contains("_m_")
  125. && !file.Contains("_man_")
  126. )
  127. {
  128. if (path.Contains(@"\sex\")) eroPoseList.Add(file);
  129. else otherPoseList.Add(file);
  130. }
  131. }
  132. }
  133. }
  134. PoseDict["normal"].AddRange(editPoseList);
  135. PoseDict["normal2"] = otherPoseList;
  136. PoseDict["ero2"] = eroPoseList;
  137. PoseGroupList.AddRange(new[] { "normal2", "ero2" });
  138. }
  139. Action<string> GetPoses = directory =>
  140. {
  141. List<string> poseList = Directory.GetFiles(directory)
  142. .Where(file => Path.GetExtension(file) == ".anm").ToList();
  143. if (poseList.Count > 0)
  144. {
  145. string poseGroupName = new DirectoryInfo(directory).Name;
  146. CustomPoseGroupList.Add(poseGroupName);
  147. CustomPoseDict[poseGroupName] = poseList;
  148. }
  149. };
  150. GetPoses(customPosePath);
  151. foreach (string directory in Directory.GetDirectories(customPosePath))
  152. {
  153. GetPoses(directory);
  154. }
  155. }
  156. public static void InitializeFaceBlends()
  157. {
  158. using (CsvParser csvParser = OpenCsvParser("phot_face_list.nei"))
  159. {
  160. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  161. {
  162. if (csvParser.IsCellToExistData(3, cell_y))
  163. {
  164. string blendValue = csvParser.GetCellAsString(3, cell_y);
  165. FaceBlendList.Add(blendValue);
  166. }
  167. }
  168. }
  169. }
  170. public static void InitializeBGs()
  171. {
  172. // Load BGs
  173. PhotoBGData.Create();
  174. List<PhotoBGData> photList = PhotoBGData.data;
  175. // COM3D2 BGs
  176. foreach (PhotoBGData bgData in photList)
  177. {
  178. if (!string.IsNullOrEmpty(bgData.create_prefab_name))
  179. {
  180. string bg = bgData.create_prefab_name;
  181. BGList.Add(bg);
  182. }
  183. }
  184. // CM3D2 BGs
  185. if (GameUty.IsEnabledCompatibilityMode)
  186. {
  187. using (CsvParser csvParser = OpenCsvParser("phot_bg_list.nei", GameUty.FileSystemOld))
  188. {
  189. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  190. {
  191. if (csvParser.IsCellToExistData(3, cell_y))
  192. {
  193. string bg = csvParser.GetCellAsString(3, cell_y);
  194. BGList.Add(bg);
  195. }
  196. }
  197. }
  198. }
  199. Dictionary<string, string> saveDataDict = MyRoomCustom.CreativeRoomManager.GetSaveDataDic();
  200. if (saveDataDict != null)
  201. {
  202. MyRoomCustomBGIndex = BGList.Count;
  203. MyRoomCustomBGList.AddRange(saveDataDict);
  204. }
  205. }
  206. public static void InitializeDogu()
  207. {
  208. foreach (string customCategory in customDoguCategories.Values)
  209. {
  210. DoguDict[customCategory] = new List<string>();
  211. }
  212. InitializeDeskItems();
  213. InitializePhotoBGItems();
  214. InitializeOtherDogu();
  215. InitializeHandItems();
  216. foreach (string category in PhotoBGObjectData.popup_category_list.Select(kvp => kvp.Key))
  217. {
  218. if (category == "マイオブジェクト") continue;
  219. DoguCategories.Add(category);
  220. }
  221. foreach (DoguCategory category in Enum.GetValues(typeof(DoguCategory)))
  222. {
  223. DoguCategories.Add(customDoguCategories[category]);
  224. }
  225. }
  226. private static void InitializeOtherDogu()
  227. {
  228. DoguDict[customDoguCategories[DoguCategory.BGSmall]] = BGList;
  229. DoguDict[customDoguCategories[DoguCategory.Mob]].AddRange(new[] {
  230. "Mob_Man_Stand001", "Mob_Man_Stand002", "Mob_Man_Stand003", "Mob_Man_Sit001", "Mob_Man_Sit002",
  231. "Mob_Man_Sit003", "Mob_Girl_Stand001", "Mob_Girl_Stand002", "Mob_Girl_Stand003", "Mob_Girl_Sit001",
  232. "Mob_Girl_Sit002", "Mob_Girl_Sit003", "Salon:65", "Salon:63", "Salon:69"
  233. });
  234. List<string> DoguList = DoguDict[customDoguCategories[DoguCategory.Other]];
  235. string ignoreListPath = Path.Combine(configPath, "mm_ignore_list.json");
  236. string ignoreListJson = File.ReadAllText(ignoreListPath);
  237. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  238. // bg object extend
  239. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  240. doguHashSet.UnionWith(BGList);
  241. doguHashSet.UnionWith(ignoreList);
  242. foreach (List<string> doguList in DoguDict.Values)
  243. {
  244. doguHashSet.UnionWith(doguList);
  245. }
  246. string[] com3d2BgList = GameUty.FileSystem.GetList("bg", AFileSystemBase.ListType.AllFile);
  247. foreach (string path in com3d2BgList)
  248. {
  249. if (Path.GetExtension(path) == ".asset_bg" && !path.Contains("myroomcustomize"))
  250. {
  251. string file = Path.GetFileNameWithoutExtension(path);
  252. if (!doguHashSet.Contains(file) && !file.EndsWith("_hit"))
  253. {
  254. DoguList.Add(file);
  255. doguHashSet.Add(file);
  256. }
  257. }
  258. }
  259. // Get cherry picked dogu that I can't find in the game files
  260. string doguExtendPath = Path.Combine(configPath, "mm_dogu_extend.json");
  261. string doguExtendJson = File.ReadAllText(doguExtendPath);
  262. DoguList.AddRange(JsonConvert.DeserializeObject<IEnumerable<string>>(doguExtendJson));
  263. string[] cm3d2BgList = GameUty.FileSystemOld.GetList("bg", AFileSystemBase.ListType.AllFile);
  264. foreach (string path in cm3d2BgList)
  265. {
  266. if (Path.GetExtension(path) == ".asset_bg")
  267. {
  268. string file = Path.GetFileNameWithoutExtension(path);
  269. if (!doguHashSet.Contains(file) && !file.EndsWith("_not_optimisation"))
  270. {
  271. DoguList.Add(file);
  272. }
  273. }
  274. }
  275. }
  276. private static void InitializeDeskItems()
  277. {
  278. HashSet<int> enabledIDs = new HashSet<int>();
  279. CsvCommonIdManager.ReadEnabledIdList(
  280. CsvCommonIdManager.FileSystemType.Normal, true, "desk_item_enabled_id", ref enabledIDs
  281. );
  282. CsvCommonIdManager.ReadEnabledIdList(
  283. CsvCommonIdManager.FileSystemType.Old, true, "desk_item_enabled_id", ref enabledIDs
  284. );
  285. List<string> com3d2DeskDogu = DoguDict[customDoguCategories[DoguCategory.Desk]];
  286. Action<AFileSystemBase> GetDeskItems = fs =>
  287. {
  288. using (CsvParser csvParser = OpenCsvParser("desk_item_detail.nei", fs))
  289. {
  290. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  291. {
  292. if (csvParser.IsCellToExistData(0, cell_y))
  293. {
  294. int cell = csvParser.GetCellAsInteger(0, cell_y);
  295. if (enabledIDs.Contains(cell))
  296. {
  297. string dogu = String.Empty;
  298. if (csvParser.IsCellToExistData(3, cell_y))
  299. {
  300. dogu = csvParser.GetCellAsString(3, cell_y);
  301. }
  302. else if (csvParser.IsCellToExistData(4, cell_y))
  303. {
  304. dogu = csvParser.GetCellAsString(4, cell_y);
  305. }
  306. if (!string.IsNullOrEmpty(dogu))
  307. {
  308. com3d2DeskDogu.Add(dogu);
  309. }
  310. }
  311. }
  312. }
  313. }
  314. };
  315. GetDeskItems(GameUty.FileSystem);
  316. }
  317. private static void InitializePhotoBGItems()
  318. {
  319. PhotoBGObjectData.Create();
  320. List<PhotoBGObjectData> photoBGObjectList = PhotoBGObjectData.data;
  321. List<string> doguCategories = new List<string>();
  322. HashSet<string> addedCategories = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  323. foreach (PhotoBGObjectData photoBGObject in photoBGObjectList)
  324. {
  325. string category = photoBGObject.category;
  326. if (!addedCategories.Contains(category))
  327. {
  328. addedCategories.Add(category);
  329. doguCategories.Add(category);
  330. }
  331. if (!DoguDict.ContainsKey(category))
  332. {
  333. DoguDict[category] = new List<string>();
  334. }
  335. string dogu = String.Empty;
  336. if (!string.IsNullOrEmpty(photoBGObject.create_prefab_name))
  337. {
  338. dogu = photoBGObject.create_prefab_name;
  339. }
  340. else if (!string.IsNullOrEmpty(photoBGObject.create_asset_bundle_name))
  341. {
  342. dogu = photoBGObject.create_asset_bundle_name;
  343. }
  344. else if (!string.IsNullOrEmpty(photoBGObject.direct_file))
  345. {
  346. dogu = photoBGObject.direct_file;
  347. }
  348. if (!string.IsNullOrEmpty(dogu))
  349. {
  350. DoguDict[category].Add(dogu);
  351. }
  352. }
  353. DoguDict["パーティクル"].AddRange(new[] {
  354. "Particle/pLineY", "Particle/pLineP02", "Particle/pHeart01",
  355. "Particle/pLine_act2", "Particle/pstarY_act2"
  356. });
  357. }
  358. private static void InitializeHandItems()
  359. {
  360. if (HandItemsInitialized) return;
  361. if (!MenuFileUtility.MenuFilesReady)
  362. {
  363. if (!beginHandItemInit) MenuFileUtility.MenuFilesReadyChange += (s, a) => InitializeHandItems();
  364. beginHandItemInit = true;
  365. return;
  366. }
  367. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  368. string ignoreListJson = File.ReadAllText(Path.Combine(configPath, "mm_ignore_list.json"));
  369. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  370. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  371. doguHashSet.UnionWith(BGList);
  372. doguHashSet.UnionWith(ignoreList);
  373. foreach (List<string> doguList in DoguDict.Values)
  374. {
  375. doguHashSet.UnionWith(doguList);
  376. }
  377. string category = customDoguCategories[DoguCategory.HandItem];
  378. for (int i = 0; i < menuDataBase.GetDataSize(); i++)
  379. {
  380. menuDataBase.SetIndex(i);
  381. if ((MPN)menuDataBase.GetCategoryMpn() == MPN.handitem)
  382. {
  383. string menuFileName = menuDataBase.GetMenuFileName();
  384. if (menuDataBase.GetBoDelOnly() || menuFileName.EndsWith("_del.menu")) continue;
  385. string handItemAsOdogu = Utility.HandItemToOdogu(menuFileName);
  386. string isolatedHandItem = menuFileName.Substring(menuFileName.IndexOf('_') + 1);
  387. if (!doguHashSet.Contains(handItemAsOdogu) && !doguHashSet.Contains(isolatedHandItem))
  388. {
  389. doguHashSet.Add(isolatedHandItem);
  390. DoguDict[category].Add(menuFileName);
  391. // Check for a half deck of cards to add the full deck as well
  392. if (menuFileName == "handitemd_cards_i_.menu")
  393. {
  394. DoguDict[category].Add("handiteml_cards_i_.menu");
  395. }
  396. }
  397. }
  398. }
  399. OnMenuFilesChange(MenuFilesEventArgs.HandItems);
  400. HandItemsInitialized = true;
  401. }
  402. private static void InitializeMyRoomProps()
  403. {
  404. PlacementData.CreateData();
  405. List<PlacementData.Data> myRoomData = PlacementData.GetAllDatas(false);
  406. myRoomData.Sort((a, b) =>
  407. {
  408. int res = a.categoryID.CompareTo(b.categoryID);
  409. if (res == 0) res = a.ID.CompareTo(b.ID);
  410. return res;
  411. });
  412. foreach (PlacementData.Data data in myRoomData)
  413. {
  414. string category = PlacementData.GetCategoryName(data.categoryID);
  415. if (!MyRoomPropDict.ContainsKey(category))
  416. {
  417. MyRoomPropCategories.Add(category);
  418. MyRoomPropDict[category] = new List<MyRoomItem>();
  419. }
  420. string asset = !string.IsNullOrEmpty(data.resourceName) ? data.resourceName : data.assetName;
  421. MyRoomItem item = new MyRoomItem() { PrefabName = asset, ID = data.ID };
  422. MyRoomPropDict[category].Add(item);
  423. }
  424. }
  425. private static void InitializeModProps()
  426. {
  427. // TODO: cache menu files
  428. for (int i = 1; i < MenuFileUtility.MenuCategories.Length; i++)
  429. {
  430. ModPropDict[MenuCategories[i]] = new List<ModItem>();
  431. }
  432. if (!Configuration.ModItemsOnly)
  433. {
  434. MenuDataBase menuDatabase = GameMain.Instance.MenuDataBase;
  435. for (int i = 0; i < menuDatabase.GetDataSize(); i++)
  436. {
  437. menuDatabase.SetIndex(i);
  438. ModItem modItem = new ModItem();
  439. if (MenuFileUtility.ParseNativeMenuFile(i, modItem))
  440. {
  441. ModPropDict[modItem.Category].Add(modItem);
  442. }
  443. }
  444. }
  445. MenuFileCache cache = new MenuFileCache();
  446. foreach (string modMenuFile in GameUty.ModOnlysMenuFiles)
  447. {
  448. ModItem modItem;
  449. if (cache.Has(modMenuFile))
  450. {
  451. modItem = cache[modMenuFile];
  452. }
  453. else
  454. {
  455. modItem = new ModItem() { MenuFile = modMenuFile, IsMod = true };
  456. MenuFileUtility.ParseMenuFile(modMenuFile, modItem);
  457. cache[modMenuFile] = modItem;
  458. }
  459. if (MenuFileUtility.ValidBG2MenuFile(modItem)) ModPropDict[modItem.Category].Add(modItem);
  460. }
  461. cache.Serialize();
  462. foreach (string modFile in Menu.GetModFiles())
  463. {
  464. ModItem modItem = new ModItem()
  465. {
  466. MenuFile = modFile,
  467. IsMod = true,
  468. IsOfficialMod = true,
  469. Priority = 1000f
  470. };
  471. if (ParseModMenuFile(modFile, modItem))
  472. {
  473. ModPropDict[modItem.Category].Add(modItem);
  474. }
  475. }
  476. MenuFilesInitialized = true;
  477. }
  478. public static List<ModItem> GetModPropList(string category)
  479. {
  480. if (!Configuration.ModItemsOnly)
  481. {
  482. if (!MenuFileUtility.MenuFilesReady)
  483. {
  484. Utility.Logger.LogInfo("Menu files are not ready yet");
  485. return null;
  486. }
  487. }
  488. if (!MenuFilesInitialized) InitializeModProps();
  489. if (!ModPropDict.ContainsKey(category)) return null;
  490. List<ModItem> selectedList = ModPropDict[category];
  491. if (selectedList[0].Icon == null)
  492. {
  493. selectedList.Sort((a, b) =>
  494. {
  495. int res = a.Priority.CompareTo(b.Priority);
  496. if (res == 0) res = string.Compare(a.Name, b.Name);
  497. return res;
  498. });
  499. string previousMenuFile = String.Empty;
  500. selectedList.RemoveAll(item =>
  501. {
  502. if (item.Icon == null)
  503. {
  504. Texture2D icon;
  505. string iconFile = item.IconFile;
  506. if (string.IsNullOrEmpty(iconFile) || !GameUty.FileSystem.IsExistentFile(iconFile))
  507. {
  508. Utility.Logger.LogWarning($"Could not find icon '{iconFile}' for menu '{item.MenuFile}");
  509. return true;
  510. }
  511. else
  512. {
  513. try
  514. {
  515. icon = ImportCM.CreateTexture(iconFile);
  516. }
  517. catch
  518. {
  519. try
  520. {
  521. icon = ImportCM.CreateTexture($"tex\\{iconFile}");
  522. }
  523. catch
  524. {
  525. Utility.Logger.LogWarning($"Could not load '{iconFile}' for menu '{item.MenuFile}");
  526. return true;
  527. }
  528. }
  529. }
  530. item.Icon = icon;
  531. }
  532. return false;
  533. });
  534. }
  535. return selectedList;
  536. }
  537. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  538. {
  539. try
  540. {
  541. if (fs.IsExistentFile(nei))
  542. {
  543. AFileBase file = fs.FileOpen(nei);
  544. CsvParser csvParser = new CsvParser();
  545. if (csvParser.Open(file)) return csvParser;
  546. else file?.Dispose();
  547. }
  548. }
  549. catch { }
  550. return null;
  551. }
  552. private static CsvParser OpenCsvParser(string nei)
  553. {
  554. return OpenCsvParser(nei, GameUty.FileSystem);
  555. }
  556. public static void WriteToFile(string name, IEnumerable<string> list)
  557. {
  558. if (Path.GetExtension(name) != ".txt") name += ".txt";
  559. File.WriteAllLines(Path.Combine(configPath, name), list.ToArray());
  560. }
  561. private static void OnMenuFilesChange(MenuFilesEventArgs args)
  562. {
  563. MenuFilesChange?.Invoke(null, args);
  564. }
  565. private class SerializePoseList
  566. {
  567. public string UIName { get; set; }
  568. public List<string> PoseList { get; set; }
  569. }
  570. }
  571. public class MenuFilesEventArgs : EventArgs
  572. {
  573. public EventType Type { get; }
  574. public enum EventType
  575. {
  576. HandItems, MenuFiles
  577. }
  578. public static MenuFilesEventArgs HandItems => new MenuFilesEventArgs(EventType.HandItems);
  579. public static MenuFilesEventArgs MenuFiles => new MenuFilesEventArgs(EventType.MenuFiles);
  580. public MenuFilesEventArgs(EventType type) => this.Type = type;
  581. }
  582. }