Ejemplo n.º 1
0
        //--------------------------------------------------------
        //	SavePalette
        //		Saves a palette to file using given path
        //
        //	@param
        //	string path - path to Save file to
        //--------------------------------------------------------
        private void SavePalette(string path)
        {
            FilePalette data = new FilePalette();

            // Add Ungrouped Images
            foreach (PictureBox pb in unGroupedList)
            {
                data.unGroupedList.Add(pb.ImageLocation);
            }

            // Add Groups
            foreach (Group group in groupList)
            {
                GroupData         temp = new GroupData();
                List <PictureBox> list;

                group.GetData(out temp.name, out list);
                foreach (PictureBox pb in list)
                {
                    temp.dataList.Add(pb.ImageLocation);
                }

                data.groupList.Add(temp);
            }

            // Serialize
            XmlSerializer serializer = new XmlSerializer(typeof(FilePalette));

            using (StreamWriter writer = new StreamWriter(path))
            {
                serializer.Serialize(writer, data);
            }
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------
        //	LoadPalette
        //		Loads a palette from file using given path
        //
        //	@param
        //	string path - path to load file from
        //--------------------------------------------------------
        private void LoadPalette(string path)
        {
            ClearData();

            // Load Blank Palette
            if (!File.Exists(path))
            {
                return;
            }

            // Deserialize
            XmlSerializer serializer = new XmlSerializer(typeof(FilePalette));

            using (StreamReader reader = new StreamReader(path))
            {
                FilePalette data = (FilePalette)serializer.Deserialize(reader);

                foreach (string imageLoc in data.unGroupedList)
                {
                    // Check image exists
                    if (!File.Exists(imageLoc))
                    {
                        errorState = ErrorState.DoesNotExist;
                        errorText += (imageLoc + "\n");
                        continue;
                    }

                    // Get Image from Save
                    Image image = new Bitmap(imageLoc);
                    image.Tag = imageLoc;

                    // Add Image to imageList
                    imageList.Add(image);

                    // Create PictureBox
                    PictureBox pictureBox = new PictureBox();
                    pictureBox.Image              = image;
                    pictureBox.ImageLocation      = (string)image.Tag;
                    pictureBox.Parent             = UngroupedPanel;
                    pictureBox.Size               = new Size(Group.m_nImageSize, Group.m_nImageSize);
                    pictureBox.SizeMode           = PictureBoxSizeMode.Zoom;
                    pictureBox.MouseDown         += PictureBox_MouseDown;
                    pictureBox.QueryContinueDrag += PictureBox_QueryContinueDrag;

                    // Add Tooltip
                    toolTip1.SetToolTip(pictureBox, "Left Click Picture Box to select it for map painting");

                    // Add PictureBox to unGroupedList
                    unGroupedList.Add(pictureBox);
                }
                ResizeUngrouped();

                foreach (GroupData groupData in data.groupList)
                {
                    Group temp = new Group(groupList, splitContainer1.Panel1);
                    groupList.Add(temp);

                    // Set Name
                    temp.SetName(groupData.name);

                    // Get Data
                    foreach (string imageLoc in groupData.dataList)
                    {
                        // Check image exists
                        if (!File.Exists(imageLoc))
                        {
                            errorState = ErrorState.DoesNotExist;
                            errorText += (imageLoc + "\n");
                            continue;
                        }
                        // Get Image from Save
                        Image image;
                        image = new Bitmap(imageLoc);

                        // Add Image to imageList
                        imageList.Add(image);
                        image.Tag = imageLoc;

                        // Create PictureBox
                        PictureBox pictureBox = new PictureBox();
                        pictureBox.Image              = image;
                        pictureBox.ImageLocation      = (string)image.Tag;
                        pictureBox.Parent             = temp.GetDataPanel();
                        pictureBox.Size               = new Size(Group.m_nImageSize, Group.m_nImageSize);
                        pictureBox.SizeMode           = PictureBoxSizeMode.Zoom;
                        pictureBox.MouseDown         += PictureBox_MouseDown;
                        pictureBox.QueryContinueDrag += PictureBox_QueryContinueDrag;

                        // Add Tooltip
                        toolTip1.SetToolTip(pictureBox, "Left Click Picture Box to select it for map painting");

                        // Add PictureBox to unGroupedList
                        temp.GetDataList().Add(pictureBox);
                    }

                    temp.ResizeData();
                }

                // If Image failed to load
                if (errorState == ErrorState.DoesNotExist)
                {
                    errorState = ErrorState.Default;
                    ErrorForm errorForm = new ErrorForm("The following Images failed to load: \n" + errorText);
                    errorForm.ShowDialog();
                }
            }
        }