PoemPhotoDataManager.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using ET;
  5. using FairyGUI;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class PoemPhotoDataManager : SingletonBase<PoemPhotoDataManager>
  10. {
  11. /// <summary>
  12. /// 个人相册
  13. /// </summary>
  14. /// <typeparam name="PoemPhotoData"></typeparam>
  15. /// <returns></returns>
  16. public List<PoemPhotoData> PersonalPhotoInfos = new List<PoemPhotoData>();
  17. /// <summary>
  18. /// 万水千山相册
  19. /// </summary>
  20. /// <typeparam name="PoemPhotoData"></typeparam>
  21. /// <returns></returns>
  22. public List<PoemPhotoData> WsqsPhotoInfos = new List<PoemPhotoData>();
  23. public void Clear()
  24. {
  25. PersonalPhotoInfos.Clear();
  26. WsqsPhotoInfos.Clear();
  27. }
  28. public void Add(PoemPhotoData photoData, int sourceType)
  29. {
  30. List<PoemPhotoData> poemPhotoDatas = null;
  31. if (sourceType == (int)PictureSourceType.PersonalAlbum)
  32. {
  33. poemPhotoDatas = PersonalPhotoInfos;
  34. }
  35. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  36. {
  37. poemPhotoDatas = WsqsPhotoInfos;
  38. }
  39. poemPhotoDatas.Add(photoData);
  40. SortInfos(poemPhotoDatas);
  41. }
  42. public void Remove(List<long> pictureIds, int sourceType)
  43. {
  44. List<PoemPhotoData> poemPhotoDatas = null;
  45. if (sourceType == (int)PictureSourceType.PersonalAlbum)
  46. {
  47. poemPhotoDatas = PersonalPhotoInfos;
  48. }
  49. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  50. {
  51. poemPhotoDatas = WsqsPhotoInfos;
  52. }
  53. for (int i = 0; i < pictureIds.Count; i++)
  54. {
  55. for (int j = 0; j < poemPhotoDatas.Count; j++)
  56. {
  57. if (pictureIds[i] == poemPhotoDatas[j].PictureId)
  58. {
  59. poemPhotoDatas.RemoveAt(j);
  60. break;
  61. }
  62. }
  63. }
  64. SortInfos(poemPhotoDatas);
  65. }
  66. public void ChangeLockingState(long pictureId, bool state, int sourceType)
  67. {
  68. List<PoemPhotoData> poemPhotoDatas = null;
  69. if (sourceType == (int)PictureSourceType.PersonalAlbum)
  70. {
  71. poemPhotoDatas = PersonalPhotoInfos;
  72. }
  73. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  74. {
  75. poemPhotoDatas = WsqsPhotoInfos;
  76. }
  77. for (int i = 0; i < poemPhotoDatas.Count; i++)
  78. {
  79. if (poemPhotoDatas[i].PictureId == pictureId)
  80. {
  81. poemPhotoDatas[i].LockingStatus = state;
  82. break;
  83. }
  84. }
  85. SortInfos(poemPhotoDatas);
  86. }
  87. public void ChangeToppingState(long pictureId, bool state, int sourceType)
  88. {
  89. List<PoemPhotoData> poemPhotoDatas = null;
  90. if (sourceType == (int)PictureSourceType.PersonalAlbum)
  91. {
  92. poemPhotoDatas = PersonalPhotoInfos;
  93. }
  94. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  95. {
  96. poemPhotoDatas = WsqsPhotoInfos;
  97. }
  98. for (int i = 0; i < poemPhotoDatas.Count; i++)
  99. {
  100. if (poemPhotoDatas[i].PictureId == pictureId)
  101. {
  102. poemPhotoDatas[i].ToppingStatus = state;
  103. break;
  104. }
  105. }
  106. SortInfos(poemPhotoDatas);
  107. }
  108. private List<PoemPhotoData> SortInfos(List<PoemPhotoData> photoInfos)
  109. {
  110. photoInfos.Sort((PoemPhotoData a, PoemPhotoData b) =>
  111. {
  112. if (a.ToppingStatus && !b.ToppingStatus) return -1;
  113. if (b.ToppingStatus && !a.ToppingStatus) return 1;
  114. if (a.CreationTime < b.CreationTime) return 1;
  115. if (a.CreationTime > b.CreationTime) return -1;
  116. return 0;
  117. });
  118. return photoInfos;
  119. }
  120. public PoemPhotoData GetPersonalPhotoDataById(long pictureId)
  121. {
  122. for (int i = 0; i < PersonalPhotoInfos.Count; i++)
  123. {
  124. if (pictureId == PersonalPhotoInfos[i].PictureId)
  125. {
  126. return PersonalPhotoInfos[i];
  127. }
  128. }
  129. return null;
  130. }
  131. public NTexture BytesToTexture2D(byte[] bytes)
  132. {
  133. Texture2D texture2D = new Texture2D(UnityEngine.Screen.width, UnityEngine.Screen.height);
  134. texture2D.LoadImage(bytes);
  135. return new NTexture(texture2D);
  136. }
  137. }
  138. }