Cocos2d-x の EditBox コントロールクラスで数字のみ入力させたいがそのようなInputMode指定ができなかったのでcocos2d-x(V3.2)本体ソースを修正した際のメモ
リファレンスには、NUMERICを指定すればInt型になるような表現が書かれているが実際には、DECIMALと動作が変わらない。
リファレンス抜粋
enum InputMode
The EditBox::InputMode defines the type of text that the user is allowed to enter.
Enumerator
EditBox::InputMode | exp. |
---|---|
ANY | The user is allowed to enter any text, including line breaks. |
EMAIL_ADDRESS | The user is allowed to enter an e-mail address. |
NUMERIC | The user is allowed to enter an integer value. |
PHONE_NUMBER | The user is allowed to enter a phone number. |
URL | The user is allowed to enter a URL. |
DECIMAL | The user is allowed to enter a real number value. This extends kEditBoxInputModeNumeric by allowing a decimal point. |
SINGLE_LINE | The user is allowed to enter any text, except for line breaks. |
CCEditBoxImplIOS.mm の修正
/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm
void EditBoxImplIOS::setInputMode(EditBox::InputMode inputMode)関数内
1 2 3 4 |
case EditBox::InputMode::NUMERIC: _systemControl.textField.keyboardType = UIKeyboardTypeDecimalPad; break; |
↓(変更)
1 2 3 4 5 |
case EditBox::InputMode::NUMERIC: //_systemControl.textField.keyboardType = UIKeyboardTypeDecimalPad; _systemControl.textField.keyboardType = UIKeyboardTypeNumberPad; break; |
この修正をしたうえで
1 2 |
editSample->setInputMode(EditBox::InputMode::NUMERIC); |
と指定すればピリオドなしの入力モードとなりました。
、、、、、はて、Androidはどうしたものか。その時が来たらまた考えます。