Skip to content

Commit 335c44a

Browse files
committed
enhancement: character window and quest log
- simplifies extra buffs details into a button with tooltip details. - Weylon's review -> update tooltip on hover and initialization only. - To prevent duplicated code -> creates UpdateEquippedItems method.
1 parent 8574ac4 commit 335c44a

File tree

2 files changed

+64
-96
lines changed

2 files changed

+64
-96
lines changed

Intersect.Client.Core/Interface/Game/Character/CharacterWindow.cs

Lines changed: 63 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
using Intersect.Enums;
1010
using Intersect.Framework.Core.GameObjects.Items;
1111
using Intersect.Framework.Core.GameObjects.PlayerClass;
12-
using Intersect.GameObjects;
13-
using Intersect.Network.Packets.Server;
1412

1513
namespace Intersect.Client.Interface.Game.Character;
1614

@@ -71,40 +69,24 @@ public partial class CharacterWindow
7169
public int Y;
7270

7371
//Extra Buffs
72+
Button _detailsButton;
73+
7474
ClassDescriptor mPlayer;
7575

76-
Label mHpRegen;
77-
7876
long HpRegenAmount;
7977

80-
Label mManaRegen;
81-
8278
long ManaRegenAmount;
8379

84-
Label mLifeSteal;
85-
8680
int LifeStealAmount = 0;
8781

88-
Label mAttackSpeed;
89-
90-
Label mExtraExp;
91-
9282
int ExtraExpAmount = 0;
9383

94-
Label mLuck;
95-
9684
int LuckAmount = 0;
9785

98-
Label mTenacity;
99-
10086
int TenacityAmount = 0;
10187

102-
Label mCooldownReduction;
103-
10488
int CooldownAmount = 0;
10589

106-
Label mManaSteal;
107-
10890
int ManaStealAmount = 0;
10991

11092
//Init
@@ -168,18 +150,12 @@ public CharacterWindow(Canvas gameCanvas)
168150
Items[i].Setup();
169151
}
170152

171-
var extraBuffsLabel = new Label(mCharacterWindow, "ExtraBuffsLabel");
172-
extraBuffsLabel.SetText(Strings.Character.ExtraBuffs);
173-
174-
mHpRegen = new Label(mCharacterWindow, "HpRegen");
175-
mManaRegen = new Label(mCharacterWindow, "ManaRegen");
176-
mLifeSteal = new Label(mCharacterWindow, "Lifesteal");
177-
mAttackSpeed = new Label(mCharacterWindow, "AttackSpeed");
178-
mExtraExp = new Label(mCharacterWindow, "ExtraExp");
179-
mLuck = new Label(mCharacterWindow, "Luck");
180-
mTenacity = new Label(mCharacterWindow, "Tenacity");
181-
mCooldownReduction = new Label(mCharacterWindow, "CooldownReduction");
182-
mManaSteal = new Label(mCharacterWindow, "Manasteal");
153+
_detailsButton = new Button(mCharacterWindow, nameof(_detailsButton))
154+
{
155+
Text = Strings.Character.ExtraBuffDetails,
156+
};
157+
_detailsButton.HoverEnter += UpdateExtraBuffTooltip; // Update Tooltip on hover.
158+
UpdateExtraBuffTooltip(null, null); // Initial tooltip update.
183159

