qmlfrontend/Page1.qml
author unC0Rr
Wed, 01 May 2024 16:49:16 +0200
changeset 16012 caba603f461f
parent 15891 d52f5d8e75e6
child 16016 4933920eba89
permissions -rw-r--r--
Allow to move camera by dragging mouse cursor over game field
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
     1
import QtQuick
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 {
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
     5
  focus: true
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
     6
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
     7
  property HWEngine hwEngine
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
     8
  property NetSession netSession
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
     9
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    10
  Component {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
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
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    13
    HWEngine {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    14
      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
    15
      dataPath: "../share/hedgewars/Data"
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    16
      previewAcceptor: PreviewAcceptor
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    17
      onPreviewImageChanged: previewImage.source = "image://preview/image"
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    18
      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
    19
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    20
  }
14371
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    21
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    22
  Component {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    23
    id: netSessionComponent
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    24
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    25
    NetSession {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    26
      nickname: "test0272"
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    27
      url: "hwnet://gameserver.hedgewars.org:46632"
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    28
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    29
  }
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    30
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    31
  Component.onCompleted: {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    32
    hwEngine = hwEngineComponent.createObject()
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    33
  }
14371
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    34
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    35
  tickButton {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    36
    onClicked: {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    37
      tickButton.visible = false
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    38
      gameView.tick(100)
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    39
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    40
  }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    41
  gameButton {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    42
    visible: !gameView.engineInstance
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    43
    onClicked: {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    44
      const engineInstance = hwEngine.runQuickGame()
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    45
      gameView.engineInstance = engineInstance
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    46
    }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    47
  }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    48
  button1 {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    49
    visible: !gameView.engineInstance
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    50
    onClicked: {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    51
      hwEngine.getPreview()
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    52
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    53
  }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    54
  preview {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    55
    visible: !gameView.engineInstance
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    56
  }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    57
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    58
  netButton.onClicked: {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    59
    netSession = netSessionComponent.createObject()
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    60
    netSession.open()
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    61
  }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    62
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    63
  Keys.onPressed: {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    64
    if (event.key === Qt.Key_Enter)
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    65
      gameView.engineInstance.longEvent(Engine.Attack, Engine.Set)
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    66
  }
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    67
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    68
  Keys.onReleased: {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    69
    if (event.key === Qt.Key_Enter)
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    70
      gameView.engineInstance.longEvent(Engine.Attack, Engine.Unset)
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    71
  }
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    72
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    73
  gameMouseArea {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    74
    onPressed: event => {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    75
                 gameMouseArea.lastPoint = Qt.point(event.x, event.y)
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    76
               }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    77
    onPositionChanged: event => {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    78
                         gameView.engineInstance.moveCamera(
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    79
                           Qt.point(event.x - gameMouseArea.lastPoint.x,
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    80
                                    event.y - gameMouseArea.lastPoint.y))
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    81
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    82
                         gameMouseArea.lastPoint = Qt.point(event.x, event.y)
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    83
                       }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    84
  }
12854
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    85
}