--- a/hedgewars/hwLibrary.pas Sat Nov 21 17:07:06 2015 +0300
+++ b/hedgewars/hwLibrary.pas Sat Nov 21 23:56:41 2015 +0300
@@ -182,6 +182,7 @@
passNetData,
sendChatLine,
joinRoom,
+ partRoom,
// dunno what these are
RunEngine,
--- a/hedgewars/uFLGameConfig.pas Sat Nov 21 17:07:06 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas Sat Nov 21 23:56:41 2015 +0300
@@ -160,7 +160,7 @@
teams[0].color:= 0;
teams[1]:= createRandomTeam;
teams[1].color:= 1;
- teams[1].botLevel:= 1;
+ teams[1].botLevel:= 3;
queueExecution;
end;
--- a/hedgewars/uFLNet.pas Sat Nov 21 17:07:06 2015 +0300
+++ b/hedgewars/uFLNet.pas Sat Nov 21 23:56:41 2015 +0300
@@ -17,7 +17,7 @@
function getCurrChar: char; forward;
type
- TNetState = (netDisconnected, netConnecting, netLoggedIn);
+ TNetState = (netDisconnected, netConnecting);
TParserState = record
cmd: TCmdType;
l: LongInt;
@@ -128,9 +128,21 @@
end;
procedure handler_SMS;
+var cmd: TCmdParamS;
+ f: boolean;
begin
- writeln('handler_SMS');
- handleTail()
+ cmd.cmd:= state.cmd;
+ cmd.str1:= getShortString;
+ if cmd.str1[0] = #0 then exit;
+ sendUI(mtNetData, @cmd, sizeof(cmd));
+
+ cmd.cmd:= Succ(state.cmd);
+ repeat
+ cmd.str1:= getShortString;
+ f:= cmd.str1[0] <> #0;
+ if f then
+ sendUI(mtNetData, @cmd, sizeof(cmd));
+ until not f
end;
procedure handler__i;
--- a/hedgewars/uFLNetProtocol.pas Sat Nov 21 17:07:06 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas Sat Nov 21 23:56:41 2015 +0300
@@ -5,6 +5,9 @@
procedure sendChatLine(msg: PChar); cdecl;
procedure joinRoom(roomName: PChar); cdecl;
+procedure partRoom(msg: PChar); cdecl;
+
+procedure ResetNetState;
implementation
uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet;
@@ -12,6 +15,8 @@
type
PHandler = procedure (var t: TCmdData);
+var isInRoom: boolean;
+
procedure handler_ASKPASSWORD(var p: TCmdParamS);
begin
end;
@@ -33,7 +38,10 @@
var s: string;
begin
s:= p.str1 + #10 + p.str2;
- sendUI(mtLobbyChatLine, @s[1], length(s));
+ if isInRoom then
+ sendUI(mtRoomChatLine, @s[1], length(s))
+ else
+ sendUI(mtLobbyChatLine, @s[1], length(s));
end;
procedure handler_CLIENT_FLAGS(var p: TCmdParamS);
@@ -87,7 +95,12 @@
procedure handler_JOINED_s(var s: TCmdParamS);
begin
if s.str1 = 'qmlfrontend' then // we joined a room
- sendNet('LIST');
+ begin
+ isInRoom:= true;
+ sendUI(mtMoveToRoom, nil, 0);
+ end;
+
+ sendUI(mtAddRoomClient, @s.str1[1], length(s.str1));
end;
procedure handler_JOINING(var p: TCmdParamS);
@@ -96,10 +109,13 @@
procedure handler_KICKED(var p: TCmdParam);
begin
+ isInRoom:= false;
+ sendUI(mtMoveToLobby, nil, 0);
end;
procedure handler_LEFT(var p: TCmdParamS);
begin
+ sendUI(mtRemoveLobbyClient, @p.str1[1], length(p.str1));
end;
procedure handler_LEFT_s(var s: TCmdParamS);
@@ -112,7 +128,11 @@
procedure handler_LOBBY_JOINED_s(var s: TCmdParamS);
begin
- if s.str1 = 'qmlfrontend' then sendNet('LIST');
+ if s.str1 = 'qmlfrontend' then
+ begin
+ sendUI(mtMoveToLobby, nil, 0);
+ sendNet('LIST');
+ end;
sendUI(mtAddLobbyClient, @s.str1[1], length(s.str1));
end;
@@ -276,5 +296,25 @@
sendNet(roomName);
end;
+procedure partRoom(msg: PChar); cdecl;
+var s: string;
+begin
+ if isInRoom then
+ begin
+ isInRoom:= false;
+ s:= 'PART';
+ if length(msg) > 0 then
+ s:= s + #10 + msg;
+ sendNet(s);
+ sendUI(mtMoveToLobby, nil, 0);
+ end
+end;
+
+
+procedure ResetNetState;
+begin
+ isInRoom:= false;
+end;
+
end.
--- a/hedgewars/uFLTypes.pas Sat Nov 21 17:07:06 2015 +0300
+++ b/hedgewars/uFLTypes.pas Sat Nov 21 23:56:41 2015 +0300
@@ -4,8 +4,9 @@
type
TMessageType = (mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam
, mtTeamColor, mtNetData, mtConnected, mtDisconnected, mtAddLobbyClient
- , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoom, mtUpdateRoom
- , mtRemoveRoom, mtError, mtWarning);
+ , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
+ , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
+ , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom);
TIPCMessage = record
str: shortstring;
--- a/qmlFrontend/flib.h Sat Nov 21 17:07:06 2015 +0300
+++ b/qmlFrontend/flib.h Sat Nov 21 23:56:41 2015 +0300
@@ -20,11 +20,16 @@
, MSG_ADDLOBBYCLIENT
, MSG_REMOVELOBBYCLIENT
, MSG_LOBBYCHATLINE
+ , MSG_ADDROOMCLIENT
+ , MSG_REMOVEROOMCLIENT
+ , MSG_ROOMCHATLINE
, MSG_ADDROOM
, MSG_UPDATEROOM
, MSG_REMOVEROOM
, MSG_ERROR
, MSG_WARNING
+ , MSG_MOVETOLOBBY
+ , MSG_MOVETOROOM
};
typedef union string255_
@@ -55,6 +60,7 @@
typedef void passNetData_t(const char * data);
typedef void sendChatLine_t(const char * msg);
typedef void joinRoom_t(const char * roomName);
+typedef void partRoom_t(const char * message);
typedef char **getThemesList_t();
typedef void freeThemesList_t(char **list);
--- a/qmlFrontend/hwengine.cpp Sat Nov 21 17:07:06 2015 +0300
+++ b/qmlFrontend/hwengine.cpp Sat Nov 21 23:56:41 2015 +0300
@@ -38,9 +38,10 @@
passNetData_t * flibPassNetData;
sendChatLine_t * flibSendChatLine;
joinRoom_t * flibJoinRoom;
+ partRoom_t * flibPartRoom;
}
-Q_DECLARE_METATYPE(MessageType);
+Q_DECLARE_METATYPE(MessageType)
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) :
QObject(parent),
@@ -86,6 +87,7 @@
flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData");
flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine");
flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom");
+ flibPartRoom = (partRoom_t*) hwlib.resolve("partRoom");
flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
@@ -202,6 +204,20 @@
emit lobbyChatLine(l[0], l[1]);
break;
}
+ case MSG_ADDROOMCLIENT: {
+ emit roomClientAdded(QString::fromUtf8(msg));
+ break;
+ }
+ case MSG_REMOVEROOMCLIENT: {
+ QStringList l = QString::fromUtf8(msg).split('\n');
+ emit roomClientRemoved(l[0], l[1]);
+ break;
+ }
+ case MSG_ROOMCHATLINE: {
+ QStringList l = QString::fromUtf8(msg).split('\n');
+ emit roomChatLine(l[0], l[1]);
+ break;
+ }
case MSG_ADDROOM: {
QStringList l = QString::fromUtf8(msg).split('\n');
emit roomAdded(0, l[1], l[2].toInt(), l[3].toInt(), l[4], l[5], l[6], l[7], l[8]);
@@ -224,6 +240,14 @@
emit warningMessage(QString::fromUtf8(msg));
break;
}
+ case MSG_MOVETOLOBBY: {
+ emit movedToLobby();
+ break;
+ }
+ case MSG_MOVETOROOM: {
+ emit movedToRoom();
+ break;
+ }
}
}
@@ -310,6 +334,11 @@
flibJoinRoom(roomName.toUtf8().constData());
}
+void HWEngine::partRoom(const QString &message)
+{
+ flibPartRoom(message.toUtf8().constData());
+}
+
void HWEngine::setTheme(const QString &theme)
{
flibSetTheme(theme.toUtf8().constData());
--- a/qmlFrontend/hwengine.h Sat Nov 21 17:07:06 2015 +0300
+++ b/qmlFrontend/hwengine.h Sat Nov 21 23:56:41 2015 +0300
@@ -39,6 +39,7 @@
Q_INVOKABLE void sendChatMessage(const QString & msg);
Q_INVOKABLE void joinRoom(const QString & roomName);
+ Q_INVOKABLE void partRoom(const QString & message);
signals:
void errorMessage(const QString & message);
@@ -60,6 +61,13 @@
void lobbyClientRemoved(const QString & clientName, const QString & reason);
void lobbyChatLine(const QString & nickname, const QString & line);
+ void roomClientAdded(const QString & clientName);
+ void roomClientRemoved(const QString & clientName, const QString & reason);
+ void roomChatLine(const QString & nickname, const QString & line);
+
+ void movedToLobby();
+ void movedToRoom();
+
void roomAdded(quint32 flags
, const QString & name
, int players
--- a/qmlFrontend/qml/qmlFrontend/Chat.qml Sat Nov 21 17:07:06 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Chat.qml Sat Nov 21 23:56:41 2015 +0300
@@ -2,19 +2,17 @@
import Hedgewars.Engine 1.0
Rectangle {
- id: chat
color: "#15193a"
radius: 8
border.width: 4
- opacity: 1
border.color: "#ea761d"
ListView {
id: chatLines
x: 0
- y: 0
width: parent.width - clientsList.width
- height: parent.height - input.height
+ anchors.top: parent.top
+ anchors.bottom: input.top
focus: true
clip: true
highlightFollowsCurrentItem: true
@@ -61,19 +59,14 @@
chatLinesModel.remove(0)
chatLines.currentIndex = chatLinesModel.count - 1
}
-
- Connections {
- target: HWEngine
- onLobbyChatLine: chatLines.addLine(nickname, line)
- }
}
TextInput {
id: input
x: 0
- y: chatLines.height
width: chatLines.width
height: 24
+ anchors.bottom: parent.bottom
color: "#eccd2f"
onAccepted: {
@@ -115,22 +108,24 @@
}
}
+ }
- Connections {
- target: HWEngine
- onLobbyClientAdded: {
- chatClientsModel.append({"isAdmin": false, "name": clientName})
- chatLines.addLine("***", qsTr("%1 joined").arg(clientName))
- }
- onLobbyClientRemoved: {
- var i = chatClientsModel.count - 1;
- while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;
+ function addChatLine(nickname, line) {
+ chatLines.addLine(nickname, line)
+ }
- if(i >= 0) {
- chatClientsModel.remove(i, 1);
- chatLines.addLine("***", qsTr("%1 quit (%2)").arg(clientName).arg(reason))
- }
- }
+ function addClient(clientName) {
+ chatClientsModel.append({"isAdmin": false, "name": clientName})
+ chatLines.addLine("***", qsTr("%1 joined").arg(clientName))
+ }
+
+ function removeClient(clientName, reason) {
+ var i = chatClientsModel.count - 1;
+ while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;
+
+ if(i >= 0) {
+ chatClientsModel.remove(i, 1);
+ chatLines.addLine("***", qsTr("%1 quit (%2)").arg(clientName).arg(reason))
}
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlFrontend/qml/qmlFrontend/Lobby.qml Sat Nov 21 23:56:41 2015 +0300
@@ -0,0 +1,110 @@
+import QtQuick 2.0
+import Hedgewars.Engine 1.0
+
+Rectangle {
+ ListView {
+ id: roomsList
+ x: 20
+ y: 0
+ width: parent.width
+ height: parent.height - x
+ focus: true
+ clip: true
+
+ model: ListModel {
+ id: roomsListModel
+ }
+
+ delegate: Rectangle {
+ id: roomDelegate
+ height: 24
+ width: parent.width
+ color: "transparent"
+
+ Row {
+ spacing: 8;
+ Text {
+ text: name
+ }
+ Text {
+ text: players + " / " + teams
+ }
+ Text {
+ text: host
+ }
+ Text {
+ text: map
+ }
+ Text {
+ text: script
+ }
+ Text {
+ text: scheme
+ }
+ Text {
+ text: weapons
+ }
+ }
+
+ MouseArea {
+ z: 1
+ anchors.fill: parent
+ onDoubleClicked: HWEngine.joinRoom(name);
+ }
+ }
+
+ Connections {
+ target: HWEngine
+ onRoomAdded: roomsListModel.append({
+ "name" : name
+ , "players": players
+ , "teams": teams
+ , "host": host
+ , "map": map
+ , "script": script
+ , "scheme": scheme
+ , "weapons": weapons
+ })
+ onRoomUpdated: {
+ var i = roomsListModel.count - 1;
+ while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
+
+ if(i >= 0) {
+ roomsListModel.set(i, {
+ "name" : newName
+ , "players": players
+ , "teams": teams
+ , "host": host
+ , "map": map
+ , "script": script
+ , "scheme": scheme
+ , "weapons": weapons
+ })
+ }
+ }
+ onRoomRemoved: {
+ var i = roomsListModel.count - 1;
+ while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
+
+ if(i >= 0) roomsListModel.remove(i, 1)
+ }
+ }
+ }
+
+ Chat {
+ id: lobbyChat;
+ x: 0;
+ y: 300;
+ width: parent.width;
+ height: parent.height - y;
+
+ Connections {
+ target: HWEngine
+ onLobbyChatLine: lobbyChat.addChatLine(nickname, line)
+ onLobbyClientAdded: lobbyChat.addClient(clientName)
+ onLobbyClientRemoved: lobbyChat.removeClient(clientName, reason)
+ }
+ }
+}
+
+
--- a/qmlFrontend/qml/qmlFrontend/LobbyPage.qml Sat Nov 21 17:07:06 2015 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-import QtQuick 2.0
-import Hedgewars.Engine 1.0
-
-Rectangle {
- ListView {
- id: roomsList
- x: 20
- y: 0
- width: parent.width
- height: parent.height - x
- focus: true
- clip: true
-
- model: ListModel {
- id: roomsListModel
- }
-
- delegate: Rectangle {
- id: roomDelegate
- height: 24
- width: parent.width
- color: "transparent"
-
- Row {
- spacing: 8;
- Text {
- text: name
- }
- Text {
- text: players + " / " + teams
- }
- Text {
- text: host
- }
- Text {
- text: map
- }
- Text {
- text: script
- }
- Text {
- text: scheme
- }
- Text {
- text: weapons
- }
- }
-
- MouseArea {
- z: 1
- anchors.fill: parent
- onDoubleClicked: HWEngine.joinRoom(name);
- }
- }
-
- Connections {
- target: HWEngine
- onRoomAdded: roomsListModel.append({
- "name" : name
- , "players": players
- , "teams": teams
- , "host": host
- , "map": map
- , "script": script
- , "scheme": scheme
- , "weapons": weapons
- })
- onRoomUpdated: {
- var i = roomsListModel.count - 1;
- while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
-
- if(i >= 0) {
- roomsListModel.set(i, {
- "name" : newName
- , "players": players
- , "teams": teams
- , "host": host
- , "map": map
- , "script": script
- , "scheme": scheme
- , "weapons": weapons
- })
- }
- }
- onRoomRemoved: {
- var i = roomsListModel.count - 1;
- while ((i >= 0) && (roomsListModel.get(i).name !== name)) --i
-
- if(i >= 0) roomsListModel.remove(i, 1)
- }
- }
- }
-
- Chat {
- id: lobbyChat;
- x: 0;
- y: 300;
- width: parent.width;
- height: parent.height - y;
- }
-}
-
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlFrontend/qml/qmlFrontend/Room.qml Sat Nov 21 23:56:41 2015 +0300
@@ -0,0 +1,29 @@
+import QtQuick 2.0
+import Hedgewars.Engine 1.0
+
+Rectangle {
+ HWButton {
+ id: btnBack
+ width: 40
+ height: 40
+ anchors.left: parent.left
+ anchors.bottom: parent.bottom
+
+ onClicked: HWEngine.partRoom("")
+ }
+
+ Chat {
+ id: roomChat;
+ x: 0;
+ width: parent.width;
+ height: 250;
+ anchors.bottom: btnBack.top
+
+ Connections {
+ target: HWEngine
+ onRoomChatLine: roomChat.addChatLine(nickname, line)
+ onRoomClientAdded: roomChat.addClient(clientName)
+ onRoomClientRemoved: roomChat.removeClient(clientName, reason)
+ }
+ }
+}
--- a/qmlFrontend/qml/qmlFrontend/main.qml Sat Nov 21 17:07:06 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/main.qml Sat Nov 21 23:56:41 2015 +0300
@@ -6,22 +6,28 @@
width: 800
height: 600
- property variant pagesList : [
+ property variant pagesList : [
"First"
, "LocalGame"
, "GameConfig"
, "Connect"
- , "LobbyPage"
+ , "Lobby"
+ , "Room"
];
property string currentPage : "First";
Repeater {
- model: pagesList;
+ id: pagesView
+ model: pagesList
+
+ function loadPage(page) {
+ // somehow load the page (when Loader has asynchronous == true)
+ }
delegate: Loader {
active: false
- asynchronous: true
+ asynchronous: false
anchors.fill: parent
visible: (currentPage === modelData)
source: "%1.qml".arg(modelData)
@@ -72,7 +78,12 @@
Connections {
target: HWEngine
- onNetConnected: currentPage = "LobbyPage";
+ onNetConnected: {
+ pagesView.loadPage("Lobby");
+ pagesView.loadPage("Room");
+ }
+ onMovedToLobby: currentPage = "Lobby";
+ onMovedToRoom: currentPage = "Room";
onNetDisconnected: currentPage = "First";
onWarningMessage: warningsBox.showMessage(message);
onErrorMessage: warningsBox.showMessage(message);
--- a/qmlFrontend/qmlFrontend.qrc Sat Nov 21 17:07:06 2015 +0300
+++ b/qmlFrontend/qmlFrontend.qrc Sat Nov 21 23:56:41 2015 +0300
@@ -7,7 +7,8 @@
<file>qml/qmlFrontend/LocalGame.qml</file>
<file>qml/qmlFrontend/main.qml</file>
<file>qml/qmlFrontend/Connect.qml</file>
- <file>qml/qmlFrontend/LobbyPage.qml</file>
<file>qml/qmlFrontend/Chat.qml</file>
+ <file>qml/qmlFrontend/Room.qml</file>
+ <file>qml/qmlFrontend/Lobby.qml</file>
</qresource>
</RCC>