Skip to content

Commit

Permalink
openmw-cn: v1-v10
Browse files Browse the repository at this point in the history
  • Loading branch information
dwing4g committed May 28, 2024
1 parent 26d776c commit d15f7f7
Show file tree
Hide file tree
Showing 68 changed files with 52,614 additions and 36 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ elseif(NOT APPLE)
ENDIF(BUILD_OPENMW)
IF(BUILD_LAUNCHER)
INSTALL(PROGRAMS "${INSTALL_SOURCE}/openmw-launcher" DESTINATION "${BINDIR}" )
INSTALL(PROGRAMS "${INSTALL_SOURCE}/pinyin.txt" DESTINATION "${BINDIR}" )
ENDIF(BUILD_LAUNCHER)
IF(BUILD_BSATOOL)
INSTALL(PROGRAMS "${INSTALL_SOURCE}/bsatool" DESTINATION "${BINDIR}" )
Expand Down
20 changes: 14 additions & 6 deletions apps/launcher/datafilespage.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "datafilespage.hpp"
#include "datafilespage.hpp"
#include "maindialog.hpp"

#include <QDebug>
Expand Down Expand Up @@ -147,7 +147,7 @@ Launcher::DataFilesPage::DataFilesPage(const Files::ConfigurationManager& cfg, C

QVector<std::pair<QString, QString>> languages = { { "English", tr("English") }, { "French", tr("French") },
{ "German", tr("German") }, { "Italian", tr("Italian") }, { "Polish", tr("Polish") },
{ "Russian", tr("Russian") }, { "Spanish", tr("Spanish") } };
{ "Russian", tr("Russian") }, { "Spanish", tr("Spanish") }, { "Chinese(GBK)", tr("简体中文(GBK)") }, { "UTF-8", tr("UTF-8") } };

