Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Reflection;
- using Microsoft.Xna.Framework.Input;
- using Nuclex.UserInterface.Controls;
- using Nuclex.UserInterface.Controls.Desktop;
- using Nuclex.UserInterface;
- using SpeechLib;
- using System.Xml.Linq;
- namespace Space_Total_Conflict
- {
- public class Dialog
- : WindowControl
- {
- private StringBuilder textToSpeach;
- private String title;
- private UniRectangle rectangle;
- private Dictionary<ButtonControl, ButtonParameters> buttons;
- public Dialog(String xml)
- {
- buttons = new Dictionary<ButtonControl, ButtonParameters> ();
- XDocument doc = XDocument.Parse(xml);
- XElement tree = doc.Element("dialog");
- rectangle = new UniRectangle(
- new UniScalar(float.Parse(tree.Attribute("fx").Value), float.Parse(tree.Attribute("x").Value)),
- new UniScalar(float.Parse(tree.Attribute("fy").Value), float.Parse(tree.Attribute("y").Value)),
- float.Parse(tree.Attribute("width").Value),
- float.Parse(tree.Attribute("height").Value)
- );
- title = tree.Attribute("title").Value;
- this.Bounds = rectangle;
- this.Title = title;
- IEnumerable<XElement> elements = tree.Elements("control");
- foreach (XElement element in elements)
- {
- UniRectangle bounds = new UniRectangle(
- new UniScalar(float.Parse(element.Attribute("fx").Value), float.Parse(element.Attribute("x").Value)),
- new UniScalar(float.Parse(element.Attribute("fy").Value), float.Parse(element.Attribute("y").Value)),
- float.Parse(element.Attribute("width").Value),
- float.Parse(element.Attribute("height").Value)
- );
- switch (element.Attribute("type").Value)
- {
- case "label":
- {
- LabelControl label = new LabelControl
- {
- Bounds = bounds,
- Text = element.Element ("text").Value
- };
- textToSpeach.Append (element.Element("tts").Value);
- Children.Add(label);
- break;
- }
- case "button":
- {
- ButtonControl button = new ButtonControl
- {
- Bounds = bounds,
- Text = element.Element("text").Value,
- };
- button.Pressed += delegate(object sender, EventArgs arguments)
- {
- ButtonParameters buttonParameters = buttons[(ButtonControl)sender];
- Assembly MyAssembly = Assembly.Load("Space_Total_Conflict");
- Type MyType = MyAssembly.GetType("Space_Total_Conflict." + buttonParameters.ControlObject);
- try
- {
- MyType.InvokeMember (buttonParameters.Method,
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null, null, new object[] { }
- );
- }
- catch (MissingMethodException e)
- {
- // You shouldn't ignore this exception, it should crash if there's something wrong so you can catch it early
- if (Debugger.IsAttached)
- throw e;
- }
- };
- buttons.Add (button, new ButtonParameters (element.Element ("object").Value, element.Element ("method").Value));
- Children.Add(button);
- break;
- }
- case "input":
- {
- InputControl input = new InputControl
- {
- Bounds = bounds
- };
- Children.Add(input);
- break;
- }
- }
- }
- }
- private void okClicked(object sender, EventArgs arguments)
- {
- Close();
- }
- private void cancelClicked(object sender, EventArgs arguments)
- {
- Close();
- }
- }
- public class ButtonParameters
- {
- public ButtonParameters (string controlObject, string method)
- {
- this.ControlObject = controlObject;
- this.Method = method;
- }
- public string ControlObject
- {
- get;
- private set;
- }
- public string Method
- {
- get;
- private set;
- }
- }
- }
Add Comment
Please, Sign In to add comment