2022-05-19 01:51:26 -07:00
|
|
|
#include "credits.h"
|
|
|
|
|
2022-09-15 02:38:23 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
#include "art.h"
|
|
|
|
#include "color.h"
|
|
|
|
#include "core.h"
|
|
|
|
#include "cycle.h"
|
2022-06-18 06:05:07 -07:00
|
|
|
#include "db.h"
|
2022-05-19 01:51:26 -07:00
|
|
|
#include "debug.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "game_mouse.h"
|
2022-10-04 23:23:27 -07:00
|
|
|
#include "input.h"
|
2022-05-19 01:51:26 -07:00
|
|
|
#include "memory.h"
|
|
|
|
#include "message.h"
|
2022-10-03 02:41:33 -07:00
|
|
|
#include "mouse.h"
|
2022-05-19 01:51:26 -07:00
|
|
|
#include "palette.h"
|
2022-05-28 02:34:49 -07:00
|
|
|
#include "platform_compat.h"
|
2022-05-19 01:51:26 -07:00
|
|
|
#include "sound.h"
|
|
|
|
#include "text_font.h"
|
|
|
|
#include "window_manager.h"
|
|
|
|
|
2022-09-23 05:43:44 -07:00
|
|
|
namespace fallout {
|
|
|
|
|
2022-06-18 06:05:07 -07:00
|
|
|
#define CREDITS_WINDOW_WIDTH (640)
|
|
|
|
#define CREDITS_WINDOW_HEIGHT (480)
|
|
|
|
#define CREDITS_WINDOW_SCROLLING_DELAY (38)
|
|
|
|
|
|
|
|
static bool creditsFileParseNextLine(char* dest, int* font, int* color);
|
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
// 0x56D740
|
2022-06-18 06:05:07 -07:00
|
|
|
static File* gCreditsFile;
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
// 0x56D744
|
2022-06-18 06:05:07 -07:00
|
|
|
static int gCreditsWindowNameColor;
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
// 0x56D748
|
2022-06-18 06:05:07 -07:00
|
|
|
static int gCreditsWindowTitleFont;
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
// 0x56D74C
|
2022-06-18 06:05:07 -07:00
|
|
|
static int gCreditsWindowNameFont;
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
// 0x56D750
|
2022-06-18 06:05:07 -07:00
|
|
|
static int gCreditsWindowTitleColor;
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
// 0x42C860
|
|
|
|
void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
|
|
|
|
{
|
|
|
|
int oldFont = fontGetCurrent();
|
|
|
|
|
|
|
|
colorPaletteLoad("color.pal");
|
|
|
|
|
|
|
|
if (useReversedStyle) {
|
|
|
|
gCreditsWindowTitleColor = _colorTable[18917];
|
|
|
|
gCreditsWindowNameFont = 103;
|
|
|
|
gCreditsWindowTitleFont = 104;
|
|
|
|
gCreditsWindowNameColor = _colorTable[13673];
|
|
|
|
} else {
|
|
|
|
gCreditsWindowTitleColor = _colorTable[13673];
|
|
|
|
gCreditsWindowNameFont = 104;
|
|
|
|
gCreditsWindowTitleFont = 103;
|
|
|
|
gCreditsWindowNameColor = _colorTable[18917];
|
|
|
|
}
|
|
|
|
|
|
|
|
soundContinueAll();
|
|
|
|
|
2022-05-28 02:34:49 -07:00
|
|
|
char localizedPath[COMPAT_MAX_PATH];
|
2022-05-19 01:51:26 -07:00
|
|
|
if (_message_make_path(localizedPath, filePath)) {
|
|
|
|
gCreditsFile = fileOpen(localizedPath, "rt");
|
|
|
|
if (gCreditsFile != NULL) {
|
|
|
|
soundContinueAll();
|
|
|
|
|
|
|
|
colorCycleDisable();
|
|
|
|
gameMouseSetCursor(MOUSE_CURSOR_NONE);
|
|
|
|
|
|
|
|
bool cursorWasHidden = cursorIsHidden();
|
|
|
|
if (cursorWasHidden) {
|
|
|
|
mouseShowCursor();
|
|
|
|
}
|
|
|
|
|
2022-05-21 04:00:30 -07:00
|
|
|
int creditsWindowX = (screenGetWidth() - CREDITS_WINDOW_WIDTH) / 2;
|
|
|
|
int creditsWindowY = (screenGetHeight() - CREDITS_WINDOW_HEIGHT) / 2;
|
|
|
|
int window = windowCreate(creditsWindowX, creditsWindowY, CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_HEIGHT, _colorTable[0], 20);
|
2022-05-19 01:51:26 -07:00
|
|
|
soundContinueAll();
|
|
|
|
if (window != -1) {
|
|
|
|
unsigned char* windowBuffer = windowGetBuffer(window);
|
|
|
|
if (windowBuffer != NULL) {
|
2022-05-21 08:22:03 -07:00
|
|
|
unsigned char* backgroundBuffer = (unsigned char*)internal_malloc(CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
|
2022-05-19 01:51:26 -07:00
|
|
|
if (backgroundBuffer) {
|
|
|
|
soundContinueAll();
|
|
|
|
|
|
|
|
memset(backgroundBuffer, _colorTable[0], CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
|
|
|
|
|
|
|
|
if (backgroundFid != -1) {
|
|
|
|
CacheEntry* backgroundFrmHandle;
|
|
|
|
Art* frm = artLock(backgroundFid, &backgroundFrmHandle);
|
|
|
|
if (frm != NULL) {
|
|
|
|
int width = artGetWidth(frm, 0, 0);
|
|
|
|
int height = artGetHeight(frm, 0, 0);
|
|
|
|
unsigned char* backgroundFrmData = artGetFrameData(frm, 0, 0);
|
|
|
|
blitBufferToBuffer(backgroundFrmData,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
width,
|
|
|
|
backgroundBuffer + CREDITS_WINDOW_WIDTH * ((CREDITS_WINDOW_HEIGHT - height) / 2) + (CREDITS_WINDOW_WIDTH - width) / 2,
|
|
|
|
CREDITS_WINDOW_WIDTH);
|
|
|
|
artUnlock(backgroundFrmHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-21 08:22:03 -07:00
|
|
|
unsigned char* intermediateBuffer = (unsigned char*)internal_malloc(CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
|
2022-05-19 01:51:26 -07:00
|
|
|
if (intermediateBuffer != NULL) {
|
|
|
|
memset(intermediateBuffer, 0, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT);
|
|
|
|
|
|
|
|
fontSetCurrent(gCreditsWindowTitleFont);
|
|
|
|
int titleFontLineHeight = fontGetLineHeight();
|
|
|
|
|
|
|
|
fontSetCurrent(gCreditsWindowNameFont);
|
|
|
|
int nameFontLineHeight = fontGetLineHeight();
|
|
|
|
|
|
|
|
int lineHeight = nameFontLineHeight + (titleFontLineHeight >= nameFontLineHeight ? titleFontLineHeight - nameFontLineHeight : 0);
|
|
|
|
int stringBufferSize = CREDITS_WINDOW_WIDTH * lineHeight;
|
2022-05-21 08:22:03 -07:00
|
|
|
unsigned char* stringBuffer = (unsigned char*)internal_malloc(stringBufferSize);
|
2022-05-19 01:51:26 -07:00
|
|
|
if (stringBuffer != NULL) {
|
|
|
|
blitBufferToBuffer(backgroundBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
CREDITS_WINDOW_HEIGHT,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
windowBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH);
|
|
|
|
|
|
|
|
windowRefresh(window);
|
|
|
|
|
|
|
|
paletteFadeTo(_cmap);
|
|
|
|
|
|
|
|
unsigned char* v40 = intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH;
|
|
|
|
char str[260];
|
|
|
|
int font;
|
|
|
|
int color;
|
|
|
|
unsigned int tick = 0;
|
|
|
|
bool stop = false;
|
|
|
|
while (creditsFileParseNextLine(str, &font, &color)) {
|
|
|
|
fontSetCurrent(font);
|
|
|
|
|
|
|
|
int v19 = fontGetStringWidth(str);
|
|
|
|
if (v19 >= CREDITS_WINDOW_WIDTH) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(stringBuffer, 0, stringBufferSize);
|
|
|
|
fontDrawText(stringBuffer, str, CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH, color);
|
|
|
|
|
|
|
|
unsigned char* dest = intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH + (CREDITS_WINDOW_WIDTH - v19) / 2;
|
|
|
|
unsigned char* src = stringBuffer;
|
|
|
|
for (int index = 0; index < lineHeight; index++) {
|
2022-10-05 00:11:47 -07:00
|
|
|
if (inputGetInput() != -1) {
|
2022-05-19 01:51:26 -07:00
|
|
|
stop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memmove(intermediateBuffer, intermediateBuffer + CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH);
|
|
|
|
memcpy(dest, src, v19);
|
|
|
|
|
|
|
|
blitBufferToBuffer(backgroundBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
CREDITS_WINDOW_HEIGHT,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
windowBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH);
|
|
|
|
|
|
|
|
blitBufferToBufferTrans(intermediateBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
CREDITS_WINDOW_HEIGHT,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
windowBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH);
|
|
|
|
|
|
|
|
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
|
|
|
|
}
|
|
|
|
|
2022-10-05 00:11:47 -07:00
|
|
|
tick = getTicks();
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
windowRefresh(window);
|
|
|
|
|
|
|
|
src += CREDITS_WINDOW_WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stop) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stop) {
|
|
|
|
for (int index = 0; index < CREDITS_WINDOW_HEIGHT; index++) {
|
2022-10-05 00:11:47 -07:00
|
|
|
if (inputGetInput() != -1) {
|
2022-05-19 01:51:26 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memmove(intermediateBuffer, intermediateBuffer + CREDITS_WINDOW_WIDTH, CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH);
|
|
|
|
memset(intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH, 0, CREDITS_WINDOW_WIDTH);
|
|
|
|
|
|
|
|
blitBufferToBuffer(backgroundBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
CREDITS_WINDOW_HEIGHT,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
windowBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH);
|
|
|
|
|
|
|
|
blitBufferToBufferTrans(intermediateBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
CREDITS_WINDOW_HEIGHT,
|
|
|
|
CREDITS_WINDOW_WIDTH,
|
|
|
|
windowBuffer,
|
|
|
|
CREDITS_WINDOW_WIDTH);
|
|
|
|
|
|
|
|
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
|
|
|
|
}
|
|
|
|
|
2022-10-05 00:11:47 -07:00
|
|
|
tick = getTicks();
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
windowRefresh(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal_free(stringBuffer);
|
|
|
|
}
|
|
|
|
internal_free(intermediateBuffer);
|
|
|
|
}
|
|
|
|
internal_free(backgroundBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
soundContinueAll();
|
|
|
|
paletteFadeTo(gPaletteBlack);
|
|
|
|
soundContinueAll();
|
|
|
|
windowDestroy(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursorWasHidden) {
|
|
|
|
mouseHideCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
gameMouseSetCursor(MOUSE_CURSOR_ARROW);
|
|
|
|
colorCycleEnable();
|
|
|
|
fileClose(gCreditsFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fontSetCurrent(oldFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x42CE6C
|
2022-06-18 06:05:07 -07:00
|
|
|
static bool creditsFileParseNextLine(char* dest, int* font, int* color)
|
2022-05-19 01:51:26 -07:00
|
|
|
{
|
|
|
|
char string[256];
|
|
|
|
while (fileReadString(string, 256, gCreditsFile)) {
|
|
|
|
char* pch;
|
|
|
|
if (string[0] == ';') {
|
|
|
|
continue;
|
|
|
|
} else if (string[0] == '@') {
|
|
|
|
*font = gCreditsWindowTitleFont;
|
|
|
|
*color = gCreditsWindowTitleColor;
|
|
|
|
pch = string + 1;
|
|
|
|
} else if (string[0] == '#') {
|
|
|
|
*font = gCreditsWindowNameFont;
|
|
|
|
*color = _colorTable[17969];
|
|
|
|
pch = string + 1;
|
|
|
|
} else {
|
|
|
|
*font = gCreditsWindowNameFont;
|
|
|
|
*color = gCreditsWindowNameColor;
|
|
|
|
pch = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(dest, pch);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-23 05:43:44 -07:00
|
|
|
|
|
|
|
} // namespace fallout
|