quest-wizard/view/qw_scene.cpp

129 lines
3.2 KiB
C++

#include "qw_scene.h"
#include "models/qw_trigger.h"
#include "controls/sceneinventorypanel.h"
#include "controls/pushbuttonsound.h"
#include "controls/scenedialoguepanel.h"
QWScene::QWScene(int x, int y) :
QGraphicsScene(0, 0, x, y)
{
QLinkedList<std::shared_ptr<QWAbstractSceneControl>> widgt_list =
{ std::make_shared<SceneInventoryPanel>(),
std::make_shared<SceneDialoguePanel>()
//std::make_shared<PushButtonSound>(QPixmap(":/res/cell.png")/*, ptr_inventory_panel.get()*/),
};
foreach (std::shared_ptr<QWAbstractSceneControl> widgt, widgt_list) {
addItem(widgt.get());
list_on_inventory_widgets.append(std::move(widgt));
}
}
QLinkedList<std::shared_ptr<QWAbstractSceneControl>> QWScene::inventoryWidgets() const noexcept
{
return list_on_inventory_widgets;
}
void QWScene::onEntryGameplay() noexcept
{
status = GAMEPLAY;
}
void QWScene::onEntryInventory() noexcept
{
status = INVENTORY;
}
void QWScene::onEntryMenu() noexcept
{
status = MENU;
emit signalEnterMenu();
}
void QWScene::onEntryDialogue() noexcept
{
status = DIALOGUE;
}
void QWScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
switch (status)
{
case MENU:
case GAMEPLAY:
// On GAMEPLAY and MENU state we check all the in-game entities.
foreach (std::shared_ptr<QWTrigger> tr, location->triggers()) {
if (tr->isUnderMouse() && event->button() == Qt::LeftButton)
tr->activate();
}
break;
case INVENTORY:
// On INVENTORY state we check all the system controls like buttons for sound, etc.
foreach (std::shared_ptr<QWAbstractSceneControl> tr, list_on_inventory_widgets) {
if (tr->isUnderMouse() && event->button() == Qt::LeftButton)
tr->onClick();
}
break;
case DIALOGUE:
// On DIALOGUE state we interact with current dialogue only.
switch (event->button()) {
case Qt::LeftButton:
emit signalClickDialogue(MouseButton::LEFT);
break;
case Qt::RightButton:
emit signalClickDialogue(MouseButton::RIGHT);
break;
default:
break;
}
break;
case EXAMINATION:
// On EXAMINATION state we activate examination events of triggers
foreach (std::shared_ptr<QWTrigger> tr, location->triggers()) {
if (tr->isUnderMouse() && event->button() == Qt::LeftButton)
emit signalLeaveExamination();
tr->startExaminationDialogue();
}
break;
}
}
void QWScene::keyReleaseEvent(QKeyEvent *event)
{
switch (status)
{
case GAMEPLAY:
if (event->key() == Qt::Key_E)
emit signalEnterExamination();
break;
default:
return;
}
}
void QWScene::clearLocation()
{
if (!location)
return;
// Moving to another location by erasing current
foreach (const std::shared_ptr<QWTrigger> trigger, location->triggers())
removeItem(trigger.get());
location = nullptr;
}
void QWScene::setCurrentLocation(const std::shared_ptr<QWLocation> &loc) noexcept
{
location = loc;
}
std::shared_ptr<QWLocation> QWScene::currentLocation() const noexcept
{
return location;
}