2010-11-03 21:21:08 +01:00
|
|
|
#include "dialogue.hpp"
|
|
|
|
|
2017-09-27 12:40:47 +02:00
|
|
|
#include <MyGUI_Button.h>
|
2015-01-10 02:50:43 +01:00
|
|
|
#include <MyGUI_LanguageManager.h>
|
|
|
|
#include <MyGUI_ProgressBar.h>
|
2017-09-27 12:40:47 +02:00
|
|
|
#include <MyGUI_ScrollBar.h>
|
2023-11-23 19:52:18 +01:00
|
|
|
#include <MyGUI_UString.h>
|
2017-09-27 12:40:47 +02:00
|
|
|
#include <MyGUI_Window.h>
|
2015-01-10 02:50:43 +01:00
|
|
|
|
2018-08-14 23:05:43 +04:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadcrea.hpp>
|
2023-07-16 20:46:54 +02:00
|
|
|
#include <components/settings/values.hpp>
|
2015-03-11 20:04:25 +01:00
|
|
|
#include <components/translation/translation.hpp>
|
2022-08-30 07:54:20 +00:00
|
|
|
#include <components/widgets/box.hpp>
|
2014-09-25 16:25:08 +02:00
|
|
|
#include <components/widgets/list.hpp>
|
|
|
|
|
2015-03-11 20:04:25 +01:00
|
|
|
#include "../mwbase/dialoguemanager.hpp"
|
2012-05-17 17:15:44 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-11-05 19:55:06 +01:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2013-04-16 20:16:22 -04:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-05-17 17:15:44 +02:00
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
#include "../mwworld/class.hpp"
|
2013-11-21 04:27:53 +01:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
2014-12-19 11:26:54 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2023-09-24 21:58:10 +04:00
|
|
|
#include "../mwworld/player.hpp"
|
2013-05-11 18:38:27 +02:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2015-07-18 19:40:31 +02:00
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2023-09-24 21:58:10 +04:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2015-07-18 19:40:31 +02:00
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
#include "bookpage.hpp"
|
2017-07-24 13:25:01 +02:00
|
|
|
#include "textcolours.hpp"
|
2012-05-17 17:15:44 +02:00
|
|
|
|
2014-03-16 23:38:51 +01:00
|
|
|
#include "journalbooks.hpp" // to_utf8_span
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
namespace MWGui
|
2012-11-09 20:18:38 +01:00
|
|
|
{
|
2023-05-21 16:39:32 +02:00
|
|
|
void ResponseCallback::addResponse(std::string_view title, std::string_view text)
|
2017-10-24 00:25:41 +02:00
|
|
|
{
|
2022-09-01 18:25:41 +02:00
|
|
|
mWindow->addResponse(title, text, mNeedMargin);
|
|
|
|
}
|
2017-10-24 00:25:41 +02:00
|
|
|
|
2022-09-01 18:25:41 +02:00
|
|
|
void ResponseCallback::updateTopics() const
|
|
|
|
{
|
|
|
|
mWindow->updateTopics();
|
|
|
|
}
|
2017-10-24 00:25:41 +02:00
|
|
|
|
2022-08-28 11:35:39 +02:00
|
|
|
PersuasionDialog::PersuasionDialog(std::unique_ptr<ResponseCallback> callback)
|
2013-04-17 18:56:48 -04:00
|
|
|
: WindowModal("openmw_persuasion_dialog.layout")
|
2022-08-28 11:35:39 +02:00
|
|
|
, mCallback(std::move(callback))
|
2022-08-30 07:54:20 +00:00
|
|
|
, mInitialGoldLabelWidth(0)
|
|
|
|
, mInitialMainWidgetWidth(0)
|
2012-11-09 20:18:38 +01:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mCancelButton, "CancelButton");
|
|
|
|
getWidget(mAdmireButton, "AdmireButton");
|
|
|
|
getWidget(mIntimidateButton, "IntimidateButton");
|
|
|
|
getWidget(mTauntButton, "TauntButton");
|
|
|
|
getWidget(mBribe10Button, "Bribe10Button");
|
|
|
|
getWidget(mBribe100Button, "Bribe100Button");
|
|
|
|
getWidget(mBribe1000Button, "Bribe1000Button");
|
|
|
|
getWidget(mGoldLabel, "GoldLabel");
|
2022-08-30 07:54:20 +00:00
|
|
|
getWidget(mActionsBox, "ActionsBox");
|
|
|
|
|
|
|
|
int totalHeight = 3;
|
|
|
|
adjustAction(mAdmireButton, totalHeight);
|
|
|
|
adjustAction(mIntimidateButton, totalHeight);
|
|
|
|
adjustAction(mTauntButton, totalHeight);
|
|
|
|
adjustAction(mBribe10Button, totalHeight);
|
|
|
|
adjustAction(mBribe100Button, totalHeight);
|
|
|
|
adjustAction(mBribe1000Button, totalHeight);
|
|
|
|
totalHeight += 3;
|
|
|
|
|
|
|
|
int diff = totalHeight - mActionsBox->getSize().height;
|
|
|
|
if (diff > 0)
|
|
|
|
{
|
|
|
|
auto mainWidgetSize = mMainWidget->getSize();
|
|
|
|
mMainWidget->setSize(mainWidgetSize.width, mainWidgetSize.height + diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInitialGoldLabelWidth = mActionsBox->getSize().width - mCancelButton->getSize().width - 8;
|
|
|
|
mInitialMainWidgetWidth = mMainWidget->getSize().width;
|
2013-04-17 18:56:48 -04:00
|
|
|
|
|
|
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onCancel);
|
|
|
|
mAdmireButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
|
|
|
|
mIntimidateButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
|
|
|
|
mTauntButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
|
|
|
|
mBribe10Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
|
|
|
|
mBribe100Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
|
|
|
|
mBribe1000Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
|
2012-11-09 20:18:38 +01:00
|
|
|
}
|
2013-04-17 18:56:48 -04:00
|
|
|
|
2022-08-30 07:54:20 +00:00
|
|
|
void PersuasionDialog::adjustAction(MyGUI::Widget* action, int& totalHeight)
|
|
|
|
{
|
2023-07-16 20:46:54 +02:00
|
|
|
const int lineHeight = Settings::gui().mFontSize + 2;
|
2022-08-30 07:54:20 +00:00
|
|
|
auto currentCoords = action->getCoord();
|
|
|
|
action->setCoord(currentCoords.left, totalHeight, currentCoords.width, lineHeight);
|
|
|
|
totalHeight += lineHeight;
|
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void PersuasionDialog::onCancel(MyGUI::Widget* sender)
|
2012-11-09 20:18:38 +01:00
|
|
|
{
|
2017-09-23 12:18:39 +02:00
|
|
|
setVisible(false);
|
2012-11-09 20:18:38 +01:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void PersuasionDialog::onPersuade(MyGUI::Widget* sender)
|
|
|
|
{
|
|
|
|
MWBase::MechanicsManager::PersuasionType type;
|
|
|
|
if (sender == mAdmireButton)
|
|
|
|
type = MWBase::MechanicsManager::PT_Admire;
|
|
|
|
else if (sender == mIntimidateButton)
|
|
|
|
type = MWBase::MechanicsManager::PT_Intimidate;
|
|
|
|
else if (sender == mTauntButton)
|
|
|
|
type = MWBase::MechanicsManager::PT_Taunt;
|
|
|
|
else if (sender == mBribe10Button)
|
|
|
|
type = MWBase::MechanicsManager::PT_Bribe10;
|
|
|
|
else if (sender == mBribe100Button)
|
|
|
|
type = MWBase::MechanicsManager::PT_Bribe100;
|
|
|
|
else /*if (sender == mBribe1000Button)*/
|
|
|
|
type = MWBase::MechanicsManager::PT_Bribe1000;
|
2012-11-10 00:29:36 +01:00
|
|
|
|
2017-10-24 00:25:41 +02:00
|
|
|
MWBase::Environment::get().getDialogueManager()->persuade(type, mCallback.get());
|
2017-11-15 16:29:50 +01:00
|
|
|
mCallback->updateTopics();
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
setVisible(false);
|
|
|
|
}
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2017-09-22 17:10:53 +02:00
|
|
|
void PersuasionDialog::onOpen()
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
center();
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2014-01-08 23:37:46 +01:00
|
|
|
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
mBribe10Button->setEnabled(playerGold >= 10);
|
|
|
|
mBribe100Button->setEnabled(playerGold >= 100);
|
|
|
|
mBribe1000Button->setEnabled(playerGold >= 1000);
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2015-01-10 03:01:01 +01:00
|
|
|
mGoldLabel->setCaptionWithReplacing("#{sGold}: " + MyGUI::utility::toString(playerGold));
|
2022-08-30 07:54:20 +00:00
|
|
|
|
|
|
|
int diff = mGoldLabel->getRequestedSize().width - mInitialGoldLabelWidth;
|
|
|
|
if (diff > 0)
|
|
|
|
mMainWidget->setSize(mInitialMainWidgetWidth + diff, mMainWidget->getSize().height);
|
|
|
|
else
|
|
|
|
mMainWidget->setSize(mInitialMainWidgetWidth, mMainWidget->getSize().height);
|
|
|
|
|
2017-09-26 22:21:30 +02:00
|
|
|
WindowModal::onOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
MyGUI::Widget* PersuasionDialog::getDefaultKeyFocus()
|
|
|
|
{
|
|
|
|
return mAdmireButton;
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
// --------------------------------------------------------------------------------------------------
|
2010-11-03 21:21:08 +01:00
|
|
|
|
2023-05-21 16:39:32 +02:00
|
|
|
Response::Response(std::string_view text, std::string_view title, bool needMargin)
|
2017-06-08 22:40:31 +04:00
|
|
|
: mTitle(title)
|
|
|
|
, mNeedMargin(needMargin)
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
|
|
|
mText = text;
|
|
|
|
}
|
|
|
|
|
2022-08-28 11:35:39 +02:00
|
|
|
void Response::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch,
|
|
|
|
std::map<std::string, std::unique_ptr<Link>>& topicLinks) const
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2017-06-08 22:40:31 +04:00
|
|
|
typesetter->sectionBreak(mNeedMargin ? 9 : 0);
|
2022-08-28 11:35:39 +02:00
|
|
|
auto windowManager = MWBase::Environment::get().getWindowManager();
|
2017-06-04 23:20:43 +04:00
|
|
|
|
2022-08-28 11:35:39 +02:00
|
|
|
if (!mTitle.empty())
|
2017-06-04 23:20:43 +04:00
|
|
|
{
|
2022-08-28 11:35:39 +02:00
|
|
|
const MyGUI::Colour& headerColour = windowManager->getTextColours().header;
|
|
|
|
BookTypesetter::Style* title = typesetter->createStyle({}, headerColour, false);
|
2023-01-29 21:31:21 +01:00
|
|
|
typesetter->write(title, to_utf8_span(mTitle));
|
2017-06-08 22:40:31 +04:00
|
|
|
typesetter->sectionBreak();
|
2017-06-04 23:20:43 +04:00
|
|
|
}
|
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
typedef std::pair<size_t, size_t> Range;
|
|
|
|
std::map<Range, intptr_t> hyperLinks;
|
|
|
|
|
2013-05-06 13:13:14 +02:00
|
|
|
// We need this copy for when @# hyperlinks are replaced
|
|
|
|
std::string text = mText;
|
|
|
|
|
2021-04-19 15:51:00 +04:00
|
|
|
size_t pos_end = std::string::npos;
|
2013-05-04 14:15:47 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2014-09-26 17:12:48 +02:00
|
|
|
size_t pos_begin = text.find('@');
|
2013-05-04 14:15:47 +02:00
|
|
|
if (pos_begin != std::string::npos)
|
2013-05-06 13:13:14 +02:00
|
|
|
pos_end = text.find('#', pos_begin);
|
2013-05-04 14:15:47 +02:00
|
|
|
|
|
|
|
if (pos_begin != std::string::npos && pos_end != std::string::npos)
|
|
|
|
{
|
2013-05-06 13:13:14 +02:00
|
|
|
std::string link = text.substr(pos_begin + 1, pos_end - pos_begin - 1);
|
2013-05-04 14:15:47 +02:00
|
|
|
const char specialPseudoAsteriskCharacter = 127;
|
|
|
|
std::replace(link.begin(), link.end(), specialPseudoAsteriskCharacter, '*');
|
2022-08-28 11:35:39 +02:00
|
|
|
std::string topicName
|
|
|
|
= Misc::StringUtils::lowerCase(windowManager->getTranslationDataStorage().topicStandardForm(link));
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2024-01-24 20:39:04 +04:00
|
|
|
std::string displayName = std::move(link);
|
2013-05-06 13:13:14 +02:00
|
|
|
while (displayName[displayName.size() - 1] == '*')
|
|
|
|
displayName.erase(displayName.size() - 1, 1);
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2013-05-06 13:13:14 +02:00
|
|
|
text.replace(pos_begin, pos_end + 1 - pos_begin, displayName);
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2022-08-28 11:35:39 +02:00
|
|
|
if (topicLinks.find(topicName) != topicLinks.end())
|
|
|
|
hyperLinks[std::make_pair(pos_begin, pos_begin + displayName.size())]
|
|
|
|
= intptr_t(topicLinks[topicName].get());
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
2013-05-04 14:18:13 +02:00
|
|
|
else
|
|
|
|
break;
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
2023-01-29 21:31:21 +01:00
|
|
|
typesetter->addContent(to_utf8_span(text));
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2013-05-06 13:13:14 +02:00
|
|
|
if (hyperLinks.size()
|
|
|
|
&& MWBase::Environment::get().getWindowManager()->getTranslationDataStorage().hasTranslation())
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2017-07-24 13:25:01 +02:00
|
|
|
const TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
|
|
|
|
|
2023-05-21 16:39:32 +02:00
|
|
|
BookTypesetter::Style* style = typesetter->createStyle({}, textColours.normal, false);
|
2013-05-06 13:13:14 +02:00
|
|
|
size_t formatted = 0; // points to the first character that is not laid out yet
|
2019-03-02 13:27:59 +04:00
|
|
|
for (auto& hyperLink : hyperLinks)
|
2013-05-06 13:13:14 +02:00
|
|
|
{
|
2019-03-02 13:27:59 +04:00
|
|
|
intptr_t topicId = hyperLink.second;
|
2017-07-24 13:25:01 +02:00
|
|
|
BookTypesetter::Style* hotStyle = typesetter->createHotStyle(
|
|
|
|
style, textColours.link, textColours.linkOver, textColours.linkPressed, topicId);
|
2019-03-02 13:27:59 +04:00
|
|
|
if (formatted < hyperLink.first.first)
|
|
|
|
typesetter->write(style, formatted, hyperLink.first.first);
|
|
|
|
typesetter->write(hotStyle, hyperLink.first.first, hyperLink.first.second);
|
|
|
|
formatted = hyperLink.first.second;
|
2013-05-06 13:13:14 +02:00
|
|
|
}
|
|
|
|
if (formatted < text.size())
|
|
|
|
typesetter->write(style, formatted, text.size());
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
2013-05-06 13:13:14 +02:00
|
|
|
else
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2015-01-09 04:19:38 +01:00
|
|
|
std::vector<KeywordSearchT::Match> matches;
|
|
|
|
keywordSearch->highlightKeywords(text.begin(), text.end(), matches);
|
2014-05-10 17:05:15 -04:00
|
|
|
|
2015-01-09 04:19:38 +01:00
|
|
|
std::string::const_iterator i = text.begin();
|
2019-03-02 13:27:59 +04:00
|
|
|
for (KeywordSearchT::Match& match : matches)
|
2013-05-06 13:13:14 +02:00
|
|
|
{
|
|
|
|
if (i != match.mBeg)
|
|
|
|
addTopicLink(typesetter, 0, i - text.begin(), match.mBeg - text.begin());
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2013-05-06 13:13:14 +02:00
|
|
|
addTopicLink(typesetter, match.mValue, match.mBeg - text.begin(), match.mEnd - text.begin());
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2013-05-06 13:13:14 +02:00
|
|
|
i = match.mEnd;
|
|
|
|
}
|
|
|
|
if (i != text.end())
|
2024-01-24 20:39:04 +04:00
|
|
|
addTopicLink(std::move(typesetter), 0, i - text.begin(), text.size());
|
2013-05-06 13:13:14 +02:00
|
|
|
}
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
2013-05-06 13:13:14 +02:00
|
|
|
void Response::addTopicLink(BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end) const
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2017-07-24 13:25:01 +02:00
|
|
|
const TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
|
|
|
|
|
2023-05-21 16:39:32 +02:00
|
|
|
BookTypesetter::Style* style = typesetter->createStyle({}, textColours.normal, false);
|
2013-05-04 15:15:44 +02:00
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
if (topicId)
|
2017-07-24 13:25:01 +02:00
|
|
|
style = typesetter->createHotStyle(
|
|
|
|
style, textColours.link, textColours.linkOver, textColours.linkPressed, topicId);
|
2013-05-04 14:15:47 +02:00
|
|
|
typesetter->write(style, begin, end);
|
|
|
|
}
|
|
|
|
|
2023-05-21 16:39:32 +02:00
|
|
|
Message::Message(std::string_view text)
|
2013-05-04 15:15:44 +02:00
|
|
|
{
|
|
|
|
mText = text;
|
|
|
|
}
|
|
|
|
|
2022-08-28 11:35:39 +02:00
|
|
|
void Message::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch,
|
|
|
|
std::map<std::string, std::unique_ptr<Link>>& topicLinks) const
|
2013-05-04 15:15:44 +02:00
|
|
|
{
|
2017-07-24 13:25:01 +02:00
|
|
|
const MyGUI::Colour& textColour = MWBase::Environment::get().getWindowManager()->getTextColours().notify;
|
2023-05-21 16:39:32 +02:00
|
|
|
BookTypesetter::Style* title = typesetter->createStyle({}, textColour, false);
|
2013-05-04 15:15:44 +02:00
|
|
|
typesetter->sectionBreak(9);
|
2023-01-29 21:31:21 +01:00
|
|
|
typesetter->write(title, to_utf8_span(mText));
|
2013-05-04 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
// --------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Choice::activated()
|
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
|
2017-09-25 21:38:38 +02:00
|
|
|
eventChoiceActivated(mChoiceId);
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Topic::activated()
|
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
|
2017-09-25 21:38:38 +02:00
|
|
|
eventTopicActivated(mTopicId);
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
2013-05-04 15:15:44 +02:00
|
|
|
void Goodbye::activated()
|
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
|
2017-09-25 21:38:38 +02:00
|
|
|
eventActivated();
|
2013-05-04 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
// --------------------------------------------------------------------------------------------------
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
DialogueWindow::DialogueWindow()
|
|
|
|
: WindowBase("openmw_dialogue_window.layout")
|
2017-09-26 23:27:00 +02:00
|
|
|
, mIsCompanion(false)
|
2013-05-04 15:15:44 +02:00
|
|
|
, mGoodbye(false)
|
2022-08-28 11:35:39 +02:00
|
|
|
, mPersuasionDialog(std::make_unique<ResponseCallback>(this))
|
|
|
|
, mCallback(std::make_unique<ResponseCallback>(this))
|
|
|
|
, mGreetingCallback(std::make_unique<ResponseCallback>(this, false))
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
// Centre dialog
|
|
|
|
center();
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
mPersuasionDialog.setVisible(false);
|
2012-03-22 15:01:37 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
// History view
|
|
|
|
getWidget(mHistory, "History");
|
2010-11-03 21:21:08 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
// Topics list
|
|
|
|
getWidget(mTopicsList, "TopicsList");
|
2017-09-25 21:38:38 +02:00
|
|
|
mTopicsList->eventItemSelected += MyGUI::newDelegate(this, &DialogueWindow::onSelectListItem);
|
2010-11-03 21:21:08 +01:00
|
|
|
|
2017-09-22 16:58:05 +02:00
|
|
|
getWidget(mGoodbyeButton, "ByeButton");
|
|
|
|
mGoodbyeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &DialogueWindow::onByeClicked);
|
2012-05-10 11:19:22 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mDispositionBar, "Disposition");
|
|
|
|
getWidget(mDispositionText, "DispositionText");
|
2013-05-04 14:15:47 +02:00
|
|
|
getWidget(mScrollBar, "VScroll");
|
|
|
|
|
|
|
|
mScrollBar->eventScrollChangePosition += MyGUI::newDelegate(this, &DialogueWindow::onScrollbarMoved);
|
|
|
|
mHistory->eventMouseWheel += MyGUI::newDelegate(this, &DialogueWindow::onMouseWheel);
|
|
|
|
|
2023-05-14 22:51:43 +02:00
|
|
|
BookPage::ClickCallback callback = [this](TypesetBook::InteractiveId link) { notifyLinkClicked(link); };
|
2023-07-29 11:44:39 +04:00
|
|
|
mHistory->adviseLinkClicked(std::move(callback));
|
2010-11-03 21:21:08 +01:00
|
|
|
|
2014-09-13 04:07:40 +02:00
|
|
|
mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord
|
|
|
|
+= MyGUI::newDelegate(this, &DialogueWindow::onWindowResize);
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2010-11-03 21:21:08 +01:00
|
|
|
|
2017-09-25 18:07:49 +02:00
|
|
|
void DialogueWindow::onTradeComplete()
|
|
|
|
{
|
2023-05-21 16:39:32 +02:00
|
|
|
MyGUI::UString message = MyGUI::LanguageManager::getInstance().replaceTags("#{sBarterDialog5}");
|
2023-11-22 22:02:06 +01:00
|
|
|
addResponse({}, message);
|
2017-09-25 18:07:49 +02:00
|
|
|
}
|
|
|
|
|
2017-09-23 12:18:39 +02:00
|
|
|
bool DialogueWindow::exit()
|
2014-05-26 23:13:37 -04:00
|
|
|
{
|
2017-09-25 21:38:38 +02:00
|
|
|
if ((MWBase::Environment::get().getDialogueManager()->isInChoice()))
|
2014-07-13 06:42:24 +02:00
|
|
|
{
|
2017-09-23 12:18:39 +02:00
|
|
|
return false;
|
2014-07-13 06:42:24 +02:00
|
|
|
}
|
|
|
|
else
|
2015-06-01 23:49:40 +03:00
|
|
|
{
|
2017-09-25 19:58:34 +02:00
|
|
|
resetReference();
|
2014-07-13 06:42:24 +02:00
|
|
|
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
|
2015-06-01 23:49:40 +03:00
|
|
|
mTopicsList->scrollToTop();
|
2017-09-23 12:18:39 +02:00
|
|
|
return true;
|
2015-06-01 23:49:40 +03:00
|
|
|
}
|
2014-05-26 23:13:37 -04:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void DialogueWindow::onWindowResize(MyGUI::Window* _sender)
|
|
|
|
{
|
2017-07-24 13:25:01 +02:00
|
|
|
// if the window has only been moved, not resized, we don't need to update
|
|
|
|
if (mCurrentWindowSize == _sender->getSize())
|
|
|
|
return;
|
|
|
|
|
2024-01-11 03:12:13 +03:00
|
|
|
redrawTopicsList();
|
2013-05-04 14:15:47 +02:00
|
|
|
updateHistory();
|
2017-07-24 13:25:01 +02:00
|
|
|
mCurrentWindowSize = _sender->getSize();
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2010-11-03 21:21:08 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void DialogueWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
|
|
|
{
|
2013-05-04 14:15:47 +02:00
|
|
|
if (!mScrollBar->getVisible())
|
|
|
|
return;
|
2021-11-06 07:30:28 +03:00
|
|
|
mScrollBar->setScrollPosition(
|
|
|
|
std::clamp<int>(mScrollBar->getScrollPosition() - _rel * 0.3, 0, mScrollBar->getScrollRange() - 1));
|
2013-05-04 14:15:47 +02:00
|
|
|
onScrollbarMoved(mScrollBar, mScrollBar->getScrollPosition());
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-05-11 07:18:41 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void DialogueWindow::onByeClicked(MyGUI::Widget* _sender)
|
2012-09-26 18:30:47 +02:00
|
|
|
{
|
2017-09-23 12:18:39 +02:00
|
|
|
if (exit())
|
2020-04-07 02:06:58 +03:00
|
|
|
{
|
2017-09-23 12:18:39 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue);
|
2020-04-07 02:06:58 +03:00
|
|
|
}
|
2012-09-26 18:30:47 +02:00
|
|
|
}
|
2013-03-09 21:50:01 +01:00
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
void DialogueWindow::onSelectListItem(const std::string& topic, int id)
|
2012-10-17 18:03:02 +02:00
|
|
|
{
|
2020-08-21 17:18:39 +04:00
|
|
|
MWBase::DialogueManager* dialogueManager = MWBase::Environment::get().getDialogueManager();
|
|
|
|
|
|
|
|
if (mGoodbye || dialogueManager->isInChoice())
|
2013-04-17 18:56:48 -04:00
|
|
|
return;
|
2013-03-09 21:50:01 +01:00
|
|
|
|
2018-08-04 21:12:24 +03:00
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst
|
2023-04-20 21:07:53 +02:00
|
|
|
= MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>();
|
2018-08-04 21:12:24 +03:00
|
|
|
|
2022-03-06 17:38:58 +00:00
|
|
|
const std::string& sPersuasion = gmst.find("sPersuasion")->mValue.getString();
|
|
|
|
const std::string& sCompanionShare = gmst.find("sCompanionShare")->mValue.getString();
|
|
|
|
const std::string& sBarter = gmst.find("sBarter")->mValue.getString();
|
|
|
|
const std::string& sSpells = gmst.find("sSpells")->mValue.getString();
|
|
|
|
const std::string& sTravel = gmst.find("sTravel")->mValue.getString();
|
|
|
|
const std::string& sSpellMakingMenuTitle = gmst.find("sSpellMakingMenuTitle")->mValue.getString();
|
|
|
|
const std::string& sEnchanting = gmst.find("sEnchanting")->mValue.getString();
|
|
|
|
const std::string& sServiceTrainingTitle = gmst.find("sServiceTrainingTitle")->mValue.getString();
|
|
|
|
const std::string& sRepair = gmst.find("sRepair")->mValue.getString();
|
2018-08-04 21:12:24 +03:00
|
|
|
|
|
|
|
if (topic != sPersuasion && topic != sCompanionShare && topic != sBarter && topic != sSpells && topic != sTravel
|
|
|
|
&& topic != sSpellMakingMenuTitle && topic != sEnchanting && topic != sServiceTrainingTitle
|
|
|
|
&& topic != sRepair)
|
2017-09-28 16:57:55 +00:00
|
|
|
{
|
2017-09-25 21:38:38 +02:00
|
|
|
onTopicActivated(topic);
|
2017-09-28 17:00:07 +00:00
|
|
|
if (mGoodbyeButton->getEnabled())
|
2019-06-09 02:08:09 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mGoodbyeButton);
|
2017-09-28 16:57:55 +00:00
|
|
|
}
|
2018-08-04 21:12:24 +03:00
|
|
|
else if (topic == sPersuasion)
|
|
|
|
mPersuasionDialog.setVisible(true);
|
|
|
|
else if (topic == sCompanionShare)
|
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Companion, mPtr);
|
2020-08-21 17:18:39 +04:00
|
|
|
else if (!dialogueManager->checkServiceRefused(mCallback.get()))
|
2013-03-09 21:50:01 +01:00
|
|
|
{
|
2020-08-21 17:18:39 +04:00
|
|
|
if (topic == sBarter
|
|
|
|
&& !dialogueManager->checkServiceRefused(mCallback.get(), MWBase::DialogueManager::Barter))
|
2018-08-04 21:12:24 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Barter, mPtr);
|
2020-08-21 17:18:39 +04:00
|
|
|
else if (topic == sSpells
|
|
|
|
&& !dialogueManager->checkServiceRefused(mCallback.get(), MWBase::DialogueManager::Spells))
|
2018-08-04 21:12:24 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_SpellBuying, mPtr);
|
2020-08-21 17:18:39 +04:00
|
|
|
else if (topic == sTravel
|
|
|
|
&& !dialogueManager->checkServiceRefused(mCallback.get(), MWBase::DialogueManager::Travel))
|
2018-08-04 21:12:24 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Travel, mPtr);
|
2020-08-21 17:18:39 +04:00
|
|
|
else if (topic == sSpellMakingMenuTitle
|
|
|
|
&& !dialogueManager->checkServiceRefused(mCallback.get(), MWBase::DialogueManager::Spellmaking))
|
2018-08-04 21:12:24 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_SpellCreation, mPtr);
|
2020-08-21 17:18:39 +04:00
|
|
|
else if (topic == sEnchanting
|
|
|
|
&& !dialogueManager->checkServiceRefused(mCallback.get(), MWBase::DialogueManager::Enchanting))
|
2018-08-04 21:12:24 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Enchanting, mPtr);
|
2020-08-21 17:18:39 +04:00
|
|
|
else if (topic == sServiceTrainingTitle
|
|
|
|
&& !dialogueManager->checkServiceRefused(mCallback.get(), MWBase::DialogueManager::Training))
|
2018-08-04 21:12:24 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_Training, mPtr);
|
2020-08-21 17:18:39 +04:00
|
|
|
else if (topic == sRepair
|
|
|
|
&& !dialogueManager->checkServiceRefused(mCallback.get(), MWBase::DialogueManager::Repair))
|
2018-08-04 21:12:24 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(GM_MerchantRepair, mPtr);
|
2013-03-09 21:50:01 +01:00
|
|
|
}
|
2018-08-04 21:12:24 +03:00
|
|
|
else
|
|
|
|
updateTopics();
|
2012-10-17 18:03:02 +02:00
|
|
|
}
|
2010-11-03 21:21:08 +01:00
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
void DialogueWindow::setPtr(const MWWorld::Ptr& actor)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2023-08-20 15:27:00 +02:00
|
|
|
if (actor.isEmpty() || !actor.getClass().isActor())
|
2018-08-05 09:31:45 +04:00
|
|
|
{
|
2018-08-14 23:05:43 +04:00
|
|
|
Log(Debug::Warning) << "Warning: can not talk with non-actor object.";
|
2018-08-05 09:31:45 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-24 00:25:41 +02:00
|
|
|
bool sameActor = (mPtr == actor);
|
|
|
|
if (!sameActor)
|
|
|
|
{
|
2020-04-07 02:06:58 +03:00
|
|
|
// The history is not reset here
|
2017-10-24 00:25:41 +02:00
|
|
|
mKeywords.clear();
|
|
|
|
mTopicsList->clear();
|
2022-08-28 11:35:39 +02:00
|
|
|
for (auto& link : mLinks)
|
|
|
|
mDeleteLater.push_back(
|
|
|
|
std::move(link)); // Links are not deleted right away to prevent issues with event handlers
|
2017-10-24 00:25:41 +02:00
|
|
|
mLinks.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
mPtr = actor;
|
|
|
|
mGoodbye = false;
|
|
|
|
mTopicsList->setEnabled(true);
|
|
|
|
|
2019-05-14 14:20:27 +04:00
|
|
|
if (!MWBase::Environment::get().getDialogueManager()->startDialogue(actor, mGreetingCallback.get()))
|
2017-09-25 21:38:38 +02:00
|
|
|
{
|
|
|
|
// No greetings found. The dialogue window should not be shown.
|
|
|
|
// If this is a companion, we must show the companion window directly (used by BM_bear_be_unique).
|
2017-10-03 22:07:56 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Dialogue);
|
2017-10-24 00:25:41 +02:00
|
|
|
mPtr = MWWorld::Ptr();
|
2019-05-14 14:20:27 +04:00
|
|
|
if (isCompanion(actor))
|
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Companion, actor);
|
2017-09-25 21:38:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-05-14 14:20:27 +04:00
|
|
|
|
2019-06-09 02:08:09 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mGoodbyeButton);
|
2017-09-22 16:58:05 +02:00
|
|
|
|
2019-05-14 14:20:27 +04:00
|
|
|
setTitle(mPtr.getClass().getName(mPtr));
|
|
|
|
|
2017-11-15 16:29:50 +01:00
|
|
|
updateTopics();
|
2020-12-12 22:43:06 +03:00
|
|
|
updateTopicsPane(); // force update for new services
|
2017-11-15 16:29:50 +01:00
|
|
|
|
2019-05-14 14:20:27 +04:00
|
|
|
updateDisposition();
|
|
|
|
restock();
|
2014-07-28 02:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogueWindow::restock()
|
|
|
|
{
|
|
|
|
MWMechanics::CreatureStats& sellerStats = mPtr.getClass().getCreatureStats(mPtr);
|
2018-08-29 18:38:12 +03:00
|
|
|
float delay = MWBase::Environment::get()
|
2023-04-20 21:07:53 +02:00
|
|
|
.getESMStore()
|
|
|
|
->get<ESM::GameSetting>()
|
2018-08-29 18:38:12 +03:00
|
|
|
.find("fBarterGoldResetDelay")
|
|
|
|
->mValue.getFloat();
|
2014-07-28 02:27:48 +02:00
|
|
|
|
2014-12-20 20:17:14 +01:00
|
|
|
// Gold is restocked every 24h
|
2014-07-28 02:27:48 +02:00
|
|
|
if (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getLastRestockTime() + delay)
|
|
|
|
{
|
|
|
|
sellerStats.setGoldPool(mPtr.getClass().getBaseGold(mPtr));
|
|
|
|
|
|
|
|
sellerStats.setLastRestockTime(MWBase::Environment::get().getWorld()->getTimeStamp());
|
|
|
|
}
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-01-27 14:50:13 +01:00
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
void DialogueWindow::deleteLater()
|
|
|
|
{
|
|
|
|
mDeleteLater.clear();
|
|
|
|
}
|
|
|
|
|
2020-04-14 08:49:14 +03:00
|
|
|
void DialogueWindow::onClose()
|
2020-04-07 02:06:58 +03:00
|
|
|
{
|
2020-05-09 02:01:55 +03:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->containsMode(GM_Dialogue))
|
|
|
|
return;
|
2020-04-14 08:49:14 +03:00
|
|
|
// Reset history
|
2020-04-07 02:06:58 +03:00
|
|
|
mHistoryContents.clear();
|
|
|
|
}
|
|
|
|
|
2021-06-23 23:13:59 +02:00
|
|
|
bool DialogueWindow::setKeywords(const std::list<std::string>& keyWords)
|
2017-09-26 23:27:00 +02:00
|
|
|
{
|
|
|
|
if (mKeywords == keyWords && isCompanion() == mIsCompanion)
|
2020-12-12 22:43:06 +03:00
|
|
|
return false;
|
2017-09-26 23:27:00 +02:00
|
|
|
mIsCompanion = isCompanion();
|
|
|
|
mKeywords = keyWords;
|
2020-12-12 22:43:06 +03:00
|
|
|
updateTopicsPane();
|
|
|
|
return true;
|
2017-09-26 23:27:00 +02:00
|
|
|
}
|
|
|
|
|
2024-01-11 03:12:13 +03:00
|
|
|
void DialogueWindow::redrawTopicsList()
|
|
|
|
{
|
|
|
|
mTopicsList->adjustSize();
|
|
|
|
|
|
|
|
// The topics list has been regenerated so topic formatting needs to be updated
|
|
|
|
updateTopicFormat();
|
|
|
|
}
|
|
|
|
|
2017-09-26 23:27:00 +02:00
|
|
|
void DialogueWindow::updateTopicsPane()
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
mTopicsList->clear();
|
2019-03-02 13:27:59 +04:00
|
|
|
for (auto& linkPair : mTopicLinks)
|
2022-08-28 11:35:39 +02:00
|
|
|
mDeleteLater.push_back(std::move(linkPair.second));
|
2013-05-04 14:15:47 +02:00
|
|
|
mTopicLinks.clear();
|
|
|
|
mKeywordSearch.clear();
|
2012-05-17 14:54:03 +02:00
|
|
|
|
2017-09-25 19:52:20 +02:00
|
|
|
int services = mPtr.getClass().getServices(mPtr);
|
|
|
|
|
2021-10-11 11:46:21 +00:00
|
|
|
bool travel = (mPtr.getType() == ESM::NPC::sRecordId && !mPtr.get<ESM::NPC>()->mBase->getTransport().empty())
|
|
|
|
|| (mPtr.getType() == ESM::Creature::sRecordId
|
|
|
|
&& !mPtr.get<ESM::Creature>()->mBase->getTransport().empty());
|
2017-09-25 19:52:20 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst
|
2023-04-20 21:07:53 +02:00
|
|
|
= MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>();
|
2012-11-06 00:34:11 +04:00
|
|
|
|
2021-10-11 11:46:21 +00:00
|
|
|
if (mPtr.getType() == ESM::NPC::sRecordId)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sPersuasion")->mValue.getString());
|
2012-11-09 20:18:38 +01:00
|
|
|
|
2017-09-25 19:52:20 +02:00
|
|
|
if (services & ESM::NPC::AllItems)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sBarter")->mValue.getString());
|
2012-05-17 14:54:03 +02:00
|
|
|
|
2017-09-25 19:52:20 +02:00
|
|
|
if (services & ESM::NPC::Spells)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sSpells")->mValue.getString());
|
2012-09-08 18:17:03 -04:00
|
|
|
|
2017-09-30 16:53:39 +02:00
|
|
|
if (travel)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sTravel")->mValue.getString());
|
2012-09-26 18:30:47 +02:00
|
|
|
|
2017-09-25 19:52:20 +02:00
|
|
|
if (services & ESM::NPC::Spellmaking)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sSpellmakingMenuTitle")->mValue.getString());
|
2012-09-27 08:47:47 +02:00
|
|
|
|
2017-09-25 19:52:20 +02:00
|
|
|
if (services & ESM::NPC::Enchanting)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sEnchanting")->mValue.getString());
|
2012-09-23 00:36:20 +02:00
|
|
|
|
2017-09-25 19:52:20 +02:00
|
|
|
if (services & ESM::NPC::Training)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sServiceTrainingTitle")->mValue.getString());
|
2012-10-17 18:03:02 +02:00
|
|
|
|
2017-09-25 19:52:20 +02:00
|
|
|
if (services & ESM::NPC::Repair)
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sRepair")->mValue.getString());
|
2013-03-22 14:13:10 +01:00
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
if (isCompanion())
|
2018-08-29 18:38:12 +03:00
|
|
|
mTopicsList->addItem(gmst.find("sCompanionShare")->mValue.getString());
|
2013-03-31 13:13:46 +02:00
|
|
|
|
2015-03-11 20:04:25 +01:00
|
|
|
if (mTopicsList->getItemCount() > 0)
|
2013-04-17 18:56:48 -04:00
|
|
|
mTopicsList->addSeparator();
|
2012-05-17 14:54:03 +02:00
|
|
|
|
2019-05-13 22:32:46 +02:00
|
|
|
for (const auto& keyword : mKeywords)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2019-05-13 22:32:46 +02:00
|
|
|
std::string topicId = Misc::StringUtils::lowerCase(keyword);
|
2019-03-02 13:27:59 +04:00
|
|
|
mTopicsList->addItem(keyword);
|
2012-01-27 14:50:13 +01:00
|
|
|
|
2022-08-28 11:35:39 +02:00
|
|
|
auto t = std::make_unique<Topic>(keyword);
|
|
|
|
mKeywordSearch.seed(topicId, intptr_t(t.get()));
|
2017-09-25 21:38:38 +02:00
|
|
|
t->eventTopicActivated += MyGUI::newDelegate(this, &DialogueWindow::onTopicActivated);
|
2022-08-28 11:35:39 +02:00
|
|
|
mTopicLinks[topicId] = std::move(t);
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
|
|
|
|
2024-01-11 03:12:13 +03:00
|
|
|
redrawTopicsList();
|
2013-05-04 14:15:47 +02:00
|
|
|
updateHistory();
|
2012-01-27 14:50:13 +01:00
|
|
|
}
|
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
void DialogueWindow::updateHistory(bool scrollbar)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2013-05-04 14:15:47 +02:00
|
|
|
if (!scrollbar && mScrollBar->getVisible())
|
|
|
|
{
|
|
|
|
mHistory->setSize(mHistory->getSize() + MyGUI::IntSize(mScrollBar->getWidth(), 0));
|
|
|
|
mScrollBar->setVisible(false);
|
|
|
|
}
|
|
|
|
if (scrollbar && !mScrollBar->getVisible())
|
|
|
|
{
|
|
|
|
mHistory->setSize(mHistory->getSize() - MyGUI::IntSize(mScrollBar->getWidth(), 0));
|
|
|
|
mScrollBar->setVisible(true);
|
|
|
|
}
|
|
|
|
|
2014-10-12 23:26:03 +02:00
|
|
|
BookTypesetter::Ptr typesetter = BookTypesetter::create(mHistory->getWidth(), std::numeric_limits<int>::max());
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2022-08-28 11:35:39 +02:00
|
|
|
for (const auto& text : mHistoryContents)
|
2019-03-02 13:27:59 +04:00
|
|
|
text->write(typesetter, &mKeywordSearch, mTopicLinks);
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2023-05-21 16:39:32 +02:00
|
|
|
BookTypesetter::Style* body = typesetter->createStyle({}, MyGUI::Colour::White, false);
|
2013-05-04 14:15:47 +02:00
|
|
|
|
2013-06-16 19:46:55 +02:00
|
|
|
typesetter->sectionBreak(9);
|
2013-05-04 14:15:47 +02:00
|
|
|
// choices
|
2017-07-24 13:25:01 +02:00
|
|
|
const TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
|
2017-09-25 21:38:38 +02:00
|
|
|
mChoices = MWBase::Environment::get().getDialogueManager()->getChoices();
|
2019-03-02 13:27:59 +04:00
|
|
|
for (std::pair<std::string, int>& choice : mChoices)
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2022-08-28 11:35:39 +02:00
|
|
|
auto link = std::make_unique<Choice>(choice.second);
|
2017-09-25 21:38:38 +02:00
|
|
|
link->eventChoiceActivated += MyGUI::newDelegate(this, &DialogueWindow::onChoiceActivated);
|
2022-08-28 11:35:39 +02:00
|
|
|
auto interactiveId = TypesetBook::InteractiveId(link.get());
|
|
|
|
mLinks.push_back(std::move(link));
|
2013-05-04 14:15:47 +02:00
|
|
|
|
|
|
|
typesetter->lineBreak();
|
2017-07-24 13:25:01 +02:00
|
|
|
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(
|
|
|
|
body, textColours.answer, textColours.answerOver, textColours.answerPressed, interactiveId);
|
2023-01-29 21:31:21 +01:00
|
|
|
typesetter->write(questionStyle, to_utf8_span(choice.first));
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
mGoodbye = MWBase::Environment::get().getDialogueManager()->isGoodbye();
|
2013-05-04 15:15:44 +02:00
|
|
|
if (mGoodbye)
|
|
|
|
{
|
2022-08-28 11:35:39 +02:00
|
|
|
auto link = std::make_unique<Goodbye>();
|
2017-09-25 21:38:38 +02:00
|
|
|
link->eventActivated += MyGUI::newDelegate(this, &DialogueWindow::onGoodbyeActivated);
|
2022-08-28 11:35:39 +02:00
|
|
|
auto interactiveId = TypesetBook::InteractiveId(link.get());
|
|
|
|
mLinks.push_back(std::move(link));
|
2022-03-06 17:38:58 +00:00
|
|
|
const std::string& goodbye = MWBase::Environment::get()
|
2023-04-20 21:07:53 +02:00
|
|
|
.getESMStore()
|
|
|
|
->get<ESM::GameSetting>()
|
2022-03-06 17:38:58 +00:00
|
|
|
.find("sGoodbye")
|
|
|
|
->mValue.getString();
|
2017-07-24 13:25:01 +02:00
|
|
|
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(
|
|
|
|
body, textColours.answer, textColours.answerOver, textColours.answerPressed, interactiveId);
|
2013-05-04 15:15:44 +02:00
|
|
|
typesetter->lineBreak();
|
2023-01-29 21:31:21 +01:00
|
|
|
typesetter->write(questionStyle, to_utf8_span(goodbye));
|
2013-05-04 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
TypesetBook::Ptr book = typesetter->complete();
|
|
|
|
mHistory->showPage(book, 0);
|
|
|
|
size_t viewHeight = mHistory->getParent()->getHeight();
|
|
|
|
if (!scrollbar && book->getSize().second > viewHeight)
|
|
|
|
updateHistory(true);
|
|
|
|
else if (scrollbar)
|
|
|
|
{
|
|
|
|
mHistory->setSize(MyGUI::IntSize(mHistory->getWidth(), book->getSize().second));
|
|
|
|
size_t range = book->getSize().second - viewHeight;
|
|
|
|
mScrollBar->setScrollRange(range);
|
|
|
|
mScrollBar->setScrollPosition(range - 1);
|
2015-03-08 13:07:29 +13:00
|
|
|
mScrollBar->setTrackSize(
|
|
|
|
static_cast<int>(viewHeight / static_cast<float>(book->getSize().second) * mScrollBar->getLineSize()));
|
2013-05-04 14:15:47 +02:00
|
|
|
onScrollbarMoved(mScrollBar, range - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no scrollbar
|
|
|
|
onScrollbarMoved(mScrollBar, 0);
|
|
|
|
}
|
2014-05-27 00:30:37 -04:00
|
|
|
|
2014-09-28 14:00:15 +02:00
|
|
|
bool goodbyeEnabled = !MWBase::Environment::get().getDialogueManager()->isInChoice() || mGoodbye;
|
2017-09-23 12:55:28 +02:00
|
|
|
bool goodbyeWasEnabled = mGoodbyeButton->getEnabled();
|
2017-09-22 16:58:05 +02:00
|
|
|
mGoodbyeButton->setEnabled(goodbyeEnabled);
|
2017-09-23 12:55:28 +02:00
|
|
|
if (goodbyeEnabled && !goodbyeWasEnabled)
|
2019-06-09 02:08:09 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mGoodbyeButton);
|
2014-09-28 14:00:15 +02:00
|
|
|
|
|
|
|
bool topicsEnabled = !MWBase::Environment::get().getDialogueManager()->isInChoice() && !mGoodbye;
|
|
|
|
mTopicsList->setEnabled(topicsEnabled);
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-12-26 22:57:53 +00:00
|
|
|
|
2013-05-04 14:15:47 +02:00
|
|
|
void DialogueWindow::notifyLinkClicked(TypesetBook::InteractiveId link)
|
2012-04-17 23:47:50 +02:00
|
|
|
{
|
2013-05-04 14:15:47 +02:00
|
|
|
reinterpret_cast<Link*>(link)->activated();
|
2012-04-17 23:47:50 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
void DialogueWindow::onTopicActivated(const std::string& topicId)
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2018-07-06 19:38:36 +03:00
|
|
|
if (mGoodbye)
|
|
|
|
return;
|
|
|
|
|
2017-10-24 00:25:41 +02:00
|
|
|
MWBase::Environment::get().getDialogueManager()->keywordSelected(topicId, mCallback.get());
|
2017-11-15 16:29:50 +01:00
|
|
|
updateTopics();
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
void DialogueWindow::onChoiceActivated(int id)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2018-06-07 22:05:55 +03:00
|
|
|
if (mGoodbye)
|
|
|
|
{
|
|
|
|
onGoodbyeActivated();
|
|
|
|
return;
|
|
|
|
}
|
2017-10-24 00:25:41 +02:00
|
|
|
MWBase::Environment::get().getDialogueManager()->questionAnswered(id, mCallback.get());
|
2017-11-15 16:29:50 +01:00
|
|
|
updateTopics();
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
void DialogueWindow::onGoodbyeActivated()
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2017-09-25 21:38:38 +02:00
|
|
|
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Dialogue);
|
|
|
|
resetReference();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogueWindow::onScrollbarMoved(MyGUI::ScrollBar* sender, size_t pos)
|
|
|
|
{
|
|
|
|
mHistory->setPosition(0, static_cast<int>(pos) * -1);
|
2013-05-04 14:15:47 +02:00
|
|
|
}
|
|
|
|
|
2023-05-21 16:39:32 +02:00
|
|
|
void DialogueWindow::addResponse(std::string_view title, std::string_view text, bool needMargin)
|
2013-05-04 14:15:47 +02:00
|
|
|
{
|
2022-08-28 11:35:39 +02:00
|
|
|
mHistoryContents.push_back(std::make_unique<Response>(text, title, needMargin));
|
2013-05-04 14:15:47 +02:00
|
|
|
updateHistory();
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-01-28 16:08:22 +01:00
|
|
|
|
2023-05-21 16:39:32 +02:00
|
|
|
void DialogueWindow::addMessageBox(std::string_view text)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2022-08-28 11:35:39 +02:00
|
|
|
mHistoryContents.push_back(std::make_unique<Message>(text));
|
2013-05-04 14:15:47 +02:00
|
|
|
updateHistory();
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-01-27 14:50:13 +01:00
|
|
|
|
2017-09-25 21:29:06 +02:00
|
|
|
void DialogueWindow::updateDisposition()
|
2012-11-08 22:31:08 +01:00
|
|
|
{
|
2014-06-26 15:36:19 +02:00
|
|
|
bool dispositionVisible = false;
|
2017-09-25 21:29:06 +02:00
|
|
|
if (!mPtr.isEmpty() && mPtr.getClass().isNpc())
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2023-09-24 21:58:10 +04:00
|
|
|
// If actor was a witness to a crime which was payed off,
|
|
|
|
// restore original disposition immediately.
|
|
|
|
MWMechanics::NpcStats& npcStats = mPtr.getClass().getNpcStats(mPtr);
|
|
|
|
if (npcStats.getCrimeId() != -1 && npcStats.getCrimeDispositionModifier() != 0)
|
|
|
|
{
|
|
|
|
if (npcStats.getCrimeId() <= MWBase::Environment::get().getWorld()->getPlayer().getCrimeId())
|
|
|
|
npcStats.setCrimeDispositionModifier(0);
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:36:19 +02:00
|
|
|
dispositionVisible = true;
|
2013-04-17 18:56:48 -04:00
|
|
|
mDispositionBar->setProgressRange(100);
|
|
|
|
mDispositionBar->setProgressPosition(
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr));
|
2015-01-10 03:01:01 +01:00
|
|
|
mDispositionText->setCaption(
|
|
|
|
MyGUI::utility::toString(MWBase::Environment::get().getMechanicsManager()->getDerivedDisposition(mPtr))
|
|
|
|
+ std::string("/100"));
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2014-06-26 15:36:19 +02:00
|
|
|
|
2024-01-11 03:12:13 +03:00
|
|
|
if (mDispositionBar->getVisible() != dispositionVisible)
|
2014-06-26 15:36:19 +02:00
|
|
|
{
|
2024-01-11 03:12:13 +03:00
|
|
|
mDispositionBar->setVisible(dispositionVisible);
|
|
|
|
const int offset = (mDispositionBar->getHeight() + 5) * (dispositionVisible ? 1 : -1);
|
2014-06-26 15:36:19 +02:00
|
|
|
mTopicsList->setCoord(mTopicsList->getCoord() + MyGUI::IntCoord(0, offset, 0, -offset));
|
2024-01-11 03:12:13 +03:00
|
|
|
redrawTopicsList();
|
2014-06-26 15:36:19 +02:00
|
|
|
}
|
2012-11-08 22:31:08 +01:00
|
|
|
}
|
2012-05-11 07:18:41 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void DialogueWindow::onReferenceUnavailable()
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue);
|
|
|
|
}
|
2012-11-05 23:16:37 +01:00
|
|
|
|
2017-09-23 22:00:15 +02:00
|
|
|
void DialogueWindow::onFrame(float dt)
|
2012-11-05 23:16:37 +01:00
|
|
|
{
|
2017-09-23 22:00:15 +02:00
|
|
|
checkReferenceAvailable();
|
2017-09-25 21:38:38 +02:00
|
|
|
if (mPtr.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2017-09-25 21:29:06 +02:00
|
|
|
updateDisposition();
|
2017-09-25 21:38:38 +02:00
|
|
|
deleteLater();
|
|
|
|
|
|
|
|
if (mChoices != MWBase::Environment::get().getDialogueManager()->getChoices()
|
|
|
|
|| mGoodbye != MWBase::Environment::get().getDialogueManager()->isGoodbye())
|
|
|
|
updateHistory();
|
|
|
|
}
|
|
|
|
|
2019-05-13 22:32:46 +02:00
|
|
|
void DialogueWindow::updateTopicFormat()
|
|
|
|
{
|
2023-07-16 20:46:54 +02:00
|
|
|
if (!Settings::gui().mColorTopicEnable)
|
2020-06-22 03:24:41 +02:00
|
|
|
return;
|
|
|
|
|
2023-07-16 20:46:54 +02:00
|
|
|
const MyGUI::Colour& specialColour = Settings::gui().mColorTopicSpecific;
|
|
|
|
const MyGUI::Colour& oldColour = Settings::gui().mColorTopicExhausted;
|
2019-05-13 22:32:46 +02:00
|
|
|
|
|
|
|
for (const std::string& keyword : mKeywords)
|
|
|
|
{
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
int flag = MWBase::Environment::get().getDialogueManager()->getTopicFlag(ESM::RefId::stringRefId(keyword));
|
2019-05-13 22:32:46 +02:00
|
|
|
MyGUI::Button* button = mTopicsList->getItemWidget(keyword);
|
|
|
|
|
2023-07-16 20:46:54 +02:00
|
|
|
if (flag & MWBase::DialogueManager::TopicType::Specific)
|
|
|
|
button->getSubWidgetText()->setTextColour(specialColour);
|
|
|
|
else if (flag & MWBase::DialogueManager::TopicType::Exhausted)
|
|
|
|
button->getSubWidgetText()->setTextColour(oldColour);
|
2019-05-13 22:32:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 21:38:38 +02:00
|
|
|
void DialogueWindow::updateTopics()
|
|
|
|
{
|
2020-12-12 22:43:06 +03:00
|
|
|
// Topic formatting needs to be updated regardless of whether the topic list has changed
|
|
|
|
if (!setKeywords(MWBase::Environment::get().getDialogueManager()->getAvailableTopics()))
|
|
|
|
updateTopicFormat();
|
2017-09-25 21:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DialogueWindow::isCompanion()
|
|
|
|
{
|
2017-10-21 16:56:21 +04:00
|
|
|
return isCompanion(mPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DialogueWindow::isCompanion(const MWWorld::Ptr& actor)
|
|
|
|
{
|
2018-11-13 10:32:23 +04:00
|
|
|
if (actor.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
2017-10-21 16:56:21 +04:00
|
|
|
return !actor.getClass().getScript(actor).empty()
|
|
|
|
&& actor.getRefData().getLocals().getIntVar(actor.getClass().getScript(actor), "companion");
|
2017-09-25 21:38:38 +02:00
|
|
|
}
|
|
|
|
|
2012-11-05 23:16:37 +01:00
|
|
|
}
|