예제 #1
0
 /** <summary> Opens the water object. </summary> */
 private void Open(object sender, EventArgs e)
 {
     if (fileName == "")
     {
         openFileDialog.InitialDirectory = "";
         openFileDialog.FileName         = "";
     }
     else
     {
         openFileDialog.InitialDirectory = Path.GetDirectoryName(fileName);
         openFileDialog.FileName         = Path.GetFileNameWithoutExtension(fileName);
     }
     if (!changed || WarningMessageBox.Show(this, "Scenery group has been changed.", "Are you sure you want to continue?") == DialogResult.Yes)
     {
         if (openFileDialog.ShowDialog(this) == DialogResult.OK)
         {
             fileName = openFileDialog.FileName;
             ObjectData obj     = ObjectData.FromFile(fileName);
             bool       invalid = false;
             if (obj is SceneryGroup && (obj as SceneryGroup).GraphicsData.NumImages == 2)
             {
                 this.sceneryGroup = (SceneryGroup)obj;
                 LoadSceneryGroup();
             }
             else
             {
                 invalid = true;
             }
             if (invalid)
             {
                 ErrorMessageBox.Show(this, "Failed to load scenery group.", "Object may be invalid.");
             }
         }
     }
 }
예제 #2
0
        private void ChangeTabIcon(object sender, EventArgs e)
        {
            if (this.openFileDialogIcon.ShowDialog(this) == DialogResult.OK)
            {
                try {
                    this.sceneryGroup.GraphicsData.Set(0, PaletteImage.FromBuffer(Resources.TabBack));
                    this.sceneryGroup.GraphicsData.Set(1, PaletteImage.FromBuffer(Resources.TabFront));

                    Bitmap icon             = (Bitmap)Bitmap.FromFile(this.openFileDialogIcon.FileName);
                    Color  transparentColor = icon.GetPixel(0, 0);

                    for (int i = 0; i < 2; i++)
                    {
                        for (int x = 0; x < this.sceneryGroup.GraphicsData.GetPaletteImage(i).Width; x++)
                        {
                            for (int y = 0; y < this.sceneryGroup.GraphicsData.GetPaletteImage(i).Height; y++)
                            {
                                if (x < icon.Width && y < icon.Height && (i == 1 || y < 26))
                                {
                                    int colorIndex = FindClosestColor(icon.GetPixel(x, y), transparentColor);
                                    if (colorIndex != 0)
                                    {
                                        this.sceneryGroup.GraphicsData.GetPaletteImage(i).Pixels[x, y] = (byte)colorIndex;
                                    }
                                }
                            }
                        }
                    }

                    Graphics g = Graphics.FromImage(this.iconImage);

                    PaletteImage icon2 = this.sceneryGroup.GraphicsData.GetPaletteImage(1);
                    icon2.Draw(g, (46 - icon2.Width) / 2, (46 - icon2.Height) / 2, Palette.SceneryGroupPalette);
                    g.Dispose();

                    this.iconView.Image = this.iconImage;

                    changed = true;
                }
                catch (Exception) {
                    ErrorMessageBox.Show(this, "Error using image for tab icon.", "File may not be an image.");
                }
            }
        }
