123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- using KernelViewerCtrlDll;
- using MediaGalleryDll;
- 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.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
- namespace HistoryDLL
- {
- /// <summary>
- /// DetailViewer.xaml 的互動邏輯
- /// </summary>
- public partial class DetailViewer : UserControl
- {
- public delegate void ChangeLanguageBtnTriggerDelegate(int index, int useLangIndex);
- public event ChangeLanguageBtnTriggerDelegate ChangeLanguageBtnTriggerEvent;
- public delegate void CloseBtnTriggerDelegate(int indexOfCtrl);
- public event CloseBtnTriggerDelegate CloseBtnTriggerEvent;
- private XmlData xmlDatas;
- private int dataIndex = 0;
- private int eventIndex = 0;
- private int mediaIndex = 0;
- private double itemWidth = 85;
- private double itemHeight = 85;
- private LangIndex curDisLan = LangIndex.Language1;
- public int IndexOfControl = -1;
- public bool isPlayVideo = false;
- /// <summary>
- /// 建構
- /// </summary>
- /// <param name="xmlData">資料</param>
- /// <param name="dataIndex">參數一資料的索引值,改變語系時通知上層所傳的 Index</param>
- /// <param name="eventIndex">該資料的第幾個事件</param>
- /// <param name="picIndex">該事件的第幾張媒體檔</param>
- public DetailViewer(XmlData xmlData, int dataIndex, int eventIndex, int picIndex)
- {
- InitializeComponent();
- if (GlobalFunction.isSolutionUsing4K)
- {
- this.Width *= 2;
- this.Height *= 2;
- uxFirstLayer1.Height = new GridLength(20 * 2);
- uxFirstLayer2.Height = new GridLength(30 * 2);
- uxFirstLayer3.Height = new GridLength(85 * 2);
- uxFirstLayer4.Height = new GridLength(60 * 2);
- uxTopLayer1.Width = new GridLength(20 * 2);
- uxTopLayer2.Width = new GridLength(20 * 2);
- uxTopLayer3.Width = new GridLength(275 * 2);
- uxTopLayer4.Width = new GridLength(20 * 2);
- uxImgLayer.Height = new GridLength(310 * 2);
- uxGalleryGd.Margin = new Thickness(uxGalleryGd.Margin.Left * 2, 0, uxGalleryGd.Margin.Right * 2, 0);
- uxLan0.Width *= 2;
- uxLan1.Width *= 2;
- uxLan2.Width *= 2;
- uxLan3.Width *= 2;
- uxLan0.Height *= 2;
- uxLan1.Height *= 2;
- uxLan2.Height *= 2;
- uxLan3.Height *= 2;
- uxLan0.FontSize *= 1.5;
- uxLan1.FontSize *= 1.5;
- uxLan2.FontSize *= 1.5;
- uxLan3.FontSize *= 1.5;
- uxExitBtn.Width *= 2;
- uxExitBtn.Height *= 2;
- uxExitBtn.FontSize *= 1.5;
- uxLan0.Margin = uxLan1.Margin = uxLan2.Margin = uxLan3.Margin = uxExitBtn.Margin = new Thickness(0, 0, 10 * 2, 0);
- uxTitleText.Width *= 2;
- uxTitleText.Height *= 2;
- uxStrMainScroll.Width *= 2;
- uxStrMainScroll.Height *= 2;
- uxDateText.Width *= 2;
- uxDateText.Height *= 2;
- uxContentText.Width *= 2;
- uxContentText.Height *= 2;
- uxTitleText.FontSize *= 1.5;
- uxDateText.FontSize *= 1.5;
- uxContentText.FontSize *= 1.5;
- }
- this.xmlDatas = xmlData;
- this.dataIndex = dataIndex;
- this.eventIndex = eventIndex;
- this.mediaIndex = picIndex;
- //this.curDisLan = (LangIndex)ConfigSettingClass.MainBackCollect.DefaultLangIndex;
- if (this.mediaIndex < 0)
- this.mediaIndex = 0;
- this.Loaded += DetailViewer_Loaded;
- }
- private List<string> GetEventFirstFileMap()
- {
- List<string> result = new List<string>();
- for (int i = 0; i < xmlDatas.monthclassList.Count; i++)
- {
- if (xmlDatas.monthclassList[i].imagepath != "" && Directory.Exists(GlobalFunction.EventFileImgPath + xmlDatas.monthclassList[i].imagepath))
- {
- string[] files = Directory.GetFiles(GlobalFunction.EventFileImgPath + xmlDatas.monthclassList[i].imagepath);
- foreach (string file in files)
- {
- if (GlobalFunction.imgDimList.Contains(System.IO.Path.GetExtension(file).ToLower()) ||
- GlobalFunction.mediaDimList.Contains(System.IO.Path.GetExtension(file).ToLower()))
- {
- result.Add(file);
- break;
- }
- }
- }
- else
- {
- // 沒有圖片~ 則載入 Logo
- result.Add(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo);
- }
- }
- return result;
- }
- private void InitialLayoutColor()
- {
- // 背景
- uxDetailviewerGd.Background = new SolidColorBrush(ConfigSettingClass.EventContentCollect.BackgroundColor);
- // 文字顏色
- uxTitleText.Foreground = new SolidColorBrush(ConfigSettingClass.EventContentCollect.TextColor);
- uxDateText.Foreground = new SolidColorBrush(ConfigSettingClass.EventContentCollect.TextColor);
- uxContentText.Foreground = new SolidColorBrush(ConfigSettingClass.EventContentCollect.TextColor);
- // 切換語系的 Radiobtn
- for (int i = 0; i < ConfigSettingClass.MainBackCollect.LangText.Count(); i++)
- {
- RadioButton radiobtn = FindName("uxLan" + i) as RadioButton;
- radiobtn.Content = ConfigSettingClass.MainBackCollect.LangText[i];
- radiobtn.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColorUnselect);
- radiobtn.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColorUnselect);
- if (ConfigSettingClass.MainBackCollect.LangText[i] == "")
- {
- radiobtn.Visibility = Visibility.Collapsed;
- }
- }
- // 關閉按鈕
- uxExitBtn.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColor);
- uxExitBtn.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColor);
- }
- private void DetailViewer_Loaded(object sender, RoutedEventArgs e)
- {
- InitialLayoutColor();
- // 載入小圖列表 (取得每個事件的第一張圖)
- List<string> eventFileList = GetEventFirstFileMap();
- MediaGalleryCtrl mediaList = new MediaGalleryCtrl(eventFileList, eventIndex, ConfigSettingClass.EventContentCollect.ThicknessColor);
- mediaList.Width = 770;
- mediaList.Height = 85;
- mediaList.CallbackMediaFileNameEvent += MediaList_CallbackMediaFileNameEvent;
- mediaList.ItemWidth = itemWidth;
- mediaList.ItemHeight = itemHeight;
- if (GlobalFunction.isSolutionUsing4K)
- {
- mediaList.Width *= 2;
- mediaList.Height *= 2;
- mediaList.ItemWidth *= 2;
- mediaList.ItemHeight *= 2;
- }
- uxGalleryGd.Children.Add(mediaList);
- switch (ConfigSettingClass.MainBackCollect.DefaultLangIndex)
- {
- case 0:
- uxLan0.IsChecked = true;
- break;
- case 1:
- uxLan1.IsChecked = true;
- break;
- case 2:
- uxLan2.IsChecked = true;
- break;
- case 3:
- uxLan3.IsChecked = true;
- break;
- }
- // 載入圖片
- LoadEventInforMedia();
- }
- // 由 MediaGalleryDll 傳出來的事件,重新載入圖片
- private void MediaList_CallbackMediaFileNameEvent(int selectedIndex)
- {
- if (eventIndex != selectedIndex)
- {
- eventIndex = selectedIndex;
- // 重載入文字
- LoadEventInforStr();
- // 重新載入圖片
- LoadEventInforMedia();
- }
- }
- private void LoadEventInforMedia()
- {
- uxMainMediaShowGd.Children.Clear();
- Dviewer dviewer = new Dviewer(GlobalFunction.EventFileImgPath + xmlDatas.monthclassList[eventIndex].imagepath, mediaIndex, GlobalFunction.isSolutionUsing4K, GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo);
- mediaIndex = 0;
- dviewer.CallBackFileCountEvent += Dviewer_CallBackFileCountEvent;
- dviewer.CallBackDisplayIndexEvent += Dviewer_CallBackDisplayIndexEvent;
- dviewer.CurIsPlaingVideoEvent += Dviewer_CurIsPlaingVideoEvent;
- uxMainMediaShowGd.Children.Add(dviewer);
- }
- private void Dviewer_CurIsPlaingVideoEvent(bool isPlayVideo)
- {
- this.isPlayVideo = isPlayVideo;
- }
- private void Dviewer_CallBackDisplayIndexEvent(int Index)
- {
- for (int i = 0; i < uxImgTagList.Children.Count; i++)
- {
- (uxImgTagList.Children[i] as DetailViewerDot).uxLabel.IsEnabled = false;
- }
- if (Index < uxImgTagList.Children.Count)
- {
- (uxImgTagList.Children[Index] as DetailViewerDot).uxLabel.IsEnabled = true;
- }
- }
- private void Dviewer_CallBackFileCountEvent(int realCount)
- {
- uxImgTagList.Children.Clear();
- for (int i = 0; i < realCount; i++)
- {
- DetailViewerDot dot = new DetailViewerDot(ConfigSettingClass.EventContentCollect.ThicknessColor);
- if (i >= 20)
- break;
- uxImgTagList.Children.Add(dot);
- }
- }
- private void LoadEventInforStr()
- {
- if (eventIndex < ConfigSettingClass.MainBackCollect.LangFlowDir.Length)
- {
- uxTitleText.FlowDirection = ConfigSettingClass.MainBackCollect.LangFlowDir[eventIndex];
- uxDateText.FlowDirection = ConfigSettingClass.MainBackCollect.LangFlowDir[eventIndex];
- uxContentText.FlowDirection = ConfigSettingClass.MainBackCollect.LangFlowDir[eventIndex];
- }
- switch (curDisLan)
- {
- case LangIndex.Language1:
- uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan1;
- uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language1;
- break;
- case LangIndex.Language2:
- uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan2;
- uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language2;
- break;
- case LangIndex.Language3:
- uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan3;
- uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language3;
- break;
- case LangIndex.Language4:
- uxTitleText.Text = xmlDatas.monthclassList[eventIndex].titleLan4;
- uxContentText.Text = xmlDatas.monthclassList[eventIndex].Language4;
- break;
- }
- if (xmlDatas.monthclassList[eventIndex].month == null || xmlDatas.monthclassList[eventIndex].month == "")
- uxDateText.Visibility = Visibility.Collapsed;
- else
- uxDateText.Text = xmlDatas.monthclassList[eventIndex].month;
- }
- private void uxBoundGrid_ManipulationBoundaryFeedback(object sender, System.Windows.Input.ManipulationBoundaryFeedbackEventArgs e)
- {
- e.Handled = true;
- }
- private void uxCloseBtn_Click(object sender, RoutedEventArgs e)
- {
- if (CloseBtnTriggerEvent != null)
- this.Dispatcher.BeginInvoke(CloseBtnTriggerEvent, DispatcherPriority.Background, IndexOfControl);
- }
- private void uxLan_Checked(object sender, RoutedEventArgs e)
- {
- RadioButton radiobtnDisable = FindName("uxLan" + (int)this.curDisLan) as RadioButton;
- radiobtnDisable.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColorUnselect);
- radiobtnDisable.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColorUnselect);
- this.curDisLan = (LangIndex)int.Parse((sender as RadioButton).Tag.ToString());
- RadioButton radiobtnEnable = FindName("uxLan" + (int)this.curDisLan) as RadioButton;
- radiobtnEnable.Background = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.BackgroundColor);
- radiobtnEnable.Foreground = new SolidColorBrush(ConfigSettingClass.BtnSelectCollect.TextColor);
- // 重載入文字
- LoadEventInforStr();
- }
- }
- public enum LangIndex
- {
- Language1 = 0,
- Language2 = 1,
- Language3 = 2,
- Language4 = 3
- }
- }
|