using CommunityToolkit.Mvvm.Messaging; using DotNet4.Utilities; using HandyControl.Controls; using LiveTools.Data; using LiveTools.RuleItem; using Newtonsoft.Json.Linq; using ryCommon; using ryCommonDb; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; 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; namespace LiveTools { /// /// Rule_ShowPic.xaml 的交互逻辑 /// public partial class Rule_ShowPic : UserControl, IRule { public Rule_ShowPic() { InitializeComponent(); } public string RuleID { get;} = "ShowPic"; public int ID { get; set; } = 0; public void LoadSetting(JObject jo) { ChkPlaySound.IsChecked = jo.GetJsonValue("PlaySound", true); var PicPath = API.GetTruePath(jo.GetJsonValue("PicPath", "")); if (System.IO.File.Exists(PicPath)) { PicSelector.SetValue(ImageSelector.UriPropertyKey, new Uri(PicPath)); PicSelector.SetValue(ImageSelector.PreviewBrushPropertyKey, new ImageBrush(BitmapFrame.Create(PicSelector.Uri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None)) { Stretch = PicSelector.Stretch }); PicSelector.SetCurrentValue(FrameworkElement.ToolTipProperty, PicPath); } NumPicSize.Value = jo.GetJsonValue("PicSize", 70); NumPicCount.Value = jo.GetJsonValue("PicCount", 10); } public JObject SettingJson() { return new JObject() { { "Name",this.GetType().Name}, { "Mode",RuleID}, { "PlaySound", ChkPlaySound.IsChecked ?? true }, { "PicPath",API.GetRelativePath(PicSelector.Uri.LocalPath) }, { "PicSize", NumPicSize.Value.ToInt() }, { "PicCount", NumPicCount.Value.ToInt() }, }; } public void Run(EffectInfo info, JObject jo) { } public bool CheckVerification() { if (PicSelector.Uri == null) { HandyControl.Controls.MessageBox.Warning("请选择图片。", "提示"); return false; } if (!System.IO.File.Exists(PicSelector.Uri.LocalPath)) { HandyControl.Controls.MessageBox.Warning("选择的图片不存在。", "提示"); return false; } return true; } private void UserControl_Loaded(object sender, RoutedEventArgs e) { } private void BtnClose_Click(object sender, RoutedEventArgs e) { WeakReferenceMessenger.Default.Send(new RuleMsg() { ID = ID, Message="Close" }); } } }