qmlFrontend/qml/qmlFrontend/Lobby.qml
branchqmlfrontend
changeset 11424 86c13e5662f1
parent 11423 e045dc60c37e
child 11434 23912c93935a
equal deleted inserted replaced
11423:e045dc60c37e 11424:86c13e5662f1
       
     1 import QtQuick 2.0
       
     2 import Hedgewars.Engine 1.0
       
     3 
       
     4 Rectangle {
       
     5     ListView {
       
     6         id: roomsList
       
     7         x: 20
       
     8         y: 0
       
     9         width: parent.width
       
    10         height: parent.height - x
       
    11         focus: true
       
    12         clip: true
       
    13 
       
    14         model: ListModel {
       
    15             id: roomsListModel
       
    16         }
       
    17 
       
    18         delegate: Rectangle {
       
    19             id: roomDelegate
       
    20             height: 24
       
    21             width: parent.width
       
    22             color: "transparent"
       
    23 
       
    24             Row {
       
    25                 spacing: 8;
       
    26                 Text {
       
    27                     text: name
       
    28                 }
       
    29                 Text {
       
    30                     text: players + " / " + teams
       
    31                 }
       
    32                 Text {
       
    33                     text: host
       
    34                 }
       
    35                 Text {
       
    36                     text: map
       
    37                 }
       
    38                 Text {
       
    39                     text: script
       
    40                 }
       
    41                 Text {
       
    42                     text: scheme
       
    43                 }
       
    44                 Text {
       
    45                     text: weapons
       
    46                 }
       
    47             }
       
    48 
       
    49             MouseArea {
       
    50                  z: 1
       
    51                  anchors.fill: parent
       
    52                  onDoubleClicked: HWEngine.joinRoom(name);
       
    53             }
       
    54         }
       
    55 
       
    56         Connections {
       
    57             target: HWEngine
       
    58             onRoomAdded: roomsListModel.append({
       
    59                                "name" : name
       
    60                                , "players": players
       
    61                                , "teams": teams
       
    62                                , "host": host
       
    63                                , "map": map
       
    64                                , "script": script
       
    65                                , "scheme": scheme
       
    66                                , "weapons": weapons
       
    67                            })
       
    68             onRoomUpdated: {
       
    69                 var i = roomsListModel.count - 1;
       
    70                 while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
       
    71 
       
    72                 if(i >= 0) {
       
    73                     roomsListModel.set(i, {
       
    74                                            "name" : newName
       
    75                                            , "players": players
       
    76                                            , "teams": teams
       
    77                                            , "host": host
       
    78                                            , "map": map
       
    79                                            , "script": script
       
    80                                            , "scheme": scheme
       
    81                                            , "weapons": weapons
       
    82                                        })
       
    83                 }
       
    84             }
       
    85             onRoomRemoved: {
       
    86                 var i = roomsListModel.count - 1;
       
    87                 while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
       
    88 
       
    89                 if(i >= 0) roomsListModel.remove(i, 1)
       
    90             }
       
    91         }
       
    92     }
       
    93 
       
    94     Chat {
       
    95         id: lobbyChat;
       
    96         x: 0;
       
    97         y: 300;
       
    98         width: parent.width;
       
    99         height: parent.height - y;
       
   100 
       
   101         Connections {
       
   102             target: HWEngine
       
   103             onLobbyChatLine: lobbyChat.addChatLine(nickname, line)
       
   104             onLobbyClientAdded: lobbyChat.addClient(clientName)
       
   105             onLobbyClientRemoved: lobbyChat.removeClient(clientName, reason)
       
   106         }
       
   107     }
       
   108 }
       
   109 
       
   110