1 #include "repair.hpp" 2 3 #include <components/esm/loadrepa.hpp> 4 5 #include "../mwbase/environment.hpp" 6 #include "../mwbase/windowmanager.hpp" 7 8 #include "../mwworld/ptr.hpp" 9 #include "../mwworld/cellstore.hpp" 10 #include "../mwphysics/physicssystem.hpp" 11 #include "../mwworld/actionrepair.hpp" 12 13 #include "../mwgui/tooltips.hpp" 14 15 #include "../mwrender/objects.hpp" 16 #include "../mwrender/renderinginterface.hpp" 17 18 namespace MWClass 19 { 20 insertObjectRendering(const MWWorld::Ptr & ptr,const std::string & model,MWRender::RenderingInterface & renderingInterface) const21 void Repair::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const 22 { 23 if (!model.empty()) { 24 renderingInterface.getObjects().insertModel(ptr, model); 25 } 26 } 27 insertObject(const MWWorld::Ptr & ptr,const std::string & model,MWPhysics::PhysicsSystem & physics) const28 void Repair::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const 29 { 30 // TODO: add option somewhere to enable collision for placeable objects 31 } 32 getModel(const MWWorld::ConstPtr & ptr) const33 std::string Repair::getModel(const MWWorld::ConstPtr &ptr) const 34 { 35 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 36 37 const std::string &model = ref->mBase->mModel; 38 if (!model.empty()) { 39 return "meshes\\" + model; 40 } 41 return ""; 42 } 43 getName(const MWWorld::ConstPtr & ptr) const44 std::string Repair::getName (const MWWorld::ConstPtr& ptr) const 45 { 46 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 47 const std::string& name = ref->mBase->mName; 48 49 return !name.empty() ? name : ref->mBase->mId; 50 } 51 activate(const MWWorld::Ptr & ptr,const MWWorld::Ptr & actor) const52 std::shared_ptr<MWWorld::Action> Repair::activate (const MWWorld::Ptr& ptr, 53 const MWWorld::Ptr& actor) const 54 { 55 return defaultItemActivate(ptr, actor); 56 } 57 getScript(const MWWorld::ConstPtr & ptr) const58 std::string Repair::getScript (const MWWorld::ConstPtr& ptr) const 59 { 60 const MWWorld::LiveCellRef<ESM::Repair> *ref = 61 ptr.get<ESM::Repair>(); 62 63 return ref->mBase->mScript; 64 } 65 getValue(const MWWorld::ConstPtr & ptr) const66 int Repair::getValue (const MWWorld::ConstPtr& ptr) const 67 { 68 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 69 70 return ref->mBase->mData.mValue; 71 } 72 registerSelf()73 void Repair::registerSelf() 74 { 75 std::shared_ptr<Class> instance (new Repair); 76 77 registerClass (typeid (ESM::Repair).name(), instance); 78 } 79 getUpSoundId(const MWWorld::ConstPtr & ptr) const80 std::string Repair::getUpSoundId (const MWWorld::ConstPtr& ptr) const 81 { 82 return std::string("Item Repair Up"); 83 } 84 getDownSoundId(const MWWorld::ConstPtr & ptr) const85 std::string Repair::getDownSoundId (const MWWorld::ConstPtr& ptr) const 86 { 87 return std::string("Item Repair Down"); 88 } 89 getInventoryIcon(const MWWorld::ConstPtr & ptr) const90 std::string Repair::getInventoryIcon (const MWWorld::ConstPtr& ptr) const 91 { 92 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 93 94 return ref->mBase->mIcon; 95 } 96 hasItemHealth(const MWWorld::ConstPtr & ptr) const97 bool Repair::hasItemHealth (const MWWorld::ConstPtr& ptr) const 98 { 99 return true; 100 } 101 getItemMaxHealth(const MWWorld::ConstPtr & ptr) const102 int Repair::getItemMaxHealth (const MWWorld::ConstPtr& ptr) const 103 { 104 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 105 106 return ref->mBase->mData.mUses; 107 } 108 getToolTipInfo(const MWWorld::ConstPtr & ptr,int count) const109 MWGui::ToolTipInfo Repair::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const 110 { 111 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 112 113 MWGui::ToolTipInfo info; 114 info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count); 115 info.icon = ref->mBase->mIcon; 116 117 std::string text; 118 119 int remainingUses = getItemHealth(ptr); 120 121 text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses); 122 text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality); 123 text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}"); 124 text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}"); 125 126 if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { 127 text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); 128 text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); 129 } 130 131 info.text = text; 132 133 return info; 134 } 135 copyToCellImpl(const MWWorld::ConstPtr & ptr,MWWorld::CellStore & cell) const136 MWWorld::Ptr Repair::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const 137 { 138 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 139 140 return MWWorld::Ptr(cell.insert(ref), &cell); 141 } 142 use(const MWWorld::Ptr & ptr,bool force) const143 std::shared_ptr<MWWorld::Action> Repair::use (const MWWorld::Ptr& ptr, bool force) const 144 { 145 return std::shared_ptr<MWWorld::Action>(new MWWorld::ActionRepair(ptr, force)); 146 } 147 canSell(const MWWorld::ConstPtr & item,int npcServices) const148 bool Repair::canSell (const MWWorld::ConstPtr& item, int npcServices) const 149 { 150 return (npcServices & ESM::NPC::RepairItem) != 0; 151 } 152 getWeight(const MWWorld::ConstPtr & ptr) const153 float Repair::getWeight(const MWWorld::ConstPtr &ptr) const 154 { 155 const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>(); 156 return ref->mBase->mData.mWeight; 157 } 158 } 159