Skip to content

Commit

Permalink
Implemented Move Item
Browse files Browse the repository at this point in the history
  • Loading branch information
laserXdolphin committed Jul 17, 2024
1 parent 80a6a21 commit 7ef137f
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/constants/party_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#define PARTY_MSG_ALREADY_HOLDING_ONE 26
#define PARTY_MSG_WHICH_APPLIANCE 27
#define PARTY_MSG_CHOOSE_SECOND_FUSION 28
#define PARTY_MSG_MOVE_ITEM_WHERE 29
#define PARTY_MSG_NONE 127

// IDs for DisplayPartyPokemonDescriptionText, to display a message in the party pokemon's box
Expand Down
6 changes: 6 additions & 0 deletions include/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3061,4 +3061,10 @@ extern const u8 gText_BasePointsResetToZero[];
extern const u8 gText_Fertilize[];
extern const u8 gText_PlantBerry[];

// Move Item
extern const u8 gMenuText_Move[];
extern const u8 gText_MoveItemWhere[];
extern const u8 gText_XsYAnd[];
extern const u8 gText_XsYWereSwapped[];

#endif // GUARD_STRINGS_H
8 changes: 5 additions & 3 deletions src/data/party_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ static const struct WindowTemplate sItemGiveTakeWindowTemplate =
{
.bg = 2,
.tilemapLeft = 23,
.tilemapTop = 13,
.tilemapTop = 11,
.width = 6,
.height = 6,
.height = 8,
.paletteNum = 14,
.baseBlock = 0x39D,
};
Expand Down Expand Up @@ -659,6 +659,7 @@ static const u8 *const sActionStringTable[] =
[PARTY_MSG_ALREADY_HOLDING_ONE] = gText_AlreadyHoldingOne,
[PARTY_MSG_WHICH_APPLIANCE] = gText_WhichAppliance,
[PARTY_MSG_CHOOSE_SECOND_FUSION] = gText_NextFusionMon,
[PARTY_MSG_MOVE_ITEM_WHERE] = gText_MoveItemWhere,
};

static const u8 *const sDescriptionStringTable[] =
Expand Down Expand Up @@ -698,6 +699,7 @@ struct
[MENU_ITEM] = {gText_Item, CursorCb_Item},
[MENU_GIVE] = {gMenuText_Give, CursorCb_Give},
[MENU_TAKE_ITEM] = {gText_Take, CursorCb_TakeItem},
[MENU_MOVE_ITEM] = {gMenuText_Move, CursorCb_MoveItem},
[MENU_MAIL] = {gText_Mail, CursorCb_Mail},
[MENU_TAKE_MAIL] = {gText_Take2, CursorCb_TakeMail},
[MENU_READ] = {gText_Read2, CursorCb_Read},
Expand Down Expand Up @@ -728,7 +730,7 @@ static const u8 sPartyMenuAction_SummaryCancel[] = {MENU_SUMMARY, MENU_CANCEL1};
static const u8 sPartyMenuAction_EnterSummaryCancel[] = {MENU_ENTER, MENU_SUMMARY, MENU_CANCEL1};
static const u8 sPartyMenuAction_NoEntrySummaryCancel[] = {MENU_NO_ENTRY, MENU_SUMMARY, MENU_CANCEL1};
static const u8 sPartyMenuAction_StoreSummaryCancel[] = {MENU_STORE, MENU_SUMMARY, MENU_CANCEL1};
static const u8 sPartyMenuAction_GiveTakeItemCancel[] = {MENU_GIVE, MENU_TAKE_ITEM, MENU_CANCEL2};
static const u8 sPartyMenuAction_GiveTakeItemCancel[] = {MENU_GIVE, MENU_TAKE_ITEM, MENU_MOVE_ITEM, MENU_CANCEL2};
static const u8 sPartyMenuAction_ReadTakeMailCancel[] = {MENU_READ, MENU_TAKE_MAIL, MENU_CANCEL2};
static const u8 sPartyMenuAction_RegisterSummaryCancel[] = {MENU_REGISTER, MENU_SUMMARY, MENU_CANCEL1};
static const u8 sPartyMenuAction_TradeSummaryCancel1[] = {MENU_TRADE1, MENU_SUMMARY, MENU_CANCEL1};
Expand Down
115 changes: 115 additions & 0 deletions src/party_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum {
MENU_ITEM,
MENU_GIVE,
MENU_TAKE_ITEM,
MENU_MOVE_ITEM,
MENU_MAIL,
MENU_TAKE_MAIL,
MENU_READ,
Expand Down Expand Up @@ -477,6 +478,7 @@ static void CursorCb_Cancel1(u8);
static void CursorCb_Item(u8);
static void CursorCb_Give(u8);
static void CursorCb_TakeItem(u8);
static void CursorCb_MoveItem(u8);
static void CursorCb_Mail(u8);
static void CursorCb_Read(u8);
static void CursorCb_TakeMail(u8);
Expand Down Expand Up @@ -7739,3 +7741,116 @@ void IsLastMonThatKnowsSurf(void)
gSpecialVar_Result = TRUE;
}
}

