ObjectivesPanel.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import StandardOfIron 1.0
  5. Item {
  6. id: root
  7. property var mission_objectives: null
  8. signal closeRequested()
  9. function refreshObjectives() {
  10. if (typeof game !== 'undefined' && game.get_current_mission_objectives)
  11. mission_objectives = game.get_current_mission_objectives();
  12. else
  13. mission_objectives = null;
  14. }
  15. anchors.fill: parent
  16. z: 10
  17. focus: true
  18. Keys.onPressed: function(event) {
  19. if (event.key === Qt.Key_Escape) {
  20. root.closeRequested();
  21. event.accepted = true;
  22. }
  23. }
  24. Component.onCompleted: {
  25. refreshObjectives();
  26. }
  27. onVisibleChanged: {
  28. if (visible)
  29. refreshObjectives();
  30. }
  31. Rectangle {
  32. anchors.fill: parent
  33. color: Theme.dim
  34. }
  35. Rectangle {
  36. id: container
  37. width: Math.min(parent.width * 0.7, 800)
  38. height: Math.min(parent.height * 0.8, 600)
  39. anchors.centerIn: parent
  40. radius: Theme.radiusPanel
  41. color: Theme.panelBase
  42. border.color: Theme.panelBr
  43. border.width: 1
  44. opacity: 0.98
  45. ColumnLayout {
  46. anchors.fill: parent
  47. anchors.margins: Theme.spacingXLarge
  48. spacing: Theme.spacingLarge
  49. RowLayout {
  50. Layout.fillWidth: true
  51. spacing: Theme.spacingMedium
  52. Label {
  53. text: qsTr("Mission Objectives")
  54. color: Theme.textMain
  55. font.pointSize: Theme.fontSizeHero
  56. font.bold: true
  57. Layout.fillWidth: true
  58. }
  59. StyledButton {
  60. text: "×"
  61. Layout.preferredWidth: 40
  62. Layout.preferredHeight: 40
  63. onClicked: root.closeRequested()
  64. }
  65. }
  66. Rectangle {
  67. Layout.fillWidth: true
  68. Layout.preferredHeight: 1
  69. color: Theme.border
  70. }
  71. ScrollView {
  72. id: objectivesScroll
  73. Layout.fillWidth: true
  74. Layout.fillHeight: true
  75. clip: true
  76. contentWidth: objectivesScroll.availableWidth
  77. ColumnLayout {
  78. width: objectivesScroll.availableWidth
  79. spacing: Theme.spacingLarge
  80. ColumnLayout {
  81. Layout.fillWidth: true
  82. spacing: Theme.spacingSmall
  83. visible: !!(mission_objectives && mission_objectives.title)
  84. Label {
  85. text: mission_objectives && mission_objectives.title ? mission_objectives.title : ""
  86. color: Theme.textMain
  87. font.pointSize: Theme.fontSizeTitle
  88. font.bold: true
  89. wrapMode: Text.WordWrap
  90. Layout.fillWidth: true
  91. }
  92. Label {
  93. text: mission_objectives && mission_objectives.summary ? mission_objectives.summary : ""
  94. color: Theme.textSubLite
  95. font.pointSize: Theme.fontSizeMedium
  96. wrapMode: Text.WordWrap
  97. Layout.fillWidth: true
  98. }
  99. }
  100. ColumnLayout {
  101. Layout.fillWidth: true
  102. spacing: Theme.spacingMedium
  103. visible: !!(mission_objectives && mission_objectives.victory_conditions && mission_objectives.victory_conditions.length > 0)
  104. Label {
  105. text: qsTr("Victory Conditions")
  106. color: Theme.successText
  107. font.pointSize: Theme.fontSizeLarge
  108. font.bold: true
  109. Layout.fillWidth: true
  110. }
  111. Repeater {
  112. model: mission_objectives && mission_objectives.victory_conditions ? mission_objectives.victory_conditions : []
  113. delegate: Rectangle {
  114. Layout.fillWidth: true
  115. Layout.preferredHeight: victory_content.implicitHeight + Theme.spacingMedium * 2
  116. radius: Theme.radiusMedium
  117. color: Theme.successBg
  118. border.color: Theme.successBr
  119. border.width: 1
  120. RowLayout {
  121. id: victory_content
  122. anchors.fill: parent
  123. anchors.margins: Theme.spacingMedium
  124. spacing: Theme.spacingMedium
  125. Label {
  126. text: "✓"
  127. color: Theme.successText
  128. font.pointSize: Theme.fontSizeLarge
  129. font.bold: true
  130. Layout.alignment: Qt.AlignTop
  131. }
  132. Label {
  133. text: modelData.description || qsTr("Complete the objective")
  134. color: Theme.textMain
  135. font.pointSize: Theme.fontSizeMedium
  136. wrapMode: Text.WordWrap
  137. Layout.fillWidth: true
  138. }
  139. }
  140. }
  141. }
  142. }
  143. ColumnLayout {
  144. Layout.fillWidth: true
  145. spacing: Theme.spacingMedium
  146. visible: !!(mission_objectives && mission_objectives.defeat_conditions && mission_objectives.defeat_conditions.length > 0)
  147. Label {
  148. text: qsTr("Defeat Conditions")
  149. color: Theme.removeColor
  150. font.pointSize: Theme.fontSizeLarge
  151. font.bold: true
  152. Layout.fillWidth: true
  153. }
  154. Repeater {
  155. model: mission_objectives && mission_objectives.defeat_conditions ? mission_objectives.defeat_conditions : []
  156. delegate: Rectangle {
  157. Layout.fillWidth: true
  158. Layout.preferredHeight: defeat_content.implicitHeight + Theme.spacingMedium * 2
  159. radius: Theme.radiusMedium
  160. color: Theme.dangerBg
  161. border.color: Theme.dangerBr
  162. border.width: 1
  163. RowLayout {
  164. id: defeat_content
  165. anchors.fill: parent
  166. anchors.margins: Theme.spacingMedium
  167. spacing: Theme.spacingMedium
  168. Label {
  169. text: "✗"
  170. color: Theme.removeColor
  171. font.pointSize: Theme.fontSizeLarge
  172. font.bold: true
  173. Layout.alignment: Qt.AlignTop
  174. }
  175. Label {
  176. text: modelData.description || qsTr("Avoid this condition")
  177. color: Theme.removeColor
  178. font.pointSize: Theme.fontSizeMedium
  179. wrapMode: Text.WordWrap
  180. Layout.fillWidth: true
  181. }
  182. }
  183. }
  184. }
  185. }
  186. ColumnLayout {
  187. Layout.fillWidth: true
  188. spacing: Theme.spacingMedium
  189. visible: !!(mission_objectives && mission_objectives.optional_objectives && mission_objectives.optional_objectives.length > 0)
  190. Label {
  191. text: qsTr("Optional Objectives")
  192. color: Theme.accent
  193. font.pointSize: Theme.fontSizeLarge
  194. font.bold: true
  195. Layout.fillWidth: true
  196. }
  197. Repeater {
  198. model: mission_objectives && mission_objectives.optional_objectives ? mission_objectives.optional_objectives : []
  199. delegate: Rectangle {
  200. Layout.fillWidth: true
  201. Layout.preferredHeight: optional_content.implicitHeight + Theme.spacingMedium * 2
  202. radius: Theme.radiusMedium
  203. color: Theme.infoBg
  204. border.color: Theme.infoBr
  205. border.width: 1
  206. RowLayout {
  207. id: optional_content
  208. anchors.fill: parent
  209. anchors.margins: Theme.spacingMedium
  210. spacing: Theme.spacingMedium
  211. Label {
  212. text: "★"
  213. color: Theme.accent
  214. font.pointSize: Theme.fontSizeLarge
  215. font.bold: true
  216. Layout.alignment: Qt.AlignTop
  217. }
  218. Label {
  219. text: modelData.description || qsTr("Optional objective")
  220. color: Theme.textMain
  221. font.pointSize: Theme.fontSizeMedium
  222. wrapMode: Text.WordWrap
  223. Layout.fillWidth: true
  224. }
  225. }
  226. }
  227. }
  228. }
  229. Label {
  230. visible: !mission_objectives || (!mission_objectives.victory_conditions && !mission_objectives.defeat_conditions && !mission_objectives.optional_objectives)
  231. text: qsTr("No mission objectives available.\nThis may be a skirmish game or objectives have not been configured.")
  232. color: Theme.textDim
  233. font.pointSize: Theme.fontSizeMedium
  234. horizontalAlignment: Text.AlignHCenter
  235. wrapMode: Text.WordWrap
  236. Layout.fillWidth: true
  237. Layout.topMargin: Theme.spacingXLarge
  238. }
  239. }
  240. }
  241. RowLayout {
  242. Layout.fillWidth: true
  243. spacing: Theme.spacingMedium
  244. Item {
  245. Layout.fillWidth: true
  246. }
  247. StyledButton {
  248. text: qsTr("Close")
  249. onClicked: root.closeRequested()
  250. }
  251. }
  252. }
  253. }
  254. }