61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
#include "models/dialogues/qw_textdialogue.h"
|
|
#include "qw_textdialoguemanager.h"
|
|
|
|
QWTextDialogueManager::QWTextDialogueManager(QWScene *scene) :
|
|
QWAbstractDialogueManager(scene),
|
|
p_frametext(new QGraphicsSimpleTextItem)
|
|
{
|
|
p_frametext->setFont(QFont("Arial", 25));
|
|
p_frametext->setBrush(QBrush(Qt::white));
|
|
p_frametext->setPos(12, 12);
|
|
scene->addItem(p_frametext);
|
|
}
|
|
|
|
QWTextDialogueManager::~QWTextDialogueManager()
|
|
{
|
|
delete p_frametext;
|
|
}
|
|
|
|
void QWTextDialogueManager::activateDialogue(const std::shared_ptr<QWAbstractGameDialogue> &dialogue)
|
|
{
|
|
/* Moving to text dialogue state.
|
|
* Make the panel with text visible.
|
|
* Game freezes until when player reads all
|
|
* the frames. */
|
|
|
|
ptr_text_dialogue = std::dynamic_pointer_cast<QWTextDialogue>(dialogue);
|
|
|
|
connect(ptr_scene, SIGNAL(signalClickDialogue(MouseButton)), this, SLOT(onClicked(MouseButton)));
|
|
|
|
emit onEntryDialogueTransition();
|
|
|
|
p_frametext->show();
|
|
|
|
// Show the first page of active dialogue.
|
|
p_frametext->setText(ptr_text_dialogue->currentText());
|
|
}
|
|
|
|
////////////////////////
|
|
|
|
void QWTextDialogueManager::setDialoguePanel(const std::shared_ptr<QGraphicsWidget> &panel) noexcept
|
|
{
|
|
p_textbox = panel;
|
|
}
|
|
|
|
void QWTextDialogueManager::onClicked(MouseButton mouse_button)
|
|
{
|
|
const bool has_next_pages = ptr_text_dialogue->toNextPage();
|
|
|
|
if (!has_next_pages || mouse_button == MouseButton::RIGHT) {
|
|
p_frametext->hide();
|
|
ptr_text_dialogue->resetPage();
|
|
ptr_text_dialogue->onExit(static_cast<int>(mouse_button));
|
|
|
|
disconnect(ptr_scene, SIGNAL(signalClickDialogue(MouseButton)), this, SLOT(onClicked(MouseButton)));
|
|
|
|
emit onLeaveDialogueTransition();
|
|
|
|
} else
|
|
p_frametext->setText(ptr_text_dialogue->currentText());
|
|
}
|