Dialoges - saving II

This commit is contained in:
kabix09 2023-01-02 00:05:47 +01:00
parent 82f3cf19fe
commit b72537003b
38 changed files with 14090 additions and 546 deletions

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 06201cadd951bcc4db5fccaa01783060, type: 3}
m_Name: BarryDialENG 1
m_EditorClassIdentifier:
SpeakerName:
SpeakerName: Barry
CurrentStep: 0
DialogueSteps:
- Header: Barry

View File

@ -12,19 +12,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 06201cadd951bcc4db5fccaa01783060, type: 3}
m_Name: BarryDialENG
m_EditorClassIdentifier:
SpeakerName: ThePlayer(Clone)
SpeakerName: Barry
CurrentStep: 0
DialogueSteps:
- Header: ThePlayer(Clone)
- Header: Barry
WasDisplayed: 0
ListOfSentences:
- Sentence: Hiya, do you have any spare change? Friend?
Buttons:
- ButtonName: Can't do, you drunk.
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls: []
- ButtonName: Sure thing friend.
Type: 1
ButtonActions:
@ -32,7 +27,7 @@ MonoBehaviour:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Dialogue, Assembly-CSharp
m_MethodName: GoToNextSentence
m_MethodName: FinishDialogue
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
@ -42,12 +37,17 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- ButtonName: Can't do, you drunk.
Type: 1
ButtonActions:
m_PersistentCalls:
m_Calls: []
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000, guid: 9696f03c8b09aaa47b9a8fe810886ea3, type: 2}
m_TargetAssemblyTypeName: MultiDialogue, Assembly-CSharp
m_MethodName: GoToNextDialogue
m_MethodName: GoToNextDialogueWithoutFinalAction
m_Mode: 3
m_Arguments:
m_ObjectArgument: {fileID: 0}

View File

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 45b41589283138641ba006c2243b0637, type: 3}
m_Name: BarryMultiDialENG
m_EditorClassIdentifier:
SpeakerName:
SpeakerName: Barry
CurrentDialogue: 0
Dialogues:
- Key: 0

View File

@ -12,83 +12,28 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0a3bcdd1e2dba0c4791bcb151c0df6c1, type: 3}
m_Name: TestMission
m_EditorClassIdentifier:
MissionName: Test mission I
PlayerTask:
id: 0
title:
description:
difficulty: 0
Type: 0
SpeakerName:
Status: 0
CurrentStep: 0
MissionStepsList:
- SpeakerName:
Status: 0
DialogueStep: {fileID: 0}
missionProcess:
Amount: 0
PrefabAsset: {fileID: 0}
_currentAmount: 0
NextStepCondition:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Mission, Assembly-CSharp
m_MethodName: AssignMissionProcessToStep
m_Mode: 3
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- SpeakerName:
Status: 0
DialogueStep: {fileID: 0}
missionProcess:
Amount: 0
PrefabAsset: {fileID: 0}
_currentAmount: 0
NextStepCondition:
m_PersistentCalls:
m_Calls: []
- SpeakerName:
Status: 0
DialogueStep: {fileID: 0}
missionProcess:
Amount: 0
PrefabAsset: {fileID: 0}
_currentAmount: 0
NextStepCondition:
m_PersistentCalls:
m_Calls: []
- SpeakerName:
Status: 0
DialogueStep: {fileID: 0}
missionProcess:
Amount: 0
PrefabAsset: {fileID: 0}
_currentAmount: 0
NextStepCondition:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 11400000}
m_TargetAssemblyTypeName: Mission, Assembly-CSharp
m_MethodName: GiveReward
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
missionProcess:
Amount: 0
PrefabAsset: {fileID: 0}
_currentAmount: 0
DialogueStepTemplate: {fileID: 11400000, guid: fe2810d79ff17f74eab5cf9a916167b4, type: 2}
DialogueStep: {fileID: 11400000, guid: fe2810d79ff17f74eab5cf9a916167b4, type: 2}
MissionConditions:
Key: 0
Value:
- Type: 0
RequiredElements:
- RequiredAmount: 1
RequiredObject: {fileID: 8687962458953192462, guid: ae7e7f7d0d926174a8edae16f7f4d305, type: 3}
Reward:
Items: []
Cash: 0
Items:
- {fileID: 11400000, guid: b366ff81d4bcf0d4f9633bbbf7ea17df, type: 2}
Cash: 500

View File

