Esempio n. 1
0
        // non-allocation image generator
        public static Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale, int[] acre1, int[] acreScale, Bitmap dest, int transparency = -1)
        {
            var w = layer.GridWidth;
            var h = layer.GridHeight;

            LoadPixelsFromLayer(layer, x0, y0, w, acre1);
            w *= scale;
            h *= scale;
            ImageUtil.ScalePixelImage(acre1, acreScale, w, h, scale);

            if (transparency >> 24 != 0xFF)
            {
                ImageUtil.SetAllTransparencyTo(acreScale, transparency);
            }

            // draw symbols over special items now?
            DrawDirectionals(acreScale, layer, w, x0, y0, scale);

            // Slap on a grid
            DrawGrid(acreScale, w, h, scale);

            // Return final data
            ImageUtil.SetBitmapData(dest, acreScale);
            return(dest);
        }
Esempio n. 2
0
        public static bool ImportToLayerAcreSingle(FieldItemLayer layer, int acreIndex, string acre, int layerIndex)
        {
            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Field Item Layer (*.nhl)|*.nhl|All files (*.*)|*.*",
                      FileName = $"{acre}-{layerIndex}.nhl",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            var path = ofd.FileName;
            var fi   = new FileInfo(path);

            int expect = layer.AcreTileCount * Item.SIZE;

            if (fi.Length != expect)
            {
                WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect));
                return(false);
            }

            var data = File.ReadAllBytes(path);

            layer.ImportAcre(acreIndex, data);
            return(true);
        }
Esempio n. 3
0
        private void ReloadGrid(FieldItemLayer layer, int topX, int topY)
        {
            var transparency = TR_Transparency.Value / 100d;
            var t            = ((int)(0xFF * transparency) << 24) | 0x00FF_FFFF;

            PB_Acre.Image = FieldItemSpriteDrawer.GetBitmapLayerAcre(layer, topX, topY, AcreScale, Scale1, ScaleX, ScaleAcre, t);
        }
    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);
    }
Esempio n. 5
0
 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);
             }
         }
     }
 }
Esempio n. 6
0
 public static Bitmap GetBitmapLayer(FieldItemLayer layer, int x, int y, int[] data, Bitmap dest, int transparency = -1)
 {
     LoadBitmapLayer(layer.Tiles, data, layer.MapWidth, layer.MapHeight);
     if (transparency >> 24 != 0xFF)
     {
         ImageUtil.SetAllTransparencyTo(data, transparency);
     }
     ImageUtil.SetBitmapData(dest, data);
     return(DrawViewReticle(dest, layer, x, y));
 }
Esempio n. 7
0
        public static Bitmap GetBitmapLayer(FieldItemLayer layer, int x, int y, int scale = 1)
        {
            var map = GetBitmapLayer(layer);

            if (scale > 1)
            {
                map = ImageUtil.ResizeImage(map, map.Width, map.Height);
            }

            return(DrawViewReticle(map, layer, x, y, scale));
        }
Esempio n. 8
0
        private static int[] GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, out int width, out int height)
        {
            height = layer.GridWidth;
            width  = layer.GridWidth;

            var bmpData = new int[width * height];

            LoadPixelsFromLayer(layer, x0, y0, width, bmpData);

            return(bmpData);
        }
Esempio n. 9
0
        public static Bitmap GetBitmapLayer(FieldItemLayer layer)
        {
            var items  = layer.Tiles;
            var height = layer.MapHeight;
            var width  = items.Length / height;

            var bmpData = new int[width * height];

            LoadBitmapLayer(items, bmpData, width, height);

            return(ImageUtil.GetBitmap(bmpData, width, height));
        }
Esempio n. 10
0
        public MapTerrainLite(byte[] itemBytes)
        {
            if (itemBytes.Length != ByteSize)
            {
                throw new Exception("Field items are of the incorrect size.");
            }
            StartupBytes = itemBytes;
            var items = Item.GetArray(StartupBytes);

            StartupItems = CloneItemArray(items);
            ItemLayer    = new FieldItemLayer(items);
        }
