|
想要查看内容赶紧注册登陆吧!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
#include "Stdafx.h"
#include "GameScore.h"
#include
//////////////////////////////////////////////////////////////////////////
//按钮标识
#define IDC_CLOSE_SCORE 100 //关闭成绩
//////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CGameScore, CDialog)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_ERASEBKGND()
ON_BN_CLICKED(IDC_BT_NEXT, OnBnNext)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////
//构造函数
CGameScore::CGameScore() : CDialog(IDD_GAME_SCORE)
{
//初始化变量
ZeroMemory( m_cbWeaveCount,sizeof(m_cbWeaveCount) );
ZeroMemory(&m_ScoreInfo,sizeof(m_ScoreInfo));
m_cbCurrentIndex = 0;
HINSTANCE hInst = AfxGetInstanceHandle();
m_ImageBack.LoadFromResource( hInst,IDB_GAME_SCORE );
m_ImageFangPao.LoadImage( hInst,TEXT("FANG_PAO") );
m_ImageZiMo.LoadImage( hInst,TEXT("ZI_MO") );
m_PngBanker.LoadImage( hInst,TEXT("ZHUANG") );
}
//析构函数
CGameScore::~CGameScore()
{
}
//控件绑定
void CGameScore:oDataExchange(CDataExchange * pDX)
{
__super:oDataExchange(pDX);
DDX_Control(pDX, IDOK, m_btCloseScore);
DDX_Control(pDX, IDC_BT_NEXT, m_btNext);
}
//初始化函数
BOOL CGameScore::OnInitDialog()
{
__super::OnInitDialog();
//删除窗口标题和获取属性
ModifyStyle(WS_CAPTION,0,0);
SetClassLong(m_hWnd,GCL_HBRBACKGROUND,NULL);
//创建区域
CRgn RgnControl;
m_ImageBack.CreateImageRegion(RgnControl,RGB(255,0,255));
//设置窗口
if (RgnControl.GetSafeHandle()!=NULL)
{
//移动窗口
SetWindowRgn(RgnControl,TRUE);
SetWindowPos(NULL,0,0,m_ImageBack.GetWidth(),m_ImageBack.GetHeight(),SWP_NOMOVE);
}
m_btCloseScore.SetButtonImage(IDB_BT_SCORE_CLOSE,AfxGetInstanceHandle(),false,false);
m_btNext.SetButtonImage(IDB_BT_NEXT,AfxGetInstanceHandle(),false,false);
//调整按钮
CRect rcClient;
GetClientRect(&rcClient);
CRect rcBtClose;
m_btCloseScore.GetWindowRect(&rcBtClose);
m_btCloseScore.SetWindowPos(NULL,(rcClient.Width()-rcBtClose.Width())/2,rcClient.Height()-rcBtClose.Height()-10,0,0,SWP_NOSIZE|SWP_NOZORDER);
m_btNext.SetWindowPos(NULL,100,16,0,0,SWP_NOSIZE|SWP_NOZORDER);
//创建字体
//LOGFONT lg;
//ZeroMemory( &lg,sizeof(lg) );
//lg.lfCharSet = GB2312_CHARSET;
//strcpy( lg.lfFaceName,"黑体" );
//lg.lfHeight = -20;
//if( !m_InfoFont.CreateFontIndirect( &lg ) )
// m_InfoFont.Attach(CSkinResourceManager::GetDefaultFont());
//设置透明
ModifyStyleEx(0,0x00080000);
HINSTANCE hInst = LoadLibrary(TEXT("User32.DLL"));
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
//取得SetLayeredWindowAttributes()函数指针
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)fun(this->GetSafeHwnd(),0,220,2);
FreeLibrary(hInst);
}
return TRUE;
}
//复位数据
void CGameScore::RestorationData()
{
//设置变量
ZeroMemory( m_cbWeaveCount,sizeof(m_cbWeaveCount) );
ZeroMemory(&m_ScoreInfo,sizeof(m_ScoreInfo));
m_cbCurrentIndex = 0;
for( BYTE i = 0; i < GAME_PLAYER; i++ )
{
m_cbWeaveCount = 0;
for( BYTE j = 0; j < CountArray(m_WeaveCard[0]); j++ )
m_WeaveCard[j].SetCardData(NULL,0);
m_ChiHuRight.SetEmpty();
}
//隐藏窗口
if (m_hWnd!=NULL) ShowWindow(SW_HIDE);
return;
}
//设置积分
void CGameScore::SetScoreInfo(const tagScoreInfo & ScoreInfo, const tagWeaveInfo WeaveInfo[GAME_PLAYER])
{
//设置变量
m_ScoreInfo=ScoreInfo;
BYTE cbChiHuCount = 0;
for( BYTE j = 0; j < GAME_PLAYER; j++ )
{
m_cbWeaveCount[j]=WeaveInfo[j].cbWeaveCount;
for (BYTE i=0;i<m_cbWeaveCount[j];i++)
{
bool bPublicWeave=(WeaveInfo[j].cbPublicWeave==TRUE);
m_WeaveCard[j].SetCardData(WeaveInfo[j].cbCardData,WeaveInfo[j].cbCardCount);
m_WeaveCard[j].SetDisplayItem(true);
}
m_ChiHuRight[j].SetRightData( m_ScoreInfo.dwChiHuRight[j],MAX_RIGHT_COUNT );
if( !m_ChiHuRight[j].IsEmpty() )
cbChiHuCount++;
}
//确定显示索引
for( BYTE j = 0; j < GAME_PLAYER; j++ )
{
if( !m_ChiHuRight[j].IsEmpty() )
{
m_cbCurrentIndex = j;
break;
}
}
m_btNext.ShowWindow( cbChiHuCount>1?SW_SHOW:SW_HIDE );
//显示窗口
ShowWindow(SW_SHOW);
return;
}
//关闭按钮
void CGameScore::OnOK()
{
//隐藏窗口
RestorationData();
__super::OnOK();
}
//重画函数
void CGameScore::OnPaint()
{
CPaintDC dc(this);
//获取位置
CRect rcClient;
GetClientRect(&rcClient);
//创建缓冲
CDC DCBuffer;
CBitmap ImageBuffer;
DCBuffer.CreateCompatibleDC(&dc);
ImageBuffer.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height());
//设置 DC
DCBuffer.SetBkMode(TRANSPARENT);
DCBuffer.SelectObject(&ImageBuffer);
//DCBuffer.SelectObject(&m_InfoFont);
DCBuffer.SetTextColor(RGB(250,250,250));
//绘画背景
if (m_ImageBack.IsNull()==false) m_ImageBack.BitBlt(DCBuffer,0,0);
//位置变量
int nCardSpace=5;
int nItemWidth=g_CardResource.m_ImageTableBottom.GetViewWidth();
int nTotalWidth=m_cbWeaveCount[m_cbCurrentIndex]*(nItemWidth*3+nCardSpace)+nItemWidth*m_ScoreInfo.cbCardCount[m_cbCurrentIndex]+nCardSpace;
//计算位置
int nYCardPos=94-g_CardResource.m_ImageTableBottom.GetViewHeight();
int nXCardPos=(rcClient.Width()-nTotalWidth)/2;
//绘画组合
for (BYTE i=0;i<m_cbWeaveCount[m_cbCurrentIndex];i++)
{
//绘画扑克
m_WeaveCard[m_cbCurrentIndex].DrawCardControl(&DCBuffer,nXCardPos,nYCardPos,false);
//设置位置
nXCardPos+=(nCardSpace+nItemWidth*3);
}
//绘画扑克
for (BYTE i=0;i<m_ScoreInfo.cbCardCount[m_cbCurrentIndex];i++)
{
//绘画扑克
g_CardResource.m_ImageTableBottom.DrawCardItem(&DCBuffer,m_ScoreInfo.cbCardData[m_cbCurrentIndex],nXCardPos,nYCardPos,false);
//设置位置
nXCardPos+=nItemWidth;
if ((i+2)==m_ScoreInfo.cbCardCount[m_cbCurrentIndex]) nXCardPos+=nCardSpace;
}
TCHAR szBuffer[256] = TEXT("");
//胡牌信息
if( m_ScoreInfo.wProvideUser != INVALID_CHAIR )
{
//胡牌者
CRect rcName(20,18,90,38);
//DCBuffer.SelectObject(CSkinResourceManager::GetDefaultFont());
DCBuffer.SetTextColor(RGB(252,255,0));
DCBuffer.DrawText(m_ScoreInfo.szUserName[m_cbCurrentIndex],lstrlen(m_ScoreInfo.szUserName[m_cbCurrentIndex]),&rcName,
DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER|DT_CENTER);
DCBuffer.SelectObject(&m_InfoFont);
DCBuffer.SetTextColor( RGB(250,250,250) );
CRect rcDraw;
//放炮
if( m_ScoreInfo.wProvideUser != m_cbCurrentIndex )
{
rcDraw.SetRect(15,102,190,129);
DCBuffer.DrawText( m_ScoreInfo.szUserName[m_ScoreInfo.wProvideUser],lstrlen(m_ScoreInfo.szUserName[m_ScoreInfo.wProvideUser]),
&rcDraw,DT_SINGLELINE|DT_END_ELLIPSIS|DT_RIGHT|DT_BOTTOM );
m_ImageFangPao.DrawImage( &DCBuffer,205,104 );
rcDraw.SetRect(295,102,482,129);
DCBuffer.DrawText( m_ScoreInfo.szUserName[m_cbCurrentIndex],lstrlen(m_ScoreInfo.szUserName[m_cbCurrentIndex]),
&rcDraw,DT_SINGLELINE|DT_END_ELLIPSIS|DT_LEFT|DT_BOTTOM );
}
//自摸
else
{
rcDraw.SetRect(15,102,190,129);
DCBuffer.DrawText( m_ScoreInfo.szUserName[m_ScoreInfo.wProvideUser],lstrlen(m_ScoreInfo.szUserName[m_ScoreInfo.wProvideUser]),
&rcDraw,DT_SINGLELINE|DT_END_ELLIPSIS|DT_RIGHT|DT_BOTTOM );
m_ImageZiMo.DrawImage( &DCBuffer,215,104 );
}
}
//得分信息
DCBuffer.SetTextColor( RGB(250,250,250) );
for( WORD i = 0; i < GAME_PLAYER; i++ )
{
//庄家
if( i == m_ScoreInfo.wBankerUser )
m_PngBanker.DrawImage( &DCBuffer,100-m_PngBanker.GetWidth()-10,143+i*26 );
CRect rcDrawPlayer(100,138+i*26,275,164+i*26);
DCBuffer.SetTextColor( RGB(250,250,250) );
//玩家
DCBuffer.DrawText( m_ScoreInfo.szUserName,lstrlen(m_ScoreInfo.szUserName),
&rcDrawPlayer,DT_SINGLELINE|DT_END_ELLIPSIS|DT_LEFT|DT_BOTTOM );
//分数
CRect rcDrawScore(295,138+i*26,355,164+i*26);
_sntprintf( szBuffer,CountArray(szBuffer),TEXT("%+I64d"),m_ScoreInfo.lGameScore );
DCBuffer.SetTextColor( RGB(252,255,0) );
DCBuffer.DrawText( szBuffer,lstrlen(szBuffer),&rcDrawScore,DT_SINGLELINE|DT_BOTTOM|DT_RIGHT );
DCBuffer.SetTextColor( RGB(250,250,250) );
CRect rcDrawFen(360,138+i*26-46,512,164+i*26);
DCBuffer.DrawText( CString(TEXT("分")),&rcDrawFen,DT_SINGLELINE|DT_LEFT|DT_BOTTOM );
}
//牌型信息
LPCTSTR pszKind[] = {
TEXT("自摸"),TEXT("放炮胡")
};
//牌型区域
CRect rcFanXing(34,255,159,281);
DCBuffer.SetTextColor( RGB(250,250,250) );
if( m_ScoreInfo.wLeftUser == INVALID_CHAIR )
{
//放炮
if( m_ScoreInfo.wProvideUser != m_cbCurrentIndex )
DCBuffer.DrawText( pszKind[1],lstrlen(pszKind[1]),rcFanXing,DT_SINGLELINE|DT_LEFT|DT_BOTTOM );
else DCBuffer.DrawText( pszKind[0],lstrlen(pszKind[0]),rcFanXing,DT_SINGLELINE|DT_LEFT|DT_BOTTOM );
}
//玩家逃跑
else
{
LONGLONG lTemp = __max(m_ScoreInfo.lGameScore[m_ScoreInfo.wLeftUser],-m_ScoreInfo.lGameScore[m_ScoreInfo.wLeftUser]);
_sntprintf( szBuffer,CountArray(szBuffer),TEXT("玩家【%s】逃跑,扣除%I64d分!"),m_ScoreInfo.szUserName[m_ScoreInfo.wLeftUser],
lTemp );
DCBuffer.DrawText( szBuffer,lstrlen(szBuffer),CRect(34,258,36+400,258+100),DT_LEFT|DT_WORDBREAK|DT_END_ELLIPSIS );
}
//绘画界面
dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),&DCBuffer,0,0,SRCCOPY);
//清理资源
DCBuffer.DeleteDC();
ImageBuffer.DeleteObject();
return;
}
//鼠标消息
void CGameScore::OnLButtonDown(UINT nFlags, CPoint Point)
{
__super::OnLButtonDown(nFlags,Point);
//消息模拟
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(Point.x,Point.y));
return;
}
//背景函数
BOOL CGameScore::OnEraseBkgnd(CDC * pDC)
{
Invalidate(FALSE);
UpdateWindow();
return TRUE;
}
//
void CGameScore::OnBnNext()
{
BYTE cbIndexTemp = m_cbCurrentIndex;
cbIndexTemp = (cbIndexTemp+1)%GAME_PLAYER;
while( cbIndexTemp != m_cbCurrentIndex )
{
if( !m_ChiHuRight[cbIndexTemp].IsEmpty() ) break;
cbIndexTemp = (cbIndexTemp+1)%GAME_PLAYER;
}
if( cbIndexTemp != m_cbCurrentIndex )
{
m_cbCurrentIndex = cbIndexTemp;
Invalidate(FALSE);
UpdateWindow();
}
return;
}
//////////////////////////////////////////////////////////////////////////
|
|