//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// 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
{
#region Properties
///
/// 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; }
}
///
/// MDI-child form which can be used to load usercontrols into a floating mdi form.
///
public static Form childForm;
public static SplitContainer UCAD_Bottom_SplitContainer;
public static SplitContainer UCAD_Left_SplitContainer;
public static SplitContainer UCAD_Right_SplitContainer;
#endregion
public UCAD()
{
UCAD._UCAD_Self = this;
InitializeComponent();
this.Dock = DockStyle.Fill;
UCAD._UCAD_Main_Panel = this.panelMain;
UCAD._UCAD_Left_Panel = this.panelLeft;
UCAD._UCAD_Right_Panel = this.panelRight;
UCAD._UCAD_Bottom_Panel = this.panelBottom;
UCAD.UCAD_Bottom_SplitContainer = this.UCAD_BottomSplitContainer;
UCAD.UCAD_Left_SplitContainer = this.UCAD_LeftSplitContainer;
UCAD.UCAD_Right_SplitContainer = this.UCAD_RightSplitContainer;
ToggleFullscreen_Click(new Object(), new EventArgs());
}
protected override void OnCreateControl()
{
base.OnCreateControl();
this.ParentForm.FormClosing += new FormClosingEventHandler(DarkWynter.Engine.DarkWynterEngine.DoExit);
}
#region UCAD Loading
///
/// Choose which UCAD xml file to open using a File Dialog.
///
///
public void Load_UCAD_Dialog()
{
List fileNames = new List();
openFileDialog1.Filter = "Xml Level File (*.xml)|*.xml|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 0;
openFileDialog1.RestoreDirectory = true;
// Launch the FolderBrowserDialog Control
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// Record FolderBrowserDialog result in Directory TextBox, enabling user to inspect and edit the path.
fileNames.AddRange(openFileDialog1.FileNames);
}
// Load all user requested UCAD files
for (int i = 0; i < fileNames.Count; i++)
{
Load_UCAD_File(fileNames[i]);
}
}
///
/// Loads a UCAD xml file passed in by string parameter.
/// UCAD controls are actually menustrip added Toolstrip container
///
///
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_UCAD_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());
}
}
}
#endregion
#region Panel Collapse and Expand
public static void LeftPanelCollapse()
{
UCAD.UCAD_Left_SplitContainer.Panel1Collapsed = true;
}
public static void RightPanelCollapse()
{
UCAD.UCAD_Right_SplitContainer.Panel2Collapsed = true;
}
public static void BottomPanelCollapse()
{
UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed = true;
}
public static void LeftPanelExpand()
{
UCAD.UCAD_Left_SplitContainer.Panel1Collapsed = false;
}
public static void RightPanelExpand()
{
UCAD.UCAD_Right_SplitContainer.Panel2Collapsed = false;
}
public static 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
#region ToolStrip Menu
///
/// MenuStrip click lauches Load_UCAD_Dialog()
///
///
///
private void importControlsToolStripMenuItem_Click(object sender, EventArgs e)
{
Load_UCAD_Dialog();
}
private void importGameToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
// openFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
openFileDialog1.InitialDirectory = "C:\\Documents and Settings\\Owner\\Desktop\\DWTesseract-Oversoul\\Oversoul\\bin\\x86\\Debug";
openFileDialog1.Filter = "Xml Level File (*.xml)|*.xml|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 0;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// Parse selected file path
string path = openFileDialog1.FileName;
int subfilename = path.LastIndexOf("\\");
string pathName = path.Substring(0, subfilename + 1);
string fileName = path.Substring(subfilename + 1, (path.Length - pathName.Length));
DarkWynter.Engine.DarkWynterEngine.Load_GameIndex(fileName, pathName);
//UCAD.RightPanelExpand();
}
}
private void saveLogToolStripMenuItem_Click(object sender, EventArgs e)
{
//Logging.writeG2LSurvey(name);
//Logging.writeG2LPositionalLog(name);
Application.Exit();
}
#endregion
}
}