Пример #1
0
        private void Skill_PropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
        {
            if (_blnLoading)
            {
                return;
            }

            bool blnUpdateAll = false;

            //I learned something from this but i'm not sure it is a good solution
            //scratch that, i'm sure it is a bad solution. (Tooltip manager from tooltip, properties from reflection?

            //if name of changed is null it does magic to change all, otherwise it only does one.
            switch (propertyChangedEventArgs?.PropertyName)
            {
            case null:
                blnUpdateAll = true;
                goto case nameof(Skill.DisplayPool);

            case nameof(Skill.DisplayPool):
                lblModifiedRating.Text        = _objSkill.DisplayOtherAttribute(_objAttributeActive.Abbrev);
                lblModifiedRating.ToolTipText = _objSkill.CompileDicepoolTooltip(_objAttributeActive.Abbrev);
                if (blnUpdateAll)
                {
                    goto case nameof(Skill.Default);
                }
                break;

            case nameof(Skill.Default):
                lblName.Font = !_objSkill.Default ? _fntItalicName : _fntNormalName;
                if (blnUpdateAll)
                {
                    goto case nameof(Skill.CGLSpecializations);
                }
                break;

            case nameof(Skill.CGLSpecializations):
                if (cboSpec?.Visible == true)
                {
                    string strOldSpec = cboSpec.Text;
                    cboSpec.BeginUpdate();
                    cboSpec.PopulateWithListItems(_objSkill.CGLSpecializations);
                    if (string.IsNullOrEmpty(strOldSpec))
                    {
                        cboSpec.SelectedIndex = -1;
                    }
                    else
                    {
                        cboSpec.SelectedValue = strOldSpec;
                        if (cboSpec.SelectedIndex == -1)
                        {
                            cboSpec.Text = strOldSpec;
                        }
                    }
                    cboSpec.EndUpdate();
                }
                break;
            }
        }
Пример #2
0
        private void Skill_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            bool blnAll = false;

            switch (e?.PropertyName)
            {
            case null:
                blnAll = true;
                goto case nameof(Skill.CGLSpecializations);

            case nameof(Skill.CGLSpecializations):
                if (cboSpec != null)
                {
                    string strOldSpec = _skill.CGLSpecializations.Count != 0 ? cboSpec.SelectedItem?.ToString() : cboSpec.Text;
                    cboSpec.BeginUpdate();
                    cboSpec.PopulateWithListItems(_skill.CGLSpecializations);
                    cboSpec.MaxDropDownItems = Math.Max(1, _skill.CGLSpecializations.Count);
                    if (string.IsNullOrEmpty(strOldSpec))
                    {
                        cboSpec.SelectedIndex = -1;
                    }
                    else
                    {
                        cboSpec.SelectedValue = strOldSpec;
                        if (cboSpec.SelectedIndex == -1)
                        {
                            cboSpec.Text = strOldSpec;
                        }
                    }
                    cboSpec.EndUpdate();
                }
                if (blnAll)
                {
                    goto case nameof(KnowledgeSkill.WriteableName);
                }
                break;

            case nameof(KnowledgeSkill.WriteableName):
                if (!_blnUpdatingName)
                {
                    cboName.Text = _skill.WriteableName;
                }
                if (blnAll)
                {
                    goto case nameof(Skill.IsNativeLanguage);
                }
                break;

            case nameof(Skill.IsNativeLanguage):
                if (chkNativeLanguage != null)
                {
                    chkNativeLanguage.Enabled = _skill.IsNativeLanguage || _skill.CharacterObject.SkillsSection.HasAvailableNativeLanguageSlots;
                }
                break;
            }
        }
