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