dialogue window topic list word-wrapping

actorid
scrawl 13 years ago
parent 12453d4e9d
commit 499dd26398

@ -25,7 +25,7 @@ add_openmw_dir (mwinput
add_openmw_dir (mwgui
layouts text_input widgets race class birth review window_manager console dialogue
dialogue_history window_base stats_window messagebox journalwindow charactercreation
map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow
map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow list
)
add_openmw_dir (mwdialogue

@ -2,6 +2,7 @@
#include "dialogue_history.hpp"
#include "window_manager.hpp"
#include "widgets.hpp"
#include "list.hpp"
#include "components/esm_store/store.hpp"
#include "../mwbase/environment.hpp"
#include "../mwdialogue/dialoguemanager.hpp"
@ -56,9 +57,8 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager)
//Topics list
getWidget(topicsList, "TopicsList");
topicsList->setScrollVisible(true);
//topicsList->eventListSelectAccept += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
topicsList->eventListMouseItemActivate += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
topicsList->eventItemSelected += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
//topicsList->eventListChangePosition += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
MyGUI::ButtonPtr byeButton;
@ -98,7 +98,7 @@ void DialogueWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
void DialogueWindow::open()
{
topicsList->removeAllItems();
topicsList->clear();
pTopicsText.clear();
history->eraseText(0,history->getTextLength());
updateOptions();
@ -110,11 +110,8 @@ void DialogueWindow::onByeClicked(MyGUI::Widget* _sender)
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
}
void DialogueWindow::onSelectTopic(MyGUI::ListBox* _sender, size_t _index)
void DialogueWindow::onSelectTopic(std::string topic)
{
if (_index == MyGUI::ITEM_NONE)
return;
std::string topic = _sender->getItemNameAt(_index);
MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic));
}
@ -126,7 +123,7 @@ void DialogueWindow::startDialogue(std::string npcName)
void DialogueWindow::setKeywords(std::list<std::string> keyWords)
{
topicsList->removeAllItems();
topicsList->clear();
for(std::list<std::string>::iterator it = keyWords.begin(); it != keyWords.end(); it++)
{
topicsList->addItem(*it);
@ -135,9 +132,9 @@ void DialogueWindow::setKeywords(std::list<std::string> keyWords)
void DialogueWindow::removeKeyword(std::string keyWord)
{
if(topicsList->findItemIndexWith(keyWord) != MyGUI::ITEM_NONE)
if(topicsList->hasItem(keyWord))
{
topicsList->removeItemAt(topicsList->findItemIndexWith(keyWord));
topicsList->removeItem(keyWord);
pTopicsText.erase(keyWord);
}
}
@ -211,7 +208,7 @@ void DialogueWindow::askQuestion(std::string question)
void DialogueWindow::updateOptions()
{
//Clear the list of topics
topicsList->removeAllItems();
topicsList->clear();
pTopicsText.clear();
history->eraseText(0,history->getTextLength());

@ -7,6 +7,11 @@
namespace MWGui
{
class WindowManager;
namespace Widgets
{
class MWList;
}
}
/*
@ -42,7 +47,7 @@ namespace MWGui
void askQuestion(std::string question);
protected:
void onSelectTopic(MyGUI::ListBox* _sender, size_t _index);
void onSelectTopic(std::string topic);
void onByeClicked(MyGUI::Widget* _sender);
void onHistoryClicked(MyGUI::Widget* _sender);
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
@ -55,7 +60,7 @@ namespace MWGui
std::string parseText(std::string text);
DialogueHistory* history;
MyGUI::ListBox* topicsList;
Widgets::MWList* topicsList;
MyGUI::ProgressPtr pDispositionBar;
MyGUI::EditPtr pDispositionText;
std::map<std::string,std::string> pTopicsText;// this map links keyword and "real" text.

@ -0,0 +1,116 @@
#include "list.hpp"
#include <MyGUI.h>
using namespace MWGui;
using namespace MWGui::Widgets;
MWList::MWList() :
mClient(0)
, mScrollView(0)
, mItemHeight(0)
{
}
void MWList::initialiseOverride()
{
Base::initialiseOverride();
assignWidget(mClient, "Client");
if (mClient == 0)
mClient = this;
mScrollView = mClient->createWidgetReal<MyGUI::ScrollView>(
"MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0),
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
}
void MWList::addItem(const std::string& name)
{
mItems.push_back(name);
redraw();
}
void MWList::redraw(bool scrollbarShown)
{
const int _scrollBarWidth = 24; // fetch this from skin?
const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0;
const int spacing = 3;
while (mScrollView->getChildCount())
{
MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));
}
mItemHeight = 0;
for (std::vector<std::string>::const_iterator it=mItems.begin();
it!=mItems.end(); ++it)
{
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(
"MW_ListLine", MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it));
button->setCaption((*it));
button->getSubWidgetText()->setWordWrap(true);
button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left);
button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel);
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected);
int height = button->getTextSize().height;
button->setSize(MyGUI::IntSize(button->getSize().width, height));
mItemHeight += height + spacing;
}
mScrollView->setCanvasSize(mClient->getSize().width + (_scrollBarWidth-scrollBarWidth), std::max(mItemHeight, mClient->getSize().height));
mScrollView->setViewOffset(MyGUI::IntPoint(0,0));
if (!scrollbarShown && mItemHeight > mClient->getSize().height)
redraw(true);
}
bool MWList::hasItem(const std::string& name)
{
return (std::find(mItems.begin(), mItems.end(), name) != mItems.end());
}
unsigned int MWList::getItemCount()
{
return mItems.size();
}
std::string MWList::getItemNameAt(unsigned int at)
{
assert(at < mItems.size() && "List item out of bounds");
return mItems[at];
}
void MWList::removeItem(const std::string& name)
{
assert( std::find(mItems.begin(), mItems.end(), name) != mItems.end() );
mItems.erase( std::find(mItems.begin(), mItems.end(), name) );
redraw();
}
void MWList::clear()
{
mItems.clear();
redraw();
}
void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel)
{
//NB view offset is negative
if (mScrollView->getViewOffset().top + _rel*0.3 > 0)
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
else
mScrollView->setViewOffset(MyGUI::IntPoint(0, mScrollView->getViewOffset().top + _rel*0.3));
}
void MWList::onItemSelected(MyGUI::Widget* _sender)
{
std::string name = static_cast<MyGUI::Button*>(_sender)->getCaption();
eventItemSelected(name);
}

@ -0,0 +1,54 @@
#ifndef MWGUI_LIST_HPP
#define MWGUI_LIST_HPP
#include <MyGUI.h>
namespace MWGui
{
namespace Widgets
{
/**
* \brief a very simple list widget that supports word-wrapping entries
* \note does not handle changing the width of the list at runtime
*/
class MWList : public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MWList)
public:
MWList();
typedef MyGUI::delegates::CMultiDelegate1<std::string> EventHandle_String;
/**
* Event: Item selected with the mouse.
* signature: void method(std::string itemName)
*/
EventHandle_String eventItemSelected;
void addItem(const std::string& name);
void removeItem(const std::string& name);
bool hasItem(const std::string& name);
unsigned int getItemCount();
std::string getItemNameAt(unsigned int at);
void clear();
protected:
void initialiseOverride();
void redraw(bool scrollbarShown = false);
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
void onItemSelected(MyGUI::Widget* _sender);
private:
MyGUI::ScrollView* mScrollView;
MyGUI::Widget* mClient;
std::vector<std::string> mItems;
int mItemHeight; // height of all items
};
}
}
#endif

