qmlFrontend/qml/qmlFrontend/Lobby.qml
author unc0rr
Mon, 14 Dec 2015 00:24:03 +0300
branchqmlfrontend
changeset 11454 3c5d99013baf
parent 11434 23912c93935a
permissions -rw-r--r--
- Improve IPC handling in engine - Handle EM protocol command - Some fixes for net game
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     1
import QtQuick 2.0
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
     2
import Hedgewars.Engine 1.0
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     3
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     4
Rectangle {
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
     5
    ListView {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
     6
        id: roomsList
11454
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
     7
        anchors.top: parent.top
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
     8
        anchors.left: parent.left
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
     9
        anchors.right: parent.right
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
    10
        anchors.bottom: lobbyChat.top
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    11
        focus: true
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    12
        clip: true
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    13
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    14
        model: ListModel {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    15
            id: roomsListModel
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    16
        }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    17
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    18
        delegate: Rectangle {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    19
            id: roomDelegate
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    20
            height: 24
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    21
            width: parent.width
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    22
            color: "transparent"
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    23
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    24
            Row {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    25
                spacing: 8;
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    26
                Text {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    27
                    text: name
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    28
                }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    29
                Text {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    30
                    text: players + " / " + teams
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    31
                }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    32
                Text {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    33
                    text: host
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    34
                }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    35
                Text {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    36
                    text: map
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    37
                }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    38
                Text {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    39
                    text: script
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    40
                }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    41
                Text {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    42
                    text: scheme
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    43
                }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    44
                Text {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    45
                    text: weapons
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    46
                }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    47
            }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    48
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    49
            MouseArea {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    50
                 z: 1
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    51
                 anchors.fill: parent
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11422
diff changeset
    52
                 onDoubleClicked: HWEngine.joinRoom(name);
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    53
            }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    54
        }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    55
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    56
        Connections {
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    57
            target: HWEngine
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    58
            onRoomAdded: roomsListModel.append({
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    59
                               "name" : name
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    60
                               , "players": players
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    61
                               , "teams": teams
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    62
                               , "host": host
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    63
                               , "map": map
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    64
                               , "script": script
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    65
                               , "scheme": scheme
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    66
                               , "weapons": weapons
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    67
                           })
11422
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    68
            onRoomUpdated: {
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    69
                var i = roomsListModel.count - 1;
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    70
                while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    71
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    72
                if(i >= 0) {
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    73
                    roomsListModel.set(i, {
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    74
                                           "name" : newName
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    75
                                           , "players": players
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    76
                                           , "teams": teams
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    77
                                           , "host": host
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    78
                                           , "map": map
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    79
                                           , "script": script
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    80
                                           , "scheme": scheme
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    81
                                           , "weapons": weapons
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    82
                                       })
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    83
                }
c6c6a4b32cea Handle ROOM UPD
unc0rr
parents: 11419
diff changeset
    84
            }
11419
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
    85
            onRoomRemoved: {
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
    86
                var i = roomsListModel.count - 1;
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
    87
                while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
    88
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
    89
                if(i >= 0) roomsListModel.remove(i, 1)
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
    90
            }
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    91
        }
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    92
    }
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    93
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    94
    Chat {
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
    95
        id: lobbyChat;
11454
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
    96
        height: 300
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
    97
        anchors.top: undefined
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
    98
        anchors.left: parent.left
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
    99
        anchors.right: parent.right
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11434
diff changeset
   100
        anchors.bottom: parent.bottom
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   101
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   102
        Connections {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   103
            target: HWEngine
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11424
diff changeset
   104
            onNetConnected: lobbyChat.clear()
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   105
            onLobbyChatLine: lobbyChat.addChatLine(nickname, line)
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   106
            onLobbyClientAdded: lobbyChat.addClient(clientName)
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   107
            onLobbyClientRemoved: lobbyChat.removeClient(clientName, reason)
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   108
        }
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   109
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   110
}
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   111
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   112