for (auto lang : languages)
{
Expand Down Expand Up @@ -185,13 +185,13 @@ void Launcher::DataFilesPage::buildView()
QToolButton* refreshButton = mSelector->refreshButton();

// tool buttons
ui.newProfileButton->setToolTip("Create a new Content List");
ui.cloneProfileButton->setToolTip("Clone the current Content List");
ui.deleteProfileButton->setToolTip("Delete an existing Content List");
ui.newProfileButton->setToolTip("创建一个内容列表");
ui.cloneProfileButton->setToolTip("克隆当前的内容列表");
ui.deleteProfileButton->setToolTip("删除已存在的内容列表");

// combo box
ui.profilesComboBox->addItem(mDefaultContentListName);
ui.profilesComboBox->setPlaceholderText(QString("Select a Content List..."));
ui.profilesComboBox->setPlaceholderText(QString("选择一个内容列表..."));
ui.profilesComboBox->setCurrentIndex(ui.profilesComboBox->findText(QLatin1String(mDefaultContentListName)));

// Add the actions to the toolbuttons
Expand Down Expand Up @@ -453,6 +453,14 @@ void Launcher::DataFilesPage::saveSettings(const QString& profile)
{
mGameSettings.setValue(QLatin1String("encoding"), { "win1251" });
}
else if (language == QLatin1String("Chinese(GBK)"))
{
mGameSettings.setValue(QLatin1String("encoding"), { "gbk" });
}
else if (language == QLatin1String("UTF-8"))
{
mGameSettings.setValue(QLatin1String("encoding"), { "utf8" });
}
else
{
mGameSettings.setValue(QLatin1String("encoding"), { "win1252" });
Expand Down
4 changes: 2 additions & 2 deletions apps/launcher/maindialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "maindialog.hpp"
#include "maindialog.hpp"

#include <QCloseEvent>
#include <QDir>
Expand Down Expand Up @@ -523,7 +523,7 @@ bool Launcher::MainDialog::writeSettings()
}
catch (std::exception& e)
{
std::string msg = "<br><b>Error writing settings.cfg</b><br><br>" + Files::pathToUnicodeString(settingsPath)
std::string msg = "<br><b>写入 settings.cfg 出错</b><br><br>" + Files::pathToUnicodeString(settingsPath)
+ "<br><br>" + e.what();
cfgError(tr("Error writing user settings file"), tr(msg.c_str()));
return false;
Expand Down
2 changes: 2 additions & 0 deletions apps/openmw/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ void OMW::Engine::createWindow()

SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, Settings::video().mMinimizeOnFocusLoss ? "1" : "0");

SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");

checkSDLError(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
checkSDLError(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
checkSDLError(SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8));
Expand Down
55 changes: 55 additions & 0 deletions apps/openmw/mwdialogue/keywordsearch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <algorithm> // std::reverse
#include <cctype>
#include <set>
#include <map>
#include <stdexcept>
#include <vector>
Expand Down Expand Up @@ -187,6 +188,60 @@ namespace MWDialogue
std::sort(out.begin(), out.end(), sortMatches);
}

static bool removeUnusedPostfix(std::string& text, std::vector<Match>& matches)
{
if (text.empty() || text.back() != '}')
return false;
const auto pos = text.find_last_of('{');
if (pos == std::string::npos)
return false;
auto it = text.cbegin() + pos;
if (matches.empty() || matches.back().mEnd < it)
text.erase(pos > 0 && text[pos - 1] == ' ' ? pos - 1 : pos);
else
{
it++;
size_t n = 0;
std::set<std::string> kws;
for (auto i = matches.begin(); i != matches.end();)
{
auto& match = *i;
match.mBeg -= n;
match.mEnd -= n;
if (match.mEnd <= it)
kws.insert(std::string(match.mBeg, match.mEnd));
else
{
if (match.mBeg < it || match.mEnd >= text.cend()
|| *(match.mBeg - 1) != ',' && *(match.mBeg - 1) != '{'
|| *match.mEnd != ',' && *match.mEnd != '}'
|| kws.contains(std::string(match.mBeg, match.mEnd)))
{
i = matches.erase(i);
continue;
}
if (it < match.mBeg)
{
auto s = match.mBeg - it;
n += s;
text.erase(it, match.mBeg);
match.mBeg -= s;
match.mEnd -= s;
}
it = match.mEnd;
if (it < text.cend() && *it == ',')
it++;
}
i++;
}
if (it - 1 == text.cbegin() + pos)
text.erase(pos > 0 && text[pos - 1] == ' ' ? pos - 1 : pos);
else if (it < text.cend() - 1)
text.erase(*(it - 1) == ',' ? it - 1 : it, text.cend() - 1);
}
return true;
}

private:
struct Entry
{
Expand Down
7 changes: 5 additions & 2 deletions apps/openmw/mwgui/bookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ namespace MWGui
void writeImpl(StyleImpl* style, Utf8Stream::Point _begin, Utf8Stream::Point _end)
{
Utf8Stream stream(_begin, _end);
Utf8Stream::UnicodeChar lastChar = 0;

while (!stream.eof())
{
Expand All @@ -509,7 +510,7 @@ namespace MWGui
continue;
}

if (ucsBreakingSpace(stream.peek()) && !mPartialWord.empty())
if (!mPartialWord.empty())
add_partial_text();

int word_width = 0;
Expand All @@ -532,7 +533,9 @@ namespace MWGui
MWGui::GlyphInfo info = GlyphInfo(style->mFont, stream.peek());
if (info.charFound)
word_width += static_cast<int>(info.advance + info.bearingX);
stream.consume();
lastChar = stream.consume();
if (lastChar >= 0x2000 || stream.eof() || stream.peek() >= 0x2000) // for wide char
break;
}

Utf8Stream::Point extent = stream.current();
Expand Down
7 changes: 5 additions & 2 deletions apps/openmw/mwgui/dialogue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ namespace MWGui
break;
}

typesetter->addContent(to_utf8_span(text));

if (hyperLinks.size()
&& MWBase::Environment::get().getWindowManager()->getTranslationDataStorage().hasTranslation())
{
typesetter->addContent(to_utf8_span(text));

const TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();

BookTypesetter::Style* style = typesetter->createStyle({}, textColours.normal, false);
Expand All @@ -237,6 +237,9 @@ namespace MWGui
std::vector<KeywordSearchT::Match> matches;
keywordSearch->highlightKeywords(text.begin(), text.end(), matches);

KeywordSearchT::removeUnusedPostfix(text, matches);
typesetter->addContent(to_utf8_span(text));

std::string::const_iterator i = text.begin();
for (KeywordSearchT::Match& match : matches)
{
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwgui/itemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace
return {};

// With small text size we can use up to 4 characters, while with large ones - only up to 3.
if (Settings::gui().mFontSize > 16)
if (Settings::gui().mFontSize > 18)
{
if (count > 999999999)
return MyGUI::utility::toString(count / 1000000000) + "b";
Expand Down
4 changes: 1 addition & 3 deletions apps/openmw/mwgui/journalbooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ namespace

void operator()(MWGui::JournalViewModel::Entry const& entry)
{
mTypesetter->addContent(entry.body());

entry.visitSpans(AddSpan(mTypesetter, mBodyStyle));
entry.visitSpans(mTypesetter, AddSpan(mTypesetter, mBodyStyle));
}
};

Expand Down
15 changes: 10 additions & 5 deletions apps/openmw/mwgui/journalviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ namespace MWGui
return toUtf8Span(utf8text);
}

void visitSpans(std::function<void(TopicId, size_t, size_t)> visitor) const override
void visitSpans(MWGui::BookTypesetter::Ptr mTypesetter,
std::function<void(TopicId, size_t, size_t)> visitor) const override
{
ensureLoaded();
mModel->ensureKeyWordSearchLoaded();

if (mHyperLinks.size()
&& MWBase::Environment::get().getWindowManager()->getTranslationDataStorage().hasTranslation())
{
mTypesetter->addContent(body());

size_t formatted = 0; // points to the first character that is not laid out yet
for (std::map<Range, intptr_t>::const_iterator it = mHyperLinks.begin(); it != mHyperLinks.end();
++it)
Expand All @@ -173,6 +176,9 @@ namespace MWGui
std::vector<KeywordSearchT::Match> matches;
mModel->mKeywordSearch.highlightKeywords(utf8text.begin(), utf8text.end(), matches);

KeywordSearchT::removeUnusedPostfix(utf8text, matches);
mTypesetter->addContent(body());

std::string::const_iterator i = utf8text.begin();
for (std::vector<KeywordSearchT::Match>::const_iterator it = matches.begin(); it != matches.end();
++it)
Expand Down Expand Up @@ -312,15 +318,14 @@ namespace MWGui
{
MWBase::Journal* journal = MWBase::Environment::get().getJournal();

character = Utf8Stream::toLowerUtf8(character);
for (MWBase::Journal::TTopicIter i = journal->topicBegin(); i != journal->topicEnd(); ++i)
{
Utf8Stream stream(i->second.getName());
Utf8Stream::UnicodeChar first = Utf8Stream::toLowerUtf8(stream.peek());

if (first != Utf8Stream::toLowerUtf8(character))
continue;

visitor(i->second.getName());
if (Translation::isFirstChar(first, (char)character))
visitor(i->second.getName());
}
}

Expand Down
5 changes: 4 additions & 1 deletion apps/openmw/mwgui/journalviewmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <components/misc/utf8stream.hpp>

#include "bookpage.hpp"

namespace MWGui
{
/// View-Model for the journal GUI
Expand Down Expand Up @@ -38,7 +40,8 @@ namespace MWGui
/// Visits each subset of text in the body, delivering the beginning
/// and end of the span relative to the body, and a valid topic ID if
/// the span represents a keyword, or zero if not.
virtual void visitSpans(std::function<void(TopicId, size_t, size_t)> visitor) const = 0;
virtual void visitSpans(MWGui::BookTypesetter::Ptr mTypesetter,
std::function<void(TopicId, size_t, size_t)> visitor) const = 0;

virtual ~Entry() = default;
};
Expand Down
5 changes: 4 additions & 1 deletion apps/openmw/mwgui/messagebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ namespace MWGui
auto box = std::make_unique<MessageBox>(*this, message);
box->mCurrentTime = 0;
auto realMessage = MyGUI::LanguageManager::getInstance().replaceTags({ message.data(), message.size() });
box->mMaxTime = realMessage.length() * mMessageBoxSpeed;
size_t n = 5;
for (size_t i = 0, s = realMessage.length(); i < s; i++)
n += realMessage[i] < 0x2000 ? 1 : 3; // wide chars need more time to read
box->mMaxTime = n * mMessageBoxSpeed;

if (stat)
mStaticMessageBox = box.get();
Expand Down
2 changes: 2 additions & 0 deletions apps/openmw/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ namespace OpenMW

addOption("encoding", bpo::value<std::string>()->default_value("win1252"),
"Character encoding used in OpenMW game messages:\n"
"\n\tutf8 - Unicode\n"
"\n\tgbk - Chinese(GBK)\n"
"\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, "
"Croatian, Serbian (Latin script), Romanian and Albanian languages\n"
"\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n"
Expand Down
4 changes: 2 additions & 2 deletions apps/wizard/languageselectionpage.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "languageselectionpage.hpp"
#include "languageselectionpage.hpp"

#include <components/misc/scalableicon.hpp>

Expand All @@ -20,7 +20,7 @@ void Wizard::LanguageSelectionPage::initializePage()
{
QVector<std::pair<QString, QString>> languages = { { "English", tr("English") }, { "French", tr("French") },
{ "German", tr("German") }, { "Italian", tr("Italian") }, { "Polish", tr("Polish") },
{ "Russian", tr("Russian") }, { "Spanish", tr("Spanish") } };
{ "Russian", tr("Russian") }, { "Spanish", tr("Spanish") }, { "Chinese(GBK)", tr("简体中文(GBK)") }, { "UTF-8", tr("UTF-8") } };

for (auto lang : languages)
{
Expand Down
18 changes: 17 additions & 1 deletion apps/wizard/mainwizard.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mainwizard.hpp"
#include "mainwizard.hpp"

#include <QDateTime>
#include <QDebug>
Expand Down Expand Up @@ -279,6 +279,14 @@ void Wizard::MainWizard::runSettingsImporter()
{
arguments.append(QLatin1String("win1251"));
}
else if (language == QLatin1String("Chinese(GBK)"))
{
arguments.append(QLatin1String("gbk"));
}
else if (language == QLatin1String("UTF-8"))
{
arguments.append(QLatin1String("utf8"));
}
else
{
arguments.append(QLatin1String("win1252"));
Expand Down Expand Up @@ -404,6 +412,14 @@ void Wizard::MainWizard::writeSettings()
{
mGameSettings.setValue(QLatin1String("encoding"), { "win1251" });
}
else if (language == QLatin1String("Chinese(GBK)"))
{
mGameSettings.setValue(QLatin1String("encoding"), { "gbk" });
}
else if (language == QLatin1String("UTF-8"))
{
mGameSettings.setValue(QLatin1String("encoding"), { "utf8" });
}
else
{
mGameSettings.setValue(QLatin1String("encoding"), { "win1252" });
Expand Down
4 changes: 2 additions & 2 deletions components/crashcatcher/windows_crashmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Crash
return reinterpret_cast<IsHungAppWindowFn>(GetProcAddress(user32Handle, "IsHungAppWindow"));
}

static const IsHungAppWindowFn sIsHungAppWindow = getIsHungAppWindow();
static const IsHungAppWindowFn sIsHungAppWindow = nullptr; // getIsHungAppWindow();

CrashMonitor::CrashMonitor(HANDLE shmHandle)
: mShmHandle(shmHandle)
Expand Down Expand Up @@ -154,7 +154,7 @@ namespace Crash

if (CheckRemoteDebuggerPresent(mAppProcessHandle, &debuggerPresent) && debuggerPresent)
return false;
if (SendMessageTimeoutA(mAppWindowHandle, WM_NULL, 0, 0, 0, 5000, nullptr) == 0)
if (SendMessageTimeoutA(mAppWindowHandle, WM_NULL, 0, 0, 0, 15000, nullptr) == 0)
return GetLastError() == ERROR_TIMEOUT;
}
return false;
Expand Down
Loading

0 comments on commit d15f7f7

Please sign in to comment.