From 57c39da301cd3a368ea8706283324f2cbb8f9224 Mon Sep 17 00:00:00 2001 From: Freek Date: Wed, 28 Feb 2024 16:13:56 +0100 Subject: [PATCH] feat(skills-overview): added xp tooltips to skills overview fix #28 --- CHANGELOG.md | 4 + .../general/tooltip/tooltip.component.ts | 5 +- .../player/player-skill.component.ts | 48 +++++++++-- .../player/player-skills.component.ts | 82 +++++++++++-------- 4 files changed, 95 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a9942f..c5c05f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2024/02/28 + +- Added xp tooltips to the skills overview in xp tracker + ## 2024/02/27 - updated dependencies diff --git a/src/app/common/components/general/tooltip/tooltip.component.ts b/src/app/common/components/general/tooltip/tooltip.component.ts index a6f2ed1..78d322a 100644 --- a/src/app/common/components/general/tooltip/tooltip.component.ts +++ b/src/app/common/components/general/tooltip/tooltip.component.ts @@ -61,6 +61,7 @@ export class TooltipComponent implements OnInit, AfterViewInit, OnDestroy { @HostBinding('class.cursor-help') cursorHelp = true; @Input() tooltipTemplate: TemplateRef; + @Input() tooltipUnderline: boolean = true; @ViewChild('tooltipTemplateArrow') tooltipTemplateArrow: TemplateRef; @ViewChild('tooltipTemplateContainer') tooltipTemplateContainer: TemplateRef; @@ -85,7 +86,9 @@ export class TooltipComponent implements OnInit, AfterViewInit, OnDestroy { } ngOnInit(): void { - this.elementRef.nativeElement.classList.add('underline', 'underline-offset-[6px]', 'decoration-dotted'); + if (this.tooltipUnderline) { + this.elementRef.nativeElement.classList.add('underline', 'underline-offset-[6px]', 'decoration-dotted'); + } } ngAfterViewInit(): void { diff --git a/src/app/common/components/player/player-skill.component.ts b/src/app/common/components/player/player-skill.component.ts index d13208e..c75b248 100644 --- a/src/app/common/components/player/player-skill.component.ts +++ b/src/app/common/components/player/player-skill.component.ts @@ -1,23 +1,53 @@ -import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; -import { Skill } from '@osrs-tracker/hiscores'; +import { DecimalPipe } from '@angular/common'; +import { ChangeDetectionStrategy, Component, InputSignal, input } from '@angular/core'; +import { Skill, calculateXPForSkillLevel, calculateXPToNextLevel } from '@osrs-tracker/hiscores'; import { IconDirective } from '../../directives/icon/icon.directive'; +import { TooltipComponent } from '../general/tooltip/tooltip.component'; @Component({ standalone: true, selector: 'player-skill', template: ` -
- @if (skill) { - -
{{ skill.level }}
+
+ @if (skill()) { + +
{{ skill()!.level }}
} @else { -
+
}
+ + +
+
+
{{ skill()?.name }} XP:
+
Next Level at:
+
Remaining XP:
+
+
+
{{ skill()?.xp | number }}
+
{{ xpForNextLevel | number }}
+
{{ xpToNextLevel | number }}
+
+
+
`, changeDetection: ChangeDetectionStrategy.OnPush, - imports: [IconDirective], + imports: [IconDirective, TooltipComponent, DecimalPipe], }) export class PlayerSkillWidgetComponent { - @Input() skill?: Skill; + skill: InputSignal = input(); + + get xpToNextLevel(): number { + return calculateXPToNextLevel(this.skill()?.xp ?? 0, this.skill()?.level ?? 1); + } + + get xpForNextLevel(): number { + return calculateXPForSkillLevel((this.skill()?.level ?? 1) + 1); + } } diff --git a/src/app/common/components/player/player-skills.component.ts b/src/app/common/components/player/player-skills.component.ts index 8b90df0..5a8a785 100644 --- a/src/app/common/components/player/player-skills.component.ts +++ b/src/app/common/components/player/player-skills.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; +import { ChangeDetectionStrategy, Component, InputSignal, Signal, computed, input } from '@angular/core'; import { Hiscore } from '@osrs-tracker/hiscores'; import { IconDirective } from '../../directives/icon/icon.directive'; import { PlayerSkillWidgetComponent } from './player-skill.component'; @@ -7,43 +7,57 @@ import { PlayerSkillWidgetComponent } from './player-skill.component'; standalone: true, selector: 'player-skills', template: ` -
- - - - - - - - - - - - - - - - - - - - - - - - +
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
`, changeDetection: ChangeDetectionStrategy.OnPush, imports: [IconDirective, PlayerSkillWidgetComponent], }) export class PlayerSkillsWidgetComponent { - get skills(): Hiscore['skills'] | undefined { - return this.hiscore?.skills; - } - - @Input() hiscore?: Hiscore; + hiscore: InputSignal = input(); + skills: Signal = computed(() => this.hiscore()?.skills); }