From 04c376fc2ddf2d6be1925a118b7ace54c7001101 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C4=8Cern=C3=BD?= <cernym65@fit.cvut.cz>
Date: Sat, 21 Jan 2023 04:40:22 +0100
Subject: [PATCH] add self dialogue to player

---
 .../Code/Scripts/Dialogue/DialogueHolder.cs   | 10 ++---
 .../Code/Scripts/Level/Level1Controller.cs    | 14 ++++--
 Assets/SZZ/Code/Scripts/Level/Timer.cs        | 11 +++--
 Assets/SZZ/Code/Scripts/Player/Player.cs      | 12 +++++
 .../Code/Scripts/Player/PlayerInteractUI.cs   |  6 +--
 Assets/SZZ/Code/Scripts/View.cs               |  3 ++
 Assets/SZZ/Dialogue/Adela.ink                 |  1 +
 Assets/SZZ/Dialogue/Self/level1-start.ink     |  3 --
 .../SZZ/Dialogue/Self/level1-start.ink.meta   |  7 ---
 Assets/SZZ/Dialogue/Self/level1-start.json    |  1 -
 .../SZZ/Dialogue/Self/level1-start.json.meta  |  7 ---
 .../SZZ/Dialogue/Self/max-cheats-reached.ink  |  2 +-
 .../SZZ/Dialogue/Self/max-cheats-reached.json |  2 +-
 Assets/SZZ/Level/Scenes/building a.unity      | 14 +++---
 Assets/SZZ/Prefabs/Logic/GameState.prefab     |  1 +
 Assets/SZZ/Prefabs/Logic/View.prefab          | 44 +++++++++++++++++++
 16 files changed, 94 insertions(+), 44 deletions(-)
 delete mode 100644 Assets/SZZ/Dialogue/Self/level1-start.ink
 delete mode 100644 Assets/SZZ/Dialogue/Self/level1-start.ink.meta
 delete mode 100644 Assets/SZZ/Dialogue/Self/level1-start.json
 delete mode 100644 Assets/SZZ/Dialogue/Self/level1-start.json.meta

