1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using KairoEngine.UI.InteractionHandler;
- using KairoEngine.Core;
- namespace KairoEngine.UI.Encyclopedia
- {
- [HideMonoScript]
- public class EncyclopediaController : MonoBehaviour, IClickHandler
- {
- public static EncyclopediaController instance;
- [ShowInInspector, HorizontalGroup("IndexLine", 0.7f), LabelText("Index")] public int menuIndex;
- [ShowInInspector, HorizontalGroup("IndexLine", 0.3f), HideLabel] public int subMenuIndex;
- public EncyclopediaUi encyclopediaUi;
- public GameObject categoryButtomPrefab;
- public List<EncyclopediaCategory> categories = new List<EncyclopediaCategory>();
- private void Awake()
- {
- if(instance == null) instance = this;
- else Destroy(this);
- }
- [Button("Build Menu"), ButtonGroup("Buttons")]
- public void BuildMenu()
- {
- if(encyclopediaUi != null) encyclopediaUi.Populate();
- else Debug.LogError("Missing Encyclopedia UI in Encyclopedia Controller", this.gameObject);
- }
- public void OnClick(string id)
- {
- for (int i = 0; i < categories.Count; i++)
- {
- if(id == categories[i].id)
- {
- menuIndex = i;
- Navigate();
- return;
- }
- var articles = categories[i].GetArticles();
- for (int a = 0; a < articles.Count; a++)
- {
- if(id == articles[a].id)
- {
- menuIndex = i;
- subMenuIndex = a;
- Navigate();
- return;
- }
- }
- }
- }
- [Button("Navigate"), ButtonGroup("Buttons")]
- public void Navigate()
- {
- if(encyclopediaUi != null) encyclopediaUi.Navigate();
- GenericEvents.Trigger("OpeningEncyclopediaArticle", menuIndex, subMenuIndex);
- }
- public EncyclopediaCategory GetCategory(int categoryIndex) => categories[categoryIndex];
- public EncyclopediaArticle GetArticle(int categoryIndex, int articleIndex)
- {
- var category = categories[categoryIndex];
- var articles = category.GetArticles();
- if(articleIndex < articles.Count) return articles[articleIndex];
- else return null;
- }
- }
- }
|