Skip to content

Commit b6dba30

Browse files
committed
trade: Add ability to reset connection state
Allows for resetting the connection back to not connected, as if the Flipper left the Trade Center or restarted, but keeps the current pokemon in RAM. This woudl allow, for example, to trade a pokemon between two real cartridges with only a single Game Boy. By trading from Pokemon Cart A to the Flipper, resetting the connection state on the Flipper, and loading Pokemon Cart B in to the Game Boy, and trading from the Flipper to the real game. Fixes #37 Signed-off-by: Kris Bahnsen <[email protected]>
1 parent 17dc0b7 commit b6dba30

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The video below trades a Bulbasaur from the Flipper to a Game Boy Color with Pok
1515
- [Customizing Pokemon](#customizing-pokemon)
1616
- [Trade](#trade-pkmn)
1717
- [Modifying Traded Pokemon](#modifying-traded-pokemon)
18+
- [Reset Trade Connection State](#reset-trade-connection-state)
1819
- [How it Works / Build your own Interface](#how-does-it-work)
1920

2021

@@ -376,6 +377,15 @@ The Game Boy should remain on and in the trade room. When the Flipper re-enters
376377

377378
---
378379

380+
#### Reset Trade Connection State
381+
It is possible to reset the Flipper's connection state to having never been connected to a Game Boy. This allows the Flipper to restart communication with a Game Boy if it was accidentally turned off, for example, and the Game Boy needs to re-enter the Trade Center. Doing this keeps the current Pokemon the Flipper has in memory intact.
382+
383+
This can also be used to leverage the Flipper to trade a pokemon between two Pokemon games with only a single Game Boy. For example, trade from Pokemon Blue to the Flipper (and then modifying the Pokemon on the Flipper if desired), resetting the trade state on the Flipper, swap the Game Boy game to Pokemon Silver, and on both the Game Boy and Flipper, start the trade process (using Time Capsule trade mode on the Pokemon Silver game).
384+
385+
Once a connection has been established between the Flipper and a Pokemon game, the option `Reset Connection` will appear in the configuration screen under `Trade PKMN`. The Flipper will then ask for confirmation of the operation.
386+
387+
---
388+
379389
#### Special Note on MALVEKE PCB Rev. <= 2.5
380390
Version 2.0 of the Pokemon Trade tool fixes a bug on MALVEKE boards that are Rev. 2.5 or lower where after a trade is completed the `OK` button no longer functions. However, while on the trade screen the `OK` button will continue to not function. For example, if you try to press the `OK` button to turn the backlight on, the Flipper will not respond. The `OK` button functionality will be restored once the Flipper leaves the Trade screen.
381391

src/scenes/include/pokemon_scene_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ ADD_SCENE(pokemon, select_name, OTName)
2020
ADD_SCENE(pokemon, trade, Trade)
2121
ADD_SCENE(pokemon, select_pins, Pins)
2222
ADD_SCENE(pokemon, exit_confirm, ExitConfirm)
23+
ADD_SCENE(pokemon, reset_confirm, ResetConfirm)

src/scenes/pokemon_gen.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ void pokemon_scene_gen_on_enter(void* context) {
180180
submenu_add_item(
181181
pokemon_fap->submenu, "Trade PKMN", PokemonSceneTrade, scene_change_from_main_cb, pokemon_fap);
182182

183+
if (trade_connected(pokemon_fap->trade)) {
184+
submenu_add_item(pokemon_fap->submenu,
185+
"Reset Connection",
186+
PokemonSceneResetConfirm,
187+
scene_change_from_main_cb,
188+
pokemon_fap);
189+
}
190+
183191
/* TODO: Add Save pokemon option here */
184192

185193
/* HACK: No matter what gen were in, we just store the scene state in PokemonSceneGenITrade */
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <gui/modules/dialog_ex.h>
2+
3+
#include <pokemon_icons.h>
4+
#include <src/include/pokemon_app.h>
5+
#include <src/include/pokemon_data.h>
6+
7+
#include <src/scenes/include/pokemon_scene.h>
8+
9+
#include <src/views/select_pokemon.h>
10+
#include <src/views/trade.h>
11+
12+
static void pokemon_scene_reset_confirm_dialog_callback(DialogExResult result, void* context) {
13+
PokemonFap* pokemon_fap = context;
14+
15+
view_dispatcher_send_custom_event(pokemon_fap->view_dispatcher, result);
16+
}
17+
18+
void pokemon_scene_reset_confirm_on_enter(void* context) {
19+
PokemonFap* pokemon_fap = context;
20+
DialogEx* dialog_ex = pokemon_fap->dialog_ex;
21+
22+
// Clean view
23+
dialog_ex_reset(pokemon_fap->dialog_ex);
24+
25+
dialog_ex_set_left_button_text(dialog_ex, "Reset");
26+
dialog_ex_set_right_button_text(dialog_ex, "Back");
27+
dialog_ex_set_header(dialog_ex, "Reset Trade State?", 64, 0, AlignCenter, AlignTop);
28+
dialog_ex_set_text(
29+
dialog_ex,
30+
"Trade partner will need to\nleave and re-enter the\nTrade Center!",
31+
64,
32+
12,
33+
AlignCenter,
34+
AlignTop);
35+
dialog_ex_set_context(dialog_ex, pokemon_fap);
36+
dialog_ex_set_result_callback(dialog_ex, pokemon_scene_reset_confirm_dialog_callback);
37+
38+
view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewDialogEx);
39+
}
40+
41+
bool pokemon_scene_reset_confirm_on_event(void* context, SceneManagerEvent event) {
42+
PokemonFap* pokemon_fap = context;
43+
bool consumed = false;
44+
45+
if(event.type == SceneManagerEventTypeCustom) {
46+
switch (event.event) {
47+
case DialogExResultLeft:
48+
trade_reset_connection(pokemon_fap->trade);
49+
[[fallthrough]];
50+
case DialogExResultRight:
51+
scene_manager_previous_scene(pokemon_fap->scene_manager);
52+
consumed = true;
53+
break;
54+
}
55+
} else if(event.type == SceneManagerEventTypeBack) {
56+
consumed = true;
57+
}
58+
59+
return consumed;
60+
}
61+
62+
void pokemon_scene_reset_confirm_on_exit(void* context) {
63+
UNUSED(context);
64+
}
65+

src/views/trade.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,3 +965,26 @@ void trade_free(ViewDispatcher* view_dispatcher, uint32_t view_id, void* trade_c
965965
pokemon_data_free(trade->input_pdata);
966966
free(trade);
967967
}
968+
969+
void trade_reset_connection(void* trade_ctx) {
970+
struct trade_ctx *trade = trade_ctx;
971+
972+
with_view_model(
973+
trade->view,
974+
struct trade_model * model,
975+
{ model->gameboy_status = GAMEBOY_CONN_FALSE; },
976+
false);
977+
}
978+
979+
bool trade_connected(void* trade_ctx) {
980+
struct trade_ctx *trade = trade_ctx;
981+
bool connected = false;
982+
983+
with_view_model(
984+
trade->view,
985+
struct trade_model * model,
986+
{ connected = (model->gameboy_status > GAMEBOY_CONN_FALSE); },
987+
false);
988+
989+
return connected;
990+
}

src/views/trade.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ void* trade_alloc(
1414

1515
void trade_free(ViewDispatcher* view_dispatcher, uint32_t view_id, void* trade_ctx);
1616

17+
void trade_reset_connection(void* trade_ctx);
18+
19+
bool trade_connected(void* trade_ctx);
20+
1721
#endif /* TRADE_H */

0 commit comments

Comments
 (0)