Fix shop System
add food indicator
This commit is contained in:
@@ -1,61 +1,46 @@
|
||||
using Assets.Scripts.Actions;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[System.Serializable]
|
||||
public class ConversationChangeEvent : UnityEvent<BaseAction> { }
|
||||
|
||||
public class ChoiceController : MonoBehaviour
|
||||
{
|
||||
public PlayerController playerController;
|
||||
public KeyValuePair<string, BaseAction> _option;
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
// Update is called once per frame
|
||||
public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, KeyValuePair<string, BaseAction> option, int index)
|
||||
{
|
||||
int buttonSpacing = -50;
|
||||
|
||||
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.Key;
|
||||
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>();
|
||||
|
||||
var txt = btn.GetComponentInChildren<TextMeshProUGUI>();
|
||||
txt.text = _option.Key;
|
||||
}
|
||||
|
||||
public void MakeChoice()
|
||||
{
|
||||
if (playerController.TryBuyAction(_option.Value))
|
||||
{
|
||||
conversationChangeEvent.Invoke(_option.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
YesNoDialogUI.Instance.ShowQuestion("not enouth money",
|
||||
() =>
|
||||
{
|
||||
},
|
||||
() =>
|
||||
{
|
||||
//do nothing
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
using Assets.Scripts.Actions;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[System.Serializable]
|
||||
public class ConversationChangeEvent : UnityEvent<BaseAction> { }
|
||||
|
||||
public class ChoiceController : MonoBehaviour
|
||||
{
|
||||
public KeyValuePair<string, BaseAction> _option;
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
// Update is called once per frame
|
||||
public static ChoiceController AddChoiceButton(Button choiceButtonTemplate, KeyValuePair<string, BaseAction> option, int index)
|
||||
{
|
||||
int buttonSpacing = -50;
|
||||
|
||||
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.Key;
|
||||
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>();
|
||||
|
||||
var txt = btn.GetComponentInChildren<TextMeshProUGUI>();
|
||||
txt.text = _option.Key;
|
||||
}
|
||||
|
||||
public void MakeChoice()
|
||||
{
|
||||
conversationChangeEvent.Invoke(_option.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,85 @@
|
||||
using Assets.Scripts.Actions;
|
||||
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]
|
||||
using Assets.Scripts.Actions;
|
||||
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 _closeBtn;
|
||||
|
||||
[SerializeField]
|
||||
CharacterMovement _player;
|
||||
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
private List<ChoiceController> choiceControllers = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Change(string title, Dictionary<string, BaseAction> options)
|
||||
[SerializeField]
|
||||
PlayerManager _playerManager;
|
||||
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
private List<ChoiceController> choiceControllers = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Change(string title, Dictionary<string, BaseAction> options)
|
||||
{
|
||||
_closeBtn.onClick.AddListener(() =>
|
||||
{
|
||||
Hide();
|
||||
});
|
||||
|
||||
_player.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);
|
||||
choiceControllers.Add(c);
|
||||
}
|
||||
|
||||
StopAllCoroutines();
|
||||
|
||||
|
||||
Time.timeScale = 0;
|
||||
_choiceButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void RemoveChoices()
|
||||
{
|
||||
foreach (ChoiceController c in choiceControllers)
|
||||
Destroy(c.gameObject);
|
||||
|
||||
choiceControllers.Clear();
|
||||
}
|
||||
public void Hide()
|
||||
{
|
||||
RemoveChoices();
|
||||
gameObject.SetActive(false);
|
||||
Time.timeScale = 1;
|
||||
_player.allowMovement = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_playerManager.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(ApplyActionOnPlayer);
|
||||
choiceControllers.Add(c);
|
||||
}
|
||||
|
||||
StopAllCoroutines();
|
||||
|
||||
|
||||
Time.timeScale = 0;
|
||||
_choiceButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void ApplyActionOnPlayer(BaseAction action)
|
||||
{
|
||||
if (!_playerManager.TryBuyAction(action))
|
||||
{
|
||||
YesNoDialogUI.Instance.ShowQuestion("not enouth money",
|
||||
() =>
|
||||
{
|
||||
},
|
||||
() =>
|
||||
{
|
||||
//do nothing
|
||||
});
|
||||
}
|
||||
}
|
||||
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;
|
||||
_playerManager.allowMovement = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user