Пример #3
0
        public KnowledgeSkillControl(KnowledgeSkill objSkill)
        {
            if (objSkill == null)
            {
                return;
            }
            _objSkill = objSkill;
            InitializeComponent();
            SuspendLayout();
            tlpMain.SuspendLayout();
            tlpMiddle.SuspendLayout();
            try
            {
                lblModifiedRating.DoOneWayDataBinding("Text", objSkill, nameof(KnowledgeSkill.DisplayPool));
                lblModifiedRating.DoOneWayDataBinding("ToolTipText", objSkill, nameof(KnowledgeSkill.PoolToolTip));

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

                cboType.BeginUpdate();
                cboType.PopulateWithListItems(objSkill.CharacterObject.SkillsSection.MyKnowledgeTypes);
                cboType.DoDataBinding("SelectedValue", objSkill, nameof(KnowledgeSkill.Type));
                cboType.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.AllowTypeChange));
                cboType.EndUpdate();

                lblName.DoOneWayNegatableDataBinding("Visible", objSkill, nameof(Skill.AllowNameChange));
                lblName.DoOneWayDataBinding("Text", objSkill, nameof(KnowledgeSkill.WritableName));
                lblName.DoOneWayDataBinding("ForeColor", objSkill, nameof(Skill.PreferredColor));

                cboName.BeginUpdate();
                cboName.PopulateWithListItems(objSkill.CharacterObject.SkillsSection.MyDefaultKnowledgeSkills);
                cboName.SelectedIndex = -1;
                cboName.Text          = objSkill.WritableName;
                cboName.DoOneWayDataBinding("Visible", objSkill, nameof(Skill.AllowNameChange));
                cboName.EndUpdate();
                _blnUpdatingName    = false;
                _tmrNameChangeTimer = new Timer {
                    Interval = 1000
                };
                _tmrNameChangeTimer.Tick += NameChangeTimer_Tick;

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

                    lblRating.DoOneWayNegatableDataBinding("Visible", objSkill, nameof(KnowledgeSkill.IsNativeLanguage));
                    lblRating.DoOneWayDataBinding("Text", objSkill, nameof(Skill.Rating));

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

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

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

                    lblSpec.DoOneWayDataBinding("Text", objSkill, nameof(Skill.CurrentDisplaySpecialization));

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

                    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", objSkill.CharacterObject.SkillsSection,
                                                 nameof(SkillsSection.HasKnowledgePoints));
                    nudSkill.DoOneWayDataBinding("Enabled", objSkill, nameof(KnowledgeSkill.AllowUpgrade));
                    nudSkill.DoDataBinding("Value", objSkill, nameof(Skill.Base));
                    nudSkill.InterceptMouseWheel = GlobalSettings.InterceptMode;
                    nudKarma.DoOneWayDataBinding("Enabled", objSkill, nameof(KnowledgeSkill.AllowUpgrade));
                    nudKarma.DoDataBinding("Value", objSkill, nameof(Skill.Karma));
                    nudKarma.InterceptMouseWheel = GlobalSettings.InterceptMode;

                    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, 4, 3, 4),
                        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,
                        Margin             = new Padding(3, 4, 3, 4),
                        Name = "chkKarma",
                        UseVisualStyleBackColor = true
                    };

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

                    cboSpec.BeginUpdate();
                    cboSpec.PopulateWithListItems(objSkill.CGLSpecializations);
                    cboSpec.EndUpdate();
                    cboSpec.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanHaveSpecs));
                    cboSpec.Text         = objSkill.CurrentDisplaySpecialization;
                    cboSpec.TextChanged += cboSpec_TextChanged;
                    _blnUpdatingSpec     = false;
                    _tmrSpecChangeTimer  = new Timer {
                        Interval = 1000
                    };
                    _tmrSpecChangeTimer.Tick += SpecChangeTimer_Tick;

                    chkKarma.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanHaveSpecs));
                    chkKarma.DoDataBinding("Checked", objSkill, nameof(Skill.BuyWithKarma));

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

                    // Hacky way of fixing a weird UI issue caused by items of a combobox only being populated from the DataSource after the combobox is added
                    _blnUpdatingSpec = true;
                    cboSpec.Text     = objSkill.CurrentDisplaySpecialization;
                    _blnUpdatingSpec = false;
                }

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

                AdjustForDpi();
                this.UpdateLightDarkMode();
                this.TranslateWinForm(blnDoResumeLayout: false);
            }
            finally
            {
                tlpMiddle.ResumeLayout();
                tlpMain.ResumeLayout();
                ResumeLayout(true);
                objSkill.PropertyChanged += Skill_PropertyChanged;
                objSkill.CharacterObject.SkillsSection.PropertyChanged += OnSkillsSectionPropertyChanged;
            }
        }
