Added textscreen macro

This commit is contained in:
Ninjdai 2023-11-11 10:49:46 +01:00
parent de9f15a76b
commit a722911e4e
12 changed files with 272 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

14
include/text_screen.h Normal file
View File

@ -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

View File

@ -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 :

View File

@ -0,0 +1,4 @@
#define TEXT_SCREEN_TEXT_EXAMPLE 0
#define TEXT_SCREEN_TEXT_COUNT 1
static const u8 sText_Example[] = _("Hello world");

View File

@ -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);

View File

@ -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;
}

221
src/text_screen.c Normal file
View File

@ -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;
}

View File

@ -150,3 +150,4 @@
.include "src/rayquaza_scene.o"
.include "src/debug.o"
.include "src/battle_controller_player.o"
.include "src/text_screen.o"