From cd936b86f0968b98a0ee706dffc6eaac16609160 Mon Sep 17 00:00:00 2001 From: sonil Date: Mon, 24 Oct 2022 14:50:24 +0800 Subject: [PATCH 1/6] add support for IFACE_BAR_WIDTH --- src/display_monitor.cc | 45 ++++++---- src/interface.cc | 185 ++++++++++++++++++++++++++++------------- src/interface.h | 5 ++ src/svga.cc | 1 + 4 files changed, 161 insertions(+), 75 deletions(-) diff --git a/src/display_monitor.cc b/src/display_monitor.cc index acfefa61..6485f676 100644 --- a/src/display_monitor.cc +++ b/src/display_monitor.cc @@ -30,7 +30,7 @@ namespace fallout { #define DISPLAY_MONITOR_X (23) #define DISPLAY_MONITOR_Y (24) -#define DISPLAY_MONITOR_WIDTH (167) +#define DISPLAY_MONITOR_WIDTH (gInterfaceCustomBar == true ? 167 + ifaceOffset : 167) #define DISPLAY_MONITOR_HEIGHT (60) #define DISPLAY_MONITOR_HALF_HEIGHT (DISPLAY_MONITOR_HEIGHT / 2) @@ -120,24 +120,35 @@ int displayMonitorInit() return -1; } - CacheEntry* backgroundFrmHandle; - int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 16, 0, 0, 0); - Art* backgroundFrm = artLock(backgroundFid, &backgroundFrmHandle); - if (backgroundFrm == NULL) { - internal_free(gDisplayMonitorBackgroundFrmData); - return -1; - } + if (gInterfaceCustomBar) { + _intface_full_width = gInterfaceBarWidth; + blitBufferToBuffer(GetCustomIfaceBarImageData() + gInterfaceBarWidth * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X, + DISPLAY_MONITOR_WIDTH, + DISPLAY_MONITOR_HEIGHT, + gInterfaceBarWidth, + gDisplayMonitorBackgroundFrmData, + DISPLAY_MONITOR_WIDTH); + } else { + CacheEntry* backgroundFrmHandle; + int backgroundFid = buildFid(OBJ_TYPE_INTERFACE, 16, 0, 0, 0); + Art* backgroundFrm = artLock(backgroundFid, &backgroundFrmHandle); + if (backgroundFrm == NULL) { + internal_free(gDisplayMonitorBackgroundFrmData); + return -1; + } - unsigned char* backgroundFrmData = artGetFrameData(backgroundFrm, 0, 0); - _intface_full_width = artGetWidth(backgroundFrm, 0, 0); - blitBufferToBuffer(backgroundFrmData + _intface_full_width * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X, - DISPLAY_MONITOR_WIDTH, - DISPLAY_MONITOR_HEIGHT, - _intface_full_width, - gDisplayMonitorBackgroundFrmData, - DISPLAY_MONITOR_WIDTH); + unsigned char* backgroundFrmData = artGetFrameData(backgroundFrm, 0, 0); + _intface_full_width = artGetWidth(backgroundFrm, 0, 0); + + blitBufferToBuffer(backgroundFrmData + _intface_full_width * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X, + DISPLAY_MONITOR_WIDTH, + DISPLAY_MONITOR_HEIGHT, + _intface_full_width, + gDisplayMonitorBackgroundFrmData, + DISPLAY_MONITOR_WIDTH); - artUnlock(backgroundFrmHandle); + artUnlock(backgroundFrmHandle); + } gDisplayMonitorScrollUpButton = buttonCreate(gInterfaceBarWindow, DISPLAY_MONITOR_X, diff --git a/src/interface.cc b/src/interface.cc index cb5296e7..4ec7fffd 100644 --- a/src/interface.cc +++ b/src/interface.cc @@ -161,7 +161,7 @@ static int gSingleAttackButton = -1; static int gInterfaceCurrentHand = HAND_LEFT; // 0x518F7C -static const Rect gInterfaceBarMainActionRect = { 267, 26, 455, 93 }; +static const Rect gInterfaceBarMainActionRect = { 267 + 160, 26, 455 + 160, 93 }; // 0x518F8C static int gChangeHandsButton = -1; @@ -172,7 +172,7 @@ static bool gInterfaceBarEndButtonsIsVisible = false; // Combat mode curtains rect. // // 0x518FA0 -static const Rect gInterfaceBarEndButtonsRect = { 580, 38, 637, 96 }; +static const Rect gInterfaceBarEndButtonsRect = { 580 + 160, 38, 637 + 160, 96 }; // 0x518FB0 static int gEndTurnButton = -1; @@ -181,7 +181,7 @@ static int gEndTurnButton = -1; static int gEndCombatButton = -1; // 0x518FD4 -static const Rect gInterfaceBarActionPointsBarRect = { 316, 14, 406, 19 }; +static const Rect gInterfaceBarActionPointsBarRect = { 316 + 160, 14, 406 + 160, 19 }; // 0x518FE8 static IndicatorDescription gIndicatorDescriptions[INDICATOR_COUNT] = { @@ -280,6 +280,70 @@ static FrmImage _greenLightFrmImage; static FrmImage _yellowLightFrmImage; static FrmImage _redLightFrmImage; +unsigned char* artLockFrameDataReturningSize2(int fid, int* widthPtr, int* heightPtr) +{ + Art* art; + if (art == NULL) { + return NULL; + } + + // NOTE: Uninline. + *widthPtr = artGetWidth(art, 0, 0); + if (*widthPtr == -1) { + return NULL; + } + + // NOTE: Uninline. + *heightPtr = artGetHeight(art, 0, 0); + if (*heightPtr == -1) { + return NULL; + } + + // NOTE: Uninline. + return artGetFrameData(art, 0, 0); +} + +int ifaceOffset = 0; +unsigned char* CustomInterfaceData; +int gInterfaceBarWidth = -1; +bool gInterfaceCustomBar = false; + +unsigned char* GetCustomIfaceBarImageData() +{ + if (!gInterfaceCustomBar) { + return NULL; + } + + return artGetFrameData((Art*)CustomInterfaceData, 0, 0); +} + + +int CustomInterfaceBarInit() +{ + ifaceOffset = gInterfaceBarWidth - 640; + + char path[128]; + int size; + + sprintf(path, "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth); + + if (dbGetFileSize(path, &size) != 0 || ifaceOffset <= 0) { + ifaceOffset = 0; + gInterfaceBarWidth = 640; + gInterfaceCustomBar = false; + } else { + gInterfaceCustomBar = true; + + CustomInterfaceData = (unsigned char *)malloc(size); + if (artRead(path, CustomInterfaceData) != 0) { + gInterfaceCustomBar = false; + free(CustomInterfaceData); + } + } + + return 0; +} + // intface_init // 0x45D880 int interfaceInit() @@ -290,12 +354,14 @@ int interfaceInit() return -1; } + CustomInterfaceBarInit(); + gInterfaceBarInitialized = 1; - int interfaceBarWindowX = (screenGetWidth() - INTERFACE_BAR_WIDTH) / 2; + int interfaceBarWindowX = (screenGetWidth() - gInterfaceBarWidth) / 2; int interfaceBarWindowY = screenGetHeight() - INTERFACE_BAR_HEIGHT; - gInterfaceBarWindow = windowCreate(interfaceBarWindowX, interfaceBarWindowY, INTERFACE_BAR_WIDTH, INTERFACE_BAR_HEIGHT, _colorTable[0], WINDOW_HIDDEN); + gInterfaceBarWindow = windowCreate(interfaceBarWindowX, interfaceBarWindowY, gInterfaceBarWidth, INTERFACE_BAR_HEIGHT, _colorTable[0], WINDOW_HIDDEN); if (gInterfaceBarWindow == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -307,15 +373,18 @@ int interfaceInit() return intface_fatal_error(-1); } - FrmImage backgroundFrmImage; - fid = buildFid(OBJ_TYPE_INTERFACE, 16, 0, 0, 0); - if (!backgroundFrmImage.lock(fid)) { - // NOTE: Uninline. - return intface_fatal_error(-1); - } + if (gInterfaceCustomBar) { + blitBufferToBuffer(GetCustomIfaceBarImageData(), gInterfaceBarWidth, INTERFACE_BAR_HEIGHT - 1, gInterfaceBarWidth, gInterfaceWindowBuffer, gInterfaceBarWidth); + } else { + FrmImage backgroundFrmImage; + fid = buildFid(OBJ_TYPE_INTERFACE, 16, 0, 0, 0); + if (!backgroundFrmImage.lock(fid)) { + return intface_fatal_error(-1); + } - blitBufferToBuffer(backgroundFrmImage.getData(), INTERFACE_BAR_WIDTH, INTERFACE_BAR_HEIGHT - 1, INTERFACE_BAR_WIDTH, gInterfaceWindowBuffer, 640); - backgroundFrmImage.unlock(); + blitBufferToBuffer(backgroundFrmImage.getData(), gInterfaceBarWidth, INTERFACE_BAR_HEIGHT - 1, gInterfaceBarWidth, gInterfaceWindowBuffer, gInterfaceBarWidth); + backgroundFrmImage.unlock(); + } fid = buildFid(OBJ_TYPE_INTERFACE, 47, 0, 0, 0); if (!_inventoryButtonNormalFrmImage.lock(fid)) { @@ -329,7 +398,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gInventoryButton = buttonCreate(gInterfaceBarWindow, 211, 40, 32, 21, -1, -1, -1, KEY_LOWERCASE_I, _inventoryButtonNormalFrmImage.getData(), _inventoryButtonPressedFrmImage.getData(), NULL, 0); + gInventoryButton = buttonCreate(gInterfaceBarWindow, 211 + ifaceOffset, 40, 32, 21, -1, -1, -1, KEY_LOWERCASE_I, _inventoryButtonNormalFrmImage.getData(), _inventoryButtonPressedFrmImage.getData(), NULL, 0); if (gInventoryButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -349,7 +418,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gOptionsButton = buttonCreate(gInterfaceBarWindow, 210, 61, 34, 34, -1, -1, -1, KEY_LOWERCASE_O, _optionsButtonNormalFrmImage.getData(), _optionsButtonPressedFrmImage.getData(), NULL, 0); + gOptionsButton = buttonCreate(gInterfaceBarWindow, 210 + ifaceOffset, 61, 34, 34, -1, -1, -1, KEY_LOWERCASE_O, _optionsButtonNormalFrmImage.getData(), _optionsButtonPressedFrmImage.getData(), NULL, 0); if (gOptionsButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -375,7 +444,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gSkilldexButton = buttonCreate(gInterfaceBarWindow, 523, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_S, _skilldexButtonNormalFrmImage.getData(), _skilldexButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); + gSkilldexButton = buttonCreate(gInterfaceBarWindow, 523 + ifaceOffset, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_S, _skilldexButtonNormalFrmImage.getData(), _skilldexButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); if (gSkilldexButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -402,7 +471,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gMapButton = buttonCreate(gInterfaceBarWindow, 526, 39, 41, 19, -1, -1, -1, KEY_TAB, _mapButtonNormalFrmImage.getData(), _mapButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); + gMapButton = buttonCreate(gInterfaceBarWindow, 526 + ifaceOffset, 39, 41, 19, -1, -1, -1, KEY_TAB, _mapButtonNormalFrmImage.getData(), _mapButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); if (gMapButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -423,7 +492,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gPipboyButton = buttonCreate(gInterfaceBarWindow, 526, 77, 41, 19, -1, -1, -1, KEY_LOWERCASE_P, _pipboyButtonNormalFrmImage.getData(), _pipboyButtonPressedFrmImage.getData(), NULL, 0); + gPipboyButton = buttonCreate(gInterfaceBarWindow, 526 + ifaceOffset, 77, 41, 19, -1, -1, -1, KEY_LOWERCASE_P, _pipboyButtonNormalFrmImage.getData(), _pipboyButtonPressedFrmImage.getData(), NULL, 0); if (gPipboyButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -444,7 +513,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gCharacterButton = buttonCreate(gInterfaceBarWindow, 526, 58, 41, 19, -1, -1, -1, KEY_LOWERCASE_C, _characterButtonNormalFrmImage.getData(), _characterButtonPressedFrmImage.getData(), NULL, 0); + gCharacterButton = buttonCreate(gInterfaceBarWindow, 526 + ifaceOffset, 58, 41, 19, -1, -1, -1, KEY_LOWERCASE_C, _characterButtonNormalFrmImage.getData(), _characterButtonPressedFrmImage.getData(), NULL, 0); if (gCharacterButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -474,7 +543,7 @@ int interfaceInit() memcpy(_itemButtonUp, _itemButtonNormalFrmImage.getData(), sizeof(_itemButtonUp)); memcpy(_itemButtonDown, _itemButtonPressedFrmImage.getData(), sizeof(_itemButtonDown)); - gSingleAttackButton = buttonCreate(gInterfaceBarWindow, 267, 26, 188, 67, -1, -1, -1, -20, _itemButtonUp, _itemButtonDown, NULL, BUTTON_FLAG_TRANSPARENT); + gSingleAttackButton = buttonCreate(gInterfaceBarWindow, 267 + ifaceOffset, 26, 188, 67, -1, -1, -1, -20, _itemButtonUp, _itemButtonDown, NULL, BUTTON_FLAG_TRANSPARENT); if (gSingleAttackButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -502,7 +571,7 @@ int interfaceInit() } // Swap hands button - gChangeHandsButton = buttonCreate(gInterfaceBarWindow, 218, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_B, _changeHandsButtonNormalFrmImage.getData(), _changeHandsButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); + gChangeHandsButton = buttonCreate(gInterfaceBarWindow, 218 + ifaceOffset, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_B, _changeHandsButtonNormalFrmImage.getData(), _changeHandsButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); if (gChangeHandsButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -535,7 +604,7 @@ int interfaceInit() return intface_fatal_error(-1); } - blitBufferToBuffer(gInterfaceWindowBuffer + 640 * 14 + 316, 90, 5, 640, gInterfaceActionPointsBarBackground, 90); + blitBufferToBuffer(gInterfaceWindowBuffer + gInterfaceBarWidth * 14 + 316 + ifaceOffset, 90, 5, gInterfaceBarWidth, gInterfaceActionPointsBarBackground, 90); if (indicatorBarInit() == -1) { // NOTE: Uninline. @@ -890,10 +959,10 @@ void interfaceRenderHitPoints(bool animate) if (animate) { int delay = 250 / (abs(gInterfaceLastRenderedHitPoints - hp) + 1); for (int index = 0; index < count; index++) { - interfaceRenderCounter(473, 40, v1[index], v1[index + 1], v2[index], delay); + interfaceRenderCounter(473 + ifaceOffset, 40, v1[index], v1[index + 1], v2[index], delay); } } else { - interfaceRenderCounter(473, 40, gInterfaceLastRenderedHitPoints, hp, color, 0); + interfaceRenderCounter(473 + ifaceOffset, 40, gInterfaceLastRenderedHitPoints, hp, color, 0); } gInterfaceLastRenderedHitPoints = hp; @@ -912,7 +981,7 @@ void interfaceRenderArmorClass(bool animate) delay = 250 / (abs(gInterfaceLastRenderedArmorClass - armorClass) + 1); } - interfaceRenderCounter(473, 75, gInterfaceLastRenderedArmorClass, armorClass, 0, delay); + interfaceRenderCounter(473 + ifaceOffset, 75, gInterfaceLastRenderedArmorClass, armorClass, 0, delay); gInterfaceLastRenderedArmorClass = armorClass; } @@ -926,7 +995,7 @@ void interfaceRenderActionPoints(int actionPointsLeft, int bonusActionPoints) return; } - blitBufferToBuffer(gInterfaceActionPointsBarBackground, 90, 5, 90, gInterfaceWindowBuffer + 14 * 640 + 316, 640); + blitBufferToBuffer(gInterfaceActionPointsBarBackground, 90, 5, 90, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + ifaceOffset + 316, gInterfaceBarWidth); if (actionPointsLeft == -1) { frmData = _redLightFrmImage.getData(); @@ -954,11 +1023,11 @@ void interfaceRenderActionPoints(int actionPointsLeft, int bonusActionPoints) int index; for (index = 0; index < actionPointsLeft; index++) { - blitBufferToBuffer(frmData, 5, 5, 5, gInterfaceWindowBuffer + 14 * 640 + 316 + index * 9, 640); + blitBufferToBuffer(frmData, 5, 5, 5, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + 316 + index * 9 + ifaceOffset, gInterfaceBarWidth); } for (; index < (actionPointsLeft + bonusActionPoints); index++) { - blitBufferToBuffer(_yellowLightFrmImage.getData(), 5, 5, 5, gInterfaceWindowBuffer + 14 * 640 + 316 + index * 9, 640); + blitBufferToBuffer(_yellowLightFrmImage.getData(), 5, 5, 5, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + 316 + ifaceOffset + index * 9, gInterfaceBarWidth); } if (!gInterfaceBarInitialized) { @@ -1327,7 +1396,7 @@ int _intface_update_ammo_lights() } } - interfaceUpdateAmmoBar(463, ratio); + interfaceUpdateAmmoBar(463 + ifaceOffset, ratio); return 0; } @@ -1363,7 +1432,7 @@ void interfaceBarEndButtonsShow(bool animated) if (getTicksSince(time) >= delay) { unsigned char* src = artGetFrameData(art, frame, 0); if (src != NULL) { - blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + 640 * 38 + 580, 640); + blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } @@ -1377,7 +1446,7 @@ void interfaceBarEndButtonsShow(bool animated) } } else { unsigned char* src = artGetFrameData(art, frameCount - 1, 0); - blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + 640 * 38 + 580, 640); + blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } @@ -1421,9 +1490,9 @@ void interfaceBarEndButtonsHide(bool animated) if (getTicksSince(time) >= delay) { unsigned char* src = artGetFrameData(art, frame - 1, 0); - unsigned char* dest = gInterfaceWindowBuffer + 640 * 38 + 580; + unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset; if (src != NULL) { - blitBufferToBuffer(src, 57, 58, 57, dest, 640); + blitBufferToBuffer(src, 57, 58, 57, dest, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } @@ -1436,9 +1505,9 @@ void interfaceBarEndButtonsHide(bool animated) sharedFpsLimiter.throttle(); } } else { - unsigned char* dest = gInterfaceWindowBuffer + 640 * 38 + 580; + unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset; unsigned char* src = artGetFrameData(art, 0, 0); - blitBufferToBuffer(src, 57, 58, 57, dest, 640); + blitBufferToBuffer(src, 57, 58, 57, dest, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } @@ -1461,7 +1530,7 @@ void interfaceBarEndButtonsRenderGreenLights() } soundPlayFile("icombat2"); - blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * 640 + 580, 640); + blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * gInterfaceBarWidth + 580 + ifaceOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } } @@ -1481,7 +1550,7 @@ void interfaceBarEndButtonsRenderRedLights() } soundPlayFile("icombat1"); - blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * 640 + 580, 640); + blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * gInterfaceBarWidth + 580 + ifaceOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } } @@ -1857,7 +1926,7 @@ static int endTurnButtonInit() return -1; } - gEndTurnButton = buttonCreate(gInterfaceBarWindow, 590, 43, 38, 22, -1, -1, -1, 32, _endTurnButtonNormalFrmImage.getData(), _endTurnButtonPressedFrmImage.getData(), NULL, 0); + gEndTurnButton = buttonCreate(gInterfaceBarWindow, 590 + ifaceOffset, 43, 38, 22, -1, -1, -1, 32, _endTurnButtonNormalFrmImage.getData(), _endTurnButtonPressedFrmImage.getData(), NULL, 0); if (gEndTurnButton == -1) { return -1; } @@ -1909,7 +1978,7 @@ static int endCombatButtonInit() return -1; } - gEndCombatButton = buttonCreate(gInterfaceBarWindow, 590, 65, 38, 22, -1, -1, -1, 13, _endCombatButtonNormalFrmImage.getData(), _endCombatButtonPressedFrmImage.getData(), NULL, 0); + gEndCombatButton = buttonCreate(gInterfaceBarWindow, 590 + ifaceOffset, 65, 38, 22, -1, -1, -1, 13, _endCombatButtonNormalFrmImage.getData(), _endCombatButtonPressedFrmImage.getData(), NULL, 0); if (gEndCombatButton == -1) { return -1; } @@ -1945,19 +2014,19 @@ static void interfaceUpdateAmmoBar(int x, int ratio) ratio -= 1; } - unsigned char* dest = gInterfaceWindowBuffer + 640 * 26 + x; + unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * 26 + x; for (int index = 70; index > ratio; index--) { *dest = 14; - dest += 640; + dest += gInterfaceBarWidth; } while (ratio > 0) { *dest = 196; - dest += 640; + dest += gInterfaceBarWidth; *dest = 14; - dest += 640; + dest += gInterfaceBarWidth; ratio -= 2; } @@ -2013,7 +2082,7 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i } unsigned char* numbers = _numbersFrmImage.getData() + offset; - unsigned char* dest = gInterfaceWindowBuffer + 640 * y; + unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * y; unsigned char* downSrc = numbers + 90; unsigned char* upSrc = numbers + 99; @@ -2039,10 +2108,10 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i int tens = (normalizedValue / 10) % 10; int hundreds = normalizedValue / 100; - blitBufferToBuffer(numbers + 9 * hundreds, 9, 17, 360, hundredsDest, 640); - blitBufferToBuffer(numbers + 9 * tens, 9, 17, 360, tensDest, 640); - blitBufferToBuffer(numbers + 9 * ones, 9, 17, 360, onesDest, 640); - blitBufferToBuffer(normalizedSign >= 0 ? plusSrc : minusSrc, 6, 17, 360, signDest, 640); + blitBufferToBuffer(numbers + 9 * hundreds, 9, 17, 360, hundredsDest, gInterfaceBarWidth); + blitBufferToBuffer(numbers + 9 * tens, 9, 17, 360, tensDest, gInterfaceBarWidth); + blitBufferToBuffer(numbers + 9 * ones, 9, 17, 360, onesDest, gInterfaceBarWidth); + blitBufferToBuffer(normalizedSign >= 0 ? plusSrc : minusSrc, 6, 17, 360, signDest, gInterfaceBarWidth); if (!gInterfaceBarInitialized) { Rect numbersRect = { x, y, x + 33, y + 17 }; @@ -2056,7 +2125,7 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i v49 = 1; } - blitBufferToBuffer(upSrc, 9, 17, 360, onesDest, 640); + blitBufferToBuffer(upSrc, 9, 17, 360, onesDest, gInterfaceBarWidth); _mouse_info(); gameMouseRefresh(); renderPresent(); @@ -2066,7 +2135,7 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i ones += v49; if (ones > 9 || ones < 0) { - blitBufferToBuffer(upSrc, 9, 17, 360, tensDest, 640); + blitBufferToBuffer(upSrc, 9, 17, 360, tensDest, gInterfaceBarWidth); _mouse_info(); gameMouseRefresh(); renderPresent(); @@ -2076,7 +2145,7 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i tens += v49; ones -= 10 * v49; if (tens == 10 || tens == -1) { - blitBufferToBuffer(upSrc, 9, 17, 360, hundredsDest, 640); + blitBufferToBuffer(upSrc, 9, 17, 360, hundredsDest, gInterfaceBarWidth); _mouse_info(); gameMouseRefresh(); renderPresent(); @@ -2089,7 +2158,7 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i hundreds -= 10 * v49; } - blitBufferToBuffer(downSrc, 9, 17, 360, hundredsDest, 640); + blitBufferToBuffer(downSrc, 9, 17, 360, hundredsDest, gInterfaceBarWidth); _mouse_info(); gameMouseRefresh(); renderPresent(); @@ -2097,13 +2166,13 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i windowRefreshRect(gInterfaceBarWindow, &numbersRect); } - blitBufferToBuffer(downSrc, 9, 17, 360, tensDest, 640); + blitBufferToBuffer(downSrc, 9, 17, 360, tensDest, gInterfaceBarWidth); renderPresent(); inputBlockForTocks(delay); windowRefreshRect(gInterfaceBarWindow, &numbersRect); } - blitBufferToBuffer(downSrc, 9, 17, 360, onesDest, 640); + blitBufferToBuffer(downSrc, 9, 17, 360, onesDest, gInterfaceBarWidth); _mouse_info(); gameMouseRefresh(); renderPresent(); @@ -2112,11 +2181,11 @@ static void interfaceRenderCounter(int x, int y, int previousValue, int value, i previousValue += change; - blitBufferToBuffer(numbers + 9 * hundreds, 9, 17, 360, hundredsDest, 640); - blitBufferToBuffer(numbers + 9 * tens, 9, 17, 360, tensDest, 640); - blitBufferToBuffer(numbers + 9 * ones, 9, 17, 360, onesDest, 640); + blitBufferToBuffer(numbers + 9 * hundreds, 9, 17, 360, hundredsDest, gInterfaceBarWidth); + blitBufferToBuffer(numbers + 9 * tens, 9, 17, 360, tensDest, gInterfaceBarWidth); + blitBufferToBuffer(numbers + 9 * ones, 9, 17, 360, onesDest, gInterfaceBarWidth); - blitBufferToBuffer(previousValue >= 0 ? plusSrc : minusSrc, 6, 17, 360, signDest, 640); + blitBufferToBuffer(previousValue >= 0 ? plusSrc : minusSrc, 6, 17, 360, signDest, gInterfaceBarWidth); _mouse_info(); gameMouseRefresh(); renderPresent(); diff --git a/src/interface.h b/src/interface.h index bbc9d2a0..f0590de8 100644 --- a/src/interface.h +++ b/src/interface.h @@ -33,6 +33,9 @@ typedef enum InterfaceItemAction { extern int gInterfaceBarWindow; extern bool gInterfaceBarMode; +extern int gInterfaceBarWidth; +extern bool gInterfaceCustomBar; +extern int ifaceOffset; int interfaceInit(); void interfaceReset(); @@ -65,6 +68,8 @@ int indicatorBarRefresh(); bool indicatorBarShow(); bool indicatorBarHide(); +unsigned char* GetCustomIfaceBarImageData(); + } // namespace fallout #endif /* INTERFACE_H */ diff --git a/src/svga.cc b/src/svga.cc index 3eba9491..117ee59e 100644 --- a/src/svga.cc +++ b/src/svga.cc @@ -186,6 +186,7 @@ int _GNW95_init_mode_ex(int width, int height, int bpp) } configGetBool(&resolutionConfig, "IFACE", "IFACE_BAR_MODE", &gInterfaceBarMode); + configGetInt(&resolutionConfig, "IFACE", "IFACE_BAR_WIDTH", &gInterfaceBarWidth); } configFree(&resolutionConfig); } From bd6db5ba7c738b4dd29254a4df658cc3539fa65f Mon Sep 17 00:00:00 2001 From: sonil Date: Mon, 24 Oct 2022 15:50:25 +0800 Subject: [PATCH 2/6] fix skilldex position --- src/skilldex.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skilldex.cc b/src/skilldex.cc index feb32be3..6955e207 100644 --- a/src/skilldex.cc +++ b/src/skilldex.cc @@ -220,7 +220,7 @@ static int skilldexWindowInit() } // Maintain original position relative to centered interface bar. - int skilldexWindowX = (screenGetWidth() - 640) / 2 + 640 - _skilldexFrmImages[SKILLDEX_FRM_BACKGROUND].getWidth() - SKILLDEX_WINDOW_RIGHT_MARGIN; + int skilldexWindowX = (screenGetWidth() - gInterfaceBarWidth) / 2 + gInterfaceBarWidth - _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, From b4da17df58415788ca30c45fa5c6d977ae84a102 Mon Sep 17 00:00:00 2001 From: sonil Date: Mon, 24 Oct 2022 16:01:53 +0800 Subject: [PATCH 3/6] fix refresh rect --- src/display_monitor.cc | 14 ++++++++------ src/interface.cc | 10 +++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/display_monitor.cc b/src/display_monitor.cc index 6485f676..5ed676d3 100644 --- a/src/display_monitor.cc +++ b/src/display_monitor.cc @@ -59,12 +59,7 @@ static bool gDisplayMonitorInitialized = false; // The rectangle that display monitor occupies in the main interface window. // // 0x518510 -static const Rect gDisplayMonitorRect = { - DISPLAY_MONITOR_X, - DISPLAY_MONITOR_Y, - DISPLAY_MONITOR_X + DISPLAY_MONITOR_WIDTH - 1, - DISPLAY_MONITOR_Y + DISPLAY_MONITOR_HEIGHT - 1, -}; +static Rect gDisplayMonitorRect; // 0x518520 static int gDisplayMonitorScrollDownButton = -1; @@ -106,6 +101,13 @@ static int gConsoleFilePrintCount = 0; int displayMonitorInit() { if (!gDisplayMonitorInitialized) { + gDisplayMonitorRect = { + DISPLAY_MONITOR_X, + DISPLAY_MONITOR_Y, + DISPLAY_MONITOR_X + DISPLAY_MONITOR_WIDTH - 1, + DISPLAY_MONITOR_Y + DISPLAY_MONITOR_HEIGHT - 1, + }; + int oldFont = fontGetCurrent(); fontSetCurrent(DISPLAY_MONITOR_FONT); diff --git a/src/interface.cc b/src/interface.cc index 4ec7fffd..1f4bf439 100644 --- a/src/interface.cc +++ b/src/interface.cc @@ -161,7 +161,7 @@ static int gSingleAttackButton = -1; static int gInterfaceCurrentHand = HAND_LEFT; // 0x518F7C -static const Rect gInterfaceBarMainActionRect = { 267 + 160, 26, 455 + 160, 93 }; +static Rect gInterfaceBarMainActionRect; // 0x518F8C static int gChangeHandsButton = -1; @@ -172,7 +172,7 @@ static bool gInterfaceBarEndButtonsIsVisible = false; // Combat mode curtains rect. // // 0x518FA0 -static const Rect gInterfaceBarEndButtonsRect = { 580 + 160, 38, 637 + 160, 96 }; +static Rect gInterfaceBarEndButtonsRect; // 0x518FB0 static int gEndTurnButton = -1; @@ -181,7 +181,7 @@ static int gEndTurnButton = -1; static int gEndCombatButton = -1; // 0x518FD4 -static const Rect gInterfaceBarActionPointsBarRect = { 316 + 160, 14, 406 + 160, 19 }; +static Rect gInterfaceBarActionPointsBarRect; // 0x518FE8 static IndicatorDescription gIndicatorDescriptions[INDICATOR_COUNT] = { @@ -356,6 +356,10 @@ int interfaceInit() CustomInterfaceBarInit(); + gInterfaceBarActionPointsBarRect = { 316 + ifaceOffset, 14, 406 + ifaceOffset, 19 }; + gInterfaceBarEndButtonsRect = { 580 + ifaceOffset, 38, 637 + ifaceOffset, 96 }; + gInterfaceBarMainActionRect = { 267 + ifaceOffset, 26, 455 + ifaceOffset, 93 }; + gInterfaceBarInitialized = 1; int interfaceBarWindowX = (screenGetWidth() - gInterfaceBarWidth) / 2; From c367d595ff7bda81f7b1a74c7b3b207c88e898df Mon Sep 17 00:00:00 2001 From: sonil Date: Mon, 24 Oct 2022 18:48:19 +0800 Subject: [PATCH 4/6] cleanup code --- src/interface.cc | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/interface.cc b/src/interface.cc index 1f4bf439..fd941dbd 100644 --- a/src/interface.cc +++ b/src/interface.cc @@ -280,29 +280,6 @@ static FrmImage _greenLightFrmImage; static FrmImage _yellowLightFrmImage; static FrmImage _redLightFrmImage; -unsigned char* artLockFrameDataReturningSize2(int fid, int* widthPtr, int* heightPtr) -{ - Art* art; - if (art == NULL) { - return NULL; - } - - // NOTE: Uninline. - *widthPtr = artGetWidth(art, 0, 0); - if (*widthPtr == -1) { - return NULL; - } - - // NOTE: Uninline. - *heightPtr = artGetHeight(art, 0, 0); - if (*heightPtr == -1) { - return NULL; - } - - // NOTE: Uninline. - return artGetFrameData(art, 0, 0); -} - int ifaceOffset = 0; unsigned char* CustomInterfaceData; int gInterfaceBarWidth = -1; From 139837d408bae73b956d999e515165ab9c9c7a84 Mon Sep 17 00:00:00 2001 From: sonil Date: Mon, 24 Oct 2022 18:55:09 +0800 Subject: [PATCH 5/6] fix crash for screen width --- src/interface.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface.cc b/src/interface.cc index fd941dbd..4489b664 100644 --- a/src/interface.cc +++ b/src/interface.cc @@ -304,7 +304,7 @@ int CustomInterfaceBarInit() sprintf(path, "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth); - if (dbGetFileSize(path, &size) != 0 || ifaceOffset <= 0) { + if (dbGetFileSize(path, &size) != 0 || ifaceOffset <= 0 || screenGetWidth() <= 640) { ifaceOffset = 0; gInterfaceBarWidth = 640; gInterfaceCustomBar = false; From 5c5cf797e8539f97a3483d0c532e14a5da2387be Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Mon, 7 Nov 2022 13:23:48 +0300 Subject: [PATCH 6/6] Rearrange and rename new stuff --- src/display_monitor.cc | 6 +- src/interface.cc | 148 ++++++++++++++++++++++------------------- src/interface.h | 6 +- 3 files changed, 85 insertions(+), 75 deletions(-) diff --git a/src/display_monitor.cc b/src/display_monitor.cc index 5ed676d3..aeb5467c 100644 --- a/src/display_monitor.cc +++ b/src/display_monitor.cc @@ -30,7 +30,7 @@ namespace fallout { #define DISPLAY_MONITOR_X (23) #define DISPLAY_MONITOR_Y (24) -#define DISPLAY_MONITOR_WIDTH (gInterfaceCustomBar == true ? 167 + ifaceOffset : 167) +#define DISPLAY_MONITOR_WIDTH (167 + gInterfaceBarContentOffset) #define DISPLAY_MONITOR_HEIGHT (60) #define DISPLAY_MONITOR_HALF_HEIGHT (DISPLAY_MONITOR_HEIGHT / 2) @@ -122,9 +122,9 @@ int displayMonitorInit() return -1; } - if (gInterfaceCustomBar) { + if (gInterfaceBarIsCustom) { _intface_full_width = gInterfaceBarWidth; - blitBufferToBuffer(GetCustomIfaceBarImageData() + gInterfaceBarWidth * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X, + blitBufferToBuffer(customInterfaceBarGetBackgroundImageData() + gInterfaceBarWidth * DISPLAY_MONITOR_Y + DISPLAY_MONITOR_X, DISPLAY_MONITOR_WIDTH, DISPLAY_MONITOR_HEIGHT, gInterfaceBarWidth, diff --git a/src/interface.cc b/src/interface.cc index 4489b664..9d4b416d 100644 --- a/src/interface.cc +++ b/src/interface.cc @@ -124,6 +124,9 @@ static int indicatorBoxCompareByPosition(const void* a, const void* b); static void indicatorBarRender(int count); static bool indicatorBarAdd(int indicator); +static void customInterfaceBarInit(); +static void customInterfaceBarExit(); + // 0x518F08 static bool gInterfaceBarInitialized = false; @@ -280,46 +283,10 @@ static FrmImage _greenLightFrmImage; static FrmImage _yellowLightFrmImage; static FrmImage _redLightFrmImage; -int ifaceOffset = 0; -unsigned char* CustomInterfaceData; +int gInterfaceBarContentOffset = 0; int gInterfaceBarWidth = -1; -bool gInterfaceCustomBar = false; - -unsigned char* GetCustomIfaceBarImageData() -{ - if (!gInterfaceCustomBar) { - return NULL; - } - - return artGetFrameData((Art*)CustomInterfaceData, 0, 0); -} - - -int CustomInterfaceBarInit() -{ - ifaceOffset = gInterfaceBarWidth - 640; - - char path[128]; - int size; - - sprintf(path, "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth); - - if (dbGetFileSize(path, &size) != 0 || ifaceOffset <= 0 || screenGetWidth() <= 640) { - ifaceOffset = 0; - gInterfaceBarWidth = 640; - gInterfaceCustomBar = false; - } else { - gInterfaceCustomBar = true; - - CustomInterfaceData = (unsigned char *)malloc(size); - if (artRead(path, CustomInterfaceData) != 0) { - gInterfaceCustomBar = false; - free(CustomInterfaceData); - } - } - - return 0; -} +bool gInterfaceBarIsCustom = false; +static Art* gCustomInterfaceBarBackground = nullptr; // intface_init // 0x45D880 @@ -331,11 +298,11 @@ int interfaceInit() return -1; } - CustomInterfaceBarInit(); + customInterfaceBarInit(); - gInterfaceBarActionPointsBarRect = { 316 + ifaceOffset, 14, 406 + ifaceOffset, 19 }; - gInterfaceBarEndButtonsRect = { 580 + ifaceOffset, 38, 637 + ifaceOffset, 96 }; - gInterfaceBarMainActionRect = { 267 + ifaceOffset, 26, 455 + ifaceOffset, 93 }; + gInterfaceBarActionPointsBarRect = { 316 + gInterfaceBarContentOffset, 14, 406 + gInterfaceBarContentOffset, 19 }; + gInterfaceBarEndButtonsRect = { 580 + gInterfaceBarContentOffset, 38, 637 + gInterfaceBarContentOffset, 96 }; + gInterfaceBarMainActionRect = { 267 + gInterfaceBarContentOffset, 26, 455 + gInterfaceBarContentOffset, 93 }; gInterfaceBarInitialized = 1; @@ -354,8 +321,8 @@ int interfaceInit() return intface_fatal_error(-1); } - if (gInterfaceCustomBar) { - blitBufferToBuffer(GetCustomIfaceBarImageData(), gInterfaceBarWidth, INTERFACE_BAR_HEIGHT - 1, gInterfaceBarWidth, gInterfaceWindowBuffer, gInterfaceBarWidth); + if (gInterfaceBarIsCustom) { + blitBufferToBuffer(customInterfaceBarGetBackgroundImageData(), gInterfaceBarWidth, INTERFACE_BAR_HEIGHT - 1, gInterfaceBarWidth, gInterfaceWindowBuffer, gInterfaceBarWidth); } else { FrmImage backgroundFrmImage; fid = buildFid(OBJ_TYPE_INTERFACE, 16, 0, 0, 0); @@ -379,7 +346,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gInventoryButton = buttonCreate(gInterfaceBarWindow, 211 + ifaceOffset, 40, 32, 21, -1, -1, -1, KEY_LOWERCASE_I, _inventoryButtonNormalFrmImage.getData(), _inventoryButtonPressedFrmImage.getData(), NULL, 0); + gInventoryButton = buttonCreate(gInterfaceBarWindow, 211 + gInterfaceBarContentOffset, 40, 32, 21, -1, -1, -1, KEY_LOWERCASE_I, _inventoryButtonNormalFrmImage.getData(), _inventoryButtonPressedFrmImage.getData(), NULL, 0); if (gInventoryButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -399,7 +366,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gOptionsButton = buttonCreate(gInterfaceBarWindow, 210 + ifaceOffset, 61, 34, 34, -1, -1, -1, KEY_LOWERCASE_O, _optionsButtonNormalFrmImage.getData(), _optionsButtonPressedFrmImage.getData(), NULL, 0); + gOptionsButton = buttonCreate(gInterfaceBarWindow, 210 + gInterfaceBarContentOffset, 61, 34, 34, -1, -1, -1, KEY_LOWERCASE_O, _optionsButtonNormalFrmImage.getData(), _optionsButtonPressedFrmImage.getData(), NULL, 0); if (gOptionsButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -425,7 +392,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gSkilldexButton = buttonCreate(gInterfaceBarWindow, 523 + ifaceOffset, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_S, _skilldexButtonNormalFrmImage.getData(), _skilldexButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); + gSkilldexButton = buttonCreate(gInterfaceBarWindow, 523 + gInterfaceBarContentOffset, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_S, _skilldexButtonNormalFrmImage.getData(), _skilldexButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); if (gSkilldexButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -452,7 +419,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gMapButton = buttonCreate(gInterfaceBarWindow, 526 + ifaceOffset, 39, 41, 19, -1, -1, -1, KEY_TAB, _mapButtonNormalFrmImage.getData(), _mapButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); + gMapButton = buttonCreate(gInterfaceBarWindow, 526 + gInterfaceBarContentOffset, 39, 41, 19, -1, -1, -1, KEY_TAB, _mapButtonNormalFrmImage.getData(), _mapButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); if (gMapButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -473,7 +440,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gPipboyButton = buttonCreate(gInterfaceBarWindow, 526 + ifaceOffset, 77, 41, 19, -1, -1, -1, KEY_LOWERCASE_P, _pipboyButtonNormalFrmImage.getData(), _pipboyButtonPressedFrmImage.getData(), NULL, 0); + gPipboyButton = buttonCreate(gInterfaceBarWindow, 526 + gInterfaceBarContentOffset, 77, 41, 19, -1, -1, -1, KEY_LOWERCASE_P, _pipboyButtonNormalFrmImage.getData(), _pipboyButtonPressedFrmImage.getData(), NULL, 0); if (gPipboyButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -494,7 +461,7 @@ int interfaceInit() return intface_fatal_error(-1); } - gCharacterButton = buttonCreate(gInterfaceBarWindow, 526 + ifaceOffset, 58, 41, 19, -1, -1, -1, KEY_LOWERCASE_C, _characterButtonNormalFrmImage.getData(), _characterButtonPressedFrmImage.getData(), NULL, 0); + gCharacterButton = buttonCreate(gInterfaceBarWindow, 526 + gInterfaceBarContentOffset, 58, 41, 19, -1, -1, -1, KEY_LOWERCASE_C, _characterButtonNormalFrmImage.getData(), _characterButtonPressedFrmImage.getData(), NULL, 0); if (gCharacterButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -524,7 +491,7 @@ int interfaceInit() memcpy(_itemButtonUp, _itemButtonNormalFrmImage.getData(), sizeof(_itemButtonUp)); memcpy(_itemButtonDown, _itemButtonPressedFrmImage.getData(), sizeof(_itemButtonDown)); - gSingleAttackButton = buttonCreate(gInterfaceBarWindow, 267 + ifaceOffset, 26, 188, 67, -1, -1, -1, -20, _itemButtonUp, _itemButtonDown, NULL, BUTTON_FLAG_TRANSPARENT); + gSingleAttackButton = buttonCreate(gInterfaceBarWindow, 267 + gInterfaceBarContentOffset, 26, 188, 67, -1, -1, -1, -20, _itemButtonUp, _itemButtonDown, NULL, BUTTON_FLAG_TRANSPARENT); if (gSingleAttackButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -552,7 +519,7 @@ int interfaceInit() } // Swap hands button - gChangeHandsButton = buttonCreate(gInterfaceBarWindow, 218 + ifaceOffset, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_B, _changeHandsButtonNormalFrmImage.getData(), _changeHandsButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); + gChangeHandsButton = buttonCreate(gInterfaceBarWindow, 218 + gInterfaceBarContentOffset, 6, 22, 21, -1, -1, -1, KEY_LOWERCASE_B, _changeHandsButtonNormalFrmImage.getData(), _changeHandsButtonPressedFrmImage.getData(), NULL, BUTTON_FLAG_TRANSPARENT); if (gChangeHandsButton == -1) { // NOTE: Uninline. return intface_fatal_error(-1); @@ -585,7 +552,7 @@ int interfaceInit() return intface_fatal_error(-1); } - blitBufferToBuffer(gInterfaceWindowBuffer + gInterfaceBarWidth * 14 + 316 + ifaceOffset, 90, 5, gInterfaceBarWidth, gInterfaceActionPointsBarBackground, 90); + blitBufferToBuffer(gInterfaceWindowBuffer + gInterfaceBarWidth * 14 + 316 + gInterfaceBarContentOffset, 90, 5, gInterfaceBarWidth, gInterfaceActionPointsBarBackground, 90); if (indicatorBarInit() == -1) { // NOTE: Uninline. @@ -709,6 +676,8 @@ void interfaceFree() } } + customInterfaceBarExit(); + interfaceBarFree(); } @@ -940,10 +909,10 @@ void interfaceRenderHitPoints(bool animate) if (animate) { int delay = 250 / (abs(gInterfaceLastRenderedHitPoints - hp) + 1); for (int index = 0; index < count; index++) { - interfaceRenderCounter(473 + ifaceOffset, 40, v1[index], v1[index + 1], v2[index], delay); + interfaceRenderCounter(473 + gInterfaceBarContentOffset, 40, v1[index], v1[index + 1], v2[index], delay); } } else { - interfaceRenderCounter(473 + ifaceOffset, 40, gInterfaceLastRenderedHitPoints, hp, color, 0); + interfaceRenderCounter(473 + gInterfaceBarContentOffset, 40, gInterfaceLastRenderedHitPoints, hp, color, 0); } gInterfaceLastRenderedHitPoints = hp; @@ -962,7 +931,7 @@ void interfaceRenderArmorClass(bool animate) delay = 250 / (abs(gInterfaceLastRenderedArmorClass - armorClass) + 1); } - interfaceRenderCounter(473 + ifaceOffset, 75, gInterfaceLastRenderedArmorClass, armorClass, 0, delay); + interfaceRenderCounter(473 + gInterfaceBarContentOffset, 75, gInterfaceLastRenderedArmorClass, armorClass, 0, delay); gInterfaceLastRenderedArmorClass = armorClass; } @@ -976,7 +945,7 @@ void interfaceRenderActionPoints(int actionPointsLeft, int bonusActionPoints) return; } - blitBufferToBuffer(gInterfaceActionPointsBarBackground, 90, 5, 90, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + ifaceOffset + 316, gInterfaceBarWidth); + blitBufferToBuffer(gInterfaceActionPointsBarBackground, 90, 5, 90, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + gInterfaceBarContentOffset + 316, gInterfaceBarWidth); if (actionPointsLeft == -1) { frmData = _redLightFrmImage.getData(); @@ -1004,11 +973,11 @@ void interfaceRenderActionPoints(int actionPointsLeft, int bonusActionPoints) int index; for (index = 0; index < actionPointsLeft; index++) { - blitBufferToBuffer(frmData, 5, 5, 5, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + 316 + index * 9 + ifaceOffset, gInterfaceBarWidth); + blitBufferToBuffer(frmData, 5, 5, 5, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + 316 + index * 9 + gInterfaceBarContentOffset, gInterfaceBarWidth); } for (; index < (actionPointsLeft + bonusActionPoints); index++) { - blitBufferToBuffer(_yellowLightFrmImage.getData(), 5, 5, 5, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + 316 + ifaceOffset + index * 9, gInterfaceBarWidth); + blitBufferToBuffer(_yellowLightFrmImage.getData(), 5, 5, 5, gInterfaceWindowBuffer + 14 * gInterfaceBarWidth + 316 + gInterfaceBarContentOffset + index * 9, gInterfaceBarWidth); } if (!gInterfaceBarInitialized) { @@ -1377,7 +1346,7 @@ int _intface_update_ammo_lights() } } - interfaceUpdateAmmoBar(463 + ifaceOffset, ratio); + interfaceUpdateAmmoBar(463 + gInterfaceBarContentOffset, ratio); return 0; } @@ -1413,7 +1382,7 @@ void interfaceBarEndButtonsShow(bool animated) if (getTicksSince(time) >= delay) { unsigned char* src = artGetFrameData(art, frame, 0); if (src != NULL) { - blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset, gInterfaceBarWidth); + blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + gInterfaceBarContentOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } @@ -1427,7 +1396,7 @@ void interfaceBarEndButtonsShow(bool animated) } } else { unsigned char* src = artGetFrameData(art, frameCount - 1, 0); - blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset, gInterfaceBarWidth); + blitBufferToBuffer(src, 57, 58, 57, gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + gInterfaceBarContentOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } @@ -1471,7 +1440,7 @@ void interfaceBarEndButtonsHide(bool animated) if (getTicksSince(time) >= delay) { unsigned char* src = artGetFrameData(art, frame - 1, 0); - unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset; + unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + gInterfaceBarContentOffset; if (src != NULL) { blitBufferToBuffer(src, 57, 58, 57, dest, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); @@ -1486,7 +1455,7 @@ void interfaceBarEndButtonsHide(bool animated) sharedFpsLimiter.throttle(); } } else { - unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + ifaceOffset; + unsigned char* dest = gInterfaceWindowBuffer + gInterfaceBarWidth * 38 + 580 + gInterfaceBarContentOffset; unsigned char* src = artGetFrameData(art, 0, 0); blitBufferToBuffer(src, 57, 58, 57, dest, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); @@ -1511,7 +1480,7 @@ void interfaceBarEndButtonsRenderGreenLights() } soundPlayFile("icombat2"); - blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * gInterfaceBarWidth + 580 + ifaceOffset, gInterfaceBarWidth); + blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * gInterfaceBarWidth + 580 + gInterfaceBarContentOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } } @@ -1531,7 +1500,7 @@ void interfaceBarEndButtonsRenderRedLights() } soundPlayFile("icombat1"); - blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * gInterfaceBarWidth + 580 + ifaceOffset, gInterfaceBarWidth); + blitBufferToBufferTrans(lightsFrmImage.getData(), 57, 58, 57, gInterfaceWindowBuffer + 38 * gInterfaceBarWidth + 580 + gInterfaceBarContentOffset, gInterfaceBarWidth); windowRefreshRect(gInterfaceBarWindow, &gInterfaceBarEndButtonsRect); } } @@ -1907,7 +1876,7 @@ static int endTurnButtonInit() return -1; } - gEndTurnButton = buttonCreate(gInterfaceBarWindow, 590 + ifaceOffset, 43, 38, 22, -1, -1, -1, 32, _endTurnButtonNormalFrmImage.getData(), _endTurnButtonPressedFrmImage.getData(), NULL, 0); + gEndTurnButton = buttonCreate(gInterfaceBarWindow, 590 + gInterfaceBarContentOffset, 43, 38, 22, -1, -1, -1, 32, _endTurnButtonNormalFrmImage.getData(), _endTurnButtonPressedFrmImage.getData(), NULL, 0); if (gEndTurnButton == -1) { return -1; } @@ -1959,7 +1928,7 @@ static int endCombatButtonInit() return -1; } - gEndCombatButton = buttonCreate(gInterfaceBarWindow, 590 + ifaceOffset, 65, 38, 22, -1, -1, -1, 13, _endCombatButtonNormalFrmImage.getData(), _endCombatButtonPressedFrmImage.getData(), NULL, 0); + gEndCombatButton = buttonCreate(gInterfaceBarWindow, 590 + gInterfaceBarContentOffset, 65, 38, 22, -1, -1, -1, 13, _endCombatButtonNormalFrmImage.getData(), _endCombatButtonPressedFrmImage.getData(), NULL, 0); if (gEndCombatButton == -1) { return -1; } @@ -2486,4 +2455,45 @@ bool indicatorBarHide() return oldIsVisible; } +static void customInterfaceBarInit() +{ + gInterfaceBarContentOffset = gInterfaceBarWidth - 640; + + char path[COMPAT_MAX_PATH]; + sprintf(path, "art\\intrface\\HR_IFACE_%d.FRM", gInterfaceBarWidth); + + int size; + if (dbGetFileSize(path, &size) != 0 || gInterfaceBarContentOffset <= 0 || screenGetWidth() <= 640) { + gInterfaceBarContentOffset = 0; + gInterfaceBarWidth = 640; + gInterfaceBarIsCustom = false; + } else { + gInterfaceBarIsCustom = true; + + gCustomInterfaceBarBackground = (Art*)(malloc(size)); + if (artRead(path, (unsigned char*)gCustomInterfaceBarBackground) != 0) { + gInterfaceBarIsCustom = false; + free(gCustomInterfaceBarBackground); + gCustomInterfaceBarBackground = nullptr; + } + } +} + +static void customInterfaceBarExit() +{ + if (gCustomInterfaceBarBackground != nullptr) { + free(gCustomInterfaceBarBackground); + gCustomInterfaceBarBackground = nullptr; + } +} + +unsigned char* customInterfaceBarGetBackgroundImageData() +{ + if (!gInterfaceBarIsCustom) { + return nullptr; + } + + return artGetFrameData(gCustomInterfaceBarBackground, 0, 0); +} + } // namespace fallout diff --git a/src/interface.h b/src/interface.h index f0590de8..fee94e90 100644 --- a/src/interface.h +++ b/src/interface.h @@ -34,8 +34,8 @@ typedef enum InterfaceItemAction { extern int gInterfaceBarWindow; extern bool gInterfaceBarMode; extern int gInterfaceBarWidth; -extern bool gInterfaceCustomBar; -extern int ifaceOffset; +extern bool gInterfaceBarIsCustom; +extern int gInterfaceBarContentOffset; int interfaceInit(); void interfaceReset(); @@ -68,7 +68,7 @@ int indicatorBarRefresh(); bool indicatorBarShow(); bool indicatorBarHide(); -unsigned char* GetCustomIfaceBarImageData(); +unsigned char* customInterfaceBarGetBackgroundImageData(); } // namespace fallout