Browse Source

Init

master
NaiJi 10 months ago
commit
95e270d6dc
  1. 2
      .gitignore
  2. 24
      LICENSE
  3. 118
      QuestWizard.pro
  4. 3
      README.md
  5. 1
      add_ico.rc
  6. 17
      application.qrc
  7. 41
      features/gamefeatures.h
  8. 9
      features/qw_abstractdialoguemanager.cpp
  9. 29
      features/qw_abstractdialoguemanager.h
  10. 234
      features/qw_eventfactory.cpp
  11. 48
      features/qw_eventfactory.h
  12. 94
      features/qw_inventorymanager.cpp
  13. 67
      features/qw_inventorymanager.h
  14. 423
      features/qw_levelbuilder.cpp
  15. 76
      features/qw_levelbuilder.h
  16. 121
      features/qw_soundplayer.cpp
  17. 61
      features/qw_soundplayer.h
  18. 15
      features/qw_statemachine.cpp
  19. 23
      features/qw_statemachine.h
  20. 60
      features/qw_textdialoguemanager.cpp
  21. 37
      features/qw_textdialoguemanager.h
  22. 50
      features/qw_widgetdialoguemanager.cpp
  23. 28
      features/qw_widgetdialoguemanager.h
  24. 114
      game.cpp
  25. 34
      game.h
  26. BIN
      icon.ico
  27. 14
      main.cpp
  28. 28
      models/dialogues/qw_abstractgamedialogue.cpp
  29. 38
      models/dialogues/qw_abstractgamedialogue.h
  30. 48
      models/dialogues/qw_textdialogue.cpp
  31. 35
      models/dialogues/qw_textdialogue.h
  32. 63
      models/dialogues/qw_widgetdialogue.cpp
  33. 45
      models/dialogues/qw_widgetdialogue.h
  34. 7
      models/events/qw_abstractevent.cpp
  35. 43
      models/events/qw_abstractevent.h
  36. 20
      models/events/qw_abstractinventoryevent.cpp
  37. 31
      models/events/qw_abstractinventoryevent.h
  38. 20
      models/events/qw_abstractlevelevent.cpp
  39. 31
      models/events/qw_abstractlevelevent.h
  40. 19
      models/events/qw_abstractsceneevent.cpp
  41. 31
      models/events/qw_abstractsceneevent.h
  42. 19
      models/events/qw_abstractsoundevent.cpp
  43. 31
      models/events/qw_abstractsoundevent.h
  44. 49
      models/events/qw_addtriggerevent.cpp
  45. 31
      models/events/qw_addtriggerevent.h
  46. 52
      models/events/qw_changelocationevent.cpp
  47. 32
      models/events/qw_changelocationevent.h
  48. 65
      models/events/qw_changetriggerpropertiesevent.cpp
  49. 43
      models/events/qw_changetriggerpropertiesevent.h
  50. 37
      models/events/qw_deletefrominventoryevent.cpp
  51. 33
      models/events/qw_deletefrominventoryevent.h
  52. 25
      models/events/qw_endlevelevent.cpp
  53. 25
      models/events/qw_endlevelevent.h
  54. 45
      models/events/qw_newgameevent.cpp
  55. 27
      models/events/qw_newgameevent.h
  56. 37
      models/events/qw_pickupitemevent.cpp
  57. 33
      models/events/qw_pickupitemevent.h
  58. 43
      models/events/qw_playmusicevent.cpp
  59. 34
      models/events/qw_playmusicevent.h
  60. 24
      models/events/qw_playsoundevent.cpp
  61. 30
      models/events/qw_playsoundevent.h
  62. 26
      models/events/qw_quitgameevent.cpp
  63. 25
      models/events/qw_quitgameevent.h
  64. 49
      models/events/qw_removetriggerevent.cpp
  65. 31
      models/events/qw_removetriggerevent.h
  66. 36
      models/events/qw_startdialogueevent.cpp
  67. 34
      models/events/qw_startdialogueevent.h
  68. 75
      models/events/qw_switcheventsevent.cpp
  69. 48
      models/events/qw_switcheventsevent.h
  70. 114
      models/qw_location.cpp
  71. 51
      models/qw_location.h
  72. 18
      models/qw_tagholder.cpp
  73. 26
      models/qw_tagholder.h
  74. 113
      models/qw_trigger.cpp
  75. 46
      models/qw_trigger.h
  76. 21
      qml/test.qml
  77. 42
      qw_globalmetadata.cpp
  78. 30
      qw_globalmetadata.h
  79. BIN
      res/cell.png
  80. 28
      res/config.json
  81. 165
      res/defaultsave.json
  82. BIN
      res/dialogue_panel.jpeg
  83. BIN
      res/door.png
  84. BIN
      res/final_background.jpg
  85. BIN
      res/inv.jpg
  86. 111
      res/levels/level1.json
  87. 53
      res/menu.json
  88. BIN
      res/osaka.png
  89. BIN
      res/roomkey_background.jpg
  90. BIN
      res/sound.wav
  91. BIN
      res/spawn_background.jpg
  92. 37
      view/controls/pushbuttonsound.cpp
  93. 40
      view/controls/pushbuttonsound.h
  94. 13
      view/controls/qw_abstractscenecontrol.cpp
  95. 25
      view/controls/qw_abstractscenecontrol.h
  96. 71
      view/controls/scenedialoguepanel.cpp
  97. 45
      view/controls/scenedialoguepanel.h
  98. 85
      view/controls/sceneinventorypanel.cpp
  99. 49
      view/controls/sceneinventorypanel.h
  100. 128
      view/qw_scene.cpp

2
.gitignore

@ -0,0 +1,2 @@
*.pro.user
*.autosave

24
LICENSE

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

118
QuestWizard.pro

