Menu.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.0
  5. View {
  6. id: menu
  7. property string action
  8. viewWidth: 250
  9. viewHeight: 350
  10. color: "#ffeecc"
  11. onClosed: {
  12. switch(action) {
  13. case "resume":
  14. mainTimer.start();
  15. break;
  16. case "reset":
  17. reset();
  18. break;
  19. case "new game":
  20. newGame();
  21. break;
  22. }
  23. }
  24. onClicked: {
  25. if (gameOn) {
  26. action = "resume"
  27. viewLoader.close(optionsButton.x + optionsButton.width / 2,
  28. optionsButton.y + optionsButton.height / 2);
  29. }
  30. }
  31. Column {
  32. id: buttonColumn
  33. anchors.centerIn: parent
  34. spacing: 15
  35. Button {
  36. id: resumeButton
  37. opacity: gameOn
  38. width: viewWidth * 0.8
  39. height: viewHeight * 0.15
  40. text: "Resume"
  41. onClicked: {
  42. action = "resume"
  43. viewLoader.close(optionsButton.x + optionsButton.width / 2,
  44. optionsButton.y + optionsButton.height / 2);
  45. }
  46. focus: gameOn
  47. KeyNavigation.up: menuExitButton
  48. KeyNavigation.down: restartButton
  49. }
  50. Button {
  51. id: restartButton
  52. opacity: gameOn
  53. width: viewWidth * 0.8
  54. height: viewHeight * 0.15
  55. text: "Restart"
  56. onClicked: {
  57. action = "reset";
  58. viewLoader.close(buttonColumn.x + x + width / 2,
  59. buttonColumn.y + y + height / 2);
  60. }
  61. KeyNavigation.up: resumeButton
  62. KeyNavigation.down: newGameButton
  63. }
  64. Button {
  65. id: newGameButton
  66. width: viewWidth * 0.8
  67. height: viewHeight * 0.15
  68. text: "New game"
  69. onClicked: {
  70. viewLoader.switchTo("WaitNote.qml",
  71. buttonColumn.x + x + width / 2,
  72. buttonColumn.y + y + height / 2);
  73. action = "new game";
  74. }
  75. focus: !gameOn
  76. KeyNavigation.up: gameOn ? restartButton : menuExitButton
  77. KeyNavigation.down: highScoresButton
  78. }
  79. Button {
  80. id: highScoresButton
  81. width: viewWidth * 0.8
  82. height: viewHeight * 0.15
  83. text: "High Scores"
  84. onClicked: viewLoader.switchTo("HighScores.qml",
  85. buttonColumn.x + x + width / 2,
  86. buttonColumn.y + y + height / 2);
  87. KeyNavigation.up: newGameButton
  88. KeyNavigation.down: menuExitButton
  89. }
  90. Button{
  91. id: menuExitButton
  92. width: viewWidth * 0.8
  93. height: viewHeight * 0.15
  94. text: "Exit"
  95. onClicked: Qt.quit();
  96. KeyNavigation.up: highScoresButton
  97. KeyNavigation.down: gameOn ? resumeButton : newGameButton
  98. }
  99. }
  100. }