MaidTransferLoadMain.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. [RequireComponent(typeof(UIPanel))]
  6. public class MaidTransferLoadMain : WfFadeBehaviour
  7. {
  8. public void Awake()
  9. {
  10. this.pageTabPanel = UTY.GetChildObject(base.gameObject, "SaveAndLoadPanel/PageGroup/PageButtonParent", false).GetComponent<UIWFTabPanel>();
  11. UIWFTabButton[] componentsInChildren = this.pageTabPanel.GetComponentsInChildren<UIWFTabButton>(true);
  12. foreach (UIWFTabButton uiwftabButton in componentsInChildren)
  13. {
  14. EventDelegate.Add(uiwftabButton.onSelect, new EventDelegate.Callback(this.OnSelectPage));
  15. }
  16. GameObject childObject = UTY.GetChildObject(base.gameObject, "SaveAndLoadPanel/DataViewer/DataUnitParent", false);
  17. UIButton[] componentsInChildren2 = childObject.GetComponentsInChildren<UIButton>(true);
  18. foreach (UIButton uibutton in componentsInChildren2)
  19. {
  20. EventDelegate.Add(uibutton.onClick, new EventDelegate.Callback(this.OnSelectDataUnit));
  21. }
  22. this.saveDataPath = GameMain.Instance.CMSystem.CM3D2Path;
  23. if (!string.IsNullOrEmpty(this.saveDataPath))
  24. {
  25. this.saveDataPath += "\\SaveData";
  26. if (!Directory.Exists(this.saveDataPath))
  27. {
  28. this.saveDataPath = string.Empty;
  29. }
  30. }
  31. long num = 0L;
  32. if (!string.IsNullOrEmpty(this.saveDataPath))
  33. {
  34. string[] files = Directory.GetFiles(this.saveDataPath, "*.save");
  35. foreach (string text in files)
  36. {
  37. int saveFileNameToSaveNo = this.GetSaveFileNameToSaveNo(text);
  38. if (saveFileNameToSaveNo >= 0)
  39. {
  40. GameMain.SerializeHeader saveDataHeader = this.GetSaveDataHeader(text);
  41. this.saveDataHeaderDic.Add(saveFileNameToSaveNo, new KeyValuePair<string, GameMain.SerializeHeader>(text, saveDataHeader));
  42. long num2 = 0L;
  43. if (long.TryParse(saveDataHeader.strSaveTime, out num2) && num < num2)
  44. {
  45. num = num2;
  46. this.newSaveDataNo = saveFileNameToSaveNo;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. public void Start()
  53. {
  54. this.panel = base.GetComponent<UIPanel>();
  55. this.panel.alpha = 0f;
  56. }
  57. public void Call(Action onEventFinishCall)
  58. {
  59. if (this.newSaveDataNo < 0 || 100 <= this.newSaveDataNo)
  60. {
  61. this.pageTabPanel.Select(this.pageTabPanel.transform.GetChild(0).GetComponentInChildren<UIWFTabButton>());
  62. }
  63. else
  64. {
  65. int index = this.newSaveDataNo / 10;
  66. this.pageTabPanel.Select(this.pageTabPanel.transform.GetChild(index).GetComponentInChildren<UIWFTabButton>());
  67. }
  68. this.onEventFinishCall = onEventFinishCall;
  69. WfFadeJob.Create(this, this.mainUi, this.fadeTime, iTween.EaseType.easeOutSine);
  70. }
  71. public void Close()
  72. {
  73. WfFadeJob.Create(this.mainUi, this, this.fadeTime, iTween.EaseType.easeOutSine);
  74. }
  75. public override void OnUpdateFadeIn(float val)
  76. {
  77. this.panel.alpha = val;
  78. }
  79. public override void OnUpdateFadeOut(float val)
  80. {
  81. this.panel.alpha = val;
  82. }
  83. public override void OnCompleteFadeIn()
  84. {
  85. base.OnCompleteFadeIn();
  86. if (this.onEventFinishCall != null)
  87. {
  88. this.onEventFinishCall();
  89. }
  90. }
  91. private void OnSelectPage()
  92. {
  93. if (!UIWFSelectButton.current.isSelected)
  94. {
  95. return;
  96. }
  97. string[] array = UIWFSelectButton.current.transform.parent.name.Split(new char[]
  98. {
  99. '_'
  100. });
  101. NDebug.Assert(array.Length == 2, "ページボタンの名前が不正です");
  102. int num = 0;
  103. if (!int.TryParse(array[1], out num))
  104. {
  105. NDebug.Assert("ページボタンのint.Parseに失敗しました", false);
  106. }
  107. this.UpdateDataUnit(num - 1);
  108. }
  109. private void UpdateDataUnit(int selectedPage)
  110. {
  111. this.selectedPage = selectedPage;
  112. Transform transform = UTY.GetChildObject(base.gameObject, "SaveAndLoadPanel/DataViewer/DataUnitParent", false).transform;
  113. for (int i = 0; i < transform.childCount; i++)
  114. {
  115. int num = selectedPage * 10 + i;
  116. GameObject gameObject = transform.GetChild(i).gameObject;
  117. if (!this.saveDataHeaderDic.ContainsKey(num))
  118. {
  119. UTY.GetChildObject(gameObject, "NewLabel", false).SetActive(false);
  120. UTY.GetChildObject(gameObject, "Content", false).SetActive(false);
  121. gameObject.GetComponent<UIButton>().isEnabled = false;
  122. }
  123. else
  124. {
  125. GameMain.SerializeHeader value = this.saveDataHeaderDic[num].Value;
  126. UTY.GetChildObject(gameObject, "NewLabel", false).SetActive(this.newSaveDataNo == num);
  127. GameObject childObject = UTY.GetChildObject(gameObject, "Content", false);
  128. childObject.SetActive(true);
  129. gameObject.GetComponent<UIButton>().isEnabled = true;
  130. UILabel component = UTY.GetChildObject(childObject, "DataInfo/Date", false).GetComponent<UILabel>();
  131. component.text = value.strSaveTime;
  132. UILabel component2 = UTY.GetChildObject(childObject, "DataInfo/LapsedDays/Number", false).GetComponent<UILabel>();
  133. component2.text = value.nGameDay.ToString();
  134. UILabel component3 = UTY.GetChildObject(childObject, "DataInfo/Manager/Name", false).GetComponent<UILabel>();
  135. component3.text = value.strPlayerName;
  136. UILabel component4 = UTY.GetChildObject(childObject, "DataInfo/NumberOfEmployees/Number", false).GetComponent<UILabel>();
  137. component4.text = value.nMaidNum.ToString();
  138. GameObject childObject2 = UTY.GetChildObject(childObject, "Comment/InputField/Label", false);
  139. UILabel component5 = childObject2.GetComponent<UILabel>();
  140. component5.text = value.strComment;
  141. }
  142. }
  143. }
  144. private void OnSelectDataUnit()
  145. {
  146. if (this.selectedPage < 0)
  147. {
  148. return;
  149. }
  150. string[] array = UIButton.current.transform.name.Split(new char[]
  151. {
  152. '_'
  153. });
  154. NDebug.Assert(array.Length == 2, "データユニットの名前が不正です");
  155. int num = 0;
  156. if (!int.TryParse(array[1], out num))
  157. {
  158. NDebug.Assert("データユニットのint.Parseに失敗しました", false);
  159. }
  160. num--;
  161. if (!this.saveDataHeaderDic.ContainsKey(this.selectedPage * 10 + num))
  162. {
  163. return;
  164. }
  165. UIButton.current.SetState(UIButtonColor.State.Normal, true);
  166. string key = this.saveDataHeaderDic[this.selectedPage * 10 + num].Key;
  167. this.transferMain.Call(key);
  168. }
  169. private int GetSaveFileNameToSaveNo(string filePath)
  170. {
  171. string text = Path.GetFileName(filePath);
  172. if (Path.GetExtension(text) != Path.GetExtension(".save"))
  173. {
  174. return -1;
  175. }
  176. text = Path.GetFileNameWithoutExtension(text);
  177. if (text.Length != 11)
  178. {
  179. return -1;
  180. }
  181. int num = text.IndexOf("SaveData");
  182. if (num != 0)
  183. {
  184. return -1;
  185. }
  186. int result = -1;
  187. if (!int.TryParse(text.Substring(8), out result))
  188. {
  189. return -1;
  190. }
  191. return result;
  192. }
  193. private GameMain.SerializeHeader GetSaveDataHeader(string filePath)
  194. {
  195. GameMain.SerializeHeader serializeHeader = null;
  196. if (File.Exists(filePath))
  197. {
  198. using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
  199. {
  200. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  201. {
  202. string a = binaryReader.ReadString();
  203. NDebug.Assert(a == "CM3D2_SAVE", "セーブデータファイルのヘッダーが不正です。");
  204. int nVer = binaryReader.ReadInt32();
  205. serializeHeader = new GameMain.SerializeHeader();
  206. serializeHeader.strSaveTime = binaryReader.ReadString();
  207. serializeHeader.nGameDay = binaryReader.ReadInt32();
  208. serializeHeader.strPlayerName = binaryReader.ReadString();
  209. serializeHeader.nMaidNum = binaryReader.ReadInt32();
  210. serializeHeader.strComment = binaryReader.ReadString();
  211. serializeHeader.nVer = nVer;
  212. serializeHeader.lHeaderSize = binaryReader.BaseStream.Position;
  213. }
  214. }
  215. }
  216. return serializeHeader;
  217. }
  218. [SerializeField]
  219. public float fadeTime;
  220. [SerializeField]
  221. private WfFadeBehaviour mainUi;
  222. [SerializeField]
  223. private MaidTransferMain transferMain;
  224. private UIPanel panel;
  225. private string saveDataPath = string.Empty;
  226. private UIWFTabPanel pageTabPanel;
  227. private Action onEventFinishCall;
  228. private Dictionary<int, KeyValuePair<string, GameMain.SerializeHeader>> saveDataHeaderDic = new Dictionary<int, KeyValuePair<string, GameMain.SerializeHeader>>();
  229. private int newSaveDataNo = -1;
  230. private int selectedPage = -1;
  231. }