加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LeftView.cpp 4.66 KB
一键复制 编辑 原始数据 按行查看 历史
Shaker 提交于 2014-08-12 21:17 . *提交到Git@OSC
// LeftView.cpp : 实现文件
//
#include "stdafx.h"
#include "TurboMir.h"
#include "GameMir.h"
#include "MainFrm.h"
#include "LeftView.h"
#include ".\leftview.h"
const int scale=6;
const int top=7;
const int left=7;
const int width=31;
const int height=21;
// CLeftView 对话框
IMPLEMENT_DYNAMIC(CLeftView, CDialog)
CLeftView::CLeftView( CGameMir& game, CMainFrame& Parent /*=NULL*/)
: CDialog(CLeftView::IDD, &Parent), m_Game(game), m_FrameWnd(Parent), m_TargetId(0)
{
}
CLeftView::~CLeftView()
{
}
void CLeftView::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TARGET_HP, m_TargetHP);
DDX_Control(pDX, IDC_TARGET_NAME, m_TargetName);
DDX_Control(pDX, IDC_URL, m_URL);
}
BEGIN_MESSAGE_MAP(CLeftView, CDialog)
ON_WM_TIMER()
ON_WM_PAINT()
END_MESSAGE_MAP()
// CLeftView 消息处理程序
BOOL CLeftView::OnInitDialog()
{
CDialog::OnInitDialog();
CClientDC dc(this);
m_Bitmap.CreateCompatibleBitmap(&dc, width*scale, height*scale);
m_MemDC.CreateCompatibleDC(&dc);
m_MemDC.SelectObject(&m_Bitmap);
CRect rectClient;
GetClientRect(rectClient);
m_TargetHP.SetBkColour(crWhite);
m_TargetHP.SetTextBkColour(crWhite);
m_TargetHP.SetForeColour(RGB(0xff,0x80,0x00));
m_TargetHP.SetTextForeColour(RGB(0xff,0x80,0x00));
m_TargetHP.SetRange(0,100);
m_TargetHP.SetPos(100);
m_TargetHP.SetTextFont(&m_FrameWnd.m_Font);
m_TargetHP.SetShowText(TRUE);
m_TargetHP.SetShowTextStyle(3);
int NowTop=top*2+height*scale;
m_TargetName.MoveWindow(left,NowTop,width*scale,18);
m_TargetName.SetWindowText("没有目标");
NowTop+=22;
m_TargetHP.MoveWindow(left,NowTop,width*scale,16);
NowTop+=32;
m_URL.MoveWindow(left,NowTop,width*scale,22);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CLeftView::OnTimer(UINT nIDEvent)
{
CDialog::OnTimer(nIDEvent);
}
void CLeftView::RedrawMiniMap(void)
{
//25*17
int offsetx=m_Game.GetSelfInfo().xx-((width-1)/2);
int offsety=m_Game.GetSelfInfo().yy-((height-1)/2);
int xx,yy;
for (xx=0;xx<width;xx++)
{
for (yy=0;yy<height;yy++)
{
if (m_Game.m_Map.TestMap(offsetx+xx,offsety+yy))
{
m_MemDC.FillSolidRect(xx*scale,yy*scale,scale,scale,crMapFree);
}
else
{
m_MemDC.FillSolidRect(xx*scale,yy*scale,scale,scale,crMapNotFree);
}
}
}
CFont font;
font.CreatePointFont(10*9,"宋体");
m_MemDC.SelectObject(&font);
m_MemDC.SetTextColor(crWhite);
std::string name;
m_MemDC.SetBkMode(TRANSPARENT);
CGameMir::sActorList& ActorList=const_cast<CGameMir::sActorList&>(m_Game.GetActorList());
for ( CGameMir::sActorList::const_iterator actor=ActorList.begin();actor!=ActorList.end();actor++)
{
if ( actor->ServerId==m_TargetId )
{
xx=actor->xx-offsetx;
yy=actor->yy-offsety;
m_MemDC.FillSolidRect(xx*scale,yy*scale,scale,scale,crRed);
m_MemDC.FillSolidRect(xx*scale+1,yy*scale+1,scale-2,scale-2,crYellow);
name=actor->Name;
m_MemDC.TextOut((xx+1)*scale,(yy+1)*scale,name.c_str(),name.length());
}
else
{
COLORREF color;
switch(actor->Type)
{
case CGameMir::AT_Monst:
color=crMonst;
break;
case CGameMir::AT_Merchant:
color=crNPC;
break;
case CGameMir::AT_Baby:
color=crBaby;
break;
case CGameMir::AT_Human:
color=crPlayer;
break;
case CGameMir::AT_Guard:
color=crNPC;
break;
default:
color=crGray;
break;
}
xx=actor->xx-offsetx;
yy=actor->yy-offsety;
if( xx>=0 && xx<width && yy>=0 && yy<height )
{
m_MemDC.FillSolidRect(xx*scale+1,yy*scale+1,scale-2,scale-2,color);
}
}
}
m_MemDC.FillSolidRect(((width-1)/2)*scale+1,((height-1)/2)*scale+1,scale-2,scale-2,crSelf);
RECT rect;
rect.left=left;
rect.top=top;
rect.right=left+width*scale;
rect.bottom=top+height*scale;
InvalidateRect(&rect,FALSE);
}
void CLeftView::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.BitBlt(left,top,width*scale,height*scale,&m_MemDC,0,0,SRCCOPY);
}
void CLeftView::SetTarget(const CGameMir::sActor&actor)
{
m_TargetId=actor.ServerId;
OnTargetHpChange(actor.ServerId,actor.Hp,actor.MaxHp);
OnTargetPosChange(actor.ServerId,actor.xx,actor.yy,ParseName(actor.Name).c_str());
RedrawMiniMap();
}
void CLeftView::OnTargetHpChange(DWORD id, WORD hp, WORD maxhp)
{
if ( m_TargetId==id )
{
if ( maxhp==0 )
{
m_TargetHP.SetRange(0,100);
m_TargetHP.SetPos(100);
}
else
{
m_TargetHP.SetRange(0,maxhp);
m_TargetHP.SetPos(hp);
}
}
}
void CLeftView::OnTargetPosChange(DWORD id, WORD x, WORD y, LPCTSTR name)
{
if ( m_TargetId==id )
{
char str[256];
sprintf(str,"%s (%d,%d)",name,x,y);
m_TargetName.SetWindowText(str);
}
}
CSize CLeftView::GetNeedSize(void)
{
return CSize(left*2+width*scale,top*2+height*scale+36+top+40);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化