Skip to content

Commit

Permalink
enh - kb for all languages
Browse files Browse the repository at this point in the history
  • Loading branch information
w3irDv committed Sep 22, 2024
1 parent 2aea873 commit 73810c8
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 24 deletions.
40 changes: 33 additions & 7 deletions include/utils/KeyboardUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <string>
#include <vector>
#include <utils/LanguageUtils.h>

class Keyboard {
public:
Expand All @@ -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;' ",
Expand All @@ -24,17 +32,35 @@ class Keyboard {
"QWERTYUIOP{}\\",
"ASDFGHJKL:\" ",
"ZXCVBNM <> "};
*/
std::vector<std::string> keyboardNormal = {
"KB_N_0",
"KB_N_1",
"KB_N_2",
"KB_N_3"
};
std::vector<std::string> keyboardShift = {
"KB_S_0",
"KB_S_1",
"KB_S_2",
"KB_S_3"

};
for (unsigned int i=0;i<keyboardNormal.size();i++) {
keysNormal.push_back(utf8ToUcs4(LanguageUtils::gettext(keyboardNormal[i].c_str())));
}
for (unsigned int i=0;i<keyboardShift.size();i++) {
keysShift.push_back(utf8ToUcs4(LanguageUtils::gettext(keyboardShift[i].c_str())));
}
currentKeyboard = keysNormal;
setCurrentKey();
}
void setCurrentKey() { currentKey = currentKeyboard[row].substr(column,1); }
int getColumn() {return column;};
private:
std::vector<std::string> keysNormal;
std::vector<std::string> keysShift;
std::vector<std::string> currentKeyboard;
std::string prevKeys;
std::string currentKey;
std::string nextKeys;
std::vector<std::u32string> keysNormal;
std::vector<std::u32string> keysShift;
std::vector<std::u32string> currentKeyboard;
std::u32string currentKey;
int row;
int column;

Expand Down
13 changes: 11 additions & 2 deletions romfs/languages/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 <> "
}
4 changes: 3 additions & 1 deletion romfs/languages/japanese.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "うーん、本当によろしいです"
}
22 changes: 12 additions & 10 deletions src/menu/KeyboardState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;ii<keyboard->currentKeyboard[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_<keyboard->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
Expand All @@ -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();
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/menu/MainMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ ApplicationState::eSubState MainMenuState::update(Input *input) {
this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<KeyboardState>(tag);
}
/*
if (input->get(TRIGGER, PAD_BUTTON_X)) {
this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<BackupSetListState>();
}
}
*/
} else if (this->state == STATE_DO_SUBSTATE) {
auto retSubState = this->subState->update(input);
if (retSubState == SUBSTATE_RUNNING) {
Expand Down
42 changes: 39 additions & 3 deletions src/utils/KeyboardUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
#include <utils/KeyboardUtils.h>
#include <string>
#include <locale>
#include <codecvt>

void Keyboard::render() {
}

std::string Keyboard::ucs4ToUtf8(const std::u32string& in)
{
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv;
return conv.to_bytes(in);
}

std::u32string Keyboard::utf8ToUcs4(const std::string& in)
{
std::wstring_convert<std::codecvt_utf8<char32_t>, 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;
Expand All @@ -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;
}
Expand All @@ -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();
}

0 comments on commit 73810c8

Please sign in to comment.