Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New grid related features #931

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions UndertaleModLib/Models/UndertaleRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public enum RoomEntryFlags : uint
/// <summary>
/// The thickness of the room grid in pixels.
/// </summary>
public double GridThicknessPx { get; set; } = 1d;
public double GridThicknessPx { get; set; } = 0.5d;
plrusek marked this conversation as resolved.
Show resolved Hide resolved
private UndertalePointerList<Layer> _layers = new();

/// <summary>
Expand Down Expand Up @@ -352,7 +352,7 @@ public void Unserialize(UndertaleReader reader)
}
}

public void SetupRoom(bool calculateGrid = true)
public void SetupRoom(bool calculateGridWidth = true, bool calculateGridHeight = true)
{
foreach (Layer layer in Layers)
{
Expand All @@ -362,7 +362,7 @@ public void SetupRoom(bool calculateGrid = true)
foreach (UndertaleRoom.Background bgnd in Backgrounds)
bgnd.ParentRoom = this;

if (calculateGrid)
if (calculateGridWidth || calculateGridHeight)
{
// Automagically set the grid size to whatever most tiles are sized

Expand Down Expand Up @@ -403,11 +403,18 @@ public void SetupRoom(bool calculateGrid = true)
}

// If tiles exist at all, grab the most used tile size and use that as our grid size
// If a default starting grid is set in the settings, use that instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is slightly misleading, as in this code block the starting grid is not get from the settings as the grid isn't even recalculated in that case.

if (tileSizes.Count > 0)
{
var largestKey = tileSizes.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;
GridWidth = largestKey.X;
GridHeight = largestKey.Y;
if (calculateGridWidth)
{
GridWidth = largestKey.X;
}
if (calculateGridHeight)
{
GridHeight = largestKey.Y;
}
plrusek marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Controls/UndertaleRoomRenderer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public UndertaleRoomRenderer()

private void RoomRenderer_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
(DataContext as UndertaleRoom)?.SetupRoom(!bgGridDisabled);
(DataContext as UndertaleRoom)?.SetupRoom(!bgGridDisabled, !bgGridDisabled);
UndertaleRoomEditor.GenerateSpriteCache(DataContext as UndertaleRoom);
}

Expand Down
37 changes: 32 additions & 5 deletions UndertaleModTool/Editors/UndertaleRoomEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@
<TextBlock Grid.Row="1" Grid.Column="0" Margin="3">Image speed</TextBlock>
<TextBox Grid.Row="1" Grid.Column="2" Margin="3" Text="{Binding ImageSpeed}"/>
</Grid>

<TextBlock Grid.Row="8" Grid.Column="0" Margin="3">Pre Create code</TextBlock>
<local:UndertaleObjectReference Grid.Row="9" Grid.Column="2" Margin="3" ObjectReference="{Binding PreCreateCode}" ObjectType="{x:Type undertale:UndertaleCode}" ObjectEventType="{x:Static undertale:EventType.PreCreate}" ObjectEventSubtype="0"/>
</Grid>
Expand Down Expand Up @@ -973,7 +973,7 @@

<!-- Don't forget to modify "UndertaleRoomRenderer" control as well -->
<ScrollViewer Name="RoomGraphicsScroll" Margin="0,8,0,0" Grid.Column="0" Grid.Row="2" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" ScrollChanged="ScrollViewer_ScrollChanged">
<ItemsControl Name="RoomGraphics" Background="Black" MouseDown="RectangleBackground_MouseDown" MouseMove="RectangleBackground_MouseMove" MouseUp="RectangleBackground_MouseUp" MouseWheel="Canvas_MouseWheel">
<ItemsControl Name="RoomGraphics" Background="Gray" MouseDown="RectangleBackground_MouseDown" MouseMove="RectangleBackground_MouseMove" MouseUp="RectangleBackground_MouseUp" MouseWheel="Canvas_MouseWheel">
<ItemsControl.Style>
<Style TargetType="ItemsControl">
<Style.Triggers>
Expand Down Expand Up @@ -1011,6 +1011,36 @@
<ItemsPanelTemplate>
<local:RoomCanvas x:Name="RoomCanvas" Width="{Binding Width, Mode=OneWay}" Height="{Binding Height, Mode=OneWay}" IsItemsHost="True" AllowDrop="True"
DragOver="Canvas_DragOver" Drop="Canvas_Drop" Loaded="RoomCanvas_Loaded">
<Canvas.OpacityMask>
<DrawingBrush TileMode="Tile" ViewportUnits="Absolute">
<DrawingBrush.Viewport>
<MultiBinding Converter="{StaticResource GridConverter}">
<Binding Path="GridWidth" Mode="OneWay"/>
<Binding Path="GridHeight" Mode="OneWay"/>
</MultiBinding>
</DrawingBrush.Viewport>
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<RectangleGeometry>
<RectangleGeometry.Rect>
<MultiBinding Converter="{StaticResource GridConverter}">
<Binding Path="GridWidth" Mode="OneWay"/>
<Binding Path="GridHeight" Mode="OneWay"/>
</MultiBinding>
</RectangleGeometry.Rect>
</RectangleGeometry>
</GeometryDrawing.Geometry>
<GeometryDrawing.Brush>
<SolidColorBrush Color="Black"></SolidColorBrush>
</GeometryDrawing.Brush>
<GeometryDrawing.Pen>
<Pen Brush="Transparent" Thickness="{Binding GridThicknessPx, Mode=OneWay}"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.OpacityMask>
<Canvas.Background>
<DrawingBrush TileMode="Tile" ViewportUnits="Absolute">
<DrawingBrush.Viewport>
Expand Down Expand Up @@ -1038,9 +1068,6 @@
<Binding Path="Flags" Mode="OneTime"/>
</MultiBinding>
</GeometryDrawing.Brush>
<GeometryDrawing.Pen>
<Pen Brush="Gray" Thickness="{Binding GridThicknessPx, Mode=OneWay}"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
Expand Down
27 changes: 24 additions & 3 deletions UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void UndertaleRoomEditor_DataContextChanged(object sender, DependencyPro
GameObjItems.Header = room.Flags.HasFlag(RoomEntryFlags.IsGMS2)
? "Game objects (from all layers)"
: "Game objects";
room.SetupRoom();
this.SetupRoomWithGrids(room);
GenerateSpriteCache(DataContext as UndertaleRoom);

if (room.Layers.Count > 0) // if GMS 2+
Expand Down Expand Up @@ -462,7 +462,7 @@ private void Rectangle_MouseUp(object sender, MouseButtonEventArgs e)
}

// recalculates room grid size
room.SetupRoom();
this.SetupRoomWithGrids(room);
}
else if (obj is GameObject gameObj)
{
Expand Down Expand Up @@ -832,6 +832,7 @@ private void SelectObject(UndertaleObject obj)

resListView.IsExpanded = true;
resListView.BringIntoView();
resListView.Focus();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be after line 856 (resItem.IsSelected = true;).

resListView.UpdateLayout();

StackPanel resPanel = MainWindow.FindVisualChild<StackPanel>(resListView);
Expand Down Expand Up @@ -1316,7 +1317,7 @@ public void Command_Paste(object sender, ExecutedRoutedEventArgs e)
}

SelectObject(layer);
room.SetupRoom(false);
room.SetupRoom(false, false);
}