Пример #4
0
        private void Skill_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            bool blnAll = false;

            switch (e?.PropertyName)
            {
            case null:
                blnAll = true;
                goto case nameof(Skill.CGLSpecializations);

            case nameof(Skill.CGLSpecializations):
                if (cboSpec != null)
                {
                    string strOldSpec = _objSkill.CGLSpecializations.Count != 0 ? cboSpec.SelectedItem?.ToString() : cboSpec.Text;
                    IReadOnlyList <ListItem> lstSpecializations = _objSkill.CGLSpecializations;
                    cboSpec.QueueThreadSafe(() =>
                    {
                        _blnUpdatingSpec = true;
                        cboSpec.BeginUpdate();
                        cboSpec.PopulateWithListItems(lstSpecializations);
                        if (string.IsNullOrEmpty(strOldSpec))
                        {
                            cboSpec.SelectedIndex = -1;
                        }
                        else
                        {
                            cboSpec.SelectedValue = strOldSpec;
                            if (cboSpec.SelectedIndex == -1)
                            {
                                cboSpec.Text = strOldSpec;
                            }
                        }
                        cboSpec.EndUpdate();
                        _blnUpdatingSpec = false;
                    });
                }
                if (blnAll)
                {
                    goto case nameof(KnowledgeSkill.WritableName);
                }
                break;

            case nameof(KnowledgeSkill.WritableName):
                if (!_blnUpdatingName)
                {
                    string strWritableName = _objSkill.WritableName;
                    cboName.QueueThreadSafe(() =>
                    {
                        _blnUpdatingName = true;
                        cboName.Text     = strWritableName;
                        _blnUpdatingName = false;
                    });
                }
                if (blnAll)
                {
                    goto case nameof(Skill.TopMostDisplaySpecialization);
                }
                break;

            case nameof(KnowledgeSkill.TopMostDisplaySpecialization):
                if (!_blnUpdatingSpec)
                {
                    string strDisplaySpec = _objSkill.TopMostDisplaySpecialization;
                    cboSpec.QueueThreadSafe(() =>
                    {
                        _blnUpdatingSpec = true;
                        cboSpec.Text     = strDisplaySpec;
                        _blnUpdatingSpec = false;
                    });
                }
                if (blnAll)
                {
                    goto case nameof(Skill.IsNativeLanguage);
                }
                break;

            case nameof(Skill.IsNativeLanguage):
                if (chkNativeLanguage != null)
                {
                    bool blnEnabled = _objSkill.IsNativeLanguage ||
                                      _objSkill.CharacterObject.SkillsSection.HasAvailableNativeLanguageSlots;
                    chkNativeLanguage.QueueThreadSafe(() => chkNativeLanguage.Enabled = blnEnabled);
                }
                break;
            }
        }