@ -14493,6 +14493,30 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 431601327}
m_TargetAssemblyTypeName: SaveController, Assembly-CSharp
m_MethodName: SaveAccountBalance
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 431601327}
m_TargetAssemblyTypeName: SaveController, Assembly-CSharp
m_MethodName: SaveDialogues
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &431601330
MonoBehaviour:
m_ObjectHideFlags: 0
@ -14572,6 +14596,51 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -20, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &456741522
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 456741523}
- component: {fileID: 456741524}
m_Layer: 0
m_Name: DialogueManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &456741523
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 456741522}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 857141515}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &456741524
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 456741522}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1ebc89f7b8b469d448c3787923ceb966, type: 3}
m_Name:
m_EditorClassIdentifier:
MultiDialogueDataList: []
--- !u!1 &494020752
GameObject:
m_ObjectHideFlags: 0
@ -15783,6 +15852,7 @@ Transform:
- {fileID: 425810219}
- {fileID: 132569182}
- {fileID: 1642689255}
- {fileID: 456741523}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -56537,6 +56607,30 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 2021738498}
m_TargetAssemblyTypeName: SaveController, Assembly-CSharp
m_MethodName: SaveAccountBalance
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 2021738498}
m_TargetAssemblyTypeName: SaveController, Assembly-CSharp
m_MethodName: SaveDialogues
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &2021738500
MonoBehaviour:
m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -67,6 +67,7 @@ public class AnimatedDoorBehaviour : TriggerDoor
SaveController.GetComponent<SaveController>().SaveChests();
SaveController.GetComponent<SaveController>().SaveShops();
SaveController.GetComponent<SaveController>().SaveDialogues();
// 2. Change scene
SceneManager.LoadScene(gateway.nextMapName);

View File

@ -48,6 +48,7 @@ public class DoorBehaviour : MonoBehaviour
SaveController.GetComponent<SaveController>().SaveChests();
SaveController.GetComponent<SaveController>().SaveShops();
SaveController.GetComponent<SaveController>().SaveDialogues();
// 2. Change scene
SceneManager.LoadScene(gateway.nextMapName);

View File

