Skip to content

Commit

Permalink
added responsive toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Oct 1, 2021
1 parent 2a11f35 commit 29f89ff
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Actions {
public static readonly TOGGLE_GIZMOS = 'TOGGLE_GIZMOS';
public static readonly TOGGLE_GUIDES = 'TOGGLE_GUIDES';
public static readonly TOGGLE_HIT_AREA = 'TOGGLE_HIT_AREA';
public static readonly TOGGLE_RESPONSIVE = 'TOGGLE_RESPONSIVE';
public static readonly TOGGLE_REF_IMAGE = 'TOGGLE_REF_IMAGE';
public static readonly TOGGLE_ENABLED = 'TOGGLE_ENABLED';
public static readonly PRINT_OBJECT = 'PRINT_OBJECT';
Expand Down
6 changes: 6 additions & 0 deletions src/core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ class EditorClass {
label: 'hit area',
icon: 'fa-hand-point-up',
},
{
id: Actions.TOGGLE_RESPONSIVE,
toggle: true,
label: 'responsive',
icon: 'fa-expand-arrows-alt',
},
{
id: Actions.TOGGLE_REF_IMAGE,
label: 'reference image',
Expand Down
11 changes: 11 additions & 0 deletions src/core/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ export class Preferences {
this.save('hitArea', value);
}

private _responsive = false;

public get responsive() { return this._responsive; }

public set responsive(value: boolean) {
this._responsive = value;
this.notifyListeners('responsive', value);
this.save('responsive', value);
}

// #endregion

public readonly onPreferenceChanged = new Phaser.Signal();
Expand All @@ -76,6 +86,7 @@ export class Preferences {
actions.setActionCommand(Actions.TOGGLE_GIZMOS, () => this.gizmos = !this._gizmos, () => this._gizmos);
actions.setActionCommand(Actions.TOGGLE_HIT_AREA, () => this.hitArea = !this._hitArea, () => this._hitArea);
actions.setActionCommand(Actions.TOGGLE_GUIDES, () => this.guides = !this._guides, () => this._guides);
actions.setActionCommand(Actions.TOGGLE_RESPONSIVE, () => this.responsive = !this._responsive, () => this._responsive);
actions.setActionCommand(Actions.TOGGLE_REF_IMAGE, () => this.refImage = !this._refImage, () => this._refImage);
}

Expand Down
1 change: 1 addition & 0 deletions src/editor-view/actions/actions-toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class ActionsToolbar extends Widget {
this.createButton(actions.getAction(Actions.TOGGLE_HIT_AREA));
this.createButton(actions.getAction(Actions.TOGGLE_GIZMOS));
this.createSeparator();
this.createButton(actions.getAction(Actions.TOGGLE_RESPONSIVE));
this.createButton(actions.getAction(Actions.ZOOM_OUT));
this.createButton(actions.getAction(Actions.ZOOM_IN));
this.createSeparator();
Expand Down
6 changes: 6 additions & 0 deletions src/editor-view/game-container/game-container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ phred-game-container {

#phred-game-parent {
position: absolute;

&.responsive {
width: 100% !important;
height: 100% !important;
}

.phred-game,
.phred-game * {
max-width: 100% !important;
Expand Down
19 changes: 19 additions & 0 deletions src/editor-view/game-container/game-container.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ComponentTags } from 'component-tags';
import { ActionHandler } from 'core/action-handler';
import { Actions } from 'core/actions';
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import './game-container.scss';

const MIN_WIDTH = 100;
Expand All @@ -22,12 +24,18 @@ export class GameContainer extends HTMLElement {
actions.setActionCommand(Actions.ZOOM, (e) => this.zoom(-(e as WheelEvent).deltaY));
actions.setActionCommand(Actions.ZOOM_IN, () => this.zoom(100));
actions.setActionCommand(Actions.ZOOM_OUT, () => this.zoom(-100));
Editor.prefs.onPreferenceChanged.add(this.onPreferencesChanged, this);
this.onPreferencesChanged('responsive', Editor.prefs.responsive);

this.onmousedown = this.onInputDown;
this.onmousemove = this.onInputMove;
this.onmouseup = this.onInputUp;
}

private onPreferencesChanged(key: PreferenceKey, value: boolean) {
if (key === 'responsive') this.setResponsive(value);
}

public addGame(game: Phaser.Game) {
this.game = game;
const el = game.canvas.parentElement;
Expand All @@ -54,6 +62,17 @@ export class GameContainer extends HTMLElement {
this.game.scale.refresh();
}

private setResponsive(responsive: boolean) {
const style = this.gameEditorParentElement.style;
if (responsive) {
style.width = '100%';
style.height = '100%';
} else {
style.width = 'unset';
style.height = 'unset';
}
}

// #region Panning

private _downPageX = 0;
Expand Down

0 comments on commit 29f89ff

Please sign in to comment.