📄 45mapmakerview.cpp
字号:
// 45MapMakerView.cpp : implementation of the CMy45MapMakerView class
//
#include "stdafx.h"
#include "45MapMaker.h"
#include "45MapMakerDoc.h"
#include "45MapMakerView.h"
#include ".\45mapmakerview.h"
#include "MyWall.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy45MapMakerView
IMPLEMENT_DYNCREATE(CMy45MapMakerView, CView)
BEGIN_MESSAGE_MAP(CMy45MapMakerView, CView)
//{{AFX_MSG_MAP(CMy45MapMakerView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_WM_ERASEBKGND()
// ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_SIZE()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_VIEWFRONT, OnViewfront)
ON_UPDATE_COMMAND_UI(ID_VIEWFRONT, OnUpdateViewfront)
ON_COMMAND(ID_VIEWSECOND, OnViewsecond)
ON_UPDATE_COMMAND_UI(ID_VIEWSECOND, OnUpdateViewsecond)
ON_COMMAND(ID_VIEWBLOCK, OnViewblock)
ON_UPDATE_COMMAND_UI(ID_VIEWBLOCK, OnUpdateViewblock)
ON_COMMAND(ID_VIEWNET, OnViewnet)
ON_UPDATE_COMMAND_UI(ID_VIEWNET, OnUpdateViewnet)
ON_COMMAND(ID_EDITFRONT, OnEditfront)
ON_COMMAND(ID_EDITSECOND, OnEditsecond)
ON_COMMAND(ID_EDITBLOCK, OnEditblock)
ON_UPDATE_COMMAND_UI(ID_EDITFRONT, OnUpdateEditfront)
ON_UPDATE_COMMAND_UI(ID_EDITSECOND, OnUpdateEditsecond)
ON_UPDATE_COMMAND_UI(ID_EDITBLOCK, OnUpdateEditblock)
ON_COMMAND(ID_SELECTMODE, OnSelectmode)
ON_COMMAND(ID_BRUSHMODE, OnBrushmode)
ON_UPDATE_COMMAND_UI(ID_SELECTMODE, OnUpdateSelectmode)
ON_UPDATE_COMMAND_UI(ID_BRUSHMODE, OnUpdateBrushmode)
ON_COMMAND(ID_ViewSecondTarg, OnViewsecondtarg)
ON_UPDATE_COMMAND_UI(ID_ViewSecondTarg, OnUpdateViewsecondtarg)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy45MapMakerView construction/destruction
CMy45MapMakerView::CMy45MapMakerView()
{
// TODO: add construction code here
editx = edity = 0;
mapBeginx = mapBeginy = 0;
this->editMode = false;
brushed = false;
mouse = 0;
((CMy45MapMakerApp*)AfxGetApp())->display = NULL;
}
CMy45MapMakerView::~CMy45MapMakerView()
{
}
BOOL CMy45MapMakerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
viewFront = true;
viewSecond = true;
viewBlock = true;
editMode = false; //true表示画刷模式,false表示选择模式
editFront = true;
editSecond = false;
editBlock = false;
viewNet = false;
ViewEditSecond = true;
BOOL temp = CView::PreCreateWindow(cs);
if(!temp)
return false;
}
/////////////////////////////////////////////////////////////////////////////
// CMy45MapMakerView drawing
void CMy45MapMakerView::OnDraw(CDC* pDC)
{
CMy45MapMakerDoc* pDoc = GetDocument();
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp();
CRect rc;
GetClientRect(&rc);
int showWidth = rc.Width()/tileWidth+1;
int showHeight = rc.Height()/tileHeight+1;
showWidth = mapWidth<showWidth?mapWidth:showWidth;
showHeight = mapHeight<showHeight?mapHeight:showHeight;
int scrWidth = mapWidth-showWidth;
int scrHeight = mapHeight-showHeight;
this->SetScrollRange(0,0,scrWidth,true);
this->SetScrollRange(1,0,scrHeight,true);
this->SetScrollPos( 0,mapBeginx,true);
this->SetScrollPos(1,mapBeginy,true);
HDC hdc;
theApp->display->Clear(0);
DrawFront(&rc);
DrawSecond(&rc);
if(this->viewBlock)
DrawProject(&rc);
//theApp->display->Present();
theApp->display->GetBackBuffer()->GetDC(&hdc);
::BitBlt(pDC->m_hDC,0,0,rc.Width(),rc.Height(),hdc,0,0,SRCCOPY);
theApp->display->GetBackBuffer()->ReleaseDC(hdc);
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMy45MapMakerView printing
BOOL CMy45MapMakerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy45MapMakerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy45MapMakerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy45MapMakerView diagnostics
#ifdef _DEBUG
void CMy45MapMakerView::AssertValid() const
{
CView::AssertValid();
}
void CMy45MapMakerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy45MapMakerDoc* CMy45MapMakerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy45MapMakerDoc)));
return (CMy45MapMakerDoc*)m_pDocument;
}
#endif //_DEBUG
HRESULT CMy45MapMakerView::InitDirectDraw(HWND hWnd)
{
LPDIRECTDRAWPALETTE pDDPal = NULL;
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp();
HRESULT hr;
theApp->display = new CDisplay();
if( FAILED( hr = theApp->display->CreateWindowedDisplay( hWnd, DDRAW_WIDTH, DDRAW_HEIGHT) ) )
{
MessageBox("无法创建DirectDraw","error",MB_OK);
return hr;
}
if( FAILED( hr = theApp->display->CreatePaletteFromBitmap( &pDDPal, "Image//Tile//000.bmp") ) )
return hr;
theApp->display->InitClipper();
theApp->display->SetPalette( pDDPal );
SAFE_RELEASE( pDDPal );
return true;
}
void CMy45MapMakerView::DrawSecond(CRect* rt)
{
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp(); //app
CMy45MapMakerDoc* pDoc = GetDocument(); //doc
int width = ((rt->Width())/tileWidth)*2+2; //需要画画的区域大小
int height = ((rt->Height())/tileHeight)+2; //
short int* map = pDoc->m_myMap.arr2;
int w = pDoc->m_myMap.width; //地图的宽
int h = pDoc->m_myMap.height; //地图的高
int w1 = tileWidth/2;
int h1 = tileHeight/2;
CSurface* draw;
int id;
int ix,iy;
int offx,offy;
WallConfig* wallcfg;
int i = width+mapBeginx;
if(i%2==0)
i--;
while(i>=mapBeginx-1)
{
int j =i-1;
int k = mapBeginy;
int flag=0;
for(;j<=width+mapBeginx&&k<height+mapBeginy;j++)
{
if(j<0||j>w-1)
{
continue;
}
id = *(map + (k)*w+j);
if(id!=0)
{
draw = NULL;
draw = theApp->GetCSurface("Wall",id);
if(draw)
{
theApp->m_myWall.find(id,wallcfg); //得到指针描述
offx = wallcfg->offx;
offy = wallcfg->offy;
ix = (j-mapBeginx)*(tileWidth/2);
if(j%2==0)
iy = (k-mapBeginy)*tileHeight;
else
iy = (k-mapBeginy)*tileHeight+tileHeight/2;
theApp->display->Blt(ix-offx,iy-offy,draw);
if(ViewEditSecond)
{
draw = theApp->GetCSurface("Wall",101);
if(draw)
{
theApp->display->Blt(ix-tileWidth/2,iy-tileHeight/2,draw);
}
}
}
//if((((i+mapBeginy)*mapWidth)+j+mapBeginx)==this->editarry&&this->editSecond)
}
if((((k)*mapWidth)+j)==this->editarry&&this->editSecond)
{
draw =theApp->GetCSurface("Wall",theApp->CurrentEditId);
if(draw)
{
theApp->m_myWall.find(theApp->CurrentEditId,wallcfg);
offx = wallcfg->offx;
offy = wallcfg->offy;
ix = (j-mapBeginx)*(tileWidth/2);
if(j%2==0)
iy = (k-mapBeginy)*tileHeight;
else
iy = (k-mapBeginy)*tileHeight+tileHeight/2;
theApp->display->AlphaBlt(ix-offx,iy-offy,draw,100,RGB(255,0,255));
}
}
flag++;
if(flag==2)
{
flag = 0;
k++;
}
}
i-=2;
}//画右上角
i +=2;//把i还原,哈哈忘了吧?
if(i%2==1)
i++;
int p = mapBeginy+1;
while(p<mapBeginy+height)
{
int k = p;
int j = i;
int flag=0;
for(;j<=width+mapBeginx&&k<height+mapBeginy;j++)
{
if(j<0||j>w-1||k<0||k>h-1)
{
continue;
}
id = *(map + (k)*w+j);
if(id!=0)
{
draw = NULL;
draw = theApp->GetCSurface("Wall",id);
if(draw)
{
theApp->m_myWall.find(id,wallcfg); //得到指针描述
offx = wallcfg->offx;
offy = wallcfg->offy;
ix = (j-mapBeginx)*(tileWidth/2);
if(j%2==0)
iy = (k-mapBeginy)*tileHeight;
else
iy = (k-mapBeginy)*tileHeight+tileHeight/2;
theApp->display->Blt(ix-offx,iy-offy,draw);
if(ViewEditSecond)
{
draw = theApp->GetCSurface("Wall",101);
if(draw)
{
theApp->display->Blt(ix-tileWidth/2,iy-tileHeight/2,draw);
}
}
}
}
if((((k)*w)+j)==this->editarry&&this->editSecond)
{
draw =theApp->GetCSurface("Wall",theApp->CurrentEditId);
if(draw)
{
theApp->m_myWall.find(theApp->CurrentEditId,wallcfg);
offx = wallcfg->offx;
offy = wallcfg->offy;
ix = (j-mapBeginx)*(tileWidth/2);
if(j%2==0)
iy = (k-mapBeginy)*tileHeight;
else
iy = (k-mapBeginy)*tileHeight+tileHeight/2;
theApp->display->AlphaBlt(ix-offx,iy-offy,draw,100,RGB(255,0,255));
}
}
flag++;
if(flag==2)
{
flag = 0;
k++;
}
}
p++;
}
}
/*
void CMy45MapMakerView::DrawSecond(CRect* rt)
//老版本的第二层帖图,严重错误
{
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp(); //app
CMy45MapMakerDoc* pDoc = GetDocument(); //doc
int width = ((rt->Width())/tileWidth)*2+2; //需要画画的区域大小
int height = ((rt->Height())/tileHeight)+2; //
short int* map = pDoc->m_myMap.arr2;
int w = pDoc->m_myMap.width; //地图的宽
int h = pDoc->m_myMap.height; //地图的高
int w1 = tileWidth/2;
int h1 = tileHeight/2;
CSurface* draw;
int i=0,j=0,id,ix,iy,ixbegin,hbegin,h2;
WallConfig* wallcfg;
ix = ixbegin=-tileWidth/2; //x起始坐标永远是这个~~~~x坐标每画一次+tileWidth/2
{
if((mapBeginx)%2==0) //y起始坐标由x的起始位置确定
{
iy = hbegin=-tileHeight/2;
h1 =h2 = tileHeight/2;
}
else
{
iy = hbegin=0;
h1= h2=-tileHeight/2;
}
}
//从左到右,从上到下
for(i=0;i<height;i++)
{
if(i+mapBeginy>=h)
continue;
for(j=0;j<width;j++)
{
if(j+mapBeginx>=w)
continue;
//取得当前屏幕所在地途中的位置,也就是确定map指针的位置
id = *(map + (i+mapBeginy)*w+j+mapBeginx);
if(id!=0)
{
draw = NULL;
draw = theApp->GetCSurface("Wall",id);
if(draw)
{
theApp->m_myWall.find(id,wallcfg); //得到指针描述
int offx = wallcfg->offx;
int offy = wallcfg->offy;
theApp->display->Blt(ix-offx+tileWidth/2,iy-offy+tileHeight/2,draw);
}
if(ViewEditSecond)
{
draw = theApp->GetCSurface("Wall",101);
if(draw)
{
theApp->display->Blt(ix,iy,draw);
}
}
}
if((((i+mapBeginy)*mapWidth)+j+mapBeginx)==this->editarry&&this->editSecond)
{
draw =theApp->GetCSurface("Wall",theApp->CurrentEditId);
if(draw)
{
theApp->m_myWall.find(theApp->CurrentEditId,wallcfg);
int offx = wallcfg->offx;
int offy = wallcfg->offy;
theApp->display->AlphaBlt(ix-offx+tileWidth/2,iy-offy+tileHeight/2,draw,100,RGB(255,0,255));
}
}
ix+=tileWidth/2;
iy +=h1;
h1 = -h1;
}
ix=ixbegin;//每次画完一行之后x坐标要复原
iy = hbegin+tileHeight;
hbegin+=tileHeight;
h1 = h2;
}
return;
}*/
void CMy45MapMakerView::DrawProject(CRect* rt)//画遮挡
{
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp(); //app
CMy45MapMakerDoc* pDoc = GetDocument(); //doc
int width = ((rt->Width())/(tileWidth/2))+2; //需要画画的区域大小
int height = ((rt->Height())/tileHeight)+2; //
//int width = 5;
//int height = 5;
short int* map = pDoc->m_myMap.arr1; //第一层
//short int* wall = pDoc->m_myMap.arr2; //第二层 暂时写在这里,还需要改进,如果图片的中心点不再显示范围之内,那么。。。
int w = pDoc->m_myMap.width;
int h = pDoc->m_myMap.height;
int w1 = tileWidth/2;
int h1 = tileHeight/2;
CSurface* draw = theApp->GetCSurface("Wall",100);;
int i=0,j=0,id,ix,iy,ixbegin,hbegin;
ix = ixbegin=-tileWidth/2;
{
if((j+mapBeginx)%2==0)
{
iy = hbegin=-tileHeight/2;
h1 = tileHeight/2;
}
else
{
iy = hbegin=0;
h1=-tileHeight/2;
}
}
for(i=0;i<width;i++)
{
if(i+mapBeginx>=w)
continue;
for(j=0;j<height;j++)
{
if(j+mapBeginy>=h)
continue;
//取得当前屏幕所在地途中的位置,也就是确定map指针的位置
id = (*(map + (j+mapBeginy)*w+i+mapBeginx));
if(id<0)
{
theApp->display->Blt(ix,iy,draw);
}
iy+=tileHeight;
}
ix=ixbegin+tileWidth/2; //每次画完一列之后x坐标要向右移动
ixbegin+=tileWidth/2; //然后作一下纪录
iy=hbegin+h1; //iy要回到原来位置并且变动
hbegin+=h1;
h1 = -h1;
}
}
void CMy45MapMakerView::DrawFront(CRect* rt) //画第一层,这个函数真他妈搞死人
{
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp(); //app
CMy45MapMakerDoc* pDoc = GetDocument(); //doc
int width = ((rt->Width())/(tileWidth/2))+2; //需要画画的区域大小
int height = ((rt->Height())/tileHeight)+2; //
//int width = 5;
//int height = 5;
short int* map = pDoc->m_myMap.arr1; //第一层
short int* wall = pDoc->m_myMap.arr2; //第二层 暂时写在这里,还需要改进,如果图片的中心点不再显示范围之内,那么。。。
int w = pDoc->m_myMap.width;
int h = pDoc->m_myMap.height;
int w1 = tileWidth/2;
int h1 = tileHeight/2;
CSurface* draw;
int i=0,j=0,id,ix,iy,ixbegin,hbegin;
ix = ixbegin=-tileWidth/2;
{
if((j+mapBeginx)%2==0)
{
iy = hbegin=-tileHeight/2;
h1 = tileHeight/2;
}
else
{
iy = hbegin=0;
h1=-tileHeight/2;
}
}
for(i=0;i<width;i++)
{
if(i+mapBeginx>=w)
continue;
for(j=0;j<height;j++)
{
if(j+mapBeginy>=h)
continue;
//取得当前屏幕所在地途中的位置,也就是确定map指针的位置
id = abs(*(map + (j+mapBeginy)*w+i+mapBeginx));
if(id!=0)
{
draw = NULL;
draw = theApp->GetCSurface("Tile",id);
if(draw)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -