📄 cbdraw.cpp
字号:
{
OutputDebugString( "DRAW_LoadMaps Error(5): Error when loading shadow surfaces!\n" );
return FALSE;
}
// WriteLogFile( "Dead.log","EEE" );
// load MMX temp surface
// has color key, in system memory
if( !DRAW_sMMX.Create( DRAW_MMX_WIDTH, DRAW_MMX_HEIGHT, TRUE, FALSE ) )
{
ErrorMessage( hwndGame, DRAW_ERROR_ID+7, "Cannot create MMX temp surface!" );
return FALSE;
}
DRAW_sMMX.Erase();
// load Build surfaces
if( !BUILD_Load() )
{
OutputDebugString( "DRAW_LoadMaps Error(4): Error when loading build surfaces!\n" );
return FALSE;
}
// load text surfaces
tCopyright.BeginText( 20, 1, FALSE );
tWood.BeginText( 8, 1, FALSE );
tFood.BeginText( 8, 1, FALSE );
tIron.BeginText( 8, 1, FALSE );
tGold.BeginText( 8, 1, FALSE );
// initialize byconts
MOUSE_InitByConts();
#ifdef _DEBUG
timeEnd = timeGetTime();
OutputString( timeEnd-timeBegin, "\n" );
timeBegin = timeEnd;
#endif
/*
//Warning : the width of surface must not be larger than 640 piexel!!
if( !DRAW_sUnitMap[0].Create( 640,10 ) )
{
ErrorMessage( hwndGame, DRAW_ERROR_ID+3, "Cannot open unit map" );
return FALSE;
}
*/
// WriteLogFile( "Dead.log","FFF" );
// set done flag
DRAW_bLoadMaps=TRUE;
return TRUE;
// return GAME_Begin( 0 );
//*****************************Test only, Mar.21.1997
/* struct OTHER_STRUCT other;
other.nType = 1;
other.nCol[0] = 1 + MAP_Lib.AniSeq[22].nOffset;
other.szItem = MAP_Lib.Unit[22].szItem;
other.ptBegin.x = 300, other.ptBegin.y = 300;
OTHER_CreateData( &other );
*/
//*****************************
} // DRAW_LoadMaps()
// 释放所有在战场上装入的缓冲区和位图
// release user defined surfaces
void DRAW_ReleaseMaps()
{
if( !DRAW_bLoadMaps )
{
ErrorMessage( hwndGame, DRAW_ERROR_ID+20, "Try to release maps before load them!" );
return;
}
// 释放所有生产出来的单元和其它个体
// GAME_ReleaseAllUnits();
// relese text surfaces
tCopyright.EndText();
tWood.EndText();
tFood.EndText();
tIron.EndText();
tGold.EndText();
// release image compression library
#ifdef _MAP_COMPRESS_
DRAW_ImageLib.image_close_compress();
DRAW_ImageLib.image_close_index();
#else
// release unit maps
for( int j=0; j < MAP_Lib.nULibNum; j++ )
{
DRAW_sUnitMap[j].Release();
}
#endif // _MAP_COMPRESS_
// release ground maps
for( int i=0; i < MAP_Lib.nGLibNum; i++ )
{
DRAW_sGroundMap[i].Release();
}
// release MMX surface
DRAW_sMMX.Release();
// Load other surfaces, must before read med file, read shadow file, read build file
// 读取其它图素文件
for( i=0; i< MAP_Lib.nOtherNum; i++ )
{
// has color key , in system memory
DRAW_sOtherMap[i].Release();
}
// release shadow surfaces
SHADOW_Release();
// release build surfaces
BUILD_Release();
// release bkground surface
DRAW_sBkGround.Release();
// clear done flag
DRAW_bLoadMaps = FALSE;
// GAME_End( 0 );
} // DRAW_ReleaseMaps();
/////////////////////
/////////////////////
// 注意:这里的方向和程序其它部分所用的方向不一样。
// 0 1 2
// 7 3
// 6 5 4
// 为满足日方的要求,对移动屏幕的出发范围进行另外的计算
// point : 鼠标在屏幕上的位置
// return : 应该移动的方向,-1时为不移动
int DRAW_MoveScreen2( POINT point );
// 检测是否移动屏幕
// test if should move screen, if so move it
// return value : TRUE if moved
int DRAW_MoveScreen( void )
{
POINT point;
GetCursorPos(&point);
static int nDir=-1;
static int nDirSave=-1;
nDirSave = nDir;
if( DRAW_bMoveScreenEx )
{
nDir = DRAW_MoveScreen2( point );
}
else
{
if( point.x == 0 )
{
if( point.y == 0 ) nDir=0;
else if( point.y == SCREEN_HEIGHT-1 ) nDir=6;
else nDir=7;
}
else if( point.x == SCREEN_WIDTH-1 )
{
if( point.y == 0 ) nDir=2;
else if( point.y == SCREEN_HEIGHT-1 ) nDir=4;
else nDir=3;
}
else
{
if( point.y == 0 ) nDir=1;
else if( point.y == SCREEN_HEIGHT-1 ) nDir=5;
else nDir = -1;
}
}
// if mouse cursor is not in scrolling region, do nothing
// 判断鼠标是否在滚动区
// set cursor part 1, 第一部分
if( nDir == -1 )
{ // 鼠标不在滚动区
if( nDirSave != -1 ) // 鼠标刚刚移出滚动区
{
CURSOR_Set( &MAIN_Cursors[0] );
MOUSE_EnableTest( TRUE );
}
return FALSE;
}
// save old top-left point
POINT ptTopLeft;
ptTopLeft.x = DRAW_rcScreen.left;
ptTopLeft.y = DRAW_rcScreen.top;
// DRAW_rcScreen should always be larger than (0,0,640,480)
int width = DRAW_rcScreen.right - DRAW_rcScreen.left;
int height = DRAW_rcScreen.bottom - DRAW_rcScreen.top;
DRAW_rcScreen.left+=DD[nDir][0] * GAME.nSpeedScroll;
DRAW_rcScreen.top+=DD[nDir][1] * GAME.nSpeedScroll;
// adjust
if( DRAW_rcScreen.left < 0 )
{
DRAW_rcScreen.left = 0;
if( nDir == 0 ) nDir = 1;
else if( nDir == 6 ) nDir = 5;
}
if( DRAW_rcScreen.left >= MAP_Lib.szNum.cx - width )
{
DRAW_rcScreen.left = MAP_Lib.szNum.cx - width - 1;
if( nDir == 2 ) nDir = 1;
else if( nDir == 4 ) nDir = 5;
}
if( DRAW_rcScreen.top < 0 )
{
DRAW_rcScreen.top = 0;
if( nDir == 0 ) nDir = 7;
else if( nDir == 2 ) nDir = 3;
}
if( DRAW_rcScreen.top > MAP_Lib.szNum.cy - height + 9 )
{
DRAW_rcScreen.top = MAP_Lib.szNum.cy - height + 9;
if( nDir == 4 ) nDir = 3;
else if( nDir == 6 ) nDir = 7;
}
DRAW_rcScreen.right=DRAW_rcScreen.left + width;
DRAW_rcScreen.bottom=DRAW_rcScreen.top+height;
// if need't move
if( DRAW_rcScreen.left == ptTopLeft.x && DRAW_rcScreen.top == ptTopLeft.y )
{ //如果到头了,则退出滚屏状态
CDDCursor *pCursor;
pCursor = CURSOR_Get();
Assert( pCursor );
if( pCursor != &MAIN_Cursors[0] )
{
CURSOR_Set( &MAIN_Cursors[0] );
MOUSE_EnableTest( TRUE );
}
nDir = -1;
return FALSE;
}
else
{ // 鼠标在滚动区
if( nDirSave == -1 )
{
CURSOR_Set( &MAIN_Cursors[1] );
MOUSE_EnableTest( FALSE );
}
if( nDirSave != nDir )
{
CDDCursor *pCursor;
pCursor = CURSOR_Get();
Assert( pCursor );
pCursor->SetState( nDir );
}
}
// set screen offset
POINT ptSave;
ptSave.x = DRAW_ptScreenOffset.x;
ptSave.y = DRAW_ptScreenOffset.y;
DRAW_ptScreenOffset.x = (DRAW_rcScreen.left+DRAW_SCREEN_ADJUST)*MAP_Lib.szItem.cx;
DRAW_ptScreenOffset.y = DRAW_rcScreen.top*(MAP_Lib.szItem.cy>>1);
//DRAW_UpdateScreen();
// offset since move screen
ptSave.x = DRAW_ptScreenOffset.x - ptSave.x;
ptSave.y = DRAW_ptScreenOffset.y - ptSave.y;
DRAW_DrawMoveScreen( ptSave );
return TRUE;
} // DRAW_MoveScreen()
// 为满足日方的要求,对移动屏幕的出发范围进行另外的计算
// point : 鼠标在屏幕上的位置
// return : 应该移动的方向,-1时为不移动
//RECT rcScroll[8]={{15,39,24,48},{24,39,483,48},{483,39,492,48},
//{483,48,492,456},{483,456,492,465},{24,456,492,465},
//{15,456,24,465},{15,48,24,456}};
//RECT rcScroll[8]={{24,48,48,72},{48,48,459,72},{459,48,483,72},
//{459,72,483,432},{459,432,483,456},{48,432,459,456},
//{24,432,48,456},{24,72,48,432}};
RECT rcScroll[8]={{24,48,72,96},{72,48,435,96},{435,48,483,96},
{435,96,483,408},{435,408,483,456},{72,408,435,456},
{24,408,72,456},{24,96,72,408}};
#define DRAW_MOVE_SCREEN_DELAY 10
BOOL DRAW_bShowScrollBorder = TRUE;
int DRAW_MoveScreen2( POINT point )
{
int i, nDir = -1;
if( DRAW_bShowScrollBorder )
for ( i=0; i< 8; i++ )
{
DDC_FrameRect( &rcScroll[i], RGB(255,0,0), TRUE );
}
static int nCounter=0;
for ( i=0; i< 8; i++ )
{
if( PtInRect( &rcScroll[i], point ) )
{
nCounter ++;
nDir = i; break;
}
}
if( nDir == -1 )
{
nCounter = 0;
}
else if( nCounter < DRAW_MOVE_SCREEN_DELAY )
{
nDir = -1;
}
return nDir;
} // DRAW_MoveScreen2()
// 将计算好位置的屏幕重新画一遍
// draw moving screen, it should be much faster than DRAW_UpdateScreen()
// ptOff : 新位置与旧位置的偏移量
void DRAW_DrawMoveScreen( POINT ptOff )
{
if( !DRAW_bLoadMaps ) return;
POINT ptDest;
RECT rcRemain;
RECT rcMore1, rcMore2;
// 计算保留部分的矩形
rcRemain.left = rcRemain.top = 0;
rcRemain.right = DRAW_rcClient.right - DRAW_rcClient.left;
rcRemain.bottom = DRAW_rcClient.bottom - DRAW_rcClient.top;
// 计算新增加部分的矩形,一般有两个
// if move to left
if( ptOff.x < 0 )
{
ptDest.x = -ptOff.x;
rcMore1.left = 0; rcMore1.right = -ptOff.x;
//rcMore2.left = rcRemain.left; rcMore2.right = rcRemain.right;
rcMore2.left = -ptOff.x; rcMore2.right = rcRemain.right;
rcRemain.right += ptOff.x;
}
else
{
ptDest.x = 0;
rcMore1.left = rcRemain.right-ptOff.x; rcMore1.right = rcRemain.right;
//rcMore2.left = rcRemain.left; rcMore2.right = rcRemain.right;
rcMore2.left = 0; rcMore2.right = rcRemain.right-ptOff.x;
rcRemain.left += ptOff.x;
}
// if move to top
if( ptOff.y < 0 )
{
ptDest.y = -ptOff.y;
rcMore1.top = 0; rcMore1.bottom = rcRemain.bottom;
rcMore2.top = 0; rcMore2.bottom = -ptOff.y;
rcRemain.bottom += ptOff.y;
}
else
{
ptDest.y = 0;
rcMore1.top = 0; rcMore1.bottom = rcRemain.bottom;
rcMore2.top = rcRemain.bottom - ptOff.y; rcMore2.bottom = rcRemain.bottom;
rcRemain.top += ptOff.y;
}
// draw the part on screen that remains to the new position
// 拷贝地形背景面上保留的区域到新的位置
DRAW_sBkGround.BltSurface( ptDest.x, ptDest.y,
DRAW_sBkGround.GetSurface(),
&rcRemain, DDBLTFAST_NOCOLORKEY );
// 拷贝屏幕背景面上保留的区域到新的位置
OffsetRect( &rcRemain, DRAW_rcClient.left, DRAW_rcClient.top );
ptDest.x += DRAW_rcClient.left;
ptDest.y += DRAW_rcClient.top;
DD_BltSurface( ptDest, DD_GetBackBuffer(),
&rcRemain, DD_GetBackBuffer(), DDBLTFAST_NOCOLORKEY );
// 拷贝阴影背景面上保留的区域到新的位置
SHADOW_MoveBack( ptDest, &rcRemain );
// 在新增加的矩形区域内显示新的单元和地形
if( !IsRectEmpty( &rcMore1 ) )
{
OffsetRect( &rcMore1, DRAW_rcClient.left, DRAW_rcClient.top );
DRAW_DrawGround( rcMore1, 0, FALSE );
DRAW_DrawGround( rcMore1, 1, FALSE );
DRAW_DrawGround( rcMore1, 2, FALSE );
DRAW_DrawBack2BkGround( &rcMore1 );
DRAW_DrawUnit( rcMore1, FALSE );
SHADOW_DrawAll( &rcMore1 );
}
if( !IsRectEmpty( &rcMore2 ) )
{
OffsetRect( &rcMore2, DRAW_rcClient.left, DRAW_rcClient.top );
DRAW_DrawGround( rcMore2, 0, FALSE );
DRAW_DrawGround( rcMore2, 1, FALSE );
DRAW_DrawGround( rcMore2, 2, FALSE );
DRAW_DrawBack2BkGround( &rcMore2 );
DRAW_DrawUnit( rcMore2, FALSE );
SHADOW_DrawAll( &rcMore2 );
}
// 显示影子
// draw shadow
//SHADOW_DrawAll();
// draw shadow
SHADOW_Update2Back();
// debug
// DDC_FrameRect( &rcMore1, RGB(255,0,0), TRUE );
// DDC_FrameRect( &rcMore2, RGB(255,0,0), TRUE );
// 更新缩略图
// draw minimap, do not erase blink point array
// draw to back buffer
// July 23. 1997
MINI_Update( 0, FALSE );
FACE_BlitCurrentMenu();
// update to front buffer
// July 23. 1997
MINI_Update( 2, FALSE );
} // DRAW_DrawMoveScreen()
// 如果鼠标点击缩略图,或者游戏一开始时,使屏幕跳到相应位置
// if mouse hit minimap, should jump the screen to the point
// ptCenter : mouse hit point, in grid
// return value : TRUE if jumped
BOOL DRAW_JumpScreen( POINT ptCenter )
{
// if not hit minimap, not jump screen
if( ptCenter.x == -1 ) return FALSE;
// save old top-left point
POINT ptTopLeft;
ptTopLeft.x = DRAW_rcScreen.left;
ptTopLeft.y = DRAW_rcScreen.top;
// DRAW_rcScreen should always be larger than (0,0,640,480)
// calc new DRAW_rcScreen
int width = DRAW_rcScreen.right - DRAW_rcScreen.left;
int height = DRAW_rcScreen.bottom - DRAW_rcScreen.top;
// adjust
int nOffX = ptCenter.x - (width>>1);
int nOffY = ptCenter.y - (height>>2)-12;
if( nOffX < 0 ) nOffX = 0;
if( nOffX >= MAP_Lib.szNum.cx-width ) nOffX = MAP_Lib.szNum.cx-width-1;
if( nOffY < 0 ) nOffY = 0;
if( nOffY > MAP_Lib.szNum.cy-height+9 ) nOffY = MAP_Lib.szNum.cy-height+9;
// set
DRAW_rcScreen.left = nOffX;
DRAW_rcScreen.right = DRAW_rcScreen.left + width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -