mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 12:55:06 +00:00
remove unit menu (#1338)
## Description:
This PR reverts 0b79d0be16
The unit menu adds additionally complexity, and can be unintentionally
opened on mobile when trying to build a unit.
Unit upgrades will be handled automatically:
https://github.com/openfrontio/OpenFrontIO/commit/513fcb094418f0e9405e878396bd5b3db8b34e5a
## Please complete the following:
- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors
## Please put your Discord username so you can be contacted if a bug or
regression is found:
evan
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { colord, Colord } from "colord";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { MouseUpEvent } from "../../InputHandler";
|
||||
import { TransformHandler } from "../TransformHandler";
|
||||
import { Layer } from "./Layer";
|
||||
import { UnitInfoModal } from "./UnitInfoModal";
|
||||
|
||||
import cityIcon from "../../../../resources/non-commercial/images/buildings/cityAlt1.png";
|
||||
import factoryIcon from "../../../../resources/non-commercial/images/buildings/factoryAlt1.png";
|
||||
@@ -18,7 +16,6 @@ import { GameUpdateType } from "../../../core/game/GameUpdates";
|
||||
import { GameView, UnitView } from "../../../core/game/GameView";
|
||||
|
||||
const underConstructionColor = colord({ r: 150, g: 150, b: 150 });
|
||||
const selectedUnitColor = colord({ r: 0, g: 255, b: 255 });
|
||||
|
||||
// Base radius values and scaling factor for unit borders and territories
|
||||
const BASE_BORDER_RADIUS = 16.5;
|
||||
@@ -37,8 +34,6 @@ export class StructureLayer implements Layer {
|
||||
private context: CanvasRenderingContext2D;
|
||||
private unitIcons: Map<string, HTMLImageElement> = new Map();
|
||||
private theme: Theme;
|
||||
private selectedStructureUnit: UnitView | null = null;
|
||||
private previouslySelected: UnitView | null = null;
|
||||
private tempCanvas: HTMLCanvasElement;
|
||||
private tempContext: CanvasRenderingContext2D;
|
||||
|
||||
@@ -80,14 +75,7 @@ export class StructureLayer implements Layer {
|
||||
private game: GameView,
|
||||
private eventBus: EventBus,
|
||||
private transformHandler: TransformHandler,
|
||||
private unitInfoModal: UnitInfoModal | null,
|
||||
) {
|
||||
if (!unitInfoModal) {
|
||||
throw new Error(
|
||||
"UnitInfoModal instance must be provided to StructureLayer.",
|
||||
);
|
||||
}
|
||||
this.unitInfoModal = unitInfoModal;
|
||||
this.theme = game.config().theme();
|
||||
this.tempCanvas = document.createElement("canvas");
|
||||
const tempContext = this.tempCanvas.getContext("2d");
|
||||
@@ -132,7 +120,6 @@ export class StructureLayer implements Layer {
|
||||
|
||||
init() {
|
||||
this.redraw();
|
||||
this.eventBus.on(MouseUpEvent, (e) => this.onMouseUp(e));
|
||||
}
|
||||
|
||||
redraw() {
|
||||
@@ -228,9 +215,6 @@ export class StructureLayer implements Layer {
|
||||
|
||||
if (!unit.isActive()) return;
|
||||
|
||||
if (this.selectedStructureUnit === unit) {
|
||||
borderColor = selectedUnitColor;
|
||||
}
|
||||
this.drawBorder(unit, borderColor, config);
|
||||
|
||||
// Render icon at 1/2 scale for better quality
|
||||
@@ -283,84 +267,4 @@ export class StructureLayer implements Layer {
|
||||
clearCell(cell: Cell) {
|
||||
this.context.clearRect(cell.x * 2, cell.y * 2, 2, 2);
|
||||
}
|
||||
|
||||
private findStructureUnitAtCell(
|
||||
cell: { x: number; y: number },
|
||||
maxDistance: number = 10,
|
||||
): UnitView | null {
|
||||
const targetRef = this.game.ref(cell.x, cell.y);
|
||||
|
||||
const allUnitTypes = Object.values(UnitType);
|
||||
|
||||
const nearby = this.game.nearbyUnits(targetRef, maxDistance, allUnitTypes);
|
||||
|
||||
for (const { unit } of nearby) {
|
||||
if (unit.isActive() && this.isUnitTypeSupported(unit.type())) {
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private onMouseUp(event: MouseUpEvent) {
|
||||
const cell = this.transformHandler.screenToWorldCoordinates(
|
||||
event.x,
|
||||
event.y,
|
||||
);
|
||||
if (!this.game.isValidCoord(cell.x, cell.y)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const clickedUnit = this.findStructureUnitAtCell(cell);
|
||||
this.previouslySelected = this.selectedStructureUnit;
|
||||
|
||||
if (clickedUnit) {
|
||||
if (clickedUnit.owner() !== this.game.myPlayer()) {
|
||||
return;
|
||||
}
|
||||
const wasSelected = this.previouslySelected === clickedUnit;
|
||||
if (wasSelected) {
|
||||
this.selectedStructureUnit = null;
|
||||
if (this.previouslySelected) {
|
||||
this.handleUnitRendering(this.previouslySelected);
|
||||
}
|
||||
this.unitInfoModal?.onCloseStructureModal();
|
||||
} else {
|
||||
this.selectedStructureUnit = clickedUnit;
|
||||
if (
|
||||
this.previouslySelected &&
|
||||
this.previouslySelected !== clickedUnit
|
||||
) {
|
||||
this.handleUnitRendering(this.previouslySelected);
|
||||
}
|
||||
this.handleUnitRendering(clickedUnit);
|
||||
|
||||
const screenPos = this.transformHandler.worldToScreenCoordinates(cell);
|
||||
const unitTile = clickedUnit.tile();
|
||||
this.unitInfoModal?.onOpenStructureModal({
|
||||
eventBus: this.eventBus,
|
||||
unit: clickedUnit,
|
||||
x: screenPos.x,
|
||||
y: screenPos.y,
|
||||
tileX: this.game.x(unitTile),
|
||||
tileY: this.game.y(unitTile),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.selectedStructureUnit = null;
|
||||
if (this.previouslySelected) {
|
||||
this.handleUnitRendering(this.previouslySelected);
|
||||
}
|
||||
this.unitInfoModal?.onCloseStructureModal();
|
||||
}
|
||||
}
|
||||
|
||||
public unSelectStructureUnit() {
|
||||
if (this.selectedStructureUnit) {
|
||||
this.previouslySelected = this.selectedStructureUnit;
|
||||
this.selectedStructureUnit = null;
|
||||
this.handleUnitRendering(this.previouslySelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user