diff --git a/asm/macros/event.inc b/asm/macros/event.inc index d2d8f8ca6..a8f33e37e 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -1735,6 +1735,20 @@ .2byte \quantity .endm + @ Textscreen (functionality is in the name) + .macro textscreen textId:req, x:req, y:req, width:req, height:req, speed:req, bgColor:req, fontId:req, fontColor:req + .byte 0xe3 + .byte \textId + .byte \x + .byte \y + .byte \width + .byte \height + .byte \speed + .byte \bgColor + .byte \fontId + .byte \fontColor + .endm + @ Supplementary @@ -2018,7 +2032,7 @@ setvar VAR_0x8002, \tryMultiple special TrySpecialOverworldEvo .endm - + .macro ai_vs_ai_battle trainer1:req, trainer2:req setflag B_FLAG_AI_VS_AI_BATTLE setvar VAR_0x8004, \trainer1 diff --git a/data/maps/InsideOfStartBoat_0F/scripts.inc b/data/maps/InsideOfStartBoat_0F/scripts.inc index 47aa6e6f2..a51e63699 100644 --- a/data/maps/InsideOfStartBoat_0F/scripts.inc +++ b/data/maps/InsideOfStartBoat_0F/scripts.inc @@ -3,6 +3,8 @@ InsideOfStartBoat_0F_MapScripts:: InsideOfStartBoat_0F_EventScript_BirchsBag:: lock +// textscreen textId:req, x:req, y:req, width:req, height:req, speed:req, bgColor:req, fontId:req, fontColor:req + textscreen 0, 5, 5, 10, 5, 2, 0, 1, 1 faceplayer setflag FLAG_SYS_POKEMON_GET setflag FLAG_RESCUED_BIRCH diff --git a/data/script_cmd_table.inc b/data/script_cmd_table.inc index f50ce5322..a9c992b38 100644 --- a/data/script_cmd_table.inc +++ b/data/script_cmd_table.inc @@ -227,6 +227,7 @@ gScriptCmdTable:: .4byte ScrCmd_warpwhitefade @ 0xe0 .4byte ScrCmd_buffercontestname @ 0xe1 .4byte ScrCmd_bufferitemnameplural @ 0xe2 + .4byte ScrCmd_textscreen @ 0xe3 gScriptCmdTableEnd:: .4byte ScrCmd_nop diff --git a/include/constants/global.h b/include/constants/global.h index 2930ae2ae..8b95b42dd 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -55,7 +55,7 @@ #define SECRET_BASES_COUNT 20 #define POKE_NEWS_COUNT 16 #define PC_ITEMS_COUNT 50 -#define BAG_ITEMS_COUNT 30 +#define BAG_ITEMS_COUNT 60 #define BAG_KEYITEMS_COUNT 30 #define BAG_POKEBALLS_COUNT 16 #define BAG_TMHM_COUNT 64 diff --git a/include/menu.h b/include/menu.h index 0b0a42423..f96101428 100644 --- a/include/menu.h +++ b/include/menu.h @@ -42,6 +42,8 @@ struct MenuAction extern const u16 gStandardMenuPalette[]; +u16 AddWindowParameterized(u8, u8, u8, u8, u8, u8, u16); + void FreeAllOverworldWindowBuffers(void); void InitStandardTextBoxWindows(void); void InitTextBoxGfxAndPrinters(void); diff --git a/include/text_screen.h b/include/text_screen.h new file mode 100644 index 000000000..bca1e3b01 --- /dev/null +++ b/include/text_screen.h @@ -0,0 +1,14 @@ +#ifndef GUARD_TEXT_SCREEN_H +#define GUARD_TEXT_SCREEN_H + +#include "script.h" + +#define TEXT_SCREEN_BG_COLOR_BLACK 0 +#define TEXT_SCREEN_BG_COLOR_COUNT 1 + +#define TEXT_SCREEN_FONT_COLOR_WHITE 0 +#define TEXT_SCREEN_FONT_COLOR_COUNT 1 + +void InitTextScreen(struct ScriptContext *ctx); + +#endif // GUARD_TEXT_SCREEN_H diff --git a/ld_script.txt b/ld_script.txt index a68d1a2a2..e59dc2dca 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -344,6 +344,7 @@ SECTIONS { src/international_string_util.o(.text); src/pokemon_debug.o(.text); src/expansion_intro.o(.text); + src/text_screen.o(.text); } =0 script_data : @@ -711,6 +712,7 @@ SECTIONS { data/sound_data.o(.rodata); src/pokemon_debug.o(.rodata); src/expansion_intro.o(.rodata); + src/text_screen.o(.rodata); } =0 song_data : diff --git a/src/data/text/text_screen.h b/src/data/text/text_screen.h new file mode 100644 index 000000000..f14e6d594 --- /dev/null +++ b/src/data/text/text_screen.h @@ -0,0 +1,4 @@ +#define TEXT_SCREEN_TEXT_EXAMPLE 0 +#define TEXT_SCREEN_TEXT_COUNT 1 + +static const u8 sText_Example[] = _("Hello world"); diff --git a/src/menu.c b/src/menu.c index ca61f8b87..011201544 100644 --- a/src/menu.c +++ b/src/menu.c @@ -49,7 +49,7 @@ struct Menu bool8 APressMuted; }; -static u16 AddWindowParameterized(u8, u8, u8, u8, u8, u8, u16); +/*static */u16 AddWindowParameterized(u8, u8, u8, u8, u8, u8, u16); static void WindowFunc_DrawStandardFrame(u8, u8, u8, u8, u8, u8); static void WindowFunc_DrawDialogueFrame(u8, u8, u8, u8, u8, u8); static void WindowFunc_ClearStdWindowAndFrame(u8, u8, u8, u8, u8, u8); diff --git a/src/scrcmd.c b/src/scrcmd.c index 583cd71be..23aea1f6e 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -50,6 +50,8 @@ #include "window.h" #include "constants/event_objects.h" +#include "text_screen.h" + typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(struct ScriptContext *ctx); @@ -2326,3 +2328,9 @@ bool8 ScrCmd_warpwhitefade(struct ScriptContext *ctx) ResetInitialPlayerAvatarState(); return TRUE; } + +bool8 ScrCmd_textscreen(struct ScriptContext *ctx) +{ + InitTextScreen(ctx); + return FALSE; +} diff --git a/src/text_screen.c b/src/text_screen.c new file mode 100644 index 000000000..06673bd3e --- /dev/null +++ b/src/text_screen.c @@ -0,0 +1,221 @@ +#include "global.h" +#include "main.h" +#include "bg.h" +#include "sprite.h" +#include "palette.h" +#include "text.h" +#include "text_window.h" +#include "string.h" +#include "string_util.h" +#include "menu.h" +#include "menu_helpers.h" +#include "decompress.h" +#include "window.h" +#include "string.h" +#include "task.h" +#include "sound.h" +#include "gpu_regs.h" +#include "malloc.h" +#include "scanline_effect.h" +#include "event_object_movement.h" +#include "overworld.h" +#include "constants/event_objects.h" +#include "constants/rgb.h" +#include "constants/songs.h" +#include "trig.h" +#include "text_screen.h" +#include "data/text/text_screen.h" +#include "field_weather.h" +#include "script.h" + +enum{BG_0, + BG_COUNT}; +static const struct BgTemplate sBgTemplates_TextScreen[BG_COUNT] = { + [BG_0] = { + .bg = BG_0, + .charBaseIndex = 0, + .mapBaseIndex = 21, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0, + }, +}; + +#define TEXT_SCREEN_WINDOW_BG 0 +#define TEXT_SCREEN_WINDOW_PALETTE_NUM 15 +#define TEXT_SCREEN_WINDOW_BASE_BLOCK 1 + +#define TEXT_WINDOW_BG_PALETTE 0 +#define TEXT_WINDOW_BG_PALETTE_SIZE 2 + +static EWRAM_DATA u8 sTextScreenWindowId = 0; + +static EWRAM_DATA u8 sTextScreenTextId = 0; +static EWRAM_DATA u8 sTextScreenTextX = 0; +static EWRAM_DATA u8 sTextScreenTextY = 0; +static EWRAM_DATA u8 sTextScreenTextWidth = 0; +static EWRAM_DATA u8 sTextScreenTextHeight = 0; +static EWRAM_DATA u8 sTextScreenTextSpeed = 0; +static EWRAM_DATA u8 sTextScreenBgColor = 0; +static EWRAM_DATA u8 sTextScreenFontId = 0; +static EWRAM_DATA u8 sTextScreenFontColor = 0; + +static const u8* const sTextScreen_Texts[TEXT_SCREEN_TEXT_COUNT] = +{ + [TEXT_SCREEN_TEXT_EXAMPLE] = sText_Example, +}; + +static const u16 sTextScreen_BgColor[TEXT_SCREEN_BG_COLOR_COUNT][1] = +{ + [TEXT_SCREEN_BG_COLOR_BLACK] = {RGB(0,0,0)}, +}; + +static const u8 sTextScreen_FontColors[TEXT_SCREEN_FONT_COLOR_COUNT][3] = +{ + [TEXT_SCREEN_FONT_COLOR_WHITE] = {0, 1, 2}, +}; + +static void TextScreen_ScriptReadValues(struct ScriptContext *ctx); +void CB2_InitTextScreen(); +static void TextScreen_InitBgs(); +static void TextScreen_InitWindow(); +static void TextScreen_LoadText(); +static void CB2_TextScreen(); +static void VBlankCallback_TextScreen(); +static void Task_TextScreen_PrintText(u8 taskId); +static void Task_TextScreen_HandleInput(u8 taskId); +static u8 GetValidValue(u8 value, u8 maxValue); + +void InitTextScreen(struct ScriptContext *ctx) +{ + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); + PlayRainStoppingSoundEffect(); + CleanupOverworldWindowsAndTilemaps(); + TextScreen_ScriptReadValues(ctx); + SetMainCallback2(CB2_InitTextScreen); +} + +static void TextScreen_ScriptReadValues(struct ScriptContext *ctx) +{ + sTextScreenTextId = GetValidValue(ScriptReadByte(ctx), TEXT_SCREEN_TEXT_COUNT); + sTextScreenTextX = ScriptReadByte(ctx); + sTextScreenTextY = ScriptReadByte(ctx); + sTextScreenTextWidth = ScriptReadByte(ctx); + sTextScreenTextHeight = ScriptReadByte(ctx); + sTextScreenTextSpeed = ScriptReadByte(ctx); + sTextScreenBgColor = GetValidValue(ScriptReadByte(ctx), TEXT_SCREEN_BG_COLOR_COUNT); + sTextScreenFontId = ScriptReadByte(ctx); + sTextScreenFontColor = GetValidValue(ScriptReadByte(ctx), TEXT_SCREEN_FONT_COLOR_COUNT); +} + +void CB2_InitTextScreen() +{ + if(!UpdatePaletteFade()) + { + switch (gMain.state) + { + case 0: + SetVBlankCallback(NULL); + ResetPaletteFade(); + ScanlineEffect_Stop(); + ResetTasks(); + ResetSpriteData(); + gMain.state++; + break; + case 1: + TextScreen_InitBgs(); + TextScreen_InitWindow(); + gMain.state++; + break; + case 2: + LoadPalette(sTextScreen_BgColor[sTextScreenBgColor], TEXT_WINDOW_BG_PALETTE * 0x10, TEXT_WINDOW_BG_PALETTE_SIZE * 2); + gMain.state++; + break; + case 3: + PutWindowTilemap(sTextScreenWindowId); + TextScreen_LoadText(); + gMain.state++; + break; + default: + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); + + SetMainCallback2(CB2_TextScreen); + SetVBlankCallback(VBlankCallback_TextScreen); + + CreateTask(Task_TextScreen_PrintText, 0); + break; + } + } +} + +static void TextScreen_InitBgs() +{ + ResetVramOamAndBgCntRegs(); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, sBgTemplates_TextScreen, BG_COUNT); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ShowBg(0); +} + +static void TextScreen_InitWindow() +{ + sTextScreenWindowId = AddWindowParameterized(TEXT_SCREEN_WINDOW_BG, + sTextScreenTextX, sTextScreenTextY, + sTextScreenTextWidth, sTextScreenTextHeight, + TEXT_SCREEN_WINDOW_PALETTE_NUM, TEXT_SCREEN_WINDOW_BASE_BLOCK); + DeactivateAllTextPrinters(); +} + +static void TextScreen_LoadText(){ + AddTextPrinterParameterized3(sTextScreenWindowId, sTextScreenFontId, 0, 0, + sTextScreen_FontColors[sTextScreenFontColor], sTextScreenTextSpeed, + sTextScreen_Texts[sTextScreenTextId]); + CopyWindowToVram(sTextScreenWindowId, 3); +} + +static void CB2_TextScreen() +{ + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + DoScheduledBgTilemapCopiesToVram(); + UpdatePaletteFade(); +} + +static void VBlankCallback_TextScreen() +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +static void Task_TextScreen_PrintText(u8 taskId) +{ + if(UpdatePaletteFade()) + return; + + RunTextPrinters(); + if (!IsTextPrinterActive(sTextScreenWindowId)) + { + gTasks[taskId].func = Task_TextScreen_HandleInput; + } +} + +static void Task_TextScreen_HandleInput(u8 taskId) +{ + if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + { + SetMainCallback2(CB2_ReturnToFieldContinueScript); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); + DestroyTask(taskId); + } +} + +static u8 GetValidValue(u8 value, u8 maxValue) +{ + if(value < maxValue) + return value; + return 0; +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 2d7a6e26e..c2778a6a2 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -150,3 +150,4 @@ .include "src/rayquaza_scene.o" .include "src/debug.o" .include "src/battle_controller_player.o" + .include "src/text_screen.o"