- 1
- Posts
- 2
- Years
- Seen Jul 17, 2023
I'm trying to create a gym leader preview on the signs in front of the gym itself.
So far I achieved to display the trainer and all the team :
Now I would like to add a black background window with a bit of transparency, exactly what is already done one starter selection for the pokémon label :
Here i'm totally lost and i can't get something to work properly. I just can't figure out how windows are managed exactly and i think the problem might be palette related.
The window either don't show up or does not have the right color and transparency.
Here is my code so far :
So far I achieved to display the trainer and all the team :
Now I would like to add a black background window with a bit of transparency, exactly what is already done one starter selection for the pokémon label :
Here i'm totally lost and i can't get something to work properly. I just can't figure out how windows are managed exactly and i think the problem might be palette related.
The window either don't show up or does not have the right color and transparency.
Here is my code so far :
Spoiler:
Code:
src/script_menu.c
Code:
static const struct WindowTemplate sWindowTemplate_TrainerTeamWindow =
{
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 13,
.height = 4,
.paletteNum = 14,
.baseBlock = 0x0274
};
static const u8 sTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY};
static const s16 sPreviewTeamLocation[PARTY_SIZE][2] =
{
{56, 30},
{184, 30},
{200, 80},
{40, 80},
{56, 130},
{184, 130}
};
#define tState data[0]
#define tWindowId data[1]
#define tSpriteNumber data[2]
#define tTrainerSpriteId data[3]
#define tMonSpriteId(i) data[i + 4]
bool8 ScriptMenu_ShowTrainerTeam(u16 trainerId)
{
if (FindTaskIdByFunc(Task_DisplayTrainerTeam) != TASK_NONE)
{
return FALSE;
}
else
{
u8 taskId;
u8 windowId;
u8 i;
u8 width;
const struct Trainer *trainer = &gTrainers[trainerId];
struct WindowTemplate winTemplate;
taskId = CreateTask(Task_DisplayTrainerTeam, 80);
// Background window
winTemplate = sWindowTemplate_TrainerTeamWindow;
windowId = AddWindow(&winTemplate);
gTasks[taskId].tWindowId = windowId;
FillWindowPixelBuffer(windowId, PIXEL_FILL(0));
width = GetStringCenterAlignXOffset(FONT_NARROW, trainer->trainerName, 0x68);
AddTextPrinterParameterized3(windowId, FONT_NARROW, width + 20, 30, sTextColors, 0, trainer->trainerName);
// Display trainer and party sprites
gTasks[taskId].tTrainerSpriteId = CreateTrainerPicSprite(trainer->trainerPic, TRUE, 120, 80, 12, TAG_NONE);
gTasks[taskId].tSpriteNumber = trainer->partySize;
for(i = 0; i < trainer->partySize; i++) {
u8 startX = sPreviewTeamLocation[i][0];
u8 startY = sPreviewTeamLocation[i][1];
u8 spriteId = CreateMonSprite_PicBox(trainer->party.NoItemDefaultMoves[i].species, startX, startY, 0);
gSprites[spriteId].callback = SpriteCallbackDummy;
gSprites[spriteId].oam.priority = 0;
gTasks[taskId].tMonSpriteId(i) = spriteId;
}
PutWindowTilemap(windowId);
//ScheduleBgCopyTilemapToVram(0);
CopyWindowToVram(windowId, COPYWIN_FULL);
return TRUE;
}
}
static void Task_DisplayTrainerTeam(u8 taskId)
{
s8 selection;
s16 *data = gTasks[taskId].data;
u8 i;
struct Task *task = &gTasks[taskId];
switch (task->tState)
{
case 0:
task->tState++;
break;
case 1:
//selection = Menu_ProcessInput();
if (JOY_NEW(A_BUTTON | B_BUTTON))
{
task->tState++;
}
break;
case 2:
for(i = 0; i < task->tSpriteNumber; i++) {
FreeResourcesAndDestroySprite(&gSprites[task->tMonSpriteId(i)], task->tMonSpriteId(i));
}
FreeResourcesAndDestroySprite(&gSprites[task->tTrainerSpriteId], task->tTrainerSpriteId);
task->tState++;
break;
case 3:
FillWindowPixelBuffer(0, PIXEL_FILL(0));
ClearWindowTilemap(task->tWindowId);
RemoveWindow(task->tWindowId);
task->tWindowId = WINDOW_NONE;
DestroyTask(taskId);
ScriptContext_Enable();
break;
}
}