@ -66,8 +66,7 @@ public class DialogueController
{
if (listOfDialogue.Count == 0)
{
CloseCurrentPanel(parentDialController);
FinishDialoguStep();
FinishCurrentDialogue(parentDialController);
return false;
}
@ -83,6 +82,17 @@ public class DialogueController
return true;
}
/// <summary>
/// Function to close currently opened panel
/// And invoke final actions
/// </summary>
/// <param name="parentDialController"></param>
public void FinishCurrentDialogue(DialogueController parentDialController)
{
CloseCurrentPanel(parentDialController);
FinishDialoguStep();
}
public void CloseCurrentPanel(DialogueController parentDialController)
{
MonoBehaviour.Destroy(parentDialController.CurrentPanel);

View File

@ -25,6 +25,22 @@ public class Dialogue : ScriptableObject, IDialogue
}
#region finish action api
public void SetActionAfterEachDialogueStep(UnityEvent _endOfDialogueStepAction)
{
foreach(var dialogueStep in DialogueSteps)
{
dialogueStep.SetActionAfterDialogueStep(_endOfDialogueStepAction);
}
}
public void SetActionAfterEachDialogueStep(Action _finishDialogueAction)
{
foreach (var dialogueStep in DialogueSteps)
{
dialogueStep.SetActionAfterDialogueStep(_finishDialogueAction);
}
}
public void SetActionAfterDialogueStep(int dialogueStepNo, UnityEvent _endOfDialogueStepAction)
{
if(DialogueSteps.Count >= dialogueStepNo)
@ -32,7 +48,7 @@ public class Dialogue : ScriptableObject, IDialogue
}
public void SetActionAfterDialogueStep(int dialogueStepNo, Action _finishDialogueAction)
{
Debug.Log(dialogueStepNo);
/* Debug.Log(dialogueStepNo); */
if (DialogueSteps.Count >= dialogueStepNo)
DialogueSteps[dialogueStepNo].SetActionAfterDialogueStep(_finishDialogueAction);
}
@ -61,6 +77,60 @@ public class Dialogue : ScriptableObject, IDialogue
}
}
/// <summary>
/// Function to
/// - close panel
/// - INVOKE FINAL DIALOGUE ACTION
/// - mark as dispalyed
/// - increasing step number
///
/// Dont invoke final action!!!
/// </summary>
public void FinishDialogue()
{
foreach (var DialogueStep in DialogueSteps)
{
if (!DialogueStep.WasDisplayed)
{
// status must be changes before invoked final action - example - updating state
DialogueStep.WasDisplayed = true;
CurrentStep++;
DialogueStep.DialogueController.FinishCurrentDialogue(DialogueStep.DialogueController);
break;
}
}
}
/// <summary>
/// Function to
/// - close panel
/// - mark as dispalyed
/// - increasing step number
///
/// Dont invoke final action!!!
/// </summary>
public void CloseDialogue()
{
foreach (var DialogueStep in DialogueSteps)
{
if (!DialogueStep.WasDisplayed)
{
DialogueStep.WasDisplayed = true;
CurrentStep++;
DialogueStep.DialogueController.CloseCurrentPanel(DialogueStep.DialogueController);
break;
}
}
}
/// <summary>
/// Dialogue API
///
@ -128,7 +198,6 @@ public class Dialogue : ScriptableObject, IDialogue
public void GoToNextSentence()
{
// wskazujemy na inny krok kolejno niz nieoznaczony
Debug.Log($"Step befor next: {CurrentStep}");
// MISLEADING - last sentence mark step ad "wasDisplayed" but not increase "CurrentPanel" index
foreach (var DialogueStep in DialogueSteps)
@ -137,13 +206,12 @@ public class Dialogue : ScriptableObject, IDialogue
{
var nextSentence = DialogueStep.DialogueController.ShowNextPanel(DialogueStep.DialogueController);
Debug.Log($"GoToNextSentence - {nextSentence}");
if (!nextSentence)
{
DialogueStep.WasDisplayed = true;
CurrentStep++;
Debug.Log($"Step after: {CurrentStep}");
ShowDialogueStepPanel();
}
@ -151,8 +219,24 @@ public class Dialogue : ScriptableObject, IDialogue
}
}
}
#endregion
public void InvokeFinalAction()
{
foreach (var DialogueStep in DialogueSteps)
{
if (!DialogueStep.WasDisplayed)
{
DialogueStep.DialogueController.FinishDialoguStep();
break;
}
}
}
public void BuildDialogue()
{
BuildDialogue(DialogueSteps);
@ -163,8 +247,6 @@ public class Dialogue : ScriptableObject, IDialogue
/// </summary>
public void BuildDialogue(List<DialogueStepModel> Dialogue)
{
Debug.Log("BuildDialogue");
foreach (var dialogueStep in Dialogue)
{
dialogueStep.Header = SpeakerName;
@ -173,16 +255,10 @@ public class Dialogue : ScriptableObject, IDialogue
// synchronize current step counter
// cause ERROR - multi counting ....
/* if (dialogueStep.WasDisplayed)
CurrentStep++;*/
}
}
public void BuildDialogue()
{
BuildDialogue(DialogueSteps);
}
#region Dialogue Status API
/// <summary>
/// Function to reset rememebered dialogue status
///
@ -205,6 +281,7 @@ public class Dialogue : ScriptableObject, IDialogue
DialogueSteps[i].WasDisplayed = dialogueData.DialogueStepModelDataList[i].WasDisplayed;
}
}
#endregion
public DialogueStepModel GetCurrentStep()
{// TODO - argument out of colection :/

View File

@ -37,67 +37,18 @@ public class DialogueManager : MonoBehaviour
public bool OpenInDefaultWay = true;
public virtual void Start()
{
if(languageDetector.InstanceTemplates.Count() > 0)
{
// create and config dailogue
CreateInstanceBasedOnLanguage();
Dialogue.BuildCurrentDialogue();
/*
Debug.Log(Dialogue.DialogueStepStatus());
Debug.Log(Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == Dialogue.DialogueStepStatus().Item1)
.First()
.Value);
Debug.Log(
Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == Dialogue.DialogueStepStatus().Item1)
.First()
.Value
.DialogueSteps.Count());
Debug.Log(
Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == Dialogue.DialogueStepStatus().Item1)
.First()
.Value
.DialogueSteps
.ElementAtOrDefault(Dialogue.DialogueStepStatus().Item2)
);
Debug.Log(
Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == Dialogue.DialogueStepStatus().Item1)
.First()
.Value
.DialogueSteps
.ElementAtOrDefault(Dialogue.DialogueStepStatus().Item2)
.DialogueController
);
Debug.Log(
Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == Dialogue.DialogueStepStatus().Item1)
.First()
.Value
.DialogueSteps
.ElementAtOrDefault(Dialogue.DialogueStepStatus().Item2)
.DialogueController
.listOfDialogue.Count()
);
Debug.Log(GetCurrentDialoguePanelStatus());
*/
}
}
public void Update()
public virtual void Update()
{
if (OpenInDefaultWay && Input.GetKeyDown(keyToOpen) && OpenPanelCondition())
{
@ -115,22 +66,22 @@ public class DialogueManager : MonoBehaviour
if (collision.gameObject.tag == "Player")
{
CanBeOpened = true;
SpeakerName = collision.gameObject.name;
}
}
public virtual void OnTriggerExit2D(Collider2D collision)
{
// don't listen when component is disabled
if (ComponentEnabledCondition() || !OpenInDefaultWay)
if (ComponentEnabledCondition())
return;
if (collision.gameObject.tag == "Player")
{
CanBeOpened = false;
if (GetCurrentDialoguePanelStatus())
// Shop dont have dialoge in this script but in its own one
// TODO change - pass eachd ialogue to this script and use conditions from child class
if (Dialogue != null && GetCurrentDialoguePanelStatus())
{
Dialogue.BreakDialogueStep();
}
@ -139,13 +90,26 @@ public class DialogueManager : MonoBehaviour
public virtual void CreateInstanceBasedOnLanguage()
{
Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage());
// DONT CLONE TO HAVE CONSTANT DATA - init - deep copy - to prevent overwritting chil;dern :D
Dialogue = languageDetector.DetectInstanceBasedOnLanguage();
Dialogue.ResetDialogue();
/* var cloneDialogues = new List<IndexValuePair<int, Dialogue>>(Dialogue.Dialogues);
Dialogue.Dialogues.Clear();
foreach (var dial in cloneDialogues)
{
Dialogue.Dialogues.Add(new IndexValuePair<int, Dialogue>(dial.Key, Instantiate(dial.Value)));
}*/
Dialogue.SetSpeakerName(PlayerPrefs.GetString("name"));
// Bind setted actions
BindEndActionsToDialogues();
// Add one more action
Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterDialogueStep(dial.Key, dial.Value.ResetDialogue)); // reset dial
// Add one more action - to reset proggress
Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterEachDialogueStep(dial.Value.ResetDialogue)); // reset dial
}
#region Open Panel API
@ -153,9 +117,6 @@ public class DialogueManager : MonoBehaviour
{
if(OpenPanelCondition())
{
// Update speaker name before every opening
Dialogue.SetSpeakerName(SpeakerName);
gameObject.GetComponent<DialogueManager>().Dialogue.StartDialogue();
}
}
@ -187,17 +148,30 @@ public class DialogueManager : MonoBehaviour
/// <returns></returns>
public virtual bool GetCurrentDialoguePanelStatus()
{
Debug.Log(Dialogue);
var multiDialStatius = Dialogue.DialogueStepStatus();
Debug.Log(multiDialStatius);
// parse result (dialoge no, step no)
// dialogue not exist - finished
// dialoge exists & step no > steps sum - finished
// dialoge no exists && step no exists - not finished - check panel status
Debug.Log(Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == multiDialStatius.Item1)
.First()
.Value
.DialogueSteps);
if(!Dialogue.Dialogues.Where(dial => dial.Key == multiDialStatius.Item1).Any())
return false;
var fixedDialogue = Dialogue.Dialogues.Where(dial => dial.Key == multiDialStatius.Item1).First().Value;
if (fixedDialogue.CurrentStep >= fixedDialogue.DialogueSteps.Count())
return false;
// CONTINUE dont increment counter - only mark checkboxes
if (fixedDialogue
.DialogueSteps
.Where(step => step.WasDisplayed == false)
.ToArray()
.Count() == 0)
return false;
// when we are here we can be sure given points are correct
return Dialogue
.Dialogues
.Where(dialogue => dialogue.Key == multiDialStatius.Item1)

View File

@ -72,6 +72,13 @@ public class DialogueStepModel
EndOfDialogueStepAction.AddListener(new UnityAction(_finishDialogueAction));
}
// new function - now we should change all places closing open panels toi use its not manually close
public void ClosePanel()
{
if (DialogueController != null && DialogueController.CurrentPanel != null)
DialogueController.CloseCurrentPanel();
}
public void MarkAsDisplayed()
{
WasDisplayed = true;

View File

@ -29,27 +29,6 @@ public class MultiDialogue : ScriptableObject, IDialogue
* Jesli przechodzimy odpowiedzia do nastepnego dialogu musi to byc osttani panel w obecnym!!!
*/
public void Start()
{
/* CODE DIALOGUE DECLARATION EXAMPLE
DialogueController DialogueStep = new DialogueController();
DialogueStep.AddSentence(new DialogueModel("lorem ipsum"));
*//* di.AddSentence(new QuestionDialogueModel("tolore dolore?",
new List<Tuple<string, Action>> {
new Tuple<string, Action>("AcceptButton", CustomPanel),
new Tuple<string, Action>("RejectButton", QuestionPanel)
}));*//*
DialogueStep.SetActionAfterDialogueEnds(() => { });
DialogueStepModel dialogueStepModel = new DialogueStepModel(DialogueStep);
DialogueStepsList = new List<DialogueStepModel> { dialogueStepModel };
*/
/*if (MultiWayDialogue.Count > 0)
BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value);*/
}
public void SetSpeakerName(string speakerName)
{
SpeakerName = speakerName;
@ -101,23 +80,33 @@ public class MultiDialogue : ScriptableObject, IDialogue
/// Dialogue API
///
/// Function to prepare next dialogue to start after one more palyer interaction with actor
/// - ends current dialogue (destroy panel & invoke finish action - if setupped)
/// - ends current dialogue (destroy panel & invoke finish action!! - if setupped)
/// - set new dialogue pointer
///
/// </summary>
/// <param name="dialogueNumber"></param>
public void SetNextDialogue(int dialogueNumber)
{
Debug.Log("----------------- SetNextDialogue");
Debug.Log(dialogueNumber);
if (Dialogues.Where(el => el.Key == dialogueNumber).ToArray().Count() == 0)
return;
// 1. Make sure to close current panel after finishing current dialogue and 'finish action' will invoked if setuped
Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.FinishDialogue();
// 2. Chane index
CurrentDialogue = dialogueNumber;
}
public void SetNextDialogueWithoutFinalAction(int dialogueNumber)
{
if (Dialogues.Where(el => el.Key == dialogueNumber).ToArray().Count() == 0)
return;
// 1. Make sure to close current panel after finishing current dialogue and 'finish action' will invoked if setuped
GoToNextSentence();
Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.CloseDialogue();
// 2. Chane index
CurrentDialogue = dialogueNumber;
}
/// <summary>
@ -132,7 +121,32 @@ public class MultiDialogue : ScriptableObject, IDialogue
// 1. Prepare necessary environoment parts
SetNextDialogue(dialogueNumber);
// 2. Build new (next) dialogue & show panel
// 2. Update proggress
// Savintg one more time because saving in final action invoking by line above
// dont contain increased 'CurrentDialogue' index pointer !!!
//((MultiDialogueDataManager)MultiDialogueDataManager.Instance).RegisterDialogue(this);
// 3. Build new (next) dialogue & show panel
StartDialogue();
}
/// <summary>
/// Function like one above but
/// PREFPARED AS FINAL ACTION IN DIALOGUE WHICH IS INVOKED VIA 'Dialogue.FinishDialoge'
/// to prevent looping Final aCTION INVOKING
/// once from 'Dialogue.FinishDialoge' in button next time from 'MultiDialogue.SetNextDialogue -> FinishDialogue' ....
/// </summary>
/// <param name="dialogueNumber"></param>
public void GoToNextDialogueWithoutFinalAction(int dialogueNumber)
{
// 1. Prepare necessary environoment parts
SetNextDialogueWithoutFinalAction(dialogueNumber);
// 2. Update proggress
//((MultiDialogueDataManager)MultiDialogueDataManager.Instance).RegisterDialogue(this);
// 3. Build new (next) dialogue & show panel
StartDialogue();
}
@ -170,12 +184,23 @@ public class MultiDialogue : ScriptableObject, IDialogue
/// </summary>
public void ResetDialogue()
{
SpeakerName = "";
CurrentDialogue = 0;
Dialogues.ForEach(dial => dial.Value.SetSpeakerName(""));
Dialogues.ForEach(dial => dial.Value.CurrentStep = 0);
Dialogues.ForEach(dial => dial.Value.DialogueSteps.ForEach(step => step.WasDisplayed = false));
}
public (int, int) DialogueStepStatus()
{
Debug.Log(CurrentDialogue);
/* var currentStep = Dialogues
.Where(el => el.Key == CurrentDialogue)
.Select(el => el.Value)
.First()
.CurrentStep
;*/
var currentDialogueStepIndex = Dialogues
.Where(el => el.Key == CurrentDialogue)
.Select(el => el.Value)

View File

@ -64,7 +64,7 @@ class SaveMissionDialogueManager : SaveModelSystem<MissionDialogue>
// 1. From model to data format
public static MissionDialogueData ConvertObjectToDataModel(MissionDialogue model)
{
return new MissionDialogueData(); //model
return new MissionDialogueData(model);
}
public static List<MissionDialogueData> ConvertObjectsListToListOfDataModels(List<MissionDialogue> modelsList)

View File

@ -10,6 +10,9 @@ class MultiDialogueDataManager : SceneBaseDataManager<MultiDialogueData>
protected override string OBJECT_FOLDER_NAME { get { return "MultiDialogue"; } }
protected override string OBJECT_LIST_NAME { get { return "MultiDialogueList"; } }
[SerializeField]
public List<MultiDialogueData> MultiDialogueDataList;
public override void Awake()
{
if (Instance == null)
@ -37,8 +40,7 @@ class MultiDialogueDataManager : SceneBaseDataManager<MultiDialogueData>
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)
@ -70,7 +72,9 @@ class MultiDialogueDataManager : SceneBaseDataManager<MultiDialogueData>
protected override void UseDefaultSettings()
{
DynamicDataList.SetList(new List<MultiDialogueData>());
UiManager.SetList(new List<MultiDialogueData>());
MultiDialogueDataList = DynamicDataList.GetList();
// we dont need to convert anything
// Instead of build elements on scene we collect shops distracted on scene from npc's
}
@ -83,67 +87,59 @@ class MultiDialogueDataManager : SceneBaseDataManager<MultiDialogueData>
LoadDynamicData();
// VERy VERY provisional SOLUTION
if (DynamicDataList.GetList().Count == 0)
{
UseDefaultSettings();
return;
}
UiManager.SetList(DynamicDataList.GetList());
MultiDialogueDataList = 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");
{
// if dial is already registered - update it
UpdateDialogue(newDialogue);
}
else
{
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
DynamicDataList.AddElementToList(multiDialogueData);
UiManager.SetList(DynamicDataList.GetList());
//DynamicDataList.AddElementToList(multiDialogueData); - nie dodwaca bo modyfikacja jednej duplikuje
MultiDialogueDataList.Add(multiDialogueData);
}
}
// 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");
if (!DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).Any())
Debug.LogError($"There is no registered dialoge like {newDialogue.SpeakerName}");
else
{
Debug.Log($"Dialogue {newDialogue.SpeakerName} - updated");
var multiDialogueData = SaveMultiDialogueManager.ConvertObjectToDataModel(newDialogue);
DynamicDataList.AddElementToList(multiDialogueData);
UiManager.SetList(DynamicDataList.GetList());
MultiDialogueDataList.RemoveAll(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName);
// duplicated from registerDialogue
MultiDialogueDataList.Add(multiDialogueData);
}
}
public MultiDialogueData GetDialogue(MultiDialogue newDialogue)
public MultiDialogueData? GetDialogue(MultiDialogue newDialogue)
{
return DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).First();
return DynamicDataList.GetList().Where(dialogue => dialogue.SpeakerName == newDialogue.SpeakerName).FirstOrDefault();
}
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);
return SaveData(MultiDialogueDataList, SceneElementTypeEnum.Dynamic);
}
}

