pokemon_type.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  19. static void select_type_2_callback(VariableItem* item) {
  20. PokemonFap* pokemon_fap = variable_item_get_context(item);
  21. uint8_t index = variable_item_get_current_value_index(item);
  22. variable_item_set_current_value_text(item, pokemon_fap->type_list[index].name);
  23. pokemon_fap->trade_block->party[0].type[1] = pokemon_fap->type_list[index].index;
  24. }
  25. void select_type_scene_on_exit(void* context) {
  26. PokemonFap* pokemon_fap = (PokemonFap*)context;
  27. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  28. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewOpts);
  29. }
  30. void select_type_scene_on_enter(void* context) {
  31. PokemonFap* pokemon_fap = (PokemonFap*)context;
  32. VariableItem* type1;
  33. VariableItem* type2;
  34. int curr_pokemon_type1 = pokemon_fap->trade_block->party[0].type[0];
  35. int curr_pokemon_type2 = pokemon_fap->trade_block->party[0].type[1];
  36. int num_types = pokemon_named_list_get_num_elements(pokemon_fap->type_list);
  37. const NamedList* type_list = pokemon_fap->type_list;
  38. variable_item_list_reset(pokemon_fap->variable_item_list);
  39. type1 = variable_item_list_add(
  40. pokemon_fap->variable_item_list, "Type 1:", num_types, select_type_1_callback, pokemon_fap);
  41. type2 = variable_item_list_add(
  42. pokemon_fap->variable_item_list, "Type 2:", num_types, select_type_2_callback, pokemon_fap);
  43. variable_item_set_current_value_index(
  44. type1, pokemon_named_list_get_list_pos_from_index(type_list, curr_pokemon_type1));
  45. variable_item_set_current_value_text(
  46. type1, pokemon_named_list_get_name_from_index(type_list, curr_pokemon_type1));
  47. variable_item_set_current_value_index(
  48. type2, pokemon_named_list_get_list_pos_from_index(type_list, curr_pokemon_type2));
  49. variable_item_set_current_value_text(
  50. type2, pokemon_named_list_get_name_from_index(type_list, curr_pokemon_type2));
  51. view_dispatcher_add_view(
  52. pokemon_fap->view_dispatcher,
  53. AppViewOpts,
  54. variable_item_list_get_view(pokemon_fap->variable_item_list));
  55. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewOpts);
  56. }