public void ChangeData(byte[] data, int x8, int y8) { int x16 = x8 / 2; int y16 = y8 / 2; Map16Tile16x16 t16 = Map[x16 + y16 * 16]; t16.ChangeData(data, y8 % 2 == 0, x8 % 2 == 0); RedrawObject(t16); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Image))); }
public void ChangeData(byte[] data, int block_start) { //subarray because of stupid internal logic regarding the offset in the byte array //being used to calculate the tile number. var subData = new byte[block_start * 8 + data.Length]; Array.Copy(data, 0, subData, block_start * 8, data.Length); for (int i = 0; i < data.Length && block_start + (i / 8) < 0x400; i += 8) { var sub = new Map16Tile16x16(subData, block_start * 8 + i) { Resources = Resources, }; RedrawObject(sub); Map[block_start + (i / 8)] = sub; } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Image))); }
/// <summary> /// /// </summary> /// <param name="x8">Horizontal value on an 8x8 grid</param> /// <param name="y8">Vertical value on an 8x8 grid</param> public void Select(int x8, int y8, bool in8x8Mode) { int index = (y8 / 2) * 16 + (x8 / 2); //32 8x8 tiles per horizontal row Map16Tile16x16 tile16 = Map[index]; SelectedObject.PropertyChanged -= SelectedObject_PropertyChanged; if (!in8x8Mode) { SelectedObject = tile16; } else { int xPlus = (x8 % 2) * 2; // +2 if we're on the right side int yPlus = y8 % 2; // +1 if we're on the bottom Map16Tile8x8 tile8 = tile16.SubTiles[xPlus + yPlus]; SelectedObject = tile8; } SelectedObject.PropertyChanged += SelectedObject_PropertyChanged; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedObject))); }
public override bool Equals(object obj) { if (object.ReferenceEquals(obj, this)) { return(true); } Map16Tile16x16 m = obj as Map16Tile16x16; if ((object)m == null) { return(false); } for (int i = 0; i < 4; i++) { if (m.SubTiles[i] != SubTiles[i]) { return(false); } } return(true); }
public Map16Data(byte[] data, Map16Resources resources) { Resources = resources; Map = new Map16Tile16x16[data.Length / 8]; for (int i = 0; i < data.Length; i += 8) { Map[i / 8] = new Map16Tile16x16(data, i) { Resources = resources, }; } resources.Graphics.TileChanged += (s, e) => { var updateMap = Map.Where(m => e.Tiles.Contains(m.TopLeft) || e.Tiles.Contains(m.TopRight) || e.Tiles.Contains(m.BottomLeft) || e.Tiles.Contains(m.BottomRight)); foreach (var maptile in updateMap) { RedrawObject(maptile); } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Image))); }; int height = (int)Math.Ceiling((data.Length / 8.0m) / 16.0m); Image = new Bitmap(256, 16 * 320); using (Graphics g = Graphics.FromImage(Image)) { foreach (Map16Tile16x16 m in Map) { Image im = m.GetImage(); g.DrawImage(im, new Point(m.PixelX, m.PixelY)); im.Dispose(); } } SelectedObject = Map[0]; }