View File

@ -17,12 +17,27 @@ public class NpcDialogueManager : DialogueManager
// UPDATE DIALOGUE
// search in scene manager list
var machedDialogueData = ((MultiDialogueDataManager)MultiDialogueDataManager.Instance).GetDialogue(Dialogue);
if(Dialogue != null && machedDialogueData != null)
if (Dialogue != null)
{
var machedDialogueData = ((MultiDialogueDataManager)MultiDialogueDataManager.Instance).GetDialogue(Dialogue);
if (machedDialogueData != null)
{
Debug.Log("Multi Dialogue - updated");
UpdateDialogueState(machedDialogueData);
}
else
{
UpdateProggres();
}
}
}
public override void Update()
{
if (Input.GetKeyDown(keyToOpen) && OpenPanelCondition())
{
OpenDialoguePanel();
}
}
#region Open Panel API
@ -42,10 +57,30 @@ public class NpcDialogueManager : DialogueManager
return !gameObject.GetComponent<NpcDialogueManager>().enabled;
}
#endregion
public override void CreateInstanceBasedOnLanguage()
{
Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage());
// DONT CLONE TO HAVE CONSTANT DATA - init - deep copy - to prevent overwritting chil;dern :D
Dialogue = languageDetector.DetectInstanceBasedOnLanguage();
Dialogue.ResetDialogue();
/* var cloneDialogues = new List<IndexValuePair<int, Dialogue>>(Dialogue.Dialogues);
Dialogue.Dialogues.Clear();
foreach (var dial in cloneDialogues)
{
Dialogue.Dialogues.Add(new IndexValuePair<int, Dialogue>(dial.Key, Instantiate(dial.Value)));
}*/
Dialogue.SetSpeakerName(gameObject.GetComponent<NPC>().Name);
// Bind setted actions
BindEndActionsToDialogues();
// update dial state - sync in order to prepare to save
Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterEachDialogueStep(UpdateProggres));
}
public void UpdateDialogueState(MultiDialogueData dialogueData)
@ -64,6 +99,15 @@ public class NpcDialogueManager : DialogueManager
}
}
/// <summary>
/// Function to sync local dialogue state with remote one
/// Handled in Scene Manager
/// </summary>
public void UpdateProggres()
{
((MultiDialogueDataManager)MultiDialogueDataManager.Instance).RegisterDialogue(Dialogue);
}
#region Dialogue actions API
/// <summary>
/// Function to invoke actions declared in manager on object from scene not onto asset

