| 4393 | |
| 4394 | |
| 4395 | void PixelGameEngine::UpdateTextEntry() |
| 4396 | { |
| 4397 | // Check for typed characters |
| 4398 | for (const auto& key : GetKeyPressCache()) |
| 4399 | { |
| 4400 | const auto& sym = GetKeySymbol(ConvertKeycode(key), GetKey(olc::Key::SHIFT).bHeld, GetKey(olc::Key::CTRL).bHeld); |
| 4401 | |
| 4402 | |
| 4403 | |
| 4404 | // Check for command characters |
| 4405 | if (sym == "_L") |
| 4406 | nTextEntryCursor = std::max(0, nTextEntryCursor - 1); |
| 4407 | else if (sym == "_R") |
| 4408 | nTextEntryCursor = std::min(int32_t(sTextEntryString.size()), nTextEntryCursor + 1); |
| 4409 | else if (sym == "\b" && nTextEntryCursor > 0) |
| 4410 | { |
| 4411 | sTextEntryString.erase(nTextEntryCursor - 1, 1); |
| 4412 | nTextEntryCursor = std::max(0, nTextEntryCursor - 1); |
| 4413 | } |
| 4414 | else if (sym == "_X" && size_t(nTextEntryCursor) < sTextEntryString.size()) |
| 4415 | sTextEntryString.erase(nTextEntryCursor, 1); |
| 4416 | else if (sym == "_U") |
| 4417 | { |
| 4418 | if (!sCommandHistory.empty()) |
| 4419 | { |
| 4420 | if (sCommandHistoryIt != sCommandHistory.begin()) |
| 4421 | sCommandHistoryIt--; |
| 4422 | |
| 4423 | nTextEntryCursor = int32_t(sCommandHistoryIt->size()); |
| 4424 | sTextEntryString = *sCommandHistoryIt; |
| 4425 | } |
| 4426 | } |
| 4427 | |
| 4428 | else if (sym == "_D") |
| 4429 | { |
| 4430 | if (!sCommandHistory.empty()) |
| 4431 | { |
| 4432 | if (sCommandHistoryIt != sCommandHistory.end()) |
| 4433 | { |
| 4434 | sCommandHistoryIt++; |
| 4435 | if (sCommandHistoryIt != sCommandHistory.end()) |
| 4436 | { |
| 4437 | nTextEntryCursor = int32_t(sCommandHistoryIt->size()); |
| 4438 | sTextEntryString = *sCommandHistoryIt; |
| 4439 | } |
| 4440 | else |
| 4441 | { |
| 4442 | nTextEntryCursor = 0; |
| 4443 | sTextEntryString = ""; |
| 4444 | } |
| 4445 | } |
| 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | else if (sym == "\n") |
| 4450 | { |
| 4451 | if (bConsoleShow) |
| 4452 | { |