|
|
@@ -9,66 +9,30 @@
|
|
|
|
|
|
#include <src/scenes/include/pokemon_scene.h>
|
|
|
|
|
|
-#include <src/scenes/include/pokemon_menu.h>
|
|
|
#include <src/include/pokemon_attribute.h>
|
|
|
|
|
|
static void scene_change_from_main_cb(void* context, uint32_t index) {
|
|
|
PokemonFap* pokemon_fap = (PokemonFap*)context;
|
|
|
|
|
|
- /* Reuse of scenes to allow for using the same functions to set names */
|
|
|
- switch(index) {
|
|
|
- case PokemonSceneNickname:
|
|
|
- case PokemonSceneOTName:
|
|
|
- case PokemonSceneUnownForm:
|
|
|
- scene_manager_set_scene_state(pokemon_fap->scene_manager, PokemonSceneNickname, index);
|
|
|
- break;
|
|
|
- case PokemonSceneLevel:
|
|
|
- case PokemonSceneOTID:
|
|
|
- scene_manager_set_scene_state(pokemon_fap->scene_manager, PokemonSceneLevel, index);
|
|
|
- break;
|
|
|
- case PokemonSceneGender:
|
|
|
- if(pokemon_gender_is_static(
|
|
|
- pokemon_fap->pdata,
|
|
|
- table_stat_base_get(
|
|
|
- pokemon_fap->pdata->pokemon_table,
|
|
|
- pokemon_stat_get(pokemon_fap->pdata, STAT_NUM, NONE),
|
|
|
- STAT_BASE_GENDER_RATIO,
|
|
|
- NONE)))
|
|
|
- return;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- /* Set the navigation handler back to the basic one in the main menu. We only
|
|
|
- * want gen_back_event_callback from this menu as going back from the gen menu
|
|
|
- * means we need to free pdata.
|
|
|
- */
|
|
|
- view_dispatcher_set_navigation_event_callback(
|
|
|
- pokemon_fap->view_dispatcher, main_menu_back_event_callback);
|
|
|
-
|
|
|
/* Set scene state to the current index so we can have that element highlighted when
|
|
|
- * we return.
|
|
|
+ * we return. Note that GenI scene is always used as a reference for this in this
|
|
|
+ * scene, whether its GenI or GenII.
|
|
|
*/
|
|
|
scene_manager_set_scene_state(pokemon_fap->scene_manager, PokemonSceneGenITrade, index);
|
|
|
- scene_manager_next_scene(pokemon_fap->scene_manager, index);
|
|
|
-}
|
|
|
-
|
|
|
-bool gen_back_event_callback(void* context) {
|
|
|
- furi_assert(context);
|
|
|
- PokemonFap* pokemon_fap = context;
|
|
|
|
|
|
- scene_manager_next_scene(pokemon_fap->scene_manager, PokemonSceneExitConfirm);
|
|
|
- return true;
|
|
|
+ view_dispatcher_send_custom_event(pokemon_fap->view_dispatcher, index);
|
|
|
}
|
|
|
|
|
|
void pokemon_scene_gen_on_enter(void* context) {
|
|
|
char buf[32];
|
|
|
char name_buf[11]; // All name buffers are 11 bytes at most, including term
|
|
|
PokemonFap* pokemon_fap = (PokemonFap*)context;
|
|
|
+ PokemonData* pdata = pokemon_fap->pdata;
|
|
|
int pkmn_num;
|
|
|
uint32_t state;
|
|
|
|
|
|
// Set up trade party struct
|
|
|
- if(!pokemon_fap->pdata) {
|
|
|
+ if(!pdata) {
|
|
|
state = scene_manager_get_scene_state(pokemon_fap->scene_manager, PokemonSceneGenITrade);
|
|
|
switch(state) {
|
|
|
case PokemonSceneGenITrade:
|
|
|
@@ -82,6 +46,7 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
break;
|
|
|
}
|
|
|
pokemon_fap->pdata = pokemon_data_alloc(state);
|
|
|
+ pdata = pokemon_fap->pdata;
|
|
|
|
|
|
/* Clear the scene state as this is the first entry in to this scene
|
|
|
* we definitely want to be completely reset.
|
|
|
@@ -91,18 +56,17 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
/* Allocate select and trade views */
|
|
|
/* Allocates its own view and adds it to the main view_dispatcher */
|
|
|
pokemon_fap->select = select_pokemon_alloc(
|
|
|
- pokemon_fap->pdata,
|
|
|
+ pdata,
|
|
|
pokemon_fap->view_dispatcher,
|
|
|
- pokemon_fap->scene_manager,
|
|
|
AppViewSelectPokemon);
|
|
|
|
|
|
// Trade View
|
|
|
/* Allocates its own view and adds it to the main view_dispatcher */
|
|
|
pokemon_fap->trade = trade_alloc(
|
|
|
- pokemon_fap->pdata, &pokemon_fap->pins, pokemon_fap->view_dispatcher, AppViewTrade);
|
|
|
+ pdata, &pokemon_fap->pins, pokemon_fap->view_dispatcher, AppViewTrade);
|
|
|
}
|
|
|
|
|
|
- pkmn_num = pokemon_stat_get(pokemon_fap->pdata, STAT_NUM, NONE);
|
|
|
+ pkmn_num = pokemon_stat_get(pdata, STAT_NUM, NONE);
|
|
|
|
|
|
/* Clear the scene state of the Move scene since that is used to set the
|
|
|
* highlighted menu item.
|
|
|
@@ -119,11 +83,11 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
buf,
|
|
|
sizeof(buf),
|
|
|
"Pokemon: %s",
|
|
|
- table_stat_name_get(pokemon_fap->pdata->pokemon_table, pkmn_num));
|
|
|
+ table_stat_name_get(pdata->pokemon_table, pkmn_num));
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneSelect, scene_change_from_main_cb, pokemon_fap);
|
|
|
|
|
|
- pokemon_name_get(pokemon_fap->pdata, STAT_NICKNAME, name_buf, sizeof(name_buf));
|
|
|
+ pokemon_name_get(pdata, STAT_NICKNAME, name_buf, sizeof(name_buf));
|
|
|
snprintf(buf, sizeof(buf), "Nickname: %s", name_buf);
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneNickname, scene_change_from_main_cb, pokemon_fap);
|
|
|
@@ -132,18 +96,18 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
buf,
|
|
|
sizeof(buf),
|
|
|
"Level: %d",
|
|
|
- pokemon_stat_get(pokemon_fap->pdata, STAT_LEVEL, NONE));
|
|
|
+ pokemon_stat_get(pdata, STAT_LEVEL, NONE));
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneLevel, scene_change_from_main_cb, pokemon_fap);
|
|
|
|
|
|
- if(pokemon_fap->pdata->gen == GEN_II) {
|
|
|
+ if(pdata->gen == GEN_II) {
|
|
|
snprintf(
|
|
|
buf,
|
|
|
sizeof(buf),
|
|
|
"Held Item: %s",
|
|
|
namedlist_name_get_index(
|
|
|
- pokemon_fap->pdata->item_list,
|
|
|
- pokemon_stat_get(pokemon_fap->pdata, STAT_HELD_ITEM, NONE)));
|
|
|
+ pdata->item_list,
|
|
|
+ pokemon_stat_get(pdata, STAT_HELD_ITEM, NONE)));
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneItem, scene_change_from_main_cb, pokemon_fap);
|
|
|
}
|
|
|
@@ -155,7 +119,7 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
scene_change_from_main_cb,
|
|
|
pokemon_fap);
|
|
|
|
|
|
- if(pokemon_fap->pdata->gen == GEN_I) {
|
|
|
+ if(pdata->gen == GEN_I) {
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu,
|
|
|
"Select Types",
|
|
|
@@ -167,30 +131,30 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu,
|
|
|
namedlist_name_get_index(
|
|
|
- pokemon_fap->pdata->stat_list, pokemon_stat_get(pokemon_fap->pdata, STAT_SEL, NONE)),
|
|
|
+ pdata->stat_list, pokemon_stat_get(pdata, STAT_SEL, NONE)),
|
|
|
PokemonSceneStats,
|
|
|
scene_change_from_main_cb,
|
|
|
pokemon_fap);
|
|
|
|
|
|
- if(pokemon_fap->pdata->gen == GEN_II) {
|
|
|
+ if(pdata->gen == GEN_II) {
|
|
|
snprintf(
|
|
|
buf,
|
|
|
sizeof(buf),
|
|
|
"Shiny: %s",
|
|
|
- pokemon_is_shiny(pokemon_fap->pdata) ? "Yes" : "No");
|
|
|
+ pokemon_is_shiny(pdata) ? "Yes" : "No");
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneShiny, scene_change_from_main_cb, pokemon_fap);
|
|
|
|
|
|
- snprintf(buf, sizeof(buf), "Gender: %s", pokemon_gender_get(pokemon_fap->pdata));
|
|
|
+ snprintf(buf, sizeof(buf), "Gender: %s", pokemon_gender_get(pdata));
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneGender, scene_change_from_main_cb, pokemon_fap);
|
|
|
|
|
|
- snprintf(buf, sizeof(buf), "Pokerus: %s", pokerus_get_status_str(pokemon_fap->pdata));
|
|
|
+ snprintf(buf, sizeof(buf), "Pokerus: %s", pokerus_get_status_str(pdata));
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonScenePokerus, scene_change_from_main_cb, pokemon_fap);
|
|
|
|
|
|
- if(pokemon_stat_get(pokemon_fap->pdata, STAT_NUM, NONE) == 0xC8) { // Unown
|
|
|
- snprintf(buf, sizeof(buf), "Unown Form: %c", unown_form_get(pokemon_fap->pdata));
|
|
|
+ if(pokemon_stat_get(pdata, STAT_NUM, NONE) == 0xC8) { // Unown
|
|
|
+ snprintf(buf, sizeof(buf), "Unown Form: %c", unown_form_get(pdata));
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu,
|
|
|
buf,
|
|
|
@@ -204,11 +168,11 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
buf,
|
|
|
sizeof(buf),
|
|
|
"OT ID#: %05d",
|
|
|
- pokemon_stat_get(pokemon_fap->pdata, STAT_OT_ID, NONE));
|
|
|
+ pokemon_stat_get(pdata, STAT_OT_ID, NONE));
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneOTID, scene_change_from_main_cb, pokemon_fap);
|
|
|
|
|
|
- pokemon_name_get(pokemon_fap->pdata, STAT_OT_NAME, name_buf, sizeof(name_buf));
|
|
|
+ pokemon_name_get(pdata, STAT_OT_NAME, name_buf, sizeof(name_buf));
|
|
|
snprintf(buf, sizeof(buf), "OT Name: %s", name_buf);
|
|
|
submenu_add_item(
|
|
|
pokemon_fap->submenu, buf, PokemonSceneOTName, scene_change_from_main_cb, pokemon_fap);
|
|
|
@@ -223,16 +187,56 @@ void pokemon_scene_gen_on_enter(void* context) {
|
|
|
pokemon_fap->submenu,
|
|
|
scene_manager_get_scene_state(pokemon_fap->scene_manager, PokemonSceneGenITrade));
|
|
|
|
|
|
- view_dispatcher_set_navigation_event_callback(
|
|
|
- pokemon_fap->view_dispatcher, gen_back_event_callback);
|
|
|
-
|
|
|
- view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
|
|
|
+ view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewSubmenu);
|
|
|
}
|
|
|
|
|
|
bool pokemon_scene_gen_on_event(void* context, SceneManagerEvent event) {
|
|
|
- UNUSED(context);
|
|
|
- UNUSED(event);
|
|
|
- return false;
|
|
|
+ PokemonFap* pokemon_fap = context;
|
|
|
+ bool consumed = false;
|
|
|
+ PokemonData* pdata = pokemon_fap->pdata;
|
|
|
+ uint8_t pokemon_num;
|
|
|
+ uint8_t gender_ratio;
|
|
|
+
|
|
|
+
|
|
|
+ /* If the user tries to go back from this scene to main menu, instead
|
|
|
+ * shift to the exit confirmation scene. That scene will handle freeing
|
|
|
+ * data as well as going back to the main menu.
|
|
|
+ */
|
|
|
+ if (event.type == SceneManagerEventTypeBack) {
|
|
|
+ scene_manager_next_scene(pokemon_fap->scene_manager, PokemonSceneExitConfirm);
|
|
|
+ consumed = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (event.type == SceneManagerEventTypeCustom) {
|
|
|
+ consumed = true;
|
|
|
+
|
|
|
+ /* Reuse of scenes to allow for using the same functions to set names */
|
|
|
+ switch(event.event) {
|
|
|
+ case PokemonSceneNickname:
|
|
|
+ case PokemonSceneOTName:
|
|
|
+ case PokemonSceneUnownForm:
|
|
|
+ scene_manager_set_scene_state(pokemon_fap->scene_manager, PokemonSceneNickname, event.event);
|
|
|
+ break;
|
|
|
+ case PokemonSceneLevel:
|
|
|
+ case PokemonSceneOTID:
|
|
|
+ scene_manager_set_scene_state(pokemon_fap->scene_manager, PokemonSceneLevel, event.event);
|
|
|
+ break;
|
|
|
+ case PokemonSceneGender:
|
|
|
+ pokemon_num = pokemon_stat_get(pdata, STAT_NUM, NONE);
|
|
|
+ gender_ratio = table_stat_base_get(pdata->pokemon_table, pokemon_num, STAT_BASE_GENDER_RATIO, NONE);
|
|
|
+ /* If the pokemon's gender is static (always male, always female,
|
|
|
+ * or unknown), then don't transition to the gender selection scene.
|
|
|
+ */
|
|
|
+ if(pokemon_gender_is_static(pdata, gender_ratio))
|
|
|
+ goto out;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ scene_manager_next_scene(pokemon_fap->scene_manager, event.event);
|
|
|
+ }
|
|
|
+
|
|
|
+out:
|
|
|
+ return consumed;
|
|
|
}
|
|
|
|
|
|
void pokemon_scene_gen_on_exit(void* context) {
|