SaveAndLoadMgr.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SaveAndLoadMgr : BaseCreatePanel
  5. {
  6. public SaveAndLoadMgr.PageNo GetCurrentPageNo()
  7. {
  8. return this.currentPageNo;
  9. }
  10. public Action CallbackAfterFadeOut { get; set; }
  11. public void SetCurrentActiveData(string activeData)
  12. {
  13. this.currentActiveData = activeData;
  14. }
  15. public Action OnOpenLoadPanelKasizukiLocal { get; set; }
  16. public override void Init()
  17. {
  18. this.m_goPanel = base.GetPanel("SaveAndLoadPanel");
  19. this.m_ctrl = base.GetCtrl<SaveAndLoadCtrl>();
  20. this.m_ctrl.Init(this, this.m_goPanel);
  21. this.m_goPanel.SetActive(false);
  22. this.currentView = SaveAndLoadMgr.ViewType.None;
  23. this.currentPageNo = SaveAndLoadMgr.PageNo.Page_1;
  24. }
  25. public void OpenSavePanel()
  26. {
  27. Debug.Log("セーブをオープンしました。");
  28. base.BaseOpenPanel(SaveAndLoadMgr.ViewType.Save.ToString());
  29. }
  30. public void OpenLoadPanel()
  31. {
  32. this.m_ctrl.Kasiduki = false;
  33. Debug.Log("ロードをオープンしました。");
  34. base.BaseOpenPanel(SaveAndLoadMgr.ViewType.Load.ToString());
  35. }
  36. public void OpenLoadPanelKasiduki()
  37. {
  38. this.m_ctrl.Kasiduki = true;
  39. Debug.Log("ロード(カシヅキ)をオープンしました。");
  40. base.BaseOpenPanel(SaveAndLoadMgr.ViewType.Load.ToString());
  41. }
  42. public void OpenLoadPanelKasizukiLocal()
  43. {
  44. base.BaseOpenPanel("傅き");
  45. }
  46. protected override void OpenPanel(string openType)
  47. {
  48. if (openType == "傅き")
  49. {
  50. if (this.OnOpenLoadPanelKasizukiLocal != null)
  51. {
  52. this.OnOpenLoadPanelKasizukiLocal();
  53. }
  54. return;
  55. }
  56. SaveAndLoadMgr.ViewType viewType = (SaveAndLoadMgr.ViewType)Enum.Parse(typeof(SaveAndLoadMgr.ViewType), openType);
  57. if (viewType != SaveAndLoadMgr.ViewType.Save)
  58. {
  59. if (viewType == SaveAndLoadMgr.ViewType.Load)
  60. {
  61. this.DisplayLoadPanel();
  62. }
  63. }
  64. else
  65. {
  66. this.DisplaySavePanel();
  67. }
  68. }
  69. private void DisplaySavePanel()
  70. {
  71. this.CreateSaveOrLoadViewer(SaveAndLoadMgr.ViewType.Save);
  72. }
  73. private void DisplayLoadPanel()
  74. {
  75. this.CreateSaveOrLoadViewer(SaveAndLoadMgr.ViewType.Load);
  76. }
  77. private void CreateSaveOrLoadViewer(SaveAndLoadMgr.ViewType selectView)
  78. {
  79. if (this.currentView == selectView)
  80. {
  81. return;
  82. }
  83. int pageNoLatestData = this.GetPageNoLatestData();
  84. if (pageNoLatestData == -1)
  85. {
  86. this.currentPageNo = SaveAndLoadMgr.PageNo.Page_1;
  87. }
  88. else
  89. {
  90. this.currentPageNo = (SaveAndLoadMgr.PageNo)pageNoLatestData;
  91. }
  92. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage((int)this.currentPageNo);
  93. this.m_goPanel.SetActive(true);
  94. this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, selectView);
  95. this.currentView = selectView;
  96. this.currentActiveData = string.Empty;
  97. }
  98. private int GetPageNoLatestData()
  99. {
  100. long num = GameMain.Instance.NewSaveDataNo();
  101. return (int)num / 10 + 1;
  102. }
  103. public void CloseSaveAndLoadPanel()
  104. {
  105. base.BaseClosePanel();
  106. this.m_ctrl.CloseReset();
  107. }
  108. public void ClosePanelAfterAction<T>(Func<T, bool> action, T param)
  109. {
  110. TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, 0.5f, 0f);
  111. EventDelegate.Set(tweenAlpha.onFinished, delegate
  112. {
  113. if (action != null)
  114. {
  115. if (action(param))
  116. {
  117. this.fadeTargetPanel.SetActive(false);
  118. }
  119. else
  120. {
  121. this.CloseSaveAndLoadPanel();
  122. }
  123. action = null;
  124. }
  125. });
  126. }
  127. protected override void ClosePanel()
  128. {
  129. this.currentView = SaveAndLoadMgr.ViewType.None;
  130. this.currentPageNo = SaveAndLoadMgr.PageNo.Page_1;
  131. }
  132. public void ClickPageNo()
  133. {
  134. string name = UIButton.current.name;
  135. if (!base.IsValidateButton<SaveAndLoadMgr.PageNo>(name))
  136. {
  137. return;
  138. }
  139. SaveAndLoadMgr.PageNo pageNo = (SaveAndLoadMgr.PageNo)Enum.Parse(typeof(SaveAndLoadMgr.PageNo), name);
  140. if (pageNo == this.currentPageNo)
  141. {
  142. return;
  143. }
  144. this.currentPageNo = pageNo;
  145. int pageNo2 = (int)pageNo;
  146. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage(pageNo2);
  147. this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, this.currentView);
  148. }
  149. public void PageUpper()
  150. {
  151. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage((int)this.currentPageNo);
  152. this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, this.currentView);
  153. }
  154. public void ClickSaveOrLoadData()
  155. {
  156. string name = UIButton.current.name;
  157. if (this.currentActiveData == name)
  158. {
  159. Debug.Log("同じデータがクリックされたので処理を抜けます。");
  160. return;
  161. }
  162. if (UICamera.currentTouchID == -1)
  163. {
  164. this.m_ctrl.SetSaveOrLoadDataActive(name);
  165. if (UICamera.currentTouchID == -1)
  166. {
  167. this.currentActiveData = name;
  168. this.m_ctrl.SaveAndLoad(this.currentView, name);
  169. }
  170. }
  171. else if (UICamera.currentTouchID == -2 && !GameMain.Instance.VRMode)
  172. {
  173. Debug.Log(string.Format("{0}ボタンが右クリックされました。", name));
  174. if (this.m_ctrl.ExistData(name))
  175. {
  176. this.m_ctrl.DeleteSaveOrLoadData(name);
  177. }
  178. }
  179. }
  180. public void ClickComment()
  181. {
  182. Collider collider = UICamera.lastHit.collider;
  183. if (collider != null)
  184. {
  185. UIButton componentInParent = collider.GetComponentInParent<UIButton>();
  186. this.m_ctrl.SetSaveOrLoadDataActive(componentInParent.name);
  187. }
  188. }
  189. public void OnChangeComment()
  190. {
  191. string name = UIInput.current.name;
  192. string value = UIInput.current.value;
  193. this.m_ctrl.SaveComment(name, value);
  194. }
  195. protected override void SetFadeTargetPanel()
  196. {
  197. this.fadeTargetPanel = this.m_goPanel;
  198. }
  199. protected override void AfterFadeOut()
  200. {
  201. if (this.m_ctrl.IsTitleScene)
  202. {
  203. if (this.CallbackAfterFadeOut != null)
  204. {
  205. this.CallbackAfterFadeOut();
  206. }
  207. }
  208. else if (!this.m_ctrl.GetIsLoading())
  209. {
  210. DailyMgr manager = base.GetManager<DailyMgr>();
  211. manager.BaseOpenPanel(manager.GetCurrentDaily().ToString());
  212. }
  213. base.AfterFadeOut();
  214. }
  215. protected override void BeforeClose()
  216. {
  217. UICamera.InputEnable = false;
  218. }
  219. protected override void AfterClose()
  220. {
  221. if (!this.m_ctrl.GetIsLoading())
  222. {
  223. UICamera.InputEnable = true;
  224. }
  225. }
  226. private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> LoadDataByPage(int pageNo)
  227. {
  228. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dictionary = new Dictionary<string, SaveAndLoadCtrl.LoadDataUnit>();
  229. int num = (pageNo - 1) * 10;
  230. int num2 = num + 10 - 1;
  231. for (int i = num; i <= num2; i++)
  232. {
  233. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = new SaveAndLoadCtrl.LoadDataUnit();
  234. GameMain.SerializeHeader saveDataHeader = GameMain.Instance.GetSaveDataHeader(i);
  235. if (saveDataHeader != null)
  236. {
  237. loadDataUnit.pageNo = pageNo;
  238. loadDataUnit.serialNo = i;
  239. loadDataUnit.isLatest = GameMain.Instance.IsSaveDataNew(i);
  240. loadDataUnit.nVer = saveDataHeader.nVer;
  241. loadDataUnit.createAt = this.DateTimeParse(saveDataHeader.strSaveTime);
  242. loadDataUnit.lapsedDays = saveDataHeader.nGameDay;
  243. loadDataUnit.managerName = saveDataHeader.strPlayerName;
  244. loadDataUnit.numberOfEmployees = saveDataHeader.nMaidNum;
  245. loadDataUnit.comment = saveDataHeader.strComment;
  246. loadDataUnit.isEmpty = false;
  247. }
  248. else
  249. {
  250. loadDataUnit.pageNo = pageNo;
  251. loadDataUnit.serialNo = i;
  252. loadDataUnit.isEmpty = true;
  253. }
  254. dictionary.Add(string.Format("serialNo_{0}", i), loadDataUnit);
  255. }
  256. return dictionary;
  257. }
  258. private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> MakeDummyData()
  259. {
  260. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dictionary = new Dictionary<string, SaveAndLoadCtrl.LoadDataUnit>();
  261. int num = 0;
  262. int num2 = 0;
  263. int num3 = 0;
  264. int num4 = 47;
  265. for (int i = 0; i < num4; i++)
  266. {
  267. if (i % 10 == 0)
  268. {
  269. num++;
  270. num2 = 1;
  271. }
  272. int num5 = UnityEngine.Random.Range(0, 10);
  273. if (num5 % 3 == 0)
  274. {
  275. num2++;
  276. }
  277. else
  278. {
  279. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = new SaveAndLoadCtrl.LoadDataUnit();
  280. loadDataUnit.pageNo = num;
  281. loadDataUnit.serialNo = num3;
  282. loadDataUnit.isLatest = false;
  283. loadDataUnit.createAt = DateTime.Now.ToString();
  284. loadDataUnit.lapsedDays = i;
  285. loadDataUnit.managerName = "経営者_" + i;
  286. loadDataUnit.numberOfEmployees = UnityEngine.Random.Range(0, 30);
  287. loadDataUnit.comment = string.Format("コメント_{0}、ページ={1}、シリアルNo={2}", i, loadDataUnit.pageNo, loadDataUnit.serialNo);
  288. dictionary.Add(string.Format("serialNo_{0}", num3), loadDataUnit);
  289. num2++;
  290. num3++;
  291. }
  292. }
  293. return dictionary;
  294. }
  295. private string DateTimeParse(string strDate)
  296. {
  297. string format = "yyyyMMddHHmmss";
  298. return DateTime.ParseExact(strDate, format, null).ToString("yyyy.MM.dd HH:mm");
  299. }
  300. private string currentActiveData;
  301. private SaveAndLoadMgr.PageNo currentPageNo;
  302. private SaveAndLoadCtrl m_ctrl;
  303. private SaveAndLoadMgr.ViewType currentView;
  304. private const SaveAndLoadMgr.PageNo PAGE_NO_WHEN_OPEN = SaveAndLoadMgr.PageNo.Page_1;
  305. private const string BUTTON_NAME_TEMPLATE = "serialNo_{0}";
  306. private const float DURATION_TO_FADE = 0.5f;
  307. private const int MAX_SLOT_COUNT_PER_PAGE = 10;
  308. private const int NOTHING_SAVE_DATA = -1;
  309. private const int LeftClick = -1;
  310. private const int RightClick = -2;
  311. public enum ViewType
  312. {
  313. None,
  314. Save,
  315. Load
  316. }
  317. public enum PageNo
  318. {
  319. Page_1 = 1,
  320. Page_2,
  321. Page_3,
  322. Page_4,
  323. Page_5,
  324. Page_6,
  325. Page_7,
  326. Page_8,
  327. Page_9,
  328. Page_10
  329. }
  330. }