diff --git a/CHANGELOG.md b/CHANGELOG.md index d1dafb4b..baef9eca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- Floating windows can now be resized + ### Changed - Reduced the minimum size of TeleportGround and TouchTrigger to 8 -- +- The tile selector now resets zoom and pan when the tileset is changed + ### Fixed - Fixed an issue where keyboard shortcuts conflicted with input elements [#364](https://github.com/CCDirectLink/crosscode-map-editor/issues/364) diff --git a/webapp/src/app/components/dialogs/floating-window/floating-window.component.html b/webapp/src/app/components/dialogs/floating-window/floating-window.component.html index 9d673447..c479f667 100644 --- a/webapp/src/app/components/dialogs/floating-window/floating-window.component.html +++ b/webapp/src/app/components/dialogs/floating-window/floating-window.component.html @@ -1,23 +1,28 @@
-
- {{ title }} - @if (showMin) { - - } @if (showClose) { - }
-
- +
+ +
diff --git a/webapp/src/app/components/dialogs/floating-window/floating-window.component.scss b/webapp/src/app/components/dialogs/floating-window/floating-window.component.scss index 0b3efd24..9b5893a2 100644 --- a/webapp/src/app/components/dialogs/floating-window/floating-window.component.scss +++ b/webapp/src/app/components/dialogs/floating-window/floating-window.component.scss @@ -5,14 +5,21 @@ $toolbarHeight: 32px; min-width: 100px; position: absolute; z-index: 100; + } -.ng-draggable { - cursor: move; +.is-resizable { + resize: both; + overflow: hidden; + direction: rtl; + + & > ::ng-deep * { + direction: ltr; + } } -.title { - user-select: none; +.ng-draggable { + cursor: move; } .toolbar { @@ -48,8 +55,3 @@ $toolbarHeight: 32px; min-height: 0; height: 100px !important; } - -.content { - height: 100%; -} - diff --git a/webapp/src/app/components/dialogs/floating-window/floating-window.component.ts b/webapp/src/app/components/dialogs/floating-window/floating-window.component.ts index 98c2f233..d826bc53 100644 --- a/webapp/src/app/components/dialogs/floating-window/floating-window.component.ts +++ b/webapp/src/app/components/dialogs/floating-window/floating-window.component.ts @@ -1,68 +1,53 @@ -import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ChangeDetectionStrategy } from '@angular/core'; import { CdkDrag, CdkDragHandle } from '@angular/cdk/drag-drop'; -import { FlexModule } from '@angular/flex-layout/flex'; -import { MatButton } from '@angular/material/button'; -import { NgStyle } from '@angular/common'; +import { Component, effect, ElementRef, input, linkedSignal, output, viewChild } from '@angular/core'; import { ExtendedModule } from '@angular/flex-layout/extended'; +import { MatButton } from '@angular/material/button'; @Component({ selector: 'app-floating-window', templateUrl: './floating-window.component.html', styleUrls: ['./floating-window.component.scss'], - changeDetection: ChangeDetectionStrategy.Eager, - imports: [CdkDrag, FlexModule, CdkDragHandle, MatButton, NgStyle, ExtendedModule] + imports: [CdkDrag, CdkDragHandle, MatButton, ExtendedModule] }) -export class FloatingWindowComponent implements OnInit, OnChanges { - - @Input() visible = true; - @Input() title = 'no title'; - - @Input() height = ''; - @Input() width = ''; - @Input() top: string | number = 0; - @Input() right: string | number = 0; +export class FloatingWindowComponent { + public readonly visible = input(true); + public readonly title = input('no title'); - @Input() showClose = false; - @Input() showMin = true; + public readonly height = input(''); + public readonly width = input(''); + public readonly top = input(0); + public readonly right = input(0); - @Output() close = new EventEmitter(); - @Output() dragEnd = new EventEmitter(); + public readonly showClose = input(false); + public readonly showMin = input(true); - contentStyle = { - height: this.height, - display: '' - }; - - constructor() { - } - - ngOnInit() { - this.updateContentStyle(); - } - - ngOnChanges(changes: SimpleChanges): void { - if (changes['visible']) { - this.updateContentStyle(); + public readonly close = output(); + public readonly dragEnd = output(); + public readonly resize = output<{ width: number, height: number; }>(); + + protected readonly isVisible = linkedSignal(this.visible); + + private readonly content = viewChild>('content'); + + private readonly _resizeObserver = effect((cleanup) => { + const content = this.content(); + if (!content) { + return; } - } - - private updateContentStyle() { - this.contentStyle = { - height: this.visible ? this.height : '0', - display: this.visible ? 'inherit' : 'none' - }; - } + const observer = new ResizeObserver((entries) => this.resize.emit(entries[0].contentRect)); + observer.observe(content.nativeElement); + cleanup(() => observer.disconnect()); + }); - onDragEnd() { + protected onDragEnd() { this.dragEnd.emit(); } - toggle() { - this.visible = !this.visible; - this.updateContentStyle(); + protected toggle() { + this.isVisible.update(visible => !visible); } - onClose() { + protected onClose() { this.close.emit(); } diff --git a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.html b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.html index e4cb3fad..ca325254 100644 --- a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.html +++ b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.html @@ -1,9 +1,12 @@ - -
+ (resize)="onResize()" + [style.display]="hide() ? 'none' : ''"> +
diff --git a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.scss b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.scss index 144b85d5..b4bbb955 100644 --- a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.scss +++ b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.scss @@ -3,14 +3,4 @@ position: relative; background-color: var(--gray-800); overflow: hidden; - max-height: 80vh; -} - -.button-container { - padding-right: 16px; - margin-bottom: 8px; -} - -.item-selected { - background-color: var(--gray-700) !important; -} +} \ No newline at end of file diff --git a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.ts b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.ts index df6402eb..e3c9fc1c 100644 --- a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.ts +++ b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.component.ts @@ -1,35 +1,39 @@ -import { AfterViewInit, ChangeDetectionStrategy, Component, HostListener, inject, OnDestroy } from '@angular/core'; +import { AfterViewInit, Component, ElementRef, inject, OnDestroy, signal, viewChild } from '@angular/core'; import { NavigationStart, Router } from '@angular/router'; import * as Phaser from 'phaser'; import { EditorView } from '../../../../models/editor-view'; import { GlobalEventsService } from '../../../../services/global-events.service'; -import { TileSelectorScene } from './tile-selector.scene'; import { FloatingWindowComponent } from '../floating-window.component'; +import { TileSelectorScene } from './tile-selector.scene'; @Component({ selector: 'app-tile-selector', templateUrl: './tile-selector.component.html', styleUrls: ['./tile-selector.component.scss'], - changeDetection: ChangeDetectionStrategy.Eager, imports: [FloatingWindowComponent], + host: { + '(window:resize)': 'onResize()' + } }) export class TileSelectorComponent implements AfterViewInit, OnDestroy { private display?: Phaser.Game; private scene?: TileSelectorScene; - hide = false; + protected readonly hide = signal(false); + + private readonly content = viewChild>('content'); constructor() { const globalEvents = inject(GlobalEventsService); const router = inject(Router); - globalEvents.currentView.subscribe(view => this.hide = view !== EditorView.Layers); + globalEvents.currentView.subscribe(view => this.hide.set(view !== EditorView.Layers)); // TODO: floating windows should be handled globally router.events.subscribe(event => { if (event instanceof NavigationStart) { - this.hide = event.url === '/3d'; + this.hide.set(event.url === '/3d'); } }); } @@ -51,18 +55,26 @@ export class TileSelectorComponent implements AfterViewInit, OnDestroy { zoom: 1, scene: [this.scene], }); + + this.onResize(); } ngOnDestroy() { this.display?.destroy(true); } - @HostListener('window:resize', ['$event']) - onResize(event: Event) { + onResize() { if (!this.display) { return; } this.display.scale.refresh(); + + const scale = this.getScale(); + this.display.scale.resize( + scale.width, + scale.height, + ); + this.display.scale.setZoom(1 / window.devicePixelRatio); } onDragEnd() { @@ -72,4 +84,18 @@ export class TileSelectorComponent implements AfterViewInit, OnDestroy { this.scene.resize(); } + + private getScale() { + const rect = this.content()?.nativeElement.getBoundingClientRect(); + if (!rect) { + return { + width: 400 * window.devicePixelRatio, + height: 1200 * window.devicePixelRatio, + }; + } + return { + width: rect.width * window.devicePixelRatio, + height: rect.height * window.devicePixelRatio, + }; + } } diff --git a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.scene.ts b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.scene.ts index 3de8984b..9f72a977 100644 --- a/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.scene.ts +++ b/webapp/src/app/components/dialogs/floating-window/tile-selector/tile-selector.scene.ts @@ -1,11 +1,11 @@ import * as Phaser from 'phaser'; -import { Subscription } from 'rxjs'; +import { distinctUntilChanged, filter, map, Subscription } from 'rxjs'; import { Globals } from '../../../../services/globals'; +import { BaseTileDrawer } from '../../../../services/phaser/BaseTileDrawer'; import { Helper } from '../../../../services/phaser/helper'; import { MapPan } from '../../../../services/phaser/map-pan'; import { CCMapLayer } from '../../../../services/phaser/tilemap/cc-map-layer'; import { customPutTilesAt } from '../../../../services/phaser/tilemap/layer-helper'; -import { BaseTileDrawer } from '../../../../services/phaser/BaseTileDrawer'; export class TileSelectorScene extends Phaser.Scene { @@ -67,6 +67,17 @@ export class TileSelectorScene extends Phaser.Scene { const start = Helper.indexToPoint(baseTile.id, this.tilesetWidth); this.baseDrawer.drawRect(width + 1, height + 1, start.x * Globals.TILE_SIZE, start.y * Globals.TILE_SIZE); })); + + this.subs.push(Globals.mapLoaderService.selectedLayer.pipe( + map(layer => layer?.details?.tilesetName), + filter(tileset => !!tileset), + distinctUntilChanged(), + ).subscribe(() => { + const camera = this.cameras.main; + camera.scrollX = 0; + camera.scrollY = 0; + camera.zoom = 1; + })); const pan = new MapPan(this, 'mapPan'); this.add.existing(pan);