MenuItem.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Globalization;
  2. using System.IO;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. public abstract class MenuItem
  7. {
  8. public string IconFile { get; set; }
  9. public Texture2D Icon { get; set; }
  10. }
  11. public class ModItem : MenuItem
  12. {
  13. public string MenuFile { get; set; }
  14. public string BaseMenuFile { get; set; }
  15. public string Name { get; set; }
  16. public string Category { get; set; }
  17. public float Priority { get; set; }
  18. public bool IsMod { get; private set; }
  19. public bool IsOfficialMod { get; private set; }
  20. public static ModItem OfficialMod(string menuFile) => new ModItem()
  21. {
  22. MenuFile = menuFile, IsMod = true, IsOfficialMod = true, Priority = 1000f
  23. };
  24. public static ModItem Mod(string menuFile) => new ModItem() { MenuFile = menuFile, IsMod = true };
  25. public ModItem() { }
  26. public ModItem(string menuFile) => MenuFile = menuFile;
  27. public override string ToString() => IsOfficialMod ? $"{Path.GetFileName(MenuFile)}#{BaseMenuFile}" : MenuFile;
  28. public static ModItem Deserialize(BinaryReader binaryReader) => new ModItem()
  29. {
  30. MenuFile = binaryReader.ReadNullableString(),
  31. BaseMenuFile = binaryReader.ReadNullableString(),
  32. IconFile = binaryReader.ReadNullableString(),
  33. Name = binaryReader.ReadNullableString(),
  34. Category = binaryReader.ReadNullableString(),
  35. Priority = float.Parse(binaryReader.ReadNullableString()),
  36. IsMod = binaryReader.ReadBoolean(),
  37. IsOfficialMod = binaryReader.ReadBoolean()
  38. };
  39. public void Serialize(BinaryWriter binaryWriter)
  40. {
  41. if (IsOfficialMod) return;
  42. binaryWriter.WriteNullableString(MenuFile);
  43. binaryWriter.WriteNullableString(BaseMenuFile);
  44. binaryWriter.WriteNullableString(IconFile);
  45. binaryWriter.WriteNullableString(Name);
  46. binaryWriter.WriteNullableString(Category);
  47. binaryWriter.WriteNullableString(Priority.ToString(CultureInfo.InvariantCulture));
  48. binaryWriter.Write(IsMod);
  49. binaryWriter.Write(IsOfficialMod);
  50. }
  51. }
  52. public class MyRoomItem : MenuItem
  53. {
  54. public int ID { get; set; }
  55. public string PrefabName { get; set; }
  56. public override string ToString() => $"MYR_{ID}#{PrefabName}";
  57. }
  58. }