feat: 样式支持自定义视频

This commit is contained in:
denglihong2007
2025-04-04 01:15:13 +08:00
parent 6669f57c12
commit 8bfed0d19e
6 changed files with 46 additions and 8 deletions

View File

@@ -15,6 +15,9 @@ namespace CRSim.ScreenSimulator.ViewModels.ChengduMetro
private TrainInfo _secondTrain = new();
[ObservableProperty]
private string _text = "不吃火锅,就吃烤匠。 建设成渝地区双城经济圈,共同唱好新时代西部“双城记”。 2018年2月8日复兴号列车首次担当G89次列车正式开进四川标志着“复兴号”高速列车正式走上蜀道。然而在行驶至西安北站时发生了突发设备故障车轴出现过热报警导致车号为CR400BF-5033的复兴号列车被迫停运并进行检修。相关工作人员迅速展开故障排查并确保乘客安全无虞。";
[ObservableProperty]
private Uri _video = new("Assets\\Advertisement.mp4", UriKind.Relative);
public List<TrainInfo> TrainInfos { get; set; } = [];
public PlatformScreenViewModel(ITimeService timeService)
{

View File

@@ -1,4 +1,4 @@
<Window x:Class="CRSim.ScreenSimulator.Views.ChengduMetro.PlatformScreenView"
<Window x:Class="CRSim.ScreenSimulator.Views.ChengduMetro.PlatformScreenView"
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"
@@ -106,7 +106,8 @@
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<MediaElement Grid.Row="0" Name="player" HorizontalAlignment="Center" VerticalAlignment="Stretch" LoadedBehavior="Manual" UnloadedBehavior="Stop" Volume="0" MediaEnded="MediaElement_MediaEnded"/>
<MediaElement Grid.Row="0" Name="player" HorizontalAlignment="Center" VerticalAlignment="Stretch"
LoadedBehavior="Manual" UnloadedBehavior="Stop" Volume="0" MediaEnded="MediaElement_MediaEnded" Source="{Binding ViewModel.Video}"/>
<pp:RunningText Grid.Row="1" x:Name="rt" Background="Orange" Foreground="White" Padding="4" FontSize="20" Speed="75"
Text="{Binding ViewModel.Text,Mode=OneWay}">
<pp:RunningText.Style>

View File

@@ -17,7 +17,6 @@ namespace CRSim.ScreenSimulator.Views.ChengduMetro
ViewModel = viewModel;
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
DataContext = this;
player.Source = new Uri("Assets\\Advertisement.mp4", UriKind.Relative);
player.Play();
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)

View File

@@ -63,7 +63,8 @@
"ImagePath": "Assets/StyleImages/ChengduMetro/PlatformScreen.png",
"Parameters": [
"Station",
"Text"
"Text",
"Video"
]
},
{

View File

@@ -28,12 +28,18 @@ public partial class ScreenSimulationPageViewModel : ObservableObject
[ObservableProperty]
private bool _textNeeded;
[ObservableProperty]
private bool _videoNeeded;
[ObservableProperty]
private bool _locationNeeded;
[ObservableProperty]
private string _text = "";
[ObservableProperty]
private string _video = "";
public string SelectedStationName = "";
public string SelectedTicketCheck = "";
@@ -86,6 +92,7 @@ public partial class ScreenSimulationPageViewModel : ObservableObject
StationNeeded = neededParameters.Contains("Station");
TicketCheckNeeded = neededParameters.Contains("TicketCheck");
PlatformNeeded = neededParameters.Contains("Platform");
VideoNeeded = neededParameters.Contains("Video");
TextNeeded = neededParameters.Contains("Text");
LocationNeeded = neededParameters.Contains("Location");
}
@@ -149,6 +156,13 @@ public partial class ScreenSimulationPageViewModel : ObservableObject
CheckCanStart();
}
[RelayCommand]
public void SelectVideo()
{
string? Path = _dialogService.GetFile("视频文件 (*.mp4)|*.mp4|所有文件 (*.*)|*.*");
if (Path == null) return;
Video = Path;
}
[RelayCommand]
public void StartSimulation()
{
var Window = _serviceProvider.GetRequiredService(selectedStyle) as dynamic;
@@ -161,6 +175,10 @@ public partial class ScreenSimulationPageViewModel : ObservableObject
{
Window.ViewModel.Location = SelectedLoaction;
}
if (VideoNeeded && Video != string.Empty)
{
Window.ViewModel.Video = new Uri(Video, UriKind.Absolute);
}
Window.ViewModel.LoadData(_databaseService.GetStationByName(SelectedStationName),
TicketCheckNeeded ? SelectedTicketCheck : string.Empty,

View File

@@ -1,4 +1,4 @@
<Page
<Page
x:Class="CRSim.Views.ScreenSimulationPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -161,7 +161,24 @@
</ComboBox>
</Grid>
</Border>
<Border Style="{StaticResource SettingsCardStyle}" Visibility="{Binding ViewModel.VideoNeeded,Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Vertical">
<TextBlock Text="视频资源路径" Style="{StaticResource BodyTextBlockStyle}"/>
<TextBlock Opacity="0.7" Style="{StaticResource CaptionTextBlockStyle}">
留空即为默认
</TextBlock>
</StackPanel>
<TextBox Grid.Column="2" MaxWidth="256" MinWidth="128" Text="{Binding ViewModel.Video ,Mode=TwoWay}" Margin="0,0,8,0"/>
<Button Grid.Column="3" Content="浏览" Command="{Binding ViewModel.SelectVideoCommand}"/>
</Grid>
</Border>
<Border Style="{StaticResource BottomSettingsCardStyle}">
<Grid IsEnabled="{Binding ViewModel.TextNeeded}">
<Grid.ColumnDefinitions>
@@ -174,11 +191,10 @@
<TextBlock Opacity="0.7" Style="{StaticResource CaptionTextBlockStyle}">
留空即为默认
</TextBlock>
</StackPanel>
</StackPanel>
<TextBox Grid.Column="2" MaxWidth="256" MinWidth="128" Text="{Binding ViewModel.Text ,Mode=TwoWay}"/>
</Grid>
</Border>
</StackPanel>
</Expander.Content>
</Expander>