mirror of
http://junepve.top:3000/chicrobot/CINC.git
synced 2026-10-30 00:31:29 +08:00
feat(control) 小地图
This commit is contained in:
1 parent
f86e5f3a79
commit
e2bc630d6d
8 files changed
+339
-24
No files matched your search
@@ -7,7 +7,9 @@ export class SelectionSystem {
|
||||
this.selectionBox = null;
|
||||
|
||||
scene.events.on('selection-start', this.onStart, this);
|
||||
scene.events.on('selection-update', this.onUpdate, this);
|
||||
scene.events.on('selection-end', this.onEnd, this);
|
||||
scene.events.on('select-unit', this.onSelectUnit, this);
|
||||
}
|
||||
|
||||
onStart(pos) {
|
||||
@@ -20,6 +22,37 @@ export class SelectionSystem {
|
||||
}
|
||||
}
|
||||
|
||||
onUpdate(rect) {
|
||||
if (this.selectionBox && this.selectionBox.visible) {
|
||||
// 更新选择框的位置和大小
|
||||
this.selectionBox.setPosition(rect.centerX, rect.centerY);
|
||||
this.selectionBox.setSize(rect.width, rect.height);
|
||||
}
|
||||
}
|
||||
|
||||
onSelectUnit(unit) {
|
||||
// 清除所有单位的选中状态
|
||||
this.scene.unitGroup.getChildren().forEach(u => {
|
||||
if (u.setSelected) {
|
||||
u.setSelected(false);
|
||||
}
|
||||
});
|
||||
|
||||
// 清除当前选择
|
||||
clearSelection();
|
||||
|
||||
// 选择点击的单位
|
||||
setActiveUnit(unit);
|
||||
addToSelection(unit);
|
||||
|
||||
// 设置选中状态
|
||||
if (unit.setSelected) {
|
||||
unit.setSelected(true);
|
||||
}
|
||||
|
||||
this.scene.events.emit('units-selected', [unit]);
|
||||
}
|
||||
|
||||
onEnd(rect) {
|
||||
if (this.selectionBox) {
|
||||
this.selectionBox.setVisible(false);
|
||||
@@ -30,12 +63,28 @@ export class SelectionSystem {
|
||||
const unitRect = unit.getBounds();
|
||||
return Phaser.Geom.Rectangle.Overlaps(rect, unitRect);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 先清除所有单位的选中状态
|
||||
units.forEach(unit => {
|
||||
if (unit.setSelected) {
|
||||
unit.setSelected(false);
|
||||
}
|
||||
});
|
||||
|
||||
clearSelection();
|
||||
selected.forEach(addToSelection);
|
||||
|
||||
if (selected.length > 0) {
|
||||
setActiveUnit(selected[0]); // 激活第一个
|
||||
// 先设置激活单位
|
||||
setActiveUnit(selected[0]);
|
||||
// 然后添加所有选中的单位(包括激活单位)
|
||||
selected.forEach(unit => {
|
||||
addToSelection(unit);
|
||||
if (unit.setSelected) {
|
||||
unit.setSelected(true);
|
||||
}
|
||||
});
|
||||
this.scene.events.emit('units-selected', selected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user