Exemplo n.º 1
0
        private void MapViewBox_SelectionChanged(object sender, EventArgs e)
        {
            if (MapViewBox.SelectionIsSingle())
            {
                Point selection = MapViewBox.GetSelectionCoords();
                MapSelection_Label.Text = "X: " + selection.X + ", Y: " + selection.Y;
            }
            else
            {
                MapSelection_Label.Text = "X: __, Y: __";
            }

            int width  = MapViewBox.Selection.GetLength(0);
            int height = MapViewBox.Selection.GetLength(1);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (MapViewBox.Selection[x, y])
                    {
                        for (int i = 0; i < EventList.Count; i++)
                        {
                            if (EventList[i].Command == "UNIT" &&
                                EventList[i].Arguments[UNIT_argX] == x &&
                                EventList[i].Arguments[UNIT_argY] == y)
                            {
                                int index = UnitEvents_ListBox.Items.IndexOf(EventList[i].Label);
                                if (index == -1)
                                {
                                    continue;
                                }
                                else if (UnitEvents_ListBox.GetItemChecked(index))
                                {
                                    index = Event.GetCodeIndex(Event_CodeBox.Text, EventList[i].CodeLineNumber);
                                    Event_CodeBox.SelectionStart  = index;
                                    Event_CodeBox.SelectionLength = 4;
                                    Event_CodeBox.DoSelectionVisible();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        void Core_LoadMap_Units(GBA.Bitmap result)
        {
            try
            {
                Pointer address_mapsprites = Core.GetPointer("Map Sprite Idle Array");
                Pointer address_classes    = Core.GetPointer("Class Array");
                Pointer address;
                byte    palette_index;
                byte    palette_amount = 4;
                address = Core.GetPointer("Map Sprite Palettes");
                byte[][] palettes = new byte[palette_amount][];
                for (int i = 0; i < palette_amount; i++)
                {
                    palettes[i] = Core.ReadData(address + i * Palette.LENGTH, Palette.LENGTH);
                    result.Colors.Add(new Palette(palettes[i]));
                }
                int       class_length = (Core.CurrentROM is FE6 ? 72 : 84);
                GBA.Image image;
                byte      unitclass;
                byte      mapsprite;
                byte      size;
                Tileset   tileset;
                int       offsetX;
                int       offsetY;
                int       index;
                for (int i = 0; i < EventList.Count; i++)
                {
                    if (EventList[i].Command == "UNIT" &&
                        EventList[i].Label != null)
                    {
                        index = UnitEvents_ListBox.Items.IndexOf(EventList[i].Label);
                        if (index == -1)
                        {
                            continue;
                        }
                        else if (!UnitEvents_ListBox.GetItemChecked(index))
                        {
                            continue;
                        }
                        unitclass     = (byte)EventList[i].Arguments[1];
                        mapsprite     = Core.ReadByte(address_classes + 6 + unitclass * class_length);
                        address       = address_mapsprites + mapsprite * 8;
                        size          = Core.ReadByte(address + 2);
                        tileset       = new Tileset(Core.ReadData(Core.ReadPointer(address + 4), 0));
                        palette_index = (byte)(EventList[i].Arguments[3] & 6);
                        if (palette_index > 2)
                        {
                            palette_index -= 3;
                        }
                        switch (size)
                        {
                        case 0x00: image = tileset.ToImage(2, 2, palettes[palette_index]); break;

                        case 0x01: image = tileset.ToImage(2, 4, palettes[palette_index]); break;

                        case 0x02: image = tileset.ToImage(4, 4, palettes[palette_index]); break;

                        default: image = null; break;
                        }
                        if (image != null)
                        {
                            offsetX  = (int)(EventList[i].Arguments[UNIT_argX] * 16);
                            offsetY  = (int)(EventList[i].Arguments[UNIT_argY] * 16);
                            offsetX -= (size == 0x02 ? 8 : 0);
                            offsetY -= (size == 0x00 ? 0 : 16);
                            int pixel;
                            for (int y = 0; y < image.Height; y++)
                            {
                                for (int x = 0; x < image.Width; x++)
                                {
                                    index = (x / 2) + y * (image.Width / 2);
                                    pixel = (x % 2 == 0) ?
                                            (image.Bytes[index] & 0x0F) :
                                            (image.Bytes[index] & 0xF0) >> 4;
                                    if (pixel != 0 &&
                                        offsetX + x >= 0 && offsetX + x < result.Width &&
                                        offsetY + y >= 0 && offsetY + y < result.Height)
                                    {
                                        result.SetColor(offsetX + x, offsetY + y, image.Colors[pixel]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not load the units to display on the map.", ex);
            }
        }