NewOnlineGameScript.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7. using System.Linq;
  8. public class NewOnlineGameScript : MonoBehaviour
  9. {
  10. public Slider answerTimeSlider;
  11. public Slider daysToAnswerSlider;
  12. public Slider correctsToWinSlider;
  13. public GameObject invitePanel;
  14. [SerializeField] Button StartButton;
  15. [SerializeField] GameObject categoryPanel;
  16. private InvitePanelScript ips;
  17. private selectCategoriesPanelController selectedCategoriesController;
  18. // Start is called before the first frame update
  19. void Start()
  20. {
  21. StartButton.onClick.AddListener(StartNewOnlineGame);
  22. StartButton.interactable = false;
  23. ips = invitePanel.GetComponent<InvitePanelScript>();
  24. selectedCategoriesController = categoryPanel.GetComponent<selectCategoriesPanelController>();
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. if (ips.AreThereInvites() &&
  30. selectedCategoriesController.GetSelectedCategories().Sum(c => c.questionCount) > 0) { // Fungerar ej, stoppar inte vid 0
  31. StartButton.interactable = true;
  32. }
  33. // TODO, make sure there are enough questions selected in categories
  34. }
  35. void StartNewOnlineGame() {
  36. List<InviteSearchResult> inviteUsers = ips.GetSelectedUsersForInvite();
  37. List<CategoryPanel.Category> selectedCategories = selectedCategoriesController.GetSelectedCategories();
  38. List<int> selectedCategoryIds = selectedCategories.Select(c => c.id).ToList();
  39. OnlineDatabase.Instance.SetupNewOnlineGame((int)answerTimeSlider.value, (int)daysToAnswerSlider.value, (int)correctsToWinSlider.value, inviteUsers, selectedCategoryIds);
  40. SceneManager.LoadScene("MainMenu");
  41. }
  42. }