From 61488d9753b99c186617dc292e17e154ec148494 Mon Sep 17 00:00:00 2001 From: XProger Date: Thu, 10 Jan 2019 07:34:31 +0300 Subject: [PATCH] fix show inventory for non-existent player, show pickups overview in split-screen mode, positioning of health bar in the inventory depending on the player index for split-screen co-op --- src/inventory.h | 11 ++++++++--- src/lara.h | 5 ++++- src/level.h | 22 +++++++++++++--------- src/ui.h | 22 ++++++++++++++++------ 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/inventory.h b/src/inventory.h index ab52356..c6b9408 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -1544,10 +1544,15 @@ struct Inventory { vec2 size = vec2(180, 10); vec2 pos; - if (Core::settings.detail.stereo == Core::Settings::STEREO_VR) + if (Core::settings.detail.stereo == Core::Settings::STEREO_VR) { pos = vec2((UI::width - size.x) * 0.5f - eye * 4.0f, 96); - else - pos = vec2(UI::width - 32 - size.x - eye, 32); + } else { + if (game->getLara(1) && playerIndex == 0) { + pos = vec2(32 - eye, 32); + } else { + pos = vec2(UI::width - 32 - size.x - eye, 32); + } + } UI::renderBar(UI::BAR_HEALTH, pos, size, health); } diff --git a/src/lara.h b/src/lara.h index a7f5898..ade4ea4 100644 --- a/src/lara.h +++ b/src/lara.h @@ -3118,10 +3118,13 @@ struct Lara : Character { if (p.w != 0.0f) { p.x = ( p.x / p.w * 0.5f + 0.5f) * UI::width; p.y = (-p.y / p.w * 0.5f + 0.5f) * UI::height; + if (game->getLara(1)) { + p.x *= 0.5f; + } } else p = vec4(UI::width * 0.5f, UI::height * 0.5f, 0.0f, 0.0f); - UI::addPickup(item->getEntity().type, vec2(p.x, p.y)); + UI::addPickup(item->getEntity().type, camera->cameraIndex, vec2(p.x, p.y)); saveStats.pickups++; } pickupListCount = 0; diff --git a/src/level.h b/src/level.h index 7e74889..e2d2c16 100644 --- a/src/level.h +++ b/src/level.h @@ -1729,15 +1729,17 @@ struct Level : IGame { if ((Input::lastState[0] == cInventory || Input::lastState[1] == cInventory) && !level.isTitle() && inventory->titleTimer < 1.0f && !inventory->active) { int playerIndex = (Input::lastState[0] == cInventory) ? 0 : 1; - if (level.isCutsceneLevel()) { // skip cutscene level - loadNextLevel(); - return; - } + if (getLara(playerIndex)) { + if (level.isCutsceneLevel()) { // skip cutscene level + loadNextLevel(); + return; + } - if (player->health <= 0.0f) - inventory->toggle(playerIndex, Inventory::PAGE_OPTION, TR::Entity::INV_PASSPORT); - else - inventory->toggle(playerIndex); + if (player->health <= 0.0f) + inventory->toggle(playerIndex, Inventory::PAGE_OPTION, TR::Entity::INV_PASSPORT); + else + inventory->toggle(playerIndex); + } } bool invActive = inventory->isActive(); @@ -1769,7 +1771,9 @@ struct Level : IGame { return; } - UI::update(); + if (!inventory->isActive()) { + UI::update(); + } float volWater, volTrack; diff --git a/src/ui.h b/src/ui.h index 10d6f49..2872e15 100644 --- a/src/ui.h +++ b/src/ui.h @@ -296,6 +296,7 @@ namespace UI { struct PickupItem { float time; vec2 pos; + int playerIndex; int modelIndex; Animation *animation; }; @@ -525,6 +526,11 @@ namespace UI { if (helpTipTime > 0.0f) helpTipTime -= Core::deltaTime; + float w = UI::width; + if (game->getLara(1)) { + w *= 0.5f; + } + int i = 0; while (i < pickups.length) { PickupItem &item = pickups[i]; @@ -533,7 +539,7 @@ namespace UI { delete item.animation; pickups.remove(i); } else { - vec2 target = vec2(UI::width - 48.0f - Core::eye * 16.0f - (i % 4) * 96.0f, UI::height - 48.0f - (i / 4) * 96.0f); + vec2 target = vec2(w - 48.0f - Core::eye * 16.0f - (i % 4) * 96.0f, UI::height - 48.0f - (i / 4) * 96.0f); item.pos = item.pos.lerp(target, Core::deltaTime * 5.0f); i++; } @@ -626,16 +632,17 @@ namespace UI { #endif } - void addPickup(TR::Entity::Type type, const vec2 &pos) { + void addPickup(TR::Entity::Type type, int playerIndex, const vec2 &pos) { TR::Level *level = game->getLevel(); PickupItem item; - item.time = PICKUP_SHOW_TIME; - item.pos = pos; - item.modelIndex = level->getModelIndex(TR::Level::convToInv(type)); + item.time = PICKUP_SHOW_TIME; + item.pos = pos; + item.playerIndex = playerIndex; + item.modelIndex = level->getModelIndex(TR::Level::convToInv(type)); if (item.modelIndex <= 0) return; - item.animation = new Animation(level, &level->models[item.modelIndex - 1]); + item.animation = new Animation(level, &level->models[item.modelIndex - 1]); pickups.push(item); } @@ -690,6 +697,9 @@ namespace UI { for (int i = 0; i < pickups.length; i++) { const PickupItem &item = pickups[i]; + if (item.playerIndex != game->getCamera()->cameraIndex) + continue; + float offset = 0.0f; if (item.time < 1.0f) { offset = 1.0f - item.time;