DlgMap.cpp
资源名称:ROA3.40.rar [点击查看]
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:7k
源码类别:
外挂编程
开发平台:
Visual C++
- // DlgMap.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ROA.h"
- #include "DlgMap.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define SCALE_MIN 0.125
- #define SCALE_MAX 1
- /////////////////////////////////////////////////////////////////////////////
- // CDlgMap dialog
- CDlgMap::CDlgMap(CWnd* pParent /*=NULL*/)
- : CDialog(CDlgMap::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgMap)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_dScale = 1.0f;
- }
- void CDlgMap::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgMap)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgMap, CDialog)
- //{{AFX_MSG_MAP(CDlgMap)
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_BTN_ZOOMOUT, OnBtnZoomout)
- ON_BN_CLICKED(IDC_BTN_ZOOMIN, OnBtnZoomin)
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgMap message handlers
- void CDlgMap::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: Add your message handler code here
- CBitmap bitmap;
- CSize szShow;
- CRect rectClient;
- // refreshReq.bMap = false;
- if(you.pntPos.x == 0 && you.pntPos.y == 0)
- return;
- CBrush bshYou, bshPlayer, bshMonster, bshPortal, bshItem,*brushOld;
- int i;
- bshYou.CreateSolidBrush(RGB(255, 0, 0));
- bshPlayer.CreateSolidBrush(RGB(0, 0, 255));
- bshMonster.CreateSolidBrush(RGB(255, 255, 0));
- bshPortal.CreateSolidBrush(RGB(255, 0, 255));
- bshItem.CreateSolidBrush(RGB(0, 255, 0));
- GetWindowRect(&rectClient);
- szShow.cx = rectClient.Width();
- szShow.cy = rectClient.Height();
- double X = you.pntTo.x;
- double Y = you.pntTo.y;
- int nRadius = 3;
- CRect rectPaste;
- double dXPaste, dYPaste;
- double dXScale = (double)szShow.cx/field.m_szField.cx/m_dScale;
- double dYScale = (double)szShow.cy/field.m_szField.cy/m_dScale;
- // Draw backgound
- Y = field.m_szField.cy - Y;
- dXPaste = (double)field.m_szField.cx*m_dScale/2;
- dYPaste = (double)field.m_szField.cy*m_dScale/2;
- rectPaste.SetRect((long)(X - dXPaste),
- (long)(Y - dYPaste),
- (long)(X + dXPaste),
- (long)(Y + dYPaste));
- if(rectPaste.top < 0)
- rectPaste.OffsetRect(0, -rectPaste.top);
- if(rectPaste.left < 0)
- rectPaste.OffsetRect(-rectPaste.left, 0);
- if(rectPaste.bottom > field.m_szField.cy)
- rectPaste.OffsetRect(0, field.m_szField.cy - rectPaste.bottom);
- if(rectPaste.right > field.m_szField.cx)
- rectPaste.OffsetRect(field.m_szField.cx - rectPaste.right, 0);
- dc.StretchBlt(0, 0, szShow.cx, szShow.cy, &field.m_dcField, rectPaste.left, rectPaste.top, rectPaste.Width(), rectPaste.Height(), SRCCOPY);
- // Draw you
- CRect rectYou;
- CPoint pntYou;
- pntYou.x = (long)(X - rectPaste.left);
- pntYou.y = (long)(Y - rectPaste.top);
- pntYou.x = (long)(dXScale * pntYou.x);
- pntYou.y = (long)(dYScale * pntYou.y);
- rectYou.SetRect(pntYou.x-nRadius, pntYou.y-nRadius, pntYou.x+nRadius, pntYou.y+nRadius);
- brushOld = dc.SelectObject(&bshYou);
- dc.Ellipse(rectYou);
- //Draw monsters
- CRect rectMon;
- CPoint pntMon;
- dc.SelectObject(&bshMonster);
- for(i=0; i<monsters.GetSize(); i++)
- {
- X = monsters[i].pntTo.x;
- Y = monsters[i].pntTo.y;
- Y = field.m_szField.cy - Y;
- pntMon.x = (long)(X - rectPaste.left);
- pntMon.y = (long)(Y - rectPaste.top);
- pntMon.x = (long)(dXScale * pntMon.x);
- pntMon.y = (long)(dYScale * pntMon.y);
- rectMon.SetRect(pntMon.x-nRadius, pntMon.y-nRadius, pntMon.x+nRadius, pntMon.y+nRadius);
- dc.Ellipse(rectMon);
- int nModeOld = dc.SetBkMode(TRANSPARENT);
- rectMon.InflateRect(30, 10);
- CFont font, *pOld;
- font.CreatePointFont(90, "Courier New");
- pOld = dc.SelectObject(&font);
- dc.DrawText(monsters[i].cName, rectMon, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
- dc.SetBkMode(nModeOld);
- dc.SelectObject(pOld);
- // test
- /* pos pos1, pos2, *posp;
- pos_list *poslist;
- pos1.x = (WORD)you.pntTo.x;
- pos1.y = (WORD)you.pntTo.y;
- pos2.x = (WORD)monsters[i].pntTo.x;
- pos2.y = (WORD)monsters[i].pntTo.y;
- poslist = (pos_list*)new char[sizeof(pos)*300+sizeof(int)];
- DWORD session = (*CalcPath_init)(poslist, (char*)field.m_byFields, field.m_szField.cx, field.m_szField.cy,
- &pos1, &pos2, 100);
- BOOL bFail= (*CalcPath_pathStep)(session);
- if(!bFail)
- {
- posp = (pos*)(((char*)poslist)+4);
- for(int j=0; j<poslist->size; j++)
- {
- X = posp[j].x;
- Y = posp[j].y;
- Y = field.m_szField.cy - Y;
- pntMon.x = (long)(X - rectPaste.left);
- pntMon.y = (long)(Y - rectPaste.top);
- pntMon.x = (long)(dXScale * pntMon.x);
- pntMon.y = (long)(dYScale * pntMon.y);
- dc.SetPixel(pntMon.x, pntMon.y, RGB(0, 0, 0));
- }
- }
- (*CalcPath_destory)(session);
- delete poslist;
- */ }
- //Draw players
- CRect rectPlayer;
- CPoint pntPlayer;
- dc.SelectObject(&bshPlayer);
- for(i=0; i<players.GetSize(); i++)
- {
- X = players[i].pntTo.x;
- Y = players[i].pntTo.y;
- Y = field.m_szField.cy - Y;
- pntPlayer.x = (long)(X - rectPaste.left);
- pntPlayer.y = (long)(Y - rectPaste.top);
- pntPlayer.x = (long)(dXScale * pntPlayer.x);
- pntPlayer.y = (long)(dYScale * pntPlayer.y);
- rectPlayer.SetRect(pntPlayer.x-nRadius, pntPlayer.y-nRadius, pntPlayer.x+nRadius, pntPlayer.y+nRadius);
- dc.Ellipse(rectPlayer);
- }
- //Draw portals
- CRect rectPortal;
- CPoint pntPortal;
- dc.SelectObject(&bshPortal);
- for(i=0; i<portals.GetSize(); i++)
- {
- X = portals[i].pntPos.x;
- Y = portals[i].pntPos.y;
- Y = field.m_szField.cy - Y;
- pntPortal.x = (long)(X - rectPaste.left);
- pntPortal.y = (long)(Y - rectPaste.top);
- pntPortal.x = (long)(dXScale * pntPortal.x);
- pntPortal.y = (long)(dYScale * pntPortal.y);
- rectPortal.SetRect(pntPortal.x-nRadius*2, pntPortal.y-nRadius*2, pntPortal.x+nRadius*2, pntPortal.y+nRadius*2);
- dc.Ellipse(rectPortal);
- }
- //Draw items
- CRect rectItem;
- CPoint pntItem;
- dc.SelectObject(&bshItem);
- for(i=0; i<items.GetSize(); i++)
- {
- X = items[i].pntPos.x;
- Y = items[i].pntPos.y;
- Y = field.m_szField.cy - Y;
- pntItem.x = (long)(X - rectPaste.left);
- pntItem.y = (long)(Y - rectPaste.top);
- pntItem.x = (long)(dXScale * pntItem.x);
- pntItem.y = (long)(dYScale * pntItem.y);
- rectItem.SetRect(pntItem.x-nRadius, pntItem.y-nRadius, pntItem.x+nRadius, pntItem.y+nRadius);
- dc.Ellipse(rectItem);
- }
- // Draw finished
- dc.SelectObject(brushOld);
- bshYou.DeleteObject();
- bshPlayer.DeleteObject();
- bshMonster.DeleteObject();
- bshPortal.DeleteObject();
- bshItem.DeleteObject();
- }
- void CDlgMap::OnBtnZoomout()
- {
- m_dScale /= 2.0;
- if(m_dScale < SCALE_MIN)
- m_dScale = SCALE_MIN;
- RedrawWindow();
- }
- void CDlgMap::OnBtnZoomin()
- {
- m_dScale *= 2.0;
- if(m_dScale > SCALE_MAX)
- m_dScale = SCALE_MAX;
- RedrawWindow();
- }
- BOOL CDlgMap::OnEraseBkgnd( CDC* pDC )
- {
- if(!field.m_bLoaded)
- {
- CRect rect;
- CWnd::OnEraseBkgnd(pDC);
- GetClientRect(&rect);
- int nModeOld = pDC->SetBkMode(TRANSPARENT);
- pDC->DrawText("NO MAP", rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
- pDC->SetBkMode(nModeOld);
- }
- return(false);
- }