Skip to content

Commit

Permalink
丰富课程表展示内容(开始时间、剩余时间)
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Jul 26, 2024
1 parent 4e21302 commit 755ac32
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 44 deletions.
29 changes: 29 additions & 0 deletions ZongziTEK_Blackboard_Sticker/Controls/TimetableLesson.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<UserControl x:Class="ZongziTEK_Blackboard_Sticker.TimetableLesson"
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:ui="http://schemas.inkore.net/lib/ui/wpf/modern" xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
xmlns:local="clr-namespace:ZongziTEK_Blackboard_Sticker"
mc:Ignorable="d"
d:DesignHeight="44" d:DesignWidth="200" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Loaded="UserControl_Loaded" Height="44">
<Grid>
<Grid>
<Border Background="{DynamicResource {x:Static ui:ThemeKeys.CardBackgroundFillColorDefaultBrushKey}}"
CornerRadius="4" BorderBrush="{DynamicResource {x:Static ui:ThemeKeys.CardStrokeColorDefaultBrushKey}}" BorderThickness="1" MinHeight="44">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Border x:Name="BorderActiveIndicator" Grid.Column="0" CornerRadius="2" Width="4" Background="#99555555" Margin="8"/>
<Viewbox Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="6">
<TextBlock Foreground="{DynamicResource ForegroundColor}" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:TimetableLesson}, Mode=FindAncestor}, Path=Subject}" FontSize="32" Padding="0,0,0,2"/>
</Viewbox>
<TextBlock Foreground="{DynamicResource ForegroundColor}" Grid.Column="2" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:TimetableLesson}, Mode=FindAncestor}, Path=Time}" VerticalAlignment="Center" Margin="8" FontSize="20" Opacity="0.75" FontFamily="../Resources/#Digital-7 Mono"/>
</Grid>
</Border>
</Grid>
</Grid>
</UserControl>
78 changes: 78 additions & 0 deletions ZongziTEK_Blackboard_Sticker/Controls/TimetableLesson.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using iNKORE.UI.WPF.Modern;
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.Navigation;
using System.Windows.Shapes;
using ZongziTEK_Blackboard_Sticker.Helpers;

namespace ZongziTEK_Blackboard_Sticker
{
/// <summary>
/// TimetableLesson.xaml 的交互逻辑
/// </summary>
public partial class TimetableLesson : UserControl
{
public TimetableLesson()
{
InitializeComponent();
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
if (IsActive) Activate();
else Deactivate();
}

public void Activate()
{
ControlsHelper.SetDynamicResource(BorderActiveIndicator, Border.BackgroundProperty, ThemeKeys.SystemControlBackgroundAccentBrushKey);
if (!IsActive) IsActive = true;
}

public void Deactivate()
{
BorderActiveIndicator.Background = new SolidColorBrush(Color.FromArgb(153, 85, 85, 85));
if (IsActive) IsActive = false;
}

public string Subject
{
get { return (string)GetValue(SubjectProperty); }
set { SetValue(SubjectProperty, value); }
}

// Using a DependencyProperty as the backing store for Subject. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SubjectProperty =
DependencyProperty.Register("Subject", typeof(string), typeof(TimetableLesson), new PropertyMetadata(""));

public string Time
{
get { return (string)GetValue(TimeProperty); }
set { SetValue(TimeProperty, value); }
}

// Using a DependencyProperty as the backing store for Time. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TimeProperty =
DependencyProperty.Register("Time", typeof(string), typeof(TimetableLesson), new PropertyMetadata(""));

public bool IsActive
{
get { return (bool)GetValue(IsActiveProperty); }
set { SetValue(IsActiveProperty, value); }
}

// Using a DependencyProperty as the backing store for IsActive. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register("IsActive", typeof(bool), typeof(TimetableLesson), new PropertyMetadata(false));
}
}
10 changes: 6 additions & 4 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@
</Grid.RowDefinitions>
<ui:ScrollViewerEx Name="ScrollViewerShowCurriculum" PanningMode="VerticalOnly">
<Grid Margin="16">
<TextBlock Visibility="Collapsed" Name="textBlockCurriculum" TextWrapping="Wrap"
Text="语文&#10;数学&#10;英语&#10;物理&#10;化学&#10;生物&#10;历史&#10;政治&#10;地理&#10;活动&#10;体育"
FontSize="28" Foreground="{DynamicResource ForegroundColor}" TextAlignment="Center"/>
<ikw:SimpleStackPanel Name="StackPanelShowTimetable"/>
<TextBlock Visibility="Collapsed" Name="textBlockCurriculum" TextWrapping="Wrap" FontSize="28" Foreground="{DynamicResource ForegroundColor}" TextAlignment="Center"/>
<ikw:SimpleStackPanel Name="StackPanelShowTimetable" Spacing="4">
<ikw:SimpleStackPanel.LayoutTransform>
<ScaleTransform x:Name="ScaleTimetable"/>
</ikw:SimpleStackPanel.LayoutTransform>
</ikw:SimpleStackPanel>
</Grid>
</ui:ScrollViewerEx>
<ui:ScrollViewerEx x:Name="ScrollViewerCurriculum" Visibility="Collapsed" PanningMode="VerticalOnly">
Expand Down
46 changes: 22 additions & 24 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,29 +1126,28 @@ private void LoadTimetable()
{
FontSize = Settings.TimetableSettings.FontSize,
HorizontalAlignment = HorizontalAlignment.Center,
Foreground = (SolidColorBrush)FindResource("ForegroundColor"),
Text = "无课程"
};

