forked from teamnwah/openmw-tes3coop
Topic link fixes for russian version, thanks to greye for testing
This commit is contained in:
parent
166eac2e25
commit
d43adbaa7c
2 changed files with 50 additions and 35 deletions
|
@ -111,7 +111,7 @@ namespace MWGui
|
||||||
mText = text;
|
mText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks)
|
void Response::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const
|
||||||
{
|
{
|
||||||
BookTypesetter::Style* title = typesetter->createStyle("EB Garamond", MyGUI::Colour(223/255.f, 201/255.f, 159/255.f));
|
BookTypesetter::Style* title = typesetter->createStyle("EB Garamond", MyGUI::Colour(223/255.f, 201/255.f, 159/255.f));
|
||||||
typesetter->sectionBreak(9);
|
typesetter->sectionBreak(9);
|
||||||
|
@ -122,63 +122,78 @@ namespace MWGui
|
||||||
typedef std::pair<size_t, size_t> Range;
|
typedef std::pair<size_t, size_t> Range;
|
||||||
std::map<Range, intptr_t> hyperLinks;
|
std::map<Range, intptr_t> hyperLinks;
|
||||||
|
|
||||||
|
// We need this copy for when @# hyperlinks are replaced
|
||||||
|
std::string text = mText;
|
||||||
|
|
||||||
size_t pos_begin, pos_end;
|
size_t pos_begin, pos_end;
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
pos_begin = mText.find('@');
|
pos_begin = text.find('@');
|
||||||
if (pos_begin != std::string::npos)
|
if (pos_begin != std::string::npos)
|
||||||
pos_end = mText.find('#', pos_begin);
|
pos_end = text.find('#', pos_begin);
|
||||||
|
|
||||||
if (pos_begin != std::string::npos && pos_end != std::string::npos)
|
if (pos_begin != std::string::npos && pos_end != std::string::npos)
|
||||||
{
|
{
|
||||||
std::string link = mText.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 = MWBase::Environment::get().getWindowManager()->
|
||||||
getTranslationDataStorage().topicStandardForm(link);
|
getTranslationDataStorage().topicStandardForm(link);
|
||||||
|
|
||||||
std::string displayName = link;
|
std::string displayName = link;
|
||||||
MWDialogue::RemovePseudoAsterisks(displayName);
|
while (displayName[displayName.size()-1] == '*')
|
||||||
|
displayName.erase(displayName.size()-1, 1);
|
||||||
|
|
||||||
mText.replace(pos_begin, pos_end+1-pos_begin, displayName);
|
text.replace(pos_begin, pos_end+1-pos_begin, displayName);
|
||||||
|
|
||||||
assert(topicLinks.find(topicName) != topicLinks.end());
|
if (topicLinks.find(Misc::StringUtils::lowerCase(topicName)) != topicLinks.end())
|
||||||
hyperLinks[std::make_pair(pos_begin, pos_begin+displayName.size())] = intptr_t(topicLinks[topicName]);
|
hyperLinks[std::make_pair(pos_begin, pos_begin+displayName.size())] = intptr_t(topicLinks[Misc::StringUtils::lowerCase(topicName)]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
typesetter->addContent(to_utf8_span(mText.c_str()));
|
typesetter->addContent(to_utf8_span(text.c_str()));
|
||||||
|
|
||||||
|
if (hyperLinks.size() && MWBase::Environment::get().getWindowManager()->getTranslationDataStorage().hasTranslation())
|
||||||
|
{
|
||||||
|
BookTypesetter::Style* style = typesetter->createStyle("EB Garamond", MyGUI::Colour(202/255.f, 165/255.f, 96/255.f));
|
||||||
|
size_t formatted = 0; // points to the first character that is not laid out yet
|
||||||
for (std::map<Range, intptr_t>::iterator it = hyperLinks.begin(); it != hyperLinks.end(); ++it)
|
for (std::map<Range, intptr_t>::iterator it = hyperLinks.begin(); it != hyperLinks.end(); ++it)
|
||||||
{
|
{
|
||||||
intptr_t topicId = it->second;
|
intptr_t topicId = it->second;
|
||||||
BookTypesetter::Style* style = typesetter->createStyle("EB Garamond", MyGUI::Colour::Green);
|
|
||||||
const MyGUI::Colour linkHot (143/255.f, 155/255.f, 218/255.f);
|
const MyGUI::Colour linkHot (143/255.f, 155/255.f, 218/255.f);
|
||||||
const MyGUI::Colour linkNormal (112/255.f, 126/255.f, 207/255.f);
|
const MyGUI::Colour linkNormal (112/255.f, 126/255.f, 207/255.f);
|
||||||
const MyGUI::Colour linkActive (175/255.f, 184/255.f, 228/255.f);
|
const MyGUI::Colour linkActive (175/255.f, 184/255.f, 228/255.f);
|
||||||
style = typesetter->createHotStyle (style, linkNormal, linkHot, linkActive, topicId);
|
BookTypesetter::Style* hotStyle = typesetter->createHotStyle (style, linkNormal, linkHot, linkActive, topicId);
|
||||||
typesetter->write(style, it->first.first, it->first.second);
|
if (formatted < it->first.first)
|
||||||
|
typesetter->write(style, formatted, it->first.first);
|
||||||
|
typesetter->write(hotStyle, it->first.first, it->first.second);
|
||||||
|
formatted = it->first.second;
|
||||||
}
|
}
|
||||||
|
if (formatted < text.size())
|
||||||
std::string::const_iterator i = mText.begin ();
|
typesetter->write(style, formatted, text.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string::const_iterator i = text.begin ();
|
||||||
KeywordSearchT::Match match;
|
KeywordSearchT::Match match;
|
||||||
while (i != mText.end () && keywordSearch->search (i, mText.end (), match))
|
while (i != text.end () && keywordSearch->search (i, text.end (), match))
|
||||||
{
|
{
|
||||||
if (i != match.mBeg)
|
if (i != match.mBeg)
|
||||||
addTopicLink (typesetter, 0, i - mText.begin (), match.mBeg - mText.begin ());
|
addTopicLink (typesetter, 0, i - text.begin (), match.mBeg - text.begin ());
|
||||||
|
|
||||||
addTopicLink (typesetter, match.mValue, match.mBeg - mText.begin (), match.mEnd - mText.begin ());
|
addTopicLink (typesetter, match.mValue, match.mBeg - text.begin (), match.mEnd - text.begin ());
|
||||||
|
|
||||||
i = match.mEnd;
|
i = match.mEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i != mText.end ())
|
if (i != text.end ())
|
||||||
addTopicLink (typesetter, 0, i - mText.begin (), mText.size ());
|
addTopicLink (typesetter, 0, i - text.begin (), text.size ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::addTopicLink(BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end)
|
void Response::addTopicLink(BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end) const
|
||||||
{
|
{
|
||||||
BookTypesetter::Style* style = typesetter->createStyle("EB Garamond", MyGUI::Colour(202/255.f, 165/255.f, 96/255.f));
|
BookTypesetter::Style* style = typesetter->createStyle("EB Garamond", MyGUI::Colour(202/255.f, 165/255.f, 96/255.f));
|
||||||
|
|
||||||
|
@ -196,7 +211,7 @@ namespace MWGui
|
||||||
mText = text;
|
mText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Message::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks)
|
void Message::write(BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const
|
||||||
{
|
{
|
||||||
BookTypesetter::Style* title = typesetter->createStyle("EB Garamond", MyGUI::Colour(223/255.f, 201/255.f, 159/255.f));
|
BookTypesetter::Style* title = typesetter->createStyle("EB Garamond", MyGUI::Colour(223/255.f, 201/255.f, 159/255.f));
|
||||||
typesetter->sectionBreak(9);
|
typesetter->sectionBreak(9);
|
||||||
|
@ -420,7 +435,7 @@ namespace MWGui
|
||||||
mTopicsList->addItem(*it);
|
mTopicsList->addItem(*it);
|
||||||
|
|
||||||
Topic* t = new Topic(*it);
|
Topic* t = new Topic(*it);
|
||||||
mTopicLinks[*it] = t;
|
mTopicLinks[Misc::StringUtils::lowerCase(*it)] = t;
|
||||||
|
|
||||||
mKeywordSearch.seed(Misc::StringUtils::lowerCase(*it), intptr_t(t));
|
mKeywordSearch.seed(Misc::StringUtils::lowerCase(*it), intptr_t(t));
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,22 +80,22 @@ namespace MWGui
|
||||||
struct DialogueText
|
struct DialogueText
|
||||||
{
|
{
|
||||||
virtual ~DialogueText() {}
|
virtual ~DialogueText() {}
|
||||||
virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) = 0;
|
virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, 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 = "");
|
Response(const std::string& text, const std::string& title = "");
|
||||||
virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks);
|
virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const;
|
||||||
void addTopicLink (BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end);
|
void addTopicLink (BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end) const;
|
||||||
std::string mTitle;
|
std::string mTitle;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Message : DialogueText
|
struct Message : DialogueText
|
||||||
{
|
{
|
||||||
Message(const std::string& text);
|
Message(const std::string& text);
|
||||||
virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks);
|
virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DialogueWindow: public WindowBase, public ReferenceInterface
|
class DialogueWindow: public WindowBase, public ReferenceInterface
|
||||||
|
|
Loading…
Reference in a new issue