diff options
author | Tamas Martinec <tamas.martinec@symbio.com> | 2021-02-25 12:14:02 +0200 |
---|---|---|
committer | Tamas Martinec <tamas.martinec@symbio.com> | 2021-03-08 11:35:00 +0200 |
commit | bd1f00bb67c1e4a10774fdfdf6f0a0fd513ee50d (patch) | |
tree | 42c6796be97143607070318a299e95d5d16de470 /examples | |
parent | be635ace5186e8ea4db160a48cac123af84fdcd4 (diff) |
QtScxml: Improve sub-attaq example
- Added information about how to start and play the game
- Improved the english in messages and comments
Pick-to: 6.1
Task-number: QTBUG-89834
Change-Id: I3bb1d8667c58a601d8d660316e2e29805e1e0bca
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Diffstat (limited to 'examples')
5 files changed, 24 insertions, 17 deletions
diff --git a/examples/statemachine/animation/sub-attaq/graphicsscene.cpp b/examples/statemachine/animation/sub-attaq/graphicsscene.cpp index 5248ed9..d8c068a 100644 --- a/examples/statemachine/animation/sub-attaq/graphicsscene.cpp +++ b/examples/statemachine/animation/sub-attaq/graphicsscene.cpp @@ -84,17 +84,21 @@ GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode, QOb surfaceItem->setPos(0, sealLevel() - surfaceItem->boundingRect().height() / 2); addItem(surfaceItem); - //The item that display score and level + //The item that displays score and level progressItem = new ProgressItem(backgroundItem); textInformationItem = new TextInformationItem(backgroundItem); - textInformationItem->hide(); + + textInformationItem->setMessage(QString("Select new game from the menu or press Ctrl+N to start!<br/>Press left or right to move the ship and up to drop bombs."), false); + textInformationItem->setPos(backgroundItem->boundingRect().center().x() - textInformationItem->boundingRect().size().width() / 2, + backgroundItem->boundingRect().height() * 3 / 4); + //We create the boat addItem(boat); boat->setPos(this->width()/2, sealLevel() - boat->size().height()); boat->hide(); - //parse the xml that contain all data of the game + //Parse the xml that contains all data of the game QXmlStreamReader reader; QFile file(":data.xml"); file.open(QIODevice::ReadOnly); @@ -177,19 +181,19 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction) //Final state QFinalState *finalState = new QFinalState(machine); - //Animation when the player enter in the game + //Animation when the player enters the game QAnimationState *lettersMovingState = new QAnimationState(machine); lettersMovingState->setAnimation(lettersGroupMoving); - //Animation when the welcome screen disappear + //Animation when the welcome screen disappears QAnimationState *lettersFadingState = new QAnimationState(machine); lettersFadingState->setAnimation(lettersGroupFading); - //if new game then we fade out the welcome screen and start playing + //if it is a new game then we fade out the welcome screen and start playing lettersMovingState->addTransition(newAction, &QAction::triggered, lettersFadingState); lettersFadingState->addTransition(lettersFadingState, &QAnimationState::animationFinished, gameState); - //New Game is triggered then player start playing + //New Game is triggered then player starts playing gameState->addTransition(newAction, &QAction::triggered, gameState); //Wanna quit, then connect to CTRL+Q diff --git a/examples/statemachine/animation/sub-attaq/states.cpp b/examples/statemachine/animation/sub-attaq/states.cpp index c7e2738..3142f2c 100644 --- a/examples/statemachine/animation/sub-attaq/states.cpp +++ b/examples/statemachine/animation/sub-attaq/states.cpp @@ -156,6 +156,7 @@ void PlayState::onEntry(QEvent *) //We lost we should reach the final state lostState->addTransition(lostState, &QState::finished, finalState); + scene->textInformationItem->hide(); machine->start(); } @@ -224,7 +225,7 @@ LostState::LostState(GraphicsScene *scene, PlayState *game, QState *parent) : QS void LostState::onEntry(QEvent *) { //The message to display - QString message = QString("You lose on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); + QString message = QString("You lost on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); //We set the level back to 0 game->currentLevel = 0; @@ -258,11 +259,11 @@ void WinState::onEntry(QEvent *) QString message; if (scene->levelsData.size() - 1 != game->currentLevel) { - message = QString("You win the level %1. Your score is %2.\nPress Space to continue.").arg(game->currentLevel+1).arg(game->score); + message = QString("You won level %1. Your score is %2.\nPress Space to continue.").arg(game->currentLevel+1).arg(game->score); //We increment the level number game->currentLevel++; } else { - message = QString("You finish the game on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); + message = QString("You finished the game on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); //We set the level back to 0 game->currentLevel = 0; //We set the score back to 0 diff --git a/examples/statemachine/animation/sub-attaq/states.h b/examples/statemachine/animation/sub-attaq/states.h index b3651e1..e891c7e 100644 --- a/examples/statemachine/animation/sub-attaq/states.h +++ b/examples/statemachine/animation/sub-attaq/states.h @@ -142,7 +142,7 @@ public: private: }; -//These transtion is used to update the score +//This transition is used to update the score class UpdateScoreTransition : public QSignalTransition { public: @@ -154,7 +154,7 @@ private: GraphicsScene *scene; }; -//These transtion test if we have won the game +//This transition tests if we have won the game class WinTransition : public QSignalTransition { public: @@ -166,7 +166,7 @@ private: GraphicsScene *scene; }; -//These transtion is true if one level has been completed and the player want to continue +//This transition is true if one level has been completed and the player wants to continue class CustomSpaceTransition : public QKeyEventTransition { public: diff --git a/examples/statemachine/animation/sub-attaq/textinformationitem.cpp b/examples/statemachine/animation/sub-attaq/textinformationitem.cpp index 4d4934f..c79bcc2 100644 --- a/examples/statemachine/animation/sub-attaq/textinformationitem.cpp +++ b/examples/statemachine/animation/sub-attaq/textinformationitem.cpp @@ -56,9 +56,11 @@ TextInformationItem::TextInformationItem (QGraphicsItem *parent) setFont(QFont("Comic Sans MS", 15)); } -void TextInformationItem::setMessage(const QString &text) +void TextInformationItem::setMessage(const QString &text, bool centerPosition) { setHtml(text); - setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width() / 2, - parentItem()->boundingRect().center().y()); + if (centerPosition) { + setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width() / 2, + parentItem()->boundingRect().center().y()); + } } diff --git a/examples/statemachine/animation/sub-attaq/textinformationitem.h b/examples/statemachine/animation/sub-attaq/textinformationitem.h index 0a0b618..db12acc 100644 --- a/examples/statemachine/animation/sub-attaq/textinformationitem.h +++ b/examples/statemachine/animation/sub-attaq/textinformationitem.h @@ -58,7 +58,7 @@ class TextInformationItem : public QGraphicsTextItem { public: TextInformationItem(QGraphicsItem *parent = nullptr); - void setMessage(const QString &text); + void setMessage(const QString &text, const bool centerPosition = true); }; #endif // TEXTINFORMATIONITEM_H |