UIDragDropMaidStatus.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6. using com.workman.cm3d2.scene.dailyEtc;
  7. using Schedule;
  8. using UnityEngine;
  9. public class UIDragDropMaidStatus : UIDragDropItem
  10. {
  11. protected override void Start()
  12. {
  13. this.m_parent = base.transform.parent.transform.parent.gameObject;
  14. this.mTrans = base.transform.parent;
  15. this.startLocalPosX = this.mTrans.transform.localPosition.x;
  16. GameObject f_goParent = GameObject.Find("/UI Root");
  17. SceneMgr component = UTY.GetChildObject(f_goParent, "Manager", false).GetComponent<SceneMgr>();
  18. this.m_scheduleMgr = component.GetManager<ScheduleMgr>();
  19. this.mCollider = base.gameObject.GetComponent<Collider>();
  20. this.mCollider2D = base.gameObject.GetComponent<Collider2D>();
  21. this.mButton = base.GetComponent<UIButton>();
  22. this.mDragScrollView = base.GetComponent<UIDragScrollView>();
  23. }
  24. protected override void OnDragDropStart()
  25. {
  26. if (UICamera.currentTouchID != -1)
  27. {
  28. return;
  29. }
  30. base.OnDragDropStart();
  31. }
  32. protected override void OnDragDropRelease(GameObject surface)
  33. {
  34. this.m_surface = surface;
  35. base.OnDragDropRelease(surface);
  36. }
  37. protected override void OnDragDropEnd()
  38. {
  39. this.ChangeSlotInfo(this.m_surface);
  40. if (this.mTable != null)
  41. {
  42. this.mTable.onReposition = new UITable.OnReposition(this.AdjustPosX);
  43. }
  44. else if (this.mGrid != null)
  45. {
  46. }
  47. }
  48. private void AdjustPosX()
  49. {
  50. if (this.mTrans != null)
  51. {
  52. this.mTrans.transform.localPosition = new Vector2(this.startLocalPosX, this.mTrans.transform.localPosition.y);
  53. }
  54. }
  55. private void ChangeSlotInfo(GameObject surface)
  56. {
  57. string name = base.transform.name;
  58. string name2 = surface.name;
  59. if (name2.Contains("slot"))
  60. {
  61. this.ChangeSlotData(name, name2);
  62. this.ChangeButtonNameForSlotNo(surface);
  63. this.ChangeCurrentActiveButton(name, name2);
  64. }
  65. this.Sort();
  66. }
  67. private void ChangeCurrentActiveButton(string srcName, string destName)
  68. {
  69. string currentActiveButton = this.m_scheduleMgr.CurrentActiveButton;
  70. string text = this.ToSlotNo(srcName);
  71. string text2 = this.ToSlotNo(destName);
  72. if (!string.IsNullOrEmpty(currentActiveButton))
  73. {
  74. if (currentActiveButton.Contains(text))
  75. {
  76. this.m_scheduleMgr.CurrentActiveButton = this.ReplaceSlotNo(currentActiveButton, text2);
  77. this.m_scheduleMgr.SetActiveSlotNo(text2);
  78. }
  79. else if (currentActiveButton.Contains(text2))
  80. {
  81. this.m_scheduleMgr.CurrentActiveButton = this.ReplaceSlotNo(currentActiveButton, text);
  82. this.m_scheduleMgr.SetActiveSlotNo(text);
  83. }
  84. }
  85. }
  86. private void ChangeButtonNameForSlotNo(GameObject surface)
  87. {
  88. string text = this.ToSlotNo(base.transform.name);
  89. string text2 = this.ToSlotNo(surface.name);
  90. IEnumerator enumerator = base.transform.parent.GetEnumerator();
  91. try
  92. {
  93. while (enumerator.MoveNext())
  94. {
  95. object obj = enumerator.Current;
  96. Transform transform = (Transform)obj;
  97. GameObject gameObject = transform.gameObject;
  98. gameObject.name = this.ReplaceSlotNo(gameObject.name, text2);
  99. }
  100. }
  101. finally
  102. {
  103. IDisposable disposable;
  104. if ((disposable = (enumerator as IDisposable)) != null)
  105. {
  106. disposable.Dispose();
  107. }
  108. }
  109. IEnumerator enumerator2 = surface.transform.parent.GetEnumerator();
  110. try
  111. {
  112. while (enumerator2.MoveNext())
  113. {
  114. object obj2 = enumerator2.Current;
  115. Transform transform2 = (Transform)obj2;
  116. GameObject gameObject2 = transform2.gameObject;
  117. gameObject2.name = this.ReplaceSlotNo(gameObject2.name, text);
  118. }
  119. }
  120. finally
  121. {
  122. IDisposable disposable2;
  123. if ((disposable2 = (enumerator2 as IDisposable)) != null)
  124. {
  125. disposable2.Dispose();
  126. }
  127. }
  128. GameObject gameObject3 = surface.transform.parent.gameObject;
  129. gameObject3.name = text;
  130. GameObject gameObject4 = base.transform.parent.gameObject;
  131. gameObject4.name = text2;
  132. }
  133. private string ReplaceSlotNo(string src, string destSlotNo)
  134. {
  135. string text = "slot_\\d+";
  136. return Regex.Replace(src, text, destSlotNo);
  137. }
  138. private void ChangeSlotData(string srcName, string destName)
  139. {
  140. Dictionary<string, ScheduleCtrl.MaidStatusAndTaskUnit> maidStatusAndTask = this.m_scheduleMgr.GetMaidStatusAndTask();
  141. string text = this.ToSlotNo(srcName);
  142. string text2 = this.ToSlotNo(destName);
  143. ScheduleCtrl.MaidStatusAndTaskUnit maidStatusAndTaskUnit = null;
  144. if (!maidStatusAndTask.TryGetValue(text, out maidStatusAndTaskUnit))
  145. {
  146. Debug.LogError(string.Format("不適切なスロットが選択されました。選択されたスロットNo={0}", text));
  147. }
  148. ScheduleCtrl.MaidStatusAndTaskUnit maidStatusAndTaskUnit2 = null;
  149. if (!maidStatusAndTask.TryGetValue(text2, out maidStatusAndTaskUnit2))
  150. {
  151. Debug.LogError(string.Format("不適切なスロットが選択されました。選択されたスロットNo={0}", maidStatusAndTaskUnit2));
  152. }
  153. ScheduleScene scheduleApi = this.m_scheduleMgr.GetScheduleApi();
  154. Maid maidBySlotNo = this.m_scheduleMgr.GetMaidBySlotNo(text);
  155. Maid maidBySlotNo2 = this.m_scheduleMgr.GetMaidBySlotNo(text2);
  156. maidStatusAndTaskUnit2.slotNo = int.Parse(text.Replace("slot_", string.Empty));
  157. maidStatusAndTask[text] = maidStatusAndTaskUnit2;
  158. maidStatusAndTaskUnit.slotNo = int.Parse(text2.Replace("slot_", string.Empty));
  159. maidStatusAndTask[text2] = maidStatusAndTaskUnit;
  160. scheduleApi.SetSlot_Safe(maidStatusAndTaskUnit.slotNo, maidBySlotNo, false, true);
  161. scheduleApi.SetSlot_Safe(maidStatusAndTaskUnit2.slotNo, maidBySlotNo2, false, true);
  162. }
  163. private void Sort()
  164. {
  165. List<GameObject> list = new List<GameObject>();
  166. IEnumerator enumerator = this.m_parent.transform.GetEnumerator();
  167. try
  168. {
  169. while (enumerator.MoveNext())
  170. {
  171. object obj = enumerator.Current;
  172. Transform transform = (Transform)obj;
  173. GameObject gameObject = transform.gameObject;
  174. list.Add(gameObject);
  175. }
  176. }
  177. finally
  178. {
  179. IDisposable disposable;
  180. if ((disposable = (enumerator as IDisposable)) != null)
  181. {
  182. disposable.Dispose();
  183. }
  184. }
  185. this.m_parent.transform.DetachChildren();
  186. IOrderedEnumerable<GameObject> orderedEnumerable = from go in list
  187. orderby ScheduleCtrl.ToIntSlotNo(go.name)
  188. select go;
  189. foreach (GameObject child in orderedEnumerable)
  190. {
  191. this.SetTransformInfo(this.m_parent, child);
  192. }
  193. }
  194. private string ToSlotNo(string buttonName)
  195. {
  196. ScheduleCtrl.Slot slotByButtonName = ScheduleCtrl.GetSlotByButtonName(buttonName);
  197. return slotByButtonName.slotNo;
  198. }
  199. private void DelChildGameObject(GameObject goParent)
  200. {
  201. IEnumerator enumerator = goParent.transform.GetEnumerator();
  202. try
  203. {
  204. while (enumerator.MoveNext())
  205. {
  206. object obj = enumerator.Current;
  207. Transform transform = (Transform)obj;
  208. UnityEngine.Object.Destroy(transform.gameObject);
  209. }
  210. }
  211. finally
  212. {
  213. IDisposable disposable;
  214. if ((disposable = (enumerator as IDisposable)) != null)
  215. {
  216. disposable.Dispose();
  217. }
  218. }
  219. goParent.transform.DetachChildren();
  220. }
  221. private void SetTransformInfo(GameObject parent, GameObject child)
  222. {
  223. child.transform.parent = parent.transform;
  224. }
  225. private ScheduleMgr m_scheduleMgr;
  226. private GameObject m_parent;
  227. private GameObject m_surface;
  228. private Vector2 startLocalPos = Vector2.zero;
  229. private string pattern;
  230. private bool cancel;
  231. private float startLocalPosX;
  232. private int frameCount;
  233. private const string DROPABLE_MARK = "slot";
  234. private const string uiRootPath = "/UI Root";
  235. private const int LeftClick = -1;
  236. }