mirror of
http://junepve.top:3000/chicrobot/CINC.git
synced 2026-10-29 23:31:29 +08:00
fix(scenes) 种田系统测试,添加按钮等
This commit is contained in:
1 parent
ce4e04740a
commit
761a9338ba
19 files changed
+1248
-86
No files matched your search
@@ -4,9 +4,9 @@ import { InputSystem } from '../../systems/InputSystem.js';
|
||||
import { SelectionSystem } from '../../systems/SelectionSystem.js';
|
||||
import { CommandSystem } from '../../systems/CommandSystem.js';
|
||||
|
||||
export default class MovementTestScene5 extends Phaser.Scene {
|
||||
export default class AutoMovementTestScene extends Phaser.Scene {
|
||||
constructor() {
|
||||
super({ key: 'MovementTestScene5' });
|
||||
super({ key: 'AutoMovementTestScene' });
|
||||
}
|
||||
|
||||
create() {
|
||||
@@ -108,6 +108,43 @@ export default class MovementTestScene5 extends Phaser.Scene {
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(10, 130, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(10);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(25, 140, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
@@ -213,28 +213,38 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
this.inventoryUI.toggle();
|
||||
});
|
||||
|
||||
// 使用物品快捷键(Q键)
|
||||
this.input.keyboard.on('keydown-Q', () => {
|
||||
console.log('DEBUG: Q键被按下,尝试使用选中的物品');
|
||||
if (this.inventoryUI && this.inventoryUI.selectedItem) {
|
||||
console.log('DEBUG: 有选中的物品,调用useItem方法');
|
||||
this.inventoryUI.useItem(this.inventoryUI.selectedItem);
|
||||
}
|
||||
});
|
||||
|
||||
// 空格键返回启动场景
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
console.log('DEBUG: 空格键被按下,返回启动场景');
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 鼠标左键点击地面种植作物
|
||||
// 鼠标点击处理
|
||||
this.input.on('pointerdown', (pointer) => {
|
||||
console.log(`DEBUG: 鼠标点击事件触发,按键: ${pointer.button}, 位置: x=${pointer.x}, y=${pointer.y}`);
|
||||
console.log(`DEBUG: 当前种植模式状态: isPlantingMode=${this.isPlantingMode}, selectedSeed=${this.selectedSeed ? this.selectedSeed.name : 'null'}`);
|
||||
|
||||
if (this.isPlantingMode && this.selectedSeed) {
|
||||
console.log('DEBUG: 满足种植条件,调用 plantSeedAt 方法');
|
||||
this.plantSeedAt(pointer);
|
||||
}
|
||||
});
|
||||
|
||||
// 鼠标右键取消种植模式
|
||||
this.input.on('pointerdown', (pointer) => {
|
||||
// 检查点击位置是否在UI元素上(背包UI或侧边栏)
|
||||
const isUIClick = this.isPointInUI(pointer);
|
||||
console.log(`DEBUG: 是否点击在UI元素上: ${isUIClick}`);
|
||||
|
||||
if (pointer.rightButtonDown()) {
|
||||
// 右键点击取消种植模式
|
||||
console.log('DEBUG: 鼠标右键点击,取消种植模式');
|
||||
this.cancelPlantingMode();
|
||||
} else if (this.isPlantingMode && this.selectedSeed && !isUIClick) {
|
||||
// 左键点击地面种植作物,确保不是点击UI元素
|
||||
console.log('DEBUG: 满足种植条件且不是UI点击,调用 plantSeedAt 方法');
|
||||
this.plantSeedAt(pointer);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -249,14 +259,30 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
createButtons() {
|
||||
const buttonWidth = 200;
|
||||
const buttonHeight = 40;
|
||||
const buttonY = this.sys.game.config.height - 100;
|
||||
const buttonY = this.sys.game.config.height - 150;
|
||||
|
||||
// 创建拾取物品按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY - 50, '拾取物品(F)', () => {
|
||||
// 调用与F键相同的拾取功能
|
||||
this.inputSystem.handleQuickPickup();
|
||||
});
|
||||
|
||||
// 创建背包按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY, '打开/关闭背包', () => {
|
||||
this.inventoryUI.toggle();
|
||||
});
|
||||
|
||||
// 创建随机物品按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY, '创建随机种子', () => {
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 50, '创建随机种子', () => {
|
||||
const seedTypes = ['wheat_seed', 'carrot_seed'];
|
||||
const randomSeedType = seedTypes[Math.floor(Math.random() * seedTypes.length)];
|
||||
this.itemManager.createItem(randomSeedType, this.player.x + 50, this.player.y);
|
||||
});
|
||||
|
||||
// 创建返回菜单按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 100, '返回菜单', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,8 +338,8 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
|
||||
// 显示种植光标,初始位置设置为当前鼠标位置
|
||||
console.log(`DEBUG: 当前鼠标位置: x=${this.input.mousePointer.x}, y=${this.input.mousePointer.y}`);
|
||||
this.plantingCursor = this.add.text(this.input.mousePointer.x, this.input.mousePointer.y, '🌱', {
|
||||
fontSize: '24px'
|
||||
this.plantingCursor = this.add.text(this.input.mousePointer.x, this.input.mousePointer.y, '🌱', {
|
||||
fontSize: '24px'
|
||||
});
|
||||
|
||||
console.log(`DEBUG: 种植光标创建结果: ${this.plantingCursor ? '成功' : '失败'}`);
|
||||
@@ -330,12 +356,22 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
// 跟随鼠标移动 - 使用命名的事件监听器,方便后续移除
|
||||
this.mouseMoveListener = (pointer) => {
|
||||
console.log(`DEBUG: 鼠标移动事件触发,指针位置: x=${pointer.x}, y=${pointer.y}`);
|
||||
scene.plantingCursor.setPosition(pointer.x, pointer.y);
|
||||
// 检查种植光标是否存在,避免null引用错误
|
||||
if (scene.plantingCursor) {
|
||||
scene.plantingCursor.setPosition(pointer.x, pointer.y);
|
||||
}
|
||||
};
|
||||
|
||||
// 添加鼠标移动事件监听
|
||||
console.log('DEBUG: 添加鼠标移动事件监听');
|
||||
this.input.on('pointermove', this.mouseMoveListener);
|
||||
|
||||
// 更新背包UI,切换到取消种植按钮
|
||||
if (this.inventoryUI) {
|
||||
console.log('DEBUG: 更新背包UI,切换到取消种植按钮');
|
||||
this.inventoryUI.updatePlantButtonState(true);
|
||||
}
|
||||
|
||||
console.log('DEBUG: 种植模式启动完成');
|
||||
}
|
||||
|
||||
@@ -367,6 +403,15 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
console.log(`DEBUG: 鼠标移动监听器移除结果: ${this.mouseMoveListener ? '失败' : '成功'}`);
|
||||
}
|
||||
|
||||
// 更新背包UI,切换回种植按钮
|
||||
if (this.inventoryUI) {
|
||||
console.log('DEBUG: 更新背包UI,切换回种植按钮');
|
||||
this.inventoryUI.updatePlantButtonState(false);
|
||||
// 取消背包中选中的物品,保持UI一致性
|
||||
console.log('DEBUG: 取消背包中选中的物品');
|
||||
this.inventoryUI.deselectItem();
|
||||
}
|
||||
|
||||
console.log('DEBUG: 种植模式取消完成');
|
||||
}
|
||||
|
||||
@@ -376,6 +421,29 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
plantSeedAt(pointer) {
|
||||
console.log('DEBUG: plantSeedAt 方法被调用');
|
||||
|
||||
// 检查背包中是否还有该种子
|
||||
let seedItem = null;
|
||||
if (this.player.inventory) {
|
||||
// 查找背包中是否还有该类型的种子
|
||||
const allItems = this.player.inventory.getAllItems();
|
||||
if (allItems instanceof Map) {
|
||||
allItems.forEach(item => {
|
||||
if (item.itemTypeId === this.selectedSeed.itemTypeId) {
|
||||
seedItem = item;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
seedItem = allItems.find(item => item.itemTypeId === this.selectedSeed.itemTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!seedItem) {
|
||||
console.log('DEBUG: 背包中没有该种子,取消种植');
|
||||
this.showMessage(`背包中没有 ${this.selectedSeed.name},无法种植`);
|
||||
this.cancelPlantingMode();
|
||||
return;
|
||||
}
|
||||
|
||||
// 将屏幕坐标转换为世界坐标
|
||||
const worldPoint = this.cameras.main.getWorldPoint(pointer.x, pointer.y);
|
||||
console.log(`DEBUG: 屏幕坐标转世界坐标: 屏幕(${pointer.x},${pointer.y}) -> 世界(${worldPoint.x},${worldPoint.y})`);
|
||||
@@ -393,13 +461,26 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
|
||||
console.log(`DEBUG: 作物创建结果: ${crop ? '成功' : '失败'}`);
|
||||
|
||||
// 添加到作物组
|
||||
this.cropGroup.add(crop);
|
||||
console.log(`DEBUG: 作物已添加到作物组,当前作物数量: ${this.cropGroup.getLength()}`);
|
||||
|
||||
// 显示种植成功消息
|
||||
this.showMessage(`已种植 ${this.selectedSeed.name}`);
|
||||
console.log(`DEBUG: 显示种植成功消息: 已种植 ${this.selectedSeed.name}`);
|
||||
if (crop) {
|
||||
// 从背包中移除种子
|
||||
if (this.player.inventory) {
|
||||
console.log(`DEBUG: 从背包中移除种子 ${seedItem.id}`);
|
||||
this.player.inventory.removeItem(seedItem.id);
|
||||
// 更新背包UI
|
||||
this.inventoryUI.updateUI();
|
||||
}
|
||||
|
||||
// 添加到作物组
|
||||
this.cropGroup.add(crop);
|
||||
console.log(`DEBUG: 作物已添加到作物组,当前作物数量: ${this.cropGroup.getLength()}`);
|
||||
|
||||
// 显示种植成功消息
|
||||
this.showMessage(`已种植 ${this.selectedSeed.name}`);
|
||||
console.log(`DEBUG: 显示种植成功消息: 已种植 ${this.selectedSeed.name}`);
|
||||
} else {
|
||||
console.log('DEBUG: 作物创建失败');
|
||||
this.showMessage(`种植 ${this.selectedSeed.name} 失败`);
|
||||
}
|
||||
|
||||
// 取消种植模式
|
||||
this.cancelPlantingMode();
|
||||
@@ -429,6 +510,10 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁作物对象
|
||||
crop.destroy();
|
||||
console.log('DEBUG: 作物已销毁');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -601,6 +686,193 @@ export default class FarmingTestScene extends Phaser.Scene {
|
||||
this.unitStatusText.setText(statusText);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查点击位置是否在UI元素上
|
||||
* @param {Phaser.Input.Pointer} pointer - 指针对象
|
||||
* @returns {boolean} 是否点击在UI元素上
|
||||
*/
|
||||
isPointInUI(pointer) {
|
||||
// 检查是否点击在背包UI上
|
||||
if (this.inventoryUI && this.inventoryUI.isOpen) {
|
||||
const uiRect = this.inventoryUI.container.getBounds();
|
||||
if (Phaser.Geom.Rectangle.Contains(uiRect, pointer.x - this.inventoryUI.container.x, pointer.y - this.inventoryUI.container.y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否点击在侧边栏上
|
||||
if (this.sidebar) {
|
||||
const sidebarRect = this.sidebar.getBounds();
|
||||
if (Phaser.Geom.Rectangle.Contains(sidebarRect, pointer.x, pointer.y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否点击在物品信息面板上
|
||||
if (this.inventoryUI && this.inventoryUI.itemInfoPanel) {
|
||||
const infoRect = this.inventoryUI.itemInfoPanel.getBounds();
|
||||
if (Phaser.Geom.Rectangle.Contains(infoRect, pointer.x, pointer.y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否点击在作物详情面板上
|
||||
if (this.cropDetailsPanel) {
|
||||
const detailsRect = this.cropDetailsPanel.getBounds();
|
||||
if (Phaser.Geom.Rectangle.Contains(detailsRect, pointer.x, pointer.y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否点击在交互按钮上(返回菜单按钮等)
|
||||
// 这里可以添加按钮的点击区域检查
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示作物详情信息
|
||||
* @param {Crop} crop - 作物对象
|
||||
*/
|
||||
showCropDetails(crop) {
|
||||
console.log('DEBUG: showCropDetails 方法被调用');
|
||||
|
||||
// 销毁之前的作物详情面板
|
||||
this.hideCropDetails();
|
||||
|
||||
// 创建作物详情面板
|
||||
const panelWidth = 250;
|
||||
const panelHeight = 150;
|
||||
const panelX = this.sys.game.config.width - panelWidth - 20;
|
||||
const panelY = 100;
|
||||
|
||||
this.cropDetailsPanel = this.add.rectangle(
|
||||
panelX,
|
||||
panelY,
|
||||
panelWidth,
|
||||
panelHeight,
|
||||
0x000000,
|
||||
0.8
|
||||
);
|
||||
this.cropDetailsPanel.setOrigin(0, 0);
|
||||
this.cropDetailsPanel.setStrokeStyle(2, 0x4CAF50);
|
||||
this.cropDetailsPanel.setDepth(200);
|
||||
this.cropDetailsPanel.setScrollFactor(0, 0);
|
||||
|
||||
// 阻止事件冒泡
|
||||
this.cropDetailsPanel.setInteractive();
|
||||
this.cropDetailsPanel.on('pointerdown', (pointer) => {
|
||||
return false;
|
||||
});
|
||||
|
||||
// 作物信息文本
|
||||
const cropInfo = crop.getInfo();
|
||||
const growthProgress = Math.min(100, Math.floor(((Date.now() - cropInfo.plantedTime) / cropInfo.growthTime) * 100));
|
||||
const stageNames = ['种子', '幼苗', '成长中', '成熟'];
|
||||
|
||||
let detailsText = `${cropInfo.type} 作物\n`;
|
||||
detailsText += `生长阶段: ${stageNames[cropInfo.growthStage]}\n`;
|
||||
detailsText += `生长进度: ${growthProgress}%\n`;
|
||||
detailsText += `可收获: ${cropInfo.isHarvestable ? '是' : '否'}`;
|
||||
|
||||
this.cropDetailsText = this.add.text(
|
||||
panelX + 10,
|
||||
panelY + 10,
|
||||
detailsText,
|
||||
{ font: '14px Arial', fill: '#ffffff', wordWrap: { width: panelWidth - 20 } }
|
||||
);
|
||||
this.cropDetailsText.setDepth(210);
|
||||
this.cropDetailsText.setScrollFactor(0, 0);
|
||||
|
||||
// 如果作物可收获,添加收获按钮
|
||||
if (cropInfo.isHarvestable) {
|
||||
this.harvestButton = this.add.text(
|
||||
panelX + 10,
|
||||
panelY + 100,
|
||||
'[收获作物]',
|
||||
{ font: '14px Arial', fill: '#00ff00' }
|
||||
);
|
||||
this.harvestButton.setDepth(210);
|
||||
this.harvestButton.setScrollFactor(0, 0);
|
||||
this.harvestButton.setInteractive({
|
||||
useHandCursor: true,
|
||||
cursor: 'pointer'
|
||||
});
|
||||
|
||||
// 绑定收获按钮事件
|
||||
this.harvestButton.on('pointerdown', (pointer) => {
|
||||
console.log('DEBUG: 点击收获按钮');
|
||||
this.harvestCrop(crop);
|
||||
this.hideCropDetails();
|
||||
return false; // 阻止事件冒泡,防止触发角色移动
|
||||
});
|
||||
|
||||
this.harvestButton.on('pointerover', (pointer) => {
|
||||
this.harvestButton.setFill('#ffff00');
|
||||
return false;
|
||||
});
|
||||
|
||||
this.harvestButton.on('pointerout', (pointer) => {
|
||||
this.harvestButton.setFill('#00ff00');
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// 添加关闭按钮
|
||||
this.closeCropDetailsButton = this.add.text(
|
||||
panelX + panelWidth - 25,
|
||||
panelY + 5,
|
||||
'X',
|
||||
{ font: '18px Arial', fill: '#ffffff' }
|
||||
);
|
||||
this.closeCropDetailsButton.setDepth(210);
|
||||
this.closeCropDetailsButton.setScrollFactor(0, 0);
|
||||
this.closeCropDetailsButton.setInteractive({
|
||||
useHandCursor: true,
|
||||
cursor: 'pointer'
|
||||
});
|
||||
|
||||
this.closeCropDetailsButton.on('pointerdown', (pointer) => {
|
||||
this.hideCropDetails();
|
||||
return false;
|
||||
});
|
||||
|
||||
this.closeCropDetailsButton.on('pointerover', (pointer) => {
|
||||
this.closeCropDetailsButton.setFill('#ff0000');
|
||||
return false;
|
||||
});
|
||||
|
||||
this.closeCropDetailsButton.on('pointerout', (pointer) => {
|
||||
this.closeCropDetailsButton.setFill('#ffffff');
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏作物详情信息
|
||||
*/
|
||||
hideCropDetails() {
|
||||
if (this.cropDetailsPanel) {
|
||||
this.cropDetailsPanel.destroy();
|
||||
this.cropDetailsPanel = null;
|
||||
}
|
||||
|
||||
if (this.cropDetailsText) {
|
||||
this.cropDetailsText.destroy();
|
||||
this.cropDetailsText = null;
|
||||
}
|
||||
|
||||
if (this.harvestButton) {
|
||||
this.harvestButton.destroy();
|
||||
this.harvestButton = null;
|
||||
}
|
||||
|
||||
if (this.closeCropDetailsButton) {
|
||||
this.closeCropDetailsButton.destroy();
|
||||
this.closeCropDetailsButton = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示消息
|
||||
*/
|
||||
|
||||
@@ -223,18 +223,28 @@ export default class InventoryTestScene extends Phaser.Scene {
|
||||
createButtons() {
|
||||
const buttonWidth = 200;
|
||||
const buttonHeight = 40;
|
||||
const buttonY = this.sys.game.config.height - 100;
|
||||
const buttonY = this.sys.game.config.height - 150;
|
||||
|
||||
// 创建背包按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY, '打开/关闭背包', () => {
|
||||
this.inventoryUI.toggle();
|
||||
});
|
||||
|
||||
// 创建随机物品按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY, '创建随机物品', () => {
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 50, '创建随机物品', () => {
|
||||
this.itemManager.createRandomItem();
|
||||
});
|
||||
|
||||
// 创建清理物品按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 50, '清理所有物品', () => {
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 100, '清理所有物品', () => {
|
||||
this.itemManager.clearAllItems();
|
||||
this.itemInfoText.setText('所有物品已清理');
|
||||
});
|
||||
|
||||
// 创建返回菜单按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 150, '返回菜单', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -253,15 +253,20 @@ export default class ItemListTestScene extends Phaser.Scene {
|
||||
createButtons() {
|
||||
const buttonWidth = 200;
|
||||
const buttonHeight = 40;
|
||||
const buttonY = this.sys.game.config.height - 100;
|
||||
const buttonY = this.sys.game.config.height - 150;
|
||||
|
||||
// 创建背包按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY, '打开/关闭背包', () => {
|
||||
this.inventoryUI.toggle();
|
||||
});
|
||||
|
||||
// 创建随机物品按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY, '创建随机物品', () => {
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 50, '创建随机物品', () => {
|
||||
this.itemManager.createRandomItem();
|
||||
});
|
||||
|
||||
// 创建清理物品按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 50, '清理所有物品', () => {
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 100, '清理所有物品', () => {
|
||||
this.itemManager.clearAllItems();
|
||||
this.itemInfoText.setText('所有物品已清理');
|
||||
// 更新物品列表UI
|
||||
@@ -269,6 +274,11 @@ export default class ItemListTestScene extends Phaser.Scene {
|
||||
this.itemListUI.updateItems(this.player, this.itemManager.getActiveItems());
|
||||
}
|
||||
});
|
||||
|
||||
// 创建返回菜单按钮
|
||||
this.createButton(this.sys.game.config.width - buttonWidth - 10, buttonY + 150, '返回菜单', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -153,35 +153,58 @@ export default class ItemTestScene extends Phaser.Scene {
|
||||
});
|
||||
|
||||
this.input.keyboard.on('keydown-TWO', () => {
|
||||
// 在单位附近创建食物类物品
|
||||
const x = unit.x + Phaser.Math.Between(-100, 100);
|
||||
const y = unit.y + Phaser.Math.Between(-100, 100);
|
||||
this.itemManager.createItemByType('food', x, y);
|
||||
this.itemManager.createItem('wheat_seed', 0, 0);
|
||||
});
|
||||
|
||||
this.input.keyboard.on('keydown-THREE', () => {
|
||||
// 在单位附近创建工具类物品
|
||||
const x = unit.x + Phaser.Math.Between(-100, 100);
|
||||
const y = unit.y + Phaser.Math.Between(-100, 100);
|
||||
this.itemManager.createItemByType('tool', x, y);
|
||||
this.itemManager.createItem('wooden_sword', 0, 0);
|
||||
});
|
||||
|
||||
this.input.keyboard.on('keydown-FOUR', () => {
|
||||
// 清理所有物品
|
||||
this.itemManager.clearAllItems();
|
||||
this.itemInfoText.setText('所有物品已清理');
|
||||
});
|
||||
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 监听物品点击事件
|
||||
this.events.on('item-clicked', (item) => {
|
||||
this.showItemInfo(item);
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(10, 250, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(10);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(25, 260, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 创建一些交互按钮
|
||||
this.createButtons();
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,6 +80,43 @@ export default class JoystickMovementTestScene extends Phaser.Scene {
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(10, 100, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(10);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(25, 110, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
@@ -78,6 +78,43 @@ export default class KeyboardMovementTestScene extends Phaser.Scene {
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(10, 100, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(10);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(25, 110, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
@@ -291,6 +291,11 @@ export default class MapEditSinglePicTestScene extends Phaser.Scene {
|
||||
this.createButton(this.sys.game.config.width - 200, 130, 180, 30, '加载地图', () => {
|
||||
this.loadMap();
|
||||
});
|
||||
|
||||
// 返回启动场景按钮
|
||||
this.createButton(this.sys.game.config.width - 200, 170, 180, 30, '返回菜单', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -494,6 +494,46 @@ export default class MapEditTestScene extends Phaser.Scene {
|
||||
this.terrainModeButton.on('pointerdown', () => {
|
||||
this.toggleTerrainMode();
|
||||
});
|
||||
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
const buttonX = 10;
|
||||
const buttonY = this.sys.game.config.height - 50;
|
||||
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(buttonX, buttonY, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(100);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(buttonX + 25, buttonY + 10, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(101);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,9 +5,9 @@ import { SelectionSystem } from '../../systems/SelectionSystem.js';
|
||||
import { CommandSystem } from '../../systems/CommandSystem.js';
|
||||
import { MiniMap } from '../../ui/MiniMap.js';
|
||||
|
||||
export default class MovementTestScene6 extends Phaser.Scene {
|
||||
export default class MiniMapTestScene extends Phaser.Scene {
|
||||
constructor() {
|
||||
super({ key: 'MovementTestScene6' });
|
||||
super({ key: 'MiniMapTestScene' });
|
||||
}
|
||||
|
||||
create() {
|
||||
@@ -100,6 +100,9 @@ export default class MovementTestScene6 extends Phaser.Scene {
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
|
||||
// 添加相机移动控制
|
||||
this.cameraSpeed = 2;
|
||||
@@ -110,6 +113,40 @@ export default class MovementTestScene6 extends Phaser.Scene {
|
||||
right: Phaser.Input.Keyboard.KeyCodes.D
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(10, 130, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(10);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(25, 140, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
this.inputSystem.update();
|
||||
|
||||
@@ -213,6 +213,21 @@ export default class ResourceTestScene extends Phaser.Scene {
|
||||
this.nextButtonText.setScrollFactor(0, 0);
|
||||
this.nextButtonText.setDepth(11);
|
||||
|
||||
// 返回菜单按钮
|
||||
this.returnButton = this.add.rectangle(270, 100, 120, 40, 0x333333);
|
||||
this.returnButton.setOrigin(0, 0);
|
||||
this.returnButton.setScrollFactor(0, 0);
|
||||
this.returnButton.setDepth(10);
|
||||
this.returnButton.setInteractive({ useHandCursor: true });
|
||||
|
||||
this.returnButtonText = this.add.text(280, 110, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
this.returnButtonText.setScrollFactor(0, 0);
|
||||
this.returnButtonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
this.prevButton.on('pointerdown', () => {
|
||||
this.currentCategory = (this.currentCategory - 1 + this.resourceCategories.length) % this.resourceCategories.length;
|
||||
@@ -224,11 +239,17 @@ export default class ResourceTestScene extends Phaser.Scene {
|
||||
this.updateCategoryDisplay();
|
||||
});
|
||||
|
||||
this.returnButton.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 悬停效果
|
||||
this.prevButton.on('pointerover', () => this.prevButton.setFillStyle(0x555555));
|
||||
this.prevButton.on('pointerout', () => this.prevButton.setFillStyle(0x333333));
|
||||
this.nextButton.on('pointerover', () => this.nextButton.setFillStyle(0x555555));
|
||||
this.nextButton.on('pointerout', () => this.nextButton.setFillStyle(0x333333));
|
||||
this.returnButton.on('pointerover', () => this.returnButton.setFillStyle(0x555555));
|
||||
this.returnButton.on('pointerout', () => this.returnButton.setFillStyle(0x333333));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,6 +96,43 @@ export default class SelectionAndMovementTestScene extends Phaser.Scene {
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(10, 130, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(10);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(25, 140, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
@@ -78,6 +78,43 @@ export default class TargetMovementTestScene extends Phaser.Scene {
|
||||
this.input.keyboard.on('keydown-SPACE', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
// 添加返回菜单按钮
|
||||
this.createReturnButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建返回菜单按钮
|
||||
*/
|
||||
createReturnButton() {
|
||||
// 创建按钮背景
|
||||
const button = this.add.rectangle(10, 100, 150, 40, 0x333333);
|
||||
button.setOrigin(0, 0);
|
||||
button.setScrollFactor(0, 0);
|
||||
button.setDepth(10);
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
|
||||
// 按钮文本
|
||||
const buttonText = this.add.text(25, 110, '返回菜单', {
|
||||
fontSize: '16px',
|
||||
fill: '#ffffff',
|
||||
fontFamily: 'Arial'
|
||||
});
|
||||
buttonText.setScrollFactor(0, 0);
|
||||
buttonText.setDepth(11);
|
||||
|
||||
// 按钮事件
|
||||
button.on('pointerdown', () => {
|
||||
this.scene.start('BootScene');
|
||||
});
|
||||
|
||||
button.on('pointerover', () => {
|
||||
button.setFillStyle(0x555555);
|
||||
});
|
||||
|
||||
button.on('pointerout', () => {
|
||||
button.setFillStyle(0x333333);
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
Reference in new issue
Block a user