qmlfrontend/Page1.qml
author unC0Rr
Tue, 15 Nov 2022 14:27:22 +0100
changeset 15893 5b3beb90e1a6
parent 15891 d52f5d8e75e6
child 16012 caba603f461f
permissions -rw-r--r--
Implement generation of c header from rust interface, adapt qmlfrontend
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12854
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     1
import QtQuick 2.7
14143
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12854
diff changeset
     2
import Hedgewars.Engine 1.0
12854
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     3
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     4
Page1Form {
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
     5
    focus: true
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
     6
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
     7
    property HWEngine hwEngine
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
     8
    property NetSession netSession
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
     9
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    10
    Component {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    11
        id: hwEngineComponent
14371
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    12
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    13
        HWEngine {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    14
            engineLibrary: "../rust/lib-hedgewars-engine/target/debug/libhedgewars_engine.so"
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    15
            dataPath: "../share/hedgewars/Data"
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    16
            previewAcceptor: PreviewAcceptor
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    17
            onPreviewImageChanged: previewImage.source = "image://preview/image"
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    18
            onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    19
        }
14371
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    20
    }
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    21
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    22
    Component {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    23
        id: netSessionComponent
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    24
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    25
        NetSession {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    26
            nickname: "test0272"
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    27
            url: "hwnet://gameserver.hedgewars.org:46632"
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    28
        }
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    29
    }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    30
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    31
    Component.onCompleted: {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    32
        hwEngine = hwEngineComponent.createObject()
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    33
    }
14371
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    34
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    35
    tickButton {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    36
        onClicked: {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    37
            tickButton.visible = false
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    38
            gameView.tick(100)
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    39
        }
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    40
    }
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    41
    gameButton {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    42
        visible: !gameView.engineInstance
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    43
        onClicked: {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    44
            const engineInstance = hwEngine.runQuickGame()
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    45
            gameView.engineInstance = engineInstance
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    46
        }
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    47
    }
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    48
    button1 {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    49
        visible: !gameView.engineInstance
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    50
        onClicked: {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    51
            hwEngine.getPreview()
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    52
        }
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    53
    }
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    54
    netButton.onClicked: {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    55
        netSession = netSessionComponent.createObject()
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    56
        netSession.open()
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    57
    }
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    58
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    59
    Keys.onPressed: {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    60
        if (event.key === Qt.Key_Enter)
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    61
            gameView.engineInstance.longEvent(Engine.Attack, Engine.Set)
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    62
    }
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    63
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    64
    Keys.onReleased: {
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    65
        if (event.key === Qt.Key_Enter)
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    66
            gameView.engineInstance.longEvent(Engine.Attack, Engine.Unset)
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    67
    }
12854
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    68
}