Пример #5
0
        public SkillControl(Skill objSkill)
        {
            if (objSkill == null)
            {
                return;
            }
            _objSkill           = objSkill;
            _objAttributeActive = objSkill.AttributeObject;
            if (_objAttributeActive != null)
            {
                _objAttributeActive.PropertyChanged += Attribute_PropertyChanged;
            }
            InitializeComponent();
            SuspendLayout();
            pnlAttributes.SuspendLayout();
            tlpMain.SuspendLayout();
            tlpRight.SuspendLayout();
            try
            {
                //Display
                _fntNormalName = lblName.Font;
                _fntItalicName = new Font(_fntNormalName, FontStyle.Italic);
                _fntNormal     = btnAttribute.Font;
                _fntItalic     = new Font(_fntNormal, FontStyle.Italic);

                if (!_objSkill.Default)
                {
                    lblName.Font = _fntItalicName;
                }
                lblName.DoOneWayDataBinding("Text", objSkill, nameof(Skill.CurrentDisplayName));
                lblName.DoOneWayDataBinding("ForeColor", objSkill, nameof(Skill.PreferredColor));
                lblName.DoOneWayDataBinding("ToolTipText", objSkill, nameof(Skill.HtmlSkillToolTip));

                btnAttribute.DoOneWayDataBinding("Text", objSkill, nameof(Skill.DisplayAttribute));

                RefreshPoolTooltipAndDisplay();

                // Creating controls outside of the designer saves on handles if the controls would be invisible anyway
                if (objSkill.AllowDelete) // For active skills, can only change by going from Create to Career mode, so no databinding necessary
                {
                    cmdDelete = new Button
                    {
                        AutoSize                = true,
                        AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                        Dock                    = DockStyle.Fill,
                        Margin                  = new Padding(3, 0, 3, 0),
                        Name                    = "cmdDelete",
                        Tag                     = "String_Delete",
                        Text                    = "Delete",
                        UseVisualStyleBackColor = true
                    };
                    cmdDelete.Click += cmdDelete_Click;
                    tlpRight.Controls.Add(cmdDelete, 4, 0);
                }

                if (objSkill.CharacterObject.Created)
                {
                    lblCareerRating = new Label
                    {
                        Anchor    = AnchorStyles.Right,
                        AutoSize  = true,
                        Margin    = new Padding(3, 6, 3, 6),
                        Name      = "lblCareerRating",
                        Text      = "00",
                        TextAlign = ContentAlignment.MiddleRight
                    };
                    btnCareerIncrease = new ButtonWithToolTip
                    {
                        Anchor                  = AnchorStyles.Right,
                        AutoSize                = true,
                        AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                        ImageDpi96              = Resources.add,
                        ImageDpi192             = Resources.add1,
                        MinimumSize             = new Size(24, 24),
                        Name                    = "btnCareerIncrease",
                        Padding                 = new Padding(1),
                        UseVisualStyleBackColor = true
                    };
                    btnCareerIncrease.Click += btnCareerIncrease_Click;

                    lblCareerRating.DoOneWayDataBinding("Text", objSkill, nameof(Skill.Rating));
                    btnCareerIncrease.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanUpgradeCareer));
                    btnCareerIncrease.DoOneWayDataBinding("ToolTipText", objSkill, nameof(Skill.UpgradeToolTip));

                    tlpMain.Controls.Add(lblCareerRating, 2, 0);
                    tlpMain.Controls.Add(btnCareerIncrease, 3, 0);

                    btnAddSpec = new ButtonWithToolTip
                    {
                        Anchor                  = AnchorStyles.Right,
                        AutoSize                = true,
                        AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                        ImageDpi96              = Resources.add,
                        ImageDpi192             = Resources.add1,
                        MinimumSize             = new Size(24, 24),
                        Name                    = "btnAddSpec",
                        Padding                 = new Padding(1),
                        UseVisualStyleBackColor = true
                    };
                    btnAddSpec.Click += btnAddSpec_Click;
                    lblCareerSpec     = new Label
                    {
                        Anchor    = AnchorStyles.Left,
                        AutoSize  = true,
                        Margin    = new Padding(3, 6, 3, 6),
                        Name      = "lblCareerSpec",
                        Text      = "[Specializations]",
                        TextAlign = ContentAlignment.MiddleLeft
                    };
                    lblCareerSpec.DoOneWayDataBinding("Text", objSkill, nameof(Skill.CurrentDisplaySpecialization));
                    btnAddSpec.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanAffordSpecialization));
                    btnAddSpec.DoOneWayDataBinding("Visible", objSkill, nameof(Skill.CanHaveSpecs));
                    btnAddSpec.DoOneWayDataBinding("ToolTipText", objSkill, nameof(Skill.AddSpecToolTip));

                    tlpRight.Controls.Add(lblCareerSpec, 0, 0);
                    tlpRight.Controls.Add(btnAddSpec, 1, 0);

                    using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool,
                                                                      out List <ListItem> lstAttributeItems))
                    {
                        foreach (string strLoopAttribute in AttributeSection.AttributeStrings)
                        {
                            if (strLoopAttribute == "MAGAdept")
                            {
                                if (!objSkill.CharacterObject.Settings.MysAdeptSecondMAGAttribute)
                                {
                                    continue;
                                }
                                lstAttributeItems.Add(new ListItem(strLoopAttribute, LanguageManager.MAGAdeptString()));
                            }
                            else
                            {
                                string strAttributeShort = LanguageManager.GetString(
                                    "String_Attribute" + strLoopAttribute + "Short", GlobalSettings.Language, false);
                                lstAttributeItems.Add(new ListItem(strLoopAttribute,
                                                                   !string.IsNullOrEmpty(strAttributeShort)
                                                                       ? strAttributeShort
                                                                       : strLoopAttribute));
                            }
                        }

                        cboSelectAttribute = new ElasticComboBox
                        {
                            Dock              = DockStyle.Fill,
                            DropDownStyle     = ComboBoxStyle.DropDownList,
                            FormattingEnabled = true,
                            Margin            = new Padding(3, 0, 3, 0),
                            Name              = "cboSelectAttribute"
                        };
                        cboSelectAttribute.PopulateWithListItems(lstAttributeItems);
                        cboSelectAttribute.SelectedValue   = _objSkill.AttributeObject.Abbrev;
                        cboSelectAttribute.DropDownClosed += cboSelectAttribute_Closed;
                        pnlAttributes.Controls.Add(cboSelectAttribute);
                    }
                }
                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"
                    };

                    // Trick to make it seem like the button is a label (+ onclick method not doing anything in Create mode)
                    btnAttribute.FlatAppearance.MouseDownBackColor = Color.Transparent;
                    btnAttribute.FlatAppearance.MouseOverBackColor = Color.Transparent;

                    nudSkill.DoOneWayDataBinding("Visible", objSkill.CharacterObject,
                                                 nameof(objSkill.CharacterObject.EffectiveBuildMethodUsesPriorityTables));
                    nudSkill.DoDataBinding("Value", objSkill, nameof(Skill.Base));
                    nudSkill.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.BaseUnlocked));
                    nudSkill.InterceptMouseWheel = GlobalSettings.InterceptMode;
                    nudKarma.DoDataBinding("Value", objSkill, nameof(Skill.Karma));
                    nudKarma.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.KarmaUnlocked));
                    nudKarma.InterceptMouseWheel = GlobalSettings.InterceptMode;

                    tlpMain.Controls.Add(nudSkill, 2, 0);
                    tlpMain.Controls.Add(nudKarma, 3, 0);

                    if (objSkill.IsExoticSkill)
                    {
                        lblCareerSpec = new Label
                        {
                            Anchor    = AnchorStyles.Left,
                            AutoSize  = true,
                            Margin    = new Padding(3, 6, 3, 6),
                            Name      = "lblCareerSpec",
                            Text      = "[Specializations]",
                            TextAlign = ContentAlignment.MiddleLeft
                        };
                        lblCareerSpec.DoOneWayDataBinding("Text", objSkill, nameof(Skill.CurrentDisplaySpecialization));
                        tlpRight.Controls.Add(lblCareerSpec, 0, 0);
                    }
                    else
                    {
                        cboSpec = new ElasticComboBox
                        {
                            Anchor            = AnchorStyles.Left | AnchorStyles.Right,
                            AutoCompleteMode  = AutoCompleteMode.Suggest,
                            FormattingEnabled = true,
                            Margin            = new Padding(3, 0, 3, 0),
                            Name    = "cboSpec",
                            Sorted  = true,
                            TabStop = false
                        };
                        cboSpec.PopulateWithListItems(objSkill.CGLSpecializations);
                        cboSpec.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanHaveSpecs));
                        cboSpec.Text         = objSkill.CurrentDisplaySpecialization;
                        cboSpec.TextChanged += cboSpec_TextChanged;
                        _blnUpdatingSpec     = false;
                        _tmrSpecChangeTimer  = new Timer {
                            Interval = 1000
                        };
                        _tmrSpecChangeTimer.Tick += SpecChangeTimer_Tick;
                        chkKarma = new ColorableCheckBox(components)
                        {
                            Anchor             = AnchorStyles.Left,
                            AutoSize           = true,
                            DefaultColorScheme = true,
                            Margin             = new Padding(3, 4, 3, 4),
                            Name = "chkKarma",
                            UseVisualStyleBackColor = true
                        };
                        chkKarma.DoOneWayDataBinding("Visible", objSkill.CharacterObject,
                                                     nameof(objSkill.CharacterObject.EffectiveBuildMethodUsesPriorityTables));
                        chkKarma.DoDataBinding("Checked", objSkill, nameof(Skill.BuyWithKarma));
                        chkKarma.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanHaveSpecs));
                        tlpRight.Controls.Add(cboSpec, 0, 0);
                        tlpRight.Controls.Add(chkKarma, 1, 0);

                        // Hacky way of fixing a weird UI issue caused by items of a combobox only being populated from the DataSource after the combobox is added
                        _blnUpdatingSpec = true;
                        cboSpec.Text     = objSkill.CurrentDisplaySpecialization;
                        _blnUpdatingSpec = false;
                    }
                }

                this.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.Enabled));
                this.DoOneWayDataBinding("BackColor", objSkill, nameof(Skill.PreferredControlColor));

                AdjustForDpi();
                this.UpdateLightDarkMode();
                this.TranslateWinForm(blnDoResumeLayout: false);

                foreach (ToolStripItem tssItem in cmsSkillLabel.Items)
                {
                    tssItem.UpdateLightDarkMode();
                    tssItem.TranslateToolStripItemsRecursively();
                }
            }
            finally
            {
                _blnLoading = false;
                tlpRight.ResumeLayout();
                tlpMain.ResumeLayout();
                pnlAttributes.ResumeLayout();
                ResumeLayout(true);
                _objSkill.PropertyChanged += Skill_PropertyChanged;
            }
        }
