public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            if (skill == null)
            {
                return;
            }
            _skill = skill;
            InitializeComponent();

            LanguageManager.TranslateWinForm(GlobalOptions.Language, this);

            //Display
            lblModifiedRating.DoDatabinding("Text", skill, nameof(KnowledgeSkill.DisplayPool));
            lblModifiedRating.DoDatabinding("ToolTipText", skill, nameof(KnowledgeSkill.PoolToolTip));

            List <ListItem> lstTypes = KnowledgeSkill.KnowledgeTypes().ToList();

            lstTypes.Sort(CompareListItems.CompareNames);

            cboType.BeginUpdate();
            cboSkill.BeginUpdate();
            cboSpec.BeginUpdate();
            cboType.DataSource    = lstTypes;
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataBindings.Add("SelectedValue", skill, nameof(KnowledgeSkill.Type), false, DataSourceUpdateMode.OnPropertyChanged);

            nudSkill.Visible = !skill.CharacterObject.Created && skill.CharacterObject.SkillsSection.HasKnowledgePoints;
            nudKarma.Visible = !skill.CharacterObject.Created;
            chkKarma.Visible = !skill.CharacterObject.Created;
            cboSpec.Visible  = !skill.CharacterObject.Created;
            //cboType.Visible = !skill.CharacterObject.Created;

            btnCareerIncrease.Visible = skill.CharacterObject.Created;
            lblSpec.Visible           = skill.CharacterObject.Created;
            btnAddSpec.Visible        = skill.CharacterObject.Created;
            lblRating.Visible         = skill.CharacterObject.Created;

            if (skill.CharacterObject.Created)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;

                lblRating.Visible = true;
                lblRating.DataBindings.Add("Text", skill, nameof(Skill.Rating), false, DataSourceUpdateMode.OnPropertyChanged);

                //New knowledge skills start at 0. Leave the Type selector unlocked until they spend Karma on the skill.
                cboType.Enabled = (skill.Karma == 0 && skill.Base == 0 || string.IsNullOrWhiteSpace(_skill.Type));

                lblName.Visible = true;
                lblName.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);
                lblName.DataBindings.Add("ForeColor", skill, nameof(Skill.PreferredColor));
                lblName.DataBindings.Add("ToolTipText", skill, nameof(Skill.HtmlSkillToolTip));

                lblSpec.Visible = true;
                lblSpec.DataBindings.Add("Text", skill, nameof(Skill.CurrentDisplaySpecialization), false, DataSourceUpdateMode.OnPropertyChanged);

                cboSkill.Visible = false;
                chkKarma.Visible = false;
                cboSpec.Visible  = false;

                lblModifiedRating.Location = new Point(294 - 30, 4);

                btnAddSpec.DataBindings.Add("Enabled", skill, nameof(Skill.CanAffordSpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
                btnAddSpec.DataBindings.Add("Visible", skill, nameof(Skill.CanHaveSpecs), false, DataSourceUpdateMode.OnPropertyChanged);
                btnAddSpec.DataBindings.Add("ToolTipText", skill, nameof(Skill.AddSpecToolTip), false, DataSourceUpdateMode.OnPropertyChanged);
                btnCareerIncrease.DataBindings.Add("Enabled", skill, nameof(Skill.CanUpgradeCareer), false, DataSourceUpdateMode.OnPropertyChanged);
                btnCareerIncrease.DataBindings.Add("ToolTipText", skill, nameof(Skill.UpgradeToolTip), false, DataSourceUpdateMode.OnPropertyChanged);
            }
            else
            {
                //Up down boxes
                nudKarma.DataBindings.Add("Value", skill, nameof(Skill.Karma), false, DataSourceUpdateMode.OnPropertyChanged);
                nudKarma.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                nudSkill.DataBindings.Add("Value", skill, nameof(Skill.Base), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("Enabled", skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                chkKarma.DataBindings.Add("Checked", skill, nameof(Skill.BuyWithKarma), false,
                                          DataSourceUpdateMode.OnPropertyChanged);
                List <ListItem> lstDefaultKnowledgeSkills = KnowledgeSkill.DefaultKnowledgeSkills().ToList();
                lstDefaultKnowledgeSkills.Sort(CompareListItems.CompareNames);
                cboSkill.DataSource    = lstDefaultKnowledgeSkills;
                cboSkill.DisplayMember = nameof(ListItem.Name);
                cboSkill.ValueMember   = nameof(ListItem.Value);
                cboSkill.SelectedIndex = -1;
                cboSkill.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);
                cboSkill.DataBindings.Add(new NegatableBinding("Enabled", skill, nameof(KnowledgeSkill.ForcedName), true));

                //dropdown/spec
                cboSpec.DataSource    = skill.CGLSpecializations;
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.SelectedIndex = -1;

                cboSpec.DataBindings.Add("Enabled", skill, nameof(Skill.CanHaveSpecs), false, DataSourceUpdateMode.OnPropertyChanged);
                cboSpec.DataBindings.Add("Text", skill, nameof(Skill.Specialization), false, DataSourceUpdateMode.OnPropertyChanged);

                skill.PropertyChanged += Skill_PropertyChanged;
            }

            cmdDelete.DataBindings.Add("Visible", skill, nameof(Skill.AllowDelete), false, DataSourceUpdateMode.OnPropertyChanged);
            cmdDelete.Click += (sender, args) =>
            {
                if (!skill.CharacterObject.ConfirmDelete(LanguageManager.GetString("Message_DeleteKnowledgeSkill",
                                                                                   GlobalOptions.Language)))
                {
                    return;
                }
                skill.UnbindSkill();
                skill.CharacterObject.SkillsSection.KnowledgeSkills.Remove(skill);
            };
            if (skill.ForcedName)
            {
                DataBindings.Add("Enabled", skill, nameof(KnowledgeSkill.Enabled), false, DataSourceUpdateMode.OnPropertyChanged);
                if (!skill.CharacterObject.Created)
                {
                    cboType.Enabled = string.IsNullOrEmpty(_skill.Type);
                }
            }
            if (!skill.AllowUpgrade)
            {
                nudKarma.Visible          = false;
                nudSkill.Visible          = false;
                cboSkill.Enabled          = false;
                chkKarma.Visible          = false;
                btnAddSpec.Enabled        = false;
                btnCareerIncrease.Enabled = false;

                if (!skill.CharacterObject.Created)
                {
                    lblRating.Visible = true;
                    lblRating.DataBindings.Add("Text", skill, nameof(Skill.Rating), false, DataSourceUpdateMode.OnPropertyChanged);
                }
            }
            cboType.EndUpdate();
            cboSkill.EndUpdate();
            cboSpec.EndUpdate();
        }
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            _skill = skill;
            InitializeComponent();

            //Display
            lblModifiedRating.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.DisplayPool), false, DataSourceUpdateMode.OnPropertyChanged);

            List <ListItem> lstTypes = KnowledgeSkill.KnowledgeTypes(GlobalOptions.Language).ToList();

            lstTypes.Sort(CompareListItems.CompareNames);

            cboType.BeginUpdate();
            cboSkill.BeginUpdate();
            cboSpec.BeginUpdate();
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataSource    = lstTypes;
            cboType.DataBindings.Add("SelectedValue", skill, nameof(KnowledgeSkill.Type), false, DataSourceUpdateMode.OnPropertyChanged);

            if (skill.CharacterObject.Created)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;

                lblRating.Visible = true;
                lblRating.DataBindings.Add("Text", skill, nameof(Skill.Rating), false, DataSourceUpdateMode.OnPropertyChanged);

                //New knowledge skills start at 0. Leave the Type selector unlocked until they spend Karma on the skill.
                cboType.Enabled = (skill.Karma == 0 && skill.Base == 0 || string.IsNullOrWhiteSpace(_skill.Type));

                lblName.Visible = true;
                lblName.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);

                lblSpec.Visible  = true;
                lblSpec.Text     = string.Join(", ", skill.Specializations.Select(x => x.Name));
                cboSkill.Visible = false;
                chkKarma.Visible = false;
                cboSpec.Visible  = false;

                lblModifiedRating.Location = new Point(294 - 30, 4);

                btnAddSpec.Visible = true;
                btnAddSpec.DataBindings.Add("Enabled", skill, nameof(Skill.CanAffordSpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
                btnCareerIncrease.Visible = true;
                btnCareerIncrease.DataBindings.Add("Enabled", skill, nameof(Skill.CanUpgradeCareer), false,
                                                   DataSourceUpdateMode.OnPropertyChanged);
                lblSpec.DataBindings.Add("Text", skill, nameof(Skill.DisplaySpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
            }
            else
            {
                //Up down boxes
                nudKarma.DataBindings.Add("Value", skill, nameof(Skill.Karma), false, DataSourceUpdateMode.OnPropertyChanged);
                nudKarma.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                nudSkill.DataBindings.Add("Value", skill, nameof(Skill.Base), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("Enabled", skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                chkKarma.DataBindings.Add("Checked", skill, nameof(Skill.BuyWithKarma), false,
                                          DataSourceUpdateMode.OnPropertyChanged);
                cboSkill.DisplayMember = nameof(ListItem.Name);
                cboSkill.ValueMember   = nameof(ListItem.Value);
                List <ListItem> lstDefaultKnowledgeSkills = KnowledgeSkill.DefaultKnowledgeSkills(GlobalOptions.Language).ToList();
                lstDefaultKnowledgeSkills.Sort(CompareListItems.CompareNames);
                cboSkill.DataSource    = lstDefaultKnowledgeSkills;
                cboSkill.SelectedIndex = -1;
                cboSkill.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);

                //dropdown/spec
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.DataSource    = skill.CGLSpecializations;
                cboSpec.SelectedIndex = -1;

                cboSpec.DataBindings.Add("Enabled", skill, nameof(Skill.Leveled), false, DataSourceUpdateMode.OnPropertyChanged);
                cboSpec.DataBindings.Add("Text", skill, nameof(Skill.Specialization), false, DataSourceUpdateMode.OnPropertyChanged);

                skill.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == nameof(Skill.CGLSpecializations))
                    {
                        cboSpec.DataSource       = null;
                        cboSpec.DisplayMember    = nameof(ListItem.Name);
                        cboSpec.ValueMember      = nameof(ListItem.Value);
                        cboSpec.DataSource       = skill.CGLSpecializations;
                        cboSpec.MaxDropDownItems = Math.Max(1, skill.CGLSpecializations.Count);
                    }
                };
            }

            if (skill.ForcedName)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;
                cboSkill.Enabled = false;
                cboSpec.DataBindings.Clear();
                cboSpec.Enabled           = false;
                btnAddSpec.Enabled        = false;
                btnCareerIncrease.Enabled = false;

                lblRating.Visible = true;
                lblRating.Text    = skill.CyberwareRating.ToString();

                cmdDelete.Visible = false;
            }
            else
            {
                cmdDelete.Click += (sender, args) => { skill.CharacterObject.SkillsSection.KnowledgeSkills.Remove(skill); };
            }
            cboType.EndUpdate();
            cboSkill.EndUpdate();
            cboSpec.EndUpdate();
        }
