//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.Xml; using System.ComponentModel.Design; using DarkWynter.Engine.Utilities; namespace DarkWynter.Shell { // Create the UserControl as a Design-Time Control Container [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] /// /// UserControl Assembly Description (UCAD) /// UCAD uses an xml description to automatically load (Forms.) UserControls from compiled dll libraries /// /// UCAD automatically configures a TabPane per dll loaded. /// Each TabPane contains a Button per UserControl that provides access to it's interface. /// An optional Label syntax enables submenu configurations. /// /// Configurable Color settings are found in UCAD_Settings.cs /// /// This file (UCAD.cs) is configured as a UserControl to allow embedding into parent Forms, etc. /// It also provides an interaction point for modifying the layout of the UCAD control. /// /// To ship a final application built on UCAD, reconfigure to load UCAD_Xml file from the loaded lib. /// Alternatively, you may consider embedding the xml file into the final exe. /// /// public partial class UCAD : UserControl, IUCAD { /// /// Allows user to access the top-level form. /// public static Form _UCAD_ParentForm; public Form UCAD_ParentForm { get { return _UCAD_ParentForm; } set { _UCAD_ParentForm = value; } } /// /// Allows user to access the floating child form. /// public static Form _UCAD_ChildForm; public Form UCAD_ChildForm { get { return _UCAD_ChildForm; } set { _UCAD_ChildForm = value; } } /// /// Allows user to load xml FormName attribute into form header, etc. /// public static UserControl _UCAD_Self; public UserControl UCAD_Self { get { return _UCAD_Self; } set { _UCAD_Self = value; } } /// /// Allows user to load xml FormName attribute into form header, etc. /// public static string _UCAD_FormName; public string UCAD_FormName { get { return _UCAD_FormName; } set { _UCAD_FormName = value; } } /// /// The upper-right panel of the display area. /// public static Panel _UCAD_Main_Panel; public Panel UCAD_Main_Panel { get { return _UCAD_Main_Panel; } set { _UCAD_Main_Panel = value; } } /// /// The left panel of the display area. /// public static Panel _UCAD_Left_Panel; public Panel UCAD_Left_Panel { get { return _UCAD_Left_Panel; } set { _UCAD_Left_Panel = value; } } /// /// The right panel of the display area. /// public static Panel _UCAD_Right_Panel; public Panel UCAD_Right_Panel { get { return _UCAD_Right_Panel; } set { _UCAD_Right_Panel = value; } } /// /// The bottom panel of the display area. /// public static Panel _UCAD_Bottom_Panel; public Panel UCAD_Bottom_Panel { get { return _UCAD_Bottom_Panel; } set { _UCAD_Bottom_Panel = value; } } /// /// The bottom panel of the display area. /// public static Panel _UCAD_Top_Panel; public Panel UCAD_Top_Panel { get { return _UCAD_Top_Panel; } set { _UCAD_Top_Panel = value; } } /// /// The bottom panel of the display area. /// public static Panel _RandomVar; public Panel RandomVar { get { return _RandomVar; } set { _RandomVar = value; } } public static SplitContainer UCAD_Bottom_SplitContainer; public static SplitContainer UCAD_Left_SplitContainer; public static SplitContainer UCAD_Right_SplitContainer; public UCAD() { // Parent and Child Forms are statically accessible. // Associations must be made before InitializeComponent // Otherwise, they are not accessible during UCAD initialization. UCAD_ParentForm = GameForm.parentForm; UCAD_ChildForm = GameForm.childForm; UCAD_Self = this; InitializeComponent(); this.Dock = DockStyle.Fill; UCAD_Main_Panel = this.panelMain; UCAD_Left_Panel = this.panelLeft; UCAD_Right_Panel = this.panelRight; UCAD_Bottom_Panel = this.panelBottom; UCAD_Bottom_SplitContainer = this.UCAD_BottomSplitContainer; UCAD_Left_SplitContainer = this.UCAD_LeftSplitContainer; UCAD_Right_SplitContainer = this.UCAD_RightSplitContainer; // Auto load default menu load_UCAD_File("UCAD_CompilerLibrary.xml"); ToggleFullscreen_Click(new Object(), new EventArgs()); } protected override void OnCreateControl() { base.OnCreateControl(); this.ParentForm.FormClosing += new FormClosingEventHandler(DarkWynter.Engine.DarkWynterEngine.DoExit); } /// /// Choose which UCAD xml file to open using a File Dialog. /// /// public void load_UCAD_Dialog() { List fileNames = new List(); // Launch the FolderBrowserDialog Control if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { // Record FolderBrowserDialog result in Directory TextBox, enabling user to inspect and edit the path. fileNames.AddRange(this.openFileDialog1.FileNames); } // Load all user requested UCAD files for (int i = 0; i < fileNames.Count; i++) { load_UCAD_File(fileNames[i]); } } public void load_UCAD_File(string xmlFileName) { this.SuspendLayout(); // Read the Xml File try { XmlDocument reader = new XmlDocument(); reader.Load(xmlFileName); // Unpack the UCAD file foreach (XmlNode UCAD_node in reader.ChildNodes) { // Root xml node if (UCAD_node.Name == "UserControlAssemblyDescription") { // Text used in the Forms Title Bar UCAD_FormName = UCAD_node.Attributes["formText"].Value; // Add a custom MenuStrip to the Tool Container this.toolStripContainer2.BottomToolStripPanel.Controls.Add( new UCAD_MenuStrip(UCAD_node) ); } } } catch { System.Diagnostics.Debug.WriteLine("Error reading xml"); throw new Exception("Error reading XML"); } this.ResumeLayout(false); this.PerformLayout(); } /// /// Handles UCAD_Button Click events. /// Gets the UCAD_Button's UserControl and adds it to the main panel /// /// UCAD_Button that the user clicked. /// Generic EventArgs public static void Load_Control(object sender, EventArgs e) { // Type Checking if (sender is UCAD_Control) { // Get currently selected button UCAD_Control UCAD_Item = sender as UCAD_Control; if (UCAD_Item.GetControlLocation() == "Main") { // Add the buttons UserControl to the main panel UCAD._UCAD_Main_Panel.Controls.Clear(); UCAD._UCAD_Main_Panel.Controls.Add(UCAD_Item.GetUserControl()); } if (UCAD_Item.GetControlLocation() == "Left") { // Add the buttons UserControl to the main panel UCAD._UCAD_Left_Panel.Controls.Clear(); UCAD._UCAD_Left_Panel.Controls.Add(UCAD_Item.GetUserControl()); } if (UCAD_Item.GetControlLocation() == "Right") { // Add the buttons UserControl to the main panel UCAD._UCAD_Right_Panel.Controls.Clear(); UCAD._UCAD_Right_Panel.Controls.Add(UCAD_Item.GetUserControl()); } if (UCAD_Item.GetControlLocation() == "Bottom") { // Add the buttons UserControl to the main panel UCAD._UCAD_Bottom_Panel.Controls.Clear(); UCAD._UCAD_Bottom_Panel.Controls.Add(UCAD_Item.GetUserControl()); } } } public static void Load_ProxyControl(DarkWynter.Engine.Utilities.IUCAD_Control ucadControl) { ucadControl.UCAD_Inteface = UCAD._UCAD_Self as DarkWynter.Engine.Utilities.IUCAD; //ucadControl.UCAD_ParentForm = UCAD._UCAD_ParentForm; //ucadControl.UCAD_ChildForm = UCAD._UCAD_ChildForm; //ucadControl.UCAD_Self = UCAD._UCAD_Self; //ucadControl.UCAD_FormName = UCAD._UCAD_FormName; //ucadControl.UCAD_Main_Panel = UCAD._UCAD_Main_Panel; //ucadControl.UCAD_Top_Panel = UCAD._UCAD_Top_Panel; //ucadControl.UCAD_Bottom_Panel = UCAD._UCAD_Bottom_Panel; //ucadControl.UCAD_Left_Panel = UCAD._UCAD_Left_Panel; //ucadControl.RandomVar = UCAD._UCAD_Top_Panel; } #region Panel Collapse and Expand public void LeftPanelCollapse() { UCAD.UCAD_Left_SplitContainer.Panel1Collapsed = true; } public void RightPanelCollapse() { UCAD.UCAD_Right_SplitContainer.Panel2Collapsed = true; } public void BottomPanelCollapse() { UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed = true; } public void LeftPanelExpand() { UCAD.UCAD_Left_SplitContainer.Panel1Collapsed = false; } public void RightPanelExpand() { UCAD.UCAD_Right_SplitContainer.Panel2Collapsed = false; } public void BottomPanelExpand() { UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed = false; } public void ToggleFullscreen_Click(object sender, EventArgs e) { if (UCAD.UCAD_Left_SplitContainer.Panel1Collapsed == true || UCAD.UCAD_Right_SplitContainer.Panel2Collapsed == true || UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed == true ) { LeftPanelExpand(); RightPanelExpand(); BottomPanelExpand(); toggleFullscreenToolStripMenuItem.Text = "Full-Screen"; } else { LeftPanelCollapse(); RightPanelCollapse(); BottomPanelCollapse(); toggleFullscreenToolStripMenuItem.Text = "Editor-Mode"; } } private void compilerToolStripMenuItem_Click(object sender, EventArgs e) { if (UCAD.UCAD_Left_SplitContainer.Panel1Collapsed == true) { LeftPanelExpand(); } else { LeftPanelCollapse(); } } private void instructionsToolStripMenuItem_Click(object sender, EventArgs e) { if (UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed == true ) { BottomPanelExpand(); } else { BottomPanelCollapse(); } } private void objectEditorToolStripMenuItem_Click(object sender, EventArgs e) { if (UCAD.UCAD_Right_SplitContainer.Panel2Collapsed == true) { RightPanelExpand(); } else { RightPanelCollapse(); } } #endregion private void saveLogToolStripMenuItem_Click(object sender, EventArgs e) { //Logging.writeG2LSurvey(name); //Logging.writeG2LPositionalLog(name); Application.Exit(); } private void userControlsToolStripMenuItem_Click(object sender, EventArgs e) { load_UCAD_Dialog(); } } }