View File

@ -107,7 +107,7 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
{
Debug.Log(DynamicDataList);
if (DynamicDataList.GetList().Where(shop => shop.Npc == newShop.Npc && shop.Map == SceneManager.GetActiveScene().name).Any())
Debug.LogError("In Shop Manager there is register this shop already");
Debug.LogWarning("In Shop Manager there is register this shop already");
else
{
DynamicDataList.AddElementToList(newShop);

View File

@ -154,6 +154,7 @@ public abstract class SceneBaseDataManager<T> : MonoBehaviour
// approach:
// 1. get from outside, update local list && us it
// 2. Handle list synchronized all the time & pass local list
Debug.Log(DynamicDataList.GetList());
return SaveData(DynamicDataList.GetList(), SceneElementTypeEnum.Dynamic);
}
#endregion

View File

@ -55,7 +55,7 @@ public abstract class WarehousePanelController : DraggablePanelController
{
if (slot.Value != null)
{
Debug.Log($"Slot nr: {slot.Key} with item: {slot.Value}");
/* Debug.Log($"Slot nr: {slot.Key} with item: {slot.Value}"); */
UiManager.Add(new IndexValuePair<int, EquippableItem>(slot.Key, slot.Value));
}
else

View File

@ -109,19 +109,19 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
private async void animateOpening()
{
GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("OpenIt");
/* GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("OpenIt");
GameObject.Find("Prize Chest").GetComponent<Animator>().SetTrigger("OpenIt");
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("OpenIt");
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("OpenIt");*/
}
private async void animateClosing()
{
GameObject.Find("Gold Chest").GetComponent<Animator>().ResetTrigger("OpenIt");
/* GameObject.Find("Gold Chest").GetComponent<Animator>().ResetTrigger("OpenIt");
GameObject.Find("Prize Chest").GetComponent<Animator>().ResetTrigger("OpenIt");
GameObject.Find("Wodden Chest").GetComponent<Animator>().ResetTrigger("OpenIt");
GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("CloseIt");
GameObject.Find("Prize Chest").GetComponent<Animator>().SetTrigger("CloseIt");
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("CloseIt");
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("CloseIt");*/
}
private async void resettriggers()
@ -132,12 +132,12 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
await System.Threading.Tasks.Task.Yield();
}
GameObject.Find("Gold Chest").GetComponent<Animator>().ResetTrigger("CloseIt");
/* GameObject.Find("Gold Chest").GetComponent<Animator>().ResetTrigger("CloseIt");
GameObject.Find("Prize Chest").GetComponent<Animator>().ResetTrigger("CloseIt");
GameObject.Find("Wodden Chest").GetComponent<Animator>().ResetTrigger("CloseIt");
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("reactivate");
GameObject.Find("Prize Chest").GetComponent<Animator>().SetTrigger("reactivate");
GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("reactivate");
GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("reactivate");*/
}
public virtual bool OpenPanel()

