pokemon_type.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <gui/modules/variable_item_list.h>
  2. #include <named_list.h>
  3. #include "../pokemon_app.h"
  4. #include "../pokemon_data.h"
  5. #include "pokemon_menu.h"
  6. struct type_cb {
  7. DataStatSub type;
  8. PokemonFap* pokemon_fap;
  9. };
  10. static struct type_cb type_cb[] = {
  11. {TYPE_0, NULL},
  12. {TYPE_1, NULL},
  13. {},
  14. };
  15. /* TODO: In the future I would like to be able to set the types and then
  16. * require a "save" button to save them. This would require tracking of
  17. * the two different VariableItems in a way that I don't know how to do
  18. * yet with this interface.
  19. * For now, selecting a type immediately updates the trade_block struct,
  20. * requiring the user to press Back to go back. I would like to implement
  21. * an OK press or something to save both. But thats a problem for another
  22. * day.
  23. */
  24. static void select_type_callback(VariableItem* item) {
  25. struct type_cb* context = variable_item_get_context(item);
  26. uint8_t pos = variable_item_get_current_value_index(item);
  27. variable_item_set_current_value_text(
  28. item, namedlist_name_get_pos(context->pokemon_fap->pdata->type_list, pos));
  29. pokemon_stat_set(
  30. context->pokemon_fap->pdata,
  31. STAT_TYPE,
  32. context->type,
  33. namedlist_index_get(context->pokemon_fap->pdata->type_list, pos));
  34. }
  35. void select_type_scene_on_enter(void* context) {
  36. PokemonFap* pokemon_fap = (PokemonFap*)context;
  37. VariableItem* vitype[2];
  38. char* strings[2] = {"Type 1:", "Type 2:"};
  39. int type;
  40. int num_types = namedlist_cnt(pokemon_fap->pdata->type_list);
  41. int pos;
  42. int i;
  43. variable_item_list_reset(pokemon_fap->variable_item_list);
  44. /* NOTE: 2 is a magic number, but pretty obvious */
  45. for(i = 0; i < 2; i++) {
  46. type_cb[i].pokemon_fap = pokemon_fap;
  47. type = pokemon_stat_get(pokemon_fap->pdata, STAT_TYPE, i);
  48. pos = namedlist_pos_get(pokemon_fap->pdata->type_list, type);
  49. vitype[i] = variable_item_list_add(
  50. pokemon_fap->variable_item_list,
  51. strings[i],
  52. num_types,
  53. select_type_callback,
  54. &type_cb[i]);
  55. variable_item_set_current_value_index(vitype[i], pos);
  56. variable_item_set_current_value_text(
  57. vitype[i], namedlist_name_get_pos(pokemon_fap->pdata->type_list, pos));
  58. }
  59. view_dispatcher_add_view(
  60. pokemon_fap->view_dispatcher,
  61. AppViewOpts,
  62. variable_item_list_get_view(pokemon_fap->variable_item_list));
  63. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewOpts);
  64. }