qmlfrontend/Page1.qml
author Wuzzy <Wuzzy2@mail.ru>
Tue, 07 May 2019 22:36:15 +0200
changeset 14923 2dcc64515346
parent 14875 aed75d439027
child 14936 a3ad06ac390e
permissions -rw-r--r--
Add new server messages REPLAY_START and REPLAY_END for /WATCH command

import QtQuick 2.7
import Hedgewars.Engine 1.0

Page1Form {
  focus: true

  property HWEngine hwEngine

  Component {
    id: hwEngineComponent

    HWEngine {
      engineLibrary: "./libhedgewars_engine.so"
      previewAcceptor: PreviewAcceptor
      onPreviewImageChanged: previewImage.source = "image://preview/image"
      onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
    }
  }

  Component.onCompleted: {
    hwEngine = hwEngineComponent.createObject()
  }

  tickButton {
    onClicked: {
      tickButton.visible = false
      gameView.tick(100)
    }
  }
  gameButton {
    visible: !gameView.engineInstance
    onClicked: {
      var engineInstance = hwEngine.runQuickGame()
      gameView.engineInstance = engineInstance
    }
  }
  button1 {
    visible: !gameView.engineInstance
    onClicked: {
      hwEngine.getPreview()
    }
  }

  Keys.onPressed: {
    if (event.key === Qt.Key_Enter)
      gameView.engineInstance.longEvent(EngineInstance.Attack,
                                        EngineInstance.Set)
  }

  Keys.onReleased: {
    if (event.key === Qt.Key_Enter)
      gameView.engineInstance.longEvent(EngineInstance.Attack,
                                        EngineInstance.Unset)
  }
}