TravelGUI, not completly finished.

This commit is contained in:
gugus 2012-09-26 18:30:47 +02:00
parent b4db339fd5
commit 3060fbee60
10 changed files with 249 additions and 3 deletions

View file

@ -29,7 +29,7 @@ add_openmw_dir (mwgui
map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow list map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow list
formatting inventorywindow container hud countdialog tradewindow settingswindow formatting inventorywindow container hud countdialog tradewindow settingswindow
confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu
itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog travelwindow
) )
add_openmw_dir (mwdialogue add_openmw_dir (mwdialogue

View file

@ -42,6 +42,7 @@ namespace MWGui
class Console; class Console;
class SpellWindow; class SpellWindow;
class TradeWindow; class TradeWindow;
class TravelWindow;
class SpellBuyingWindow; class SpellBuyingWindow;
class ConfirmationDialog; class ConfirmationDialog;
class CountDialog; class CountDialog;
@ -108,6 +109,7 @@ namespace MWBase
virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0; virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0;
virtual MWGui::TradeWindow* getTradeWindow() = 0; virtual MWGui::TradeWindow* getTradeWindow() = 0;
virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow() = 0; virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow() = 0;
virtual MWGui::TravelWindow* getTravelWindow() = 0;
virtual MWGui::SpellWindow* getSpellWindow() = 0; virtual MWGui::SpellWindow* getSpellWindow() = 0;
virtual MWGui::Console* getConsole() = 0; virtual MWGui::Console* getConsole() = 0;

View file

@ -798,6 +798,10 @@ namespace MWDialogue
win->setShowSpells(true); win->setShowSpells(true);
else else
win->setShowSpells(false); win->setShowSpells(false);
if( !mActor.get<ESM::NPC>()->base->mTransport.empty())
win->setShowTravel(true);
else
win->setShowTravel(false);
// sort again, because the previous sort was case-sensitive // sort again, because the previous sort was case-sensitive
keywordList.sort(stringCompareNoCase); keywordList.sort(stringCompareNoCase);

View file

@ -19,6 +19,7 @@
#include "tradewindow.hpp" #include "tradewindow.hpp"
#include "spellbuyingwindow.hpp" #include "spellbuyingwindow.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
#include "travelwindow.hpp"
using namespace MWGui; using namespace MWGui;
using namespace Widgets; using namespace Widgets;
@ -134,7 +135,13 @@ void DialogueWindow::onSelectTopic(std::string topic)
mWindowManager.pushGuiMode(GM_SpellBuying); mWindowManager.pushGuiMode(GM_SpellBuying);
mWindowManager.getSpellBuyingWindow()->startSpellBuying(mPtr); mWindowManager.getSpellBuyingWindow()->startSpellBuying(mPtr);
} }
else if (topic == MWBase::Environment::get().getWorld()->getStore().gameSettings.find("sTravel")->getString())
{
std::cout << "travel!";
mWindowManager.pushGuiMode(GM_Travel);
mWindowManager.getTravelWindow()->startTravel(mPtr);
//mWindowManager.getSpellBuyingWindow()->startSpellBuying(mPtr);
}
else else
MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic)); MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic));
} }
@ -163,7 +170,10 @@ void DialogueWindow::setKeywords(std::list<std::string> keyWords)
if (mShowSpells) if (mShowSpells)
mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.find("sSpells")->getString()); mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.find("sSpells")->getString());
if (anyService) if(mShowTravel)
mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.find("sTravel")->getString());
if (anyService || mShowTravel)
mTopicsList->addSeparator(); mTopicsList->addSeparator();
for(std::list<std::string>::iterator it = keyWords.begin(); it != keyWords.end(); ++it) for(std::list<std::string>::iterator it = keyWords.begin(); it != keyWords.end(); ++it)

View file

@ -52,6 +52,7 @@ namespace MWGui
// make sure to call these before setKeywords() // make sure to call these before setKeywords()
void setShowTrade(bool show) { mShowTrade = show; } void setShowTrade(bool show) { mShowTrade = show; }
void setShowSpells(bool show) { mShowSpells = show; } void setShowSpells(bool show) { mShowSpells = show; }
void setShowTravel(bool show) { mShowTravel = show; }
protected: protected:
void onSelectTopic(std::string topic); void onSelectTopic(std::string topic);
@ -72,6 +73,7 @@ namespace MWGui
// various service button visibilities, depending if the npc/creature talked to has these services // various service button visibilities, depending if the npc/creature talked to has these services
bool mShowTrade; bool mShowTrade;
bool mShowSpells; bool mShowSpells;
bool mShowTravel;
bool mEnabled; bool mEnabled;

