Merge pull request #2038 from MartinFournier/fix/skill-progress

Fix skills tooltip edge cases
This commit is contained in:
hydroflame 2021-12-19 10:22:43 -05:00 committed by GitHub
commit 3ed5aa8045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 17 deletions

@ -9,9 +9,14 @@ export function calculateExp(skill: number, mult = 1): number {
export function calculateSkillProgress(exp: number, mult = 1): ISkillProgress { export function calculateSkillProgress(exp: number, mult = 1): ISkillProgress {
const currentSkill = calculateSkill(exp, mult); const currentSkill = calculateSkill(exp, mult);
const nextSkill = currentSkill + 1; const nextSkill = currentSkill + 1;
let baseExperience = calculateExp(currentSkill, mult); let baseExperience = calculateExp(currentSkill, mult);
if (baseExperience < 0) baseExperience = 0; if (baseExperience < 0) baseExperience = 0;
const nextExperience = calculateExp(nextSkill, mult)
let nextExperience = calculateExp(nextSkill, mult)
if (nextExperience < 0) nextExperience = 0;
const normalize = (value: number): number => ((value - baseExperience) * 100) / (nextExperience - baseExperience);
return { return {
currentSkill, currentSkill,
@ -19,7 +24,7 @@ export function calculateSkillProgress(exp: number, mult = 1): ISkillProgress {
baseExperience, baseExperience,
experience: exp, experience: exp,
nextExperience, nextExperience,
progress: exp / nextExperience, progress: (nextExperience - baseExperience !== 0) ? normalize(exp) : 99.99
} }
} }
@ -32,7 +37,7 @@ export interface ISkillProgress {
progress: number; progress: number;
} }
export function getEmptySkillProgress() { export function getEmptySkillProgress(): ISkillProgress {
return { return {
currentSkill: 0, nextSkill: 0, currentSkill: 0, nextSkill: 0,
baseExperience: 0, experience: 0, nextExperience: 0, baseExperience: 0, experience: 0, nextExperience: 0,

@ -1,6 +1,6 @@
import * as React from "react"; import * as React from "react";
import LinearProgress from "@mui/material/LinearProgress"; import LinearProgress from "@mui/material/LinearProgress";
import { TableCell, Tooltip } from "@mui/material"; import { TableCell, Tooltip, Typography } from "@mui/material";
import { characterOverviewStyles } from "./CharacterOverview"; import { characterOverviewStyles } from "./CharacterOverview";
import { ISkillProgress } from "src/PersonObjects/formulas/skill"; import { ISkillProgress } from "src/PersonObjects/formulas/skill";
import { numeralWrapper } from "../numeralFormat"; import { numeralWrapper } from "../numeralFormat";
@ -9,6 +9,7 @@ interface IProgressProps {
min: number; min: number;
max: number; max: number;
current: number; current: number;
progress: number;
color?: React.CSSProperties["color"]; color?: React.CSSProperties["color"];
} }
@ -17,21 +18,22 @@ interface IStatsOverviewCellProps {
color?: React.CSSProperties["color"]; color?: React.CSSProperties["color"];
} }
export function StatsProgressBar({ min, max, current, color }: IProgressProps): React.ReactElement { export function StatsProgressBar({ min, max, current, progress, color }: IProgressProps): React.ReactElement {
const normalise = (value: number): number => ((value - min) * 100) / (max - min); const tooltip = (
const tooltipText = ( <Typography sx={{ textAlign: 'right' }}>
<> <strong>Progress:</strong>&nbsp;
Experience: {numeralWrapper.formatExp(current)}/{numeralWrapper.formatExp(max)} {numeralWrapper.formatExp(current - min)} / {numeralWrapper.formatExp(max - min)}
<br /> <br />
{normalise(current).toFixed(2)}% <strong>Remaining:</strong>&nbsp;
</> {numeralWrapper.formatExp(max - current)} ({progress.toFixed(2)}%)
</Typography>
); );
return ( return (
<Tooltip title={tooltipText}> <Tooltip title={tooltip}>
<LinearProgress <LinearProgress
variant="determinate" variant="determinate"
value={normalise(current)} value={progress}
sx={{ sx={{
backgroundColor: "#111111", backgroundColor: "#111111",
"& .MuiLinearProgress-bar1Determinate": { "& .MuiLinearProgress-bar1Determinate": {
@ -43,7 +45,7 @@ export function StatsProgressBar({ min, max, current, color }: IProgressProps):
); );
} }
export function StatsProgressOverviewCell({ progress, color }: IStatsOverviewCellProps): React.ReactElement { export function StatsProgressOverviewCell({ progress: skill, color }: IStatsOverviewCellProps): React.ReactElement {
const classes = characterOverviewStyles(); const classes = characterOverviewStyles();
return ( return (
<TableCell <TableCell
@ -54,9 +56,10 @@ export function StatsProgressOverviewCell({ progress, color }: IStatsOverviewCel
style={{ paddingBottom: "2px", position: "relative", top: "-3px" }} style={{ paddingBottom: "2px", position: "relative", top: "-3px" }}
> >
<StatsProgressBar <StatsProgressBar
min={progress.baseExperience} min={skill.baseExperience}
max={progress.nextExperience} max={skill.nextExperience}
current={progress.experience} current={skill.experience}
progress={skill.progress}
color={color} color={color}
/> />
</TableCell> </TableCell>