using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Xml; namespace DarkWynter.App { public class SceneLibraryPanel : Panel { // File Location Handlers OpenFileDialog fdlg = new OpenFileDialog(); SaveFileDialog sfdl = new SaveFileDialog(); // ObjectLibrary Panels public List panelContent; public int currentContentPanel; /// /// Scene Library = Object Library Panel /// //private System.Windows.Forms.Panel panelSceneLibrary; public System.Windows.Forms.ListBox listBoxSceneLibrary; private System.Windows.Forms.Label lableSceneLibrary; private System.Windows.Forms.Button buttonSceneLibraryDelete; private System.Windows.Forms.Button buttonSceneLibraryClone; private System.Windows.Forms.Button buttonAddToSubTemplates; public SceneLibraryPanel() { panelContent = new List(); this.buttonAddToSubTemplates = new System.Windows.Forms.Button(); this.lableSceneLibrary = new System.Windows.Forms.Label(); this.buttonSceneLibraryDelete = new System.Windows.Forms.Button(); this.listBoxSceneLibrary = new System.Windows.Forms.ListBox(); this.buttonSceneLibraryClone = new System.Windows.Forms.Button(); this.SuspendLayout(); #region SceneLibrary // // panelSceneLibrary // this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.Location = new System.Drawing.Point(0, 0); this.Name = "panelSceneLibrary"; this.Size = new System.Drawing.Size(300, 200); this.TabIndex = 1; this.Controls.Add(this.buttonAddToSubTemplates); this.Controls.Add(this.lableSceneLibrary); this.Controls.Add(this.buttonSceneLibraryDelete); this.Controls.Add(this.listBoxSceneLibrary); this.Controls.Add(this.buttonSceneLibraryClone); // // lableSceneLibrary // this.lableSceneLibrary.AutoSize = true; this.lableSceneLibrary.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lableSceneLibrary.Location = new System.Drawing.Point(6, 10); this.lableSceneLibrary.Name = "lableSceneLibrary"; this.lableSceneLibrary.Size = new System.Drawing.Size(114, 20); this.lableSceneLibrary.TabIndex = 13; this.lableSceneLibrary.Text = "SceneLibrary"; // // buttonSceneLibraryClone // this.buttonSceneLibraryClone.Location = new System.Drawing.Point(12, 139); this.buttonSceneLibraryClone.Name = "buttonSceneLibraryClone"; this.buttonSceneLibraryClone.Size = new System.Drawing.Size(46, 22); this.buttonSceneLibraryClone.TabIndex = 12; this.buttonSceneLibraryClone.Text = "Clone"; this.buttonSceneLibraryClone.UseVisualStyleBackColor = true; this.buttonSceneLibraryClone.Click += new System.EventHandler(this.ObjectLibraryClone_Click); // // buttonSceneLibraryDelete // this.buttonSceneLibraryDelete.Location = new System.Drawing.Point(64, 139); this.buttonSceneLibraryDelete.Name = "buttonSceneLibraryDelete"; this.buttonSceneLibraryDelete.Size = new System.Drawing.Size(46, 22); this.buttonSceneLibraryDelete.TabIndex = 13; this.buttonSceneLibraryDelete.Text = "Delete"; this.buttonSceneLibraryDelete.UseVisualStyleBackColor = true; this.buttonSceneLibraryDelete.Click += new System.EventHandler(this.ObjectLibraryDelete_Click); // // listBoxSceneLibrary // this.listBoxSceneLibrary.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.listBoxSceneLibrary.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); this.listBoxSceneLibrary.ForeColor = System.Drawing.Color.Maroon; this.listBoxSceneLibrary.FormattingEnabled = true; this.listBoxSceneLibrary.Location = new System.Drawing.Point(10, 38); this.listBoxSceneLibrary.Name = "listBoxSceneLibrary"; this.listBoxSceneLibrary.Size = new System.Drawing.Size(245, 95); this.listBoxSceneLibrary.TabIndex = 0; this.listBoxSceneLibrary.SelectedIndexChanged += new System.EventHandler(this.ObjectLibrary_SelectedIndexChanged); // // buttonAddToSubTemplates // this.buttonAddToSubTemplates.Location = new System.Drawing.Point(136, 8); this.buttonAddToSubTemplates.Name = "buttonAddToSubTemplates"; this.buttonAddToSubTemplates.Size = new System.Drawing.Size(118, 22); this.buttonAddToSubTemplates.TabIndex = 19; this.buttonAddToSubTemplates.Text = "To SubTemplates"; this.buttonAddToSubTemplates.UseVisualStyleBackColor = false; #endregion this.ResumeLayout(false); this.PerformLayout(); } #region ObjectLibrary Panel private void ObjectLibraryLoad_Click(object sender, EventArgs e) { fdlg.Title = "DarkWynter - Open"; //fdlg.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); fdlg.InitialDirectory = "$(ProjectDir)"; fdlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; fdlg.FilterIndex = 1; fdlg.RestoreDirectory = true; string fileName = ""; if (fdlg.ShowDialog() == DialogResult.OK) { fileName = fdlg.FileName; // Clear Lists panelContent = new List(); this.listBoxSceneLibrary.Items.Clear(); try { // Load physics, music, and fog XmlDocument reader = new XmlDocument(); reader.Load(fileName); //reader.Load("_xml/LevelEdit/desert.xml"); XmlNodeList allNodes = reader.ChildNodes; foreach (XmlNode settingsNode in allNodes) { if (settingsNode.Name == "level") { XmlNodeList settingsNodes = settingsNode.ChildNodes; foreach (XmlNode node in settingsNodes) { if (node.Name != "#comment") { this.listBoxSceneLibrary.Items.Add(node.Name); panelContent.Add(new ContentPanel(node, ContentLoader.location, ContentLoader.size)); } } } } } catch { System.Diagnostics.Debug.WriteLine("Error reading xml"); throw new Exception("Error reading XML"); } } } private void ObjectLibrarySave_Click(object sender, EventArgs e) { sfdl.Title = "DarkWynter - Save"; sfdl.InitialDirectory = "$(ProjectDir)"; sfdl.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; sfdl.FilterIndex = 1; sfdl.RestoreDirectory = true; string fileName = ""; if (sfdl.ShowDialog() == DialogResult.OK) { fileName = sfdl.FileName; XmlTextWriter settingsFile = new XmlTextWriter(fileName, null); settingsFile.Formatting = Formatting.Indented; settingsFile.WriteStartDocument(); settingsFile.WriteStartElement("level"); settingsFile.WriteAttributeString("name", "TestLevel"); for (int i = 0; i < panelContent.Count; i++) { panelContent[i].ToXml(settingsFile); } settingsFile.WriteEndElement(); settingsFile.WriteEndDocument(); settingsFile.Flush(); settingsFile.Close(); } } private void ObjectLibrary_SelectedIndexChanged(object sender, EventArgs e) { //Load panel selected by user in ListBox currentContentPanel = this.listBoxSceneLibrary.SelectedIndex; if (currentContentPanel != -1) { // Assumes ListBox and contentPanels use same indexing //ClearPropertiesPanel(); this.Controls.Add(panelContent[currentContentPanel]); } } private void ObjectLibraryDelete_Click(object sender, EventArgs e) { int selectedIndex = this.listBoxSceneLibrary.SelectedIndex; this.listBoxSceneLibrary.Items.RemoveAt(selectedIndex); panelContent.RemoveAt(selectedIndex); } private void ObjectLibraryClone_Click(object sender, EventArgs e) { int selectedIndex = this.listBoxSceneLibrary.SelectedIndex; if (selectedIndex != -1) { ContentPanel clonePanel = this.panelContent[selectedIndex].Clone(); panelContent.Add(clonePanel); this.listBoxSceneLibrary.Items.Add(clonePanel.panelName); } } #endregion } }