private void B_Click() { switch (GlobalTool.ButtonNameParent) { case "ButtonSearch": { ObservableCollection <ParentCard> reCard = new ObservableCollection <ParentCard>(); if (GlobalTool.BoolColor == true) { //按颜色查父本 if (GlobalTool.IndexColor == 0) { GlobalTool.OpenDialogButton(_syncContextTaskScheduler, "没有选择颜色"); return; } if (SelectedColorDic == null || SelectedColorDic.Count == 0) { return; } foreach (var everyflower in SelectedColorDic) { var parent = FlowerHelper.GetMyParent(everyflower); foreach (var a in parent) { var aa = new ParentCard(a); bool inResult = false; foreach (var b in reCard) { if (b.TextGeneLeft == aa.TextGeneLeft && b.TextGeneRight == aa.TextGeneRight) { inResult = true; } } if (!inResult) { reCard.Add(aa); } } } } if (GlobalTool.BoolGene == true) { //按基因型查父本 Gene a1 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1); Gene a2 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2); Gene a3 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3); Gene a4 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4); MyFlower f = new MyFlower(SelectedFlower, a1, a2, a3, a4); var re = FlowerHelper.GetMyParent(f); foreach (var a in re) { reCard.Add(new ParentCard(a)); } } Task.Factory.StartNew(() => ShowData(reCard), new CancellationTokenSource().Token, TaskCreationOptions.None, _syncContextTaskScheduler).Wait(); } break; } }
void PopulateLayers() { CardManager.UnloadAll(); List <CardData> loadedCards = CardManager.LoadFolder(StoryFolder, true, PathType, SearchOption.AllDirectories); List <StoryData> storyCards = new List <StoryData>(); List <SectionData> sectionCards = new List <SectionData>(); List <LineData> lineCards = new List <LineData>(); List <CardData> wordCards = new List <CardData>(); foreach (CardData card in loadedCards) { switch (card.CardType) { case "StoryData": storyCards.Add((StoryData)card); break; case "SectionData": sectionCards.Add((SectionData)card); break; case "LineData": lineCards.Add((LineData)card); break; case "CardData": wordCards.Add(card); break; default: break; } } Transform storyGroup = GameObject.Instantiate(LayoutGroupPrefab, transform).transform; storyGroup.name = "StoryGroup"; Transform sectionGroup = GameObject.Instantiate(LayoutGroupPrefab, transform).transform; sectionGroup.name = "SectionGroup"; Transform LineGroup = GameObject.Instantiate(LayoutGroupPrefab, transform).transform; LineGroup.name = "LineGroup"; Transform WordGroup = GameObject.Instantiate(LayoutGroupPrefab, transform).transform; WordGroup.name = "WordGroup"; //Make word group smaller to fit more cards WordGroup.GetComponent <RectTransform>().localScale = new Vector3(.8f, .8f, .8f); Dictionary <string, GameObject> cardRefs = new Dictionary <string, GameObject>(); //Create card gameObjects and add them to dictionary storyCards.ForEach(x => cardRefs.Add(x.UID, CreateCardInGroup(x, storyGroup))); sectionCards.ForEach(x => cardRefs.Add(x.UID, CreateCardInGroup(x, sectionGroup))); lineCards.ForEach(x => cardRefs.Add(x.UID, CreateCardInGroup(x, LineGroup))); wordCards.ForEach(x => cardRefs.Add(x.UID, CreateCardInGroup(x, WordGroup))); //Add child references to each card through ParentCard for all except for line foreach (StoryData story in storyCards) { string UID = story.UID; GameObject go = cardRefs[UID]; ParentCard parenter = go.AddComponent <ParentCard>(); parenter.LineCards = story.SectionsUID.ConvertAll <GameObject>(s => cardRefs[s]); //Layer must count downward for each level parenter.LayoutLayer = (int)ParentCard.Layer.Story; parenter.cardsLayout = sectionGroup; parenter.HideTransform = CardHideArea; parenter.HideCards(); } foreach (SectionData section in sectionCards) { string UID = section.UID; GameObject go = cardRefs[UID]; ParentCard parenter = go.AddComponent <ParentCard>(); //parenter.LineCards = section.LinesUID.ConvertAll<GameObject>(s => cardRefs[s]); for (int i = 0; i < section.LinesUID.Count; i++) { GameObject foundObject = null; if (cardRefs.TryGetValue(section.LinesUID[i], out foundObject)) { parenter.LineCards.Add(foundObject); } else { Debug.LogError($"{section.To}\n{section.BrokenUpTo.Split()[i]}\n{section.PhoneticFrom.Split()[i]}"); } } parenter.LayoutLayer = (int)ParentCard.Layer.Section; parenter.cardsLayout = LineGroup; parenter.HideTransform = CardHideArea; parenter.HideCards(); parenter.HideSelf(); } foreach (LineData line in lineCards) { string UID = line.UID; GameObject go = cardRefs[UID]; ParentCard parenter = go.AddComponent <ParentCard>(); parenter.LineCards = line.CardsUID.ConvertAll <GameObject>(s => cardRefs[s]); //Layer must count downward for each level parenter.LayoutLayer = (int)ParentCard.Layer.Line; parenter.cardsLayout = WordGroup; parenter.HideTransform = CardHideArea; parenter.HideCards(); parenter.HideSelf(); } //Don't add trigger to start game here anymore foreach (CardData word in wordCards) { string UID = word.UID; GameObject go = cardRefs[UID]; ParentCard parenter = go.AddComponent <ParentCard>(); parenter.LayoutLayer = (int)ParentCard.Layer.Word; parenter.cardsLayout = null; parenter.HideTransform = CardHideArea; parenter.HideCards(); parenter.HideSelf(); //Don't trigger game from here //GameLineTrigger trigger = go.AddComponent<GameLineTrigger>(); //trigger.PathType = PathType; //trigger.Folder = StoryFolder; } }
private void Button_Click(object sender, RoutedEventArgs e) { if (GlobalTool.NaviViewMain.SelectedItem != GlobalTool.NaviItemParent) { return; } ObservableCollection <ParentCard> reCard = new ObservableCollection <ParentCard>(); GlobalTool.ShowProgress(); Task.Factory.StartNew(() => { if (GlobalTool.BoolColor == true) {//按颜色查父本 if (GlobalTool.IndexColor == 0) { GlobalTool.TipSearch.IsOpen = true; return; } if (SelectedColorDic == null || SelectedColorDic.Count == 0) { return; } foreach (var everyflower in SelectedColorDic) { var parent = FlowerHelper.GetMyParent(everyflower); foreach (var a in parent) { var aa = new ParentCard(a); bool inResult = false; foreach (var b in reCard) { if (b.TextGeneLeft == aa.TextGeneLeft && b.TextGeneRight == aa.TextGeneRight) { inResult = true; } } if (!inResult) { reCard.Add(aa); } } } } if (GlobalTool.BoolGene == true) {//按基因型查父本 Gene a1 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1); Gene a2 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2); Gene a3 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3); Gene a4 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4); MyFlower f = new MyFlower(GlobalTool.SelectedFlower, a1, a2, a3, a4); var re = FlowerHelper.GetMyParent(f); foreach (var a in re) { reCard.Add(new ParentCard(a)); } } Sync.Post((o) => { GlobalTool.CloseProgress(); var r = o as ObservableCollection <ParentCard>; ListViewParent.ItemsSource = r; }, reCard); }); }