@ -0,0 +1,118 @@
#-------------------------------------------------
#
# Project created by QtCreator 2018-02-10T20:30:04
#
#-------------------------------------------------
VERSION = 0.0.1
CONFIG += c++17
#QMAKE_CXXFLAGS = -Wall -Werror -Wextra -Wpedantic -Wconversion -std=c++17 -O2 -g
QT += core gui multimedia widgets quickwidgets
# Potato22 is the best vector artist, you can't change my mind.
# The icon is precious!
RC_FILE += add_ico.rc
TARGET = QuestWizard
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp \
game.cpp \
features/qw_abstractdialoguemanager.cpp \
features/qw_textdialoguemanager.cpp \
features/qw_widgetdialoguemanager.cpp \
features/qw_eventfactory.cpp \
features/qw_inventorymanager.cpp \
features/qw_levelbuilder.cpp \
features/qw_soundplayer.cpp \
features/qw_statemachine.cpp \
qw_globalmetadata.cpp \
\
models/events/qw_abstractevent.cpp \
models/events/qw_abstractinventoryevent.cpp \
models/events/qw_abstractlevelevent.cpp \
models/events/qw_abstractsceneevent.cpp \
models/events/qw_abstractsoundevent.cpp \
models/events/qw_changelocationevent.cpp \
models/events/qw_changetriggerpropertiesevent.cpp \
models/events/qw_deletefrominventoryevent.cpp \
models/events/qw_endlevelevent.cpp \
models/events/qw_newgameevent.cpp \
models/events/qw_pickupitemevent.cpp \
models/events/qw_playmusicevent.cpp \
models/events/qw_playsoundevent.cpp \
models/events/qw_quitgameevent.cpp \
models/events/qw_startdialogueevent.cpp \
models/events/qw_addtriggerevent.cpp \
models/events/qw_removetriggerevent.cpp \
models/events/qw_switcheventsevent.cpp \
models/dialogues/qw_abstractgamedialogue.cpp \
models/dialogues/qw_textdialogue.cpp \
models/dialogues/qw_widgetdialogue.cpp \
models/qw_tagholder.cpp \
models/qw_trigger.cpp \
models/qw_location.cpp \
\
view/controls/pushbuttonsound.cpp \
view/controls/qw_abstractscenecontrol.cpp \
view/controls/scenedialoguepanel.cpp \
view/controls/sceneinventorypanel.cpp \
\
view/qw_scene.cpp \
view/qw_view.cpp
HEADERS += \
game.h \
features/qw_abstractdialoguemanager.h \
features/gamefeatures.h \
features/qw_textdialoguemanager.h \
features/qw_widgetdialoguemanager.h \
features/qw_eventfactory.h \
features/qw_inventorymanager.h \
features/qw_levelbuilder.h \
features/qw_soundplayer.h \
features/qw_statemachine.h \
qw_globalmetadata.h \
\
models/events/qw_abstractevent.h \
models/events/qw_abstractinventoryevent.h \
models/events/qw_abstractlevelevent.h \
models/events/qw_abstractsceneevent.h \
models/events/qw_abstractsoundevent.h \
models/events/qw_changelocationevent.h \
models/events/qw_changetriggerpropertiesevent.h \
models/events/qw_deletefrominventoryevent.h \
models/events/qw_endlevelevent.h \
models/events/qw_newgameevent.h \
models/events/qw_pickupitemevent.h \
models/events/qw_playmusicevent.h \
models/events/qw_playsoundevent.h \
models/events/qw_quitgameevent.h \
models/events/qw_startdialogueevent.h \
models/events/qw_addtriggerevent.h \
models/events/qw_removetriggerevent.h \
models/events/qw_switcheventsevent.h \
models/dialogues/qw_abstractgamedialogue.h \
models/dialogues/qw_textdialogue.h \
models/dialogues/qw_widgetdialogue.h \
models/qw_tagholder.h \
models/qw_trigger.h \
models/qw_location.h \
\
view/controls/pushbuttonsound.h \
view/controls/qw_abstractscenecontrol.h \
view/controls/scenedialoguepanel.h \
view/controls/sceneinventorypanel.h \
\
view/qw_scene.h \
view/qw_view.h
RESOURCES += \
application.qrc
DISTFILES += \
qml/test.qml

3
README.md

@ -0,0 +1,3 @@
# QuestWizard
I am not really sure what this thing is going to be but anyway here is trello where I try to manage stuff
https://trello.com/b/M3kqOaDB/questwizard-functional-requirements?menu=filter&filter=label:master-merge%201.1

1
add_ico.rc

@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "icon.ico"

17
application.qrc

@ -0,0 +1,17 @@
<RCC>
<qresource prefix="/">
<file>res/levels/level1.json</file>
<file>res/defaultsave.json</file>
<file>res/menu.json</file>
<file>res/final_background.jpg</file>
<file>res/roomkey_background.jpg</file>
<file>res/spawn_background.jpg</file>
<file>res/cell.png</file>
<file>res/door.png</file>
<file>res/inv.jpg</file>
<file>res/dialogue_panel.jpeg</file>
<file>res/sound.wav</file>
<file>res/osaka.png</file>
<file>res/config.json</file>
</qresource>
</RCC>

41
features/gamefeatures.h

@ -0,0 +1,41 @@
#ifndef GAMEFEATURES_H
#define GAMEFEATURES_H
#include "game.h"
#include "qw_levelbuilder.h"
#include "qw_soundplayer.h"
#include "qw_inventorymanager.h"
#include "qw_textdialoguemanager.h"
#include "qw_widgetdialoguemanager.h"
#include "view/qw_view.h"
/* GameFeatures
* The package of all key in-game managers. This way they are easy to transport. */
struct GameFeatures final
{
public:
QWView *ptr_view;
QWScene *ptr_scene;
QWSoundPlayer *ptr_sound_player;
QWInventoryManager *ptr_inventory;
QWLevelBuilder *ptr_builder;
QWTextDialogueManager *ptr_text_dlg;
QWWidgetDialogueManager *ptr_widget_dlg;
explicit GameFeatures(Game *ptr_game)
{
ptr_scene = new QWScene(1280, 720);
ptr_view = new QWView(ptr_scene);
ptr_sound_player = new QWSoundPlayer(ptr_game);
ptr_inventory = new QWInventoryManager(ptr_scene);
ptr_builder = new QWLevelBuilder(ptr_game);
ptr_text_dlg = new QWTextDialogueManager(ptr_scene);
ptr_widget_dlg = new QWWidgetDialogueManager(ptr_scene);
}
~GameFeatures() = default;
};
#endif // GAMEFEATURES_H

9
features/qw_abstractdialoguemanager.cpp

