- Decrease font size in chat
authorunc0rr
Sat, 03 Jan 2009 20:48:37 +0000
changeset 1577 e3e37c730dc0
parent 1576 a02353129a41
child 1578 f02806f66e00
- Decrease font size in chat - Add "Info" command to nick list, which shows only client version for now
QTfrontend/chatwidget.cpp
QTfrontend/chatwidget.h
QTfrontend/hwform.cpp
QTfrontend/main.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
netserver/HWProto.hs
netserver/Miscutils.hs
--- a/QTfrontend/chatwidget.cpp	Sat Jan 03 19:01:50 2009 +0000
+++ b/QTfrontend/chatwidget.cpp	Sat Jan 03 20:48:37 2009 +0000
@@ -1,6 +1,7 @@
 /*
  * Hedgewars, a free turn based strategy game
  * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com>
+ * Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,6 +21,7 @@
 #include <QListWidget>
 #include <QLineEdit>
 #include <QAction>
+#include <QApplication>
 
 #include "chatwidget.h"
 
@@ -27,40 +29,44 @@
   QWidget(parent),
   mainLayout(this)
 {
-  mainLayout.setSpacing(1);
-  mainLayout.setMargin(1);
-  mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
-  mainLayout.setColumnStretch(0, 75);
-  mainLayout.setColumnStretch(1, 25);
+	mainLayout.setSpacing(1);
+	mainLayout.setMargin(1);
+	mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
+	mainLayout.setColumnStretch(0, 75);
+	mainLayout.setColumnStretch(1, 25);
 
-  chatEditLine = new QLineEdit(this);
-  chatEditLine->setMaxLength(300);
-  connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+	chatEditLine = new QLineEdit(this);
+	chatEditLine->setMaxLength(300);
+	connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
 
-  mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
+	mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
 
-  chatText = new QTextBrowser(this);
-  chatText->setMinimumHeight(20);
-  chatText->setMinimumWidth(10);
-  chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-  mainLayout.addWidget(chatText, 0, 0);
+	chatText = new QTextBrowser(this);
+	chatText->setMinimumHeight(20);
+	chatText->setMinimumWidth(10);
+	chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+	mainLayout.addWidget(chatText, 0, 0);
 
-  chatNicks = new QListWidget(this);
-  chatNicks->setMinimumHeight(10);
-  chatNicks->setMinimumWidth(10);
-  chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-  chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
-  mainLayout.addWidget(chatNicks, 0, 1);
+	chatNicks = new QListWidget(this);
+	chatNicks->setMinimumHeight(10);
+	chatNicks->setMinimumWidth(10);
+	chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+	chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
+	mainLayout.addWidget(chatNicks, 0, 1);
 
-  QAction * acBan = new QAction(QAction::tr("Kick"), chatNicks);
-  connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onKick()));
-  chatNicks->insertAction(0, acBan);
+	QAction * acBan = new QAction(QAction::tr("Kick"), chatNicks);
+	connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onKick()));
+	chatNicks->insertAction(0, acBan);
+
+	QAction * acInfo = new QAction(QAction::tr("Info"), chatNicks);
+	connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo()));
+	chatNicks->insertAction(0, acInfo);
 }
 
 void HWChatWidget::returnPressed()
 {
-  emit chatLine(chatEditLine->text());
-  chatEditLine->clear();
+	emit chatLine(chatEditLine->text());
+	chatEditLine->clear();
 }
 
 void HWChatWidget::onChatString(const QString& str)
@@ -104,6 +110,13 @@
 		emit kick(curritem->text());
 }
 
+void HWChatWidget::onInfo()
+{
+	QListWidgetItem * curritem = chatNicks->currentItem();
+	if (curritem)
+		emit info(curritem->text());
+}
+
 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady)
 {
 	QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
--- a/QTfrontend/chatwidget.h	Sat Jan 03 19:01:50 2009 +0000
+++ b/QTfrontend/chatwidget.h	Sat Jan 03 20:48:37 2009 +0000
@@ -44,6 +44,7 @@
  signals:
   void chatLine(const QString& str);
   void kick(const QString & str);
+  void info(const QString & str);
 
  private:
   QGridLayout mainLayout;
@@ -55,6 +56,7 @@
  private slots:
   void returnPressed();
   void onKick();
+  void onInfo();
 };
 
 #endif // _CHAT_WIDGET_INCLUDED
--- a/QTfrontend/hwform.cpp	Sat Jan 03 19:01:50 2009 +0000
+++ b/QTfrontend/hwform.cpp	Sat Jan 03 20:48:37 2009 +0000
@@ -470,9 +470,14 @@
 		ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)),
 		hwnet, SLOT(chatLineToNet(const QString&)));
+	connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
+
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
 		hwnet, SLOT(kickPlayer(const QString&)));
-	connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
+	connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)),
+		hwnet, SLOT(infoPlayer(const QString&)));
+	connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)),
+		hwnet, SLOT(infoPlayer(const QString&)));
 
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)),
 		hwnet, SLOT(chatLineToLobby(const QString&)));
--- a/QTfrontend/main.cpp	Sat Jan 03 19:01:50 2009 +0000
+++ b/QTfrontend/main.cpp	Sat Jan 03 20:48:37 2009 +0000
@@ -118,7 +118,7 @@
 				"border-color: #ffcc00;"
 				"background-color: #0d0544;"
 				"color: #ffcc00;"
-				"font: bold 14px;"
+//				"font: bold 14px;"
 				"}"
 
 			"QSpinBox{"
--- a/QTfrontend/newnetclient.cpp	Sat Jan 03 19:01:50 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Sat Jan 03 20:48:37 2009 +0000
@@ -269,6 +269,21 @@
 		return;
 	}
 
+	if (lst[0] == "INFO") {
+		if(lst.size() < 2)
+		{
+			qWarning("Net: Empty INFO message");
+			return;
+		}
+		QStringList tmp = lst;
+		tmp.removeFirst();
+		if (netClientState == 2)
+			emit chatStringLobby(tmp.join("\n"));
+		else
+			emit chatStringFromNet(tmp.join("\n"));
+		return;
+	}
+
 	if (lst[0] == "READY") {
 		if(lst.size() != 2)
 		{
@@ -642,6 +657,11 @@
 	RawSendNet(QString("KICK%1%2").arg(delimeter).arg(nick));
 }
 
+void HWNewNet::infoPlayer(const QString & nick)
+{
+	RawSendNet(QString("INFO%1%2").arg(delimeter).arg(nick));
+}
+
 void HWNewNet::startGame()
 {
 	RawSendNet(QString("START_GAME"));
--- a/QTfrontend/newnetclient.h	Sat Jan 03 19:01:50 2009 +0000
+++ b/QTfrontend/newnetclient.h	Sat Jan 03 20:48:37 2009 +0000
@@ -144,6 +144,7 @@
   void askRoomsList();
   void gameFinished();
   void kickPlayer(const QString &);
+  void infoPlayer(const QString &);
   void startGame();
   void toggleRestrictJoins();
   void toggleRestrictTeamAdds();
--- a/netserver/HWProto.hs	Sat Jan 03 19:01:50 2009 +0000
+++ b/netserver/HWProto.hs	Sat Jan 03 20:48:37 2009 +0000
@@ -45,6 +45,7 @@
 answerConnected         = answerClientOnly ["CONNECTED", "Hedgewars server http://www.hedgewars.org/"]
 answerNotOwner          = answerClientOnly ["ERROR", "You do not own this team"]
 answerCannotCreateRoom  = answerClientOnly ["WARNING", "Cannot create more rooms"]
+answerInfo client       = answerClientOnly ["INFO", nick client, proto2ver $ protocol client]
 
 answerAbandoned           = answerOthersRoom ["BYE", "Room abandoned"]
 answerChatString nick msg = answerOthersRoom ["CHAT_STRING", nick, msg]
@@ -130,6 +131,17 @@
 handleCmd _ _ _ ["ERROR", msg] =
 	(noChangeClients, noChangeRooms, answerErrorMsg msg)
 
+handleCmd _ clients _ ["INFO", asknick] =
+	if noSuchClient then
+		(noChangeClients, noChangeRooms, [])
+	else
+		(noChangeClients, noChangeRooms, answerInfo client)
+	where
+		maybeClient = find (\cl -> asknick == nick cl) clients
+		noSuchClient = isNothing maybeClient
+		client = fromJust maybeClient
+
+
 -- check state and call state-dependent commmand handlers
 handleCmd client clients rooms cmd =
 	if null (nick client) || protocol client == 0 then
--- a/netserver/Miscutils.hs	Sat Jan 03 19:01:50 2009 +0000
+++ b/netserver/Miscutils.hs	Sat Jan 03 20:48:37 2009 +0000
@@ -181,3 +181,9 @@
 			team : teams
 		else
 			t : replaceTeam team teams
+
+proto2ver :: Word16 -> String
+proto2ver 17 = "0.9.7-dev"
+proto2ver 19 = "0.9.7"
+proto2ver 20 = "0.9.8-dev"
+proto2ver _ = "Unknown"
\ No newline at end of file