CursorManager.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import QtQuick 2.15
  2. Item {
  3. id: cursorManager
  4. property string currentMode: "normal"
  5. property var cursorItem: null
  6. function updateCursor(mode) {
  7. currentMode = mode;
  8. if (cursorItem) {
  9. cursorItem.destroy();
  10. cursorItem = null;
  11. }
  12. switch (mode) {
  13. case "attack":
  14. cursorItem = attackCursorComponent.createObject(cursorManager);
  15. break;
  16. case "guard":
  17. cursorItem = guardCursorComponent.createObject(cursorManager);
  18. break;
  19. case "patrol":
  20. cursorItem = patrolCursorComponent.createObject(cursorManager);
  21. break;
  22. default:
  23. break;
  24. }
  25. }
  26. Component {
  27. id: attackCursorComponent
  28. Canvas {
  29. width: 32
  30. height: 32
  31. onPaint: {
  32. var ctx = getContext("2d");
  33. ctx.clearRect(0, 0, width, height);
  34. ctx.strokeStyle = "#e74c3c";
  35. ctx.lineWidth = 2;
  36. ctx.beginPath();
  37. ctx.moveTo(16, 4);
  38. ctx.lineTo(16, 28);
  39. ctx.stroke();
  40. ctx.beginPath();
  41. ctx.moveTo(4, 16);
  42. ctx.lineTo(28, 16);
  43. ctx.stroke();
  44. ctx.fillStyle = "#e74c3c";
  45. ctx.beginPath();
  46. ctx.arc(16, 16, 3, 0, Math.PI * 2);
  47. ctx.fill();
  48. ctx.strokeStyle = "#c0392b";
  49. ctx.lineWidth = 2;
  50. ctx.beginPath();
  51. ctx.moveTo(8, 12);
  52. ctx.lineTo(8, 8);
  53. ctx.lineTo(12, 8);
  54. ctx.stroke();
  55. ctx.beginPath();
  56. ctx.moveTo(20, 8);
  57. ctx.lineTo(24, 8);
  58. ctx.lineTo(24, 12);
  59. ctx.stroke();
  60. ctx.beginPath();
  61. ctx.moveTo(8, 20);
  62. ctx.lineTo(8, 24);
  63. ctx.lineTo(12, 24);
  64. ctx.stroke();
  65. ctx.beginPath();
  66. ctx.moveTo(20, 24);
  67. ctx.lineTo(24, 24);
  68. ctx.lineTo(24, 20);
  69. ctx.stroke();
  70. }
  71. }
  72. }
  73. Component {
  74. id: guardCursorComponent
  75. Canvas {
  76. width: 32
  77. height: 32
  78. onPaint: {
  79. var ctx = getContext("2d");
  80. ctx.clearRect(0, 0, width, height);
  81. ctx.fillStyle = "#3498db";
  82. ctx.strokeStyle = "#2980b9";
  83. ctx.lineWidth = 2;
  84. ctx.beginPath();
  85. ctx.moveTo(16, 6);
  86. ctx.lineTo(24, 10);
  87. ctx.lineTo(24, 18);
  88. ctx.lineTo(16, 26);
  89. ctx.lineTo(8, 18);
  90. ctx.lineTo(8, 10);
  91. ctx.closePath();
  92. ctx.fill();
  93. ctx.stroke();
  94. ctx.strokeStyle = "#ecf0f1";
  95. ctx.lineWidth = 2;
  96. ctx.beginPath();
  97. ctx.moveTo(13, 16);
  98. ctx.lineTo(15, 18);
  99. ctx.lineTo(19, 12);
  100. ctx.stroke();
  101. }
  102. }
  103. }
  104. Component {
  105. id: patrolCursorComponent
  106. Canvas {
  107. width: 32
  108. height: 32
  109. onPaint: {
  110. var ctx = getContext("2d");
  111. ctx.clearRect(0, 0, width, height);
  112. ctx.fillStyle = "#27ae60";
  113. ctx.strokeStyle = "#229954";
  114. ctx.lineWidth = 2;
  115. ctx.beginPath();
  116. ctx.arc(16, 16, 10, 0, Math.PI * 2);
  117. ctx.stroke();
  118. ctx.fillStyle = "#27ae60";
  119. ctx.beginPath();
  120. ctx.moveTo(26, 16);
  121. ctx.lineTo(22, 13);
  122. ctx.lineTo(22, 19);
  123. ctx.closePath();
  124. ctx.fill();
  125. ctx.beginPath();
  126. ctx.moveTo(6, 16);
  127. ctx.lineTo(10, 13);
  128. ctx.lineTo(10, 19);
  129. ctx.closePath();
  130. ctx.fill();
  131. ctx.beginPath();
  132. ctx.arc(16, 16, 3, 0, Math.PI * 2);
  133. ctx.fill();
  134. }
  135. }
  136. }
  137. }