//добавление нового экранного спрайта
        void AddScreenSprite()
        {
            if (CurrentScreen == null)
            {
                MessageBox.Show("Select screen!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (CurrentSprite == null)
            {
                MessageBox.Show("Select sprite!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ScreenSprite scr_spr = new ScreenSprite();

            scr_spr.sprite = CurrentSprite;
            scr_spr.x_cord = 16 - CurrentSprite.width / 2;
            scr_spr.y_cord = 12 - CurrentSprite.height / 2;
            CurrentScreen.sprites.Add(scr_spr);
            RefreshScreenSpriteList();
            ScreenSpriteList.CurrentCell          = ScreenSpriteList.Rows[ScreenSpriteList.RowCount - 1].Cells[0];;
            ScreenSpriteList.CurrentCell.Selected = true;
            CalcProjectLenght();
            ProjectChanged = true;
        }
 //изменение объекта текущего экранного спрайта
 private void ScreenSpriteList_CurrentCellChanged(object sender, EventArgs e)
 {
     CurrentScreenSprite = null;
     if (ScreenSpriteList.CurrentCell != null && CurrentScreen != null && CurrentScreen.visible)
     {
         CurrentScreenSprite = CurrentScreen.sprites[ScreenSpriteList.CurrentCell.RowIndex];
     }
     ShowScreenPreview();
 }
 private void ScreenImg_MouseDown(object sender, MouseEventArgs e)
 {
     if (CurrentScreenSprite != null)
     {
         int x = e.X / 16;
         int y = e.Y / 16;
         //проверка выбора текущего экранного спрайта
         if (x >= CurrentScreenSprite.x_cord && x < CurrentScreenSprite.x_cord + CurrentScreenSprite.sprite.width && y >= CurrentScreenSprite.y_cord && y < CurrentScreenSprite.y_cord + CurrentScreenSprite.sprite.height)
         {
             LastXCord = x;
             LastYCord = y;
             XOffset   = x - CurrentScreenSprite.x_cord;
             YOffset   = y - CurrentScreenSprite.y_cord;
             DragMode  = true;
         }
         else
         {
             //поиск подходящего экранного спрайта
             for (int i = Screens.Count - 1; i >= 0; i--)
             {
                 for (int j = Screens[i].sprites.Count - 1; j >= 0; j--)
                 {
                     if (Screens[i].visible)
                     {
                         ScreenSprite scr_spr = Screens[i].sprites[j];
                         if (x >= scr_spr.x_cord && x < scr_spr.x_cord + scr_spr.sprite.width && y >= scr_spr.y_cord && y < scr_spr.y_cord + scr_spr.sprite.height)
                         {
                             ScreensList.CurrentCell               = ScreensList.Rows[i].Cells[0];
                             ScreensList.CurrentCell.Selected      = true;
                             ScreenSpriteList.CurrentCell          = ScreenSpriteList.Rows[j].Cells[0];
                             ScreenSpriteList.CurrentCell.Selected = true;
                             LastXCord = x;
                             LastYCord = y;
                             XOffset   = x - CurrentScreenSprite.x_cord;
                             YOffset   = y - CurrentScreenSprite.y_cord;
                             DragMode  = true;
                             return;
                         }
                     }
                 }
             }
             DragMode = false;
         }
     }
 }
 //чекбокс видимости экрана
 private void ScreensList_MouseUp(object sender, MouseEventArgs e)
 {
     if (CurrentScreen != null && ScreensList.CurrentCell.ColumnIndex == 1)
     {
         CurrentScreen.visible = (bool)ScreensList[1, ScreensList.CurrentRow.Index].EditedFormattedValue;
         if (!CurrentScreen.visible)
         {
             CurrentScreenSprite = null;
         }
         else
         {
             RefreshScreenSpriteList();
         }
         ShowScreenPreview();
         ViewCheckScreens();
         ProjectChanged = true;
     }
 }
        //загрузка проекта
        void LoadProject()
        {
            try
            {
                if (ProjectPath == "")
                {
                    if (OpenProjectDialog.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    ProjectPath = OpenProjectDialog.FileName;
                }
                BinaryReader proj = new BinaryReader(File.Open(ProjectPath, FileMode.Open));

                //загружаем спрайты
                int spr_count = proj.ReadInt32();
                Sprites.Clear();
                for (int i = 0; i < spr_count; i++)
                {
                    Sprite spr = new Sprite();
                    spr.name   = proj.ReadString();
                    spr.lenght = proj.ReadInt32();
                    spr.width  = proj.ReadInt32();
                    spr.height = proj.ReadInt32();
                    spr.data   = new byte[spr.width, spr.height][];
                    for (int y = 0; y < spr.height; y++)
                    {
                        for (int x = 0; x < spr.width; x++)
                        {
                            spr.data[x, y] = new byte[9];
                            for (int j = 0; j < 9; j++)
                            {
                                spr.data[x, y][j] = proj.ReadByte();
                            }
                        }
                    }
                    CreateSpriteImg(spr);
                    Sprites.Add(spr);
                }

                //загружаем скрины
                int scr_count = proj.ReadInt32();
                Screens.Clear();
                for (int i = 0; i < scr_count; i++)
                {
                    Screen scr = new Screen();
                    scr.name    = proj.ReadString();
                    scr.visible = proj.ReadBoolean();
                    int scrspr_count = proj.ReadInt32();
                    for (int j = 0; j < scrspr_count; j++)
                    {
                        ScreenSprite scrspr = new ScreenSprite();
                        scrspr.sprite = FindSprite(proj.ReadString());
                        scrspr.x_cord = proj.ReadInt32();
                        scrspr.y_cord = proj.ReadInt32();
                        scrspr.attr   = proj.ReadInt32();
                        scr.sprites.Add(scrspr);
                    }
                    Screens.Add(scr);
                }

                proj.Close();
                RefreshSpritesList();
                RefreshScreensList();
                ProjectChanged = false;
                ShowProjectName();
            }
            catch
            {
            }
        }