Skip to content

Commit

Permalink
Finished poll plugin, implemented implicit grant flow, outgoing messa…
Browse files Browse the repository at this point in the history
…ges can now display emoticons
  • Loading branch information
newcat committed Aug 10, 2016
1 parent bd5f948 commit 6524c2f
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 75 deletions.
4 changes: 2 additions & 2 deletions pollPlugin/ChartBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Effect).BlurRadius" To="10"
Duration="0:0:0.3" />
Duration="0:0:0.15" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Effect).BlurRadius" To="0"
Duration="0:0:0.3" />
Duration="0:0:0.15" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
Expand Down
17 changes: 9 additions & 8 deletions pollPlugin/UserControl1.xaml → pollPlugin/PollSetup.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Window x:Class="pollPlugin.UserControl1"
<Window x:Class="pollPlugin.PollSetup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:pollPlugin"
mc:Ignorable="d"
Background="{DynamicResource WindowBackgroundBrush}"
Title="PollWindow" Height="270" Width="260" ResizeMode="CanMinimize" Closing="Window_Closing">
Title="Setup poll" Height="275" Width="265" ResizeMode="CanMinimize" Closing="Window_Closing">

<Window.Resources>

Expand Down Expand Up @@ -85,14 +85,15 @@

<Grid x:Name="MainGrid">

<CheckBox x:Name="checkBox" Content="Multi-Vote" HorizontalAlignment="Left" Margin="10,207,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Segoe UI Light">
<CheckBox x:Name="cbMultiVote" Content="Multi-Vote" HorizontalAlignment="Left" Margin="10,207,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Segoe UI Light" Height="20"
ToolTip="If this option is enabled, viewers can vote for multiple options instead of just one, but they can still only vote one time per option.">
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="Template" Value="{DynamicResource CheckboxTemplate}" />
</Style>
</CheckBox.Style>
</CheckBox>
<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="171" Margin="10,31,0,0" VerticalAlignment="Top" Width="231" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="166" Margin="10,36,0,0" VerticalAlignment="Top" Width="231" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.Style>
<Style TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="Transparent" />
Expand Down Expand Up @@ -121,14 +122,14 @@
</Style>
</Button.Style>
</Button>
<Button x:Name="btnDelete" Content="-" HorizontalAlignment="Left" Margin="225,10,0,0" VerticalAlignment="Top" Width="16" Height="16" Click="btnDelete_Click">
<Button x:Name="btnDelete" Content="-" HorizontalAlignment="Left" Margin="220,10,0,0" VerticalAlignment="Top" Width="21" Height="21" Click="btnDelete_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template" Value="{StaticResource ButtonTemplate}" />
</Style>
</Button.Style>
</Button>
<Button x:Name="btnAdd" Content="+" HorizontalAlignment="Left" Margin="204,10,0,0" VerticalAlignment="Top" Width="16" Height="16" Click="btnAdd_Click">
<Button x:Name="btnAdd" Content="+" HorizontalAlignment="Left" Margin="194,10,0,0" VerticalAlignment="Top" Width="21" Height="21" Click="btnAdd_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template" Value="{StaticResource ButtonTemplate}" />
Expand All @@ -138,8 +139,8 @@
<TextBox Background="Transparent"
CaretBrush="White" BorderBrush="White"
Foreground="White" x:Name="tbAddOption" HorizontalAlignment="Left"
Height="16" Margin="10,10,0,0" TextWrapping="Wrap" Text=""
VerticalAlignment="Top" Width="189" FontSize="10"/>
Height="21" Margin="10,10,0,0" TextWrapping="Wrap" Text=""
VerticalAlignment="Top" Width="179" />

</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace pollPlugin
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : Window, IPlugin
public partial class PollSetup : Window, IPlugin
{

private IPluginHost host;
private ObservableCollection<string> pollOptions = new ObservableCollection<string>();
private ResultsWindow rw;

public UserControl1()
public PollSetup()
{
Assembly.LoadFrom("plugin.dll");
InitializeComponent();
Expand Down Expand Up @@ -111,7 +111,7 @@ private void btnDelete_Click(object sender, RoutedEventArgs e)
private void btnStartPoll_Click(object sender, RoutedEventArgs e)
{
Hide();
ResultsWindow rw = new ResultsWindow(pollOptions, host);
ResultsWindow rw = new ResultsWindow(pollOptions, host, (bool)cbMultiVote.IsChecked);
}
}
}
26 changes: 17 additions & 9 deletions pollPlugin/Properties/Settings.Designer.cs

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

