Browse Source

Update Status Light design

Zixuan 1 month ago
parent
commit
d60a1d28e7

+ 19 - 0
FurnaceNewWorld/FurnaceNewWorld/Controls/BuzzerLight.xaml

@@ -0,0 +1,19 @@
+<UserControl x:Class="FurnaceNewWorld.Controls.BuzzerLight"
+             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:FurnaceNewWorld.Controls"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800">
+    <Grid>
+        <StackPanel Margin="16,0" Grid.Column="6" VerticalAlignment="Center">
+            <Border Width="40" Height="8" Background="#dedede"></Border>
+            <Border x:Name="Red" Width="40" Height="14" Background="{StaticResource LightEmergencyColor}"></Border>
+            <Border x:Name="Yellow" Width="40" Height="14" Background="{StaticResource LightWarningColor}"></Border>
+            <Border x:Name="Green" Width="40" Height="14" Background="{StaticResource LightNormalColor}"></Border>
+            <Border x:Name="Blue" Width="40" Height="14" Background="{StaticResource NiceBlue}"></Border>
+            <Border  Width="40" Height="8" Background="#dedede"></Border>
+        </StackPanel>
+    </Grid>
+</UserControl>

+ 106 - 0
FurnaceNewWorld/FurnaceNewWorld/Controls/BuzzerLight.xaml.cs

@@ -0,0 +1,106 @@
+using System.Runtime.CompilerServices;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Media3D;
+
+namespace FurnaceNewWorld.Controls;
+
+/// <summary>
+/// Interaction logic for BuzzerLight.xaml
+/// </summary>
+public partial class BuzzerLight : UserControl
+{
+    public BuzzerLight()
+    {
+        InitializeComponent();
+        this.Red.Width = DisableWidth;
+        this.Yellow.Width = DisableWidth;
+        this.Green.Width = DisableWidth;
+        this.Blue.Width = DisableWidth;
+
+        this.Red.Height = DisableHeight;
+        this.Yellow.Height = DisableHeight;
+        this.Green.Height = DisableHeight;
+        this.Blue.Height = DisableHeight;
+
+        this.Red.Background = (SolidColorBrush)App.Current.FindResource("LightEmergencyColor");
+        this.Yellow.Background = (SolidColorBrush)App.Current.FindResource("LightWarningColor");
+        this.Green.Background = (SolidColorBrush)App.Current.FindResource("LightNormalColor");
+        this.Blue.Background = (SolidColorBrush)App.Current.FindResource("NiceLightBlue");
+    }
+
+    private const float DisableWidth = 40;
+    private const float DisableHeight = 14;
+
+    private const float EnableWidth = 48;
+    private const float EnableHeight = 20;
+
+    public BuzzerLightEnum LightType
+    {
+        get { return (BuzzerLightEnum)GetValue(LightTypeProperty); }
+        set { SetValue(LightTypeProperty, value); }
+    }
+
+    public static readonly DependencyProperty LightTypeProperty =
+        DependencyProperty.Register(nameof(LightType), typeof(BuzzerLightEnum), typeof(BuzzerLight), new PropertyMetadata(LightEnumChangedCallback));
+
+    private static void LightEnumChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
+    {
+        if (d is not BuzzerLight light)
+            return;
+
+        if (e.NewValue is not BuzzerLightEnum lightEnum)
+            return;
+
+        light.Red.Width = DisableWidth;
+        light.Yellow.Width = DisableWidth;
+        light.Green.Width = DisableWidth;
+        light.Blue.Width = DisableWidth;
+
+        light.Red.Height = DisableHeight;
+        light.Yellow.Height = DisableHeight;
+        light.Green.Height = DisableHeight;
+        light.Blue.Height = DisableHeight;
+
+        light.Red.Background = (SolidColorBrush)App.Current.FindResource("LightEmergencyColor");
+        light.Yellow.Background = (SolidColorBrush)App.Current.FindResource("LightWarningColor");
+        light.Green.Background = (SolidColorBrush)App.Current.FindResource("LightNormalColor");
+        light.Blue.Background = (SolidColorBrush)App.Current.FindResource("NiceLightBlue");
+
+        Border? border = lightEnum switch
+        {
+            BuzzerLightEnum.Red => light.Red,
+            BuzzerLightEnum.Yellow => light.Yellow,
+            BuzzerLightEnum.Green => light.Green,
+            BuzzerLightEnum.Blue => light.Blue,
+            _ => null
+        };
+
+        if (border is null)
+            return;
+
+        border.Width=EnableWidth;
+        border.Height=EnableHeight;
+        border.IsEnabled = true;
+
+        border.Background = lightEnum switch
+        {
+            BuzzerLightEnum.Red => (SolidColorBrush)App.Current.FindResource("EmergencyColor"),
+            BuzzerLightEnum.Yellow => (SolidColorBrush)App.Current.FindResource("WarningColor"),
+            BuzzerLightEnum.Green => (SolidColorBrush)App.Current.FindResource("NormalColor"),
+            BuzzerLightEnum.Blue => (SolidColorBrush)App.Current.FindResource("NiceBlue"),
+            _ => null
+        };
+
+    }
+}
+
+
+public enum BuzzerLightEnum
+{
+    Undefined,
+    Red,
+    Yellow,
+    Green,
+    Blue,
+}

+ 2 - 7
FurnaceNewWorld/FurnaceNewWorld/Controls/HeaderBar.xaml

@@ -112,12 +112,7 @@
 
         </Border>
 
-        <StackPanel Margin="16,0" Grid.Column="6" VerticalAlignment="Center">
-            <Border Width="40" Height="8" Background="#dedede"></Border>
-            <Border Width="40" Height="14" Background="#efd9d9"></Border>
-            <Border Width="40" Height="14" Background="#f6ead0"></Border>
-            <Border Width="40" Height="14" Background="#0ee8d4"></Border>
-            <Border Width="40" Height="8" Background="#dedede"></Border>
-        </StackPanel>
+        <local:BuzzerLight Grid.Column="6" LightType="Green"/>
+
     </Grid>
 </UserControl>

+ 3 - 0
FurnaceNewWorld/FurnaceNewWorld/FurnaceNewWorld.csproj.user

@@ -2,6 +2,9 @@
 <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup />
   <ItemGroup>
+    <Compile Update="Controls\BuzzerLight.xaml.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Update="Controls\HeaderBar.xaml.cs">
       <SubType>Code</SubType>
     </Compile>

+ 1 - 0
FurnaceNewWorld/UICommon/Brush.xaml

@@ -25,5 +25,6 @@
     <SolidColorBrush x:Key="LightDisableColor" Color="#cccccc"/>
 
     <SolidColorBrush x:Key="NiceBlue" Color="#0083ff"/>
+    <SolidColorBrush x:Key="NiceLightBlue" Color="#aaddff"/>
     <SolidColorBrush x:Key="NiceGreen" Color="#00CC33"/>
 </ResourceDictionary>