View File

@ -84,8 +84,8 @@ public abstract class UIWarehouseManager : UISlotPanelManager<IndexValuePair<int
if (!CheckIfSlotExists(keyPosition))
return; // throw new System.Exception($"Slot with number: {keyPosition} don't exist");
Debug.Log($"Remove from position: {keyPosition}");
/* Debug.Log($"Remove from position: {keyPosition}");
*/
Elements.RemoveAll(itemSlot => itemSlot.Key == keyPosition);
}

View File

@ -61,10 +61,10 @@ public class EquipmentPanelController : DraggablePanelController
base.BuildPanelContent(elements);
Debug.Log("Build content");
/* Debug.Log("Build content"); */
foreach (IndexValuePair<int, EquippableItem> element in elements)
{
Debug.Log($"key: {element.Key} - value: {element.Value}");
/* Debug.Log($"key: {element.Key} - value: {element.Value}"); */
if(element.Value != null)
ChildBoxList.Where(slot => ((EquipmentSlot)slot).type == (EquipmentPanelSlotsTypeEnum)element.Key).ToList().ForEach(slot => slot.SetItem((EquippableItem)element.Value));

View File

@ -87,10 +87,9 @@ public class InventoryPanelController : WarehousePanelController
base.BuildPanelContent(elements);
Debug.Log("Build content");
foreach (IndexValuePair<int, EquippableItem> element in elements)
{
Debug.Log($"key: {element.Key} - value: {element.Value}");
/* Debug.Log($"key: {element.Key} - value: {element.Value}"); */
ChildBoxList[element.Key].SetItem(element.Value);
}
}

