Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createOverlayBackground, createOverlayButton, createOverlayMenuButton,
dismissOverlay as sharedDismissOverlay,
} from '../../../src/ui';
import { createHudText } from '../../../src/ui/Renderer/adapters/BeleagueredCastleAdapter';


export class BeleagueredCastleOverlayManager {
Expand Down Expand Up @@ -50,10 +51,13 @@ export class BeleagueredCastleOverlayManager {
}).setOrigin(0.5).setDepth(BUTTON_DEPTH);
overlayObjects.push(title);

const stats = this.scene.add.text(GAME_W / 2, GAME_H / 2 - 20,
`Moves: ${this.state.moveCount} Time: ${mm}:${ss}`, {
fontSize: '22px', color: '#aaccaa', fontFamily: FONT_FAMILY, align: 'center',
}).setOrigin(0.5).setDepth(BUTTON_DEPTH);
const stats = createHudText(this.scene, GAME_W / 2, GAME_H / 2 - 20,
`Moves: ${this.state.moveCount} Time: ${mm}:${ss}`, '#aaccaa', {
fontSize: '22px',
originX: 0.5,
originY: 0.5,
});
stats.setDepth(BUTTON_DEPTH);
overlayObjects.push(stats);

const newGameBtn = createOverlayButton(this.scene, GAME_W / 2 - 150, GAME_H / 2 + 50, '[ New Game ]', BUTTON_DEPTH);
Expand All @@ -76,9 +80,13 @@ export class BeleagueredCastleOverlayManager {

const { objects: overlayObjects } = createOverlayBackground(this.scene, { depth: OVERLAY_DEPTH, alpha: 0.75 });

const title = this.scene.add.text(GAME_W / 2, GAME_H / 2 - 60, 'No Productive Moves Available', {
fontSize: '34px', color: '#ff8888', fontFamily: FONT_FAMILY, fontStyle: 'bold',
}).setOrigin(0.5).setDepth(BUTTON_DEPTH);
const title = createHudText(this.scene, GAME_W / 2, GAME_H / 2 - 60,
'No Productive Moves Available', '#ff8888', {
fontSize: '34px',
originX: 0.5,
originY: 0.5,
});
title.setDepth(BUTTON_DEPTH);
overlayObjects.push(title);

const undoBtn = createOverlayButton(this.scene, GAME_W / 2 - 180, GAME_H / 2 + 30, '[ Undo Last ]', BUTTON_DEPTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Phaser from 'phaser';
import type { BeleagueredCastleState } from '../BeleagueredCastleState';
import { FOUNDATION_COUNT, TABLEAU_COUNT } from '../BeleagueredCastleState';
import { cardTextureKey } from '../../../src/ui';
import { GAME_W, GAME_H, FONT_FAMILY, createSceneTitle, createSceneMenuButton } from '../../../src/ui';
import { GAME_W, GAME_H, createSceneTitle, createSceneMenuButton } from '../../../src/ui';
import { createBcHudText, createActionButton } from '../../../src/ui/Renderer/adapters/BeleagueredCastleAdapter';
import {
BC_CARD_W, BC_CARD_H, CARD_GAP, CASCADE_OFFSET_Y,
DRAG_DEPTH, DEAL_STAGGER, ANIM_DURATION, SNAP_BACK_DURATION,
Expand Down Expand Up @@ -42,8 +43,8 @@ export class BeleagueredCastleRenderer {
private moveCountText!: Phaser.GameObjects.Text;
private timerText!: Phaser.GameObjects.Text;
private seedText!: Phaser.GameObjects.Text;
private undoButton!: Phaser.GameObjects.Text;
private redoButton!: Phaser.GameObjects.Text;
private undoButton!: Phaser.GameObjects.Container;
private redoButton!: Phaser.GameObjects.Container;

// Callbacks
onUndoClick?: () => void;
Expand All @@ -66,8 +67,8 @@ export class BeleagueredCastleRenderer {
get moveText(): Phaser.GameObjects.Text { return this.moveCountText; }
get timer(): Phaser.GameObjects.Text { return this.timerText; }
get seedDisplay(): Phaser.GameObjects.Text { return this.seedText; }
get undoBtn(): Phaser.GameObjects.Text { return this.undoButton; }
get redoBtn(): Phaser.GameObjects.Text { return this.redoButton; }
get undoBtn(): Phaser.GameObjects.Container { return this.undoButton; }
get redoBtn(): Phaser.GameObjects.Container { return this.redoButton; }

// ── UI creation ─────────────────────────────────────────
createTitle(): void {
Expand Down Expand Up @@ -114,40 +115,22 @@ export class BeleagueredCastleRenderer {
}

createHUD(seed: number): void {
this.moveCountText = this.scene.add.text(20, GAME_H - 28, 'Moves: 0', {
fontSize: '20px', color: '#aaccaa', fontFamily: FONT_FAMILY,
}).setOrigin(0, 0.5);

this.timerText = this.scene.add.text(GAME_W / 2, GAME_H - 28, '00:00', {
fontSize: '20px', color: '#aaccaa', fontFamily: FONT_FAMILY,
}).setOrigin(0.5, 0.5);

this.seedText = this.scene.add.text(GAME_W - 20, GAME_H - 28, `Seed: ${seed}`, {
fontSize: '18px', color: '#668866', fontFamily: FONT_FAMILY,
}).setOrigin(1, 0.5);

this.undoButton = this.scene.add.text(GAME_W - 220, this.layout.headerY, '[ Undo ]', {
fontSize: '18px', color: '#557755', fontFamily: FONT_FAMILY,
}).setOrigin(0.5).setInteractive({ useHandCursor: true });
this.undoButton.on('pointerdown', () => this.onUndoClick?.());
this.undoButton.on('pointerover', () => {
if (this.onUndoClick) this.undoButton.setColor('#88ff88');
});
this.undoButton.on('pointerout', () => this.refreshUndoRedoButtons(false, false));

this.redoButton = this.scene.add.text(GAME_W - 140, this.layout.headerY, '[ Redo ]', {
fontSize: '18px', color: '#557755', fontFamily: FONT_FAMILY,
}).setOrigin(0.5).setInteractive({ useHandCursor: true });
this.redoButton.on('pointerdown', () => this.onRedoClick?.());
this.redoButton.on('pointerover', () => {
if (this.onRedoClick) this.redoButton.setColor('#88ff88');
this.moveCountText = createBcHudText(this.scene, 20, GAME_H - 28, 'Moves: 0', '#aaccaa', { fontSize: '20px' });

this.timerText = createBcHudText(this.scene, GAME_W / 2, GAME_H - 28, '00:00', '#aaccaa', { fontSize: '20px' });

this.seedText = createBcHudText(this.scene, GAME_W - 20, GAME_H - 28, `Seed: ${seed}`, '#668866', {
fontSize: '18px',
originX: 1,
});
this.redoButton.on('pointerout', () => this.refreshUndoRedoButtons(false, false));

this.undoButton = createActionButton(this.scene, GAME_W - 220, this.layout.headerY, 60, 'Undo', () => this.onUndoClick?.());
this.redoButton = createActionButton(this.scene, GAME_W - 140, this.layout.headerY, 60, 'Redo', () => this.onRedoClick?.());
}

refreshUndoRedoButtons(canUndo: boolean, canRedo: boolean): void {
this.undoButton.setColor(canUndo ? '#aaccaa' : '#557755');
this.redoButton.setColor(canRedo ? '#aaccaa' : '#557755');
this.undoButton.setAlpha(canUndo ? 1 : 0.5);
this.redoButton.setAlpha(canRedo ? 1 : 0.5);
}

// ── Foundation rendering ────────────────────────────────
Expand Down
60 changes: 32 additions & 28 deletions example-games/golf/scenes/GolfOverlayManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import type { TranscriptRecorder } from '../GameTranscript';
import { TranscriptStore, autoSaveTranscript } from '../../../src/core-engine/transcript';
import type { SoundManager, GameEventEmitter } from '../../../src/core-engine';
import { GAME_W, GAME_H } from '../../../src/ui';
import {
GAME_W, GAME_H, FONT_FAMILY,
createOverlayBackground, createOverlayButton, createOverlayMenuButton,
} from '../../../src/ui';
createActionButton,
createGolfHudText,
createGolfMenuButton,
createOverlayBackground,
} from '../../../src/ui/Renderer/adapters/GolfAdapter';
import { SFX_KEYS } from './GolfConstants';
import type { GolfSession } from '../GolfGame';

Expand Down Expand Up @@ -64,35 +67,36 @@ export class GolfOverlayManager {
);

const winnerText = results.winnerIndex === 0 ? 'You Win!' : 'AI Wins!';
this.scene.add
.text(
GAME_W / 2,
GAME_H / 2 - 50,
`${winnerText}\n\nYou: ${results.scores[0]} pts\nAI: ${results.scores[1]} pts`,
{
fontSize: '28px',
color: '#ffffff',
fontFamily: FONT_FAMILY,
align: 'center',
},
)
.setOrigin(0.5)
.setDepth(11);
createGolfHudText(
this.scene,
GAME_W / 2,
GAME_H / 2 - 50,
`${winnerText}\n\nYou: ${results.scores[0]} pts\nAI: ${results.scores[1]} pts`,
'#ffffff',
{ fontSize: '28px', originX: 0.5, align: 'center' },
);

// Play again button
const btn = createOverlayButton(
this.scene, GAME_W / 2 - 85, GAME_H / 2 + 85, '[ Play Again ]',
createActionButton(
this.scene,
GAME_W / 2 - 85,
GAME_H / 2 + 85,
170,
'[ Play Again ]',
() => {
this.soundManager?.play(SFX_KEYS.UI_CLICK);
this.gameEvents.emit('ui-interaction', {
elementId: 'play-again',
action: 'click',
});
this.scene.scene.restart();
},
{ depth: 11 },
);
btn.on('pointerdown', () => {
this.soundManager?.play(SFX_KEYS.UI_CLICK);
this.gameEvents.emit('ui-interaction', {
elementId: 'play-again',
action: 'click',
});
this.scene.scene.restart();
});

// Menu button
createOverlayMenuButton(this.scene, GAME_W / 2 + 85, GAME_H / 2 + 85);
createGolfMenuButton(this.scene, GAME_W / 2 + 85, GAME_H / 2 + 85, 80, {
depth: 11,
});
}
}
132 changes: 71 additions & 61 deletions example-games/golf/scenes/GolfRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import { scoreVisibleCards, scoreGrid } from '../GolfScoring';
import type { GolfSession } from '../GolfGame';
import { GAME_W, GAME_H } from '../../../src/ui';
import {
GAME_W, GAME_H, FONT_FAMILY,
createGolfHudText,
getCardTexture,
createSceneTitle, createSceneMenuButton,
} from '../../../src/ui';
createSceneTitle,
createSceneMenuButton,
} from '../../../src/ui/Renderer/adapters/GolfAdapter';
import {
GOLF_CARD_H, CARD_GAP,
GRID_ROWS,
Expand Down Expand Up @@ -61,21 +63,23 @@ export class GolfRenderer {
// Player labels above each grid
const gridH = GRID_ROWS * GOLF_CARD_H + (GRID_ROWS - 1) * CARD_GAP;

this.humanLabel = this.scene.add
.text(this.layout.humanGridCenterX, this.layout.humanGridCenterY - gridH / 2 - 24, 'You', {
fontSize: '24px',
color: '#ffffff',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);

this.aiLabel = this.scene.add
.text(this.layout.aiGridCenterX, this.layout.aiGridCenterY - gridH / 2 - 24, 'AI', {
fontSize: '24px',
color: '#cccccc',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);
this.humanLabel = createGolfHudText(
this.scene,
this.layout.humanGridCenterX,
this.layout.humanGridCenterY - gridH / 2 - 24,
'You',
'#ffffff',
{ fontSize: '24px', originX: 0.5 },
);

this.aiLabel = createGolfHudText(
this.scene,
this.layout.aiGridCenterX,
this.layout.aiGridCenterY - gridH / 2 - 24,
'AI',
'#cccccc',
{ fontSize: '24px', originX: 0.5 },
);
}

createPiles(
Expand All @@ -89,13 +93,14 @@ export class GolfRenderer {
this.stockSprite.on('pointerdown', onStockClick);
}

this.scene.add
.text(this.layout.stockPileCenterX, this.layout.stockPileCenterY + GOLF_CARD_H / 2 + 16, 'Stock', {
fontSize: '16px',
color: '#aaccaa',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);
createGolfHudText(
this.scene,
this.layout.stockPileCenterX,
this.layout.stockPileCenterY + GOLF_CARD_H / 2 + 16,
'Stock',
'#aaccaa',
{ fontSize: '16px', originX: 0.5 },
);

// Discard pile (lower center)
this.discardSprite = this.scene.add.image(this.layout.discardPileCenterX, this.layout.discardPileCenterY, 'card_back');
Expand All @@ -104,13 +109,14 @@ export class GolfRenderer {
this.discardSprite.on('pointerdown', onDiscardClick);
}

this.scene.add
.text(this.layout.discardPileCenterX, this.layout.discardPileCenterY + GOLF_CARD_H / 2 + 16, 'Discard', {
fontSize: '16px',
color: '#aaccaa',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);
createGolfHudText(
this.scene,
this.layout.discardPileCenterX,
this.layout.discardPileCenterY + GOLF_CARD_H / 2 + 16,
'Discard',
'#aaccaa',
{ fontSize: '16px', originX: 0.5 },
);
}

createGrids(onHumanCardClick: (index: number) => void): void {
Expand All @@ -137,40 +143,44 @@ export class GolfRenderer {
// Scores below each grid
const gridH = GRID_ROWS * GOLF_CARD_H + (GRID_ROWS - 1) * CARD_GAP;

this.humanScoreText = this.scene.add
.text(this.layout.humanGridCenterX, this.layout.humanGridCenterY + gridH / 2 + 24, 'Score: 0', {
fontSize: '22px',
color: '#ffffff',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);

this.aiScoreText = this.scene.add
.text(this.layout.aiGridCenterX, this.layout.aiGridCenterY + gridH / 2 + 24, 'Score: 0', {
fontSize: '22px',
color: '#cccccc',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);
this.humanScoreText = createGolfHudText(
this.scene,
this.layout.humanGridCenterX,
this.layout.humanGridCenterY + gridH / 2 + 24,
'Score: 0',
'#ffffff',
{ fontSize: '22px', originX: 0.5 },
);

this.aiScoreText = createGolfHudText(
this.scene,
this.layout.aiGridCenterX,
this.layout.aiGridCenterY + gridH / 2 + 24,
'Score: 0',
'#cccccc',
{ fontSize: '22px', originX: 0.5 },
);

// Turn indicator above the stock pile in center
this.turnText = this.scene.add
.text(this.layout.stockPileCenterX, this.layout.stockPileCenterY - GOLF_CARD_H / 2 - 24, '', {
fontSize: '20px',
color: '#ffdd44',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);
this.turnText = createGolfHudText(
this.scene,
this.layout.stockPileCenterX,
this.layout.stockPileCenterY - GOLF_CARD_H / 2 - 24,
'',
'#ffdd44',
{ fontSize: '20px', originX: 0.5 },
);
}

createInstructions(): void {
this.instructionText = this.scene.add
.text(GAME_W / 2, GAME_H - 18, '', {
fontSize: '18px',
color: '#88aa88',
fontFamily: FONT_FAMILY,
})
.setOrigin(0.5);
this.instructionText = createGolfHudText(
this.scene,
GAME_W / 2,
GAME_H - 18,
'',
'#88aa88',
{ fontSize: '18px', originX: 0.5 },
);
}

// ── Grid layout helpers ─────────────────────────────────
Expand Down
Loading
Loading