--- a/qmlfrontend/Page1.qml Wed Aug 28 15:31:51 2024 +0200
+++ b/qmlfrontend/Page1.qml Wed Aug 28 15:34:49 2024 +0200
@@ -1,68 +1,132 @@
-import QtQuick 2.7
+import QtQuick
import Hedgewars.Engine 1.0
Page1Form {
- focus: true
+ property HWEngine hwEngine
+ property var keyBindings: ({
+ "long": {
+ [Qt.Key_Space]: Engine.Attack,
+ [Qt.Key_Up]: Engine.ArrowUp,
+ [Qt.Key_Right]: Engine.ArrowRight,
+ [Qt.Key_Down]: Engine.ArrowDown,
+ [Qt.Key_Left]: Engine.ArrowLeft,
+ [Qt.Key_Shift]: Engine.Precision
+ },
+ "simple": {
+ [Qt.Key_Tab]: Engine.SwitchHedgehog,
+ [Qt.Key_Enter]: Engine.LongJump,
+ [Qt.Key_Backspace]: Engine.HighJump,
+ [Qt.Key_Y]: Engine.Accept,
+ [Qt.Key_N]: Engine.Deny
+ }
+ })
+ property NetSession netSession
- property HWEngine hwEngine
- property NetSession netSession
-
- Component {
- id: hwEngineComponent
+ focus: true
- HWEngine {
- engineLibrary: "../rust/lib-hedgewars-engine/target/debug/libhedgewars_engine.so"
- dataPath: "../share/hedgewars/Data"
- previewAcceptor: PreviewAcceptor
- onPreviewImageChanged: previewImage.source = "image://preview/image"
- onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
- }
+ Component.onCompleted: {
+ hwEngine = hwEngineComponent.createObject();
+ }
+ Keys.onPressed: event => {
+ if (event.isAutoRepeat) {
+ return;
+ }
+ let action = keyBindings["simple"][event.key];
+ if (action !== undefined) {
+ gameView.engineInstance.simpleEvent(action);
+ event.accepted = true;
+ return;
}
+ action = keyBindings["long"][event.key];
+ if (action !== undefined) {
+ gameView.engineInstance.longEvent(action, Engine.Set);
+ event.accepted = true;
+ }
+ }
+ Keys.onReleased: event => {
+ if (event.isAutoRepeat) {
+ return;
+ }
+ const action = keyBindings["long"][event.key];
+ if (action !== undefined) {
+ gameView.engineInstance.longEvent(action, Engine.Unset);
+ event.accepted = true;
+ }
+ }
+ netButton.onClicked: {
+ netSession = netSessionComponent.createObject();
+ netSession.open();
+ }
- Component {
- id: netSessionComponent
+ Component {
+ id: hwEngineComponent
- NetSession {
- nickname: "test0272"
- url: "hwnet://gameserver.hedgewars.org:46632"
- }
- }
-
- Component.onCompleted: {
- hwEngine = hwEngineComponent.createObject()
- }
+ HWEngine {
+ dataPath: "../share/hedgewars/Data"
+ engineLibrary: "../rust/lib-hedgewars-engine/target/debug/libhedgewars_engine.so"
+ previewAcceptor: PreviewAcceptor
- tickButton {
- onClicked: {
- tickButton.visible = false
- gameView.tick(100)
- }
+ onPreviewImageChanged: previewImage.source = "image://preview/image"
+ onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
+ }
+ }
+
+ Component {
+ id: netSessionComponent
+
+ NetSession {
+ nickname: "test0272"
+ url: "hwnet://gameserver.hedgewars.org:46632"
}
- gameButton {
- visible: !gameView.engineInstance
- onClicked: {
- const engineInstance = hwEngine.runQuickGame()
- gameView.engineInstance = engineInstance
- }
+ }
+
+ tickButton {
+ onClicked: {
+ tickButton.visible = false;
+ }
+ }
+
+ Timer {
+ id: advancingTimer
+
+ interval: 100
+ repeat: true
+ running: !tickButton.visible
+
+ onTriggered: {
+ gameView.tick(100);
+ gameView.update();
}
- button1 {
- visible: !gameView.engineInstance
- onClicked: {
- hwEngine.getPreview()
- }
+ }
+
+ gameButton {
+ visible: !gameView.engineInstance
+
+ onClicked: {
+ const engineInstance = hwEngine.runQuickGame();
+ gameView.engineInstance = engineInstance;
}
- netButton.onClicked: {
- netSession = netSessionComponent.createObject()
- netSession.open()
- }
+ }
+
+ button1 {
+ visible: !gameView.engineInstance
- Keys.onPressed: {
- if (event.key === Qt.Key_Enter)
- gameView.engineInstance.longEvent(Engine.Attack, Engine.Set)
+ onClicked: {
+ hwEngine.getPreview();
}
+ }
+
+ preview {
+ visible: !gameView.engineInstance
+ }
- Keys.onReleased: {
- if (event.key === Qt.Key_Enter)
- gameView.engineInstance.longEvent(Engine.Attack, Engine.Unset)
+ gameMouseArea {
+ onPositionChanged: event => {
+ gameView.engineInstance.moveCamera(Qt.point(event.x - gameMouseArea.lastPoint.x, event.y - gameMouseArea.lastPoint.y));
+ gameMouseArea.lastPoint = Qt.point(event.x, event.y);
}
+ onPressed: event => {
+ gameMouseArea.lastPoint = Qt.point(event.x, event.y);
+ }
+ }
}