12 changes: 7 additions & 5 deletions pollPlugin/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="pollPlugin.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="notify" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
9 changes: 9 additions & 0 deletions pollPlugin/ResultsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@
<TextBlock x:Name="tbTimeRunning" HorizontalAlignment="Right" Margin="0,31,10,0" TextWrapping="Wrap" Text="0:00" VerticalAlignment="Top" TextAlignment="Right" Foreground="White"/>
<TextBlock HorizontalAlignment="Right" Margin="0,70,10,0" TextWrapping="Wrap" Text="Total Votes:" VerticalAlignment="Top" Foreground="White"/>
<TextBlock x:Name="tbTotalVotes" HorizontalAlignment="Right" Margin="0,86,10.333,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Foreground="White" FontFamily="Segoe UI Light" FontSize="48" TextAlignment="Right" Height="70"/>
<TextBlock x:Name="tbVoteType" Margin="0,161,10,0" TextWrapping="Wrap" Text="Single Vote" VerticalAlignment="Top" Foreground="White" HorizontalAlignment="Right" Width="85" TextAlignment="Right"/>
<CheckBox x:Name="cbNotify" Content="Notify" Foreground="White" HorizontalAlignment="Right" Margin="0,185,10,0" VerticalAlignment="Top"
ToolTip="Sends a whisper message to the users after they voted so they know their vote has been received." Checked="cbNotify_Checked" Unchecked="cbNotify_Unchecked">
<CheckBox.Style>
<Style TargetType="CheckBox">
<Setter Property="Template" Value="{StaticResource CheckboxTemplate}" />
</Style>
</CheckBox.Style>
</CheckBox>

</Grid>
</Window>
71 changes: 51 additions & 20 deletions pollPlugin/ResultsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using tvdc.EventArguments;
using tvdc.Plugin;
Expand All @@ -34,23 +26,28 @@ public partial class ResultsWindow : Window
{ Color.FromRgb(255, 136, 0), Color.FromRgb(255, 165, 61)}
};

//UIElement[0] = ChartBar, [1] = TextBlock
private Dictionary<string, OptionData> pollOptions = new Dictionary<string, OptionData>();
private Dictionary<string, string> voters = new Dictionary<string, string>();
private Dictionary<string, List<string>> voters = new Dictionary<string, List<string>>();
private int totalVotes = 0;
private bool multiVote;

private IPluginHost host;

private DispatcherTimer tmr = new DispatcherTimer();
private DateTime startTime;

