using System; using System.Collections; using System.Collections.Generic; using com.workman.cm3d2.button; using UnityEngine; public class SaveAndLoadCtrl : BaseCreateViewerCtrl { public bool Kasiduki { set { this.kasiduki = value; } } public bool IsTitleScene { get { return this.isTitleScene; } } public bool GetIsLoading() { return this.isLoading; } public void Init(SaveAndLoadMgr saveAndLoadMgr, GameObject goSaveAndLoadPanel) { this.m_mgr = saveAndLoadMgr; this.m_goPanel = goSaveAndLoadPanel; } private void InitViewer() { this.m_goTitleSave = UTY.GetChildObject(this.m_goPanel, "TitleGroup/TitleSave", false); this.m_goTitleLoad = UTY.GetChildObject(this.m_goPanel, "TitleGroup/TitleLoad", false); this.m_listAllButton = new List(); this.m_goDisplaySave = UTY.GetChildObject(this.m_goPanel, "DisplayButtonGroup/DisplaySave", false); this.m_goDisplayLoad = UTY.GetChildObject(this.m_goPanel, "DisplayButtonGroup/DisplayLoad", false); BoxCollider component3; ButtonEnable item; if (this.isTitleScene) { this.m_goDisplaySave.SetActive(false); this.m_goDisplayLoad.SetActive(false); } else { UIButton component = this.m_goDisplaySave.GetComponent(); EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.m_mgr.OpenSavePanel)); UIButton component2 = this.m_goDisplayLoad.GetComponent(); EventDelegate.Add(component2.onClick, new EventDelegate.Callback(this.m_mgr.OpenLoadPanel)); component3 = this.m_goDisplaySave.GetComponent(); item = new ButtonEnable(component, component3); this.m_listAllButton.Add(item); component3 = this.m_goDisplayLoad.GetComponent(); item = new ButtonEnable(component2, component3); this.m_listAllButton.Add(item); } this.m_dicPageButton = new Dictionary(); bool flag = false; IEnumerator enumerator = Enum.GetValues(typeof(SaveAndLoadMgr.PageNo)).GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; SaveAndLoadMgr.PageNo pageNo = (SaveAndLoadMgr.PageNo)obj; GameObject childObject = UTY.GetChildObject(this.m_goPanel, "PageGroup/PageButtonParent/" + pageNo.ToString(), false); UIButton component4 = childObject.GetComponent(); EventDelegate.Add(component4.onClick, new EventDelegate.Callback(this.m_mgr.ClickPageNo)); GameObject childObject2 = UTY.GetChildObject(childObject, "SelectCursor", false); childObject2.SetActive(false); SaveAndLoadCtrl.PageButton pageButton = new SaveAndLoadCtrl.PageButton(); pageButton.pageNo = pageNo; pageButton.btnPageNo = component4; pageButton.selectCursor = childObject2; this.m_dicPageButton.Add(pageButton.pageNo, pageButton); component3 = childObject.GetComponent(); item = new ButtonEnable(component4, component3); this.m_listAllButton.Add(item); if (!flag) { this.activeColor = new Color(component4.defaultColor.r, component4.defaultColor.g, component4.defaultColor.b, 1f); this.inActiveColor = component4.defaultColor; flag = true; } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } GameObject childObject3 = UTY.GetChildObject(this.m_goPanel, "Cancel", false); UIButton component5 = childObject3.GetComponent(); EventDelegate.Add(component5.onClick, new EventDelegate.Callback(this.m_mgr.CloseSaveAndLoadPanel)); component3 = childObject3.GetComponent(); item = new ButtonEnable(component5, component3); this.m_listAllButton.Add(item); this.m_unitPrefabPath = "SceneDaily/SaveAndLoad/Prefab/DataUnit"; this.m_goEmptyPrefab = (Resources.Load("SceneDaily/SaveAndLoad/Prefab/EmptyUnit") as GameObject); this.m_goUnitParent = UTY.GetChildObject(this.m_goPanel, "DataViewer/DataUnitParent", false); } public void CreateSaveAndLoadDataViewer(Dictionary dicData, SaveAndLoadMgr.ViewType viewType) { if (!this.m_bInit) { this.InitViewer(); this.m_bInit = true; } this.m_dicLoadData = dicData; this.m_selectedViewType = viewType; base.CreateViewerWhenDataNotExist(dicData); bool saveUI = false; if (viewType != SaveAndLoadMgr.ViewType.Save) { if (viewType == SaveAndLoadMgr.ViewType.Load) { saveUI = false; this.isLoading = false; } } else { saveUI = true; } this.SetSaveUI(saveUI); this.SetPageButtonActive(this.m_mgr.GetCurrentPageNo()); } private void SetSaveUI(bool active) { this.m_goTitleSave.SetActive(active); this.m_goTitleLoad.SetActive(!active); if (!this.isTitleScene) { this.m_goDisplaySave.SetActive(!active); this.m_goDisplayLoad.SetActive(active); } } protected override void SetDataForViewer() { foreach (KeyValuePair keyValuePair in this.m_dicLoadData) { string key = keyValuePair.Key; SaveAndLoadCtrl.LoadDataUnit value = keyValuePair.Value; GameObject gameObject; if (value.isEmpty) { gameObject = UnityEngine.Object.Instantiate(this.m_goEmptyPrefab); } else { gameObject = UnityEngine.Object.Instantiate(this.m_goUnitPrefab); } gameObject.name = key; base.SetTransformInfo(gameObject); GameObject childObject = UTY.GetChildObject(gameObject, "Content/SelectCursor", false); childObject.SetActive(false); value.selectCursor = childObject; UIButton component = gameObject.GetComponent(); value.btnLoadData = component; EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.m_mgr.ClickSaveOrLoadData)); if (value.isEmpty) { if (this.m_selectedViewType == SaveAndLoadMgr.ViewType.Load) { component.enabled = false; gameObject.GetComponent().enabled = false; } } else { GameObject childObject2 = UTY.GetChildObject(gameObject, "NewLabel", false); if (value.isLatest) { childObject2.SetActive(true); } UILabel component2 = UTY.GetChildObject(gameObject, "Content/DataInfo/Date", false).GetComponent(); component2.text = value.createAt; UILabel component3 = UTY.GetChildObject(gameObject, "Content/DataInfo/LapsedDays/Number", false).GetComponent(); component3.text = value.lapsedDays.ToString(); UILabel component4 = UTY.GetChildObject(gameObject, "Content/DataInfo/Manager/Name", false).GetComponent(); component4.text = value.managerName; UILabel component5 = UTY.GetChildObject(gameObject, "Content/DataInfo/NumberOfEmployees/Number", false).GetComponent(); component5.text = value.numberOfEmployees.ToString(); GameObject childObject3 = UTY.GetChildObject(gameObject, "Content/Comment/InputField", false); UIEventTrigger uieventTrigger = childObject3.AddComponent(); EventDelegate.Add(uieventTrigger.onClick, new EventDelegate.Callback(this.m_mgr.ClickComment)); UIInput component6 = childObject3.GetComponent(); component6.value = value.comment; component6.name = "Comment_" + key; value.uiComment = component6; BoxCollider component7 = gameObject.GetComponent(); ButtonEnable item = new ButtonEnable(component, component7); this.m_listAllButton.Add(item); EventDelegate.Add(component6.onChange, new EventDelegate.Callback(this.m_mgr.OnChangeComment)); } } } private void SetPageButtonActive(SaveAndLoadMgr.PageNo pageNo) { SaveAndLoadCtrl.PageButton pageButton = null; if (this.m_dicPageButton.TryGetValue(pageNo, out pageButton)) { foreach (KeyValuePair keyValuePair in this.m_dicPageButton) { SaveAndLoadCtrl.PageButton value = keyValuePair.Value; if (value.pageNo == pageNo) { value.selectCursor.SetActive(true); value.btnPageNo.defaultColor = this.activeColor; } else { value.selectCursor.SetActive(false); value.btnPageNo.defaultColor = this.inActiveColor; } } } } public void SaveComment(string commentName, string comment) { if (this.MAX_COMMENT_LENGTH < comment.Length) { comment = comment.Substring(0, this.MAX_COMMENT_LENGTH); } string key = this.ToButtonName(commentName); SaveAndLoadCtrl.LoadDataUnit loadDataUnitByKey = this.GetLoadDataUnitByKey(key); GameMain.Instance.SaveDataCommentSave(loadDataUnitByKey.serialNo, comment); } private string ToButtonName(string commentName) { return commentName.Replace("Comment_", string.Empty); } public void SaveAndLoad(SaveAndLoadMgr.ViewType currentView, string buttonName) { string f_strMsg = string.Empty; SystemDialog.OnClick f_dgOk = null; SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null; if (!this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit)) { Debug.LogError(string.Format("不適切なデータがクリックされました。クリックされたデータ名={0}", buttonName)); } if (currentView != SaveAndLoadMgr.ViewType.Save) { if (currentView == SaveAndLoadMgr.ViewType.Load) { if (loadDataUnit.isEmpty) { return; } this.m_loadDataNo = buttonName; if (this.kasiduki) { f_strMsg = "このエンパイアクラブでゲストモードを開始しますか?"; f_dgOk = new SystemDialog.OnClick(this.LoadDataOnKasizuli); } else { f_strMsg = "データをロードしますか?"; f_dgOk = new SystemDialog.OnClick(this.LoadData); } } } else { if (loadDataUnit.isEmpty) { f_strMsg = "データを保存しますか?"; } else { f_strMsg = "上書きして保存しますが宜しいですか?"; } this.m_saveDataNo = buttonName; f_dgOk = new SystemDialog.OnClick(this.SaveData); } GameMain.Instance.SysDlg.Show(f_strMsg, SystemDialog.TYPE.OK_CANCEL, f_dgOk, new SystemDialog.OnClick(this.CloseDialog)); } public void SetSaveOrLoadDataActive(string buttonName) { SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null; if (this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit)) { foreach (KeyValuePair keyValuePair in this.m_dicLoadData) { string key = keyValuePair.Key; SaveAndLoadCtrl.LoadDataUnit value = keyValuePair.Value; if (key == buttonName) { value.selectCursor.SetActive(true); if (value.isEmpty) { value.btnLoadData.defaultColor = this.activeColor; } } else { value.selectCursor.SetActive(false); if (value.isEmpty) { value.btnLoadData.defaultColor = this.inActiveColor; } } } } else { Debug.LogError(string.Format("不適切なデータがクリックされました。クリックされたデータ名={0}", buttonName)); } } private void SaveData() { SaveAndLoadCtrl.LoadDataUnit loadDataUnit = this.m_dicLoadData[this.m_saveDataNo]; string f_strComment = string.Empty; if (!loadDataUnit.isEmpty) { f_strComment = loadDataUnit.uiComment.value; } GameMain.Instance.Serialize(loadDataUnit.serialNo, f_strComment); this.m_mgr.PageUpper(); GameMain.Instance.SysDlg.Show("データが保存されました。", SystemDialog.TYPE.OK, new SystemDialog.OnClick(this.CloseDialog), null); this.m_saveDataNo = string.Empty; } public void LoadData() { this.SetAllButtonEnable(false); GameMain.Instance.SysDlg.Close(); int serialNoByKey = this.GetSerialNoByKey(this.m_loadDataNo); this.isLoading = true; this.m_loadDataNo = string.Empty; this.m_mgr.ClosePanelAfterAction(new Func(this.GameStart), serialNoByKey); DanceSelect.ChallengeDay = 0; } private bool GameStart(int loadDataNo) { bool result = GameMain.Instance.Deserialize(loadDataNo, false); GameMain.Instance.CharacterMgr.status.SetFlag("傅きモード", (int)Convert.ToInt16(this.kasiduki)); GameMain.Instance.ScriptMgr.adv_kag.Exec(); return result; } private void LoadDataOnKasizuli() { GameMain.Instance.SysDlg.Close(); int serialNoByKey = this.GetSerialNoByKey(this.m_loadDataNo); this.isLoading = true; this.m_loadDataNo = string.Empty; this.m_mgr.ClosePanelAfterAction(delegate(int dataNo) { bool result = GameMain.Instance.Deserialize(dataNo, false); this.m_mgr.OpenLoadPanelKasizukiLocal(); return result; }, serialNoByKey); } public void CloseReset() { this.m_saveDataNo = (this.m_loadDataNo = string.Empty); this.SetAllButtonEnable(true); this.isLoading = false; UICamera.InputEnable = true; } private SaveAndLoadCtrl.LoadDataUnit GetLoadDataUnitByKey(string key) { SaveAndLoadCtrl.LoadDataUnit result = null; if (this.m_dicLoadData.TryGetValue(key, out result)) { return result; } Debug.LogError(string.Format("不適切なキーが指定されました。指定されたキー={0}", key)); return result; } private int GetSerialNoByKey(string key) { return this.GetLoadDataUnitByKey(key).serialNo; } private void CloseDialog() { this.m_mgr.SetCurrentActiveData(string.Empty); GameMain.Instance.SysDlg.Close(); } public void SetAllButtonEnable(bool enabled) { foreach (ButtonEnable buttonEnable in this.m_listAllButton) { buttonEnable.SetEnable(enabled); } } public bool ExistData(string buttonName) { SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null; if (this.m_dicLoadData.TryGetValue(buttonName, out loadDataUnit)) { return !loadDataUnit.isEmpty; } Debug.LogError(string.Format("不適切なボタンが右クリックされました。クリックされたボタン名={0}", buttonName)); return false; } public void DeleteSaveOrLoadData(string btnName) { this.SetSaveOrLoadDataActive(btnName); SaveAndLoadCtrl.LoadDataUnit loadDataUnit = null; if (this.m_dicLoadData.TryGetValue(btnName, out loadDataUnit)) { this.m_deleteSerialNo = loadDataUnit.serialNo; } GameMain.Instance.SysDlg.Show("データを削除しますが宜しいですか。", SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.DeleteData), new SystemDialog.OnClick(this.CloseDialog)); } private void DeleteData() { GameMain.Instance.DeleteSerializeData(this.m_deleteSerialNo); this.CloseDialog(); this.m_mgr.PageUpper(); } public void OnDisablePanel() { if (this.m_goUnitParent != null) { base.DelChildGameObject(this.m_goUnitParent); } } [SerializeField] private bool isTitleScene; [SerializeField] private bool kasiduki; private SaveAndLoadMgr m_mgr; private GameObject m_goPanel; private GameObject m_goTitleSave; private GameObject m_goTitleLoad; private GameObject m_goDisplaySave; private GameObject m_goDisplayLoad; private GameObject m_goEmptyPrefab; private Dictionary m_dicPageButton; private Dictionary m_dicLoadData; private List m_listAllButton; private bool isLoading; private const string DATA_UNIT_PARENT_PATH = "DataViewer/DataUnitParent"; private const string DATA_UNIT_PREFAB_PATH = "SceneDaily/SaveAndLoad/Prefab/DataUnit"; private const string EMPTY_UNIT_PREFAB_PATH = "SceneDaily/SaveAndLoad/Prefab/EmptyUnit"; private const string PAGE_BUTTON_PARENT_PATH = "PageGroup/PageButtonParent/"; private const string SYSTEM_UI_ROOT_PATH = "__GameMain__/SystemUI Root"; private const string DIALOG_MESSAGE_TO_SAVE_NORMAL = "データを保存しますか?"; private const string DIALOG_MESSAGE_TO_SAVE_OVERWRITE = "上書きして保存しますが宜しいですか?"; private const string DIALOG_MESSAGE_TO_LOAD = "データをロードしますか?"; private const string DIALOG_MESSAGE_TO_LOAD_KASIDUKI = "このエンパイアクラブでゲストモードを開始しますか?"; private const string DIALOG_MESSAGE_RESULT_SAVE = "データが保存されました。"; private const string DIALOG_MESSAGE_RESULT_LOAD = "データをロードしました。"; private const string DIALOG_MESSAGE_TO_DELETE = "データを削除しますが宜しいですか。"; private const string PREFIX_COMMENT = "Comment_"; private Color activeColor; private Color inActiveColor; private SaveAndLoadMgr.ViewType m_selectedViewType; private bool m_bInit; private string m_saveDataNo; private string m_loadDataNo; private int m_deleteSerialNo; private int MAX_COMMENT_LENGTH = 25; public class PageButton { public SaveAndLoadMgr.PageNo pageNo; public UIButton btnPageNo; public GameObject selectCursor; } public class LoadDataUnit { public int pageNo; public int serialNo; public bool isLatest; public string createAt; public int lapsedDays; public string managerName; public int numberOfEmployees; public string comment; public bool isEmpty; public int nVer; public GameObject selectCursor; public UIButton btnLoadData; public UIInput uiComment; } }