refactor(HeroBoxComp): 替换手动格式化逻辑为NumberFormatter
统一大数值展示格式,使用千分位缩写避免溢出标签,同时保留小数位数的原有逻辑
This commit is contained in:
@@ -21,7 +21,7 @@ import { GameEvent } from "../common/config/GameEvent";
|
|||||||
import { HeroInfo } from "../common/config/heroSet";
|
import { HeroInfo } from "../common/config/heroSet";
|
||||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||||
import { Hero } from "../hero/Hero";
|
import { Hero } from "../hero/Hero";
|
||||||
import { FacSet, FightSet, getLvColor } from "../common/config/GameSet";
|
import { FacSet, FightSet, getLvColor, NumberFormatter } from "../common/config/GameSet";
|
||||||
import { buildSkillDesc, ISkillDescSource } from "../common/config/HeroSkillDesc";
|
import { buildSkillDesc, ISkillDescSource } from "../common/config/HeroSkillDesc";
|
||||||
import { MissionEconomy } from "./MissionEconomy";
|
import { MissionEconomy } from "./MissionEconomy";
|
||||||
import { UIID } from "../common/config/GameUIConfig";
|
import { UIID } from "../common/config/GameUIConfig";
|
||||||
@@ -592,7 +592,8 @@ export class HeroBoxComp extends CCComp {
|
|||||||
* @param decimals 保留小数位数(默认 0,取整)
|
* @param decimals 保留小数位数(默认 0,取整)
|
||||||
*/
|
*/
|
||||||
private setStatRow(allLabel: Label | null, plusLabel: Label | null, total: number, bonus: number, suffix: string = "", decimals: number = 0) {
|
private setStatRow(allLabel: Label | null, plusLabel: Label | null, total: number, bonus: number, suffix: string = "", decimals: number = 0) {
|
||||||
const fmt = (v: number) => decimals > 0 ? v.toFixed(decimals) : `${Math.floor(v)}`;
|
// 整数数值统一走 NumberFormatter 千分位缩写(如 12.3k),避免大数值溢出标签
|
||||||
|
const fmt = (v: number) => decimals > 0 ? v.toFixed(decimals) : NumberFormatter.formatNumber(Math.floor(v));
|
||||||
if (allLabel && allLabel.isValid) {
|
if (allLabel && allLabel.isValid) {
|
||||||
allLabel.string = `${fmt(total)}${suffix}`;
|
allLabel.string = `${fmt(total)}${suffix}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user