Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<div class="container mat-elevation-z8"
[style.width]="width"
[style.top]="top"
[style.right]="right"
[style.top]="top()"
[style.right]="right()"
(stopped)="onDragEnd()"
cdkDrag
>
<div class="toolbar" fxLayout="row" fxLayoutAlign="center" cdkDragHandle>
<span fxFlexAlign="center" class="title" style="pointer-events: none;" fxFlex>{{ title }}</span>
@if (showMin) {
<button mat-button color="primary" fxFlexAlign="center" class="toolbar-button minimize-button"
(click)="toggle()">-
<div class="toolbar flex flex-row items-center" cdkDragHandle>
<span class="select-none pointer-events-none grow">{{ title() }}</span>
@if (showMin()) {
<button mat-button color="primary" class="toolbar-button minimize-button" (click)="toggle()">
-
</button>
} @if (showClose) {
<button mat-button color="warn" fxFlexAlign="center" class="toolbar-button close-button"
(click)="onClose()">x
} @if (showClose()) {
<button mat-button color="warn" class="toolbar-button close-button" (click)="onClose()">
x
</button>
}
</div>
<div class="content" [ngStyle]="contentStyle">
<ng-content [ngStyle]="{display: visible ? 'inherit' : 'none'}"></ng-content>
<div
[style.width]="width()"
[style.height]="isVisible() ? height() : '0'"
[style.display]="isVisible() ? 'inherit' : 'none'"
[class.is-resizable]="isVisible()"
#content>

<ng-content [style.display]="isVisible() ? 'inherit' : 'none'"></ng-content>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -48,8 +55,3 @@ $toolbarHeight: 32px;
min-height: 0;
height: 100px !important;
}

.content {
height: 100%;
}

Original file line number Diff line number Diff line change
@@ -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<string | number>(0);
public readonly right = input<string | number>(0);

@Output() close = new EventEmitter<void>();
@Output() dragEnd = new EventEmitter<void>();
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<void>();
public readonly dragEnd = output<void>();
public readonly resize = output<{ width: number, height: number; }>();

protected readonly isVisible = linkedSignal(this.visible);

private readonly content = viewChild<ElementRef<HTMLDivElement>>('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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<app-floating-window [right]="'4px'"
[top]="'240px'"
[title]="'Tile selector'"
<app-floating-window right="4px"
top="240px"
height="calc(100vh - 400px)"
width="400px"
title="Tile selector"
(dragEnd)="onDragEnd()"
[style.display]="hide ? 'none' : ''">
<div class="tile-selector-container">
(resize)="onResize()"
[style.display]="hide() ? 'none' : ''">
<div class="tile-selector-container size-full" #content>
<div id="tile-selector-content"></div>
</div>
</app-floating-window>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ElementRef<HTMLDivElement>>('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');
}
});
}
Expand All @@ -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() {
Expand All @@ -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,
};
}
}
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
Loading