Example #1
0
        /// <summary>
        /// このシナリオのlistViewItemを作成します。
        /// </summary>
        /// <param name="listView">対象のlistView</param>
        public ListViewItem CreateListViewItem(ListView listView)
        {
            Item = new ListViewItem(Data.Title);
            //シナリオ情報の設定
            Item.Name = Data.Title ?? "";

            //SubItemIndexに合わせてSubItemを代入
            string[] subItems = new string[Enum.GetNames(typeof(SubItemIndex)).Length];
            subItems[(int)SubItemIndex.TITLE]         = Data.Title ?? "";
            subItems[(int)SubItemIndex.ROUTE_TITLE]   = Data.RouteTitle ?? "";
            subItems[(int)SubItemIndex.VEHICLE_TITLE] = Data.VehicleTitle ?? "";
            subItems[(int)SubItemIndex.AUTHOR]        = Data.Author ?? "";
            subItems[(int)SubItemIndex.FILE_NAME]     = FileName;

            Item.SubItems.AddRange(subItems);
            Item.SubItems.RemoveAt(0); //なぜかSubItemsが一つ多いのでindex0を削除する。

            //画像の追加
            string dirName = Path.GetDirectoryName(FilePath) + @"\";

            if (Data.Image != null && System.IO.File.Exists(dirName + Data.Image))
            {
                //画像登録
                try
                {
                    if (!listView.LargeImageList.Images.ContainsKey(Data.Image))
                    {
                        listView.LargeImageList.Images.Add(Data.Image, ThumbnailModule.CreateThumbnail(dirName + Data.Image, listView.LargeImageList.ImageSize));
                    }
                    Image img = Image.FromFile(dirName + Data.Image);
                    Item.ImageIndex = listView.LargeImageList.Images.IndexOfKey(Data.Image);
                }
                catch (Exception) { Console.Error.WriteLine("Scenario: Image not active format."); }
            }

            return(Item);
        }
        /// <summary>
        /// リストビューの選択されているアイテムが変更された際に、シナリオ情報を更新します。
        /// </summary>
        /// <param name="sender">イベントのソース</param>
        /// <param name="e">イベントのデータ</param>
        void ScenarioSelectListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <Scenario> scenarios = scenarioManager.GetNewestSnapShot();
            List <Scenario> selected  = GetSelectedScenario();

            statusText.Text = "シナリオを" + selected.Count + "個選択中。";

            ClearScenarioInfo();

            if (selected.Count == 0)
            {
                return;
            }
            else
            {
                //ベースとなるアイテムの取得
                string title        = selected[0].Data.Title;
                string routeTitle   = selected[0].Data.RouteTitle;
                string vehicleTitle = selected[0].Data.VehicleTitle;
                string author       = selected[0].Data.Author;
                string comment      = selected[0].Data.Comment;
                string image        = selected[0].Data.Image;
                string fileName     = selected[0].FileName;

                //ベースと異なる項目を「複数...」に変更
                if (selected.Count(x => x.Data.Title.Equals(title)) < selected.Count)
                {
                    title = "複数タイトル...";
                }
                if (selected.Count(x => x.Data.RouteTitle.Equals(routeTitle)) < selected.Count)
                {
                    routeTitle = "複数路線名...";
                }
                if (selected.Count(x => x.Data.VehicleTitle.Equals(vehicleTitle)) < selected.Count)
                {
                    vehicleTitle = "複数車両名...";
                }
                if (selected.Count(x => x.Data.Author.Equals(author)) < selected.Count)
                {
                    author = "複数作者名...";
                }
                if (selected.Count(x => x.Data.Comment.Equals(comment)) < selected.Count)
                {
                    comment = "複数コメント...";
                }
                if (selected.Count(x => x.Data.Image.Equals(image)) < selected.Count)
                {
                    image = "";
                }

                //サムネイル情報の描画
                if (!image.Equals("") && File.Exists(dirPath + @"\" + image))
                {
                    thumbnailImage.Source     = ThumbnailModule.CreateThumbnailImageSource(dirPath + @"\" + image, ThumbnailSize);
                    thumbnailImage.Visibility = Visibility.Visible;
                }

                //情報を表示
                if (!title.Equals(""))
                {
                    scenarioTitleText.Text       = title;
                    scenarioTitleText.Visibility = Visibility.Visible;
                }
                if (!routeTitle.Equals(""))
                {
                    scenarioRouteTitleText.Text = routeTitle;
                    scenarioRouteTitleText.Text = routeTitle;
                }
                if (!vehicleTitle.Equals(""))
                {
                    scenarioVehicleTitleText.Text       = vehicleTitle;
                    scenarioVehicleTitleText.Visibility = Visibility.Visible;
                }
                if (!author.Equals(""))
                {
                    scenarioAuthorText.Text       = author;
                    scenarioAuthorText.Visibility = Visibility.Visible;
                }
                if (!comment.Equals(""))
                {
                    scenarioCommentText.Text       = comment;
                    scenarioCommentText.Visibility = Visibility.Visible;
                }
                if (selected.Count == 1)
                {
                    scenarioFileNameText.Text       = selected[0].FileName;
                    scenarioFileNameText.Visibility = Visibility.Visible;
                }
            }
        }