Skip to content

Commit

Permalink
Update selection logic and label/level up property changes for active…
Browse files Browse the repository at this point in the history
… spells
  • Loading branch information
ethanmoffat committed Apr 13, 2022
1 parent 40bcd01 commit bbe6283
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 25 additions & 6 deletions EndlessClient/HUD/Panels/ActiveSpellsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ActiveSpellsPanel : XNAPanel, IHudPanel
private readonly ScrollBar _scrollBar;

private HashSet<IInventorySpell> _cachedSpells;
private ICharacterStats _cachedStats;
private bool _confirmedTraining;
private int _lastScrollOffset;
private Texture2D _activeSpellIcon;
Expand Down Expand Up @@ -196,6 +197,10 @@ protected override void OnUpdateControl(GameTime gameTime)
matchedSpell.MatchSome(childControl =>
{
childControl.InventorySpell = spell;
if (childControl.IsSelected)
{
_selectedSpellLevel.Text = spell.Level.ToString();
}
});
}

Expand Down Expand Up @@ -250,6 +255,19 @@ protected override void OnUpdateControl(GameTime gameTime)
UpdateSpellItemsForScroll();
}

if (_cachedStats != _characterProvider.MainCharacter.Stats && _activeSpellIcon != null)
{
_cachedStats = _characterProvider.MainCharacter.Stats;
var skillPoints = _cachedStats[CharacterStat.SkillPoints];
_totalSkillPoints.Text = skillPoints.ToString();

if (skillPoints == 0)
{
_levelUpButton1.Visible = false;
_levelUpButton2.Visible = false;
}
}

base.OnUpdateControl(gameTime);
}

Expand Down Expand Up @@ -328,18 +346,18 @@ private void LevelUp_Click(object sender, EventArgs args)

private void SetSelectedSpell(object sender, EventArgs e)
{
ClearSelectedSpell();

var spell = (SpellPanelItem)sender;

ClearSelectedSpell(exclude: spell);

var spellData = spell.SpellData;
if (spellData.Target == EOLib.IO.SpellTarget.Normal)
_statusLabelSetter.SetStatusLabel(EOResourceID.SKILLMASTER_WORD_SPELL, spellData.Name, EOResourceID.SPELL_WAS_SELECTED);
_statusLabelSetter.SetStatusLabel(EOResourceID.SKILLMASTER_WORD_SPELL, $"{spellData.Name} ", EOResourceID.SPELL_WAS_SELECTED);
else if (spellData.Target == EOLib.IO.SpellTarget.Group /*&& not in party*/) // todo: parties
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.SPELL_ONLY_WORKS_ON_GROUP);

_activeSpellIcon = NativeGraphicsManager.TextureFromResource(GFXTypes.SpellIcons, spellData.Icon);

_selectedSpellName.Text = spellData.Name;
_selectedSpellName.Visible = true;

Expand Down Expand Up @@ -412,7 +430,7 @@ private ISpellPanelItem CreateEmptySpell(int slot)
return emptyItem;
}

private void ClearSelectedSpell()
private void ClearSelectedSpell(params ISpellPanelItem[] exclude)
{
_activeSpellIcon = null;

Expand All @@ -423,9 +441,10 @@ private void ClearSelectedSpell()

_levelUpButton1.Visible = _levelUpButton2.Visible = false;

foreach (var item in _childItems.Where(x => x.IsSelected))
foreach (var item in _childItems.Where(x => x.IsSelected).Except(exclude))
item.IsSelected = false;
}

private void SwapFunctionKeySourceRectangles()
{
var tmpRect = _functionKeyRow2Source;
Expand Down
4 changes: 3 additions & 1 deletion EndlessClient/HUD/Spells/BaseSpellPanelItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public virtual bool IsSelected
set
{
_selected = value;
Selected?.Invoke(this, EventArgs.Empty);

if (_selected)
Selected?.Invoke(this, EventArgs.Empty);
}
}

Expand Down

0 comments on commit bbe6283

Please sign in to comment.