@ -0,0 +1,9 @@
#include "qw_abstractdialoguemanager.h"
QWAbstractDialogueManager:: QWAbstractDialogueManager(QWScene *scene) :
QObject(scene),
ptr_scene(scene)
{}
QWAbstractDialogueManager::~QWAbstractDialogueManager()
{}

29
features/qw_abstractdialoguemanager.h

@ -0,0 +1,29 @@
#ifndef QWABSTRACTDIALOGUEMANAGER_H
#define QWABSTRACTDIALOGUEMANAGER_H
#include <QObject>
#include "view/qw_scene.h"
#include "models/dialogues/qw_abstractgamedialogue.h"
class QWAbstractDialogueManager : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(QWAbstractDialogueManager)
protected:
QWScene *ptr_scene;
public:
explicit QWAbstractDialogueManager(QWScene *scene = nullptr);
virtual ~QWAbstractDialogueManager() override = 0;
virtual void activateDialogue(const std::shared_ptr<QWAbstractGameDialogue> &dialogue) = 0;
public slots:
virtual void onClicked(MouseButton mouse_button) = 0;
signals:
void onEntryDialogueTransition();
void onLeaveDialogueTransition();
};
#endif // QWABSTRACTDIALOGUEMANAGER_H

234
features/qw_eventfactory.cpp

@ -0,0 +1,234 @@
#include "qw_eventfactory.h"
#include "qw_levelbuilder.h"
#include "qw_widgetdialoguemanager.h"
#include "qw_textdialoguemanager.h"
#include "models/dialogues/qw_textdialogue.h"
#include "models/dialogues/qw_widgetdialogue.h"
QWEventFactory::QWEventFactory(QWLevelBuilder *b) :
builder(b)
{}
std::shared_ptr<QWDeleteFromInventoryEvent> QWEventFactory::createDeleteItEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWDeleteFromInventoryEvent> new_event;
qDebug() << " Found QWDeleteFromInventoryEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("target"));
Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString()));
new_event = std::make_unique<QWDeleteFromInventoryEvent>(builder->hash_triggers[json_object["target"].toString()]);
new_event->setInventoryManager(builder->ptr_inventory);
return std::shared_ptr<QWDeleteFromInventoryEvent>{std::move(new_event)};
}
std::shared_ptr<QWChangeLocationEvent> QWEventFactory::createChangeLocEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWChangeLocationEvent> new_event;
qDebug() << " Found QWChangeLocationEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("location"));
Q_ASSERT(builder->hash_locations.contains(json_object["location"].toString()));
new_event = std::make_unique<QWChangeLocationEvent>(builder->hash_locations[json_object["location"].toString()]);
new_event->setScene(builder->ptr_scene);
return std::shared_ptr<QWChangeLocationEvent>{std::move(new_event)};
}
std::shared_ptr<QWChangeTriggerPropertiesEvent> QWEventFactory::createChangeTrProperts(const QJsonObject &json_object)
{
std::unique_ptr<QWChangeTriggerPropertiesEvent> new_event;
qDebug() << " Found QWChangeTriggerPropertiesEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("target"));
Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString()));
new_event = std::make_unique<QWChangeTriggerPropertiesEvent>(builder->hash_triggers[json_object["target"].toString()]);
if (json_object.contains("x") && json_object.contains("y"))
new_event->setParams(json_object["x"].toDouble(), json_object["y"].toDouble(),
json_object.contains("path") ? json_object["path"].toString() : "$no_pic");
else
new_event->setParams(json_object.contains("path") ? json_object["path"].toString() : "$no_pic");
return std::shared_ptr<QWChangeTriggerPropertiesEvent>{std::move(new_event)};
}
std::shared_ptr<QWSwitchEventsEvent> QWEventFactory::createSwitchEventsEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWSwitchEventsEvent> new_event;
qDebug() << " Found QWSwitchEventsEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("target"));
Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString()));
new_event = std::make_unique<QWSwitchEventsEvent>(builder->hash_triggers[json_object["target"].toString()]);
Q_ASSERT(json_object.contains("enable_evs") && json_object.contains("disable_evs"));
// Linking events of enabled state
QJsonArray evs = json_object["enable_evs"].toArray();
QList<std::shared_ptr<QWAbstractEvent>> list_events;
for (const auto obj : evs) {
Q_ASSERT(builder->hash_events.contains(obj.toString()));
list_events.append(builder->hash_events[obj.toString()]);
}
new_event->setEventsOnEnable(list_events);
list_events.clear();
// Linking events of disabled state
evs = json_object["disable_evs"].toArray();
for (const auto obj : evs) {
Q_ASSERT(builder->hash_events.contains(obj.toString()));
list_events.append(builder->hash_events[obj.toString()]);
}
new_event->setEventsOnDisable(list_events);
new_event->init();
return std::shared_ptr<QWSwitchEventsEvent>{std::move(new_event)};
}
std::shared_ptr<QWPickupItemEvent> QWEventFactory::createPickupItEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWPickupItemEvent> new_event;
qDebug() << " Found QWPickupItemEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("target"));
Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString()));
new_event = std::make_unique<QWPickupItemEvent>(builder->hash_triggers[json_object["target"].toString()]);
new_event->setInventoryManager(builder->ptr_inventory);
return std::shared_ptr<QWPickupItemEvent>{std::move(new_event)};
}
std::shared_ptr<QWEndLevelEvent> QWEventFactory::createEndLevelEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWEndLevelEvent> new_event;
qDebug() << " Found QWEndLevelEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("new_level"));
new_event = std::make_unique<QWEndLevelEvent>(json_object["target"].toString());
new_event->setLevelBuilder(builder);
return std::shared_ptr<QWEndLevelEvent>{std::move(new_event)};
}
std::shared_ptr<QWPlaySoundEvent> QWEventFactory::createPlaySoundEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWPlaySoundEvent> new_event;
qDebug() << " Found QWPlaySoundEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("sound"));
new_event = std::make_unique<QWPlaySoundEvent>(json_object["sound"].toString());
new_event->setSoundPlayer(builder->ptr_soundplayer);
return std::shared_ptr<QWPlaySoundEvent>{std::move(new_event)};
}
std::shared_ptr<QWNewGameEvent> QWEventFactory::createNewGameEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWNewGameEvent> new_event;
qDebug() << " Found QWNewGameEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("save_file"));
new_event = std::make_unique<QWNewGameEvent>(json_object["save_file"].toString());
new_event->setLevelBuilder(builder);
return std::shared_ptr<QWNewGameEvent>{std::move(new_event)};
}
std::shared_ptr<QWQuitGameEvent> QWEventFactory::createQuitGameEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWQuitGameEvent> new_event;
qDebug() << " Found QWQuitGameEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("save_game"));
new_event = std::make_unique<QWQuitGameEvent>(json_object["save_game"].toBool());
new_event->setLevelBuilder(builder);
return std::shared_ptr<QWQuitGameEvent>{std::move(new_event)};
}
std::shared_ptr<QWStartDialogueEvent> QWEventFactory::createStartDlgEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWStartDialogueEvent> new_event;
qDebug() << " Found QWStartTextDialogueEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("dialogue_type"));
if (json_object["dialogue_type"].toInt() == 0) {
std::shared_ptr<QWTextDialogue> new_dialogue;
Q_ASSERT(json_object.contains("text"));
QStringList text;
const QJsonArray text_pages = json_object["text"].toArray();
for (auto const &page : text_pages)
text << page.toString();
new_dialogue = std::make_shared<QWTextDialogue>(text);
new_event = std::make_unique<QWStartDialogueEvent>(new_dialogue);
new_event->setDialogueManager(builder->ptr_text_dlg);
}
else {
std::shared_ptr<QWWidgetDialogue> new_dialogue;
Q_ASSERT(json_object.contains("qml_filename"));
new_dialogue = std::make_shared<QWWidgetDialogue>(json_object["qml_filename"].toString());
new_event = std::make_unique<QWStartDialogueEvent>(new_dialogue);
new_event->setDialogueManager(builder->ptr_widget_dlg);
}
return std::shared_ptr<QWStartDialogueEvent>{std::move(new_event)};
}
std::shared_ptr<QWAddTriggerEvent> QWEventFactory::createAddTrEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWAddTriggerEvent> new_event;
qDebug() << " Found QWAddTriggerEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("trigger"));
Q_ASSERT(builder->hash_triggers.contains(json_object["trigger"].toString()));
new_event = std::make_unique<QWAddTriggerEvent>(builder->hash_triggers[json_object["trigger"].toString()]);
Q_ASSERT(json_object.contains("location"));
Q_ASSERT(builder->hash_locations.contains(json_object["location"].toString()));
new_event->setLocation(builder->hash_locations[json_object["location"].toString()]);
return std::shared_ptr<QWAddTriggerEvent>{std::move(new_event)};
}
std::shared_ptr<QWRemoveTriggerEvent> QWEventFactory::createRemoveTrEvent(const QJsonObject &json_object)
{
std::unique_ptr<QWRemoveTriggerEvent> new_event;
qDebug() << " Found QWRemoveTriggerEvent. " << json_object["id"].toString() << ".";
Q_ASSERT(json_object.contains("trigger"));
Q_ASSERT(builder->hash_triggers.contains(json_object["trigger"].toString()));
new_event = std::make_unique<QWRemoveTriggerEvent>(builder->hash_triggers[json_object["trigger"].toString()]);
Q_ASSERT(json_object.contains("location"));
Q_ASSERT(builder->hash_locations.contains(json_object["location"].toString()));
new_event->setLocation(builder->hash_locations[json_object["location"].toString()]);
return std::shared_ptr<QWRemoveTriggerEvent>{std::move(new_event)};
}

