pokemon_level.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /* XXX: Need to recalculate other stats with level updated! */
  19. }
  20. return rc;
  21. }
  22. static void select_level_input_callback(void* context) {
  23. PokemonFap* pokemon_fap = (PokemonFap*)context;
  24. pokemon_trade_block_recalculate_stats_from_level(pokemon_fap);
  25. scene_manager_previous_scene(pokemon_fap->scene_manager);
  26. }
  27. void select_level_scene_on_exit(void* context) {
  28. PokemonFap* pokemon_fap = (PokemonFap*)context;
  29. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  30. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewOpts);
  31. }
  32. void select_level_scene_on_enter(void* context) {
  33. PokemonFap* pokemon_fap = (PokemonFap*)context;
  34. text_input_reset(pokemon_fap->text_input);
  35. text_input_set_validator(pokemon_fap->text_input, select_level_input_validator, pokemon_fap);
  36. text_input_set_result_callback(
  37. pokemon_fap->text_input,
  38. select_level_input_callback,
  39. pokemon_fap,
  40. level_buf,
  41. sizeof(level_buf),
  42. true);
  43. text_input_set_header_text(pokemon_fap->text_input, "Enter level (numbers only):");
  44. view_dispatcher_add_view(
  45. pokemon_fap->view_dispatcher, AppViewOpts, text_input_get_view(pokemon_fap->text_input));
  46. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewOpts);
  47. }