//-------------------------------------------------------- // LoadImage // Load Images from new image list //-------------------------------------------------------- protected void LoadImage() { newImageList.Clear(); foreach (string path in dragPathList) { Image temp = new Bitmap(path); temp.Tag = path; newImageList.Add(temp); } if (errorState == ErrorState.NotRoot) { // Give Warning to User string text = "Image is not in root directory, only share palettes that have images in root directory"; ErrorForm errorForm = new ErrorForm(text); errorForm.ShowDialog(); errorState = ErrorState.Default; } }
//-------------------------------------------------------- // OffsetChangedButton_Click // On Click changes offset based on user input if valid //-------------------------------------------------------- private void OffsetChangedButton_Click(object sender, EventArgs e) { bool XOffsetInvalid = false; bool YOffsetInvalid = false; if (uint.TryParse(XPosTextBox.Text, out mapOffsetX)) { if (uint.TryParse(YPosTextBox.Text, out mapOffsetY)) { ShiftMap(); } else { YOffsetInvalid = true; } } else { XOffsetInvalid = true; } // If failure if (XOffsetInvalid || YOffsetInvalid) { // Get Error Text string errorText; if (XOffsetInvalid) { errorText = "X offset is Invalid"; } else { errorText = "Y offset is Invalid"; } // Show Error Dialog ErrorForm errorForm = new ErrorForm(errorText); errorForm.ShowDialog(); errorForm.DesktopLocation = MousePosition; } }
//-------------------------------------------------------- // LoadMap // Loads a map from given path // // @param // string path - path to load map from //-------------------------------------------------------- private void LoadMap(string path) { bool error = false; string errorText = null; Reset(); // Load Blank Palette if (!File.Exists(path)) { return; } // Deserialize XmlSerializer serializer = new XmlSerializer(typeof(SaveData)); using (StreamReader reader = new StreamReader(path)) { SaveData data = (SaveData)serializer.Deserialize(reader); foreach (List <MapSaveData> list in data.mapArray) { List <MapData> newList = new List <MapData>(); mapArray.Add(newList); foreach (MapSaveData saveData in list) { MapData mapData = new MapData(); // Get image Location from saveData var imageLoc = saveData.m_imageLoc; // Add MapData to list newList.Add(mapData); // Add SaveData to MapData mapData.m_Data = saveData; // Check path is not null if (imageLoc != null) { // Check image exists if (!File.Exists(imageLoc)) { error = true; errorText += (imageLoc + "\n"); continue; } // Get Image from Save Image image = new Bitmap(imageLoc); image.Tag = imageLoc; // Add Image to mapData mapData.m_Image = image; } } } // Get other var imageSize = data.imageSize; mapHeight = data.mapHeight; mapWidth = data.mapWidth; mapOffsetX = data.mapOffsetX; mapOffsetY = data.mapOffsetY; // Init text boxes InitTextBoxes(); // Resize PictureBoxArray ResizePictureBoxArray(); ShiftMap(); } // If Image failed to load if (error) { ErrorForm errorForm = new ErrorForm("The following Images failed to load: \n" + errorText); errorForm.ShowDialog(); errorForm.Location = MousePosition; } }
//-------------------------------------------------------- // ResizeMapButton_Click // On click changes map size based on user input // if valid //-------------------------------------------------------- private void ResizeMapButton_Click(object sender, EventArgs e) { bool widthInvalid = false; bool heightInvalid = false; if (uint.TryParse(HeightTextBox.Text, out mapHeight)) { if (uint.TryParse(WidthTextBox.Text, out mapWidth)) { //Change Map Size // Change Width int arrayWidth = mapArray.Count(); // Shrink if (arrayWidth > mapWidth) { // Shrink Map Array int removeCount = arrayWidth - (int)mapWidth; for (int i = 0; i < removeCount; ++i) { mapArray.Remove(mapArray.Last()); } } // Grow else { int addCount = (int)mapWidth - arrayWidth; for (int i = 0; i < addCount; ++i) { mapArray.Add(new List <MapData>()); } } // Change Height foreach (List <MapData> list in mapArray) { int arrayHeight = list.Count(); // Shrink if (arrayHeight > mapHeight) { int removeCount = arrayHeight - (int)mapHeight; for (int i = 0; i < removeCount; ++i) { list.Remove(list.Last()); } } // Grow else { int addCount = (int)mapHeight - arrayHeight; for (int i = 0; i < addCount; ++i) { list.Add(new MapData()); } } } // Resize PictureBox Array ResizePictureBoxArray(); } // ELSE Width try parse failed else { widthInvalid = true; } } // ELSE Height try parse failed else { heightInvalid = true; } // If failure if (widthInvalid || heightInvalid) { // Get Error Text string errorText; if (widthInvalid) { errorText = "Width is Invalid"; } else { errorText = "Height is Invalid"; } // Show Error Dialog ErrorForm errorForm = new ErrorForm(errorText); errorForm.ShowDialog(); errorForm.Location = MousePosition; } }
//-------------------------------------------------------- // 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(); } } }