Försterkreislauf: Setzlinge beim Fällen, Försterhaus, Förster-Job

- Gefällter Baum → 1–2 tree_seed im Stockpile (zufällig)
- Neues Gebäude forester_hut (50 wood): Log-Hütten-Grafik, Klick öffnet Info-Panel
- Zonenmarkierung: Edit-Zone-Tool, Radius 5 Tiles, halbtransparente Overlay-Anzeige
- Neuer JobType 'forester': Nisse pflanzen Setzlinge auf markierten Zonen-Tiles
- Chop-Priorisierung: Zonen-Bäume werden vor natürlichen Bäumen gefällt
- Nisse-Panel & Info-Panel zeigen forester-Priorität-Button

Closes #25

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 13:07:36 +00:00
parent b024cf36fb
commit 969a82949e
9 changed files with 629 additions and 39 deletions

View File

@@ -52,6 +52,15 @@ export class UIScene extends Phaser.Scene {
private settingsGroup!: Phaser.GameObjects.Group
private settingsVisible = false
// ── Forester Hut Panel ────────────────────────────────────────────────────
private foresterPanelGroup!: Phaser.GameObjects.Group
private foresterPanelVisible = false
private foresterPanelBuildingId: string | null = null
/** Tile-count text inside the forester panel, updated live when zone changes. */
private foresterTileCountText: Phaser.GameObjects.Text | null = null
/** True while the zone-edit tool is active (shown in ESC priority stack). */
private inForesterZoneEdit = false
constructor() { super({ key: 'UI' }) }
/**
@@ -88,11 +97,16 @@ export class UIScene extends Phaser.Scene {
gameScene.events.on('nisseClicked', (id: string) => this.openNisseInfoPanel(id))
this.input.mouse!.disableContextMenu()
this.contextMenuGroup = this.add.group()
this.escMenuGroup = this.add.group()
this.confirmGroup = this.add.group()
this.nisseInfoGroup = this.add.group()
this.settingsGroup = this.add.group()
this.contextMenuGroup = this.add.group()
this.escMenuGroup = this.add.group()
this.confirmGroup = this.add.group()
this.nisseInfoGroup = this.add.group()
this.settingsGroup = this.add.group()
this.foresterPanelGroup = this.add.group()
gameScene.events.on('foresterHutClicked', (id: string) => this.openForesterPanel(id))
gameScene.events.on('foresterZoneEditEnded', () => this.onForesterEditEnded())
gameScene.events.on('foresterZoneChanged', (id: string, tiles: string[]) => this.onForesterZoneChanged(id, tiles))
this.input.on('pointerdown', (ptr: Phaser.Input.Pointer) => {
if (ptr.rightButtonDown()) {
@@ -204,9 +218,10 @@ export class UIScene extends Phaser.Scene {
{ kind: 'chest', label: 'Chest', cost: '5 wood + 2 stone' },
{ kind: 'bed', label: '🛏 Bed', cost: '6 wood (+1 villager)' },
{ kind: 'stockpile_zone', label: '📦 Stockpile', cost: 'free (workers deliver here)' },
{ kind: 'forester_hut', label: '🌲 Forester Hut', cost: '50 wood' },
]
const menuX = this.scale.width / 2 - 150, menuY = this.scale.height / 2 - 140
const bg = this.add.rectangle(menuX, menuY, 300, 280, 0x000000, this.uiOpacity).setOrigin(0,0).setScrollFactor(0).setDepth(200)
const menuX = this.scale.width / 2 - 150, menuY = this.scale.height / 2 - 168
const bg = this.add.rectangle(menuX, menuY, 300, 326, 0x000000, this.uiOpacity).setOrigin(0,0).setScrollFactor(0).setDepth(200)
this.buildMenuGroup.add(bg)
this.buildMenuGroup.add(this.add.text(menuX + 150, menuY + 14, 'BUILD MENU [B/ESC]', { fontSize: '11px', color: '#aaaaaa', fontFamily: 'monospace' }).setOrigin(0.5,0).setScrollFactor(0).setDepth(201))
@@ -267,7 +282,7 @@ export class UIScene extends Phaser.Scene {
const state = stateManager.getState()
const villagers = Object.values(state.world.villagers)
const panelW = 420
const panelW = 490
const rowH = 60
const panelH = Math.max(100, villagers.length * rowH + 50)
const px = this.scale.width / 2 - panelW / 2
@@ -309,12 +324,12 @@ export class UIScene extends Phaser.Scene {
eg.fillStyle(col); eg.fillRect(px + 12, ry + 30, 80 * v.energy / 100, 6)
this.villagerPanelGroup.add(eg)
// Job priority buttons: chop / mine / farm
// Job priority buttons: chop / mine / farm / forester
const jobs: Array<{ key: keyof JobPriorities; label: string }> = [
{ key: 'chop', label: '🪓' }, { key: 'mine', label: '⛏' }, { key: 'farm', label: '🌾' }
{ key: 'chop', label: '🪓' }, { key: 'mine', label: '⛏' }, { key: 'farm', label: '🌾' }, { key: 'forester', label: '🌲' }
]
jobs.forEach((job, ji) => {
const bx = px + 110 + ji * 100
const bx = px + 110 + ji * 76
const pri = v.priorities[job.key]
const label = pri === 0 ? `${job.label} OFF` : `${job.label} P${pri}`
const btn = this.add.text(bx, ry + 6, label, {
@@ -527,13 +542,15 @@ export class UIScene extends Phaser.Scene {
* esc menu → build/farm mode (handled by their own systems) → open ESC menu.
*/
private handleEsc(): void {
if (this.confirmVisible) { this.hideConfirm(); return }
if (this.contextMenuVisible) { this.hideContextMenu(); return }
if (this.buildMenuVisible) { this.closeBuildMenu(); return }
if (this.villagerPanelVisible){ this.closeVillagerPanel(); return }
if (this.nisseInfoVisible) { this.closeNisseInfoPanel(); return }
if (this.settingsVisible) { this.closeSettings(); return }
if (this.escMenuVisible) { this.closeEscMenu(); return }
if (this.confirmVisible) { this.hideConfirm(); return }
if (this.inForesterZoneEdit) { this.scene.get('Game').events.emit('foresterZoneEditStop'); return }
if (this.foresterPanelVisible) { this.closeForesterPanel(); return }
if (this.contextMenuVisible) { this.hideContextMenu(); return }
if (this.buildMenuVisible) { this.closeBuildMenu(); return }
if (this.villagerPanelVisible) { this.closeVillagerPanel(); return }
if (this.nisseInfoVisible) { this.closeNisseInfoPanel(); return }
if (this.settingsVisible) { this.closeSettings(); return }
if (this.escMenuVisible) { this.closeEscMenu(); return }
// Build/farm mode: let BuildingSystem / FarmingSystem handle their own ESC key.
// We only skip opening the ESC menu while those modes are active.
if (this.inBuildMode || this.inFarmMode) return
@@ -928,12 +945,12 @@ export class UIScene extends Phaser.Scene {
// Static: priority label + buttons
const jobKeys: Array<{ key: string; icon: string }> = [
{ key: 'chop', icon: '🪓' }, { key: 'mine', icon: '⛏' }, { key: 'farm', icon: '🌾' },
{ key: 'chop', icon: '🪓' }, { key: 'mine', icon: '⛏' }, { key: 'farm', icon: '🌾' }, { key: 'forester', icon: '🌲' },
]
jobKeys.forEach((j, i) => {
const pri = v.priorities[j.key as keyof typeof v.priorities]
const label = pri === 0 ? `${j.icon} OFF` : `${j.icon} P${pri}`
const bx = px + 10 + i * 88
const bx = px + 10 + i * 66
const btn = this.add.text(bx, py + 78, label, {
fontSize: '11px', color: pri === 0 ? '#555555' : '#ffffff',
fontFamily: 'monospace', backgroundColor: pri === 0 ? '#1a1a1a' : '#1a3a1a',
@@ -1008,6 +1025,131 @@ export class UIScene extends Phaser.Scene {
})
}
// ─── Forester Hut Panel ───────────────────────────────────────────────────
/**
* Opens the forester hut info panel for the given building.
* If another forester panel is open it is replaced.
* @param buildingId - ID of the clicked forester_hut
*/
private openForesterPanel(buildingId: string): void {
this.foresterPanelBuildingId = buildingId
this.foresterPanelVisible = true
this.buildForesterPanel()
}
/** Closes and destroys the forester hut panel and exits zone edit mode if active. */
private closeForesterPanel(): void {
if (!this.foresterPanelVisible) return
if (this.inForesterZoneEdit) {
this.scene.get('Game').events.emit('foresterZoneEditStop')
}
this.foresterPanelVisible = false
this.foresterPanelBuildingId = null
this.foresterTileCountText = null
this.foresterPanelGroup.destroy(true)
this.foresterPanelGroup = this.add.group()
}
/**
* Builds the forester hut panel showing zone tile count and an edit-zone button.
* Positioned in the top-left corner (similar to the Nisse info panel).
*/
private buildForesterPanel(): void {
this.foresterPanelGroup.destroy(true)
this.foresterPanelGroup = this.add.group()
this.foresterTileCountText = null
const id = this.foresterPanelBuildingId
if (!id) return
const state = stateManager.getState()
const building = state.world.buildings[id]
if (!building) { this.closeForesterPanel(); return }
const zone = state.world.foresterZones[id]
const tileCount = zone?.tiles.length ?? 0
const panelW = 240
const panelH = 100
const px = 10, py = 10
// Background
this.foresterPanelGroup.add(
this.add.rectangle(px, py, panelW, panelH, 0x030a03, this.uiOpacity)
.setOrigin(0, 0).setScrollFactor(0).setDepth(250)
)
// Title
this.foresterPanelGroup.add(
this.add.text(px + 10, py + 10, '🌲 FORESTER HUT', {
fontSize: '13px', color: '#88dd88', fontFamily: 'monospace',
}).setScrollFactor(0).setDepth(251)
)
// Close button
const closeBtn = this.add.text(px + panelW - 12, py + 10, '✕', {
fontSize: '13px', color: '#888888', fontFamily: 'monospace',
}).setOrigin(1, 0).setScrollFactor(0).setDepth(251).setInteractive()
closeBtn.on('pointerover', () => closeBtn.setStyle({ color: '#ffffff' }))
closeBtn.on('pointerout', () => closeBtn.setStyle({ color: '#888888' }))
closeBtn.on('pointerdown', () => this.closeForesterPanel())
this.foresterPanelGroup.add(closeBtn)
// Zone tile count (dynamic — updated via onForesterZoneChanged)
const countTxt = this.add.text(px + 10, py + 32, `Zone: ${tileCount} tile${tileCount === 1 ? '' : 's'} marked`, {
fontSize: '11px', color: '#aaaaaa', fontFamily: 'monospace',
}).setScrollFactor(0).setDepth(251)
this.foresterPanelGroup.add(countTxt)
this.foresterTileCountText = countTxt
// Edit zone button
const editLabel = this.inForesterZoneEdit ? '✅ Done editing' : '✏️ Edit Zone'
const editBtn = this.add.rectangle(px + 10, py + 54, panelW - 20, 30, 0x1a3a1a, 0.9)
.setOrigin(0, 0).setScrollFactor(0).setDepth(251).setInteractive()
editBtn.on('pointerover', () => editBtn.setFillStyle(0x2d6a4f, 0.9))
editBtn.on('pointerout', () => editBtn.setFillStyle(0x1a3a1a, 0.9))
editBtn.on('pointerdown', () => {
if (this.inForesterZoneEdit) {
this.scene.get('Game').events.emit('foresterZoneEditStop')
} else {
this.inForesterZoneEdit = true
this.scene.get('Game').events.emit('foresterZoneEditStart', id)
// Rebuild panel to show "Done editing" button
this.buildForesterPanel()
}
})
this.foresterPanelGroup.add(editBtn)
this.foresterPanelGroup.add(
this.add.text(px + panelW / 2, py + 69, editLabel, {
fontSize: '12px', color: '#dddddd', fontFamily: 'monospace',
}).setOrigin(0.5, 0.5).setScrollFactor(0).setDepth(252)
)
}
/**
* Called when the ForesterZoneSystem signals that zone editing ended
* (via right-click, ESC, or the "Done" button).
*/
private onForesterEditEnded(): void {
this.inForesterZoneEdit = false
// Rebuild panel to switch button back to "Edit Zone"
if (this.foresterPanelVisible) this.buildForesterPanel()
}
/**
* Called when the zone tiles change so we can update the tile-count text live.
* @param buildingId - Building whose zone changed
* @param tiles - Updated tile array
*/
private onForesterZoneChanged(buildingId: string, tiles: string[]): void {
if (buildingId !== this.foresterPanelBuildingId) return
if (this.foresterTileCountText) {
const n = tiles.length
this.foresterTileCountText.setText(`Zone: ${n} tile${n === 1 ? '' : 's'} marked`)
}
}
// ─── Resize ───────────────────────────────────────────────────────────────
/**
@@ -1042,5 +1184,6 @@ export class UIScene extends Phaser.Scene {
if (this.settingsVisible) this.closeSettings()
if (this.confirmVisible) this.hideConfirm()
if (this.nisseInfoVisible) this.closeNisseInfoPanel()
if (this.foresterPanelVisible) this.closeForesterPanel()
}
}