View file

@ -22,6 +22,7 @@ namespace MWGui
GM_Rest, GM_Rest,
GM_RestBed, GM_RestBed,
GM_SpellBuying, GM_SpellBuying,
GM_Travel,
GM_Levelup, GM_Levelup,

View file

@ -0,0 +1,159 @@
#include "travelwindow.hpp"
#include <algorithm>
#include <boost/lexical_cast.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.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_spell_buying_window.layout", parWindowManager)
, ContainerBase(NULL) // no drag&drop
, mCurrentY(0)
, mLastPos(0)
{
setCoord(0, 0, 450, 300);
getWidget(mCancelButton, "CancelButton");
getWidget(mPlayerGold, "PlayerGold");
getWidget(mSelect, "Select");
getWidget(mDestinations, "Spells");
getWidget(mDestinationsView, "SpellsView");
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)
{
//std::cout << "travel to" << travelId;
/*const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellId);
int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.find("fSpellValueMult")->getFloat();*/
int price = 0;
MyGUI::Button* toAdd = mDestinationsView->createWidget<MyGUI::Button>((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
mCurrentY += sLineHeight;
/// \todo price adjustment depending on merchantile skill
toAdd->setUserData(price);
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("ToolTipType", "Spell");
toAdd->setUserString("Spell", travelId);
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();
mActor = actor;
clearDestinations();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
/*MWMechanics::Spells& playerSpells = MWWorld::Class::get (player).getCreatureStats (player).getSpells();
MWMechanics::Spells& merchantSpells = MWWorld::Class::get (actor).getCreatureStats (actor).getSpells();
for (MWMechanics::Spells::TIterator iter = merchantSpells.begin(); iter!=merchantSpells.end(); ++iter)
{
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find (*iter);
if (spell->data.type!=ESM::Spell::ST_Spell)
continue; // don't try to sell diseases, curses or powers
if (std::find (playerSpells.begin(), playerSpells.end(), *iter)!=playerSpells.end())
continue; // we have that spell already
addDestination (*iter);
}*/
for(int i = 0;i<mActor.get<ESM::NPC>()->base->mTransport.size();i++)
{
addDestination(mActor.get<ESM::NPC>()->base->mTransport[i].mCellName);
}
updateLabels();
mDestinationsView->setCanvasSize (MyGUI::IntSize(mDestinationsView->getWidth(), std::max(mDestinationsView->getHeight(), mCurrentY)));
}
void TravelWindow::onTravelButtonClick(MyGUI::Widget* _sender)
{
/*int price = *_sender->getUserData<int>();
if (mWindowManager.getInventoryWindow()->getPlayerGold()>=price)
{
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
MWMechanics::Spells& spells = stats.getSpells();
spells.add (mSpellsWidgetMap.find(_sender)->second);
mWindowManager.getTradeWindow()->addOrRemoveGold(-price);
startSpellBuying(mActor);
MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0);
}*/
}
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()
{
// remove both Spells and Dialogue (since you always trade with the NPC/creature that you have previously talked to)
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));
}
}

View file

@ -0,0 +1,57 @@
#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 ContainerBase, 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;
MWWorld::Ptr mActor;
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);
void clearDestinations();
int mLastPos,mCurrentY;
static const int sLineHeight;
void updateLabels();
virtual void onReferenceUnavailable();
};
}
#endif

View file