Esempio n. 11
0
    private void loadBytes(int l, byte[] data)
    {
        //Array.Copy(data, 0, field, l * MapGrid.MapTileCount32x32 * Item.SIZE, MapGrid.MapTileCount32x32 * Item.SIZE);
        //generateAll();
        Item[]         itemLayer   = Item.GetArray(data);
        FieldItemLayer toOverwrite = l == 0 ? fieldManager.Layer1 : fieldManager.Layer2;

        for (int i = 0; i < toOverwrite.Tiles.Length; ++i)
        {
            toOverwrite.Tiles[i].CopyFrom(itemLayer[i]);
        }
        UpdateLayerImage();
    }
Esempio n. 12
0
        // unused -- allocates!
        public static Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale)
        {
            var map  = GetBitmapLayerAcre(layer, x0, y0, out int mh, out int mw);
            var data = ImageUtil.ScalePixelImage(map, scale, mw, mh, out var w, out var h);

            // draw symbols over special items now?
            DrawDirectionals(data, layer, w, x0, y0, scale);

            // Slap on a grid
            DrawGrid(data, w, h, scale);

            // Return final data
            return(ImageUtil.GetBitmap(data, w, h));
        }
Esempio n. 13
0
        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;
                }
            }
        }
Esempio n. 14
0
        public static void DumpLayerAcreAll(FieldItemLayer layer)
        {
            using var sfd = new SaveFileDialog
                  {
                      Filter   = "New Horizons Field Item Layer (*.nhl)|*.nhl|All files (*.*)|*.*",
                      FileName = "acres.nhl",
                  };
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var path = sfd.FileName;
            var data = layer.DumpAllAcres();

            File.WriteAllBytes(path, data);
        }
Esempio n. 15
0
        public static void DumpLayerAcreSingle(FieldItemLayer layer, int acreIndex, string acre, int layerIndex)
        {
            using var sfd = new SaveFileDialog
                  {
                      Filter   = "New Horizons Field Item Layer (*.nhl)|*.nhl|All files (*.*)|*.*",
                      FileName = $"{acre}-{layerIndex}.nhl",
                  };
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var path = sfd.FileName;
            var data = layer.DumpAcre(acreIndex);

            File.WriteAllBytes(path, data);
        }
Esempio n. 16
0
 public static Item GetTile(this FieldItemLayer layer, Point itemPt)
 => layer.GetTile(itemPt.X, itemPt.Y);
Esempio n. 17
0
 public static void DeleteExtensionTiles(this FieldItemLayer layer, Item tile, Point itemPt)
 => layer.DeleteExtensionTiles(tile, itemPt.X, itemPt.Y);
Esempio n. 18
0
 private Bitmap GetMapWithReticle(int topX, int topY, int t, FieldItemLayer layer)
 {
     return(ItemLayerSprite.GetBitmapItemLayer(layer, topX, topY, PixelsItemMap, MapReticle, t));
 }
Esempio n. 19
0
 private FieldItem GetTile(FieldItemLayer layer, MouseEventArgs e)
 {
     SetHoveredItem(e);
     return(layer.GetTile(X + HoverX, Y + HoverY));
 }
Esempio n. 20
0
 private void ReloadGrid(FieldItemLayer layer, int topX, int topY)
 {
     PB_Acre.Image = FieldItemSpriteDrawer.GetBitmapLayerAcre(layer, topX, topY, AcreScale, Scale1, ScaleX, ScaleAcre);
 }
Esempio n. 21
0
 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));
 }
Esempio n. 22
0
 public static Bitmap GetBitmapLayer(FieldItemLayer layer, int x, int y, int[] data, Bitmap dest)
 {
     LoadBitmapLayer(layer.Tiles, data, layer.MapWidth, layer.MapHeight);
     ImageUtil.SetBitmapData(dest, data);
     return(DrawViewReticle(dest, layer, x, y));
 }