Beispiel #3
0
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            if (skill == null)
            {
                return;
            }
            _skill = skill;
            _tmrNameChangeTimer = new Timer {
                Interval = 1000
            };
            _tmrNameChangeTimer.Tick += NameChangeTimer_Tick;
            InitializeComponent();
            KnowledgeSkillControl_DpiChangedAfterParent(null, EventArgs.Empty);
            this.UpdateLightDarkMode();
            this.TranslateWinForm();

            SuspendLayout();

            lblModifiedRating.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.DisplayPool));
            lblModifiedRating.DoOneWayDataBinding("ToolTipText", _skill, nameof(KnowledgeSkill.PoolToolTip));

            cmdDelete.DoOneWayDataBinding("Visible", _skill, nameof(Skill.AllowDelete));

            cboType.BeginUpdate();
            cboType.DataSource    = KnowledgeSkill.KnowledgeTypes(_skill.CharacterObject);
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DoDatabinding("SelectedValue", _skill, nameof(KnowledgeSkill.Type));
            cboType.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.AllowTypeChange));
            cboType.EndUpdate();

            lblName.DoOneWayNegatableDatabinding("Visible", _skill, nameof(Skill.AllowNameChange));
            lblName.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
            lblName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));

            cboName.BeginUpdate();
            cboName.DoOneWayDataBinding("Visible", _skill, nameof(Skill.AllowNameChange));
            cboName.DataSource    = KnowledgeSkill.DefaultKnowledgeSkills(_skill.CharacterObject);
            cboName.DisplayMember = nameof(ListItem.Name);
            cboName.ValueMember   = nameof(ListItem.Value);
            cboName.SelectedIndex = -1;
            cboName.Text          = _skill.WriteableName;
            cboName.EndUpdate();
            _blnUpdatingName = false;

            int intMinimumSize;

            using (Graphics g = CreateGraphics())
                intMinimumSize = (int)(25 * g.DpiX / 96.0f);

            if (_skill.CharacterObject.Created)
            {
                lblRating = new Label
                {
                    Anchor      = AnchorStyles.Right,
                    AutoSize    = true,
                    MinimumSize = new Size(intMinimumSize, 0),
                    Name        = "lblRating",
                    Text        = "00",
                    TextAlign   = ContentAlignment.MiddleCenter
                };
                btnCareerIncrease = new ButtonWithToolTip
                {
                    Anchor                  = AnchorStyles.Right,
                    AutoSize                = true,
                    AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                    Image                   = Resources.add,
                    Margin                  = new Padding(3, 0, 3, 0),
                    Name                    = "btnCareerIncrease",
                    Padding                 = new Padding(1),
                    UseVisualStyleBackColor = true
                };
                btnCareerIncrease.Click += btnCareerIncrease_Click;

                lblRating.DoOneWayNegatableDatabinding("Visible", _skill, nameof(KnowledgeSkill.IsNativeLanguage));
                lblRating.DoOneWayDataBinding("Text", _skill, nameof(Skill.Rating));

                btnCareerIncrease.DoOneWayDataBinding("Visible", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                btnCareerIncrease.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanUpgradeCareer));
                btnCareerIncrease.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.UpgradeToolTip));

                lblRating.UpdateLightDarkMode();
                lblRating.TranslateWinForm();
                btnCareerIncrease.UpdateLightDarkMode();
                btnCareerIncrease.TranslateWinForm();
                tlpMain.Controls.Add(lblRating, 1, 0);
                tlpMain.Controls.Add(btnCareerIncrease, 2, 0);

                lblSpec = new Label
                {
                    Anchor    = AnchorStyles.Left,
                    AutoSize  = true,
                    Name      = "lblSpec",
                    Text      = "[SPEC]",
                    TextAlign = ContentAlignment.MiddleLeft
                };
                btnAddSpec = new ButtonWithToolTip
                {
                    Anchor                  = AnchorStyles.Right,
                    AutoSize                = true,
                    AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                    Image                   = Resources.add,
                    Margin                  = new Padding(3, 0, 3, 0),
                    Name                    = "btnAddSpec",
                    Padding                 = new Padding(1),
                    UseVisualStyleBackColor = true
                };
                btnAddSpec.Click += btnAddSpec_Click;

                lblSpec.DoOneWayNegatableDatabinding("Visible", _skill, nameof(KnowledgeSkill.IsNativeLanguage));
                lblSpec.DoOneWayDataBinding("Text", _skill, nameof(Skill.CurrentDisplaySpecialization));

                btnAddSpec.DoOneWayDataBinding("Visible", _skill, nameof(Skill.CanHaveSpecs));
                btnAddSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanAffordSpecialization));
                btnAddSpec.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.AddSpecToolTip));

                lblSpec.UpdateLightDarkMode();
                lblSpec.TranslateWinForm();
                btnAddSpec.UpdateLightDarkMode();
                btnAddSpec.TranslateWinForm();
                tlpMiddle.SetColumnSpan(lblSpec, 2);
                tlpMiddle.Controls.Add(lblSpec, 1, 0);
                tlpMiddle.Controls.Add(btnAddSpec, 3, 0);
            }
            else
            {
                nudSkill = new NumericUpDownEx
                {
                    Anchor              = AnchorStyles.Right,
                    AutoSize            = true,
                    InterceptMouseWheel = NumericUpDownEx.InterceptMouseWheelMode.WhenMouseOver,
                    Margin              = new Padding(3, 2, 3, 2),
                    Maximum             = new decimal(new[] { 99, 0, 0, 0 }),
                    Name = "nudSkill"
                };
                nudKarma = new NumericUpDownEx
                {
                    Anchor              = AnchorStyles.Right,
                    AutoSize            = true,
                    InterceptMouseWheel = NumericUpDownEx.InterceptMouseWheelMode.WhenMouseOver,
                    Margin              = new Padding(3, 2, 3, 2),
                    Maximum             = new decimal(new[] { 99, 0, 0, 0 }),
                    Name = "nudKarma"
                };

                nudSkill.DoOneWayDataBinding("Visible", _skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints));
                nudSkill.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                nudSkill.DoDatabinding("Value", _skill, nameof(Skill.Base));
                nudSkill.InterceptMouseWheel = GlobalOptions.InterceptMode;
                nudKarma.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                nudKarma.DoDatabinding("Value", _skill, nameof(Skill.Karma));
                nudKarma.InterceptMouseWheel = GlobalOptions.InterceptMode;

                nudSkill.UpdateLightDarkMode();
                nudSkill.TranslateWinForm();
                nudKarma.UpdateLightDarkMode();
                nudKarma.TranslateWinForm();
                tlpMain.Controls.Add(nudSkill, 1, 0);
                tlpMain.Controls.Add(nudKarma, 2, 0);

                chkNativeLanguage = new ColorableCheckBox(components)
                {
                    Anchor             = AnchorStyles.Left,
                    AutoSize           = true,
                    DefaultColorScheme = true,
                    Margin             = new Padding(3, 0, 3, 0),
                    Name = "chkNativeLanguage",
                    Tag  = "Skill_NativeLanguageLong",
                    Text = "Native",
                    UseVisualStyleBackColor = true
                };
                cboSpec = new ElasticComboBox
                {
                    Anchor            = AnchorStyles.Left | AnchorStyles.Right,
                    AutoCompleteMode  = AutoCompleteMode.Suggest,
                    FormattingEnabled = true,
                    Margin            = new Padding(3, 0, 3, 0),
                    Name    = "cboSpec",
                    TabStop = false
                };
                chkKarma = new ColorableCheckBox(components)
                {
                    Anchor             = AnchorStyles.Left,
                    AutoSize           = true,
                    DefaultColorScheme = true,
                    Name = "chkKarma",
                    UseVisualStyleBackColor = true
                };

                chkNativeLanguage.DoOneWayDataBinding("Visible", _skill, nameof(Skill.IsLanguage));
                chkNativeLanguage.Enabled = _skill.IsNativeLanguage || _skill.CharacterObject.SkillsSection.HasAvailableNativeLanguageSlots;
                chkNativeLanguage.DoDatabinding("Checked", _skill, nameof(Skill.IsNativeLanguage));

                cboSpec.BeginUpdate();
                cboSpec.DataSource    = _skill.CGLSpecializations;
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.SelectedIndex = -1;
                cboSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanHaveSpecs));
                cboSpec.DoDatabinding("Text", _skill, nameof(Skill.Specialization));
                cboSpec.EndUpdate();

                chkKarma.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanHaveSpecs));
                chkKarma.DoDatabinding("Checked", _skill, nameof(Skill.BuyWithKarma));

                chkNativeLanguage.UpdateLightDarkMode();
                chkNativeLanguage.TranslateWinForm();
                cboSpec.UpdateLightDarkMode();
                cboSpec.TranslateWinForm();
                chkKarma.UpdateLightDarkMode();
                chkKarma.TranslateWinForm();
                tlpMiddle.Controls.Add(chkNativeLanguage, 1, 0);
                tlpMiddle.Controls.Add(cboSpec, 2, 0);
                tlpMiddle.Controls.Add(chkKarma, 3, 0);
            }

            if (_skill.ForcedName)
            {
                this.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.Enabled));
            }

            ResumeLayout();

            _skill.PropertyChanged += Skill_PropertyChanged;
            _skill.CharacterObject.SkillsSection.PropertyChanged += OnSkillsSectionPropertyChanged;
        }