Skip to content

Commit

Permalink
Achivment Bar is localized and gets bigger when using german
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeTappert committed May 28, 2024
1 parent 8468df8 commit 898afd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/system/achv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class Achv {
}

getName(): string {
return this.name;
// Localization key is used to get the name of the achievement
return i18next.t(`achv:${this.localizationKey}.name`);
}

getIconImage(): string {
Expand Down
30 changes: 23 additions & 7 deletions src/ui/achv-bar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import BattleScene from "../battle-scene";
import { Achv } from "../system/achv";
import {Achv, getAchievementDescription} from "../system/achv";
import { Voucher } from "../system/voucher";
import { TextStyle, addTextObject } from "./text";
import i18next from "i18next";

export default class AchvBar extends Phaser.GameObjects.Container {
private bg: Phaser.GameObjects.NineSlice;
Expand All @@ -19,28 +20,43 @@ export default class AchvBar extends Phaser.GameObjects.Container {
}

setup(): void {
this.bg = this.scene.add.nineslice(0, 0, "achv_bar", null, 160, 40, 41, 6, 16, 4);
let xNineSlice = 0;
let heightNineSlice = 40;
let xicon= 4;
let titleTextX = 40;
let descriptionTextX = 43;
let wordWrapWidth = 664;
if (i18next.language === "de") {
xNineSlice = -20;
heightNineSlice = 60;
xicon = -16;
titleTextX = 20;
descriptionTextX = 23;
wordWrapWidth = 700;
}

this.bg = this.scene.add.nineslice(xNineSlice , 0, "achv_bar", null, 800, heightNineSlice, 41, 6, 16, 4);
this.bg.setOrigin(0, 0);

this.add(this.bg);

this.icon = this.scene.add.sprite(4, 4, "items");
this.icon = this.scene.add.sprite(xicon, this.bg.height/2 - this.bg.height/4, "items");
this.icon.setOrigin(0, 0);
this.add(this.icon);

this.titleText = addTextObject(this.scene, 40, 3, "", TextStyle.MESSAGE, { fontSize: "72px" });
this.titleText = addTextObject(this.scene, titleTextX, 3, "", TextStyle.MESSAGE, { fontSize: "72px" });
this.titleText.setOrigin(0, 0);
this.add(this.titleText);

this.scoreText = addTextObject(this.scene, 150, 3, "", TextStyle.MESSAGE, { fontSize: "72px" });
this.scoreText.setOrigin(1, 0);
this.add(this.scoreText);

this.descriptionText = addTextObject(this.scene, 43, 16, "", TextStyle.WINDOW_ALT, { fontSize: "72px" });
this.descriptionText = addTextObject(this.scene, descriptionTextX, 16, "", TextStyle.WINDOW_ALT, { fontSize: "72px" });
this.descriptionText.setOrigin(0, 0);
this.add(this.descriptionText);

this.descriptionText.setWordWrapWidth(664);
this.descriptionText.setWordWrapWidth(wordWrapWidth);
this.descriptionText.setLineSpacing(-5);

this.setScale(0.5);
Expand All @@ -60,7 +76,7 @@ export default class AchvBar extends Phaser.GameObjects.Container {
this.icon.setFrame(achv.getIconImage());
this.titleText.setText(achv.getName());
this.scoreText.setVisible(achv instanceof Achv);
this.descriptionText.setText(achv.description);
this.descriptionText.setText(getAchievementDescription((achv as Achv).localizationKey));

if (achv instanceof Achv) {
this.scoreText.setText(`+${(achv as Achv).score}pt`);
Expand Down

0 comments on commit 898afd4

Please sign in to comment.