/// <summary> /// Handles the Click event of the nouveauToolStripMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void nouveauToolStripMenuItem_Click(object sender, EventArgs e) { if (map != null) { string message = "Votre carte n'est pas sauvegardée, voulez-vous la sauvegarder?"; string caption = "Sauvegarder"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result; // Displays the MessageBox. result = MessageBox.Show(view, message, caption, buttons); if (result == DialogResult.Yes) { if (validator.MapIsValid()) { SaveMapAsXML(); view.paEditor.Controls.Clear(); view.cmbLayer.Items.Clear(); map = null; } else { MessageBox.Show("La carte ne peut être sauvegarder car elle est invalide"); MapIsInvalid mapIsInvalid = new MapIsInvalid(this, validator.listOfErrors); mapIsInvalid.ShowDialog(); } } else { CreateMap createMapWindow = new CreateMap(this); createMapWindow.ShowDialog(); } } else { CreateMap createMapWindow = new CreateMap(this); createMapWindow.ShowDialog(); } }
/// <summary> /// Creates a new map with the dimensions entered by the user and adds the original layer. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="layerByDefault">if set to <c>true</c> [floor by default].</param> public void CreateNewMap(int x, int y, bool layerByDefault) { map = new Map(x, y); AddNewLayer(layerByDefault); view.visualTiles = new PictureBox[map.Width, map.Height]; CreateInterface(view.visualTiles); }
/// <summary> /// Loads the map from XML. /// </summary> private void LoadMapFromXML() { OpenFileDialog xmlFileDialog = new OpenFileDialog(); xmlFileDialog.Filter = "XML-File | *.xml"; if (xmlFileDialog.ShowDialog() == DialogResult.OK) { XmlSerializer mySerializer = new XmlSerializer(typeof(Map)); FileStream myFileStream = new FileStream(xmlFileDialog.FileName, FileMode.Open); map = (Map)mySerializer.Deserialize(myFileStream); view.visualTiles = new PictureBox[map.Width, map.Height]; CreateInterface(view.visualTiles); } }