JobBoardBehaviour.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using DataTools;
  4. public class JobBoardBehaviour : MonoBehaviour
  5. {
  6. [Header("Data")]
  7. [SerializeField] private DataGigTemplates dataTemplates;
  8. [Header("Instant gig panel")]
  9. [SerializeField] private InstaGigs instaGigs;
  10. [Header("Job Cards")]
  11. [SerializeField] private List<JobCardManager> jobCards;
  12. [Header("Allowed gig types")]
  13. [SerializeField] private List<DataTools.GigType> allowedTypes;
  14. private void SetupJobBoard()
  15. {
  16. foreach(JobCardManager jobCard in jobCards)
  17. {
  18. setupJobCard(jobCard);
  19. }
  20. }
  21. private void setupJobCard(JobCardManager card)
  22. {
  23. bool done = false;
  24. while(!done)
  25. {
  26. DataTools.Gig gig = dataTemplates.atlas.GetRandomOfTypeOnLocation(location, allowedTypes[Random.Range(0, allowedTypes.Count)]);
  27. if(!names.Contains(gig.Description))
  28. {
  29. names.Add(gig.Description);
  30. card.AddGig(gig);
  31. done = true;
  32. }
  33. }
  34. }
  35. private void Start()
  36. {
  37. instaGigs = GameObject.FindObjectOfType<InstaGigs>();
  38. GameGlobal.Instance.OnLocationChanged += Reload;
  39. mainStoryGigs = new List<GigsBase>(FindObjectsOfType<GigsBase>());
  40. mainStoryGigs.RemoveAll(g => !g.IsMainStoryGig);
  41. }
  42. private void Reload(Location l)
  43. {
  44. needToReload = true;
  45. }
  46. private void OnEnable()
  47. {
  48. if(needToReload)
  49. {
  50. location = GameGlobal.Instance.Location;
  51. SetupJobBoard();
  52. needToReload = false;
  53. }
  54. }
  55. public void ClosePanel()
  56. {
  57. MenuOld.Instance.GoToMainPanel();
  58. }
  59. public void StartGig(DataTools.Gig gig, JobCardManager sender)
  60. {
  61. if (instaGigs != null)
  62. {
  63. instaGigs.GenerateGigs(gig);
  64. }
  65. BlockerManager.Instance.UnblockAllButtons(GameplayManager.instance.isFirstGigPassed);
  66. GameGlobal.Instance.PannigLocked = false;
  67. MenuOld.Instance.GoToMainPanel();
  68. //************************
  69. setupJobCard(sender);
  70. }
  71. private void Update()
  72. {
  73. foreach(JobCardManager jobcard in jobCards)
  74. {
  75. jobcard.UpdateButton(!mainStoryGigs.Exists(g => g.HasGigsRemaining) && !instaGigs.HasGigsRemaining);
  76. }
  77. }
  78. private string location = "";
  79. private bool needToReload = true;
  80. private List<GigsBase> mainStoryGigs;
  81. private List<string> names = new List<string>();
  82. }