PoemPhotoDataManager.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // PersonalPhotoInfos.Add(photoData);
  34. // PersonalPhotoInfos = SortInfos(PersonalPhotoInfos);
  35. poemPhotoDatas = PersonalPhotoInfos;
  36. }
  37. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  38. {
  39. // WsqsPhotoInfos.Add(photoData);
  40. // WsqsPhotoInfos = SortInfos(WsqsPhotoInfos);
  41. poemPhotoDatas = WsqsPhotoInfos;
  42. }
  43. poemPhotoDatas.Add(photoData);
  44. poemPhotoDatas = SortInfos(poemPhotoDatas);
  45. }
  46. public void Remove(List<long> pictureIds, int sourceType)
  47. {
  48. List<PoemPhotoData> poemPhotoDatas = null;
  49. if (sourceType == (int)PictureSourceType.PersonalAlbum)
  50. {
  51. poemPhotoDatas = PersonalPhotoInfos;
  52. }
  53. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  54. {
  55. poemPhotoDatas = WsqsPhotoInfos;
  56. }
  57. for (int i = 0; i < pictureIds.Count; i++)
  58. {
  59. for (int j = 0; j < poemPhotoDatas.Count; j++)
  60. {
  61. if (pictureIds[i] == poemPhotoDatas[j].PictureId)
  62. {
  63. poemPhotoDatas.RemoveAt(j);
  64. break;
  65. }
  66. }
  67. }
  68. poemPhotoDatas = SortInfos(poemPhotoDatas);
  69. }
  70. public void ChangeLockingState(long pictureId, bool state, int sourceType)
  71. {
  72. List<PoemPhotoData> poemPhotoDatas = null;
  73. if (sourceType == (int)PictureSourceType.PersonalAlbum)
  74. {
  75. poemPhotoDatas = PersonalPhotoInfos;
  76. }
  77. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  78. {
  79. poemPhotoDatas = WsqsPhotoInfos;
  80. }
  81. for (int i = 0; i < poemPhotoDatas.Count; i++)
  82. {
  83. if (poemPhotoDatas[i].PictureId == pictureId)
  84. {
  85. poemPhotoDatas[i].LockingStatus = state;
  86. break;
  87. }
  88. }
  89. poemPhotoDatas = SortInfos(poemPhotoDatas);
  90. }
  91. public void ChangeToppingState(long pictureId, bool state, int sourceType)
  92. {
  93. List<PoemPhotoData> poemPhotoDatas = null;
  94. if (sourceType == (int)PictureSourceType.PersonalAlbum)
  95. {
  96. poemPhotoDatas = PersonalPhotoInfos;
  97. }
  98. else if (sourceType == (int)PictureSourceType.WanShuiQianShan)
  99. {
  100. poemPhotoDatas = WsqsPhotoInfos;
  101. }
  102. for (int i = 0; i < poemPhotoDatas.Count; i++)
  103. {
  104. if (poemPhotoDatas[i].PictureId == pictureId)
  105. {
  106. poemPhotoDatas[i].ToppingStatus = state;
  107. break;
  108. }
  109. }
  110. poemPhotoDatas = SortInfos(poemPhotoDatas);
  111. }
  112. private List<PoemPhotoData> SortInfos(List<PoemPhotoData> photoInfos)
  113. {
  114. photoInfos.Sort((PoemPhotoData a, PoemPhotoData b) =>
  115. {
  116. if (a.ToppingStatus) return 1;
  117. if (b.ToppingStatus) return -1;
  118. if (a.CreationTime < b.CreationTime) return 1;
  119. if (a.CreationTime > b.CreationTime) return -1;
  120. return 0;
  121. });
  122. return photoInfos;
  123. }
  124. public NTexture BytesToTexture2D(byte[] bytes)
  125. {
  126. Texture2D texture2D = new Texture2D(UnityEngine.Screen.width, UnityEngine.Screen.height);
  127. texture2D.LoadImage(bytes);
  128. return new NTexture(texture2D);
  129. }
  130. }
  131. }