public ResultsWindow(IEnumerable<string> options, IPluginHost host)
public ResultsWindow(IEnumerable<string> options, IPluginHost host, bool multiVote)
{
InitializeComponent();

cbNotify.IsChecked = Properties.Settings.Default.notify;

this.host = host;
this.host.IRC_PrivmsgReceived += messageReceived;

this.multiVote = multiVote;
tbVoteType.Text = multiVote ? "Multi Vote" : "Single Vote";

startTime = DateTime.Now;
tmr.Interval = TimeSpan.FromSeconds(1);
tmr.Tick += Tmr_Tick;
Expand Down Expand Up @@ -87,10 +84,10 @@ private void Tmr_Tick(object sender, EventArgs e)
{
if (totalVotes == 0)
{
od.cb.setValue(100);
od.cb.setValue(0);
} else
{
od.cb.setValue((od.voteCount / totalVotes) * 200);
od.cb.setValue((od.voteCount / totalVotes * 1.0) * 200);
}
}
}
Expand Down Expand Up @@ -121,16 +118,38 @@ public void messageReceived(object sender, PrivmsgReceivedEventArgs e)
string option = e.message.Trim().ToLower();
if (voters.ContainsKey(e.username))
{
pollOptions[voters[e.username]].voteCount -= 1;
voters[e.username] = option;
host.sendMesssage(string.Format("/w {0} You changed your vote to {1}.",
e.username, option));
if (multiVote)
{
if (voters[e.username].Contains(option) && Properties.Settings.Default.notify)
{
host.sendMesssage(string.Format("/w {0} You already voted for {1}.",
e.username, option));
return;
} else
{
voters[e.username].Add(option);
totalVotes += 1;
if (Properties.Settings.Default.notify)
host.sendMesssage(string.Format("/w {0} Thanks for voting! You voted for {1}.",
e.username, string.Join(", ", voters[e.username].ToArray())));
}
} else
{
pollOptions[voters[e.username][0]].voteCount -= 1;
voters[e.username][0] = option;
if (Properties.Settings.Default.notify)
host.sendMesssage(string.Format("/w {0} You changed your vote to {1}.",
e.username, option));
}
} else
{
totalVotes += 1;
voters.Add(e.username, option);
host.sendMesssage(string.Format("/w {0} Thanks for voting! You voted for {1}.",
e.username, option));
List<string> l = new List<string>();
l.Add(option);
voters.Add(e.username, l);
if (Properties.Settings.Default.notify)
host.sendMesssage(string.Format("/w {0} Thanks for voting! You voted for {1}.",
e.username, option));
}
pollOptions[option].voteCount += 1;
}
Expand All @@ -153,5 +172,17 @@ private void Window_Closed(object sender, EventArgs e)
tmr.Stop();
host.IRC_PrivmsgReceived -= messageReceived;
}

private void cbNotify_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.notify = true;
Properties.Settings.Default.Save();
}

private void cbNotify_Unchecked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.notify = false;
Properties.Settings.Default.Save();
}
}
}
15 changes: 15 additions & 0 deletions pollPlugin/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="pollPlugin.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<pollPlugin.Properties.Settings>
<setting name="notify" serializeAs="String">
<value>True</value>
</setting>
</pollPlugin.Properties.Settings>
</userSettings>
</configuration>
9 changes: 5 additions & 4 deletions pollPlugin/pollPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl1.xaml">
<Page Include="PollSetup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Expand All @@ -68,8 +68,8 @@
<Compile Include="ResultsWindow.xaml.cs">
<DependentUpon>ResultsWindow.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl1.xaml.cs">
<DependentUpon>UserControl1.xaml</DependentUpon>
<Compile Include="PollSetup.xaml.cs">
<DependentUpon>PollSetup.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
Expand All @@ -91,6 +91,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -111,7 +112,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy $(TargetPath) $(SolutionDir)\tvdc\bin\Debug\</PostBuildEvent>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)tvdc\bin\Debug\"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
6 changes: 5 additions & 1 deletion tvdc.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tvdc", "tvdc\tvdc.csproj", "{BD9CC7C0-3D04-42B9-BA3C-40CA4F1B78F8}"
ProjectSection(ProjectDependencies) = postProject
{8CE76121-E353-4A06-A8E6-2DF560ED2228} = {8CE76121-E353-4A06-A8E6-2DF560ED2228}
{B857BA90-2B28-4138-B0D2-27213281EE21} = {B857BA90-2B28-4138-B0D2-27213281EE21}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pollPlugin", "pollPlugin\pollPlugin.csproj", "{8CE76121-E353-4A06-A8E6-2DF560ED2228}"
ProjectSection(ProjectDependencies) = postProject
{B857BA90-2B28-4138-B0D2-27213281EE21} = {B857BA90-2B28-4138-B0D2-27213281EE21}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "plugin", "plugin\plugin.csproj", "{B857BA90-2B28-4138-B0D2-27213281EE21}"
EndProject
Expand Down
13 changes: 13 additions & 0 deletions tvdc/AuthenticationWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Window x:Class="tvdc.AuthenticationWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:tvdc"
mc:Ignorable="d"
Title="Authenticate" Height="400" Width="350" Loaded="Window_Loaded">
<Grid>
<WebBrowser x:Name="wb" Margin="0,0,0,0" Navigating="wb_Navigating" />

</Grid>
</Window>
Loading

0 comments on commit 6524c2f

Please sign in to comment.