1
- using OutwardEnchanter . Helpers ;
1
+ using Mono . Cecil ;
2
+ using OutwardEnchanter . Helpers ;
2
3
using SideLoader . Helpers ;
3
4
using System ;
4
5
using System . Collections . Generic ;
5
6
using System . Linq ;
7
+ using System . Reflection ;
6
8
using UnityEngine ;
7
9
using UnityEngine . UI ;
8
10
@@ -26,6 +28,9 @@ public class GUIMainCanvasManager : MonoBehaviour
26
28
private Dropdown _chooseItemDropdown ;
27
29
private Dropdown _chooseEnchantmentDropdown ;
28
30
31
+ private InputField _itemFilterInput ;
32
+ private InputField _enchantmentFilterInput ;
33
+
29
34
private GUIMainCanvasManager ( )
30
35
{
31
36
try
@@ -63,6 +68,9 @@ public static GUIMainCanvasManager Instance
63
68
public Dictionary < string , Equipment > EquipmentDictionary { get => _equipmentDictionary ; set => _equipmentDictionary = value ; }
64
69
public Dictionary < string , EnchantmentRecipe > EnchantmentRecipeDictionary { get => _enchantmentRecipeDictionary ; set => _enchantmentRecipeDictionary = value ; }
65
70
71
+ public InputField EnchantmentFilterInput { get => _enchantmentFilterInput ; set => _enchantmentFilterInput = value ; }
72
+ public InputField ItemFilterInput { get => _itemFilterInput ; set => _itemFilterInput = value ; }
73
+
66
74
public void Init ( )
67
75
{
68
76
string mainPanelPath = "Background-Panel/Main-Panel/" ;
@@ -135,6 +143,38 @@ public void Init()
135
143
{
136
144
ResultAndLogMessage ( "Couldn't find Enchantments Dropdown component" ) ;
137
145
}
146
+
147
+ ItemFilterInput = this . transform . Find ( mainPanelPath + "Middle-Panel/ItemFilter-Panel/ItemFilter-Input" ) ? . GetComponent < InputField > ( ) ;
148
+
149
+ if ( ItemFilterInput == null )
150
+ {
151
+ ResultAndLogMessage ( "Couldn't find Item Filter Input component" ) ;
152
+ }
153
+ else
154
+ {
155
+ ItemFilterInput . onEndEdit . AddListener ( HandleOnItemFilterEnd ) ;
156
+ }
157
+
158
+ EnchantmentFilterInput = this . transform . Find ( mainPanelPath + "Middle-Panel/EnchantmentFilter-Panel/EnchantmentFilter-Input" ) ? . GetComponent < InputField > ( ) ;
159
+
160
+ if ( EnchantmentFilterInput == null )
161
+ {
162
+ ResultAndLogMessage ( "Couldn't find Enchantment Filter Input component" ) ;
163
+ }
164
+ else
165
+ {
166
+ EnchantmentFilterInput . onEndEdit . AddListener ( HandleOnEnchantmentFilterEnd ) ;
167
+ }
168
+ }
169
+
170
+ public void HandleOnItemFilterEnd ( string text )
171
+ {
172
+ FilterItemsData ( text ) ;
173
+ }
174
+
175
+ public void HandleOnEnchantmentFilterEnd ( string text )
176
+ {
177
+ FilterEnchantmentsData ( text ) ;
138
178
}
139
179
140
180
public void HandleOnEnchantButtonClick ( )
@@ -215,52 +255,114 @@ public void HandleOnChooseItemChange(int index)
215
255
{
216
256
try
217
257
{
218
- string selectedValue = ChooseItemDropdown . options [ index ] . text ;
219
- if ( ! EquipmentDictionary . TryGetValue ( selectedValue , out Equipment equipment ) )
258
+ FilterEnchantmentsData ( EnchantmentFilterInput . text ) ;
259
+ }
260
+ catch ( Exception ex )
261
+ {
262
+ OutwardEnchanter . LogMessage ( "GUIMainCanvasManager@HandleOnChooseItemChange error: " + ex . Message ) ;
263
+ }
264
+ }
265
+
266
+ public string GetUniqueEnchantmentsName ( EnchantmentRecipe recipe )
267
+ {
268
+ Enchantment enchantment = null ;
269
+ string keyName = "" ;
270
+
271
+ keyName = recipe . name ;
272
+
273
+ if ( keyName == "" )
274
+ {
275
+ enchantment = ResourcesPrefabManager . Instance . GetEnchantmentPrefab ( recipe . RecipeID ) ;
276
+
277
+ if ( enchantment == null )
220
278
{
221
- return ;
279
+ return null ;
222
280
}
223
281
224
- List < EnchantmentRecipe > availableRecipes = EnchantmentsHelper . GetAvailableEnchantmentRecipies ( equipment ) ;
225
- EnchantmentRecipeDictionary = new Dictionary < string , EnchantmentRecipe > ( ) ;
226
- List < string > availableRecipesOptions = new List < string > ( ) ;
227
- Enchantment enchantment = null ;
228
- string keyName = "" ;
282
+ keyName = enchantment . PresetID + "_" + enchantment . Name ;
283
+ }
229
284
230
- foreach ( EnchantmentRecipe recipe in availableRecipes )
231
- {
285
+ //some modders included duplicate names
286
+ if ( EnchantmentRecipeDictionary . TryGetValue ( keyName , out EnchantmentRecipe foundEnchantment ) )
287
+ {
288
+ keyName += "_" + Guid . NewGuid ( ) ;
289
+ }
232
290
233
- keyName = recipe . name ;
291
+ return keyName ;
292
+ }
234
293
235
- if ( keyName == "" )
236
- {
237
- enchantment = ResourcesPrefabManager . Instance . GetEnchantmentPrefab ( recipe . RecipeID ) ;
294
+ public string GetUniqueEquipmentsName ( Equipment equipment )
295
+ {
296
+ string keyName = "" ;
297
+
298
+ keyName = equipment . ItemID + "_" + equipment . Name . Replace ( " " , "_" ) ;
238
299
239
- if ( enchantment == null )
240
- {
241
- continue ;
242
- }
300
+ //some modders included duplicate names
301
+ if ( EquipmentDictionary . TryGetValue ( keyName , out Equipment foundEquipment ) )
302
+ {
303
+ keyName += "_" + Guid . NewGuid ( ) ;
304
+ }
243
305
244
- keyName = enchantment . PresetID + "_" + enchantment . Name ;
245
- }
306
+ return keyName ;
307
+ }
246
308
247
- //some modders included duplicate names
248
- if ( EnchantmentRecipeDictionary . TryGetValue ( keyName , out EnchantmentRecipe foundEnchantment ) )
249
- {
250
- keyName + = "_" + Guid . NewGuid ( ) ;
251
- }
309
+ public void FilterItemsData ( string filter )
310
+ {
311
+ List < string > dropdownOptions = new List < string > ( ) ;
312
+ string keyName = "" ;
313
+ EquipmentDictionary = new Dictionary < string , Equipment > ( ) ;
252
314
253
- EnchantmentRecipeDictionary . Add ( keyName , recipe ) ;
254
- availableRecipesOptions . Add ( keyName ) ;
315
+ foreach ( Equipment equipment in AvailableEquipment )
316
+ {
317
+ keyName = GetUniqueEquipmentsName ( equipment ) ;
318
+
319
+ if ( EnchantmentsHelper . ContainsIgnoreCase ( keyName , filter ) )
320
+ {
321
+ dropdownOptions . Add ( keyName ) ;
322
+ EquipmentDictionary . Add ( keyName , equipment ) ;
255
323
}
324
+ }
325
+
326
+ FillDropdownChoices ( ChooseItemDropdown , dropdownOptions ) ;
327
+
328
+ ChooseItemDropdown . value = 0 ;
329
+ ChooseItemDropdown . RefreshShownValue ( ) ;
330
+ ChooseItemDropdown . onValueChanged . Invoke ( ChooseItemDropdown . value ) ;
331
+ }
256
332
257
- if ( ChooseEnchantmentDropdown != null )
258
- FillDropdownChoices ( ChooseEnchantmentDropdown , availableRecipesOptions ) ;
333
+ public void FilterEnchantmentsData ( string filter )
334
+ {
335
+ if ( ChooseItemDropdown . value < 0 || ChooseItemDropdown . value >= ChooseItemDropdown . options . Count )
336
+ {
337
+ ResultAndLogMessage ( $ "Invalid dropdown selection: { ChooseItemDropdown . value } , options count: { ChooseItemDropdown . options . Count } ") ;
338
+ return ;
259
339
}
260
- catch ( Exception ex )
340
+
341
+ string selectedValue = ChooseItemDropdown . options [ ChooseItemDropdown . value ] . text ;
342
+ if ( ! EquipmentDictionary . TryGetValue ( selectedValue , out Equipment equipment ) )
261
343
{
262
- OutwardEnchanter . LogMessage ( "GUIMainCanvasManager@HandleOnChooseItemChange error: " + ex . Message ) ;
344
+ ResultAndLogMessage ( $ "Item: { selectedValue } is not found! Tried to access: { ChooseItemDropdown . value } ") ;
345
+ return ;
263
346
}
347
+
348
+ List < EnchantmentRecipe > availableRecipes = EnchantmentsHelper . GetAvailableEnchantmentRecipies ( equipment ) ;
349
+ EnchantmentRecipeDictionary = new Dictionary < string , EnchantmentRecipe > ( ) ;
350
+ List < string > availableRecipesOptions = new List < string > ( ) ;
351
+ string keyName = "" ;
352
+
353
+ foreach ( EnchantmentRecipe recipe in availableRecipes )
354
+ {
355
+ keyName = GetUniqueEnchantmentsName ( recipe ) ;
356
+
357
+ if ( keyName == null || ! EnchantmentsHelper . ContainsIgnoreCase ( keyName , filter ) )
358
+ continue ;
359
+
360
+ EnchantmentRecipeDictionary . Add ( keyName , recipe ) ;
361
+ availableRecipesOptions . Add ( keyName ) ;
362
+ }
363
+
364
+ if ( ChooseEnchantmentDropdown != null )
365
+ FillDropdownChoices ( ChooseEnchantmentDropdown , availableRecipesOptions ) ;
264
366
}
265
367
266
368
public void FillItemsData ( )
@@ -278,16 +380,14 @@ public void FillItemsData()
278
380
OutwardEnchanter . LogMessage ( "GUIMainCanvasManager@FillItemsData equipment is null!" ) ;
279
381
#endif
280
382
281
- keyName = equipment . ItemID + "_" + equipment . Name ;
282
-
283
- //some modders included duplicate names
284
- if ( EquipmentDictionary . TryGetValue ( keyName , out Equipment foundEquipment ) )
285
- {
286
- keyName += "_" + Guid . NewGuid ( ) ;
287
- }
383
+ keyName = GetUniqueEquipmentsName ( equipment ) ;
288
384
289
385
dropdownOptions . Add ( keyName ) ;
290
386
EquipmentDictionary . Add ( keyName , equipment ) ;
387
+
388
+ #if DEBUG
389
+ OutwardEnchanter . LogMessage ( $ "GUIMainCanvasManager@FillItemsData equipment keyName added: { keyName } !") ;
390
+ #endif
291
391
}
292
392
293
393
#if DEBUG
0 commit comments