2018-05-01 21:19:24 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "constants/decorations.h"
|
2019-10-20 22:11:07 +02:00
|
|
|
#include "constants/mauville_old_man.h"
|
2018-05-01 21:19:24 +02:00
|
|
|
#include "decoration.h"
|
|
|
|
#include "decoration_inventory.h"
|
|
|
|
#include "event_data.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "menu_helpers.h"
|
|
|
|
#include "script.h"
|
|
|
|
#include "constants/songs.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "string_util.h"
|
|
|
|
#include "strings.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "script_menu.h"
|
|
|
|
|
2022-04-02 23:09:51 +02:00
|
|
|
static const u8 * const sDefaultTraderNames[NUM_TRADER_ITEMS] =
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
gText_Tristan,
|
|
|
|
gText_Philip,
|
|
|
|
gText_Dennis,
|
|
|
|
gText_Roberto,
|
|
|
|
};
|
|
|
|
|
2022-04-02 23:09:51 +02:00
|
|
|
static const u8 sDefaultTraderDecorations[NUM_TRADER_ITEMS] =
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
DECOR_DUSKULL_DOLL,
|
|
|
|
DECOR_BALL_CUSHION,
|
|
|
|
DECOR_TIRE,
|
|
|
|
DECOR_PRETTY_FLOWERS,
|
|
|
|
};
|
|
|
|
|
|
|
|
void TraderSetup(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader;
|
|
|
|
|
|
|
|
trader->id = MAUVILLE_MAN_TRADER;
|
|
|
|
trader->alreadyTraded = FALSE;
|
|
|
|
|
2022-04-02 23:09:51 +02:00
|
|
|
for (i = 0; i < NUM_TRADER_ITEMS; i++)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
2018-05-08 00:18:00 +02:00
|
|
|
StringCopy(trader->playerNames[i], sDefaultTraderNames[i]);
|
2020-02-23 16:46:22 +01:00
|
|
|
trader->decorations[i] = sDefaultTraderDecorations[i];
|
2018-05-01 21:19:24 +02:00
|
|
|
trader->language[i] = GAME_LANGUAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 00:18:00 +02:00
|
|
|
void Trader_ResetFlag(void)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader;
|
|
|
|
trader->alreadyTraded = FALSE;
|
|
|
|
}
|
|
|
|
|
2022-04-02 23:09:51 +02:00
|
|
|
#define tWindowId data[3]
|
|
|
|
|
2018-05-01 21:19:24 +02:00
|
|
|
void CreateAvailableDecorationsMenu(u8 taskId)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
s16 * data = gTasks[taskId].data;
|
|
|
|
struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader;
|
2022-04-02 23:09:51 +02:00
|
|
|
struct WindowTemplate windowTemplate = {
|
|
|
|
.bg = 0,
|
|
|
|
.tilemapLeft = 1,
|
|
|
|
.tilemapTop = 1,
|
|
|
|
.width = 10,
|
|
|
|
.height = 10,
|
|
|
|
.paletteNum = 15,
|
|
|
|
.baseBlock = 1
|
|
|
|
};
|
2021-10-30 22:47:37 +02:00
|
|
|
s32 windowWidth = GetStringWidth(FONT_NORMAL, gText_Exit, 0);
|
|
|
|
s32 fiveMarksWidth = GetStringWidth(FONT_NORMAL, gText_FiveMarks, 0);
|
2022-04-02 23:09:51 +02:00
|
|
|
for (i = 0; i < NUM_TRADER_ITEMS; i++)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
s32 curWidth;
|
2020-02-23 16:46:22 +01:00
|
|
|
if (trader->decorations[i] > NUM_DECORATIONS)
|
2018-05-01 21:19:24 +02:00
|
|
|
curWidth = fiveMarksWidth;
|
|
|
|
else
|
2021-10-30 22:47:37 +02:00
|
|
|
curWidth = GetStringWidth(FONT_NORMAL, gDecorations[trader->decorations[i]].name, 0);
|
2018-05-01 21:19:24 +02:00
|
|
|
if (curWidth > windowWidth)
|
|
|
|
windowWidth = curWidth;
|
|
|
|
}
|
2019-09-19 23:26:25 +02:00
|
|
|
windowTemplate.width = ConvertPixelWidthToTileWidth(windowWidth);
|
2022-04-02 23:09:51 +02:00
|
|
|
tWindowId = AddWindow(&windowTemplate);
|
|
|
|
DrawStdFrameWithCustomTileAndPalette(tWindowId, FALSE, 0x214, 14);
|
|
|
|
for (i = 0; i < NUM_TRADER_ITEMS; i++)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
2020-02-23 16:46:22 +01:00
|
|
|
if (trader->decorations[i] > NUM_DECORATIONS)
|
2022-04-02 23:09:51 +02:00
|
|
|
AddTextPrinterParameterized(tWindowId, FONT_NORMAL, gText_FiveMarks, 8, 16 * i + 1, TEXT_SKIP_DRAW, NULL);
|
2018-05-01 21:19:24 +02:00
|
|
|
else
|
2022-04-02 23:09:51 +02:00
|
|
|
AddTextPrinterParameterized(tWindowId, FONT_NORMAL, gDecorations[trader->decorations[i]].name, 8, 16 * i + 1, TEXT_SKIP_DRAW, NULL);
|
2018-05-01 21:19:24 +02:00
|
|
|
}
|
2022-04-02 23:09:51 +02:00
|
|
|
AddTextPrinterParameterized(tWindowId, FONT_NORMAL, gText_Exit, 8, 16 * i + 1, TEXT_SKIP_DRAW, NULL);
|
|
|
|
InitMenuInUpperLeftCornerNormal(tWindowId, NUM_TRADER_ITEMS + 1, 0);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(0);
|
2018-05-01 21:19:24 +02:00
|
|
|
}
|
|
|
|
|
2019-10-20 22:11:07 +02:00
|
|
|
void Task_BufferDecorSelectionAndCloseWindow(u8 taskId, u8 decorationId)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
s16 * data = gTasks[taskId].data;
|
|
|
|
if (decorationId > NUM_DECORATIONS)
|
|
|
|
gSpecialVar_0x8004 = 0xFFFF;
|
|
|
|
else
|
|
|
|
gSpecialVar_0x8004 = decorationId;
|
|
|
|
|
2022-04-02 23:09:51 +02:00
|
|
|
ClearStdWindowAndFrameToTransparent(tWindowId, FALSE);
|
|
|
|
ClearWindowTilemap(tWindowId);
|
|
|
|
RemoveWindow(tWindowId);
|
2020-05-14 10:37:09 +02:00
|
|
|
ScheduleBgCopyTilemapToVram(0);
|
2018-05-01 21:19:24 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
EnableBothScriptContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Task_HandleGetDecorationMenuInput(u8 taskId)
|
|
|
|
{
|
|
|
|
struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader;
|
2018-11-05 21:45:54 +01:00
|
|
|
s8 input = Menu_ProcessInput();
|
2018-05-01 21:19:24 +02:00
|
|
|
|
|
|
|
switch (input)
|
|
|
|
{
|
2019-02-02 11:04:38 +01:00
|
|
|
case MENU_NOTHING_CHOSEN:
|
2018-05-01 21:19:24 +02:00
|
|
|
break;
|
2019-02-02 11:04:38 +01:00
|
|
|
case MENU_B_PRESSED:
|
2022-04-02 23:09:51 +02:00
|
|
|
case NUM_TRADER_ITEMS: // EXIT
|
2018-05-01 21:19:24 +02:00
|
|
|
PlaySE(SE_SELECT);
|
2019-10-20 22:11:07 +02:00
|
|
|
Task_BufferDecorSelectionAndCloseWindow(taskId, 0);
|
2018-05-01 21:19:24 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
gSpecialVar_0x8005 = input;
|
2018-05-08 00:18:00 +02:00
|
|
|
StringCopy(gStringVar1, trader->playerNames[input]);
|
2018-05-01 21:19:24 +02:00
|
|
|
ConvertInternationalString(gStringVar1, trader->language[input]);
|
2020-02-23 16:46:22 +01:00
|
|
|
Task_BufferDecorSelectionAndCloseWindow(taskId, trader->decorations[input]);
|
2018-05-01 21:19:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 06:08:36 +02:00
|
|
|
void GetTraderTradedFlag(void)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader;
|
|
|
|
gSpecialVar_Result = trader->alreadyTraded;
|
|
|
|
}
|
|
|
|
|
2021-10-18 06:08:36 +02:00
|
|
|
void DoesPlayerHaveNoDecorations(void)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2022-04-02 23:09:51 +02:00
|
|
|
for (i = 0; i < DECORCAT_COUNT; i++)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
2019-04-06 19:41:55 +02:00
|
|
|
if (GetNumOwnedDecorationsInCategory(i))
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
gSpecialVar_Result = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gSpecialVar_Result = TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-18 06:08:36 +02:00
|
|
|
void IsDecorationCategoryFull(void)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
gSpecialVar_Result = FALSE;
|
|
|
|
if (gDecorations[gSpecialVar_0x8004].category != gDecorations[gSpecialVar_0x8006].category
|
|
|
|
&& GetFirstEmptyDecorSlot(gDecorations[gSpecialVar_0x8004].category) == -1)
|
|
|
|
{
|
2019-04-06 19:41:55 +02:00
|
|
|
CopyDecorationCategoryName(gStringVar2, gDecorations[gSpecialVar_0x8004].category);
|
2018-05-01 21:19:24 +02:00
|
|
|
gSpecialVar_Result = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 06:08:36 +02:00
|
|
|
void TraderShowDecorationMenu(void)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
2019-04-06 19:41:55 +02:00
|
|
|
CreateTask(ShowDecorationCategoriesWindow, 0);
|
2018-05-01 21:19:24 +02:00
|
|
|
}
|
|
|
|
|
2020-02-23 16:46:22 +01:00
|
|
|
void DecorationItemsMenuAction_Trade(u8 taskId)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
if (IsSelectedDecorInThePC() == TRUE)
|
|
|
|
{
|
2019-04-06 19:41:55 +02:00
|
|
|
gSpecialVar_0x8006 = gCurDecorationItems[gCurDecorationIndex];
|
2018-05-01 21:19:24 +02:00
|
|
|
StringCopy(gStringVar3, gDecorations[gSpecialVar_0x8004].name);
|
|
|
|
StringCopy(gStringVar2, gDecorations[gSpecialVar_0x8006].name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gSpecialVar_0x8006 = 0xFFFF;
|
|
|
|
}
|
|
|
|
DestroyTask(taskId);
|
|
|
|
EnableBothScriptContexts();
|
|
|
|
}
|
|
|
|
|
2019-04-06 19:41:55 +02:00
|
|
|
void ExitTraderMenu(u8 taskId)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
gSpecialVar_0x8006 = 0;
|
|
|
|
DestroyTask(taskId);
|
|
|
|
EnableBothScriptContexts();
|
|
|
|
}
|
|
|
|
|
2021-10-18 06:08:36 +02:00
|
|
|
void TraderDoDecorationTrade(void)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader;
|
|
|
|
|
|
|
|
DecorationRemove(gSpecialVar_0x8006);
|
|
|
|
DecorationAdd(gSpecialVar_0x8004);
|
2018-05-08 00:18:00 +02:00
|
|
|
StringCopy(trader->playerNames[gSpecialVar_0x8005], gSaveBlock2Ptr->playerName);
|
2020-02-23 16:46:22 +01:00
|
|
|
trader->decorations[gSpecialVar_0x8005] = gSpecialVar_0x8006;
|
2018-05-01 21:19:24 +02:00
|
|
|
trader->language[gSpecialVar_0x8005] = GAME_LANGUAGE;
|
|
|
|
trader->alreadyTraded = TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-18 06:08:36 +02:00
|
|
|
void TraderMenuGetDecoration(void)
|
2018-05-01 21:19:24 +02:00
|
|
|
{
|
|
|
|
u8 taskId = CreateTask(Task_HandleGetDecorationMenuInput, 0);
|
|
|
|
CreateAvailableDecorationsMenu(taskId);
|
|
|
|
}
|