2013-01-27 20:01:37 +00:00
|
|
|
#include "journalviewmodel.hpp"
|
|
|
|
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/journal.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwdialogue/journalentry.hpp"
|
|
|
|
|
|
|
|
//#include "MyGUI_LanguageManager.h"
|
|
|
|
|
|
|
|
#include <components/misc/utf8stream.hpp>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <sstream>
|
2013-02-09 18:44:20 +00:00
|
|
|
#include <boost/make_shared.hpp>
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
using namespace MWGui;
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
namespace MWGui { struct JournalViewModelImpl; }
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
static void injectMonthName (std::ostream & os, int month);
|
|
|
|
|
|
|
|
template <typename string_t, typename value_t>
|
2013-02-15 05:37:33 +00:00
|
|
|
class KeywordSearch
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef typename string_t::const_iterator point;
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
struct Match
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
point mBeg;
|
|
|
|
point mEnd;
|
|
|
|
value_t mValue;
|
2013-01-27 20:01:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void seed (string_t Keyword, value_t Value)
|
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
seed_impl (/*std::move*/ (Keyword), /*std::move*/ (Value), 0, mRoot);
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear ()
|
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
mRoot.mChildren.clear ();
|
|
|
|
mRoot.mKeyword.clear ();
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
bool search (point Beg, point End, Match & Match)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
for (point i = Beg; i != End; ++i)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
// check first character
|
2013-02-15 05:37:33 +00:00
|
|
|
typename Entry::childen_t::iterator candidate = mRoot.mChildren.find (std::tolower (*i, mLocale));
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
// no match, on to next character
|
2013-02-15 05:37:33 +00:00
|
|
|
if (candidate == mRoot.mChildren.end ())
|
2013-01-27 20:01:37 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// see how far the match goes
|
2013-02-09 18:44:20 +00:00
|
|
|
point j = i;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
while ((j + 1) != End)
|
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
typename Entry::childen_t::iterator next = candidate->second.mChildren.find (std::tolower (*++j, mLocale));
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
if (next == candidate->second.mChildren.end ())
|
2013-01-27 20:01:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
candidate = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't match enough to disambiguate, on to next character
|
2013-02-15 05:37:33 +00:00
|
|
|
if (!candidate->second.mKeyword.size ())
|
2013-01-27 20:01:37 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// match the rest of the keyword
|
2013-02-15 05:37:33 +00:00
|
|
|
typename string_t::const_iterator t = candidate->second.mKeyword.begin () + (j - i);
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
while (j != End && t != candidate->second.mKeyword.end ())
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
if (std::tolower (*j, mLocale) != std::tolower (*t, mLocale))
|
2013-01-27 20:01:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
++j, ++t;
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't match full keyword, on to next character
|
2013-02-15 05:37:33 +00:00
|
|
|
if (t != candidate->second.mKeyword.end ())
|
2013-01-27 20:01:37 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// we did it, report the good news
|
2013-02-15 05:37:33 +00:00
|
|
|
Match.mValue = candidate->second.mValue;
|
|
|
|
Match.mBeg = i;
|
|
|
|
Match.mEnd = j;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no match in range, report the bad news
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
struct Entry
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
typedef std::map <wchar_t, Entry> childen_t;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
string_t mKeyword;
|
|
|
|
value_t mValue;
|
|
|
|
childen_t mChildren;
|
2013-01-27 20:01:37 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void seed_impl (string_t Keyword, value_t Value, size_t Depth, Entry & Entry)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
int ch = tolower (Keyword.at (Depth), mLocale);
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
typename Entry::childen_t::iterator j = Entry.mChildren.find (ch);
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
if (j == Entry.mChildren.end ())
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
Entry.mChildren [ch].mValue = /*std::move*/ (Value);
|
|
|
|
Entry.mChildren [ch].mKeyword = /*std::move*/ (Keyword);
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
if (j->second.mKeyword.size () > 0)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
if (Keyword == j->second.mKeyword)
|
2013-01-27 20:01:37 +00:00
|
|
|
throw std::runtime_error ("duplicate keyword inserted");
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
value_t pushValue = /*std::move*/ (j->second.mValue);
|
|
|
|
string_t pushKeyword = /*std::move*/ (j->second.mKeyword);
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
j->second.mKeyword.clear ();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
if (Depth >= pushKeyword.size ())
|
|
|
|
throw std::runtime_error ("unexpected");
|
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
seed_impl (/*std::move*/ (pushKeyword), /*std::move*/ (pushValue), Depth+1, j->second);
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
seed_impl (/*std::move*/ (Keyword), /*std::move*/ (Value), Depth+1, j->second);
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Entry mRoot;
|
|
|
|
std::locale mLocale;
|
2013-01-27 20:01:37 +00:00
|
|
|
};
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
struct MWGui::JournalViewModelImpl : JournalViewModel
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
typedef KeywordSearch <std::string, intptr_t> keyword_search_t;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
mutable bool mKeywordSearchLoaded;
|
|
|
|
mutable keyword_search_t mKeywordSearch;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
std::locale mLocale;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
JournalViewModelImpl ()
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
mKeywordSearchLoaded = false;
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
virtual ~JournalViewModelImpl ()
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: replace this nasty BS
|
2013-02-15 05:37:33 +00:00
|
|
|
static utf8_span toUtf8Span (std::string const & str)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
if (str.size () == 0)
|
|
|
|
return utf8_span (utf8_point (NULL), utf8_point (NULL));
|
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
utf8_point point = reinterpret_cast <utf8_point> (str.c_str ());
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
return utf8_span (point, point + str.size ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void load ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void unload ()
|
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
mKeywordSearch.clear ();
|
|
|
|
mKeywordSearchLoaded = false;
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void ensureKeyWordSearchLoaded () const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
if (!mKeywordSearchLoaded)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
MWBase::Journal * journal = MWBase::Environment::get().getJournal();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
for(MWBase::Journal::TTopicIter i = journal->topicBegin(); i != journal->topicEnd (); ++i)
|
2013-02-15 05:37:33 +00:00
|
|
|
mKeywordSearch.seed (i->first, intptr_t (&i->second));
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
mKeywordSearchLoaded = true;
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
wchar_t tolower (wchar_t ch) const { return std::tolower (ch, mLocale); }
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
bool isEmpty () const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
MWBase::Journal * journal = MWBase::Environment::get().getJournal();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
return journal->begin () == journal->end ();
|
|
|
|
}
|
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
template <typename t_iterator, typename IInterface>
|
2013-02-15 05:37:33 +00:00
|
|
|
struct BaseEntry : IInterface
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
typedef t_iterator iterator_t;
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
iterator_t itr;
|
|
|
|
JournalViewModelImpl const * Model;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
BaseEntry (JournalViewModelImpl const * Model, iterator_t itr) :
|
2013-01-27 20:01:37 +00:00
|
|
|
Model (Model), itr (itr), loaded (false)
|
|
|
|
{}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
virtual ~BaseEntry () {}
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
mutable bool loaded;
|
|
|
|
mutable std::string utf8text;
|
|
|
|
|
|
|
|
virtual std::string getText () const = 0;
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void ensureLoaded () const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
if (!loaded)
|
|
|
|
{
|
|
|
|
utf8text = getText ();
|
|
|
|
loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
utf8_span body () const
|
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
ensureLoaded ();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
return toUtf8Span (utf8text);
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void visitSpans (boost::function < void (topic_id, size_t, size_t)> visitor) const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
ensureLoaded ();
|
|
|
|
Model->ensureKeyWordSearchLoaded ();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
std::string::const_iterator i = utf8text.begin ();
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
keyword_search_t::Match match;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
while (i != utf8text.end () && Model->mKeywordSearch.search (i, utf8text.end (), match))
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
if (i != match.mBeg)
|
|
|
|
visitor (0, i - utf8text.begin (), match.mBeg - utf8text.begin ());
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
visitor (match.mValue, match.mBeg - utf8text.begin (), match.mEnd - utf8text.begin ());
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
i = match.mEnd;
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i != utf8text.end ())
|
|
|
|
visitor (0, i - utf8text.begin (), utf8text.size ());
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void visitQuestNames (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
MWBase::Journal * journal = MWBase::Environment::get ().getJournal ();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
for (MWBase::Journal::TQuestIter i = journal->questBegin (); i != journal->questEnd (); ++i)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
if (active_only && i->second.isFinished ())
|
|
|
|
continue;
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
visitor (reinterpret_cast <quest_id> (&i->second), toUtf8Span (i->first));
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void visitQuestName (quest_id questId, boost::function <void (utf8_span)> visitor) const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId);
|
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
std::string name = quest->getName ();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
visitor (toUtf8Span (name));
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename iterator_t>
|
2013-03-07 04:02:00 +00:00
|
|
|
struct JournalEntryImpl : BaseEntry <iterator_t, JournalEntry>
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-03-07 04:02:00 +00:00
|
|
|
using BaseEntry <iterator_t, JournalEntry>::itr;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
mutable std::string timestamp_buffer;
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
JournalEntryImpl (JournalViewModelImpl const * Model, iterator_t itr) :
|
|
|
|
BaseEntry <iterator_t, JournalEntry> (Model, itr)
|
2013-01-27 20:01:37 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
std::string getText () const
|
|
|
|
{
|
|
|
|
return itr->getText(MWBase::Environment::get().getWorld()->getStore());
|
|
|
|
}
|
|
|
|
|
|
|
|
utf8_span timestamp () const
|
|
|
|
{
|
|
|
|
if (timestamp_buffer.empty ())
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
|
|
|
|
os << itr->mDayOfMonth << ' ';
|
|
|
|
|
|
|
|
injectMonthName (os, itr->mMonth);
|
|
|
|
|
|
|
|
os << " (Day " << (itr->mDay + 1) << ')';
|
|
|
|
|
|
|
|
timestamp_buffer = os.str ();
|
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
return toUtf8Span (timestamp_buffer);
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void visitJournalEntries (quest_id questId, boost::function <void (JournalEntry const &)> visitor) const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
MWBase::Journal * journal = MWBase::Environment::get().getJournal();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
|
|
|
if (questId != 0)
|
|
|
|
{
|
|
|
|
MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId);
|
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
for(MWBase::Journal::TEntryIter i = journal->begin(); i != journal->end (); ++i)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
for (MWDialogue::Topic::TEntryIter j = quest->begin (); j != quest->end (); ++j)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
if (i->mInfoId == *j)
|
2013-03-07 04:02:00 +00:00
|
|
|
visitor (JournalEntryImpl <MWBase::Journal::TEntryIter> (this, i));
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
for(MWBase::Journal::TEntryIter i = journal->begin(); i != journal->end (); ++i)
|
2013-03-07 04:02:00 +00:00
|
|
|
visitor (JournalEntryImpl <MWBase::Journal::TEntryIter> (this, i));
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void visitTopics (boost::function <void (topic_id, utf8_span)> visitor) const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
|
|
|
throw std::runtime_error ("not implemented");
|
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void visitTopicName (topic_id topicId, boost::function <void (utf8_span)> visitor) const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
visitor (toUtf8Span (Topic.getName ()));
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
void visitTopicNamesStartingWith (int character, boost::function < void (topic_id , utf8_span) > visitor) const
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
MWBase::Journal * journal = MWBase::Environment::get().getJournal();
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i)
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-15 05:37:33 +00:00
|
|
|
if (i->first [0] != std::tolower (character, mLocale))
|
2013-01-27 20:01:37 +00:00
|
|
|
continue;
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
visitor (topic_id (&i->second), toUtf8Span (i->first));
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
struct TopicEntryImpl : BaseEntry <MWDialogue::Topic::TEntryIter, TopicEntry>
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-02-09 18:44:20 +00:00
|
|
|
MWDialogue::Topic const & Topic;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
mutable std::string source_buffer;
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
TopicEntryImpl (JournalViewModelImpl const * Model, MWDialogue::Topic const & Topic, iterator_t itr) :
|
2013-02-15 05:37:33 +00:00
|
|
|
BaseEntry (Model, itr), Topic (Topic)
|
2013-02-09 18:44:20 +00:00
|
|
|
{}
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
std::string getText () const
|
|
|
|
{
|
|
|
|
return Topic.getEntry (*itr).getText(MWBase::Environment::get().getWorld()->getStore());
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
}
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
utf8_span source () const
|
|
|
|
{
|
|
|
|
if (source_buffer.empty ())
|
|
|
|
source_buffer = "someone";
|
2013-02-15 05:37:33 +00:00
|
|
|
return toUtf8Span (source_buffer);
|
2013-02-09 18:44:20 +00:00
|
|
|
}
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
};
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void visitTopicEntries (topic_id topicId, boost::function <void (TopicEntry const &)> visitor) const
|
2013-02-09 18:44:20 +00:00
|
|
|
{
|
|
|
|
typedef MWDialogue::Topic::TEntryIter iterator_t;
|
2013-02-15 05:37:33 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
|
2013-01-27 20:01:37 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
for (iterator_t i = Topic.begin (); i != Topic.end (); ++i)
|
2013-03-07 04:02:00 +00:00
|
|
|
visitor (TopicEntryImpl (this, Topic, i));
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void injectMonthName (std::ostream & os, int month)
|
|
|
|
{
|
|
|
|
#ifndef MYGUI_SIGNLETON_FIXED_FOR_MSVC
|
|
|
|
static char const * month_names [] =
|
|
|
|
{
|
|
|
|
"Morning Star",
|
|
|
|
"Sun's Dawn",
|
|
|
|
"First Seed",
|
|
|
|
"Rain's Hand",
|
|
|
|
"Second Seed",
|
|
|
|
"Midyear",
|
|
|
|
"Sun's Height",
|
|
|
|
"Last Seed",
|
|
|
|
"Hearthfire",
|
|
|
|
"Frostfall",
|
|
|
|
"Sun's Dusk",
|
|
|
|
"Evening Star",
|
|
|
|
};
|
|
|
|
if (month >= 0 && month <= 11)
|
|
|
|
os << month_names [month ];
|
|
|
|
else
|
|
|
|
os << month ;
|
|
|
|
#else
|
|
|
|
auto lm = MyGUI::LanguageManager::getInstance();
|
|
|
|
|
|
|
|
if (month == 0)
|
|
|
|
os << lm.getTag ("sMonthMorningstar");
|
|
|
|
else if (month == 1)
|
|
|
|
os << lm.getTag ("sMonthSunsdawn");
|
|
|
|
else if (month == 2)
|
|
|
|
os << lm.getTag ("sMonthFirstseed");
|
|
|
|
else if (month == 3)
|
|
|
|
os << lm.getTag ("sMonthRainshand");
|
|
|
|
else if (month == 4)
|
|
|
|
os << lm.getTag ("sMonthSecondseed");
|
|
|
|
else if (month == 5)
|
|
|
|
os << lm.getTag ("sMonthMidyear");
|
|
|
|
else if (month == 6)
|
|
|
|
os << lm.getTag ("sMonthSunsheight");
|
|
|
|
else if (month == 7)
|
|
|
|
os << lm.getTag ("sMonthLastseed");
|
|
|
|
else if (month == 8)
|
|
|
|
os << lm.getTag ("sMonthHeartfire");
|
|
|
|
else if (month == 9)
|
|
|
|
os << lm.getTag ("sMonthFrostfall");
|
|
|
|
else if (month == 10)
|
|
|
|
os << lm.getTag ("sMonthSunsdusk");
|
|
|
|
else if (month == 11)
|
|
|
|
os << lm.getTag ("sMonthEveningstar");
|
|
|
|
else
|
|
|
|
os << month;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
JournalViewModel::ptr JournalViewModel::create ()
|
2013-01-27 20:01:37 +00:00
|
|
|
{
|
2013-03-07 04:02:00 +00:00
|
|
|
return boost::make_shared <JournalViewModelImpl> ();
|
2013-01-27 20:01:37 +00:00
|
|
|
}
|