/// <summary> /// Creates a Selection Button for CardData /// </summary> /// <param name="parent"></param> /// <returns></returns> public DerivedCardDataSelectionButton CreateCardDataSelectionButton(Transform parent) { GameObject sbp = GameObject.Instantiate(SelectionButtonPrefab); DontDestroyOnLoad(sbp); sbp.transform.SetParent(parent); DerivedCardDataSelectionButton sb = sbp.AddComponent <DerivedCardDataSelectionButton>(); sb.plugin = this; sb.OnClick += OnClickCardData; sb.UpdateTextFunc += GetCardDataName; return(sb); }
public void InitializeCardDataBase() { if (currentSave != null && data != null) { List <CardData> dataList = data.GetAllCardData().Where(x => x.GetRarity() != CollectableRarity.Champion).OrderBy(x => x.GetName()).ToList(); for (int i = 0; i < dataList.Count; i++) { DerivedCardDataSelectionButton selectionButton = CreateCardDataSelectionButton(CardDatabaseContent.transform); selectionButton.UpdateText(dataList[i]); AllGameDataSelectionButtonsPool.Add(selectionButton); } } }
/// <summary> /// Updates the Databases based on search parameter /// </summary> /// <param name="newSearch"></param> public void UpdateDatabases(string newSearch) { search = newSearch; if (currentSave != null && data != null) { //Go Through DataList Realigning new Items, in case a mod has been enabled or disabled List <CardData> dataList = data.GetAllCardData().Where(x => x.GetRarity() != CollectableRarity.Champion).OrderBy(x => x.GetName()).ToList(); if (dataList.Count != AllGameDataSelectionButtonsPool.Count) { for (int j = 0; j < AllGameDataSelectionButtonsPool.Count; j++) { AllGameDataSelectionButtonsPool[j].UpdateText(dataList[j]); } for (int i = AllGameDataSelectionButtonsPool.Count; i < dataList.Count; i++) { DerivedCardDataSelectionButton selectionButton = CreateCardDataSelectionButton(CardDatabaseContent.transform); selectionButton.UpdateText(dataList[i]); AllGameDataSelectionButtonsPool.Add(selectionButton); } } List <CollectableRelicData> relicDataList = data.GetAllCollectableRelicData().OrderBy(x => x.GetName()).ToList(); if (relicDataList.Count != RelicDataSelectionButtonsPool.Count) { for (int j = 0; j < RelicDataSelectionButtonsPool.Count; j++) { RelicDataSelectionButtonsPool[j].UpdateText(relicDataList[j]); } for (int i = RelicDataSelectionButtonsPool.Count; i < relicDataList.Count; i++) { DerivedRelicDataSelectionButton selectionButton = CreateRelicDataSelectionButton(RelicDatabaseContent.transform); selectionButton.UpdateText(relicDataList[i]); RelicDataSelectionButtonsPool.Add(selectionButton); } } //Do Search Culling (WIP) string searchCopy = string.Copy(search).ToLower(); foreach (ClassData clan in data.GetAllClassDatas()) { if (searchCopy.Contains($"[{clan.GetTitle().ToLower()}]")) { Logger.LogInfo($"Search contains tag: [{clan}]"); dataList = dataList.Where((x) => (x.GetLinkedClass() == clan)).ToList(); searchCopy.Replace($"[{clan.ToString().ToLower()}]", ""); } } //Go through each database and cull based on search results dataList = dataList.Where((x) => x.GetName().ToLower().Contains(searchCopy)).ToList(); for (int i = 0; i < dataList.Count; i++) { AllGameDataSelectionButtonsPool[i].gameObject.SetActive(true); AllGameDataSelectionButtonsPool[i].UpdateText(dataList[i]); } for (int j = dataList.Count; j < AllGameDataSelectionButtonsPool.Count; j++) { AllGameDataSelectionButtonsPool[j].gameObject.SetActive(false); } relicDataList = relicDataList.Where(x => x.GetName().ToLower().Contains(searchCopy)).ToList(); for (int ri = 0; ri < relicDataList.Count; ri++) { RelicDataSelectionButtonsPool[ri].gameObject.SetActive(true); RelicDataSelectionButtonsPool[ri].UpdateText(relicDataList[ri]); } for (int rj = relicDataList.Count; rj < RelicDataSelectionButtonsPool.Count; rj++) { RelicDataSelectionButtonsPool[rj].gameObject.SetActive(false); } UpdateUpgradeDatabaseBySearchString(search); } }