From 8236002b7cf41b0179aab6ff0a5cd266046e6ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Sun, 6 May 2018 13:48:45 +0900 Subject: [PATCH] Fix: apply RoundRectButton --- src/game/global/define_variables_global.js | 3 +- src/game/lib/input_type_text.js | 2781 ++++++++--------- src/game/lib/round_rect_button.js | 202 +- src/game/login/login.js | 75 +- .../RoundRectButton/round_rect_button_main.js | 39 +- 5 files changed, 1528 insertions(+), 1572 deletions(-) diff --git a/src/game/global/define_variables_global.js b/src/game/global/define_variables_global.js index 92a4ee2..cdcc35c 100644 --- a/src/game/global/define_variables_global.js +++ b/src/game/global/define_variables_global.js @@ -16,8 +16,7 @@ function isReleaseMode() { } -const GAME_SCREEN_SIZE = { x: 1024, y: 768 -} +const GAME_SCREEN_SIZE = { x: 1024, y: 768 } let playerName; diff --git a/src/game/lib/input_type_text.js b/src/game/lib/input_type_text.js index 0015a9a..c9a77ab 100644 --- a/src/game/lib/input_type_text.js +++ b/src/game/lib/input_type_text.js @@ -1,67 +1,36 @@ -var InputTypeText = function(x, y) { - var bmd = game.add.bitmapData(400, 50); - var myInput = game.add.sprite(x, y, bmd); +class InputTypeText { - myInput.canvasInput = new CanvasInput({ - canvas: bmd.canvas, - fontSize: 30, - fontFamily: 'Arial', - fontColor: '#212121', - fontWeight: 'bold', - width: 400, - padding: 8, - borderWidth: 1, - borderColor: '#000', - borderRadius: 3, - boxShadow: '1px 1px 0px #fff', - innerShadow: '0px 0px 5px rgba(0, 0, 0, 0.5)', - placeHolder: 'Enter message here...' - }); - myInput.inputEnabled = true; - myInput.input.useHandCursor = true; - myInput.events.onInputUp.add(this.inputFocus, this); + constructor(x, y) { + var bmd = game.add.bitmapData(400, 50); + var myInput = game.add.sprite(x, y, bmd); - return myInput; -}; + myInput.canvasInput = new CanvasInput({ + canvas: bmd.canvas, + fontSize: 30, + fontFamily: 'Arial', + fontColor: '#212121', + fontWeight: 'bold', + width: 400, + padding: 8, + borderWidth: 1, + borderColor: '#000', + borderRadius: 3, + boxShadow: '1px 1px 0px #fff', + innerShadow: '0px 0px 5px rgba(0, 0, 0, 0.5)', + placeHolder: 'Enter message here...' + }); + myInput.inputEnabled = true; + myInput.input.useHandCursor = true; + myInput.events.onInputUp.add(this.inputFocus, this); -InputTypeText.prototype = { - inputFocus: function(sprite){ - sprite.canvasInput.focus(); - } -}; + return myInput; + } -/* -var inputFocus = function(sprite){ - sprite.canvasInput.focus(); + inputFocus(sprite){ + sprite.canvasInput.focus(); + } } -var createInput = function(x, y){ - var bmd = game.add.bitmapData(400, 50); - var myInput = game.add.sprite(x, y, bmd); - - myInput.canvasInput = new CanvasInput({ - canvas: bmd.canvas, - fontSize: 30, - fontFamily: 'Arial', - fontColor: '#212121', - fontWeight: 'bold', - width: 400, - padding: 8, - borderWidth: 1, - borderColor: '#000', - borderRadius: 3, - boxShadow: '1px 1px 0px #fff', - innerShadow: '0px 0px 5px rgba(0, 0, 0, 0.5)', - placeHolder: 'Enter message here...' - }); - myInput.inputEnabled = true; - myInput.input.useHandCursor = true; - myInput.events.onInputUp.add(this.inputFocus, this); - - return myInput; -} -*/ - /*! * CanvasInput v1.2.0 @@ -74,1352 +43,1352 @@ var createInput = function(x, y){ */ (function() { - // create a buffer that stores all inputs so that tabbing - // between them is made possible. - var inputs = []; - - // initialize the Canvas Input - var CanvasInput = window.CanvasInput = function(o) { - var self = this; - - o = o ? o : {}; - - // setup the defaults - self._canvas = o.canvas || null; - self._ctx = self._canvas ? self._canvas.getContext('2d') : null; - self._x = o.x || 0; - self._y = o.y || 0; - self._extraX = o.extraX || 0; - self._extraY = o.extraY || 0; - self._fontSize = o.fontSize || 14; - self._fontFamily = o.fontFamily || 'Arial'; - self._fontColor = o.fontColor || '#000'; - self._placeHolderColor = o.placeHolderColor || '#bfbebd'; - self._fontWeight = o.fontWeight || 'normal'; - self._fontStyle = o.fontStyle || 'normal'; - self._readonly = o.readonly || false; - self._maxlength = o.maxlength || null; - self._width = o.width || 150; - self._height = o.height || self._fontSize; - self._padding = o.padding >= 0 ? o.padding : 5; - self._borderWidth = o.borderWidth >= 0 ? o.borderWidth : 1; - self._borderColor = o.borderColor || '#959595'; - self._borderRadius = o.borderRadius >= 0 ? o.borderRadius : 3; - self._backgroundImage = o.backgroundImage || ''; - self._boxShadow = o.boxShadow || '1px 1px 0px rgba(255, 255, 255, 1)'; - self._innerShadow = o.innerShadow || '0px 0px 4px rgba(0, 0, 0, 0.4)'; - self._selectionColor = o.selectionColor || 'rgba(179, 212, 253, 0.8)'; - self._placeHolder = o.placeHolder || ''; - self._value = (o.value || self._placeHolder) + ''; - self._onsubmit = o.onsubmit || function() {}; - self._onkeydown = o.onkeydown || function() {}; - self._onkeyup = o.onkeyup || function() {}; - self._onfocus = o.onfocus || function() {}; - self._onblur = o.onblur || function() {}; - self._cursor = false; - self._cursorPos = 0; - self._hasFocus = false; - self._selection = [0, 0]; - self._wasOver = false; - - // parse box shadow - self.boxShadow(self._boxShadow, true); - - // calculate the full width and height with padding, borders and shadows - self._calcWH(); - - // setup the off-DOM canvas - self._renderCanvas = document.createElement('canvas'); - self._renderCanvas.setAttribute('width', self.outerW); - self._renderCanvas.setAttribute('height', self.outerH); - self._renderCtx = self._renderCanvas.getContext('2d'); - - // setup another off-DOM canvas for inner-shadows - self._shadowCanvas = document.createElement('canvas'); - self._shadowCanvas.setAttribute('width', self._width + self._padding * 2); - self._shadowCanvas.setAttribute('height', self._height + self._padding * 2); - self._shadowCtx = self._shadowCanvas.getContext('2d'); - - // setup the background color - if (typeof o.backgroundGradient !== 'undefined') { - self._backgroundColor = self._renderCtx.createLinearGradient( - 0, - 0, - 0, - self.outerH - ); - self._backgroundColor.addColorStop(0, o.backgroundGradient[0]); - self._backgroundColor.addColorStop(1, o.backgroundGradient[1]); - } else { - self._backgroundColor = o.backgroundColor || '#fff'; - } - - // setup main canvas events - if (self._canvas) { - self._canvas.addEventListener('mousemove', function(e) { - e = e || window.event; - self.mousemove(e, self); - }, false); - - self._canvas.addEventListener('mousedown', function(e) { - e = e || window.event; - self.mousedown(e, self); - }, false); - - self._canvas.addEventListener('mouseup', function(e) { - e = e || window.event; - self.mouseup(e, self); - }, false); - } - - // setup a global mouseup to blur the input outside of the canvas - window.addEventListener('mouseup', function(e) { - e = e || window.event; - - if (self._hasFocus && !self._mouseDown) { - self.blur(); - } - }, true); - - // create the hidden input element - self._hiddenInput = document.createElement('input'); - self._hiddenInput.type = 'text'; - self._hiddenInput.style.position = 'absolute'; - self._hiddenInput.style.opacity = 0; - self._hiddenInput.style.pointerEvents = 'none'; - self._hiddenInput.style.left = (self._x + self._extraX + (self._canvas ? self._canvas.offsetLeft : 0)) + 'px'; - self._hiddenInput.style.top = (self._y + self._extraY + (self._canvas ? self._canvas.offsetTop : 0)) + 'px'; - self._hiddenInput.style.width = self._width + 'px'; - self._hiddenInput.style.height = self._height + 'px'; - self._hiddenInput.style.zIndex = 0; - if (self._maxlength) { - self._hiddenInput.maxLength = self._maxlength; - } - document.body.appendChild(self._hiddenInput); - self._hiddenInput.value = self._value; - - // setup the keydown listener - self._hiddenInput.addEventListener('keydown', function(e) { - e = e || window.event; - - if (self._hasFocus) { - self.keydown(e, self); - } - }); - - // setup the keyup listener - self._hiddenInput.addEventListener('keyup', function(e) { - e = e || window.event; - - // update the canvas input state information from the hidden input - self._value = self._hiddenInput.value; - self._cursorPos = self._hiddenInput.selectionStart; - self.render(); - - if (self._hasFocus) { - self._onkeyup(e, self); - } - }); - - // add this to the buffer - inputs.push(self); - self._inputsIndex = inputs.length - 1; - - // draw the text box - self.render(); - }; - - // setup the prototype - CanvasInput.prototype = { - /** - * Get/set the main canvas. - * @param {Object} data Canvas reference. - * @return {Mixed} CanvasInput or current canvas. - */ - canvas: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._canvas = data; - self._ctx = self._canvas.getContext('2d'); - - return self.render(); - } else { - return self._canvas; - } - }, - - /** - * Get/set the x-position. - * @param {Number} data The pixel position along the x-coordinate. - * @return {Mixed} CanvasInput or current x-value. - */ - x: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._x = data; - - return self.render(); - } else { - return self._x; - } - }, - - /** - * Get/set the y-position. - * @param {Number} data The pixel position along the y-coordinate. - * @return {Mixed} CanvasInput or current y-value. - */ - y: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._y = data; - - return self.render(); - } else { - return self._y; - } - }, - - /** - * Get/set the extra x-position (generally used when no canvas is specified). - * @param {Number} data The pixel position along the x-coordinate. - * @return {Mixed} CanvasInput or current x-value. - */ - extraX: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._extraX = data; - - return self.render(); - } else { - return self._extraX; - } - }, - - /** - * Get/set the extra y-position (generally used when no canvas is specified). - * @param {Number} data The pixel position along the y-coordinate. - * @return {Mixed} CanvasInput or current y-value. - */ - extraY: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._extraY = data; - - return self.render(); - } else { - return self._extraY; - } - }, - - /** - * Get/set the font size. - * @param {Number} data Font size. - * @return {Mixed} CanvasInput or current font size. - */ - fontSize: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._fontSize = data; - - return self.render(); - } else { - return self._fontSize; - } - }, - - /** - * Get/set the font family. - * @param {String} data Font family. - * @return {Mixed} CanvasInput or current font family. - */ - fontFamily: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._fontFamily = data; - - return self.render(); - } else { - return self._fontFamily; - } - }, - - /** - * Get/set the font color. - * @param {String} data Font color. - * @return {Mixed} CanvasInput or current font color. - */ - fontColor: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._fontColor = data; - - return self.render(); - } else { - return self._fontColor; - } - }, - - /** - * Get/set the place holder font color. - * @param {String} data Font color. - * @return {Mixed} CanvasInput or current place holder font color. - */ - placeHolderColor: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._placeHolderColor = data; - - return self.render(); - } else { - return self._placeHolderColor; - } - }, - - /** - * Get/set the font weight. - * @param {String} data Font weight. - * @return {Mixed} CanvasInput or current font weight. - */ - fontWeight: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._fontWeight = data; - - return self.render(); - } else { - return self._fontWeight; - } - }, - - /** - * Get/set the font style. - * @param {String} data Font style. - * @return {Mixed} CanvasInput or current font style. - */ - fontStyle: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._fontStyle = data; - - return self.render(); - } else { - return self._fontStyle; - } - }, - - /** - * Get/set the width of the text box. - * @param {Number} data Width in pixels. - * @return {Mixed} CanvasInput or current width. - */ - width: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._width = data; - self._calcWH(); - self._updateCanvasWH(); - - return self.render(); - } else { - return self._width; - } - }, - - /** - * Get/set the height of the text box. - * @param {Number} data Height in pixels. - * @return {Mixed} CanvasInput or current height. - */ - height: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._height = data; - self._calcWH(); - self._updateCanvasWH(); - - return self.render(); - } else { - return self._height; - } - }, - - /** - * Get/set the padding of the text box. - * @param {Number} data Padding in pixels. - * @return {Mixed} CanvasInput or current padding. - */ - padding: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._padding = data; - self._calcWH(); - self._updateCanvasWH(); - - return self.render(); - } else { - return self._padding; - } - }, - - /** - * Get/set the border width. - * @param {Number} data Border width. - * @return {Mixed} CanvasInput or current border width. - */ - borderWidth: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._borderWidth = data; - self._calcWH(); - self._updateCanvasWH(); - - return self.render(); - } else { - return self._borderWidth; - } - }, - - /** - * Get/set the border color. - * @param {String} data Border color. - * @return {Mixed} CanvasInput or current border color. - */ - borderColor: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._borderColor = data; - - return self.render(); - } else { - return self._borderColor; - } - }, - - /** - * Get/set the border radius. - * @param {Number} data Border radius. - * @return {Mixed} CanvasInput or current border radius. - */ - borderRadius: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._borderRadius = data; - - return self.render(); - } else { - return self._borderRadius; - } - }, - - /** - * Get/set the background color. - * @param {Number} data Background color. - * @return {Mixed} CanvasInput or current background color. - */ - backgroundColor: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._backgroundColor = data; - - return self.render(); - } else { - return self._backgroundColor; - } - }, - - /** - * Get/set the background gradient. - * @param {Number} data Background gradient. - * @return {Mixed} CanvasInput or current background gradient. - */ - backgroundGradient: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._backgroundColor = self._renderCtx.createLinearGradient( - 0, - 0, - 0, - self.outerH - ); - self._backgroundColor.addColorStop(0, data[0]); - self._backgroundColor.addColorStop(1, data[1]); - - return self.render(); - } else { - return self._backgroundColor; - } - }, - - /** - * Get/set the box shadow. - * @param {String} data Box shadow in CSS format (1px 1px 1px rgba(0, 0, 0.5)). - * @param {Boolean} doReturn (optional) True to prevent a premature render. - * @return {Mixed} CanvasInput or current box shadow. - */ - boxShadow: function(data, doReturn) { - var self = this; - - if (typeof data !== 'undefined') { - // parse box shadow - var boxShadow = data.split('px '); - self._boxShadow = { - x: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[0], 10), - y: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[1], 10), - blur: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[2], 10), - color: self._boxShadow === 'none' ? '' : boxShadow[3] - }; - - // take into account the shadow and its direction - if (self._boxShadow.x < 0) { - self.shadowL = Math.abs(self._boxShadow.x) + self._boxShadow.blur; - self.shadowR = self._boxShadow.blur + self._boxShadow.x; - } else { - self.shadowL = Math.abs(self._boxShadow.blur - self._boxShadow.x); - self.shadowR = self._boxShadow.blur + self._boxShadow.x; - } - if (self._boxShadow.y < 0) { - self.shadowT = Math.abs(self._boxShadow.y) + self._boxShadow.blur; - self.shadowB = self._boxShadow.blur + self._boxShadow.y; - } else { - self.shadowT = Math.abs(self._boxShadow.blur - self._boxShadow.y); - self.shadowB = self._boxShadow.blur + self._boxShadow.y; - } - - self.shadowW = self.shadowL + self.shadowR; - self.shadowH = self.shadowT + self.shadowB; - - self._calcWH(); - - if (!doReturn) { - self._updateCanvasWH(); - - return self.render(); - } - } else { - return self._boxShadow; - } - }, - - /** - * Get/set the inner shadow. - * @param {String} data In the format of a CSS box shadow (1px 1px 1px rgba(0, 0, 0.5)). - * @return {Mixed} CanvasInput or current inner shadow. - */ - innerShadow: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._innerShadow = data; - - return self.render(); - } else { - return self._innerShadow; - } - }, - - /** - * Get/set the text selection color. - * @param {String} data Color. - * @return {Mixed} CanvasInput or current selection color. - */ - selectionColor: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._selectionColor = data; - - return self.render(); - } else { - return self._selectionColor; - } - }, - - /** - * Get/set the place holder text. - * @param {String} data Place holder text. - * @return {Mixed} CanvasInput or current place holder text. - */ - placeHolder: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._placeHolder = data; - - return self.render(); - } else { - return self._placeHolder; - } - }, - - /** - * Get/set the current text box value. - * @param {String} data Text value. - * @return {Mixed} CanvasInput or current text value. - */ - value: function(data) { - var self = this; - - if (typeof data !== 'undefined') { - self._value = data + ''; - self._hiddenInput.value = data + ''; - - // update the cursor position - self._cursorPos = self._clipText().length; - - self.render(); - - return self; - } else { - return (self._value === self._placeHolder) ? '' : self._value; - } - }, - - /** - * Set or fire the onsubmit event. - * @param {Function} fn Custom callback. - */ - onsubmit: function(fn) { - var self = this; - - if (typeof fn !== 'undefined') { - self._onsubmit = fn; - - return self; - } else { - self._onsubmit(); - } - }, - - /** - * Set or fire the onkeydown event. - * @param {Function} fn Custom callback. - */ - onkeydown: function(fn) { - var self = this; - - if (typeof fn !== 'undefined') { - self._onkeydown = fn; - - return self; - } else { - self._onkeydown(); - } - }, - - /** - * Set or fire the onkeyup event. - * @param {Function} fn Custom callback. - */ - onkeyup: function(fn) { - var self = this; - - if (typeof fn !== 'undefined') { - self._onkeyup = fn; - - return self; - } else { - self._onkeyup(); - } - }, - - /** - * Place focus on the CanvasInput box, placing the cursor - * either at the end of the text or where the user clicked. - * @param {Number} pos (optional) The position to place the cursor. - * @return {CanvasInput} - */ - focus: function(pos) { - var self = this; - - // only fire the focus event when going from unfocussed - if (!self._hasFocus) { - self._onfocus(self); - - // remove focus from all other inputs - for (var i=0; i