123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- namespace HistoryDLL
- {
- public partial class CyclicScroller : UserControl,IDisposable
- {
- private int AutoRunVelocityValue = 0;
- private bool IsConfigSettingExist = false;
- private List<bool> canUsingLangList = new List<bool>(4) { false, false, false, false };
-
-
-
- private void InitialWholeSetting(string settingPath = null)
- {
-
- if (!Directory.Exists(GlobalFunction.settingPath))
- {
- Directory.CreateDirectory(GlobalFunction.settingPath);
- }
- else if (File.Exists(GlobalFunction.ConfigSettingFilePath))
- {
- IsConfigSettingExist = true;
- }
-
- SetChangeLangStatus();
-
- SetHomeBtnStatus();
-
- AutoRunVelocityValue = GetAutoRunVelocity();
-
- storyboardForLocate.Completed += new EventHandler(storyboardForLocate_Completed);
-
- GlobalFunction.CheckAutoRunTimer.Interval = TimeSpan.FromMilliseconds(ConfigSettingClass.MainBackCollect.BackHomeMillisecond * 1000);
- GlobalFunction.CheckAutoRunTimer.Tick += CheckAutoRunTimer_Tick;
-
- GlobalFunction.isSolutionUsing4K = ConfigSettingClass.MainBackCollect.IsUsing4kResolution;
-
- if (IsConfigSettingExist)
- {
- if (File.Exists(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgBackground))
- {
- this.uxBackGroundImg.Visibility = System.Windows.Visibility.Visible;
- this.Background = Brushes.White;
- this.uxBackGroundImg.Source = GetBitMap(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgBackground);
- }
- else
- {
- this.uxBackGroundImg.Visibility = System.Windows.Visibility.Collapsed;
- this.Background = new SolidColorBrush(ConfigSettingClass.MainBackCollect.BackgroundColor);
- }
- }
- else
- {
-
- LoadBackgroundFromResolution();
- }
-
- if (File.Exists(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo))
- {
- uxLeftLogoMap.Visibility = Visibility.Visible;
- uxRightLogoMap.Visibility = Visibility.Visible;
- uxLeftLogoMap.Source = new BitmapImage(new Uri(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo));
- uxRightLogoMap.Source = new BitmapImage(new Uri(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo));
- RenderOptions.SetBitmapScalingMode(uxLeftLogoMap, BitmapScalingMode.HighQuality);
- RenderOptions.SetBitmapScalingMode(uxRightLogoMap, BitmapScalingMode.HighQuality);
- }
- else
- {
- uxLeftLogoMap.Opacity = 0;
- uxRightLogoMap.Opacity = 0;
- }
- }
- private void LoadBackgroundFromResolution()
- {
- if (CurrentMonitorCount.ncm == MonitorFlag.Monitor1_1)
- {
-
- }
- else if (CurrentMonitorCount.ncm == MonitorFlag.Monitor2_1)
- {
- this.Background = new ImageBrush(new BitmapImage(new Uri(GlobalFunction.thumbPath + "1x2.jpg")));
- }
- else if (CurrentMonitorCount.ncm == MonitorFlag.Monitor3_1)
- {
- this.Background = new ImageBrush(new BitmapImage(new Uri(GlobalFunction.thumbPath + "1x3.jpg")));
- }
- }
-
- private void SetChangeLangStatus()
- {
- if (File.Exists(GlobalFunction.CanChangeLangPath))
- {
- string text = System.IO.File.ReadAllText(GlobalFunction.CanChangeLangPath);
- int usingCount = 0;
- if (text.ToLower() == "true")
- {
- if (ConfigSettingClass.MainBackCollect.LangText[0] != "")
- {
- canUsingLangList[0] = true;
- usingCount++;
- }
- if (ConfigSettingClass.MainBackCollect.LangText[1] != "")
- {
- canUsingLangList[1] = true;
- usingCount++;
- }
- if (ConfigSettingClass.MainBackCollect.LangText[2] != "")
- {
- canUsingLangList[2] = true;
- usingCount++;
- }
- if (ConfigSettingClass.MainBackCollect.LangText[3] != "")
- {
- canUsingLangList[3] = true;
- usingCount++;
- }
- }
- if (usingCount >= 2)
- {
- uxMainLangBtnR.Visibility = Visibility.Visible;
- uxMainLangBtnL.Visibility = Visibility.Visible;
- }
- }
- }
-
- private void SetHomeBtnStatus()
- {
- if (File.Exists(GlobalFunction.CanHomeClickPath))
- {
- string text = System.IO.File.ReadAllText(GlobalFunction.CanHomeClickPath);
- if (text.ToLower() == "true")
- {
- uxHomeBtnR.Visibility = Visibility.Visible;
- uxHomeBtnL.Visibility = Visibility.Visible;
- }
- }
- }
-
- private int GetAutoRunVelocity()
- {
- int result = 5;
- if (File.Exists(GlobalFunction.AutoRunVelocityPath))
- {
- string text = System.IO.File.ReadAllText(GlobalFunction.AutoRunVelocityPath);
- result = int.Parse(text);
- }
- return result;
- }
-
- private void SetAutoRunStoryBoard(double from, double to)
- {
- autoRunStoryboard.Children.Clear();
- DoubleAnimation dbOffset = new DoubleAnimation()
- {
- Duration = TimeSpan.FromSeconds(AutoRunVelocityValue),
- };
- ScrollViewerUtilities.UseMotionStop = false;
- Storyboard.SetTarget(dbOffset, (DependencyObject)this.FindName("uxMyScroll"));
- Storyboard.SetTargetProperty(dbOffset, new PropertyPath(ScrollViewerUtilities.HorizontalOffsetProperty));
- autoRunStoryboard.Children.Add(dbOffset);
- autoRunStoryboard.FillBehavior = FillBehavior.HoldEnd;
- dbOffset.From = from;
- dbOffset.To = to;
- }
- private ImageSource GetBitMap(string imgpath)
- {
- BitmapImage bitmapImg = new BitmapImage();
- bitmapImg.BeginInit();
- bitmapImg.UriSource = new Uri(imgpath, UriKind.RelativeOrAbsolute);
-
-
- bitmapImg.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
-
- bitmapImg.CacheOption = BitmapCacheOption.OnLoad;
-
- bitmapImg.EndInit();
- bitmapImg.Freeze();
- return bitmapImg;
- }
-
-
-
- private void CreateExtraUnitGrid()
- {
- ExtraUnitGridList.Clear();
- for (int count = 0; count < ChildrenCount; count++)
- {
- ExtraUnitGrid ExtraGrid = new ExtraUnitGrid(MainEventWidth, MainEventHeight, YearEventHeight, NoneUseRange);
- ExtraGrid.ExtraUnitGridBubbleToCyclicScrollerEvent += new ExtraUnitGrid.ExtraUnitGridBubbleToCyclicScroller(ExtraGrid_ExtraUnitGridBubbleToCyclicScrollerEvent);
- ExtraUnitGridList.Add(ExtraGrid);
- }
- }
-
-
-
- private void InitializeExtraUnitGrid()
- {
- int index = 1;
-
-
- for (int count = 0; count < ExtraUnitGridList.Count; count++)
- {
- ExtraUnitGridList[count].Get_Set_MonitorIndex = index;
-
- if (index == 1 || index == ExtraUnitGridList.Count)
- {
-
- ExtraUnitGridList[count].Get_Set_BlockControlMode = ExtraUnitGrid.ControlMode.UnUse;
-
- ExtraUnitGridList[count].SetOriControlMode(ExtraUnitGrid.ControlMode.UnUse);
- }
- else
- {
- ExtraUnitGridList[count].Get_Set_BlockControlMode = ExtraUnitGrid.ControlMode.CanExtend;
- ExtraUnitGridList[count].SetOriControlMode(ExtraUnitGrid.ControlMode.CanExtend);
- }
- index++;
- }
-
- for (int count = 0; count < ExtraUnitGridList.Count; count++)
- {
-
- if (count == 0)
- {
- ExtraUnitGridList[count].Margin = new Thickness(-NoneUseRange, 0, 0, uxMyScroll.Margin.Bottom - 5);
- ExtraUnitGridList[count].RecodeMarginLeft = ExtraUnitGridList[count].Margin.Left;
- continue;
- }
- ExtraUnitGridList[count].Margin = new Thickness(ExtraUnitGridList[count - 1].Margin.Left + MainEventWidth, 0, 0, uxMyScroll.Margin.Bottom - 5);
- ExtraUnitGridList[count].RecodeMarginLeft = ExtraUnitGridList[count].Margin.Left;
- }
- }
-
-
-
- private void SetLanguage()
- {
-
- System.Windows.Application.Current.Properties["Language"] = "Language1";
- uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[0];
- uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[0];
-
- if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 1)
- {
- System.Windows.Application.Current.Properties["Language"] = "Language2";
- uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[1];
- uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[1];
- }
- else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 2)
- {
- System.Windows.Application.Current.Properties["Language"] = "Language3";
- uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[2];
- uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[2];
- }
- else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 3)
- {
- System.Windows.Application.Current.Properties["Language"] = "Language4";
- uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[3];
- uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[3];
- }
- }
-
-
-
- private void SetReturnPos()
- {
- System.Windows.Application.Current.Properties["ReturnPos"] = MainEventWidth + NoneUseRange;
- }
-
-
-
-
- private int GetIndexFromRightSide()
- {
- int index = currentLoadIndex;
- if (index < LiveContainerList.Count)
- {
- index += 1;
- }
- else
- {
- index = 1;
- }
- return index;
- }
-
-
-
-
- private int GetIndexFromLeftSide()
- {
- int index = currentLoadIndex;
- if (index > 0)
- {
- index -= 1;
- }
- else
- {
- index = LiveContainerList.Count - 1;
- }
- return index;
- }
-
-
-
-
- private int GetCenterIndexValue()
- {
- int result = 0;
- switch (CurrentMonitorCount.ncm)
- {
- case MonitorFlag.Monitor1_1:
- case MonitorFlag.Monitor2_1:
- case MonitorFlag.Monitor3_1:
- case MonitorFlag.Monitor4_1:
- case MonitorFlag.Monitor5_1:
- case MonitorFlag.Monitor6_1:
- {
- result = ChildrenCount / 2;
- break;
- }
- }
- return result;
- }
- #region 首頁動畫
-
-
-
- private void CalcCountToHomePage()
- {
- if (!RunHomePageAnimation)
- {
- return;
- }
- int staticvalue = GetCycleCount();
- int totalevent = 0;
- for (int index = 0; index < staticvalue; index++)
- {
- for (int count = 0; count < xmlDataList.Count; count++)
- {
- totalevent += xmlDataList[count].monthclassList.Count;
- }
- }
- hp.SetEventCount(totalevent);
- }
-
-
-
- private void LoadingStart()
- {
- if (RunHomePageAnimation)
- {
- this.uxCyclicGrid.Opacity = 0;
- }
- }
- private void AddHomePageAnimation()
- {
- if (RunHomePageAnimation)
- {
- hp = new HomePage(ResolutionValueWidth, ResolutionValueHeight);
- hp.SetBlockCommonSetting(MainEventWidth, YearEventHeight, NoneUseRange);
- hp.SetHistoryWallControl(uxCyclicGrid);
- hp.OnLoadProgessComplete += Hp_OnLoadProgessComplete;
- uxMainWindow.Children.Add(hp);
- }
- }
- private void Hp_OnLoadProgessComplete(object sender, EventArgs e)
- {
- OnDataLoadCompeleted?.Invoke(this,null);
- }
- #endregion
- #region 自動輪播相關
- void CheckAutoRunTimer_Tick(object sender, EventArgs e)
- {
-
- if (CheckExtraGridIsVideoRun())
- {
-
- CloseExtraGrid();
-
- WpfDelayDoWork.DoWork(HistoryWallAutoRun, 1000);
- isAutoRun = true;
- GlobalFunction.CheckAutoRunTimer.Stop();
- }
- }
- private bool CheckExtraGridIsVideoRun()
- {
- bool isCheckVideo = true;
- int count = ExtraUnitGridList.Count;
- for (int i = 0; i < count; i++)
- {
- Grid gd = ExtraUnitGridList[i].BorderUp.Child as Grid;
- if (gd != null && gd.Children.Count > 0)
- {
- DetailViewer dv = gd.Children[0] as DetailViewer;
- if (dv.isPlayVideo)
- {
- isCheckVideo = false;
- break;
- }
- }
- }
- return isCheckVideo;
- }
-
-
-
- private void CloseExtraGrid()
- {
- int count = ExtraUnitGridList.Count;
- for (int i = 0; i < count; i++)
- {
- ExtraUnitGridList[i].BorderDown_TouchUp(null, null);
- }
- }
-
-
-
- private void HistoryWallAutoRun()
- {
- if (ControlMode == HistoryControlMode.Manual)
- {
- ControlMode = HistoryControlMode.AutoRun;
- SendControlModeToLiveContainer(ControlMode);
- SetAutoRunStoryBoard(this.uxMyScroll.HorizontalOffset, this.uxMyScroll.HorizontalOffset + MainEventWidth);
- autoRunStoryboard.Begin();
- }
- }
-
-
-
- private void StopAutoRunTheWall()
- {
- if (ControlMode == HistoryControlMode.AutoRun)
- {
- ScrollViewerUtilities.UseMotionStop = true;
- autoRunStoryboard.Stop();
- ControlMode = HistoryControlMode.Manual;
- SendControlModeToLiveContainer(ControlMode);
- }
- }
- #endregion
- public void Dispose()
- {
- GlobalFunction.CheckAutoRunTimer.Tick -= CheckAutoRunTimer_Tick;
- }
- }
- }
|