@ -10,6 +10,7 @@
#include "tooltips.hpp"
#include "scrollwindow.hpp"
#include "bookwindow.hpp"
#include "list.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwinput/inputmanager.hpp"
@ -73,6 +74,13 @@ WindowManager::WindowManager(
//Register own widgets with MyGUI
MyGUI::FactoryManager::getInstance().registerFactory<DialogueHistory>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWEffectList>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpellEffect>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWDynamicStat>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWList>("Widget");
// Get size info from the Gui object
assert(gui);
@ -107,13 +115,6 @@ WindowManager::WindowManager(
playerSkillValues.insert(std::make_pair(ESM::Skill::skillIds[i], MWMechanics::Stat<float>()));
}
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWEffectList>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpellEffect>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWDynamicStat>("Widget");
// Set up visibility
updateVisible();
}

@ -19,7 +19,7 @@
<Widget type="EditBox" skin="MW_DispositionEdit" position_real = "0 0 1 1" align="Stretch" name = "DispositionText"/>
</Widget>
<!-- The list of topics -->
<Widget type="ListBox" skin="MW_List" position="432 31 132 328" name="TopicsList" align="Right VStretch">
<Widget type="MWList" skin="MW_SimpleList" position="432 31 132 328" name="TopicsList" align="Right VStretch">
</Widget>
<!-- The Goodbye button -->

