76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
|
|
import './components/LoginScreen.js';
|
||
|
|
import './components/StatsDisplay.js';
|
||
|
|
import './components/BuildingToolbox.js';
|
||
|
|
import './components/ChatBox.js';
|
||
|
|
import './components/ContextMenu.js';
|
||
|
|
|
||
|
|
export class UIManager {
|
||
|
|
constructor(app) {
|
||
|
|
this.app = app;
|
||
|
|
this.loginScreen = null;
|
||
|
|
this.statsDisplay = null;
|
||
|
|
this.buildingToolbox = null;
|
||
|
|
this.chatBox = null;
|
||
|
|
this.contextMenu = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
init() {
|
||
|
|
this.loginScreen = document.getElementById('loginScreen');
|
||
|
|
this.statsDisplay = document.getElementById('statsDisplay');
|
||
|
|
this.buildingToolbox = document.getElementById('buildingToolbox');
|
||
|
|
this.chatBox = document.getElementById('chatBox');
|
||
|
|
this.contextMenu = document.getElementById('contextMenu');
|
||
|
|
|
||
|
|
// Set app reference in components
|
||
|
|
this.loginScreen.app = this.app;
|
||
|
|
this.buildingToolbox.app = this.app;
|
||
|
|
this.chatBox.app = this.app;
|
||
|
|
this.contextMenu.app = this.app;
|
||
|
|
}
|
||
|
|
|
||
|
|
showLoginScreen() {
|
||
|
|
this.loginScreen.style.display = 'flex';
|
||
|
|
}
|
||
|
|
|
||
|
|
hideLoginScreen() {
|
||
|
|
this.loginScreen.style.display = 'none';
|
||
|
|
}
|
||
|
|
|
||
|
|
showGameUI() {
|
||
|
|
document.getElementById('gameUI').style.display = 'block';
|
||
|
|
}
|
||
|
|
|
||
|
|
updateStats(player) {
|
||
|
|
if (this.statsDisplay) {
|
||
|
|
this.statsDisplay.setAttribute('money', player.money);
|
||
|
|
this.statsDisplay.setAttribute('population', player.population);
|
||
|
|
this.statsDisplay.setAttribute('nickname', player.nickname);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
updateBuildingToolbox(player) {
|
||
|
|
if (this.buildingToolbox) {
|
||
|
|
this.buildingToolbox.setAttribute('player-money', player.money);
|
||
|
|
this.buildingToolbox.setAttribute('player-population', player.population);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
addChatMessage(nickname, message, timestamp) {
|
||
|
|
if (this.chatBox) {
|
||
|
|
this.chatBox.addMessage(nickname, message, timestamp);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
showContextMenu(x, y, tileX, tileY) {
|
||
|
|
if (this.contextMenu) {
|
||
|
|
this.contextMenu.show(x, y, tileX, tileY);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
hideContextMenu() {
|
||
|
|
if (this.contextMenu) {
|
||
|
|
this.contextMenu.hide();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|