Skip to content

Commit

Permalink
Bugfixes, support for /me command, improved update system
Browse files Browse the repository at this point in the history
  • Loading branch information
newcat committed Jul 24, 2016
1 parent 38541ca commit 575c171
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 41 deletions.
7 changes: 4 additions & 3 deletions pollPlugin/UserControl1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Reflection;
using System.Drawing;
using tvdc;
Expand All @@ -19,7 +20,7 @@ namespace pollPlugin
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : Window, IPlugin
public partial class UserControl1 : UserControl, IPlugin
{

public UserControl1()
Expand All @@ -38,7 +39,7 @@ public string pluginName

public event EventHandler<SendMessageEventArgs> sendMessage;

public Image getMenuIcon()
public System.Windows.Controls.Image getMenuIcon()
{

Bitmap bmp = new Bitmap(28, 28);
Expand All @@ -50,7 +51,7 @@ public Image getMenuIcon()

}

public Image getMenuIconHover() {
public System.Windows.Controls.Image getMenuIconHover() {

Bitmap bmp = new Bitmap(28, 28);
Graphics g = Graphics.FromImage(bmp);
Expand Down
18 changes: 16 additions & 2 deletions tvdc/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.IO;

namespace tvdc
{

//TODO: Fix that twitchnotify messages ("xxx just subscribed") are being treated as PRIVMSG which leads to crash
//TODO: Fix that if there is text after an emoticon it sometimes doesn't get displayed
//TODO: Replace poll window with poll plugin
//TODO: Add support for cheering
Expand Down Expand Up @@ -44,6 +44,18 @@ public MainWindow()
{
InitializeComponent();
DataContext = vm;

if (File.Exists(Path.Combine(Environment.CurrentDirectory, "tvd_settings.cfg")))
{
string[] cfg = File.ReadAllLines(Path.Combine(Environment.CurrentDirectory, "tvd_settings.cfg"));
Properties.Settings.Default.nick = cfg[0];
Properties.Settings.Default.oauth = cfg[1];
Properties.Settings.Default.channel = cfg[2];
Properties.Settings.Default.debug = cfg[3] == "True" ? true : false;
Properties.Settings.Default.showJoinLeave = cfg[4] == "True" ? true : false;
File.Delete(Path.Combine(Environment.CurrentDirectory, "tvd_settings.cfg"));
}

}

private async void init()
Expand Down Expand Up @@ -325,6 +337,7 @@ private void Image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
irc.disconnect();
vm.chatEntryList_Clear();
vm.viewerList_Clear();
vm.followerCount = 0;
ViewerGraph.reset();
init();
}
Expand All @@ -348,7 +361,8 @@ private void btnChatSmaller_Click(object sender, RoutedEventArgs e)

private void Window_Closed(object sender, EventArgs e)
{
irc.disconnect();
if (irc != null)
irc.disconnect();
viewerGraphTimer.Stop();
followerTimer.Stop();
Application.Current.Shutdown();
Expand Down
14 changes: 7 additions & 7 deletions tvdc/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("tvdc")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Twitch Viewer Display")]
[assembly: AssemblyDescription("View chat and stats about your viewers")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("tvdc")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyProduct("Twitch Viewer Display")]
[assembly: AssemblyCopyright("Copyright © 2016 by newcat")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -52,6 +52,6 @@
// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: nUpdateVersion("1.0")]
[assembly: AssemblyVersion("1.1.2.0")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: nUpdateVersion("1.1.2.0")]
20 changes: 6 additions & 14 deletions tvdc/Settings.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
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.Diagnostics;
using nUpdate.Updating;
using System.Globalization;
using System.IO;
using System.Text;

namespace tvdc
{
Expand All @@ -24,6 +16,7 @@ public partial class Settings : Window
{

private bool clearedCache = false;
UpdateManager manager;

public Settings()
{
Expand Down Expand Up @@ -76,10 +69,9 @@ private void btnClearCache_Click(object sender, RoutedEventArgs e)

private void btnCheckUpdate_Click(object sender, RoutedEventArgs e)
{
UpdateManager manager = new UpdateManager(new Uri("http://newcat.bplaced.net/tvd/updates.json"), "<RSAKeyValue><Modulus>8l5adrCGpcd1yzQ6gTORp/zUDwl/jxtPW3g3dqFgEFpjS9ZFW05YA6/GdGMyU0nJQ6mdnd6j3fmqYsXSPsfG8iQmsCYvjEj/2eHUl5u3I7alxsqTViifuI1pm4hJ6A5+vVU4cCW7o8twzr1tgWElvIA/AOLLADu7PfeWmH+RwQaO5uGnIklmE8A4Qsz0IBr+0BvXwn9cgj7N6jw7hQNWGnb4bOU7yrVD64J1j9GxXuYS0GRjmddtYk67EaIb8/eHW1XzzMwPiOFVb+n/S4jnfQ11bYbq35K7ruklEnWVCg21JuB+i5D5ho746RXnlLFfNcN4wi5W0X0iadwJChlN64D12QtWZtkgUacte0vlwUZojvQXVKCSRqTXQjExZwA5eyptumjtYn1firqzsRvSjeqEtK/WXFL/ArGlwteJMGIh1OLfgXsSyd0CLvAtiE3TKWsIB1ZsT1ut5Bk304cukSWtKp//ixislc00z/w/NXPSQfaNEC2jE+7fKZ4lu92tLnVVmwGT7sVLUj/hrrhwIX3biu07d5wVNvc6uXLosF7jnPrmAX2XdwghiaN77uyLVfIeUJ2RGMHfF8lVnNCyOORl+R/L1Sxww09jk1nRLWGn8ZhiRHt8t5Mj7E6cZl9kV+TBxNPkTblpZbgdZOe4HThy3NHZU9zJh7+KtNiCsziqk+iySY/ew75uHgRUYWpAncloa7rYzFkvySTBPkpSM9rqnMEmB7c1EM9XX3x+OqC+y25Viop7e7xRGYPnYaolCbiJMNdKT82fIMQEU8iQ5cvboirLd9u8pWzItkIUlg/HPaZeX0r5Nhu4ZeeduHie3OoTeS6RZ0GWZoEmgNotpzc6iSDrH5QZ1zb+LuBW+t+oi1Tyeuy7fIEPV9dkB6/ibMdUVp/qMuzPzDeJdMrNiU+VHZiulrVr2v2RUoU3Eom8pZWWWgEqwsc5FZ6/LWtLWtYBQ3mSaPWS/ilTY6DAAI0ScMU+/ahYgMk9pmexUiOc8TJDtVn4Q5DzdAmO5atyiBeFgokq8BvNnwLJRRLODF7n+qoU9eMMOWVujE61a+NqbM7bkYutF9rNH+U4F8RGz/aDOPq+m2FYcomKLXE6Hgk47DkB2Q3An2ou4Xvw5PdvmBYVAp4brR9dJ1JhsZml5J8ukXYp+XqBdTlghW/FhAIfmbF32EAzoHpa/oHV2IOr2IEGpARKj2pJAIW4oMEhqYCPV+ZEA56h78YVVJKqVeghhZGrmbhLLfe+tx0BcN/YyEvbDhwjkr8nD6QXVH239ziPiszlnJ0kxGP+dnaobYJd9pADXF9qxAC4n5RIaUT587FHJeW//oEfaPXQ5OnYUcTUX+xJbeAwvCwsEcTRbQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>", new CultureInfo("en"));
manager.CloseHostApplication = true;
var updaterUI = new UpdaterUI(manager, System.Threading.SynchronizationContext.Current);
updaterUI.ShowUserInterface();
UpdateWindow uw = new UpdateWindow();
uw.ShowDialog();
}

}
}
4 changes: 3 additions & 1 deletion tvdc/Static Stuff/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public static void Sort<T>(this ObservableCollection<T> collection) where T : IC

public static void AddSorted<T>(this ObservableCollection<T> collection, T itemToAdd) where T : IComparable<T>
{
for (int i = 0; i < collection.Count; i++)
for (int i = 0; i < collection.Count - 1; i++)
{
if (collection[i].CompareTo(itemToAdd) < 0 && collection[i + 1].CompareTo(itemToAdd) > 0)
{
collection.Insert(i + 1, itemToAdd);
return;
}
}
collection.Insert(collection.Count, itemToAdd);
}

}
Expand Down
59 changes: 45 additions & 14 deletions tvdc/UserControls/ChatRow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ namespace tvdc
public partial class ChatRow : UserControl
{

public static readonly DependencyProperty UsernameProperty = DependencyProperty.Register("Username", typeof(string), typeof(ChatRow));
public string Username
{
get { return (string)GetValue(UsernameProperty); }
set { SetValue(UsernameProperty, value); }
}

public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color", typeof(string), typeof(ChatRow));
public string Color
{
get { return (string)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}

public static readonly DependencyProperty TagsProperty = DependencyProperty.Register("Tags", typeof(Dictionary<string, string>), typeof(ChatRow));
public Dictionary<string, string> Tags
{
Expand Down Expand Up @@ -86,6 +72,27 @@ private void updateData()

}

if (Tags.Count == 1 && Tags.ContainsKey("text") && Tags["text"] != null)
{
TextBlock t = new TextBlock();
t.Text = Tags["text"];
t.VerticalAlignment = VerticalAlignment.Center;
t.HorizontalAlignment = HorizontalAlignment.Center;
t.FontWeight = FontWeights.Bold;
t.Foreground = Brushes.LightGray;
mainPanel.Children.Clear();
mainPanel.Children.Add(t);
return;
}


bool isAction = false;
if (Tags.ContainsKey("text") && Tags["text"] != null && Tags["text"].StartsWith("\u0001ACTION"))
{
isAction = true;
Tags["text"] = Tags["text"].Substring(8);
}

//Split the text into not emoticon parts
//Therefore we first need to parse the emoticons
ArrayList paragraphs = new ArrayList();
Expand Down Expand Up @@ -208,6 +215,14 @@ private void updateData()
t.Text = pg.text;
t.VerticalAlignment = VerticalAlignment.Center;

if (isAction)
{
Brush b = getUsernameColor();
if (b != null)
{
t.SetBinding(TextBlock.ForegroundProperty, "color");
}
}

if (isUrl(pg.text))
{
Expand All @@ -225,6 +240,22 @@ private void updateData()

}

private Brush getUsernameColor()
{
foreach (UIElement uie in mainPanel.Children)
{
if (uie is TextBlock)
{
TextBlock tb = (TextBlock)uie;
if (tb.Tag != null && tb.Tag.ToString() == "username")
{
return tb.Foreground;
}
}
}
return null;
}

private void addBadge(BitmapImage b)
{
Image i = new Image();
Expand Down
7 changes: 7 additions & 0 deletions tvdc/tvdc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
<Compile Include="Models\Emoticon.cs" />
<Compile Include="Static Stuff\Badges.cs" />
<Compile Include="Static Stuff\EmoticonManager.cs" />
<Compile Include="UpdateWindow.xaml.cs">
<DependentUpon>UpdateWindow.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\FNFGraph.xaml.cs">
<DependentUpon>FNFGraph.xaml</DependentUpon>
</Compile>
Expand All @@ -110,6 +113,10 @@
<Compile Include="UserControls\ViewerRow.xaml.cs">
<DependentUpon>ViewerRow.xaml</DependentUpon>
</Compile>
<Page Include="UpdateWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\FNFGraph.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
66 changes: 66 additions & 0 deletions tvdc/updateWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<Window x:Class="tvdc.UpdateWindow"
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" Background="{StaticResource WindowBackgroundBrush}"
Title="TVD Update" Height="300" Width="460" ResizeMode="NoResize" Loaded="Window_Loaded" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" Topmost="True">
<Window.Resources>
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
<Style x:Key="TextBoxStyle1" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="White"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>

<Label x:Name="lblStatus" Content="Searching for updates..." HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Foreground="White"/>
<Button x:Name="btnCancel" Content="Cancel" HorizontalAlignment="Left" Margin="367,239,0,0" VerticalAlignment="Top" Width="75" Height="20" Click="btnCancel_Click">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template" Value="{StaticResource ButtonTemplate}" />
</Style>
</Button.Style>
</Button>
<Button x:Name="btnInstall" Content="Install" HorizontalAlignment="Left" Margin="287,239,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="1.365,0.608" Height="20" IsEnabled="False" Click="btnInstall_Click">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template" Value="{StaticResource ButtonTemplate}" />
</Style>
</Button.Style>
</Button>
<ProgressBar HorizontalAlignment="Left" Height="10" Margin="10,224,0,0" VerticalAlignment="Top" Width="432" x:Name="pb"/>
<TextBox x:Name="tbChangelog" HorizontalAlignment="Left" Height="178" Margin="10,41,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="432" Style="{DynamicResource TextBoxStyle1}" IsEnabled="False" />


</Grid>
</Window>
Loading

0 comments on commit 575c171

Please sign in to comment.