SaveAndLoadMgr.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. BasePanelMgr.isOpen = false;
  111. TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, 0.5f, 0f);
  112. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  113. {
  114. if (action != null)
  115. {
  116. if (action(param))
  117. {
  118. this.fadeTargetPanel.SetActive(false);
  119. }
  120. else
  121. {
  122. this.CloseSaveAndLoadPanel();
  123. }
  124. action = null;
  125. }
  126. });
  127. }
  128. protected override void ClosePanel()
  129. {
  130. this.currentView = SaveAndLoadMgr.ViewType.None;
  131. this.currentPageNo = SaveAndLoadMgr.PageNo.Page_1;
  132. }
  133. public void ClickPageNo()
  134. {
  135. string name = UIButton.current.name;
  136. if (!base.IsValidateButton<SaveAndLoadMgr.PageNo>(name))
  137. {
  138. return;
  139. }
  140. SaveAndLoadMgr.PageNo pageNo = (SaveAndLoadMgr.PageNo)Enum.Parse(typeof(SaveAndLoadMgr.PageNo), name);
  141. if (pageNo == this.currentPageNo)
  142. {
  143. return;
  144. }
  145. this.currentPageNo = pageNo;
  146. int pageNo2 = (int)pageNo;
  147. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage(pageNo2);
  148. this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, this.currentView);
  149. }
  150. public void PageUpper()
  151. {
  152. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage((int)this.currentPageNo);
  153. this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, this.currentView);
  154. }
  155. public void ClickSaveOrLoadData()
  156. {
  157. string name = UIButton.current.name;
  158. if (this.currentActiveData == name)
  159. {
  160. Debug.Log("同じデータがクリックされたので処理を抜けます。");
  161. return;
  162. }
  163. if (UICamera.currentTouchID == -1)
  164. {
  165. this.m_ctrl.SetSaveOrLoadDataActive(name);
  166. if (UICamera.currentTouchID == -1)
  167. {
  168. this.currentActiveData = name;
  169. this.m_ctrl.SaveAndLoad(this.currentView, name);
  170. }
  171. }
  172. else if (UICamera.currentTouchID == -2 && !GameMain.Instance.VRMode)
  173. {
  174. Debug.Log(string.Format("{0}ボタンが右クリックされました。", name));
  175. if (this.m_ctrl.ExistData(name))
  176. {
  177. this.m_ctrl.DeleteSaveOrLoadData(name);
  178. }
  179. }
  180. }
  181. public void ClickComment()
  182. {
  183. Collider collider = UICamera.lastHit.collider;
  184. if (collider != null)
  185. {
  186. UIButton componentInParent = collider.GetComponentInParent<UIButton>();
  187. this.m_ctrl.SetSaveOrLoadDataActive(componentInParent.name);
  188. }
  189. }
  190. public void OnChangeComment()
  191. {
  192. string name = UIInput.current.name;
  193. string value = UIInput.current.value;
  194. this.m_ctrl.SaveComment(name, value);
  195. }
  196. protected override void SetFadeTargetPanel()
  197. {
  198. this.fadeTargetPanel = this.m_goPanel;
  199. }
  200. protected override void AfterFadeOut()
  201. {
  202. if (this.m_ctrl.IsTitleScene)
  203. {
  204. if (this.CallbackAfterFadeOut != null)
  205. {
  206. this.CallbackAfterFadeOut();
  207. }
  208. }
  209. else if (!this.m_ctrl.GetIsLoading())
  210. {
  211. DailyMgr manager = base.GetManager<DailyMgr>();
  212. manager.BaseOpenPanel(manager.GetCurrentDaily().ToString());
  213. }
  214. base.AfterFadeOut();
  215. }
  216. protected override void BeforeClose()
  217. {
  218. UICamera.InputEnable = false;
  219. }
  220. protected override void AfterClose()
  221. {
  222. if (!this.m_ctrl.GetIsLoading())
  223. {
  224. UICamera.InputEnable = true;
  225. }
  226. }
  227. private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> LoadDataByPage(int pageNo)
  228. {
  229. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dictionary = new Dictionary<string, SaveAndLoadCtrl.LoadDataUnit>();
  230. int num = (pageNo - 1) * 10;
  231. int num2 = num + 10 - 1;
  232. for (int i = num; i <= num2; i++)
  233. {
  234. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = new SaveAndLoadCtrl.LoadDataUnit();
  235. GameMain.SerializeHeader saveDataHeader = GameMain.Instance.GetSaveDataHeader(i);
  236. if (saveDataHeader != null)
  237. {
  238. loadDataUnit.pageNo = pageNo;
  239. loadDataUnit.serialNo = i;
  240. loadDataUnit.isLatest = GameMain.Instance.IsSaveDataNew(i);
  241. loadDataUnit.nVer = saveDataHeader.nVer;
  242. loadDataUnit.createAt = this.DateTimeParse(saveDataHeader.strSaveTime);
  243. loadDataUnit.lapsedDays = saveDataHeader.nGameDay;
  244. loadDataUnit.managerName = saveDataHeader.strPlayerName;
  245. loadDataUnit.numberOfEmployees = saveDataHeader.nMaidNum;
  246. loadDataUnit.comment = saveDataHeader.strComment;
  247. loadDataUnit.isEmpty = false;
  248. loadDataUnit.productTypeID = saveDataHeader.productTypeID;
  249. }
  250. else
  251. {
  252. loadDataUnit.pageNo = pageNo;
  253. loadDataUnit.serialNo = i;
  254. loadDataUnit.isEmpty = true;
  255. }
  256. dictionary.Add(string.Format("serialNo_{0}", i), loadDataUnit);
  257. }
  258. return dictionary;
  259. }
  260. private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> MakeDummyData()
  261. {
  262. Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dictionary = new Dictionary<string, SaveAndLoadCtrl.LoadDataUnit>();
  263. int num = 0;
  264. int num2 = 0;
  265. int num3 = 0;
  266. int num4 = 47;
  267. for (int i = 0; i < num4; i++)
  268. {
  269. if (i % 10 == 0)
  270. {
  271. num++;
  272. num2 = 1;
  273. }
  274. int num5 = UnityEngine.Random.Range(0, 10);
  275. if (num5 % 3 == 0)
  276. {
  277. num2++;
  278. }
  279. else
  280. {
  281. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = new SaveAndLoadCtrl.LoadDataUnit();
  282. loadDataUnit.pageNo = num;
  283. loadDataUnit.serialNo = num3;
  284. loadDataUnit.isLatest = false;
  285. loadDataUnit.createAt = DateTime.Now.ToString();
  286. loadDataUnit.lapsedDays = i;
  287. loadDataUnit.managerName = "経営者_" + i;
  288. loadDataUnit.numberOfEmployees = UnityEngine.Random.Range(0, 30);
  289. loadDataUnit.comment = string.Format("コメント_{0}、ページ={1}、シリアルNo={2}", i, loadDataUnit.pageNo, loadDataUnit.serialNo);
  290. dictionary.Add(string.Format("serialNo_{0}", num3), loadDataUnit);
  291. num2++;
  292. num3++;
  293. }
  294. }
  295. return dictionary;
  296. }
  297. private string DateTimeParse(string strDate)
  298. {
  299. string format = "yyyyMMddHHmmss";
  300. return DateTime.ParseExact(strDate, format, null).ToString("yyyy.MM.dd HH:mm");
  301. }
  302. private string currentActiveData;
  303. private SaveAndLoadMgr.PageNo currentPageNo;
  304. private SaveAndLoadCtrl m_ctrl;
  305. private SaveAndLoadMgr.ViewType currentView;
  306. private const SaveAndLoadMgr.PageNo PAGE_NO_WHEN_OPEN = SaveAndLoadMgr.PageNo.Page_1;
  307. private const string BUTTON_NAME_TEMPLATE = "serialNo_{0}";
  308. private const float DURATION_TO_FADE = 0.5f;
  309. private const int MAX_SLOT_COUNT_PER_PAGE = 10;
  310. private const int NOTHING_SAVE_DATA = -1;
  311. private const int LeftClick = -1;
  312. private const int RightClick = -2;
  313. public enum ViewType
  314. {
  315. None,
  316. Save,
  317. Load
  318. }
  319. public enum PageNo
  320. {
  321. Page_1 = 1,
  322. Page_2,
  323. Page_3,
  324. Page_4,
  325. Page_5,
  326. Page_6,
  327. Page_7,
  328. Page_8,
  329. Page_9,
  330. Page_10
  331. }
  332. }