private void findAndReplace(Item toReplace, Item newItem, FindAndReplaceOptions options, int layer) { Func <Item, Item, bool> compareFunc = GetComparer(options); FieldItemLayer fil = layer == 0 ? fieldManager.Layer1 : fieldManager.Layer2; int replaceCount = 0; for (int i = 0; i < MapItemsWidthMax; ++i) { for (int j = 0; j < MapItemsHeightMax; ++j) { Item item = fil.GetTile(i, j); if (compareFunc(toReplace, item)) { item.CopyFrom(newItem); fil.SetExtensionTiles(item, i, j); replaceCount++; } } } if (replaceCount > 0) { UI_Popup.CurrentInstance.CreatePopupMessage(2f, $"Replaced {replaceCount} items.", () => { }); } else { UI_Popup.CurrentInstance.CreatePopupMessage(3f, "Unable to find any items that match desired replacement type.", () => { }, Color.red); } UpdateLayerImage(); updateGrid(lastCursorX, lastCursorY); }
// Start is called before the first frame update void Start() { MatchMode.ClearOptions(); string[] smChoices = Enum.GetNames(typeof(FindAndReplaceOptions)); foreach (string sm in smChoices) { Dropdown.OptionData newVal = new Dropdown.OptionData(); newVal.text = UI_MapItemTile.AddNewlinesAfterCapitals(sm, ' '); MatchMode.options.Add(newVal); } MatchMode.onValueChanged.AddListener(delegate { CurrentOption = (FindAndReplaceOptions)MatchMode.value; }); MatchMode.value = 0; MatchMode.RefreshShownValue(); SearchWindow.OnNewItemSelected += updateItem; SearchWindow.OnReturnSearchWindow += updateItemVals; ResetAll(); }
public Func <Item, Item, bool> GetComparer(FindAndReplaceOptions options) { Func <Item, Item, bool> retFunc; switch (options) { case FindAndReplaceOptions.MatchItemId: retFunc = ItemIdsMatch; break; case FindAndReplaceOptions.MatchItemAndVariation: retFunc = ItemVariationsMatch; break; case FindAndReplaceOptions.MatchFully: retFunc = ItemsAreSame; break; default: retFunc = ItemIdsMatch; break; } return(retFunc); }