mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-26 01:34:40 +00:00
added menu system
This commit is contained in:
parent
dc8c308e3b
commit
56fd4bdaa6
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -29,6 +29,10 @@
|
||||
<source>Crawl</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Please Select level. If level is not availabel please bue it first.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DefaultMenu</name>
|
||||
@ -80,10 +84,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>PreviewControl</name>
|
||||
<message>
|
||||
<source>Back to menu.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -13,6 +13,9 @@ namespace CRAWL {
|
||||
IPreviewScaneWorld::IPreviewScaneWorld(const IWorld* mainWorld) {
|
||||
debug_assert(mainWorld, "The mainWorld world option should be initialized.");
|
||||
_mainWorld = mainWorld;
|
||||
|
||||
setCameraReleativePosition({0, 100, 100});
|
||||
setCameraRotation(QQuaternion::fromEulerAngles(-40,0,0));
|
||||
}
|
||||
|
||||
QString IPreviewScaneWorld::itemTextId() const {
|
||||
@ -50,33 +53,32 @@ bool IPreviewScaneWorld::start(const StartData& config) {
|
||||
|
||||
worldChanged(worldRules()->cbegin());
|
||||
setTargetFps(60);
|
||||
setRunning(true);
|
||||
setVisible(true);
|
||||
startRenderLoop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IPreviewScaneWorld::stop() {
|
||||
setRunning(false);
|
||||
reset();
|
||||
stopRenderLoopWithClearItems();
|
||||
setVisible(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void IPreviewScaneWorld::handleStop() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void IPreviewScaneWorld::handleRotation(double x, double y) {
|
||||
auto normal = (QQuaternion::fromEulerAngles(x, y, 0) * QVector3D{0,0,1}).normalized();
|
||||
auto rotation = cameraRotation() * QQuaternion::fromEulerAngles(x, y, 0);
|
||||
auto normal = (rotation * QVector3D{0,0,1}).normalized();
|
||||
|
||||
setCameraReleativePosition(normal * 100);
|
||||
setCameraRotation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, {0,0,0}));
|
||||
setCameraRotation(rotation);
|
||||
}
|
||||
|
||||
void IPreviewScaneWorld::handleStart() {
|
||||
auto playerObj = dynamic_cast<IItem*>(player());
|
||||
_configuration.setSnakePerks(playerObj->activeItems());
|
||||
emit sigPrepareIsFinished(_configuration);
|
||||
handleStop();
|
||||
stop();
|
||||
}
|
||||
|
||||
void IPreviewScaneWorld::handleSelect(int item, bool isSelected) {
|
||||
@ -97,7 +99,6 @@ void IPreviewScaneWorld::initControl(IControl *control) {
|
||||
auto controlObject = dynamic_cast<PreviewControl*>(control);
|
||||
|
||||
if (controlObject) {
|
||||
connect(controlObject, &PreviewControl::backToMenu, this, &IPreviewScaneWorld::handleStop);
|
||||
connect(controlObject, &PreviewControl::mousePositionChanged, this, &IPreviewScaneWorld::handleRotation);
|
||||
connect(controlObject, &PreviewControl::start, this, &IPreviewScaneWorld::handleStart);
|
||||
connect(controlObject, &PreviewControl::select, this, &IPreviewScaneWorld::handleSelect);
|
||||
|
@ -50,7 +50,6 @@ signals:
|
||||
|
||||
private slots:
|
||||
|
||||
void handleStop();
|
||||
void handleRotation(double x, double y);
|
||||
void handleStart();
|
||||
void handleSelect(int item, bool isSelected);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "diff.h"
|
||||
#include "eventserver.h"
|
||||
#include "player.h"
|
||||
#include <QtConcurrent>
|
||||
|
||||
namespace CRAWL {
|
||||
|
||||
@ -37,6 +38,7 @@ IWorld::IWorld() {
|
||||
}
|
||||
|
||||
IWorld::~IWorld() {
|
||||
disconnect();
|
||||
reset();
|
||||
delete _eventServer;
|
||||
}
|
||||
@ -62,11 +64,6 @@ IControl *IWorld::initUserInterface() const {
|
||||
|
||||
void IWorld::render(unsigned int tbfMsec) {
|
||||
|
||||
if (!_running) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
return;
|
||||
}
|
||||
|
||||
_ItemsMutex.lock();
|
||||
QList<int> toRemove;
|
||||
for (auto i = _items.begin(); i != _items.end(); ++i) {
|
||||
@ -103,18 +100,27 @@ void IWorld::initControl(IControl *control) {
|
||||
|
||||
bool IWorld::start(const StartData& config) {
|
||||
|
||||
auto player = dynamic_cast<Player*>(userInterface());
|
||||
if (!player) {
|
||||
QuasarAppUtils::Params::log("Failed to start world. T userIterface control should be children class of the Palyer class",
|
||||
QuasarAppUtils::Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
setWorldStatus(WorldStatus::Game);
|
||||
backgroundAI()->stopAI();
|
||||
setPlayer(initPlayer(config.snakeType()));
|
||||
|
||||
userInterface()->setUserData(config.player());
|
||||
player->setUserData(config.player());
|
||||
|
||||
worldChanged(worldRules()->cbegin());
|
||||
setTargetFps(60);
|
||||
setRunning(true);
|
||||
_eventServer->start();
|
||||
setVisible(true);
|
||||
|
||||
startRenderLoop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -150,9 +156,12 @@ IWorldItem *IWorld::generate(const QString &objectType) const {
|
||||
}
|
||||
|
||||
bool IWorld::stop() {
|
||||
setRunning(false);
|
||||
setVisible(false);
|
||||
_eventServer->stop();
|
||||
|
||||
stopRenderLoopWithClearItems();
|
||||
setVisible(false);
|
||||
|
||||
emit sigGameFinished();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -167,7 +176,6 @@ IWorldItem *IWorld::getItem(int id) const {
|
||||
}
|
||||
|
||||
void IWorld::clearItems() {
|
||||
IWorld::stop();
|
||||
|
||||
while (_items.cbegin() != _items.cend()) {
|
||||
removeItem(*_items.cbegin());
|
||||
@ -242,6 +250,8 @@ void IWorld::removeItem(IWorldItem* item, QList<int> *removedObjectsList) {
|
||||
|
||||
void IWorld::reset() {
|
||||
|
||||
stop();
|
||||
|
||||
if (_player) {
|
||||
_player = nullptr;
|
||||
}
|
||||
@ -261,7 +271,6 @@ void IWorld::reset() {
|
||||
_backgroundAI = nullptr;
|
||||
}
|
||||
|
||||
clearItems();
|
||||
setHdr("");
|
||||
|
||||
}
|
||||
@ -317,6 +326,44 @@ void IWorld::removeAnyItemFromGroup(const QString &group,
|
||||
removeItem(anyObjectId, removedObjectsList);
|
||||
}
|
||||
|
||||
void IWorld::startRenderLoop() {
|
||||
if (isRendering())
|
||||
return;
|
||||
|
||||
_renderLoop = true;
|
||||
_renderLoopFuture = QtConcurrent::run([this](){renderLoop();});
|
||||
}
|
||||
|
||||
void IWorld::stopRenderLoopWithClearItems() {
|
||||
stopRenderLoop();
|
||||
clearItems();
|
||||
}
|
||||
|
||||
void IWorld::stopRenderLoop() {
|
||||
_renderLoop = false;
|
||||
_renderLoopFuture.waitForFinished();
|
||||
}
|
||||
|
||||
bool IWorld::isRendering() const {
|
||||
return _renderLoopFuture.isRunning();
|
||||
}
|
||||
|
||||
void IWorld::renderLoop() {
|
||||
|
||||
while (_renderLoop) {
|
||||
|
||||
quint64 currentTime = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
if (!_oldTimeRender) {
|
||||
_oldTimeRender = currentTime;
|
||||
continue;
|
||||
}
|
||||
|
||||
render(currentTime - _oldTimeRender);
|
||||
_oldTimeRender = currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
const WorldRule *IWorld::worldRules() {
|
||||
|
||||
if (!_worldRules)
|
||||
@ -334,16 +381,8 @@ void IWorld::setVisible(bool visible) {
|
||||
emit visibleChanged();
|
||||
}
|
||||
|
||||
void IWorld::playerIsDead(PlayableObject *) const {
|
||||
emit sigGameFinished();
|
||||
}
|
||||
|
||||
bool IWorld::running() const {
|
||||
return _running;
|
||||
}
|
||||
|
||||
void IWorld::setRunning(bool newRunning) {
|
||||
_running = newRunning;
|
||||
void IWorld::playerIsDead(PlayableObject *) {
|
||||
stop();
|
||||
}
|
||||
|
||||
int IWorld::targetFps() const {
|
||||
@ -402,10 +441,10 @@ IAI *IWorld::backgroundAI() {
|
||||
return _backgroundAI;
|
||||
}
|
||||
|
||||
Player *IWorld::userInterface() {
|
||||
IControl *IWorld::userInterface() {
|
||||
|
||||
if (!_userInterface) {
|
||||
_userInterface = dynamic_cast<Player*>(initUserInterface());
|
||||
_userInterface = initUserInterface();
|
||||
initControl(_userInterface);
|
||||
}
|
||||
|
||||
@ -486,20 +525,11 @@ void IWorld::runAsBackGround() {
|
||||
setTargetFps(30);
|
||||
}
|
||||
|
||||
QObject *IWorld::getMenu() const {
|
||||
return _menu;
|
||||
QObject *IWorld::getMenu() {
|
||||
return userInterface();
|
||||
}
|
||||
|
||||
void IWorld::setMenu(QObject *newMenu) {
|
||||
if (_menu == newMenu)
|
||||
return;
|
||||
|
||||
_menu = newMenu;
|
||||
emit menuChanged();
|
||||
}
|
||||
|
||||
bool IWorld::visible() const
|
||||
{
|
||||
bool IWorld::visible() const {
|
||||
return _visible;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "playableobject.h"
|
||||
#include "startdata.h"
|
||||
|
||||
#include <QFuture>
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QMultiHash>
|
||||
@ -67,11 +68,10 @@ class CRAWL_EXPORT IWorld : public QObject, public IRender, public IItem
|
||||
|
||||
/**
|
||||
* @brief menu This propertye contains user interface model that initialised on the IWorld::userInterface method. For get more information see the IContol class.
|
||||
* @see IWorld::setMenu
|
||||
* @see IWorld::getMenu
|
||||
* @see IWorld::userInterface
|
||||
*/
|
||||
Q_PROPERTY(QObject * menu READ getMenu WRITE setMenu NOTIFY menuChanged)
|
||||
Q_PROPERTY(QObject * menu READ getMenu NOTIFY menuChanged)
|
||||
Q_PROPERTY(QString hdr READ hdr NOTIFY hdrChanged)
|
||||
Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
|
||||
|
||||
@ -187,7 +187,7 @@ public:
|
||||
* @return pointe to requaried object.
|
||||
* @note if you want to get ovject in the render function of another ItemWorld object then use the IWorldItem::getItem method.
|
||||
*/
|
||||
IWorldItem *getItem(int id) const;
|
||||
Q_INVOKABLE IWorldItem *getItem(int id) const;
|
||||
|
||||
/**
|
||||
* @brief cameraReleativePosition return a releative of player camera position.
|
||||
@ -199,7 +199,7 @@ public:
|
||||
* @brief userInterface This method return pointer to userinterface.
|
||||
* @return pointer to user interface
|
||||
*/
|
||||
Player *userInterface();
|
||||
IControl *userInterface();
|
||||
|
||||
/**
|
||||
* @brief wordlStatus This method return current world status.
|
||||
@ -246,19 +246,10 @@ public:
|
||||
/**
|
||||
* @brief menu This method return current pointer to the user interface of this world.
|
||||
* @return pointer of the user Interface of this world.
|
||||
* @see IWorld::setMenu
|
||||
* @see IWorld::menu
|
||||
* @see IWorld::userInterface
|
||||
*/
|
||||
QObject *getMenu() const;
|
||||
/**
|
||||
* @brief setMenu This method sets new user interface object fot this world.
|
||||
* @param newMenu This is new object of user interfavce of this world.
|
||||
* @see IWorld::getMenu
|
||||
* @see IWorld::menu
|
||||
* @see IWorld::userInterface
|
||||
*/
|
||||
void setMenu(QObject *newMenu);
|
||||
QObject *getMenu();
|
||||
|
||||
/**
|
||||
* @brief reset This method reset all world objects.
|
||||
@ -429,18 +420,6 @@ protected:
|
||||
*/
|
||||
void updateWorld();
|
||||
|
||||
/**
|
||||
* @brief running This varibale check in render function if the running is true then render loop are working correctly
|
||||
* @return status of the render function
|
||||
*/
|
||||
bool running() const;
|
||||
|
||||
/**
|
||||
* @brief setRunning This method sets runnign render function status.
|
||||
* @param newRunning new status of the render function
|
||||
*/
|
||||
void setRunning(bool newRunning);
|
||||
|
||||
/**
|
||||
* @brief worldRules This method return world cure map.
|
||||
* @return world rule map.
|
||||
@ -456,7 +435,35 @@ protected:
|
||||
/**
|
||||
* @brief playerIsDead This method will be invoked when player object get signal dead.
|
||||
*/
|
||||
virtual void playerIsDead(PlayableObject*) const;
|
||||
virtual void playerIsDead(PlayableObject*);
|
||||
|
||||
/**
|
||||
* @brief isRendering This method erturn true if the render loop is working else false.
|
||||
* @return true if the render loop is working else false.
|
||||
* @see IWorld::stopRenderLoop
|
||||
* @see IWorld::startRenderLoop
|
||||
*/
|
||||
bool isRendering() const;
|
||||
|
||||
/**
|
||||
* @brief stopRenderLoop This method stop render loop in engine.
|
||||
* @see IWorld::isRendering
|
||||
* @see IWorld::startRenderLoop
|
||||
*/
|
||||
void stopRenderLoop();
|
||||
|
||||
/**
|
||||
* @brief startRenderLoop This method start render loop in engine.
|
||||
* @see IWorld::stopRenderLoop
|
||||
* @see IWorld::isRendering
|
||||
*/
|
||||
void startRenderLoop();
|
||||
|
||||
/**
|
||||
* @brief stopRenderLoopWithClearItems This method stoped render loop and clear all created items.
|
||||
* @see IWorld::stopRenderLoop
|
||||
*/
|
||||
void stopRenderLoopWithClearItems();
|
||||
|
||||
protected slots:
|
||||
virtual void onIntersects(const IWorldItem * trigger, QList<const IWorldItem *> list);
|
||||
@ -476,7 +483,6 @@ private slots:
|
||||
void handleStop();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief clearItems This method remove all created items from world.
|
||||
*/
|
||||
@ -536,6 +542,9 @@ private:
|
||||
void removeAnyItemFromGroup(const QString &group,
|
||||
QList<int>* removedObjectsList = nullptr);
|
||||
|
||||
void renderLoop();
|
||||
QFuture<void> _renderLoopFuture;
|
||||
|
||||
EventServer * _eventServer = nullptr;
|
||||
|
||||
QHash<int, IWorldItem*> _items;
|
||||
@ -553,15 +562,16 @@ private:
|
||||
|
||||
PlayableObject *_player = nullptr;
|
||||
IAI *_backgroundAI = nullptr;
|
||||
Player *_userInterface = nullptr;
|
||||
QObject *_menu = nullptr;
|
||||
IControl *_userInterface = nullptr;
|
||||
|
||||
int _worldStatus = 0;
|
||||
QHash<QString, std::function<IWorldItem*()>> _registeredTypes;
|
||||
|
||||
int _targetFps = 60;
|
||||
bool _running = false;
|
||||
quint64 _oldTimeRender = 0;
|
||||
|
||||
bool _visible = true;
|
||||
bool _renderLoop = false;
|
||||
|
||||
// testing
|
||||
friend ClastersTest;
|
||||
|
@ -23,10 +23,6 @@ public:
|
||||
QString initQmlView() const override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief backToMenu Emit when user click the return to main menu button.
|
||||
*/
|
||||
void backToMenu();
|
||||
|
||||
/**
|
||||
* @brief start emited when user click start button from the preview menu.
|
||||
|
@ -22,6 +22,15 @@ ApplicationWindow {
|
||||
|
||||
Metrix {id: metrix}
|
||||
|
||||
Label {
|
||||
anchors.fill: parent
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
font.pixelSize: 25
|
||||
wrapMode: Text.WordWrap
|
||||
text: qsTr("Please Select level. If level is not availabel please bue it first.")
|
||||
}
|
||||
|
||||
Scene {
|
||||
id: scane;
|
||||
worldModel: (model)? model.world : null;
|
||||
@ -34,10 +43,83 @@ ApplicationWindow {
|
||||
anchors.fill: parent;
|
||||
}
|
||||
|
||||
MainMenu {
|
||||
ToolButton {
|
||||
text: "👾"
|
||||
font.pixelSize: 35
|
||||
|
||||
onClicked: {
|
||||
mainMenuPopUp.open()
|
||||
}
|
||||
visible: !mainMenuPopUp.visible
|
||||
}
|
||||
|
||||
Drawer {
|
||||
id: mainMenuPopUp
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
|
||||
height: parent.height
|
||||
width: parent.width / 3
|
||||
|
||||
MainMenu {
|
||||
id: mainMenu
|
||||
model: (mainWindow.model)? mainWindow.model.menu: null;
|
||||
anchors.fill: parent;
|
||||
}
|
||||
}
|
||||
|
||||
PagePopUp {
|
||||
id: settingsPopUp
|
||||
|
||||
source: SettingsView {
|
||||
id: settingsView
|
||||
model: mainMenu.model ? mainMenu.model.userSettingsModel: null
|
||||
}
|
||||
|
||||
standardButtons: Dialog.Save | Dialog.Cancel | Dialog.RestoreDefaults
|
||||
modal: false;
|
||||
width: parent.width * 0.8
|
||||
height: parent.height * 0.8;
|
||||
|
||||
onAccepted: {
|
||||
settingsView.save();
|
||||
}
|
||||
|
||||
onReset: {
|
||||
settingsView.reset();
|
||||
}
|
||||
|
||||
onOpened: {
|
||||
settingsView.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PagePopUp {
|
||||
id: storePopUp
|
||||
source: StoreView {
|
||||
id: view
|
||||
model: mainMenu.model ? mainMenu.model.storeView: null
|
||||
|
||||
}
|
||||
|
||||
modal: false;
|
||||
width: parent.width * 0.8
|
||||
height: parent.height * 0.8;
|
||||
|
||||
}
|
||||
|
||||
PagePopUp {
|
||||
id: selectLvl
|
||||
source: SelectLevelView {
|
||||
id: selectLvlView
|
||||
model: mainMenu.model ? mainMenu.model.selectLevelModle: null
|
||||
|
||||
}
|
||||
|
||||
modal: false;
|
||||
width: parent.width * 0.8
|
||||
height: parent.height * 0.8;
|
||||
|
||||
model: (mainWindow.model)? mainWindow.model.menu: null;
|
||||
anchors.fill: parent;
|
||||
}
|
||||
|
||||
NotificationServiceView {
|
||||
|
@ -29,8 +29,8 @@ Item {
|
||||
anchors.bottomMargin: 0
|
||||
anchors.topMargin: 0
|
||||
|
||||
columns: 3
|
||||
rows: 2
|
||||
columns: 1
|
||||
rows: 10
|
||||
|
||||
|
||||
transformOrigin: Item.Center
|
||||
@ -74,59 +74,6 @@ Item {
|
||||
|
||||
}
|
||||
|
||||
PagePopUp {
|
||||
id: settingsPopUp
|
||||
source: SettingsView {
|
||||
id: settingsView
|
||||
model: root.model ? root.model.userSettingsModel: null
|
||||
}
|
||||
|
||||
standardButtons: Dialog.Save | Dialog.Cancel | Dialog.RestoreDefaults
|
||||
modal: false;
|
||||
width: parent.width * 0.8
|
||||
height: parent.height * 0.8;
|
||||
|
||||
onAccepted: {
|
||||
settingsView.save();
|
||||
}
|
||||
|
||||
onReset: {
|
||||
settingsView.reset();
|
||||
}
|
||||
|
||||
onOpened: {
|
||||
settingsView.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PagePopUp {
|
||||
id: storePopUp
|
||||
source: StoreView {
|
||||
id: view
|
||||
model: root.model ? root.model.storeView: null
|
||||
|
||||
}
|
||||
|
||||
modal: false;
|
||||
width: parent.width * 0.8
|
||||
height: parent.height * 0.8;
|
||||
|
||||
}
|
||||
|
||||
PagePopUp {
|
||||
id: selectLvl
|
||||
source: SelectLevelView {
|
||||
id: selectLvlView
|
||||
model: root.model ? root.model.selectLevelModle: null
|
||||
|
||||
}
|
||||
|
||||
modal: false;
|
||||
width: parent.width * 0.8
|
||||
height: parent.height * 0.8;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,12 +13,12 @@ import QtQuick.Layouts
|
||||
Button {
|
||||
id: exit
|
||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
||||
font.pixelSize: height * 0.1
|
||||
font.pixelSize: height * 0.2
|
||||
display: AbstractButton.TextBesideIcon
|
||||
spacing: 4
|
||||
focusPolicy: Qt.StrongFocus
|
||||
|
||||
Layout.preferredHeight: parent.height / (parent.rows + 1)
|
||||
Layout.preferredWidth: parent.width / (parent.columns + 1)
|
||||
Layout.preferredWidth: parent.width / (parent.columns + 0.5)
|
||||
|
||||
}
|
||||
|
@ -23,10 +23,6 @@ AbstractMenuView {
|
||||
Layout.columnSpan: 4
|
||||
Layout.rowSpan: 1
|
||||
|
||||
onClicked: {
|
||||
model.userTap()
|
||||
}
|
||||
|
||||
|
||||
property bool track: false
|
||||
property real oldX: 0
|
||||
@ -65,20 +61,11 @@ AbstractMenuView {
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Back to menu.")
|
||||
onClicked: {
|
||||
if (model) {
|
||||
model.backToMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Start")
|
||||
onClicked: {
|
||||
if (model) {
|
||||
model.backToMenu()
|
||||
model.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ View3D {
|
||||
return;
|
||||
}
|
||||
|
||||
const objModel = model.getGameObject(cppObjId);
|
||||
const objModel = worldModel.getItem(cppObjId);
|
||||
|
||||
if (!objModel) {
|
||||
console.log("object model not found");
|
||||
console.log("model of the crawl object is not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,15 +32,16 @@ Engine::Engine(QObject *parent): QObject(parent) {
|
||||
}
|
||||
|
||||
Engine::~Engine() {
|
||||
stopRenderLoop();
|
||||
delete _menu;
|
||||
delete _currentUser;
|
||||
|
||||
|
||||
for (auto it = _availableLvls.begin(); it != _availableLvls.end(); ++it) {
|
||||
delete it.value();
|
||||
}
|
||||
|
||||
_availableLvls.clear();
|
||||
|
||||
delete _menu;
|
||||
delete _currentUser;
|
||||
}
|
||||
|
||||
QObject *Engine::scane() {
|
||||
@ -86,9 +87,6 @@ void Engine::setLevel(ILevel *world) {
|
||||
return;
|
||||
}
|
||||
|
||||
startRenderLoop();
|
||||
_currentLevel->world()->runAsBackGround();
|
||||
|
||||
connect(_currentLevel->previewScane(), &IPreviewScaneWorld::sigPrepareIsFinished,
|
||||
this, &Engine::start);
|
||||
|
||||
@ -136,11 +134,6 @@ void Engine::stop() const {
|
||||
if (!_currentLevel)
|
||||
return;
|
||||
|
||||
|
||||
if (!_currentLevel->world()->stop()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_currentLevel->previewScane()->start(_currentLevel->previewScane()->configuration());
|
||||
}
|
||||
|
||||
@ -179,49 +172,6 @@ ILevel *Engine::getLastLevel() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QObject *Engine::getGameObject(int id) const {
|
||||
if (!_currentLevel)
|
||||
return nullptr;
|
||||
|
||||
return _currentLevel->world()->getItem(id);
|
||||
}
|
||||
|
||||
void Engine::startRenderLoop() {
|
||||
if (isRendering())
|
||||
return;
|
||||
|
||||
_renderLoop = true;
|
||||
_renderLoopFuture = QtConcurrent::run([this](){renderLoop();});
|
||||
}
|
||||
|
||||
void Engine::stopRenderLoop() {
|
||||
_renderLoop = false;
|
||||
_renderLoopFuture.waitForFinished();
|
||||
}
|
||||
|
||||
bool Engine::isRendering() const {
|
||||
return _renderLoopFuture.isRunning();
|
||||
}
|
||||
|
||||
void Engine::renderLoop() {
|
||||
|
||||
if (!_currentLevel)
|
||||
return;
|
||||
|
||||
while (_renderLoop) {
|
||||
|
||||
quint64 currentTime = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
if (!_oldTimeRender) {
|
||||
_oldTimeRender = currentTime;
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentLevel->world()->render(currentTime - _oldTimeRender);
|
||||
_oldTimeRender = currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
QObject *Engine::menu() const {
|
||||
return _menu;
|
||||
}
|
||||
|
@ -77,29 +77,6 @@ public:
|
||||
*/
|
||||
QObject* world() const;
|
||||
|
||||
/**
|
||||
* @brief getGameObject This method using in qml for getting main model of the gui objects.
|
||||
* @param id This is id of the gui object.
|
||||
* @return pointer to game object model
|
||||
*/
|
||||
Q_INVOKABLE QObject *getGameObject(int id) const;
|
||||
|
||||
/**
|
||||
* @brief startRenderLoop This method start render loop in engine.
|
||||
*/
|
||||
void startRenderLoop();
|
||||
|
||||
/**
|
||||
* @brief stopRenderLoop This method stop render loop in engine.
|
||||
*/
|
||||
void stopRenderLoop();
|
||||
|
||||
/**
|
||||
* @brief isRendering This method erturn true if the render loop is working else false.
|
||||
* @return true if the render loop is working else false.
|
||||
*/
|
||||
bool isRendering() const;
|
||||
|
||||
/**
|
||||
* @brief currentUser This method return pointer too current user.
|
||||
* @return pointer too current user.
|
||||
@ -197,13 +174,8 @@ private:
|
||||
|
||||
MainMenuModel *_menu = nullptr;
|
||||
|
||||
quint64 _oldTimeRender = 0;
|
||||
|
||||
User *_currentUser = nullptr;
|
||||
Store *_store = nullptr;
|
||||
|
||||
QFuture<void> _renderLoopFuture;
|
||||
bool _renderLoop = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,9 +8,13 @@
|
||||
#include "abstractlevel.h"
|
||||
#include "abslvlworld.h"
|
||||
|
||||
#include <absnest.h>
|
||||
|
||||
AbstractLevel::AbstractLevel() {
|
||||
initAbstractLvlResources();
|
||||
|
||||
setWorld(new AbstractLvl::AbsLvlWorld());
|
||||
auto world = new AbstractLvl::AbsLvlWorld();
|
||||
setWorld(world);
|
||||
setPreviewScane(new AbstractLvl::AbsNest(world));
|
||||
}
|
||||
|
||||
|
35
src/CrawlAbstractLvl/private/absnest.cpp
Normal file
35
src/CrawlAbstractLvl/private/absnest.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "absnest.h"
|
||||
#include "obstacleblue.h"
|
||||
|
||||
#include <Crawl/defaultlight.h>
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
AbsNest::AbsNest(IWorld * mainWorld): CRAWL::IPreviewScaneWorld(mainWorld) {
|
||||
|
||||
}
|
||||
|
||||
CRAWL::WorldRule *AbsNest::initWorldRules() {
|
||||
return new CRAWL::WorldRule {
|
||||
{0,
|
||||
{
|
||||
{registerObject<ObstacleBlue>(), 1},
|
||||
{registerObject<CRAWL::DefaultLight>(), 1}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
QString AbsNest::initHdrBackGround() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
32
src/CrawlAbstractLvl/private/absnest.h
Normal file
32
src/CrawlAbstractLvl/private/absnest.h
Normal file
@ -0,0 +1,32 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
|
||||
#ifndef ABSNEST_H
|
||||
#define ABSNEST_H
|
||||
#include <Crawl/ipreviewscaneworld.h>
|
||||
|
||||
|
||||
namespace AbstractLvl {
|
||||
|
||||
/**
|
||||
* @brief The AbsNest class Abstrcat nest level
|
||||
*/
|
||||
class AbsNest: public CRAWL::IPreviewScaneWorld
|
||||
{
|
||||
public:
|
||||
AbsNest(IWorld *mainWorld);
|
||||
|
||||
// IWorld interface
|
||||
public:
|
||||
CRAWL::WorldRule *initWorldRules() override;
|
||||
QString initHdrBackGround() const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // ABSNEST_H
|
@ -8,9 +8,14 @@
|
||||
|
||||
#include "jungle.h"
|
||||
#include "world.h"
|
||||
#include "nest.h"
|
||||
|
||||
Jungle::Jungle() {
|
||||
initJungleLvlResources();
|
||||
|
||||
setWorld(new JungleLvl::World());
|
||||
auto world = new JungleLvl::World();
|
||||
|
||||
setWorld(world);
|
||||
|
||||
setPreviewScane(new JungleLvl::Nest(world));
|
||||
}
|
||||
|
40
src/JungleLvl/private/nest.cpp
Normal file
40
src/JungleLvl/private/nest.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "absaluteplate.h"
|
||||
#include "grees.h"
|
||||
#include "ground.h"
|
||||
#include "nest.h"
|
||||
|
||||
#include <Crawl/day.h>
|
||||
#include <Crawl/moon.h>
|
||||
#include <Crawl/sun.h>
|
||||
|
||||
namespace JungleLvl {
|
||||
|
||||
Nest::Nest(IWorld *mainWorld): CRAWL::IPreviewScaneWorld(mainWorld) {
|
||||
|
||||
}
|
||||
|
||||
CRAWL::WorldRule *Nest::initWorldRules() {
|
||||
using Day = CRAWL::Day<CRAWL::Sun, CRAWL::Moon>;
|
||||
|
||||
return new CRAWL::WorldRule {
|
||||
{0, {
|
||||
{registerObject<AbsalutePlate>(), 1},
|
||||
{registerObject<Day>(), 1},
|
||||
{registerObject<Ground>(), 1},
|
||||
{registerObject<Grees>(), 500}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
QString Nest::initHdrBackGround() const {
|
||||
return "";
|
||||
}
|
||||
}
|
29
src/JungleLvl/private/nest.h
Normal file
29
src/JungleLvl/private/nest.h
Normal file
@ -0,0 +1,29 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#ifndef NEST_H
|
||||
#define NEST_H
|
||||
#include <Crawl/ipreviewscaneworld.h>
|
||||
|
||||
namespace JungleLvl {
|
||||
|
||||
/**
|
||||
* @brief The Nest class
|
||||
*/
|
||||
class Nest: public CRAWL::IPreviewScaneWorld
|
||||
{
|
||||
public:
|
||||
Nest(IWorld *mainWorld);
|
||||
|
||||
// IWorld interface
|
||||
public:
|
||||
CRAWL::WorldRule *initWorldRules() override;
|
||||
QString initHdrBackGround() const override;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // NEST_H
|
Loading…
x
Reference in New Issue
Block a user