pokemon_ot_name.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <ctype.h>
  2. #include <furi.h>
  3. #include <gui/modules/text_input.h>
  4. #include <gui/view_dispatcher.h>
  5. #include <stdlib.h>
  6. #include "../pokemon_app.h"
  7. #include "../pokemon_char_encode.h"
  8. #include "pokemon_menu.h"
  9. static char ot_name_buf[8];
  10. static bool select_ot_name_input_validator(const char* text, FuriString* error, void* context) {
  11. PokemonFap* pokemon_fap = (PokemonFap*)context;
  12. bool rc = true;
  13. unsigned int i;
  14. // XXX If no pokemon name, use default. How TF to have text input handle that?
  15. // OT name is 7 chars max on gen 1, so only take that and then fill the rest of the 11 bytes with term
  16. for(i = 0; i < sizeof(ot_name_buf); i++) {
  17. if(!isalnum((unsigned int)text[i])) {
  18. if(text[i] == '\0') break;
  19. rc = false;
  20. break;
  21. }
  22. }
  23. if(rc == false) {
  24. furi_string_printf(error, "Some error?");
  25. } else {
  26. /* Clear existing OT Name in trade block*/
  27. memset(pokemon_fap->trade_block->ot_name, TERM_, sizeof(struct name));
  28. /* Encode string to OT Name */
  29. pokemon_str_to_encoded_array(
  30. (uint8_t*)pokemon_fap->trade_block->ot_name, (char*)text, strlen(text));
  31. }
  32. return rc;
  33. }
  34. static void select_ot_name_input_callback(void* context) {
  35. PokemonFap* pokemon_fap = (PokemonFap*)context;
  36. scene_manager_previous_scene(pokemon_fap->scene_manager);
  37. }
  38. void select_ot_name_scene_on_exit(void* context) {
  39. PokemonFap* pokemon_fap = (PokemonFap*)context;
  40. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  41. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewOpts);
  42. }
  43. void select_ot_name_scene_on_enter(void* context) {
  44. PokemonFap* pokemon_fap = (PokemonFap*)context;
  45. text_input_reset(pokemon_fap->text_input);
  46. text_input_set_validator(pokemon_fap->text_input, select_ot_name_input_validator, pokemon_fap);
  47. text_input_set_result_callback(
  48. pokemon_fap->text_input,
  49. select_ot_name_input_callback,
  50. pokemon_fap,
  51. ot_name_buf,
  52. sizeof(ot_name_buf),
  53. true);
  54. text_input_set_header_text(pokemon_fap->text_input, "Enter OT Name");
  55. view_dispatcher_add_view(
  56. pokemon_fap->view_dispatcher, AppViewOpts, text_input_get_view(pokemon_fap->text_input));
  57. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewOpts);
  58. }