Пример #6
0
        private void Skill_PropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
        {
            if (_blnLoading)
            {
                return;
            }

            bool blnUpdateAll = false;

            //I learned something from this but i'm not sure it is a good solution
            //scratch that, i'm sure it is a bad solution. (Tooltip manager from tooltip, properties from reflection?

            //if name of changed is null it does magic to change all, otherwise it only does one.
            switch (propertyChangedEventArgs?.PropertyName)
            {
            case null:
                blnUpdateAll = true;
                goto case nameof(Skill.DisplayPool);

            case nameof(Skill.DisplayPool):
                RefreshPoolTooltipAndDisplay();
                if (blnUpdateAll)
                {
                    goto case nameof(Skill.Default);
                }
                break;

            case nameof(Skill.Default):
                lblName.Font = !_objSkill.Default ? _fntItalicName : _fntNormalName;
                if (blnUpdateAll)
                {
                    goto case nameof(Skill.DefaultAttribute);
                }
                break;

            case nameof(Skill.DefaultAttribute):
                if (cboSelectAttribute != null)
                {
                    cboSelectAttribute.SelectedValue = _objSkill.AttributeObject.Abbrev;
                    cboSelectAttribute_Closed(this, EventArgs.Empty);
                }
                else
                {
                    AttributeActive = _objSkill.AttributeObject;
                }
                if (blnUpdateAll)
                {
                    goto case nameof(Skill.TopMostDisplaySpecialization);
                }
                break;

            case nameof(Skill.TopMostDisplaySpecialization):
                if (!_blnUpdatingSpec)
                {
                    string strDisplaySpec = _objSkill.TopMostDisplaySpecialization;
                    cboSpec.QueueThreadSafe(() =>
                    {
                        _blnUpdatingSpec = true;
                        cboSpec.Text     = strDisplaySpec;
                        _blnUpdatingSpec = false;
                    });
                }
                if (blnUpdateAll)
                {
                    goto case nameof(Skill.CGLSpecializations);
                }
                break;

            case nameof(Skill.CGLSpecializations):
                if (cboSpec?.Visible == true)
                {
                    string strOldSpec = cboSpec.Text;
                    IReadOnlyList <ListItem> lstSpecializations = _objSkill.CGLSpecializations;
                    cboSpec.QueueThreadSafe(() =>
                    {
                        _blnUpdatingSpec = true;
                        cboSpec.PopulateWithListItems(lstSpecializations);
                        if (string.IsNullOrEmpty(strOldSpec))
                        {
                            cboSpec.SelectedIndex = -1;
                        }
                        else
                        {
                            cboSpec.SelectedValue = strOldSpec;
                            if (cboSpec.SelectedIndex == -1)
                            {
                                cboSpec.Text = strOldSpec;
                            }
                        }
                        _blnUpdatingSpec = false;
                    });
                }
                break;
            }
        }
