forked from teamnwah/openmw-tes3coop
Merge pull request #1558 from akortunov/rusjournal
Cyrillic journal index (bug #2485)
This commit is contained in:
commit
665ca5b2d5
9 changed files with 109 additions and 23 deletions
|
@ -5,8 +5,10 @@
|
|||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include "textcolours.hpp"
|
||||
#include <components/fontloader/fontloader.hpp>
|
||||
#include <components/misc/utf8stream.hpp>
|
||||
|
||||
#include "textcolours.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -154,8 +156,8 @@ MWGui::BookTypesetter::Utf8Span to_utf8_span (char const * text)
|
|||
|
||||
typedef TypesetBook::Ptr book;
|
||||
|
||||
JournalBooks::JournalBooks (JournalViewModel::Ptr model) :
|
||||
mModel (model)
|
||||
JournalBooks::JournalBooks (JournalViewModel::Ptr model, ToUTF8::FromType encoding) :
|
||||
mModel (model), mEncoding(encoding)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -217,34 +219,82 @@ book JournalBooks::createQuestBook (const std::string& questName)
|
|||
}
|
||||
|
||||
book JournalBooks::createTopicIndexBook ()
|
||||
{
|
||||
bool isRussian = (mEncoding == ToUTF8::WINDOWS_1251);
|
||||
|
||||
BookTypesetter::Ptr typesetter = isRussian ? createCyrillicJournalIndex() : createLatinJournalIndex();
|
||||
|
||||
return typesetter->complete ();
|
||||
}
|
||||
|
||||
BookTypesetter::Ptr JournalBooks::createLatinJournalIndex ()
|
||||
{
|
||||
BookTypesetter::Ptr typesetter = BookTypesetter::create (92, 250);
|
||||
|
||||
typesetter->setSectionAlignment (BookTypesetter::AlignCenter);
|
||||
|
||||
BookTypesetter::Style* body = typesetter->createStyle ("", MyGUI::Colour::Black);
|
||||
char ch = 'A';
|
||||
|
||||
BookTypesetter::Style* body = typesetter->createStyle ("", MyGUI::Colour::Black);
|
||||
for (int i = 0; i < 26; ++i)
|
||||
{
|
||||
char ch = 'A' + i;
|
||||
|
||||
char buffer [32];
|
||||
|
||||
sprintf (buffer, "( %c )", ch);
|
||||
|
||||
const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
|
||||
BookTypesetter::Style* style = typesetter->createHotStyle (body, textColours.journalTopic,
|
||||
textColours.journalTopicOver,
|
||||
textColours.journalTopicPressed, ch);
|
||||
textColours.journalTopicPressed, (uint32_t) ch);
|
||||
|
||||
if (i == 13)
|
||||
typesetter->sectionBreak ();
|
||||
|
||||
typesetter->write (style, to_utf8_span (buffer));
|
||||
typesetter->lineBreak ();
|
||||
|
||||
ch++;
|
||||
}
|
||||
|
||||
return typesetter->complete ();
|
||||
return typesetter;
|
||||
}
|
||||
|
||||
BookTypesetter::Ptr JournalBooks::createCyrillicJournalIndex ()
|
||||
{
|
||||
BookTypesetter::Ptr typesetter = BookTypesetter::create (92, 250);
|
||||
|
||||
typesetter->setSectionAlignment (BookTypesetter::AlignCenter);
|
||||
|
||||
BookTypesetter::Style* body = typesetter->createStyle ("", MyGUI::Colour::Black);
|
||||
|
||||
unsigned char ch[2] = {0xd0, 0x90}; // CYRILLIC CAPITAL A is a 0xd090 in UTF-8
|
||||
|
||||
for (int i = 0; i < 32; ++i)
|
||||
{
|
||||
char buffer [32];
|
||||
sprintf(buffer, "( %c%c )", ch[0], ch[1]);
|
||||
|
||||
Utf8Stream stream ((char*) ch);
|
||||
uint32_t first = stream.peek();
|
||||
|
||||
const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
|
||||
BookTypesetter::Style* style = typesetter->createHotStyle (body, textColours.journalTopic,
|
||||
textColours.journalTopicOver,
|
||||
textColours.journalTopicPressed, first);
|
||||
|
||||
// Words can not be started with these characters
|
||||
if (i == 26 || i == 28)
|
||||
continue;
|
||||
|
||||
if (i == 15)
|
||||
typesetter->sectionBreak ();
|
||||
|
||||
typesetter->write (style, to_utf8_span (buffer));
|
||||
typesetter->lineBreak ();
|
||||
|
||||
ch[1]++;
|
||||
}
|
||||
|
||||
return typesetter;
|
||||
}
|
||||
|
||||
BookTypesetter::Ptr JournalBooks::createTypesetter ()
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "bookpage.hpp"
|
||||
#include "journalviewmodel.hpp"
|
||||
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
MWGui::BookTypesetter::Utf8Span to_utf8_span (char const * text);
|
||||
|
@ -13,7 +15,7 @@ namespace MWGui
|
|||
typedef TypesetBook::Ptr Book;
|
||||
JournalViewModel::Ptr mModel;
|
||||
|
||||
JournalBooks (JournalViewModel::Ptr model);
|
||||
JournalBooks (JournalViewModel::Ptr model, ToUTF8::FromType encoding);
|
||||
|
||||
Book createEmptyJournalBook ();
|
||||
Book createJournalBook ();
|
||||
|
@ -22,8 +24,12 @@ namespace MWGui
|
|||
Book createQuestBook (const std::string& questName);
|
||||
Book createTopicIndexBook ();
|
||||
|
||||
ToUTF8::FromType mEncoding;
|
||||
|
||||
private:
|
||||
BookTypesetter::Ptr createTypesetter ();
|
||||
BookTypesetter::Ptr createLatinJournalIndex ();
|
||||
BookTypesetter::Ptr createCyrillicJournalIndex ();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <MyGUI_LanguageManager.h>
|
||||
|
||||
#include <components/translation/translation.hpp>
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include <components/misc/utf8stream.hpp>
|
||||
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/journal.hpp"
|
||||
|
@ -305,18 +307,37 @@ struct JournalViewModelImpl : JournalViewModel
|
|||
visitor (toUtf8Span (topic.getName()));
|
||||
}
|
||||
|
||||
void visitTopicNamesStartingWith (char character, std::function < void (const std::string&) > visitor) const
|
||||
void visitTopicNamesStartingWith (uint32_t character, std::function < void (const std::string&) > visitor) const
|
||||
{
|
||||
MWBase::Journal * journal = MWBase::Environment::get().getJournal();
|
||||
|
||||
for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i)
|
||||
{
|
||||
if (i->first [0] != Misc::StringUtils::toLower(character))
|
||||
Utf8Stream stream (i->first.c_str());
|
||||
uint32_t first = toUpper(stream.peek());
|
||||
|
||||
if (first != character)
|
||||
continue;
|
||||
|
||||
visitor (i->second.getName());
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t toUpper(uint32_t ch)
|
||||
{
|
||||
// Russian alphabet
|
||||
if (ch >= 0x0430 && ch < 0x0450)
|
||||
ch -= 0x20;
|
||||
|
||||
// Cyrillic IO character
|
||||
if (ch == 0x0451)
|
||||
ch -= 0x50;
|
||||
|
||||
// Latin alphabet
|
||||
if (ch >= 0x61 && ch < 0x80)
|
||||
ch -= 0x20;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
struct TopicEntryImpl : BaseEntry <MWDialogue::Topic::TEntryIter, TopicEntry>
|
||||
|
|
|
@ -75,8 +75,8 @@ namespace MWGui
|
|||
/// provides the name of the topic specified by its id
|
||||
virtual void visitTopicName (TopicId topicId, std::function <void (Utf8Span)> visitor) const = 0;
|
||||
|
||||
/// walks over the topics whose names start with the specified character providing the topics name
|
||||
virtual void visitTopicNamesStartingWith (char character, std::function < void (const std::string&) > visitor) const = 0;
|
||||
/// walks over the topics whose names start with the character
|
||||
virtual void visitTopicNamesStartingWith (uint32_t character, std::function < void (const std::string&) > visitor) const = 0;
|
||||
|
||||
/// walks over the topic entries for the topic specified by its identifier
|
||||
virtual void visitTopicEntries (TopicId topicId, std::function <void (TopicEntry const &)> visitor) const = 0;
|
||||
|
|
|
@ -100,8 +100,8 @@ namespace
|
|||
return getWidget <MWGui::BookPage> (name);
|
||||
}
|
||||
|
||||
JournalWindowImpl (MWGui::JournalViewModel::Ptr Model, bool questList)
|
||||
: JournalBooks (Model), JournalWindow()
|
||||
JournalWindowImpl (MWGui::JournalViewModel::Ptr Model, bool questList, ToUTF8::FromType encoding)
|
||||
: JournalBooks (Model, encoding), JournalWindow()
|
||||
{
|
||||
center();
|
||||
|
||||
|
@ -477,7 +477,7 @@ namespace
|
|||
MWBase::Environment::get().getWindowManager()->playSound("book page");
|
||||
}
|
||||
|
||||
void notifyIndexLinkClicked (MWGui::TypesetBook::InteractiveId character)
|
||||
void notifyIndexLinkClicked (MWGui::TypesetBook::InteractiveId index)
|
||||
{
|
||||
setVisible (LeftTopicIndex, false);
|
||||
setVisible (RightTopicIndex, false);
|
||||
|
@ -490,7 +490,7 @@ namespace
|
|||
|
||||
AddNamesToList add(list);
|
||||
|
||||
mModel->visitTopicNamesStartingWith((char) character, add);
|
||||
mModel->visitTopicNamesStartingWith(index, add);
|
||||
|
||||
list->adjustSize();
|
||||
|
||||
|
@ -645,9 +645,9 @@ namespace
|
|||
}
|
||||
|
||||
// glue the implementation to the interface
|
||||
MWGui::JournalWindow * MWGui::JournalWindow::create (JournalViewModel::Ptr Model, bool questList)
|
||||
MWGui::JournalWindow * MWGui::JournalWindow::create (JournalViewModel::Ptr Model, bool questList, ToUTF8::FromType encoding)
|
||||
{
|
||||
return new JournalWindowImpl (Model, questList);
|
||||
return new JournalWindowImpl (Model, questList, encoding);
|
||||
}
|
||||
|
||||
MWGui::JournalWindow::JournalWindow()
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "windowbase.hpp"
|
||||
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace MWBase { class WindowManager; }
|
||||
|
@ -16,7 +18,7 @@ namespace MWGui
|
|||
JournalWindow();
|
||||
|
||||
/// construct a new instance of the one JournalWindow implementation
|
||||
static JournalWindow * create (std::shared_ptr <JournalViewModel> Model, bool questList);
|
||||
static JournalWindow * create (std::shared_ptr <JournalViewModel> Model, bool questList, ToUTF8::FromType encoding);
|
||||
|
||||
/// destroy this instance of the JournalWindow implementation
|
||||
virtual ~JournalWindow () {};
|
||||
|
|
|
@ -193,6 +193,7 @@ namespace MWGui
|
|||
, mRestAllowed(true)
|
||||
, mFallbackMap(fallbackMap)
|
||||
, mShowOwned(0)
|
||||
, mEncoding(encoding)
|
||||
, mVersionDescription(versionDescription)
|
||||
{
|
||||
float uiScale = Settings::Manager::getFloat("scaling factor", "GUI");
|
||||
|
@ -346,7 +347,7 @@ namespace MWGui
|
|||
mGuiModeStates[GM_Console] = GuiModeState(mConsole);
|
||||
|
||||
bool questList = mResourceSystem->getVFS()->exists("textures/tx_menubook_options_over.dds");
|
||||
JournalWindow* journal = JournalWindow::create(JournalViewModel::create (), questList);
|
||||
JournalWindow* journal = JournalWindow::create(JournalViewModel::create (), questList, mEncoding);
|
||||
mWindows.push_back(journal);
|
||||
mGuiModeStates[GM_Journal] = GuiModeState(journal);
|
||||
mGuiModeStates[GM_Journal].mCloseSound = "book close";
|
||||
|
@ -2069,5 +2070,4 @@ namespace MWGui
|
|||
for (unsigned int i=0; i<mWindows.size(); ++i)
|
||||
mWindows[i]->setVisible(visible);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -511,6 +511,8 @@ namespace MWGui
|
|||
|
||||
int mShowOwned;
|
||||
|
||||
ToUTF8::FromType mEncoding;
|
||||
|
||||
std::string mVersionDescription;
|
||||
|
||||
MWGui::TextColours mTextColours;
|
||||
|
|
|
@ -18,6 +18,11 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
Utf8Stream (const char * str) :
|
||||
cur ((unsigned char*) str), nxt ((unsigned char*) str), end ((unsigned char*) str + strlen(str)), val(Utf8Stream::sBadChar())
|
||||
{
|
||||
}
|
||||
|
||||
Utf8Stream (std::pair <Point, Point> range) :
|
||||
cur (range.first), nxt (range.first), end (range.second), val(Utf8Stream::sBadChar())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue