CyclicScrollerSubFunction.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Media.Imaging;
  12. namespace HistoryDLL
  13. {
  14. public partial class CyclicScroller : UserControl,IDisposable
  15. {
  16. private int AutoRunVelocityValue = 0;
  17. private bool IsConfigSettingExist = false;
  18. private List<bool> canUsingLangList = new List<bool>(4) { false, false, false, false };
  19. /// <summary>
  20. /// 初始化除了Spec外的基本設定
  21. /// </summary>
  22. private void InitialWholeSetting(string settingPath = null)
  23. {
  24. //建Setting Folder 並判斷是否有存在 ConfigSetting.ini 檔案
  25. if (!Directory.Exists(GlobalFunction.settingPath))
  26. {
  27. Directory.CreateDirectory(GlobalFunction.settingPath);
  28. }
  29. else if (File.Exists(GlobalFunction.ConfigSettingFilePath))
  30. {
  31. IsConfigSettingExist = true;
  32. }
  33. //設定是否啟用切換主標題語系功能
  34. SetChangeLangStatus();
  35. //設定是否啟用回首頁功能
  36. SetHomeBtnStatus();
  37. //取得自動輪播時候的速度
  38. AutoRunVelocityValue = GetAutoRunVelocity();
  39. //掛載 StoryBoard 完成後的事件
  40. storyboardForLocate.Completed += new EventHandler(storyboardForLocate_Completed);
  41. //設定自動輪撥的 Timer
  42. GlobalFunction.CheckAutoRunTimer.Interval = TimeSpan.FromMilliseconds(ConfigSettingClass.MainBackCollect.BackHomeMillisecond * 1000);
  43. GlobalFunction.CheckAutoRunTimer.Tick += CheckAutoRunTimer_Tick;
  44. // 取得 4K 解析度設定
  45. GlobalFunction.isSolutionUsing4K = ConfigSettingClass.MainBackCollect.IsUsing4kResolution;
  46. //設定背景圖
  47. if (IsConfigSettingExist)
  48. {
  49. if (File.Exists(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgBackground))
  50. {
  51. this.uxBackGroundImg.Visibility = System.Windows.Visibility.Visible;
  52. this.Background = Brushes.White;
  53. this.uxBackGroundImg.Source = GetBitMap(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgBackground);
  54. }
  55. else
  56. {
  57. this.uxBackGroundImg.Visibility = System.Windows.Visibility.Collapsed;
  58. this.Background = new SolidColorBrush(ConfigSettingClass.MainBackCollect.BackgroundColor);
  59. }
  60. }
  61. else
  62. {
  63. //如無設定檔案~則依照解析度載入對應的圖檔
  64. LoadBackgroundFromResolution();
  65. }
  66. //設定左上及右上logo
  67. if (File.Exists(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo))
  68. {
  69. uxLeftLogoMap.Visibility = Visibility.Visible;
  70. uxRightLogoMap.Visibility = Visibility.Visible;
  71. uxLeftLogoMap.Source = new BitmapImage(new Uri(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo));
  72. uxRightLogoMap.Source = new BitmapImage(new Uri(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo));
  73. RenderOptions.SetBitmapScalingMode(uxLeftLogoMap, BitmapScalingMode.HighQuality);
  74. RenderOptions.SetBitmapScalingMode(uxRightLogoMap, BitmapScalingMode.HighQuality);
  75. }
  76. else
  77. {
  78. uxLeftLogoMap.Opacity = 0;
  79. uxRightLogoMap.Opacity = 0;
  80. }
  81. }
  82. private void LoadBackgroundFromResolution()
  83. {
  84. if (CurrentMonitorCount.ncm == MonitorFlag.Monitor1_1)
  85. {
  86. //this.Background = new ImageBrush(new BitmapImage(new Uri(GlobalFunction.thumbPath + "1x1.jpg")));
  87. }
  88. else if (CurrentMonitorCount.ncm == MonitorFlag.Monitor2_1)
  89. {
  90. this.Background = new ImageBrush(new BitmapImage(new Uri(GlobalFunction.thumbPath + "1x2.jpg")));
  91. }
  92. else if (CurrentMonitorCount.ncm == MonitorFlag.Monitor3_1)
  93. {
  94. this.Background = new ImageBrush(new BitmapImage(new Uri(GlobalFunction.thumbPath + "1x3.jpg")));
  95. }
  96. }
  97. //透過ChangeLan.txt 取得是否顯示改變主標題語系功能
  98. private void SetChangeLangStatus()
  99. {
  100. if (File.Exists(GlobalFunction.CanChangeLangPath))
  101. {
  102. string text = System.IO.File.ReadAllText(GlobalFunction.CanChangeLangPath);
  103. int usingCount = 0;
  104. if (text.ToLower() == "true")
  105. {
  106. if (ConfigSettingClass.MainBackCollect.LangText[0] != "")
  107. {
  108. canUsingLangList[0] = true;
  109. usingCount++;
  110. }
  111. if (ConfigSettingClass.MainBackCollect.LangText[1] != "")
  112. {
  113. canUsingLangList[1] = true;
  114. usingCount++;
  115. }
  116. if (ConfigSettingClass.MainBackCollect.LangText[2] != "")
  117. {
  118. canUsingLangList[2] = true;
  119. usingCount++;
  120. }
  121. if (ConfigSettingClass.MainBackCollect.LangText[3] != "")
  122. {
  123. canUsingLangList[3] = true;
  124. usingCount++;
  125. }
  126. }
  127. if (usingCount >= 2)
  128. {
  129. uxMainLangBtnR.Visibility = Visibility.Visible;
  130. uxMainLangBtnL.Visibility = Visibility.Visible;
  131. }
  132. }
  133. }
  134. //透過HomeClick.txt 取得是否顯示回首頁功能
  135. private void SetHomeBtnStatus()
  136. {
  137. if (File.Exists(GlobalFunction.CanHomeClickPath))
  138. {
  139. string text = System.IO.File.ReadAllText(GlobalFunction.CanHomeClickPath);
  140. if (text.ToLower() == "true")
  141. {
  142. uxHomeBtnR.Visibility = Visibility.Visible;
  143. uxHomeBtnL.Visibility = Visibility.Visible;
  144. }
  145. }
  146. }
  147. //透過Velocity.txt 取得設定的自動輪播速度
  148. private int GetAutoRunVelocity()
  149. {
  150. int result = 5;
  151. if (File.Exists(GlobalFunction.AutoRunVelocityPath))
  152. {
  153. string text = System.IO.File.ReadAllText(GlobalFunction.AutoRunVelocityPath);
  154. result = int.Parse(text);
  155. }
  156. return result;
  157. }
  158. //設定自動輪播的動畫
  159. private void SetAutoRunStoryBoard(double from, double to)
  160. {
  161. autoRunStoryboard.Children.Clear();
  162. DoubleAnimation dbOffset = new DoubleAnimation()
  163. {
  164. Duration = TimeSpan.FromSeconds(AutoRunVelocityValue),
  165. };
  166. ScrollViewerUtilities.UseMotionStop = false;
  167. Storyboard.SetTarget(dbOffset, (DependencyObject)this.FindName("uxMyScroll"));
  168. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(ScrollViewerUtilities.HorizontalOffsetProperty));
  169. autoRunStoryboard.Children.Add(dbOffset);
  170. autoRunStoryboard.FillBehavior = FillBehavior.HoldEnd;
  171. dbOffset.From = from;
  172. dbOffset.To = to;
  173. }
  174. private ImageSource GetBitMap(string imgpath)
  175. {
  176. BitmapImage bitmapImg = new BitmapImage();
  177. bitmapImg.BeginInit();
  178. bitmapImg.UriSource = new Uri(imgpath, UriKind.RelativeOrAbsolute);
  179. //忽略原始圖檔的色盤設定,使用預設值,可縮短載入圖檔的時間
  180. //如有遇到色彩不正確的問題,或者原圖有特殊的自定義色盤,請不要使用此設定
  181. bitmapImg.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
  182. //使用以下的預先載入設定,在BitmapImage創建完成之後,可立刻釋放其所占用或鎖住的資源,以免咬住檔案
  183. bitmapImg.CacheOption = BitmapCacheOption.OnLoad;
  184. //根據欲顯示的區域長或寬,來設定 DecodePixelHeight 或 DecodePixelWidth 的值
  185. bitmapImg.EndInit();
  186. bitmapImg.Freeze();
  187. return bitmapImg;
  188. }
  189. /// <summary>
  190. /// 新建出 Grid For 裝載DetailViewer
  191. /// </summary>
  192. private void CreateExtraUnitGrid()
  193. {
  194. ExtraUnitGridList.Clear();
  195. for (int count = 0; count < ChildrenCount; count++)
  196. {
  197. ExtraUnitGrid ExtraGrid = new ExtraUnitGrid(MainEventWidth, MainEventHeight, YearEventHeight, NoneUseRange);
  198. ExtraGrid.ExtraUnitGridBubbleToCyclicScrollerEvent += new ExtraUnitGrid.ExtraUnitGridBubbleToCyclicScroller(ExtraGrid_ExtraUnitGridBubbleToCyclicScrollerEvent);
  199. ExtraUnitGridList.Add(ExtraGrid);
  200. }
  201. }
  202. /// <summary>
  203. /// 初始化該 ExtraUnitGrid ~包括 狀態 位置
  204. /// </summary>
  205. private void InitializeExtraUnitGrid()
  206. {
  207. int index = 1;
  208. //替每個 Grid 標上索引值~該索引值是代表該Grid在螢幕上的位置(從1開始算起)
  209. //且如果是第一個或者是最後一個~則狀態UnUse灰色
  210. for (int count = 0; count < ExtraUnitGridList.Count; count++)
  211. {
  212. ExtraUnitGridList[count].Get_Set_MonitorIndex = index;
  213. //設定狀態
  214. if (index == 1 || index == ExtraUnitGridList.Count)
  215. {
  216. //判斷用
  217. ExtraUnitGridList[count].Get_Set_BlockControlMode = ExtraUnitGrid.ControlMode.UnUse;
  218. //回原始狀態用
  219. ExtraUnitGridList[count].SetOriControlMode(ExtraUnitGrid.ControlMode.UnUse);
  220. }
  221. else
  222. {
  223. ExtraUnitGridList[count].Get_Set_BlockControlMode = ExtraUnitGrid.ControlMode.CanExtend;
  224. ExtraUnitGridList[count].SetOriControlMode(ExtraUnitGrid.ControlMode.CanExtend);
  225. }
  226. index++;
  227. }
  228. //調整位置
  229. for (int count = 0; count < ExtraUnitGridList.Count; count++)
  230. {
  231. //先設定第一個
  232. if (count == 0)
  233. {
  234. ExtraUnitGridList[count].Margin = new Thickness(-NoneUseRange, 0, 0, uxMyScroll.Margin.Bottom - 5);
  235. ExtraUnitGridList[count].RecodeMarginLeft = ExtraUnitGridList[count].Margin.Left;
  236. continue;
  237. }
  238. ExtraUnitGridList[count].Margin = new Thickness(ExtraUnitGridList[count - 1].Margin.Left + MainEventWidth, 0, 0, uxMyScroll.Margin.Bottom - 5);
  239. ExtraUnitGridList[count].RecodeMarginLeft = ExtraUnitGridList[count].Margin.Left;
  240. }
  241. }
  242. /// <summary>
  243. /// 設定當前語系
  244. /// </summary>
  245. private void SetLanguage()
  246. {
  247. //預設
  248. System.Windows.Application.Current.Properties["Language"] = "Language1";
  249. uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[0];
  250. uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[0];
  251. //如果更改
  252. if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 1)
  253. {
  254. System.Windows.Application.Current.Properties["Language"] = "Language2";
  255. uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[1];
  256. uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[1];
  257. }
  258. else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 2)
  259. {
  260. System.Windows.Application.Current.Properties["Language"] = "Language3";
  261. uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[2];
  262. uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[2];
  263. }
  264. else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 3)
  265. {
  266. System.Windows.Application.Current.Properties["Language"] = "Language4";
  267. uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[3];
  268. uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[3];
  269. }
  270. }
  271. /// <summary>
  272. /// 設定回正被中斷時~應該回到的顯示位置
  273. /// </summary>
  274. private void SetReturnPos()
  275. {
  276. System.Windows.Application.Current.Properties["ReturnPos"] = MainEventWidth + NoneUseRange;
  277. }
  278. /// <summary>
  279. /// 判斷當前的Index是否超出"最大"容許範圍~進行調整
  280. /// </summary>
  281. /// <returns></returns>
  282. private int GetIndexFromRightSide()
  283. {
  284. int index = currentLoadIndex;
  285. if (index < LiveContainerList.Count)
  286. {
  287. index += 1;
  288. }
  289. else
  290. {
  291. index = 1;
  292. }
  293. return index;
  294. }
  295. /// <summary>
  296. /// 判斷當前的Index是否低於"最小"容許範圍~進行調整
  297. /// </summary>
  298. /// <returns></returns>
  299. private int GetIndexFromLeftSide()
  300. {
  301. int index = currentLoadIndex;
  302. if (index > 0)
  303. {
  304. index -= 1;
  305. }
  306. else
  307. {
  308. index = LiveContainerList.Count - 1;
  309. }
  310. return index;
  311. }
  312. /// <summary>
  313. /// 透過螢幕可容納的個數取得當前年份中間位置
  314. /// </summary>
  315. /// <returns></returns>
  316. private int GetCenterIndexValue()
  317. {
  318. int result = 0;
  319. switch (CurrentMonitorCount.ncm)
  320. {
  321. case MonitorFlag.Monitor1_1:
  322. case MonitorFlag.Monitor2_1:
  323. case MonitorFlag.Monitor3_1:
  324. case MonitorFlag.Monitor4_1:
  325. case MonitorFlag.Monitor5_1:
  326. case MonitorFlag.Monitor6_1:
  327. {
  328. result = ChildrenCount / 2;
  329. break;
  330. }
  331. }
  332. return result;
  333. }
  334. #region 首頁動畫
  335. /// <summary>
  336. /// 計算總事件~並將該直傳到Homepage中
  337. /// </summary>
  338. private void CalcCountToHomePage()
  339. {
  340. if (!RunHomePageAnimation)
  341. {
  342. return;
  343. }
  344. int staticvalue = GetCycleCount();
  345. int totalevent = 0;
  346. for (int index = 0; index < staticvalue; index++)
  347. {
  348. for (int count = 0; count < xmlDataList.Count; count++)
  349. {
  350. totalevent += xmlDataList[count].monthclassList.Count;
  351. }
  352. }
  353. hp.SetEventCount(totalevent);
  354. }
  355. /// <summary>
  356. /// Loading start
  357. /// </summary>
  358. private void LoadingStart()
  359. {
  360. if (RunHomePageAnimation)
  361. {
  362. this.uxCyclicGrid.Opacity = 0;
  363. }
  364. }
  365. private void AddHomePageAnimation()
  366. {
  367. if (RunHomePageAnimation)
  368. {
  369. hp = new HomePage(ResolutionValueWidth, ResolutionValueHeight);
  370. hp.SetBlockCommonSetting(MainEventWidth, YearEventHeight, NoneUseRange);
  371. hp.SetHistoryWallControl(uxCyclicGrid);
  372. hp.OnLoadProgessComplete += Hp_OnLoadProgessComplete;
  373. uxMainWindow.Children.Add(hp);
  374. }
  375. }
  376. private void Hp_OnLoadProgessComplete(object sender, EventArgs e)
  377. {
  378. OnDataLoadCompeleted?.Invoke(this,null);
  379. }
  380. #endregion
  381. #region 自動輪播相關
  382. void CheckAutoRunTimer_Tick(object sender, EventArgs e)
  383. {
  384. // 確認 Detailviewer 狀況 sdlu
  385. if (CheckExtraGridIsVideoRun())
  386. {
  387. //將上層Grid關閉
  388. CloseExtraGrid();
  389. //自動輪播開始
  390. WpfDelayDoWork.DoWork(HistoryWallAutoRun, 1000);
  391. isAutoRun = true;
  392. GlobalFunction.CheckAutoRunTimer.Stop();
  393. }
  394. }
  395. private bool CheckExtraGridIsVideoRun()
  396. {
  397. bool isCheckVideo = true;
  398. int count = ExtraUnitGridList.Count;
  399. for (int i = 0; i < count; i++)
  400. {
  401. Grid gd = ExtraUnitGridList[i].BorderUp.Child as Grid;
  402. if (gd != null && gd.Children.Count > 0)
  403. {
  404. DetailViewer dv = gd.Children[0] as DetailViewer;
  405. if (dv.isPlayVideo)
  406. {
  407. isCheckVideo = false;
  408. break;
  409. }
  410. }
  411. }
  412. return isCheckVideo;
  413. }
  414. /// <summary>
  415. /// 關閉上層Grid
  416. /// </summary>
  417. private void CloseExtraGrid()
  418. {
  419. int count = ExtraUnitGridList.Count;
  420. for (int i = 0; i < count; i++)
  421. {
  422. ExtraUnitGridList[i].BorderDown_TouchUp(null, null);
  423. }
  424. }
  425. /// <summary>
  426. /// 自動移動啟動
  427. /// </summary>
  428. private void HistoryWallAutoRun()
  429. {
  430. if (ControlMode == HistoryControlMode.Manual)
  431. {
  432. ControlMode = HistoryControlMode.AutoRun;
  433. SendControlModeToLiveContainer(ControlMode);
  434. SetAutoRunStoryBoard(this.uxMyScroll.HorizontalOffset, this.uxMyScroll.HorizontalOffset + MainEventWidth);
  435. autoRunStoryboard.Begin();
  436. }
  437. }
  438. /// <summary>
  439. /// 關閉自動移動
  440. /// </summary>
  441. private void StopAutoRunTheWall()
  442. {
  443. if (ControlMode == HistoryControlMode.AutoRun)
  444. {
  445. ScrollViewerUtilities.UseMotionStop = true;
  446. autoRunStoryboard.Stop();
  447. ControlMode = HistoryControlMode.Manual;
  448. SendControlModeToLiveContainer(ControlMode);
  449. }
  450. }
  451. #endregion
  452. public void Dispose()
  453. {
  454. GlobalFunction.CheckAutoRunTimer.Tick -= CheckAutoRunTimer_Tick;
  455. }
  456. }
  457. }