Skip to content

Commit

Permalink
Add editing bookmark coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfirex86 committed Jan 30, 2020
1 parent 58e6cdb commit 39cba2a
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 54 deletions.
4 changes: 2 additions & 2 deletions OpenSpaceToolbox/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.2.0.0")]
[assembly: AssemblyFileVersion("3.2.0.0")]
[assembly: AssemblyVersion("3.3.0.0")]
[assembly: AssemblyFileVersion("3.3.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public BookmarkItemViewModel(string level, string name, float x, float y, float
/// <summary>
/// The X position
/// </summary>
public float X { get; }
public float X { get; set; }

/// <summary>
/// The Y position
/// </summary>
public float Y { get; }
public float Y { get; set; }

/// <summary>
/// The Z position
/// </summary>
public float Z { get; }
public float Z { get; set; }

#endregion

Expand Down
45 changes: 24 additions & 21 deletions OpenSpaceToolbox/ViewModels/Bookmarks/BookmarksViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public BookmarksViewModel(GenericGameManager gameManager)

private string _currentLevel;

#endregion

#region Private Methods

/// <summary>
Expand All @@ -82,16 +84,14 @@ private void LoadBookmarks()
var bookmark = element.Element("Bookmark");

AllBookmarkItems.Add(new BookmarkItemViewModel(element.Name.LocalName, bookmark.Element("Name").Value,
Single.Parse(bookmark.Element("X").Value, CultureInfo.InvariantCulture.NumberFormat),
Single.Parse(bookmark.Element("Y").Value, CultureInfo.InvariantCulture.NumberFormat),
Single.Parse(bookmark.Element("Z").Value, CultureInfo.InvariantCulture.NumberFormat)));
float.Parse(bookmark.Element("X").Value, CultureInfo.InvariantCulture.NumberFormat),
float.Parse(bookmark.Element("Y").Value, CultureInfo.InvariantCulture.NumberFormat),
float.Parse(bookmark.Element("Z").Value, CultureInfo.InvariantCulture.NumberFormat)));
}
}

#endregion

#endregion

#region Public Properties

/// <summary>
Expand Down Expand Up @@ -258,31 +258,34 @@ public void RenameBookmark()
if (SelectedBookmark == null)
return;

RenameDialog rename = new RenameDialog
{
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
txtbox_name =
RenameDialog rename =
new RenameDialog(SelectedBookmark.Name, SelectedBookmark.X, SelectedBookmark.Y, SelectedBookmark.Z)
{
Text = SelectedBookmark.Name
}
};
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};

rename.ShowDialog();

// Get the result
string renameBookmarkName = rename.Result;
if (!rename.Result) return;

if (String.IsNullOrEmpty(renameBookmarkName) || SelectedBookmark.Name == renameBookmarkName)
return;
string newName;

if (AllBookmarkItems.Any(x => x.Name == renameBookmarkName))
if (rename.BookmarkName != SelectedBookmark.Name && AllBookmarkItems.Any(x => x.Name == rename.BookmarkName))
{
MessageBox.Show("A bookmark with that name already exists!");
return;
int i = 1;
do
{
newName = rename.BookmarkName + $" ({i})";
i++;
} while (AllBookmarkItems.Any(x => x.Name == newName));
}
else newName = rename.BookmarkName;

SelectedBookmark.Name = renameBookmarkName;
SelectedBookmark.Name = newName;
SelectedBookmark.X = rename.X;
SelectedBookmark.Y = rename.Y;
SelectedBookmark.Z = rename.Z;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenSpaceToolbox/Views/GameManagerFullView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
Margin="0 0 3 3"
Command="{Binding Path=BookmarksVm.AddBookmarkCommand}" />

<Button Content="Rename"
<Button Content="Edit"
Margin="0 0 3 3"
Command="{Binding Path=BookmarksVm.RenameBookmarkCommand}"
IsEnabled="{Binding Path=BookmarksVm.SelectedBookmarkIndex, Converter={local:IsValidIndexConverter}}" />
Expand Down
2 changes: 1 addition & 1 deletion OpenSpaceToolbox/Views/GameManagerMinimizedView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<Button Content="Add"
Command="{Binding Path=BookmarksVm.AddBookmarkCommand}" />

<Button Content="Rename"
<Button Content="Edit"
Command="{Binding Path=BookmarksVm.RenameBookmarkCommand}"
IsEnabled="{Binding Path=BookmarksVm.SelectedBookmarkIndex, Converter={local:IsValidIndexConverter}}"/>