Пример #7
0
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            if (skill == null)
            {
                return;
            }
            _skill = skill;
            _tmrNameChangeTimer = new Timer {
                Interval = 1000
            };
            _tmrNameChangeTimer.Tick += NameChangeTimer_Tick;
            InitializeComponent();
            SuspendLayout();
            tlpMain.SuspendLayout();
            tlpMiddle.SuspendLayout();
            try
            {
                lblModifiedRating.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.DisplayPool));
                lblModifiedRating.DoOneWayDataBinding("ToolTipText", _skill, nameof(KnowledgeSkill.PoolToolTip));

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

                cboType.BeginUpdate();
                cboType.PopulateWithListItems(_skill.CharacterObject.SkillsSection.MyKnowledgeTypes);
                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.PopulateWithListItems(_skill.CharacterObject.SkillsSection.MyDefaultKnowledgeSkills);
                cboName.SelectedIndex = -1;
                cboName.Text          = _skill.WriteableName;
                cboName.DoDatabinding("Visible", _skill, nameof(Skill.AllowNameChange));
                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.DoDatabinding("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.DoDatabinding("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.DoDatabinding("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.DoDatabinding("Visible", _skill, nameof(Skill.IsLanguage));
                    chkNativeLanguage.Enabled = _skill.IsNativeLanguage ||
                                                _skill.CharacterObject.SkillsSection.HasAvailableNativeLanguageSlots;
                    chkNativeLanguage.DoDatabinding("Checked", _skill, nameof(Skill.IsNativeLanguage));

                    cboSpec.BeginUpdate();
                    cboSpec.PopulateWithListItems(_skill.CGLSpecializations);
                    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));
                }

                KnowledgeSkillControl_DpiChangedAfterParent(null, EventArgs.Empty);
                this.UpdateLightDarkMode();
                this.TranslateWinForm(string.Empty, false);
            }
            finally
            {
                tlpMiddle.ResumeLayout();
                tlpMain.ResumeLayout();
                ResumeLayout(true);
                _skill.PropertyChanged += Skill_PropertyChanged;
                _skill.CharacterObject.SkillsSection.PropertyChanged += OnSkillsSectionPropertyChanged;
            }
        }