View File

@ -82,7 +82,7 @@ public class ShopPanelController : WarehousePanelController
foreach (IndexValuePair<int, EquippableItem> element in elements)
{
Debug.Log($"key: {element.Key} - value: {element.Value}");
/* Debug.Log($"key: {element.Key} - value: {element.Value}"); */
ChildBoxList[element.Key].SetItem(new EquippableItem(element.Value));
}
}

View File

@ -73,7 +73,6 @@ public class ShopUIManager : UIBaseManager<Shop>
if (shop == null)
throw new Exception($"Shop {CurrentShopOwnerName} not found");
Debug.Log("Shop UI setupPanel");
ShopContentUIManager.Instance.SetList(shop.GetContent());
ShopContentUIManager.Instance.DynamicPanel = DynamicPanel;
@ -108,7 +107,6 @@ public class ShopUIManager : UIBaseManager<Shop>
private Shop FindShopInCollection(string _mapName, string _shopOwnerName)
{
Elements.ForEach(el => Debug.Log(el.Npc + " - " + el.Map));
return Elements.Find(shop => shop.Map == _mapName && shop.Npc == _shopOwnerName);
}
}

View File

@ -6,18 +6,32 @@ using System.Threading.Tasks;
using UnityEngine;
[Serializable]
public abstract class DialogueData<T> : ModelData<T, T>
public abstract class DialogueData<T> : IModelMapper<T>
{
protected override string SPRITE_LOCALIZATION => "";
protected override string MODEL_LOCALIZATION => "Dialogue/";
[SerializeField]
public int CurrentStep;
[SerializeField]
public List<DialogueStepData> DialogueStepModelDataList = new List<DialogueStepData>();
#region NotImplemented
/*
* we dont want to map it here, we will mark fields in NpcDialogfeManager after each loading and fetching dialogue
*/
public T MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();
}
public T MapDataToObject()
{
throw new NotImplementedException();
}
#endregion
}
[Serializable]
public class DialogueData : DialogueData<Dialogue>
{
@ -39,28 +53,5 @@ public class DialogueData : DialogueData<Dialogue>
DialogueStepModelDataList.Add(new DialogueStepData(dialogueStepModelData.WasDisplayed));
}
}
#region NotImplemented
/*
* we dont want to map it here, we will mark fields in NpcDialogfeManager after each loading and fetching dialogue
*/
public override Dialogue MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();
}
/*
* we dont want to map it here, we will mark fields in NpcDialogfeManager after each loading and fetching dialogue
*/
public override Dialogue MapDataToObject()
{
throw new NotImplementedException();
}
protected override Dialogue TryFindResource(string modelName)
{
throw new NotImplementedException();
}
#endregion
}

