public void InitForFrames(Frames frame) { Frame = frame; if (Frame.frameGrid != null) { if (Frame.frameGrid.size.Count >= 2) { FrameGrid.size.Width = Frame.frameGrid.size[0]; FrameGrid.size.Height = Frame.frameGrid.size[1]; } else if (Frame.frameGrid.size.Count == 1) { FrameGrid.size.Width = Frame.frameGrid.size[0]; FrameGrid.size.Height = 1; Frame.frameGrid.size.Add(1); } else { FrameGrid.size.Width = 1; FrameGrid.size.Height = 1; Frame.frameGrid.size.Add(1); Frame.frameGrid.size.Add(1); } if (Frame.frameGrid.dimensions.Count >= 2) { FrameGrid.dimensions.Width = Frame.frameGrid.dimensions[0]; FrameGrid.dimensions.Height = Frame.frameGrid.dimensions[1]; } else if (Frame.frameGrid.dimensions.Count == 1) { FrameGrid.dimensions.Width = Frame.frameGrid.dimensions[0]; FrameGrid.dimensions.Height = 1; Frame.frameGrid.dimensions.Add(1); } else { FrameGrid.dimensions.Width = 1; FrameGrid.dimensions.Height = 1; Frame.frameGrid.dimensions.Add(1); Frame.frameGrid.dimensions.Add(1); } } }
void SetWorkingFrames(Frames frame) { if (Globals.WorkingFrames != null) { UnsetWorkingFrames(); } if (Globals.WorkingAnimation != null) { UnsetWorkingAnimation(); } if (Globals.WorkingScript != null) { UnsetWorkingScript(); } Globals.WorkingFrames = frame; tbSource.Text = frame.Source; FramesProperties.InitForFrames(frame); pgProperties.SelectedObject = FramesProperties; pnlFramesEditor.InitForFrame(); framesToolStripMenuItem2.Visible = true; FrameGridChanged(frame.frameGrid != null); }
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 = ""; * }*/ }