qmlfrontend/Page1.qml
branchtransitional_engine
changeset 16051 2003b466b279
parent 16046 e8afb1bf2779
equal deleted inserted replaced
16050:6a3dc15b78b9 16051:2003b466b279
     1 import QtQuick 2.7
     1 import QtQuick
     2 import Hedgewars.Engine 1.0
     2 import Hedgewars.Engine 1.0
     3 
     3 
     4 Page1Form {
     4 Page1Form {
     5     focus: true
     5   property HWEngine hwEngine
       
     6   property var keyBindings: ({
       
     7       "long": {
       
     8         [Qt.Key_Space]: Engine.Attack,
       
     9         [Qt.Key_Up]: Engine.ArrowUp,
       
    10         [Qt.Key_Right]: Engine.ArrowRight,
       
    11         [Qt.Key_Down]: Engine.ArrowDown,
       
    12         [Qt.Key_Left]: Engine.ArrowLeft,
       
    13         [Qt.Key_Shift]: Engine.Precision
       
    14       },
       
    15       "simple": {
       
    16         [Qt.Key_Tab]: Engine.SwitchHedgehog,
       
    17         [Qt.Key_Enter]: Engine.LongJump,
       
    18         [Qt.Key_Backspace]: Engine.HighJump,
       
    19         [Qt.Key_Y]: Engine.Accept,
       
    20         [Qt.Key_N]: Engine.Deny
       
    21       }
       
    22     })
       
    23   property NetSession netSession
     6 
    24 
     7     property HWEngine hwEngine
    25   focus: true
     8     property NetSession netSession
       
     9 
    26 
    10     Component {
    27   Component.onCompleted: {
    11         id: hwEngineComponent
    28     hwEngine = hwEngineComponent.createObject();
       
    29   }
       
    30   Keys.onPressed: event => {
       
    31     if (event.isAutoRepeat) {
       
    32       return;
       
    33     }
       
    34     let action = keyBindings["simple"][event.key];
       
    35     if (action !== undefined) {
       
    36       gameView.engineInstance.simpleEvent(action);
       
    37       event.accepted = true;
       
    38       return;
       
    39     }
       
    40     action = keyBindings["long"][event.key];
       
    41     if (action !== undefined) {
       
    42       gameView.engineInstance.longEvent(action, Engine.Set);
       
    43       event.accepted = true;
       
    44     }
       
    45   }
       
    46   Keys.onReleased: event => {
       
    47     if (event.isAutoRepeat) {
       
    48       return;
       
    49     }
       
    50     const action = keyBindings["long"][event.key];
       
    51     if (action !== undefined) {
       
    52       gameView.engineInstance.longEvent(action, Engine.Unset);
       
    53       event.accepted = true;
       
    54     }
       
    55   }
       
    56   netButton.onClicked: {
       
    57     netSession = netSessionComponent.createObject();
       
    58     netSession.open();
       
    59   }
    12 
    60 
    13         HWEngine {
    61   Component {
    14             engineLibrary: "../rust/lib-hedgewars-engine/target/debug/libhedgewars_engine.so"
    62     id: hwEngineComponent
    15             dataPath: "../share/hedgewars/Data"
    63 
    16             previewAcceptor: PreviewAcceptor
    64     HWEngine {
    17             onPreviewImageChanged: previewImage.source = "image://preview/image"
    65       dataPath: "../share/hedgewars/Data"
    18             onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
    66       engineLibrary: "../rust/lib-hedgewars-engine/target/debug/libhedgewars_engine.so"
    19         }
    67       previewAcceptor: PreviewAcceptor
       
    68 
       
    69       onPreviewImageChanged: previewImage.source = "image://preview/image"
       
    70       onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
    20     }
    71     }
       
    72   }
    21 
    73 
    22     Component {
    74   Component {
    23         id: netSessionComponent
    75     id: netSessionComponent
    24 
    76 
    25         NetSession {
    77     NetSession {
    26             nickname: "test0272"
    78       nickname: "test0272"
    27             url: "hwnet://gameserver.hedgewars.org:46632"
    79       url: "hwnet://gameserver.hedgewars.org:46632"
    28         }
       
    29     }
    80     }
       
    81   }
    30 
    82 
    31     Component.onCompleted: {
    83   tickButton {
    32         hwEngine = hwEngineComponent.createObject()
    84     onClicked: {
       
    85       tickButton.visible = false;
    33     }
    86     }
       
    87   }
    34 
    88 
    35     tickButton {
    89   Timer {
    36         onClicked: {
    90     id: advancingTimer
    37             tickButton.visible = false
    91 
    38             gameView.tick(100)
    92     interval: 100
    39         }
    93     repeat: true
       
    94     running: !tickButton.visible
       
    95 
       
    96     onTriggered: {
       
    97       gameView.tick(100);
       
    98       gameView.update();
    40     }
    99     }
    41     gameButton {
   100   }
    42         visible: !gameView.engineInstance
   101 
    43         onClicked: {
   102   gameButton {
    44             const engineInstance = hwEngine.runQuickGame()
   103     visible: !gameView.engineInstance
    45             gameView.engineInstance = engineInstance
   104 
    46         }
   105     onClicked: {
       
   106       const engineInstance = hwEngine.runQuickGame();
       
   107       gameView.engineInstance = engineInstance;
    47     }
   108     }
    48     button1 {
   109   }
    49         visible: !gameView.engineInstance
   110 
    50         onClicked: {
   111   button1 {
    51             hwEngine.getPreview()
   112     visible: !gameView.engineInstance
    52         }
   113 
       
   114     onClicked: {
       
   115       hwEngine.getPreview();
    53     }
   116     }
    54     netButton.onClicked: {
   117   }
    55         netSession = netSessionComponent.createObject()
   118 
    56         netSession.open()
   119   preview {
       
   120     visible: !gameView.engineInstance
       
   121   }
       
   122 
       
   123   gameMouseArea {
       
   124     onPositionChanged: event => {
       
   125       gameView.engineInstance.moveCamera(Qt.point(event.x - gameMouseArea.lastPoint.x, event.y - gameMouseArea.lastPoint.y));
       
   126       gameMouseArea.lastPoint = Qt.point(event.x, event.y);
    57     }
   127     }
    58 
   128     onPressed: event => {
    59     Keys.onPressed: {
   129       gameMouseArea.lastPoint = Qt.point(event.x, event.y);
    60         if (event.key === Qt.Key_Enter)
       
    61             gameView.engineInstance.longEvent(Engine.Attack, Engine.Set)
       
    62     }
   130     }
    63 
   131   }
    64     Keys.onReleased: {
       
    65         if (event.key === Qt.Key_Enter)
       
    66             gameView.engineInstance.longEvent(Engine.Attack, Engine.Unset)
       
    67     }
       
    68 }
   132 }