48
features/qw_eventfactory.h

@ -0,0 +1,48 @@
#ifndef EVENTFACTORY_H
#define EVENTFACTORY_H
#include <QJsonObject>
#include <QJsonArray>
#include "models/events/qw_abstractevent.h"
#include "models/events/qw_changelocationevent.h"
#include "models/events/qw_switcheventsevent.h"
#include "models/events/qw_deletefrominventoryevent.h"
#include "models/events/qw_pickupitemevent.h"
#include "models/events/qw_endlevelevent.h"
#include "models/events/qw_playsoundevent.h"
#include "models/events/qw_changetriggerpropertiesevent.h"
#include "models/events/qw_newgameevent.h"
#include "models/events/qw_quitgameevent.h"
#include "models/events/qw_startdialogueevent.h"
#include "models/events/qw_addtriggerevent.h"
#include "models/events/qw_removetriggerevent.h"
/* QWEventFactory
* Creates game events of all kinds! */
class QWLevelBuilder;
class QWEventFactory final
{
private:
QWLevelBuilder *builder;
public:
explicit QWEventFactory(QWLevelBuilder *b);
std::shared_ptr<QWDeleteFromInventoryEvent> createDeleteItEvent(const QJsonObject &json_object);
std::shared_ptr<QWChangeLocationEvent> createChangeLocEvent(const QJsonObject &json_object);
std::shared_ptr<QWChangeTriggerPropertiesEvent> createChangeTrProperts(const QJsonObject &json_object);
std::shared_ptr<QWSwitchEventsEvent> createSwitchEventsEvent(const QJsonObject &json_object);
std::shared_ptr<QWPickupItemEvent> createPickupItEvent(const QJsonObject &json_object);
std::shared_ptr<QWEndLevelEvent> createEndLevelEvent(const QJsonObject &json_object);
std::shared_ptr<QWPlaySoundEvent> createPlaySoundEvent(const QJsonObject &json_object);
std::shared_ptr<QWNewGameEvent> createNewGameEvent(const QJsonObject &json_object);
std::shared_ptr<QWQuitGameEvent> createQuitGameEvent(const QJsonObject &json_object);
std::shared_ptr<QWStartDialogueEvent> createStartDlgEvent(const QJsonObject &json_object);
std::shared_ptr<QWAddTriggerEvent> createAddTrEvent(const QJsonObject &json_object);
std::shared_ptr<QWRemoveTriggerEvent> createRemoveTrEvent(const QJsonObject &json_object);
};
#endif // EVENTFACTORY_H

94
features/qw_inventorymanager.cpp

