diff --git a/include/utils/KeyboardUtils.h b/include/utils/KeyboardUtils.h index d8b7520..27d1eea 100644 --- a/include/utils/KeyboardUtils.h +++ b/include/utils/KeyboardUtils.h @@ -2,6 +2,7 @@ #include #include +#include class Keyboard { public: @@ -14,8 +15,15 @@ class Keyboard { void kbKeyPressed(); void shiftPressed(); void delPressed(); + void setCurrentKey(); + std::string getKey(int row_,int column_); + std::string getCurrentKey(); + int getKeyboardRowSize(int row_); + std::string ucs4ToUtf8(const std::u32string& in); + std::u32string utf8ToUcs4(const std::string& in); std::string input; Keyboard() : row(2),column(5) { + /* keysNormal = {"1234567890-= ", "qwertyuiop[]|", "asdfghjkl;' ", @@ -24,17 +32,35 @@ class Keyboard { "QWERTYUIOP{}\\", "ASDFGHJKL:\" ", "ZXCVBNM <> "}; + */ + std::vector keyboardNormal = { + "KB_N_0", + "KB_N_1", + "KB_N_2", + "KB_N_3" + }; + std::vector keyboardShift = { + "KB_S_0", + "KB_S_1", + "KB_S_2", + "KB_S_3" + + }; + for (unsigned int i=0;i keysNormal; - std::vector keysShift; - std::vector currentKeyboard; - std::string prevKeys; - std::string currentKey; - std::string nextKeys; + std::vector keysNormal; + std::vector keysShift; + std::vector currentKeyboard; + std::u32string currentKey; int row; int column; diff --git a/romfs/languages/english.json b/romfs/languages/english.json index 8689c58..7c61215 100644 --- a/romfs/languages/english.json +++ b/romfs/languages/english.json @@ -123,7 +123,7 @@ "BackupSets": "BackupSets", "BackupSets (filter applied)": "BackupSets (filter applied)", "\ue000: Select BS \ue046: Wipe BS \ue003: Filter List \ue001: Back": "\ue000: Select BS \ue046: Wipe BS \ue003: Filter List \ue001: Back", - "\ue000: Select BackupSet \ue003: Filter List \ue001: Back": "\ue000: Select BackupSet \ue002: Filter List \ue001: Back", + "\ue000: Select BackupSet \ue003: Filter List \ue001: Back": "\ue000: Select BackupSet \ue003: Filter List \ue001: Back", "Batch Backup": "Batch Backup", "Backup": "Backup", "Restore": "Restore", @@ -133,5 +133,14 @@ "Copy to Other Device": "Copy to Other Device", "Tasks": "Tasks", "Initializing BackupSets metadata.": "Initializing BackupSets metadata.", - "Please wait. First write to SD may be slow.": "Please wait. First write to SD may be slow." + "Please wait. First write to SD may be slow.": "Please wait. First write to SD may be slow.", + "1234567890-=": "1234567890-=", + "KB_N_0": "1234567890-= ", + "KB_N_1": "qwertyuiop[]|", + "KB_N_2": "asdfghjkl;' ", + "KB_N_3": "zxcvbnm ,./ ", + "KB_S_0": "!@#$%^&*()_+~", + "KB_S_1": "QWERTYUIOP{}\\", + "KB_S_2": "ASDFGHJKL:\" ", + "KB_S_3": "ZXCVBNM <> " } \ No newline at end of file diff --git a/romfs/languages/japanese.json b/romfs/languages/japanese.json index ffcf765..dfa1809 100644 --- a/romfs/languages/japanese.json +++ b/romfs/languages/japanese.json @@ -94,5 +94,7 @@ "Failed to delete savefile.": "保存ファイルの削除に失敗しました。", "Failed to delete user folder: %s": "ユーザー フォルダの削除に失敗しました: %s", "Failed to import savedata from loadiine.": "loadiine からセーブデータをインポートできませんでした。", - "Failed to export savedata to loadiine.": "セーブデータを loadiine にエクスポートできませんでした。" + "Failed to export savedata to loadiine.": "セーブデータを loadiine にエクスポートできませんでした。", + "KB_N_0": "セーブデータを load", + "KB_S_1": "うーん、本当によろしいです" } \ No newline at end of file diff --git a/src/menu/KeyboardState.cpp b/src/menu/KeyboardState.cpp index 97fbd4b..4aa4f5a 100644 --- a/src/menu/KeyboardState.cpp +++ b/src/menu/KeyboardState.cpp @@ -17,21 +17,20 @@ void KeyboardState::render() { consolePrintPosAligned(0,4,1,"Keyboard"); DrawUtils::setFontColor(COLOR_INFO); - consolePrintPosAligned(4,0,1,keyboard->input.c_str()); + consolePrintPosAligned(3,0,1,("["+keyboard->input+"]").c_str()); DrawUtils::setFontColor(COLOR_TEXT); - DrawUtils::setKFont(); - for (unsigned int i=0;i<4;i++) - for (unsigned int ii=0;iicurrentKeyboard[i].size();ii++) - kConsolePrintPos(KB_X_OFFSET+ii,KB_Y_OFFSET+i,KB_ROW_OFFSET*i, "%c", keyboard->currentKeyboard[i][ii]); + DrawUtils::setFont(); //was kFont + for (int row_=0;row_<4;row_++) + for (int column_=0;column_getKeyboardRowSize(row_);column_++) + kConsolePrintPos(KB_X_OFFSET+column_,KB_Y_OFFSET+row_,KB_ROW_OFFSET*row_, "%s", keyboard->getKey(row_,column_).c_str()); DrawUtils::setFontColor(COLOR_KEY_S); - kConsolePrintPos(cursorPosX+KB_X_OFFSET,cursorPosY+KB_Y_OFFSET,cursorPosY*KB_ROW_OFFSET-3,"%s", keyboard->currentKey.c_str()); - kConsolePrintPos(cursorPosX+KB_X_OFFSET,cursorPosY+KB_Y_OFFSET,cursorPosY*KB_ROW_OFFSET+3,"%s", keyboard->currentKey.c_str()); + kConsolePrintPos(cursorPosX+KB_X_OFFSET,cursorPosY+KB_Y_OFFSET,cursorPosY*KB_ROW_OFFSET-3,"%s", keyboard->getCurrentKey().c_str()); + kConsolePrintPos(cursorPosX+KB_X_OFFSET,cursorPosY+KB_Y_OFFSET,cursorPosY*KB_ROW_OFFSET+3,"%s", keyboard->getCurrentKey().c_str()); DrawUtils::setFontColor(COLOR_KEY); - kConsolePrintPos(cursorPosX+KB_X_OFFSET,cursorPosY+KB_Y_OFFSET,cursorPosY*KB_ROW_OFFSET,"%s", keyboard->currentKey.c_str()); + kConsolePrintPos(cursorPosX+KB_X_OFFSET,cursorPosY+KB_Y_OFFSET,cursorPosY*KB_ROW_OFFSET,"%s", keyboard->getCurrentKey().c_str()); DrawUtils::setFontColor(COLOR_TEXT); DrawUtils::setFont(); - consolePrintPosAligned(17, 4, 2, LanguageUtils::gettext("\ue000: Select Key \uE003: Shift \uE002: Del \ue045: OK! \ue001: Back")); - + consolePrintPosAligned(17, 4, 2, LanguageUtils::gettext("\ue000: Press Key \uE003: Shift \uE002: Del \ue045: OK! \ue001: Back")); } } // cursor , A -> select , X -> delete, Y -> shift, B -> Back, + = return @@ -48,9 +47,11 @@ ApplicationState::eSubState KeyboardState::update(Input *input) { } if (input->get(TRIGGER, PAD_BUTTON_DOWN)) { cursorPosY = keyboard->kbDown(); + cursorPosX = keyboard->getColumn(); } if (input->get(TRIGGER, PAD_BUTTON_UP)) { cursorPosY = keyboard->kbUp(); + cursorPosX = keyboard->getColumn(); } if (input->get(TRIGGER, PAD_BUTTON_A)) { keyboard->kbKeyPressed(); @@ -60,6 +61,7 @@ ApplicationState::eSubState KeyboardState::update(Input *input) { } if (input->get(TRIGGER,PAD_BUTTON_Y)) { keyboard->shiftPressed(); + cursorPosX = keyboard->getColumn(); } if (input->get(TRIGGER,PAD_BUTTON_PLUS)) { this->input = keyboard->input; diff --git a/src/menu/MainMenuState.cpp b/src/menu/MainMenuState.cpp index 5a12cea..47be850 100644 --- a/src/menu/MainMenuState.cpp +++ b/src/menu/MainMenuState.cpp @@ -69,10 +69,12 @@ ApplicationState::eSubState MainMenuState::update(Input *input) { this->state = STATE_DO_SUBSTATE; this->subState = std::make_unique(tag); } + /* if (input->get(TRIGGER, PAD_BUTTON_X)) { this->state = STATE_DO_SUBSTATE; this->subState = std::make_unique(); - } + } + */ } else if (this->state == STATE_DO_SUBSTATE) { auto retSubState = this->subState->update(input); if (retSubState == SUBSTATE_RUNNING) { diff --git a/src/utils/KeyboardUtils.cpp b/src/utils/KeyboardUtils.cpp index bde68f3..124c2be 100644 --- a/src/utils/KeyboardUtils.cpp +++ b/src/utils/KeyboardUtils.cpp @@ -1,20 +1,34 @@ #include #include +#include +#include void Keyboard::render() { } +std::string Keyboard::ucs4ToUtf8(const std::u32string& in) +{ + std::wstring_convert, char32_t> conv; + return conv.to_bytes(in); +} + +std::u32string Keyboard::utf8ToUcs4(const std::string& in) +{ + std::wstring_convert, char32_t> conv; + return conv.from_bytes(in); +} + int Keyboard::kbLeft() { if (column > 0) column--; else - column = (int) currentKeyboard[row].size()-1; + column = getKeyboardRowSize(row)-1; setCurrentKey(); return column; } int Keyboard::kbRight() { - if ( column < (int) currentKeyboard[row].size()-1) + if ( column < getKeyboardRowSize(row)-1) column++; else column = 0; @@ -27,6 +41,8 @@ int Keyboard::kbUp() { row--; else row = (int) currentKeyboard.size()-1; + if (column > getKeyboardRowSize(row)-1) + column = getKeyboardRowSize(row)-1; setCurrentKey(); return row; } @@ -36,20 +52,40 @@ int Keyboard::kbDown() { row++; else row = 0; + if (column > getKeyboardRowSize(row)-1) + column = getKeyboardRowSize(row)-1; setCurrentKey(); return row; } void Keyboard::shiftPressed() { currentKeyboard = ( currentKeyboard == keysNormal ? keysShift : keysNormal ); + if (column > getKeyboardRowSize(row)-1) + column = getKeyboardRowSize(row)-1; setCurrentKey(); } void Keyboard::kbKeyPressed() { - input.append(currentKey); + input.append(ucs4ToUtf8(currentKey)); } void Keyboard::delPressed() { if (input.size() > 0) input.pop_back(); } + +void Keyboard::setCurrentKey() { + currentKey = currentKeyboard[row].substr(column,1); +} + +std::string Keyboard::getKey(int row_,int column_) { + return ucs4ToUtf8(currentKeyboard[row_].substr(column_,1)); +} + +std::string Keyboard::getCurrentKey() { + return ucs4ToUtf8(currentKeyboard[row].substr(column,1)); +} + +int Keyboard::getKeyboardRowSize(int row_) { + return currentKeyboard[row_].size(); +} \ No newline at end of file