Skip to content

Commit

Permalink
Add new UI option to place voter list inside a spoiler.
Browse files Browse the repository at this point in the history
Update the displayed results depending on whether it's checked.
  • Loading branch information
Kinematics committed Mar 17, 2015
1 parent 682bad9 commit 123bcf8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NetTally/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<setting name="Upgraded" serializeAs="String">
<value>False</value>
</setting>
<setting name="UseSpoilerForVoters" serializeAs="String">
<value>False</value>
</setting>
</NetTally.Properties.Settings>
</userSettings>
</configuration>
4 changes: 3 additions & 1 deletion NetTally/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<CheckBox x:Name="partitionedVotes" Content="Partition Votes" Margin="318,45,0,0" VerticalAlignment="Top"
IsChecked="{Binding Path=CurrentItem.UseVotePartitions}" HorizontalAlignment="Left" Width="95"
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}"/>
<StackPanel HorizontalAlignment="Left" Height="51" Margin="418,45,0,0" VerticalAlignment="Top" Width="87"
<StackPanel HorizontalAlignment="Left" Height="39" Margin="418,45,0,0" VerticalAlignment="Top" Width="87"
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}">
<RadioButton x:Name="partitionByLine" Content="By Line" HorizontalAlignment="Left" VerticalAlignment="Top"
GroupName="PartitionType" IsChecked="{Binding Path=CurrentItem.PartitionByLine, ConverterParameter=Normal, Converter={StaticResource BoolConverter}}"
Expand All @@ -56,6 +56,8 @@
GroupName="PartitionType" IsChecked="{Binding ElementName=partitionByLine, Path=IsChecked, ConverterParameter=Invert, Converter={StaticResource BoolConverter}, Mode=OneWay}"
IsEnabled="{Binding IsChecked, ElementName=partitionedVotes}"/>
</StackPanel>
<CheckBox x:Name="useSpoilerForVoters" Content="Use Spoiler for Voters" HorizontalAlignment="Left" Margin="318,80,0,0" VerticalAlignment="Top"
IsChecked="{Binding Path=UseSpoilerForVoters}"/>
<Button x:Name="clearTallyCacheButton" Height="47" Margin="0,10,173,0" VerticalAlignment="Top" Click="clearTallyCacheButton_Click" HorizontalAlignment="Right" Width="49"
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}">
<TextBlock TextWrapping="Wrap" TextAlignment="Center">Clear Cache</TextBlock>
Expand Down
7 changes: 7 additions & 0 deletions NetTally/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ public MainWindow()
// Set the current item
QuestCollectionView.MoveCurrentTo(questCollection[wrapper.CurrentQuest]);

Properties.Settings settings = new Properties.Settings();
tally.UseSpoilerForVoters = settings.UseSpoilerForVoters;

// Set up data contexts
DataContext = QuestCollectionView;
resultsWindow.DataContext = tally;
useSpoilerForVoters.DataContext = tally;
}

/// <summary>
Expand All @@ -72,6 +75,10 @@ private void Window_Closing(object sender, CancelEventArgs e)
}
QuestCollectionWrapper qcw = new QuestCollectionWrapper(questCollection, selectedQuest);
NetTallyConfig.Save(tally, qcw);

Properties.Settings settings = new Properties.Settings();
settings.UseSpoilerForVoters = tally.UseSpoilerForVoters;
settings.Save();
}
#endregion

Expand Down
12 changes: 12 additions & 0 deletions NetTally/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions NetTally/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<Setting Name="Upgraded" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="UseSpoilerForVoters" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
31 changes: 31 additions & 0 deletions TallyCore/Tally.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ public string TallyResults
}
}

bool useSpoilerForVoters = false;
public bool UseSpoilerForVoters
{
get { return useSpoilerForVoters; }
set
{
useSpoilerForVoters = value;
UpdateResults();
}
}


IQuest lastTallyQuest = null;
private void UpdateResults()
{
if (lastTallyQuest != null)
ConstructResults(lastTallyQuest);
}

#endregion

#region Interface functions
Expand Down Expand Up @@ -121,6 +140,8 @@ public void ClearPageCache()
/// </summary>
private void ConstructResults(IQuest quest)
{
lastTallyQuest = quest;

StringBuilder sb = new StringBuilder();

var assembly = Assembly.GetExecutingAssembly();
Expand All @@ -142,13 +163,23 @@ private void ConstructResults(IQuest quest)
sb.Append(vote.Value.Count);
sb.AppendLine("[/b]");

if (UseSpoilerForVoters)
{
sb.AppendLine("[spoiler=Voters]");
}

sb.Append(GenerateSupporterUrl(quest, vote.Value.First()));

var remainder = vote.Value.Skip(1);

foreach (var supporter in vote.Value.Skip(1).OrderBy(v => v))
sb.Append(GenerateSupporterUrl(quest, supporter));

if (UseSpoilerForVoters)
{
sb.AppendLine("[/spoiler]");
}

sb.AppendLine("");
}

Expand Down

0 comments on commit 123bcf8

Please sign in to comment.