author | unC0Rr |
Tue, 03 Sep 2024 11:16:52 +0200 | |
branch | transitional_engine |
changeset 16028 | 509ecce37522 |
parent 16017 | e8afb1bf2779 |
permissions | -rw-r--r-- |
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
1 |
import QtQuick |
14143 | 2 |
import Hedgewars.Engine 1.0 |
12854 | 3 |
|
4 |
Page1Form { |
|
16016 | 5 |
property HWEngine hwEngine |
6 |
property var keyBindings: ({ |
|
7 |
"long": { |
|
8 |
[Qt.Key_Space]: Engine.Attack, |
|
9 |
[Qt.Key_Up]: Engine.ArrowUp, |
|
10 |
[Qt.Key_Right]: Engine.ArrowRight, |
|
11 |
[Qt.Key_Down]: Engine.ArrowDown, |
|
12 |
[Qt.Key_Left]: Engine.ArrowLeft, |
|
13 |
[Qt.Key_Shift]: Engine.Precision |
|
14 |
}, |
|
15 |
"simple": { |
|
16 |
[Qt.Key_Tab]: Engine.SwitchHedgehog, |
|
17 |
[Qt.Key_Enter]: Engine.LongJump, |
|
18 |
[Qt.Key_Backspace]: Engine.HighJump, |
|
19 |
[Qt.Key_Y]: Engine.Accept, |
|
20 |
[Qt.Key_N]: Engine.Deny |
|
21 |
} |
|
22 |
}) |
|
23 |
property NetSession netSession |
|
24 |
||
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
25 |
focus: true |
14854
aed75d439027
Implement external events approach to input user actions into engine.
unc0rr
parents:
14372
diff
changeset
|
26 |
|
16016 | 27 |
Component.onCompleted: { |
28 |
hwEngine = hwEngineComponent.createObject(); |
|
29 |
} |
|
30 |
Keys.onPressed: event => { |
|
31 |
if (event.isAutoRepeat) { |
|
32 |
return; |
|
33 |
} |
|
34 |
let action = keyBindings["simple"][event.key]; |
|
35 |
if (action !== undefined) { |
|
36 |
gameView.engineInstance.simpleEvent(action); |
|
37 |
event.accepted = true; |
|
38 |
return; |
|
39 |
} |
|
40 |
action = keyBindings["long"][event.key]; |
|
41 |
if (action !== undefined) { |
|
42 |
gameView.engineInstance.longEvent(action, Engine.Set); |
|
43 |
event.accepted = true; |
|
44 |
} |
|
45 |
} |
|
46 |
Keys.onReleased: event => { |
|
47 |
if (event.isAutoRepeat) { |
|
48 |
return; |
|
49 |
} |
|
50 |
const action = keyBindings["long"][event.key]; |
|
51 |
if (action !== undefined) { |
|
52 |
gameView.engineInstance.longEvent(action, Engine.Unset); |
|
53 |
event.accepted = true; |
|
54 |
} |
|
55 |
} |
|
56 |
netButton.onClicked: { |
|
57 |
netSession = netSessionComponent.createObject(); |
|
58 |
netSession.open(); |
|
59 |
} |
|
15891 | 60 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
61 |
Component { |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
62 |
id: hwEngineComponent |
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
63 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
64 |
HWEngine { |
16016 | 65 |
dataPath: "../share/hedgewars/Data" |
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
66 |
engineLibrary: "../rust/lib-hedgewars-engine/target/debug/libhedgewars_engine.so" |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
67 |
previewAcceptor: PreviewAcceptor |
16016 | 68 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
69 |
onPreviewImageChanged: previewImage.source = "image://preview/image" |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
70 |
onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png" |
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
71 |
} |
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
72 |
} |
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
73 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
74 |
Component { |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
75 |
id: netSessionComponent |
14915 | 76 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
77 |
NetSession { |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
78 |
nickname: "test0272" |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
79 |
url: "hwnet://gameserver.hedgewars.org:46632" |
14915 | 80 |
} |
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
81 |
} |
14915 | 82 |
|
16016 | 83 |
tickButton { |
84 |
onClicked: { |
|
85 |
tickButton.visible = false; |
|
16017
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
86 |
} |
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
87 |
} |
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
88 |
|
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
89 |
Timer { |
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
90 |
id: advancingTimer |
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
91 |
|
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
92 |
interval: 100 |
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
93 |
repeat: true |
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
94 |
running: !tickButton.visible |
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
95 |
|
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
96 |
onTriggered: { |
16016 | 97 |
gameView.tick(100); |
16017
e8afb1bf2779
Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents:
16016
diff
changeset
|
98 |
gameView.update(); |
16016 | 99 |
} |
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
100 |
} |
14371
90bd2c331703
Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents:
14298
diff
changeset
|
101 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
102 |
gameButton { |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
103 |
visible: !gameView.engineInstance |
16016 | 104 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
105 |
onClicked: { |
16016 | 106 |
const engineInstance = hwEngine.runQuickGame(); |
107 |
gameView.engineInstance = engineInstance; |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
108 |
} |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
109 |
} |
16016 | 110 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
111 |
button1 { |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
112 |
visible: !gameView.engineInstance |
16016 | 113 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
114 |
onClicked: { |
16016 | 115 |
hwEngine.getPreview(); |
14854
aed75d439027
Implement external events approach to input user actions into engine.
unc0rr
parents:
14372
diff
changeset
|
116 |
} |
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
117 |
} |
16016 | 118 |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
119 |
preview { |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
120 |
visible: !gameView.engineInstance |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
121 |
} |
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
122 |
|
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
123 |
gameMouseArea { |
16016 | 124 |
onPositionChanged: event => { |
125 |
gameView.engineInstance.moveCamera(Qt.point(event.x - gameMouseArea.lastPoint.x, event.y - gameMouseArea.lastPoint.y)); |
|
126 |
gameMouseArea.lastPoint = Qt.point(event.x, event.y); |
|
127 |
} |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
128 |
onPressed: event => { |
16016 | 129 |
gameMouseArea.lastPoint = Qt.point(event.x, event.y); |
130 |
} |
|
16012
caba603f461f
Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents:
15891
diff
changeset
|
131 |
} |
12854 | 132 |
} |