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); }
// Remove all tile checking code public void Spawn(Item[] newItems, int itemsPerLine = 10, bool forceFlag32 = true) { int totalXTiles = itemsPerLine * 2; int x = SpawnX; int y = SpawnY; for (int i = 0; i < newItems.Length; ++i) { var currItem = newItems[i]; x = SpawnX + ((i * 2) % totalXTiles); y = SpawnY + ((i / itemsPerLine) * 2); var tile = ItemLayer.GetTile(x, y); if (!currItem.IsNone) { tile.CopyFrom(currItem); if (forceFlag32) { tile.SystemParam = 0x20; } ItemLayer.SetExtensionTiles(tile, x, y); } else { tile.Delete(); ItemLayer.DeleteExtensionTiles(tile, x, y); } } }
private static void DrawDirectionals(int[] data, FieldItemLayer layer, int w, int x0, int y0, int scale) { for (int x = x0; x < x0 + layer.GridWidth; x++) { for (int y = y0; y < y0 + layer.GridHeight; y++) { var tile = layer.GetTile(x, y); if (tile.IsNone) { continue; } if (tile.IsBuried) { DrawX(data, (x - x0) * scale, (y - y0) * scale, scale, w); } else if (tile.IsDropped) { DrawPlus(data, (x - x0) * scale, (y - y0) * scale, scale, w); } else if (tile.IsExtension) { DrawDirectional(data, tile, (x - x0) * scale, (y - y0) * scale, scale, w); } } } }
private static void LoadPixelsFromLayer(FieldItemLayer layer, int x0, int y0, int width, int[] bmpData) { var stride = layer.GridWidth; for (int y = 0; y < stride; y++) { var baseIndex = (y * width); for (int x = 0; x < stride; x++) { var tile = layer.GetTile(x + x0, y + y0); var color = FieldItemSprite.GetItemColor(tile).ToArgb(); var index = baseIndex + x; bmpData[index] = color; } } }
private FieldItem GetTile(FieldItemLayer layer, MouseEventArgs e, out int x, out int y) { SetHoveredItem(e); return(layer.GetTile(x = View.X + HoverX, y = View.Y + HoverY)); }
public static Item GetTile(this FieldItemLayer layer, Point itemPt) => layer.GetTile(itemPt.X, itemPt.Y);
private FieldItem GetTile(FieldItemLayer layer, MouseEventArgs e) { SetHoveredItem(e); return(layer.GetTile(X + HoverX, Y + HoverY)); }