Added dialouge window

actorid
Jan-Peter Nilsson 14 years ago
parent 54319b0117
commit be5562cb2c

@ -43,6 +43,8 @@ set(GAMEGUI_HEADER
mwgui/review.hpp
mwgui/window_manager.hpp
mwgui/console.hpp
mwgui/dialogue.hpp
mwgui/dialogue_history.hpp
)
set(GAMEGUI
mwgui/window_manager.cpp
@ -54,6 +56,8 @@ set(GAMEGUI
mwgui/birth.cpp
mwgui/class.cpp
mwgui/review.cpp
mwgui/dialogue.cpp
mwgui/dialogue_history.cpp
)
source_group(apps\\openmw\\mwgui FILES ${GAMEGUI_HEADER} ${GAMEGUI})

@ -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

@ -5,6 +5,8 @@
#include "class.hpp"
#include "birth.hpp"
#include "review.hpp"
#include "dialogue.hpp"
#include "dialogue_history.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwinput/inputmanager.hpp"
@ -22,6 +24,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
: environment(environment)
, nameDialog(nullptr)
, raceDialog(nullptr)
, dialogueWindow(nullptr)
, classChoiceDialog(nullptr)
, generateClassQuestionDialog(nullptr)
, generateClassResultDialog(nullptr)
@ -41,6 +44,10 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
, shown(GW_ALL)
, allowed(newGame ? GW_None : GW_ALL)
{
//Register own widgets with MyGUI
MyGUI::FactoryManager::getInstance().registerFactory<DialogeHistory>("Widget");
// Get size info from the Gui object
assert(gui);
int w = gui->getViewSize().width;
@ -86,6 +93,7 @@ WindowManager::~WindowManager()
delete nameDialog;
delete raceDialog;
delete dialogueWindow;
delete classChoiceDialog;
delete generateClassQuestionDialog;
delete generateClassResultDialog;
@ -307,6 +315,17 @@ void WindowManager::updateVisible()
return;
}
if (mode == GM_Dialogue)
{
if (dialogueWindow)
removeDialog(dialogueWindow);
dialogueWindow = new DialogueWindow(environment);
dialogueWindow->eventBye = MyGUI::newDelegate(this, &WindowManager::onDialogueWindowBye);
dialogueWindow->open();
return;
}
// Unsupported mode, switch back to game
// Note: The call will eventually end up this method again but
// will stop at the check if(mode == GM_Game) above.
@ -522,6 +541,16 @@ void WindowManager::onRaceDialogDone()
setGuiMode(GM_Game);
}
void WindowManager::onDialogueWindowBye()
{
if (dialogueWindow)
{
//FIXME set some state and stuff?
removeDialog(dialogueWindow);
}
setGuiMode(GM_Game);
}
void WindowManager::onRaceDialogBack()
{
if (raceDialog)

@ -54,6 +54,7 @@ namespace MWGui
class TextInputDialog;
class InfoBoxDialog;
class RaceDialog;
class DialogueWindow;
class ClassChoiceDialog;
class GenerateClassResultDialog;
class PickClassDialog;
@ -82,6 +83,7 @@ namespace MWGui
// Character creation
TextInputDialog *nameDialog;
RaceDialog *raceDialog;
DialogueWindow *dialogueWindow;
ClassChoiceDialog *classChoiceDialog;
InfoBoxDialog *generateClassQuestionDialog;
GenerateClassResultDialog *generateClassResultDialog;
@ -248,6 +250,9 @@ namespace MWGui
const std::string &getGameSettingString(const std::string &id, const std::string &default_);
private:
void onDialogueWindowBye();
// Character generation: Name dialog
void onNameDialogDone();

@ -53,6 +53,7 @@ configure_file("${SDIR}/openmw_chargen_select_skill_layout.xml" "${DDIR}/openmw_
configure_file("${SDIR}/openmw_chargen_class_description_layout.xml" "${DDIR}/openmw_chargen_class_description_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_chargen_birth_layout.xml" "${DDIR}/openmw_chargen_birth_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_chargen_review_layout.xml" "${DDIR}/openmw_chargen_review_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_dialogue_window_layout.xml" "${DDIR}/openmw_dialogue_window_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_inventory_window_layout.xml" "${DDIR}/openmw_inventory_window_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_layers.xml" "${DDIR}/openmw_layers.xml" COPYONLY)
configure_file("${SDIR}/openmw_mainmenu_layout.xml" "${DDIR}/openmw_mainmenu_layout.xml" COPYONLY)

@ -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…
Cancel
Save