demos/declarative/samegame/samegame.qml
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    44 import "SamegameCore/samegame.js" as Logic
    44 import "SamegameCore/samegame.js" as Logic
    45 
    45 
    46 Rectangle {
    46 Rectangle {
    47     id: screen
    47     id: screen
    48     width: 490; height: 720
    48     width: 490; height: 720
       
    49     property bool inAnotherDemo: false //Samegame often is just plonked straight into other demos
    49 
    50 
    50     SystemPalette { id: activePalette }
    51     SystemPalette { id: activePalette }
    51 
    52 
    52     Item {
    53     Item {
    53         width: parent.width
    54         width: parent.width
    85         anchors.centerIn: parent
    86         anchors.centerIn: parent
    86         z: 22;
    87         z: 22;
    87 
    88 
    88         Behavior on width {
    89         Behavior on width {
    89             NumberAnimation {} 
    90             NumberAnimation {} 
    90             enabled: initialWidth != 0
    91             enabled: nameInputDialog.initialWidth != 0
    91         }
    92         }
    92 
    93 
       
    94         onOpened: nameInputText.focus = true;
       
    95         onClosed: {
       
    96             nameInputText.focus = false;
       
    97             if (nameInputText.text != "")
       
    98                 Logic.saveHighScore(nameInputText.text);
       
    99         }
    93         Text {
   100         Text {
    94             id: dialogText
   101             id: dialogText
    95             anchors { left: nameInputDialog.left; leftMargin: 20; verticalCenter: parent.verticalCenter }
   102             anchors { left: nameInputDialog.left; leftMargin: 20; verticalCenter: parent.verticalCenter }
    96             text: "You won! Please enter your name: "
   103             text: "You won! Please enter your name: "
    97         }
   104         }
       
   105         MouseArea {
       
   106             anchors.fill: parent
       
   107             onClicked: {
       
   108                 if (nameInputText.text == "")
       
   109                     nameInputText.openSoftwareInputPanel();
       
   110                 else
       
   111                     nameInputDialog.forceClose();
       
   112             }
       
   113         }
    98 
   114 
    99         TextInput {
   115         TextInput {
   100             id: nameInputText
   116             id: nameInputText
   101             anchors { verticalCenter: parent.verticalCenter; left: dialogText.right }
   117             anchors { verticalCenter: parent.verticalCenter; left: dialogText.right }
   102             focus: true
   118             focus: false
   103 
   119             autoScroll: false
       
   120             maximumLength: 24
   104             onTextChanged: {
   121             onTextChanged: {
   105                 var newWidth = nameInputText.width + dialogText.width + 40;
   122                 var newWidth = nameInputText.width + dialogText.width + 40;
   106                 if ( (newWidth > nameInputDialog.width && newWidth < screen.width) 
   123                 if ( (newWidth > nameInputDialog.width && newWidth < screen.width) 
   107                         || (nameInputDialog.width > nameInputDialog.initialWidth) )
   124                         || (nameInputDialog.width > nameInputDialog.initialWidth) )
   108                     nameInputDialog.width = newWidth;
   125                     nameInputDialog.width = newWidth;
   109             }
   126             }
   110             onAccepted: {
   127             onAccepted: {
   111                 if (nameInputDialog.opacity == 1 && nameInputText.text != "")
       
   112                     Logic.saveHighScore(nameInputText.text);
       
   113                 nameInputDialog.forceClose();
   128                 nameInputDialog.forceClose();
   114             }
   129             }
   115         }
   130         }
   116     }
   131     }
   117 
   132 
   127             text: "New Game" 
   142             text: "New Game" 
   128             onClicked: Logic.startNewGame()
   143             onClicked: Logic.startNewGame()
   129         }
   144         }
   130 
   145 
   131         Button {
   146         Button {
       
   147             visible: !inAnotherDemo
   132             text: "Quit"
   148             text: "Quit"
   133             anchors { left: newGameButton.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
   149             anchors { left: newGameButton.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
   134             onClicked: Qt.quit();
   150             onClicked: Qt.quit();
   135         }
   151         }
   136 
   152