@ -212,6 +212,20 @@
<Child type="Widget" skin="IB_BR" offset="514 514 2 2" align="ALIGN_BOTTOM ALIGN_RIGHT"/>
</Skin>
<Skin name = "MW_SimpleList" size = "516 516" align = "ALIGN_LEFT ALIGN_TOP" texture="mwgui.png">
<Child type="Widget" skin="" offset = "3 3 510 510" align = "ALIGN_STRETCH" name = "Client">
</Child>
<Child type="Widget" skin="IB_T" offset="2 0 512 2" align="ALIGN_TOP ALIGN_HSTRETCH"/>
<Child type="Widget" skin="IB_B" offset="2 514 512 2" align="ALIGN_BOTTOM ALIGN_HSTRETCH"/>
<Child type="Widget" skin="IB_L" offset="0 2 2 512" align="ALIGN_LEFT ALIGN_VSTRETCH"/>
<Child type="Widget" skin="IB_R" offset="514 2 2 512" align="ALIGN_RIGHT ALIGN_VSTRETCH"/>
<Child type="Widget" skin="IB_TL" offset="0 0 2 2" align="ALIGN_TOP ALIGN_LEFT"/>
<Child type="Widget" skin="IB_TR" offset="514 0 2 2" align="ALIGN_TOP ALIGN_RIGHT"/>
<Child type="Widget" skin="IB_BL" offset="0 514 2 2" align="ALIGN_BOTTOM ALIGN_LEFT"/>
<Child type="Widget" skin="IB_BR" offset="514 514 2 2" align="ALIGN_BOTTOM ALIGN_RIGHT"/>
</Skin>
<Skin name = "MW_MultiSubList" size = "516 516" align = "ALIGN_LEFT ALIGN_TOP">
<Property key="NeedKey" value = "true" />
<Property key="SkinLine" value = "MW_ListLine" />

@ -15,6 +15,19 @@
<Property key="ImageResource" value="MenuBook_Close"/>
</Widget>
<Widget type="ScrollView" skin="MW_ScrollView" position="60 130 410 300" name="TextView">
<Property key="CanvasSize" value="410 900"/>
<Widget type="EditBox" skin="NormalText" position="0 0 380 900">
<Property key="Caption" value="fisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idjfisdj fjidifj dij fdijf idj fjidi jfdij fidj fidj ifjdi fj idj"/>
<Property key="WordWrap" value="true"/>
<Property key="TextColour" value="0 0 0"/>
<Property key="TextAlign" value="ALIGN_LEFT ALIGN_TOP"/>
<Property key="Static" value="true"/>
<Property key="VisibleVScroll" value="1"/>
<Property key="NeedMouse" value="0"/>
</Widget>
</Widget>
</Widget>
</Widget>

@ -2,4 +2,10 @@
<MyGUI type="Skin">
<Skin name="MW_ScrollView" size="516 516" texture="mwgui.png">
<Child type="Widget" skin="" offset="0 0 516 516" align="Stretch" name="Client"/>
<Child type="ScrollBar" skin="MW_VScroll" offset="498 3 14 509" align="ALIGN_RIGHT ALIGN_VSTRETCH" name="VScroll"/>
</Skin>
</MyGUI>

Loading…
Cancel
Save