private void FilesDropOnNodeCreating(FilesDropHandler.NodeCreatingEventArgs nodeCreatingEventArgs) { var nodeUnderMouse = WidgetContext.Current.NodeUnderMouse; if (nodeUnderMouse == null || !nodeUnderMouse.SameOrDescendantOf(RootWidget)) { return; } switch (nodeCreatingEventArgs.AssetType) { case ".png": { if (Document.Current.Rows.Count == 0) { return; } var widget = Document.Current.Rows[cellUnderMouseOnFilesDrop.Y].Components.Get <Core.Components.NodeRow>()?.Node as Widget; if (widget == null) { return; } nodeCreatingEventArgs.Cancel = true; var key = new Keyframe <ITexture> { Frame = cellUnderMouseOnFilesDrop.X + animateTextureCellOffset, Value = new SerializableTexture(nodeCreatingEventArgs.AssetPath) }; Core.Operations.SetKeyframe.Perform(widget, nameof(Widget.Texture), Document.Current.AnimationId, key); animateTextureCellOffset++; break; } case ".ogg": { nodeCreatingEventArgs.Cancel = true; var fileName = Path.GetFileNameWithoutExtension(nodeCreatingEventArgs.AssetPath); var node = Core.Operations.CreateNode.Perform(typeof(Audio)); var sample = new SerializableSample(nodeCreatingEventArgs.AssetPath); Core.Operations.SetProperty.Perform(node, nameof(Audio.Sample), sample); Core.Operations.SetProperty.Perform(node, nameof(Node.Id), fileName); Core.Operations.SetProperty.Perform(node, nameof(Audio.Volume), 1); var key = new Keyframe <AudioAction> { Frame = cellUnderMouseOnFilesDrop.X, Value = AudioAction.Play }; Core.Operations.SetKeyframe.Perform(node, nameof(Audio.Action), Document.Current.AnimationId, key); timeline.FilesDropHandler.OnNodeCreated(node); break; } } }
/// <summary> /// Handles files drop. /// </summary> /// <param name="files">Dropped files.</param> public void Handle(List <string> files) { using (Document.Current.History.BeginTransaction()) { foreach (var file in files.Where(f => Path.GetExtension(f) == ".ogg").ToList()) { files.Remove(file); if (!Utils.ExtractAssetPathOrShowAlert(file, out var assetPath, out var assetType)) { continue; } var node = CreateNode.Perform(typeof(Audio)); var sample = new SerializableSample(assetPath); SetProperty.Perform(node, nameof(Audio.Sample), sample); SetProperty.Perform(node, nameof(Node.Id), Path.GetFileNameWithoutExtension(assetPath)); SetProperty.Perform(node, nameof(Audio.Volume), 1); var key = new Keyframe <AudioAction> { Frame = Document.Current.AnimationFrame, Value = AudioAction.Play }; SetKeyframe.Perform(node, nameof(Audio.Action), Document.Current.AnimationId, key); } Document.Current.History.CommitTransaction(); } }
void DropFiles(IEnumerable <string> files) { if (!InputArea.IsMouseOverThisOrDescendant()) { return; } var widgetPos = MousePosition * Scene.CalcTransitionToSpaceOf(Document.Current.Container.AsWidget); Document.Current.History.BeginTransaction(); try { List <string> pendingImages = new List <string>(); foreach (var file in files) { try { string assetPath, assetType; if (Utils.ExtractAssetPathOrShowAlert(file, out assetPath, out assetType)) { if (assetType == ".png") { pendingImages.Add(assetPath); } else if (assetType == ".ogg") { var node = Core.Operations.CreateNode.Perform(typeof(Audio)); var sample = new SerializableSample(assetPath); Core.Operations.SetProperty.Perform(node, nameof(Audio.Sample), sample); Core.Operations.SetProperty.Perform(node, nameof(Node.Id), Path.GetFileNameWithoutExtension(assetPath)); Core.Operations.SetProperty.Perform(node, nameof(Audio.Volume), 1); var key = new Keyframe <AudioAction> { Frame = Document.Current.AnimationFrame, Value = AudioAction.Play }; Core.Operations.SetKeyframe.Perform(node, nameof(Audio.Action), Document.Current.AnimationId, key); } else if (assetType == ".tan" || assetType == ".model" || assetType == ".scene") { var scene = Node.CreateFromAssetBundle(assetPath); var node = Core.Operations.CreateNode.Perform(scene.GetType()); Core.Operations.SetProperty.Perform(node, nameof(Widget.ContentsPath), assetPath); if (scene is Widget) { Core.Operations.SetProperty.Perform(node, nameof(Widget.Position), widgetPos); Core.Operations.SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); Core.Operations.SetProperty.Perform(node, nameof(Widget.Size), ((Widget)scene).Size); } node.LoadExternalScenes(); } } } catch (System.Exception e) { AlertDialog.Show(e.Message); } } if (pendingImages.Count > 0) { var menu = new Menu() { ImageDropCommands.AsImage, ImageDropCommands.AsDistortionMesh, ImageDropCommands.AsNineGrid, ImageDropCommands.AsParticleModifier, }; ImageDropCommands.AssetPaths = pendingImages; menu.Popup(); } } finally { Document.Current.History.EndTransaction(); } }
public void Handle(List <string> files) { var grid = Timeline.Instance.Grid; var rowLocationUnderMouseOnFilesDrop = SelectAndDragRowsProcessor.MouseToRowLocation(grid.RootWidget.Input.MousePosition); var handled = new List <string>(); var cellUnderMouseOnFilesDrop = grid.CellUnderMouse(); var animateTextureCellOffset = 0; using (Document.Current.History.BeginTransaction()) { foreach (var file in files.ToList()) { if (Document.Current.Animation.IsCompound) { try { // Dirty hack: using a file drag&drop mechanics for dropping animation clips on the grid. var decodedAnimationId = Encoding.UTF8.GetString(Convert.FromBase64String(file)); AddAnimationClip.Perform( new IntVector2( cellUnderMouseOnFilesDrop.X + animateTextureCellOffset, cellUnderMouseOnFilesDrop.Y), decodedAnimationId); return; } catch { } } if (!Utils.ExtractAssetPathOrShowAlert(file, out var assetPath, out var assetType)) { continue; } switch (assetType) { case ".png": { if (Document.Current.Rows.Count == 0) { continue; } var widget = Document.Current.Rows[cellUnderMouseOnFilesDrop.Y].Components.Get <NodeRow>()?.Node as Widget; if (widget == null) { continue; } var key = new Keyframe <ITexture> { Frame = cellUnderMouseOnFilesDrop.X + animateTextureCellOffset, Value = new SerializableTexture(assetPath), Function = KeyFunction.Steep, }; SetKeyframe.Perform(widget, nameof(Widget.Texture), Document.Current.AnimationId, key); animateTextureCellOffset++; break; } case ".ogg": { var node = CreateNode.Perform(typeof(Audio)); if (rowLocationUnderMouseOnFilesDrop.HasValue) { var location = rowLocationUnderMouseOnFilesDrop.Value; var row = Document.Current.Rows.FirstOrDefault(r => r.Components.Get <Core.Components.NodeRow>()?.Node == node); if (row != null) { if (location.Index >= row.Index) { location.Index++; } SelectAndDragRowsProcessor.Probers.Any(p => p.Probe(row, location)); } } var sample = new SerializableSample(assetPath); SetProperty.Perform(node, nameof(Audio.Sample), sample); SetProperty.Perform(node, nameof(Node.Id), assetPath); SetProperty.Perform(node, nameof(Audio.Volume), 1); var key = new Keyframe <AudioAction> { Frame = cellUnderMouseOnFilesDrop.X, Value = AudioAction.Play }; SetKeyframe.Perform(node, nameof(Audio.Action), Document.Current.AnimationId, key); break; } } files.Remove(file); } Document.Current.History.CommitTransaction(); } }
private void Handle(IEnumerable <string> files) { Handling?.Invoke(); using (Document.Current.History.BeginTransaction()) { pendingImages = new List <string>(); foreach (var file in files) { try { string assetPath, assetType; if (!Utils.ExtractAssetPathOrShowAlert(file, out assetPath, out assetType) || !Utils.AssertCurrentDocument(assetPath, assetType)) { continue; } var nodeCreatingEventArgs = new NodeCreatingEventArgs(assetPath, assetType); NodeCreating?.Invoke(nodeCreatingEventArgs); if (nodeCreatingEventArgs.Cancel) { continue; } var fileName = Path.GetFileNameWithoutExtension(assetPath); switch (assetType) { case ".png": pendingImages.Add(assetPath); break; case ".ogg": { var node = CreateNode.Perform(typeof(Audio)); var sample = new SerializableSample(assetPath); SetProperty.Perform(node, nameof(Audio.Sample), sample); SetProperty.Perform(node, nameof(Node.Id), fileName); SetProperty.Perform(node, nameof(Audio.Volume), 1); var key = new Keyframe <AudioAction> { Frame = Document.Current.AnimationFrame, Value = AudioAction.Play }; SetKeyframe.Perform(node, nameof(Audio.Action), Document.Current.AnimationId, key); OnNodeCreated(node); break; } case ".tan": case ".model": case ".scene": DropSceneContextMenu.Create(assetPath, assetType, NodeCreated); break; } } catch (System.Exception e) { AlertDialog.Show(e.Message); } } if (pendingImages.Count > 0) { var menu = new Menu(); foreach (var kv in imageDropCommands.Commands) { if (NodeCompositionValidator.Validate(Document.Current.Container.GetType(), kv.Value)) { menu.Add(kv.Key); } } menu.Popup(); } Document.Current.History.CommitTransaction(); } }