Fix inventory window position

See #3
This commit is contained in:
Alexander Batalov 2022-05-22 13:33:41 +03:00
parent 1267b8ddfb
commit be81049ff5
1 changed files with 189 additions and 94 deletions

View File

@ -37,6 +37,78 @@
#include <assert.h>
#include <stdio.h>
#define INVENTORY_LARGE_SLOT_WIDTH 90
#define INVENTORY_LARGE_SLOT_HEIGHT 61
#define INVENTORY_SLOT_WIDTH 64
#define INVENTORY_SLOT_HEIGHT 48
#define INVENTORY_LEFT_HAND_SLOT_X 154
#define INVENTORY_LEFT_HAND_SLOT_Y 286
#define INVENTORY_LEFT_HAND_SLOT_MAX_X (INVENTORY_LEFT_HAND_SLOT_X + INVENTORY_LARGE_SLOT_WIDTH)
#define INVENTORY_LEFT_HAND_SLOT_MAX_Y (INVENTORY_LEFT_HAND_SLOT_Y + INVENTORY_LARGE_SLOT_HEIGHT)
#define INVENTORY_RIGHT_HAND_SLOT_X 245
#define INVENTORY_RIGHT_HAND_SLOT_Y 286
#define INVENTORY_RIGHT_HAND_SLOT_MAX_X (INVENTORY_RIGHT_HAND_SLOT_X + INVENTORY_LARGE_SLOT_WIDTH)
#define INVENTORY_RIGHT_HAND_SLOT_MAX_Y (INVENTORY_RIGHT_HAND_SLOT_Y + INVENTORY_LARGE_SLOT_HEIGHT)
#define INVENTORY_ARMOR_SLOT_X 154
#define INVENTORY_ARMOR_SLOT_Y 183
#define INVENTORY_ARMOR_SLOT_MAX_X (INVENTORY_ARMOR_SLOT_X + INVENTORY_LARGE_SLOT_WIDTH)
#define INVENTORY_ARMOR_SLOT_MAX_Y (INVENTORY_ARMOR_SLOT_Y + INVENTORY_LARGE_SLOT_HEIGHT)
#define INVENTORY_TRADE_LEFT_SCROLLER_X 29
#define INVENTORY_TRADE_RIGHT_SCROLLER_X 395
#define INVENTORY_TRADE_INNER_LEFT_SCROLLER_X 165
#define INVENTORY_TRADE_INNER_RIGHT_SCROLLER_X 250
#define INVENTORY_TRADE_OUTER_SCROLLER_Y 35
#define INVENTORY_TRADE_INNER_SCROLLER_Y 20
#define INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_X 165
#define INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_Y 10
#define INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_MAX_X (INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_X + INVENTORY_SLOT_WIDTH)
#define INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_X 0
#define INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_Y 10
#define INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_MAX_X (INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_X + INVENTORY_SLOT_WIDTH)
#define INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_X 250
#define INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_Y 10
#define INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_MAX_X (INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_X + INVENTORY_SLOT_WIDTH)
#define INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_X 395
#define INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_Y 10
#define INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_MAX_X (INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_X + INVENTORY_SLOT_WIDTH)
#define INVENTORY_LOOT_LEFT_SCROLLER_X 176
#define INVENTORY_LOOT_LEFT_SCROLLER_Y 37
#define INVENTORY_LOOT_LEFT_SCROLLER_MAX_X (INVENTORY_LOOT_LEFT_SCROLLER_X + INVENTORY_SLOT_WIDTH)
#define INVENTORY_LOOT_RIGHT_SCROLLER_X 297
#define INVENTORY_LOOT_RIGHT_SCROLLER_Y 37
#define INVENTORY_LOOT_RIGHT_SCROLLER_MAX_X (INVENTORY_LOOT_RIGHT_SCROLLER_X + INVENTORY_SLOT_WIDTH)
#define INVENTORY_SCROLLER_X 44
#define INVENTORY_SCROLLER_Y 35
#define INVENTORY_SCROLLER_MAX_X (INVENTORY_SCROLLER_X + INVENTORY_SLOT_WIDTH)
#define INVENTORY_BODY_VIEW_WIDTH 60
#define INVENTORY_BODY_VIEW_HEIGHT 100
#define INVENTORY_PC_BODY_VIEW_X 176
#define INVENTORY_PC_BODY_VIEW_Y 37
#define INVENTORY_PC_BODY_VIEW_MAX_X (INVENTORY_PC_BODY_VIEW_X + INVENTORY_BODY_VIEW_WIDTH)
#define INVENTORY_PC_BODY_VIEW_MAX_Y (INVENTORY_PC_BODY_VIEW_Y + INVENTORY_BODY_VIEW_HEIGHT)
#define INVENTORY_LOOT_RIGHT_BODY_VIEW_X 422
#define INVENTORY_LOOT_RIGHT_BODY_VIEW_Y 35
#define INVENTORY_LOOT_LEFT_BODY_VIEW_X 44
#define INVENTORY_LOOT_LEFT_BODY_VIEW_Y 35
// 0x46E6D0
const int dword_46E6D0[7] = {
STAT_CURRENT_HIT_POINTS,
@ -470,9 +542,22 @@ bool _setup_inventory(int inventoryWindowType)
if (inventoryWindowType <= INVENTORY_WINDOW_TYPE_LOOT) {
const InventoryWindowDescription* windowDescription = &(gInventoryWindowDescriptions[inventoryWindowType]);
gInventoryWindow = windowCreate(80, 0, windowDescription->width, windowDescription->height, 257, 20);
gInventoryWindowMaxX = windowDescription->width + 80;
gInventoryWindowMaxY = windowDescription->height;
// Maintain original position in original resolution, otherwise center it.
int inventoryWindowX = screenGetWidth() != 640
? (screenGetWidth() - windowDescription->width) / 2
: 80;
int inventoryWindowY = screenGetHeight() != 480
? (screenGetHeight() - windowDescription->height) / 2
: 0;
gInventoryWindow = windowCreate(inventoryWindowX,
inventoryWindowY,
windowDescription->width,
windowDescription->height,
257,
WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
gInventoryWindowMaxX = windowDescription->width + inventoryWindowX;
gInventoryWindowMaxY = windowDescription->height + inventoryWindowY;
unsigned char* dest = windowGetBuffer(gInventoryWindow);
int backgroundFid = buildFid(6, windowDescription->field_0, 0, 0, 0);
@ -492,13 +577,16 @@ bool _setup_inventory(int inventoryWindowType)
gInventorySlotsCount = 3;
gInventoryWindow = windowCreate(80, 290, 480, 180, 257, 0);
gInventoryWindowMaxX = 560;
gInventoryWindowMaxY = 470;
// Trade inventory window is a part of game dialog, which is 640x480.
int tradeWindowX = (screenGetWidth() - 640) / 2 + 80;
int tradeWindowY = (screenGetHeight() - 480) / 2 + 290;
gInventoryWindow = windowCreate(tradeWindowX, tradeWindowY, 480, 180, 257, 0);
gInventoryWindowMaxX = tradeWindowX + 480;
gInventoryWindowMaxY = tradeWindowY + 180;
unsigned char* dest = windowGetBuffer(gInventoryWindow);
unsigned char* src = windowGetBuffer(_barter_back_win);
blitBufferToBuffer(src + 80, 480, 180, _scr_size.right - _scr_size.left + 1, dest, 480);
blitBufferToBuffer(src + 80, 480, 180, 640, dest, 480);
gInventoryPrintItemDescriptionHandler = gameDialogRenderSupplementaryMessage;
}
@ -507,14 +595,14 @@ bool _setup_inventory(int inventoryWindowType)
// Create invsibile buttons representing character's inventory item
// slots.
for (int index = 0; index < gInventorySlotsCount; index++) {
int btn = buttonCreate(gInventoryWindow, 176, 48 * (gInventorySlotsCount - index - 1) + 37, 64, 48, 999 + gInventorySlotsCount - index, -1, 999 + gInventorySlotsCount - index, -1, NULL, NULL, NULL, 0);
int btn = buttonCreate(gInventoryWindow, INVENTORY_LOOT_LEFT_SCROLLER_X, INVENTORY_SLOT_HEIGHT * (gInventorySlotsCount - index - 1) + INVENTORY_LOOT_LEFT_SCROLLER_Y, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, 999 + gInventorySlotsCount - index, -1, 999 + gInventorySlotsCount - index, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
}
int eventCode = 2005;
int y = 277;
int y = INVENTORY_SLOT_HEIGHT * 5 + INVENTORY_SLOT_HEIGHT;
// Create invisible buttons representing container's inventory item
// slots. For unknown reason it loops backwards and it's size is
@ -524,56 +612,56 @@ bool _setup_inventory(int inventoryWindowType)
// which is a bit awkward for a loop. Probably result of some
// optimization.
for (int index = 0; index < 6; index++) {
int btn = buttonCreate(gInventoryWindow, 297, y, 64, 48, eventCode, -1, eventCode, -1, NULL, NULL, NULL, 0);
int btn = buttonCreate(gInventoryWindow, INVENTORY_LOOT_RIGHT_SCROLLER_X, y, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, eventCode, -1, eventCode, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
eventCode -= 1;
y -= 48;
y -= INVENTORY_SLOT_HEIGHT;
}
} else if (inventoryWindowType == INVENTORY_WINDOW_TYPE_TRADE) {
int y1 = 35;
int y2 = 20;
int y1 = INVENTORY_TRADE_OUTER_SCROLLER_Y;
int y2 = INVENTORY_TRADE_INNER_SCROLLER_Y;
for (int index = 0; index < gInventorySlotsCount; index++) {
int btn;
// Invsibile button representing left inventory slot.
btn = buttonCreate(gInventoryWindow, 29, y1, 64, 48, 1000 + index, -1, 1000 + index, -1, NULL, NULL, NULL, 0);
btn = buttonCreate(gInventoryWindow, INVENTORY_TRADE_LEFT_SCROLLER_X, y1, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, 1000 + index, -1, 1000 + index, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
// Invisible button representing right inventory slot.
btn = buttonCreate(gInventoryWindow, 395, y1, 64, 48, 2000 + index, -1, 2000 + index, -1, NULL, NULL, NULL, 0);
btn = buttonCreate(gInventoryWindow, INVENTORY_TRADE_RIGHT_SCROLLER_X, y1, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, 2000 + index, -1, 2000 + index, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
// Invisible button representing left suggested slot.
btn = buttonCreate(gInventoryWindow, 165, y2, 64, 48, 2300 + index, -1, 2300 + index, -1, NULL, NULL, NULL, 0);
btn = buttonCreate(gInventoryWindow, INVENTORY_TRADE_INNER_LEFT_SCROLLER_X, y2, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, 2300 + index, -1, 2300 + index, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
// Invisible button representing right suggested slot.
btn = buttonCreate(gInventoryWindow, 250, y2, 64, 48, 2400 + index, -1, 2400 + index, -1, NULL, NULL, NULL, 0);
btn = buttonCreate(gInventoryWindow, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_X, y2, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, 2400 + index, -1, 2400 + index, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
y1 += 48;
y2 += 48;
y1 += INVENTORY_SLOT_HEIGHT;
y2 += INVENTORY_SLOT_HEIGHT;
}
} else {
// Create invisible buttons representing item slots.
for (int index = 0; index < gInventorySlotsCount; index++) {
int btn = buttonCreate(gInventoryWindow,
44,
48 * (gInventorySlotsCount - index - 1) + 35,
64,
48,
INVENTORY_SCROLLER_X,
INVENTORY_SLOT_HEIGHT * (gInventorySlotsCount - index - 1) + INVENTORY_SCROLLER_Y,
INVENTORY_SLOT_WIDTH,
INVENTORY_SLOT_HEIGHT,
999 + gInventorySlotsCount - index,
-1,
999 + gInventorySlotsCount - index,
@ -592,19 +680,19 @@ bool _setup_inventory(int inventoryWindowType)
int btn;
// Item2 slot
btn = buttonCreate(gInventoryWindow, 245, 286, 90, 61, 1006, -1, 1006, -1, NULL, NULL, NULL, 0);
btn = buttonCreate(gInventoryWindow, INVENTORY_RIGHT_HAND_SLOT_X, INVENTORY_RIGHT_HAND_SLOT_Y, INVENTORY_LARGE_SLOT_WIDTH, INVENTORY_LARGE_SLOT_HEIGHT, 1006, -1, 1006, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
// Item1 slot
btn = buttonCreate(gInventoryWindow, 154, 286, 90, 61, 1007, -1, 1007, -1, NULL, NULL, NULL, 0);
btn = buttonCreate(gInventoryWindow, INVENTORY_LEFT_HAND_SLOT_X, INVENTORY_LEFT_HAND_SLOT_Y, INVENTORY_LARGE_SLOT_WIDTH, INVENTORY_LARGE_SLOT_HEIGHT, 1007, -1, 1007, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
// Armor slot
btn = buttonCreate(gInventoryWindow, 154, 183, 90, 61, 1008, -1, 1008, -1, NULL, NULL, NULL, 0);
btn = buttonCreate(gInventoryWindow, INVENTORY_ARMOR_SLOT_X, INVENTORY_ARMOR_SLOT_Y, INVENTORY_LARGE_SLOT_WIDTH, INVENTORY_LARGE_SLOT_HEIGHT, 1008, -1, 1008, -1, NULL, NULL, NULL, 0);
if (btn != -1) {
buttonSetMouseCallbacks(btn, inventoryItemSlotOnMouseEnter, inventoryItemSlotOnMouseExit, NULL, NULL);
}
@ -733,10 +821,10 @@ bool _setup_inventory(int inventoryWindowType)
}
// Invisible button representing left character.
buttonCreate(_barter_back_win, 15, 25, 60, 100, -1, -1, 2500, -1, NULL, NULL, NULL, 0);
buttonCreate(_barter_back_win, 15, 25, INVENTORY_BODY_VIEW_WIDTH, INVENTORY_BODY_VIEW_HEIGHT, -1, -1, 2500, -1, NULL, NULL, NULL, 0);
// Invisible button representing right character.
buttonCreate(_barter_back_win, 560, 25, 60, 100, -1, -1, 2501, -1, NULL, NULL, NULL, 0);
buttonCreate(_barter_back_win, 560, 25, INVENTORY_BODY_VIEW_WIDTH, INVENTORY_BODY_VIEW_HEIGHT, -1, -1, 2501, -1, NULL, NULL, NULL, 0);
}
} else {
// Large arrow down (normal).
@ -760,7 +848,7 @@ bool _setup_inventory(int inventoryWindowType)
if (inventoryWindowType == INVENTORY_WINDOW_TYPE_LOOT) {
// Invisible button representing left character.
buttonCreate(gInventoryWindow, 44, 35, 60, 100, -1, -1, 2500, -1, NULL, NULL, NULL, 0);
buttonCreate(gInventoryWindow, INVENTORY_LOOT_LEFT_BODY_VIEW_X, INVENTORY_LOOT_LEFT_BODY_VIEW_Y, INVENTORY_BODY_VIEW_WIDTH, INVENTORY_BODY_VIEW_HEIGHT, -1, -1, 2500, -1, NULL, NULL, NULL, 0);
// Right inventory down button.
gSecondaryInventoryScrollDownButton = buttonCreate(gInventoryWindow, 379, 62, 22, 23, -1, -1, KEY_CTRL_ARROW_DOWN, -1, buttonUpData, buttonDownData, 0, 0);
@ -771,10 +859,10 @@ bool _setup_inventory(int inventoryWindowType)
}
// Invisible button representing right character.
buttonCreate(gInventoryWindow, 422, 35, 60, 100, -1, -1, 2501, -1, NULL, NULL, NULL, 0);
buttonCreate(gInventoryWindow, INVENTORY_LOOT_RIGHT_BODY_VIEW_X, INVENTORY_LOOT_RIGHT_BODY_VIEW_Y, INVENTORY_BODY_VIEW_WIDTH, INVENTORY_BODY_VIEW_HEIGHT, -1, -1, 2501, -1, NULL, NULL, NULL, 0);
} else {
// Invisible button representing character (in inventory and use on dialogs).
buttonCreate(gInventoryWindow, 176, 37, 60, 100, -1, -1, 2500, -1, NULL, NULL, NULL, 0);
buttonCreate(gInventoryWindow, INVENTORY_PC_BODY_VIEW_X, INVENTORY_PC_BODY_VIEW_Y, INVENTORY_BODY_VIEW_WIDTH, INVENTORY_BODY_VIEW_HEIGHT, -1, -1, 2500, -1, NULL, NULL, NULL, 0);
}
}
}
@ -981,10 +1069,10 @@ void _display_inventory(int a1, int a2, int inventoryWindowType)
unsigned char* backgroundFrmData = artLockFrameData(backgroundFid, 0, 0, &backgroundFrmHandle);
if (backgroundFrmData != NULL) {
// Clear scroll view background.
blitBufferToBuffer(backgroundFrmData + pitch * 35 + 44, 64, gInventorySlotsCount * 48, pitch, windowBuffer + pitch * 35 + 44, pitch);
blitBufferToBuffer(backgroundFrmData + pitch * 35 + 44, INVENTORY_SLOT_WIDTH, gInventorySlotsCount * INVENTORY_SLOT_HEIGHT, pitch, windowBuffer + pitch * 35 + 44, pitch);
// Clear armor button background.
blitBufferToBuffer(backgroundFrmData + pitch * 183 + 154, 90, 61, pitch, windowBuffer + pitch * 183 + 154, pitch);
blitBufferToBuffer(backgroundFrmData + pitch * INVENTORY_ARMOR_SLOT_Y + INVENTORY_ARMOR_SLOT_X, INVENTORY_LARGE_SLOT_WIDTH, INVENTORY_LARGE_SLOT_HEIGHT, pitch, windowBuffer + pitch * INVENTORY_ARMOR_SLOT_Y + INVENTORY_ARMOR_SLOT_X, pitch);
if (gInventoryLeftHandItem != NULL && gInventoryLeftHandItem == gInventoryRightHandItem) {
// Clear item1.
@ -1001,7 +1089,7 @@ void _display_inventory(int a1, int a2, int inventoryWindowType)
}
} else {
// Clear both items in one go.
blitBufferToBuffer(backgroundFrmData + pitch * 286 + 154, 180, 61, pitch, windowBuffer + pitch * 286 + 154, pitch);
blitBufferToBuffer(backgroundFrmData + pitch * INVENTORY_LEFT_HAND_SLOT_Y + INVENTORY_LEFT_HAND_SLOT_X, INVENTORY_LARGE_SLOT_WIDTH * 2, INVENTORY_LARGE_SLOT_HEIGHT, pitch, windowBuffer + pitch * INVENTORY_LEFT_HAND_SLOT_Y + INVENTORY_LEFT_HAND_SLOT_X, pitch);
}
artUnlock(backgroundFrmHandle);
@ -1035,7 +1123,7 @@ void _display_inventory(int a1, int a2, int inventoryWindowType)
windowBuffer = windowGetBuffer(gInventoryWindow);
blitBufferToBuffer(windowGetBuffer(_barter_back_win) + 35 * (_scr_size.right - _scr_size.left + 1) + 100, 64, 48 * gInventorySlotsCount, _scr_size.right - _scr_size.left + 1, windowBuffer + pitch * 35 + 20, pitch);
blitBufferToBuffer(windowGetBuffer(_barter_back_win) + 35 * 640 + 100, 64, 48 * gInventorySlotsCount, 640, windowBuffer + pitch * 35 + 20, pitch);
v49 = -20;
} else {
assert(false && "Should be unreachable");
@ -1097,19 +1185,19 @@ void _display_inventory(int a1, int a2, int inventoryWindowType)
if (inventoryWindowType == INVENTORY_WINDOW_TYPE_NORMAL) {
if (gInventoryRightHandItem != NULL) {
int width = gInventoryRightHandItem == gInventoryLeftHandItem ? 180 : 90;
int width = gInventoryRightHandItem == gInventoryLeftHandItem ? INVENTORY_LARGE_SLOT_WIDTH * 2 : INVENTORY_LARGE_SLOT_WIDTH;
int inventoryFid = itemGetInventoryFid(gInventoryRightHandItem);
artRender(inventoryFid, windowBuffer + 499 * 286 + 245, width, 61, 499);
artRender(inventoryFid, windowBuffer + 499 * INVENTORY_RIGHT_HAND_SLOT_Y + INVENTORY_RIGHT_HAND_SLOT_X, width, INVENTORY_LARGE_SLOT_HEIGHT, 499);
}
if (gInventoryLeftHandItem != NULL && gInventoryLeftHandItem != gInventoryRightHandItem) {
int inventoryFid = itemGetInventoryFid(gInventoryLeftHandItem);
artRender(inventoryFid, windowBuffer + 499 * 286 + 154, 90, 61, 499);
artRender(inventoryFid, windowBuffer + 499 * INVENTORY_LEFT_HAND_SLOT_Y + INVENTORY_LEFT_HAND_SLOT_X, INVENTORY_LARGE_SLOT_WIDTH, INVENTORY_LARGE_SLOT_HEIGHT, 499);
}
if (gInventoryArmor != NULL) {
int inventoryFid = itemGetInventoryFid(gInventoryArmor);
artRender(inventoryFid, windowBuffer + 499 * 183 + 154, 90, 61, 499);
artRender(inventoryFid, windowBuffer + 499 * INVENTORY_ARMOR_SLOT_Y + INVENTORY_ARMOR_SLOT_X, INVENTORY_LARGE_SLOT_WIDTH, INVENTORY_LARGE_SLOT_HEIGHT, 499);
}
}
@ -1142,7 +1230,7 @@ void _display_target_inventory(int a1, int a2, Inventory* inventory, int invento
pitch = 480;
unsigned char* src = windowGetBuffer(_barter_back_win);
blitBufferToBuffer(src + (_scr_size.right - _scr_size.left + 1) * 35 + 475, 64, 48 * gInventorySlotsCount, _scr_size.right - _scr_size.left + 1, windowBuffer + 480 * 35 + 395, 480);
blitBufferToBuffer(src + 640 * 35 + 475, 64, 48 * gInventorySlotsCount, 640, windowBuffer + 480 * 35 + 395, 480);
} else {
assert(false && "Should be unreachable");
}
@ -1292,11 +1380,11 @@ void _display_body(int fid, int inventoryWindowType)
unsigned char* frameData = artGetFrameData(art, frame, rotation);
int framePitch = artGetWidth(art, frame, rotation);
int frameWidth = min(framePitch, 60);
int frameWidth = min(framePitch, INVENTORY_BODY_VIEW_WIDTH);
int frameHeight = artGetHeight(art, frame, rotation);
if (frameHeight > 100) {
frameHeight = 100;
if (frameHeight > INVENTORY_BODY_VIEW_HEIGHT) {
frameHeight = INVENTORY_BODY_VIEW_HEIGHT;
}
int win;
@ -1314,24 +1402,24 @@ void _display_body(int fid, int inventoryWindowType)
rect.top = 25;
}
rect.right = rect.left + 60 - 1;
rect.bottom = rect.top + 100 - 1;
rect.right = rect.left + INVENTORY_BODY_VIEW_WIDTH - 1;
rect.bottom = rect.top + INVENTORY_BODY_VIEW_HEIGHT - 1;
int frmId = gGameDialogSpeakerIsPartyMember ? 420 : 111;
int backgroundFid = buildFid(6, frmId, 0, 0, 0);
unsigned char* src = artLockFrameData(backgroundFid, 0, 0, &backrgroundFrmHandle);
if (src != NULL) {
blitBufferToBuffer(src + rect.top * (_scr_size.right - _scr_size.left + 1) + rect.left,
60,
100,
_scr_size.right - _scr_size.left + 1,
blitBufferToBuffer(src + rect.top * 640 + rect.left,
INVENTORY_BODY_VIEW_WIDTH,
INVENTORY_BODY_VIEW_HEIGHT,
640,
windowBuffer + windowPitch * rect.top + rect.left,
windowPitch);
}
blitBufferToBufferTrans(frameData, frameWidth, frameHeight, framePitch,
windowBuffer + windowPitch * (rect.top + (100 - frameHeight) / 2) + (60 - frameWidth) / 2 + rect.left,
windowBuffer + windowPitch * (rect.top + (INVENTORY_BODY_VIEW_HEIGHT - frameHeight) / 2) + (INVENTORY_BODY_VIEW_WIDTH - frameWidth) / 2 + rect.left,
windowPitch);
win = _barter_back_win;
@ -1357,22 +1445,22 @@ void _display_body(int fid, int inventoryWindowType)
}
}
rect.right = rect.left + 60 - 1;
rect.bottom = rect.top + 100 - 1;
rect.right = rect.left + INVENTORY_BODY_VIEW_WIDTH - 1;
rect.bottom = rect.top + INVENTORY_BODY_VIEW_HEIGHT - 1;
int backgroundFid = buildFid(6, 114, 0, 0, 0);
unsigned char* src = artLockFrameData(backgroundFid, 0, 0, &backrgroundFrmHandle);
if (src != NULL) {
blitBufferToBuffer(src + 537 * rect.top + rect.left,
60,
100,
INVENTORY_BODY_VIEW_WIDTH,
INVENTORY_BODY_VIEW_HEIGHT,
537,
windowBuffer + windowPitch * rect.top + rect.left,
windowPitch);
}
blitBufferToBufferTrans(frameData, frameWidth, frameHeight, framePitch,
windowBuffer + windowPitch * (rect.top + (100 - frameHeight) / 2) + (60 - frameWidth) / 2 + rect.left,
windowBuffer + windowPitch * (rect.top + (INVENTORY_BODY_VIEW_HEIGHT - frameHeight) / 2) + (INVENTORY_BODY_VIEW_WIDTH - frameWidth) / 2 + rect.left,
windowPitch);
win = gInventoryWindow;
@ -1478,7 +1566,7 @@ void inventoryItemSlotOnMouseEnter(int btn, int keyCode)
if (gInventoryCursor == INVENTORY_WINDOW_CURSOR_ARROW) {
int x;
int y;
mouseGetPosition(&x, &y);
mouseGetPositionInWindow(gInventoryWindow, &x, &y);
Object* a2a = NULL;
if (_inven_from_button(keyCode, &a2a, NULL, NULL) != 0) {
@ -1581,11 +1669,11 @@ void _inven_pickup(int keyCode, int a2)
int height;
int width;
if (v3 == -1) {
height = 61;
width = 90;
height = INVENTORY_LARGE_SLOT_HEIGHT;
width = INVENTORY_LARGE_SLOT_WIDTH;
} else {
height = 48;
width = 64;
height = INVENTORY_SLOT_HEIGHT;
width = INVENTORY_SLOT_WIDTH;
}
CacheEntry* backgroundFrmHandle;
@ -1642,10 +1730,10 @@ void _inven_pickup(int keyCode, int a2)
soundPlayFile("iputdown");
}
if (_mouse_click_in(124, 35, 188, 48 * gInventorySlotsCount + 35)) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_SCROLLER_X, INVENTORY_SCROLLER_Y, INVENTORY_SCROLLER_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_SCROLLER_Y)) {
int x;
int y;
mouseGetPosition(&x, &y);
mouseGetPositionInWindow(gInventoryWindow, &x, &y);
int v18 = (y - 39) / 48 + a2;
if (v18 < _pud->length) {
@ -1676,19 +1764,19 @@ void _inven_pickup(int keyCode, int a2)
gInventoryRightHandItem = NULL;
}
}
} else if (_mouse_click_in(234, 286, 324, 347)) {
} else if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_LEFT_HAND_SLOT_X, INVENTORY_LEFT_HAND_SLOT_Y, INVENTORY_LEFT_HAND_SLOT_MAX_X, INVENTORY_LEFT_HAND_SLOT_MAX_Y)) {
if (gInventoryLeftHandItem != NULL && itemGetType(gInventoryLeftHandItem) == ITEM_TYPE_CONTAINER && gInventoryLeftHandItem != a1a) {
_drop_into_container(gInventoryLeftHandItem, a1a, v3, v29, count);
} else if (gInventoryLeftHandItem == NULL || _drop_ammo_into_weapon(gInventoryLeftHandItem, a1a, v29, count, keyCode)) {
_switch_hand(a1a, &gInventoryLeftHandItem, v29, keyCode);
}
} else if (_mouse_click_in(325, 286, 415, 347)) {
} else if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_RIGHT_HAND_SLOT_X, INVENTORY_RIGHT_HAND_SLOT_Y, INVENTORY_RIGHT_HAND_SLOT_MAX_X, INVENTORY_RIGHT_HAND_SLOT_MAX_Y)) {
if (gInventoryRightHandItem != NULL && itemGetType(gInventoryRightHandItem) == ITEM_TYPE_CONTAINER && gInventoryRightHandItem != a1a) {
_drop_into_container(gInventoryRightHandItem, a1a, v3, v29, count);
} else if (gInventoryRightHandItem == NULL || _drop_ammo_into_weapon(gInventoryRightHandItem, a1a, v29, count, keyCode)) {
_switch_hand(a1a, &gInventoryRightHandItem, v29, v3);
}
} else if (_mouse_click_in(234, 183, 324, 244)) {
} else if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_ARMOR_SLOT_X, INVENTORY_ARMOR_SLOT_Y, INVENTORY_ARMOR_SLOT_MAX_X, INVENTORY_ARMOR_SLOT_MAX_Y)) {
if (itemGetType(a1a) == ITEM_TYPE_ARMOR) {
Object* v21 = gInventoryArmor;
int v22 = 0;
@ -1719,7 +1807,7 @@ void _inven_pickup(int keyCode, int a2)
gInventoryArmor = a1a;
}
}
} else if (_mouse_click_in(256, 37, 316, 137)) {
} else if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_PC_BODY_VIEW_X, INVENTORY_PC_BODY_VIEW_Y, INVENTORY_PC_BODY_VIEW_MAX_X, INVENTORY_PC_BODY_VIEW_MAX_Y)) {
if (_curr_stack != 0) {
// TODO: Check this _curr_stack - 1, not sure.
_drop_into_container(_stack[_curr_stack - 1], a1a, v3, v29, count);
@ -2897,7 +2985,7 @@ void inventoryWindowOpenContextMenu(int keyCode, int inventoryWindowType)
int x;
int y;
mouseGetPosition(&x, &y);
mouseGetPositionInWindow(gInventoryWindow, &x, &y);
int actionMenuItemsLength;
const int* actionMenuItems;
@ -2992,7 +3080,7 @@ void inventoryWindowOpenContextMenu(int keyCode, int inventoryWindowType)
int x;
int y;
mouseGetPosition(&x, &y);
mouseGetPositionInWindow(gInventoryWindow, &x, &y);
if (y - previousMouseY > 10 || previousMouseY - y > 10) {
if (y >= previousMouseY || menuItemIndex <= 0) {
if (previousMouseY < y && menuItemIndex < actionMenuItemsLength - 1) {
@ -3011,7 +3099,7 @@ void inventoryWindowOpenContextMenu(int keyCode, int inventoryWindowType)
if (inventoryWindowType == INVENTORY_WINDOW_TYPE_TRADE) {
unsigned char* src = windowGetBuffer(_barter_back_win);
int pitch = _scr_size.right - _scr_size.left + 1;
int pitch = 640;
blitBufferToBuffer(src + pitch * rect.top + rect.left + 80,
cursorData->width,
menuButtonHeight,
@ -3616,8 +3704,8 @@ int _move_inventory(Object* a1, int a2, Object* a3, bool a4)
int quantity;
if (a4) {
rect.left = 176;
rect.top = 48 * a2 + 37;
rect.left = INVENTORY_LOOT_LEFT_SCROLLER_X;
rect.top = INVENTORY_SLOT_HEIGHT * a2 + INVENTORY_LOOT_LEFT_SCROLLER_Y;
InventoryItem* inventoryItem = &(_pud->items[_pud->length - (a2 + _stack_offset[_curr_stack] + 1)]);
quantity = inventoryItem->quantity;
@ -3626,8 +3714,8 @@ int _move_inventory(Object* a1, int a2, Object* a3, bool a4)
v38 = false;
}
} else {
rect.left = 297;
rect.top = 48 * a2 + 37;
rect.left = INVENTORY_LOOT_RIGHT_SCROLLER_X;
rect.top = INVENTORY_SLOT_HEIGHT * a2 + INVENTORY_LOOT_RIGHT_SCROLLER_Y;
InventoryItem* inventoryItem = &(_target_pud->items[_target_pud->length - (a2 + _target_stack_offset[_target_curr_stack] + 1)]);
quantity = inventoryItem->quantity;
@ -3645,12 +3733,12 @@ int _move_inventory(Object* a1, int a2, Object* a3, bool a4)
int fid = buildFid(6, 114, 0, 0, 0);
unsigned char* data = artLockFrameData(fid, 0, 0, &handle);
if (data != NULL) {
blitBufferToBuffer(data + 537 * rect.top + rect.left, 64, 48, 537, windowBuffer + 537 * rect.top + rect.left, 537);
blitBufferToBuffer(data + 537 * rect.top + rect.left, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, 537, windowBuffer + 537 * rect.top + rect.left, 537);
artUnlock(handle);
}
rect.right = rect.left + 64 - 1;
rect.bottom = rect.top + 48 - 1;
rect.right = rect.left + INVENTORY_SLOT_WIDTH - 1;
rect.bottom = rect.top + INVENTORY_SLOT_HEIGHT - 1;
windowRefreshRect(gInventoryWindow, &rect);
}
@ -3678,7 +3766,7 @@ int _move_inventory(Object* a1, int a2, Object* a3, bool a4)
MessageListItem messageListItem;
if (a4) {
if (_mouse_click_in(377, 37, 441, 48 * gInventorySlotsCount + 37)) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_LOOT_RIGHT_SCROLLER_X, INVENTORY_LOOT_RIGHT_SCROLLER_Y, INVENTORY_LOOT_RIGHT_SCROLLER_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_LOOT_RIGHT_SCROLLER_Y)) {
int quantityToMove;
if (quantity > 1) {
quantityToMove = inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, a1, quantity);
@ -3707,7 +3795,7 @@ int _move_inventory(Object* a1, int a2, Object* a3, bool a4)
}
}
} else {
if (_mouse_click_in(256, 37, 320, 48 * gInventorySlotsCount + 37)) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_LOOT_LEFT_SCROLLER_X, INVENTORY_LOOT_LEFT_SCROLLER_Y, INVENTORY_LOOT_LEFT_SCROLLER_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_LOOT_LEFT_SCROLLER_Y)) {
int quantityToMove;
if (quantity > 1) {
quantityToMove = inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, a1, quantity);
@ -3862,11 +3950,11 @@ void _barter_move_inventory(Object* a1, int quantity, int a3, int a4, Object* a5
unsigned char* dest = windowGetBuffer(gInventoryWindow);
unsigned char* src = windowGetBuffer(_barter_back_win);
int pitch = _scr_size.right - _scr_size.left + 1;
blitBufferToBuffer(src + pitch * rect.top + rect.left + 80, 64, 48, pitch, dest + 480 * rect.top + rect.left, 480);
int pitch = 640;
blitBufferToBuffer(src + pitch * rect.top + rect.left + 80, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, pitch, dest + 480 * rect.top + rect.left, 480);
rect.right = rect.left + 64 - 1;
rect.bottom = rect.top + 48 - 1;
rect.right = rect.left + INVENTORY_SLOT_WIDTH - 1;
rect.bottom = rect.top + INVENTORY_SLOT_HEIGHT - 1;
windowRefreshRect(gInventoryWindow, &rect);
}
@ -3893,7 +3981,7 @@ void _barter_move_inventory(Object* a1, int quantity, int a3, int a4, Object* a5
MessageListItem messageListItem;
if (a7) {
if (_mouse_click_in(245, 310, 309, 48 * gInventorySlotsCount + 310)) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_X, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_LEFT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, a1, quantity) : 1;
if (quantityToMove != -1) {
if (_item_move_force(_inven_dude, a6, a1, quantityToMove) == -1) {
@ -3906,7 +3994,7 @@ void _barter_move_inventory(Object* a1, int quantity, int a3, int a4, Object* a5
}
}
} else {
if (_mouse_click_in(330, 310, 394, 48 * gInventorySlotsCount + 310)) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_X, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_INNER_RIGHT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, a1, quantity) : 1;
if (quantityToMove != -1) {
if (_item_move_force(a5, a6, a1, quantityToMove) == -1) {
@ -3945,11 +4033,11 @@ void _barter_move_from_table_inventory(Object* a1, int quantity, int a3, Object*
unsigned char* dest = windowGetBuffer(gInventoryWindow);
unsigned char* src = windowGetBuffer(_barter_back_win);
int pitch = _scr_size.right - _scr_size.left + 1;
blitBufferToBuffer(src + pitch * rect.top + rect.left + 80, 64, 48, pitch, dest + 480 * rect.top + rect.left, 480);
int pitch = 640;
blitBufferToBuffer(src + pitch * rect.top + rect.left + 80, INVENTORY_SLOT_WIDTH, INVENTORY_SLOT_HEIGHT, pitch, dest + 480 * rect.top + rect.left, 480);
rect.right = rect.left + 64 - 1;
rect.bottom = rect.top + 48 - 1;
rect.right = rect.left + INVENTORY_SLOT_WIDTH - 1;
rect.bottom = rect.top + INVENTORY_SLOT_HEIGHT - 1;
windowRefreshRect(gInventoryWindow, &rect);
}
@ -3976,7 +4064,7 @@ void _barter_move_from_table_inventory(Object* a1, int quantity, int a3, Object*
MessageListItem messageListItem;
if (a6) {
if (_mouse_click_in(80, 310, 144, 48 * gInventorySlotsCount + 310)) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_X, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_INNER_LEFT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, a1, quantity) : 1;
if (quantityToMove != -1) {
if (_item_move_force(a5, _inven_dude, a1, quantityToMove) == -1) {
@ -3989,7 +4077,7 @@ void _barter_move_from_table_inventory(Object* a1, int quantity, int a3, Object*
}
}
} else {
if (_mouse_click_in(475, 310, 539, 48 * gInventorySlotsCount + 310)) {
if (mouseHitTestInWindow(gInventoryWindow, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_X, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_Y, INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_MAX_X, INVENTORY_SLOT_HEIGHT * gInventorySlotsCount + INVENTORY_TRADE_RIGHT_SCROLLER_TRACKING_Y)) {
int quantityToMove = quantity > 1 ? inventoryQuantitySelect(INVENTORY_WINDOW_TYPE_MOVE_ITEMS, a1, quantity) : 1;
if (quantityToMove != -1) {
if (_item_move_force(a5, a4, a1, quantityToMove) == -1) {
@ -4019,7 +4107,7 @@ void inventoryWindowRenderInnerInventories(int win, Object* a2, Object* a3, int
if (a2 != NULL) {
unsigned char* src = windowGetBuffer(win);
blitBufferToBuffer(src + (_scr_size.right - _scr_size.left + 1) * 20 + 249, 64, v45 + 1, _scr_size.right - _scr_size.left + 1, windowBuffer + 480 * 20 + 169, 480);
blitBufferToBuffer(src + 640 * 20 + 249, 64, v45 + 1, 640, windowBuffer + 480 * 20 + 169, 480);
unsigned char* dest = windowBuffer + 480 * 24 + 169;
Inventory* inventory = &(a2->data.inventory);
@ -4057,7 +4145,7 @@ void inventoryWindowRenderInnerInventories(int win, Object* a2, Object* a3, int
if (a3 != NULL) {
unsigned char* src = windowGetBuffer(win);
blitBufferToBuffer(src + (_scr_size.right - _scr_size.left + 1) * 20 + 334, 64, v45 + 1, _scr_size.right - _scr_size.left + 1, windowBuffer + 480 * 20 + 254, 480);
blitBufferToBuffer(src + 640 * 20 + 334, 64, v45 + 1, 640, windowBuffer + 480 * 20 + 254, 480);
unsigned char* dest = windowBuffer + 480 * 24 + 254;
Inventory* inventory = &(a3->data.inventory);
@ -4729,7 +4817,14 @@ int inventoryQuantityWindowInit(int inventoryWindowType, Object* item)
const InventoryWindowDescription* windowDescription = &(gInventoryWindowDescriptions[inventoryWindowType]);
_mt_wid = windowCreate(windowDescription->x, windowDescription->y, windowDescription->width, windowDescription->height, 257, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
// Maintain original position in original resolution, otherwise center it.
int quantityWindowX = screenGetWidth() != 640
? (screenGetWidth() - windowDescription->width) / 2
: windowDescription->x;
int quantityWindowY = screenGetHeight() != 480
? (screenGetHeight() - windowDescription->height) / 2
: windowDescription->y;
_mt_wid = windowCreate(quantityWindowX, quantityWindowY, windowDescription->width, windowDescription->height, 257, WINDOW_FLAG_0x10 | WINDOW_FLAG_0x04);
unsigned char* windowBuffer = windowGetBuffer(_mt_wid);
CacheEntry* backgroundHandle;
@ -4767,7 +4862,7 @@ int inventoryQuantityWindowInit(int inventoryWindowType, Object* item)
}
int inventoryFid = itemGetInventoryFid(item);
artRender(inventoryFid, windowBuffer + windowDescription->width * 46 + 16, 90, 61, windowDescription->width);
artRender(inventoryFid, windowBuffer + windowDescription->width * 46 + 16, INVENTORY_LARGE_SLOT_WIDTH, INVENTORY_LARGE_SLOT_HEIGHT, windowDescription->width);
int x;
int y;