Add missing files
parent
af6409b9f5
commit
bc6e1fd981
@ -0,0 +1,107 @@
|
|||||||
|
#include "companionwindow.hpp"
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/dialoguemanager.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
|
#include "messagebox.hpp"
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
|
||||||
|
CompanionWindow::CompanionWindow(MWBase::WindowManager &parWindowManager, DragAndDrop *dragAndDrop, MessageBoxManager* manager)
|
||||||
|
: ContainerBase(dragAndDrop)
|
||||||
|
, WindowBase("openmw_companion_window.layout", parWindowManager)
|
||||||
|
, mMessageBoxManager(manager)
|
||||||
|
{
|
||||||
|
MyGUI::ScrollView* itemView;
|
||||||
|
MyGUI::Widget* containerWidget;
|
||||||
|
getWidget(containerWidget, "Items");
|
||||||
|
getWidget(itemView, "ItemView");
|
||||||
|
setWidgets(containerWidget, itemView);
|
||||||
|
|
||||||
|
getWidget(mCloseButton, "CloseButton");
|
||||||
|
getWidget(mProfitLabel, "ProfitLabel");
|
||||||
|
getWidget(mEncumbranceBar, "EncumbranceBar");
|
||||||
|
|
||||||
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CompanionWindow::onCloseButtonClicked);
|
||||||
|
|
||||||
|
setCoord(200,0,600,300);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::open(MWWorld::Ptr npc)
|
||||||
|
{
|
||||||
|
openContainer(npc);
|
||||||
|
setTitle(MWWorld::Class::get(npc).getName(npc));
|
||||||
|
drawItems();
|
||||||
|
updateEncumbranceBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::notifyItemDragged(MWWorld::Ptr item, int count)
|
||||||
|
{
|
||||||
|
if (mPtr.getTypeName() == typeid(ESM::NPC).name())
|
||||||
|
{
|
||||||
|
MWMechanics::NpcStats& stats = MWWorld::Class::get(mPtr).getNpcStats(mPtr);
|
||||||
|
stats.modifyProfit(MWWorld::Class::get(item).getValue(item) * count);
|
||||||
|
}
|
||||||
|
updateEncumbranceBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::updateEncumbranceBar()
|
||||||
|
{
|
||||||
|
float capacity = MWWorld::Class::get(mPtr).getCapacity(mPtr);
|
||||||
|
float encumbrance = MWWorld::Class::get(mPtr).getEncumbrance(mPtr);
|
||||||
|
mEncumbranceBar->setValue(encumbrance, capacity);
|
||||||
|
|
||||||
|
if (mPtr.getTypeName() != typeid(ESM::NPC).name())
|
||||||
|
mProfitLabel->setCaption("");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MWMechanics::NpcStats& stats = MWWorld::Class::get(mPtr).getNpcStats(mPtr);
|
||||||
|
mProfitLabel->setCaptionWithReplacing("#{sProfitValue} " + boost::lexical_cast<std::string>(stats.getProfit()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::onWindowResize(MyGUI::Window* window)
|
||||||
|
{
|
||||||
|
drawItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
||||||
|
{
|
||||||
|
if (mPtr.getTypeName() == typeid(ESM::NPC).name() && MWWorld::Class::get(mPtr).getNpcStats(mPtr).getProfit() < 0)
|
||||||
|
{
|
||||||
|
std::vector<std::string> buttons;
|
||||||
|
buttons.push_back("#{sCompanionWarningButtonOne}");
|
||||||
|
buttons.push_back("#{sCompanionWarningButtonTwo}");
|
||||||
|
mMessageBoxManager->createInteractiveMessageBox("#{sCompanionWarningMessage}", buttons);
|
||||||
|
mMessageBoxManager->eventButtonPressed += MyGUI::newDelegate(this, &CompanionWindow::onMessageBoxButtonClicked);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::onMessageBoxButtonClicked(int button)
|
||||||
|
{
|
||||||
|
if (button == 0)
|
||||||
|
{
|
||||||
|
mPtr.getRefData().getLocals().setVarByInt(MWWorld::Class::get(mPtr).getScript(mPtr),
|
||||||
|
"minimumProfit", MWWorld::Class::get(mPtr).getNpcStats(mPtr).getProfit());
|
||||||
|
|
||||||
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion);
|
||||||
|
MWBase::Environment::get().getDialogueManager()->startDialogue (mPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::onReferenceUnavailable()
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef OPENMW_MWGUI_COMPANIONWINDOW_H
|
||||||
|
#define OPENMW_MWGUI_COMPANIONWINDOW_H
|
||||||
|
|
||||||
|
#include "container.hpp"
|
||||||
|
#include "widgets.hpp"
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
class MessageBoxManager;
|
||||||
|
|
||||||
|
class CompanionWindow : public ContainerBase, public WindowBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CompanionWindow(MWBase::WindowManager& parWindowManager,DragAndDrop* dragAndDrop, MessageBoxManager* manager);
|
||||||
|
virtual ~CompanionWindow() {}
|
||||||
|
|
||||||
|
void open(MWWorld::Ptr npc);
|
||||||
|
|
||||||
|
virtual void notifyItemDragged(MWWorld::Ptr item, int count);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MyGUI::Button* mCloseButton;
|
||||||
|
MyGUI::TextBox* mProfitLabel;
|
||||||
|
Widgets::MWDynamicStat* mEncumbranceBar;
|
||||||
|
MessageBoxManager* mMessageBoxManager;
|
||||||
|
|
||||||
|
void onMessageBoxButtonClicked(int button);
|
||||||
|
|
||||||
|
void updateEncumbranceBar();
|
||||||
|
|
||||||
|
void onWindowResize(MyGUI::Window* window);
|
||||||
|
void onCloseButtonClicked(MyGUI::Widget* _sender);
|
||||||
|
|
||||||
|
virtual void onReferenceUnavailable();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<MyGUI type="Layout">
|
||||||
|
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 600 300" name="_Main">
|
||||||
|
|
||||||
|
<!-- Items -->
|
||||||
|
<Widget type="Widget" skin="MW_Box" position="5 5 575 225" name="box" align="Left Top Stretch">
|
||||||
|
<Widget type="ScrollView" skin="MW_ScrollViewH" position="4 4 567 217" name="ItemView" align="Left Top Stretch">
|
||||||
|
<Property key="CanvasAlign" value="Left Top"/>
|
||||||
|
<Widget type="Button" skin="" name="Items" position="0 0 567 217" name="Items" align="Left Top Stretch"/>
|
||||||
|
</Widget>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="HBox" position="5 235 575 24" align="Right Bottom">
|
||||||
|
<Widget type="MWDynamicStat" skin="MW_ChargeBar_Blue" position="8 8 212 24" name="EncumbranceBar" align="Left Top HStretch">
|
||||||
|
<UserString key="HStretch" value="true"/>
|
||||||
|
</Widget>
|
||||||
|
<Widget type="AutoSizedTextBox" skin="SandText" name="ProfitLabel">
|
||||||
|
</Widget>
|
||||||
|
<Widget type="AutoSizedButton" skin="MW_Button" name="CloseButton">
|
||||||
|
<Property key="Caption" value="#{sClose}"/>
|
||||||
|
</Widget>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
</Widget>
|
||||||
|
</MyGUI>
|
Loading…
Reference in New Issue