qmlfrontend/Page1.qml
author unC0Rr
Tue, 04 Feb 2025 17:31:55 +0100
branchqmlrenderer
changeset 16087 8da5a118120b
parent 16017 e8afb1bf2779
permissions -rw-r--r--
Modernize approach for building qmlfrontend
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
16087
8da5a118120b Modernize approach for building qmlfrontend
unC0Rr
parents: 16017
diff changeset
     2
import Hedgewars 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 {
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
     5
  property HWEngine hwEngine
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
     6
  property NetSession netSession
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
     7
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
     8
  focus: true
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
     9
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    10
  Component.onCompleted: {
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    11
    hwEngine = hwEngineComponent.createObject();
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    12
  }
16087
8da5a118120b Modernize approach for building qmlfrontend
unC0Rr
parents: 16017
diff changeset
    13
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    14
  netButton.onClicked: {
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    15
    netSession = netSessionComponent.createObject();
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    16
    netSession.open();
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    17
  }
15891
d52f5d8e75e6 Allow passing data_path from QML
unc0rr
parents: 15217
diff changeset
    18
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    19
  Component {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    20
    id: hwEngineComponent
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
    HWEngine {
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    23
      dataPath: "../share/hedgewars/Data"
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    24
      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
    25
      previewAcceptor: PreviewAcceptor
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    26
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    27
      onPreviewImageChanged: previewImage.source = "image://preview/image"
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    28
      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
    29
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    30
  }
14371
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    31
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    32
  Component {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    33
    id: netSessionComponent
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    34
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    35
    NetSession {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    36
      nickname: "test0272"
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    37
      url: "hwnet://gameserver.hedgewars.org:46632"
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    38
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    39
  }
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents: 14854
diff changeset
    40
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    41
  tickButton {
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    42
    onClicked: {
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    43
      tickButton.visible = false;
16017
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    44
    }
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    45
  }
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    46
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    47
  Timer {
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    48
    id: advancingTimer
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    49
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    50
    interval: 100
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    51
    repeat: true
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    52
    running: !tickButton.visible
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    53
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    54
    onTriggered: {
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    55
      gameView.tick(100);
16017
e8afb1bf2779 Implement triggering advancement of simulation in qmlfrontend
unC0Rr
parents: 16016
diff changeset
    56
      gameView.update();
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    57
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    58
  }
14371
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14298
diff changeset
    59
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    60
  gameButton {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    61
    visible: !gameView.engineInstance
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    62
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    63
    onClicked: {
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    64
      const engineInstance = hwEngine.runQuickGame();
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    65
      gameView.engineInstance = engineInstance;
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    66
    }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    67
  }
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    68
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    69
  button1 {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    70
    visible: !gameView.engineInstance
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    71
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    72
    onClicked: {
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    73
      hwEngine.getPreview();
14854
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14372
diff changeset
    74
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    75
  }
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    76
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    77
  preview {
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    78
    visible: !gameView.engineInstance
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    79
  }
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    80
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    81
  gameMouseArea {
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    82
    onPositionChanged: event => {
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    83
      gameView.engineInstance.moveCamera(Qt.point(event.x - gameMouseArea.lastPoint.x, event.y - gameMouseArea.lastPoint.y));
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    84
      gameMouseArea.lastPoint = Qt.point(event.x, event.y);
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    85
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    86
    onPressed: event => {
16016
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    87
      gameMouseArea.lastPoint = Qt.point(event.x, event.y);
4933920eba89 Implement key bindings
unC0Rr
parents: 16012
diff changeset
    88
    }
16012
caba603f461f Allow to move camera by dragging mouse cursor over game field
unC0Rr
parents: 15891
diff changeset
    89
  }
12854
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    90
}