123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class SaveAndLoadMgr : BaseCreatePanel
- {
- public SaveAndLoadMgr.PageNo GetCurrentPageNo()
- {
- return this.currentPageNo;
- }
- public Action CallbackAfterFadeOut { get; set; }
- public void SetCurrentActiveData(string activeData)
- {
- this.currentActiveData = activeData;
- }
- public Action OnOpenLoadPanelKasizukiLocal { get; set; }
- public override void Init()
- {
- this.m_goPanel = base.GetPanel("SaveAndLoadPanel");
- this.m_ctrl = base.GetCtrl<SaveAndLoadCtrl>();
- this.m_ctrl.Init(this, this.m_goPanel);
- this.m_goPanel.SetActive(false);
- this.currentView = SaveAndLoadMgr.ViewType.None;
- this.currentPageNo = SaveAndLoadMgr.PageNo.Page_1;
- }
- public void OpenSavePanel()
- {
- Debug.Log("セーブをオープンしました。");
- base.BaseOpenPanel(SaveAndLoadMgr.ViewType.Save.ToString());
- }
- public void OpenLoadPanel()
- {
- this.m_ctrl.Kasiduki = false;
- Debug.Log("ロードをオープンしました。");
- base.BaseOpenPanel(SaveAndLoadMgr.ViewType.Load.ToString());
- }
- public void OpenLoadPanelKasiduki()
- {
- this.m_ctrl.Kasiduki = true;
- Debug.Log("ロード(カシヅキ)をオープンしました。");
- base.BaseOpenPanel(SaveAndLoadMgr.ViewType.Load.ToString());
- }
- public void OpenLoadPanelKasizukiLocal()
- {
- base.BaseOpenPanel("傅き");
- }
- protected override void OpenPanel(string openType)
- {
- if (openType == "傅き")
- {
- if (this.OnOpenLoadPanelKasizukiLocal != null)
- {
- this.OnOpenLoadPanelKasizukiLocal();
- }
- return;
- }
- SaveAndLoadMgr.ViewType viewType = (SaveAndLoadMgr.ViewType)Enum.Parse(typeof(SaveAndLoadMgr.ViewType), openType);
- if (viewType != SaveAndLoadMgr.ViewType.Save)
- {
- if (viewType == SaveAndLoadMgr.ViewType.Load)
- {
- this.DisplayLoadPanel();
- }
- }
- else
- {
- this.DisplaySavePanel();
- }
- }
- private void DisplaySavePanel()
- {
- this.CreateSaveOrLoadViewer(SaveAndLoadMgr.ViewType.Save);
- }
- private void DisplayLoadPanel()
- {
- this.CreateSaveOrLoadViewer(SaveAndLoadMgr.ViewType.Load);
- }
- private void CreateSaveOrLoadViewer(SaveAndLoadMgr.ViewType selectView)
- {
- if (this.currentView == selectView)
- {
- return;
- }
- int pageNoLatestData = this.GetPageNoLatestData();
- if (pageNoLatestData == -1)
- {
- this.currentPageNo = SaveAndLoadMgr.PageNo.Page_1;
- }
- else
- {
- this.currentPageNo = (SaveAndLoadMgr.PageNo)pageNoLatestData;
- }
- Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage((int)this.currentPageNo);
- this.m_goPanel.SetActive(true);
- this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, selectView);
- this.currentView = selectView;
- this.currentActiveData = string.Empty;
- }
- private int GetPageNoLatestData()
- {
- long num = GameMain.Instance.NewSaveDataNo();
- return (int)num / 10 + 1;
- }
- public void CloseSaveAndLoadPanel()
- {
- base.BaseClosePanel();
- this.m_ctrl.CloseReset();
- }
- public void ClosePanelAfterAction<T>(Func<T, bool> action, T param)
- {
- BasePanelMgr.isOpen = false;
- TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, 0.5f, 0f);
- EventDelegate.Set(tweenAlpha.onFinished, delegate()
- {
- if (action != null)
- {
- if (action(param))
- {
- this.fadeTargetPanel.SetActive(false);
- }
- else
- {
- this.CloseSaveAndLoadPanel();
- }
- action = null;
- }
- });
- }
- protected override void ClosePanel()
- {
- this.currentView = SaveAndLoadMgr.ViewType.None;
- this.currentPageNo = SaveAndLoadMgr.PageNo.Page_1;
- }
- public void ClickPageNo()
- {
- string name = UIButton.current.name;
- if (!base.IsValidateButton<SaveAndLoadMgr.PageNo>(name))
- {
- return;
- }
- SaveAndLoadMgr.PageNo pageNo = (SaveAndLoadMgr.PageNo)Enum.Parse(typeof(SaveAndLoadMgr.PageNo), name);
- if (pageNo == this.currentPageNo)
- {
- return;
- }
- this.currentPageNo = pageNo;
- int pageNo2 = (int)pageNo;
- Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage(pageNo2);
- this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, this.currentView);
- }
- public void PageUpper()
- {
- Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dicData = this.LoadDataByPage((int)this.currentPageNo);
- this.m_ctrl.CreateSaveAndLoadDataViewer(dicData, this.currentView);
- }
- public void ClickSaveOrLoadData()
- {
- string name = UIButton.current.name;
- if (this.currentActiveData == name)
- {
- Debug.Log("同じデータがクリックされたので処理を抜けます。");
- return;
- }
- if (UICamera.currentTouchID == -1)
- {
- this.m_ctrl.SetSaveOrLoadDataActive(name);
- if (UICamera.currentTouchID == -1)
- {
- this.currentActiveData = name;
- this.m_ctrl.SaveAndLoad(this.currentView, name);
- }
- }
- else if (UICamera.currentTouchID == -2 && !GameMain.Instance.VRMode)
- {
- Debug.Log(string.Format("{0}ボタンが右クリックされました。", name));
- if (this.m_ctrl.ExistData(name))
- {
- this.m_ctrl.DeleteSaveOrLoadData(name);
- }
- }
- }
- public void ClickComment()
- {
- Collider collider = UICamera.lastHit.collider;
- if (collider != null)
- {
- UIButton componentInParent = collider.GetComponentInParent<UIButton>();
- this.m_ctrl.SetSaveOrLoadDataActive(componentInParent.name);
- }
- }
- public void OnChangeComment()
- {
- string name = UIInput.current.name;
- string value = UIInput.current.value;
- this.m_ctrl.SaveComment(name, value);
- }
- protected override void SetFadeTargetPanel()
- {
- this.fadeTargetPanel = this.m_goPanel;
- }
- protected override void AfterFadeOut()
- {
- if (this.m_ctrl.IsTitleScene)
- {
- if (this.CallbackAfterFadeOut != null)
- {
- this.CallbackAfterFadeOut();
- }
- }
- else if (!this.m_ctrl.GetIsLoading())
- {
- DailyMgr manager = base.GetManager<DailyMgr>();
- manager.BaseOpenPanel(manager.GetCurrentDaily().ToString());
- }
- base.AfterFadeOut();
- }
- protected override void BeforeClose()
- {
- UICamera.InputEnable = false;
- }
- protected override void AfterClose()
- {
- if (!this.m_ctrl.GetIsLoading())
- {
- UICamera.InputEnable = true;
- }
- }
- private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> LoadDataByPage(int pageNo)
- {
- Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dictionary = new Dictionary<string, SaveAndLoadCtrl.LoadDataUnit>();
- int num = (pageNo - 1) * 10;
- int num2 = num + 10 - 1;
- for (int i = num; i <= num2; i++)
- {
- SaveAndLoadCtrl.LoadDataUnit loadDataUnit = new SaveAndLoadCtrl.LoadDataUnit();
- GameMain.SerializeHeader saveDataHeader = GameMain.Instance.GetSaveDataHeader(i);
- if (saveDataHeader != null)
- {
- loadDataUnit.pageNo = pageNo;
- loadDataUnit.serialNo = i;
- loadDataUnit.isLatest = GameMain.Instance.IsSaveDataNew(i);
- loadDataUnit.nVer = saveDataHeader.nVer;
- loadDataUnit.createAt = this.DateTimeParse(saveDataHeader.strSaveTime);
- loadDataUnit.lapsedDays = saveDataHeader.nGameDay;
- loadDataUnit.managerName = saveDataHeader.strPlayerName;
- loadDataUnit.numberOfEmployees = saveDataHeader.nMaidNum;
- loadDataUnit.comment = saveDataHeader.strComment;
- loadDataUnit.isEmpty = false;
- loadDataUnit.productTypeID = saveDataHeader.productTypeID;
- }
- else
- {
- loadDataUnit.pageNo = pageNo;
- loadDataUnit.serialNo = i;
- loadDataUnit.isEmpty = true;
- }
- dictionary.Add(string.Format("serialNo_{0}", i), loadDataUnit);
- }
- return dictionary;
- }
- private Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> MakeDummyData()
- {
- Dictionary<string, SaveAndLoadCtrl.LoadDataUnit> dictionary = new Dictionary<string, SaveAndLoadCtrl.LoadDataUnit>();
- int num = 0;
- int num2 = 0;
- int num3 = 0;
- int num4 = 47;
- for (int i = 0; i < num4; i++)
- {
- if (i % 10 == 0)
- {
- num++;
- num2 = 1;
- }
- int num5 = UnityEngine.Random.Range(0, 10);
- if (num5 % 3 == 0)
- {
- num2++;
- }
- else
- {
- SaveAndLoadCtrl.LoadDataUnit loadDataUnit = new SaveAndLoadCtrl.LoadDataUnit();
- loadDataUnit.pageNo = num;
- loadDataUnit.serialNo = num3;
- loadDataUnit.isLatest = false;
- loadDataUnit.createAt = DateTime.Now.ToString();
- loadDataUnit.lapsedDays = i;
- loadDataUnit.managerName = "経営者_" + i;
- loadDataUnit.numberOfEmployees = UnityEngine.Random.Range(0, 30);
- loadDataUnit.comment = string.Format("コメント_{0}、ページ={1}、シリアルNo={2}", i, loadDataUnit.pageNo, loadDataUnit.serialNo);
- dictionary.Add(string.Format("serialNo_{0}", num3), loadDataUnit);
- num2++;
- num3++;
- }
- }
- return dictionary;
- }
- private string DateTimeParse(string strDate)
- {
- string format = "yyyyMMddHHmmss";
- return DateTime.ParseExact(strDate, format, null).ToString("yyyy.MM.dd HH:mm");
- }
- private string currentActiveData;
- private SaveAndLoadMgr.PageNo currentPageNo;
- private SaveAndLoadCtrl m_ctrl;
- private SaveAndLoadMgr.ViewType currentView;
- private const SaveAndLoadMgr.PageNo PAGE_NO_WHEN_OPEN = SaveAndLoadMgr.PageNo.Page_1;
- private const string BUTTON_NAME_TEMPLATE = "serialNo_{0}";
- private const float DURATION_TO_FADE = 0.5f;
- private const int MAX_SLOT_COUNT_PER_PAGE = 10;
- private const int NOTHING_SAVE_DATA = -1;
- private const int LeftClick = -1;
- private const int RightClick = -2;
- public enum ViewType
- {
- None,
- Save,
- Load
- }
- public enum PageNo
- {
- Page_1 = 1,
- Page_2,
- Page_3,
- Page_4,
- Page_5,
- Page_6,
- Page_7,
- Page_8,
- Page_9,
- Page_10
- }
- }
|