Skip to content

Commit b108fca

Browse files
enhancement: updates character window and quest log (#2742)
* (Aru) enhancement: character window and quest log - Simplifies extra buffs details into a button with tooltip details. - To prevent duplicated code -> creates UpdateEquippedItems method. * (Weylon) Review - Update tooltip on hover and initialization only. * (Weylon) equipment update cleanup + fix: equipment not showing when entering game --------- Co-authored-by: WeylonSantana <[email protected]>
1 parent 8574ac4 commit b108fca

File tree

3 files changed

+95
-130
lines changed

3 files changed

+95
-130
lines changed

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

Lines changed: 68 additions & 104 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,72 +351,45 @@ 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+
var invSlot = player.MyEquipment[i];
367+
if (invSlot < 0 || invSlot >= Options.Instance.Player.MaxInventory)
383368
{
384-
if (Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId != Guid.Empty)
385-
{
386-
Items[i]
387-
.Update(
388-
Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId,
389-
Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemProperties
390-
);
391-
392-
UpdateExtraBuffs(Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId);
393-
}
394-
else
395-
{
396-
Items[i].Update(Guid.Empty, mItemProperties);
397-
}
369+
Items[i].Update(Guid.Empty, mItemProperties);
370+
continue;
398371
}
399-
else
372+
373+
var item = player.Inventory[invSlot];
374+
if (item.ItemId == Guid.Empty)
400375
{
401376
Items[i].Update(Guid.Empty, mItemProperties);
377+
continue;
402378
}
403-
}
404-
}
405379

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));
380+
Items[i].Update(item.ItemId, item.ItemProperties);
381+
if (updateExtraBuffs)
382+
{
383+
UpdateExtraBuffs(item.ItemId);
384+
}
420385
}
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));
437386
}
438387

439388
/// <summary>
440389
/// Update Extra Buffs Effects like hp/mana regen and items effect types
441390
/// </summary>
442391
/// <param name="itemId">Id of item to update extra buffs</param>
443-
public void UpdateExtraBuffs(Guid itemId)
392+
private void UpdateExtraBuffs(Guid itemId)
444393
{
445394
var item = ItemDescriptor.Get(itemId);
446395

@@ -449,23 +398,21 @@ public void UpdateExtraBuffs(Guid itemId)
449398
return;
450399
}
451400

452-
//Getting HP and Mana Regen
453-
if (item.VitalsRegen[0] != 0)
401+
//Getting HP and Mana Regen from items
402+
if (item.VitalsRegen[(int)Vital.Health] != 0)
454403
{
455-
HpRegenAmount += item.VitalsRegen[0];
456-
mHpRegen?.SetText(Strings.Character.HealthRegen.ToString(HpRegenAmount));
404+
HpRegenAmount += item.VitalsRegen[(int)Vital.Health];
457405
}
458406

459-
if (item.VitalsRegen[1] != 0)
407+
if (item.VitalsRegen[(int)Vital.Mana] != 0)
460408
{
461-
ManaRegenAmount += item.VitalsRegen[1];
462-
mManaRegen?.SetText(Strings.Character.ManaRegen.ToString(ManaRegenAmount));
409+
ManaRegenAmount += item.VitalsRegen[(int)Vital.Mana];
463410
}
464411

465-
//Getting extra buffs
412+
//Getting extra buffs from items
466413
if (item.Effects.Find(effect => effect.Type != ItemEffect.None && effect.Percentage > 0) != default)
467414
{
468-
foreach(var effect in item.Effects)
415+
foreach (var effect in item.Effects)
469416
{
470417
if (effect.Percentage <= 0)
471418
{
@@ -476,39 +423,56 @@ public void UpdateExtraBuffs(Guid itemId)
476423
{
477424
case ItemEffect.CooldownReduction:
478425
CooldownAmount += effect.Percentage;
479-
mCooldownReduction?.SetText(Strings.Character.CooldownReduction.ToString(CooldownAmount));
480-
481426
break;
482427
case ItemEffect.Lifesteal:
483428
LifeStealAmount += effect.Percentage;
484-
mLifeSteal?.SetText(Strings.Character.Lifesteal.ToString(LifeStealAmount));
485-
486429
break;
487430
case ItemEffect.Tenacity:
488431
TenacityAmount += effect.Percentage;
489-
mTenacity?.SetText(Strings.Character.Tenacity.ToString(TenacityAmount));
490-
491432
break;
492433
case ItemEffect.Luck:
493434
LuckAmount += effect.Percentage;
494-
mLuck?.SetText(Strings.Character.Luck.ToString(LuckAmount));
495-
496435
break;
497436
case ItemEffect.EXP:
498437
ExtraExpAmount += effect.Percentage;
499-
mExtraExp?.SetText(Strings.Character.ExtraExp.ToString(ExtraExpAmount));
500-
501438
break;
502439
case ItemEffect.Manasteal:
503440
ManaStealAmount += effect.Percentage;
504-
mManaSteal?.SetText(Strings.Character.Manasteal.ToString(ManaStealAmount));
505-
506441
break;
507442
}
508443
}
509444
}
510445
}
511446

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

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics;
2+
using Intersect.Client.Framework.File_Management;
13
using Intersect.Client.Framework.GenericClasses;
24
using Intersect.Client.Framework.Gwen.Control;
35
using Intersect.Client.Framework.Gwen.Control.EventArguments;
@@ -20,7 +22,7 @@ public partial class EquipmentItem
2022

2123
private ItemProperties mItemProperties = null;
2224

23-
private bool mTexLoaded;
25+
private string? _loadedTexture;
2426

2527
private int mYindex;
2628

@@ -110,32 +112,31 @@ public FloatRect RenderBounds()
110112

111113
public void Update(Guid currentItemId, ItemProperties itemProperties)
112114
{
113-
if (currentItemId != mCurrentItemId || !mTexLoaded)
115+
if (!ItemDescriptor.TryGet(currentItemId, out var item))
114116
{
115-
mCurrentItemId = currentItemId;
116-
mItemProperties = itemProperties;
117-
var item = ItemDescriptor.Get(mCurrentItemId);
118-
if (item != null)
119-
{
120-
var itemTex = Globals.ContentManager.GetTexture(Framework.Content.TextureType.Item, item.Icon);
121-
if (itemTex != null)
122-
{
123-
ContentPanel.Show();
124-
ContentPanel.Texture = itemTex;
125-
ContentPanel.RenderColor = item.Color;
126-
}
127-
else
128-
{
129-
ContentPanel.Hide();
130-
}
131-
}
132-
else
133-
{
134-
ContentPanel.Hide();
135-
}
117+
ContentPanel.Hide();
118+
_loadedTexture = default;
119+
return;
120+
}
136121

137-
mTexLoaded = true;
122+
if (currentItemId == mCurrentItemId && ContentPanel.Texture?.Name == _loadedTexture)
123+
{
124+
return;
138125
}
139-
}
140126

127+
mCurrentItemId = currentItemId;
128+
mItemProperties = itemProperties;
129+
130+
if (GameContentManager.Current.GetTexture(Framework.Content.TextureType.Item, item.Icon) is not { } itemTexture)
131+
{
132+
ContentPanel.Hide();
133+
_loadedTexture = default;
134+
return;
135+
}
136+
137+
ContentPanel.Show();
138+
ContentPanel.Texture = itemTexture;
139+
ContentPanel.RenderColor = item.Color;
140+
_loadedTexture = ContentPanel.Texture?.Name;
141+
}
141142
}

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)