mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-05 06:40:09 +00:00
Merge branch 'pointed_words' into 'master'
Use unique_ptr in MWGui::DialogueWindow See merge request OpenMW/openmw!2344
This commit is contained in:
commit
1e389b26aa
@ -56,9 +56,9 @@ namespace MWGui
|
|||||||
bool mNeedMargin;
|
bool mNeedMargin;
|
||||||
};
|
};
|
||||||
|
|
||||||
PersuasionDialog::PersuasionDialog(ResponseCallback* callback)
|
PersuasionDialog::PersuasionDialog(std::unique_ptr<ResponseCallback> callback)
|
||||||
: WindowModal("openmw_persuasion_dialog.layout")
|
: WindowModal("openmw_persuasion_dialog.layout")
|
||||||
, mCallback(callback)
|
, mCallback(std::move(callback))
|
||||||
{
|
{
|
||||||
getWidget(mCancelButton, "CancelButton");
|
getWidget(mCancelButton, "CancelButton");
|
||||||
getWidget(mAdmireButton, "AdmireButton");
|
getWidget(mAdmireButton, "AdmireButton");
|
||||||
@ -130,14 +130,15 @@ namespace MWGui
|
|||||||
mText = text;
|
mText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const
|
void Response::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, std::unique_ptr<Link>>& topicLinks) const
|
||||||
{
|
{
|
||||||
typesetter->sectionBreak(mNeedMargin ? 9 : 0);
|
typesetter->sectionBreak(mNeedMargin ? 9 : 0);
|
||||||
|
auto windowManager = MWBase::Environment::get().getWindowManager();
|
||||||
|
|
||||||
if (mTitle != "")
|
if (!mTitle.empty())
|
||||||
{
|
{
|
||||||
const MyGUI::Colour& headerColour = MWBase::Environment::get().getWindowManager()->getTextColours().header;
|
const MyGUI::Colour& headerColour = windowManager->getTextColours().header;
|
||||||
BookTypesetter::Style* title = typesetter->createStyle("", headerColour, false);
|
BookTypesetter::Style* title = typesetter->createStyle({}, headerColour, false);
|
||||||
typesetter->write(title, to_utf8_span(mTitle.c_str()));
|
typesetter->write(title, to_utf8_span(mTitle.c_str()));
|
||||||
typesetter->sectionBreak();
|
typesetter->sectionBreak();
|
||||||
}
|
}
|
||||||
@ -160,8 +161,7 @@ namespace MWGui
|
|||||||
std::string link = text.substr(pos_begin + 1, pos_end - pos_begin - 1);
|
std::string link = text.substr(pos_begin + 1, pos_end - pos_begin - 1);
|
||||||
const char specialPseudoAsteriskCharacter = 127;
|
const char specialPseudoAsteriskCharacter = 127;
|
||||||
std::replace(link.begin(), link.end(), specialPseudoAsteriskCharacter, '*');
|
std::replace(link.begin(), link.end(), specialPseudoAsteriskCharacter, '*');
|
||||||
std::string topicName = MWBase::Environment::get().getWindowManager()->
|
std::string topicName = Misc::StringUtils::lowerCase(windowManager->getTranslationDataStorage().topicStandardForm(link));
|
||||||
getTranslationDataStorage().topicStandardForm(link);
|
|
||||||
|
|
||||||
std::string displayName = link;
|
std::string displayName = link;
|
||||||
while (displayName[displayName.size()-1] == '*')
|
while (displayName[displayName.size()-1] == '*')
|
||||||
@ -169,8 +169,8 @@ namespace MWGui
|
|||||||
|
|
||||||
text.replace(pos_begin, pos_end+1-pos_begin, displayName);
|
text.replace(pos_begin, pos_end+1-pos_begin, displayName);
|
||||||
|
|
||||||
if (topicLinks.find(Misc::StringUtils::lowerCase(topicName)) != topicLinks.end())
|
if (topicLinks.find(topicName) != topicLinks.end())
|
||||||
hyperLinks[std::make_pair(pos_begin, pos_begin+displayName.size())] = intptr_t(topicLinks[Misc::StringUtils::lowerCase(topicName)]);
|
hyperLinks[std::make_pair(pos_begin, pos_begin+displayName.size())] = intptr_t(topicLinks[topicName].get());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@ -235,7 +235,7 @@ namespace MWGui
|
|||||||
mText = text;
|
mText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Message::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const
|
void Message::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, std::unique_ptr<Link>>& topicLinks) const
|
||||||
{
|
{
|
||||||
const MyGUI::Colour& textColour = MWBase::Environment::get().getWindowManager()->getTextColours().notify;
|
const MyGUI::Colour& textColour = MWBase::Environment::get().getWindowManager()->getTextColours().notify;
|
||||||
BookTypesetter::Style* title = typesetter->createStyle("", textColour, false);
|
BookTypesetter::Style* title = typesetter->createStyle("", textColour, false);
|
||||||
@ -269,9 +269,9 @@ namespace MWGui
|
|||||||
: WindowBase("openmw_dialogue_window.layout")
|
: WindowBase("openmw_dialogue_window.layout")
|
||||||
, mIsCompanion(false)
|
, mIsCompanion(false)
|
||||||
, mGoodbye(false)
|
, mGoodbye(false)
|
||||||
, mPersuasionDialog(new ResponseCallback(this))
|
, mPersuasionDialog(std::make_unique<ResponseCallback>(this))
|
||||||
, mCallback(new ResponseCallback(this))
|
, mCallback(std::make_unique<ResponseCallback>(this))
|
||||||
, mGreetingCallback(new ResponseCallback(this, false))
|
, mGreetingCallback(std::make_unique<ResponseCallback>(this, false))
|
||||||
{
|
{
|
||||||
// Centre dialog
|
// Centre dialog
|
||||||
center();
|
center();
|
||||||
@ -301,17 +301,6 @@ namespace MWGui
|
|||||||
mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize);
|
mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize);
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogueWindow::~DialogueWindow()
|
|
||||||
{
|
|
||||||
deleteLater();
|
|
||||||
for (Link* link : mLinks)
|
|
||||||
delete link;
|
|
||||||
for (const auto& link : mTopicLinks)
|
|
||||||
delete link.second;
|
|
||||||
for (auto history : mHistoryContents)
|
|
||||||
delete history;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogueWindow::onTradeComplete()
|
void DialogueWindow::onTradeComplete()
|
||||||
{
|
{
|
||||||
addResponse("", MyGUI::LanguageManager::getInstance().replaceTags("#{sBarterDialog5}"));
|
addResponse("", MyGUI::LanguageManager::getInstance().replaceTags("#{sBarterDialog5}"));
|
||||||
@ -425,8 +414,8 @@ namespace MWGui
|
|||||||
// The history is not reset here
|
// The history is not reset here
|
||||||
mKeywords.clear();
|
mKeywords.clear();
|
||||||
mTopicsList->clear();
|
mTopicsList->clear();
|
||||||
for (Link* link : mLinks)
|
for (auto& link : mLinks)
|
||||||
mDeleteLater.push_back(link); // Links are not deleted right away to prevent issues with event handlers
|
mDeleteLater.push_back(std::move(link)); // Links are not deleted right away to prevent issues with event handlers
|
||||||
mLinks.clear();
|
mLinks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,8 +461,6 @@ namespace MWGui
|
|||||||
|
|
||||||
void DialogueWindow::deleteLater()
|
void DialogueWindow::deleteLater()
|
||||||
{
|
{
|
||||||
for (Link* link : mDeleteLater)
|
|
||||||
delete link;
|
|
||||||
mDeleteLater.clear();
|
mDeleteLater.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,8 +469,6 @@ namespace MWGui
|
|||||||
if (MWBase::Environment::get().getWindowManager()->containsMode(GM_Dialogue))
|
if (MWBase::Environment::get().getWindowManager()->containsMode(GM_Dialogue))
|
||||||
return;
|
return;
|
||||||
// Reset history
|
// Reset history
|
||||||
for (DialogueText* text : mHistoryContents)
|
|
||||||
delete text;
|
|
||||||
mHistoryContents.clear();
|
mHistoryContents.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,7 +486,7 @@ namespace MWGui
|
|||||||
{
|
{
|
||||||
mTopicsList->clear();
|
mTopicsList->clear();
|
||||||
for (auto& linkPair : mTopicLinks)
|
for (auto& linkPair : mTopicLinks)
|
||||||
mDeleteLater.push_back(linkPair.second);
|
mDeleteLater.push_back(std::move(linkPair.second));
|
||||||
mTopicLinks.clear();
|
mTopicLinks.clear();
|
||||||
mKeywordSearch.clear();
|
mKeywordSearch.clear();
|
||||||
|
|
||||||
@ -549,11 +534,10 @@ namespace MWGui
|
|||||||
std::string topicId = Misc::StringUtils::lowerCase(keyword);
|
std::string topicId = Misc::StringUtils::lowerCase(keyword);
|
||||||
mTopicsList->addItem(keyword);
|
mTopicsList->addItem(keyword);
|
||||||
|
|
||||||
Topic* t = new Topic(keyword);
|
auto t = std::make_unique<Topic>(keyword);
|
||||||
|
mKeywordSearch.seed(topicId, intptr_t(t.get()));
|
||||||
t->eventTopicActivated += MyGUI::newDelegate(this, &DialogueWindow::onTopicActivated);
|
t->eventTopicActivated += MyGUI::newDelegate(this, &DialogueWindow::onTopicActivated);
|
||||||
mTopicLinks[topicId] = t;
|
mTopicLinks[topicId] = std::move(t);
|
||||||
|
|
||||||
mKeywordSearch.seed(topicId, intptr_t(t));
|
|
||||||
}
|
}
|
||||||
mTopicsList->adjustSize();
|
mTopicsList->adjustSize();
|
||||||
|
|
||||||
@ -577,7 +561,7 @@ namespace MWGui
|
|||||||
|
|
||||||
BookTypesetter::Ptr typesetter = BookTypesetter::create (mHistory->getWidth(), std::numeric_limits<int>::max());
|
BookTypesetter::Ptr typesetter = BookTypesetter::create (mHistory->getWidth(), std::numeric_limits<int>::max());
|
||||||
|
|
||||||
for (DialogueText* text : mHistoryContents)
|
for (const auto& text : mHistoryContents)
|
||||||
text->write(typesetter, &mKeywordSearch, mTopicLinks);
|
text->write(typesetter, &mKeywordSearch, mTopicLinks);
|
||||||
|
|
||||||
BookTypesetter::Style* body = typesetter->createStyle("", MyGUI::Colour::White, false);
|
BookTypesetter::Style* body = typesetter->createStyle("", MyGUI::Colour::White, false);
|
||||||
@ -588,27 +572,27 @@ namespace MWGui
|
|||||||
mChoices = MWBase::Environment::get().getDialogueManager()->getChoices();
|
mChoices = MWBase::Environment::get().getDialogueManager()->getChoices();
|
||||||
for (std::pair<std::string, int>& choice : mChoices)
|
for (std::pair<std::string, int>& choice : mChoices)
|
||||||
{
|
{
|
||||||
Choice* link = new Choice(choice.second);
|
auto link = std::make_unique<Choice>(choice.second);
|
||||||
link->eventChoiceActivated += MyGUI::newDelegate(this, &DialogueWindow::onChoiceActivated);
|
link->eventChoiceActivated += MyGUI::newDelegate(this, &DialogueWindow::onChoiceActivated);
|
||||||
mLinks.push_back(link);
|
auto interactiveId = TypesetBook::InteractiveId(link.get());
|
||||||
|
mLinks.push_back(std::move(link));
|
||||||
|
|
||||||
typesetter->lineBreak();
|
typesetter->lineBreak();
|
||||||
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(body, textColours.answer, textColours.answerOver,
|
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(body, textColours.answer, textColours.answerOver,
|
||||||
textColours.answerPressed,
|
textColours.answerPressed, interactiveId);
|
||||||
TypesetBook::InteractiveId(link));
|
|
||||||
typesetter->write(questionStyle, to_utf8_span(choice.first.c_str()));
|
typesetter->write(questionStyle, to_utf8_span(choice.first.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
mGoodbye = MWBase::Environment::get().getDialogueManager()->isGoodbye();
|
mGoodbye = MWBase::Environment::get().getDialogueManager()->isGoodbye();
|
||||||
if (mGoodbye)
|
if (mGoodbye)
|
||||||
{
|
{
|
||||||
Goodbye* link = new Goodbye();
|
auto link = std::make_unique<Goodbye>();
|
||||||
link->eventActivated += MyGUI::newDelegate(this, &DialogueWindow::onGoodbyeActivated);
|
link->eventActivated += MyGUI::newDelegate(this, &DialogueWindow::onGoodbyeActivated);
|
||||||
mLinks.push_back(link);
|
auto interactiveId = TypesetBook::InteractiveId(link.get());
|
||||||
|
mLinks.push_back(std::move(link));
|
||||||
const std::string& goodbye = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sGoodbye")->mValue.getString();
|
const std::string& goodbye = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sGoodbye")->mValue.getString();
|
||||||
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(body, textColours.answer, textColours.answerOver,
|
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(body, textColours.answer, textColours.answerOver,
|
||||||
textColours.answerPressed,
|
textColours.answerPressed, interactiveId);
|
||||||
TypesetBook::InteractiveId(link));
|
|
||||||
typesetter->lineBreak();
|
typesetter->lineBreak();
|
||||||
typesetter->write(questionStyle, to_utf8_span(goodbye.c_str()));
|
typesetter->write(questionStyle, to_utf8_span(goodbye.c_str()));
|
||||||
}
|
}
|
||||||
@ -682,13 +666,13 @@ namespace MWGui
|
|||||||
|
|
||||||
void DialogueWindow::addResponse(const std::string &title, const std::string &text, bool needMargin)
|
void DialogueWindow::addResponse(const std::string &title, const std::string &text, bool needMargin)
|
||||||
{
|
{
|
||||||
mHistoryContents.push_back(new Response(text, title, needMargin));
|
mHistoryContents.push_back(std::make_unique<Response>(text, title, needMargin));
|
||||||
updateHistory();
|
updateHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogueWindow::addMessageBox(const std::string& text)
|
void DialogueWindow::addMessageBox(const std::string& text)
|
||||||
{
|
{
|
||||||
mHistoryContents.push_back(new Message(text));
|
mHistoryContents.push_back(std::make_unique<Message>(text));
|
||||||
updateHistory();
|
updateHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef MWGUI_DIALOGE_H
|
#ifndef MWGUI_DIALOGE_H
|
||||||
#define MWGUI_DIALOGE_H
|
#define MWGUI_DIALOGE_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "windowbase.hpp"
|
#include "windowbase.hpp"
|
||||||
#include "referenceinterface.hpp"
|
#include "referenceinterface.hpp"
|
||||||
|
|
||||||
@ -22,7 +24,7 @@ namespace MWGui
|
|||||||
class PersuasionDialog : public WindowModal
|
class PersuasionDialog : public WindowModal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PersuasionDialog(ResponseCallback* callback);
|
PersuasionDialog(std::unique_ptr<ResponseCallback> callback);
|
||||||
|
|
||||||
void onOpen() override;
|
void onOpen() override;
|
||||||
|
|
||||||
@ -81,14 +83,14 @@ namespace MWGui
|
|||||||
struct DialogueText
|
struct DialogueText
|
||||||
{
|
{
|
||||||
virtual ~DialogueText() {}
|
virtual ~DialogueText() {}
|
||||||
virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const = 0;
|
virtual void write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, std::unique_ptr<Link>>& topicLinks) const = 0;
|
||||||
std::string mText;
|
std::string mText;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Response : DialogueText
|
struct Response : DialogueText
|
||||||
{
|
{
|
||||||
Response(const std::string& text, const std::string& title = "", bool needMargin = true);
|
Response(const std::string& text, const std::string& title = "", bool needMargin = true);
|
||||||
void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const override;
|
void write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, std::unique_ptr<Link>>& topicLinks) const override;
|
||||||
void addTopicLink (BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end) const;
|
void addTopicLink (BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end) const;
|
||||||
std::string mTitle;
|
std::string mTitle;
|
||||||
bool mNeedMargin;
|
bool mNeedMargin;
|
||||||
@ -97,14 +99,13 @@ namespace MWGui
|
|||||||
struct Message : DialogueText
|
struct Message : DialogueText
|
||||||
{
|
{
|
||||||
Message(const std::string& text);
|
Message(const std::string& text);
|
||||||
void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const override;
|
void write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, std::unique_ptr<Link>>& topicLinks) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DialogueWindow: public WindowBase, public ReferenceInterface
|
class DialogueWindow: public WindowBase, public ReferenceInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DialogueWindow();
|
DialogueWindow();
|
||||||
~DialogueWindow();
|
|
||||||
|
|
||||||
void onTradeComplete();
|
void onTradeComplete();
|
||||||
|
|
||||||
@ -158,14 +159,14 @@ namespace MWGui
|
|||||||
bool mIsCompanion;
|
bool mIsCompanion;
|
||||||
std::list<std::string> mKeywords;
|
std::list<std::string> mKeywords;
|
||||||
|
|
||||||
std::vector<DialogueText*> mHistoryContents;
|
std::vector<std::unique_ptr<DialogueText>> mHistoryContents;
|
||||||
std::vector<std::pair<std::string, int> > mChoices;
|
std::vector<std::pair<std::string, int> > mChoices;
|
||||||
bool mGoodbye;
|
bool mGoodbye;
|
||||||
|
|
||||||
std::vector<Link*> mLinks;
|
std::vector<std::unique_ptr<Link>> mLinks;
|
||||||
std::map<std::string, Link*> mTopicLinks;
|
std::map<std::string, std::unique_ptr<Link>> mTopicLinks;
|
||||||
|
|
||||||
std::vector<Link*> mDeleteLater;
|
std::vector<std::unique_ptr<Link>> mDeleteLater;
|
||||||
|
|
||||||
KeywordSearchT mKeywordSearch;
|
KeywordSearchT mKeywordSearch;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user