diff --git a/client/SkribblAvatar.js b/client/SkribblAvatar.js new file mode 100644 index 0000000000000000000000000000000000000000..bfb898c2fc0fa0ab363d0b42d4d3d1f2884fc28a --- /dev/null +++ b/client/SkribblAvatar.js @@ -0,0 +1,85 @@ +import { SkribblCanvasOverlay } from "./SkribblCanvas.js"; + +/** + * Custom element `<skribbl-avatar>` to remember how the player looks like and for configuration. + */ + export default class SkribblAvatar extends HTMLElement { + constructor(){ + super(); + this.attachShadow({mode:"open"}); + this.shadowRoot.innerHTML = ` + <style> + :host { + display: block; + position: relative; + overflow: hidden; + background: #ffffff; + border-radius: 5px; + } + .container-character{ + border: 2px solid #777; + border-radius: 10px; + } + .character-eyes{ + height: 34px; + width: 34px; + background:url("/res/MouthsAndEyes.png"); + background-position: 10px 0; + } + .character-mouth{ + height: 34px; + width: 34x; + background:url("/res/MouthsAndEyes.png"); + background-position: 0px -52px; + } + </style> + + <div class="container-character"> + <div id="eyes" class="character-eyes" alt="CharacterLook"></div> + <div id="mouth" class="character-mouth" alt="CharacterLook"></div> + </div> + `; + this.eyesDisplacement = 10; + this.mouthDisplacement = 0; + } + + /** @param {boolean} toTheRight */ + changeEye(toTheRight) { + let displacement = 80; + + if (toTheRight){ + this.eyesDisplacement += displacement; + }else{ + this.eyesDisplacement -= displacement; + } + const eye = this.shadowRoot.getElementById("eyes"); + eye.style.backgroundPositionX = this.eyesDisplacement+"px"; + } + + /** @param {boolean} toTheRight */ + changeMouth(toTheRight) { + let displacement = 80; + + if (toTheRight){ + this.mouthDisplacement += displacement; + }else{ + this.mouthDisplacement -= displacement; + } + const mouth = this.shadowRoot.getElementById("mouth"); + mouth.style.backgroundPositionX = this.mouthDisplacement+"px"; + } + + /** @param {string} unique_title */ + getStyleSheet(unique_title) { + for(var i=0; i<document.styleSheets.length; i++) { + var sheet = document.styleSheets[i]; + if(sheet.title == unique_title) { + return sheet; + } + } + } + +} + + +customElements.define("skribbl-avatar",SkribblAvatar); diff --git a/client/SkribblMenu.js b/client/SkribblMenu.js index 200b10cfb3c2e65583eb83ad63935b95d07a1d05..3dc1c3940f3392fdb28854b6982220411fe121f8 100644 --- a/client/SkribblMenu.js +++ b/client/SkribblMenu.js @@ -1,3 +1,7 @@ +import SkribblAvatar from "./SkribblAvatar.js"; +import SkribblCanvas from "./SkribblCanvas.js"; + + /** * Custom element `<skribbl-menu>` for the name selection menu that appears when first entering a game. */ @@ -13,12 +17,126 @@ export default class SkribblMenu extends HTMLElement { border-radius: 10px; padding: 15px; } + .arrow-button { + margin: auto; + text-align: center; + display:inline-block; + border:none; + height:34px; + width:34px; + background: url('/res/selectArrows.png'); + background-size: 54px; + background-repeat: no-repeat; + cursor: pointer; + } + .arrow-left{ + background-position: 0px 0px; + } + + .arrow-right{ + background-position: -24px 0px; + } + + .middle-aligned{ + margin: auto; + text-align: center; + display:inline-block; + } + #ColorButtons{ + text-align: center; + } + .generic-button{ + padding: 8px 25px; + font-size: 20px; + background: orange; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; + } + + .name-input{ + padding: 8px 25px; + font-size: 20px; + } + + + + .container-left-arrows{ + display:flex; + flex-direction: column; + } + .container-right-arrows{ + display:flex; + flex-direction: column; + } + .container-customize-avatar{ + display:flex; + justify-content: center; + position: relative; + } + + + </style> - <input type="text"> - <button>Play</button> + <div class="container-customize-avatar"> + + <div class="container" id="ColorButtons"> + <div class="container-left-arrows"> + <button id="arrow-left-eyes" class="arrow-button arrow-left"></button> + <button id="arrow-left-mouth" class="arrow-button arrow-left"></button> + </div> + </div> + + <div id="avatar-container"></div> + + <div class="container" id="ColorButtons"> + <div class="container-right-arrows"> + <button id="arrow-right-eyes" class="arrow-button arrow-right"></button> + <button id="arrow-right-mouth" class="arrow-button arrow-right"></button> + </div> + </div> + + + + + </div> + + <div class="middle-aligned"> + <input type="text" class="name-input" placeholder="Your Name"> + <button id="play-button" class ="generic-button">Play</button> + </div> + + `; + this._avatarContainer = this.shadowRoot.getElementById("avatar-container"); + this._avatar = new SkribblAvatar(); + this._avatarContainer.append(this._avatar); + + this._selectEyesLeftButton = this.shadowRoot.querySelector("#arrow-left-eyes"); + this._selectEyesLeftButton.addEventListener("click",e=>{ + this._avatar.changeEye(false); + + }); + + this._selectEyesRightButton = this.shadowRoot.querySelector("#arrow-right-eyes"); + this._selectEyesRightButton.addEventListener("click",e=>{ + this._avatar.changeEye(true); + }); + + this._selectMouthLeftButton = this.shadowRoot.querySelector("#arrow-left-mouth"); + this._selectMouthLeftButton.addEventListener("click",e=>{ + this._avatar.changeMouth(false); + + }); + + this._selectMouthRightButton = this.shadowRoot.querySelector("#arrow-right-mouth"); + this._selectMouthRightButton.addEventListener("click",e=>{ + this._avatar.changeMouth(true); + }); + this._nameInput = this.shadowRoot.querySelector("input"); - this._playButton = this.shadowRoot.querySelector("button"); + this._playButton = this.shadowRoot.querySelector("#play-button"); /** @type {Promise<{name:string}>} */ this._proceedPromise = new Promise(resolve=>{ this._playButton.addEventListener("click",e=>{ diff --git a/client/res/MouthsAndEyes.png b/client/res/MouthsAndEyes.png new file mode 100644 index 0000000000000000000000000000000000000000..201f3d6b9eb56f076563b8019736f95049787e35 Binary files /dev/null and b/client/res/MouthsAndEyes.png differ diff --git a/client/res/selectArrows.png b/client/res/selectArrows.png new file mode 100644 index 0000000000000000000000000000000000000000..2718751b617ddacc6f23b2560e4f290b06bba339 Binary files /dev/null and b/client/res/selectArrows.png differ diff --git a/startEverythingUp.sh b/startEverythingUp.sh new file mode 100755 index 0000000000000000000000000000000000000000..b4a7341d1fcb8f7b1c617e787de861290ac3b412 --- /dev/null +++ b/startEverythingUp.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cd client/ +php -S localhost:8080 +cd .. +