RecruitDialogueUI.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using TMPro;
  4. public class RecruitDialogueUI : MonoBehaviour
  5. {
  6. public static RecruitDialogueUI Instance;
  7. public GameObject panel;
  8. public TextMeshProUGUI messageText;
  9. public Button yesButton;
  10. public Button noButton;
  11. private RecruitableCharacter currentRecruit;
  12. private void Awake()
  13. {
  14. Instance = this;
  15. panel.SetActive(false); // Panel caché au démarrage
  16. }
  17. public void ShowRecruitDialog(RecruitableCharacter recruit)
  18. {
  19. currentRecruit = recruit;
  20. messageText.text = "Bonjour, puis-je me joindre à vous ?";
  21. panel.SetActive(true);
  22. yesButton.onClick.RemoveAllListeners();
  23. noButton.onClick.RemoveAllListeners();
  24. yesButton.onClick.AddListener(() =>
  25. {
  26. AddToParty(currentRecruit);
  27. panel.SetActive(false);
  28. Destroy(currentRecruit.gameObject);
  29. });
  30. noButton.onClick.AddListener(() =>
  31. {
  32. panel.SetActive(false);
  33. });
  34. }
  35. public void Hide()
  36. {
  37. panel.SetActive(false);
  38. }
  39. void AddToParty(RecruitableCharacter recruit)
  40. {
  41. if (FindObjectOfType<TeamCohesionManager>().groupMembers.Count >= 5)
  42. {
  43. return;
  44. }
  45. var newChar = recruit.GenerateCharacter();
  46. TeamCohesionManager team = FindObjectOfType<TeamCohesionManager>();
  47. var existing = team.groupMembers;
  48. for (int y = 0; y < 5; y++)
  49. {
  50. for (int x = 0; x < 5; x++)
  51. {
  52. bool used = existing.Exists(c => c.gridX == x && c.gridY == y);
  53. if (!used)
  54. {
  55. newChar.gridX = x;
  56. newChar.gridY = y;
  57. team.groupMembers.Add(newChar);
  58. PositionGridManager grid = FindObjectOfType<PositionGridManager>();
  59. if (grid != null)
  60. {
  61. grid.AddCharacter(newChar);
  62. }
  63. PartyUIManager ui = FindObjectOfType<PartyUIManager>();
  64. ui.DisplayPartyUI();
  65. return;
  66. }
  67. }
  68. }
  69. }
  70. }