Skip to content

feature/colored-keyword-in-dialogue #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: Develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -5911,6 +5911,14 @@ PrefabInstance:
propertyPath: weaponPartButtons.Array.data[6]
value:
objectReference: {fileID: 176353656}
- target: {fileID: 2796954696694094515, guid: 719cb460859d5d549965dbcce7bc7358, type: 3}
propertyPath: keyWordColor
value: <color = "red">
objectReference: {fileID: 0}
- target: {fileID: 2796954696694094515, guid: 719cb460859d5d549965dbcce7bc7358, type: 3}
propertyPath: startDialogue
value:
objectReference: {fileID: 11400000, guid: 1924fcd8e85a45942b69b77bd1f10e56, type: 2}
- target: {fileID: 2796954696694094517, guid: 719cb460859d5d549965dbcce7bc7358, type: 3}
propertyPath: m_Pivot.x
value: 0
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/DialogueData/StartOfDialogue.asset
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,30 @@ MonoBehaviour:
m_EditorClassIdentifier:
textWithKey:
- dialogue:
- I wish to have a weapon that is sharp hot, so that I can show off to the other
heroes.
- I wish to have a weapon that is sharp hot, so that I can show off to the other
heroes.
keyword: 0
- dialogue:
- Can you make a weapon that is pointy?
- Can you make a weapon that is pointy?
keyword: 2
- dialogue:
- "I\u2019m going on an adventure and I need a long weapon."
- "I\u2019m going on an adventure and I need a long weapon."
keyword: 3
- dialogue:
- 'Could you make a blunt weapon for me? '
- 'Could you make a blunt weapon for me? '
keyword: 1
- dialogue:
- I need a big weapon that I can add to my collection of weapons.
- I need a big weapon that I can add to my collection of weapons.
keyword: 7
- dialogue:
- On my next mission I need a small weapon, so that I can hide it in underneath
my armor.
- On my next mission I need a small weapon, so that I can hide it in underneath
my armor.
keyword: 8
34 changes: 18 additions & 16 deletions Assets/Scripts/UI/Dialogue/DialogueUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public sealed class DialogueUI : MonoBehaviour
[SerializeField] private GameObject dialogueBox;
[SerializeField] private TMP_Text textlabel;
[SerializeField] private TMP_Text keywordText;
[SerializeField] private DialogueObject testDialogue;
[SerializeField] private DialogueObject startDialogue;
[SerializeField] private WeaponPartsDesirables weaponDesirables;
[SerializeField] private string keyWordColor;

private int _dialogueIndex;
private string _randomDialogue;
private KeyWithText _randomDialogue;
private TypeWriterEffect _typeWriterEffect;

private void Start()
Expand All @@ -23,34 +25,34 @@ private void Start()
public void ShowDialogue(DialogueObject? dialogueObject)
{
dialogueBox.SetActive(true);
StartCoroutine(dialogueObject == null
? StepThroughDialogue(testDialogue)
StartCoroutine(dialogueObject == null
? StepThroughDialogue(startDialogue)
: StepThroughDialogue(dialogueObject));
}

private IEnumerator StepThroughDialogue(DialogueObject dialogueObject)
{
_dialogueIndex = 1;

Debug.Log(dialogueObject);
var randomNumber = Random.Range(0, dialogueObject.TextWithKey.Count);
_randomDialogue = dialogueObject.TextWithKey[randomNumber].Dialogue[0];
_randomDialogue = dialogueObject.TextWithKey[randomNumber];
//_randomDialogue = dialogueObject.TextWithKey[randomNumber].Dialogue[0];

for (int i = 0; i < dialogueObject.TextWithKey[randomNumber].Dialogue.Length; i++)
{
yield return _typeWriterEffect.Run(_randomDialogue, textlabel);
yield return new WaitUntil(() => SetNextDialogue(dialogueObject.TextWithKey[randomNumber]));
}

var dialogueCombinedWithColor = _randomDialogue.Dialogue[0] + keyWordColor + weaponDesirables.ToString() + "</color>" + _randomDialogue.Dialogue[1];

yield return _typeWriterEffect.Run(dialogueCombinedWithColor, textlabel);
yield return new WaitUntil(() => SetNextDialogue(dialogueObject.TextWithKey[randomNumber]));

CloseDialogueBox();
}

private bool SetNextDialogue(KeyWithText keyWithText)
{
if (_dialogueIndex >= keyWithText.Dialogue.Length) return false;
//if (_dialogueIndex >= keyWithText.Dialogue.Length) return false;
if (!Input.GetKeyDown(KeyCode.Space)) return false;

_randomDialogue = keyWithText.Dialogue[_dialogueIndex];
_dialogueIndex++;
//_randomDialogue = keyWithText.Dialogue[_dialogueIndex];
//_dialogueIndex++;
return true;
}

Expand Down
13 changes: 12 additions & 1 deletion Assets/Scripts/UI/Dialogue/TypeWriterEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ private IEnumerator TypeText(string textToType, TMP_Text textLabel)
while (charIndex < textToType.Length)
{
theText += Time.deltaTime * typeWriterSpeed;
//if(the next charcter = <) search for the right arrow ">" if we have both of them, then type the arrow itself and the content in one go. after that go letter by letter.
charIndex = Mathf.FloorToInt(theText);
charIndex = Mathf.Clamp(charIndex, 0, textToType.Length);

if (textToType[charIndex] == '<')
{
Debug.Log(textToType[charIndex]);
for (int i = charIndex; i < textToType.Length; i++)
{
if (textToType[i] == '>')
{
charIndex = i;
}
}
}
textLabel.text = textToType.Substring(0, charIndex);
yield return null;
}
Expand Down
Loading