From e493428dc9b57836f5e2ab7407a3bf86e69e5434 Mon Sep 17 00:00:00 2001 From: duckietm Date: Thu, 6 Mar 2025 15:51:55 +0100 Subject: [PATCH] :up: FloorPlanner Add the select all button --- .../images/floorplaneditor/icon-select.png | Bin 0 -> 1721 bytes src/assets/styles/icons.scss | 6 + .../floorplan-editor/common/Constants.ts | 2 +- .../common/FloorplanEditor.ts | 106 ++++++++++++------ .../floorplan-editor/common/Tile.ts | 12 ++ .../views/FloorplanOptionsView.tsx | 3 + 6 files changed, 93 insertions(+), 36 deletions(-) create mode 100644 src/assets/images/floorplaneditor/icon-select.png diff --git a/src/assets/images/floorplaneditor/icon-select.png b/src/assets/images/floorplaneditor/icon-select.png new file mode 100644 index 0000000000000000000000000000000000000000..dc81c0ed66e0b5bc60be795355460a4b0dc27aee GIT binary patch literal 1721 zcmbVNO^Do79FKIBy6qw=_=Sg%y=*_;aVFCaRUvJU>sR$Id(W|M6?5eSW$#tUMJ9!mfMM<2K>#cODRg z+duPai^-yU$id9dA;Ri3*Y!h=7K8%_yCK3$G!g5x=>-Mp%9)QP(IW-vh~YvvoTe?W zvKG;Wwb>e8Tf#Px4n86t=sKLhrwJ0femjVrZb9nvI((hpmL;(dNtOyyF%=XS-8pfZ zMO3tN3cwJmqGjihiA>El_lqi2bs1{1q5^0+dfrhrarl$CTtphqeCe^F7{4k=tt1H@ zS?+W?xsH}&QBziI+m@j!t193K5U&Oa>VhDi95Iw=j3X~hJQj#4BdW9Iq#$vtgBbiU zqYdI=o_NOOE(&EO2h*7PK!P(|xE!_n;sndIO??_9F~=$yHf*tk#VxiCb@uo=0iIje z%`~?3;`^CIoRn917{i2YiH>WlA(iK8%$6fe%PZXGWExHAOh*(YEUGcq9#v{?WLZ>= zoGnfr@dCm+@t#c^XbB~>Af;6UiUJh7rogmnhP4kW4uk`!%ZS%l&7cN=8h~a^F&q^- z8oUn5dxoF{-4sl)(_oR0c)*^Inp6&hrX*%*bf#IGMO>J>)A}x4*Qo|^f&xsdrGms` z&UqejEZxM!A_mA)q5_TT3b2WZfJT&hUegI8YGbs&#PD)j*>wM)%L&7r<6l(`TSQej z5mu=I5YlZ>M}`6Fx~7{7)XhB1*q(?y{-UAwX4cdd;fxxhwu;mSup7DsOhZ?JZR8bT zSP0cMjbPPM({AoJh*R-mUb@xc`>{Zu8?M@(*zXAk;k4Ha5>AUui8Q?JZIO>#QXcN_ zv?wRNLGcIbF>53p6wzXn=kBJ>C2wawMk_bAeru&1c*?AA*Np$i`Ymt6lx&s|yQ1I)5KJwQu92iMw}xI{VH0_dU5|hk1Ut_WOe%JT`W+0$&|Fx&P-E zfBNv1FU~Dq+*=er`Qyr4Ur${9o_(9&YYBH%&i!_3(%bXicjf59`JQ|B@cPq7XD*f3 zpFh#N_(AXR>! 0) + if(currentHeightIndex === futureHeightIndex) return; + + // Only update _width and _height if not forcing. + if (!force && futureHeightIndex > 0) { - if((x + 1) > this._width) this._width = x + 1; - - if((y + 1) > this._height) this._height = y + 1; + if ((x + 1) > this._width) this._width = x + 1; + if ((y + 1) > this._height) this._height = y + 1; } - + const newHeight = HEIGHT_SCHEME[futureHeightIndex]; - - if(!newHeight) return; - - // if(tile.isBlocked) return; - + if (!newHeight) return; + this._tilemap[y][x].height = newHeight; - - this.renderTiles(); + + if(render) this.renderTiles(); } public renderTiles(): void @@ -205,6 +198,51 @@ export class FloorplanEditor } this.renderer.drawImage(this._image, asset.frame.x, asset.frame.y, asset.frame.w, asset.frame.h, positionX, positionY, asset.frame.w, asset.frame.h); + + // If the tile is selected, draw a semi-transparent blue overlay. + if (tile.selected) + { + this.renderer.fillStyle = 'rgba(0, 0, 255, 0.3)'; + this.renderer.fillRect(positionX, positionY, asset.frame.w, asset.frame.h); + } + } + } + } + + public toggleSelectAll(): void + { + + const newState = true; + + + for (let y = 0; y < this._tilemap.length; y++) + { + for (let x = 0; x < this._tilemap[y].length; x++) + { + this._tilemap[y][x].selected = newState; + this.onClick(x, y, false, true); + } + } + + this.recalcActiveArea(); + this.renderTiles(); + } + + + // New helper method to recalculate active area dimensions. + private recalcActiveArea(): void + { + this._width = 0; + this._height = 0; + for (let y = 0; y < this._tilemap.length; y++) + { + for (let x = 0; x < this._tilemap[y].length; x++) + { + if (this._tilemap[y][x].height !== 'x') + { + if ((x + 1) > this._width) this._width = x + 1; + if ((y + 1) > this._height) this._height = y + 1; + } } } } @@ -307,7 +345,6 @@ export class FloorplanEditor } } - const rows = []; for(let y = 0; y < this._height; y++) @@ -317,7 +354,6 @@ export class FloorplanEditor for(let x = 0; x < this._width; x++) { const tile = this._tilemap[y][x]; - row[x] = tile.height; } @@ -341,8 +377,8 @@ export class FloorplanEditor public clearCanvas(): void { - this.renderer.fillStyle = '0x000000'; - this.renderer.fillRect(0, 0, this._renderer.canvas.width, this._renderer.canvas.height); + this.renderer.fillStyle = '#000000'; + this.renderer.fillRect(0, 0, this._renderer.canvas.width, this._renderer.canvas.height); } public get renderer(): CanvasRenderingContext2D @@ -379,4 +415,4 @@ export class FloorplanEditor return FloorplanEditor._INSTANCE; } -} \ No newline at end of file +} diff --git a/src/components/floorplan-editor/common/Tile.ts b/src/components/floorplan-editor/common/Tile.ts index fd9c059..444855f 100644 --- a/src/components/floorplan-editor/common/Tile.ts +++ b/src/components/floorplan-editor/common/Tile.ts @@ -2,11 +2,13 @@ export class Tile { private _height: string; private _isBlocked: boolean; + private _selected: boolean; // new property constructor(height: string, isBlocked: boolean) { this._height = height; this._isBlocked = isBlocked; + this._selected = false; // default to not selected } public get height(): string @@ -28,4 +30,14 @@ export class Tile { this._isBlocked = val; } + + public get selected(): boolean + { + return this._selected; + } + + public set selected(value: boolean) + { + this._selected = value; + } } diff --git a/src/components/floorplan-editor/views/FloorplanOptionsView.tsx b/src/components/floorplan-editor/views/FloorplanOptionsView.tsx index b168581..13e5e7d 100644 --- a/src/components/floorplan-editor/views/FloorplanOptionsView.tsx +++ b/src/components/floorplan-editor/views/FloorplanOptionsView.tsx @@ -138,6 +138,9 @@ export const FloorplanOptionsView: FC<{}> = props => selectAction(FloorAction.DOOR) }> + FloorplanEditor.instance.toggleSelectAll() }> + +