Skip to content

Commit

Permalink
moved version selection to save button (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
epix37 committed Jan 29, 2015
1 parent 3ac2244 commit f441a71
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 48 deletions.
13 changes: 7 additions & 6 deletions Hearthstone Deck Tracker/MainWindow/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,17 @@


<Menu Name="MenuNewDeck" Grid.Column="2" Grid.Row="0" Visibility="Collapsed">
<MenuItem Header="SAVE" Click="BtnSaveDeck_Click">
<MenuItem Header="SAVE" Name="MenuItemSave" SubmenuOpened="MenuItem_OnSubmenuOpened">
<MenuItem.Icon>
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<VisualBrush Visual="{StaticResource appbar_save}" />
</Rectangle.Fill>
</Rectangle>
</MenuItem.Icon>
<MenuItem Name="MenuItemSaveVersionCurrent" Header="v1.0 (current)" Click="MenuItemSaveVersionCurrent_OnClick"/>
<MenuItem Name="MenuItemSaveVersionMinor" Header="v1.1" Click="MenuItemSaveVersionMinor_OnClick"/>
<MenuItem Name="MenuItemSaveVersionMajor" Header="v2.0" Click="MenuItemSaveVersionMajor_OnClick"/>
</MenuItem>
<MenuItem Header="CANCEL" Click="BtnCancelEdit_Click">
<MenuItem.Icon>
Expand Down Expand Up @@ -406,7 +409,7 @@
ScrollViewer.CanContentScroll="True" FontFamily="Arial" Margin="0,6,0,6"
HorizontalAlignment="Left"
Width="235" KeyDown="ListViewDB_KeyDown"
MouseLeftButtonUp="ListViewDB_MouseLeftButtonUp" Grid.Row="1">
MouseLeftButtonUp="ListViewDB_MouseLeftButtonUp" Grid.Row="1" Grid.Column="0">
<ListView.Resources>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Visibility" Value="Collapsed" />
Expand Down Expand Up @@ -439,11 +442,9 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<DockPanel Grid.Column="1" Margin="0,6,0,0">
<DockPanel Grid.Column="1" Margin="0,6,0,0" Grid.Row="0">
<TextBlock x:Name="DeckCurrentVersionHeader" Text="DECK HISTORY:" VerticalAlignment="Center" FontSize="12" DockPanel.Dock="Left"/>
<TextBlock x:Name="DeckCurrentVersion" Margin="6,0,0,0" FontSize="12" Text="v1.0" VerticalAlignment="Center" DockPanel.Dock="Left"/>
<Label Content="->" VerticalAlignment="Center" DockPanel.Dock="Left"/>
<ComboBox Name="ComboBoxVersionIncrement" Margin="0,0,6,0" />
<TextBlock x:Name="DeckCurrentVersion" Margin="6,0,0,0" FontSize="12" Text="v1.0" VerticalAlignment="Center"/>
</DockPanel>
<ScrollViewer Grid.Column="1" Grid.Row="1" Margin="0,6,6,6" Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}">
<StackPanel x:Name="DeckHistoryPanel"
Expand Down
81 changes: 56 additions & 25 deletions Hearthstone Deck Tracker/MainWindow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public partial class MainWindow
private bool _doUpdate;
private DateTime _lastUpdateCheck;
private Deck _newDeck;
private Deck _originalDeck;
private Deck _originalDeck;
private bool _newDeckUnsavedChanges;
private bool _tempUpdateCheckDisabled;
private Version _updatedVersion;
Expand Down Expand Up @@ -437,7 +437,8 @@ public void ShowIncorrectDeckMessage()
}
else if(decks.Count > 0)
{
decks.Add(new Deck("Use no deck", "", new List<Card>(), new List<string>(), "", "", DateTime.Now, new List<Card>() ,SerializableVersion.Default, new List<Deck>()));
decks.Add(new Deck("Use no deck", "", new List<Card>(), new List<string>(), "", "", DateTime.Now, new List<Deck>(), SerializableVersion.Default,
new List<Deck>()));
var dsDialog = new DeckSelectionDialog(decks);

//todo: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ClassColor; DataItem=null; target element is 'GradientStop' (HashCode=7260326); target property is 'Color' (type 'Color')
Expand Down Expand Up @@ -815,31 +816,46 @@ public void UpdateDeckList(Deck selected)
}
}

