pokemon_type.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <gui/modules/variable_item_list.h>
  2. #include "../pokemon_app.h"
  3. #include "pokemon_menu.h"
  4. /* TODO: In the future I would like to be able to set the types and then
  5. * require a "save" button to save them. This would require tracking of
  6. * the two different VariableItems in a way that I don't know how to do
  7. * yet with this interface.
  8. * For now, selecting a type immediately updates the trade_block struct,
  9. * requiring the user to press Back to go back. I would like to implement
  10. * an OK press or something to save both. But thats a problem for another
  11. * day.
  12. */
  13. static void select_type_1_callback(VariableItem* item) {
  14. PokemonFap* pokemon_fap = variable_item_get_context(item);
  15. uint8_t index = variable_item_get_current_value_index(item);
  16. variable_item_set_current_value_text(item, pokemon_fap->type_list[index].name);
  17. pokemon_fap->trade_block->party[0].type[0] = pokemon_fap->type_list[index].index;
  18. FURI_LOG_D(
  19. TAG,
  20. "[type] Set type1 to %s",
  21. pokemon_named_list_get_name_from_index(
  22. pokemon_fap->type_list, pokemon_fap->type_list[index].index));
  23. }
  24. static void select_type_2_callback(VariableItem* item) {
  25. PokemonFap* pokemon_fap = variable_item_get_context(item);
  26. uint8_t index = variable_item_get_current_value_index(item);
  27. variable_item_set_current_value_text(item, pokemon_fap->type_list[index].name);
  28. pokemon_fap->trade_block->party[0].type[1] = pokemon_fap->type_list[index].index;
  29. FURI_LOG_D(
  30. TAG,
  31. "[type] Set type2 to %s",
  32. pokemon_named_list_get_name_from_index(
  33. pokemon_fap->type_list, pokemon_fap->type_list[index].index));
  34. }
  35. void select_type_scene_on_exit(void* context) {
  36. PokemonFap* pokemon_fap = (PokemonFap*)context;
  37. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  38. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewOpts);
  39. }
  40. void select_type_scene_on_enter(void* context) {
  41. PokemonFap* pokemon_fap = (PokemonFap*)context;
  42. VariableItem* type1;
  43. VariableItem* type2;
  44. int curr_pokemon_type1 = pokemon_fap->trade_block->party[0].type[0];
  45. int curr_pokemon_type2 = pokemon_fap->trade_block->party[0].type[1];
  46. int num_types = pokemon_named_list_get_num_elements(pokemon_fap->type_list);
  47. const NamedList* type_list = pokemon_fap->type_list;
  48. variable_item_list_reset(pokemon_fap->variable_item_list);
  49. type1 = variable_item_list_add(
  50. pokemon_fap->variable_item_list, "Type 1:", num_types, select_type_1_callback, pokemon_fap);
  51. type2 = variable_item_list_add(
  52. pokemon_fap->variable_item_list, "Type 2:", num_types, select_type_2_callback, pokemon_fap);
  53. variable_item_set_current_value_index(
  54. type1, pokemon_named_list_get_list_pos_from_index(type_list, curr_pokemon_type1));
  55. variable_item_set_current_value_text(
  56. type1, pokemon_named_list_get_name_from_index(type_list, curr_pokemon_type1));
  57. variable_item_set_current_value_index(
  58. type2, pokemon_named_list_get_list_pos_from_index(type_list, curr_pokemon_type2));
  59. variable_item_set_current_value_text(
  60. type2, pokemon_named_list_get_name_from_index(type_list, curr_pokemon_type2));
  61. view_dispatcher_add_view(
  62. pokemon_fap->view_dispatcher,
  63. AppViewOpts,
  64. variable_item_list_get_view(pokemon_fap->variable_item_list));
  65. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewOpts);
  66. }