pokemon_level.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <furi.h>
  2. #include <gui/modules/text_input.h>
  3. #include <gui/view_dispatcher.h>
  4. #include <stdlib.h>
  5. #include "../pokemon_app.h"
  6. #include "pokemon_menu.h"
  7. static char level_buf[4];
  8. static bool select_level_input_validator(const char* text, FuriString* error, void* context) {
  9. PokemonFap* pokemon_fap = (PokemonFap*)context;
  10. int level_val;
  11. bool rc = true;
  12. level_val = atoi(text);
  13. if(level_val < 2 || level_val > 100) {
  14. furi_string_printf(error, "Level must\nbe a number\nbetween\n2-100!\n");
  15. rc = false;
  16. } else {
  17. pokemon_fap->trade_block->party[0].level = level_val;
  18. pokemon_fap->trade_block->party[0].level_again = level_val;
  19. }
  20. return rc;
  21. }
  22. static void select_level_input_callback(void* context) {
  23. PokemonFap* pokemon_fap = (PokemonFap*)context;
  24. /* Recalculate all stats from updated level */
  25. pokemon_trade_block_recalculate_stats_from_level(pokemon_fap);
  26. scene_manager_previous_scene(pokemon_fap->scene_manager);
  27. }
  28. void select_level_scene_on_exit(void* context) {
  29. PokemonFap* pokemon_fap = (PokemonFap*)context;
  30. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  31. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewOpts);
  32. }
  33. void select_level_scene_on_enter(void* context) {
  34. PokemonFap* pokemon_fap = (PokemonFap*)context;
  35. text_input_reset(pokemon_fap->text_input);
  36. text_input_set_validator(pokemon_fap->text_input, select_level_input_validator, pokemon_fap);
  37. text_input_set_result_callback(
  38. pokemon_fap->text_input,
  39. select_level_input_callback,
  40. pokemon_fap,
  41. level_buf,
  42. sizeof(level_buf),
  43. true);
  44. text_input_set_header_text(pokemon_fap->text_input, "Enter level (numbers only):");
  45. view_dispatcher_add_view(
  46. pokemon_fap->view_dispatcher, AppViewOpts, text_input_get_view(pokemon_fap->text_input));
  47. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewOpts);
  48. }