Пример #1
0
        void SetWorkingScript(LuaScriptAsset script)
        {
            if (Globals.WorkingFrames != null)
            {
                UnsetWorkingFrames();
            }
            if (Globals.WorkingAnimation != null)
            {
                UnsetWorkingAnimation();
            }
            if (Globals.WorkingScript != null)
            {
                UnsetWorkingScript();
            }

            Globals.WorkingScript  = script;
            luaScriptBox1.ReadOnly = script.bReadOnly;
            luaScriptBox1.SetScript(script.Script);

            scriptToolStripMenuItem.Visible = true;
        }
Пример #2
0
        private void tvAssets_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Text.EndsWith(Frames.FileExtension))
            {
                ActivateWorkspaceTabPage(tabFramesEditor);
                //UnsetWorkingAnimation();
                //UnsetWorkingFrames();

                Frames frame     = null;
                string framepath = GetFullPathForNode(e.Node);
                if ((e.Node as AssetTreeNode).Asset != null)
                {
                    frame = (e.Node as AssetTreeNode).Asset as Frames;
                }
                else
                {
                    frame = Frames.LoadFromFile(framepath);
                    (e.Node as AssetTreeNode).Asset = frame;
                }

                if (frame != null)
                {
                    frame.bReadOnly           = GetReadOnlyStatus(e.Node);
                    e.Node.ImageIndex         = (int)EAssetImageList.Frames;
                    e.Node.SelectedImageIndex = (int)EAssetImageList.Frames;

                    if (string.IsNullOrEmpty(frame.image))
                    {
                        string imagepath = framepath.Substring(0, framepath.Length - Path.GetFileName(framepath).Length);
                        string imagename = Path.GetFileNameWithoutExtension(framepath) + ".png";
                        if (File.Exists(imagepath + imagename))
                        {
                            DialogResult dr = MessageBox.Show("Image is unset! Do you want to try using " + imagename + "?", "Missing image", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == DialogResult.Yes)
                            {
                                frame.image = imagename;
                                try
                                {
                                    Image img = Image.FromFile(imagepath + imagename);
                                    frame.Img = img.Clone() as Image;
                                    img.Dispose();
                                }
                                catch
                                {
                                    if (frame.Img != null)
                                    {
                                        frame.Img.Dispose();
                                        frame.Img = null;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // load the referenced image
                        // going to have issues with images using relative paths

                        string imagepath = "";

                        if (frame.image.Contains("/"))
                        {
                        }
                        else
                        {
                            imagepath = framepath.Substring(0, framepath.Length - Path.GetFileName(framepath).Length) + frame.image;
                        }

                        try
                        {
                            Image img = Image.FromFile(imagepath);
                            frame.Img = img.Clone() as Image;
                            img.Dispose();
                        }
                        catch
                        {
                            if (frame.Img != null)
                            {
                                frame.Img.Dispose();
                                frame.Img = null;
                            }
                        }
                    }

                    if (frame.Img == null)
                    {
                        int w = 0;
                        int h = 0;
                        if (frame.frameGrid != null)
                        {
                            w = frame.frameGrid.size[0] * frame.frameGrid.dimensions[0];
                            h = frame.frameGrid.size[1] * frame.frameGrid.dimensions[1];
                        }
                        else if (frame.frameList != null)
                        {
                        }
                        if ((w > 0) && (h > 0))
                        {
                            Bitmap bmp = new Bitmap(w, h);
                            using (Graphics graph = Graphics.FromImage(bmp))
                            {
                                Rectangle ImageSize = new Rectangle(0, 0, w, h);
                                graph.FillRectangle(Brushes.Black, ImageSize);
                            }
                            frame.Img = bmp;
                        }
                    }

                    SetWorkingFrames(frame);
                }
                else
                {
                    tbSource.Text             = "";
                    e.Node.ImageIndex         = (int)EAssetImageList.FramesBad;
                    e.Node.SelectedImageIndex = (int)EAssetImageList.FramesBad;
                }

                if (tabWorkspace.SelectedTab == tabFramesEditor)
                {
                    tabFramesEditor.Invalidate();
                }
                else
                {
                    tabWorkspace.SelectedTab = tabFramesEditor;
                }
                tabWorkspace.Visible = true;
            }
            else if (e.Node.Text.EndsWith(Animation.FileExtension))
            {
                ActivateWorkspaceTabPage(tabAnimationEditor);

                Animation anim = null;
                if ((e.Node as AssetTreeNode).Asset != null)
                {
                    anim = (e.Node as AssetTreeNode).Asset as Animation;
                }
                else
                {
                    anim = Animation.LoadFromFile(GetFullPathForNode(e.Node));
                    (e.Node as AssetTreeNode).Asset = anim;
                }

                if (anim != null)
                {
                    anim.bReadOnly            = GetReadOnlyStatus(e.Node);
                    e.Node.ImageIndex         = (int)EAssetImageList.Frames;
                    e.Node.SelectedImageIndex = (int)EAssetImageList.Frames;

                    SetWorkingAnimation(anim);
                }
                else
                {
                    tbSource.Text = "";
                }
            }
            else if (e.Node.Text.EndsWith(LuaScriptAsset.FileExtension))
            {
                ActivateWorkspaceTabPage(tabScriptEditor);

                LuaScriptAsset script = null;
                if ((e.Node as AssetTreeNode).Asset != null)
                {
                    script = (e.Node as AssetTreeNode).Asset as LuaScriptAsset;
                }
                else
                {
                    script = LuaScriptAsset.LoadFromFile(GetFullPathForNode(e.Node));
                    (e.Node as AssetTreeNode).Asset = script;
                }

                if (script != null)
                {
                    script.bReadOnly = GetReadOnlyStatus(e.Node);
                    SetWorkingScript(script);
                    e.Node.ImageIndex         = (int)EAssetImageList.LuaScript;
                    e.Node.SelectedImageIndex = (int)EAssetImageList.LuaScript;
                }
                else
                {
                    e.Node.ImageIndex         = (int)EAssetImageList.LuaScriptBad;
                    e.Node.SelectedImageIndex = (int)EAssetImageList.LuaScriptBad;
                }

                if (tabWorkspace.SelectedTab == tabScriptEditor)
                {
                    tabScriptEditor.Invalidate();
                }
                else
                {
                    tabWorkspace.SelectedTab = tabScriptEditor;
                }
                tabWorkspace.Visible = true;
            }

            /*else if (e.Node != null)
             * {
             *      // clear out whatever was there
             *
             *      tabWorkspace.Visible = false;
             *      tbSource.Text = "";
             * }*/
        }
Пример #3
0
        public new static LuaScriptAsset LoadFromFile(string path)
        {
            LuaScriptAsset lsa = new LuaScriptAsset(Asset.LoadFromFile(path));

            return(lsa);
        }