Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/minor update 1 #444

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/TQVaultAE.Data/PlayerCollectionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void CommitPlayerInfo(PlayerCollection pc, PlayerInfo playerInfo)
pc.PlayerInfo.CurrentLevel = playerInfo.CurrentLevel;
pc.PlayerInfo.MasteriesAllowed = playerInfo.MasteriesAllowed;
pc.PlayerInfo.MasteriesResetRequiered = playerInfo.MasteriesResetRequiered;
pc.PlayerInfo.ResetMasteryAndKeepSkillsFlag = playerInfo.ResetMasteryAndKeepSkillsFlag;
pc.PlayerInfo.CurrentXP = playerInfo.CurrentXP;
pc.PlayerInfo.DifficultyUnlocked = playerInfo.DifficultyUnlocked;
pc.PlayerInfo.AttributesPoints = playerInfo.AttributesPoints;
Expand Down
12 changes: 11 additions & 1 deletion src/TQVaultAE.Domain/Entities/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PlayerInfo
|| this.MasteriesResetRequiered;

public bool MasteriesResetRequiered { get; set; }
public bool ResetMasteryAndKeepSkillsFlag { get; set; }

/// <summary>
/// Skills removed during <see cref="ResetMasteries"/>
Expand Down Expand Up @@ -111,7 +112,16 @@ public bool ResetMasteries()
.Where(sk => sk.skillName.StartsWith(recBase, noCase))
);
}
this.SkillRecordList.RemoveAll(s => this._SkillRecordListRemoved.Contains(s));

if (ResetMasteryAndKeepSkillsFlag)
{
var masterySkills = this._SkillRecordListRemoved.Where(sk => sk.skillName.EndsWith("Mastery.dbr", StringComparison.InvariantCultureIgnoreCase)).ToList();
this.SkillRecordList.RemoveAll(s => masterySkills.Contains(s));
}
else
{
this.SkillRecordList.RemoveAll(s => this._SkillRecordListRemoved.Contains(s));
}
this.Modified = true;
}
return isActive;
Expand Down
2 changes: 2 additions & 0 deletions src/TQVaultAE.Domain/Entities/PlayerLevel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace TQVaultAE.Domain.Entities
{
Expand Down Expand Up @@ -160,5 +161,6 @@ public static int GetLevelMinXP(int level)
}
throw new ArgumentOutOfRangeException("Level does not exist or is not supported");
}

}
}
269 changes: 180 additions & 89 deletions src/TQVaultAE.GUI/CharacterEditDialog.Designer.cs

Large diffs are not rendered by default.

62 changes: 43 additions & 19 deletions src/TQVaultAE.GUI/CharacterEditDialog.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Collections;
using System.Windows.Input;

