From 9061ab54c3419c60d46813ecb6fd79535b56e396 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: Tue, 16 Oct 2018 11:47:34 +0900 Subject: [PATCH] Add: button shortcut text --- src/game/lib/button/back_button.js | 3 ++- src/game/lib/button/round_rect_button.js | 28 ++++++++++++++++++++++++ src/game/result/result.js | 1 + src/game/start/start.js | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/game/lib/button/back_button.js b/src/game/lib/button/back_button.js index d16090a..cebf4a5 100644 --- a/src/game/lib/button/back_button.js +++ b/src/game/lib/button/back_button.js @@ -25,7 +25,8 @@ function BackButton(clickEvent) { "#333" ); - new RoundRectButton(setting, RoundRectButton.NONE_ICON, "<", clickEvent); + var backButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "<", clickEvent); + backButton.addShortcutText("ESC"); } BackButton.prototype.startState = function(stateName) { diff --git a/src/game/lib/button/round_rect_button.js b/src/game/lib/button/round_rect_button.js index e65ac64..570af23 100644 --- a/src/game/lib/button/round_rect_button.js +++ b/src/game/lib/button/round_rect_button.js @@ -99,6 +99,9 @@ function RoundRectButton(roundRectSetting, iconName, buttonText, clickEvent) { this.setIcon(this.icon); } + this.shortcutText = this.makeShortcutText(); + this.button.addChild(this.shortcutText); + // this.button.anchor.setTo(0.5, 0.5); this.button.inputEnabled = true; this.setEventMethod(this.button); @@ -182,9 +185,28 @@ RoundRectButton.prototype.setIcon = function(icon) { this.mouseOut(); } +RoundRectButton.prototype.makeShortcutText = function() { + var shortcutText = game.add.text(this.button.width / 2, this.button.height * 9 / 10, ""); + shortcutText.anchor.set(0.5); + + shortcutText.fontSize = this.button.height * 2 / 10; + // shortcutText.addColor(this.setting.textColors.over, 0); + shortcutText.addColor("0xffffff", 0); + + return shortcutText; +} + +RoundRectButton.prototype.addShortcutText = function(text) { + var scText = "[ " + text + " ]"; + this.shortcutText.text = scText; + +} + RoundRectButton.prototype.mouseOut = function() { this.text.fill = this.setting.textColors.out; + if(this.shortcutText != undefined) + this.shortcutText.fill = this.setting.textColors.over; this.buttonStroke.tint = this.setting.strokeColors.out; this.button.tint = this.setting.buttonColors.out; if(typeof this.buttonIcon !== "undefined") { @@ -194,6 +216,8 @@ RoundRectButton.prototype.mouseOut = function() { RoundRectButton.prototype.mouseOver = function() { this.text.fill = this.setting.textColors.over; + if(this.shortcutText != undefined) + this.shortcutText.fill = this.setting.textColors.over; this.buttonStroke.tint = this.setting.strokeColors.over; this.button.tint = this.setting.buttonColors.over; if(typeof this.buttonIcon !== "undefined") { @@ -203,6 +227,8 @@ RoundRectButton.prototype.mouseOver = function() { RoundRectButton.prototype.mouseDown = function() { this.text.fill = this.setting.textColors.down; + if(this.shortcutText != undefined) + this.shortcutText.fill = this.setting.textColors.over; this.buttonStroke.tint = this.setting.strokeColors.down; this.button.tint = this.setting.buttonColors.down; if(typeof this.buttonIcon !== "undefined") { @@ -212,6 +238,8 @@ RoundRectButton.prototype.mouseDown = function() { RoundRectButton.prototype.buttonDisabled = function() { this.text.fill = this.setting.textColors.disabled; + if(this.shortcutText != undefined) + this.shortcutText.fill = this.setting.textColors.disabled; this.buttonStroke.tint = this.setting.strokeColors.disabled; this.button.tint = this.setting.buttonColors.disabled; if(typeof this.buttonIcon !== "undefined") { diff --git a/src/game/result/result.js b/src/game/result/result.js index dec18cb..3924781 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -166,6 +166,7 @@ var Result = { setting.fontStyle.fontWeight = "bold"; var startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "다시 시작", this.restartStage); + startButton.addShortcutText("Enter"); }, diff --git a/src/game/start/start.js b/src/game/start/start.js index b675a17..f891374 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -156,6 +156,7 @@ var Start = { setting.fontStyle.fontWeight = "bold"; var startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "시작", this.startStage); + startButton.addShortcutText("Enter"); }, makeRankingButton: function() {