private void AddObjectInstance(UndertaleRoom room)
Expand Down Expand Up @@ -1670,6 +1671,26 @@ private void LayerCanvas_Unloaded(object sender, RoutedEventArgs e)
if (canvas.CurrentLayer is not null)
ObjElemDict.Remove(canvas.CurrentLayer);
}
private void SetupRoomWithGrids(UndertaleRoom room)
{
if (Settings.Instance.GridWidthEnabled)
{
room.GridWidth = Settings.Instance.GlobalGridWidth;
if (Settings.Instance.GridHeightEnabled)
{
room.GridHeight = Settings.Instance.GlobalGridHeight;
room.SetupRoom(false, false);
}
else
{
room.SetupRoom(false);
}
}
else
{
room.SetupRoom();
}
plrusek marked this conversation as resolved.
Show resolved Hide resolved
}
}

public partial class RoomCanvas : Canvas
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEv

private void MainTree_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
OpenInTab(Highlighted);
OpenInTab(Highlighted, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not mentioned on the PR description.
I personally do not like everything opening in a new tab.

}

private void MainTree_KeyUp(object sender, KeyEventArgs e)
Expand Down
4 changes: 4 additions & 0 deletions UndertaleModTool/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public class Settings

public bool DeleteOldProfileOnSave { get; set; } = false;
public bool WarnOnClose { get; set; } = true;
public double GlobalGridWidth { get; set; } = 0;
public bool GridWidthEnabled { get; set; } = false;
public double GlobalGridHeight { get; set; } = 0;
public bool GridHeightEnabled { get; set; } = false;

public static Settings Instance;

Expand Down
Loading