@ -0,0 +1,94 @@
#include "qw_inventorymanager.h"
#include "qw_globalmetadata.h"
#include "view/controls/sceneinventorypanel.h"
#include "view/qw_scene.h"
#include "models/qw_trigger.h"
QWInventoryManager::QWInventoryManager(QWScene *sc) :
ptr_scene(sc),
index_freepan(0)
{
// Loading metadata
metadata.length_wall = QWGlobalMetadata::valueBy("InventoryManager:length_wall").toInt();
metadata.length_cell = QWGlobalMetadata::valueBy("InventoryManager:length_cell").toInt();
metadata.max_amount = QWGlobalMetadata::valueBy("InventoryManager:max_amount").toInt();
metadata.first_wall = QWGlobalMetadata::valueBy("InventoryManager:first_wall").toInt();
metadata.clr_sel = Qt::GlobalColor(QWGlobalMetadata::valueBy("InventoryManager:clr_sel").toInt());
metadata.clr_sth = QWGlobalMetadata::valueBy("InventoryManager:clr_str").toReal();
item_selected_effect = new QGraphicsColorizeEffect();
item_selected_effect->setColor(metadata.clr_sel);
item_selected_effect->setStrength(metadata.clr_sth);
}
void QWInventoryManager::setInventoryPanel(const std::shared_ptr<QGraphicsWidget> &panel) noexcept
{
ptr_panel = panel;
}
int QWInventoryManager::freePanel() const noexcept
{
return index_freepan;
}
void QWInventoryManager::freePanelToRight()
{
++index_freepan;
Q_ASSERT(index_freepan <= metadata.max_amount);
}
void QWInventoryManager::freePanelToLeft()
{
--index_freepan;
Q_ASSERT(index_freepan >= 0);
}
void QWInventoryManager::addInventoryIcon(std::shared_ptr<QWTrigger> &inventory_icon)
{
inventory_icon->setParentItem(ptr_panel.get());
list_inventory_icons.append(inventory_icon);
inventory_icon->setPos(metadata.first_wall
+ ((metadata.length_wall + metadata.length_cell)
* freePanel())
, 0);
freePanelToRight();
}
void QWInventoryManager::removeInventoryIcon(std::shared_ptr<QWTrigger> &inventory_icon)
{
Index panel = metadata.max_amount + 1;
for (Index i = 0; i < list_inventory_icons.size(); ++i)
if (inventory_icon == list_inventory_icons[i])
panel = i;
Q_ASSERT(panel <= metadata.max_amount);
ptr_scene->removeItem(inventory_icon.get());
list_inventory_icons.removeAt(panel);
freePanelToLeft();
reorganizeItems(panel);
}
void QWInventoryManager::reorganizeItems(Index free_panel)
{
// When we remove item from the center we also should carefully move all the right items to the left
for (Index j = free_panel; j < list_inventory_icons.size(); ++j)
{
const std::shared_ptr<QWTrigger> &t = list_inventory_icons.at(j);
t->moveBy(-(metadata.length_cell + metadata.length_wall), 0);
if (j > 0)
list_inventory_icons[j-1] = list_inventory_icons[j];
}
}
void QWInventoryManager::onClicked()
{
for (auto &tr : list_inventory_icons)
if (tr->isUnderMouse()) {
tr->setGraphicsEffect(tr->graphicsEffect() ? nullptr : item_selected_effect);
tr->activate();
} else {
tr->setGraphicsEffect(nullptr);
}
}

67
features/qw_inventorymanager.h

@ -0,0 +1,67 @@
#ifndef INVENTORYMANAGER_H
#define INVENTORYMANAGER_H
#include <memory>
#include <QGraphicsColorizeEffect>
/* QWInventoryManager
* Controls everything related to inventory slots and their items. */
class QGraphicsWidget;
class QWScene;
class QWTrigger;
class QWInventoryManager final : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(QWInventoryManager)
private:
QList<std::shared_ptr<QWTrigger>> list_inventory_icons;
std::shared_ptr<QGraphicsWidget> ptr_panel;
QWScene *ptr_scene;
QRect rect_hidden;
QRect rect_visible;
using Index = QList<std::shared_ptr<QWTrigger>>::size_type;
Index index_freepan;
QGraphicsColorizeEffect *item_selected_effect;
struct metadata
{
// the separator thinkness
int length_wall;
// the cell side
int length_cell;
// the maximum amount of items to hold
int max_amount;
// the left wall of first item slot
int first_wall;
// the color for selected items
QColor clr_sel;
// the color for selected items
qreal clr_sth;
} metadata;
void reorganizeItems(Index i);
public:
explicit QWInventoryManager(QWScene *sc);
void setInventoryPanel(const std::shared_ptr<QGraphicsWidget> &panel) noexcept;
inline int freePanel() const noexcept;
inline void freePanelToRight();
inline void freePanelToLeft();
void addInventoryIcon(std::shared_ptr<QWTrigger> &inventory_icon);
void removeInventoryIcon(std::shared_ptr<QWTrigger> &inventory_icon);
public slots:
void onClicked();
};
#endif // INVENTORYMANAGER_H

423
features/qw_levelbuilder.cpp