View File

@ -6,10 +6,14 @@ using System.Threading.Tasks;
using UnityEngine;
[Serializable]
public abstract class MultiDialogueData<T> : ModelData<T, T>
public abstract class MultiDialogueData<T> : IModelMapper<T>
{
protected override string SPRITE_LOCALIZATION => "";
protected override string MODEL_LOCALIZATION => "Dialogue/";
[NonSerialized]
public string name;
[NonSerialized]
public string modelName;
[SerializeField]
public string SpeakerName;
@ -19,8 +23,25 @@ public abstract class MultiDialogueData<T> : ModelData<T, T>
[SerializeField]
public List<IndexValuePair<int, DialogueData>> DialogueStepModelDataList = new List<IndexValuePair<int, DialogueData>>();
#region NotImplemented
/*
* we dont want to map it here, we will mark fields in NpcDialogfeManager after each loading and fetching dialogue
*/
public T MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();
}
public T MapDataToObject()
{
throw new NotImplementedException();
}
#endregion
}
[Serializable]
public class MultiDialogueData : MultiDialogueData<MultiDialogue>
{
public MultiDialogueData(MultiDialogue dialogue)
@ -41,22 +62,5 @@ public class MultiDialogueData : MultiDialogueData<MultiDialogue>
);
}
}
#region NotImplemented
public override MultiDialogue MapDataToObject(string prefarbAssetName)
{
throw new NotImplementedException();
}
public override MultiDialogue MapDataToObject()
{
throw new NotImplementedException();
}
protected override MultiDialogue TryFindResource(string modelName)
{
throw new NotImplementedException();
}
#endregion
}

View File

@ -34,7 +34,7 @@ public abstract class ItemData : ModelData<Item, Item>
public override Item MapDataToObject(string prefarbAssetName)
{
Debug.Log(MODEL_LOCALIZATION + prefarbAssetName + ".asset");
/* Debug.Log(MODEL_LOCALIZATION + prefarbAssetName + ".asset"); */
return TryFindResource(prefarbAssetName);

View File

@ -6,25 +6,24 @@ using System.Threading.Tasks;
class MissionDialogueData : DialogueData<MissionDialogue>
{
protected override string SPRITE_LOCALIZATION => "";
protected override string MODEL_LOCALIZATION => "Mission/Dialogue/";
public override MissionDialogue MapDataToObject(string prefarbAssetName)
/// <summary>
/// build Data model based on Object
/// </summary>
/// <param name="dialogue"></param>
public MissionDialogueData(Dialogue dialogue)
{
throw new NotImplementedException();
}
CurrentStep = dialogue.CurrentStep;
public override MissionDialogue MapDataToObject()
DialogueStepModelDataList.Clear();
foreach (DialogueStepModel dialogueStepModelData in dialogue.DialogueSteps)
{
throw new NotImplementedException();
}
protected override MissionDialogue TryFindResource(string modelName)
{
throw new NotImplementedException();
/*
* pass WasDisplayed value from model to data representative class
*/
DialogueStepModelDataList.Add(new DialogueStepData(dialogueStepModelData.WasDisplayed));
}
}
}

View File

@ -68,4 +68,10 @@ public class SaveController : MonoBehaviour
if(SceneShopDataManager.Instance)
SceneShopDataManager.Instance.SaveDynamicData();
}
public void SaveDialogues()
{
if (MultiDialogueDataManager.Instance)
MultiDialogueDataManager.Instance.SaveDynamicData();
}
}

View File

@ -1,8 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Tell what is the beginning state of loaded scene
[Serializable]
public enum OnMapAppearanceMethodEnum
{
NewGame = 0,
@ -11,17 +13,20 @@ public enum OnMapAppearanceMethodEnum
//maybe respawn too
}
[Serializable]
public enum GameStatus
{
NewGame = 0,
Continue = 1
}
[Serializable]
public class OnMapAppearanceMethod : MonoBehaviour
{
[SerializeField]
public static OnMapAppearanceMethodEnum Gateway { get; set; } // Map status
[SerializeField]
public static GameStatus GameStatus { get; set; }
// every script which makes player appear somewhere should change this variable ! ! !