⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tables.cpp

📁 qgo-1.5.4-r3.tar.gz linux下一个很好玩的游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* *   tables.cpp = part of mainwindow */#include "talk_gui.h"#include "tables.h"#include "mainwin.h"#include "maintable.h"#include "playertable.h"#include "gamestable.h"#include "gs_globals.h"#include <qlineedit.h>//#include <qmultilineedit.h>//#include <qtextedit.h>#include <qtextbrowser.h> #include <qlayout.h>#include <qwidget.h>#include <math.h>#include <qtooltip.h>#include <qpalette.h>// prepare tables (clear, ...)void ClientWindow::prepare_tables(InfoType cmd){	switch (cmd)	{		case WHO: // delete player table		{			QListViewItemIterator lv(ListView_players);			for (QListViewItem *lvi; (lvi = lv.current());)			{				lv++;				delete lvi;			}			// set number of players to 0			myAccount->num_players = 0;			myAccount->num_watchedplayers = 0;			// use this for fast filling			playerListEmpty = true;			statusUsers->setText(" P: 0 / 0 ");			break;		}		case GAMES: // delete games table		{			QListViewItemIterator lv(ListView_games);			for (QListViewItem *lvi; (lvi = lv.current());)			{				lv++;				delete lvi;			}			// set number of games to 0			myAccount->num_games = 0;			statusGames->setText(" G: 0 / 0 ");			break;		}		case CHANNELS:		{			// delete channel info			channellist.clear();			statusChannel->setText("");/*			QListViewItemIterator lv(ListView_ch);			for (QListViewItem *lvi; (lvi = lv.current());)			{				lv++;				delete lvi;			}*/			// delete tooltips too			QToolTip::remove(statusChannel);			QToolTip::add(statusChannel, tr("Current channels and users"));			break;		}		default: // unknown command???			qWarning("unknown Command in 'prepare_tables()'");			break;	}}// return the rank of a given nameQString ClientWindow::getPlayerRk(QString player){	QListViewItemIterator lvp(ListView_players);	QListViewItem *lvpi;	// look for players in playerlist	for (; (lvpi = lvp.current()); lvp++)	{		// check if names are identical		if (lvpi->text(1) == player)		{			return lvpi->text(2);		}	}	return 0;}// check for exclude list entry of a given nameQString ClientWindow::getPlayerExcludeListEntry(QString player){	QListViewItemIterator lvp(ListView_players);	QListViewItem *lvpi;	if (DODEBUG)		qDebug(QString("getPlayerExcludeListEntry(%1)").arg(player));	// look for players in playerlist	for (; (lvpi = lvp.current()); lvp++)	{		// check if names are identical		if (lvpi->text(1) == player)		{			if (DODEBUG)				qDebug(QString("text(1) = %1, player = %2").arg(lvpi->text(1)).arg(player));			return lvpi->text(6);		}	}	return 0;}// take a new game from parservoid ClientWindow::slot_game(Game* g){	// insert into ListView	QListViewItemIterator lv(ListView_games);	if (g->running)	{		bool found = false;		GamesTableItem *lvi_mem = NULL;		// check if game already exists		if (!playerListEmpty)		{			QListViewItemIterator lvii = lv;			for (GamesTableItem *lvi; (lvi = static_cast<GamesTableItem*>(lvii.current())) && !found;)			{				lvii++;				// compare game id				if (lvi->text(0) == g->nr)				{					found = true;					lvi_mem = lvi;				}			}		}		else if (!g->H && !myAccount->num_games)		{			// skip games until initial table has loaded			qDebug("game skipped because no init table");			return;		}		QString excludeMark = "";		QString myMark = "B";				// check if exclude entry is done later		if (g->H) //g->status.length() > 1)		{			QString emw;			QString emb;			// no: do it now			emw = getPlayerExcludeListEntry(g->wname);			emb = getPlayerExcludeListEntry(g->bname);			// ensure that my game is listed first			if (emw && emw == "M" || emb && emb == "M")			{				myMark = "A";				excludeMark = "M";				// I'm playing, thus I'm open, except teaching games				if (emw && emw && (emw != "M" || emb != "M"))				{					// checkbox open					slot_checkbox(0, true);				}			}			else if (emw && emw == "W" || emb && emb == "W")			{				excludeMark = "W";			}		}				if (found)		{			// supersede entry			//lvi_mem->setText(0, g->nr);			lvi_mem->setText(1, g->wname);			lvi_mem->setText(2, g->wrank);			lvi_mem->setText(3, g->bname);			lvi_mem->setText(4, g->brank);			lvi_mem->setText(5, g->mv);			lvi_mem->setText(6, g->Sz);			lvi_mem->setText(7, g->H);			lvi_mem->setText(8, g->K);			lvi_mem->setText(9, g->By);			lvi_mem->setText(10, g->FR);			lvi_mem->setText(11, g->ob);//			lvi_mem->setText(6, g->status + " (" + g->ob + ")");			lvi_mem->setText(12, myMark + rkToKey(g->wrank) + g->wname.lower() + ":" + excludeMark);			lvi_mem->ownRepaint();		}		else		{			// from GAMES command or game info{...}			if (g->H)			{				lv = new GamesTableItem(ListView_games,					g->nr,					" " + g->wname,					g->wrank,					" " + g->bname,					g->brank,					g->mv,					g->Sz,					g->H,					g->K,					g->By,					g->FR,					g->ob);			}			else			{				lv = new GamesTableItem(ListView_games,					g->nr,					" " + g->wname,					g->wrank,					" " + g->bname,					g->brank,					g->mv,					g->Sz);			}			lv.current()->setText(12, myMark + rkToKey(g->wrank) + g->wname.lower() + ":" + excludeMark);			static_cast<GamesTableItem*>(lv.current())->ownRepaint();			// increase number of games			myAccount->num_games++;			statusGames->setText(" G: " + QString::number(myAccount->num_games) + " / " + QString::number(myAccount->num_observedgames) + " ");		}		// update player info if this is not a 'who'-result or if it's me		if (!g->H || myMark == "A") //g->status.length() < 2)		{			QListViewItemIterator lvp(ListView_players);			QListViewItem *lvpi;			int found = 0;			// look for players in playerlist			for (; (lvpi = lvp.current()) && found < 2;)			{				// check if names are identical				if (lvpi->text(1) == g->wname || lvpi->text(1) == g->bname)				{					lvpi->setText(3, g->nr);					found++;					// check if players has a rank					if (g->wrank == "??" || g->brank == "??")					{						// no rank given in case of continued game -> set rank in games table						if (lvpi->text(1) == g->wname)						{							lv.current()->setText(2, lvpi->text(2));							// correct sorting of col 2 -> set col 12							lv.current()->setText(12, myMark + rkToKey(lvpi->text(2)) + lvpi->text(1).lower() + ":" + excludeMark);						}						// no else case! bplayer could be identical to wplayer!						if (lvpi->text(1) == g->bname)							lv.current()->setText(4, lvpi->text(2));						static_cast<GamesTableItem*>(lv.current())->ownRepaint();					}				}				lvp++;			}			ListView_games->sort();		}	}	else	{		// from game info {...}		bool found = false;		QString game_id;		if (g->nr != "@")		{			for (QListViewItem *lvi; (lvi = lv.current()) && !found;)			{				lv++;				// compare game id				if (lvi->text(0) == g->nr)				{					lv++;					delete lvi;					found = true;;				}			}			// used for player update below			game_id = g->nr;		}		else		{			for (QListViewItem *lvi; (lvi = lv.current()) && !found;)			{				lv++;				// look for name				if (lvi->text(1) == myAccount->acc_name ||				    lvi->text(3) == myAccount->acc_name)				{					// used for player update below					game_id = lvi->text(0);					lv++;					delete lvi;					found = true;;				}			}		}		if (!found)			qWarning("game not found");		else		{			// decrease number of games			myAccount->num_games--;			statusGames->setText(" G: " + QString::number(myAccount->num_games) + " / " + QString::number(myAccount->num_observedgames) + " ");			QListViewItemIterator lvp(ListView_players);			QListViewItem *lvpi;			int found = 0;			// look for players in playerlist			for (; (lvpi = lvp.current()) && found < 2;)			{				// check if numbers are identical				if (lvpi->text(3) == game_id)				{					lvpi->setText(3, "-");					found++;				}				lvp++;			}		}	}}// take a new player from parservoid ClientWindow::slot_player(Player *p, bool cmdplayers){	// insert into ListView  	QListViewItemIterator lv(ListView_players);  	QPoint pp(0,0);	QListViewItem *topViewItem = ListView_players->itemAt(pp);  	bool deleted_topViewItem = false;  	if (p->online)	{		// check if it's an empty list, i.e. all items deleted before		if (cmdplayers && !playerListEmpty)		{			for (PlayerTableItem *lvi; (lvi = static_cast<PlayerTableItem*>(lv.current()));)			{				lv++;				// compare names				if (lvi->text(1) == p->name)				{					// check if new player info is less than old					if (p->info != "??")					{						// new entry has more info						lvi->setText(0, p->info);						//p->name,						lvi->setText(2, p->rank);						lvi->setText(3, p->play_str);						lvi->setText(4, p->obs_str);						lvi->setText(5, p->idle);						//mark,						lvi->setText(12, rkToKey(p->rank) + p->name.lower());						if (extUserInfo && myAccount->get_gsname() == IGS)						{							lvi->setText(7, p->extInfo);							lvi->setText(8, p->won);							lvi->setText(9, p->lost);							lvi->setText(10, p->country);							lvi->setText(11, p->nmatch_settings);						}						lvi->set_nmatchSettings(p);											//lvi->nmatch = p->nmatch;						lvi->ownRepaint();					}					if (p->name == myAccount->acc_name)					{						qDebug("updating my account info... (1)");						// checkbox open						bool b = (p->info.contains('X') == 0);						slot_checkbox(0, b);						// checkbox looking - don't set if closed						if (p->info.contains('!') != 0)							// "!" found							slot_checkbox(1, true);						else if (b)							// "!" not found && open							slot_checkbox(1, false);						// checkbox quiet						// NOT CORRECT REPORTED BY SERVER!						//b = (p->info.contains('Q') != 0);						//slot_checkbox(2, b);						// -> WORKAROUND						if (p->info.contains('Q') != 0)							slot_checkbox(2, true);						// get rank to calc handicap when matching						myAccount->set_rank(p->rank);					}					return;				}			}		}		else if (!cmdplayers && !myAccount->num_players)		{			qDebug("player skipped because no init table");			// skip players until initial table has loaded			return;		}		QString mark;		// check for watched players		if (watch && watch.contains(";" + p->name + ";"))		{			mark = "W";			// sound for entering - no sound while "who" cmd is executing			if (!cmdplayers)				qgoif->get_qgo()->playEnterSound();			else if (p->name == myAccount->acc_name)				// it's me				// - only possible if 'who'/'user' cmd is executing				// - I am on the watchlist, however				// don't count!				myAccount->num_watchedplayers--;			myAccount->num_watchedplayers++;		}		// check for excluded players		else if (exclude && exclude.contains(";" + p->name + ";"))		{			mark = "X";		}		// check for open/looking state		if (cmdplayers)		{			if (p->name == myAccount->acc_name)			{				qDebug("updating my account info...(2)");				// checkbox open				bool b = (p->info.contains('X') == 0);				slot_checkbox(0, b);				// checkbox looking				b = (p->info.contains('!') != 0);				slot_checkbox(1, b);				// checkbox quiet				// NOT CORRECT REPORTED BY SERVER!				//b = (p->info.contains('Q') != 0);				//slot_checkbox(2, b);				// -> WORKAROUND				if (p->info.contains('Q') != 0)					slot_checkbox(2, true);				// get rank to calc handicap when matching				myAccount->set_rank(p->rank);				mark = "M";			}		}		// from WHO command or {... has connected}		if (extUserInfo && myAccount->get_gsname() == IGS)		{			PlayerTableItem *lv1 = new PlayerTableItem(ListView_players,					p->info,					p->name,					p->rank,					p->play_str,					p->obs_str,					p->idle,					mark,					p->extInfo,					p->won,					p->lost,					p->country,					p->nmatch_settings);			lv1->setText(12, rkToKey(p->rank) + p->name.lower());			lv1->set_nmatchSettings(p);		}		else		{			PlayerTableItem *lv1 = new PlayerTableItem(ListView_players,					p->info,					p->name,					p->rank,					p->play_str,					p->obs_str,					p->idle,					mark);			lv1->setText(12, rkToKey(p->rank) + p->name.lower());			lv1->set_nmatchSettings(p);		}		// increase number of players

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -