| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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);
- GetCategories();
- int pos = 0;
- 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.SetSiblingIndex(pos++);
- c.transform.localScale = new Vector3(1, 1, 1);
- c.transform.SetParent(ContentPanel.transform, false);
- }
- }
- private void GetCategories()
- {
- if (categories == null || categories.Count == 0) {
- categories = new List<CategoryPanel.Category>();
- categories = OnlineDatabase.Instance.GetCategories(categories, -1);
- }
- }
- 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() {
- GetCategories();
- 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);
- }
- }
|