using System; using System.Collections.Generic; using I2.Loc; using UnityEngine; using wf; namespace Kasizuki { public class KasizukiSaveAndLoadCtrl : NGUIWindow { private void Start() { if (this.m_IsStarted) { return; } this.SetUpSavePanel(); this.SetUpLoadPanel(); this.SetUpOtherButtons(); this.SetUpDataUnits(); this.m_NowOpenPage = SaveAndLoadMgr.PageNo.Page_1; this.m_IsStarted = true; } private void SetUpSavePanel() { this.m_CacheSaveObjects = new ObjectCacheDic(); this.m_CacheSaveObjects.CacheChildObject(base.gameObject, "TitleGroup/TitleSave", "SavePanel"); UIButton childObject = this.m_CacheSaveObjects.GetChildObject(base.gameObject, "DisplayButtonGroup/DisplayLoad"); this.m_CacheSaveObjects.AddCache("LoadButton", childObject); EventDelegate.Add(childObject.onClick, delegate() { this.Open(SaveAndLoadMgr.ViewType.Load, true); }); } private void SetUpLoadPanel() { this.m_CacheLoadObjects = new ObjectCacheDic(); this.m_CacheLoadObjects.CacheChildObject(base.gameObject, "TitleGroup/TitleLoad", "LoadPanel"); UIButton childObject = this.m_CacheLoadObjects.GetChildObject(base.gameObject, "DisplayButtonGroup/DisplaySave"); this.m_CacheLoadObjects.AddCache("SaveButton", childObject); EventDelegate.Add(childObject.onClick, delegate() { this.Open(SaveAndLoadMgr.ViewType.Save, true); }); } private void SetUpOtherButtons() { this.m_CacheButtons = new ObjectCacheDic(); UIButton uibutton = this.m_CacheButtons.CacheChildObject(base.gameObject, "Cancel", "Cancel"); EventDelegate.Add(uibutton.onClick, new EventDelegate.Callback(this.OnClickCancel)); this.m_PageButtonDic = new Dictionary(); this.m_InactiveColor = (this.m_ActiveColor = this.m_ListPageButtons.tempItem.GetComponent().color); this.m_ActiveColor.a = 1f; this.m_ListPageButtons.Show(5, delegate(int index, UIButton button) { int num = index + 1; UISprite component = button.GetComponent(); if (component != null) { component.spriteName = string.Format("{0}{1:00}", "cm3d2_save_load_page", num); } SaveAndLoadCtrl.PageButton buttonPage = new SaveAndLoadCtrl.PageButton(); buttonPage.pageNo = (SaveAndLoadMgr.PageNo)Enum.Parse(typeof(SaveAndLoadMgr.PageNo), num.ToString()); buttonPage.btnPageNo = button; buttonPage.selectCursor = button.transform.Find("SelectCursor").gameObject; this.m_PageButtonDic.Add(buttonPage.pageNo, buttonPage); EventDelegate.Add(button.onClick, delegate() { this.OnClickPageButton(buttonPage.pageNo); }); }); } private void SetUpDataUnits() { this.m_ListDataUnits.tempItem.AddComponent(); this.m_ListDataUnits.Show(16, delegate(int index, KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit) { dataUnit.Init(index); UIButton component = dataUnit.GetComponent(); if (index == 0) { EventDelegate.Add(component.onClick, delegate() { this.OnClickNewGameUnit(dataUnit); }); } else { EventDelegate.Add(component.onClick, delegate() { this.OnClickDataUnit(dataUnit); }); } UIInput inputComment = dataUnit.inputComment; EventDelegate.Add(inputComment.onChange, delegate() { this.OnChangeDataUnitComment(dataUnit); }); EventDelegate.Add(inputComment.onSubmit, new EventDelegate.Callback(inputComment.RemoveFocus)); }); } public void Open(SaveAndLoadMgr.ViewType viewType, bool isLatestPageOpen = false) { if (!this.m_IsStarted) { this.Start(); } if (isLatestPageOpen) { int pageNumberLatestData = this.GetPageNumberLatestData(); if (pageNumberLatestData > 0) { this.m_NowOpenPage = (SaveAndLoadMgr.PageNo)pageNumberLatestData; } else { this.m_NowOpenPage = SaveAndLoadMgr.PageNo.Page_1; } } if (viewType == SaveAndLoadMgr.ViewType.Save) { this.OpenSave(); } else if (viewType == SaveAndLoadMgr.ViewType.Load) { this.OpenLoad(); } else { NDebug.Assert("セーブロードのUIを開くときの種類に不正な値が入りました", false); Debug.LogError("セーブロードのUIを開くときの種類に不正な値が入りました"); } this.m_NowViewType = viewType; this.OnClickPageButton(this.m_NowOpenPage); } private void OpenSave() { foreach (KeyValuePair keyValuePair in this.m_CacheLoadObjects.Dic) { Component component = (Component)keyValuePair.Value; if (component && component.gameObject) { component.gameObject.SetActive(false); } else { Debug.LogWarningFormat("m_CacheLoadObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[] { keyValuePair.Key }); } } foreach (KeyValuePair keyValuePair2 in this.m_CacheSaveObjects.Dic) { Component component2 = (Component)keyValuePair2.Value; if (component2 && component2.gameObject) { component2.gameObject.SetActive(true); } else { Debug.LogWarningFormat("m_CacheSaveObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[] { keyValuePair2.Key }); } } } private void OpenLoad() { foreach (KeyValuePair keyValuePair in this.m_CacheSaveObjects.Dic) { Component component = (Component)keyValuePair.Value; if (component && component.gameObject) { component.gameObject.SetActive(false); } else { Debug.LogWarningFormat("m_CacheSaveObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[] { keyValuePair.Key }); } } foreach (KeyValuePair keyValuePair2 in this.m_CacheLoadObjects.Dic) { Component component2 = (Component)keyValuePair2.Value; if (component2 && component2.gameObject) { component2.gameObject.SetActive(true); } else { Debug.LogWarningFormat("m_CacheLoadObjects の中に GameObject 以外のものが入っている\nキャッシュ名:{0}", new object[] { keyValuePair2.Key }); } } } private void UpdateDataUnits() { if (this.m_NowViewType == SaveAndLoadMgr.ViewType.Save) { GameObject[] itemArray = this.m_ListDataUnits.ItemArray; for (int i = 0; i < itemArray.Length; i++) { int saveDataIndex = i + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * itemArray.Length; KasizukiManager.SaveDataHeader saveDataHeader = GameMain.Instance.KasizukiMgr.GetSaveDataHeader(saveDataIndex); KasizukiSaveAndLoadCtrl.DataUnitComp component = itemArray[i].GetComponent(); this.SetDataUnitAtHeader(component, saveDataHeader); UIButton component2 = component.GetComponent(); if (i != 0) { component2.isEnabled = true; } else { component2.isEnabled = false; } } } else if (this.m_NowViewType == SaveAndLoadMgr.ViewType.Load) { GameObject[] itemArray2 = this.m_ListDataUnits.ItemArray; for (int j = 0; j < itemArray2.Length; j++) { int saveDataIndex2 = j + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * itemArray2.Length; KasizukiManager.SaveDataHeader saveDataHeader2 = GameMain.Instance.KasizukiMgr.GetSaveDataHeader(saveDataIndex2); KasizukiSaveAndLoadCtrl.DataUnitComp component3 = itemArray2[j].GetComponent(); this.SetDataUnitAtHeader(component3, saveDataHeader2); UIButton component4 = component3.GetComponent(); if (j != 0) { component4.isEnabled = (saveDataHeader2 != null); } else { component4.isEnabled = true; } } } else { NDebug.Assert("セーブロードのUIを更新するときの種類に不正な値が入っていました", false); } } private void SetDataUnitAtHeader(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit, KasizukiManager.SaveDataHeader header) { NDebug.Assert(dataUnit != null, "セーブデータの項目にnullが指定されました"); if (header != null) { dataUnit.content.SetActive(true); dataUnit.newLabel.SetActive(GameMain.Instance.KasizukiMgr.LatestSaveDataNumber == header.saveDataNumber); int id = header.lastManType; if (GameMain.Instance.CharacterMgr.status.lockNTRPlay) { id = 10; } ManData.Data data = ManData.GetData(id); dataUnit.labelDate.text = header.GetDateTime().ToString("yyyy.MM.dd HH:mm"); dataUnit.labelMaidCount.text = KasizukiManager.GetEnableMaidList().Count.ToString(); dataUnit.labelManName.text = data.drawName; if (Product.supportMultiLanguage) { Localize localize = dataUnit.labelManName.GetComponent(); if (localize == null) { localize = dataUnit.labelManName.gameObject.AddComponent(); } Utility.SetLocalizeTerm(localize, data.drawNameTerm, false); } dataUnit.labelUsedCount.text = header.playCount.ToString(); dataUnit.inputComment.value = header.strComment; } else { dataUnit.content.SetActive(false); dataUnit.newLabel.SetActive(false); } if (dataUnit.index == 0) { dataUnit.newGameLabel.SetActive(true); } else { dataUnit.newGameLabel.SetActive(false); } } private int GetPageNumberLatestData() { int latestSaveDataNumber = GameMain.Instance.KasizukiMgr.LatestSaveDataNumber; return latestSaveDataNumber / 16 + 1; } private void OnClickPageButton(SaveAndLoadMgr.PageNo pageNo) { this.m_NowOpenPage = pageNo; this.UpdatePageButtons(pageNo); this.UpdateDataUnits(); } private void UpdatePageButtons(SaveAndLoadMgr.PageNo pageNo) { foreach (KeyValuePair keyValuePair in this.m_PageButtonDic) { if (keyValuePair.Key == pageNo) { keyValuePair.Value.btnPageNo.defaultColor = this.m_ActiveColor; keyValuePair.Value.selectCursor.SetActive(true); } else { keyValuePair.Value.btnPageNo.defaultColor = this.m_InactiveColor; keyValuePair.Value.selectCursor.SetActive(false); } } } private void OnClickDataUnit(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit) { int saveSlot = dataUnit.index + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * 16; if (UICamera.currentTouchID != -2) { SaveAndLoadMgr.ViewType nowViewType = this.m_NowViewType; if (nowViewType != SaveAndLoadMgr.ViewType.Load) { if (nowViewType != SaveAndLoadMgr.ViewType.Save) { NDebug.Assert("セーブデータを開く種類に不正な値が入っていました", false); } else { string msg; if (GameMain.Instance.KasizukiMgr.IsExistSaveData(saveSlot)) { msg = string.Format("{0}番に上書きして保存します。\n宜しいですか?", saveSlot); if (Product.supportMultiLanguage) { msg = "SceneKasizukiMainMenu/ダイアログ/上書きして保存します。宜しいですか?"; } } else { msg = string.Format("{0}番にデータを保存しますか?", saveSlot); if (Product.supportMultiLanguage) { msg = "SceneKasizukiMainMenu/ダイアログ/データを保存しますか?"; } } if (Product.supportMultiLanguage) { this.OpenDialogTerm(SystemDialog.TYPE.OK_CANCEL, msg, delegate { this.CloseDialog(); this.Save(saveSlot); }); } else { this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate { this.CloseDialog(); this.Save(saveSlot); }); } } } else { string msg = string.Format("{0}番のデータをロードしますか?", saveSlot); if (Product.supportMultiLanguage) { this.OpenDialogTerm(SystemDialog.TYPE.OK_CANCEL, "Dialog/セーブロード/データをロードしますか?", delegate { this.CloseDialog(); this.Load(saveSlot); }); } else { this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate { this.CloseDialog(); this.Load(saveSlot); }); } } return; } if (!GameMain.Instance.KasizukiMgr.IsExistSaveData(saveSlot)) { return; } string msg2 = string.Format("SceneKasizukiMainMenu/ダイアログ/データを削除します。本当に宜しいですか。", new object[0]); this.OpenDialogTerm(SystemDialog.TYPE.OK_CANCEL, msg2, delegate { this.CloseDialog(); this.Delete(saveSlot); }); } private void OnClickNewGameUnit(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit) { if (dataUnit.index != 0) { return; } string msg = "SceneKasizukiMainMenu/ダイアログ/ここに新規顧客情報を登録します。"; this.OpenDialogTerm(SystemDialog.TYPE.OK_CANCEL, msg, delegate { this.CloseDialog(); this.NewGame(); }); } private void OnChangeDataUnitComment(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit) { int saveDataIndex = dataUnit.index + (this.m_NowOpenPage - SaveAndLoadMgr.PageNo.Page_1) * 16; KasizukiManager.SaveDataHeader saveDataHeader = GameMain.Instance.KasizukiMgr.GetSaveDataHeader(saveDataIndex); saveDataHeader.strComment = dataUnit.inputComment.value; } private void OnClickCancel() { if (this.onClickCancel != null) { this.onClickCancel(); } } private void OpenDialog(SystemDialog.TYPE openType, string msg, Action onOK) { GameMain.Instance.SysDlg.Show(msg, openType, delegate { if (onOK != null) { onOK(); } }, new SystemDialog.OnClick(this.CloseDialog)); } private void OpenDialogTerm(SystemDialog.TYPE openType, string msg, Action onOK) { GameMain.Instance.SysDlg.ShowFromLanguageTerm(msg, null, openType, delegate { if (onOK != null) { onOK(); } }, new SystemDialog.OnClick(this.CloseDialog)); } private void CloseDialog() { GameMain.Instance.SysDlg.Close(); } private void Save(int saveSlot) { GameMain.Instance.KasizukiMgr.SerializeLocal(saveSlot); this.Open(SaveAndLoadMgr.ViewType.Save, false); if (this.onSave != null) { this.onSave(); } this.OpenDialogTerm(SystemDialog.TYPE.OK, "SceneKasizukiMainMenu/ダイアログ/データを保存しました。", new Action(this.CloseDialog)); } private void Load(int saveSlot) { GameMain.Instance.KasizukiMgr.DeserializeLocal(saveSlot); if (this.onLoad != null) { this.onLoad(); } } private void Delete(int saveSlot) { GameMain.Instance.KasizukiMgr.DeleteSaveDataLocal(saveSlot); this.Open(this.m_NowViewType, false); if (this.onDelete != null) { this.onDelete(); } this.OpenDialogTerm(SystemDialog.TYPE.OK, "SceneKasizukiMainMenu/ダイアログ/データを削除しました。", new Action(this.CloseDialog)); } private void NewGame() { GameMain.Instance.KasizukiMgr.CreateNewData(); if (this.onClickNewGame != null) { this.onClickNewGame(); } } private void OnDestroy() { this.onClickCancel = null; this.onClickNewGame = null; this.onLoad = null; this.onSave = null; this.onDelete = null; } public Action onClickCancel { get; set; } public Action onClickNewGame { get; set; } public Action onLoad { get; set; } public Action onSave { get; set; } public Action onDelete { get; set; } private const int PAGE_BUTTON_COUNT = 5; private const int PAGE_DATA_COUNT = 16; private const string STR_PAGE_BUTTON_NAME = "cm3d2_save_load_page"; private const string DIALOG_MESSAGE_TO_SAVE_NORMAL = "{0}番にデータを保存しますか?"; private const string DIALOG_MESSAGE_TO_SAVE_NORMAL_TERM = "SceneKasizukiMainMenu/ダイアログ/データを保存しますか?"; private const string DIALOG_MESSAGE_TO_SAVE_OVERWRITE = "{0}番に上書きして保存します。\n宜しいですか?"; private const string DIALOG_MESSAGE_TO_SAVE_OVERWRITE_TERM = "SceneKasizukiMainMenu/ダイアログ/上書きして保存します。宜しいですか?"; private const string DIALOG_MESSAGE_TO_LOAD = "{0}番のデータをロードしますか?"; private const string DIALOG_MESSAGE_TO_LOAD_TERM = "Dialog/セーブロード/データをロードしますか?"; private const string DIALOG_MESSAGE_TO_DELETE = "SceneKasizukiMainMenu/ダイアログ/データを削除します。本当に宜しいですか。"; private const string DIALOG_MESSAGE_RESULT_SAVE = "SceneKasizukiMainMenu/ダイアログ/データを保存しました。"; private const string DIALOG_MESSAGE_RESULT_DELETE = "SceneKasizukiMainMenu/ダイアログ/データを削除しました。"; private const string DIALOG_MESSAGE_TO_NEW_GAME = "SceneKasizukiMainMenu/ダイアログ/ここに新規顧客情報を登録します。"; private bool m_IsStarted; [SerializeField] private uGUIListViewer m_ListPageButtons; [SerializeField] private uGUIListViewer m_ListDataUnits; private SaveAndLoadMgr.PageNo m_NowOpenPage; private SaveAndLoadMgr.ViewType m_NowViewType; private ObjectCacheDic m_CacheSaveObjects; private ObjectCacheDic m_CacheLoadObjects; private ObjectCacheDic m_CacheButtons; private Color m_ActiveColor; private Color m_InactiveColor; private Dictionary m_PageButtonDic; public class DataUnitComp : MonoBehaviour { public int index { get; private set; } public void Awake() { this.SetUpCache(); } protected virtual void SetUpCache() { this.content = UTY.GetChildObject(base.gameObject, "Content", false); this.labelDate = UTY.GetChildObject(this.content, "DataInfo/Date", false).GetComponent(); this.labelUsedCount = UTY.GetChildObject(this.content, "DataInfo/UsedCount/Number", false).GetComponent(); this.labelManName = UTY.GetChildObject(this.content, "DataInfo/Man/Name", false).GetComponent(); this.labelMaidCount = UTY.GetChildObject(this.content, "DataInfo/NumberOfEmployees/Number", false).GetComponent(); this.inputComment = UTY.GetChildObject(this.content, "Comment/InputField", false).GetComponent(); this.selectCursor = UTY.GetChildObject(this.content, "SelectCursor", false); this.newLabel = UTY.GetChildObject(base.gameObject, "NewLabel", false); this.newGameLabel = UTY.GetChildObject(base.gameObject, "NewGameLabel", false); } public void Init(int index) { if (this.isInit) { Debug.Log("セーブデータ項目{0}番目は既に Init() 関数を呼ばれています。\n処理を行いません。"); return; } this.index = index; this.isInit = true; } public UILabel labelDate; public UILabel labelUsedCount; public UILabel labelManName; public UILabel labelMaidCount; public UIInput inputComment; public GameObject selectCursor; public GameObject newLabel; public GameObject newGameLabel; public GameObject content; private bool isInit; } } }