Ejemplo n.º 1
0
        /// <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;
            }
        }
Ejemplo n.º 2
0
        /// <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;
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     フォーム読み込み時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFormLoad(object sender, EventArgs e)
        {
            Graphics g      = Graphics.FromHwnd(Handle);
            int      margin = DeviceCaps.GetScaledWidth(2) + 1;

            // 選択国コンボボックス
            srcComboBox.BeginUpdate();
            srcComboBox.Items.Clear();
            int width = srcComboBox.Width;

            foreach (string s in Countries.Tags
                     .Select(country => Countries.Strings[(int)country])
                     .Select(name => Config.ExistsKey(name)
                    ? $"{name} {Config.GetText(name)}"
                    : name))
            {
                srcComboBox.Items.Add(s);
                width = Math.Max(width,
                                 (int)g.MeasureString(s, srcComboBox.Font).Width + SystemInformation.VerticalScrollBarWidth +
                                 margin);
            }
            srcComboBox.DropDownWidth = width;
            srcComboBox.EndUpdate();
            if (srcComboBox.Items.Count > 0)
            {
                srcComboBox.SelectedIndex = Countries.Tags.ToList().IndexOf(_args.TargetCountries[0]);
            }
            srcComboBox.SelectedIndexChanged += OnSrcComboBoxSelectedIndexChanged;

            // コピー/移動先コンボボックス
            destComboBox.BeginUpdate();
            destComboBox.Items.Clear();
            width = destComboBox.Width;
            foreach (string s in Countries.Tags
                     .Select(country => Countries.Strings[(int)country])
                     .Select(name => Config.ExistsKey(name)
                    ? $"{name} {Config.GetText(name)}"
                    : name))
            {
                destComboBox.Items.Add(s);
                width = Math.Max(width,
                                 (int)g.MeasureString(s, srcComboBox.Font).Width +
                                 SystemInformation.VerticalScrollBarWidth +
                                 margin);
            }
            destComboBox.DropDownWidth = width;
            destComboBox.EndUpdate();
            if (_args.TargetCountries.Count > 0)
            {
                destComboBox.SelectedIndex = Countries.Tags.ToList().IndexOf(_args.TargetCountries[0]);
            }
            destComboBox.SelectedIndexChanged += OnDestComboBoxSelectedIndexChanged;

            // 開始ID
            if (_args.TargetCountries.Count > 0)
            {
                idNumericUpDown.Value = Teams.GetNewId(_args.TargetCountries[0]);
            }
            idNumericUpDown.ValueChanged += OnIdNumericUpDownValueChanged;
        }
Ejemplo n.º 5
0
        /// <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;
                }
            }
        }
Ejemplo n.º 6
0
        /// <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();
        }
