Skip to content

Commit ed19c99

Browse files
committed
feat: simplify pause overlay layout by removing panel background and adjusting element positioning
1 parent e03cdcb commit ed19c99

1 file changed

Lines changed: 45 additions & 44 deletions

File tree

src/view/PauseOverlay.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ interface PauseRowView {
1414
}
1515

1616
const OVERLAY_DEPTH = 40;
17-
const PANEL_WIDTH = 248;
18-
const ACTION_ROW_HEIGHT = 18;
19-
const OPTIONS_ROW_HEIGHT = 20;
20-
const PANEL_TOP_PADDING = 28;
21-
const PANEL_BOTTOM_PADDING = 26;
22-
const ROW_GAP = 3;
17+
const LAYOUT_WIDTH = 236;
18+
const ACTION_ROW_HEIGHT = 16;
19+
const OPTIONS_ROW_HEIGHT = 18;
20+
const ROW_GAP = 4;
21+
const TITLE_TO_ROWS_GAP = 14;
22+
const ROWS_TO_HINT_GAP = 16;
2323
const COLOR_TITLE = "#f7f7ff";
2424
const COLOR_SELECTED = "#ffffff";
2525
const COLOR_TEXT = "#aeb3d8";
@@ -29,30 +29,28 @@ const COLOR_DISABLED = "#4d526f";
2929
export class PauseOverlay {
3030
private readonly container: Phaser.GameObjects.Container;
3131
private readonly backdrop: Phaser.GameObjects.Graphics;
32-
private readonly panel: Phaser.GameObjects.Graphics;
3332
private readonly title: Phaser.GameObjects.Text;
3433
private readonly hint: Phaser.GameObjects.Text;
3534
private readonly rows: PauseRowView[] = [];
3635

3736
constructor(scene: Phaser.Scene) {
3837
this.container = scene.add.container(0, 0).setDepth(OVERLAY_DEPTH).setScrollFactor(0);
3938
this.backdrop = scene.add.graphics();
40-
this.panel = scene.add.graphics();
4139
this.title = scene.add.text(0, 0, "", {
4240
fontFamily: "monospace",
43-
fontSize: "20px",
41+
fontSize: "18px",
4442
color: COLOR_TITLE,
4543
align: "center",
4644
});
4745
this.hint = scene.add.text(0, 0, "", {
4846
fontFamily: "monospace",
49-
fontSize: "9px",
47+
fontSize: "8px",
5048
color: COLOR_MUTED,
5149
align: "center",
52-
wordWrap: { width: PANEL_WIDTH - 20, useAdvancedWrap: true },
50+
wordWrap: { width: LAYOUT_WIDTH, useAdvancedWrap: true },
5351
});
5452

55-
this.container.add([this.backdrop, this.panel, this.title, this.hint]);
53+
this.container.add([this.backdrop, this.title, this.hint]);
5654
this.hide();
5755
}
5856

@@ -61,19 +59,19 @@ export class PauseOverlay {
6159

6260
const rowHeight = screen.kind === "options" ? OPTIONS_ROW_HEIGHT : ACTION_ROW_HEIGHT;
6361
const itemHeight = screen.items.length * rowHeight + Math.max(0, screen.items.length - 1) * ROW_GAP;
64-
const titleSize = screen.title === "PAUSED" ? 24 : 18;
65-
const panelHeight = PANEL_TOP_PADDING + 24 + 12 + itemHeight + PANEL_BOTTOM_PADDING + 20;
66-
const panelLeft = Math.round((VIEWPORT.width - PANEL_WIDTH) * 0.5);
67-
const panelTop = Math.round((VIEWPORT.height - panelHeight) * 0.5);
68-
const panelCenterX = panelLeft + PANEL_WIDTH * 0.5;
69-
const rowStartY = panelTop + PANEL_TOP_PADDING + 30;
70-
71-
this.redrawBackdrop(panelLeft, panelTop, panelHeight);
62+
const titleSize = screen.title === "PAUSED" ? 22 : 16;
63+
const blockHeight = titleSize + TITLE_TO_ROWS_GAP + itemHeight + ROWS_TO_HINT_GAP + 18;
64+
const top = Math.round((VIEWPORT.height - blockHeight) * 0.5);
65+
const centerX = Math.round(VIEWPORT.width * 0.5);
66+
const layoutLeft = Math.round((VIEWPORT.width - LAYOUT_WIDTH) * 0.5);
67+
const rowStartY = top + titleSize + TITLE_TO_ROWS_GAP;
68+
69+
this.redrawBackdrop();
7270
this.title
7371
.setText(screen.title)
7472
.setFontSize(titleSize)
7573
.setOrigin(0.5, 0)
76-
.setPosition(panelCenterX, panelTop + PANEL_TOP_PADDING - 4);
74+
.setPosition(centerX, top);
7775

7876
for (let i = 0; i < screen.items.length; i++) {
7977
const row = this.ensureRow(i);
@@ -86,9 +84,9 @@ export class PauseOverlay {
8684

8785
if (screen.kind === "action") {
8886
row.label
89-
.setX(panelCenterX)
87+
.setX(centerX)
9088
.setOrigin(0.5, 0)
91-
.setFontSize(14);
89+
.setFontSize(12);
9290
row.leftArrow.setVisible(false);
9391
row.value.setVisible(false);
9492
row.rightArrow.setVisible(false);
@@ -98,26 +96,29 @@ export class PauseOverlay {
9896
const option = screen.items[i];
9997
const valueColor = selected ? COLOR_SELECTED : COLOR_TEXT;
10098
row.label
101-
.setX(panelLeft + 20)
99+
.setX(layoutLeft)
102100
.setOrigin(0, 0)
103-
.setFontSize(12);
101+
.setFontSize(11);
104102
row.leftArrow
105103
.setVisible(true)
106104
.setText("<")
107-
.setPosition(panelLeft + PANEL_WIDTH - 68, y)
105+
.setPosition(layoutLeft + LAYOUT_WIDTH - 62, y)
108106
.setOrigin(1, 0)
107+
.setFontSize(11)
109108
.setColor(canMovePauseOption(option, -1) ? valueColor : COLOR_DISABLED);
110109
row.value
111110
.setVisible(true)
112111
.setText(currentPauseOptionLabel(option))
113-
.setPosition(panelLeft + PANEL_WIDTH - 44, y)
112+
.setPosition(layoutLeft + LAYOUT_WIDTH - 38, y)
114113
.setOrigin(0.5, 0)
114+
.setFontSize(11)
115115
.setColor(valueColor);
116116
row.rightArrow
117117
.setVisible(true)
118118
.setText(">")
119-
.setPosition(panelLeft + PANEL_WIDTH - 20, y)
119+
.setPosition(layoutLeft + LAYOUT_WIDTH - 14, y)
120120
.setOrigin(0, 0)
121+
.setFontSize(11)
121122
.setColor(canMovePauseOption(option, 1) ? valueColor : COLOR_DISABLED);
122123
}
123124

@@ -130,14 +131,8 @@ export class PauseOverlay {
130131
}
131132

132133
this.hint
133-
.setText(
134-
screen.kind === "options"
135-
? "Up/Down Select Left/Right Change X/Esc Save"
136-
: screen.title === "PAUSED"
137-
? "Up/Down Select C Confirm X/Esc Resume"
138-
: "Up/Down Select C Confirm X/Esc Back",
139-
)
140-
.setPosition(panelCenterX, panelTop + panelHeight - PANEL_BOTTOM_PADDING)
134+
.setText(this.hintText(screen))
135+
.setPosition(centerX, rowStartY + itemHeight + ROWS_TO_HINT_GAP)
141136
.setOrigin(0.5, 0.5);
142137
}
143138

@@ -150,16 +145,10 @@ export class PauseOverlay {
150145
this.container.destroy(true);
151146
}
152147

153-
private redrawBackdrop(panelLeft: number, panelTop: number, panelHeight: number): void {
148+
private redrawBackdrop(): void {
154149
this.backdrop.clear();
155150
this.backdrop.fillStyle(0x04050b, 0.68);
156151
this.backdrop.fillRect(0, 0, VIEWPORT.width, VIEWPORT.height);
157-
158-
this.panel.clear();
159-
this.panel.fillStyle(0x15172a, 0.94);
160-
this.panel.fillRoundedRect(panelLeft, panelTop, PANEL_WIDTH, panelHeight, 8);
161-
this.panel.lineStyle(1, 0xa7acd4, 0.25);
162-
this.panel.strokeRoundedRect(panelLeft, panelTop, PANEL_WIDTH, panelHeight, 8);
163152
}
164153

165154
private ensureRow(index: number): PauseRowView {
@@ -182,8 +171,20 @@ export class PauseOverlay {
182171
private makeText(): Phaser.GameObjects.Text {
183172
return this.container.scene.add.text(0, 0, "", {
184173
fontFamily: "monospace",
185-
fontSize: "12px",
174+
fontSize: "11px",
186175
color: COLOR_TEXT,
187176
});
188177
}
178+
179+
private hintText(screen: PauseMenuScreen): string {
180+
if (screen.kind === "options") {
181+
return "UP/DOWN: SELECT | LEFT/RIGHT: CHANGE | X/ESC: SAVE";
182+
}
183+
184+
if (screen.title === "PAUSED") {
185+
return "UP/DOWN: SELECT | C: CONFIRM | X/ESC: RESUME";
186+
}
187+
188+
return "UP/DOWN: SELECT | C: CONFIRM | X/ESC: BACK";
189+
}
189190
}

0 commit comments

Comments
 (0)