Skip to content

Commit

Permalink
image panel state
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Dec 10, 2021
1 parent b2da3f4 commit 000c111
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/core/reference-image.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class ReferenceImageController {
public enable(config: PluginConfig) {
this.config = config;
this.onPreferencesChanged('responsive', this.prefs.get('responsive'));
this.onPreferencesChanged('referenceImageVisible', this.prefs.get('referenceImageVisible'));
this.image.enable(this.prefs.get('referenceImageFilters'));
}

Expand All @@ -36,12 +37,20 @@ export class ReferenceImageController {
}

private onPreferencesChanged(key: PreferenceKey, value: any) {
if (key === 'responsive') {
const size = value ? this.prefs.get('responsiveSize') as Size
: { width: this.game.width, height: this.game.height };
this.image.source = this.config.referenceImageUrl(size.width, size.height);
} else if (key === 'responsiveSize') {
this.image.source = this.config.referenceImageUrl(value.width, value.height);
switch (key) {
case 'referenceImageVisible':
this.image.visible = value === true;
break;
case 'responsive':
{
const size = value ? this.prefs.get('responsiveSize') as Size
: { width: this.game.width, height: this.game.height };
this.image.source = this.config.referenceImageUrl(size.width, size.height);
}
break;
case 'responsiveSize':
this.image.source = this.config.referenceImageUrl(value.width, value.height);
break;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/editor-view/actions/actions-toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ export class ActionsToolbar extends Widget {
public static readonly tagName = 'phred-actions-toolbar';

private readonly buttons: ActionButton[] = [];

// TODO add these to a dedicated HTMLElement
private orientationBtn: ActionButton;
private orientationTemplates: SizeTemplatesPanel;

// TODO add these to a dedicated HTMLElement
private referenceImageGroup: HTMLElement;
private referenceImageGroupButton: HTMLElement;

private leftPanelToggle: HTMLElement;
private rightPanelToggle: HTMLElement;

Expand All @@ -32,6 +37,7 @@ export class ActionsToolbar extends Widget {
this.createSeparator();

this.createButton(actions.getAction(Actions.TOGGLE_RESPONSIVE));

this.orientationBtn = this.createButton(actions.getAction(Actions.TOGGLE_ORIENTATION));
this.orientationTemplates = this.appendChild(document.createElement(SizeTemplatesPanel.tagName)) as SizeTemplatesPanel;

Expand Down Expand Up @@ -99,6 +105,7 @@ export class ActionsToolbar extends Widget {
Editor.referenceImageController.openOptionsPanel(optionsButton);
});

this.referenceImageGroupButton = optionsButton;
this.referenceImageGroup = panel;
}

Expand Down Expand Up @@ -128,6 +135,10 @@ export class ActionsToolbar extends Widget {
this.referenceImageGroup.classList
.addOrRemove('disabled', value !== true);
break;
case 'referenceImageVisible':
this.referenceImageGroupButton.classList
.addOrRemove('disabled', value !== true);
break;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/scene-view/reference-image/reference-image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ phred-reference-image {
bottom: 0;
pointer-events: none;

&.invisible {
&.invisible,
&.invalid {
display: none;
}

Expand Down
11 changes: 8 additions & 3 deletions src/scene-view/reference-image/reference-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export class ReferenceImage extends HTMLElement implements ReferenceImageFilters
if (this._src === value) return;
this._src = value;
this.image.src = value ?? '';
this.classList.addOrRemove('invisible', !value);
this.classList.addOrRemove('invalid', !value);
if (!value) this.dispatchEvent(new CustomEvent('imageLoaded', { detail: false }));
}

public set visible(value: boolean) {
if (this._src) this.classList.addOrRemove('invisible', !value);
}

public set opacity(value: number) {
this.filters.opacity = Phaser.Math.clamp(value, 0, 1);
this.applyFilters();
Expand Down Expand Up @@ -90,12 +94,13 @@ export class ReferenceImage extends HTMLElement implements ReferenceImageFilters
}

private onImageLoadComplete() {
this.classList.remove('invisible');
this.classList.remove('invalid');
this.dispatchEvent(new CustomEvent('imageLoaded', { detail: true }));
}

private onImageLoadError() {
this.classList.add('invisible');
this._src = null;
this.classList.add('invalid');
this.dispatchEvent(new CustomEvent('imageLoaded', { detail: false }));
}
}
Expand Down

0 comments on commit 000c111

Please sign in to comment.