SaveAndLoadCtrl.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using com.workman.cm3d2.button;
  5. using UnityEngine;
  6. public class SaveAndLoadCtrl : BaseCreateViewerCtrl
  7. {
  8. public bool Kasiduki
  9. {
  10. set
  11. {
  12. this.kasiduki = value;
  13. }
  14. }
  15. public bool IsTitleScene
  16. {
  17. get
  18. {
  19. return this.isTitleScene;
  20. }
  21. }
  22. public bool GetIsLoading()
  23. {
  24. return this.isLoading;
  25. }
  26. public void Init(SaveAndLoadMgr saveAndLoadMgr, GameObject goSaveAndLoadPanel)
  27. {
  28. this.m_mgr = saveAndLoadMgr;
  29. this.m_goPanel = goSaveAndLoadPanel;
  30. }
  31. private void InitViewer()
  32. {
  33. this.m_goTitleSave = UTY.GetChildObject(this.m_goPanel, "TitleGroup/TitleSave", false);
  34. this.m_goTitleLoad = UTY.GetChildObject(this.m_goPanel, "TitleGroup/TitleLoad", false);
  35. this.m_listAllButton = new List<ButtonEnable>();
  36. this.m_goDisplaySave = UTY.GetChildObject(this.m_goPanel, "DisplayButtonGroup/DisplaySave", false);
  37. this.m_goDisplayLoad = UTY.GetChildObject(this.m_goPanel, "DisplayButtonGroup/DisplayLoad", false);
  38. BoxCollider component3;
  39. ButtonEnable item;
  40. if (this.isTitleScene)
  41. {
  42. this.m_goDisplaySave.SetActive(false);
  43. this.m_goDisplayLoad.SetActive(false);
  44. }
  45. else
  46. {
  47. UIButton component = this.m_goDisplaySave.GetComponent<UIButton>();
  48. EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.m_mgr.OpenSavePanel));
  49. UIButton component2 = this.m_goDisplayLoad.GetComponent<UIButton>();
  50. EventDelegate.Add(component2.onClick, new EventDelegate.Callback(this.m_mgr.OpenLoadPanel));
  51. component3 = this.m_goDisplaySave.GetComponent<BoxCollider>();
  52. item = new ButtonEnable(component, component3);
  53. this.m_listAllButton.Add(item);
  54. component3 = this.m_goDisplayLoad.GetComponent<BoxCollider>();
  55. item = new ButtonEnable(component2, component3);
  56. this.m_listAllButton.Add(item);
  57. }
  58. this.m_dicPageButton = new Dictionary<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton>();
  59. bool flag = false;
  60. IEnumerator enumerator = Enum.GetValues(typeof(SaveAndLoadMgr.PageNo)).GetEnumerator();
  61. try
  62. {
  63. while (enumerator.MoveNext())
  64. {
  65. object obj = enumerator.Current;
  66. SaveAndLoadMgr.PageNo pageNo = (SaveAndLoadMgr.PageNo)obj;
  67. GameObject childObject = UTY.GetChildObject(this.m_goPanel, "PageGroup/PageButtonParent/" + pageNo.ToString(), false);
  68. UIButton component4 = childObject.GetComponent<UIButton>();
  69. EventDelegate.Add(component4.onClick, new EventDelegate.Callback(this.m_mgr.ClickPageNo));
  70. GameObject childObject2 = UTY.GetChildObject(childObject, "SelectCursor", false);
  71. childObject2.SetActive(false);
  72. SaveAndLoadCtrl.PageButton pageButton = new SaveAndLoadCtrl.PageButton();
  73. pageButton.pageNo = pageNo;
  74. pageButton.btnPageNo = component4;
  75. pageButton.selectCursor = childObject2;
  76. this.m_dicPageButton.Add(pageButton.pageNo, pageButton);
  77. component3 = childObject.GetComponent<BoxCollider>();
  78. item = new ButtonEnable(component4, component3);
  79. this.m_listAllButton.Add(item);
  80. if (!flag)
  81. {
  82. this.activeColor = new Color(component4.defaultColor.r, component4.defaultColor.g, component4.defaultColor.b, 1f);
  83. this.inActiveColor = component4.defaultColor;
  84. flag = true;
  85. }
  86. }
  87. }
  88. finally
  89. {
  90. IDisposable disposable;
  91. if ((disposable = (enumerator as IDisposable)) != null)
  92. {
  93. disposable.Dispose();
  94. }
  95. }
  96. GameObject childObject3 = UTY.GetChildObject(this.m_goPanel, "Cancel", false);
  97. UIButton component5 = childObject3.GetComponent<UIButton>();
  98. EventDelegate.Add(component5.onClick, new EventDelegate.Callback(this.m_mgr.CloseSaveAndLoadPanel));
  99. component3 = childObject3.GetComponent<BoxCollider>();
  100. item = new ButtonEnable(component5, component3);
  101. this.m_listAllButton.Add(item);
  102. this.m_unitPrefabPath = "SceneDaily/SaveAndLoad/Prefab/DataUnit";
  103. this.m_goEmptyPrefab = (Resources.Load("SceneDaily/SaveAndLoad/Prefab/EmptyUnit") as GameObject);
  104. this.m_goUnitParent = UTY.GetChildObject(this.m_goPanel, "DataViewer/DataUnitParent", false);
  105. }
  106. public void CreateSaveAndLoadDataViewer(Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData, SaveAndLoadMgr.ViewType viewType)
  107. {
  108. if (!this.m_bInit)
  109. {
  110. this.InitViewer();
  111. this.m_bInit = true;
  112. }
  113. this.m_dicLoadData = dicData;
  114. this.m_selectedViewType = viewType;
  115. base.CreateViewerWhenDataNotExist<string, SaveAndLoadCtrl.LoadDataUnit>(dicData);
  116. bool saveUI = false;
  117. if (viewType != SaveAndLoadMgr.ViewType.Save)
  118. {
  119. if (viewType == SaveAndLoadMgr.ViewType.Load)
  120. {
  121. saveUI = false;
  122. this.isLoading = false;
  123. }
  124. }
  125. else
  126. {
  127. saveUI = true;
  128. }
  129. this.SetSaveUI(saveUI);
  130. this.SetPageButtonActive(this.m_mgr.GetCurrentPageNo());
  131. }
  132. private void SetSaveUI(bool active)
  133. {
  134. this.m_goTitleSave.SetActive(active);
  135. this.m_goTitleLoad.SetActive(!active);
  136. if (!this.isTitleScene)
  137. {
  138. this.m_goDisplaySave.SetActive(!active);
  139. this.m_goDisplayLoad.SetActive(active);
  140. }
  141. }
  142. protected override void SetDataForViewer()
  143. {
  144. foreach (KeyValuePair<string, SaveAndLoadCtrl.LoadDataUnit> keyValuePair in this.m_dicLoadData)
  145. {
  146. string key = keyValuePair.Key;
  147. SaveAndLoadCtrl.LoadDataUnit value = keyValuePair.Value;
  148. GameObject gameObject;
  149. if (value.isEmpty)
  150. {
  151. gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_goEmptyPrefab);
  152. }
  153. else
  154. {
  155. gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_goUnitPrefab);
  156. }
  157. gameObject.name = key;
  158. base.SetTransformInfo(gameObject);
  159. GameObject childObject = UTY.GetChildObject(gameObject, "Content/SelectCursor", false);
  160. childObject.SetActive(false);
  161. value.selectCursor = childObject;
  162. UIButton component = gameObject.GetComponent<UIButton>();
  163. value.btnLoadData = component;
  164. EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.m_mgr.ClickSaveOrLoadData));
  165. if (value.isEmpty)
  166. {
  167. if (this.m_selectedViewType == SaveAndLoadMgr.ViewType.Load)
  168. {
  169. component.enabled = false;
  170. gameObject.GetComponent<BoxCollider>().enabled = false;
  171. }
  172. }
  173. else
  174. {
  175. GameObject childObject2 = UTY.GetChildObject(gameObject, "NewLabel", false);
  176. if (value.isLatest)
  177. {
  178. childObject2.SetActive(true);
  179. }
  180. UILabel component2 = UTY.GetChildObject(gameObject, "Content/DataInfo/Date", false).GetComponent<UILabel>();
  181. component2.text = value.createAt;
  182. UILabel component3 = UTY.GetChildObject(gameObject, "Content/DataInfo/LapsedDays/Number", false).GetComponent<UILabel>();
  183. component3.text = value.lapsedDays.ToString();
  184. UILabel component4 = UTY.GetChildObject(gameObject, "Content/DataInfo/Manager/Name", false).GetComponent<UILabel>();
  185. component4.text = value.managerName;
  186. UILabel component5 = UTY.GetChildObject(gameObject, "Content/DataInfo/NumberOfEmployees/Number", false).GetComponent<UILabel>();
  187. component5.text = value.numberOfEmployees.ToString();
  188. GameObject childObject3 = UTY.GetChildObject(gameObject, "Content/Comment/InputField", false);
  189. UIEventTrigger uieventTrigger = childObject3.AddComponent<UIEventTrigger>();
  190. EventDelegate.Add(uieventTrigger.onClick, new EventDelegate.Callback(this.m_mgr.ClickComment));
  191. UIInput component6 = childObject3.GetComponent<UIInput>();
  192. component6.value = value.comment;
  193. component6.name = "Comment_" + key;
  194. value.uiComment = component6;
  195. BoxCollider component7 = gameObject.GetComponent<BoxCollider>();
  196. ButtonEnable item = new ButtonEnable(component, component7);
  197. this.m_listAllButton.Add(item);
  198. EventDelegate.Add(component6.onChange, new EventDelegate.Callback(this.m_mgr.OnChangeComment));
  199. }
  200. }
  201. }
  202. private void SetPageButtonActive(SaveAndLoadMgr.PageNo pageNo)
  203. {
  204. SaveAndLoadCtrl.PageButton pageButton = null;
  205. if (this.m_dicPageButton.TryGetValue(pageNo, out pageButton))
  206. {
  207. foreach (KeyValuePair<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> keyValuePair in this.m_dicPageButton)
  208. {
  209. SaveAndLoadCtrl.PageButton value = keyValuePair.Value;
  210. if (value.pageNo == pageNo)
  211. {
  212. value.selectCursor.SetActive(true);
  213. value.btnPageNo.defaultColor = this.activeColor;
  214. }
  215. else
  216. {
  217. value.selectCursor.SetActive(false);
  218. value.btnPageNo.defaultColor = this.inActiveColor;
  219. }
  220. }
  221. }
  222. }
  223. public void SaveComment(string commentName, string comment)
  224. {
  225. if (this.MAX_COMMENT_LENGTH < comment.Length)
  226. {
  227. comment = comment.Substring(0, this.MAX_COMMENT_LENGTH);
  228. }
  229. string key = this.ToButtonName(commentName);
  230. SaveAndLoadCtrl.LoadDataUnit loadDataUnitByKey = this.GetLoadDataUnitByKey(key);
  231. GameMain.Instance.SaveDataCommentSave(loadDataUnitByKey.serialNo, comment);
  232. }
  233. private string ToButtonName(string commentName)
  234. {
  235. return commentName.Replace("Comment_", string.Empty);
  236. }
  237. public void SaveAndLoad(SaveAndLoadMgr.ViewType currentView, string buttonName)
  238. {
  239. string f_strMsg = string.Empty;
  240. SystemDialog.OnClick f_dgOk = null;
  241. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  242. if (!this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit))
  243. {
  244. Debug.LogError(string.Format("不適切なデータがクリックされました。クリックされたデータ名={0}", buttonName));
  245. }
  246. if (currentView != SaveAndLoadMgr.ViewType.Save)
  247. {
  248. if (currentView == SaveAndLoadMgr.ViewType.Load)
  249. {
  250. if (loadDataUnit.isEmpty)
  251. {
  252. return;
  253. }
  254. this.m_loadDataNo = buttonName;
  255. if (this.kasiduki)
  256. {
  257. f_strMsg = "このエンパイアクラブでゲストモードを開始しますか?";
  258. f_dgOk = new SystemDialog.OnClick(this.LoadDataOnKasizuli);
  259. }
  260. else
  261. {
  262. f_strMsg = "データをロードしますか?";
  263. f_dgOk = new SystemDialog.OnClick(this.LoadData);
  264. }
  265. }
  266. }
  267. else
  268. {
  269. if (loadDataUnit.isEmpty)
  270. {
  271. f_strMsg = "データを保存しますか?";
  272. }
  273. else
  274. {
  275. f_strMsg = "上書きして保存しますが宜しいですか?";
  276. }
  277. this.m_saveDataNo = buttonName;
  278. f_dgOk = new SystemDialog.OnClick(this.SaveData);
  279. }
  280. GameMain.Instance.SysDlg.Show(f_strMsg, SystemDialog.TYPE.OK_CANCEL, f_dgOk, new SystemDialog.OnClick(this.CloseDialog));
  281. }
  282. public void SetSaveOrLoadDataActive(string buttonName)
  283. {
  284. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  285. if (this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit))
  286. {
  287. foreach (KeyValuePair<string, SaveAndLoadCtrl.LoadDataUnit> keyValuePair in this.m_dicLoadData)
  288. {
  289. string key = keyValuePair.Key;
  290. SaveAndLoadCtrl.LoadDataUnit value = keyValuePair.Value;
  291. if (key == buttonName)
  292. {
  293. value.selectCursor.SetActive(true);
  294. if (value.isEmpty)
  295. {
  296. value.btnLoadData.defaultColor = this.activeColor;
  297. }
  298. }
  299. else
  300. {
  301. value.selectCursor.SetActive(false);
  302. if (value.isEmpty)
  303. {
  304. value.btnLoadData.defaultColor = this.inActiveColor;
  305. }
  306. }
  307. }
  308. }
  309. else
  310. {
  311. Debug.LogError(string.Format("不適切なデータがクリックされました。クリックされたデータ名={0}", buttonName));
  312. }
  313. }
  314. private void SaveData()
  315. {
  316. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = this.m_dicLoadData[this.m_saveDataNo];
  317. string f_strComment = string.Empty;
  318. if (!loadDataUnit.isEmpty)
  319. {
  320. f_strComment = loadDataUnit.uiComment.value;
  321. }
  322. GameMain.Instance.Serialize(loadDataUnit.serialNo, f_strComment);
  323. this.m_mgr.PageUpper();
  324. GameMain.Instance.SysDlg.Show("データが保存されました。", SystemDialog.TYPE.OK, new SystemDialog.OnClick(this.CloseDialog), null);
  325. this.m_saveDataNo = string.Empty;
  326. }
  327. public void LoadData()
  328. {
  329. this.SetAllButtonEnable(false);
  330. GameMain.Instance.SysDlg.Close();
  331. int serialNoByKey = this.GetSerialNoByKey(this.m_loadDataNo);
  332. this.isLoading = true;
  333. this.m_loadDataNo = string.Empty;
  334. this.m_mgr.ClosePanelAfterAction<int>(new Func<int, bool>(this.GameStart), serialNoByKey);
  335. DanceSelect.ChallengeDay = 0;
  336. }
  337. private bool GameStart(int loadDataNo)
  338. {
  339. bool result = GameMain.Instance.Deserialize(loadDataNo, false);
  340. GameMain.Instance.CharacterMgr.status.SetFlag("傅きモード", (int)Convert.ToInt16(this.kasiduki));
  341. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  342. return result;
  343. }
  344. private void LoadDataOnKasizuli()
  345. {
  346. GameMain.Instance.SysDlg.Close();
  347. int serialNoByKey = this.GetSerialNoByKey(this.m_loadDataNo);
  348. this.isLoading = true;
  349. this.m_loadDataNo = string.Empty;
  350. this.m_mgr.ClosePanelAfterAction<int>(delegate(int dataNo)
  351. {
  352. bool result = GameMain.Instance.Deserialize(dataNo, false);
  353. this.m_mgr.OpenLoadPanelKasizukiLocal();
  354. return result;
  355. }, serialNoByKey);
  356. }
  357. public void CloseReset()
  358. {
  359. this.m_saveDataNo = (this.m_loadDataNo = string.Empty);
  360. this.SetAllButtonEnable(true);
  361. this.isLoading = false;
  362. UICamera.InputEnable = true;
  363. }
  364. private SaveAndLoadCtrl.LoadDataUnit GetLoadDataUnitByKey(string key)
  365. {
  366. SaveAndLoadCtrl.LoadDataUnit result = null;
  367. if (this.m_dicLoadData.TryGetValue(key, out result))
  368. {
  369. return result;
  370. }
  371. Debug.LogError(string.Format("不適切なキーが指定されました。指定されたキー={0}", key));
  372. return result;
  373. }
  374. private int GetSerialNoByKey(string key)
  375. {
  376. return this.GetLoadDataUnitByKey(key).serialNo;
  377. }
  378. private void CloseDialog()
  379. {
  380. this.m_mgr.SetCurrentActiveData(string.Empty);
  381. GameMain.Instance.SysDlg.Close();
  382. }
  383. public void SetAllButtonEnable(bool enabled)
  384. {
  385. foreach (ButtonEnable buttonEnable in this.m_listAllButton)
  386. {
  387. buttonEnable.SetEnable(enabled);
  388. }
  389. }
  390. public bool ExistData(string buttonName)
  391. {
  392. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  393. if (this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit))
  394. {
  395. return !loadDataUnit.isEmpty;
  396. }
  397. Debug.LogError(string.Format("不適切なボタンが右クリックされました。クリックされたボタン名={0}", buttonName));
  398. return false;
  399. }
  400. public void DeleteSaveOrLoadData(string btnName)
  401. {
  402. this.SetSaveOrLoadDataActive(btnName);
  403. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  404. if (this.m_dicLoadData.TryGetValue(btnName, out loadDataUnit))
  405. {
  406. this.m_deleteSerialNo = loadDataUnit.serialNo;
  407. }
  408. GameMain.Instance.SysDlg.Show("データを削除しますが宜しいですか。", SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.DeleteData), new SystemDialog.OnClick(this.CloseDialog));
  409. }
  410. private void DeleteData()
  411. {
  412. GameMain.Instance.DeleteSerializeData(this.m_deleteSerialNo);
  413. this.CloseDialog();
  414. this.m_mgr.PageUpper();
  415. }
  416. public void OnDisablePanel()
  417. {
  418. if (this.m_goUnitParent != null)
  419. {
  420. base.DelChildGameObject(this.m_goUnitParent);
  421. }
  422. }
  423. [SerializeField]
  424. private bool isTitleScene;
  425. [SerializeField]
  426. private bool kasiduki;
  427. private SaveAndLoadMgr m_mgr;
  428. private GameObject m_goPanel;
  429. private GameObject m_goTitleSave;
  430. private GameObject m_goTitleLoad;
  431. private GameObject m_goDisplaySave;
  432. private GameObject m_goDisplayLoad;
  433. private GameObject m_goEmptyPrefab;
  434. private Dictionary<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> m_dicPageButton;
  435. private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> m_dicLoadData;
  436. private List<ButtonEnable> m_listAllButton;
  437. private bool isLoading;
  438. private const string DATA_UNIT_PARENT_PATH = "DataViewer/DataUnitParent";
  439. private const string DATA_UNIT_PREFAB_PATH = "SceneDaily/SaveAndLoad/Prefab/DataUnit";
  440. private const string EMPTY_UNIT_PREFAB_PATH = "SceneDaily/SaveAndLoad/Prefab/EmptyUnit";
  441. private const string PAGE_BUTTON_PARENT_PATH = "PageGroup/PageButtonParent/";
  442. private const string SYSTEM_UI_ROOT_PATH = "__GameMain__/SystemUI Root";
  443. private const string DIALOG_MESSAGE_TO_SAVE_NORMAL = "データを保存しますか?";
  444. private const string DIALOG_MESSAGE_TO_SAVE_OVERWRITE = "上書きして保存しますが宜しいですか?";
  445. private const string DIALOG_MESSAGE_TO_LOAD = "データをロードしますか?";
  446. private const string DIALOG_MESSAGE_TO_LOAD_KASIDUKI = "このエンパイアクラブでゲストモードを開始しますか?";
  447. private const string DIALOG_MESSAGE_RESULT_SAVE = "データが保存されました。";
  448. private const string DIALOG_MESSAGE_RESULT_LOAD = "データをロードしました。";
  449. private const string DIALOG_MESSAGE_TO_DELETE = "データを削除しますが宜しいですか。";
  450. private const string PREFIX_COMMENT = "Comment_";
  451. private Color activeColor;
  452. private Color inActiveColor;
  453. private SaveAndLoadMgr.ViewType m_selectedViewType;
  454. private bool m_bInit;
  455. private string m_saveDataNo;
  456. private string m_loadDataNo;
  457. private int m_deleteSerialNo;
  458. private int MAX_COMMENT_LENGTH = 25;
  459. public class PageButton
  460. {
  461. public SaveAndLoadMgr.PageNo pageNo;
  462. public UIButton btnPageNo;
  463. public GameObject selectCursor;
  464. }
  465. public class LoadDataUnit
  466. {
  467. public int pageNo;
  468. public int serialNo;
  469. public bool isLatest;
  470. public string createAt;
  471. public int lapsedDays;
  472. public string managerName;
  473. public int numberOfEmployees;
  474. public string comment;
  475. public bool isEmpty;
  476. public int nVer;
  477. public GameObject selectCursor;
  478. public UIButton btnLoadData;
  479. public UIInput uiComment;
  480. }
  481. }