Example #1
0
        //导出皮肤
        private void OutputToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (GlobalConfig.Project != null)
            {
                Form_OutPut outputForm = new Form_OutPut(GlobalConfig.Project.Developer,
                                                         GlobalConfig.Project.GetDefaultOutputPath(),
                                                         delegate() {
                    Form_Progress form_Progress = new Form_Progress(100, true);
                    form_Progress.Location      = new Point((displayWidth - form_Progress.Width) / 2, (displayHeight - form_Progress.Height) / 2);
                    form_Progress.Show();

                    string err = GlobalConfig.Controller.StartOutput(
                        GlobalConfig.Project.CarConfig.outputs,
                        GlobalConfig.Project.CarConfig.PropertyIdMapping,
                        GlobalConfig.Project.GetDefaultOutputPath(),
                        form_Progress);
                    if (err != null)
                    {
                        Console.WriteLine("-------------------> result " + err);
                    }
                });
                outputForm.SetDesktopBounds(Form_Main.displayWidth / 4, 80, Form_Main.displayWidth / 2, Form_Main.displayHeight / 2 + 150);
                outputForm.Show();
            }
        }
Example #2
0
        private void loadScene(TreeView treeview, CarConfig carConfig)
        {
            Form_Progress form_Progress = new Form_Progress(carConfig.GetTotalSceneNum(), false);

            form_Progress.Location = new Point((displayWidth - form_Progress.Width) / 2, (displayHeight - form_Progress.Height) / 2);
            form_Progress.Show();

            GlobalConfig.Controller.HideCenterBoardPictureBox();

            rightPanel.SuspendLayout();
            treeview.BeginUpdate();
            foreach (Scene scene in carConfig.Scenes)
            {
                TreeNode sceneNode = new TreeNode
                {
                    Name = scene.Id.ToString(),
                    Text = scene.Name
                };
                GlobalConfig.Controller.InitScene(scene.Id, true);

                foreach (Scene childScene in scene.children)
                {
                    sceneNode.Nodes.Add(new TreeNode
                    {
                        Name = childScene.Id.ToString(),
                        Text = childScene.Name
                    });

                    GlobalConfig.Controller.InitScene(childScene.Id, true);
                    form_Progress.AddProgressValue(1, string.Format("场景 {0} 已加载", childScene.Name));
                }

                form_Progress.AddProgressValue(1, string.Format("场景 {0} 已加载", scene.Name));
                treeview.Nodes.Add(sceneNode);
            }


            treeview.EndUpdate();
            rightPanel.ResumeLayout();

            GlobalConfig.Controller.ShowCenterBoardPictureBox();

            form_Progress.Close();
            form_Progress.Dispose();
        }
        public string StartOutput(Outputs outputs, Dictionary <int, Property> propertyIdMapping, string basePath, Form_Progress progressForm)
        {
            progressForm.SetProgressMax(outputs.ImageOutputs.Length + outputs.XmlOutputs.Length + outputs.MergeImageOutputs.Length);

            foreach (ImageOutput imageOutout in outputs.ImageOutputs)
            {
                if (!propertyIdMapping.ContainsKey(imageOutout.PropertyId))
                {
                    return(Errors.PropertyIdNotExist);
                }

                Property property = propertyIdMapping[imageOutout.PropertyId];

                Control[] controls = GetSceneFlowLayoutPanel(property.SceneId).Controls.Find(property.GetPictureBoxId(), true);
                if (controls == null || controls.Length == 0)
                {
                    return(Errors.UiPictureBoxNotExist);
                }

                try
                {
                    string newFile = Path.Combine(basePath, imageOutout.Target);
                    string dirName = newFile.Substring(0, newFile.LastIndexOf('\\'));

                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    ((PictureBox)(controls[0])).Image.Save(newFile);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }
                progressForm.AddProgressValue(1, string.Format("组件:{0},   属性: {1} 导出完毕", property.GroupName, property.Name));
            }

            foreach (XmlOutput xmlOutout in outputs.XmlOutputs)
            {
                if (!propertyIdMapping.ContainsKey(xmlOutout.PropertyId))
                {
                    return(Errors.PropertyIdNotExist);
                }
                Property property = propertyIdMapping[xmlOutout.PropertyId];


                Control[] controls = null;
                if (property.OptType == PropertyOperateType.AlphaWhiteImageSetAlpha)
                {
                    controls = GetSceneFlowLayoutPanel(property.SceneId).Controls.Find(property.GetTextBoxAlphaID(), true);
                }
                else if (property.OptType == PropertyOperateType.AlphaWhiteImageSetColor)
                {
                    controls = GetSceneFlowLayoutPanel(property.SceneId).Controls.Find(property.GetTextBoxColorID(), true);
                }

                if (controls == null || controls.Length == 0)
                {
                    return(Errors.UiPictureBoxNotExist);
                }
                progressForm.AddProgressValue(1, string.Format("组件:{0}, 属性: {1} 导出完毕", property.GroupName, property.Name));
            }


            List <PngUtil.MergeImageParams> list = new List <PngUtil.MergeImageParams>();

            foreach (MergeImageOutput MergeImageOutPut in outputs.MergeImageOutputs)
            {
                Dictionary <int, Property> map = MergeImageOutPut.GetPropertyMap();
                foreach (int proertyId in map.Keys)
                {
                    if (!propertyIdMapping.ContainsKey(proertyId))
                    {
                        return(Errors.PropertyIdNotExist);
                    }

                    Property propertItem = propertyIdMapping[proertyId];
                    if (map.ContainsKey(propertItem.RefPropertyId))   //如果出现引用形式, 则此图不需要参与合成
                    {
                        continue;
                    }

                    Control[] controls = GetSceneFlowLayoutPanel(propertItem.SceneId).Controls.Find(propertItem.GetPictureBoxId(), true);
                    if (controls == null || controls.Length == 0)
                    {
                        return(Errors.UiPictureBoxNotExist);
                    }


                    list.Add(new PngUtil.MergeImageParams
                    {
                        Image = ((PictureBox)(controls[0])).Image,
                    });
                }
                ;

                Image image = null;
                if (list.Count == 1)
                {
                    image = list[0].Image;
                }
                else
                {
                    image = PngUtil.MergeImageList(list, list[0].Image.Width, list[0].Image.Height);
                }

                try
                {
                    string newFile = Path.Combine(basePath, MergeImageOutPut.Target);
                    string dirName = newFile.Substring(0, newFile.LastIndexOf('\\'));

                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    image.Save(newFile);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }

                list.Clear();
                progressForm.AddProgressValue(1, string.Format("图片合成导出完毕"));
            }

            return(null);
        }