Added dialouge window
parent
54319b0117
commit
be5562cb2c
@ -0,0 +1,127 @@
|
|||||||
|
#include "dialogue.hpp"
|
||||||
|
#include "dialogue_history.hpp"
|
||||||
|
#include "../mwworld/environment.hpp"
|
||||||
|
#include "../mwworld/world.hpp"
|
||||||
|
#include "window_manager.hpp"
|
||||||
|
#include "widgets.hpp"
|
||||||
|
#include "components/esm_store/store.hpp"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
using namespace MWGui;
|
||||||
|
using namespace Widgets;
|
||||||
|
|
||||||
|
DialogueWindow::DialogueWindow(MWWorld::Environment& environment)
|
||||||
|
: Layout("openmw_dialogue_window_layout.xml")
|
||||||
|
, environment(environment)
|
||||||
|
{
|
||||||
|
// Centre dialog
|
||||||
|
MyGUI::IntSize gameWindowSize = environment.mWindowManager->getGui()->getViewSize();
|
||||||
|
MyGUI::IntCoord coord = mMainWidget->getCoord();
|
||||||
|
coord.left = (gameWindowSize.width - coord.width)/2;
|
||||||
|
coord.top = (gameWindowSize.height - coord.height)/2;
|
||||||
|
mMainWidget->setCoord(coord);
|
||||||
|
|
||||||
|
//WindowManager *wm = environment.mWindowManager;
|
||||||
|
setText("NpcName", "Name of character");
|
||||||
|
|
||||||
|
//History view
|
||||||
|
getWidget(history, "History");
|
||||||
|
history->setOverflowToTheLeft(true);
|
||||||
|
history->getClient()->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onHistoryClicked);
|
||||||
|
|
||||||
|
//Topics list
|
||||||
|
getWidget(topicsList, "TopicsList");
|
||||||
|
topicsList->setScrollVisible(true);
|
||||||
|
topicsList->eventListSelectAccept = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
|
||||||
|
topicsList->eventListMouseItemActivate = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
|
||||||
|
topicsList->eventListChangePosition = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
|
||||||
|
|
||||||
|
MyGUI::ButtonPtr byeButton;
|
||||||
|
getWidget(byeButton, "ByeButton");
|
||||||
|
byeButton->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onByeClicked);
|
||||||
|
|
||||||
|
updateOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender)
|
||||||
|
{
|
||||||
|
ISubWidgetText* t = history->getSubWidgetText();
|
||||||
|
if(t == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const IntPoint& lastPressed = InputManager::getInstance().getLastLeftPressed();
|
||||||
|
|
||||||
|
size_t cursorPosition = t->getCursorPosition(lastPressed);
|
||||||
|
if(history->getColorAtPos(cursorPosition) != "#FFFFFF")
|
||||||
|
{
|
||||||
|
UString key = history->getColorTextAt(cursorPosition);
|
||||||
|
std::cout << "Clicked on key: " << key << std::endl;
|
||||||
|
//eventTopicSelected(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogueWindow::open()
|
||||||
|
{
|
||||||
|
updateOptions();
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogueWindow::onByeClicked(MyGUI::Widget* _sender)
|
||||||
|
{
|
||||||
|
eventBye();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogueWindow::onSelectTopic(MyGUI::List* _sender, size_t _index)
|
||||||
|
{
|
||||||
|
if (_index == MyGUI::ITEM_NONE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//const std::string* theTopic = topicsList->getItemDataAt<std::string>(_index);
|
||||||
|
//std::cout << "Selected: "<< theTopic << std::endl;
|
||||||
|
//eventTopicSelected(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DialogueWindow::updateOptions()
|
||||||
|
{
|
||||||
|
//FIXME Add this properly
|
||||||
|
history->addDialogText("Through the translucent surface of the orb, you see shifting images of distant locations...");
|
||||||
|
for(int z = 0; z < 10; z++)
|
||||||
|
{
|
||||||
|
history->addDialogHeading("Fort Frostmoth");
|
||||||
|
history->addDialogText("The image in the orb flickers, and you see.... The cold courtyard of #FF0000Fort Frostmoth#FFFFFF, battered bu werewolf attack, but still standing, still projecting Imperial might even to this distant and cold corner of the world.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Clear the list of topics
|
||||||
|
topicsList->removeAllItems();
|
||||||
|
int i = 0;
|
||||||
|
topicsList->addItem("Ald'ruhn", i++);
|
||||||
|
topicsList->addItem("Balmora", i++);
|
||||||
|
topicsList->addItem("Sadrith Mora", i++);
|
||||||
|
topicsList->addItem("Vivec", i++);
|
||||||
|
topicsList->addItem("Ald Velothi", i++);
|
||||||
|
topicsList->addItem("Caldera", i++);
|
||||||
|
topicsList->addItem("Dagon Fel ", i++);
|
||||||
|
topicsList->addItem("Gnaar Mok", i++);
|
||||||
|
topicsList->addItem("Gnisis", i++);
|
||||||
|
topicsList->addItem("Hla Oad", i++);
|
||||||
|
topicsList->addItem("Khuul", i++);
|
||||||
|
topicsList->addItem("Maar Gan", i++);
|
||||||
|
topicsList->addItem("Molag Mar", i++);
|
||||||
|
topicsList->addItem("Pelagiad", i++);
|
||||||
|
topicsList->addItem("Seyda Neen", i++);
|
||||||
|
topicsList->addItem("Suran", i++);
|
||||||
|
topicsList->addItem("Tel Aruhn", i++);
|
||||||
|
topicsList->addItem("Tel Branora", i++);
|
||||||
|
topicsList->addItem("Tel Fyr", i++);
|
||||||
|
topicsList->addItem("Tel Mora", i++);
|
||||||
|
topicsList->addItem("Tel Vos", i++);
|
||||||
|
topicsList->addItem("Vos", i++);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
|||||||
|
#ifndef MWGUI_DIALOGE_H
|
||||||
|
#define MWGUI_DIALOGE_H
|
||||||
|
|
||||||
|
#include <components/esm_store/store.hpp>
|
||||||
|
|
||||||
|
#include <openengine/gui/layout.hpp>
|
||||||
|
|
||||||
|
#include <boost/array.hpp>
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
class Environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file contains the dialouge window
|
||||||
|
Layout is defined by resources/mygui/openmw_dialogue_window_layout.xml.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
class DialogeHistory;
|
||||||
|
|
||||||
|
using namespace MyGUI;
|
||||||
|
|
||||||
|
class DialogueWindow: public OEngine::GUI::Layout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DialogueWindow(MWWorld::Environment& environment);
|
||||||
|
|
||||||
|
void open();
|
||||||
|
|
||||||
|
// Events
|
||||||
|
typedef delegates::CDelegate0 EventHandle_Void;
|
||||||
|
|
||||||
|
/** Event : Dialog finished, OK button clicked.\n
|
||||||
|
signature : void method()\n
|
||||||
|
*/
|
||||||
|
EventHandle_Void eventBye;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void onSelectTopic(MyGUI::List* _sender, size_t _index);
|
||||||
|
void onByeClicked(MyGUI::Widget* _sender);
|
||||||
|
void onHistoryClicked(MyGUI::Widget* _sender);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateOptions();
|
||||||
|
|
||||||
|
MWWorld::Environment& environment;
|
||||||
|
|
||||||
|
DialogeHistory* history;
|
||||||
|
MyGUI::ListPtr topicsList;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -0,0 +1,77 @@
|
|||||||
|
#include "dialogue_history.hpp"
|
||||||
|
#include "../mwworld/environment.hpp"
|
||||||
|
#include "../mwworld/world.hpp"
|
||||||
|
#include "window_manager.hpp"
|
||||||
|
#include "widgets.hpp"
|
||||||
|
#include "components/esm_store/store.hpp"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
using namespace MWGui;
|
||||||
|
using namespace Widgets;
|
||||||
|
|
||||||
|
UString DialogeHistory::getColorAtPos(size_t _pos)
|
||||||
|
{
|
||||||
|
UString colour = TextIterator::convertTagColour(mText->getTextColour());
|
||||||
|
TextIterator iterator(mText->getCaption());
|
||||||
|
while(iterator.moveNext())
|
||||||
|
{
|
||||||
|
size_t pos = iterator.getPosition();
|
||||||
|
iterator.getTagColour(colour);
|
||||||
|
if (pos < _pos)
|
||||||
|
continue;
|
||||||
|
else if (pos == _pos)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
UString DialogeHistory::getColorTextAt(size_t _pos)
|
||||||
|
{
|
||||||
|
bool breakOnNext = false;
|
||||||
|
UString colour = TextIterator::convertTagColour(mText->getTextColour());
|
||||||
|
UString colour2 = colour;
|
||||||
|
TextIterator iterator(mText->getCaption());
|
||||||
|
TextIterator col_start = iterator;
|
||||||
|
while(iterator.moveNext())
|
||||||
|
{
|
||||||
|
size_t pos = iterator.getPosition();
|
||||||
|
iterator.getTagColour(colour);
|
||||||
|
if(colour != colour2)
|
||||||
|
{
|
||||||
|
if(breakOnNext)
|
||||||
|
{
|
||||||
|
return getOnlyText().substr(col_start.getPosition(), iterator.getPosition()-col_start.getPosition());
|
||||||
|
}
|
||||||
|
col_start = iterator;
|
||||||
|
colour2 = colour;
|
||||||
|
}
|
||||||
|
if (pos < _pos)
|
||||||
|
continue;
|
||||||
|
else if (pos == _pos)
|
||||||
|
{
|
||||||
|
breakOnNext = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogeHistory::addDialogHeading(const UString& parText)
|
||||||
|
{
|
||||||
|
UString head("\n#00FF00");
|
||||||
|
head.append(parText);
|
||||||
|
head.append("#FFFFFF\n");
|
||||||
|
addText(head);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogeHistory::addDialogText(const UString& parText)
|
||||||
|
{
|
||||||
|
addText(parText);
|
||||||
|
addText("\n");
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef MWGUI_DIALOGE_HISTORY_H
|
||||||
|
#define MWGUI_DIALOGE_HISTORY_H
|
||||||
|
#include <openengine/gui/layout.hpp>
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
using namespace MyGUI;
|
||||||
|
class DialogeHistory : public MyGUI::Edit
|
||||||
|
{
|
||||||
|
MYGUI_RTTI_DERIVED( DialogeHistory )
|
||||||
|
public:
|
||||||
|
Widget* getClient() { return mClient; }
|
||||||
|
UString getColorAtPos(size_t _pos);
|
||||||
|
UString getColorTextAt(size_t _pos);
|
||||||
|
void addDialogHeading(const UString& parText);
|
||||||
|
void addDialogText(const UString& parText);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<MyGUI type="Layout">
|
||||||
|
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 588 433" name="_Main">
|
||||||
|
<!-- HEADER -->
|
||||||
|
<Widget type="StaticText" skin="HeaderText" position="0 0 588 18" name="NpcName" align="ALIGN_LEFT ALIGN_TOP">
|
||||||
|
<Property key="Widget_Caption" value="Name"/>
|
||||||
|
<Property key="Widget_AlignText" value="ALIGN_CENTER"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<!-- The Dialogue history -->
|
||||||
|
<Widget type="DialogeHistory" skin="MW_TextBoxEdit" position="8 39 400 375" name="History" align="ALIGN_LEFT ALIGN_TOP STRETCH">
|
||||||
|
<Property key="Edit_Static" value="true"/>
|
||||||
|
<Property key="Edit_WordWrap" value="true"/>
|
||||||
|
<Property key="Text_FontHeight" value="18"/>
|
||||||
|
<Property key="Edit_MultiLine" value="1" />
|
||||||
|
<Property key="Edit_VisibleVScroll" value="1" />
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<!-- The list of topics -->
|
||||||
|
<Widget type="List" skin="MW_List" position="432 39 132 341" name="TopicsList">
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<!-- The Goodbye button -->
|
||||||
|
<Widget type="Button" skin="MW_Button" position="432 387 132 23" name="ByeButton">
|
||||||
|
<Property key="Widget_Caption" value="Goodbye"/>
|
||||||
|
</Widget>
|
||||||
|
</Widget>
|
||||||
|
</MyGUI>
|
Loading…
Reference in New Issue