Shop - open after dialogue
This commit is contained in:
parent
43e1d817d7
commit
c006e4a8ee
8
Assets/Resources/Dialogue/Shop.meta
Normal file
8
Assets/Resources/Dialogue/Shop.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e26afc3f871ece49983af659133aaf6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Resources/Dialogue/Shop/ANG.meta
Normal file
8
Assets/Resources/Dialogue/Shop/ANG.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d1f01af9ffb9b448a1854c5ef4bbbd3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Resources/Dialogue/Shop/ANG/ShopDialAng.asset
Normal file
25
Assets/Resources/Dialogue/Shop/ANG/ShopDialAng.asset
Normal file
@ -0,0 +1,25 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 06201cadd951bcc4db5fccaa01783060, type: 3}
|
||||
m_Name: ShopDialAng
|
||||
m_EditorClassIdentifier:
|
||||
SpeakerName:
|
||||
CurrentStep: 0
|
||||
DialogueSteps:
|
||||
- Header:
|
||||
WasDisplayed: 0
|
||||
ListOfSentences:
|
||||
- Sentence: Hello, are you interested in buying something?
|
||||
Buttons: []
|
||||
EndOfDialogueStepAction:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b370999d245bbf4ab85d24fd050f82a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Resources/Dialogue/Shop/PL.meta
Normal file
8
Assets/Resources/Dialogue/Shop/PL.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7d7a10db705ca246966a3d308760393
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Resources/Dialogue/Shop/PL/ShopDialPl.asset
Normal file
25
Assets/Resources/Dialogue/Shop/PL/ShopDialPl.asset
Normal file
@ -0,0 +1,25 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 06201cadd951bcc4db5fccaa01783060, type: 3}
|
||||
m_Name: ShopDialPl
|
||||
m_EditorClassIdentifier:
|
||||
SpeakerName:
|
||||
CurrentStep: 0
|
||||
DialogueSteps:
|
||||
- Header:
|
||||
WasDisplayed: 0
|
||||
ListOfSentences:
|
||||
- Sentence: "Witaj, czy chcia\u0142 by\u015B co\u015B kupi\u0107?"
|
||||
Buttons: []
|
||||
EndOfDialogueStepAction:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
8
Assets/Resources/Dialogue/Shop/PL/ShopDialPl.asset.meta
Normal file
8
Assets/Resources/Dialogue/Shop/PL/ShopDialPl.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e071e06365862a4b8b5762b14ff8555
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -64,7 +64,6 @@ public class DialogueController
|
||||
/// <returns></returns>
|
||||
public bool ShowNextPanel(DialogueController parentDialController)
|
||||
{
|
||||
Debug.Log(listOfDialogue.Count);
|
||||
if (listOfDialogue.Count == 0)
|
||||
{
|
||||
CloseCurrentPanel(parentDialController);
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.Events;
|
||||
|
||||
[Serializable]
|
||||
[CreateAssetMenu(fileName = "New Dialogue", menuName = "Dialogue/New Dialogue")]
|
||||
@ -24,6 +24,20 @@ public class Dialogue : ScriptableObject, IDialogue
|
||||
DialogueSteps.ForEach(step => step.Header = speakerName);
|
||||
}
|
||||
|
||||
#region finish action api
|
||||
public void SetActionAfterDialogueStep(int dialogueStepNo, UnityEvent _endOfDialogueStepAction)
|
||||
{
|
||||
if(DialogueSteps.Count >= dialogueStepNo)
|
||||
DialogueSteps[dialogueStepNo].SetActionAfterDialogueStep(_endOfDialogueStepAction);
|
||||
}
|
||||
public void SetActionAfterDialogueStep(int dialogueStepNo, Action _finishDialogueAction)
|
||||
{
|
||||
if (DialogueSteps.Count >= dialogueStepNo)
|
||||
DialogueSteps[dialogueStepNo].SetActionAfterDialogueStep(_finishDialogueAction);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region dialogue displaying api
|
||||
public void StartDialogue()
|
||||
{
|
||||
// 1. Build
|
||||
@ -101,6 +115,7 @@ public class Dialogue : ScriptableObject, IDialogue
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Function to build each step of dialogue
|
||||
@ -114,4 +129,14 @@ public class Dialogue : ScriptableObject, IDialogue
|
||||
dialogueStep.Build();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function to reset rememebered dialogue status
|
||||
///
|
||||
/// (Scriptable objects clones are overwritten during clone modification)
|
||||
/// </summary>
|
||||
public void ResetDialogue()
|
||||
{
|
||||
DialogueSteps.ForEach(step => step.WasDisplayed = false);
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,17 @@ public class DialogueStepModel
|
||||
public DialogueController DialogueController { get; protected set; }
|
||||
|
||||
|
||||
public DialogueStepModel() { }
|
||||
public DialogueStepModel()
|
||||
{
|
||||
// Add marked step as displayed action as first!
|
||||
EndOfDialogueStepAction.AddListener(() => { MarkAsDisplayed(); });
|
||||
}
|
||||
|
||||
public DialogueStepModel(DialogueController _dialogueController)
|
||||
{
|
||||
// Add marked step as displayed action as first!
|
||||
EndOfDialogueStepAction.AddListener(() => { MarkAsDisplayed(); });
|
||||
|
||||
DialogueController = _dialogueController;
|
||||
}
|
||||
|
||||
@ -51,12 +58,22 @@ public class DialogueStepModel
|
||||
DialogueController.AddSentence(DialogueModel);
|
||||
}
|
||||
|
||||
// 3. Bind finishing action
|
||||
|
||||
// 3.1 Add marked step as displayed action
|
||||
EndOfDialogueStepAction.AddListener(() => WasDisplayed = true);
|
||||
|
||||
// 3.2 Bind actions
|
||||
// 3 Bind ending actions
|
||||
DialogueController.SetActionAfterDialogueEnds(EndOfDialogueStepAction);
|
||||
}
|
||||
|
||||
public void SetActionAfterDialogueStep(UnityEvent _endOfDialogueStepAction)
|
||||
{
|
||||
EndOfDialogueStepAction = _endOfDialogueStepAction;
|
||||
}
|
||||
|
||||
public void SetActionAfterDialogueStep(Action _finishDialogueAction)
|
||||
{
|
||||
EndOfDialogueStepAction.AddListener(new UnityAction(_finishDialogueAction));
|
||||
}
|
||||
|
||||
public void MarkAsDisplayed()
|
||||
{
|
||||
WasDisplayed = true;
|
||||
}
|
||||
}
|
@ -147,6 +147,16 @@ public class MultiDialogue : ScriptableObject, IDialogue
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function to reset rememebered dialogue status
|
||||
///
|
||||
/// (Scriptable objects clones are overwritten during clone modification)
|
||||
/// </summary>
|
||||
public void ResetDialogue()
|
||||
{
|
||||
Dialogues.ForEach(dial => dial.Value.DialogueSteps.ForEach(step => step.WasDisplayed = false));
|
||||
}
|
||||
|
||||
public (int, int) DialogueStepStatus()
|
||||
{
|
||||
var currentDialogueStepIndex = Dialogues
|
||||
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[RequireComponent(typeof(NPC))]
|
||||
[Serializable]
|
||||
public class NpcDialogueManager : MonoBehaviour
|
||||
{
|
||||
|
@ -5,29 +5,29 @@ using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
[RequireComponent(typeof(NPC))]
|
||||
class NpcShopManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public Dialogue DialogueTemplate;
|
||||
public List<IndexValuePair<SystemLanguageEnum, Dialogue>> DialogueTemplate;
|
||||
|
||||
/* We user object CLONED TO PREVENT overwritting changes in main object inassets */
|
||||
private Dialogue Dialogue;
|
||||
public Dialogue Dialogue;
|
||||
|
||||
[SerializeField]
|
||||
public Shop shop;
|
||||
|
||||
public void Start()
|
||||
bool CanShopBeOpened = false;
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
// TODO - remove - we want ot register ir manually because condition below is not meeted in test env
|
||||
this.RegisterShop();
|
||||
// 1. Set npc state to trading
|
||||
gameObject.GetComponent<NPC>().State = NPCStateEnum.Trading;
|
||||
|
||||
// 2. Init dialogue model
|
||||
CreateInstanceBasedOnLanguage();
|
||||
|
||||
// 1. Create dialogue object from template
|
||||
|
||||
// 2. Set speaker name
|
||||
Dialogue = Instantiate(DialogueTemplate);
|
||||
Dialogue.SetSpeakerName(gameObject.GetComponent<NPC>().name);
|
||||
|
||||
//this.RegisterShop();
|
||||
// if its new game or we dont have any save from this map - use deffault shop settings / content
|
||||
// else overwrite value by saved one
|
||||
if (OnMapAppearanceMethod.GameStatus == GameStatus.NewGame ||
|
||||
@ -42,26 +42,67 @@ class NpcShopManager : MonoBehaviour
|
||||
}).First();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
/*
|
||||
* Conditions:
|
||||
* - player must be in range of shopping
|
||||
* - user must press specific keyboard button
|
||||
* - dialogue panel must be closed
|
||||
* - shop panel must be closed
|
||||
*/
|
||||
if (CanShopBeOpened && Input.GetKeyDown(ShopUIManager.Instance.keyToOpen) && Dialogue.DialogueSteps.First().DialogueController?.CurrentPanel == null && !ShopUIManager.Instance.GetPanelStatus())
|
||||
{
|
||||
// Open dialogue panel (Shop will be opened later)
|
||||
Dialogue.StartDialogue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if(collision.gameObject.tag == "Player" && gameObject.GetComponent<NPC>().State == NPCStateEnum.Trading && !ShopUIManager.Instance.GetPanelStatus())
|
||||
// don't listen when component is disabled
|
||||
if (!gameObject.GetComponent<NpcShopManager>().enabled)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Conditions:
|
||||
* - agent in collision must be player
|
||||
* - npc bust me in Trading mode
|
||||
* - shop must be currently closed
|
||||
*/
|
||||
if (collision.gameObject.tag == "Player" && gameObject.GetComponent<NPC>().State == NPCStateEnum.Trading && !ShopUIManager.Instance.GetPanelStatus())
|
||||
{
|
||||
// 1. Open dialogue panel
|
||||
|
||||
// 2. Open shop
|
||||
|
||||
OpenShop();
|
||||
CanShopBeOpened = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
// don't listen when component is disabled
|
||||
if (!gameObject.GetComponent<NpcShopManager>().enabled)
|
||||
return;
|
||||
|
||||
if (collision.gameObject.tag == "Player")
|
||||
{
|
||||
CanShopBeOpened = false;
|
||||
|
||||
if (Dialogue.DialogueSteps.First().DialogueController?.CurrentPanel != null)
|
||||
Dialogue.BreakDialogueStep();
|
||||
|
||||
|
||||
CloseShop();
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateInstanceBasedOnLanguage()
|
||||
{
|
||||
Dialogue = Instantiate(DetectInstanceBasedOnLanguage());
|
||||
Dialogue.SetSpeakerName(gameObject.GetComponent<NPC>().name);
|
||||
Dialogue.SetActionAfterDialogueStep(0, Dialogue.ResetDialogue);
|
||||
Dialogue.SetActionAfterDialogueStep(0, OpenShop);
|
||||
}
|
||||
|
||||
public void RegisterShop()
|
||||
{
|
||||
// 1. Set owner name
|
||||
@ -80,7 +121,10 @@ class NpcShopManager : MonoBehaviour
|
||||
|
||||
public void OpenShop()
|
||||
{
|
||||
Debug.Log("OpenShop");
|
||||
if (EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.ClosePanel();
|
||||
|
||||
|
||||
// Set info about current shop in shop UI manager (and wait for event - pressing E)
|
||||
|
||||
// Open shopa action - invoked as dialogue end action
|
||||
ShopUIManager.Instance.CurrentShopOwnerName = gameObject.GetComponent<NPC>().name;
|
||||
@ -90,9 +134,31 @@ class NpcShopManager : MonoBehaviour
|
||||
|
||||
public void CloseShop()
|
||||
{
|
||||
ShopUIManager.Instance.ClosePanel();
|
||||
|
||||
ShopUIManager.Instance.CurrentShopOwnerName = "";
|
||||
|
||||
ShopUIManager.Instance.ClosePanel();
|
||||
}
|
||||
|
||||
public Dialogue DetectInstanceBasedOnLanguage()
|
||||
{
|
||||
/*if (!PlayerPrefs.HasKey("language"))
|
||||
throw new Exception("Language not setted !!!");*/
|
||||
|
||||
switch(PlayerPrefs.GetString("language"))
|
||||
{
|
||||
case "English":
|
||||
{
|
||||
return DialogueTemplate.Where(template => template.Key == SystemLanguageEnum.English).First().Value;
|
||||
}
|
||||
case "Polish":
|
||||
{
|
||||
return DialogueTemplate.Where(template => template.Key == SystemLanguageEnum.Polish).First().Value;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return DialogueTemplate.Where(template => template.Key == SystemLanguageEnum.Polish).First().Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,11 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Debug.Log("Create: " + gameObject);
|
||||
|
||||
Instance = this;
|
||||
|
||||
Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -31,13 +34,13 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
Debug.Log("Start SceneChestData manager");
|
||||
Debug.Log("Start SceneShopData manager");
|
||||
|
||||
//TaskUIManager.FindOrCreateInstance();
|
||||
UiManager = ShopUIManager.Instance;
|
||||
|
||||
if (UiManager == null)
|
||||
throw new NullReferenceException("ChestUIManager not found!!!");
|
||||
throw new NullReferenceException("ShopUIManager not found!!!");
|
||||
|
||||
DynamicDataList = (new ShopDataListManager()).SetUiManager(ref UiManager);
|
||||
|
||||
@ -58,7 +61,6 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
||||
UseDefaultSettings();
|
||||
}else
|
||||
{
|
||||
Debug.Log("UseDynamicSettings");
|
||||
UseDynamicSettings();
|
||||
}
|
||||
}
|
||||
@ -78,18 +80,12 @@ public class SceneShopDataManager : SceneBaseDataManager<Shop>
|
||||
|
||||
protected override void UseDefaultSettings()
|
||||
{
|
||||
Debug.Log("UseDefaultSettings");
|
||||
|
||||
// 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()
|
||||
{
|
||||
Debug.Log("UseDynamicSettings");
|
||||
|
||||
// BuildList();
|
||||
|
||||
// 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
|
||||
|
@ -53,6 +53,8 @@ public class ShopUIManager : UIBaseManager<Shop>
|
||||
|
||||
ShopContentUIManager.Instance.DynamicPanel = null;
|
||||
|
||||
CurrentShopOwnerName = "";
|
||||
|
||||
// Close additionals panels
|
||||
if (InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.ClosePanel();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user