From f9b285ef2d6fc1dc817e78c347dcf7bafc71baf1 Mon Sep 17 00:00:00 2001 From: Vsevolod Kremianskii Date: Fri, 6 Nov 2020 14:02:17 +0700 Subject: [PATCH] fix: Fix loading party member portraits --- src/game/blueprint/creature.cpp | 5 +++++ src/game/blueprint/creature.h | 2 ++ src/game/gui/chargen/chargen.cpp | 2 +- src/game/gui/partyselect.cpp | 2 +- src/game/object/creature.cpp | 4 ++++ src/game/portraits.cpp | 7 ++++++- src/game/portraits.h | 3 ++- 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/game/blueprint/creature.cpp b/src/game/blueprint/creature.cpp index 8064cd57..1b2ceacd 100644 --- a/src/game/blueprint/creature.cpp +++ b/src/game/blueprint/creature.cpp @@ -39,6 +39,7 @@ void CreatureBlueprint::load(const GffStruct &utc) { } _appearance = utc.getInt("Appearance_Type"); + _portraitId = utc.getInt("PortraitId", -1); _conversation = utc.getString("Conversation"); loadAttributes(utc); @@ -89,6 +90,10 @@ int CreatureBlueprint::appearance() const { return _appearance; } +int CreatureBlueprint::portraitId() const { + return _portraitId; +} + const string &CreatureBlueprint::conversation() const { return _conversation; } diff --git a/src/game/blueprint/creature.h b/src/game/blueprint/creature.h index aa5b3a3c..f7f612c5 100644 --- a/src/game/blueprint/creature.h +++ b/src/game/blueprint/creature.h @@ -38,6 +38,7 @@ public: const std::string &tag() const; const std::vector &equipment() const; int appearance() const; + int portraitId() const; const std::string &conversation() const; const CreatureAttributes &attributes() const; const std::string &onSpawn() const; @@ -47,6 +48,7 @@ private: std::string _tag; std::vector _equipment; int _appearance { 0 }; + int _portraitId { -1 }; std::string _conversation; CreatureAttributes _attributes; diff --git a/src/game/gui/chargen/chargen.cpp b/src/game/gui/chargen/chargen.cpp index a2731bea..7e6d54c0 100644 --- a/src/game/gui/chargen/chargen.cpp +++ b/src/game/gui/chargen/chargen.cpp @@ -208,7 +208,7 @@ void CharacterGeneration::loadCharacterModel() { lblModel.setScene3D(move(scene)); - string portrait(findPortrait(_character.appearance)); + string portrait(getPortraitByAppearance(_character.appearance)); if (!portrait.empty()) { Control &lblPortrait = getControl("PORTRAIT_LBL"); lblPortrait.setBorderFill(portrait); diff --git a/src/game/gui/partyselect.cpp b/src/game/gui/partyselect.cpp index 00c91d1c..d122464b 100644 --- a/src/game/gui/partyselect.cpp +++ b/src/game/gui/partyselect.cpp @@ -111,7 +111,7 @@ void PartySelection::prepare(const Context &ctx) { if (maybePortrait != g_portraitByAppearance.end()) { portrait = maybePortrait->second; } else { - portrait = findPortrait(blueprint->appearance()); + portrait = getPortraitByAppearance(blueprint->appearance()); } btnNpc.setDisabled(false); lblChar.setBorderFill(Textures::instance().get(portrait, TextureType::GUI)); diff --git a/src/game/object/creature.cpp b/src/game/object/creature.cpp index bc789cb9..030478d0 100644 --- a/src/game/object/creature.cpp +++ b/src/game/object/creature.cpp @@ -30,6 +30,7 @@ #include "../../system/streamutil.h" #include "../blueprint/blueprints.h" +#include "../portraits.h" #include "../script/util.h" #include "objectfactory.h" @@ -94,6 +95,9 @@ void Creature::load(const shared_ptr &blueprint) { shared_ptr appearance(Resources::instance().get2DA("appearance")); loadAppearance(*appearance, _blueprint->appearance()); + string portrait(getPortrait(_blueprint->portraitId())); + _portrait = Textures::instance().get(portrait, TextureType::GUI); + _attributes = blueprint->attributes(); _onSpawn = blueprint->onSpawn(); _onUserDefined = blueprint->onUserDefined(); diff --git a/src/game/portraits.cpp b/src/game/portraits.cpp index bf82ae6f..e19f24a4 100644 --- a/src/game/portraits.cpp +++ b/src/game/portraits.cpp @@ -27,7 +27,12 @@ namespace reone { namespace game { -string findPortrait(int appearance) { +string getPortrait(int id) { + shared_ptr table(Resources::instance().get2DA("portraits")); + return table->getString(id, "baseresref"); +} + +string getPortraitByAppearance(int appearance) { shared_ptr table(Resources::instance().get2DA("portraits")); const TwoDaRow *row = table->findRow([&appearance](const TwoDaRow &row) { diff --git a/src/game/portraits.h b/src/game/portraits.h index 63aefbe0..ae266283 100644 --- a/src/game/portraits.h +++ b/src/game/portraits.h @@ -23,7 +23,8 @@ namespace reone { namespace game { -std::string findPortrait(int appearance); +std::string getPortrait(int id); +std::string getPortraitByAppearance(int appearance); } // namespace game