private void UpdateDeckHistoryPanel(Deck selected, bool isNewDeck)
{
DeckHistoryPanel.Children.Clear();
DeckCurrentVersion.Text = string.Format("v{0}.{1}",_newDeck.Version.Major, _newDeck.Version.Minor);
ComboBoxVersionIncrement.ItemsSource = new List<string>
private void UpdateDeckHistoryPanel(Deck selected, bool isNewDeck)
{
DeckHistoryPanel.Children.Clear();
DeckCurrentVersion.Text = string.Format("v{0}.{1}", _newDeck.Version.Major, _newDeck.Version.Minor);
if(isNewDeck)
{
_newDeck.Version.ToString("v{M}.{m}"),
string.Format("v{0}.{1}", _newDeck.Version.Major, _newDeck.Version.Minor + 1),
string.Format("v{0}.{1}", _newDeck.Version.Major + 1, 0)
};
ComboBoxVersionIncrement.SelectedIndex = isNewDeck ? 0 : 1;
MenuItemSaveVersionCurrent.IsEnabled = false;
MenuItemSaveVersionMinor.IsEnabled = false;
MenuItemSaveVersionMajor.IsEnabled = false;
MenuItemSaveVersionCurrent.Visibility = Visibility.Collapsed;
MenuItemSaveVersionMinor.Visibility = Visibility.Collapsed;
MenuItemSaveVersionMajor.Visibility = Visibility.Collapsed;
}
else
{
MenuItemSaveVersionCurrent.IsEnabled = true;
MenuItemSaveVersionMinor.IsEnabled = true;
MenuItemSaveVersionMajor.IsEnabled = true;
MenuItemSaveVersionCurrent.Visibility = Visibility.Visible;
MenuItemSaveVersionMinor.Visibility = Visibility.Visible;
MenuItemSaveVersionMajor.Visibility = Visibility.Visible;
MenuItemSaveVersionCurrent.Header = _newDeck.Version.ToString("v{M}.{m} (current)");
MenuItemSaveVersionMinor.Header = string.Format("v{0}.{1}", _newDeck.Version.Major, _newDeck.Version.Minor + 1);
MenuItemSaveVersionMajor.Header = string.Format("v{0}.{1}", _newDeck.Version.Major + 1, 0);
}

if (selected.Versions.Count > 0)
{
Deck current = selected;
foreach (Deck prevVersion in selected.Versions.OrderByDescending(d => d.Version))
{
var versionChange = new Controls.DeckVersionChange();
versionChange.Label.Text = string.Format("{0} -> {1}", prevVersion.Version.ToString("v{M}.{m}"), current.Version.ToString("v{M}.{m}"));
versionChange.ListViewDeck.ItemsSource = current - prevVersion;
DeckHistoryPanel.Children.Add(versionChange);
current = prevVersion;
}
}
}
if(selected.Versions.Count > 0)
{
Deck current = selected;
foreach(Deck prevVersion in selected.Versions.OrderByDescending(d => d.Version))
{
var versionChange = new Controls.DeckVersionChange();
versionChange.Label.Text = string.Format("{0} -> {1}", prevVersion.Version.ToString("v{M}.{m}"),
current.Version.ToString("v{M}.{m}"));
versionChange.ListViewDeck.ItemsSource = current - prevVersion;
DeckHistoryPanel.Children.Add(versionChange);
current = prevVersion;
}
}
}


private void CheckboxDeckDetection_Checked(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -956,5 +972,20 @@ private void MenuItemReplaySelectGame_OnClick(object sender, RoutedEventArgs e)
DeckStatsFlyout.TabControlOverall.SelectedIndex = 1;
}
}

private async void MenuItemSaveVersionCurrent_OnClick(object sender, RoutedEventArgs e)
{
await SaveDeckWithOverwriteCheck(_newDeck.Version);
}