@ -0,0 +1,423 @@
#include <QDebug>
#include "gamefeatures.h"
#include "qw_levelbuilder.h"
#include "qw_eventfactory.h"
#include "qw_globalmetadata.h"
#include "view/qw_scene.h"
#include "models/qw_location.h"
#include "models/qw_trigger.h"
QWLevelBuilder::QWLevelBuilder(QObject *parent) :
QObject(parent),
str_current_level(strInitLevel())
{
// Dir for local save files
if (!QDir("save").exists()) {
QDir().mkdir("save");
}
save_dir.setPath("save");
}
template<typename MODEL>
QJsonArray writeEntitesToJsonArray(const QHash<QString, std::shared_ptr<MODEL>> &hash_models)
{
// Writing in active save file all the game elements and their state
QJsonArray json_array;
for (const auto &model : hash_models)
{
QJsonObject model_data;
model->writeToJson(model_data);
json_array.append(model_data);
}
return json_array;
}
void QWLevelBuilder::initMenuLevel()
{
str_current_level = "menu";
QFile file(":/res/menu.json");
Q_ASSERT(file.open(QIODevice::ReadOnly));
const QByteArray json_arr = file.readAll();
file.close();
QJsonObject savefile = QJsonDocument::fromJson(json_arr).object();
init(savefile);
}
void QWLevelBuilder::initSaveProfile(const QString &filename, const QString &profilename)
{
Q_UNUSED(profilename)
// Creating inital save file after beginning the new game:
str_profile_filename = filename;
str_current_level = strInitLevel();
QFile file;
str_profile_filename.remove(".json");
// We move default game description to player's save file
file.setFileName(save_dir.path() + "/" + str_profile_filename + ".json");
qDebug() << save_dir.path() + "/" + str_profile_filename + ".json";
if (!file.exists()) {
qDebug() << "copy file";
QFile::copy(":/res/defaultsave.json", file.fileName());
}
// Now we modify default json file to add the chosen profile name
/*Q_ASSERT(file.open(QIODevice::ReadOnly));
const QByteArray json_arr = file.readAll();
file.close();
QJsonObject savefile = QJsonDocument::fromJson(json_arr).object();
// Pull the saved string from new game dialogue
str_current_profile = profilename;
savefile.insert("save_profile", str_current_profile);
// Write it and resave
Q_ASSERT(file.open(QIODevice::WriteOnly));
file.write(QJsonDocument(savefile).toJson());
file.close();*/
}
void QWLevelBuilder::saveGame(/*QString filename*/)
{
qDebug() << "Save current game!";
QJsonObject savejson;
QJsonArray json_entites;
/* The first Trigger which moves player into its
* needed location where the game starts */
savejson.insert("init", "spawn");
savejson.insert("save_profile", str_current_profile);
qDebug() << "Save triggers!";
json_entites = writeEntitesToJsonArray(hash_triggers);
savejson.insert("triggers", json_entites);
qDebug() << "Save locations!";
json_entites = writeEntitesToJsonArray(hash_locations);
savejson.insert("locations", json_entites);
qDebug() << "Save events!";
json_entites = writeEntitesToJsonArray(hash_events);
// Creating the inital event where player must appear after game loading
QJsonObject init_spawn_data;
QStringList trs;
for (auto & tr : ptr_scene->currentLocation()->triggers())
trs << tr->tag();
QList<std::shared_ptr<QWTrigger>> list_triggers;
init_spawn_data.insert("id", "spawn");
init_spawn_data.insert("type", 0);
init_spawn_data.insert("trs", QJsonArray::fromStringList(trs));
json_entites.append(init_spawn_data);
savejson.insert("events", json_entites);
// - - - //
QFile file(save_dir.dirName() + "/" + str_profile_filename + ".json");
Q_ASSERT(file.open(QIODevice::ReadOnly));
const QByteArray json_arr = file.readAll();
file.close();
QJsonObject savefile = QJsonDocument::fromJson(json_arr).object();
savefile[str_current_level] = savejson;
Q_ASSERT(file.open(QIODevice::WriteOnly));
file.write(QJsonDocument(savejson).toJson());
file.close();
}
void QWLevelBuilder::loadGame(/*QString filename*/)
{
QFile file;
hash_events.clear();
hash_triggers.clear();
hash_locations.clear();
init_trigger.reset();
file.setFileName(save_dir.dirName() + "/" + str_profile_filename + ".json");
file.open(QIODevice::ReadOnly);
const QByteArray json_arr = file.readAll();
file.close();
QJsonObject savefile = QJsonDocument::fromJson(json_arr).object();
str_current_level = savefile["init_level"].toString();
init(savefile);
}
void QWLevelBuilder::initLevel(const QString &lvlname)
{
str_current_level = lvlname;
QFile file(save_dir.dirName() + "/" + str_profile_filename + ".json");
Q_ASSERT(file.open(QIODevice::ReadOnly));
const QByteArray json_arr = file.readAll();
file.close();
emit ptr_scene->signalLeaveMenu();
QJsonObject savefile = QJsonDocument::fromJson(json_arr).object();
init(savefile);
}
void QWLevelBuilder::init(const QJsonObject & savefile)
{
qDebug() << "Init " << str_current_level << " level!";
hash_events.clear();
hash_triggers.clear();
init_trigger.reset();
level = savefile[str_current_level].toObject();
Q_ASSERT(!level.isEmpty());
// Building level from current json
if (level.contains("triggers"))
setupTriggers(level["triggers"].toArray());
if (level.contains("locations"))
setupLocations(level["locations"].toArray());
if (level.contains("events"))
setupEvents(level["events"].toArray());
linkEvents(level["triggers"].toArray());
init_trigger = level.contains("init") ? hash_triggers[level["init"].toString()] : nullptr;
// Start the level
Q_ASSERT(init_trigger);
init_trigger->activate();
}
QString QWLevelBuilder::strInitLevel() noexcept
{
return "start";
}
void QWLevelBuilder::setGameFeatures(std::unique_ptr<GameFeatures> &features)
{
ptr_scene = features->ptr_scene;
ptr_inventory = features->ptr_inventory;
ptr_soundplayer = features->ptr_sound_player;
ptr_text_dlg = features->ptr_text_dlg;
ptr_widget_dlg = features->ptr_widget_dlg;
}
void QWLevelBuilder::linkEvents(const QJsonArray &array)
{
qDebug() << "Link the events to triggers!";
for (const QJsonValue &json_value : array)
{
QJsonObject json_object(json_value.toObject());
if (json_object.contains("evs"))
{
qDebug() << " Trigger " << json_object["id"].toString() << " contains events!";
QJsonArray evs = json_object["evs"].toArray();
for (const QJsonValue event : evs)
{
QString obj = event.toString();
qDebug() << " Inserting " << obj << " to its trigger!";
hash_triggers[json_object["id"].toString()]->addEvents(hash_events[obj]);
qDebug() << " Success!";
}
}
if (json_object.contains("examine_dialogue"))
{
qDebug() << " Trigger " << json_object["id"].toString() << " contains examination dialogue!";
const QString dialogue_tag = json_object["examine_dialogue"].toString();
hash_triggers[json_object["id"].toString()]->setExaminationDialogueEvent(hash_events[dialogue_tag]);
}
}
}
// * * * * * * * * * * * * * * SETUP STUFF * * * * * * * * * * * * * *
//
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
void QWLevelBuilder::setupTriggers(const QJsonArray &array)
{
qDebug() << "Setup the triggers!";
QJsonObject json_object;
for (const QJsonValue &json_value : array)
{
json_object = json_value.toObject();
std::shared_ptr<QWTrigger> new_trigger;
// check if the picture exists!
Q_ASSERT(json_object.contains("id"));
QString mask = json_object.contains("mask") ? json_object["mask"].toString() : json_object["id"].toString();
new_trigger = std::make_shared<QWTrigger>(mask);
new_trigger->setTag(json_object["id"].toString());
qDebug() << "! The trigger with id " << json_object["id"].toString() << " was created.";
// setup the position on the scene
if (json_object.contains("x") && json_object.contains("y")) {
new_trigger->setPos(json_object["x"].toDouble(), json_object["y"].toDouble());
qDebug() << " The trigger was moved to "
<< new_trigger->x() << " " << new_trigger->y();
}
hash_triggers.insert(json_object["id"].toString(), new_trigger);
qDebug() << " The trigger was inserted into its map.\n - - -";
}
}
void QWLevelBuilder::setupEvents(const QJsonArray &array)
{
qDebug() << "Setup the events!";
std::unique_ptr<QWEventFactory> factory = std::make_unique<QWEventFactory>(this);
QJsonObject json_object;
QList<QJsonObject> list_later_events;
for (const QJsonValue &json_value : array)
{
json_object = json_value.toObject();
std::shared_ptr<QWAbstractEvent> new_event;
// check if the id exists!
Q_ASSERT(json_object.contains("id"));
qDebug() << "! The event with id " << json_object["id"].toString() << " is about to create.";
// independent events
Q_ASSERT(json_object.contains("type"));
int type = json_object["type"].toInt();
switch (type)
{
case (EVENT_TYPE::CHANGE_LOCATION):
new_event = factory->createChangeLocEvent(json_object);
break;
case (EVENT_TYPE::DELETE_FROM_INVENTORY):
new_event = factory->createDeleteItEvent(json_object);
break;
case (EVENT_TYPE::PICKUP_ITEM):
new_event = factory->createPickupItEvent(json_object);
break;
case (EVENT_TYPE::END_LEVEL):
new_event = factory->createEndLevelEvent(json_object);
break;
case (EVENT_TYPE::CHANGE_TRIGGER_PROPERTIES):
new_event = factory->createChangeTrProperts(json_object);
break;
case (EVENT_TYPE::NEW_GAME):
new_event = factory->createNewGameEvent(json_object);
break;
case (EVENT_TYPE::QUIT_GAME):
new_event = factory->createQuitGameEvent(json_object);
break;
case (EVENT_TYPE::START_DIALOGUE):
new_event = factory->createStartDlgEvent(json_object);
break;
case (EVENT_TYPE::ADD_TRIGGER):
new_event = factory->createAddTrEvent(json_object);
break;
case (EVENT_TYPE::REMOVE_TRIGGER):
new_event = factory->createRemoveTrEvent(json_object);
break;
default:
list_later_events.append(json_object);
continue;
}
new_event->setTag(json_object["id"].toString());
hash_events.insert(json_object["id"].toString(), new_event);
}
// Some events work with other events, so we need to initialize all
// independent events earlier than these
for (const auto &later_event : list_later_events) {
int type = later_event["type"].toInt();
std::shared_ptr<QWAbstractEvent> new_event;
switch (type)
{
case (EVENT_TYPE::SWITCH_EVENTS): // switch events
new_event = factory->createSwitchEventsEvent(later_event);
break;
default:
Q_ASSERT(false);
continue;
}
new_event->setTag(later_event["id"].toString());
hash_events.insert(later_event["id"].toString(), new_event);
}
}
void QWLevelBuilder::setupLocations(const QJsonArray &array)
{
qDebug() << "Setup the locations!";
QJsonObject json_object;
for (const QJsonValue & json_value : array)
{
json_object = json_value.toObject();
std::shared_ptr<QWLocation> new_location;
Q_ASSERT(json_object.contains("id"));
qDebug() << "! The level with id " << json_object["id"].toString() << " was created.";
new_location = std::make_shared<QWLocation>();
new_location->setTag(json_object["id"].toString());
// check and add the pixmap triggers
Q_ASSERT(json_object.contains("triggers"));
if (json_object.contains("triggers")) {
qDebug() << " Found triggers!";
QJsonArray loc_triggers = json_value["triggers"].toArray();
for (const QJsonValue trg : loc_triggers)
{
qDebug() << " Added the trigger " << trg.toString();
new_location->addTriggers( hash_triggers[trg.toString()] );
}
}
if (json_object.contains("triggers"))
new_location->setDiscovered(json_object["discovered"].toBool());
// check if it has a background
if (json_object.contains("background")) {
qDebug() << " Here is a background.";
QString b = json_value["background"].toString();
new_location->addTriggers(hash_triggers[b]);
qDebug() << " Background was added.";
}
hash_locations.insert(json_object["id"].toString(), new_location);
qDebug() << " The level was inserted into its map.\n - - -";
}
}