Ejemplo n.º 7
0
        /// <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();
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     フォーム読み込み時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFormLoad(object sender, EventArgs e)
        {
            Graphics g      = Graphics.FromHwnd(Handle);
            int      margin = DeviceCaps.GetScaledWidth(2) + 1;

            // 対象国コンボボックス
            srcComboBox.BeginUpdate();
            srcComboBox.Items.Clear();
            int width = srcComboBox.Width;

            foreach (string s in Countries.Tags
                     .Select(country => Countries.Strings[(int)country])
                     .Select(name => Config.ExistsKey(name)
                    ? $"{name} {Config.GetText(name)}"
                    : name))
            {
                srcComboBox.Items.Add(s);
                width = Math.Max(width,
                                 (int)g.MeasureString(s, srcComboBox.Font).Width +
                                 SystemInformation.VerticalScrollBarWidth +
                                 margin);
            }
            srcComboBox.DropDownWidth = width;
            srcComboBox.EndUpdate();
            if (_args.TargetCountries.Count > 0)
            {
                srcComboBox.SelectedIndex = Countries.Tags.ToList().IndexOf(_args.TargetCountries[0]);
            }
            srcComboBox.SelectedIndexChanged += OnSrcComboBoxSelectedIndexChanged;

            // 兵科
            armyCheckBox.Text     = Config.GetText(TextId.BranchArmy);
            navyCheckBox.Text     = Config.GetText(TextId.BranchNavy);
            airforceCheckBox.Text = Config.GetText(TextId.BranchAirForce);

            // コピー/移動先コンボボックス
            destComboBox.BeginUpdate();
            destComboBox.Items.Clear();
            width = destComboBox.Width;
            foreach (string s in Countries.Tags
                     .Select(country => Countries.Strings[(int)country])
                     .Select(name => Config.ExistsKey(name)
                    ? $"{name} {Config.GetText(name)}"
                    : name))
            {
                destComboBox.Items.Add(s);
                width = Math.Max(width,
                                 (int)g.MeasureString(s, srcComboBox.Font).Width +
                                 SystemInformation.VerticalScrollBarWidth +
                                 margin);
            }
            destComboBox.DropDownWidth = width;
            destComboBox.EndUpdate();
            if (_args.TargetCountries.Count > 0)
            {
                destComboBox.SelectedIndex = Countries.Tags.ToList().IndexOf(_args.TargetCountries[0]);
            }
            destComboBox.SelectedIndexChanged += OnDestComboBoxSelectedIndexChanged;

            // 開始ID
            if (_args.TargetCountries.Count > 0)
            {
                idNumericUpDown.Value = Leaders.GetNewId(_args.TargetCountries[0]);
            }
            idNumericUpDown.ValueChanged += OnIdNumericUpDownValueChanged;

            // 理想階級コンボボックス
            idealRankComboBox.BeginUpdate();
            idealRankComboBox.Items.Clear();
            width = idealRankComboBox.Width;
            foreach (string s in Leaders.RankNames.Where(name => !string.IsNullOrEmpty(name)))
            {
                idealRankComboBox.Items.Add(s);
                width = Math.Max(width, (int)g.MeasureString(s, idealRankComboBox.Font).Width + margin);
            }
            idealRankComboBox.DropDownWidth = width;
            idealRankComboBox.EndUpdate();
            if (idealRankComboBox.Items.Count > 0)
            {
                idealRankComboBox.SelectedIndex = 0;
            }
            idealRankComboBox.SelectedIndexChanged += OnIdealRankComboBoxSelectedIndexChanged;

            // 引退年
            if ((Game.Type != GameType.DarkestHour) || (Game.Version < 103))
            {
                retirementYearCheckBox.Enabled      = false;
                retirementYearNumericUpDown.Enabled = false;
                retirementYearNumericUpDown.ResetText();
            }
        }
Ejemplo n.º 10
0
        /// <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;
            }
        }
