Example #1
0
        private void loadChunkTile(int index, int tile)
        {
            Data.Chunk chunk = State.Data.Chunks[State.SelectedChunk];
            if (chunk == null)
            {
                return;
            }

            Data.TileSet tileset = State.Data.TileSets[State.SelectedTileset];
            if (tileset == null)
            {
                return;
            }

            if (index < 0 || index >= 64)
            {
                return;
            }

            chunk[index] = State.SelectedMetatile;

            for (int j = 0; j < 4; j++)
            {
                TilePageAttribute tile_page_attrib = State.Data.TileSets[State.SelectedTileset].GetSubTile(tile, j);
                ctlChunk.SetTile(index, j, tile_page_attrib.Tile, State.GfxPage(tile_page_attrib.Page).Texture);
                ctlChunk.SetAttribute(index, tile_page_attrib.Attribute);
            }
        }
Example #2
0
 /// <summary>
 /// Sets an entire chunk at once.
 /// </summary>
 /// <param name="chunk"></param>
 /// <param name="tileset"></param>
 public void SetChunk(Data.Chunk chunk, Data.TileSet tileset)
 {
     for (int i = 0; i < 64; i++)
     {
         int tile = chunk[i];
         for (int j = 0; j < 4; j++)
         {
             TilePageAttribute tile_page_attrib = State.Data.TileSets[State.SelectedTileset].GetSubTile(tile, j);
             SetTile(i, j, tile_page_attrib.Tile, State.GfxPage(tile_page_attrib.Page).Texture);
             SetAttribute(i, tile_page_attrib.Attribute);
         }
     }
 }
        public void WriteChunk(int x, int y, Data.Chunk chunk, Data.TileSet tileset, Data.TileGfx gfx)
        {
            if (m_TilesToBytes == null)
            {
                m_TilesToBytes = new Dictionary <int, int[]>();
            }

            for (int i = 0; i < 4; i++)
            {
                int[] chunksums = new int[16];
                for (int iy = 0; iy < 4; iy++)
                {
                    for (int ix = 0; ix < 4; ix++)
                    {
                        int metatile = chunk[(iy + (i / 2) * 2) * 8 + (ix + (i % 2) * 2)];
                        if (!m_TilesToBytes.ContainsKey(metatile))
                        {
                            int[] tilesums = new int[16];
                            for (int j = 0; j < 4; j++)
                            {
                                TilePageAttribute value = tileset.GetSubTile(metatile, j);
                                byte[]            tile  = gfx.GetTile(value.Page, value.Tile);
                                for (int k = 0; k < 16; k++)
                                {
                                    int t = (tile[k] & 0x03);
                                    tilesums[t + (t == 0 ? 0 : value.Attribute * 4)]++;
                                    t = ((tile[k] >> 2) & 0x03);
                                    tilesums[t + (t == 0 ? 0 : value.Attribute * 4)]++;
                                    t = ((tile[k] >> 4) & 0x03);
                                    tilesums[t + (t == 0 ? 0 : value.Attribute * 4)]++;
                                    t = ((tile[k] >> 6) & 0x03);
                                    tilesums[t + (t == 0 ? 0 : value.Attribute * 4)]++;
                                }
                            }
                            m_TilesToBytes.Add(metatile, tilesums);
                        }
                        for (int j = 0; j < 16; j++)
                        {
                            chunksums[j] += m_TilesToBytes[metatile][j];
                        }
                    }
                    uint[] mostCommonPixel = new uint[1] {
                        (uint)GreatestIndexInArray(chunksums)
                    };
                    m_Texture.SetData <uint>(0, new Rectangle(x * 2 + (i % 2), y * 2 + (i / 2), 1, 1), mostCommonPixel, 0, 1);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Loads data into the 'Selected Chunk' widget in the 'Controls' panel.
        /// </summary>
        private void refreshSelectedChunk()
        {
            Data.Chunk chunk = State.Data.Chunks[State.SelectedChunk];
            if (chunk == null)
            {
                return;
            }

            Data.TileSet tileset = State.Data.TileSets[State.SelectedTileset];
            if (tileset == null)
            {
                return;
            }

            chkSelectedChunk.SetChunk(chunk, tileset);
        }
Example #5
0
        private void loadChunkElement()
        {
            Data.Chunk chunk = State.Data.Chunks[State.SelectedChunk];
            if (chunk == null)
            {
                return;
            }

            Data.TileSet tileset = State.Data.TileSets[State.SelectedTileset];
            if (tileset == null)
            {
                return;
            }

            ctlChunk.SetChunk(chunk, tileset);
        }
Example #6
0
        private void cmbTilesets_SelectionChanged(Widget widget)
        {
            State.SelectedTileset = ((ComboBox)widget).SelectedIndex;

            Data.Chunk chunk = State.Data.Chunks[State.SelectedChunk];
            if (chunk != null)
            {
                chunk.Tileset = State.SelectedTileset;
            }

            Data.TileSet tileset = State.Data.TileSets[State.SelectedTileset];

            if (tileset != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (tileset.GetPalette(i) < 0 || tileset.GetPalette(i) >= State.Data.Palettes.Count)
                    {
                        tileset.SetPalette(i, 0);
                    }
                    byte[] palette = new byte[4];
                    palette[0] = State.Data.Palettes[tileset.GetPalette(0)][0];
                    for (int j = 1; j < 4; j++)
                    {
                        palette[j] = State.Data.Palettes[tileset.GetPalette(i)][j];
                    }
                    State.Palette.LoadPalette(i, palette);
                }

                for (int i = 0; i < Data.TileSet.TilesPerSet; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        TilePageAttribute tile_page_attrib = State.Data.TileSets[State.SelectedTileset].GetSubTile(i, j);
                        aioTileset.SetTile(i, j, tile_page_attrib.Tile, State.GfxPage(tile_page_attrib.Page).Texture);
                        aioTileset.SetAttribute(i, tile_page_attrib.Attribute);
                    }
                }

                loadChunkElement();
            }
        }