private async void MenuItemSaveVersionMinor_OnClick(object sender, RoutedEventArgs e)
{
await SaveDeckWithOverwriteCheck(SerializableVersion.IncreaseMinor(_newDeck.Version));
}

private async void MenuItemSaveVersionMajor_OnClick(object sender, RoutedEventArgs e)
{
await SaveDeckWithOverwriteCheck(SerializableVersion.IncreaseMajor(_newDeck.Version));
}
}
}
40 changes: 23 additions & 17 deletions Hearthstone Deck Tracker/MainWindow/MainWindow_NewDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void UpdateDbListView()
}
}

private async void SaveDeck(bool overwrite)
private async void SaveDeck(bool overwrite, SerializableVersion newVersion)
{
var deckName = TextBoxDeckName.Text;

Expand Down Expand Up @@ -148,9 +148,9 @@ private async void SaveDeck(bool overwrite)

if (overwrite)
{
_newDeck.Version = SerializableVersion.Parse(ComboBoxVersionIncrement.SelectedValue.ToString());
_newDeck.Version = newVersion;
AddDeckHistory();
//UpdateDeckHistoryPanel(_newDeck, false);
//UpdateDeckHistoryPanel(_newDeck, false);
}

if(EditingDeck && overwrite)
Expand Down Expand Up @@ -428,17 +428,12 @@ private async void BtnCancelEdit_Click(object sender, RoutedEventArgs e)
EditingDeck = false;
editedDeckName = string.Empty;
}

private async void BtnSaveDeck_Click(object sender, RoutedEventArgs e)
private async Task SaveDeckWithOverwriteCheck()
{
//NewDeck.Cards =
// new ObservableCollection<Card>(
// NewDeck.Cards.OrderBy(c => c.Cost).ThenByDescending(c => c.Type).ThenBy(c => c.Name).ToList());
//ListViewNewDeck.ItemsSource = NewDeck.Cards;
await SaveDeckWithOverwriteCheck();
await SaveDeckWithOverwriteCheck(_newDeck.Version);
}

private async Task SaveDeckWithOverwriteCheck()
private async Task SaveDeckWithOverwriteCheck(SerializableVersion newVersion)
{
var deckName = TextBoxDeckName.Text;
if(EditingDeck)
Expand All @@ -448,9 +443,9 @@ private async Task SaveDeckWithOverwriteCheck()
await
this.ShowMessageAsync("Saving deck", "How do you wish to save the deck?", MessageDialogStyle.AffirmativeAndNegative, settings);
if(result == MessageDialogResult.Affirmative)
SaveDeck(true);
SaveDeck(true, newVersion);
else if(result == MessageDialogResult.Negative)
SaveDeck(false);
SaveDeck(false, newVersion);
}
else if(DeckList.DecksList.Any(d => d.Name == deckName))
{
Expand All @@ -469,13 +464,13 @@ private async Task SaveDeckWithOverwriteCheck()
while((oldDeck = DeckList.DecksList.FirstOrDefault(d => d.Name == deckName)) != null)
DeleteDeck(oldDeck);

SaveDeck(true);
SaveDeck(true, newVersion);
}
else if(result == MessageDialogResult.Negative)
SaveDeck(false);
SaveDeck(false, newVersion);
}
else
SaveDeck(false);
SaveDeck(false, newVersion);

editedDeckName = string.Empty;
}
Expand Down Expand Up @@ -609,5 +604,16 @@ private void AddDeckHistory()
}

#endregion

private async void MenuItem_OnSubmenuOpened(object sender, RoutedEventArgs e)
{
//a menuitems clickevent does not fire if it has subitems
//bit of a hacky workaround, but this does the trick (subitems are disabled when a new deck is created, enabled when one is edited)
if(!MenuItemSaveVersionCurrent.IsEnabled && !MenuItemSaveVersionMinor.IsEnabled && !MenuItemSaveVersionMajor.IsEnabled)
{
MenuItemSave.IsSubmenuOpen = false;
await SaveDeckWithOverwriteCheck();
}
}
}
}

0 comments on commit f441a71

Please sign in to comment.