예제 #3
0
        /** <summary> Called when a dragged object is dropped into the list. </summary> */
        private void SceneryListDragDrop(object sender, DragEventArgs e)
        {
            Point        cp         = this.tabGroupScenery.PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = this.tabGroupScenery.GetItemAt(cp.X, cp.Y);
            int          dropIndex  = (dragToItem != null ? dragToItem.Index : this.tabGroupScenery.Items.Count);

            if (dragToItem != null)
            {
                if (this.tabGroupScenery.GetItemAt(cp.X, cp.Y + 12) != dragToItem)
                {
                    dropIndex++;
                }
            }
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                bool     invalid     = false;
                bool     invalidType = false;
                string[] fileDrops   = (string[])(e.Data.GetData(DataFormats.FileDrop));
                for (int i = 0; i < fileDrops.Length; i++)
                {
                    string file = fileDrops[i];
                    if (File.Exists(file))
                    {
                        ObjectDataInfo info = ObjectDataInfo.FromFile(file, true);
                        if (!info.Invalid)
                        {
                            if (info.Type != ObjectTypes.SmallScenery && info.Type != ObjectTypes.LargeScenery &&
                                info.Type != ObjectTypes.PathAddition && info.Type != ObjectTypes.PathBanner &&
                                info.Type != ObjectTypes.Wall)
                            {
                                invalidType = true;
                            }
                            else
                            {
                                ListViewItem item = new ListViewItem();
                                item.ImageIndex = 1;
                                if (info.Source == SourceTypes.Custom)
                                {
                                    item.ImageIndex = 2;
                                }
                                else if (info.Source == SourceTypes.RCT2)
                                {
                                    item.ImageIndex = 0;
                                }
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Source.ToString()));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(file)));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Name));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Type.ToString()));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Subtype.ToString()));
                                this.tabGroupScenery.Items.Insert(dropIndex + i, item);
                                this.sceneryGroup.Items.Insert(dropIndex + i, new SceneryGroupItem(info.Flags, info.FileName, info.CheckSum));
                            }
                        }
                        else
                        {
                            /*ListViewItem item = new ListViewItem();
                             * item.ForeColor = Color.FromArgb(200, 0, 0);
                             * //item.Font = new Font(item.Font, FontStyle.Bold);
                             * item.ImageIndex = 3;
                             * if (info.Source == SourceTypes.Custom) item.ImageIndex = 2;
                             * else if (info.Source == SourceTypes.RCT2) item.ImageIndex = 0;
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(file)));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * this.tabGroupScenery.Items.Insert(dropIndex + i, item);*/
                            invalid = true;
                        }
                    }
                }
                if (invalid)
                {
                    ErrorMessageBox.Show(this, "Some items were invalid objects and", "not added.");
                }
                if (invalidType)
                {
                    ErrorMessageBox.Show(this, "Some items were invalid object types", "and not added.");
                }
            }
            else
            {
                int itemsBefore = 0;
                int itemsAfter  = 0;
                for (int i = 0; i < this.tabGroupScenery.SelectedItems.Count; i++)
                {
                    if (this.tabGroupScenery.SelectedItems[i].Index <= dropIndex)
                    {
                        itemsBefore++;
                    }
                    else
                    {
                        itemsAfter++;
                    }
                }
                List <ListViewItem>     items   = new List <ListViewItem>();
                List <SceneryGroupItem> sgItems = new List <SceneryGroupItem>();
                for (int i = this.tabGroupScenery.SelectedItems.Count - 1; i >= 0; i--)
                {
                    items.Add(this.tabGroupScenery.SelectedItems[i]);
                    sgItems.Add(this.sceneryGroup.Items[i]);
                    this.sceneryGroup.Items.RemoveAt(this.tabGroupScenery.SelectedItems[i].Index);
                    this.tabGroupScenery.Items.RemoveAt(this.tabGroupScenery.SelectedItems[i].Index);
                }
                for (int i = 0; i < items.Count; i++)
                {
                    this.tabGroupScenery.Items.Insert(Math.Max(0, dropIndex - itemsBefore) + i, items[items.Count - 1 - i]);
                    this.sceneryGroup.Items.Insert(Math.Max(0, dropIndex - itemsBefore) + i, sgItems[items.Count - 1 - i]);
                }
            }
            changed = true;
        }
예제 #4
0
        //=========== SCENERY ============
        #region Scenery Management

        /** <summary> Opens a file dialog to add scenery. </summary> */
        private void AddScenery(object sender, EventArgs e)
        {
            if (this.openFileDialogScenery.ShowDialog(this) == DialogResult.OK)
            {
                bool invalid     = false;
                bool invalidType = false;
                for (int i = 0; i < this.openFileDialogScenery.FileNames.Length; i++)
                {
                    string file = this.openFileDialogScenery.FileNames[i];
                    if (File.Exists(file))
                    {
                        ObjectDataInfo info = ObjectDataInfo.FromFile(file, true);
                        if (!info.Invalid)
                        {
                            if (info.Type != ObjectTypes.SmallScenery && info.Type != ObjectTypes.LargeScenery &&
                                info.Type != ObjectTypes.PathAddition && info.Type != ObjectTypes.PathBanner &&
                                info.Type != ObjectTypes.Wall)
                            {
                                invalidType = true;
                            }
                            else
                            {
                                ListViewItem item = new ListViewItem();
                                item.ImageIndex = 1;
                                if (info.Source == SourceTypes.Custom)
                                {
                                    item.ImageIndex = 2;
                                }
                                else if (info.Source == SourceTypes.RCT2)
                                {
                                    item.ImageIndex = 0;
                                }
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Source.ToString()));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(file)));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Name));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Type.ToString()));
                                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Subtype.ToString()));
                                this.tabGroupScenery.Items.Add(item);
                                this.sceneryGroup.Items.Add(new SceneryGroupItem(info.Flags, info.FileName, info.CheckSum));
                            }
                        }
                        else
                        {
                            /*ListViewItem item = new ListViewItem();
                             * item.ForeColor = Color.FromArgb(200, 0, 0);
                             * //item.Font = new Font(item.Font, FontStyle.Bold);
                             * item.ImageIndex = 3;
                             * if (info.Source == SourceTypes.Custom) item.ImageIndex = 2;
                             * else if (info.Source == SourceTypes.RCT2) item.ImageIndex = 0;
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(file)));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
                             * this.tabGroupScenery.Items.Add(item);*/
                            invalid = true;
                        }
                    }
                }
                if (invalid)
                {
                    ErrorMessageBox.Show(this, "Some items were invalid objects and", "not added.");
                }
                if (invalidType)
                {
                    ErrorMessageBox.Show(this, "Some items were invalid object types", "and not added.");
                }
            }
        }
예제 #5
0
 public static DialogResult Show(Form parent, string text1, string text2)
 {
     using (var form = new ErrorMessageBox(text1, text2)) {
         return(form.ShowDialog(parent));
     }
 }