diff --git a/Assets/SZZ/Code/Scripts/Dialogue/DialogueHolder.cs b/Assets/SZZ/Code/Scripts/Dialogue/DialogueHolder.cs
index 477499e..ad0c864 100644
--- a/Assets/SZZ/Code/Scripts/Dialogue/DialogueHolder.cs
+++ b/Assets/SZZ/Code/Scripts/Dialogue/DialogueHolder.cs
@@ -5,11 +5,11 @@
 using Ink.Runtime;
 
 public class DialogueHolder : MonoBehaviour {
-    [SerializeField] private TextAsset inkJSON;
-    [SerializeField] private UnityEvent<Story> onStart;
-    [SerializeField] private UnityEvent<Story> onChoice;
-    [SerializeField] private UnityEvent<Story> onBreak;
-    [SerializeField] private UnityEvent<Story> onFinish;
+    [SerializeField] public TextAsset inkJSON;
+    [SerializeField] public UnityEvent<Story> onStart;
+    [SerializeField] public UnityEvent<Story> onChoice;
+    [SerializeField] public UnityEvent<Story> onBreak;
+    [SerializeField] public UnityEvent<Story> onFinish;
 
     private DialogueManager dialogueManager;
 
diff --git a/Assets/SZZ/Code/Scripts/Level/Level1Controller.cs b/Assets/SZZ/Code/Scripts/Level/Level1Controller.cs
index 2e35941..ed95153 100644
--- a/Assets/SZZ/Code/Scripts/Level/Level1Controller.cs
+++ b/Assets/SZZ/Code/Scripts/Level/Level1Controller.cs
@@ -5,17 +5,26 @@
 using UnityEngine;
 
 public class Level1Controller : MonoBehaviour {
+    [Header("UI")]
     [SerializeField] private string cheatCountFieldPrefix = "Zvednuté taháky: ";
     [SerializeField] private TMP_Text cheatCountField;
     [SerializeField] private Image cheatCountImageContainer;
     [SerializeField] private Sprite[] cheatCountImages;
+
+    [Header("Timer")]
     [SerializeField] private Timer timer;
     [SerializeField] private float timerLength = 100;
 
+    [Header("Self dialogue")]
+    [SerializeField] private TextAsset maxCheatsInkJSON;
+
     private GameState game;
+    private View view;
+
 
     private void Start() {
         game = GameState.GetInstance();
+        view = View.GetInstance();
         game.currentQuest = "! Najdi na patře zapomenuté taháky. Nenech. Se. Chytit.";
 
         timer.Run(timerLength, () => { game.StartLevel2(); });
@@ -46,9 +55,8 @@ public void PickupCheat() {
 
         SetImage(game.cheatsPickedUp);
 
-        if (game.cheatsPickedUp >= game.maxCheats) {
-            // TODO play dialogue
-        }
+        if (game.cheatsPickedUp >= game.maxCheats)
+            view.player.PlaySelfDialogue(maxCheatsInkJSON);
     }
 
     private void SetImage(int index) {
diff --git a/Assets/SZZ/Code/Scripts/Level/Timer.cs b/Assets/SZZ/Code/Scripts/Level/Timer.cs
index 19d207b..0e2c67f 100644
--- a/Assets/SZZ/Code/Scripts/Level/Timer.cs
+++ b/Assets/SZZ/Code/Scripts/Level/Timer.cs
@@ -25,10 +25,10 @@ void Start() {
     void Update() {
         if (!running)
             return;
-        if (remainingTime - Time.deltaTime > 0){
+        if (remainingTime - Time.deltaTime > 0) {
             remainingTime -= Time.deltaTime;
-             PlayHeartbeat();
-            }
+            PlayHeartbeat();
+        }
         else {
             remainingTime = 0;
             running = false;
@@ -55,9 +55,8 @@ private void PlayHeartbeat() {
         if (remainingTime <= fashHeartbeatThreshold)
             source = remainingTime > fashHeartbeatThreshold / 2 ? heartbeatSources[1] : heartbeatSources[2];
 
-        if(!backgroundAudioController.currentAudio.isPlaying || backgroundAudioController.currentAudio == backgroundAudioController.OSTSource){
-            Debug.Log("Play heartbeat");
+        if (!backgroundAudioController.currentAudio.isPlaying || backgroundAudioController.currentAudio == backgroundAudioController.OSTSource) {
             backgroundAudioController.Play(source, () => PlayHeartbeat());
-            }
+        }
     }
 }
diff --git a/Assets/SZZ/Code/Scripts/Player/Player.cs b/Assets/SZZ/Code/Scripts/Player/Player.cs
index ebece4c..c848e9a 100644
--- a/Assets/SZZ/Code/Scripts/Player/Player.cs
+++ b/Assets/SZZ/Code/Scripts/Player/Player.cs
@@ -3,7 +3,19 @@
 using UnityEngine;
 using UnityEngine.InputSystem;
 
+[RequireComponent(typeof(DialogueHolder))]
 public class Player : MonoBehaviour {
     [SerializeField] private GameObject _cameraRoot;
     public GameObject cameraRoot { get { return _cameraRoot; } }
+
+    private DialogueHolder dialogueHolder;
+
+    private void Awake() {
+        dialogueHolder = GetComponent<DialogueHolder>();
+    }
+
+    public void PlaySelfDialogue(TextAsset inkJSON) {
+        dialogueHolder.inkJSON = inkJSON;
+        dialogueHolder.Play();
+    }
 }
diff --git a/Assets/SZZ/Code/Scripts/Player/PlayerInteractUI.cs b/Assets/SZZ/Code/Scripts/Player/PlayerInteractUI.cs
index 24a0e47..1a9e4a9 100644
--- a/Assets/SZZ/Code/Scripts/Player/PlayerInteractUI.cs
+++ b/Assets/SZZ/Code/Scripts/Player/PlayerInteractUI.cs
@@ -33,13 +33,13 @@ private void FixedUpdate() {
         showPayRespactsPrompt = lookedAtPayRespects is not null;
 
         if (playerActionsController.interactionTrigger is not null)
-            showInteractionPrompt = !dialogueManager.dialogueIsPlaying;
+            showInteractionPrompt = true;
 
     }
 
     private void Update() {
-        TogglePrompt(interactPrompt, showInteractionPrompt);
-        TogglePrompt(payRespectsPrompt, showPayRespactsPrompt);
+        TogglePrompt(interactPrompt, showInteractionPrompt && !dialogueManager.dialogueIsPlaying);
+        TogglePrompt(payRespectsPrompt, showPayRespactsPrompt && !dialogueManager.dialogueIsPlaying);
     }
 
     private void TogglePrompt(GameObject obj, bool active) {
diff --git a/Assets/SZZ/Code/Scripts/View.cs b/Assets/SZZ/Code/Scripts/View.cs
index 0b0f252..bea452f 100644
--- a/Assets/SZZ/Code/Scripts/View.cs
+++ b/Assets/SZZ/Code/Scripts/View.cs
@@ -9,6 +9,9 @@
 public class View : MonoBehaviour {
     private static View instance;
 
+    [SerializeField] private Player _player;
+    public Player player { get { return _player; } }
+
     [SerializeField] private PlayerInput _playerInput;
     public PlayerInput playerInput { get { return _playerInput; } }
 
diff --git a/Assets/SZZ/Dialogue/Adela.ink b/Assets/SZZ/Dialogue/Adela.ink
index cc8db0d..6acd6af 100644
--- a/Assets/SZZ/Dialogue/Adela.ink
+++ b/Assets/SZZ/Dialogue/Adela.ink
@@ -42,4 +42,5 @@ To je snad vše, tak hodně štěstí a moc se nebojte… bolí to jen trochu.
 Kdybyste ještě potřeboval něco vysvětlit, nebojte se zastavit, jsem tady pro Vás.
 
 [Měl bych se rychle podívat, jestli tady někdo nezapomněl něco, co by se mi mohlo hodit. Hmm, za co asi chytli všechny ty nebožáky kolem...]
+
 -> END
diff --git a/Assets/SZZ/Dialogue/Self/level1-start.ink b/Assets/SZZ/Dialogue/Self/level1-start.ink
deleted file mode 100644
index b9f9701..0000000
--- a/Assets/SZZ/Dialogue/Self/level1-start.ink
+++ /dev/null
@@ -1,3 +0,0 @@
-Měl bych se rychle podívat, jestli tady někdo nezapomněl něco, co by se mi mohlo hodit. Hmm, za co asi chytli všechny ty nebožáky kolem...
-
--> END
diff --git a/Assets/SZZ/Dialogue/Self/level1-start.ink.meta b/Assets/SZZ/Dialogue/Self/level1-start.ink.meta
deleted file mode 100644
index eafbc33..0000000
--- a/Assets/SZZ/Dialogue/Self/level1-start.ink.meta
+++ /dev/null
@@ -1,7 +0,0 @@
-fileFormatVersion: 2
-guid: 2fa6b4d0470aebd4098f7b4dfbac9e3a
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 
diff --git a/Assets/SZZ/Dialogue/Self/level1-start.json b/Assets/SZZ/Dialogue/Self/level1-start.json
deleted file mode 100644
index 0fc2937..0000000
--- a/Assets/SZZ/Dialogue/Self/level1-start.json
+++ /dev/null
@@ -1 +0,0 @@
-{"inkVersion":20,"root":[["^Měl bych se rychle podívat, jestli tady někdo nezapomněl něco, co by se mi mohlo hodit. Hmm, za co asi chytli všechny ty nebožáky kolem...","\n","end",["done",{"#f":5,"#n":"g-0"}],null],"done",{"#f":1}],"listDefs":{}}
\ No newline at end of file
diff --git a/Assets/SZZ/Dialogue/Self/level1-start.json.meta b/Assets/SZZ/Dialogue/Self/level1-start.json.meta
deleted file mode 100644
index f55ae7a..0000000
--- a/Assets/SZZ/Dialogue/Self/level1-start.json.meta
+++ /dev/null
@@ -1,7 +0,0 @@
-fileFormatVersion: 2
-guid: 25d61c961edcbd6409317e7e59f1b6d8
-TextScriptImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 
diff --git a/Assets/SZZ/Dialogue/Self/max-cheats-reached.ink b/Assets/SZZ/Dialogue/Self/max-cheats-reached.ink
index 99a5cf2..2ae7ab9 100644
--- a/Assets/SZZ/Dialogue/Self/max-cheats-reached.ink
+++ b/Assets/SZZ/Dialogue/Self/max-cheats-reached.ink
@@ -1,3 +1,3 @@
-Dobře, to by pro teď mohlo stačit...
+[Dobře, to by pro teď mohlo stačit...]
 
 -> END
diff --git a/Assets/SZZ/Dialogue/Self/max-cheats-reached.json b/Assets/SZZ/Dialogue/Self/max-cheats-reached.json
index ad2178f..e50d544 100644
--- a/Assets/SZZ/Dialogue/Self/max-cheats-reached.json
+++ b/Assets/SZZ/Dialogue/Self/max-cheats-reached.json
@@ -1 +1 @@
-{"inkVersion":20,"root":[["^Dobře, to by pro teď mohlo stačit...","\n","end",["done",{"#f":5,"#n":"g-0"}],null],"done",{"#f":1}],"listDefs":{}}
\ No newline at end of file
+{"inkVersion":20,"root":[["^[Dobře, to by pro teď mohlo stačit...]","\n","end",["done",{"#f":5,"#n":"g-0"}],null],"done",{"#f":1}],"listDefs":{}}
\ No newline at end of file
diff --git a/Assets/SZZ/Level/Scenes/building a.unity b/Assets/SZZ/Level/Scenes/building a.unity
index d27f7c2..8d10aeb 100644
--- a/Assets/SZZ/Level/Scenes/building a.unity	
+++ b/Assets/SZZ/Level/Scenes/building a.unity	
@@ -25099,7 +25099,7 @@ Transform:
   - {fileID: 1788797531}
   - {fileID: 1893192112}
   m_Father: {fileID: 0}
-  m_RootOrder: 4
+  m_RootOrder: 6
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1001 &1004904546
 PrefabInstance:
@@ -45265,7 +45265,7 @@ Transform:
   - {fileID: 1234824317}
   - {fileID: 1092490400}
   m_Father: {fileID: 0}
-  m_RootOrder: 2
+  m_RootOrder: 4
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1001 &1860173879
 PrefabInstance:
@@ -45590,7 +45590,7 @@ Transform:
   - {fileID: 1596836417}
   - {fileID: 593223143}
   m_Father: {fileID: 0}
-  m_RootOrder: 1
+  m_RootOrder: 2
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!4 &1867072812 stripped
 Transform:
@@ -46356,7 +46356,7 @@ Transform:
   - {fileID: 32797275}
   - {fileID: 494654910}
   m_Father: {fileID: 0}
-  m_RootOrder: 3
+  m_RootOrder: 5
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1001 &1899181176
 PrefabInstance:
@@ -52064,7 +52064,7 @@ Transform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 0}
-  m_RootOrder: 6
+  m_RootOrder: 7
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!4 &543450652047391012 stripped
 Transform:
@@ -53918,7 +53918,7 @@ PrefabInstance:
     - target: {fileID: 6330820102716056176, guid: 1eb73f1b5311760469cc6e221f2538a9,
         type: 3}
       propertyPath: m_RootOrder
-      value: 5
+      value: 1
       objectReference: {fileID: 0}
     - target: {fileID: 6330820102716056176, guid: 1eb73f1b5311760469cc6e221f2538a9,
         type: 3}
@@ -54116,7 +54116,7 @@ PrefabInstance:
     - target: {fileID: 6909880373530918866, guid: 39967ec940f6f104eabe57a2974f7ab0,
         type: 3}
       propertyPath: m_RootOrder
-      value: 7
+      value: 3
       objectReference: {fileID: 0}
     - target: {fileID: 6909880373530918866, guid: 39967ec940f6f104eabe57a2974f7ab0,
         type: 3}
diff --git a/Assets/SZZ/Prefabs/Logic/GameState.prefab b/Assets/SZZ/Prefabs/Logic/GameState.prefab
index 761d9c6..1acdfe0 100644
--- a/Assets/SZZ/Prefabs/Logic/GameState.prefab
+++ b/Assets/SZZ/Prefabs/Logic/GameState.prefab
@@ -444,6 +444,7 @@ MonoBehaviour:
   - {fileID: 21300000, guid: 4709a4ad857b65f488c202f88ac74aa8, type: 3}
   timer: {fileID: 6330820102687515709}
   timerLength: 100
+  maxCheatsInkJSON: {fileID: 4900000, guid: 17670a8818c57114cabe2ba7e74d52b7, type: 3}
 --- !u!114 &6330820102716056178
 MonoBehaviour:
   m_ObjectHideFlags: 0
diff --git a/Assets/SZZ/Prefabs/Logic/View.prefab b/Assets/SZZ/Prefabs/Logic/View.prefab
index e0976c9..9693c92 100644
--- a/Assets/SZZ/Prefabs/Logic/View.prefab
+++ b/Assets/SZZ/Prefabs/Logic/View.prefab
@@ -1807,6 +1807,7 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: a7041f553154ba0409a2c56f6a8c1e28, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  _player: {fileID: 1722896712072917824}
   _playerInput: {fileID: 6909880373530918865}
   _inputActionAsset: {fileID: -944628639613478452, guid: 7a465a0d9e0a168469c9e51761952157,
     type: 3}
@@ -3059,12 +3060,55 @@ PrefabInstance:
     m_RemovedComponents:
     - {fileID: 135756641613574976, guid: c5efc39a8aaf6e64ea40e9ad573e9b47, type: 3}
   m_SourcePrefab: {fileID: 100100000, guid: c5efc39a8aaf6e64ea40e9ad573e9b47, type: 3}
+--- !u!114 &1722896712072917824 stripped
+MonoBehaviour:
+  m_CorrespondingSourceObject: {fileID: 203974826412175163, guid: c5efc39a8aaf6e64ea40e9ad573e9b47,
+    type: 3}
+  m_PrefabInstance: {fileID: 1530202875637013627}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 7109144527452912175}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 4dde85815a4da624ea44a0a174c5c23a, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!4 &3197233019988198259 stripped
 Transform:
   m_CorrespondingSourceObject: {fileID: 4135013735270702856, guid: c5efc39a8aaf6e64ea40e9ad573e9b47,
     type: 3}
   m_PrefabInstance: {fileID: 1530202875637013627}
   m_PrefabAsset: {fileID: 0}
+--- !u!1 &7109144527452912175 stripped
+GameObject:
+  m_CorrespondingSourceObject: {fileID: 8616685848737228372, guid: c5efc39a8aaf6e64ea40e9ad573e9b47,
+    type: 3}
+  m_PrefabInstance: {fileID: 1530202875637013627}
+  m_PrefabAsset: {fileID: 0}
+--- !u!114 &8329629129859309969
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 7109144527452912175}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 063913b232069524eb0bb1c306582ea0, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  inkJSON: {fileID: 0}
+  onStart:
+    m_PersistentCalls:
+      m_Calls: []
+  onChoice:
+    m_PersistentCalls:
+      m_Calls: []
+  onBreak:
+    m_PersistentCalls:
+      m_Calls: []
+  onFinish:
+    m_PersistentCalls:
+      m_Calls: []
 --- !u!4 &7629961867817803925 stripped
 Transform:
   m_CorrespondingSourceObject: {fileID: 8997996947095583982, guid: c5efc39a8aaf6e64ea40e9ad573e9b47,
-- 
GitLab