qmlfrontend/Page1.qml
author unc0rr
Mon, 29 Apr 2019 23:41:25 +0200
changeset 14859 aed75d439027
parent 14377 b6824a53d4b1
child 14920 a3ad06ac390e
permissions -rw-r--r--
Implement external events approach to input user actions into engine. Doesn't work for some obscure reason ("Error: Unknown method parameter type: LongEventType")
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     1
import QtQuick 2.7
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
     2
import Hedgewars.Engine 1.0
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     3
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
     4
Page1Form {
14859
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
     5
  focus: true
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
     6
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
     7
  property HWEngine hwEngine
14376
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
     8
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
     9
  Component {
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    10
    id: hwEngineComponent
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    11
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    12
    HWEngine {
14377
b6824a53d4b1 Allow to instantiate HWEngine with different library binaries
unC0Rr
parents: 14376
diff changeset
    13
      engineLibrary: "./libhedgewars_engine.so"
14376
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    14
      previewAcceptor: PreviewAcceptor
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    15
      onPreviewImageChanged: previewImage.source = "image://preview/image"
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    16
      onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    17
    }
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    18
  }
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    19
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    20
  Component.onCompleted: {
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    21
    hwEngine = hwEngineComponent.createObject()
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    22
  }
90bd2c331703 Add possibility to instantiate HWEngine objects from QML, reorganize work with preview
unC0Rr
parents: 14303
diff changeset
    23
14859
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    24
  tickButton {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    25
    onClicked: {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    26
      tickButton.visible = false
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    27
      gameView.tick(100)
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    28
    }
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    29
  }
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    30
  gameButton {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    31
    visible: !gameView.engineInstance
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    32
    onClicked: {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    33
      var engineInstance = hwEngine.runQuickGame()
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    34
      gameView.engineInstance = engineInstance
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    35
    }
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    36
  }
14859
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    37
  button1 {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    38
    visible: !gameView.engineInstance
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    39
    onClicked: {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    40
      hwEngine.getPreview()
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    41
    }
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents: 12859
diff changeset
    42
  }
14859
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    43
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    44
  Keys.onPressed: {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    45
    if (event.key === Qt.Key_Enter)
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    46
      gameView.engineInstance.longEvent(EngineInstance.Attack,
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    47
                                        EngineInstance.Set)
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    48
  }
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    49
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    50
  Keys.onReleased: {
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    51
    if (event.key === Qt.Key_Enter)
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    52
      gameView.engineInstance.longEvent(EngineInstance.Attack,
aed75d439027 Implement external events approach to input user actions into engine.
unc0rr
parents: 14377
diff changeset
    53
                                        EngineInstance.Unset)
12859
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    54
  }
28cb18c5e712 Add new qmlfrontend project template
unc0rr
parents:
diff changeset
    55
}