123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- /*
- * Copyright (c) 2011 Nokia Corporation.
- */
- import Qt 4.7
- import "Game.js" as GameScript
- Rectangle {
- id: menu
- Text {
- id: title
- smooth: true
- anchors.bottom: menu.top
- anchors.horizontalCenter: menu.horizontalCenter
- color: "red"
- font.pixelSize: gameArea.width / 12
- font.bold: true
- horizontalAlignment: Text.AlignHCenter
- }
- border.color: "black"
- border.width: 2
- radius: 8
- smooth: true
- opacity: 0 // transparent by default
- color: "black"
- // gradient: Gradient {
- // GradientStop { position: 0.0; color: "white" }
- // GradientStop { position: 1.0; color: "black" }
- // }
- // Signals
- signal levelSelected(int levelIndex)
- signal resumeSelected()
- // Show level menu
- function showLevelMenu() {
- menuData.clear()
- title.text = "Select Your Level"
- var plugins = GameEngine.pluginList()
- for(var i=0;i<plugins.length;i++) {
- menuData.append({"name": plugins[i],"type":"0"})
- }
- menuData.append({"name": "About","type":"4"})
- menuData.append({"name": "Exit","type":"1"})
- menu.opacity = 0.8
- listView.focus = true
- }
- function showPauseMenu() {
- menuData.clear()
- title.text = "Resume level?"
- menuData.append({"name": "Resume","type":"2"})
- menuData.append({"name": "End Game","type":"3"})
- menu.opacity = 0.8
- listView.focus = true
- }
- // Hide menu
- function hideMenu() {
- menu.opacity = 0
- listView.focus = false
- }
- function menuItemSelected(index, type) {
- switch (type) {
- case "0": {
- // Level selection
- menu.levelSelected(index)
- break;
- }
- case "1": {
- // Exit
- Qt.quit()
- break;
- }
- case "2": {
- // Resume
- menu.resumeSelected()
- break;
- }
- case "3": {
- // End Game
- gameArea.endGame()
- break;
- }
- case "4": {
- // Show about
- gameArea.messageBox.showInfoMessage()
- break;
- }
- default: {
- break;
- }
- }
- }
- ListModel {
- id: menuData
- }
- ListView {
- id: listView
- clip: true
- anchors.fill: parent
- keyNavigationWraps: true
- function doSelect() {
- menu.menuItemSelected(listView.currentIndex,menuData.get(listView.currentIndex).type)
- }
- model: menuData
- delegate: MenuItem {
- id: menuItem
- selectedItem: menuItem.ListView.isCurrentItem ? true : false
- onItemSelected: {
- listView.currentIndex = model.index
- listView.doSelect()
- }
- }
- }
- }
|