76
features/qw_levelbuilder.h

@ -0,0 +1,76 @@
#ifndef LEVELBUILDER_H
#define LEVELBUILDER_H
#include <memory>
#include <functional>
#include <QDir>
#include <QFile>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
/* QWLevelBuilder
* Saves and loads game sessions by managing dependent json files. */
struct GameFeatures;
class QWScene;
class QWAbstractEvent;
class QWAbstractGameDialogue;
class QWInventoryManager;
class QWTextDialogueManager;
class QWWidgetDialogueManager;
class QWSoundPlayer;
class QWTrigger;
class QWLocation;
class QWLevelBuilder final : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(QWLevelBuilder)
friend class QWEventFactory;
private:
QDir save_dir;
QString str_profile_filename;
QString str_current_profile;
QString str_current_level;
QJsonObject level;
QWInventoryManager *ptr_inventory;
QWScene *ptr_scene;
QWSoundPlayer *ptr_soundplayer;
QWTextDialogueManager *ptr_text_dlg;
QWWidgetDialogueManager *ptr_widget_dlg;
QHash<QString, std::shared_ptr<QWAbstractEvent>> hash_events;
QHash<QString, std::shared_ptr<QWTrigger>> hash_triggers;
QHash<QString, std::shared_ptr<QWLocation>> hash_locations;
std::shared_ptr<QWTrigger> init_trigger;
void setupTriggers(const QJsonArray &array);
void setupEvents(const QJsonArray &array);
void linkEvents(const QJsonArray &array);
void setupDialogues(const QJsonArray &array);
void setupLocations(const QJsonArray &array);
void init(const QJsonObject & savefile);
public:
explicit QWLevelBuilder(QObject *parent = nullptr);
void setGameFeatures(std::unique_ptr<GameFeatures> &features);
void initLevel(const QString &lvlname);
void initSaveProfile(const QString &filename, const QString &profilename);
void initMenuLevel();
static QString strInitLevel() noexcept;
public slots:
void saveGame( );
void loadGame(/*int on_id*/);
};
#endif // LEVELBUILDER_H

