diff --git a/src/skilldex.cc b/src/skilldex.cc index 0e30069..00ffeb6 100644 --- a/src/skilldex.cc +++ b/src/skilldex.cc @@ -82,9 +82,6 @@ static const int gSkilldexSkills[SKILLDEX_SKILL_COUNT] = { SKILL_REPAIR, }; -// 0x668088 -static Size gSkilldexFrmSizes[SKILLDEX_FRM_COUNT]; - // 0x6680B8 static unsigned char* gSkilldexButtonsData[SKILLDEX_SKILL_BUTTON_BUFFER_COUNT]; @@ -95,12 +92,6 @@ static MessageList gSkilldexMessageList; // 0x668100 static MessageListItem gSkilldexMessageListItem; -// 0x668110 -static unsigned char* gSkilldexFrmData[SKILLDEX_FRM_COUNT]; - -// 0x668128 -static CacheEntry* gSkilldexFrmHandles[SKILLDEX_FRM_COUNT]; - // 0x668140 static int gSkilldexWindow; @@ -110,6 +101,8 @@ static unsigned char* gSkilldexWindowBuffer; // 0x668148 static int gSkilldexWindowOldFont; +static FrmImage _skilldexFrmImages[SKILLDEX_FRM_COUNT]; + // skilldex_select // 0x4ABFD0 int skilldexOpen() @@ -166,15 +159,14 @@ static int skilldexWindowInit() int frmIndex; for (frmIndex = 0; frmIndex < SKILLDEX_FRM_COUNT; frmIndex++) { int fid = buildFid(OBJ_TYPE_INTERFACE, gSkilldexFrmIds[frmIndex], 0, 0, 0); - gSkilldexFrmData[frmIndex] = artLockFrameDataReturningSize(fid, &(gSkilldexFrmHandles[frmIndex]), &(gSkilldexFrmSizes[frmIndex].width), &(gSkilldexFrmSizes[frmIndex].height)); - if (gSkilldexFrmData[frmIndex] == NULL) { + if (!_skilldexFrmImages[frmIndex].lock(fid)) { break; } } if (frmIndex < SKILLDEX_FRM_COUNT) { while (--frmIndex >= 0) { - artUnlock(gSkilldexFrmHandles[frmIndex]); + _skilldexFrmImages[frmIndex].unlock(); } messageListFree(&gSkilldexMessageList); @@ -185,7 +177,7 @@ static int skilldexWindowInit() bool cycle = false; int buttonDataIndex; for (buttonDataIndex = 0; buttonDataIndex < SKILLDEX_SKILL_BUTTON_BUFFER_COUNT; buttonDataIndex++) { - gSkilldexButtonsData[buttonDataIndex] = (unsigned char*)internal_malloc(gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_ON].height * gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_ON].width + 512); + gSkilldexButtonsData[buttonDataIndex] = (unsigned char*)internal_malloc(_skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getHeight() * _skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getWidth() + 512); if (gSkilldexButtonsData[buttonDataIndex] == NULL) { break; } @@ -196,11 +188,11 @@ static int skilldexWindowInit() unsigned char* data; int size; if (cycle) { - size = gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].width * gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].height; - data = gSkilldexFrmData[SKILLDEX_FRM_BUTTON_OFF]; + size = _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getWidth() * _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getHeight(); + data = _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getData(); } else { - size = gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_ON].width * gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_ON].height; - data = gSkilldexFrmData[SKILLDEX_FRM_BUTTON_ON]; + size = _skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getWidth() * _skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getHeight(); + data = _skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getData(); } memcpy(gSkilldexButtonsData[buttonDataIndex], data, size); @@ -212,7 +204,7 @@ static int skilldexWindowInit() } for (int index = 0; index < SKILLDEX_FRM_COUNT; index++) { - artUnlock(gSkilldexFrmHandles[index]); + _skilldexFrmImages[index].unlock(); } messageListFree(&gSkilldexMessageList); @@ -221,12 +213,12 @@ static int skilldexWindowInit() } // Maintain original position relative to centered interface bar. - int skilldexWindowX = (screenGetWidth() - 640) / 2 + 640 - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width - SKILLDEX_WINDOW_RIGHT_MARGIN; - int skilldexWindowY = screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].height - SKILLDEX_WINDOW_BOTTOM_MARGIN; + int skilldexWindowX = (screenGetWidth() - 640) / 2 + 640 - _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() - SKILLDEX_WINDOW_RIGHT_MARGIN; + int skilldexWindowY = screenGetHeight() - INTERFACE_BAR_HEIGHT - 1 - _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getHeight() - SKILLDEX_WINDOW_BOTTOM_MARGIN; gSkilldexWindow = windowCreate(skilldexWindowX, skilldexWindowY, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].height, + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth(), + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getHeight(), 256, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02); if (gSkilldexWindow == -1) { @@ -235,7 +227,7 @@ static int skilldexWindowInit() } for (int index = 0; index < SKILLDEX_FRM_COUNT; index++) { - artUnlock(gSkilldexFrmHandles[index]); + _skilldexFrmImages[index].unlock(); } messageListFree(&gSkilldexMessageList); @@ -250,17 +242,17 @@ static int skilldexWindowInit() gSkilldexWindowBuffer = windowGetBuffer(gSkilldexWindow); memcpy(gSkilldexWindowBuffer, - gSkilldexFrmData[SKILLDEX_FRM_BACKGROUND], - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width * gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].height); + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getData(), + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() * _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getHeight()); fontSetCurrent(103); // Render "SKILLDEX" title. char* title = getmsg(&gSkilldexMessageList, &gSkilldexMessageListItem, 100); - fontDrawText(gSkilldexWindowBuffer + 14 * gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width + 55, + fontDrawText(gSkilldexWindowBuffer + 14 * _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() + 55, title, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width, + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth(), + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth(), _colorTable[18979]); // Render skill values. @@ -277,10 +269,10 @@ static int skilldexWindowInit() // because -5 is also a legitimate skill value. // // TODO: Provide other error code in `skillGetValue`. - unsigned char* numbersFrmData = gSkilldexFrmData[SKILLDEX_FRM_BIG_NUMBERS]; + unsigned char* numbersFrmData = _skilldexFrmImages[SKILLDEX_FRM_BIG_NUMBERS].getData(); if (value < 0) { // First half of the bignum.frm is white, second half is red. - numbersFrmData += gSkilldexFrmSizes[SKILLDEX_FRM_BIG_NUMBERS].width / 2; + numbersFrmData += _skilldexFrmImages[SKILLDEX_FRM_BIG_NUMBERS].getWidth() / 2; value = -value; } @@ -289,24 +281,24 @@ static int skilldexWindowInit() 14, 24, 336, - gSkilldexWindowBuffer + gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width * valueY + 110, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width); + gSkilldexWindowBuffer + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() * valueY + 110, + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth()); int tens = (value % 100) / 10; blitBufferToBuffer(numbersFrmData + 14 * tens, 14, 24, 336, - gSkilldexWindowBuffer + gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width * valueY + 124, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width); + gSkilldexWindowBuffer + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() * valueY + 124, + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth()); int ones = (value % 100) % 10; blitBufferToBuffer(numbersFrmData + 14 * ones, 14, 24, 336, - gSkilldexWindowBuffer + gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width * valueY + 138, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width); + gSkilldexWindowBuffer + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() * valueY + 138, + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth()); valueY += 36; } @@ -315,33 +307,33 @@ static int skilldexWindowInit() int lineHeight = fontGetLineHeight(); int buttonY = 45; - int nameY = ((gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].height - lineHeight) / 2) + 1; + int nameY = ((_skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getHeight() - lineHeight) / 2) + 1; for (int index = 0; index < SKILLDEX_SKILL_COUNT; index++) { char name[MESSAGE_LIST_ITEM_FIELD_MAX_SIZE]; strcpy(name, getmsg(&gSkilldexMessageList, &gSkilldexMessageListItem, 102 + index)); - int nameX = ((gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].width - fontGetStringWidth(name)) / 2) + 1; + int nameX = ((_skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getWidth() - fontGetStringWidth(name)) / 2) + 1; if (nameX < 0) { nameX = 0; } - fontDrawText(gSkilldexButtonsData[index * 2] + gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_ON].width * nameY + nameX, + fontDrawText(gSkilldexButtonsData[index * 2] + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getWidth() * nameY + nameX, name, - gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_ON].width, - gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_ON].width, + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getWidth(), + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_ON].getWidth(), _colorTable[18979]); - fontDrawText(gSkilldexButtonsData[index * 2 + 1] + gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].width * nameY + nameX, + fontDrawText(gSkilldexButtonsData[index * 2 + 1] + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getWidth() * nameY + nameX, name, - gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].width, - gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].width, + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getWidth(), + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getWidth(), _colorTable[14723]); int btn = buttonCreate(gSkilldexWindow, 15, buttonY, - gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].width, - gSkilldexFrmSizes[SKILLDEX_FRM_BUTTON_OFF].height, + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getWidth(), + _skilldexFrmImages[SKILLDEX_FRM_BUTTON_OFF].getHeight(), -1, -1, -1, @@ -359,23 +351,23 @@ static int skilldexWindowInit() // Render "CANCEL" button. char* cancel = getmsg(&gSkilldexMessageList, &gSkilldexMessageListItem, 101); - fontDrawText(gSkilldexWindowBuffer + gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width * 337 + 72, + fontDrawText(gSkilldexWindowBuffer + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() * 337 + 72, cancel, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width, - gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width, + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth(), + _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth(), _colorTable[18979]); int cancelBtn = buttonCreate(gSkilldexWindow, 48, 338, - gSkilldexFrmSizes[SKILLDEX_FRM_LITTLE_RED_BUTTON_UP].width, - gSkilldexFrmSizes[SKILLDEX_FRM_LITTLE_RED_BUTTON_UP].height, + _skilldexFrmImages[SKILLDEX_FRM_LITTLE_RED_BUTTON_UP].getWidth(), + _skilldexFrmImages[SKILLDEX_FRM_LITTLE_RED_BUTTON_UP].getHeight(), -1, -1, -1, 500, - gSkilldexFrmData[SKILLDEX_FRM_LITTLE_RED_BUTTON_UP], - gSkilldexFrmData[SKILLDEX_FRM_LITTLE_RED_BUTTON_DOWN], + _skilldexFrmImages[SKILLDEX_FRM_LITTLE_RED_BUTTON_UP].getData(), + _skilldexFrmImages[SKILLDEX_FRM_LITTLE_RED_BUTTON_DOWN].getData(), NULL, BUTTON_FLAG_TRANSPARENT); if (cancelBtn != -1) { @@ -397,7 +389,7 @@ static void skilldexWindowFree() } for (int index = 0; index < SKILLDEX_FRM_COUNT; index++) { - artUnlock(gSkilldexFrmHandles[index]); + _skilldexFrmImages[index].unlock(); } messageListFree(&gSkilldexMessageList);