From bc6e1fd9816f3acb914be559e7e79b4d84edb477 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 31 Mar 2013 14:36:03 +0200 Subject: [PATCH] Add missing files --- apps/openmw/mwgui/companionwindow.cpp | 107 +++++++++++++++++++++ apps/openmw/mwgui/companionwindow.hpp | 39 ++++++++ files/mygui/openmw_companion_window.layout | 26 +++++ 3 files changed, 172 insertions(+) create mode 100644 apps/openmw/mwgui/companionwindow.cpp create mode 100644 apps/openmw/mwgui/companionwindow.hpp create mode 100644 files/mygui/openmw_companion_window.layout diff --git a/apps/openmw/mwgui/companionwindow.cpp b/apps/openmw/mwgui/companionwindow.cpp new file mode 100644 index 000000000..643cdf4c6 --- /dev/null +++ b/apps/openmw/mwgui/companionwindow.cpp @@ -0,0 +1,107 @@ +#include "companionwindow.hpp" + +#include + +#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(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 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); +} + + + +} diff --git a/apps/openmw/mwgui/companionwindow.hpp b/apps/openmw/mwgui/companionwindow.hpp new file mode 100644 index 000000000..1b64a34d5 --- /dev/null +++ b/apps/openmw/mwgui/companionwindow.hpp @@ -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 diff --git a/files/mygui/openmw_companion_window.layout b/files/mygui/openmw_companion_window.layout new file mode 100644 index 000000000..6172dd5b1 --- /dev/null +++ b/files/mygui/openmw_companion_window.layout @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +