KasizukiSaveAndLoadCtrl.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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 id = header.lastManType;
  254. if (GameMain.Instance.CharacterMgr.status.lockNTRPlay)
  255. {
  256. id = 10;
  257. }
  258. ManData.Data data = ManData.GetData(id);
  259. dataUnit.labelDate.text = header.GetDateTime().ToString("yyyy.MM.dd HH:mm");
  260. dataUnit.labelMaidCount.text = KasizukiManager.GetEnableMaidList().Count.ToString();
  261. dataUnit.labelManName.text = data.drawName;
  262. dataUnit.labelUsedCount.text = header.playCount.ToString();
  263. dataUnit.inputComment.value = header.strComment;
  264. }
  265. else
  266. {
  267. dataUnit.content.SetActive(false);
  268. dataUnit.newLabel.SetActive(false);
  269. }
  270. if (dataUnit.index == 0)
  271. {
  272. dataUnit.newGameLabel.SetActive(true);
  273. }
  274. else
  275. {
  276. dataUnit.newGameLabel.SetActive(false);
  277. }
  278. }
  279. private int GetPageNumberLatestData()
  280. {
  281. int latestSaveDataNumber = GameMain.Instance.KasizukiMgr.LatestSaveDataNumber;
  282. return latestSaveDataNumber / 16 + 1;
  283. }
  284. private void OnClickPageButton(SaveAndLoadMgr.PageNo pageNo)
  285. {
  286. this.m_NowOpenPage = pageNo;
  287. this.UpdatePageButtons(pageNo);
  288. this.UpdateDataUnits();
  289. }
  290. private void UpdatePageButtons(SaveAndLoadMgr.PageNo pageNo)
  291. {
  292. foreach (KeyValuePair<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> keyValuePair in this.m_PageButtonDic)
  293. {
  294. if (keyValuePair.Key == pageNo)
  295. {
  296. keyValuePair.Value.btnPageNo.defaultColor = this.m_ActiveColor;
  297. keyValuePair.Value.selectCursor.SetActive(true);
  298. }
  299. else
  300. {
  301. keyValuePair.Value.btnPageNo.defaultColor = this.m_InactiveColor;
  302. keyValuePair.Value.selectCursor.SetActive(false);
  303. }
  304. }
  305. }
  306. private void OnClickDataUnit(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
  307. {
  308. int saveSlot = dataUnit.index + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * 16;
  309. if (UICamera.currentTouchID != -2)
  310. {
  311. SaveAndLoadMgr.ViewType nowViewType = this.m_NowViewType;
  312. if (nowViewType != SaveAndLoadMgr.ViewType.Load)
  313. {
  314. if (nowViewType != SaveAndLoadMgr.ViewType.Save)
  315. {
  316. NDebug.Assert("セーブデータを開く種類に不正な値が入っていました", false);
  317. }
  318. else
  319. {
  320. string msg;
  321. if (GameMain.Instance.KasizukiMgr.IsExistSaveData(saveSlot))
  322. {
  323. msg = string.Format("{0}番に上書きして保存します。\n宜しいですか?", saveSlot);
  324. }
  325. else
  326. {
  327. msg = string.Format("{0}番にデータを保存しますか?", saveSlot);
  328. }
  329. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate
  330. {
  331. this.CloseDialog();
  332. this.Save(saveSlot);
  333. });
  334. }
  335. }
  336. else
  337. {
  338. string msg = string.Format("{0}番のデータをロードしますか?", saveSlot);
  339. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate
  340. {
  341. this.CloseDialog();
  342. this.Load(saveSlot);
  343. });
  344. }
  345. return;
  346. }
  347. if (!GameMain.Instance.KasizukiMgr.IsExistSaveData(saveSlot))
  348. {
  349. return;
  350. }
  351. string msg2 = string.Format("データを削除します。\n本当に宜しいですか。", new object[0]);
  352. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg2, delegate
  353. {
  354. this.CloseDialog();
  355. this.Delete(saveSlot);
  356. });
  357. }
  358. private void OnClickNewGameUnit(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
  359. {
  360. if (dataUnit.index != 0)
  361. {
  362. return;
  363. }
  364. string msg = "ここに新規顧客情報を登録します。";
  365. this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate
  366. {
  367. this.CloseDialog();
  368. this.NewGame();
  369. });
  370. }
  371. private void OnChangeDataUnitComment(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
  372. {
  373. int saveDataIndex = dataUnit.index + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * 16;
  374. KasizukiManager.SaveDataHeader saveDataHeader = GameMain.Instance.KasizukiMgr.GetSaveDataHeader(saveDataIndex);
  375. saveDataHeader.strComment = dataUnit.inputComment.value;
  376. }
  377. private void OnClickCancel()
  378. {
  379. if (this.onClickCancel != null)
  380. {
  381. this.onClickCancel();
  382. }
  383. }
  384. private void OpenDialog(SystemDialog.TYPE openType, string msg, Action onOK)
  385. {
  386. GameMain.Instance.SysDlg.Show(msg, openType, delegate
  387. {
  388. if (onOK != null)
  389. {
  390. onOK();
  391. }
  392. }, new SystemDialog.OnClick(this.CloseDialog));
  393. }
  394. private void CloseDialog()
  395. {
  396. GameMain.Instance.SysDlg.Close();
  397. }
  398. private void Save(int saveSlot)
  399. {
  400. GameMain.Instance.KasizukiMgr.SerializeLocal(saveSlot);
  401. this.Open(SaveAndLoadMgr.ViewType.Save, false);
  402. if (this.onSave != null)
  403. {
  404. this.onSave();
  405. }
  406. this.OpenDialog(SystemDialog.TYPE.OK, "データを保存しました。", new Action(this.CloseDialog));
  407. }
  408. private void Load(int saveSlot)
  409. {
  410. GameMain.Instance.KasizukiMgr.DeserializeLocal(saveSlot);
  411. if (this.onLoad != null)
  412. {
  413. this.onLoad();
  414. }
  415. }
  416. private void Delete(int saveSlot)
  417. {
  418. GameMain.Instance.KasizukiMgr.DeleteSaveDataLocal(saveSlot);
  419. this.Open(this.m_NowViewType, false);
  420. if (this.onDelete != null)
  421. {
  422. this.onDelete();
  423. }
  424. this.OpenDialog(SystemDialog.TYPE.OK, "データを削除しました。", new Action(this.CloseDialog));
  425. }
  426. private void NewGame()
  427. {
  428. GameMain.Instance.KasizukiMgr.CreateNewData();
  429. if (this.onClickNewGame != null)
  430. {
  431. this.onClickNewGame();
  432. }
  433. }
  434. private void OnDestroy()
  435. {
  436. this.onClickCancel = null;
  437. this.onClickNewGame = null;
  438. this.onLoad = null;
  439. this.onSave = null;
  440. this.onDelete = null;
  441. }
  442. public Action onClickCancel { get; set; }
  443. public Action onClickNewGame { get; set; }
  444. public Action onLoad { get; set; }
  445. public Action onSave { get; set; }
  446. public Action onDelete { get; set; }
  447. private const int PAGE_BUTTON_COUNT = 5;
  448. private const int PAGE_DATA_COUNT = 16;
  449. private const string STR_PAGE_BUTTON_NAME = "cm3d2_save_load_page";
  450. private const string DIALOG_MESSAGE_TO_SAVE_NORMAL = "{0}番にデータを保存しますか?";
  451. private const string DIALOG_MESSAGE_TO_SAVE_OVERWRITE = "{0}番に上書きして保存します。\n宜しいですか?";
  452. private const string DIALOG_MESSAGE_TO_LOAD = "{0}番のデータをロードしますか?";
  453. private const string DIALOG_MESSAGE_TO_DELETE = "データを削除します。\n本当に宜しいですか。";
  454. private const string DIALOG_MESSAGE_RESULT_SAVE = "データを保存しました。";
  455. private const string DIALOG_MESSAGE_RESULT_DELETE = "データを削除しました。";
  456. private const string DIALOG_MESSAGE_TO_NEW_GAME = "ここに新規顧客情報を登録します。";
  457. private bool m_IsStarted;
  458. [SerializeField]
  459. private uGUIListViewer m_ListPageButtons;
  460. [SerializeField]
  461. private uGUIListViewer m_ListDataUnits;
  462. private SaveAndLoadMgr.PageNo m_NowOpenPage;
  463. private SaveAndLoadMgr.ViewType m_NowViewType;
  464. private ObjectCacheDic m_CacheSaveObjects;
  465. private ObjectCacheDic m_CacheLoadObjects;
  466. private ObjectCacheDic m_CacheButtons;
  467. private Color m_ActiveColor;
  468. private Color m_InactiveColor;
  469. private Dictionary<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> m_PageButtonDic;
  470. public class DataUnitComp : MonoBehaviour
  471. {
  472. public int index { get; private set; }
  473. public void Awake()
  474. {
  475. this.SetUpCache();
  476. }
  477. protected virtual void SetUpCache()
  478. {
  479. this.content = UTY.GetChildObject(base.gameObject, "Content", false);
  480. this.labelDate = UTY.GetChildObject(this.content, "DataInfo/Date", false).GetComponent<UILabel>();
  481. this.labelUsedCount = UTY.GetChildObject(this.content, "DataInfo/UsedCount/Number", false).GetComponent<UILabel>();
  482. this.labelManName = UTY.GetChildObject(this.content, "DataInfo/Man/Name", false).GetComponent<UILabel>();
  483. this.labelMaidCount = UTY.GetChildObject(this.content, "DataInfo/NumberOfEmployees/Number", false).GetComponent<UILabel>();
  484. this.inputComment = UTY.GetChildObject(this.content, "Comment/InputField", false).GetComponent<UIInput>();
  485. this.selectCursor = UTY.GetChildObject(this.content, "SelectCursor", false);
  486. this.newLabel = UTY.GetChildObject(base.gameObject, "NewLabel", false);
  487. this.newGameLabel = UTY.GetChildObject(base.gameObject, "NewGameLabel", false);
  488. }
  489. public void Init(int index)
  490. {
  491. if (this.isInit)
  492. {
  493. Debug.Log("セーブデータ項目{0}番目は既に Init() 関数を呼ばれています。\n処理を行いません。");
  494. return;
  495. }
  496. this.index = index;
  497. this.isInit = true;
  498. }
  499. public UILabel labelDate;
  500. public UILabel labelUsedCount;
  501. public UILabel labelManName;
  502. public UILabel labelMaidCount;
  503. public UIInput inputComment;
  504. public GameObject selectCursor;
  505. public GameObject newLabel;
  506. public GameObject newGameLabel;
  507. public GameObject content;
  508. private bool isInit;
  509. }
  510. }
  511. }