| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- import QtQuick 2.15
- import QtQuick.Controls 2.15
- Item {
- id: gameView
-
- property bool isPaused: false
- property real gameSpeed: 1.0
-
- signal mapClicked(real x, real y)
- signal unitSelected(int unitId)
- signal areaSelected(real x1, real y1, real x2, real y2)
-
- function setPaused(paused) {
- isPaused = paused
- }
-
- function setGameSpeed(speed) {
- gameSpeed = speed
- }
-
- function issueCommand(command) {
- console.log("Command issued:", command)
- // Handle unit commands
- }
-
- // OpenGL rendering area
- Rectangle {
- id: renderArea
- anchors.fill: parent
- color: "#2c3e50"
-
- // This will be replaced by actual OpenGL rendering
- Text {
- anchors.centerIn: parent
- text: "3D Game World\n(OpenGL Render Area)\n\nPress WASD to move camera\nMouse to look around\nScroll to zoom"
- color: "white"
- font.pointSize: 16
- horizontalAlignment: Text.AlignHCenter
- }
-
- // Camera controls info
- Rectangle {
- anchors.top: parent.top
- anchors.left: parent.left
- anchors.margins: 10
- width: 200
- height: 120
- color: "#34495e"
- opacity: 0.8
-
- Column {
- anchors.fill: parent
- anchors.margins: 8
- spacing: 4
-
- Text {
- text: "Camera Controls:"
- color: "white"
- font.bold: true
- font.pointSize: 10
- }
- Text {
- text: "WASD - Move"
- color: "white"
- font.pointSize: 9
- }
- Text {
- text: "Mouse - Look"
- color: "white"
- font.pointSize: 9
- }
- Text {
- text: "Scroll - Zoom"
- color: "white"
- font.pointSize: 9
- }
- Text {
- text: "Q/E - Rotate"
- color: "white"
- font.pointSize: 9
- }
- Text {
- text: "R/F - Up/Down"
- color: "white"
- font.pointSize: 9
- }
- }
- }
-
- MouseArea {
- id: mouseArea
- anchors.fill: parent
- acceptedButtons: Qt.LeftButton | Qt.RightButton
-
- property bool isSelecting: false
- property real startX: 0
- property real startY: 0
-
- onPressed: function(mouse) {
- if (mouse.button === Qt.LeftButton) {
- isSelecting = true
- startX = mouse.x
- startY = mouse.y
- selectionBox.x = startX
- selectionBox.y = startY
- selectionBox.width = 0
- selectionBox.height = 0
- selectionBox.visible = true
- }
- }
-
- onPositionChanged: function(mouse) {
- if (isSelecting) {
- var endX = mouse.x
- var endY = mouse.y
-
- selectionBox.x = Math.min(startX, endX)
- selectionBox.y = Math.min(startY, endY)
- selectionBox.width = Math.abs(endX - startX)
- selectionBox.height = Math.abs(endY - startY)
- }
- }
-
- onReleased: function(mouse) {
- if (mouse.button === Qt.LeftButton && isSelecting) {
- isSelecting = false
- selectionBox.visible = false
-
- if (selectionBox.width > 5 && selectionBox.height > 5) {
- // Area selection
- areaSelected(selectionBox.x, selectionBox.y,
- selectionBox.x + selectionBox.width,
- selectionBox.y + selectionBox.height)
- } else {
- // Point selection
- mapClicked(mouse.x, mouse.y)
- }
- }
- }
- }
-
- // Selection box
- Rectangle {
- id: selectionBox
- visible: false
- border.color: "white"
- border.width: 1
- color: "transparent"
- }
- }
-
- // Edge scrolling areas
- MouseArea {
- id: leftEdge
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- width: 10
- hoverEnabled: true
-
- onEntered: {
- scrollTimer.direction = "left"
- scrollTimer.start()
- }
- onExited: scrollTimer.stop()
- }
-
- MouseArea {
- id: rightEdge
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- width: 10
- hoverEnabled: true
-
- onEntered: {
- scrollTimer.direction = "right"
- scrollTimer.start()
- }
- onExited: scrollTimer.stop()
- }
-
- MouseArea {
- id: topEdge
- anchors.top: parent.top
- anchors.left: parent.left
- anchors.right: parent.right
- height: 10
- hoverEnabled: true
-
- onEntered: {
- scrollTimer.direction = "up"
- scrollTimer.start()
- }
- onExited: scrollTimer.stop()
- }
-
- MouseArea {
- id: bottomEdge
- anchors.bottom: parent.bottom
- anchors.left: parent.left
- anchors.right: parent.right
- height: 10
- hoverEnabled: true
-
- onEntered: {
- scrollTimer.direction = "down"
- scrollTimer.start()
- }
- onExited: scrollTimer.stop()
- }
-
- Timer {
- id: scrollTimer
- interval: 16 // ~60 FPS
- repeat: true
-
- property string direction: ""
-
- onTriggered: {
- // Handle camera movement based on direction
- console.log("Edge scroll:", direction)
- }
- }
-
- // Keyboard handling
- Keys.onPressed: function(event) {
- switch (event.key) {
- case Qt.Key_W:
- console.log("Move camera forward")
- break
- case Qt.Key_S:
- console.log("Move camera backward")
- break
- case Qt.Key_A:
- console.log("Move camera left")
- break
- case Qt.Key_D:
- console.log("Move camera right")
- break
- case Qt.Key_Q:
- console.log("Rotate camera left")
- break
- case Qt.Key_E:
- console.log("Rotate camera right")
- break
- case Qt.Key_R:
- console.log("Move camera up")
- break
- case Qt.Key_F:
- console.log("Move camera down")
- break
- }
- }
-
- focus: true
- }
|