|
1 | 1 | using System.Collections.Generic; |
| 2 | +using System.Linq; |
2 | 3 | using System.Text; |
3 | 4 | using System.Windows; |
4 | 5 | using System.Windows.Input; |
@@ -118,21 +119,37 @@ private void ButtonCardName_Click(object sender, RoutedEventArgs e) |
118 | 119 | return; |
119 | 120 | } |
120 | 121 |
|
| 122 | + var dictionary = new Dictionary<string, Card>(); |
121 | 123 | var cardList = Cards.GetFromFuzzyName(name, Locale.zhCN, false); |
122 | | - if (cardList.Count == 0) |
| 124 | + foreach (var item in cardList) |
| 125 | + { |
| 126 | + AddItemToDictionary(dictionary, item); |
| 127 | + } |
| 128 | + cardList = Cards.GetFromFuzzyName(name, Locale.enUS, false); |
| 129 | + foreach (var item in cardList) |
123 | 130 | { |
124 | | - cardList = Cards.GetFromFuzzyName(name, Locale.enUS, false); |
| 131 | + AddItemToDictionary(dictionary, item); |
125 | 132 | } |
126 | 133 |
|
127 | | - if (cardList == null || cardList.Count == 0) |
| 134 | + if (dictionary.Count == 0) |
128 | 135 | { |
129 | 136 | MessageBox.Show($"Can not find the card with name {name} in English(en-US) or Chinese(zh-CN)"); |
130 | 137 | return; |
131 | 138 | } |
132 | 139 |
|
| 140 | + cardList = dictionary.Values.ToList(); |
133 | 141 | AddCardToListView(cardList); |
134 | 142 | } |
135 | 143 |
|
| 144 | + private void AddItemToDictionary(Dictionary<string, Card> dictionary, Card card) |
| 145 | + { |
| 146 | + var cardId = card.Id; |
| 147 | + if (!dictionary.ContainsKey(cardId)) |
| 148 | + { |
| 149 | + dictionary.Add(cardId, card); |
| 150 | + } |
| 151 | + } |
| 152 | + |
136 | 153 | private void AddCardToListView(List<Card> cards) |
137 | 154 | { |
138 | 155 | foreach (var card in cards) |
|
0 commit comments