namespace TQVaultAE.GUI
{
using System;
Expand Down Expand Up @@ -26,6 +29,7 @@ private struct DifficultData

private readonly ILogger Log;
private readonly ITranslationService TranslationService;
private static readonly char[] acceptedNumericChars = "1234567890\b".ToCharArray();

internal PlayerCollection PlayerCollection { get; set; }

Expand All @@ -41,13 +45,14 @@ public CharacterEditDialog(IServiceProvider serviceProvider, ITranslationService

#region Apply custom font

this.ResetMasteriesScalingButton.Font =
this.ResetMasteriesScalingButton.Font =
this.ResetAttributesScalingButton.Font =
this.ok.Font =
this.ResetOnlyMasteriesScalingButton.Font =
this.ok.Font =
this.cancel.Font = FontService.GetFontLight(12F);

this.Font = FontService.GetFontLight(11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

new[] {
this.attribGroupBox,
this.levelingGroupBox,
Expand All @@ -64,9 +69,15 @@ public CharacterEditDialog(IServiceProvider serviceProvider, ITranslationService
this.cancel.Text = Resources.GlobalCancel;
this.ok.Text = Resources.GlobalOK;
this.ResetMasteriesScalingButton.Text = Resources.ResetMasteriesButton;
this.ResetOnlyMasteriesScalingButton.Text = Resources.ResetOnlyMasteriesButton;
this.ResetAttributesScalingButton.Text = Resources.ResetAttributesButton;
}

private void SetDifficultly()
{
var pd = PlayerCollection.PlayerInfo.DifficultyUnlocked;
difficultlyComboBox.SelectedIndex = Enumerable.Range(0, 2).Contains(pd) ? pd : 0;
}

/// <summary>
/// Cancel button handler
Expand All @@ -75,10 +86,6 @@ public CharacterEditDialog(IServiceProvider serviceProvider, ITranslationService
/// <param name="e">EventArgs data</param>
private void CancelButton_Click(object sender, EventArgs e) => this.Close();

/// <summary>
///
/// </summary>
/// <param name="playerInfo"></param>
private void UpdateMoneySituation(PlayerInfo playerInfoSrc, PlayerInfo playerInfoDst)
{
if (playerInfoDst.DifficultyUnlocked != playerInfoSrc.DifficultyUnlocked)
Expand Down Expand Up @@ -110,6 +117,7 @@ private void UpdatePlayerInfo(bool mustResetAttributes = false, bool masteriesRe
{
if (!Config.UserSettings.Default.AllowCharacterEdit) return;
if (PlayerCollection.PlayerInfo == null) return;

try
{
var playerInfo = new PlayerInfo();
Expand All @@ -123,11 +131,11 @@ private void UpdatePlayerInfo(bool mustResetAttributes = false, bool masteriesRe
playerInfo.MasteriesAllowed = 2;

playerInfo.CurrentXP = int.Parse(xpTextBox.Text);
playerInfo.Money = PlayerCollection.PlayerInfo.Money > 0 ? PlayerCollection.PlayerInfo.Money : 0;
playerInfo.Money = Math.Max(0, Math.Abs(int.Parse(moneyTextBox.Text)));

if (difficultlyComboBox.Enabled)
playerInfo.DifficultyUnlocked = difficultlyComboBox.SelectedIndex;
else
else
playerInfo.DifficultyUnlocked = PlayerCollection.PlayerInfo.DifficultyUnlocked;

playerInfo.SkillPoints = Convert.ToInt32(skillPointsNumericUpDown.Value);
Expand Down Expand Up @@ -158,6 +166,7 @@ private void UpdatePlayerInfo(bool mustResetAttributes = false, bool masteriesRe
}

playerInfo.MasteriesResetRequiered = masteriesResetRequired;
playerInfo.ResetMasteryAndKeepSkillsFlag = this._OnlyMasteriesResetRequiered;

if (playerInfo.MustResetMasteries)
{
Expand All @@ -167,7 +176,9 @@ private void UpdatePlayerInfo(bool mustResetAttributes = false, bool masteriesRe
playerInfo.SkillPoints += playerInfo.ReleasedSkillPoints;
playerInfo.Class = string.Empty;
}

UpdateMoneySituation(PlayerCollection.PlayerInfo, playerInfo);

PlayerCollectionProvider.CommitPlayerInfo(PlayerCollection, playerInfo);

this.Close();
Expand All @@ -180,6 +191,7 @@ private void UpdatePlayerInfo(bool mustResetAttributes = false, bool masteriesRe
}

private bool _loaded = false;
private bool _OnlyMasteriesResetRequiered;

private struct TagData
{
Expand All @@ -199,6 +211,7 @@ private void CharacterEditDlg_Load(object sender, EventArgs e)
IntelligenceLabel.Text = Resources.CEIntelligence;
healthLabel.Text = Resources.CEHealth;
manaLabel.Text = Resources.CEMana;
moneyLabel.Text = Resources.CEMoney;
levelLabel.Text = Resources.CELevel;
xpLabel.Text = Resources.CEXp;
attributeLabel.Text = Resources.CEAttributePoints;
Expand Down Expand Up @@ -267,6 +280,8 @@ private void CharacterEditDlg_Load(object sender, EventArgs e)
manacUpDown.Value = PlayerCollection.PlayerInfo.BaseMana;
manacUpDown.Tag = attrHMTag;

moneyTextBox.Text = PlayerCollection.PlayerInfo.Money.ToString();

if (PlayerCollection.PlayerInfo.CurrentLevel > Convert.ToInt32(levelNumericUpDown.Maximum))
levelNumericUpDown.Maximum = PlayerCollection.PlayerInfo.CurrentLevel;

Expand All @@ -289,6 +304,8 @@ private void CharacterEditDlg_Load(object sender, EventArgs e)
difficultlyComboBox.Items.Add(new DifficultData { Text = TranslationService.TranslateDifficulty(1), Id = 1 });
difficultlyComboBox.Items.Add(new DifficultData { Text = TranslationService.TranslateDifficulty(2), Id = 2 });

SetDifficultly();

levelingCheckBox.Checked = false;

if (PlayerCollection.PlayerInfo.HasBeenInGame == 0)
Expand Down Expand Up @@ -373,23 +390,24 @@ private void LevelingCheckBox_CheckedChanged(object sender, EventArgs e)
if (sender == null) return;

var chkbx = (CheckBox)sender;
if (chkbx.Checked)
{
this.difficultlyComboBox.Enabled = true;
this.levelNumericUpDown.Enabled = true;
}
else
{
this.difficultlyComboBox.Enabled = false;
this.levelNumericUpDown.Enabled = false;
}

this.difficultlyComboBox.Enabled = chkbx.Checked;
this.levelNumericUpDown.Enabled = chkbx.Checked;
this.attributeNumericUpDown.Enabled = chkbx.Checked;
this.skillPointsNumericUpDown.Enabled = chkbx.Checked;
}

private void ResetMasteriesScalingButton_Click(object sender, EventArgs e)
{
UpdatePlayerInfo(masteriesResetRequired: true);
}

private void ResetOnlyMasteriesScalingButton_Click(object sender, EventArgs e)
{
if (!_OnlyMasteriesResetRequiered) _OnlyMasteriesResetRequiered = true;
UpdatePlayerInfo(masteriesResetRequired: true);
}

private void ResetAttributesScalingButton_Click(object sender, EventArgs e)
{
UpdatePlayerInfo(mustResetAttributes: true);
Expand All @@ -401,5 +419,11 @@ private void difficultlyComboBox_EnabledChanged(object sender, EventArgs e)
if (levelingCheckBox.Checked && difficultlyComboBox.Enabled)
difficultlyComboBox.SelectedIndex = PlayerCollection.PlayerInfo.DifficultyUnlocked;
}

private void moneyTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!acceptedNumericChars.Contains(e.KeyChar))
e.Handled = true;
}
}
}
Loading