Constants.cs 26 KB

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