KasizukiSaveAndLoadCtrl.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Kasizuki
  5. {
  6. public class KasizukiSaveAndLoadCtrl : NGUIWindow
  7. {
  8. private void Start()
  9. {
  10. if (this.m_IsStarted)
  11. {
  12. return;
  13. }
  14. this.SetUpSavePanel();
  15. this.SetUpLoadPanel();
  16. this.SetUpOtherButtons();
  17. this.SetUpDataUnits();
  18. this.m_NowOpenPage = SaveAndLoadMgr.PageNo.Page_1;
  19. this.m_IsStarted = true;
  20. }
  21. private void SetUpSavePanel()
  22. {
  23. this.m_CacheSaveObjects = new ObjectCacheDic();
  24. this.m_CacheSaveObjects.CacheChildObject<Component>(base.gameObject, "TitleGroup/TitleSave", "SavePanel");
  25. UIButton childObject = this.m_CacheSaveObjects.GetChildObject<UIButton>(base.gameObject, "DisplayButtonGroup/DisplayLoad");
  26. this.m_CacheSaveObjects.AddCache<UIButton>("LoadButton", childObject);
  27. EventDelegate.Add(childObject.onClick, delegate()
  28. {
  29. this.Open(SaveAndLoadMgr.ViewType.Load, true);
  30. });
  31. }
  32. private void SetUpLoadPanel()
  33. {
  34. this.m_CacheLoadObjects = new ObjectCacheDic();
  35. this.m_CacheLoadObjects.CacheChildObject<Component>(base.gameObject, "TitleGroup/TitleLoad", "LoadPanel");
  36. UIButton childObject = this.m_CacheLoadObjects.GetChildObject<UIButton>(base.gameObject, "DisplayButtonGroup/DisplaySave");
  37. this.m_CacheLoadObjects.AddCache<UIButton>("SaveButton", childObject);
  38. EventDelegate.Add(childObject.onClick, delegate()
  39. {
  40. this.Open(SaveAndLoadMgr.ViewType.Save, true);
  41. });
  42. }
  43. private void SetUpOtherButtons()
  44. {
  45. this.m_CacheButtons = new ObjectCacheDic();
  46. UIButton uibutton = this.m_CacheButtons.CacheChildObject<UIButton>(base.gameObject, "Cancel", "Cancel");
  47. EventDelegate.Add(uibutton.onClick, new EventDelegate.Callback(this.OnClickCancel));
  48. this.m_PageButtonDic = new Dictionary<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton>();
  49. this.m_InactiveColor = (this.m_ActiveColor = this.m_ListPageButtons.tempItem.GetComponent<UIWidget>().color);
  50. this.m_ActiveColor.a = 1f;
  51. this.m_ListPageButtons.Show<UIButton>(5, delegate(int index, UIButton button)
  52. {
  53. int num = index + 1;
  54. UISprite component = button.GetComponent<UISprite>();
  55. if (component != null)
  56. {
  57. component.spriteName = string.Format("{0}{1:00}", "cm3d2_save_load_page", num);
  58. }
  59. SaveAndLoadCtrl.PageButton buttonPage = new SaveAndLoadCtrl.PageButton();
  60. buttonPage.pageNo = (SaveAndLoadMgr.PageNo)Enum.Parse(typeof(SaveAndLoadMgr.PageNo), num.ToString());
  61. buttonPage.btnPageNo = button;
  62. buttonPage.selectCursor = button.transform.Find("SelectCursor").gameObject;
  63. this.m_PageButtonDic.Add(buttonPage.pageNo, buttonPage);
  64. EventDelegate.Add(button.onClick, delegate()
  65. {
  66. this.OnClickPageButton(buttonPage.pageNo);
  67. });
  68. });
  69. }
  70. private void SetUpDataUnits()
  71. {
  72. this.m_ListDataUnits.tempItem.AddComponent<KasizukiSaveAndLoadCtrl.DataUnitComp>();
  73. this.m_ListDataUnits.Show<KasizukiSaveAndLoadCtrl.DataUnitComp>(16, delegate(int index, KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
  74. {
  75. dataUnit.Init(index);
  76. UIButton component = dataUnit.GetComponent<UIButton>();
  77. if (index == 0)
  78. {
  79. EventDelegate.Add(component.onClick, delegate()
  80. {
  81. this.OnClickNewGameUnit(dataUnit);
  82. });
  83. }
  84. else
  85. {
  86. EventDelegate.Add(component.onClick, delegate()
  87. {
  88. this.OnClickDataUnit(dataUnit);
  89. });
  90. }
  91. UIInput inputComment = dataUnit.inputComment;
  92. EventDelegate.Add(inputComment.onChange, delegate()
  93. {
  94. this.OnChangeDataUnitComment(dataUnit);
  95. });
  96. EventDelegate.Add(inputComment.onSubmit, new EventDelegate.Callback(inputComment.RemoveFocus));
  97. });
  98. }
  99. public void Open(SaveAndLoadMgr.ViewType viewType, bool isLatestPageOpen = false)
  100. {
  101. if (!this.m_IsStarted)
  102. {
  103. this.Start();
  104. }
  105. if (isLatestPageOpen)
  106. {
  107. int pageNumberLatestData = this.GetPageNumberLatestData();
  108. if (pageNumberLatestData > 0)
  109. {
  110. this.m_NowOpenPage = (SaveAndLoadMgr.PageNo)pageNumberLatestData;
  111. }
  112. else
  113. {
  114. this.m_NowOpenPage = SaveAndLoadMgr.PageNo.Page_1;
  115. }
  116. }
  117. if (viewType == SaveAndLoadMgr.ViewType.Save)
  118. {
  119. this.OpenSave();
  120. }
  121. else if (viewType == SaveAndLoadMgr.ViewType.Load)
  122. {
  123. this.OpenLoad();
  124. }
  125. else
  126. {
  127. NDebug.Assert("セーブロードのUIを開くときの種類に不正な値が入りました", false);
  128. Debug.LogError("セーブロードのUIを開くときの種類に不正な値が入りました");
  129. }
  130. this.m_NowViewType = viewType;
  131. this.OnClickPageButton(this.m_NowOpenPage);
  132. }
  133. private void OpenSave()
  134. {
  135. foreach (KeyValuePair<string, UnityEngine.Object> keyValuePair in this.m_CacheLoadObjects.Dic)
  136. {
  137. Component component = (Component)keyValuePair.Value;
  138. if (component && component.gameObject)
  139. {
  140. component.gameObject.SetActive(false);
  141. }
  142. else
  143. {
  144. Debug.LogWarningFormat("m_CacheLoadObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[]
  145. {
  146. keyValuePair.Key
  147. });
  148. }
  149. }
  150. foreach (KeyValuePair<string, UnityEngine.Object> keyValuePair2 in this.m_CacheSaveObjects.Dic)
  151. {
  152. Component component2 = (Component)keyValuePair2.Value;
  153. if (component2 && component2.gameObject)
  154. {
  155. component2.gameObject.SetActive(true);
  156. }
  157. else
  158. {
  159. Debug.LogWarningFormat("m_CacheSaveObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[]
  160. {
  161. keyValuePair2.Key
  162. });
  163. }
  164. }
  165. }
  166. private void OpenLoad()
  167. {
  168. foreach (KeyValuePair<string, UnityEngine.Object> keyValuePair in this.m_CacheSaveObjects.Dic)
  169. {
  170. Component component = (Component)keyValuePair.Value;
  171. if (component && component.gameObject)
  172. {
  173. component.gameObject.SetActive(false);
  174. }
  175. else
  176. {
  177. Debug.LogWarningFormat("m_CacheSaveObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[]
  178. {
  179. keyValuePair.Key
  180. });
  181. }
  182. }
  183. foreach (KeyValuePair<string, UnityEngine.Object> keyValuePair2 in this.m_CacheLoadObjects.Dic)
  184. {
  185. Component component2 = (Component)keyValuePair2.Value;
  186. if (component2 && component2.gameObject)
  187. {
  188. component2.gameObject.SetActive(true);
  189. }
  190. else
  191. {
  192. Debug.LogWarningFormat("m_CacheLoadObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[]
  193. {
  194. keyValuePair2.Key
  195. });
  196. }
  197. }
  198. }
  199. private void UpdateDataUnits()
  200. {
  201. if (this.m_NowViewType == SaveAndLoadMgr.ViewType.Save)
  202. {
  203. GameObject[] itemArray = this.m_ListDataUnits.ItemArray;
  204. for (int i = 0; i < itemArray.Length; i++)
  205. {
  206. int saveDataIndex = i + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * itemArray.Length;
  207. KasizukiManager.SaveDataHeader saveDataHeader = GameMain.Instance.KasizukiMgr.GetSaveDataHeader(saveDataIndex);
  208. KasizukiSaveAndLoadCtrl.DataUnitComp component = itemArray[i].GetComponent<KasizukiSaveAndLoadCtrl.DataUnitComp>();
  209. this.SetDataUnitAtHeader(component, saveDataHeader);
  210. UIButton component2 = component.GetComponent<UIButton>();
  211. if (i != 0)
  212. {
  213. component2.isEnabled = true;
  214. }
  215. else
  216. {
  217. component2.isEnabled = false;
  218. }
  219. }
  220. }
  221. else if (this.m_NowViewType == SaveAndLoadMgr.ViewType.Load)
  222. {
  223. GameObject[] itemArray2 = this.m_ListDataUnits.ItemArray;
  224. for (int j = 0; j < itemArray2.Length; j++)
  225. {
  226. int saveDataIndex2 = j + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * itemArray2.Length;
  227. KasizukiManager.SaveDataHeader saveDataHeader2 = GameMain.Instance.KasizukiMgr.GetSaveDataHeader(saveDataIndex2);
  228. KasizukiSaveAndLoadCtrl.DataUnitComp component3 = itemArray2[j].GetComponent<KasizukiSaveAndLoadCtrl.DataUnitComp>();
  229. this.SetDataUnitAtHeader(component3, saveDataHeader2);
  230. UIButton component4 = component3.GetComponent<UIButton>();
  231. if (j != 0)
  232. {
  233. component4.isEnabled = (saveDataHeader2 != null);
  234. }
  235. else
  236. {
  237. component4.isEnabled = true;
  238. }
  239. }
  240. }
  241. else
  242. {
  243. NDebug.Assert("セーブロードのUIを更新するときの種類に不正な値が入っていました", false);
  244. }
  245. }
  246. private void SetDataUnitAtHeader(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit, KasizukiManager.SaveDataHeader header)
  247. {
  248. NDebug.Assert(dataUnit != null, "セーブデータの項目にnullが指定されました");
  249. if (header != null)
  250. {
  251. dataUnit.content.SetActive(true);
  252. dataUnit.newLabel.SetActive(GameMain.Instance.KasizukiMgr.LatestSaveDataNumber == header.saveDataNumber);
  253. int lastManType = header.lastManType;
  254. ManData.Data data = ManData.GetData(lastManType);
  255. dataUnit.labelDate.text = header.GetDateTime().ToString("yyyy.MM.dd HH:mm");
  256. dataUnit.labelMaidCount.text = KasizukiManager.GetEnableMaidList().Count.ToString();
  257. dataUnit.labelManName.text = data.drawName;
  258. dataUnit.labelUsedCount.text = header.playCount.ToString();
  259. dataUnit.inputComment.value = header.strComment;
  260. }
  261. else
  262. {
  263. dataUnit.content.SetActive(false);
  264. dataUnit.newLabel.SetActive(false);
  265. }
  266. if (dataUnit.index == 0)
  267. {
  268. dataUnit.newGameLabel.SetActive(true);
  269. }
  270. else
  271. {
  272. dataUnit.newGameLabel.SetActive(false);
  273. }
  274. }
  275. private int GetPageNumberLatestData()
  276. {
  277. int latestSaveDataNumber = GameMain.Instance.KasizukiMgr.LatestSaveDataNumber;
  278. return latestSaveDataNumber / 16 + 1;
  279. }
  280. private void OnClickPageButton(SaveAndLoadMgr.PageNo pageNo)
  281. {
  282. this.m_NowOpenPage = pageNo;
  283. this.UpdatePageButtons(pageNo);
  284. this.UpdateDataUnits();
  285. }
  286. private void UpdatePageButtons(SaveAndLoadMgr.PageNo pageNo)
  287. {
  288. foreach (KeyValuePair<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> keyValuePair in this.m_PageButtonDic)
  289. {
  290. if (keyValuePair.Key == pageNo)
  291. {
  292. keyValuePair.Value.btnPageNo.defaultColor = this.m_ActiveColor;
  293. keyValuePair.Value.selectCursor.SetActive(true);
  294. }
  295. else
  296. {
  297. keyValuePair.Value.btnPageNo.defaultColor = this.m_InactiveColor;
  298. keyValuePair.Value.selectCursor.SetActive(false);
  299. }
  300. }
  301. }
  302. private void OnClickDataUnit(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
  303. {
  304. int saveSlot = dataUnit.index + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * 16;
  305. if (UICamera.currentTouchID != -2)
  306. {
  307. SaveAndLoadMgr.ViewType nowViewType = this.m_NowViewType;
  308. if (nowViewType != SaveAndLoadMgr.ViewType.Load)
  309. {
  310. if (nowViewType != SaveAndLoadMgr.ViewType.Save)
  311. {
  312. NDebug.Assert("セーブデータを開く種類に不正な値が入っていました", false);
  313. }
  314. else
  315. {
  316. string msg;
  317. if (GameMain.Instance.KasizukiMgr.IsExistSaveData(saveSlot))
  318. {
  319. msg = string.Format("{0}番に上書きして保存します。\n宜しいですか?", saveSlot);
  320. }
  321. else
  322. {
  323. msg = string.Format("{0}番にデータを保存しますか?", saveSlot);
  324. }
  325. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate
  326. {
  327. this.CloseDialog();
  328. this.Save(saveSlot);
  329. });
  330. }
  331. }
  332. else
  333. {
  334. string msg = string.Format("{0}番のデータをロードしますか?", saveSlot);
  335. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate
  336. {
  337. this.CloseDialog();
  338. this.Load(saveSlot);
  339. });
  340. }
  341. return;
  342. }
  343. if (!GameMain.Instance.KasizukiMgr.IsExistSaveData(saveSlot))
  344. {
  345. return;
  346. }
  347. string msg2 = string.Format("データを削除します。\n本当に宜しいですか。", new object[0]);
  348. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg2, delegate
  349. {
  350. this.CloseDialog();
  351. this.Delete(saveSlot);
  352. });
  353. }
  354. private void OnClickNewGameUnit(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
  355. {
  356. if (dataUnit.index != 0)
  357. {
  358. return;
  359. }
  360. string msg = "ここに新規顧客情報を登録します。";
  361. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate
  362. {
  363. this.CloseDialog();
  364. this.NewGame();
  365. });
  366. }
  367. private void OnChangeDataUnitComment(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
  368. {
  369. int saveDataIndex = dataUnit.index + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * 16;
  370. KasizukiManager.SaveDataHeader saveDataHeader = GameMain.Instance.KasizukiMgr.GetSaveDataHeader(saveDataIndex);
  371. saveDataHeader.strComment = dataUnit.inputComment.value;
  372. }
  373. private void OnClickCancel()
  374. {
  375. if (this.onClickCancel != null)
  376. {
  377. this.onClickCancel();
  378. }
  379. }
  380. private void OpenDialog(SystemDialog.TYPE openType, string msg, Action onOK)
  381. {
  382. GameMain.Instance.SysDlg.Show(msg, openType, delegate
  383. {
  384. if (onOK != null)
  385. {
  386. onOK();
  387. }
  388. }, new SystemDialog.OnClick(this.CloseDialog));
  389. }
  390. private void CloseDialog()
  391. {
  392. GameMain.Instance.SysDlg.Close();
  393. }
  394. private void Save(int saveSlot)
  395. {
  396. GameMain.Instance.KasizukiMgr.SerializeLocal(saveSlot);
  397. this.Open(SaveAndLoadMgr.ViewType.Save, false);
  398. if (this.onSave != null)
  399. {
  400. this.onSave();
  401. }
  402. this.OpenDialog(SystemDialog.TYPE.OK, "データを保存しました。", new Action(this.CloseDialog));
  403. }
  404. private void Load(int saveSlot)
  405. {
  406. GameMain.Instance.KasizukiMgr.DeserializeLocal(saveSlot);
  407. if (this.onLoad != null)
  408. {
  409. this.onLoad();
  410. }
  411. }
  412. private void Delete(int saveSlot)
  413. {
  414. GameMain.Instance.KasizukiMgr.DeleteSaveDataLocal(saveSlot);
  415. this.Open(this.m_NowViewType, false);
  416. if (this.onDelete != null)
  417. {
  418. this.onDelete();
  419. }
  420. this.OpenDialog(SystemDialog.TYPE.OK, "データを削除しました。", new Action(this.CloseDialog));
  421. }
  422. private void NewGame()
  423. {
  424. GameMain.Instance.KasizukiMgr.CreateNewData();
  425. if (this.onClickNewGame != null)
  426. {
  427. this.onClickNewGame();
  428. }
  429. }
  430. private void OnDestroy()
  431. {
  432. this.onClickCancel = null;
  433. this.onClickNewGame = null;
  434. this.onLoad = null;
  435. this.onSave = null;
  436. this.onDelete = null;
  437. }
  438. public Action onClickCancel { get; set; }
  439. public Action onClickNewGame { get; set; }
  440. public Action onLoad { get; set; }
  441. public Action onSave { get; set; }
  442. public Action onDelete { get; set; }
  443. private const int PAGE_BUTTON_COUNT = 5;
  444. private const int PAGE_DATA_COUNT = 16;
  445. private const string STR_PAGE_BUTTON_NAME = "cm3d2_save_load_page";
  446. private const string DIALOG_MESSAGE_TO_SAVE_NORMAL = "{0}番にデータを保存しますか?";
  447. private const string DIALOG_MESSAGE_TO_SAVE_OVERWRITE = "{0}番に上書きして保存します。\n宜しいですか?";
  448. private const string DIALOG_MESSAGE_TO_LOAD = "{0}番のデータをロードしますか?";
  449. private const string DIALOG_MESSAGE_TO_DELETE = "データを削除します。\n本当に宜しいですか。";
  450. private const string DIALOG_MESSAGE_RESULT_SAVE = "データを保存しました。";
  451. private const string DIALOG_MESSAGE_RESULT_DELETE = "データを削除しました。";
  452. private const string DIALOG_MESSAGE_TO_NEW_GAME = "ここに新規顧客情報を登録します。";
  453. private bool m_IsStarted;
  454. [SerializeField]
  455. private uGUIListViewer m_ListPageButtons;
  456. [SerializeField]
  457. private uGUIListViewer m_ListDataUnits;
  458. private SaveAndLoadMgr.PageNo m_NowOpenPage;
  459. private SaveAndLoadMgr.ViewType m_NowViewType;
  460. private ObjectCacheDic m_CacheSaveObjects;
  461. private ObjectCacheDic m_CacheLoadObjects;
  462. private ObjectCacheDic m_CacheButtons;
  463. private Color m_ActiveColor;
  464. private Color m_InactiveColor;
  465. private Dictionary<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> m_PageButtonDic;
  466. public class DataUnitComp : MonoBehaviour
  467. {
  468. public int index { get; private set; }
  469. public void Awake()
  470. {
  471. this.SetUpCache();
  472. }
  473. protected virtual void SetUpCache()
  474. {
  475. this.content = UTY.GetChildObject(base.gameObject, "Content", false);
  476. this.labelDate = UTY.GetChildObject(this.content, "DataInfo/Date", false).GetComponent<UILabel>();
  477. this.labelUsedCount = UTY.GetChildObject(this.content, "DataInfo/UsedCount/Number", false).GetComponent<UILabel>();
  478. this.labelManName = UTY.GetChildObject(this.content, "DataInfo/Man/Name", false).GetComponent<UILabel>();
  479. this.labelMaidCount = UTY.GetChildObject(this.content, "DataInfo/NumberOfEmployees/Number", false).GetComponent<UILabel>();
  480. this.inputComment = UTY.GetChildObject(this.content, "Comment/InputField", false).GetComponent<UIInput>();
  481. this.selectCursor = UTY.GetChildObject(this.content, "SelectCursor", false);
  482. this.newLabel = UTY.GetChildObject(base.gameObject, "NewLabel", false);
  483. this.newGameLabel = UTY.GetChildObject(base.gameObject, "NewGameLabel", false);
  484. }
  485. public void Init(int index)
  486. {
  487. if (this.isInit)
  488. {
  489. Debug.Log("セーブデータ項目{0}番目は既に Init() 関数を呼ばれています。\n処理を行いません。");
  490. return;
  491. }
  492. this.index = index;
  493. this.isInit = true;
  494. }
  495. public UILabel labelDate;
  496. public UILabel labelUsedCount;
  497. public UILabel labelManName;
  498. public UILabel labelMaidCount;
  499. public UIInput inputComment;
  500. public GameObject selectCursor;
  501. public GameObject newLabel;
  502. public GameObject newGameLabel;
  503. public GameObject content;
  504. private bool isInit;
  505. }
  506. }
  507. }