DetailViewer.xaml.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. using KernelViewerCtrlDll;
  2. using MediaGalleryDll;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. using System.Windows.Threading;
  19. namespace HistoryDLL
  20. {
  21. /// <summary>
  22. /// DetailViewer.xaml 的互動邏輯
  23. /// </summary>
  24. public partial class DetailViewer : UserControl
  25. {
  26. public delegate void ChangeLanguageBtnTriggerDelegate(int index, int useLangIndex);
  27. public event ChangeLanguageBtnTriggerDelegate ChangeLanguageBtnTriggerEvent;
  28. public delegate void CloseBtnTriggerDelegate(int indexOfCtrl);
  29. public event CloseBtnTriggerDelegate CloseBtnTriggerEvent;
  30. private XmlData xmlDatas;
  31. private int dataIndex = 0;
  32. private int eventIndex = 0;
  33. private int mediaIndex = 0;
  34. private double itemWidth = 85;
  35. private double itemHeight = 85;
  36. private LangIndex curDisLan = LangIndex.Language1;
  37. public int IndexOfControl = -1;
  38. public bool isPlayVideo = false;
  39. /// <summary>
  40. /// 建構
  41. /// </summary>
  42. /// <param name="xmlData">資料</param>
  43. /// <param name="dataIndex">參數一資料的索引值,改變語系時通知上層所傳的 Index</param>
  44. /// <param name="eventIndex">該資料的第幾個事件</param>
  45. /// <param name="picIndex">該事件的第幾張媒體檔</param>
  46. public DetailViewer(XmlData xmlData, int dataIndex, int eventIndex, int picIndex)
  47. {
  48. InitializeComponent();
  49. if (GlobalFunction.isSolutionUsing4K)
  50. {
  51. this.Width *= 2;
  52. this.Height *= 2;
  53. uxFirstLayer1.Height = new GridLength(20 * 2);
  54. uxFirstLayer2.Height = new GridLength(30 * 2);
  55. uxFirstLayer3.Height = new GridLength(85 * 2);
  56. uxFirstLayer4.Height = new GridLength(60 * 2);
  57. uxTopLayer1.Width = new GridLength(20 * 2);
  58. uxTopLayer2.Width = new GridLength(20 * 2);
  59. uxTopLayer3.Width = new GridLength(275 * 2);
  60. uxTopLayer4.Width = new GridLength(20 * 2);
  61. uxImgLayer.Height = new GridLength(310 * 2);
  62. uxGalleryGd.Margin = new Thickness(uxGalleryGd.Margin.Left * 2, 0, uxGalleryGd.Margin.Right * 2, 0);
  63. uxLan0.Width *= 2;
  64. uxLan1.Width *= 2;
  65. uxLan2.Width *= 2;
  66. uxLan3.Width *= 2;
  67. uxLan0.Height *= 2;
  68. uxLan1.Height *= 2;
  69. uxLan2.Height *= 2;
  70. uxLan3.Height *= 2;
  71. uxLan0.FontSize *= 1.5;
  72. uxLan1.FontSize *= 1.5;
  73. uxLan2.FontSize *= 1.5;
  74. uxLan3.FontSize *= 1.5;
  75. uxExitBtn.Width *= 2;
  76. uxExitBtn.Height *= 2;
  77. uxExitBtn.FontSize *= 1.5;
  78. uxLan0.Margin = uxLan1.Margin = uxLan2.Margin = uxLan3.Margin = uxExitBtn.Margin = new Thickness(0, 0, 10 * 2, 0);
  79. uxTitleText.Width *= 2;
  80. uxTitleText.Height *= 2;
  81. uxStrMainScroll.Width *= 2;
  82. uxStrMainScroll.Height *= 2;
  83. uxDateText.Width *= 2;
  84. uxDateText.Height *= 2;
  85. uxContentText.Width *= 2;
  86. uxContentText.Height *= 2;
  87. uxTitleText.FontSize *= 1.5;
  88. uxDateText.FontSize *= 1.5;
  89. uxContentText.FontSize *= 1.5;
  90. }
  91. this.xmlDatas = xmlData;
  92. this.dataIndex = dataIndex;
  93. this.eventIndex = eventIndex;
  94. this.mediaIndex = picIndex;
  95. //this.curDisLan = (LangIndex)ConfigSettingClass.MainBackCollect.DefaultLangIndex;
  96. if (this.mediaIndex < 0)
  97. this.mediaIndex = 0;
  98. this.Loaded += DetailViewer_Loaded;
  99. }
  100. private List<string> GetEventFirstFileMap()
  101. {
  102. List<string> result = new List<string>();
  103. for (int i = 0; i < xmlDatas.monthclassList.Count; i++)
  104. {
  105. if (xmlDatas.monthclassList[i].imagepath != "" && Directory.Exists(GlobalFunction.EventFileImgPath + xmlDatas.monthclassList[i].imagepath))
  106. {
  107. string[] files = Directory.GetFiles(GlobalFunction.EventFileImgPath + xmlDatas.monthclassList[i].imagepath);
  108. foreach (string file in files)
  109. {
  110. if (GlobalFunction.imgDimList.Contains(System.IO.Path.GetExtension(file).ToLower()) ||
  111. GlobalFunction.mediaDimList.Contains(System.IO.Path.GetExtension(file).ToLower()))
  112. {
  113. result.Add(file);
  114. break;
  115. }
  116. }
  117. }
  118. else
  119. {
  120. // 沒有圖片~ 則載入 Logo
  121. result.Add(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo);
  122. }
  123. }
  124. return result;
  125. }
  126. private void InitialLayoutColor()
  127. {
  128. // 背景
  129. uxDetailviewerGd.Background = new SolidColorBrush(ConfigSettingClass.EventContentCollect.BackgroundColor);
  130. // 文字顏色
  131. uxTitleText.Foreground = new SolidColorBrush(ConfigSettingClass.EventContentCollect.TextColor);
  132. uxDateText.Foreground = new SolidColorBrush(ConfigSettingClass.EventContentCollect.TextColor);
  133. uxContentText.Foreground = new SolidColorBrush(ConfigSettingClass.EventContentCollect.TextColor);
  134. // 切換語系的 Radiobtn
  135. for (int i = 0; i < ConfigSettingClass.MainBackCollect.LangText.Count(); i++)
  136. {
  137. RadioButton radiobtn = FindName("uxLan" + i) as RadioButton;
  138. radiobtn.Content = ConfigSettingClass.MainBackCollect.LangText[i];
  139. radiobtn.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColorUnselect);
  140. radiobtn.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColorUnselect);
  141. if (ConfigSettingClass.MainBackCollect.LangText[i] == "")
  142. {
  143. radiobtn.Visibility = Visibility.Collapsed;
  144. }
  145. }
  146. // 關閉按鈕
  147. uxExitBtn.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColor);
  148. uxExitBtn.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColor);
  149. }
  150. private void DetailViewer_Loaded(object sender, RoutedEventArgs e)
  151. {
  152. InitialLayoutColor();
  153. // 載入小圖列表 (取得每個事件的第一張圖)
  154. List<string> eventFileList = GetEventFirstFileMap();
  155. MediaGalleryCtrl mediaList = new MediaGalleryCtrl(eventFileList, eventIndex, ConfigSettingClass.EventContentCollect.ThicknessColor);
  156. mediaList.Width = 770;
  157. mediaList.Height = 85;
  158. mediaList.CallbackMediaFileNameEvent += MediaList_CallbackMediaFileNameEvent;
  159. mediaList.ItemWidth = itemWidth;
  160. mediaList.ItemHeight = itemHeight;
  161. if (GlobalFunction.isSolutionUsing4K)
  162. {
  163. mediaList.Width *= 2;
  164. mediaList.Height *= 2;
  165. mediaList.ItemWidth *= 2;
  166. mediaList.ItemHeight *= 2;
  167. }
  168. uxGalleryGd.Children.Add(mediaList);
  169. switch (ConfigSettingClass.MainBackCollect.DefaultLangIndex)
  170. {
  171. case 0:
  172. uxLan0.IsChecked = true;
  173. break;
  174. case 1:
  175. uxLan1.IsChecked = true;
  176. break;
  177. case 2:
  178. uxLan2.IsChecked = true;
  179. break;
  180. case 3:
  181. uxLan3.IsChecked = true;
  182. break;
  183. }
  184. // 載入圖片
  185. LoadEventInforMedia();
  186. }
  187. // 由 MediaGalleryDll 傳出來的事件,重新載入圖片
  188. private void MediaList_CallbackMediaFileNameEvent(int selectedIndex)
  189. {
  190. if (eventIndex != selectedIndex)
  191. {
  192. eventIndex = selectedIndex;
  193. // 重載入文字
  194. LoadEventInforStr();
  195. // 重新載入圖片
  196. LoadEventInforMedia();
  197. }
  198. }
  199. private void LoadEventInforMedia()
  200. {
  201. uxMainMediaShowGd.Children.Clear();
  202. Dviewer dviewer = new Dviewer(GlobalFunction.EventFileImgPath + xmlDatas.monthclassList[eventIndex].imagepath, mediaIndex, GlobalFunction.isSolutionUsing4K, GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo);
  203. mediaIndex = 0;
  204. dviewer.CallBackFileCountEvent += Dviewer_CallBackFileCountEvent;
  205. dviewer.CallBackDisplayIndexEvent += Dviewer_CallBackDisplayIndexEvent;
  206. dviewer.CurIsPlaingVideoEvent += Dviewer_CurIsPlaingVideoEvent;
  207. uxMainMediaShowGd.Children.Add(dviewer);
  208. }
  209. private void Dviewer_CurIsPlaingVideoEvent(bool isPlayVideo)
  210. {
  211. this.isPlayVideo = isPlayVideo;
  212. }
  213. private void Dviewer_CallBackDisplayIndexEvent(int Index)
  214. {
  215. for (int i = 0; i < uxImgTagList.Children.Count; i++)
  216. {
  217. (uxImgTagList.Children[i] as DetailViewerDot).uxLabel.IsEnabled = false;
  218. }
  219. if (Index < uxImgTagList.Children.Count)
  220. {
  221. (uxImgTagList.Children[Index] as DetailViewerDot).uxLabel.IsEnabled = true;
  222. }
  223. }
  224. private void Dviewer_CallBackFileCountEvent(int realCount)
  225. {
  226. uxImgTagList.Children.Clear();
  227. for (int i = 0; i < realCount; i++)
  228. {
  229. DetailViewerDot dot = new DetailViewerDot(ConfigSettingClass.EventContentCollect.ThicknessColor);
  230. if (i >= 20)
  231. break;
  232. uxImgTagList.Children.Add(dot);
  233. }
  234. }
  235. private void LoadEventInforStr()
  236. {
  237. if (eventIndex < ConfigSettingClass.MainBackCollect.LangFlowDir.Length)
  238. {
  239. uxTitleText.FlowDirection = ConfigSettingClass.MainBackCollect.LangFlowDir[eventIndex];
  240. uxDateText.FlowDirection = ConfigSettingClass.MainBackCollect.LangFlowDir[eventIndex];
  241. uxContentText.FlowDirection = ConfigSettingClass.MainBackCollect.LangFlowDir[eventIndex];
  242. }
  243. switch (curDisLan)
  244. {
  245. case LangIndex.Language1:
  246. uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan1;
  247. uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language1;
  248. break;
  249. case LangIndex.Language2:
  250. uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan2;
  251. uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language2;
  252. break;
  253. case LangIndex.Language3:
  254. uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan3;
  255. uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language3;
  256. break;
  257. case LangIndex.Language4:
  258. uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan4;
  259. uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language4;
  260. break;
  261. }
  262. if (xmlDatas.monthclassList[eventIndex].month == null || xmlDatas.monthclassList[eventIndex].month == "")
  263. uxDateText.Visibility = Visibility.Collapsed;
  264. else
  265. uxDateText.Text = xmlDatas.monthclassList[eventIndex].month;
  266. }
  267. private void uxBoundGrid_ManipulationBoundaryFeedback(object sender, System.Windows.Input.ManipulationBoundaryFeedbackEventArgs e)
  268. {
  269. e.Handled = true;
  270. }
  271. private void uxCloseBtn_Click(object sender, RoutedEventArgs e)
  272. {
  273. if (CloseBtnTriggerEvent != null)
  274. this.Dispatcher.BeginInvoke(CloseBtnTriggerEvent, DispatcherPriority.Background, IndexOfControl);
  275. }
  276. private void uxLan_Checked(object sender, RoutedEventArgs e)
  277. {
  278. RadioButton radiobtnDisable = FindName("uxLan" + (int)this.curDisLan) as RadioButton;
  279. radiobtnDisable.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColorUnselect);
  280. radiobtnDisable.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColorUnselect);
  281. this.curDisLan = (LangIndex)int.Parse((sender as RadioButton).Tag.ToString());
  282. RadioButton radiobtnEnable = FindName("uxLan" + (int)this.curDisLan) as RadioButton;
  283. radiobtnEnable.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColor);
  284. radiobtnEnable.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColor);
  285. // 重載入文字
  286. LoadEventInforStr();
  287. }
  288. }
  289. public enum LangIndex
  290. {
  291. Language1 = 0,
  292. Language2 = 1,
  293. Language3 = 2,
  294. Language4 = 3
  295. }
  296. }