SaveAndLoadCtrl.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. if (Product.supportMultiLanguage)
  160. {
  161. UIWFPositionStore componentInChildren = gameObject.GetComponentInChildren<UIWFPositionStore>();
  162. if (componentInChildren != null)
  163. {
  164. componentInChildren.Apply();
  165. }
  166. }
  167. GameObject childObject = UTY.GetChildObject(gameObject, "Content/SelectCursor", false);
  168. childObject.SetActive(false);
  169. value.selectCursor = childObject;
  170. UIButton component = gameObject.GetComponent<UIButton>();
  171. value.btnLoadData = component;
  172. EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.m_mgr.ClickSaveOrLoadData));
  173. if (value.isEmpty)
  174. {
  175. if (this.m_selectedViewType == SaveAndLoadMgr.ViewType.Load)
  176. {
  177. component.enabled = false;
  178. gameObject.GetComponent<BoxCollider>().enabled = false;
  179. }
  180. }
  181. else
  182. {
  183. GameObject childObject2 = UTY.GetChildObject(gameObject, "NewLabel", false);
  184. if (value.isLatest)
  185. {
  186. childObject2.SetActive(true);
  187. }
  188. UILabel component2 = UTY.GetChildObject(gameObject, "Content/DataInfo/Date", false).GetComponent<UILabel>();
  189. component2.text = value.createAt;
  190. UILabel component3 = UTY.GetChildObject(gameObject, "Content/DataInfo/LapsedDays/Number", false).GetComponent<UILabel>();
  191. component3.text = value.lapsedDays.ToString();
  192. UILabel component4 = UTY.GetChildObject(gameObject, "Content/DataInfo/Manager/Name", false).GetComponent<UILabel>();
  193. component4.text = value.managerName;
  194. UILabel component5 = UTY.GetChildObject(gameObject, "Content/DataInfo/NumberOfEmployees/Number", false).GetComponent<UILabel>();
  195. component5.text = value.numberOfEmployees.ToString();
  196. GameObject childObject3 = UTY.GetChildObject(gameObject, "Content/Comment/InputField", false);
  197. UIEventTrigger uieventTrigger = childObject3.AddComponent<UIEventTrigger>();
  198. EventDelegate.Add(uieventTrigger.onClick, new EventDelegate.Callback(this.m_mgr.ClickComment));
  199. UIInput component6 = childObject3.GetComponent<UIInput>();
  200. component6.value = value.comment;
  201. component6.name = "Comment_" + key;
  202. value.uiComment = component6;
  203. BoxCollider component7 = gameObject.GetComponent<BoxCollider>();
  204. ButtonEnable item = new ButtonEnable(component, component7);
  205. this.m_listAllButton.Add(item);
  206. EventDelegate.Add(component6.onChange, new EventDelegate.Callback(this.m_mgr.OnChangeComment));
  207. GameObject childObject4 = UTY.GetChildObject(gameObject, "NotUsePanel", false);
  208. if (childObject4 != null)
  209. {
  210. childObject4.SetActive(value.productTypeID != (int)Product.type);
  211. }
  212. }
  213. }
  214. }
  215. private void SetPageButtonActive(SaveAndLoadMgr.PageNo pageNo)
  216. {
  217. SaveAndLoadCtrl.PageButton pageButton = null;
  218. if (this.m_dicPageButton.TryGetValue(pageNo, out pageButton))
  219. {
  220. foreach (KeyValuePair<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> keyValuePair in this.m_dicPageButton)
  221. {
  222. SaveAndLoadCtrl.PageButton value = keyValuePair.Value;
  223. if (value.pageNo == pageNo)
  224. {
  225. value.selectCursor.SetActive(true);
  226. value.btnPageNo.defaultColor = this.activeColor;
  227. }
  228. else
  229. {
  230. value.selectCursor.SetActive(false);
  231. value.btnPageNo.defaultColor = this.inActiveColor;
  232. }
  233. }
  234. }
  235. }
  236. public void SaveComment(string commentName, string comment)
  237. {
  238. if (this.MAX_COMMENT_LENGTH < comment.Length)
  239. {
  240. comment = comment.Substring(0, this.MAX_COMMENT_LENGTH);
  241. }
  242. string key = this.ToButtonName(commentName);
  243. SaveAndLoadCtrl.LoadDataUnit loadDataUnitByKey = this.GetLoadDataUnitByKey(key);
  244. GameMain.Instance.SaveDataCommentSave(loadDataUnitByKey.serialNo, comment);
  245. }
  246. private string ToButtonName(string commentName)
  247. {
  248. return commentName.Replace("Comment_", string.Empty);
  249. }
  250. public void SaveAndLoad(SaveAndLoadMgr.ViewType currentView, string buttonName)
  251. {
  252. string messageTerm = string.Empty;
  253. SystemDialog.OnClick f_dgOk = null;
  254. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  255. if (!this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit))
  256. {
  257. Debug.LogError(string.Format("不適切なデータがクリックされました。クリックされたデータ名={0}", buttonName));
  258. }
  259. if (currentView != SaveAndLoadMgr.ViewType.Save)
  260. {
  261. if (currentView == SaveAndLoadMgr.ViewType.Load)
  262. {
  263. if (loadDataUnit.isEmpty)
  264. {
  265. return;
  266. }
  267. this.m_loadDataNo = buttonName;
  268. if (this.kasiduki)
  269. {
  270. messageTerm = "Dialog/このエンパイアクラブでゲストモードを開始しますか?";
  271. f_dgOk = new SystemDialog.OnClick(this.LoadDataOnKasizuli);
  272. }
  273. else
  274. {
  275. messageTerm = "Dialog/セーブロード/データをロードしますか?";
  276. f_dgOk = new SystemDialog.OnClick(this.LoadData);
  277. }
  278. }
  279. }
  280. else
  281. {
  282. if (loadDataUnit.isEmpty)
  283. {
  284. messageTerm = "Dialog/セーブロード/データを保存しますか?";
  285. }
  286. else
  287. {
  288. messageTerm = "Dialog/セーブロード/上書きして保存しますが宜しいですか?";
  289. }
  290. this.m_saveDataNo = buttonName;
  291. f_dgOk = new SystemDialog.OnClick(this.SaveData);
  292. }
  293. GameMain.Instance.SysDlg.ShowFromLanguageTerm(messageTerm, null, SystemDialog.TYPE.OK_CANCEL, f_dgOk, new SystemDialog.OnClick(this.CloseDialog));
  294. }
  295. public void SetSaveOrLoadDataActive(string buttonName)
  296. {
  297. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  298. if (this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit))
  299. {
  300. foreach (KeyValuePair<string, SaveAndLoadCtrl.LoadDataUnit> keyValuePair in this.m_dicLoadData)
  301. {
  302. string key = keyValuePair.Key;
  303. SaveAndLoadCtrl.LoadDataUnit value = keyValuePair.Value;
  304. if (key == buttonName)
  305. {
  306. value.selectCursor.SetActive(true);
  307. if (value.isEmpty)
  308. {
  309. value.btnLoadData.defaultColor = this.activeColor;
  310. }
  311. }
  312. else
  313. {
  314. value.selectCursor.SetActive(false);
  315. if (value.isEmpty)
  316. {
  317. value.btnLoadData.defaultColor = this.inActiveColor;
  318. }
  319. }
  320. }
  321. }
  322. else
  323. {
  324. Debug.LogError(string.Format("不適切なデータがクリックされました。クリックされたデータ名={0}", buttonName));
  325. }
  326. }
  327. private void SaveData()
  328. {
  329. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = this.m_dicLoadData[this.m_saveDataNo];
  330. string f_strComment = string.Empty;
  331. if (!loadDataUnit.isEmpty)
  332. {
  333. f_strComment = loadDataUnit.uiComment.value;
  334. }
  335. GameMain.Instance.Serialize(loadDataUnit.serialNo, f_strComment);
  336. this.m_mgr.PageUpper();
  337. GameMain.Instance.SysDlg.ShowFromLanguageTerm("Dialog/セーブロード/データが保存されました。", null, SystemDialog.TYPE.OK, new SystemDialog.OnClick(this.CloseDialog), null);
  338. this.m_saveDataNo = string.Empty;
  339. }
  340. public void LoadData()
  341. {
  342. this.SetAllButtonEnable(false);
  343. GameMain.Instance.SysDlg.Close();
  344. int serialNoByKey = this.GetSerialNoByKey(this.m_loadDataNo);
  345. this.isLoading = true;
  346. this.m_loadDataNo = string.Empty;
  347. this.m_mgr.ClosePanelAfterAction<int>(new Func<int, bool>(this.GameStart), serialNoByKey);
  348. DanceSelect.ChallengeDay = 0;
  349. }
  350. private bool GameStart(int loadDataNo)
  351. {
  352. bool result = GameMain.Instance.Deserialize(loadDataNo, false);
  353. GameMain.Instance.CharacterMgr.status.SetFlag("傅きモード", (int)Convert.ToInt16(this.kasiduki));
  354. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  355. return result;
  356. }
  357. private void LoadDataOnKasizuli()
  358. {
  359. GameMain.Instance.SysDlg.Close();
  360. int serialNoByKey = this.GetSerialNoByKey(this.m_loadDataNo);
  361. this.isLoading = true;
  362. this.m_loadDataNo = string.Empty;
  363. this.m_mgr.ClosePanelAfterAction<int>(delegate(int dataNo)
  364. {
  365. bool result = GameMain.Instance.Deserialize(dataNo, false);
  366. this.m_mgr.OpenLoadPanelKasizukiLocal();
  367. return result;
  368. }, serialNoByKey);
  369. }
  370. public void CloseReset()
  371. {
  372. this.m_saveDataNo = (this.m_loadDataNo = string.Empty);
  373. this.SetAllButtonEnable(true);
  374. this.isLoading = false;
  375. UICamera.InputEnable = true;
  376. }
  377. private SaveAndLoadCtrl.LoadDataUnit GetLoadDataUnitByKey(string key)
  378. {
  379. SaveAndLoadCtrl.LoadDataUnit result = null;
  380. if (this.m_dicLoadData.TryGetValue(key, out result))
  381. {
  382. return result;
  383. }
  384. Debug.LogError(string.Format("不適切なキーが指定されました。指定されたキー={0}", key));
  385. return result;
  386. }
  387. private int GetSerialNoByKey(string key)
  388. {
  389. return this.GetLoadDataUnitByKey(key).serialNo;
  390. }
  391. private void CloseDialog()
  392. {
  393. this.m_mgr.SetCurrentActiveData(string.Empty);
  394. GameMain.Instance.SysDlg.Close();
  395. }
  396. public void SetAllButtonEnable(bool enabled)
  397. {
  398. foreach (ButtonEnable buttonEnable in this.m_listAllButton)
  399. {
  400. buttonEnable.SetEnable(enabled);
  401. }
  402. }
  403. public bool ExistData(string buttonName)
  404. {
  405. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  406. if (this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit))
  407. {
  408. return !loadDataUnit.isEmpty;
  409. }
  410. Debug.LogError(string.Format("不適切なボタンが右クリックされました。クリックされたボタン名={0}", buttonName));
  411. return false;
  412. }
  413. public void DeleteSaveOrLoadData(string btnName)
  414. {
  415. this.SetSaveOrLoadDataActive(btnName);
  416. SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null;
  417. if (this.m_dicLoadData.TryGetValue(btnName, out loadDataUnit))
  418. {
  419. this.m_deleteSerialNo = loadDataUnit.serialNo;
  420. }
  421. GameMain.Instance.SysDlg.Show("データを削除しますが宜しいですか。", SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.DeleteData), new SystemDialog.OnClick(this.CloseDialog));
  422. }
  423. private void DeleteData()
  424. {
  425. GameMain.Instance.DeleteSerializeData(this.m_deleteSerialNo);
  426. this.CloseDialog();
  427. this.m_mgr.PageUpper();
  428. }
  429. public void OnDisablePanel()
  430. {
  431. if (this.m_goUnitParent != null)
  432. {
  433. base.DelChildGameObject(this.m_goUnitParent);
  434. }
  435. }
  436. [SerializeField]
  437. private bool isTitleScene;
  438. [SerializeField]
  439. private bool kasiduki;
  440. private SaveAndLoadMgr m_mgr;
  441. private GameObject m_goPanel;
  442. private GameObject m_goTitleSave;
  443. private GameObject m_goTitleLoad;
  444. private GameObject m_goDisplaySave;
  445. private GameObject m_goDisplayLoad;
  446. private GameObject m_goEmptyPrefab;
  447. private Dictionary<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> m_dicPageButton;
  448. private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> m_dicLoadData;
  449. private List<ButtonEnable> m_listAllButton;
  450. private bool isLoading;
  451. private const string DATA_UNIT_PARENT_PATH = "DataViewer/DataUnitParent";
  452. private const string DATA_UNIT_PREFAB_PATH = "SceneDaily/SaveAndLoad/Prefab/DataUnit";
  453. private const string EMPTY_UNIT_PREFAB_PATH = "SceneDaily/SaveAndLoad/Prefab/EmptyUnit";
  454. private const string PAGE_BUTTON_PARENT_PATH = "PageGroup/PageButtonParent/";
  455. private const string SYSTEM_UI_ROOT_PATH = "__GameMain__/SystemUI Root";
  456. private const string DIALOG_MESSAGE_TO_SAVE_NORMAL = "データを保存しますか?";
  457. private const string DIALOG_MESSAGE_TO_SAVE_OVERWRITE = "上書きして保存しますが宜しいですか?";
  458. private const string DIALOG_MESSAGE_TO_LOAD = "データをロードしますか?";
  459. private const string DIALOG_MESSAGE_TO_LOAD_KASIDUKI = "このエンパイアクラブでゲストモードを開始しますか?";
  460. private const string DIALOG_MESSAGE_RESULT_SAVE = "データが保存されました。";
  461. private const string DIALOG_MESSAGE_RESULT_LOAD = "データをロードしました。";
  462. private const string DIALOG_MESSAGE_TO_DELETE = "データを削除しますが宜しいですか。";
  463. private const string PREFIX_COMMENT = "Comment_";
  464. private Color activeColor;
  465. private Color inActiveColor;
  466. private SaveAndLoadMgr.ViewType m_selectedViewType;
  467. private bool m_bInit;
  468. private string m_saveDataNo;
  469. private string m_loadDataNo;
  470. private int m_deleteSerialNo;
  471. private int MAX_COMMENT_LENGTH = 25;
  472. public class PageButton
  473. {
  474. public SaveAndLoadMgr.PageNo pageNo;
  475. public UIButton btnPageNo;
  476. public GameObject selectCursor;
  477. }
  478. public class LoadDataUnit
  479. {
  480. public int pageNo;
  481. public int serialNo;
  482. public bool isLatest;
  483. public string createAt;
  484. public int lapsedDays;
  485. public string managerName;
  486. public int numberOfEmployees;
  487. public string comment;
  488. public bool isEmpty;
  489. public int nVer;
  490. public int productTypeID;
  491. public GameObject selectCursor;
  492. public UIButton btnLoadData;
  493. public UIInput uiComment;
  494. }
  495. }