Ejemplo n.º 11
0
        /// <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);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     フォーム読み込み時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFormLoad(object sender, EventArgs e)
        {
            Graphics g      = Graphics.FromHwnd(Handle);
            int      margin = DeviceCaps.GetScaledWidth(2) + 1;

            // 対象国コンボボックス
            srcComboBox.BeginUpdate();
            srcComboBox.Items.Clear();
            int width = srcComboBox.Width;

            foreach (string s in Countries.Tags
                     .Select(country => Countries.Strings[(int)country])
                     .Select(name => Config.ExistsKey(name)
                    ? $"{name} {Config.GetText(name)}"
                    : name))
            {
                srcComboBox.Items.Add(s);
                width = Math.Max(width,
                                 (int)g.MeasureString(s, srcComboBox.Font).Width + SystemInformation.VerticalScrollBarWidth +
                                 margin);
            }
            srcComboBox.DropDownWidth = width;
            srcComboBox.EndUpdate();
            if (srcComboBox.Items.Count > 0)
            {
                srcComboBox.SelectedIndex = Countries.Tags.ToList().IndexOf(_args.TargetCountries[0]);
            }
            srcComboBox.SelectedIndexChanged += OnSrcComboBoxSelectedIndexChanged;

            // 閣僚地位
            hosCheckBox.Text  = Config.GetText(TextId.MinisterHeadOfState);
            hogCheckBox.Text  = Config.GetText(TextId.MinisterHeadOfGovernment);
            mofCheckBox.Text  = Config.GetText(TextId.MinisterForeignMinister);
            moaCheckBox.Text  = Config.GetText(TextId.MinisterArmamentMinister);
            mosCheckBox.Text  = Config.GetText(TextId.MinisterMinisterOfSecurity);
            moiCheckBox.Text  = Config.GetText(TextId.MinisterMinisterOfIntelligence);
            cosCheckBox.Text  = Config.GetText(TextId.MinisterChiefOfStaff);
            coaCheckBox.Text  = Config.GetText(TextId.MinisterChiefOfArmy);
            conCheckBox.Text  = Config.GetText(TextId.MinisterChiefOfNavy);
            coafCheckBox.Text = Config.GetText(TextId.MinisterChiefOfAir);

            // コピー/移動先コンボボックス
            destComboBox.BeginUpdate();
            destComboBox.Items.Clear();
            width = destComboBox.Width;
            foreach (string s in Countries.Tags
                     .Select(country => Countries.Strings[(int)country])
                     .Select(name => Config.ExistsKey(name)
                    ? $"{name} {Config.GetText(name)}"
                    : name))
            {
                destComboBox.Items.Add(s);
                width = Math.Max(width,
                                 (int)g.MeasureString(s, destComboBox.Font).Width + SystemInformation.VerticalScrollBarWidth +
                                 margin);
            }
            destComboBox.DropDownWidth = width;
            destComboBox.EndUpdate();
            if (destComboBox.Items.Count > 0)
            {
                destComboBox.SelectedIndex = Countries.Tags.ToList().IndexOf(_args.TargetCountries[0]);
            }
            destComboBox.SelectedIndexChanged += OnDestComboBoxSelectedIndexChanged;

            // 開始ID
            if (_args.TargetCountries.Count > 0)
            {
                idNumericUpDown.Value = Ministers.GetNewId(_args.TargetCountries[0]);
            }
            idNumericUpDown.ValueChanged += OnIdNumericUpDownValueChanged;

            // 終了年
            if (Game.Type != GameType.DarkestHour)
            {
                endYearCheckBox.Enabled      = false;
                endYearNumericUpDown.Enabled = false;
                endYearNumericUpDown.ResetText();
            }

            // 引退年
            if ((Game.Type != GameType.DarkestHour) || (Game.Version < 103))
            {
                retirementYearCheckBox.Enabled      = false;
                retirementYearNumericUpDown.Enabled = false;
                retirementYearNumericUpDown.ResetText();
            }

            // イデオロギーコンボボックス
            ideologyComboBox.BeginUpdate();
            ideologyComboBox.Items.Clear();
            width = ideologyComboBox.Width;
            foreach (string s in Ministers.IdeologyNames.Where(id => id != TextId.Empty).Select(Config.GetText))
            {
                ideologyComboBox.Items.Add(s);
                width = Math.Max(width, (int)g.MeasureString(s, ideologyComboBox.Font).Width + margin);
            }
            ideologyComboBox.DropDownWidth = width;
            ideologyComboBox.EndUpdate();
            if (ideologyComboBox.Items.Count > 0)
            {
                ideologyComboBox.SelectedIndex = 0;
            }
            ideologyComboBox.SelectedIndexChanged += OnIdeologyComboBoxSelectedIndexChanged;

            // 忠誠度コンボボックス
            loyaltyComboBox.BeginUpdate();
            loyaltyComboBox.Items.Clear();
            width = loyaltyComboBox.Width;
            foreach (string s in Ministers.LoyaltyNames.Where(name => !string.IsNullOrEmpty(name)))
            {
                loyaltyComboBox.Items.Add(s);
                width = Math.Max(width, (int)g.MeasureString(s, loyaltyComboBox.Font).Width + margin);
            }
            loyaltyComboBox.DropDownWidth = width;
            loyaltyComboBox.EndUpdate();
            if (loyaltyComboBox.Items.Count > 0)
            {
                loyaltyComboBox.SelectedIndex = 0;
            }
            loyaltyComboBox.SelectedIndexChanged += OnLoyaltyComboBoxSelectedIndexChanged;
        }
Ejemplo n.º 13
0
        /// <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;
        }
Ejemplo n.º 14
0
        /// <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
            });
        }