Add: KeyMapper
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
class KeyButton {
|
||||
|
||||
constructor(x, y, width, height, normalText, shiftText, align_type) {
|
||||
constructor(x, y, width, height, normalText, shiftText, alignType) {
|
||||
this.normalText = normalText;
|
||||
this.shiftText = shiftText;
|
||||
this.alignType = alignType;
|
||||
|
||||
this.setting = new RoundRectButtonSetting(x, y, width, height, KeyButton.DEFALUT_ROUND_AMOUNT_PX);
|
||||
this.setting.strokeWidthPx = 2;
|
||||
@@ -10,9 +11,9 @@ class KeyButton {
|
||||
this.button = this.makeButtonSprite(this.setting);
|
||||
this.button.inputEnabled = true;
|
||||
|
||||
this.text = this.makeText(this.setting, this.normalText);
|
||||
this.buttonText = this.makeText(this.setting, this.normalText);
|
||||
if(this.normalText.length > 0) {
|
||||
this.button.addChild(this.text);
|
||||
this.button.addChild(this.buttonText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,22 +31,51 @@ class KeyButton {
|
||||
}
|
||||
|
||||
makeText(setting, textContent) {
|
||||
let width = setting.width - setting.strokeWidthPx * 2;
|
||||
let offsetX_px = 4;
|
||||
let offsetY_px = 5;
|
||||
|
||||
let width = setting.width - setting.strokeWidthPx * 2 - offsetX_px;
|
||||
let height = setting.height - setting.strokeWidthPx * 2;
|
||||
|
||||
setting.fontStyle.font = "20px Arial";
|
||||
let btnText = game.add.text(0, 0, textContent, setting.fontStyle)
|
||||
if(this.alignType === KeyButton.NORMAL_KEY)
|
||||
setting.fontStyle.font = "20px Courier New";
|
||||
else
|
||||
setting.fontStyle.font = "11px Courier New";
|
||||
|
||||
let btnText = game.add.text(offsetX_px, offsetY_px, textContent, setting.fontStyle)
|
||||
.setTextBounds(setting.strokeWidthPx, setting.strokeWidthPx, width, height);
|
||||
|
||||
// btnText.boundsAlignH = "right";
|
||||
// btnText.boundsAlignV = "bottom";
|
||||
if(this.alignType === KeyButton.NORMAL_KEY) {
|
||||
btnText.boundsAlignH = "center";
|
||||
btnText.boundsAlignV = "middle";
|
||||
} else if(this.alignType === KeyButton.LEFT_FUNCTION_KEY) {
|
||||
btnText.boundsAlignH = "left";
|
||||
btnText.boundsAlignV = "bottom";
|
||||
} else if(this.alignType === KeyButton.CENTER_FUNCTION_KEY) {
|
||||
btnText.boundsAlignH = "center";
|
||||
btnText.boundsAlignV = "bottom";
|
||||
} else if(this.alignType === KeyButton.RIGHT_FUNCTION_KEY) {
|
||||
btnText.boundsAlignH = "right";
|
||||
btnText.boundsAlignV = "bottom";
|
||||
}
|
||||
|
||||
btnText.lineSpacing = RoundRectButtonSetting.DEFAULT_TEXT_LINE_SPACING_PX;
|
||||
// btnText.lineSpacing = RoundRectButtonSetting.DEFAULT_TEXT_LINE_SPACING_PX;
|
||||
|
||||
btnText.text = textContent;
|
||||
|
||||
return btnText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
onShiftPressed() {
|
||||
this.buttonText.text = this.shiftText;
|
||||
}
|
||||
|
||||
onShiftUnpressed() {
|
||||
this.buttonText.text = this.normalText;
|
||||
}
|
||||
|
||||
mouseOut() {
|
||||
this.text.fill = this.setting.textColors.out;
|
||||
this.buttonStroke.tint = this.setting.strokeColors.out;
|
||||
@@ -87,4 +117,10 @@ class KeyButton {
|
||||
KeyButton.NONE_ICON = "";
|
||||
KeyButton.NONE_BUTTON_TEXT = "";
|
||||
|
||||
KeyButton.DEFALUT_ROUND_AMOUNT_PX = 10;
|
||||
KeyButton.DEFALUT_ROUND_AMOUNT_PX = 10;
|
||||
|
||||
KeyButton.NORMAL_KEY = "normal_key";
|
||||
KeyButton.NORMAL_FUNCTION_KEY = "normal_function_key";
|
||||
KeyButton.LEFT_FUNCTION_KEY = "left_function_key";
|
||||
KeyButton.CENTER_FUNCTION_KEY = "center_function_key";
|
||||
KeyButton.RIGHT_FUNCTION_KEY = "right_function_key";
|
||||
Reference in New Issue
Block a user