forked from mirror/openmw-tes3mp
Added PC repair feature
This commit is contained in:
parent
78f3f19f62
commit
a2ca679beb
16 changed files with 469 additions and 18 deletions
|
@ -31,7 +31,7 @@ add_openmw_dir (mwgui
|
||||||
confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu
|
confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu
|
||||||
itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog spellcreationdialog
|
itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog spellcreationdialog
|
||||||
enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons
|
enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons
|
||||||
merchantrepair
|
merchantrepair repair
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwdialogue
|
add_openmw_dir (mwdialogue
|
||||||
|
@ -54,7 +54,7 @@ add_openmw_dir (mwworld
|
||||||
containerstore actiontalk actiontake manualref player cellfunctors failedaction
|
containerstore actiontalk actiontake manualref player cellfunctors failedaction
|
||||||
cells localscripts customdata weather inventorystore ptr actionopen actionread
|
cells localscripts customdata weather inventorystore ptr actionopen actionread
|
||||||
actionequip timestamp actionalchemy cellstore actionapply actioneat
|
actionequip timestamp actionalchemy cellstore actionapply actioneat
|
||||||
esmstore store recordcmp fallback
|
esmstore store recordcmp fallback actionrepair
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwclass
|
add_openmw_dir (mwclass
|
||||||
|
@ -65,7 +65,7 @@ add_openmw_dir (mwclass
|
||||||
add_openmw_dir (mwmechanics
|
add_openmw_dir (mwmechanics
|
||||||
mechanicsmanagerimp stat character creaturestats magiceffects movement actors activators
|
mechanicsmanagerimp stat character creaturestats magiceffects movement actors activators
|
||||||
drawstate spells activespells npcstats aipackage aisequence alchemy aiwander aitravel aifollow
|
drawstate spells activespells npcstats aipackage aisequence alchemy aiwander aitravel aifollow
|
||||||
aiescort aiactivate
|
aiescort aiactivate repair
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwbase
|
add_openmw_dir (mwbase
|
||||||
|
|
|
@ -239,6 +239,7 @@ namespace MWBase
|
||||||
virtual void startEnchanting(MWWorld::Ptr actor) = 0;
|
virtual void startEnchanting(MWWorld::Ptr actor) = 0;
|
||||||
virtual void startTraining(MWWorld::Ptr actor) = 0;
|
virtual void startTraining(MWWorld::Ptr actor) = 0;
|
||||||
virtual void startRepair(MWWorld::Ptr actor) = 0;
|
virtual void startRepair(MWWorld::Ptr actor) = 0;
|
||||||
|
virtual void startRepairItem(MWWorld::Ptr item) = 0;
|
||||||
|
|
||||||
virtual void changePointer (const std::string& name) = 0;
|
virtual void changePointer (const std::string& name) = 0;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "../mwworld/cellstore.hpp"
|
#include "../mwworld/cellstore.hpp"
|
||||||
#include "../mwworld/physicssystem.hpp"
|
#include "../mwworld/physicssystem.hpp"
|
||||||
#include "../mwworld/nullaction.hpp"
|
#include "../mwworld/nullaction.hpp"
|
||||||
|
#include "../mwworld/actionrepair.hpp"
|
||||||
|
|
||||||
#include "../mwgui/tooltips.hpp"
|
#include "../mwgui/tooltips.hpp"
|
||||||
|
|
||||||
|
@ -120,6 +121,19 @@ namespace MWClass
|
||||||
return (ref->mBase->mName != "");
|
return (ref->mBase->mName != "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Repair::hasItemHealth (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Repair::getItemMaxHealth (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
||||||
|
ptr.get<ESM::Repair>();
|
||||||
|
|
||||||
|
return ref->mBase->mData.mUses;
|
||||||
|
}
|
||||||
|
|
||||||
MWGui::ToolTipInfo Repair::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
MWGui::ToolTipInfo Repair::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
||||||
{
|
{
|
||||||
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
||||||
|
@ -156,4 +170,9 @@ namespace MWClass
|
||||||
|
|
||||||
return MWWorld::Ptr(&cell.mRepairs.insert(*ref), &cell);
|
return MWWorld::Ptr(&cell.mRepairs.insert(*ref), &cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<MWWorld::Action> Repair::use (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionRepair(ptr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,18 @@ namespace MWClass
|
||||||
///< Return name of inventory icon.
|
///< Return name of inventory icon.
|
||||||
|
|
||||||
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
|
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
|
||||||
|
|
||||||
|
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
|
||||||
|
const;
|
||||||
|
///< Generate action for using via inventory menu (default implementation: return a
|
||||||
|
/// null action).
|
||||||
|
|
||||||
|
virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< \return Item health data available? (default implementation: false)
|
||||||
|
|
||||||
|
virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< Return item max health or throw an exception, if class does not have item health
|
||||||
|
/// (default implementation: throw an exceoption)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
157
apps/openmw/mwgui/repair.cpp
Normal file
157
apps/openmw/mwgui/repair.cpp
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
#include "repair.hpp"
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/player.hpp"
|
||||||
|
#include "../mwworld/containerstore.hpp"
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
#include "widgets.hpp"
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
|
||||||
|
Repair::Repair(MWBase::WindowManager &parWindowManager)
|
||||||
|
: WindowBase("openmw_repair.layout", parWindowManager)
|
||||||
|
{
|
||||||
|
getWidget(mRepairBox, "RepairBox");
|
||||||
|
getWidget(mRepairView, "RepairView");
|
||||||
|
getWidget(mToolBox, "ToolBox");
|
||||||
|
getWidget(mToolIcon, "ToolIcon");
|
||||||
|
getWidget(mUsesLabel, "UsesLabel");
|
||||||
|
getWidget(mQualityLabel, "QualityLabel");
|
||||||
|
getWidget(mCancelButton, "CancelButton");
|
||||||
|
|
||||||
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onCancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Repair::open()
|
||||||
|
{
|
||||||
|
center();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Repair::startRepairItem(const MWWorld::Ptr &item)
|
||||||
|
{
|
||||||
|
mRepair.setTool(item);
|
||||||
|
|
||||||
|
std::string path = std::string("icons\\");
|
||||||
|
path += MWWorld::Class::get(item).getInventoryIcon(item);
|
||||||
|
int pos = path.rfind(".");
|
||||||
|
path.erase(pos);
|
||||||
|
path.append(".dds");
|
||||||
|
mToolIcon->setImageTexture (path);
|
||||||
|
mToolIcon->setUserString("ToolTipType", "ItemPtr");
|
||||||
|
mToolIcon->setUserData(item);
|
||||||
|
|
||||||
|
updateRepairView();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Repair::updateRepairView()
|
||||||
|
{
|
||||||
|
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
||||||
|
mRepair.getTool().get<ESM::Repair>();
|
||||||
|
|
||||||
|
int uses = (mRepair.getTool().getCellRef().mCharge != -1) ? mRepair.getTool().getCellRef().mCharge : ref->mBase->mData.mUses;
|
||||||
|
|
||||||
|
float quality = ref->mBase->mData.mQuality;
|
||||||
|
|
||||||
|
std::stringstream qualityStr;
|
||||||
|
qualityStr << std::setprecision(3) << quality;
|
||||||
|
|
||||||
|
mUsesLabel->setCaptionWithReplacing("#{sUses} " + boost::lexical_cast<std::string>(uses));
|
||||||
|
mQualityLabel->setCaptionWithReplacing("#{sQuality} " + qualityStr.str());
|
||||||
|
|
||||||
|
bool toolBoxVisible = (mRepair.getTool().getRefData().getCount() != 0);
|
||||||
|
mToolBox->setVisible(toolBoxVisible);
|
||||||
|
|
||||||
|
bool toolBoxWasVisible = (mRepairBox->getPosition().top != mToolBox->getPosition().top);
|
||||||
|
|
||||||
|
if (toolBoxVisible && !toolBoxWasVisible)
|
||||||
|
{
|
||||||
|
// shrink
|
||||||
|
mRepairBox->setPosition(mRepairBox->getPosition() + MyGUI::IntPoint(0,mToolBox->getSize().height));
|
||||||
|
mRepairBox->setSize(mRepairBox->getSize() - MyGUI::IntSize(0,mToolBox->getSize().height));
|
||||||
|
}
|
||||||
|
else if (!toolBoxVisible && toolBoxWasVisible)
|
||||||
|
{
|
||||||
|
// expand
|
||||||
|
mRepairBox->setPosition(MyGUI::IntPoint (mRepairBox->getPosition().left, mToolBox->getPosition().top));
|
||||||
|
mRepairBox->setSize(mRepairBox->getSize() + MyGUI::IntSize(0,mToolBox->getSize().height));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (mRepairView->getChildCount())
|
||||||
|
MyGUI::Gui::getInstance().destroyWidget(mRepairView->getChildAt(0));
|
||||||
|
|
||||||
|
int currentY = 0;
|
||||||
|
|
||||||
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
|
int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor;
|
||||||
|
for (MWWorld::ContainerStoreIterator iter (store.begin(categories));
|
||||||
|
iter!=store.end(); ++iter)
|
||||||
|
{
|
||||||
|
if (MWWorld::Class::get(*iter).hasItemHealth(*iter))
|
||||||
|
{
|
||||||
|
int maxDurability = MWWorld::Class::get(*iter).getItemMaxHealth(*iter);
|
||||||
|
int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge;
|
||||||
|
if (maxDurability == durability)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
MyGUI::TextBox* text = mRepairView->createWidget<MyGUI::TextBox> (
|
||||||
|
"SandText", MyGUI::IntCoord(8, currentY, mRepairView->getWidth()-8, 18), MyGUI::Align::Default);
|
||||||
|
text->setCaption(MWWorld::Class::get(*iter).getName(*iter));
|
||||||
|
text->setNeedMouseFocus(false);
|
||||||
|
currentY += 19;
|
||||||
|
|
||||||
|
MyGUI::ImageBox* icon = mRepairView->createWidget<MyGUI::ImageBox> (
|
||||||
|
"ImageBox", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default);
|
||||||
|
std::string path = std::string("icons\\");
|
||||||
|
path += MWWorld::Class::get(*iter).getInventoryIcon(*iter);
|
||||||
|
int pos = path.rfind(".");
|
||||||
|
path.erase(pos);
|
||||||
|
path.append(".dds");
|
||||||
|
icon->setImageTexture (path);
|
||||||
|
icon->setUserString("ToolTipType", "ItemPtr");
|
||||||
|
icon->setUserData(*iter);
|
||||||
|
icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onRepairItem);
|
||||||
|
icon->eventMouseWheel += MyGUI::newDelegate(this, &Repair::onMouseWheel);
|
||||||
|
|
||||||
|
Widgets::MWDynamicStatPtr chargeWidget = mRepairView->createWidget<Widgets::MWDynamicStat>
|
||||||
|
("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default);
|
||||||
|
chargeWidget->setValue(durability, maxDurability);
|
||||||
|
chargeWidget->setNeedMouseFocus(false);
|
||||||
|
|
||||||
|
currentY += 32 + 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mRepairView->setCanvasSize (MyGUI::IntSize(mRepairView->getWidth(), std::max(mRepairView->getHeight(), currentY)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Repair::onCancel(MyGUI::Widget *sender)
|
||||||
|
{
|
||||||
|
mWindowManager.removeGuiMode(GM_Repair);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Repair::onRepairItem(MyGUI::Widget *sender)
|
||||||
|
{
|
||||||
|
if (!mRepair.getTool().getRefData().getCount())
|
||||||
|
return;
|
||||||
|
|
||||||
|
mRepair.repair(*sender->getUserData<MWWorld::Ptr>());
|
||||||
|
|
||||||
|
updateRepairView();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Repair::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
||||||
|
{
|
||||||
|
if (mRepairView->getViewOffset().top + _rel*0.3 > 0)
|
||||||
|
mRepairView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||||
|
else
|
||||||
|
mRepairView->setViewOffset(MyGUI::IntPoint(0, mRepairView->getViewOffset().top + _rel*0.3));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
46
apps/openmw/mwgui/repair.hpp
Normal file
46
apps/openmw/mwgui/repair.hpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#ifndef OPENMW_MWGUI_REPAIR_H
|
||||||
|
#define OPENMW_MWGUI_REPAIR_H
|
||||||
|
|
||||||
|
#include "window_base.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
#include "../mwmechanics/repair.hpp"
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
|
||||||
|
class Repair : public WindowBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Repair(MWBase::WindowManager &parWindowManager);
|
||||||
|
|
||||||
|
virtual void open();
|
||||||
|
|
||||||
|
void startRepairItem (const MWWorld::Ptr& item);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MyGUI::Widget* mRepairBox;
|
||||||
|
MyGUI::ScrollView* mRepairView;
|
||||||
|
|
||||||
|
MyGUI::Widget* mToolBox;
|
||||||
|
|
||||||
|
MyGUI::ImageBox* mToolIcon;
|
||||||
|
|
||||||
|
MyGUI::TextBox* mUsesLabel;
|
||||||
|
MyGUI::TextBox* mQualityLabel;
|
||||||
|
|
||||||
|
MyGUI::Button* mCancelButton;
|
||||||
|
|
||||||
|
MWMechanics::Repair mRepair;
|
||||||
|
|
||||||
|
void updateRepairView();
|
||||||
|
|
||||||
|
void onRepairItem (MyGUI::Widget* sender);
|
||||||
|
void onCancel (MyGUI::Widget* sender);
|
||||||
|
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -56,6 +56,7 @@
|
||||||
#include "cursor.hpp"
|
#include "cursor.hpp"
|
||||||
#include "spellicons.hpp"
|
#include "spellicons.hpp"
|
||||||
#include "merchantrepair.hpp"
|
#include "merchantrepair.hpp"
|
||||||
|
#include "repair.hpp"
|
||||||
|
|
||||||
using namespace MWGui;
|
using namespace MWGui;
|
||||||
|
|
||||||
|
@ -92,6 +93,7 @@ WindowManager::WindowManager(
|
||||||
, mEnchantingDialog(NULL)
|
, mEnchantingDialog(NULL)
|
||||||
, mTrainingWindow(NULL)
|
, mTrainingWindow(NULL)
|
||||||
, mMerchantRepair(NULL)
|
, mMerchantRepair(NULL)
|
||||||
|
, mRepair(NULL)
|
||||||
, mPlayerName()
|
, mPlayerName()
|
||||||
, mPlayerRaceId()
|
, mPlayerRaceId()
|
||||||
, mPlayerAttributes()
|
, mPlayerAttributes()
|
||||||
|
@ -183,6 +185,7 @@ WindowManager::WindowManager(
|
||||||
mEnchantingDialog = new EnchantingDialog(*this);
|
mEnchantingDialog = new EnchantingDialog(*this);
|
||||||
mTrainingWindow = new TrainingWindow(*this);
|
mTrainingWindow = new TrainingWindow(*this);
|
||||||
mMerchantRepair = new MerchantRepair(*this);
|
mMerchantRepair = new MerchantRepair(*this);
|
||||||
|
mRepair = new Repair(*this);
|
||||||
|
|
||||||
mLoadingScreen = new LoadingScreen(mRendering->getScene (), mRendering->getWindow (), *this);
|
mLoadingScreen = new LoadingScreen(mRendering->getScene (), mRendering->getWindow (), *this);
|
||||||
mLoadingScreen->onResChange (w,h);
|
mLoadingScreen->onResChange (w,h);
|
||||||
|
@ -249,6 +252,7 @@ WindowManager::~WindowManager()
|
||||||
delete mCountDialog;
|
delete mCountDialog;
|
||||||
delete mQuickKeysMenu;
|
delete mQuickKeysMenu;
|
||||||
delete mMerchantRepair;
|
delete mMerchantRepair;
|
||||||
|
delete mRepair;
|
||||||
delete mCursor;
|
delete mCursor;
|
||||||
|
|
||||||
cleanupGarbage();
|
cleanupGarbage();
|
||||||
|
@ -308,6 +312,7 @@ void WindowManager::updateVisible()
|
||||||
mEnchantingDialog->setVisible(false);
|
mEnchantingDialog->setVisible(false);
|
||||||
mTrainingWindow->setVisible(false);
|
mTrainingWindow->setVisible(false);
|
||||||
mMerchantRepair->setVisible(false);
|
mMerchantRepair->setVisible(false);
|
||||||
|
mRepair->setVisible(false);
|
||||||
|
|
||||||
mHud->setVisible(mHudEnabled);
|
mHud->setVisible(mHudEnabled);
|
||||||
|
|
||||||
|
@ -436,6 +441,9 @@ void WindowManager::updateVisible()
|
||||||
case GM_MerchantRepair:
|
case GM_MerchantRepair:
|
||||||
mMerchantRepair->setVisible(true);
|
mMerchantRepair->setVisible(true);
|
||||||
break;
|
break;
|
||||||
|
case GM_Repair:
|
||||||
|
mRepair->setVisible(true);
|
||||||
|
break;
|
||||||
case GM_InterMessageBox:
|
case GM_InterMessageBox:
|
||||||
break;
|
break;
|
||||||
case GM_Journal:
|
case GM_Journal:
|
||||||
|
@ -1145,6 +1153,11 @@ void WindowManager::startRepair(MWWorld::Ptr actor)
|
||||||
mMerchantRepair->startRepair(actor);
|
mMerchantRepair->startRepair(actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManager::startRepairItem(MWWorld::Ptr item)
|
||||||
|
{
|
||||||
|
mRepair->startRepairItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
const Translation::Storage& WindowManager::getTranslationDataStorage() const
|
const Translation::Storage& WindowManager::getTranslationDataStorage() const
|
||||||
{
|
{
|
||||||
return mTranslationDataStorage;
|
return mTranslationDataStorage;
|
||||||
|
|
|
@ -75,6 +75,7 @@ namespace MWGui
|
||||||
class Cursor;
|
class Cursor;
|
||||||
class SpellIcons;
|
class SpellIcons;
|
||||||
class MerchantRepair;
|
class MerchantRepair;
|
||||||
|
class Repair;
|
||||||
|
|
||||||
class WindowManager : public MWBase::WindowManager
|
class WindowManager : public MWBase::WindowManager
|
||||||
{
|
{
|
||||||
|
@ -231,6 +232,7 @@ namespace MWGui
|
||||||
virtual void startEnchanting(MWWorld::Ptr actor);
|
virtual void startEnchanting(MWWorld::Ptr actor);
|
||||||
virtual void startTraining(MWWorld::Ptr actor);
|
virtual void startTraining(MWWorld::Ptr actor);
|
||||||
virtual void startRepair(MWWorld::Ptr actor);
|
virtual void startRepair(MWWorld::Ptr actor);
|
||||||
|
virtual void startRepairItem(MWWorld::Ptr item);
|
||||||
|
|
||||||
virtual void changePointer (const std::string& name);
|
virtual void changePointer (const std::string& name);
|
||||||
|
|
||||||
|
@ -269,6 +271,7 @@ namespace MWGui
|
||||||
EnchantingDialog* mEnchantingDialog;
|
EnchantingDialog* mEnchantingDialog;
|
||||||
TrainingWindow* mTrainingWindow;
|
TrainingWindow* mTrainingWindow;
|
||||||
MerchantRepair* mMerchantRepair;
|
MerchantRepair* mMerchantRepair;
|
||||||
|
Repair* mRepair;
|
||||||
|
|
||||||
Translation::Storage& mTranslationDataStorage;
|
Translation::Storage& mTranslationDataStorage;
|
||||||
Cursor* mCursor;
|
Cursor* mCursor;
|
||||||
|
|
110
apps/openmw/mwmechanics/repair.cpp
Normal file
110
apps/openmw/mwmechanics/repair.cpp
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
#include "repair.hpp"
|
||||||
|
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
#include "../mwbase/soundmanager.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/player.hpp"
|
||||||
|
#include "../mwworld/containerstore.hpp"
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
|
||||||
|
void Repair::repair(const MWWorld::Ptr &itemToRepair)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
||||||
|
mTool.get<ESM::Repair>();
|
||||||
|
|
||||||
|
// reduce number of uses left
|
||||||
|
int uses = (mTool.getCellRef().mCharge != -1) ? mTool.getCellRef().mCharge : ref->mBase->mData.mUses;
|
||||||
|
mTool.getCellRef().mCharge = uses-1;
|
||||||
|
|
||||||
|
// unstack tool if required
|
||||||
|
if (mTool.getRefData().getCount() > 1 && uses == ref->mBase->mData.mUses)
|
||||||
|
{
|
||||||
|
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
|
MWWorld::ContainerStoreIterator it = store.add(mTool);
|
||||||
|
it->getRefData().setCount(mTool.getRefData().getCount()-1);
|
||||||
|
it->getCellRef().mCharge = -1;
|
||||||
|
|
||||||
|
mTool.getRefData().setCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
|
||||||
|
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats(player);
|
||||||
|
|
||||||
|
float fatigueTerm = stats.getFatigueTerm();
|
||||||
|
int pcStrength = stats.getAttribute(ESM::Attribute::Strength).getModified();
|
||||||
|
int pcLuck = stats.getAttribute(ESM::Attribute::Luck).getModified();
|
||||||
|
int armorerSkill = npcStats.getSkill(ESM::Skill::Armorer).getModified();
|
||||||
|
|
||||||
|
float fRepairAmountMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||||
|
.find("fRepairAmountMult")->getFloat();
|
||||||
|
|
||||||
|
float toolQuality = ref->mBase->mData.mQuality;
|
||||||
|
|
||||||
|
float x = (0.1 * pcStrength + 0.1 * pcLuck + armorerSkill) * fatigueTerm;
|
||||||
|
|
||||||
|
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
|
||||||
|
if (roll <= x)
|
||||||
|
{
|
||||||
|
int y = fRepairAmountMult * toolQuality * roll;
|
||||||
|
y = std::max(1, y);
|
||||||
|
|
||||||
|
// repair by 'y' points
|
||||||
|
itemToRepair.getCellRef().mCharge += y;
|
||||||
|
itemToRepair.getCellRef().mCharge = std::min(itemToRepair.getCellRef().mCharge,
|
||||||
|
MWWorld::Class::get(itemToRepair).getItemMaxHealth(itemToRepair));
|
||||||
|
|
||||||
|
// set the OnPCRepair variable on the item's script
|
||||||
|
std::string script = MWWorld::Class::get(itemToRepair).getScript(itemToRepair);
|
||||||
|
if(script != "")
|
||||||
|
itemToRepair.getRefData().getLocals().setVarByInt(script, "onpcrepair", 1);
|
||||||
|
|
||||||
|
// increase skill
|
||||||
|
MWWorld::Class::get(player).skillUsageSucceeded(player, ESM::Skill::Armorer, 0);
|
||||||
|
|
||||||
|
MWBase::Environment::get().getSoundManager()->playSound("Repair",1,1);
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sRepairSuccess}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getSoundManager()->playSound("Repair Fail",1,1);
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sRepairFailed}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// tool used up?
|
||||||
|
if (mTool.getCellRef().mCharge == 0)
|
||||||
|
{
|
||||||
|
mTool.getRefData().setCount(0);
|
||||||
|
|
||||||
|
std::string message = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||||
|
.find("sNotifyMessage51")->getString();
|
||||||
|
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox((boost::format(message) % MWWorld::Class::get(mTool).getName(mTool)).str());
|
||||||
|
|
||||||
|
// try to find a new tool of the same ID
|
||||||
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
|
for (MWWorld::ContainerStoreIterator iter (store.begin());
|
||||||
|
iter!=store.end(); ++iter)
|
||||||
|
{
|
||||||
|
if (Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, mTool.getCellRef().mRefID))
|
||||||
|
{
|
||||||
|
mTool = *iter;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
apps/openmw/mwmechanics/repair.hpp
Normal file
23
apps/openmw/mwmechanics/repair.hpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef OPENMW_MWMECHANICS_REPAIR_H
|
||||||
|
#define OPENMW_MWMECHANICS_REPAIR_H
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
|
||||||
|
class Repair
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void setTool (const MWWorld::Ptr& tool) { mTool = tool; }
|
||||||
|
MWWorld::Ptr getTool() { return mTool; }
|
||||||
|
|
||||||
|
void repair (const MWWorld::Ptr& itemToRepair);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MWWorld::Ptr mTool;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
18
apps/openmw/mwworld/actionrepair.cpp
Normal file
18
apps/openmw/mwworld/actionrepair.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "actionrepair.hpp"
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
ActionRepair::ActionRepair(const Ptr &item)
|
||||||
|
: Action(false, item)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionRepair::executeImp (const Ptr& actor)
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Repair);
|
||||||
|
MWBase::Environment::get().getWindowManager()->startRepairItem(getTarget());
|
||||||
|
}
|
||||||
|
}
|
17
apps/openmw/mwworld/actionrepair.hpp
Normal file
17
apps/openmw/mwworld/actionrepair.hpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef GAME_MWWORLD_ACTIONREPAIR_H
|
||||||
|
#define GAME_MWWORLD_ACTIONREPAIR_H
|
||||||
|
|
||||||
|
#include "action.hpp"
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
class ActionRepair : public Action
|
||||||
|
{
|
||||||
|
virtual void executeImp (const Ptr& actor);
|
||||||
|
|
||||||
|
public:
|
||||||
|
ActionRepair(const MWWorld::Ptr& item);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -38,12 +38,6 @@ namespace
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compare_string_ci(std::string str1, std::string str2)
|
|
||||||
{
|
|
||||||
Misc::StringUtils::toLower(str1);
|
|
||||||
return str1 == str2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::ContainerStore::ContainerStore() : mStateId (0), mCachedWeight (0), mWeightUpToDate (false) {}
|
MWWorld::ContainerStore::ContainerStore() : mStateId (0), mCachedWeight (0), mWeightUpToDate (false) {}
|
||||||
|
@ -68,7 +62,11 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2)
|
||||||
&& MWWorld::Class::get(ptr1).getEnchantment(ptr1) == "" // item with enchantment never stacks (we could revisit this later, but for now it makes selecting items in the spell window much easier)
|
&& MWWorld::Class::get(ptr1).getEnchantment(ptr1) == "" // item with enchantment never stacks (we could revisit this later, but for now it makes selecting items in the spell window much easier)
|
||||||
&& ptr1.mCellRef->mOwner == ptr2.mCellRef->mOwner
|
&& ptr1.mCellRef->mOwner == ptr2.mCellRef->mOwner
|
||||||
&& ptr1.mCellRef->mSoul == ptr2.mCellRef->mSoul
|
&& ptr1.mCellRef->mSoul == ptr2.mCellRef->mSoul
|
||||||
&& ptr1.mCellRef->mCharge == -1) // item that is already partly used up never stacks
|
// item that is already partly used up never stacks
|
||||||
|
&& (!MWWorld::Class::get(ptr1).hasItemHealth(ptr1) || ptr1.mCellRef->mCharge == -1
|
||||||
|
|| MWWorld::Class::get(ptr1).getItemMaxHealth(ptr1) == ptr1.mCellRef->mCharge)
|
||||||
|
&& (!MWWorld::Class::get(ptr2).hasItemHealth(ptr2) || ptr2.mCellRef->mCharge == -1
|
||||||
|
|| MWWorld::Class::get(ptr2).getItemMaxHealth(ptr2) == ptr2.mCellRef->mCharge))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -118,11 +116,11 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImp (const Ptr& ptr)
|
||||||
MWWorld::LiveCellRef<ESM::Miscellaneous> *gold =
|
MWWorld::LiveCellRef<ESM::Miscellaneous> *gold =
|
||||||
ptr.get<ESM::Miscellaneous>();
|
ptr.get<ESM::Miscellaneous>();
|
||||||
|
|
||||||
if (compare_string_ci(gold->mRef.mRefID, "gold_001")
|
if (Misc::StringUtils::ciEqual(gold->mRef.mRefID, "gold_001")
|
||||||
|| compare_string_ci(gold->mRef.mRefID, "gold_005")
|
|| Misc::StringUtils::ciEqual(gold->mRef.mRefID, "gold_005")
|
||||||
|| compare_string_ci(gold->mRef.mRefID, "gold_010")
|
|| Misc::StringUtils::ciEqual(gold->mRef.mRefID, "gold_010")
|
||||||
|| compare_string_ci(gold->mRef.mRefID, "gold_025")
|
|| Misc::StringUtils::ciEqual(gold->mRef.mRefID, "gold_025")
|
||||||
|| compare_string_ci(gold->mRef.mRefID, "gold_100"))
|
|| Misc::StringUtils::ciEqual(gold->mRef.mRefID, "gold_100"))
|
||||||
{
|
{
|
||||||
MWWorld::ManualRef ref(esmStore, "Gold_001");
|
MWWorld::ManualRef ref(esmStore, "Gold_001");
|
||||||
|
|
||||||
|
@ -130,7 +128,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImp (const Ptr& ptr)
|
||||||
ref.getPtr().getRefData().setCount(count);
|
ref.getPtr().getRefData().setCount(count);
|
||||||
for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter)
|
for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter)
|
||||||
{
|
{
|
||||||
if (compare_string_ci((*iter).get<ESM::Miscellaneous>()->mRef.mRefID, "gold_001"))
|
if (Misc::StringUtils::ciEqual((*iter).get<ESM::Miscellaneous>()->mRef.mRefID, "gold_001"))
|
||||||
{
|
{
|
||||||
(*iter).getRefData().setCount( (*iter).getRefData().getCount() + count);
|
(*iter).getRefData().setCount( (*iter).getRefData().getCount() + count);
|
||||||
flagAsModified();
|
flagAsModified();
|
||||||
|
|
|
@ -79,6 +79,7 @@ set(MYGUI_FILES
|
||||||
openmw_travel_window.layout
|
openmw_travel_window.layout
|
||||||
openmw_persuasion_dialog.layout
|
openmw_persuasion_dialog.layout
|
||||||
openmw_merchantrepair.layout
|
openmw_merchantrepair.layout
|
||||||
|
openmw_repair.layout
|
||||||
smallbars.png
|
smallbars.png
|
||||||
DejaVuLGCSansMono.ttf
|
DejaVuLGCSansMono.ttf
|
||||||
markers.png
|
markers.png
|
||||||
|
|
33
files/mygui/openmw_repair.layout
Normal file
33
files/mygui/openmw_repair.layout
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<MyGUI type="Layout">
|
||||||
|
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 329 253" name="_Main">
|
||||||
|
|
||||||
|
<Widget type="Widget" skin="" position="4 4 321 42" name="ToolBox">
|
||||||
|
<Widget type="ImageBox" skin="ImageBox" position="5 6 32 32" name="ToolIcon"/>
|
||||||
|
|
||||||
|
<Widget type="AutoSizedTextBox" skin="SandText" position="55 13 300 18" name="UsesLabel">
|
||||||
|
<Property key="Caption" value="#{sUses}"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="TextBox" skin="SandText" position="55 13 250 18" name="QualityLabel">
|
||||||
|
<Property key="Caption" value="#{sQuality}"/>
|
||||||
|
<Property key="TextAlign" value="Right"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="Widget" skin="MW_Box" position="6 46 309 160" align="Left Stretch" name="RepairBox">
|
||||||
|
<Widget type="ScrollView" skin="MW_ScrollView" position="4 4 301 152" align="Left Top Stretch" name="RepairView">
|
||||||
|
<Property key="CanvasAlign" value="Left"/>
|
||||||
|
</Widget>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="AutoSizedButton" skin="MW_Button" position="239 214 75 24" name="CancelButton">
|
||||||
|
<Property key="ExpandDirection" value="Left"/>
|
||||||
|
<Property key="Caption" value="#{sCancel}"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
</MyGUI>
|
|
@ -154,8 +154,8 @@
|
||||||
</Skin>
|
</Skin>
|
||||||
|
|
||||||
<Skin name = "MW_ChargeBar" size = "204 18">
|
<Skin name = "MW_ChargeBar" size = "204 18">
|
||||||
<Child type="ProgressBar" skin="MW_Progress_Red" offset = "0 0 204 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "Bar" />
|
<Child type="ProgressBar" skin="MW_Progress_Red" offset = "0 0 204 18" align = "ALIGN_RIGHT ALIGN_TOP ALIGN_STRETCH" name = "Bar" />
|
||||||
<Child type="TextBox" skin="SandTextC" offset = "0 0 204 18" align = "ALIGN_RIGHT ALIGN_TOP" name = "BarText" />
|
<Child type="TextBox" skin="SandTextC" offset = "0 0 204 18" align = "ALIGN_RIGHT ALIGN_TOP ALIGN_STRETCH" name = "BarText" />
|
||||||
</Skin>
|
</Skin>
|
||||||
|
|
||||||
<Skin name = "MW_DynamicStat_Red" size = "204 18">
|
<Skin name = "MW_DynamicStat_Red" size = "204 18">
|
||||||
|
|
Loading…
Reference in a new issue