forked from teamnwah/openmw-tes3coop
show the Barter entry in the dialogue gui for npcs/creatures that buy/sell stuff. doesn't work for the Creeper for some reason, but Mudcrab Merchant works.
This commit is contained in:
parent
66abfd17ab
commit
0dc5e5919b
5 changed files with 79 additions and 13 deletions
|
@ -767,6 +767,36 @@ namespace MWDialogue
|
|||
}
|
||||
}
|
||||
|
||||
// check the available services of this actor
|
||||
int services = 0;
|
||||
if (mActor.getTypeName() == typeid(ESM::NPC).name())
|
||||
{
|
||||
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData>* ref = mActor.get<ESM::NPC>();
|
||||
if (ref->base->hasAI)
|
||||
services = ref->base->AI.services;
|
||||
}
|
||||
else if (mActor.getTypeName() == typeid(ESM::Creature).name())
|
||||
{
|
||||
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData>* ref = mActor.get<ESM::Creature>();
|
||||
if (ref->base->hasAI)
|
||||
services = ref->base->AI.services;
|
||||
}
|
||||
|
||||
if (services & ESM::NPC::Weapon
|
||||
|| services & ESM::NPC::Armor
|
||||
|| services & ESM::NPC::Clothing
|
||||
|| services & ESM::NPC::Books
|
||||
|| services & ESM::NPC::Ingredients
|
||||
|| services & ESM::NPC::Picks
|
||||
|| services & ESM::NPC::Probes
|
||||
|| services & ESM::NPC::Lights
|
||||
|| services & ESM::NPC::Apparatus
|
||||
|| services & ESM::NPC::RepairItem
|
||||
|| services & ESM::NPC::Misc)
|
||||
win->setShowTrade(true);
|
||||
else
|
||||
win->setShowTrade(false);
|
||||
|
||||
// sort again, because the previous sort was case-sensitive
|
||||
keywordList.sort(stringCompareNoCase);
|
||||
win->setKeywords(keywordList);
|
||||
|
|
|
@ -40,6 +40,7 @@ std::string::size_type find_str_ci(const std::string& str, const std::string& su
|
|||
DialogueWindow::DialogueWindow(WindowManager& parWindowManager)
|
||||
: WindowBase("openmw_dialogue_window_layout.xml", parWindowManager)
|
||||
, mEnabled(true)
|
||||
, mShowTrade(false)
|
||||
{
|
||||
// Centre dialog
|
||||
center();
|
||||
|
@ -141,6 +142,15 @@ void DialogueWindow::startDialogue(std::string npcName)
|
|||
void DialogueWindow::setKeywords(std::list<std::string> keyWords)
|
||||
{
|
||||
topicsList->clear();
|
||||
|
||||
bool anyService = mShowTrade;
|
||||
|
||||
if (mShowTrade)
|
||||
topicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarter")->str);
|
||||
|
||||
if (anyService)
|
||||
topicsList->addSeparator();
|
||||
|
||||
for(std::list<std::string>::iterator it = keyWords.begin(); it != keyWords.end(); it++)
|
||||
{
|
||||
topicsList->addItem(*it);
|
||||
|
@ -194,7 +204,8 @@ std::string DialogueWindow::parseText(std::string text)
|
|||
for(unsigned int i = 0;i<topicsList->getItemCount();i++)
|
||||
{
|
||||
std::string keyWord = topicsList->getItemNameAt(i);
|
||||
addColorInString(text,keyWord,"#686EBA","#B29154");
|
||||
if (keyWord != "")
|
||||
addColorInString(text,keyWord,"#686EBA","#B29154");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,10 @@ namespace MWGui
|
|||
void askQuestion(std::string question);
|
||||
void goodbye();
|
||||
|
||||
// various service button visibilities, depending if the npc/creature talked to has these services
|
||||
// make sure to call these before setKeywords()
|
||||
void setShowTrade(bool show) { mShowTrade = show; }
|
||||
|
||||
protected:
|
||||
void onSelectTopic(std::string topic);
|
||||
void onByeClicked(MyGUI::Widget* _sender);
|
||||
|
@ -61,6 +65,9 @@ namespace MWGui
|
|||
*/
|
||||
std::string parseText(std::string text);
|
||||
|
||||
// various service button visibilities, depending if the npc/creature talked to has these services
|
||||
bool mShowTrade;
|
||||
|
||||
bool mEnabled;
|
||||
|
||||
DialogueHistory* history;
|
||||
|
|
|
@ -30,6 +30,11 @@ void MWList::addItem(const std::string& name)
|
|||
mItems.push_back(name);
|
||||
}
|
||||
|
||||
void MWList::addSeparator()
|
||||
{
|
||||
mItems.push_back("");
|
||||
}
|
||||
|
||||
void MWList::adjustSize()
|
||||
{
|
||||
redraw();
|
||||
|
@ -50,19 +55,31 @@ void MWList::redraw(bool scrollbarShown)
|
|||
for (std::vector<std::string>::const_iterator it=mItems.begin();
|
||||
it!=mItems.end(); ++it)
|
||||
{
|
||||
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(
|
||||
"MW_ListLine", MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it));
|
||||
button->setCaption((*it));
|
||||
button->getSubWidgetText()->setWordWrap(true);
|
||||
button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left);
|
||||
button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel);
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected);
|
||||
if (*it != "")
|
||||
{
|
||||
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(
|
||||
"MW_ListLine", MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it));
|
||||
button->setCaption((*it));
|
||||
button->getSubWidgetText()->setWordWrap(true);
|
||||
button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left);
|
||||
button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel);
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected);
|
||||
|
||||
int height = button->getTextSize().height;
|
||||
button->setSize(MyGUI::IntSize(button->getSize().width, height));
|
||||
int height = button->getTextSize().height;
|
||||
button->setSize(MyGUI::IntSize(button->getSize().width, height));
|
||||
|
||||
mItemHeight += height + spacing;
|
||||
mItemHeight += height + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
MyGUI::ImageBox* separator = mScrollView->createWidget<MyGUI::ImageBox>("MW_HLine",
|
||||
MyGUI::IntCoord(2, mItemHeight, mScrollView->getWidth()-4, 18),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
|
||||
separator->setNeedMouseFocus(false);
|
||||
|
||||
mItemHeight += 18 + spacing;
|
||||
}
|
||||
}
|
||||
mScrollView->setCanvasSize(mClient->getSize().width + (_scrollBarWidth-scrollBarWidth), std::max(mItemHeight, mClient->getSize().height));
|
||||
|
||||
|
|
|
@ -31,10 +31,11 @@ namespace MWGui
|
|||
void adjustSize();
|
||||
|
||||
void addItem(const std::string& name);
|
||||
void addSeparator(); ///< add a seperator between the current and the next item.
|
||||
void removeItem(const std::string& name);
|
||||
bool hasItem(const std::string& name);
|
||||
unsigned int getItemCount();
|
||||
std::string getItemNameAt(unsigned int at);
|
||||
std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in a new issue