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