Adding buttons to switch mode

This commit is contained in:
David Négrier 2020-08-17 15:20:03 +02:00
parent 05ca8c813e
commit 7fe2cc19c3
3 changed files with 49 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

View File

@ -355,12 +355,14 @@ body {
width: 100%; width: 100%;
flex-wrap: wrap; flex-wrap: wrap;
align-items: flex-start;
padding: 1%; padding: 1%;
} }
.chat-mode div { .chat-mode div {
margin: 1%; margin: 1%;
max-height: 96%;
} }
.chat-mode.one-col > div { .chat-mode.one-col > div {

View File

@ -106,6 +106,9 @@ export class GameScene extends Phaser.Scene {
private PositionNextScene: Array<Array<{ key: string, hash: string }>> = new Array<Array<{ key: string, hash: string }>>(); private PositionNextScene: Array<Array<{ key: string, hash: string }>> = new Array<Array<{ key: string, hash: string }>>();
private startLayerName: string|undefined; private startLayerName: string|undefined;
private presentationModeSprite!: Sprite;
private chatModeSprite!: Sprite;
private repositionCallback!: (this: Window, ev: UIEvent) => void;
static createFromUrl(mapUrlFile: string, instance: string, key: string|null = null): GameScene { static createFromUrl(mapUrlFile: string, instance: string, key: string|null = null): GameScene {
const mapKey = GameScene.getMapKeyByUrl(mapUrlFile); const mapKey = GameScene.getMapKeyByUrl(mapUrlFile);
@ -158,6 +161,12 @@ export class GameScene extends Phaser.Scene {
); );
}); });
this.load.spritesheet(
'layout_modes',
'resources/objects/layout_modes.png',
{frameWidth: 32, frameHeight: 32}
);
loadAllLayers(this.load); loadAllLayers(this.load);
this.load.bitmapFont('main_font', 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml'); this.load.bitmapFont('main_font', 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
@ -213,6 +222,7 @@ export class GameScene extends Phaser.Scene {
this.scene.stop(this.scene.key); this.scene.stop(this.scene.key);
this.scene.remove(this.scene.key); this.scene.remove(this.scene.key);
window.removeEventListener('resize', this.repositionCallback);
}) })
// When connection is performed, let's connect SimplePeer // When connection is performed, let's connect SimplePeer
@ -364,15 +374,39 @@ export class GameScene extends Phaser.Scene {
}, 500); }, 500);
} }
// FIXME: handle display / hide based on number of cameras connected
this.presentationModeSprite = this.add.sprite(2, this.game.renderer.height - 2, 'layout_modes', 0);
this.presentationModeSprite.setScrollFactor(0, 0);
this.presentationModeSprite.setOrigin(0, 1);
this.presentationModeSprite.setInteractive();
this.presentationModeSprite.on('pointerup', this.switchLayoutMode.bind(this));
this.chatModeSprite = this.add.sprite(36, this.game.renderer.height - 2, 'layout_modes', 3);
this.chatModeSprite.setScrollFactor(0, 0);
this.chatModeSprite.setOrigin(0, 1);
this.chatModeSprite.setInteractive();
this.chatModeSprite.on('pointerup', this.switchLayoutMode.bind(this));
// FIXME: change this to use the class for input // FIXME: change this to use the class for input
this.input.keyboard.on('keyup-' + 'M', function () { this.input.keyboard.on('keyup-' + 'M', () => {
const mode = layoutManager.getLayoutMode(); this.switchLayoutMode();
if (mode === LayoutMode.Presentation) {
layoutManager.switchLayoutMode(LayoutMode.VideoChat);
} else {
layoutManager.switchLayoutMode(LayoutMode.Presentation);
}
}); });
this.repositionCallback = this.reposition.bind(this);
window.addEventListener('resize', this.repositionCallback);
this.reposition();
}
private switchLayoutMode(): void {
const mode = layoutManager.getLayoutMode();
if (mode === LayoutMode.Presentation) {
layoutManager.switchLayoutMode(LayoutMode.VideoChat);
this.presentationModeSprite.setFrame(1);
this.chatModeSprite.setFrame(2);
} else {
layoutManager.switchLayoutMode(LayoutMode.Presentation);
this.presentationModeSprite.setFrame(0);
this.chatModeSprite.setFrame(3);
}
} }
private getExitSceneUrl(layer: ITiledMapLayer): string|undefined { private getExitSceneUrl(layer: ITiledMapLayer): string|undefined {
@ -634,6 +668,7 @@ export class GameScene extends Phaser.Scene {
this.simplePeer.unregister(); this.simplePeer.unregister();
this.scene.stop(); this.scene.stop();
this.scene.remove(this.scene.key); this.scene.remove(this.scene.key);
window.removeEventListener('resize', this.repositionCallback);
this.scene.start(nextSceneKey.key, { this.scene.start(nextSceneKey.key, {
startLayerName: nextSceneKey.hash startLayerName: nextSceneKey.hash
}); });
@ -821,4 +856,9 @@ export class GameScene extends Phaser.Scene {
const endPos = mapUrlStart.indexOf(".json"); const endPos = mapUrlStart.indexOf(".json");
return mapUrlStart.substring(startPos, endPos); return mapUrlStart.substring(startPos, endPos);
} }
private reposition(): void {
this.presentationModeSprite.setY(this.game.renderer.height - 2);
this.chatModeSprite.setY(this.game.renderer.height - 2);
}
} }