Refactor artLockFrameData with FrmImage

This commit is contained in:
Alexander Batalov 2022-09-26 11:55:06 +03:00
parent 2e5be31ed4
commit 4aae167bd8
1 changed files with 96 additions and 122 deletions

View File

@ -293,27 +293,15 @@ static PreferenceDescription gPreferenceDescriptions[PREF_COUNT] = {
{ 2, 0, 374, 451, 0, 0, { 207, 218, 0, 0 }, 0, GAME_CONFIG_MOUSE_SENSITIVITY_KEY, 1.0, 2.5, NULL }, { 2, 0, 374, 451, 0, 0, { 207, 218, 0, 0 }, 0, GAME_CONFIG_MOUSE_SENSITIVITY_KEY, 1.0, 2.5, NULL },
}; };
// 0x6637D0
static Size gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_COUNT];
// 0x6637E8 // 0x6637E8
static MessageList gOptionsMessageList; static MessageList gOptionsMessageList;
// 0x6637F0
static Size gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_COUNT];
// 0x663840 // 0x663840
static MessageListItem gOptionsMessageListItem; static MessageListItem gOptionsMessageListItem;
// 0x663850
static unsigned char* gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_COUNT];
// 0x663878 // 0x663878
static unsigned char* _opbtns[OPTIONS_WINDOW_BUTTONS_COUNT]; static unsigned char* _opbtns[OPTIONS_WINDOW_BUTTONS_COUNT];
// 0x6638A0
static CacheEntry* gPreferencesWindowFrmHandles[PREFERENCES_WINDOW_FRM_COUNT];
// 0x6638C8 // 0x6638C8
static double gPreferencesTextBaseDelay2; static double gPreferencesTextBaseDelay2;
@ -347,12 +335,6 @@ static int gPreferencesWindow;
// 0x663908 // 0x663908
static unsigned char* gOptionsWindowBuffer; static unsigned char* gOptionsWindowBuffer;
// 0x66390C
static CacheEntry* gOptionsWindowFrmHandles[OPTIONS_WINDOW_FRM_COUNT];
// 0x663918
static unsigned char* gOptionsWindowFrmData[OPTIONS_WINDOW_FRM_COUNT];
// 0x663924 // 0x663924
static int gPreferencesGameDifficulty2; static int gPreferencesGameDifficulty2;
@ -467,6 +449,9 @@ int gPreferencesGameDifficulty1;
// 0x6639C0 // 0x6639C0
int gPreferencesCombatLooks1; int gPreferencesCombatLooks1;
static FrmImage _optionsFrmImages[OPTIONS_WINDOW_FRM_COUNT];
static FrmImage _preferencesFrmImages[PREFERENCES_WINDOW_FRM_COUNT];
// 0x48FC48 // 0x48FC48
int showOptions() int showOptions()
{ {
@ -577,11 +562,9 @@ static int optionsWindowInit()
for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) { for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) {
int fid = buildFid(OBJ_TYPE_INTERFACE, gOptionsWindowFrmIds[index], 0, 0, 0); int fid = buildFid(OBJ_TYPE_INTERFACE, gOptionsWindowFrmIds[index], 0, 0, 0);
gOptionsWindowFrmData[index] = artLockFrameDataReturningSize(fid, &(gOptionsWindowFrmHandles[index]), &(gOptionsWindowFrmSizes[index].width), &(gOptionsWindowFrmSizes[index].height)); if (!_optionsFrmImages[index].lock(fid)) {
if (gOptionsWindowFrmData[index] == NULL) {
while (--index >= 0) { while (--index >= 0) {
artUnlock(gOptionsWindowFrmHandles[index]); _optionsFrmImages[index].unlock();
} }
messageListFree(&gOptionsMessageList); messageListFree(&gOptionsMessageList);
@ -592,14 +575,14 @@ static int optionsWindowInit()
int cycle = 0; int cycle = 0;
for (int index = 0; index < OPTIONS_WINDOW_BUTTONS_COUNT; index++) { for (int index = 0; index < OPTIONS_WINDOW_BUTTONS_COUNT; index++) {
_opbtns[index] = (unsigned char*)internal_malloc(gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width * gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].height + 1024); _opbtns[index] = (unsigned char*)internal_malloc(_optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth() * _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getHeight() + 1024);
if (_opbtns[index] == NULL) { if (_opbtns[index] == NULL) {
while (--index >= 0) { while (--index >= 0) {
internal_free(_opbtns[index]); internal_free(_opbtns[index]);
} }
for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) { for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) {
artUnlock(gOptionsWindowFrmHandles[index]); _optionsFrmImages[index].unlock();
} }
messageListFree(&gOptionsMessageList); messageListFree(&gOptionsMessageList);
@ -609,15 +592,15 @@ static int optionsWindowInit()
cycle = cycle ^ 1; cycle = cycle ^ 1;
memcpy(_opbtns[index], gOptionsWindowFrmData[cycle + 1], gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width * gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].height); memcpy(_opbtns[index], _optionsFrmImages[cycle + 1].getData(), _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth() * _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getHeight());
} }
int optionsWindowX = (screenGetWidth() - gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BACKGROUND].width) / 2; int optionsWindowX = (screenGetWidth() - _optionsFrmImages[OPTIONS_WINDOW_FRM_BACKGROUND].getWidth()) / 2;
int optionsWindowY = (screenGetHeight() - gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BACKGROUND].height) / 2 - 60; int optionsWindowY = (screenGetHeight() - _optionsFrmImages[OPTIONS_WINDOW_FRM_BACKGROUND].getHeight()) / 2 - 60;
gOptionsWindow = windowCreate(optionsWindowX, gOptionsWindow = windowCreate(optionsWindowX,
optionsWindowY, optionsWindowY,
gOptionsWindowFrmSizes[0].width, _optionsFrmImages[0].getWidth(),
gOptionsWindowFrmSizes[0].height, _optionsFrmImages[0].getHeight(),
256, 256,
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02); WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02);
@ -627,7 +610,7 @@ static int optionsWindowInit()
} }
for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) { for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) {
artUnlock(gOptionsWindowFrmHandles[index]); _optionsFrmImages[index].unlock();
} }
messageListFree(&gOptionsMessageList); messageListFree(&gOptionsMessageList);
@ -645,11 +628,11 @@ static int optionsWindowInit()
gameMouseSetCursor(MOUSE_CURSOR_ARROW); gameMouseSetCursor(MOUSE_CURSOR_ARROW);
gOptionsWindowBuffer = windowGetBuffer(gOptionsWindow); gOptionsWindowBuffer = windowGetBuffer(gOptionsWindow);
memcpy(gOptionsWindowBuffer, gOptionsWindowFrmData[OPTIONS_WINDOW_FRM_BACKGROUND], gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BACKGROUND].width * gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BACKGROUND].height); memcpy(gOptionsWindowBuffer, _optionsFrmImages[OPTIONS_WINDOW_FRM_BACKGROUND].getData(), _optionsFrmImages[OPTIONS_WINDOW_FRM_BACKGROUND].getWidth() * _optionsFrmImages[OPTIONS_WINDOW_FRM_BACKGROUND].getHeight());
fontSetCurrent(103); fontSetCurrent(103);
int textY = (gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].height - fontGetLineHeight()) / 2 + 1; int textY = (_optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getHeight() - fontGetLineHeight()) / 2 + 1;
int buttonY = 17; int buttonY = 17;
for (int index = 0; index < OPTIONS_WINDOW_BUTTONS_COUNT; index += 2) { for (int index = 0; index < OPTIONS_WINDOW_BUTTONS_COUNT; index += 2) {
@ -658,20 +641,32 @@ static int optionsWindowInit()
const char* msg = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, index / 2); const char* msg = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, index / 2);
strcpy(text, msg); strcpy(text, msg);
int textX = (gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width - fontGetStringWidth(text)) / 2; int textX = (_optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth() - fontGetStringWidth(text)) / 2;
if (textX < 0) { if (textX < 0) {
textX = 0; textX = 0;
} }
fontDrawText(_opbtns[index] + gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width * textY + textX, text, gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width, gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width, _colorTable[18979]); fontDrawText(_opbtns[index] + _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth() * textY + textX, text, _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth(), _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth(), _colorTable[18979]);
fontDrawText(_opbtns[index + 1] + gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width * textY + textX, text, gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width, gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width, _colorTable[14723]); fontDrawText(_opbtns[index + 1] + _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth() * textY + textX, text, _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth(), _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth(), _colorTable[14723]);
int btn = buttonCreate(gOptionsWindow, 13, buttonY, gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].width, gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].height, -1, -1, -1, index / 2 + 500, _opbtns[index], _opbtns[index + 1], NULL, 32); int btn = buttonCreate(gOptionsWindow,
13,
buttonY,
_optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getWidth(),
_optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getHeight(),
-1,
-1,
-1,
index / 2 + 500,
_opbtns[index],
_opbtns[index + 1],
NULL,
BUTTON_FLAG_TRANSPARENT);
if (btn != -1) { if (btn != -1) {
buttonSetCallbacks(btn, _gsound_lrg_butt_press, _gsound_lrg_butt_release); buttonSetCallbacks(btn, _gsound_lrg_butt_press, _gsound_lrg_butt_release);
} }
buttonY += gOptionsWindowFrmSizes[OPTIONS_WINDOW_FRM_BUTTON_ON].height + 3; buttonY += _optionsFrmImages[OPTIONS_WINDOW_FRM_BUTTON_ON].getHeight() + 3;
} }
fontSetCurrent(101); fontSetCurrent(101);
@ -693,7 +688,7 @@ static int optionsWindowFree()
} }
for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) { for (int index = 0; index < OPTIONS_WINDOW_FRM_COUNT; index++) {
artUnlock(gOptionsWindowFrmHandles[index]); _optionsFrmImages[index].unlock();
} }
if (gOptionsWindowGameMouseObjectsWasVisible) { if (gOptionsWindowGameMouseObjectsWasVisible) {
@ -710,13 +705,6 @@ static int optionsWindowFree()
// 0x4902B0 // 0x4902B0
int showPause(bool a1) int showPause(bool a1)
{ {
int graphicIds[PAUSE_WINDOW_FRM_COUNT];
unsigned char* frmData[PAUSE_WINDOW_FRM_COUNT];
CacheEntry* frmHandles[PAUSE_WINDOW_FRM_COUNT];
Size frmSizes[PAUSE_WINDOW_FRM_COUNT];
memcpy(graphicIds, gPauseWindowFrmIds, sizeof(gPauseWindowFrmIds));
bool gameMouseWasVisible; bool gameMouseWasVisible;
if (!a1) { if (!a1) {
gOptionsWindowIsoWasEnabled = isoDisable(); gOptionsWindowIsoWasEnabled = isoDisable();
@ -731,14 +719,10 @@ int showPause(bool a1)
gameMouseSetCursor(MOUSE_CURSOR_ARROW); gameMouseSetCursor(MOUSE_CURSOR_ARROW);
_ShadeScreen(a1); _ShadeScreen(a1);
FrmImage frmImages[PAUSE_WINDOW_FRM_COUNT];
for (int index = 0; index < PAUSE_WINDOW_FRM_COUNT; index++) { for (int index = 0; index < PAUSE_WINDOW_FRM_COUNT; index++) {
int fid = buildFid(OBJ_TYPE_INTERFACE, graphicIds[index], 0, 0, 0); int fid = buildFid(OBJ_TYPE_INTERFACE, gPauseWindowFrmIds[index], 0, 0, 0);
frmData[index] = artLockFrameDataReturningSize(fid, &(frmHandles[index]), &(frmSizes[index].width), &(frmSizes[index].height)); if (!frmImages[index].lock(fid)) {
if (frmData[index] == NULL) {
while (--index >= 0) {
artUnlock(frmHandles[index]);
}
debugPrint("\n** Error loading pause window graphics! **\n"); debugPrint("\n** Error loading pause window graphics! **\n");
return -1; return -1;
} }
@ -756,8 +740,8 @@ int showPause(bool a1)
return -1; return -1;
} }
int pauseWindowX = (screenGetWidth() - frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width) / 2; int pauseWindowX = (screenGetWidth() - frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth()) / 2;
int pauseWindowY = (screenGetHeight() - frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].height) / 2; int pauseWindowY = (screenGetHeight() - frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getHeight()) / 2;
if (a1) { if (a1) {
pauseWindowX -= 65; pauseWindowX -= 65;
@ -768,15 +752,11 @@ int showPause(bool a1)
int window = windowCreate(pauseWindowX, int window = windowCreate(pauseWindowX,
pauseWindowY, pauseWindowY,
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width, frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth(),
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].height, frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getHeight(),
256, 256,
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02); WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02);
if (window == -1) { if (window == -1) {
for (int index = 0; index < PAUSE_WINDOW_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
messageListFree(&gOptionsMessageList); messageListFree(&gOptionsMessageList);
debugPrint("\n** Error opening pause window! **\n"); debugPrint("\n** Error opening pause window! **\n");
@ -785,15 +765,15 @@ int showPause(bool a1)
unsigned char* windowBuffer = windowGetBuffer(window); unsigned char* windowBuffer = windowGetBuffer(window);
memcpy(windowBuffer, memcpy(windowBuffer,
frmData[PAUSE_WINDOW_FRM_BACKGROUND], frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getData(),
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width * frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].height); frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth() * frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getHeight());
blitBufferToBufferTrans(frmData[PAUSE_WINDOW_FRM_DONE_BOX], blitBufferToBufferTrans(frmImages[PAUSE_WINDOW_FRM_DONE_BOX].getData(),
frmSizes[PAUSE_WINDOW_FRM_DONE_BOX].width, frmImages[PAUSE_WINDOW_FRM_DONE_BOX].getWidth(),
frmSizes[PAUSE_WINDOW_FRM_DONE_BOX].height, frmImages[PAUSE_WINDOW_FRM_DONE_BOX].getHeight(),
frmSizes[PAUSE_WINDOW_FRM_DONE_BOX].width, frmImages[PAUSE_WINDOW_FRM_DONE_BOX].getWidth(),
windowBuffer + frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width * 42 + 13, windowBuffer + frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth() * 42 + 13,
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width); frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth());
gOptionsWindowOldFont = fontGetCurrent(); gOptionsWindowOldFont = fontGetCurrent();
fontSetCurrent(103); fontSetCurrent(103);
@ -801,10 +781,10 @@ int showPause(bool a1)
char* messageItemText; char* messageItemText;
messageItemText = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, 300); messageItemText = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, 300);
fontDrawText(windowBuffer + frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width * 45 + 52, fontDrawText(windowBuffer + frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth() * 45 + 52,
messageItemText, messageItemText,
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width, frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth(),
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width, frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth(),
_colorTable[18979]); _colorTable[18979]);
fontSetCurrent(104); fontSetCurrent(104);
@ -813,23 +793,23 @@ int showPause(bool a1)
strcpy(path, messageItemText); strcpy(path, messageItemText);
int length = fontGetStringWidth(path); int length = fontGetStringWidth(path);
fontDrawText(windowBuffer + frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width * 10 + 2 + (frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width - length) / 2, fontDrawText(windowBuffer + frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth() * 10 + 2 + (frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth() - length) / 2,
path, path,
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width, frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth(),
frmSizes[PAUSE_WINDOW_FRM_BACKGROUND].width, frmImages[PAUSE_WINDOW_FRM_BACKGROUND].getWidth(),
_colorTable[18979]); _colorTable[18979]);
int doneBtn = buttonCreate(window, int doneBtn = buttonCreate(window,
26, 26,
46, 46,
frmSizes[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_UP].width, frmImages[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getWidth(),
frmSizes[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_UP].height, frmImages[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getHeight(),
-1, -1,
-1, -1,
-1, -1,
504, 504,
frmData[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_UP], frmImages[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getData(),
frmData[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN], frmImages[PAUSE_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (doneBtn != -1) { if (doneBtn != -1) {
@ -866,11 +846,6 @@ int showPause(bool a1)
} }
windowDestroy(window); windowDestroy(window);
for (int index = 0; index < PAUSE_WINDOW_FRM_COUNT; index++) {
artUnlock(frmHandles[index]);
}
messageListFree(&gOptionsMessageList); messageListFree(&gOptionsMessageList);
if (!a1) { if (!a1) {
@ -1100,7 +1075,7 @@ static void _UpdateThing(int index)
int offsets[PRIMARY_PREF_COUNT]; int offsets[PRIMARY_PREF_COUNT];
memcpy(offsets, dword_48FC1C, sizeof(dword_48FC1C)); memcpy(offsets, dword_48FC1C, sizeof(dword_48FC1C));
blitBufferToBuffer(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_BACKGROUND] + 640 * offsets[primaryOptionIndex] + 23, 160, 54, 640, gPreferencesWindowBuffer + 640 * offsets[primaryOptionIndex] + 23, 640); blitBufferToBuffer(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getData() + 640 * offsets[primaryOptionIndex] + 23, 160, 54, 640, gPreferencesWindowBuffer + 640 * offsets[primaryOptionIndex] + 23, 640);
for (int valueIndex = 0; valueIndex < meta->valuesCount; valueIndex++) { for (int valueIndex = 0; valueIndex < meta->valuesCount; valueIndex++) {
const char* text = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, meta->labelIds[valueIndex]); const char* text = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, meta->labelIds[valueIndex]);
@ -1145,14 +1120,14 @@ static void _UpdateThing(int index)
} }
int value = *(meta->valuePtr); int value = *(meta->valuePtr);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_PRIMARY_SWITCH] + (46 * 47) * value, 46, 47, 46, gPreferencesWindowBuffer + 640 * meta->knobY + meta->knobX, 640); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_PRIMARY_SWITCH].getData() + (46 * 47) * value, 46, 47, 46, gPreferencesWindowBuffer + 640 * meta->knobY + meta->knobX, 640);
} else if (index >= FIRST_SECONDARY_PREF && index <= LAST_SECONDARY_PREF) { } else if (index >= FIRST_SECONDARY_PREF && index <= LAST_SECONDARY_PREF) {
int secondaryOptionIndex = index - FIRST_SECONDARY_PREF; int secondaryOptionIndex = index - FIRST_SECONDARY_PREF;
int offsets[SECONDARY_PREF_COUNT]; int offsets[SECONDARY_PREF_COUNT];
memcpy(offsets, dword_48FC30, sizeof(dword_48FC30)); memcpy(offsets, dword_48FC30, sizeof(dword_48FC30));
blitBufferToBuffer(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_BACKGROUND] + 640 * offsets[secondaryOptionIndex] + 251, 113, 34, 640, gPreferencesWindowBuffer + 640 * offsets[secondaryOptionIndex] + 251, 640); blitBufferToBuffer(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getData() + 640 * offsets[secondaryOptionIndex] + 251, 113, 34, 640, gPreferencesWindowBuffer + 640 * offsets[secondaryOptionIndex] + 251, 640);
// Secondary options are booleans, so it's index is also it's value. // Secondary options are booleans, so it's index is also it's value.
for (int value = 0; value < 2; value++) { for (int value = 0; value < 2; value++) {
@ -1173,9 +1148,9 @@ static void _UpdateThing(int index)
if (index == PREF_COMBAT_MESSAGES) { if (index == PREF_COMBAT_MESSAGES) {
value ^= 1; value ^= 1;
} }
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_SECONDARY_SWITCH] + (22 * 25) * value, 22, 25, 22, gPreferencesWindowBuffer + 640 * meta->knobY + meta->knobX, 640); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_SECONDARY_SWITCH].getData() + (22 * 25) * value, 22, 25, 22, gPreferencesWindowBuffer + 640 * meta->knobY + meta->knobX, 640);
} else if (index >= FIRST_RANGE_PREF && index <= LAST_RANGE_PREF) { } else if (index >= FIRST_RANGE_PREF && index <= LAST_RANGE_PREF) {
blitBufferToBuffer(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_BACKGROUND] + 640 * (meta->knobY - 12) + 384, 240, 24, 640, gPreferencesWindowBuffer + 640 * (meta->knobY - 12) + 384, 640); blitBufferToBuffer(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getData() + 640 * (meta->knobY - 12) + 384, 240, 24, 640, gPreferencesWindowBuffer + 640 * (meta->knobY - 12) + 384, 640);
switch (index) { switch (index) {
case PREF_COMBAT_SPEED: case PREF_COMBAT_SPEED:
if (1) { if (1) {
@ -1183,7 +1158,7 @@ static void _UpdateThing(int index)
value = std::clamp(value, 0.0, 50.0); value = std::clamp(value, 0.0, 50.0);
int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0); int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_OFF].getData(), 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
} }
break; break;
case PREF_TEXT_BASE_DELAY: case PREF_TEXT_BASE_DELAY:
@ -1191,7 +1166,7 @@ static void _UpdateThing(int index)
gPreferencesTextBaseDelay1 = std::clamp(gPreferencesTextBaseDelay1, 1.0, 6.0); gPreferencesTextBaseDelay1 = std::clamp(gPreferencesTextBaseDelay1, 1.0, 6.0);
int x = (int)((6.0 - gPreferencesTextBaseDelay1) * 43.8 + 384.0); int x = (int)((6.0 - gPreferencesTextBaseDelay1) * 43.8 + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_OFF].getData(), 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
double value = (gPreferencesTextBaseDelay1 - 1.0) * 0.2 * 2.0; double value = (gPreferencesTextBaseDelay1 - 1.0) * 0.2 * 2.0;
value = std::clamp(value, 0.0, 2.0); value = std::clamp(value, 0.0, 2.0);
@ -1209,7 +1184,7 @@ static void _UpdateThing(int index)
value = std::clamp(value, meta->minValue, meta->maxValue); value = std::clamp(value, meta->minValue, meta->maxValue);
int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0); int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_OFF].getData(), 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
switch (index) { switch (index) {
case PREF_MASTER_VOLUME: case PREF_MASTER_VOLUME:
@ -1232,7 +1207,7 @@ static void _UpdateThing(int index)
gPreferencesBrightness1 = std::clamp(gPreferencesBrightness1, 1.0, 1.17999267578125); gPreferencesBrightness1 = std::clamp(gPreferencesBrightness1, 1.0, 1.17999267578125);
int x = (int)((gPreferencesBrightness1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0); int x = (int)((gPreferencesBrightness1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_OFF].getData(), 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
colorSetBrightness(gPreferencesBrightness1); colorSetBrightness(gPreferencesBrightness1);
} }
@ -1242,7 +1217,7 @@ static void _UpdateThing(int index)
gPreferencesMouseSensitivity1 = std::clamp(gPreferencesMouseSensitivity1, 1.0, 2.5); gPreferencesMouseSensitivity1 = std::clamp(gPreferencesMouseSensitivity1, 1.0, 2.5);
int x = (int)((gPreferencesMouseSensitivity1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0); int x = (int)((gPreferencesMouseSensitivity1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_OFF].getData(), 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
mouseSetSensitivity(gPreferencesMouseSensitivity1); mouseSetSensitivity(gPreferencesMouseSensitivity1);
} }
@ -1501,10 +1476,9 @@ static int preferencesWindowInit()
for (i = 0; i < PREFERENCES_WINDOW_FRM_COUNT; i++) { for (i = 0; i < PREFERENCES_WINDOW_FRM_COUNT; i++) {
fid = buildFid(OBJ_TYPE_INTERFACE, gPreferencesWindowFrmIds[i], 0, 0, 0); fid = buildFid(OBJ_TYPE_INTERFACE, gPreferencesWindowFrmIds[i], 0, 0, 0);
gPreferencesWindowFrmData[i] = artLockFrameDataReturningSize(fid, &(gPreferencesWindowFrmHandles[i]), &(gPreferencesWindowFrmSizes[i].width), &(gPreferencesWindowFrmSizes[i].height)); if (!_preferencesFrmImages[i].lock(fid)) {
if (gPreferencesWindowFrmData[i] == NULL) { while (--i >= 0) {
for (; i != 0; i--) { _preferencesFrmImages[i].unlock();
artUnlock(gPreferencesWindowFrmHandles[i - 1]);
} }
return -1; return -1;
} }
@ -1522,15 +1496,15 @@ static int preferencesWindowInit()
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02); WINDOW_FLAG_0x10 | WINDOW_FLAG_0x02);
if (gPreferencesWindow == -1) { if (gPreferencesWindow == -1) {
for (i = 0; i < PREFERENCES_WINDOW_FRM_COUNT; i++) { for (i = 0; i < PREFERENCES_WINDOW_FRM_COUNT; i++) {
artUnlock(gPreferencesWindowFrmHandles[i]); _preferencesFrmImages[i].unlock();
} }
return -1; return -1;
} }
gPreferencesWindowBuffer = windowGetBuffer(gPreferencesWindow); gPreferencesWindowBuffer = windowGetBuffer(gPreferencesWindow);
memcpy(gPreferencesWindowBuffer, memcpy(gPreferencesWindowBuffer,
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_BACKGROUND], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getData(),
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_BACKGROUND].width * gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_BACKGROUND].height); _preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getWidth() * _preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getHeight());
fontSetCurrent(104); fontSetCurrent(104);
@ -1618,14 +1592,14 @@ static int preferencesWindowInit()
_plyrspdbid = buttonCreate(gPreferencesWindow, _plyrspdbid = buttonCreate(gPreferencesWindow,
383, 383,
68, 68,
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_CHECKBOX_OFF].width, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_CHECKBOX_OFF].getWidth(),
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_CHECKBOX_ON].height, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_CHECKBOX_ON].getHeight(),
-1, -1,
-1, -1,
524, 524,
524, 524,
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_CHECKBOX_OFF], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_CHECKBOX_OFF].getData(),
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_CHECKBOX_ON], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_CHECKBOX_ON].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT | BUTTON_FLAG_0x01 | BUTTON_FLAG_0x02); BUTTON_FLAG_TRANSPARENT | BUTTON_FLAG_0x01 | BUTTON_FLAG_0x02);
if (_plyrspdbid != -1) { if (_plyrspdbid != -1) {
@ -1638,14 +1612,14 @@ static int preferencesWindowInit()
btn = buttonCreate(gPreferencesWindow, btn = buttonCreate(gPreferencesWindow,
23, 23,
450, 450,
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].width, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getWidth(),
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].height, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].getHeight(),
-1, -1,
-1, -1,
-1, -1,
527, 527,
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getData(),
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (btn != -1) { if (btn != -1) {
@ -1656,14 +1630,14 @@ static int preferencesWindowInit()
btn = buttonCreate(gPreferencesWindow, btn = buttonCreate(gPreferencesWindow,
148, 148,
450, 450,
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].width, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getWidth(),
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].height, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].getHeight(),
-1, -1,
-1, -1,
-1, -1,
504, 504,
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getData(),
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (btn != -1) { if (btn != -1) {
@ -1674,14 +1648,14 @@ static int preferencesWindowInit()
btn = buttonCreate(gPreferencesWindow, btn = buttonCreate(gPreferencesWindow,
263, 263,
450, 450,
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].width, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getWidth(),
gPreferencesWindowFrmSizes[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].height, _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].getHeight(),
-1, -1,
-1, -1,
-1, -1,
528, 528,
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_UP].getData(),
gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN], _preferencesFrmImages[PREFERENCES_WINDOW_FRM_LITTLE_RED_BUTTON_DOWN].getData(),
NULL, NULL,
BUTTON_FLAG_TRANSPARENT); BUTTON_FLAG_TRANSPARENT);
if (btn != -1) { if (btn != -1) {
@ -1707,7 +1681,7 @@ static int preferencesWindowFree()
windowDestroy(gPreferencesWindow); windowDestroy(gPreferencesWindow);
for (int index = 0; index < PREFERENCES_WINDOW_FRM_COUNT; index++) { for (int index = 0; index < PREFERENCES_WINDOW_FRM_COUNT; index++) {
artUnlock(gPreferencesWindowFrmHandles[index]); _preferencesFrmImages[index].unlock();
} }
return 0; return 0;
@ -1912,8 +1886,8 @@ static void _DoThing(int eventCode)
int knobX = (int)(219.0 / (meta->maxValue - meta->minValue)); int knobX = (int)(219.0 / (meta->maxValue - meta->minValue));
int v31 = (int)((value - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0); int v31 = (int)((value - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0);
blitBufferToBuffer(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_BACKGROUND] + PREFERENCES_WINDOW_WIDTH * meta->knobY + 384, 240, 12, PREFERENCES_WINDOW_WIDTH, gPreferencesWindowBuffer + PREFERENCES_WINDOW_WIDTH * meta->knobY + 384, PREFERENCES_WINDOW_WIDTH); blitBufferToBuffer(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getData() + PREFERENCES_WINDOW_WIDTH * meta->knobY + 384, 240, 12, PREFERENCES_WINDOW_WIDTH, gPreferencesWindowBuffer + PREFERENCES_WINDOW_WIDTH * meta->knobY + 384, PREFERENCES_WINDOW_WIDTH);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_ON], 21, 12, 21, gPreferencesWindowBuffer + PREFERENCES_WINDOW_WIDTH * meta->knobY + v31, PREFERENCES_WINDOW_WIDTH); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_ON].getData(), 21, 12, 21, gPreferencesWindowBuffer + PREFERENCES_WINDOW_WIDTH * meta->knobY + v31, PREFERENCES_WINDOW_WIDTH);
windowRefresh(gPreferencesWindow); windowRefresh(gPreferencesWindow);
@ -2002,7 +1976,7 @@ static void _DoThing(int eventCode)
if (v52) { if (v52) {
int off = PREFERENCES_WINDOW_WIDTH * (meta->knobY - 12) + 384; int off = PREFERENCES_WINDOW_WIDTH * (meta->knobY - 12) + 384;
blitBufferToBuffer(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_BACKGROUND] + off, 240, 24, PREFERENCES_WINDOW_WIDTH, gPreferencesWindowBuffer + off, PREFERENCES_WINDOW_WIDTH); blitBufferToBuffer(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getData() + off, 240, 24, PREFERENCES_WINDOW_WIDTH, gPreferencesWindowBuffer + off, PREFERENCES_WINDOW_WIDTH);
for (int optionIndex = 0; optionIndex < meta->valuesCount; optionIndex++) { for (int optionIndex = 0; optionIndex < meta->valuesCount; optionIndex++) {
const char* str = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, meta->labelIds[optionIndex]); const char* str = getmsg(&gOptionsMessageList, &gOptionsMessageListItem, meta->labelIds[optionIndex]);
@ -2051,10 +2025,10 @@ static void _DoThing(int eventCode)
} }
} else { } else {
int off = PREFERENCES_WINDOW_WIDTH * meta->knobY + 384; int off = PREFERENCES_WINDOW_WIDTH * meta->knobY + 384;
blitBufferToBuffer(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_BACKGROUND] + off, 240, 12, PREFERENCES_WINDOW_WIDTH, gPreferencesWindowBuffer + off, PREFERENCES_WINDOW_WIDTH); blitBufferToBuffer(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_BACKGROUND].getData() + off, 240, 12, PREFERENCES_WINDOW_WIDTH, gPreferencesWindowBuffer + off, PREFERENCES_WINDOW_WIDTH);
} }
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_ON], 21, 12, 21, gPreferencesWindowBuffer + PREFERENCES_WINDOW_WIDTH * meta->knobY + v31, PREFERENCES_WINDOW_WIDTH); blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_ON].getData(), 21, 12, 21, gPreferencesWindowBuffer + PREFERENCES_WINDOW_WIDTH * meta->knobY + v31, PREFERENCES_WINDOW_WIDTH);
windowRefresh(gPreferencesWindow); windowRefresh(gPreferencesWindow);
while (getTicksSince(tick) < 35) while (getTicksSince(tick) < 35)