123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- 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<Component>(base.gameObject, "TitleGroup/TitleSave", "SavePanel");
- UIButton childObject = this.m_CacheSaveObjects.GetChildObject<UIButton>(base.gameObject, "DisplayButtonGroup/DisplayLoad");
- this.m_CacheSaveObjects.AddCache<UIButton>("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<Component>(base.gameObject, "TitleGroup/TitleLoad", "LoadPanel");
- UIButton childObject = this.m_CacheLoadObjects.GetChildObject<UIButton>(base.gameObject, "DisplayButtonGroup/DisplaySave");
- this.m_CacheLoadObjects.AddCache<UIButton>("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<UIButton>(base.gameObject, "Cancel", "Cancel");
- EventDelegate.Add(uibutton.onClick, new EventDelegate.Callback(this.OnClickCancel));
- this.m_PageButtonDic = new Dictionary<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton>();
- this.m_InactiveColor = (this.m_ActiveColor = this.m_ListPageButtons.tempItem.GetComponent<UIWidget>().color);
- this.m_ActiveColor.a = 1f;
- this.m_ListPageButtons.Show<UIButton>(5, delegate(int index, UIButton button)
- {
- int num = index + 1;
- UISprite component = button.GetComponent<UISprite>();
- 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<KasizukiSaveAndLoadCtrl.DataUnitComp>();
- this.m_ListDataUnits.Show<KasizukiSaveAndLoadCtrl.DataUnitComp>(16, delegate(int index, KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
- {
- dataUnit.Init(index);
- UIButton component = dataUnit.GetComponent<UIButton>();
- 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<string, UnityEngine.Object> 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<string, UnityEngine.Object> 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<string, UnityEngine.Object> 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<string, UnityEngine.Object> 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<KasizukiSaveAndLoadCtrl.DataUnitComp>();
- this.SetDataUnitAtHeader(component, saveDataHeader);
- UIButton component2 = component.GetComponent<UIButton>();
- 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<KasizukiSaveAndLoadCtrl.DataUnitComp>();
- this.SetDataUnitAtHeader(component3, saveDataHeader2);
- UIButton component4 = component3.GetComponent<UIButton>();
- 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;
- 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<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> 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);
- }
- else
- {
- msg = string.Format("{0}番にデータを保存しますか?", saveSlot);
- }
- this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg, delegate
- {
- this.CloseDialog();
- this.Save(saveSlot);
- });
- }
- }
- else
- {
- string msg = string.Format("{0}番のデータをロードしますか?", saveSlot);
- 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("データを削除します。\n本当に宜しいですか。", new object[0]);
- this.OpenDialog(SystemDialog.TYPE.OK_CANCEL, msg2, delegate
- {
- this.CloseDialog();
- this.Delete(saveSlot);
- });
- }
- private void OnClickNewGameUnit(KasizukiSaveAndLoadCtrl.DataUnitComp dataUnit)
- {
- if (dataUnit.index != 0)
- {
- return;
- }
- string msg = "ここに新規顧客情報を登録します。";
- this.OpenDialog(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 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.OpenDialog(SystemDialog.TYPE.OK, "データを保存しました。", 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.OpenDialog(SystemDialog.TYPE.OK, "データを削除しました。", 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_OVERWRITE = "{0}番に上書きして保存します。\n宜しいですか?";
- private const string DIALOG_MESSAGE_TO_LOAD = "{0}番のデータをロードしますか?";
- private const string DIALOG_MESSAGE_TO_DELETE = "データを削除します。\n本当に宜しいですか。";
- private const string DIALOG_MESSAGE_RESULT_SAVE = "データを保存しました。";
- private const string DIALOG_MESSAGE_RESULT_DELETE = "データを削除しました。";
- private const string DIALOG_MESSAGE_TO_NEW_GAME = "ここに新規顧客情報を登録します。";
- 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<SaveAndLoadMgr.PageNo, SaveAndLoadCtrl.PageButton> 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<UILabel>();
- this.labelUsedCount = UTY.GetChildObject(this.content, "DataInfo/UsedCount/Number", false).GetComponent<UILabel>();
- this.labelManName = UTY.GetChildObject(this.content, "DataInfo/Man/Name", false).GetComponent<UILabel>();
- this.labelMaidCount = UTY.GetChildObject(this.content, "DataInfo/NumberOfEmployees/Number", false).GetComponent<UILabel>();
- this.inputComment = UTY.GetChildObject(this.content, "Comment/InputField", false).GetComponent<UIInput>();
- 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;
- }
- }
- }
|