/// <summary> /// 研究機関リストビューの研究特性アイコン描画処理 /// </summary> /// <param name="e"></param> /// <param name="research">研究速度データ</param> private void DrawTeamSpecialityIcon(DrawListViewSubItemEventArgs e, Research research) { if (research == null) { return; } Rectangle rect = new Rectangle(e.Bounds.X + 4, e.Bounds.Y + 1, DeviceCaps.GetScaledWidth(16), DeviceCaps.GetScaledHeight(16)); for (int i = 0; i < Team.SpecialityLength; i++) { // 研究特性なしならば何もしない if (research.Team.Specialities[i] == TechSpeciality.None) { continue; } // 研究特性アイコンを描画する if ((int)research.Team.Specialities[i] - 1 < Techs.SpecialityImages.Images.Count) { e.Graphics.DrawImage( Techs.SpecialityImages.Images[ Array.IndexOf(Techs.Specialities, research.Team.Specialities[i]) - 1], rect); } // 研究特性オーバーレイアイコンを描画する if (research.Tech.Components.Any(component => component.Speciality == research.Team.Specialities[i])) { e.Graphics.DrawImage(_techOverlayIcon, rect); } rect.X += DeviceCaps.GetScaledWidth(16) + 3; } }
/// <summary> /// 技術ツリーに発明イベントを追加する /// </summary> /// <param name="item">追加対象の項目</param> /// <param name="position">追加対象の位置</param> private void AddEventItem(TechEvent item, TechPosition position) { Label label = new Label { Location = new Point(DeviceCaps.GetScaledWidth(position.X), DeviceCaps.GetScaledHeight(position.Y)), BackColor = Color.Transparent, Tag = new TechLabelInfo { Item = item, Position = position }, Size = new Size(_eventLabelBitmap.Width, _eventLabelBitmap.Height), Region = _eventLabelRegion }; // ラベル画像を設定する if (ApplyItemStatus && (QueryItemStatus != null)) { QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item); QueryItemStatus(this, e); label.Image = e.Done ? _doneEventLabelBitmap : _eventLabelBitmap; } else { label.Image = _doneEventLabelBitmap; } label.Click += OnItemLabelClick; label.MouseClick += OnItemLabelMouseClick; label.MouseDown += OnItemLabelMouseDown; label.MouseUp += OnItemLabelMouseUp; label.MouseMove += OnItemLabelMouseMove; label.GiveFeedback += OnItemLabelGiveFeedback; _pictureBox.Controls.Add(label); }
/// <summary> /// フォームの初期化 /// </summary> private void InitForm() { // 技術リストビュー techNameColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TechListColumnWidth[0]; techIdColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TechListColumnWidth[1]; techYearColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TechListColumnWidth[2]; techComponentsColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TechListColumnWidth[3]; // 国家リストボックス countryListBox.ColumnWidth = DeviceCaps.GetScaledWidth(countryListBox.ColumnWidth); countryListBox.ItemHeight = DeviceCaps.GetScaledHeight(countryListBox.ItemHeight); // 研究機関リストビュー teamRankColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TeamListColumnWidth[1]; teamDaysColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TeamListColumnWidth[2]; teamEndDateColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TeamListColumnWidth[3]; teamNameColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TeamListColumnWidth[4]; teamIdColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TeamListColumnWidth[5]; teamSkillColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TeamListColumnWidth[6]; teamSpecialityColumnHeader.Width = HoI2EditorController.Settings.ResearchViewer.TeamListColumnWidth[7]; // ウィンドウの位置 Location = HoI2EditorController.Settings.ResearchViewer.Location; Size = HoI2EditorController.Settings.ResearchViewer.Size; }
/// <summary> /// フォームの初期化 /// </summary> private void InitForm() { // 国家リストボックス countryListBox.ItemHeight = DeviceCaps.GetScaledHeight(countryListBox.ItemHeight); // ウィンドウの位置 Location = HoI2EditorController.Settings.RandomLeaderEditor.Location; Size = HoI2EditorController.Settings.RandomLeaderEditor.Size; }
/// <summary> /// フォームの初期化 /// </summary> private void InitForm() { // 国家リストボックス countryListBox.ItemHeight = DeviceCaps.GetScaledHeight(countryListBox.ItemHeight); // ユニット種類リストボックス typeListBox.ItemHeight = DeviceCaps.GetScaledHeight(typeListBox.ItemHeight); // ウィンドウの位置 Location = HoI2EditorController.Settings.UnitNameEditor.Location; Size = HoI2EditorController.Settings.UnitNameEditor.Size; }
/// <summary> /// フォームの初期化 /// </summary> private void InitForm() { // 兵科リストボックス branchListBox.ItemHeight = DeviceCaps.GetScaledHeight(branchListBox.ItemHeight); // 国家リストボックス countryListBox.ItemHeight = DeviceCaps.GetScaledHeight(countryListBox.ItemHeight); // ウィンドウの位置 Location = HoI2EditorController.Settings.CorpsNameEditor.Location; Size = HoI2EditorController.Settings.CorpsNameEditor.Size; }
/// <summary> /// フォームの初期化 /// </summary> private void InitForm() { // ウィンドウの位置 Location = HoI2EditorController.Settings.MiscEditor.Location; //Size = HoI2Editor.Settings.MiscEditor.Size; // 画面解像度が十分に広い場合はタブページが広く表示できるようにする int longHeight = DeviceCaps.GetScaledHeight(720); if (Screen.GetWorkingArea(this).Height >= longHeight) { Height = longHeight; } }
/// <summary> /// 技術ツリーの項目を更新する /// </summary> /// <param name="item">更新対象の項目</param> /// <param name="position">更新対象の座標</param> public void UpdateItem(ITechItem item, TechPosition position) { Control.ControlCollection labels = _pictureBox.Controls; foreach (Label label in labels) { TechLabelInfo info = label.Tag as TechLabelInfo; if (info == null) { continue; } if (info.Item != item) { continue; } // ラベルの位置を更新する if (info.Position == position) { label.Location = new Point(DeviceCaps.GetScaledWidth(position.X), DeviceCaps.GetScaledHeight(position.Y)); } // 項目ラベルの表示に項目の状態を反映しないならば座標変更のみ if (!ApplyItemStatus || (QueryItemStatus == null)) { continue; } if (item is TechItem) { // ラベル画像を設定する QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item); QueryItemStatus(this, e); label.Image = e.Done ? (e.Blueprint ? _blueprintDoneTechLabelBitmap : _doneTechLabelBitmap) : (e.Blueprint ? _blueprintTechLabelBitmap : _techLabelBitmap); } else if (item is TechEvent) { // ラベル画像を設定する QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item); QueryItemStatus(this, e); label.Image = e.Done ? _doneEventLabelBitmap : _eventLabelBitmap; } } }
/// <summary> /// フォーム読み込み時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnFormLoad(object sender, EventArgs e) { // 国家データを初期化する Countries.Init(); // 研究特性を初期化する Techs.InitSpecialities(); // ゲーム設定ファイルを読み込む Misc.Load(); // 文字列定義ファイルを読み込む Config.Load(); // 技術リストビューの高さを設定するためにダミーのイメージリストを作成する techListView.SmallImageList = new ImageList { ImageSize = new Size(1, DeviceCaps.GetScaledHeight(18)) }; // 研究機関リストビューの高さを設定するためにダミーのイメージリストを作成する teamListView.SmallImageList = new ImageList { ImageSize = new Size(1, DeviceCaps.GetScaledHeight(18)) }; // 研究特性オーバーレイアイコンを初期化する _techOverlayIcon = new Bitmap(Game.GetReadFileName(Game.TechIconOverlayPathName)); _techOverlayIcon.MakeTransparent(Color.Lime); // オプション項目を初期化する InitOptionItems(); // 技術定義ファイルを読み込む Techs.Load(); // 研究機関ファイルを読み込む Teams.Load(); // 国家リストボックスを初期化する InitCountryListBox(); // データ読み込み後の処理 OnFileLoaded(); }
/// <summary> /// 技術ツリー画像を更新する /// </summary> private void UpdateTechTreeImage() { Bitmap original = new Bitmap(Game.GetReadFileName(Game.PicturePathName, TechTreeFileNames[(int)Category])); original.MakeTransparent(Color.Lime); int width = DeviceCaps.GetScaledWidth(original.Width); int height = DeviceCaps.GetScaledHeight(original.Height); Bitmap bitmap = new Bitmap(width, height); Graphics g = Graphics.FromImage(bitmap); g.DrawImage(original, 0, 0, width, height); g.Dispose(); original.Dispose(); Image prev = _pictureBox.Image; _pictureBox.Image = bitmap; prev?.Dispose(); }
/// <summary> /// 技術リストビューの研究特性項目描画処理 /// </summary> /// <param name="e"></param> /// <param name="tech">技術項目</param> private void DrawTechSpecialityItems(DrawListViewSubItemEventArgs e, TechItem tech) { if (tech == null) { e.DrawDefault = true; return; } Rectangle gr = new Rectangle(e.Bounds.X + 4, e.Bounds.Y + 1, DeviceCaps.GetScaledWidth(16), DeviceCaps.GetScaledHeight(16)); Rectangle tr = new Rectangle(e.Bounds.X + DeviceCaps.GetScaledWidth(16) + 3, e.Bounds.Y + 3, e.Bounds.Width - DeviceCaps.GetScaledWidth(16) - 3, e.Bounds.Height); Brush brush = new SolidBrush( (techListView.SelectedIndices.Count > 0) && (e.ItemIndex == techListView.SelectedIndices[0]) ? (techListView.Focused ? SystemColors.HighlightText : SystemColors.ControlText) : SystemColors.WindowText); foreach (TechComponent component in tech.Components) { // 研究特性アイコンを描画する if ((component.Speciality != TechSpeciality.None) && ((int)component.Speciality - 1 < Techs.SpecialityImages.Images.Count)) { e.Graphics.DrawImage( Techs.SpecialityImages.Images[Array.IndexOf(Techs.Specialities, component.Speciality) - 1], gr); } // 研究難易度を描画する e.Graphics.DrawString(IntHelper.ToString(component.Difficulty), techListView.Font, brush, tr); // 次の項目の開始位置を計算する int offset = DeviceCaps.GetScaledWidth(32); gr.X += offset; tr.X += offset; } brush.Dispose(); }
/// <summary> /// 技術ツリーに技術ラベルを追加する /// </summary> /// <param name="item">追加対象の項目</param> /// <param name="position">追加対象の位置</param> private void AddLabelItem(TechLabel item, TechPosition position) { Label label = new Label { Location = new Point(DeviceCaps.GetScaledWidth(position.X), DeviceCaps.GetScaledHeight(position.Y)), BackColor = Color.Transparent, Tag = new TechLabelInfo { Item = item, Position = position } }; label.Size = Graphics.FromHwnd(label.Handle).MeasureString(item.ToString(), label.Font).ToSize(); label.Click += OnItemLabelClick; label.MouseClick += OnItemLabelMouseClick; label.MouseDown += OnItemLabelMouseDown; label.MouseUp += OnItemLabelMouseUp; label.MouseMove += OnItemLabelMouseMove; label.GiveFeedback += OnItemLabelGiveFeedback; label.Paint += OnTechLabelPaint; _pictureBox.Controls.Add(label); }
/// <summary> /// 編集項目を作成する /// </summary> /// <param name="tabPage">対象のタブページ</param> private void CreateEditableItems(TabPage tabPage) { List <List <MiscItemId> > table = tabPage.Tag as List <List <MiscItemId> >; if (table == null) { return; } Graphics g = Graphics.FromHwnd(Handle); int itemHeight = DeviceCaps.GetScaledHeight(25); int labelStartX = DeviceCaps.GetScaledWidth(10); int labelStartY = DeviceCaps.GetScaledHeight(13); int editStartY = DeviceCaps.GetScaledHeight(10); int labelEditMargin = DeviceCaps.GetScaledWidth(8); int columnMargin = DeviceCaps.GetScaledWidth(10); int textBoxWidth = DeviceCaps.GetScaledWidth(50); int textBoxHeight = DeviceCaps.GetScaledHeight(19); int comboBoxWidthUnit = DeviceCaps.GetScaledWidth(15); int comboBoxWidthBase = DeviceCaps.GetScaledWidth(50); int comboBoxWidthMargin = DeviceCaps.GetScaledWidth(8); int comboBoxHeight = DeviceCaps.GetScaledHeight(20); int labelX = labelStartX; foreach (List <MiscItemId> list in table) { int labelY = labelStartY; int editX = labelX; // 編集コントロールの右端X座標(左端ではない) foreach (MiscItemId id in list) { // ラベルを作成する Label label = new Label { Text = Misc.GetItemName(id), AutoSize = true, Location = new Point(labelX, labelY) }; string t = Misc.GetItemToolTip(id); if (!string.IsNullOrEmpty(t)) { miscToolTip.SetToolTip(label, t); } tabPage.Controls.Add(label); // 編集コントロールの幅のみ求める int x = labelX + label.Width + labelEditMargin; MiscItemType type = Misc.ItemTypes[(int)id]; switch (type) { case MiscItemType.Bool: case MiscItemType.Enum: int maxWidth = comboBoxWidthBase; for (int i = Misc.IntMinValues[id]; i <= Misc.IntMaxValues[id]; i++) { string s = Misc.GetItemChoice(id, i); if (string.IsNullOrEmpty(s)) { continue; } maxWidth = Math.Max(maxWidth, (int)g.MeasureString(s, Font).Width + SystemInformation.VerticalScrollBarWidth + comboBoxWidthMargin); maxWidth = comboBoxWidthBase + (maxWidth - comboBoxWidthBase + (comboBoxWidthUnit - 1)) / comboBoxWidthUnit * comboBoxWidthUnit; } x += maxWidth; break; default: // テキストボックスの項目は固定 x += textBoxWidth; break; } if (x > editX) { editX = x; } labelY += itemHeight; } int editY = editStartY; foreach (MiscItemId id in list) { // 編集コントロールを作成する MiscItemType type = Misc.ItemTypes[(int)id]; switch (type) { case MiscItemType.Bool: case MiscItemType.Enum: ComboBox comboBox = new ComboBox { DropDownStyle = ComboBoxStyle.DropDownList, DrawMode = DrawMode.OwnerDrawFixed, Tag = id }; // コンボボックスの選択項目を登録し、最大幅を求める int maxWidth = comboBoxWidthBase; for (int i = Misc.IntMinValues[id]; i <= Misc.IntMaxValues[id]; i++) { string s = Misc.GetItemChoice(id, i); if (string.IsNullOrEmpty(s)) { continue; } comboBox.Items.Add(s); maxWidth = Math.Max(maxWidth, (int)g.MeasureString(s, Font).Width + SystemInformation.VerticalScrollBarWidth + comboBoxWidthMargin); maxWidth = comboBoxWidthBase + (maxWidth - comboBoxWidthBase + (comboBoxWidthUnit - 1)) / comboBoxWidthUnit * comboBoxWidthUnit; } comboBox.Size = new Size(maxWidth, comboBoxHeight); comboBox.Location = new Point(editX - maxWidth, editY); comboBox.DrawItem += OnItemComboBoxDrawItem; comboBox.SelectedIndexChanged += OnItemComboBoxSelectedIndexChanged; tabPage.Controls.Add(comboBox); break; default: TextBox textBox = new TextBox { Size = new Size(textBoxWidth, textBoxHeight), Location = new Point(editX - textBoxWidth, editY), TextAlign = HorizontalAlignment.Right, Tag = id }; textBox.Validated += OnItemTextBoxValidated; tabPage.Controls.Add(textBox); break; } editY += itemHeight; } // 次の列との間を空ける labelX = editX + columnMargin; } }
/// <summary> /// タブページ群を初期化する /// </summary> private void InitTabPages() { miscTabControl.TabPages.Clear(); MiscGameType type = Misc.GetGameType(); int itemHeight = DeviceCaps.GetScaledHeight(25); int itemMargin = DeviceCaps.GetScaledWidth(20); int itemsPerColumn = (miscTabControl.ClientSize.Height - miscTabControl.ItemSize.Height - itemMargin) / itemHeight; const int columnsPerPage = 3; foreach (MiscSectionId section in Enum.GetValues(typeof(MiscSectionId)) .Cast <MiscSectionId>() .Where(section => Misc.SectionTable[(int)section, (int)type])) { TabPage tabPage = new TabPage { Text = Misc.GetSectionName(section), BackColor = SystemColors.Control }; List <List <MiscItemId> > table = new List <List <MiscItemId> >(); List <MiscItemId> list = new List <MiscItemId>(); int row = 0; int column = 0; int page = 1; foreach (MiscItemId id in Misc.SectionItems[(int)section] .Where(id => Misc.ItemTable[(int)id, (int)type])) { if (row >= itemsPerColumn) { table.Add(list); list = new List <MiscItemId>(); column++; row = 0; if (column >= columnsPerPage) { if (page == 1) { tabPage.Text += IntHelper.ToString(page); } tabPage.Tag = table; miscTabControl.TabPages.Add(tabPage); page++; tabPage = new TabPage { Text = Misc.GetSectionName(section) + IntHelper.ToString(page), BackColor = SystemColors.Control }; table = new List <List <MiscItemId> >(); column = 0; } } list.Add(id); row++; } table.Add(list); tabPage.Tag = table; miscTabControl.TabPages.Add(tabPage); } }
/// <summary> /// ラベル画像を初期化する /// </summary> private static void InitLabelBitmap() { // 既に初期化済みならば何もしない if (_labelInitialized) { return; } // 技術ラベル Bitmap bitmap = new Bitmap(Game.GetReadFileName(Game.TechLabelPathName)); _techLabelWidth = DeviceCaps.GetScaledWidth(TechLabelWidthBase); _techLabelHeight = DeviceCaps.GetScaledHeight(TechLabelHeightBase); _techLabelBitmap = new Bitmap(_techLabelWidth, _techLabelHeight); Graphics g = Graphics.FromImage(_techLabelBitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(bitmap, new Rectangle(0, 0, _techLabelWidth, _techLabelHeight), new Rectangle(0, 0, TechLabelWidthBase, TechLabelHeightBase), GraphicsUnit.Pixel); g.Dispose(); Color transparent = _techLabelBitmap.GetPixel(0, 0); // 青写真付き技術ラベル Bitmap icon = new Bitmap(Game.GetReadFileName(Game.BlueprintIconPathName)); icon.MakeTransparent(icon.GetPixel(0, 0)); g = Graphics.FromImage(bitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(icon, new Rectangle(BlueprintIconX, BlueprintIconY, BlueprintIconWidth, BlueprintIconHeight), new Rectangle(0, 0, BlueprintIconWidth, BlueprintIconHeight), GraphicsUnit.Pixel); g.Dispose(); _blueprintTechLabelBitmap = new Bitmap(_techLabelWidth, _techLabelHeight); g = Graphics.FromImage(_blueprintTechLabelBitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(bitmap, new Rectangle(0, 0, _techLabelWidth, _techLabelHeight), new Rectangle(0, 0, TechLabelWidthBase, TechLabelHeightBase), GraphicsUnit.Pixel); g.Dispose(); bitmap.Dispose(); // 完了技術ラベル bitmap = new Bitmap(Game.GetReadFileName(Game.DoneTechLabelPathName)); _doneTechLabelBitmap = new Bitmap(_techLabelWidth, _techLabelHeight); g = Graphics.FromImage(_doneTechLabelBitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(bitmap, new Rectangle(0, 0, _techLabelWidth, _techLabelHeight), new Rectangle(0, 0, TechLabelWidthBase, TechLabelHeightBase), GraphicsUnit.Pixel); g.Dispose(); // 青写真付き完了技術ラベル g = Graphics.FromImage(bitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(icon, new Rectangle(BlueprintIconX, BlueprintIconY, BlueprintIconWidth, BlueprintIconHeight), new Rectangle(0, 0, BlueprintIconWidth, BlueprintIconHeight), GraphicsUnit.Pixel); g.Dispose(); icon.Dispose(); _blueprintDoneTechLabelBitmap = new Bitmap(_techLabelWidth, _techLabelHeight); g = Graphics.FromImage(_blueprintDoneTechLabelBitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(bitmap, new Rectangle(0, 0, _techLabelWidth, _techLabelHeight), new Rectangle(0, 0, TechLabelWidthBase, TechLabelHeightBase), GraphicsUnit.Pixel); g.Dispose(); bitmap.Dispose(); // 技術ラベルの領域 _techLabelMask = new Bitmap(_techLabelWidth, _techLabelHeight); _techLabelRegion = new Region(new Rectangle(0, 0, _techLabelWidth, _techLabelHeight)); for (int y = 0; y < _techLabelBitmap.Height; y++) { for (int x = 0; x < _techLabelBitmap.Width; x++) { if (_techLabelBitmap.GetPixel(x, y) == transparent) { _techLabelRegion.Exclude(new Rectangle(x, y, 1, 1)); _techLabelMask.SetPixel(x, y, Color.White); } else { _techLabelMask.SetPixel(x, y, Color.Black); } } } // 技術ラベルの透明色設定 _techLabelBitmap.MakeTransparent(transparent); _blueprintTechLabelBitmap.MakeTransparent(transparent); _doneTechLabelBitmap.MakeTransparent(transparent); _blueprintDoneTechLabelBitmap.MakeTransparent(transparent); // 発明イベントラベル bitmap = new Bitmap(Game.GetReadFileName(Game.SecretLabelPathName)); _eventLabelWidth = DeviceCaps.GetScaledWidth(EventLabelWidthBase); _eventLabelHeight = DeviceCaps.GetScaledHeight(EventLabelHeightBase); _eventLabelBitmap = new Bitmap(_eventLabelWidth, _eventLabelHeight); g = Graphics.FromImage(_eventLabelBitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(bitmap, new Rectangle(0, 0, _eventLabelWidth, _eventLabelHeight), new Rectangle(EventLabelWidthBase, 0, EventLabelWidthBase, EventLabelHeightBase), GraphicsUnit.Pixel); g.Dispose(); transparent = _eventLabelBitmap.GetPixel(0, 0); // 完了発明イベントラベル _doneEventLabelBitmap = new Bitmap(_eventLabelWidth, _eventLabelHeight); g = Graphics.FromImage(_doneEventLabelBitmap); g.InterpolationMode = InterpolationMode.NearestNeighbor; g.DrawImage(bitmap, new Rectangle(0, 0, _eventLabelWidth, _eventLabelHeight), new Rectangle(0, 0, EventLabelWidthBase, EventLabelHeightBase), GraphicsUnit.Pixel); g.Dispose(); bitmap.Dispose(); // 発明イベントラベルの領域 _eventLabelMask = new Bitmap(_eventLabelWidth, _eventLabelHeight); _eventLabelRegion = new Region(new Rectangle(0, 0, _eventLabelWidth, _eventLabelHeight)); for (int y = 0; y < _eventLabelBitmap.Height; y++) { for (int x = 0; x < _eventLabelBitmap.Width; x++) { if (_eventLabelBitmap.GetPixel(x, y) == transparent) { _eventLabelRegion.Exclude(new Rectangle(x, y, 1, 1)); _eventLabelMask.SetPixel(x, y, Color.White); } else { _eventLabelMask.SetPixel(x, y, Color.Black); } } } // 発明イベントラベルの透明色設定 _eventLabelBitmap.MakeTransparent(transparent); _doneEventLabelBitmap.MakeTransparent(transparent); // 初期化済みフラグを設定する _labelInitialized = true; }
/// <summary> /// 編集項目の表示を更新する /// </summary> private void UpdateEditableItems() { itemPanel.Controls.Clear(); // 選択中の国家がなければ戻る if (countryListBox.SelectedIndex < 0) { return; } Country country = Countries.Tags[countryListBox.SelectedIndex]; // 選択中のユニット名種類がなければ戻る UnitClass unit = typeListBox.SelectedItem as UnitClass; if (unit == null) { return; } Graphics g = Graphics.FromHwnd(Handle); int itemHeight = DeviceCaps.GetScaledHeight(25); int labelStartX = DeviceCaps.GetScaledWidth(10); int labelStartY = DeviceCaps.GetScaledHeight(13); int textBoxStartY = DeviceCaps.GetScaledHeight(10); int labelEditMargin = DeviceCaps.GetScaledWidth(10); int columnMargin = DeviceCaps.GetScaledWidth(10); int textBoxWidthBase = DeviceCaps.GetScaledWidth(100); int textBoxWidthMargin = DeviceCaps.GetScaledWidth(8); int textBoxHeight = DeviceCaps.GetScaledHeight(19); int itemsPerColumn = (itemPanel.DisplayRectangle.Height - textBoxStartY * 2) / itemHeight; int labelX = labelStartX; int index = 0; while (index < unit.Models.Count) { int max = Math.Min(unit.Models.Count - index, itemsPerColumn) + index; int labelY = labelStartY; int maxLabelWidth = 0; int maxEditWidth = textBoxWidthBase; for (int i = index; i < max; i++) { // ラベルを作成する Label label = new Label { Text = $"{i}: {unit.GetModelName(i)}", AutoSize = true, Location = new Point(labelX, labelY) }; itemPanel.Controls.Add(label); maxLabelWidth = Math.Max(maxLabelWidth, label.Width); labelY += itemHeight; // テキストボックスの最大幅を求める if (unit.ExistsModelName(i, country)) { string s = unit.GetCountryModelName(i, country); maxEditWidth = Math.Max(maxEditWidth, (int)g.MeasureString(s, Font).Width + textBoxWidthMargin); } } int textBoxX = labelX + maxLabelWidth + labelEditMargin; int textBoxY = textBoxStartY; for (int i = index; i < max; i++) { // テキストボックスを作成する TextBox textBox = new TextBox { Size = new Size(maxEditWidth, textBoxHeight), Location = new Point(textBoxX, textBoxY), ForeColor = unit.Models[i].IsDirtyName(country) ? Color.Red : SystemColors.WindowText, Tag = i }; if (unit.ExistsModelName(i, country)) { textBox.Text = unit.GetCountryModelName(i, country); } textBox.Validated += OnItemTextBoxValidated; itemPanel.Controls.Add(textBox); textBoxY += itemHeight; } // 次の列へ移動する index += itemsPerColumn; labelX = textBoxX + maxEditWidth + columnMargin; } // スクロールバーの位置を調整するため最終列の次にダミーラベルを作成する itemPanel.Controls.Add(new Label { Location = new Point(labelX, labelStartY), AutoSize = true }); }