diff --git a/src/activities/submarine/Controls.qml b/src/activities/submarine/Controls.qml --- a/src/activities/submarine/Controls.qml +++ b/src/activities/submarine/Controls.qml @@ -37,16 +37,22 @@ property point leftBallastTankPosition property alias leftBallastTankWidth : leftBallastTankDisplay.width property alias leftBallastTankHeight : leftBallastTankDisplay.height + property alias rotateLeftFill: rotateLeftFill + property alias rotateLeftFlush: rotateLeftFlush property alias centralTankVisible : centralBallastTankController.visible property point centralBallastTankPosition property alias centralBallastTankWidth : centralBallastTankDisplay.width property alias centralBallastTankHeight : centralBallastTankDisplay.height + property alias rotateCentralFill: rotateCentralFill + property alias rotateCentralFlush: rotateCentralFlush property alias rightTankVisible : rightBallastTankController.visible property point rightBallastTankPosition property alias rightBallastTankWidth : rightBallastTankDisplay.width property alias rightBallastTankHeight : rightBallastTankDisplay.height + property alias rotateRightFill: rotateRightFill + property alias rotateRightFlush: rotateRightFlush /* Diving Plane Controller properties */ property bool divingPlaneVisible @@ -197,30 +203,6 @@ origin.y: leftBallastFill.height / 2 axis { x: 0; y: 0; z: 1 } angle: 0 } - - SequentialAnimation { - id: leftFillAnim1 - loops: 1 - PropertyAnimation { - target: rotateLeftFill - properties: "angle" - from: 0 - to: 90 - duration: 200 - } - } - - SequentialAnimation { - id: leftFillAnim2 - loops: 1 - PropertyAnimation { - target: rotateLeftFill - properties: "angle" - from: 90 - to: 0 - duration: 200 - } - } MouseArea { anchors.fill: parent @@ -228,11 +210,7 @@ onClicked: { leftBallastTank.fillBallastTanks() - if (leftBallastTank.waterFilling) { - leftFillAnim1.start() - } else { - leftFillAnim2.start() - } + updateVannes(leftBallastTank.waterFilling, rotateLeftFill) } } } @@ -254,30 +232,6 @@ origin.y: leftBallastFill.height / 2 axis { x: 0; y: 0; z: 1 } angle: 0 } - - SequentialAnimation { - id: leftFlushAnim1 - loops: 1 - PropertyAnimation { - target: rotateLeftFlush - properties: "angle" - from: 0 - to: 90 - duration: 200 - } - } - - SequentialAnimation { - id: leftFlushAnim2 - loops: 1 - PropertyAnimation { - target: rotateLeftFlush - properties: "angle" - from: 90 - to: 0 - duration: 200 - } - } MouseArea { anchors.fill: parent @@ -285,11 +239,7 @@ onClicked: { leftBallastTank.flushBallastTanks() - if (leftBallastTank.waterFlushing) { - leftFlushAnim1.start() - } else { - leftFlushAnim2.start() - } + updateVannes(leftBallastTank.waterFlushing, rotateLeftFlush) } } } @@ -360,30 +310,6 @@ origin.y: centralBallastFill.height / 2 axis { x: 0; y: 0; z: 1 } angle: 0 } - - SequentialAnimation { - id: centralFillAnim1 - loops: 1 - PropertyAnimation { - target: rotateCentralFill - properties: "angle" - from: 0 - to: 90 - duration: 200 - } - } - - SequentialAnimation { - id: centralFillAnim2 - loops: 1 - PropertyAnimation { - target: rotateCentralFill - properties: "angle" - from: 90 - to: 0 - duration: 200 - } - } MouseArea { anchors.fill: parent @@ -391,11 +317,7 @@ onClicked: { centralBallastTank.fillBallastTanks() - if (centralBallastTank.waterFilling) { - centralFillAnim1.start() - } else { - centralFillAnim2.start() - } + updateVannes(centralBallastTank.waterFilling, rotateCentralFill) } } } @@ -418,30 +340,6 @@ origin.y: centralBallastFill.height / 2 axis { x: 0; y: 0; z: 1 } angle: 0 } - - SequentialAnimation { - id: centralFlushAnim1 - loops: 1 - PropertyAnimation { - target: rotateCentralFlush - properties: "angle" - from: 0 - to: 90 - duration: 200 - } - } - - SequentialAnimation { - id: centralFlushAnim2 - loops: 1 - PropertyAnimation { - target: rotateCentralFlush - properties: "angle" - from: 90 - to: 0 - duration: 200 - } - } MouseArea { anchors.fill: parent @@ -449,11 +347,7 @@ onClicked: { centralBallastTank.flushBallastTanks() - if (centralBallastTank.waterFlushing) { - centralFlushAnim1.start() - } else { - centralFlushAnim2.start() - } + updateVannes(centralBallastTank.waterFlushing, rotateCentralFlush) } } } @@ -523,30 +417,6 @@ origin.y: rightBallastFill.height / 2 axis { x: 0; y: 0; z: 1 } angle: 0 } - - SequentialAnimation { - id: rightFillAnim1 - loops: 1 - PropertyAnimation { - target: rotateRightFill - properties: "angle" - from: 0 - to: 90 - duration: 200 - } - } - - SequentialAnimation { - id: rightFillAnim2 - loops: 1 - PropertyAnimation { - target: rotateRightFill - properties: "angle" - from: 90 - to: 0 - duration: 200 - } - } MouseArea { anchors.fill: parent @@ -554,11 +424,7 @@ onClicked: { rightBallastTank.fillBallastTanks() - if (rightBallastTank.waterFilling) { - rightFillAnim1.start() - } else { - rightFillAnim2.start() - } + updateVannes(rightBallastTank.waterFilling, rotateRightFill) } } } @@ -581,30 +447,6 @@ origin.y: rightBallastFill.height / 2 axis { x: 0; y: 0; z: 1 } angle: 0 } - - SequentialAnimation { - id: rightFlushAnim1 - loops: 1 - PropertyAnimation { - target: rotateRightFlush - properties: "angle" - from: 0 - to: 90 - duration: 200 - } - } - - SequentialAnimation { - id: rightFlushAnim2 - loops: 1 - PropertyAnimation { - target: rotateRightFlush - properties: "angle" - from: 90 - to: 0 - duration: 200 - } - } MouseArea { anchors.fill: parent @@ -612,16 +454,53 @@ onClicked: { rightBallastTank.flushBallastTanks() - if (rightBallastTank.waterFlushing) { - rightFlushAnim1.start() - } else { - rightFlushAnim2.start() - } + updateVannes(rightBallastTank.waterFlushing, rotateRightFlush) } } } } + PropertyAnimation { + id: ballastTankOnAnim + properties: "angle" + from: 0 + to: 90 + duration: 200 + } + + PropertyAnimation { + id: ballastTankOffAnim + properties: "angle" + from: 90 + to: 0 + duration: 200 + } + + function updateVannes(vanneOnCondition, animationTarget) { + if (vanneOnCondition) { + ballastTankOnAnim.target = animationTarget + ballastTankOnAnim.start() + } else { + ballastTankOffAnim.target = animationTarget + ballastTankOffAnim.start() + } + } + + function resetVannes() { + if (leftTankVisible) { + rotateLeftFill.angle = 0 + rotateLeftFlush.angle = 0 + } + if (centralTankVisible) { + rotateCentralFill.angle = 0 + rotateCentralFlush.angle = 0 + } + if (rightTankVisible) { + rotateRightFill.angle = 0 + rotateRightFlush.angle = 0 + } + } + Item { id: divingPlaneController visible: divingPlaneVisible diff --git a/src/activities/submarine/Submarine.qml b/src/activities/submarine/Submarine.qml --- a/src/activities/submarine/Submarine.qml +++ b/src/activities/submarine/Submarine.qml @@ -64,9 +64,11 @@ } if ((event.key == Qt.Key_W || event.key == Qt.Key_Up) && !tutorial.visible) { centralBallastTank.fillBallastTanks() + controls.updateVannes(centralBallastTank.waterFilling, controls.rotateCentralFill) } if ((event.key == Qt.Key_S || event.key == Qt.Key_Down) && !tutorial.visible) { centralBallastTank.flushBallastTanks() + controls.updateVannes(centralBallastTank.waterFlushing, controls.rotateCentralFlush) } if ((event.key == Qt.Key_Plus) && !tutorial.visible) { submarine.increaseWingsAngle(1) @@ -77,16 +79,20 @@ if ((event.key == Qt.Key_R) && !tutorial.visible) { leftBallastTank.fillBallastTanks() + controls.updateVannes(leftBallastTank.waterFilling, controls.rotateLeftFill) } if ((event.key == Qt.Key_F) && !tutorial.visible) { leftBallastTank.flushBallastTanks() + controls.updateVannes(leftBallastTank.waterFlushing, controls.rotateLeftFlush) } if ((event.key == Qt.Key_T) && !tutorial.visible) { rightBallastTank.fillBallastTanks() + controls.updateVannes(rightBallastTank.waterFilling, controls.rotateRightFill) } if ((event.key == Qt.Key_G) && !tutorial.visible) { rightBallastTank.flushBallastTanks() + controls.updateVannes(rightBallastTank.waterFlushing, controls.rotateRightFlush) } } @@ -111,6 +117,7 @@ property alias tutorial: tutorial property alias upperGate: upperGate property alias ship: ship + property alias controls: controls property alias physicalWorld: physicalWorld property bool processingAnswer: false } diff --git a/src/activities/submarine/submarine.js b/src/activities/submarine/submarine.js --- a/src/activities/submarine/submarine.js +++ b/src/activities/submarine/submarine.js @@ -85,6 +85,7 @@ items.crown.reset() items.whale.reset() + items.controls.resetVannes() items.processingAnswer = false