added tooltips

This commit is contained in:
Vladimir Koshevarov
2022-11-29 19:09:00 +02:00
parent 2167b43c29
commit 73f06d8754
33 changed files with 1264 additions and 250 deletions
@@ -1,19 +1,18 @@
using Assets.Scripts.Actions;
using System.Collections.Generic;
using Assets.Scripts.Actions.Interfaces;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[System.Serializable]
public class ConversationChangeEvent : UnityEvent<BaseAction> { }
public class ConversationChangeEvent : UnityEvent<IPlayerAction> { }
public class ChoiceController : MonoBehaviour
{
public KeyValuePair<string, BaseAction> _option;
public IPlayerAction _option;
public ConversationChangeEvent conversationChangeEvent;
// Update is called once per frame
public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, KeyValuePair<string, BaseAction> option, int index)
public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, IPlayerAction option, int index)
{
int buttonSpacing = -50;
@@ -22,7 +21,7 @@ public class ChoiceController : MonoBehaviour
button.transform.SetParent(choiceButtonTemplate.transform.parent);
button.transform.localScale = Vector3.one;
button.transform.localPosition = choiceButtonTemplate.transform.localPosition + new Vector3(0, index * buttonSpacing, 0);
button.name = option.Key;
button.name = option.Description;
button.gameObject.SetActive(true);
ChoiceController choiceController = button.GetComponent<ChoiceController>();
choiceController._option = option;
@@ -36,11 +35,11 @@ public class ChoiceController : MonoBehaviour
var btn = GetComponent<Button>();
var txt = btn.GetComponentInChildren<TextMeshProUGUI>();
txt.text = _option.Key;
txt.text = _option.Description;
}
public void MakeChoice()
{
conversationChangeEvent.Invoke(_option.Value);
conversationChangeEvent.Invoke(_option);
}
}
@@ -1,4 +1,4 @@
using Assets.Scripts.Actions;
using Assets.Scripts.Actions.Interfaces;
using System.Collections.Generic;
using System.Linq;
using TMPro;
@@ -7,29 +7,34 @@ using UnityEngine.UI;
public class ConversationController : MonoBehaviour
{
[SerializeField]
public TextMeshProUGUI _title;
[SerializeField]
public Button _choiceButton;
[SerializeField]
private Button _closeBtn;
[SerializeField]
PlayerManager _playerManager;
[SerializeField] public TextMeshProUGUI _title;
[SerializeField] public Button _choiceButton;
[SerializeField] private Button _btnApply;
[SerializeField] private Button _btnClose;
[SerializeField] PlayerManager _playerManager;
public ConversationChangeEvent conversationChangeEvent;
private List<ChoiceController> choiceControllers = new();
private IPlayerAction _selectedAction = null;
private void Awake()
{
Hide();
}
public void Change(string title, Dictionary<string, BaseAction> options)
public void Change(string title, List<IPlayerAction> options)
{
_closeBtn.onClick.AddListener(() =>
_btnApply.interactable = false;
_btnClose.onClick.AddListener(() =>
{
Hide();
});
_btnApply.onClick.AddListener(() =>
{
Hide();
ApplyActionOnPlayer(_selectedAction);
});
_playerManager.allowMovement = false;
@@ -40,31 +45,30 @@ public class ConversationController : MonoBehaviour
for (var count = 0; count < options.Count; count++)
{
ChoiceController c = ChoiceController.AddChoiceButton(_choiceButton, options.ElementAt(count), count);
c.conversationChangeEvent.AddListener(ApplyActionOnPlayer);
c.conversationChangeEvent.AddListener(SelectAction);
choiceControllers.Add(c);
}
StopAllCoroutines();
Time.timeScale = 0;
_choiceButton.gameObject.SetActive(false);
}
private void ApplyActionOnPlayer(BaseAction action)
private void SelectAction(IPlayerAction action)
{
if (!_playerManager.TryBuyAction(action))
_selectedAction = action;
if (action is ISellable)
{
YesNoDialogUI.Instance.ShowQuestion("not enouth money",
() =>
{
},
() =>
{
//do nothing
});
_btnApply.interactable = _playerManager.PlayerStats[GameManager.StatsId.Money].Value >= (action as ISellable).Price;
}
}
private void ApplyActionOnPlayer(IPlayerAction action)
{
if (action is ISellable)
_playerManager.BuyAction(action);
}
private void RemoveChoices()
{
foreach (ChoiceController c in choiceControllers)