| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Linq;
- public class SelectCategoryScript : MonoBehaviour
- {
- [SerializeField] Button doneButton;
- [SerializeField] Button closeButton;
- [SerializeField] GameObject CategoryToSelectPrefab;
- [SerializeField] GameObject SelectCategoryPanel;
- [SerializeField] GameObject ContentPanel;
- // Start is called before the first frame update
- private List<CategoryPanel.Category> categories;
- private void Start() {
- doneButton.onClick.AddListener(CloseDialogAction);
- closeButton.onClick.AddListener(CloseDialogAction);
- if (categories == null) {
- categories = new List<CategoryPanel.Category>();
- }
- categories = OnlineDatabase.Instance.GetCategories(categories);
- foreach (CategoryPanel.Category cat in categories)
- {
- GameObject go = Instantiate(CategoryToSelectPrefab, Vector3.zero, Quaternion.identity);
- CategorySelection c = go.GetComponent<CategorySelection>();
- c.SetSelected(true);
- c.SetCategoryText(cat.name, cat.questionCount);
- c.transform.localScale = new Vector3(1,1,1);
- c.transform.SetParent(ContentPanel.transform, false);
- }
- }
- internal void CloseDialogAction() {
- SelectCategoryPanel.GetComponent<selectCategoriesPanelController>().UpdateCategoryText();
- gameObject.SetActive(false);
- }
- internal int GetSelectedCategoriesQuestionCount()
- {
- return 0;
- }
- internal string GetCategoriesSelectedCount()
- {
- string returnValue;
- int selectionCount = GetSelectedCategoriesAsList().Count;
- if (selectionCount == categories.Count)
- {
- returnValue = LocalizationManager.Instance.GetText("ALL");
- }
- else
- {
- returnValue = selectionCount.ToString();
- }
- return returnValue;
- }
- private List<CategorySelection> GetSelectedCategoriesAsList()
- {
- return ContentPanel.GetComponentsInChildren<CategorySelection>().Where(c => c.isSelected()).ToList();
- }
- public List<CategoryPanel.Category> GetSelectedCategories() {
- List<string> categoriesName = categories.Select(c1 => c1.name).ToList();
- List<string> selectedCategoyNames = GetSelectedCategoriesAsList().Select(c2 => c2.getCategoryName()).ToList();
- List<string> names = categoriesName.Intersect(selectedCategoyNames).ToList();
- return categories.Where(c => names.Contains(c.name)).ToList();
- }
- internal void ShowDialog()
- {
- gameObject.SetActive(true);
- }
- }
|