//****************************************************************************
//Copyright (C) 2005-2006 Beijing BlueDJ Technology Co.,Ltd. All rights reserved.

//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 the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program (in the file LICENSE.GPL); if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

//Please visit http://www.bluedj.com for more infomation about us.
//Contact us at ggwizard@gmail.com or darkdong@gmail.com.
//****************************************************************************/

#include "DJGamePlayerItem.h"
#include "DJGamePanel.h"
#include "DJGameUser.h"

static const char *winds[]={
    QT_TRANSLATE_NOOP("DJGamePlayerItem","none"),
    QT_TRANSLATE_NOOP("DJGamePlayerItem","east"),
    QT_TRANSLATE_NOOP("DJGamePlayerItem","south"),
    QT_TRANSLATE_NOOP("DJGamePlayerItem","west"),
    QT_TRANSLATE_NOOP("DJGamePlayerItem","north")
};
//QStringList DJGamePlayerItem::winds	= ( QStringList() << tr("none")<< tr("east")<<tr("south")<<tr("west")<<tr("north") );
	
DJGamePlayerItem::DJGamePlayerItem( DJGameUser* user, DJGamePanel* gamePanel, QTreeWidget * parent, int type )
		: QTreeWidgetItem( parent, type),m_user(user),m_gamePanel(gamePanel)
{	
	for ( int i = 0; i < parent->columnCount(); i++ ) {
		setTextAlignment( i, Qt::AlignCenter );
	}
}
DJGamePlayerItem::~DJGamePlayerItem()
{
}
void DJGamePlayerItem::setName( const QString& name )
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::UserName );
	if ( -1 != index ) {
		setText( index, name );
	}
}
void DJGamePlayerItem::setNickName( const QString& nickname )
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::NickName );
	if ( -1 != index ) {
		setText( index, nickname );
	}
}
void DJGamePlayerItem::setSeat( quint8 seatId )
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::Seat );
	if ( -1 != index ) {
		setText( index, QString::number( seatId ) );
	}
}
void DJGamePlayerItem::setPanelScore( int score )
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::PanelScore );
	if ( -1 != index ) {
		setText( index, QString("%1").arg(score) );
	}
}
void DJGamePlayerItem::deltaPanelScore( int delta )
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::PanelScore );
	if ( -1 != index ) {
		int score	= text( index ).toInt();
		score += delta;
		setText( index, QString("%1").arg(score) );
	}
}
void DJGamePlayerItem::setPanelChips( int chips )
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::PanelChips );
	if ( -1 != index ) {
		setText( index, QString("%1").arg(chips) );
	}
}
void DJGamePlayerItem::deltaPanelChips( int delta )
{
	djDebug()<<"DJGamePlayerItem::deltaChips"<<delta;
	int index	= m_gamePanel->indexOfSection( DJGamePanel::PanelChips );
	if ( -1 != index ) {
		int chips	= text( index ).toInt();
		chips += delta;
		setText( index, QString("%1").arg(chips) );
	}
}
void DJGamePlayerItem::setDoorWind( quint8 wind )
{
	int index	= gamePanel()->indexOfSection( DJGamePanel::DoorWind );
	if ( -1 != index ) {
		if ( wind <= 4 ) {
			setText( index, tr(winds[wind]) );
		}
	}
}
void DJGamePlayerItem::setRingWind( quint8 wind )
{
	int index	= gamePanel()->indexOfSection( DJGamePanel::RingWind );
	if ( -1 != index ) {
		if ( wind <= 4 ) {
			setText( index, tr(winds[wind]) );
		}
	}
}
void DJGamePlayerItem::setScore()
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::Score );
	if ( -1 != index ) {
		setText( index, QString("%1").arg(m_user->score()) );
	}
}
void DJGamePlayerItem::setChips()
{
	int index	= m_gamePanel->indexOfSection( DJGamePanel::Chips );
	if ( -1 != index ) {
		setText( index, QString("%1").arg(m_user->chips()) );
	}
}