StackPanelShowTimetable.Children.Add(textBlock);

ControlsHelper.SetDynamicResource(textBlock, ForegroundProperty, "ForegroundColor");
}
else
{
foreach (Lesson lesson in timetableToShow)
{
TextBlock textBlock = new TextBlock()
TimetableLesson timetableLesson = new()
{
FontSize = Settings.TimetableSettings.FontSize,
HorizontalAlignment = HorizontalAlignment.Center,
Foreground = (SolidColorBrush)FindResource("ForegroundColor"),
Text = lesson.Subject
Subject = lesson.Subject,
Time = lesson.StartTime.ToString(@"hh\:mm")
};
if (lesson.IsSplitBelow)
{
textBlock.Margin = new Thickness(0, 0, 0, 8);
timetableLesson.Margin = new Thickness(0, 0, 0, 8);
}

StackPanelShowTimetable.Children.Add(textBlock);
StackPanelShowTimetable.Children.Add(timetableLesson);
}
}

Expand Down Expand Up @@ -1214,8 +1213,6 @@ private void CheckTimetable(object sender, EventArgs e)

// 在界面中高亮当前课程或下一节课
int lessonToHighlightIndex = -1; // lessonToHighlightIndex 为 -1 时,不高亮任何课程
SolidColorBrush noHighlightBrush = (SolidColorBrush)FindResource("ForegroundColor");
SolidColorBrush highlightBrush = (SolidColorBrush)FindResource(ThemeKeys.SystemControlBackgroundAccentBrushKey);

if (isInClass) // 上课时,高亮当前课程
{
Expand All @@ -1230,25 +1227,26 @@ private void CheckTimetable(object sender, EventArgs e)
lessonToHighlightIndex = -1;
}

foreach (TextBlock textBlock in StackPanelShowTimetable.Children)
if (!(StackPanelShowTimetable.Children[0] is TextBlock))
{
if (StackPanelShowTimetable.Children.IndexOf(textBlock) == lessonToHighlightIndex) // 高亮要高亮的课程
{
textBlock.Foreground = highlightBrush;
}
else // 取消高亮不要高亮的课程
foreach (TimetableLesson timetableLesson in StackPanelShowTimetable.Children)
{
textBlock.Foreground = noHighlightBrush;
if (StackPanelShowTimetable.Children.IndexOf(timetableLesson) == lessonToHighlightIndex) // 高亮要高亮的课程,在课程开始后显示距离其结束的时间
{
timetableLesson.Activate();
if (isInClass)
{
timetableLesson.Time = (timetableToShow[lessonToHighlightIndex].EndTime - new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second)).ToString(@"mm\:ss");
}
}
else // 取消高亮不要高亮的课程,并恢复时间显示
{
timetableLesson.Deactivate();
timetableLesson.Time = timetableToShow[StackPanelShowTimetable.Children.IndexOf(timetableLesson)].StartTime.ToString(@"hh\:mm");
}
}
}
}
else if (StackPanelShowTimetable.Children.Count > 0)
{
foreach (TextBlock textBlock in StackPanelShowTimetable.Children)
{
textBlock.Foreground = (SolidColorBrush)FindResource("ForegroundColor");
}
}

timetableTimer.Start();
}
Expand Down
20 changes: 4 additions & 16 deletions ZongziTEK_Blackboard_Sticker/TimetableEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Win32;
using iNKORE.UI.WPF.Helpers;
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -32,8 +33,6 @@ public TimetableEditor()
}

#region Window & Controls
public static event Action EditorButtonUseCurriculum_Click;

private bool isCloseWithoutWarning = false;

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand Down Expand Up @@ -66,18 +65,6 @@ private void ButtonClose_Click(object sender, RoutedEventArgs e)
Close();
}

private void ButtonUseCurriculum_Click(object sender, RoutedEventArgs e)
{
if (isEdited || MessageBox.Show("是否保存当前含时间信息的课程表内容", "ZongziTEK 黑板贴", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.OK)
{
ButtonSave_Click(null, null);
}
MessageBox.Show("若后续需要使用含时间信息的课程表,请在设置中启用", "ZongziTEK 黑板贴");
EditorButtonUseCurriculum_Click?.Invoke();
isCloseWithoutWarning = true;
Close();
}

private async void ComboBoxDay_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LoadTimetable();
Expand Down Expand Up @@ -121,7 +108,8 @@ private void Item_LessonInfoChanged(object sender, EventArgs e)
{
Lesson lesson = new Lesson(changedItem.Subject, TimeSpan.Parse(changedItem.StartTime), TimeSpan.Parse(changedItem.EndTime), changedItem.IsSplitBelow, changedItem.IsStrongClassOverNotificationEnabled);
GetSelectedDay()[index] = lesson;
if (lesson.IsSplitBelow)
changedItem.BeginAnimation(MarginProperty, null);
if (changedItem.IsSplitBelow)
{
changedItem.Margin = new Thickness(0, 0, 0, 8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<Compile Include="Controls\Cards\ToggleSwitchCard.xaml.cs">
<DependentUpon>ToggleSwitchCard.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\TimetableLesson.xaml.cs">
<DependentUpon>TimetableLesson.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\ControlsHelper.cs" />
<Compile Include="Pages\InfoBoardPages\CountdownPage.xaml.cs">
<DependentUpon>CountdownPage.xaml</DependentUpon>
Expand Down Expand Up @@ -188,6 +191,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\TimetableLesson.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LauncherEditor.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down

0 comments on commit 755ac32

Please sign in to comment.