184160
mCharacterWindow.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
185161
}
@@ -213,7 +189,7 @@ void _addAttackBtn_Clicked(Base sender, MouseButtonState arguments)
213189
//Methods
214190
public void Update()
215191
{
216-
if (mCharacterWindow.IsHidden)
192+
if (mCharacterWindow.IsHidden || Globals.Me is null)
217193
{
218194
return;
219195
}
@@ -375,21 +351,31 @@ public void Update()
375351
mAddSpeedBtn.IsHidden =
376352
Globals.Me.StatPoints == 0 || Globals.Me.Stat[(int) Stat.Speed] == Options.Instance.Player.MaxStat;
377353

378-
UpdateExtraBuffs();
354+
UpdateEquippedItems();
355+
}
356+
357+
private void UpdateEquippedItems(bool updateExtraBuffs = false)
358+
{
359+
if (Globals.Me is not { } player)
360+
{
361+
return;
362+
}
379363

380364
for (var i = 0; i < Options.Instance.Equipment.Slots.Count; i++)
381365
{
382-
if (Globals.Me.MyEquipment[i] > -1 && Globals.Me.MyEquipment[i] < Options.Instance.Player.MaxInventory)
366+
if (player.MyEquipment[i] > -1 && player.MyEquipment[i] < Options.Instance.Player.MaxInventory)
383367
{
384-
if (Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId != Guid.Empty)
368+
if (player.Inventory[player.MyEquipment[i]].ItemId != Guid.Empty)
385369
{
386370
Items[i]
387371
.Update(
388-
Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId,
389-
Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemProperties
372+
player.Inventory[player.MyEquipment[i]].ItemId,
373+
player.Inventory[player.MyEquipment[i]].ItemProperties
390374
);
391-
392-
UpdateExtraBuffs(Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId);
375+
if (updateExtraBuffs)
376+
{
377+
UpdateExtraBuffs(player.Inventory[player.MyEquipment[i]].ItemId);
378+
}
393379
}
394380
else
395381
{
@@ -403,44 +389,11 @@ public void Update()
403389
}
404390
}
405391

406-
/// <summary>
407-
/// Update Extra Buffs Effects like hp/mana regen and items effect types
408-
/// </summary>
409-
public void UpdateExtraBuffs()
410-
{
411-
mPlayer = ClassDescriptor.Get(Globals.Me?.Class ?? Guid.Empty);
412-
413-
//Getting HP and Mana Regen
414-
if (mPlayer != null)
415-
{
416-
HpRegenAmount = mPlayer.VitalRegen[0];
417-
mHpRegen.SetText(Strings.Character.HealthRegen.ToString(HpRegenAmount));
418-
ManaRegenAmount = mPlayer.VitalRegen[1];
419-
mManaRegen.SetText(Strings.Character.ManaRegen.ToString(ManaRegenAmount));
420-
}
421-
422-
CooldownAmount = 0;
423-
LifeStealAmount = 0;
424-
TenacityAmount = 0;
425-
LuckAmount = 0;
426-
ExtraExpAmount = 0;
427-
ManaStealAmount = 0;
428-
429-
mLifeSteal.SetText(Strings.Character.Lifesteal.ToString(0));
430-
mExtraExp.SetText(Strings.Character.ExtraExp.ToString(0));
431-
mLuck.SetText(Strings.Character.Luck.ToString(0));
432-
mTenacity.SetText(Strings.Character.Tenacity.ToString(0));
433-
mCooldownReduction.SetText(Strings.Character.CooldownReduction.ToString(0));
434-
mManaSteal.SetText(Strings.Character.Manasteal.ToString(0));
435-
436-
mAttackSpeed.SetText(Strings.Character.AttackSpeed.ToString(Globals.Me.CalculateAttackTime() / 1000f));
437-
}
438-
439392
/// <summary>
440393
/// Update Extra Buffs Effects like hp/mana regen and items effect types
441394
/// </summary>
442395
/// <param name="itemId">Id of item to update extra buffs</param>
443-
public void UpdateExtraBuffs(Guid itemId)
396+
private void UpdateExtraBuffs(Guid itemId)
444397
{
445398
var item = ItemDescriptor.Get(itemId);
446399

@@ -449,23 +402,21 @@ public void UpdateExtraBuffs(Guid itemId)
449402
return;
450403
}
451404

452-
//Getting HP and Mana Regen
453-
if (item.VitalsRegen[0] != 0)
405+
//Getting HP and Mana Regen from items
406+
if (item.VitalsRegen[(int)Vital.Health] != 0)
454407
{
455-
HpRegenAmount += item.VitalsRegen[0];
456-
mHpRegen?.SetText(Strings.Character.HealthRegen.ToString(HpRegenAmount));
408+
HpRegenAmount += item.VitalsRegen[(int)Vital.Health];
457409
}
458410

459-
if (item.VitalsRegen[1] != 0)
411+
if (item.VitalsRegen[(int)Vital.Mana] != 0)
460412
{
461-
ManaRegenAmount += item.VitalsRegen[1];
462-
mManaRegen?.SetText(Strings.Character.ManaRegen.ToString(ManaRegenAmount));
413+
ManaRegenAmount += item.VitalsRegen[(int)Vital.Mana];
463414
}
464415

465-
//Getting extra buffs
416+
//Getting extra buffs from items
466417
if (item.Effects.Find(effect => effect.Type != ItemEffect.None && effect.Percentage > 0) != default)
467418
{
468-
foreach(var effect in item.Effects)
419+
foreach (var effect in item.Effects)
469420
{
470421
if (effect.Percentage <= 0)
471422
{
@@ -476,39 +427,56 @@ public void UpdateExtraBuffs(Guid itemId)
476427
{
477428
case ItemEffect.CooldownReduction:
478429
CooldownAmount += effect.Percentage;
479-
mCooldownReduction?.SetText(Strings.Character.CooldownReduction.ToString(CooldownAmount));
480-
481430
break;
482431
case ItemEffect.Lifesteal:
483432
LifeStealAmount += effect.Percentage;
484-
mLifeSteal?.SetText(Strings.Character.Lifesteal.ToString(LifeStealAmount));
485-
486433
break;
487434
case ItemEffect.Tenacity:
488435
TenacityAmount += effect.Percentage;
489-
mTenacity?.SetText(Strings.Character.Tenacity.ToString(TenacityAmount));
490-
491436
break;
492437
case ItemEffect.Luck:
493438
LuckAmount += effect.Percentage;
494-
mLuck?.SetText(Strings.Character.Luck.ToString(LuckAmount));
495-
496439
break;
497440
case ItemEffect.EXP:
498441
ExtraExpAmount += effect.Percentage;
499-
mExtraExp?.SetText(Strings.Character.ExtraExp.ToString(ExtraExpAmount));
500-
501442
break;
502443
case ItemEffect.Manasteal:
503444
ManaStealAmount += effect.Percentage;
504-
mManaSteal?.SetText(Strings.Character.Manasteal.ToString(ManaStealAmount));
505-
506445
break;
507446
}
508447
}
509448
}
510449
}
511450

451+
private void UpdateExtraBuffTooltip(Base? sender, EventArgs? arguments)
452+
{
453+
//Reset all values
454+
HpRegenAmount = mPlayer?.VitalRegen[(int)Vital.Health] ?? 0;
455+
ManaRegenAmount = mPlayer?.VitalRegen[(int)Vital.Mana] ?? 0;
456+
CooldownAmount = 0;
457+
LifeStealAmount = 0;
458+
TenacityAmount = 0;
459+
LuckAmount = 0;
460+
ExtraExpAmount = 0;
461+
ManaStealAmount = 0;
462+
463+
// Update extra buffs from equipped items
464+
UpdateEquippedItems(true);
465+
466+
// Update tooltip with the current extra buffs
467+
var tooltip = new System.Text.StringBuilder();
468+
tooltip.AppendLine(Strings.Character.HealthRegen.ToString(HpRegenAmount));
469+
tooltip.AppendLine(Strings.Character.ManaRegen.ToString(ManaRegenAmount));
470+
tooltip.AppendLine(Strings.Character.Lifesteal.ToString(LifeStealAmount));
471+
tooltip.AppendLine(Strings.Character.AttackSpeed.ToString(Globals.Me?.CalculateAttackTime() / 1000f));
472+
tooltip.AppendLine(Strings.Character.ExtraExp.ToString(ExtraExpAmount));
473+
tooltip.AppendLine(Strings.Character.Luck.ToString(LuckAmount));
474+
tooltip.AppendLine(Strings.Character.Tenacity.ToString(TenacityAmount));
475+
tooltip.AppendLine(Strings.Character.CooldownReduction.ToString(CooldownAmount));
476+
tooltip.AppendLine(Strings.Character.Manasteal.ToString(ManaStealAmount));
477+
_detailsButton.SetToolTipText(tooltip.ToString());
478+
}
479+
512480
/// <summary>
513481
/// Show the window
514482
/// </summary>

Intersect.Client.Core/Localization/Strings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public partial struct Character
637637
public static LocalizedString Equipment = @"Equipment:";
638638

639639
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
640-
public static LocalizedString ExtraBuffs = @"Extra Buffs";
640+
public static LocalizedString ExtraBuffDetails = @"Details";
641641

642642
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
643643
public static LocalizedString ExtraExp = @"Bonus EXP: {00}%";

0 commit comments

Comments
 (0)