@ -38,6 +38,7 @@
#include "countdialog.hpp" #include "countdialog.hpp"
#include "tradewindow.hpp" #include "tradewindow.hpp"
#include "spellbuyingwindow.hpp" #include "spellbuyingwindow.hpp"
#include "travelwindow.hpp"
#include "settingswindow.hpp" #include "settingswindow.hpp"
#include "confirmationdialog.hpp" #include "confirmationdialog.hpp"
#include "alchemywindow.hpp" #include "alchemywindow.hpp"
@ -67,6 +68,7 @@ WindowManager::WindowManager(
, mCountDialog(NULL) , mCountDialog(NULL)
, mTradeWindow(NULL) , mTradeWindow(NULL)
, mSpellBuyingWindow(NULL) , mSpellBuyingWindow(NULL)
, mTravelWindow(NULL)
, mSettingsWindow(NULL) , mSettingsWindow(NULL)
, mConfirmationDialog(NULL) , mConfirmationDialog(NULL)
, mAlchemyWindow(NULL) , mAlchemyWindow(NULL)
@ -141,6 +143,7 @@ WindowManager::WindowManager(
mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mInventoryWindow = new InventoryWindow(*this,mDragAndDrop);
mTradeWindow = new TradeWindow(*this); mTradeWindow = new TradeWindow(*this);
mSpellBuyingWindow = new SpellBuyingWindow(*this); mSpellBuyingWindow = new SpellBuyingWindow(*this);
mTravelWindow = new TravelWindow(*this);
mDialogueWindow = new DialogueWindow(*this); mDialogueWindow = new DialogueWindow(*this);
mContainerWindow = new ContainerWindow(*this,mDragAndDrop); mContainerWindow = new ContainerWindow(*this,mDragAndDrop);
mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop); mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop);
@ -203,6 +206,7 @@ WindowManager::~WindowManager()
delete mScrollWindow; delete mScrollWindow;
delete mTradeWindow; delete mTradeWindow;
delete mSpellBuyingWindow; delete mSpellBuyingWindow;
delete mTravelWindow;
delete mSettingsWindow; delete mSettingsWindow;
delete mConfirmationDialog; delete mConfirmationDialog;
delete mAlchemyWindow; delete mAlchemyWindow;
@ -253,6 +257,7 @@ void WindowManager::updateVisible()
mBookWindow->setVisible(false); mBookWindow->setVisible(false);
mTradeWindow->setVisible(false); mTradeWindow->setVisible(false);
mSpellBuyingWindow->setVisible(false); mSpellBuyingWindow->setVisible(false);
mTravelWindow->setVisible(false);
mSettingsWindow->setVisible(false); mSettingsWindow->setVisible(false);
mAlchemyWindow->setVisible(false); mAlchemyWindow->setVisible(false);
mSpellWindow->setVisible(false); mSpellWindow->setVisible(false);
@ -359,6 +364,9 @@ void WindowManager::updateVisible()
case GM_SpellBuying: case GM_SpellBuying:
mSpellBuyingWindow->setVisible(true); mSpellBuyingWindow->setVisible(true);
break; break;
case GM_Travel:
mTravelWindow->setVisible(true);
break;
case GM_InterMessageBox: case GM_InterMessageBox:
break; break;
case GM_Journal: case GM_Journal:
@ -844,6 +852,7 @@ MWGui::CountDialog* WindowManager::getCountDialog() { return mCountDialog; }
MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; } MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; }
MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; } MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; }
MWGui::SpellBuyingWindow* WindowManager::getSpellBuyingWindow() { return mSpellBuyingWindow; } MWGui::SpellBuyingWindow* WindowManager::getSpellBuyingWindow() { return mSpellBuyingWindow; }
MWGui::TravelWindow* WindowManager::getTravelWindow() { return mTravelWindow; }
MWGui::SpellWindow* WindowManager::getSpellWindow() { return mSpellWindow; } MWGui::SpellWindow* WindowManager::getSpellWindow() { return mSpellWindow; }
MWGui::Console* WindowManager::getConsole() { return mConsole; } MWGui::Console* WindowManager::getConsole() { return mConsole; }

View file

@ -111,6 +111,7 @@ namespace MWGui
virtual MWGui::ConfirmationDialog* getConfirmationDialog(); virtual MWGui::ConfirmationDialog* getConfirmationDialog();
virtual MWGui::TradeWindow* getTradeWindow(); virtual MWGui::TradeWindow* getTradeWindow();
virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow(); virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow();
virtual MWGui::TravelWindow* getTravelWindow();
virtual MWGui::SpellWindow* getSpellWindow(); virtual MWGui::SpellWindow* getSpellWindow();
virtual MWGui::Console* getConsole(); virtual MWGui::Console* getConsole();
@ -229,6 +230,7 @@ namespace MWGui
CountDialog* mCountDialog; CountDialog* mCountDialog;
TradeWindow* mTradeWindow; TradeWindow* mTradeWindow;
SpellBuyingWindow* mSpellBuyingWindow; SpellBuyingWindow* mSpellBuyingWindow;
TravelWindow* mTravelWindow;
SettingsWindow* mSettingsWindow; SettingsWindow* mSettingsWindow;
ConfirmationDialog* mConfirmationDialog; ConfirmationDialog* mConfirmationDialog;
AlchemyWindow* mAlchemyWindow; AlchemyWindow* mAlchemyWindow;