CleanupCode add eating
This commit is contained in:
@@ -1,45 +1,44 @@
|
||||
using Assets.Scripts.Actions.Interfaces;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
//using TMPro;
|
||||
//using UnityEngine;
|
||||
//using UnityEngine.Events;
|
||||
//using UnityEngine.UI;
|
||||
|
||||
[System.Serializable]
|
||||
public class ConversationChangeEvent : UnityEvent<IPlayerAction> { }
|
||||
//[System.Serializable]
|
||||
//public class ConversationChangeEvent : UnityEvent<IPlayerAction> { }
|
||||
|
||||
public class ChoiceController : MonoBehaviour
|
||||
{
|
||||
public IPlayerAction _option;
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
// Update is called once per frame
|
||||
public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, IPlayerAction option, int index)
|
||||
{
|
||||
int buttonSpacing = -50;
|
||||
//public class ChoiceController : MonoBehaviour
|
||||
//{
|
||||
// public IPlayerAction _option;
|
||||
// public ConversationChangeEvent conversationChangeEvent;
|
||||
// // Update is called once per frame
|
||||
// public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, IPlayerAction option, int index)
|
||||
// {
|
||||
// int buttonSpacing = -50;
|
||||
|
||||
Button button = Instantiate(choiceButtonTemplate);
|
||||
// Button button = Instantiate(choiceButtonTemplate);
|
||||
|
||||
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.Description;
|
||||
button.gameObject.SetActive(true);
|
||||
ChoiceController choiceController = button.GetComponent<ChoiceController>();
|
||||
choiceController._option = option;
|
||||
return choiceController;
|
||||
}
|
||||
// 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.Description;
|
||||
// button.gameObject.SetActive(true);
|
||||
// ChoiceController choiceController = button.GetComponent<ChoiceController>();
|
||||
// choiceController._option = option;
|
||||
// return choiceController;
|
||||
// }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (conversationChangeEvent == null)
|
||||
conversationChangeEvent = new ConversationChangeEvent();
|
||||
var btn = GetComponent<Button>();
|
||||
// private void Start()
|
||||
// {
|
||||
// if (conversationChangeEvent == null)
|
||||
// conversationChangeEvent = new ConversationChangeEvent();
|
||||
// var btn = GetComponent<Button>();
|
||||
|
||||
var txt = btn.GetComponentInChildren<TextMeshProUGUI>();
|
||||
txt.text = _option.Description;
|
||||
}
|
||||
// var txt = btn.GetComponentInChildren<TextMeshProUGUI>();
|
||||
// txt.text = _option.Description;
|
||||
// }
|
||||
|
||||
public void MakeChoice()
|
||||
{
|
||||
conversationChangeEvent.Invoke(_option);
|
||||
}
|
||||
}
|
||||
// public void MakeChoice()
|
||||
// {
|
||||
// conversationChangeEvent.Invoke(_option);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
using Assets.Scripts.Actions.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
//using Assets.Scripts.Actions.Interfaces;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using TMPro;
|
||||
//using UnityEngine;
|
||||
//using UnityEngine.UI;
|
||||
|
||||
public class ConversationController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public TextMeshProUGUI _title;
|
||||
[SerializeField] public Button _choiceButton;
|
||||
[SerializeField] private Button _btnApply;
|
||||
[SerializeField] private Button _btnClose;
|
||||
//public class ConversationController : MonoBehaviour
|
||||
//{
|
||||
// [SerializeField] public TextMeshProUGUI _title;
|
||||
// [SerializeField] public Button _choiceButton;
|
||||
// [SerializeField] private Button _btnApply;
|
||||
// [SerializeField] private Button _btnClose;
|
||||
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
private List<ChoiceController> choiceControllers = new();
|
||||
// public ConversationChangeEvent conversationChangeEvent;
|
||||
// private List<ChoiceController> choiceControllers = new();
|
||||
|
||||
private IPlayerAction _selectedAction = null;
|
||||
// private IPlayerAction _selectedAction = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
// private void Awake()
|
||||
// {
|
||||
// Hide();
|
||||
// }
|
||||
|
||||
public void Change(string title, List<IPlayerAction> options)
|
||||
{
|
||||
_btnApply.interactable = false;
|
||||
// public void Change(string title, List<IPlayerAction> options)
|
||||
// {
|
||||
// _btnApply.interactable = false;
|
||||
|
||||
_btnClose.onClick.AddListener(() =>
|
||||
{
|
||||
Hide();
|
||||
});
|
||||
// _btnClose.onClick.AddListener(() =>
|
||||
// {
|
||||
// Hide();
|
||||
// });
|
||||
|
||||
_btnApply.onClick.AddListener(() =>
|
||||
{
|
||||
ApplyActionOnPlayer(_selectedAction);
|
||||
});
|
||||
// _btnApply.onClick.AddListener(() =>
|
||||
// {
|
||||
// ApplyActionOnPlayer(_selectedAction);
|
||||
// });
|
||||
|
||||
//Player.Instance.allowMovement = false;
|
||||
RemoveChoices();
|
||||
_title.text = title;
|
||||
gameObject.SetActive(true);
|
||||
// //Player.Instance.allowMovement = false;
|
||||
// RemoveChoices();
|
||||
// _title.text = title;
|
||||
// gameObject.SetActive(true);
|
||||
|
||||
for (var count = 0; count < options.Count; count++)
|
||||
{
|
||||
ChoiceController c = ChoiceController.AddChoiceButton(_choiceButton, options.ElementAt(count), count);
|
||||
c.conversationChangeEvent.AddListener(SelectAction);
|
||||
choiceControllers.Add(c);
|
||||
}
|
||||
// for (var count = 0; count < options.Count; count++)
|
||||
// {
|
||||
// ChoiceController c = ChoiceController.AddChoiceButton(_choiceButton, options.ElementAt(count), count);
|
||||
// c.conversationChangeEvent.AddListener(SelectAction);
|
||||
// choiceControllers.Add(c);
|
||||
// }
|
||||
|
||||
StopAllCoroutines();
|
||||
// StopAllCoroutines();
|
||||
|
||||
Time.timeScale = 0;
|
||||
_choiceButton.gameObject.SetActive(false);
|
||||
}
|
||||
// Time.timeScale = 0;
|
||||
// _choiceButton.gameObject.SetActive(false);
|
||||
// }
|
||||
|
||||
private void SelectAction(IPlayerAction action)
|
||||
{
|
||||
_selectedAction = action;
|
||||
if (action is ISellable)
|
||||
{
|
||||
// _btnApply.interactable = Player.Instance.Stats[StatsId.Money].Value >= (action as ISellable).Price;
|
||||
}
|
||||
}
|
||||
// private void SelectAction(IPlayerAction action)
|
||||
// {
|
||||
// _selectedAction = action;
|
||||
// if (action is ISellable)
|
||||
// {
|
||||
// // _btnApply.interactable = Player.Instance.Stats[StatsId.Money].Value >= (action as ISellable).Price;
|
||||
// }
|
||||
// }
|
||||
|
||||
private void ApplyActionOnPlayer(IPlayerAction action)
|
||||
{
|
||||
//if (action is ISellable)
|
||||
// Player.Instance.BuyAction(action);
|
||||
}
|
||||
private void RemoveChoices()
|
||||
{
|
||||
foreach (ChoiceController c in choiceControllers)
|
||||
{
|
||||
c.conversationChangeEvent.RemoveAllListeners();
|
||||
Destroy(c.gameObject);
|
||||
}
|
||||
choiceControllers.Clear();
|
||||
}
|
||||
// private void ApplyActionOnPlayer(IPlayerAction action)
|
||||
// {
|
||||
// //if (action is ISellable)
|
||||
// // Player.Instance.BuyAction(action);
|
||||
// }
|
||||
// private void RemoveChoices()
|
||||
// {
|
||||
// foreach (ChoiceController c in choiceControllers)
|
||||
// {
|
||||
// c.conversationChangeEvent.RemoveAllListeners();
|
||||
// Destroy(c.gameObject);
|
||||
// }
|
||||
// choiceControllers.Clear();
|
||||
// }
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
RemoveChoices();
|
||||
gameObject.SetActive(false);
|
||||
Time.timeScale = 1;
|
||||
//Player.Instance.allowMovement = true;
|
||||
}
|
||||
}
|
||||
// public void Hide()
|
||||
// {
|
||||
// RemoveChoices();
|
||||
// gameObject.SetActive(false);
|
||||
// Time.timeScale = 1;
|
||||
// //Player.Instance.allowMovement = true;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
//using TMPro;
|
||||
//using UnityEngine;
|
||||
//using UnityEngine.UI;
|
||||
|
||||
public class ItemActionsUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _title;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _description;
|
||||
//public class ItemActionsUI : MonoBehaviour
|
||||
//{
|
||||
// [SerializeField]
|
||||
// private TextMeshProUGUI _title;
|
||||
// [SerializeField]
|
||||
// private TextMeshProUGUI _description;
|
||||
|
||||
[SerializeField]
|
||||
private Button _btnCancel;
|
||||
// [SerializeField]
|
||||
// private Button _btnCancel;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
// private void Start()
|
||||
// {
|
||||
// Hide();
|
||||
// }
|
||||
|
||||
public void Show(string title, string description)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
_title.text = title;
|
||||
_description.text = description;
|
||||
// public void Show(string title, string description)
|
||||
// {
|
||||
// gameObject.SetActive(true);
|
||||
// _title.text = title;
|
||||
// _description.text = description;
|
||||
|
||||
_btnCancel.onClick.AddListener(() =>
|
||||
{
|
||||
Hide();
|
||||
});
|
||||
}
|
||||
// _btnCancel.onClick.AddListener(() =>
|
||||
// {
|
||||
// Hide();
|
||||
// });
|
||||
// }
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
// private void Hide()
|
||||
// {
|
||||
// gameObject.SetActive(false);
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user