From 687f02119f20e0b5ec77a5fbc3360281aa1086ba Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 31 Jan 2019 18:38:21 +0000 Subject: [PATCH] Added SelStage.cpp (teleporter menu) --- Makefile | 1 + src/Game.cpp | 3 +- src/Profile.cpp | 3 +- src/SelStage.cpp | 197 +++++++++++++++++++++++++++++++++++++++++++++++ src/SelStage.h | 8 ++ src/TextScr.cpp | 23 +++++- src/TextScr.h | 2 +- 7 files changed, 233 insertions(+), 4 deletions(-) create mode 100644 src/SelStage.cpp create mode 100644 src/SelStage.h diff --git a/Makefile b/Makefile index 4e6b2edc..67f203cf 100644 --- a/Makefile +++ b/Makefile @@ -89,6 +89,7 @@ SOURCES = \ Shoot \ Sound \ Stage \ + SelStage \ TextScr \ Triangle \ ValueView diff --git a/src/Game.cpp b/src/Game.cpp index 1b117843..acdf9811 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -38,6 +38,7 @@ #include "Ending.h" #include "Flash.h" #include "BossLife.h" +#include "SelStage.h" int g_GameFlags; int gCounter; @@ -439,7 +440,7 @@ int ModeAction() InitFlash(); ClearArmsData(); ClearItemData(); - //ClearPermitStage(); + ClearPermitStage(); //StartMapping(); InitFlags(); InitBossLife(); diff --git a/src/Profile.cpp b/src/Profile.cpp index e2a7d63e..0537dceb 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -15,6 +15,7 @@ #include "Stage.h" #include "Game.h" #include "BossLife.h" +#include "SelStage.h" const char *gDefaultName = "Profile.dat"; const char *gProfileCode = "Do041220"; @@ -147,7 +148,7 @@ bool InitializeGame() gCounter = 0; ClearArmsData(); ClearItemData(); - //ClearPermitStage(); + ClearPermitStage(); //StartMapping(); InitFlags(); if (!TransferStage(13, 200, 10, 8)) diff --git a/src/SelStage.cpp b/src/SelStage.cpp new file mode 100644 index 00000000..18b38f7c --- /dev/null +++ b/src/SelStage.cpp @@ -0,0 +1,197 @@ +#include "SelStage.h" + +#include + +#include "Draw.h" +#include "Escape.h" +#include "KeyControl.h" +#include "Main.h" +#include "TextScr.h" +#include "Sound.h" +#include "WindowsWrapper.h" + +static struct +{ + int index; + int event; +} gPermitStage[8]; + +static int gSelectedStage; +static int gStageSelectTitleY; + +void ClearPermitStage(void) +{ + memset(gPermitStage, 0, 0x40); +} + +bool AddPermitStage(int index, int event) +{ + for (int i = 0; i < 8; ++i) + { + if (gPermitStage[i].index == 0 || gPermitStage[i].index == index) + { + gPermitStage[i].index = index; + gPermitStage[i].event = event; + return true; + } + } + + return false; +} + +bool SubPermitStage(int index) +{ + int i; + for (i = 0; i < 8 && gPermitStage[i].index != index; ++i); + +#ifdef FIX_BUGS + if (i != 8) +#else + if (i != 32) +#endif + { + int ia; + for (ia = i + 1; ia < 8; ++ia) + { + gPermitStage[ia - 1].index = gPermitStage[ia].index; + gPermitStage[ia - 1].event = gPermitStage[ia].event; + } + + gPermitStage[ia - 1].index = 0; + gPermitStage[ia - 1].event = 0; + + return true; + } + + return false; +} + +void MoveStageSelectCursor(void) +{ + int stage_num; + for (stage_num = 0; gPermitStage[stage_num].index != 0; ++stage_num); + + if (stage_num) + { + if (gKeyTrg & gKeyLeft) + --gSelectedStage; + + if (gKeyTrg & gKeyRight) + ++gSelectedStage; + + if (gSelectedStage < 0) + gSelectedStage = stage_num - 1; + + if (stage_num - 1 < gSelectedStage) + gSelectedStage = 0; + + if ((gKeyRight | gKeyLeft) & gKeyTrg) + StartTextScript(gPermitStage[gSelectedStage].index + 1000); + + if ((gKeyRight | gKeyLeft) & gKeyTrg) + PlaySoundObject(1, 1); + } +} + +void PutStageSelectObject(void) +{ + static unsigned int flash; + + RECT rcView; + RECT rcCur[2]; + RECT rcTitle1; + + rcView = {0, 0, 320, 240}; + rcCur[0] = {80, 88, 112, 104}; + rcCur[1] = {80, 104, 112, 120}; + rcTitle1 = {80, 64, 144, 72}; + + if (gStageSelectTitleY > 46) + --gStageSelectTitleY; + + PutBitmap3(&rcView, 128, gStageSelectTitleY, &rcTitle1, SURFACE_ID_TEXT_BOX); + + int stage_num; + for (stage_num = 0; gPermitStage[stage_num].index; ++stage_num); + + ++flash; + + if (stage_num) + { + int stage_x = (320 - 40 * stage_num) / 2; + + PutBitmap3(&rcView, stage_x + 40 * gSelectedStage, 64, &rcCur[(flash >> 1) % 2], SURFACE_ID_TEXT_BOX); + + for (int i = 0; i < 8 && gPermitStage[i].index; ++i) + { + RECT rcStage; + rcStage.left = 32 * (gPermitStage[i].index % 8); + rcStage.right = rcStage.left + 32; + rcStage.top = 16 * (gPermitStage[i].index / 8); + rcStage.bottom = rcStage.top + 16; + + PutBitmap3(&rcView, stage_x + 40 * i, 64, &rcStage, SURFACE_ID_STAGE_ITEM); + } + } +} + +int StageSelectLoop(int *p_event) +{ + char old_script_path[260]; + + RECT rcView = {0, 0, 320, 240}; + + gSelectedStage = 0; + BackupSurface(10, &grcFull); + GetTextScriptPath(old_script_path); + LoadTextScript2("StageSelect.tsc"); + gStageSelectTitleY = 54; + StartTextScript(gPermitStage[gSelectedStage].index + 1000); + + do + { + GetTrg(); + + if (gKey & KEY_ESCAPE) + { + int escRet = Call_Escape(); + if (escRet == 0) + return 0; + if (escRet == 2) + return 2; + } + + MoveStageSelectCursor(); + + int tscRet = TextScriptProc(); + if (tscRet == 0) + return 0; + if (tscRet == 2) + return 2; + + PutBitmap3(&rcView, 0, 0, &rcView, 10); + PutStageSelectObject(); + PutTextScript(); + + if (gKeyTrg & gKeyOk) + { + StopTextScript(); + LoadTextScript_Stage(old_script_path); + *p_event = gPermitStage[gSelectedStage].event; + return 1; + } + + if (gKeyTrg & gKeyCancel) + { + StopTextScript(); + LoadTextScript_Stage(old_script_path); + *p_event = 0; + return 1; + } + + PutFramePerSecound(); + } + while (Flip_SystemTask()); + + return 0; +} \ No newline at end of file diff --git a/src/SelStage.h b/src/SelStage.h new file mode 100644 index 00000000..ff2cddf8 --- /dev/null +++ b/src/SelStage.h @@ -0,0 +1,8 @@ +#pragma once + +void ClearPermitStage(void); +bool AddPermitStage(int index, int event); +bool SubPermitStage(int index); +void MoveStageSelectCursor(void); +void PutStageSelectObject(void); +int StageSelectLoop(int *p_event); diff --git a/src/TextScr.cpp b/src/TextScr.cpp index afa9d909..9d98a223 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -24,6 +24,7 @@ #include "Game.h" #include "Map.h" #include "BossLife.h" +#include "SelStage.h" #define IS_COMMAND(c1, c2, c3) gTS.data[gTS.p_read + 1] == c1 && gTS.data[gTS.p_read + 2] == c2 && gTS.data[gTS.p_read + 3] == c3 @@ -85,7 +86,7 @@ void EncryptionBinaryData2(uint8_t *pData, int size) } //Load generic .tsc -bool LoadTextScript2(char *name) +bool LoadTextScript2(const char *name) { //Get path char path[260]; @@ -670,6 +671,13 @@ int TextScriptProc() SubArmsData(z); gTS.p_read += 8; } + else if (IS_COMMAND('P','S','+')) + { + x = GetTextScriptNo(gTS.p_read + 4); + y = GetTextScriptNo(gTS.p_read + 9); + AddPermitStage(x, y); + gTS.p_read += 13; + } else if (IS_COMMAND('T','R','A')) { z = GetTextScriptNo(gTS.p_read + 4); @@ -942,6 +950,19 @@ int TextScriptProc() ReCallMusic(); gTS.p_read += 4; } + else if (IS_COMMAND('S','L','P')) + { + bExit = true; + + int selRet = StageSelectLoop(&z); + if (selRet == 0) + return 0; + if (selRet == 2) + return 2; + + JumpTextScript(z); + g_GameFlags &= ~3; + } else if (IS_COMMAND('D','N','P')) { z = GetTextScriptNo(gTS.p_read + 4); diff --git a/src/TextScr.h b/src/TextScr.h index e43caba8..d44d68b1 100644 --- a/src/TextScr.h +++ b/src/TextScr.h @@ -57,7 +57,7 @@ struct TEXT_SCRIPT bool InitTextScript2(); void EndTextScript(); void EncryptionBinaryData2(uint8_t *pData, int size); -bool LoadTextScript2(char *name); +bool LoadTextScript2(const char *name); bool LoadTextScript_Stage(char *name); void GetTextScriptPath(char *path); bool StartTextScript(int no);