2020-10-23 18:06:11 +00:00
|
|
|
|
using OWML.Common;
|
2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-10-23 18:06:11 +00:00
|
|
|
|
using QSB.Utility;
|
2020-10-24 10:17:52 +00:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using System.Collections.Generic;
|
2020-10-24 14:31:20 +00:00
|
|
|
|
using System.Linq;
|
2020-09-22 20:11:29 +00:00
|
|
|
|
using UnityEngine;
|
2020-10-23 18:06:11 +00:00
|
|
|
|
using UnityEngine.UI;
|
2020-09-22 20:11:29 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.ConversationSync
|
|
|
|
|
{
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public class ConversationManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public static ConversationManager Instance { get; private set; }
|
|
|
|
|
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings { get; } = new Dictionary<CharacterDialogueTree, GameObject>();
|
|
|
|
|
|
|
|
|
|
private GameObject _boxPrefab;
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
|
2020-12-24 15:57:25 +00:00
|
|
|
|
_boxPrefab = QSBCore.ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
|
2021-08-22 15:40:50 +00:00
|
|
|
|
// BUG : make dynamic so it can be different sizes!
|
2021-02-16 20:58:46 +00:00
|
|
|
|
// the dynamic font seems to be super lo-res at this size...?
|
2020-12-14 21:20:53 +00:00
|
|
|
|
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
|
|
|
|
|
if (font == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Error - Font is null!", MessageType.Error);
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
_boxPrefab.GetComponent<Text>().font = font;
|
|
|
|
|
_boxPrefab.GetComponent<Text>().color = Color.white;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
|
|
|
|
|
{
|
|
|
|
|
var treeIndex = QSBWorldSync.OldDialogueTrees.IndexOf(tree);
|
2021-04-29 17:30:45 +00:00
|
|
|
|
return QSBPlayerManager.PlayerList.All(x => x.CurrentCharacterDialogueTreeId != treeIndex)
|
2020-12-14 21:20:53 +00:00
|
|
|
|
? uint.MaxValue
|
2021-04-29 17:30:45 +00:00
|
|
|
|
: QSBPlayerManager.PlayerList.First(x => x.CurrentCharacterDialogueTreeId == treeIndex).PlayerId;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SendPlayerOption(string text) =>
|
2021-02-13 10:11:02 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, text, ConversationType.Player);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
|
|
|
|
|
public void SendCharacterDialogue(int id, string text)
|
|
|
|
|
{
|
|
|
|
|
if (id == -1)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Warning - Tried to send conv. event with char id -1.", MessageType.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2021-02-13 10:11:02 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBConversation, (uint)id, text, ConversationType.Character);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseBoxPlayer() =>
|
2021-02-13 10:11:02 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, "", ConversationType.ClosePlayer);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
|
|
|
|
|
public void CloseBoxCharacter(int id) =>
|
2021-02-13 10:11:02 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBConversation, (uint)id, "", ConversationType.CloseCharacter);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
|
|
|
|
|
public void SendConvState(int charId, bool state)
|
|
|
|
|
{
|
|
|
|
|
if (charId == -1)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Warning - Tried to send conv. start/end event with char id -1.", MessageType.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2021-02-13 10:11:02 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBConversationStartEnd, charId, QSBPlayerManager.LocalPlayerId, state);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisplayPlayerConversationBox(uint playerId, string text)
|
|
|
|
|
{
|
|
|
|
|
if (playerId == QSBPlayerManager.LocalPlayerId)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Error - Cannot display conversation box for local player!", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(playerId);
|
|
|
|
|
|
|
|
|
|
// Destroy old box if it exists
|
|
|
|
|
var playerBox = player.CurrentDialogueBox;
|
|
|
|
|
if (playerBox != null)
|
|
|
|
|
{
|
|
|
|
|
Destroy(playerBox);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-04 12:15:31 +00:00
|
|
|
|
QSBPlayerManager.GetPlayer(playerId).CurrentDialogueBox = CreateBox(player.Body.transform, 2, text);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisplayCharacterConversationBox(int index, string text)
|
|
|
|
|
{
|
|
|
|
|
if (QSBWorldSync.OldDialogueTrees.ElementAtOrDefault(index) == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error - Tried to display character conversation box for id {index}! (Doesn't exist!)", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove old box if it exists
|
|
|
|
|
var oldDialogueTree = QSBWorldSync.OldDialogueTrees[index];
|
|
|
|
|
if (BoxMappings.ContainsKey(oldDialogueTree))
|
|
|
|
|
{
|
|
|
|
|
Destroy(BoxMappings[oldDialogueTree]);
|
|
|
|
|
BoxMappings.Remove(oldDialogueTree);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BoxMappings.Add(oldDialogueTree, CreateBox(oldDialogueTree.gameObject.transform, 2, text));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private GameObject CreateBox(Transform parent, float vertOffset, string text)
|
|
|
|
|
{
|
|
|
|
|
var newBox = Instantiate(_boxPrefab);
|
|
|
|
|
newBox.SetActive(false);
|
2020-12-31 12:10:55 +00:00
|
|
|
|
newBox.transform.SetParent(parent);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
newBox.transform.localPosition = new Vector3(0, vertOffset, 0);
|
|
|
|
|
newBox.transform.rotation = parent.rotation;
|
2021-09-27 15:54:15 +00:00
|
|
|
|
newBox.AddComponent<CameraFacingBillboard>();
|
2020-12-14 21:20:53 +00:00
|
|
|
|
newBox.GetComponent<Text>().text = text;
|
2021-05-02 08:09:37 +00:00
|
|
|
|
newBox.AddComponent<ZOverride>();
|
2020-12-14 21:20:53 +00:00
|
|
|
|
newBox.SetActive(true);
|
|
|
|
|
return newBox;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|