void CursorCb_MoveItemCallback(u8 taskId)
{
u16 item1, item2;
u8 buffer[100];

if (gPaletteFade.active || MenuHelpers_ShouldWaitForLinkRecv())
return;

switch (PartyMenuButtonHandler(&gPartyMenu.slotId2))
{
case 2: // User hit B or A while on Cancel
HandleChooseMonCancel(taskId, &gPartyMenu.slotId2);
break;
case 1: // User hit A on a Pokemon
// Pokemon can't give away items to eggs or themselves
if (GetMonData(&gPlayerParty[gPartyMenu.slotId2], MON_DATA_IS_EGG)
|| gPartyMenu.slotId == gPartyMenu.slotId2)
{
PlaySE(SE_FAILURE);
return;
}

PlaySE(SE_SELECT);
gPartyMenu.action = PARTY_ACTION_CHOOSE_MON;

// look up held items
item1 = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_HELD_ITEM);
item2 = GetMonData(&gPlayerParty[gPartyMenu.slotId2], MON_DATA_HELD_ITEM);

// swap the held items
SetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_HELD_ITEM, &item2);
SetMonData(&gPlayerParty[gPartyMenu.slotId2], MON_DATA_HELD_ITEM, &item1);

// update the held item icons
UpdatePartyMonHeldItemSprite(
&gPlayerParty[gPartyMenu.slotId],
&sPartyMenuBoxes[gPartyMenu.slotId]
);

UpdatePartyMonHeldItemSprite(
&gPlayerParty[gPartyMenu.slotId2],
&sPartyMenuBoxes[gPartyMenu.slotId2]
);

// create the string describing the move
if (item2 == ITEM_NONE)
{
GetMonNickname(&gPlayerParty[gPartyMenu.slotId2], gStringVar1);
CopyItemName(item1, gStringVar2);
StringExpandPlaceholders(gStringVar4, gText_PkmnWasGivenItem);
}
else
{
GetMonNickname(&gPlayerParty[gPartyMenu.slotId], gStringVar1);
CopyItemName(item1, gStringVar2);
StringExpandPlaceholders(buffer, gText_XsYAnd);

StringAppend(buffer, gText_XsYWereSwapped);
GetMonNickname(&gPlayerParty[gPartyMenu.slotId2], gStringVar1);
CopyItemName(item2, gStringVar2);
StringExpandPlaceholders(gStringVar4, buffer);
}

// display the string
DisplayPartyMenuMessage(gStringVar4, TRUE);

// update colors of selected boxes
AnimatePartySlot(gPartyMenu.slotId2, 0);
AnimatePartySlot(gPartyMenu.slotId, 1);

// return to the main party menu
ScheduleBgCopyTilemapToVram(2);
gTasks[taskId].func = Task_UpdateHeldItemSprite;
break;
}
}

void CursorCb_MoveItem(u8 taskId)
{
struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId];

PlaySE(SE_SELECT);

// delete old windows
PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[1]);
PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[0]);

if (GetMonData(mon, MON_DATA_HELD_ITEM) != ITEM_NONE)
{
gPartyMenu.action = PARTY_ACTION_SWITCH;

// show "Move item to where" in bottom left
DisplayPartyMenuStdMessage(PARTY_MSG_MOVE_ITEM_WHERE);
// update color of first selected box
AnimatePartySlot(gPartyMenu.slotId, 1);

// set up callback
gPartyMenu.slotId2 = gPartyMenu.slotId;
gTasks[taskId].func = CursorCb_MoveItemCallback;
}
else
{
// create and display string about lack of hold item
GetMonNickname(mon, gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_PkmnNotHolding);
DisplayPartyMenuMessage(gStringVar4, TRUE);

// return to the main party menu
ScheduleBgCopyTilemapToVram(2);
gTasks[taskId].func = Task_UpdateHeldItemSprite;
}
}
6 changes: 6 additions & 0 deletions src/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1849,3 +1849,9 @@ const u8 gText_ExpShareOff[] = _("The Exp. Share has been turned off.{PAUSE_UNTI
const u8 gText_BasePointsResetToZero[] = _("{STR_VAR_1}'s base points\nwere all reset to zero!{PAUSE_UNTIL_PRESS}");
const u8 gText_Fertilize[] = _("FERTILIZE");
const u8 gText_PlantBerry[] = _("PLANT BERRY");

// Move Item
const u8 gMenuText_Move[] = _("Move");
const u8 gText_MoveItemWhere[] = _("Move item to where?");
const u8 gText_XsYAnd[] = _("{STR_VAR_1}'s\n{STR_VAR_2} and\l");
const u8 gText_XsYWereSwapped[] = _("{STR_VAR_1}'s\l{STR_VAR_2} were swapped!{PAUSE_UNTIL_PRESS}");

0 comments on commit 7ef137f

Please sign in to comment.