Rewrite journal GUI topic list to use MWList

This commit is contained in:
scrawl 2014-06-03 16:04:18 +02:00
parent 17b15a6f4f
commit d7f3cd75ac
6 changed files with 34 additions and 24 deletions

View file

@ -254,16 +254,6 @@ book JournalBooks::createTopicIndexBook ()
return typesetter->complete (); return typesetter->complete ();
} }
book JournalBooks::createTopicIndexBook (char character)
{
BookTypesetter::Ptr typesetter = BookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
BookTypesetter::Style* style = typesetter->createStyle ("", MyGUI::Colour::Black);
mModel->visitTopicNamesStartingWith (character, AddTopicLink (typesetter, style));
return typesetter->complete ();
}
BookTypesetter::Ptr JournalBooks::createTypesetter () BookTypesetter::Ptr JournalBooks::createTypesetter ()
{ {
//TODO: determine page size from layout... //TODO: determine page size from layout...

View file

@ -18,9 +18,9 @@ namespace MWGui
Book createEmptyJournalBook (); Book createEmptyJournalBook ();
Book createJournalBook (); Book createJournalBook ();
Book createTopicBook (uintptr_t topicId); Book createTopicBook (uintptr_t topicId);
Book createTopicBook (const std::string& topicId);
Book createQuestBook (const std::string& questName); Book createQuestBook (const std::string& questName);
Book createTopicIndexBook (); Book createTopicIndexBook ();
Book createTopicIndexBook (char character);
private: private:
BookTypesetter::Ptr createTypesetter (); BookTypesetter::Ptr createTypesetter ();

View file

@ -312,7 +312,7 @@ struct JournalViewModelImpl : JournalViewModel
visitor (toUtf8Span (topic.getName())); visitor (toUtf8Span (topic.getName()));
} }
void visitTopicNamesStartingWith (char character, boost::function < void (TopicId , Utf8Span) > visitor) const void visitTopicNamesStartingWith (char character, boost::function < void (const std::string&) > visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
@ -321,7 +321,7 @@ struct JournalViewModelImpl : JournalViewModel
if (i->first [0] != std::tolower (character, mLocale)) if (i->first [0] != std::tolower (character, mLocale))
continue; continue;
visitor (TopicId (&i->second), toUtf8Span (i->second.getName())); visitor (i->second.getName());
} }
} }

View file

@ -80,8 +80,8 @@ namespace MWGui
/// provides the name of the topic specified by its id /// provides the name of the topic specified by its id
virtual void visitTopicName (TopicId topicId, boost::function <void (Utf8Span)> visitor) const = 0; virtual void visitTopicName (TopicId topicId, boost::function <void (Utf8Span)> visitor) const = 0;
/// walks over the topics whose names start with the specified character providing the topics id and name /// walks over the topics whose names start with the specified character providing the topics name
virtual void visitTopicNamesStartingWith (char character, boost::function < void (TopicId , Utf8Span) > visitor) const = 0; virtual void visitTopicNamesStartingWith (char character, boost::function < void (const std::string&) > visitor) const = 0;
/// walks over the topic entries for the topic specified by its identifier /// walks over the topic entries for the topic specified by its identifier
virtual void visitTopicEntries (TopicId topicId, boost::function <void (TopicEntry const &)> visitor) const = 0; virtual void visitTopicEntries (TopicId topicId, boost::function <void (TopicEntry const &)> visitor) const = 0;

View file

