149 lines
4.8 KiB
C#
149 lines
4.8 KiB
C#
|
using System;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.SceneManagement;
|
|||
|
|
|||
|
class MultiDialogueDataManager : SceneBaseDataManager<MultiDialogueData>
|
|||
|
{
|
|||
|
protected override string OBJECT_FOLDER_NAME { get { return "MultiDialogue"; } }
|
|||
|
protected override string OBJECT_LIST_NAME { get { return "MultiDialogueList"; } }
|
|||
|
|
|||
|
public override void Awake()
|
|||
|
{
|
|||
|
if (Instance == null)
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Destroy(gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// ZMIANA KONCEPCJI
|
|||
|
// ZMIAST TRZYMAC SUROWE OBIEKTY TYM RAZEM ZAPISUJMY modele Datai updatujmy obiket w NPC Managerze
|
|||
|
public override void Start()
|
|||
|
{
|
|||
|
Debug.Log("Start MultiDialogueData manager");
|
|||
|
|
|||
|
|
|||
|
DynamicDataList = new MultiDialogueDataListManager();
|
|||
|
|
|||
|
DataLoader = new MultiDialogueDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME);
|
|||
|
|
|||
|
|
|||
|
base.Start();
|
|||
|
}
|
|||
|
|
|||
|
// TODO - save ChestPrefabAsset (we need to save coords...) but in manager handle Chest data..
|
|||
|
//
|
|||
|
protected override void AfterStart()
|
|||
|
{
|
|||
|
if (OnMapAppearanceMethod.GameStatus == GameStatus.NewGame)
|
|||
|
{
|
|||
|
if (OnMapAppearanceMethod.Gateway != OnMapAppearanceMethodEnum.NewGame)
|
|||
|
UseDynamicSettings(); // if there is nothing saved we will use UseDefaultSettings
|
|||
|
else
|
|||
|
UseDefaultSettings();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
UseDynamicSettings();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected SceneBaseDataManager<MultiDialogueData> GetObjectType()
|
|||
|
{
|
|||
|
return GameObject.FindObjectOfType<MultiDialogueDataManager>();
|
|||
|
}
|
|||
|
|
|||
|
protected SceneBaseDataManager<MultiDialogueData> CreateInstance(ref GameObject managerGameObject)
|
|||
|
{
|
|||
|
return managerGameObject.AddComponent<MultiDialogueDataManager>();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
protected override void UseDefaultSettings()
|
|||
|
{
|
|||
|
DynamicDataList.SetList(new List<MultiDialogueData>());
|
|||
|
UiManager.SetList(new List<MultiDialogueData>());
|
|||
|
// we dont need to convert anything
|
|||
|
// Instead of build elements on scene we collect shops distracted on scene from npc's
|
|||
|
}
|
|||
|
|
|||
|
protected override void UseDynamicSettings()
|
|||
|
{
|
|||
|
// when chest detect player in near arrea and player press "c"
|
|||
|
// open panel -> chest controller handle Open panel in Scene Chest Manager passing info about what Chest Palyer want to open
|
|||
|
// Manager Build panel and pass info about chest content
|
|||
|
|
|||
|
LoadDynamicData();
|
|||
|
|
|||
|
// VERy VERY provisional SOLUTION
|
|||
|
if (DynamicDataList.GetList().Count == 0)
|
|||
|
{
|
|||
|
UseDefaultSettings();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
UiManager.SetList(DynamicDataList.GetList());
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void RegisterDialogue(MultiDialogue newDialogue)
|
|||
|
{
|
|||
|
if (DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any())
|
|||
|
Debug.LogError("In MultiDialgoue Manager there is register this dialogue already");
|
|||
|
else
|
|||
|
{
|
|||
|
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
|
|||
|
|
|||
|
DynamicDataList.AddElementToList(multiDialogueData);
|
|||
|
|
|||
|
UiManager.SetList(DynamicDataList.GetList());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// update proggress in dialogue - BUT FUNCTION BELOW SYNCH THIS ALREADY righhr???
|
|||
|
public void UpdateDialogue(MultiDialogue newDialogue)
|
|||
|
{
|
|||
|
Debug.Log("Update multi-dialogue ion manager list");
|
|||
|
if (DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any())
|
|||
|
Debug.LogError("In MultiDialgoue Manager there is register this dialogue already");
|
|||
|
else
|
|||
|
{
|
|||
|
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
|
|||
|
|
|||
|
DynamicDataList.AddElementToList(multiDialogueData);
|
|||
|
|
|||
|
UiManager.SetList(DynamicDataList.GetList());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public MultiDialogueData GetDialogue(MultiDialogue newDialogue)
|
|||
|
{
|
|||
|
return DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).First();
|
|||
|
}
|
|||
|
|
|||
|
public override bool SaveDynamicData()
|
|||
|
{
|
|||
|
// TODO
|
|||
|
// how to get list
|
|||
|
// 1. List in UI manager should be synchronized with list in this manager
|
|||
|
foreach (MultiDialogueData multiDialogue in UiManager.GetList())
|
|||
|
{
|
|||
|
DynamicDataList.GetList().Where(el => el.SpeakerName == multiDialogue.SpeakerName).ToList().ForEach(el => el = multiDialogue);
|
|||
|
}
|
|||
|
|
|||
|
//DynamicDataList.SetList(tmp);
|
|||
|
|
|||
|
// approach:
|
|||
|
// 1. get from outside, update local list && us it
|
|||
|
// 2. Handle list synchronized all the time & pass local list
|
|||
|
return SaveData(DynamicDataList?.GetList(), SceneElementTypeEnum.Dynamic);
|
|||
|
}
|
|||
|
}
|