Example #1
0
        private void adicionarSomToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "Procurar som";
            openFileDialog1.Filter = "Sons (*.WAV)|*.WAV";
            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);
            DialogResult resultado = openFileDialog1.ShowDialog();

            if (resultado == System.Windows.Forms.DialogResult.OK)
            {
                if (openFileDialog1.FileName.EndsWith(".wav", StringComparison.OrdinalIgnoreCase))
                {
                    if (!LstSons.Items.Contains(openFileDialog1.SafeFileName))
                    {
                        SomWinForm som = new SomWinForm(ProjetoJogo);
                        som.CopiarArquivo(openFileDialog1.FileName);
                        int i = openFileDialog1.FileName.LastIndexOf('\\');
                        som.Nome = openFileDialog1.FileName.Substring(i + 1);
                        ProjetoJogo.AdicionarSom(som);
                    }
                    else
                    {
                        MessageBox.Show("Esse arquivo já está incluso na lista de sons!");
                    }
                }
                else
                {
                    MessageBox.Show("É permitido apenas arquivo do tipo .wav");
                }
            }
        }
Example #2
0
        private void LerArquivoProjeto()
        {
            Type type = typeof(ConcentradorObjeto);
            Type baseInterface;
            ConcentradorObjeto o;
            XmlAttribute attribute;
            PropertyInfo p;

            XmlDocument document = new XmlDocument();
            document.Load(Arquivo);

            XmlNode scripts = document.GetElementsByTagName("Scripts")[0];
            if (scripts.ChildNodes != null)
            {
                foreach (XmlNode scriptNode in scripts.ChildNodes)
                {
                    Script script = new Script();
                    script.NomeAmigavel = scriptNode.Attributes.GetNamedItem("Nome").Value;
                    script.ID = scriptNode.Attributes.GetNamedItem("ID").Value;
                    script.CodigoScript = scriptNode.Attributes.GetNamedItem("Codigo").Value;
                    ListaScripts.Add(script);
                }
            }
            XmlNode jogo = document.GetElementsByTagName("Jogo")[0];

            //Itero as cenas do jogo
            Cena cena;
            foreach (XmlNode cenaNode in jogo.SelectNodes("Cena"))
            {
                cena = new CenaWinForm();
                cena.Nome = cenaNode.Attributes["Nome"].Value;
                cena.Cor = System.Drawing.Color.FromArgb(int.Parse(cenaNode.Attributes["Cor"].Value));

                //Adiciono a lista de cenas para controle
                ListaCena.Add(cena);

                //Itero os objetos
                Type typeOriginal;
                foreach (XmlNode objetoNode in cenaNode.SelectNodes("Objetos/Objeto"))
                {
                    typeOriginal = Assembly.GetAssembly(type).GetType(objetoNode.Attributes["type"].Value);
                    o = (ConcentradorObjeto)typeOriginal.GetConstructor(new Type[] { typeof(Jogo) }).Invoke(new object[] { this });
                    baseInterface = o.BaseInterface;
                    foreach (XmlNode nodeProp in objetoNode.ChildNodes[0].ChildNodes)
                    {
                        attribute = nodeProp.Attributes[0];
                        if (attribute.Name == "Nome")
                        {
                            o.Nome = attribute.Value;
                        }
                        else
                        {
                            p = baseInterface.GetProperty(attribute.Name);
                            if (p.PropertyType == typeof(int))
                            {
                                p.SetValue(o.WinControl, Convert.ToInt32(attribute.Value), null);
                            }
                            else if (p.PropertyType == typeof(float))
                            {
                                p.SetValue(o.WinControl, float.Parse(attribute.Value), null);
                            }
                            else if (p.PropertyType == typeof(System.Drawing.Color))
                            {
                                System.Drawing.Color c = System.Drawing.Color.FromArgb(int.Parse(attribute.Value));
                                p.SetValue(o.WinControl, c, null);
                            }
                            else
                            {
                                p.SetValue(o.WinControl, attribute.Value, null);
                            }
                        }
                    }

                    //Atribuo o script caso exista
                    if (objetoNode.ChildNodes.Count > 1)
                    {
                        o.WinControl.IDScript = objetoNode.ChildNodes[1].Attributes[1].Value;
                    }
                    cena.AdicionarObjeto(o);
                }
            }

            Som som;
            foreach (XmlNode nodeSom in jogo.SelectNodes("Sons/Som"))
            {
                som = new SomWinForm(this);
                attribute = nodeSom.Attributes["CaminhoArquivo"];
                som.CaminhoRelativo = attribute.Value;
                attribute = nodeSom.Attributes["Nome"];
                som.Nome = attribute.Value;
                ListaSom.Add(som);
            }
        }