Refactor artLockFrameData with FrmImage

This commit is contained in:
Alexander Batalov 2022-09-26 15:17:22 +03:00
parent 4aae167bd8
commit ac0a044a32
1 changed files with 146 additions and 250 deletions

View File

@ -274,25 +274,6 @@ static int _dialogue_just_started = 0;
// 0x5187F0
static int _dialogue_seconds_since_last_input = 0;
// 0x5187F4
static CacheEntry* gGameDialogReviewWindowButtonFrmHandles[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_COUNT] = {
INVALID_CACHE_ENTRY,
INVALID_CACHE_ENTRY,
INVALID_CACHE_ENTRY,
INVALID_CACHE_ENTRY,
INVALID_CACHE_ENTRY,
INVALID_CACHE_ENTRY,
};
// 0x51880C
static CacheEntry* _reviewBackKey = INVALID_CACHE_ENTRY;
// 0x518810
static CacheEntry* gGameDialogReviewWindowBackgroundFrmHandle = INVALID_CACHE_ENTRY;
// 0x518814
static unsigned char* gGameDialogReviewWindowBackgroundFrmData = NULL;
// 0x518818
static const int gGameDialogReviewWindowButtonWidths[GAME_DIALOG_REVIEW_WINDOW_BUTTON_COUNT] = {
35,
@ -505,58 +486,9 @@ static int _control_buttons_start;
// 0x58F468
static int gGameDialogReviewWindowOldFont;
// 0x58F46C
static CacheEntry* gGameDialogRedButtonUpFrmHandle;
// 0x58F470
static int _gdialog_buttons[9];
// 0x58F494
static CacheEntry* gGameDialogUpperHighlightFrmHandle;
// 0x58F498
static CacheEntry* gGameDialogReviewButtonUpFrmHandle;
// 0x58F49C
static int gGameDialogLowerHighlightFrmHeight;
// 0x58F4A0
static CacheEntry* gGameDialogReviewButtonDownFrmHandle;
// 0x58F4A4
static unsigned char* gGameDialogRedButtonDownFrmData;
// 0x58F4A8
static int gGameDialogLowerHighlightFrmWidth;
// 0x58F4AC
static unsigned char* gGameDialogRedButtonUpFrmData;
// 0x58F4B0
static int gGameDialogUpperHighlightFrmWidth;
// Yellow highlight blick effect.
//
// 0x58F4B4
static Art* gGameDialogLowerHighlightFrm;
// 0x58F4B8
static int gGameDialogUpperHighlightFrmHeight;
// 0x58F4BC
static CacheEntry* gGameDialogRedButtonDownFrmHandle;
// 0x58F4C0
static CacheEntry* gGameDialogLowerHighlightFrmHandle;
// White highlight blick effect.
//
// This effect appears at the top-right corner on dialog display. Together with
// [gDialogLowerHighlight] it gives an effect of depth of the monitor.
//
// 0x58F4C4
static Art* gGameDialogUpperHighlightFrm;
// 0x58F4C8
static int _oldFont;
@ -604,6 +536,15 @@ static unsigned int gGameDialogFidgetUpdateDelay;
// 0x596C38
static int gGameDialogFidgetFrmCurrentFrame;
static FrmImage _reviewBackgroundFrmImage;
static FrmImage _reviewFrmImages[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_COUNT];
static FrmImage _reviewButtonNormalFrmImage;
static FrmImage _reviewButtonPressedFrmImage;
static FrmImage _redButtonNormalFrmImage;
static FrmImage _redButtonPressedFrmImage;
static FrmImage _lowerHighlightFrmImage;
static FrmImage _upperHighlightFrmImage;
static int _gdialogReset();
static void gameDialogEndLips();
static int gdHide();
@ -1348,32 +1289,28 @@ int gameDialogReviewWindowInit(int* win)
return -1;
}
FrmImage backgroundFrmImage;
int fid = buildFid(OBJ_TYPE_INTERFACE, 102, 0, 0, 0);
unsigned char* backgroundFrmData = artLockFrameData(fid, 0, 0, &_reviewBackKey);
if (backgroundFrmData == NULL) {
if (!backgroundFrmImage.lock(fid)) {
windowDestroy(*win);
*win = -1;
return -1;
}
unsigned char* windowBuffer = windowGetBuffer(*win);
blitBufferToBuffer(backgroundFrmData,
blitBufferToBuffer(backgroundFrmImage.getData(),
GAME_DIALOG_REVIEW_WINDOW_WIDTH,
GAME_DIALOG_REVIEW_WINDOW_HEIGHT,
GAME_DIALOG_REVIEW_WINDOW_WIDTH,
windowBuffer,
GAME_DIALOG_REVIEW_WINDOW_WIDTH);
artUnlock(_reviewBackKey);
_reviewBackKey = INVALID_CACHE_ENTRY;
unsigned char* buttonFrmData[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_COUNT];
backgroundFrmImage.unlock();
int index;
for (index = 0; index < GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_COUNT; index++) {
int fid = buildFid(OBJ_TYPE_INTERFACE, gGameDialogReviewWindowButtonFrmIds[index], 0, 0, 0);
buttonFrmData[index] = artLockFrameData(fid, 0, 0, &(gGameDialogReviewWindowButtonFrmHandles[index]));
if (buttonFrmData[index] == NULL) {
if (!_reviewFrmImages[index].lock(fid)) {
break;
}
}
@ -1392,8 +1329,8 @@ int gameDialogReviewWindowInit(int* win)
-1,
-1,
KEY_ARROW_UP,
buttonFrmData[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_UP_NORMAL],
buttonFrmData[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_UP_PRESSED],
_reviewFrmImages[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_UP_NORMAL].getData(),
_reviewFrmImages[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_UP_PRESSED].getData(),
NULL,
BUTTON_FLAG_TRANSPARENT);
if (upBtn == -1) {
@ -1412,8 +1349,8 @@ int gameDialogReviewWindowInit(int* win)
-1,
-1,
KEY_ARROW_DOWN,
buttonFrmData[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_DOWN_NORMAL],
buttonFrmData[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_DOWN_PRESSED],
_reviewFrmImages[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_DOWN_NORMAL].getData(),
_reviewFrmImages[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_ARROW_DOWN_PRESSED].getData(),
NULL,
BUTTON_FLAG_TRANSPARENT);
if (downBtn == -1) {
@ -1432,8 +1369,8 @@ int gameDialogReviewWindowInit(int* win)
-1,
-1,
KEY_ESCAPE,
buttonFrmData[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_DONE_NORMAL],
buttonFrmData[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_DONE_PRESSED],
_reviewFrmImages[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_DONE_NORMAL].getData(),
_reviewFrmImages[GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_DONE_PRESSED].getData(),
NULL,
BUTTON_FLAG_TRANSPARENT);
if (doneBtn == -1) {
@ -1450,8 +1387,7 @@ int gameDialogReviewWindowInit(int* win)
tickersRemove(gameDialogTicker);
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 102, 0, 0, 0);
gGameDialogReviewWindowBackgroundFrmData = artLockFrameData(backgroundFid, 0, 0, &gGameDialogReviewWindowBackgroundFrmHandle);
if (gGameDialogReviewWindowBackgroundFrmData == NULL) {
if (!_reviewBackgroundFrmImage.lock(backgroundFid)) {
gameDialogReviewWindowFree(win);
return -1;
}
@ -1465,17 +1401,10 @@ int gameDialogReviewWindowFree(int* win)
tickersAdd(gameDialogTicker);
for (int index = 0; index < GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_COUNT; index++) {
if (gGameDialogReviewWindowButtonFrmHandles[index] != INVALID_CACHE_ENTRY) {
artUnlock(gGameDialogReviewWindowButtonFrmHandles[index]);
gGameDialogReviewWindowButtonFrmHandles[index] = INVALID_CACHE_ENTRY;
}
_reviewFrmImages[index].unlock();
}
if (gGameDialogReviewWindowBackgroundFrmHandle != INVALID_CACHE_ENTRY) {
artUnlock(gGameDialogReviewWindowBackgroundFrmHandle);
gGameDialogReviewWindowBackgroundFrmHandle = INVALID_CACHE_ENTRY;
gGameDialogReviewWindowBackgroundFrmData = NULL;
}
_reviewBackgroundFrmImage.unlock();
fontSetCurrent(gGameDialogReviewWindowOldFont);
@ -1562,7 +1491,7 @@ void gameDialogReviewWindowUpdate(int win, int origin)
int width = GAME_DIALOG_WINDOW_WIDTH;
blitBufferToBuffer(
gGameDialogReviewWindowBackgroundFrmData + width * entriesRect.top + entriesRect.left,
_reviewBackgroundFrmImage.getData() + width * entriesRect.top + entriesRect.left,
width,
entriesRect.bottom - entriesRect.top + 15,
width,
@ -2947,7 +2876,7 @@ void _gdialog_scroll_subwin(int win, int a2, unsigned char* a3, unsigned char* a
} else {
rect.top = v18 * 10;
v7 = a6 % 10;
v9 += (GAME_DIALOG_WINDOW_WIDTH) * rect.top;
v9 += GAME_DIALOG_WINDOW_WIDTH * rect.top;
}
for (; v18 >= 0; v18--) {
@ -3185,20 +3114,18 @@ int _gdialog_barter_create_win()
frmId = 111;
}
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, frmId, 0, 0, 0);
CacheEntry* backgroundHandle;
Art* backgroundFrm = artLock(backgroundFid, &backgroundHandle);
if (backgroundFrm == NULL) {
if (!backgroundFrmImage.lock(backgroundFid)) {
return -1;
}
unsigned char* backgroundData = artGetFrameData(backgroundFrm, 0, 0);
unsigned char* backgroundData = backgroundFrmImage.getData();
if (backgroundData == NULL) {
artUnlock(backgroundHandle);
return -1;
}
_dialogue_subwin_len = artGetHeight(backgroundFrm, 0, 0);
_dialogue_subwin_len = backgroundFrmImage.getHeight();
int barterWindowX = (screenGetWidth() - GAME_DIALOG_WINDOW_WIDTH) / 2;
int barterWindowY = (screenGetHeight() - GAME_DIALOG_WINDOW_HEIGHT) / 2 + GAME_DIALOG_WINDOW_HEIGHT - _dialogue_subwin_len;
@ -3209,7 +3136,6 @@ int _gdialog_barter_create_win()
256,
WINDOW_FLAG_0x02);
if (gGameDialogWindow == -1) {
artUnlock(backgroundHandle);
return -1;
}
@ -3221,15 +3147,15 @@ int _gdialog_barter_create_win()
_gdialog_scroll_subwin(gGameDialogWindow, 1, backgroundData, windowBuffer, NULL, _dialogue_subwin_len, 0);
artUnlock(backgroundHandle);
backgroundFrmImage.unlock();
// TRADE
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 41, 163, 14, 14, -1, -1, -1, KEY_LOWERCASE_M, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, 0, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 41, 163, 14, 14, -1, -1, -1, KEY_LOWERCASE_M, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[0] != -1) {
buttonSetCallbacks(_gdialog_buttons[0], _gsound_med_butt_press, _gsound_med_butt_release);
// TALK
_gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 584, 162, 14, 14, -1, -1, -1, KEY_LOWERCASE_T, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, 0, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 584, 162, 14, 14, -1, -1, -1, KEY_LOWERCASE_T, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[1] != -1) {
buttonSetCallbacks(_gdialog_buttons[1], _gsound_med_butt_press, _gsound_med_butt_release);
@ -3293,13 +3219,11 @@ void _gdialog_barter_destroy_win()
frmId = 111;
}
CacheEntry* backgroundFrmHandle;
int fid = buildFid(OBJ_TYPE_INTERFACE, frmId, 0, 0, 0);
unsigned char* backgroundFrmData = artLockFrameData(fid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData != NULL) {
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, frmId, 0, 0, 0);
if (backgroundFrmImage.lock(backgroundFid)) {
unsigned char* windowBuffer = windowGetBuffer(gGameDialogWindow);
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmData, windowBuffer, backgroundWindowBuffer, _dialogue_subwin_len, 0);
artUnlock(backgroundFrmHandle);
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmImage.getData(), windowBuffer, backgroundWindowBuffer, _dialogue_subwin_len, 0);
}
windowDestroy(gGameDialogWindow);
@ -3344,20 +3268,19 @@ void _gdialog_barter_cleanup_tables()
// 0x448740
int partyMemberControlWindowInit()
{
CacheEntry* backgroundFrmHandle;
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 390, 0, 0, 0);
Art* backgroundFrm = artLock(backgroundFid, &backgroundFrmHandle);
if (backgroundFrm == NULL) {
if (!backgroundFrmImage.lock(backgroundFid)) {
return -1;
}
unsigned char* backgroundData = artGetFrameData(backgroundFrm, 0, 0);
unsigned char* backgroundData = backgroundFrmImage.getData();
if (backgroundData == NULL) {
partyMemberControlWindowFree();
return -1;
}
_dialogue_subwin_len = artGetHeight(backgroundFrm, 0, 0);
_dialogue_subwin_len = backgroundFrmImage.getHeight();
int controlWindowX = (screenGetWidth() - GAME_DIALOG_WINDOW_WIDTH) / 2;
int controlWindowY = (screenGetHeight() - GAME_DIALOG_WINDOW_HEIGHT) / 2 + GAME_DIALOG_WINDOW_HEIGHT - _dialogue_subwin_len;
gGameDialogWindow = windowCreate(controlWindowX,
@ -3375,10 +3298,10 @@ int partyMemberControlWindowInit()
unsigned char* src = windowGetBuffer(gGameDialogBackgroundWindow);
blitBufferToBuffer(src + (GAME_DIALOG_WINDOW_WIDTH) * (GAME_DIALOG_WINDOW_HEIGHT - _dialogue_subwin_len), GAME_DIALOG_WINDOW_WIDTH, _dialogue_subwin_len, GAME_DIALOG_WINDOW_WIDTH, windowBuffer, GAME_DIALOG_WINDOW_WIDTH);
_gdialog_scroll_subwin(gGameDialogWindow, 1, backgroundData, windowBuffer, 0, _dialogue_subwin_len, 0);
artUnlock(backgroundFrmHandle);
backgroundFrmImage.unlock();
// TALK
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 41, 14, 14, -1, -1, -1, KEY_ESCAPE, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, NULL, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 41, 14, 14, -1, -1, -1, KEY_ESCAPE, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[0] == -1) {
partyMemberControlWindowFree();
return -1;
@ -3386,7 +3309,7 @@ int partyMemberControlWindowInit()
buttonSetCallbacks(_gdialog_buttons[0], _gsound_med_butt_press, _gsound_med_butt_release);
// TRADE
_gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 593, 97, 14, 14, -1, -1, -1, KEY_LOWERCASE_D, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, NULL, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 593, 97, 14, 14, -1, -1, -1, KEY_LOWERCASE_D, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[1] == -1) {
partyMemberControlWindowFree();
return -1;
@ -3394,7 +3317,7 @@ int partyMemberControlWindowInit()
buttonSetCallbacks(_gdialog_buttons[1], _gsound_med_butt_press, _gsound_med_butt_release);
// USE BEST WEAPON
_gdialog_buttons[2] = buttonCreate(gGameDialogWindow, 236, 15, 14, 14, -1, -1, -1, KEY_LOWERCASE_W, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, NULL, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[2] = buttonCreate(gGameDialogWindow, 236, 15, 14, 14, -1, -1, -1, KEY_LOWERCASE_W, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[2] == -1) {
partyMemberControlWindowFree();
return -1;
@ -3402,7 +3325,7 @@ int partyMemberControlWindowInit()
buttonSetCallbacks(_gdialog_buttons[1], _gsound_med_butt_press, _gsound_med_butt_release);
// USE BEST ARMOR
_gdialog_buttons[3] = buttonCreate(gGameDialogWindow, 235, 46, 14, 14, -1, -1, -1, KEY_LOWERCASE_A, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, NULL, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[3] = buttonCreate(gGameDialogWindow, 235, 46, 14, 14, -1, -1, -1, KEY_LOWERCASE_A, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[3] == -1) {
partyMemberControlWindowFree();
return -1;
@ -3520,12 +3443,10 @@ void partyMemberControlWindowFree()
}
// control.frm - party member control interface
CacheEntry* backgroundFrmHandle;
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 390, 0, 0, 0);
unsigned char* backgroundFrmData = artLockFrameData(backgroundFid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData != NULL) {
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmData, windowGetBuffer(gGameDialogWindow), windowGetBuffer(gGameDialogBackgroundWindow) + (GAME_DIALOG_WINDOW_WIDTH) * (480 - _dialogue_subwin_len), _dialogue_subwin_len, 0);
artUnlock(backgroundFrmHandle);
if (backgroundFrmImage.lock(backgroundFid)) {
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmImage.getData(), windowGetBuffer(gGameDialogWindow), windowGetBuffer(gGameDialogBackgroundWindow) + (GAME_DIALOG_WINDOW_WIDTH) * (480 - _dialogue_subwin_len), _dialogue_subwin_len, 0);
}
windowDestroy(gGameDialogWindow);
@ -3541,12 +3462,11 @@ void partyMemberControlWindowUpdate()
unsigned char* windowBuffer = windowGetBuffer(gGameDialogWindow);
int windowWidth = windowGetWidth(gGameDialogWindow);
CacheEntry* backgroundHandle;
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 390, 0, 0, 0);
Art* background = artLock(backgroundFid, &backgroundHandle);
if (background != NULL) {
int width = artGetWidth(background, 0, 0);
unsigned char* buffer = artGetFrameData(background, 0, 0);
if (!backgroundFrmImage.lock(backgroundFid)) {
int width = backgroundFrmImage.getWidth();
unsigned char* buffer = backgroundFrmImage.getData();
// Clear "Weapon Used:".
blitBufferToBuffer(buffer + width * 20 + 112, 110, fontGetLineHeight(), width, windowBuffer + windowWidth * 20 + 112, windowWidth);
@ -3560,7 +3480,7 @@ void partyMemberControlWindowUpdate()
// Clear ?
blitBufferToBuffer(buffer + width * 80 + 232, 132, 106, width, windowBuffer + windowWidth * 80 + 232, windowWidth);
artUnlock(backgroundHandle);
backgroundFrmImage.unlock();
}
MessageListItem messageListItem;
@ -3776,21 +3696,20 @@ int partyMemberCustomizationWindowInit()
return -1;
}
CacheEntry* backgroundFrmHandle;
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 391, 0, 0, 0);
Art* backgroundFrm = artLock(backgroundFid, &backgroundFrmHandle);
if (backgroundFrm == NULL) {
if (!backgroundFrmImage.lock(backgroundFid)) {
return -1;
}
unsigned char* backgroundFrmData = artGetFrameData(backgroundFrm, 0, 0);
unsigned char* backgroundFrmData = backgroundFrmImage.getData();
if (backgroundFrmData == NULL) {
// FIXME: Leaking background.
partyMemberCustomizationWindowFree();
return -1;
}
_dialogue_subwin_len = artGetHeight(backgroundFrm, 0, 0);
_dialogue_subwin_len = backgroundFrmImage.getHeight();
int customizationWindowX = (screenGetWidth() - GAME_DIALOG_WINDOW_WIDTH) / 2;
int customizationWindowY = (screenGetHeight() - GAME_DIALOG_WINDOW_HEIGHT) / 2 + GAME_DIALOG_WINDOW_HEIGHT - _dialogue_subwin_len;
@ -3815,9 +3734,9 @@ int partyMemberCustomizationWindowInit()
GAME_DIALOG_WINDOW_WIDTH);
_gdialog_scroll_subwin(gGameDialogWindow, 1, backgroundFrmData, windowBuffer, NULL, _dialogue_subwin_len, 0);
artUnlock(backgroundFrmHandle);
backgroundFrmImage.unlock();
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 101, 14, 14, -1, -1, -1, 13, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, 0, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 101, 14, 14, -1, -1, -1, 13, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[0] == -1) {
partyMemberCustomizationWindowFree();
return -1;
@ -3918,13 +3837,11 @@ void partyMemberCustomizationWindowFree()
}
}
CacheEntry* backgroundFrmHandle;
FrmImage backgroundFrmImage;
// custom.frm - party member control interface
int fid = buildFid(OBJ_TYPE_INTERFACE, 391, 0, 0, 0);
unsigned char* backgroundFrmData = artLockFrameData(fid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData != NULL) {
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmData, windowGetBuffer(gGameDialogWindow), windowGetBuffer(gGameDialogBackgroundWindow) + (GAME_DIALOG_WINDOW_WIDTH) * (480 - _dialogue_subwin_len), _dialogue_subwin_len, 0);
artUnlock(backgroundFrmHandle);
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 391, 0, 0, 0);
if (backgroundFrmImage.lock(backgroundFid)) {
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmImage.getData(), windowGetBuffer(gGameDialogWindow), windowGetBuffer(gGameDialogBackgroundWindow) + (GAME_DIALOG_WINDOW_WIDTH) * (480 - _dialogue_subwin_len), _dialogue_subwin_len, 0);
}
windowDestroy(gGameDialogWindow);
@ -3969,19 +3886,18 @@ void partyMemberCustomizationWindowUpdate()
unsigned char* windowBuffer = windowGetBuffer(gGameDialogWindow);
int windowWidth = windowGetWidth(gGameDialogWindow);
CacheEntry* backgroundHandle;
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 391, 0, 0, 0);
Art* background = artLock(backgroundFid, &backgroundHandle);
if (background == NULL) {
if (!backgroundFrmImage.lock(backgroundFid)) {
return;
}
int backgroundWidth = artGetWidth(background, 0, 0);
int backgroundHeight = artGetHeight(background, 0, 0);
unsigned char* backgroundData = artGetFrameData(background, 0, 0);
int backgroundWidth = backgroundFrmImage.getWidth();
int backgroundHeight = backgroundFrmImage.getHeight();
unsigned char* backgroundData = backgroundFrmImage.getData();
blitBufferToBuffer(backgroundData, backgroundWidth, backgroundHeight, backgroundWidth, windowBuffer, GAME_DIALOG_WINDOW_WIDTH);
artUnlock(backgroundHandle);
backgroundFrmImage.unlock();
MessageListItem messageListItem;
int num;
@ -4077,42 +3993,39 @@ int _gdCustomSelect(int a1)
{
int oldFont = fontGetCurrent();
CacheEntry* backgroundFrmHandle;
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 419, 0, 0, 0);
Art* backgroundFrm = artLock(backgroundFid, &backgroundFrmHandle);
if (backgroundFrm == NULL) {
if (!backgroundFrmImage.lock(backgroundFid)) {
return -1;
}
int backgroundFrmWidth = artGetWidth(backgroundFrm, 0, 0);
int backgroundFrmHeight = artGetHeight(backgroundFrm, 0, 0);
int backgroundFrmWidth = backgroundFrmImage.getWidth();
int backgroundFrmHeight = backgroundFrmImage.getHeight();
int selectWindowX = (screenGetWidth() - backgroundFrmWidth) / 2;
int selectWindowY = (screenGetHeight() - backgroundFrmHeight) / 2;
int win = windowCreate(selectWindowX, selectWindowY, backgroundFrmWidth, backgroundFrmHeight, 256, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
if (win == -1) {
artUnlock(backgroundFrmHandle);
return -1;
}
unsigned char* windowBuffer = windowGetBuffer(win);
unsigned char* backgroundFrmData = artGetFrameData(backgroundFrm, 0, 0);
blitBufferToBuffer(backgroundFrmData,
blitBufferToBuffer(backgroundFrmImage.getData(),
backgroundFrmWidth,
backgroundFrmHeight,
backgroundFrmWidth,
windowBuffer,
backgroundFrmWidth);
artUnlock(backgroundFrmHandle);
backgroundFrmImage.unlock();
int btn1 = buttonCreate(win, 70, 164, 14, 14, -1, -1, -1, KEY_RETURN, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, NULL, BUTTON_FLAG_TRANSPARENT);
int btn1 = buttonCreate(win, 70, 164, 14, 14, -1, -1, -1, KEY_RETURN, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT);
if (btn1 == -1) {
windowDestroy(win);
return -1;
}
int btn2 = buttonCreate(win, 176, 163, 14, 14, -1, -1, -1, KEY_ESCAPE, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, NULL, BUTTON_FLAG_TRANSPARENT);
int btn2 = buttonCreate(win, 176, 163, 14, 14, -1, -1, -1, KEY_ESCAPE, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT);
if (btn2 == -1) {
windowDestroy(win);
return -1;
@ -4314,18 +4227,17 @@ int _gdialog_window_create()
_gdialog_buttons[index] = -1;
}
CacheEntry* backgroundFrmHandle;
FrmImage backgroundFrmImage;
// 389 - di_talkp.frm - dialog screen subwindow (party members)
// 99 - di_talk.frm - dialog screen subwindow (NPC's)
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, gGameDialogSpeakerIsPartyMember ? 389 : 99, 0, 0, 0);
Art* backgroundFrm = artLock(backgroundFid, &backgroundFrmHandle);
if (backgroundFrm == NULL) {
if (!backgroundFrmImage.lock(backgroundFid)) {
return -1;
}
unsigned char* backgroundFrmData = artGetFrameData(backgroundFrm, 0, 0);
unsigned char* backgroundFrmData = backgroundFrmImage.getData();
if (backgroundFrmData != NULL) {
_dialogue_subwin_len = artGetHeight(backgroundFrm, 0, 0);
_dialogue_subwin_len = backgroundFrmImage.getHeight();
int dialogSubwindowX = (screenGetWidth() - GAME_DIALOG_WINDOW_WIDTH) / 2;
int dialogSubwindowY = (screenGetHeight() - GAME_DIALOG_WINDOW_HEIGHT) / 2 + GAME_DIALOG_WINDOW_HEIGHT - _dialogue_subwin_len;
@ -4345,24 +4257,20 @@ int _gdialog_window_create()
_gdialog_scroll_subwin(gGameDialogWindow, 1, backgroundFrmData, v10, 0, _dialogue_subwin_len, 0);
}
artUnlock(backgroundFrmHandle);
// BARTER/TRADE
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 41, 14, 14, -1, -1, -1, -1, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, NULL, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[0] = buttonCreate(gGameDialogWindow, 593, 41, 14, 14, -1, -1, -1, -1, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[0] != -1) {
buttonSetMouseCallbacks(_gdialog_buttons[0], NULL, NULL, NULL, gameDialogBarterButtonUpMouseUp);
buttonSetCallbacks(_gdialog_buttons[0], _gsound_med_butt_press, _gsound_med_butt_release);
// di_rest1.frm - dialog rest button up
int upFid = buildFid(OBJ_TYPE_INTERFACE, 97, 0, 0, 0);
unsigned char* reviewButtonUpData = artLockFrameData(upFid, 0, 0, &gGameDialogReviewButtonUpFrmHandle);
if (reviewButtonUpData != NULL) {
if (_reviewButtonNormalFrmImage.lock(upFid)) {
// di_rest2.frm - dialog rest button down
int downFid = buildFid(OBJ_TYPE_INTERFACE, 98, 0, 0, 0);
unsigned char* reivewButtonDownData = artLockFrameData(downFid, 0, 0, &gGameDialogReviewButtonDownFrmHandle);
if (reivewButtonDownData != NULL) {
if (_reviewButtonPressedFrmImage.lock(downFid)) {
// REVIEW
_gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 13, 154, 51, 29, -1, -1, -1, -1, reviewButtonUpData, reivewButtonDownData, NULL, 0);
_gdialog_buttons[1] = buttonCreate(gGameDialogWindow, 13, 154, 51, 29, -1, -1, -1, -1, _reviewButtonNormalFrmImage.getData(), _reviewButtonPressedFrmImage.getData(), NULL, 0);
if (_gdialog_buttons[1] != -1) {
buttonSetMouseCallbacks(_gdialog_buttons[1], NULL, NULL, NULL, gameDialogReviewButtonOnMouseUp);
buttonSetCallbacks(_gdialog_buttons[1], _gsound_red_butt_press, _gsound_red_butt_release);
@ -4373,7 +4281,7 @@ int _gdialog_window_create()
}
// COMBAT CONTROL
_gdialog_buttons[2] = buttonCreate(gGameDialogWindow, 593, 116, 14, 14, -1, -1, -1, -1, gGameDialogRedButtonUpFrmData, gGameDialogRedButtonDownFrmData, 0, BUTTON_FLAG_TRANSPARENT);
_gdialog_buttons[2] = buttonCreate(gGameDialogWindow, 593, 116, 14, 14, -1, -1, -1, -1, _redButtonNormalFrmImage.getData(), _redButtonPressedFrmImage.getData(), 0, BUTTON_FLAG_TRANSPARENT);
if (_gdialog_buttons[2] != -1) {
buttonSetMouseCallbacks(_gdialog_buttons[2], NULL, NULL, NULL, gameDialogCombatControlButtonOnMouseUp);
buttonSetCallbacks(_gdialog_buttons[2], _gsound_med_butt_press, _gsound_med_butt_release);
@ -4386,10 +4294,10 @@ int _gdialog_window_create()
_gdialog_buttons[1] = -1;
}
artUnlock(gGameDialogReviewButtonDownFrmHandle);
_reviewButtonPressedFrmImage.unlock();
}
artUnlock(gGameDialogReviewButtonUpFrmHandle);
_reviewButtonNormalFrmImage.unlock();
}
buttonDestroy(_gdialog_buttons[0]);
@ -4401,8 +4309,6 @@ int _gdialog_window_create()
}
}
artUnlock(backgroundFrmHandle);
return -1;
}
@ -4418,8 +4324,8 @@ void _gdialog_window_destroy()
_gdialog_buttons[index] = -1;
}
artUnlock(gGameDialogReviewButtonDownFrmHandle);
artUnlock(gGameDialogReviewButtonUpFrmHandle);
_reviewButtonNormalFrmImage.unlock();
_reviewButtonPressedFrmImage.unlock();
int offset = (GAME_DIALOG_WINDOW_WIDTH) * (480 - _dialogue_subwin_len);
unsigned char* backgroundWindowBuffer = windowGetBuffer(gGameDialogBackgroundWindow) + offset;
@ -4433,13 +4339,11 @@ void _gdialog_window_destroy()
frmId = 99;
}
CacheEntry* backgroundFrmHandle;
int fid = buildFid(OBJ_TYPE_INTERFACE, frmId, 0, 0, 0);
unsigned char* backgroundFrmData = artLockFrameData(fid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData != NULL) {
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, frmId, 0, 0, 0);
if (backgroundFrmImage.lock(backgroundFid)) {
unsigned char* windowBuffer = windowGetBuffer(gGameDialogWindow);
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmData, windowBuffer, backgroundWindowBuffer, _dialogue_subwin_len, 0);
artUnlock(backgroundFrmHandle);
_gdialog_scroll_subwin(gGameDialogWindow, 0, backgroundFrmImage.getData(), windowBuffer, backgroundWindowBuffer, _dialogue_subwin_len, 0);
windowDestroy(gGameDialogWindow);
_gdialog_window_created = 0;
gGameDialogWindow = -1;
@ -4470,18 +4374,16 @@ static int talk_to_create_background_window()
// 0x44AB18
int gameDialogWindowRenderBackground()
{
CacheEntry* backgroundFrmHandle;
FrmImage backgroundFrmImage;
// alltlk.frm - dialog screen background
int fid = buildFid(OBJ_TYPE_INTERFACE, 103, 0, 0, 0);
unsigned char* backgroundFrmData = artLockFrameData(fid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData == NULL) {
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 103, 0, 0, 0);
if (!backgroundFrmImage.lock(backgroundFid)) {
return -1;
}
int windowWidth = GAME_DIALOG_WINDOW_WIDTH;
unsigned char* windowBuffer = windowGetBuffer(gGameDialogBackgroundWindow);
blitBufferToBuffer(backgroundFrmData, windowWidth, 480, windowWidth, windowBuffer, windowWidth);
artUnlock(backgroundFrmHandle);
blitBufferToBuffer(backgroundFrmImage.getData(), windowWidth, 480, windowWidth, windowBuffer, windowWidth);
if (!_dialogue_just_started) {
windowRefresh(gGameDialogBackgroundWindow);
@ -4502,25 +4404,22 @@ int _talkToRefreshDialogWindowRect(Rect* rect)
frmId = 99;
}
CacheEntry* backgroundFrmHandle;
int fid = buildFid(OBJ_TYPE_INTERFACE, frmId, 0, 0, 0);
unsigned char* backgroundFrmData = artLockFrameData(fid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData == NULL) {
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, frmId, 0, 0, 0);
if (!backgroundFrmImage.lock(backgroundFid)) {
return -1;
}
int offset = 640 * rect->top + rect->left;
unsigned char* windowBuffer = windowGetBuffer(gGameDialogWindow);
blitBufferToBuffer(backgroundFrmData + offset,
blitBufferToBuffer(backgroundFrmImage.getData() + offset,
rect->right - rect->left,
rect->bottom - rect->top,
GAME_DIALOG_WINDOW_WIDTH,
windowBuffer + offset,
GAME_DIALOG_WINDOW_WIDTH);
artUnlock(backgroundFrmHandle);
windowRefreshRect(gGameDialogWindow, rect);
return 0;
@ -4561,23 +4460,19 @@ void gameDialogRenderTalkingHead(Art* headFrm, int frame)
_totalHotx = 0;
}
FrmImage backgroundFrmImage;
int backgroundFid = buildFid(OBJ_TYPE_BACKGROUND, gGameDialogBackground, 0, 0, 0);
CacheEntry* backgroundHandle;
Art* backgroundFrm = artLock(backgroundFid, &backgroundHandle);
if (backgroundFrm == NULL) {
if (!backgroundFrmImage.lock(backgroundFid)) {
debugPrint("\tError locking background in display...\n");
}
unsigned char* backgroundFrmData = artGetFrameData(backgroundFrm, 0, 0);
unsigned char* backgroundFrmData = backgroundFrmImage.getData();
if (backgroundFrmData != NULL) {
blitBufferToBuffer(backgroundFrmData, 388, 200, 388, gGameDialogDisplayBuffer, GAME_DIALOG_WINDOW_WIDTH);
} else {
debugPrint("\tError getting background data in display...\n");
}
artUnlock(backgroundHandle);
int width = artGetWidth(headFrm, frame, 0);
int height = artGetHeight(headFrm, frame, 0);
unsigned char* data = artGetFrameData(headFrm, frame, 0);
@ -4642,11 +4537,27 @@ void gameDialogRenderTalkingHead(Art* headFrm, int frame)
unsigned char* dest = windowGetBuffer(gGameDialogBackgroundWindow);
unsigned char* data1 = artGetFrameData(gGameDialogUpperHighlightFrm, 0, 0);
gameDialogRenderHighlight(data1, gGameDialogUpperHighlightFrmWidth, gGameDialogUpperHighlightFrmHeight, gGameDialogUpperHighlightFrmWidth, dest, 426, 15, GAME_DIALOG_WINDOW_WIDTH, _light_BlendTable, _light_GrayTable);
gameDialogRenderHighlight(_upperHighlightFrmImage.getData(),
_upperHighlightFrmImage.getWidth(),
_upperHighlightFrmImage.getHeight(),
_upperHighlightFrmImage.getWidth(),
dest,
426,
15,
GAME_DIALOG_WINDOW_WIDTH,
_light_BlendTable,
_light_GrayTable);
unsigned char* data2 = artGetFrameData(gGameDialogLowerHighlightFrm, 0, 0);
gameDialogRenderHighlight(data2, gGameDialogLowerHighlightFrmWidth, gGameDialogLowerHighlightFrmHeight, gGameDialogLowerHighlightFrmWidth, dest, 129, 214 - gGameDialogLowerHighlightFrmHeight - 2, GAME_DIALOG_WINDOW_WIDTH, _dark_BlendTable, _dark_GrayTable);
gameDialogRenderHighlight(_lowerHighlightFrmImage.getData(),
_lowerHighlightFrmImage.getWidth(),
_lowerHighlightFrmImage.getHeight(),
_lowerHighlightFrmImage.getWidth(),
dest,
129,
214 - _lowerHighlightFrmImage.getHeight() - 2,
GAME_DIALOG_WINDOW_WIDTH,
_dark_BlendTable,
_dark_GrayTable);
for (int index = 0; index < 8; ++index) {
Rect* rect = &(_backgrndRects[index]);
@ -4656,7 +4567,7 @@ void gameDialogRenderTalkingHead(Art* headFrm, int frame)
width,
rect->bottom - rect->top,
width,
dest + (GAME_DIALOG_WINDOW_WIDTH) * rect->top + rect->left,
dest + GAME_DIALOG_WINDOW_WIDTH * rect->top + rect->left,
GAME_DIALOG_WINDOW_WIDTH);
}
@ -4682,15 +4593,11 @@ void gameDialogHighlightsInit()
// hilight1.frm - dialogue upper hilight
int upperHighlightFid = buildFid(OBJ_TYPE_INTERFACE, 115, 0, 0, 0);
gGameDialogUpperHighlightFrm = artLock(upperHighlightFid, &gGameDialogUpperHighlightFrmHandle);
gGameDialogUpperHighlightFrmWidth = artGetWidth(gGameDialogUpperHighlightFrm, 0, 0);
gGameDialogUpperHighlightFrmHeight = artGetHeight(gGameDialogUpperHighlightFrm, 0, 0);
_upperHighlightFrmImage.lock(upperHighlightFid);
// hilight2.frm - dialogue lower hilight
int lowerHighlightFid = buildFid(OBJ_TYPE_INTERFACE, 116, 0, 0, 0);
gGameDialogLowerHighlightFrm = artLock(lowerHighlightFid, &gGameDialogLowerHighlightFrmHandle);
gGameDialogLowerHighlightFrmWidth = artGetWidth(gGameDialogLowerHighlightFrm, 0, 0);
gGameDialogLowerHighlightFrmHeight = artGetHeight(gGameDialogLowerHighlightFrm, 0, 0);
_lowerHighlightFrmImage.lock(lowerHighlightFid);
}
// NOTE: Inlined.
@ -4701,40 +4608,29 @@ static void gameDialogHighlightsExit()
_freeColorBlendTable(_colorTable[17969]);
_freeColorBlendTable(_colorTable[22187]);
artUnlock(gGameDialogUpperHighlightFrmHandle);
artUnlock(gGameDialogLowerHighlightFrmHandle);
_upperHighlightFrmImage.unlock();
_lowerHighlightFrmImage.unlock();
}
static void gameDialogRedButtonsInit()
{
// di_rdbt2.frm - dialog red button down
int pressedFid = buildFid(OBJ_TYPE_INTERFACE, 96, 0, 0, 0);
gGameDialogRedButtonUpFrmData = artLockFrameData(pressedFid, 0, 0, &gGameDialogRedButtonUpFrmHandle);
if (gGameDialogRedButtonUpFrmData == NULL) {
if (!_redButtonPressedFrmImage.lock(pressedFid)) {
gameDialogRedButtonsExit();
}
// di_rdbt1.frm - dialog red button up
int normalFid = buildFid(OBJ_TYPE_INTERFACE, 95, 0, 0, 0);
gGameDialogRedButtonDownFrmData = artLockFrameData(normalFid, 0, 0, &gGameDialogRedButtonDownFrmHandle);
if (gGameDialogRedButtonDownFrmData == NULL) {
if (!_redButtonNormalFrmImage.lock(normalFid)) {
gameDialogRedButtonsExit();
}
}
static void gameDialogRedButtonsExit()
{
if (gGameDialogRedButtonDownFrmHandle != NULL) {
artUnlock(gGameDialogRedButtonDownFrmHandle);
gGameDialogRedButtonDownFrmHandle = NULL;
gGameDialogRedButtonDownFrmData = NULL;
}
if (gGameDialogRedButtonUpFrmHandle != NULL) {
artUnlock(gGameDialogRedButtonUpFrmHandle);
gGameDialogRedButtonUpFrmHandle = NULL;
gGameDialogRedButtonUpFrmData = NULL;
}
_redButtonNormalFrmImage.unlock();
_redButtonPressedFrmImage.unlock();
}
} // namespace fallout