示例#1
0
        public void GameObjectsCanvas_Drop(object sender, DragEventArgs e)
        {
            Element element = e.Data.GetData(typeof(Element)) as Element;
            if (element != null)
            {
                System.Console.WriteLine("dropped " + element);
                GameObject pGo = App.ObjectBuilder.click(e.GetPosition(sender as Canvas)) as GameObject;
                Element newElement = new Element(element);
                if (pGo != null)
                {
                    pGo.Add(newElement);
                }
                else
                {
                    pGo = App.newGameObject();
                    if (pGo != null)
                    {
                        pGo.Position = e.GetPosition(sender as Canvas);
                        pGo.Add(newElement);
                    }
                }
            }
            ObjectBuilder ob = e.Data.GetData(typeof(ObjectBuilder)) as ObjectBuilder;
            if (ob != null && ob.IsMacro)
            {
                if (ob.IsRegistered || ob.IsLive)
                {
                    // TODO: Show Macro window
                    MacroCall macroCall = new MacroCall();
                    macroCall.Position = e.GetPosition(sender as Canvas);
                    macroCall.Macro = ob;
                    if (ob != App.ObjectBuilder)
                    {
                        App.ObjectBuilder.ScriptObjects.Add(macroCall);
                    }
                    else
                    {
                        MessageBox.Show("Cannot call Macro from within itself!", "Error");
                    }
                }
                else
                {
                    App.registerMacroInScript(ob);

                    (App.MainWindow as MainWindow).sortMacros();
                }
            }
        }
示例#2
0
        public void deserializeFromXml(string filename)
        {
            m_document.Load(filename);

            XmlNode objectBuilderNode = Helper.XmlHelper.getNodeByName(m_document.ChildNodes, "ObjectBuilder");
            if (objectBuilderNode == null)
                return;

            Parameters.Clear();
            m_scriptObjects.Clear();

            foreach (XmlAttribute attrib in objectBuilderNode.Attributes)
            {
                if (attrib.Name == "name")
                    this.m_name = attrib.Value;
                else if (attrib.Name == "offset_x")
                {
                    double x;
                    if (double.TryParse(attrib.Value, out x))
                        m_offset.X = x;
                }
                else if (attrib.Name == "offset_y")
                {
                    double y;
                    if (double.TryParse(attrib.Value, out y))
                        m_offset.Y = y;
                }
                else if (attrib.Name == "is_macro")
                {
                    bool.TryParse(attrib.Value, out this.m_isMacro);
                }
            }

            // Parameters
            XmlNode parameterNode = Helper.XmlHelper.getNodeByName(objectBuilderNode.ChildNodes, "Parameters");
            if (parameterNode != null)
            {
                foreach (XmlNode parameter in parameterNode.ChildNodes)
                {
                    if (parameter is XmlElement && parameter.Name == "Parameter")
                    {
                        XmlElement param = parameter as XmlElement;
                        Parameter p = new Parameter();
                        p.deserializeFromXml(param);
                        AddParameter(p);
                    }
                }
            }

            // Objects
            XmlNode objectsNode = Helper.XmlHelper.getNodeByName(objectBuilderNode.ChildNodes, "Objects");
            if (objectsNode != null)
            {
                foreach (XmlNode object_ in objectsNode.ChildNodes)
                {
                    if (object_ is XmlElement)
                    {
                        IScriptObject so = null;
                        XmlElement obj = object_ as XmlElement;
                        if (obj.Name == "GameObject")
                        {
                            so = new GameObject(this);
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "MacroCall")
                        {
                            so = new MacroCall();
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "MacroRegistration")
                        {
                            so = new MacroRegistration();
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "FunctionCall")
                        {
                            so = new FunctionCall();
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "Function")
                        {
                            so = new Function();
                            so.deserializeFromXml(obj);
                        }
                        if (so != null)
                            m_scriptObjects.Add(so);
                    }
                }
            }
        }
示例#3
0
        public void deserialize(System.IO.BinaryReader br)
        {
            Parameters.Clear();
            m_scriptObjects.Clear();

            Name = br.ReadString();
            Point p = new Point();
            p.X = br.ReadDouble();
            p.Y = br.ReadDouble();
            m_isMacro = br.ReadBoolean();
            int parameterCount = br.ReadInt32();
            for (int i = 0; i < parameterCount; ++i)
            {
                Parameter param = new Parameter();
                param.deserialize(br);
                AddParameter(param);
            }
            m_offset = p;
            int goCount = br.ReadInt32();
            for (int i = 0; i < goCount; ++i)
            {
                String type = br.ReadString();
                IScriptObject so = null;
                if (type == "GameObject")
                {
                    so = new GameObject(this);
                }
                else if (type == "MacroCall")
                {
                    so = new MacroCall();
                }
                else if (type == "MacroRegistration")
                {
                    so = new MacroRegistration();
                }
                else if (type == "FunctionCall")
                {
                    so = new FunctionCall();
                }
                else if (type == "Function")
                {
                    so = new Function();
                }
                if (so != null)
                {
                    so.deserialize(br);
                    so.ParentObjectBuilder = this;
                    m_scriptObjects.Add(so);
                }
            }
        }