quest-wizard/view/controls/sceneinventorypanel.cpp

86 lines
3.9 KiB
C++
Raw Permalink Normal View History

2023-02-09 14:41:24 +01:00
#include "sceneinventorypanel.h"
#include "features/gamefeatures.h"
#include "features/qw_statemachine.h"
#include "qw_globalmetadata.h"
SceneInventoryPanel::SceneInventoryPanel()
{
metadata.pixmap_path = QWGlobalMetadata::valueBy("InventoryPanel:pixmap_path").toString();
metadata.on_hid = QRect(QPoint(QWGlobalMetadata::valueBy("InventoryPanel:on_hid:bot_left_x" ).toInt(), // x1
QWGlobalMetadata::valueBy("InventoryPanel:on_hid:bot_left_y" ).toInt()), // y1
QPoint(QWGlobalMetadata::valueBy("InventoryPanel:on_hid:top_right_x").toInt(), // x4
QWGlobalMetadata::valueBy("InventoryPanel:on_hid:top_right_y").toInt())); // y4
metadata.on_shw = QRect(QPoint(QWGlobalMetadata::valueBy("InventoryPanel:on_shw:bot_left_x" ).toInt(), // x1
QWGlobalMetadata::valueBy("InventoryPanel:on_shw:bot_left_y" ).toInt()), // y1
QPoint(QWGlobalMetadata::valueBy("InventoryPanel:on_shw:top_right_x").toInt(), // x4
QWGlobalMetadata::valueBy("InventoryPanel:on_shw:top_right_y").toInt())); // y4
/* /
* 2-------4 /
* | | <-
* 1-------3
*/
setPixmap(QPixmap(metadata.pixmap_path));
}
void SceneInventoryPanel::onClick()
{
emit signalOnInventory();
}
void SceneInventoryPanel::onConnect(std::unique_ptr<GameFeatures> &game_features)
{
game_features->ptr_inventory->setInventoryPanel(shared_from_this());
QObject::connect(this, //sender
SIGNAL(signalOnInventory()),
game_features->ptr_inventory, // receiver
SLOT(onClicked()));
}
void SceneInventoryPanel::onBuildingStateMachine(QWStateMachine *state_machine, std::unique_ptr<GameFeatures> &game_features)
{
// Establisihing animation for inventory panel
QPropertyAnimation *anim = new QPropertyAnimation(shared_from_this().get(), "geometry");
anim->setDuration(200);
anim->setEasingCurve(QEasingCurve::InBack);
QState *state_gameplay = new QState;
state_machine->registerState("state_gameplay", state_gameplay);
connect(state_gameplay, SIGNAL(entered()), game_features->ptr_scene, SLOT(onEntryGameplay()));
QState *state_inventory = new QState;
state_machine->registerState("state_inventory", state_inventory);
connect(state_inventory, SIGNAL(entered()), game_features->ptr_scene, SLOT(onEntryInventory()));
QEventTransition *enter_inventory_transition = new QEventTransition(game_features->ptr_view, QEvent::Wheel);
enter_inventory_transition->setTargetState(state_inventory);
enter_inventory_transition->addAnimation(anim);
state_gameplay->addTransition(enter_inventory_transition);
QEventTransition *leave_inventory_transition = new QEventTransition(game_features->ptr_view, QEvent::Wheel);
leave_inventory_transition->setTargetState(state_gameplay);
leave_inventory_transition->addAnimation(anim);
state_inventory->addTransition(leave_inventory_transition);
state_gameplay->assignProperty(this, "geometry", metadata.on_hid);
state_inventory->assignProperty(this, "geometry", metadata.on_shw);
state_machine->addState(state_gameplay);
state_machine->addState(state_inventory);
}
////////////////////////
void SceneInventoryPanel::setPixmap(const QPixmap &pix) noexcept
{
pix_rect = pix;
Q_ASSERT(!pix_rect.isNull());
}
QPixmap SceneInventoryPanel::pixmap() const noexcept
{
return pix_rect;
}