121
features/qw_soundplayer.cpp

@ -0,0 +1,121 @@
#include "qw_soundplayer.h"
QWSoundPlayer::QWSoundPlayer(QObject *parent) :
QObject(parent),
i_volume(100),
b_muted(false),
player_loop(new QMediaPlayer(this)),
playlist_loop(new QMediaPlaylist(this)),
player_single(new QMediaPlayer(this)),
player_music(new QMediaPlayer(this)),
playlist_music(new QMediaPlaylist(this))
{
// Music
playlist_music->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
playlist_music->setCurrentIndex(0);
player_music->setAudioRole(QAudio::MusicRole);
player_music->setPlaylist(playlist_music);
QObject::connect(this,
SIGNAL(transferSetMuteness(bool)),
player_music,
SLOT(setMuted(bool)));
QObject::connect(this,
SIGNAL(transferAdjustVolume(int)),
player_music,
SLOT(setVolume(int)));
QObject::connect(this,
SIGNAL(playMusic()),
player_music,
SLOT(play()));
// Loop sounds
playlist_loop->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
playlist_loop->setCurrentIndex(0);
player_loop->setAudioRole(QAudio::GameRole);
player_loop->setPlaylist(playlist_loop);
QObject::connect(this,
SIGNAL(transferSetMuteness(bool)),
player_loop,
SLOT(setMuted(bool)));
QObject::connect(this,
SIGNAL(transferAdjustVolume(int)),
player_loop,
SLOT(setVolume(int)));
QObject::connect(this,
SIGNAL(playLoop()),
player_loop,
SLOT(play()));
// Single sounds
player_single->setAudioRole(QAudio::GameRole);
QObject::connect(this,
SIGNAL(transferSetMuteness(bool)),
player_single,
SLOT(setMuted(bool)));
QObject::connect(this,
SIGNAL(transferAdjustVolume(int)),
player_single,
SLOT(setVolume(int)));
QObject::connect(this,
SIGNAL(playSingle()),
player_single,
SLOT(play()));
}
int QWSoundPlayer::addMusic(const QString &path)
{
playlist_music->addMedia(QUrl::fromLocalFile(path));
playlist_music->setCurrentIndex(playlist_music->currentIndex() + 1);
return playlist_music->currentIndex() - 1;
}
bool QWSoundPlayer::isMuted() const noexcept
{
return b_muted;
}
int QWSoundPlayer::volume() const noexcept
{
return i_volume;
}
void QWSoundPlayer::playSound(QMediaContent *sound)
{
player_single->stop();
player_single->setMedia(*sound);
emit playSingle();
}
void QWSoundPlayer::playMusic(const int index)
{
playlist_music->setCurrentIndex(index);
emit playMusic();
}
void QWSoundPlayer::stopMusic()
{
player_music->stop();
}
////////////////////////
void QWSoundPlayer::setMuteness(bool mute) noexcept
{
b_muted = mute;
emit transferSetMuteness(b_muted);
}
void QWSoundPlayer::adjustVolume(int vol) noexcept
{
i_volume = vol;
emit transferAdjustVolume(i_volume);
}
void QWSoundPlayer::onEndLevel() noexcept
{
playlist_music->clear();
playlist_music->setCurrentIndex(0);
}

61
features/qw_soundplayer.h

@ -0,0 +1,61 @@
#ifndef SOUNDPLAYER_H
#define SOUNDPLAYER_H
#include <memory>
#include <QMediaPlayer>
#include <QMediaPlaylist>
/////////////////////////////////////////////////////////////////
//// DOESN'T WORK! Has to be reworked in master-merge 1.2
//// https://trello.com/c/KFUhEbYh/62-reimplement-sound-system
class QWSoundPlayer final : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(QWSoundPlayer)
private:
int i_volume;
bool b_muted;
////////////////////////
////////
//// Background sounds in loop.
QMediaPlayer *player_loop;
QMediaPlaylist *playlist_loop;
////////
//// Sounds which should play once per call.
QMediaPlayer *player_single;
////////
//// Music is music.
QMediaPlayer *player_music;
QMediaPlaylist *playlist_music;
public:
explicit QWSoundPlayer(QObject *parent = nullptr);
int addMusic(const QString &path);
inline bool isMuted() const noexcept;
inline int volume() const noexcept;
void playSound(QMediaContent *sound);
void playMusic(const int index);
void stopMusic();
////////////////////////
public slots:
void setMuteness(bool mute) noexcept;
void adjustVolume(int vol) noexcept;
void onEndLevel() noexcept;
signals:
void transferSetMuteness(bool);
void transferAdjustVolume(int);
void playLoop();
void playSingle();
void playMusic();
};
#endif // SOUNDPLAYER_H

15
features/qw_statemachine.cpp

@ -0,0 +1,15 @@
#include "qw_statemachine.h"
QWStateMachine::QWStateMachine(QObject *parent) :
QStateMachine(parent)
{}
void QWStateMachine::registerState(QString &&str, QState *state) noexcept
{
hash_states.insert(str, state);
}
QState *QWStateMachine::stateByKey(QString &&str) noexcept
{
return hash_states[str];
}

23
features/qw_statemachine.h

@ -0,0 +1,23 @@
#ifndef STATEMACHINE_H
#define STATEMACHINE_H
#include <QStateMachine>
/* QWStateMachine
* Inherited realization of qt state machine for simpler state managment. */
class QWStateMachine final : public QStateMachine
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(QWStateMachine)
private:
QHash<QString, QState*> hash_states;
public:
explicit QWStateMachine(QObject *parent = nullptr);
void registerState(QString &&str, QState *state) noexcept;
QState *stateByKey(QString &&str) noexcept;
};
#endif // STATEMACHINE_H

60
features/qw_textdialoguemanager.cpp

@ -0,0 +1,60 @@
#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(96, 96);
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)
{