@ -3,6 +3,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/journal.hpp"
#include "list.hpp" #include "list.hpp"
#include <sstream> #include <sstream>
@ -37,7 +38,6 @@ namespace
static char const PageOneNum [] = "PageOneNum"; static char const PageOneNum [] = "PageOneNum";
static char const PageTwoNum [] = "PageTwoNum"; static char const PageTwoNum [] = "PageTwoNum";
static char const TopicsList [] = "TopicsList"; static char const TopicsList [] = "TopicsList";
static char const TopicsPage [] = "TopicsPage";
static char const QuestsList [] = "QuestsList"; static char const QuestsList [] = "QuestsList";
static char const LeftBookPage [] = "LeftBookPage"; static char const LeftBookPage [] = "LeftBookPage";
static char const RightBookPage [] = "RightBookPage"; static char const RightBookPage [] = "RightBookPage";
@ -113,12 +113,14 @@ namespace
MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(QuestsList); MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(QuestsList);
list->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyQuestClicked); list->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyQuestClicked);
MWGui::Widgets::MWList* topicsList = getWidget<MWGui::Widgets::MWList>(TopicsList);
topicsList->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyTopicSelected);
{ {
MWGui::BookPage::ClickCallback callback; MWGui::BookPage::ClickCallback callback;
callback = boost::bind (&JournalWindowImpl::notifyTopicClicked, this, _1); callback = boost::bind (&JournalWindowImpl::notifyTopicClicked, this, _1);
getPage (TopicsPage)->adviseLinkClicked (callback);
getPage (LeftBookPage)->adviseLinkClicked (callback); getPage (LeftBookPage)->adviseLinkClicked (callback);
getPage (RightBookPage)->adviseLinkClicked (callback); getPage (RightBookPage)->adviseLinkClicked (callback);
} }
@ -348,6 +350,19 @@ namespace
setVisible (JournalBTN, true); setVisible (JournalBTN, true);
} }
void notifyTopicSelected (const std::string& topic, int id)
{
const MWBase::Journal* journal = MWBase::Environment::get().getJournal();
intptr_t topicId = 0; /// \todo get rid of intptr ids
for(MWBase::Journal::TTopicIter i = journal->topicBegin(); i != journal->topicEnd (); ++i)
{
if (Misc::StringUtils::ciEqual(i->first, topic))
topicId = intptr_t (&i->second);
}
notifyTopicClicked(topicId);
}
void notifyQuestClicked (const std::string& name, int id) void notifyQuestClicked (const std::string& name, int id)
{ {
Book book = createQuestBook (name); Book book = createQuestBook (name);
@ -394,7 +409,14 @@ namespace
setVisible (RightTopicIndex, false); setVisible (RightTopicIndex, false);
setVisible (TopicsList, true); setVisible (TopicsList, true);
showList (TopicsList, TopicsPage, createTopicIndexBook ((char)character)); MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(TopicsList);
list->clear();
AddNamesToList add(list);
mModel->visitTopicNamesStartingWith((char) character, add);
list->adjustSize();
} }
void notifyTopics(MyGUI::Widget* _sender) void notifyTopics(MyGUI::Widget* _sender)
@ -408,9 +430,9 @@ namespace
setVisible (ShowActiveBTN, false); setVisible (ShowActiveBTN, false);
} }
struct AddQuestNamesToList struct AddNamesToList
{ {
AddQuestNamesToList(MWGui::Widgets::MWList* list) : mList(list) {} AddNamesToList(MWGui::Widgets::MWList* list) : mList(list) {}
MWGui::Widgets::MWList* mList; MWGui::Widgets::MWList* mList;
void operator () (const std::string& name) void operator () (const std::string& name)
@ -433,7 +455,7 @@ namespace
MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(QuestsList); MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(QuestsList);
list->clear(); list->clear();
AddQuestNamesToList add(list); AddNamesToList add(list);
mModel->visitQuestNames(!mAllQuests, add); mModel->visitQuestNames(!mAllQuests, add);

View file

@ -77,9 +77,7 @@
<Property key="ImagePushed" value="textures\tx_menubook_quests_all_pressed.dds"/> <Property key="ImagePushed" value="textures\tx_menubook_quests_all_pressed.dds"/>
</Widget> </Widget>
<Widget type="ScrollView" skin="MW_ScrollView" position="20 15 184 245" name="TopicsList" align="Right VStretch"> <Widget type="MWList" skin="MW_QuestList" position="8 35 208 225" name="TopicsList" align="Right VStretch">
<Property key="CanvasAlign" value="Left Top"/>
<Widget type="BookPage" skin="MW_BookPage" position="0 0 30000 30000" name="TopicsPage"/>
</Widget> </Widget>
<Widget type="MWList" skin="MW_QuestList" position="8 35 208 225" name="QuestsList" align="Right VStretch"> <Widget type="MWList" skin="MW_QuestList" position="8 35 208 225" name="QuestsList" align="Right VStretch">