forked from mirror/openmw-tes3mp
Merge branch 'Travel_Dialogue' into training_travel
Conflicts: apps/openmw/CMakeLists.txt apps/openmw/mwgui/dialogue.cpp apps/openmw/mwrender/globalmap.cpp files/mygui/CMakeLists.txtactorid
commit
c64eb96952
@ -0,0 +1,187 @@
|
||||
#include "travelwindow.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <libs/openengine/ogre/fader.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
|
||||
#include "../mwmechanics/spells.hpp"
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
|
||||
#include "inventorywindow.hpp"
|
||||
#include "tradewindow.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
const int TravelWindow::sLineHeight = 18;
|
||||
|
||||
TravelWindow::TravelWindow(MWBase::WindowManager& parWindowManager) :
|
||||
WindowBase("openmw_travel_window.layout", parWindowManager)
|
||||
, mCurrentY(0)
|
||||
, mLastPos(0)
|
||||
{
|
||||
setCoord(0, 0, 450, 300);
|
||||
|
||||
getWidget(mCancelButton, "CancelButton");
|
||||
getWidget(mPlayerGold, "PlayerGold");
|
||||
getWidget(mSelect, "Select");
|
||||
getWidget(mDestinations, "Travel");
|
||||
getWidget(mDestinationsView, "DestinationsView");
|
||||
|
||||
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TravelWindow::onCancelButtonClicked);
|
||||
|
||||
mDestinations->setCoord(450/2-mDestinations->getTextSize().width/2,
|
||||
mDestinations->getTop(),
|
||||
mDestinations->getTextSize().width,
|
||||
mDestinations->getHeight());
|
||||
mSelect->setCoord(8,
|
||||
mSelect->getTop(),
|
||||
mSelect->getTextSize().width,
|
||||
mSelect->getHeight());
|
||||
}
|
||||
|
||||
void TravelWindow::addDestination(const std::string& travelId,ESM::Position pos,bool interior)
|
||||
{
|
||||
int price = 0;
|
||||
|
||||
if(interior)
|
||||
{
|
||||
price = MWBase::Environment::get().getWorld()->getStore().gameSettings.find("fMagesGuildTravel")->getFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
ESM::Position PlayerPos = player.getRefData().getPosition();
|
||||
float d = sqrt( pow(pos.pos[0] - PlayerPos.pos[0],2) + pow(pos.pos[1] - PlayerPos.pos[1],2) + pow(pos.pos[2] - PlayerPos.pos[2],2) );
|
||||
price = d/MWBase::Environment::get().getWorld()->getStore().gameSettings.find("fTravelMult")->getFloat();
|
||||
}
|
||||
|
||||
MyGUI::Button* toAdd = mDestinationsView->createWidget<MyGUI::Button>((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SandTextButton", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
|
||||
mCurrentY += sLineHeight;
|
||||
/// \todo price adjustment depending on merchantile skill
|
||||
if(interior)
|
||||
toAdd->setUserString("interior","y");
|
||||
else
|
||||
toAdd->setUserString("interior","n");
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << price;
|
||||
toAdd->setUserString("price",oss.str());
|
||||
|
||||
toAdd->setCaptionWithReplacing(travelId+" - "+boost::lexical_cast<std::string>(price)+"#{sgp}");
|
||||
toAdd->setSize(toAdd->getTextSize().width,sLineHeight);
|
||||
toAdd->eventMouseWheel += MyGUI::newDelegate(this, &TravelWindow::onMouseWheel);
|
||||
toAdd->setUserString("Destination", travelId);
|
||||
toAdd->setUserData(pos);
|
||||
toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &TravelWindow::onTravelButtonClick);
|
||||
mDestinationsWidgetMap.insert(std::make_pair (toAdd, travelId));
|
||||
}
|
||||
|
||||
void TravelWindow::clearDestinations()
|
||||
{
|
||||
mDestinationsView->setViewOffset(MyGUI::IntPoint(0,0));
|
||||
mCurrentY = 0;
|
||||
while (mDestinationsView->getChildCount())
|
||||
MyGUI::Gui::getInstance().destroyWidget(mDestinationsView->getChildAt(0));
|
||||
mDestinationsWidgetMap.clear();
|
||||
}
|
||||
|
||||
void TravelWindow::startTravel(const MWWorld::Ptr& actor)
|
||||
{
|
||||
center();
|
||||
mPtr = actor;
|
||||
clearDestinations();
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
|
||||
for(unsigned int i = 0;i<mPtr.get<ESM::NPC>()->base->mTransport.size();i++)
|
||||
{
|
||||
std::string cellname = mPtr.get<ESM::NPC>()->base->mTransport[i].mCellName;
|
||||
bool interior = true;
|
||||
int x,y;
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(mPtr.get<ESM::NPC>()->base->mTransport[i].mPos.pos[0],
|
||||
mPtr.get<ESM::NPC>()->base->mTransport[i].mPos.pos[1],x,y);
|
||||
if(cellname == "") {cellname = MWBase::Environment::get().getWorld()->getExterior(x,y)->cell->mName; interior= false;}
|
||||
addDestination(cellname,mPtr.get<ESM::NPC>()->base->mTransport[i].mPos,interior);
|
||||
}
|
||||
|
||||
updateLabels();
|
||||
mDestinationsView->setCanvasSize (MyGUI::IntSize(mDestinationsView->getWidth(), std::max(mDestinationsView->getHeight(), mCurrentY)));
|
||||
}
|
||||
|
||||
void TravelWindow::onTravelButtonClick(MyGUI::Widget* _sender)
|
||||
{
|
||||
std::istringstream iss(_sender->getUserString("price"));
|
||||
int price;
|
||||
iss >> price;
|
||||
|
||||
if (mWindowManager.getInventoryWindow()->getPlayerGold()<price)
|
||||
return;
|
||||
|
||||
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(1);
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
ESM::Position pos = *_sender->getUserData<ESM::Position>();
|
||||
std::string cellname = _sender->getUserString("Destination");
|
||||
int x,y;
|
||||
bool interior = _sender->getUserString("interior") == "y";
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(pos.pos[0],pos.pos[1],x,y);
|
||||
MWWorld::CellStore* cell;
|
||||
if(interior) cell = MWBase::Environment::get().getWorld()->getInterior(cellname);
|
||||
else
|
||||
{
|
||||
cell = MWBase::Environment::get().getWorld()->getExterior(x,y);
|
||||
ESM::Position PlayerPos = player.getRefData().getPosition();
|
||||
float d = sqrt( pow(pos.pos[0] - PlayerPos.pos[0],2) + pow(pos.pos[1] - PlayerPos.pos[1],2) + pow(pos.pos[2] - PlayerPos.pos[2],2) );
|
||||
int time = int(d /MWBase::Environment::get().getWorld()->getStore().gameSettings.find("fTravelTimeMult")->getFloat());
|
||||
for(int i = 0;i < time;i++)
|
||||
{
|
||||
MWBase::Environment::get().getMechanicsManager ()->restoreDynamicStats ();
|
||||
}
|
||||
MWBase::Environment::get().getWorld()->advanceTime(time);
|
||||
}
|
||||
MWBase::Environment::get().getWorld()->moveObject(player,*cell,pos.pos[0],pos.pos[1],pos.pos[2]);
|
||||
mWindowManager.removeGuiMode(GM_Travel);
|
||||
mWindowManager.removeGuiMode(GM_Dialogue);
|
||||
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0);
|
||||
MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(1);
|
||||
}
|
||||
|
||||
void TravelWindow::onCancelButtonClicked(MyGUI::Widget* _sender)
|
||||
{
|
||||
mWindowManager.removeGuiMode(GM_Travel);
|
||||
}
|
||||
|
||||
void TravelWindow::updateLabels()
|
||||
{
|
||||
mPlayerGold->setCaptionWithReplacing("#{sGold}: " + boost::lexical_cast<std::string>(mWindowManager.getInventoryWindow()->getPlayerGold()));
|
||||
mPlayerGold->setCoord(8,
|
||||
mPlayerGold->getTop(),
|
||||
mPlayerGold->getTextSize().width,
|
||||
mPlayerGold->getHeight());
|
||||
}
|
||||
|
||||
void TravelWindow::onReferenceUnavailable()
|
||||
{
|
||||
mWindowManager.removeGuiMode(GM_Travel);
|
||||
mWindowManager.removeGuiMode(GM_Dialogue);
|
||||
}
|
||||
|
||||
void TravelWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
||||
{
|
||||
if (mDestinationsView->getViewOffset().top + _rel*0.3 > 0)
|
||||
mDestinationsView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
else
|
||||
mDestinationsView->setViewOffset(MyGUI::IntPoint(0, mDestinationsView->getViewOffset().top + _rel*0.3));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
#ifndef MWGUI_TravelWINDOW_H
|
||||
#define MWGUI_TravelWINDOW_H
|
||||
|
||||
#include "container.hpp"
|
||||
#include "window_base.hpp"
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
class Gui;
|
||||
class Widget;
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class WindowManager;
|
||||
}
|
||||
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class TravelWindow : public ReferenceInterface, public WindowBase
|
||||
{
|
||||
public:
|
||||
TravelWindow(MWBase::WindowManager& parWindowManager);
|
||||
|
||||
void startTravel(const MWWorld::Ptr& actor);
|
||||
|
||||
protected:
|
||||
MyGUI::Button* mCancelButton;
|
||||
MyGUI::TextBox* mPlayerGold;
|
||||
MyGUI::TextBox* mDestinations;
|
||||
MyGUI::TextBox* mSelect;
|
||||
|
||||
MyGUI::ScrollView* mDestinationsView;
|
||||
|
||||
std::map<MyGUI::Widget*, std::string> mDestinationsWidgetMap;
|
||||
|
||||
void onCancelButtonClicked(MyGUI::Widget* _sender);
|
||||
void onTravelButtonClick(MyGUI::Widget* _sender);
|
||||
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||
void addDestination(const std::string& destinationID,ESM::Position pos,bool interior);
|
||||
void clearDestinations();
|
||||
int mLastPos,mCurrentY;
|
||||
|
||||
static const int sLineHeight;
|
||||
|
||||
void updateLabels();
|
||||
|
||||
virtual void onReferenceUnavailable();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 450 300" name="_Main">
|
||||
<Property key="Visible" value="false"/>
|
||||
|
||||
|
||||
<Widget type="TextBox" skin="SandText" position="8 10 24 24" name="Select" align="Right Top">
|
||||
<Property key="TextAlign" value="Right"/>
|
||||
<Property key="Caption" value="#{sTravelServiceTitle}"/>
|
||||
</Widget>
|
||||
<Widget type="TextBox" skin="SandText" position="0 0 24 24" name="Travel" align="Right Top">
|
||||
<Property key="TextAlign" value="Right"/>
|
||||
<Property key="Caption" value="#D8C09A#{sTravel}"/>
|
||||
</Widget>
|
||||
|
||||
|
||||
<Widget type="Widget" skin="MW_Box" position="6 31 430 225" align="ALIGN_LEFT ALIGN_STRETCH">
|
||||
<Widget type="ScrollView" skin="MW_ScrollView" position="4 4 422 217" align="ALIGN_LEFT ALIGN_TOP ALIGN_STRETCH" name="DestinationsView">
|
||||
<Property key="CanvasAlign" value="Left"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
|
||||
<Widget type="TextBox" skin="SandText" position="8 255 24 24" name="PlayerGold" align="Right Top">
|
||||
<Property key="TextAlign" value="Right"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedButton" skin="MW_Button" position="375 260 60 24" name="CancelButton" align="Right Top">
|
||||
<Property key="ExpandDirection" value="Left"/>
|
||||
<Property key="Caption" value="#{sOK}"/>
|
||||
</Widget>
|
||||
|
||||
</Widget>
|
||||
|
||||
</MyGUI>
|
Loading…
Reference in New Issue