private void Canvas_Drop(object sender, DragEventArgs e) { UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[e.Data.GetFormats().Length - 1]) as UndertaleObject; e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && (sourceItem is UndertaleGameObject || sourceItem is UndertalePath) ? DragDropEffects.Link : DragDropEffects.None; if (e.Effects == DragDropEffects.Link) { if (sourceItem is UndertaleGameObject) { UndertaleGameObject droppedObject = sourceItem as UndertaleGameObject; var mousePos = e.GetPosition(RoomGraphics); UndertaleRoom room = this.DataContext as UndertaleRoom; var obj = new UndertaleRoom.GameObject() { X = (int)mousePos.X, Y = (int)mousePos.Y, ObjectDefinition = droppedObject, InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastObj++ }; room.GameObjects.Add(obj); SelectObject(obj); } if (sourceItem is UndertalePath) { PreviewPath = sourceItem as UndertalePath; } } e.Handled = true; }
private void RoomObjectsTree_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { UndertaleRoom room = this.DataContext as UndertaleRoom; UndertaleObject selectedObj = ObjectEditor.Content as UndertaleObject; if (selectedObj is UndertaleRoom.Background) { UndertaleRoom.Background bg = selectedObj as UndertaleRoom.Background; bg.Enabled = false; bg.BackgroundDefinition = null; ObjectEditor.Content = null; } else if (selectedObj is UndertaleRoom.View) { UndertaleRoom.View view = selectedObj as UndertaleRoom.View; view.Enabled = false; ObjectEditor.Content = null; } else if (selectedObj is UndertaleRoom.Tile) { UndertaleRoom.Tile tile = selectedObj as UndertaleRoom.Tile; room.Tiles.Remove(tile); ObjectEditor.Content = null; } else if (selectedObj is UndertaleRoom.GameObject) { UndertaleRoom.GameObject gameObj = selectedObj as UndertaleRoom.GameObject; room.GameObjects.Remove(gameObj); ObjectEditor.Content = null; } } }
private void AddLayer <T>(UndertaleRoom.LayerType type, string name) where T : UndertaleRoom.Layer.LayerData, new() { UndertaleRoom room = this.DataContext as UndertaleRoom; // get last layer id var data = (Application.Current.MainWindow as MainWindow).Data; uint lastlayer_id = 0; for (var i = data.Rooms.Count - 1; i >= 0; i--) { var lastroom_layers = data.Rooms[i].Layers; if (lastroom_layers.Count != 0) { lastlayer_id = lastroom_layers[lastroom_layers.Count - 1].LayerId; break; } } UndertaleRoom.Layer layer = new UndertaleRoom.Layer(); layer.LayerName = (Application.Current.MainWindow as MainWindow).Data.Strings.MakeString(name); layer.LayerId = lastlayer_id + 1; layer.LayerType = type; layer.Data = new T(); room.Layers.Add(layer); SelectObject(layer); (this.DataContext as UndertaleRoom)?.SetupRoom(); }
private void ExportAsPNG_Click(object sender, RoutedEventArgs e) { UndertaleRoom room = this.DataContext as UndertaleRoom; SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = room.Name.Content + ".png"; dlg.DefaultExt = ".png"; dlg.Filter = "PNG files (.png)|*.png|All files|*"; if (dlg.ShowDialog() == true) { try { using (var file = File.OpenWrite(dlg.FileName)) { SaveImagePNG(file); } } catch (Exception ex) { MessageBox.Show("Failed to export file: " + ex.Message, "Failed to export file", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void AddObjectInstance(UndertaleRoom room) { var newobject = new UndertaleRoom.GameObject { InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastObj++ }; room.GameObjects.Add(newobject); SelectObject(newobject); }
private void AddGMS1Tile(UndertaleRoom room) { // add tile to list var tile = new UndertaleRoom.Tile { InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastTile++ }; room.Tiles.Add(tile); SelectObject(tile); }
private void Canvas_Drop(object sender, DragEventArgs e) { UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[e.Data.GetFormats().Length - 1]) as UndertaleObject; e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && (sourceItem is UndertaleGameObject || sourceItem is UndertalePath) ? DragDropEffects.Link : DragDropEffects.None; if (e.Effects == DragDropEffects.Link) { if (sourceItem is UndertaleBackground) { } else if (sourceItem is UndertaleGameObject) { UndertaleGameObject droppedObject = sourceItem as UndertaleGameObject; var mousePos = e.GetPosition(RoomGraphics); UndertaleRoom room = this.DataContext as UndertaleRoom; UndertaleRoom.Layer layer = ObjectEditor.Content as UndertaleRoom.Layer; if ((Application.Current.MainWindow as MainWindow).IsGMS2 == Visibility.Visible && layer == null) { MessageBox.Show("Must have a layer selected", "UndertaleModTool", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (layer != null && layer.InstancesData == null) { MessageBox.Show("Must be on an instances layer", "UndertaleModTool", MessageBoxButton.OK, MessageBoxImage.Error); return; } var obj = new UndertaleRoom.GameObject() { X = (int)mousePos.X, Y = (int)mousePos.Y, ObjectDefinition = droppedObject, InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastObj++ }; room.GameObjects.Add(obj); if (layer != null) { layer.InstancesData.Instances.Add(obj); } SelectObject(obj); } if (sourceItem is UndertalePath) { PreviewPath = sourceItem as UndertalePath; } } e.Handled = true; (this.DataContext as UndertaleRoom)?.SetupRoom(); }
private void AddLayer <T>(UndertaleRoom.LayerType type, string name) where T : UndertaleRoom.Layer.LayerData, new() { UndertaleRoom room = this.DataContext as UndertaleRoom; UndertaleRoom.Layer layer = new UndertaleRoom.Layer(); layer.LayerName = (Application.Current.MainWindow as MainWindow).Data.Strings.MakeString(name); layer.LayerId = 0; // TODO: find next ID layer.LayerType = type; layer.Data = new T(); room.Layers.Add(layer); SelectObject(layer); }
public void Command_Paste(object sender, ExecutedRoutedEventArgs e) { /*IDataObject data = Clipboard.GetDataObject(); * UndertaleObject obj = data.GetData(data.GetFormats()[0]) as UndertaleObject; * if (obj != null) * { * Debug.WriteLine("Paste"); * Debug.WriteLine(obj); * }*/ if (copied != null) { UndertaleRoom room = this.DataContext as UndertaleRoom; if (copied is UndertaleRoom.GameObject) { var other = copied as UndertaleRoom.GameObject; var obj = new UndertaleRoom.GameObject(); obj.X = other.X; obj.Y = other.Y; obj.ObjectDefinition = other.ObjectDefinition; obj.InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastObj++; obj.CreationCode = other.CreationCode; obj.ScaleX = other.ScaleX; obj.ScaleY = other.ScaleY; obj.Color = other.Color; obj.Rotation = other.Rotation; obj.PreCreateCode = other.PreCreateCode; room.GameObjects.Add(obj); SelectObject(obj); } if (copied is UndertaleRoom.Tile) { var other = copied as UndertaleRoom.Tile; var obj = new UndertaleRoom.Tile(); obj.X = other.X; obj.Y = other.Y; obj.BackgroundDefinition = other.BackgroundDefinition; obj.SourceX = other.SourceX; obj.SourceY = other.SourceY; obj.Width = other.Width; obj.Height = other.Height; obj.TileDepth = other.TileDepth; obj.InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastTile++; obj.ScaleX = other.ScaleX; obj.ScaleY = other.ScaleY; obj.Color = other.Color; room.Tiles.Add(obj); SelectObject(obj); } } }
private void AddGMS2ObjectInstance(UndertaleRoom.Layer layer) { UndertaleRoom room = this.DataContext as UndertaleRoom; AddObjectInstance(room); var gameobject = room.GameObjects.Last(); layer.InstancesData.Instances.Add(gameobject); if (layer != null) { SelectObject(gameobject); } }
private void AddLayer <T>(UndertaleRoom.LayerType type, string name) where T : UndertaleRoom.Layer.LayerData, new() { UndertaleRoom room = this.DataContext as UndertaleRoom; var data = (Application.Current.MainWindow as MainWindow).Data; uint largest_layerid = 0; // Find the largest layer id // See #355 foreach (UndertaleRoom Room in data.Rooms) { foreach (UndertaleRoom.Layer Layer in Room.Layers) { if (Layer.LayerId > largest_layerid) { largest_layerid = Layer.LayerId; } } } UndertaleRoom.Layer layer = new UndertaleRoom.Layer(); layer.LayerName = data.Strings.MakeString(name); layer.LayerId = largest_layerid + 1; layer.LayerType = type; layer.Data = new T(); room.Layers.Add(layer); if (layer.LayerType == UndertaleRoom.LayerType.Assets) { // create a new pointer list if (layer.AssetsData.LegacyTiles == null) { layer.AssetsData.LegacyTiles = new UndertalePointerList <UndertaleRoom.Tile>(); } // create new sprite pointer list if (layer.AssetsData.Sprites == null) { layer.AssetsData.Sprites = new UndertalePointerList <UndertaleRoom.SpriteInstance>(); } } SelectObject(layer); (this.DataContext as UndertaleRoom)?.SetupRoom(); }
private void MenuItem_NewObjectInstance_Click(object sender, RoutedEventArgs e) { UndertaleRoom room = this.DataContext as UndertaleRoom; AddObjectInstance(room); }
private void MenuItem_NewGMS1Tile_Click(object sender, RoutedEventArgs e) { UndertaleRoom room = this.DataContext as UndertaleRoom; AddGMS1Tile(room); }
public void Command_Paste(object sender, ExecutedRoutedEventArgs e) { /*IDataObject data = Clipboard.GetDataObject(); * UndertaleObject obj = data.GetData(data.GetFormats()[0]) as UndertaleObject; * if (obj != null) * { * Debug.WriteLine("Paste"); * Debug.WriteLine(obj); * }*/ if (copied != null) { UndertaleRoom room = this.DataContext as UndertaleRoom; UndertaleRoom.Layer layer = ObjectEditor.Content as UndertaleRoom.Layer; if ((Application.Current.MainWindow as MainWindow).IsGMS2 == Visibility.Visible && layer == null) { MessageBox.Show("Must paste onto a layer", "UndertaleModTool", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (copied is UndertaleRoom.GameObject) { if (layer != null && layer.InstancesData == null) { MessageBox.Show("Must be on an instances layer", "UndertaleModTool", MessageBoxButton.OK, MessageBoxImage.Error); return; } var other = copied as UndertaleRoom.GameObject; var obj = new UndertaleRoom.GameObject(); obj.X = other.X; obj.Y = other.Y; obj.ObjectDefinition = other.ObjectDefinition; obj.InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastObj++; obj.CreationCode = other.CreationCode; obj.ScaleX = other.ScaleX; obj.ScaleY = other.ScaleY; obj.Color = other.Color; obj.Rotation = other.Rotation; obj.PreCreateCode = other.PreCreateCode; room.GameObjects.Add(obj); if (layer != null) { layer.InstancesData.Instances.Add(obj); } SelectObject(obj); } if (copied is UndertaleRoom.Tile) { if (layer != null && layer.AssetsData == null) { MessageBox.Show("Must be on an assets layer", "UndertaleModTool", MessageBoxButton.OK, MessageBoxImage.Error); return; } var other = copied as UndertaleRoom.Tile; var obj = new UndertaleRoom.Tile(); obj.X = -(int)other.Height; //other.X; obj.Y = -(int)other.Height; //other.Y; obj._SpriteMode = other._SpriteMode; obj.ObjectDefinition = other.ObjectDefinition; obj.SourceX = other.SourceX; obj.SourceY = other.SourceY; obj.Width = other.Width; obj.Height = other.Height; obj.TileDepth = other.TileDepth; obj.InstanceID = (Application.Current.MainWindow as MainWindow).Data.GeneralInfo.LastTile++; obj.ScaleX = other.ScaleX; obj.ScaleY = other.ScaleY; obj.Color = other.Color; if (layer != null) { layer.AssetsData.LegacyTiles.Add(obj); } else { room.Tiles.Add(obj); } SelectObject(obj); } } (this.DataContext as UndertaleRoom)?.SetupRoom(); }
private void RoomObjectsTree_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { UndertaleRoom room = this.DataContext as UndertaleRoom; UndertaleObject selectedObj = ObjectEditor.Content as UndertaleObject; if (selectedObj is UndertaleRoom.Background) { UndertaleRoom.Background bg = selectedObj as UndertaleRoom.Background; bg.Enabled = false; bg.BackgroundDefinition = null; ObjectEditor.Content = null; } else if (selectedObj is UndertaleRoom.View) { UndertaleRoom.View view = selectedObj as UndertaleRoom.View; view.Enabled = false; ObjectEditor.Content = null; } else if (selectedObj is UndertaleRoom.Tile) { UndertaleRoom.Tile tile = selectedObj as UndertaleRoom.Tile; if ((Application.Current.MainWindow as MainWindow).IsGMS2 == Visibility.Visible) { foreach (var layer in room.Layers) { if (layer.AssetsData != null) { layer.AssetsData.LegacyTiles.Remove(tile); } } } room.Tiles.Remove(tile); ObjectEditor.Content = null; } else if (selectedObj is UndertaleRoom.GameObject) { UndertaleRoom.GameObject gameObj = selectedObj as UndertaleRoom.GameObject; if ((Application.Current.MainWindow as MainWindow).IsGMS2 == Visibility.Visible) { foreach (var layer in room.Layers) { if (layer.InstancesData != null) { layer.InstancesData.Instances.Remove(gameObj); } } } room.GameObjects.Remove(gameObj); ObjectEditor.Content = null; } else if (selectedObj is UndertaleRoom.Layer) { UndertaleRoom.Layer layer = selectedObj as UndertaleRoom.Layer; if (layer.InstancesData != null) { foreach (var go in layer.InstancesData.Instances) { room.GameObjects.Remove(go); } } room.Layers.Remove(layer); ObjectEditor.Content = null; } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { UndertaleRoom room = value as UndertaleRoom; return(room is not null ? $"{room.Name.Content}: {room.Width}x{room.Height}" : "null"); }