Skip to content
Snippets Groups Projects
Commit 8f614fcc authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe parametric input padding for hud

parent e837a757
No related branches found
No related tags found
No related merge requests found
...@@ -23,8 +23,9 @@ const INPUT_BASE_TEXT_STYLE = { ...@@ -23,8 +23,9 @@ const INPUT_BASE_TEXT_STYLE = {
interface HudOptions { interface HudOptions {
statsPadding: number; statsPadding: number;
statsFontSize: string; statsFontSize: string;
inputPosition: number; inputPadding: number;
inputFontSize: string; inputFontSize: string;
inputPosition: number;
} }
export default class HUD { export default class HUD {
...@@ -38,10 +39,11 @@ export default class HUD { ...@@ -38,10 +39,11 @@ export default class HUD {
constructor(scene: Phaser.Scene, options?: HudOptions) { constructor(scene: Phaser.Scene, options?: HudOptions) {
this.scene = scene; this.scene = scene;
this.options = options || { this.options = options || {
statsPadding: Math.min(this.scene.cameras.main.width * 0.01, 10), // min(1vw,10px) statsPadding: 10,
statsFontSize: "max(3vw,20px)", // never smaller than 20px statsFontSize: "22px",
inputPadding: 4,
inputFontSize: "60px",
inputPosition: 0.5, inputPosition: 0.5,
inputFontSize: "min(12vw,60px)", // always fit ~12 chars comfortably in width
}; };
this.input = this.initInput(scene); this.input = this.initInput(scene);
this.score = this.initScore(scene); this.score = this.initScore(scene);
...@@ -55,14 +57,22 @@ export default class HUD { ...@@ -55,14 +57,22 @@ export default class HUD {
scene.cameras.main.width / 2, scene.cameras.main.width / 2,
scene.cameras.main.height * this.options.inputPosition, scene.cameras.main.height * this.options.inputPosition,
"", "",
{ this.inputTextStyle(),
...INPUT_BASE_TEXT_STYLE,
fontSize: this.options.inputFontSize,
},
) )
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
} }
inputTextStyle(): Phaser.Types.GameObjects.Text.TextStyle {
return {
...INPUT_BASE_TEXT_STYLE,
fontSize: this.options.inputFontSize,
padding: {
x: this.options.inputPadding,
y: this.options.inputPadding,
},
};
}
statsTextStyle(): Phaser.Types.GameObjects.Text.TextStyle { statsTextStyle(): Phaser.Types.GameObjects.Text.TextStyle {
return { return {
...STATS_BASE_TEXT_STYLE, ...STATS_BASE_TEXT_STYLE,
...@@ -127,8 +137,7 @@ export default class HUD { ...@@ -127,8 +137,7 @@ export default class HUD {
this.scene.cameras.main.height * this.options.inputPosition, this.scene.cameras.main.height * this.options.inputPosition,
input, input,
{ {
...INPUT_BASE_TEXT_STYLE, ...this.inputTextStyle(),
fontSize: this.options.inputFontSize,
color: color, color: color,
}, },
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment