private void CreateSpriteAnimatedImage(List <string> files) { onBeforeDrop?.Invoke(); using (Document.Current.History.BeginTransaction()) { var node = CreateNode.Perform(typeof(Image)); SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); SetProperty.Perform(node, nameof(Widget.Id), "Temp"); postProcessNode?.Invoke(node); var i = 0; ITexture first = null; foreach (var file in files) { if (!Utils.ExtractAssetPathOrShowAlert(file, out var assetPath, out var assetType)) { continue; } var text = new SerializableTexture(assetPath); first = first ?? text; SetKeyframe.Perform(node, nameof(Widget.Texture), Document.Current.AnimationId, new Keyframe <ITexture> { Value = text, Frame = i++, Function = KeyFunction.Steep, }); } SetProperty.Perform(node, nameof(Widget.Size), (Vector2)first.ImageSize); Document.Current.History.CommitTransaction(); } }
public static void Create(string assetPath, string assetType, Action <Node> onNodeCreated) { var fileName = Path.GetFileNameWithoutExtension(assetPath); var menu = new Menu() { new Command("Open in New Tab", () => Project.Current.OpenDocument(assetPath)), new Command("Add As External Scene", () => Document.Current.History.DoTransaction( () => { var scene = Node.CreateFromAssetBundle(assetPath, yuzu: TangerineYuzu.Instance.Value); var node = CreateNode.Perform(scene.GetType()); SetProperty.Perform(node, nameof(Widget.ContentsPath), assetPath); SetProperty.Perform(node, nameof(Node.Id), fileName); if (scene is Widget) { SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); SetProperty.Perform(node, nameof(Widget.Size), ((Widget)scene).Size); } onNodeCreated?.Invoke(node); node.LoadExternalScenes(); })), new Command("Cancel") }; menu[0].Enabled = assetType != ".model"; menu.Popup(); }
public void HandleDropImage() { foreach (var kv in imageDropCommands.Commands) { if (pendingImages != null && kv.Key.WasIssued()) { kv.Key.Consume(); using (Document.Current.History.BeginTransaction()) { foreach (var assetPath in pendingImages) { var node = CreateNode.Perform(kv.Value); var texture = new SerializableTexture(assetPath); var nodeSize = (Vector2)texture.ImageSize; var nodeId = Path.GetFileNameWithoutExtension(assetPath); if (node is Widget) { SetProperty.Perform(node, nameof(Widget.Texture), texture); SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); SetProperty.Perform(node, nameof(Widget.Size), nodeSize); SetProperty.Perform(node, nameof(Widget.Id), nodeId); } else if (node is ParticleModifier) { SetProperty.Perform(node, nameof(ParticleModifier.Texture), texture); SetProperty.Perform(node, nameof(ParticleModifier.Size), nodeSize); SetProperty.Perform(node, nameof(ParticleModifier.Id), nodeId); } OnNodeCreated(node); } Document.Current.History.CommitTransaction(); pendingImages = null; } } else { kv.Key.Consume(); } } }
private void CreateImageTypeInstance(Type type, List <string> files) { onBeforeDrop?.Invoke(); using (Document.Current.History.BeginTransaction()) { var nodes = new List <Node>(files.Count); foreach (var file in files) { if (!Utils.ExtractAssetPathOrShowAlert(file, out var assetPath, out var assetType)) { continue; } var node = CreateNode.Perform(type); nodes.Add(node); var texture = new SerializableTexture(assetPath); var nodeSize = (Vector2)texture.ImageSize; var nodeId = Path.GetFileNameWithoutExtension(assetPath); if (node is Widget) { SetProperty.Perform(node, nameof(Widget.Texture), texture); SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); SetProperty.Perform(node, nameof(Widget.Size), nodeSize); SetProperty.Perform(node, nameof(Widget.Id), nodeId); } else if (node is ParticleModifier) { SetProperty.Perform(node, nameof(ParticleModifier.Texture), texture); SetProperty.Perform(node, nameof(ParticleModifier.Size), nodeSize); SetProperty.Perform(node, nameof(ParticleModifier.Id), nodeId); } postProcessNode?.Invoke(node); } foreach (var node in nodes) { SelectNode.Perform(node); } Document.Current.History.CommitTransaction(); } }
/// <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(); } }
IEnumerator <object> CreateSplinePoint3DTask() { command.Checked = true; while (true) { if (sv.InputArea.IsMouseOver()) { Utils.ChangeCursorIfDefault(MouseCursor.Hand); } CreateNodeRequestComponent.Consume <Node>(sv.Components); if (input.ConsumeKeyPress(Key.Mouse0)) { using (history.BeginTransaction()) { SplinePoint3D point; try { point = (SplinePoint3D)CreateNode.Perform(typeof(SplinePoint3D), aboveSelected: false); } catch (InvalidOperationException e) { AlertDialog.Show(e.Message); yield break; } var spline = (Spline3D)Document.Current.Container; var vp = spline.Viewport; var ray = vp.ScreenPointToRay(input.MousePosition); var xyPlane = new Plane(new Vector3(0, 0, 1), 0).Transform(spline.GlobalTransform); var d = ray.Intersects(xyPlane); if (d.HasValue) { var pos = (ray.Position + ray.Direction * d.Value) * spline.GlobalTransform.CalcInverted(); SetProperty.Perform(point, nameof(SplinePoint3D.Position), pos); using (history.BeginTransaction()) { while (input.IsMousePressed()) { history.RollbackTransaction(); ray = vp.ScreenPointToRay(input.MousePosition); d = ray.Intersects(xyPlane); if (d.HasValue) { var tangent = (ray.Position + ray.Direction * d.Value) * spline.GlobalTransform.CalcInverted() - point.Position; SetProperty.Perform(point, nameof(SplinePoint3D.TangentA), tangent); SetProperty.Perform(point, nameof(SplinePoint3D.TangentB), -tangent); } history.CommitTransaction(); yield return(null); } if (point.TangentA.Length < 0.01f) { SetProperty.Perform(point, nameof(SplinePoint3D.TangentA), new Vector3(1, 0, 0)); SetProperty.Perform(point, nameof(SplinePoint3D.TangentB), new Vector3(-1, 0, 0)); } } } history.CommitTransaction(); } history.CommitTransaction(); } if (input.WasMousePressed(1) || input.WasKeyPressed(Key.Escape)) { break; } yield return(null); } command.Checked = false; Utils.ChangeCursorIfDefault(MouseCursor.Default); }
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(); } }