Expand Down
1 change: 1 addition & 0 deletions OpenSpaceToolbox/Windows/GlmWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
MinWidth="280"
MinHeight="220"
ResizeMode="NoResize"
SnapsToDevicePixels="True"
d:DataContext="{d:DesignInstance local:GlmWindowViewModel}" SizeToContent="WidthAndHeight" Closing="Window_Closing">
<Window.Resources>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
Expand Down
70 changes: 55 additions & 15 deletions OpenSpaceToolbox/Windows/RenameDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,71 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OpenSpaceToolbox"
mc:Ignorable="d"
Title="Rename Bookmark"
SizeToContent="WidthAndHeight"
MinWidth="200"
WindowStyle="ToolWindow"
ResizeMode="NoResize"
Loaded="Window_Loaded">
Title="Edit Bookmark"
SizeToContent="Height"
Width="250"
SnapsToDevicePixels="True"
ResizeMode="NoResize">
<StackPanel Margin="10">

<TextBlock Text="Rename bookmark:"
<TextBlock Text="Name:"
Margin="3 0 3 3"
HorizontalAlignment="Left"/>

<TextBox x:Name="txtbox_name"
Margin="0 10"/>
<TextBox Name="NameBox"
Margin="0 0 0 5"/>

<Grid>
<Button Content="Rename"
HorizontalAlignment="Left"
<Grid Margin="0 0 0 15">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<TextBlock Text="X:"
Grid.Row="0" Grid.Column="0"
Margin="3 0 3 3"
HorizontalAlignment="Left"/>

<TextBox Name="XBox"
Margin="0 0 1 0"
Grid.Row="1" Grid.Column="0"/>

<TextBlock Text="Y:"
Grid.Row="0" Grid.Column="1"
Margin="3 0 3 3"
HorizontalAlignment="Left"/>

<TextBox Name="YBox"
Margin="1 0"
Grid.Row="1" Grid.Column="1"/>

<TextBlock Text="Z:"
Grid.Row="0" Grid.Column="2"
Margin="3 0 3 3"
HorizontalAlignment="Left"/>

<TextBox Name="ZBox"
Margin="1 0 0 0"
Grid.Row="1" Grid.Column="2"/>

</Grid>

<WrapPanel HorizontalAlignment="Right">

<Button Content="OK"
IsDefault="True"
Margin="0 0 5 0"
Click="Btn_rename_Click"/>

<Button Content="Cancel"
HorizontalAlignment="Right"
<Button Content="Cancel"
IsCancel="True"/>

</Grid>
</WrapPanel>

</StackPanel>
</Window>
40 changes: 29 additions & 11 deletions OpenSpaceToolbox/Windows/RenameDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Globalization;
using System.Windows;

namespace OpenSpaceToolbox
{
Expand All @@ -7,23 +8,40 @@ namespace OpenSpaceToolbox
/// </summary>
public partial class RenameDialog : Window
{
public RenameDialog()
public RenameDialog(string name, float x, float y, float z)
{
InitializeComponent();

NameBox.Text = name;
XBox.Text = x.ToString(CultureInfo.InvariantCulture);
YBox.Text = y.ToString(CultureInfo.InvariantCulture);
ZBox.Text = z.ToString(CultureInfo.InvariantCulture);
Result = false;
}

public string Result { get; set; }
public string BookmarkName { get; set; }

private void Btn_rename_Click(object sender, RoutedEventArgs e)
{
Result = txtbox_name.Text;
Close();
}
public float X;
public float Y;
public float Z;

public bool Result { get; set; }

private void Window_Loaded(object sender, RoutedEventArgs e)
private void Btn_rename_Click(object sender, RoutedEventArgs e)
{
txtbox_name.Focus();
txtbox_name.SelectAll();
if (float.TryParse(XBox.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out X) &&
float.TryParse(YBox.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out Y) &&
float.TryParse(ZBox.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out Z))
{
if (!string.IsNullOrWhiteSpace(NameBox.Text))
{
BookmarkName = NameBox.Text;
Result = true;
Close();
}
else MessageBox.Show("Bookmark name cannot be empty.");
}
else MessageBox.Show("Invalid number format. Make sure the coordinates are correct.");
}
}
}

0 comments on commit 39cba2a

Please sign in to comment.