⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ui.cpp

📁 一个3D的保龄球的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
void CUI::BigString(int x, int y, const char *str, int align)
{
	int p, i;
	if (align)	{
		p = BStrLen(str);
		if (align == 1)
			p = x-p/2;
		else
			p = x-p;
	}	else
		p = x;
	for (i=0; str[i]; i++)
		if (str[i] >= 'A' && str[i] <= 'Z')	{
			m_pAnim[IDA_RESULTNUM].drawModule(str[i]-'A'+52, p, y);
			p+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(str[i]-'A'+52)-2;
		}	else
			if ((str[i] >= 'a' && str[i] <= 'z'))	{
				m_pAnim[IDA_RESULTNUM].drawModule(str[i]-'a'+52, p, y);
				p+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(str[i]-'a'+52)-2;
			}	else
				if (str[i] >= '0' && str[i] <= '9')	{
					m_pAnim[IDA_RESULTNUM].drawModule(str[i]-'0'+26, p, y);
					p+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(str[i]-'0'+26)-2;
				}	else
					if (str[i] == '!')	{
						m_pAnim[IDA_RESULTNUM].drawModule(12+26, p, y);
						p+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(12+26)-2;
					}	else
						p+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(0)-2;
}

void CUI::PlayerHead(int id, int x, int y)
{
	m_pAnim[IDA_HEAD].drawModule(id, x, y);
}

void CUI::DrawBmp2Buf(GFXBMP *dest, int dx, int dy, int id, int sx, int sy, int flag)
{
	if (!id)
		return;
	GFXBMP *old = m_pGfx->GetVideo();
	dest->bpp = old->bpp;
	dest->flag = 0;
	dest->npal = 0;
	m_pGfx->SetVideoBmp(dest);
	m_pGfx->DrawBmp(dx, dy, m_Icon[id]->w, m_Icon[id]->h, m_Icon[id], sx, sy, flag);
	m_pGfx->SetVideoBmp(old);
}

void CUI::DrawHand(int playerid, int x, int y)
{
	m_pAnim[IDA_HANDS].drawModule(playerid, x, SCREEN_HEIGHT-m_pAnim[IDA_HANDS].GetModuleHeight(playerid)+y);
}

void CUI::Rotation(int curRot)
{
	if (!curRot)
		m_rotframe = 48000000;
	else
		m_rotframe += curRot;
	if (((m_rotframe-12)%48)<24)
		m_pAnim[IDA_SPIN].drawAction(SPINA_01, 24, 140, 150);
	else	{
		m_pAnim[IDA_SPIN].drawAction(SPINA_01, (m_rotframe-12)%48-24, 140, 150);
		if (curRot>0)
			m_pAnim[IDA_SPIN].drawAction(SPINA_02, ((m_rotframe-12)%48-24)*m_pAnim[IDA_SPIN].GetActionSize(SPINA_02)/24, 140, 150);
		if (curRot<0)
			m_pAnim[IDA_SPIN].drawAction(SPINA_03, (47-(m_rotframe-12)%48)*m_pAnim[IDA_SPIN].GetActionSize(SPINA_03)/24, 140, 150);
	}
}

void CUI::LaneEffect(int sel, int y, int offset)
{
	const int width = m_Images[IMAGE_CLUB]->w;
	const int height = m_Images[IMAGE_CLUB]->h/3;
	const int span = (SCREEN_WIDTH-width*3)/4;
	const int left = span+offset;
	m_pGfx->FillRec(0, y-6, SCREEN_WIDTH, height+12, 0);
	const int mid = left+width+span;
	const int right = mid+width+span;
	short color = 255-255*Abs(offset)/30/2;
	color = MAKERGB(color, color, color);
	m_pGfx->DrawBmp(left, y, width, height, m_Images[IMAGE_CLUB], 0, ((sel+2)%3)*height, 0);
	m_pGfx->DrawColorMask(MAKERGB(128, 128, 128), 0, left, y, width, height);
	m_pGfx->DrawBmp(mid, y, width, height, m_Images[IMAGE_CLUB], 0, (sel%3)*height, 0);
	m_pGfx->DrawColorMask(color, 0, mid, y, width, height);
	m_pGfx->DrawBmp(right, y, width, height, m_Images[IMAGE_CLUB], 0, ((sel+1)%3)*height, 0);
	m_pGfx->DrawColorMask(MAKERGB(128, 128, 128), 0, right, y, width, height);
	if (!offset)	{
		const int ww = m_pAnim[IDA_MENU].GetModuleWidth(0);
		m_pAnim[IDA_MENU].drawModule(0, SCREEN_WIDTH/2-width/2-ww-3, y+height/2-3);
		m_pAnim[IDA_MENU].drawModule(1, SCREEN_WIDTH/2+width/2+4, y+height/2-3);
		m_pGfx->DrawRect(mid, y, width, height, 0x3ADD);
	}
	for (int k=0; k<6; k++)	{
		m_pGfx->FillRec(left+k*9-width-span, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(left+k*9-width-span, y+height+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(left+k*9, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(left+k*9, y+height+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(mid+k*9, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(mid+k*9, y+height+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right+k*9, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right+k*9, y+height+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right+k*9+width+span, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right+k*9+width+span, y+height+2, 3, 2, MAKERGB(128, 128, 128));
	}
}

void CUI::Ball2D(unsigned short *buf, int x, int y)
{
	unsigned short *bb = reinterpret_cast<unsigned short *>(m_pGfx->GetVideo()->pData);
	int sx = 60;
	int w = 60;
	int sy = 150;
	int h = SCREEN_HEIGHT-sy;
	int dx = 60+x;
	int dy = 150+y;
	if (dx<0)	{
		w += dx;
		dx = 0;
	}
	if (dx+w>SCREEN_WIDTH)
		w = SCREEN_WIDTH-dx;
	if (dy+h>SCREEN_HEIGHT)
		h = SCREEN_HEIGHT-dy;
	int i, j;
	for (i=0; i<h; i++)
		for (j=0; j<w; j++)
			if (buf[(i+sy)*SCREEN_WIDTH+j+sx])
				bb[(i+dy)*SCREEN_WIDTH+j+dx] = buf[(i+sy)*SCREEN_WIDTH+j+sx];
}

void CUI::DrawLButton(int type)
{
	switch (type)	{
	case 1:
		m_pAnim[IDA_MENU].drawFrame(MENUF_ALL_NEXT_1, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
		break;
	case 2:
		DrawMenuString(2, 193, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_BUTTON_NO]);
		break;
	case 3:
//		m_pAnim[IDA_MENU].drawModule(10, 2, 191);
		DrawMenuString(2, 193, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_BUTTON_BACK]);
		break;
	}
}

void CUI::DrawRButton(int type)
{
	switch (type)	{
	case 1:
		m_pAnim[IDA_MENU].drawFrame(MENUF_ALL_BACK_1, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
		break;
	case 2:
		DrawMenuString(SCREEN_WIDTH-2, 193, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_BUTTON_YES], 2);
		break;
	case 3:
		DrawMenuString(SCREEN_WIDTH-2, 193, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_BUTTON_SELECT], 2);
		break;
	}
}

int CUI::MStrLen(const char *str) const
{
	if (!str)
		return 0;
	int i, len;
	len = 0;
	for (i=0; str[i]; i++)
		len += m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(str[i]));
	return len;
}

int CUI::BStrLen(const char *str) const
{
	if (!str)
		return 0;
	int i, len;
	len = 0;
	for (i=0; str[i]; i++)
		if (str[i] >= 'A' && str[i] <= 'Z')
			len+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(str[i]-'A'+52)-2;
		else
			if ((str[i] >= 'a' && str[i] <= 'z'))
				len+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(str[i]-'a'+52)-2;
			else
				if (str[i] >= '0' && str[i] <= '9')
					len+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(str[i]-'0'+26)-2;
				else
					if (str[i] == '!')
						len+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(12+26)-2;
					else
						len+=m_pAnim[IDA_RESULTNUM].GetModuleWidth(0)-2;
	return len;
}

void CUI::RollingString(int x, int y, const char *str, int color)
{
	if (m_strRolling != str)	{
		m_rollinganim = x;
		m_strRolling = str;
	}	else
		m_rollinganim -= 3;
	int l = MStrLen(str);
	if (l<SCREEN_WIDTH)	{
		DrawMenuString(SCREEN_WIDTH/2, y, str, 1, color);
		return;
	}
	if (m_rollinganim+l < 0)
		m_rollinganim = SCREEN_WIDTH;
	DrawMenuString(m_rollinganim, y, str, 0, color, 0, 0xffff);
}

void CUI::PauseBg(int y, int item, int sel, int seed)
{
	y-=5;
	int i=0;
	seed = 5-seed;
	if (seed < 0)
		seed = 0;
	while (i<item)	{
		if (i==sel)	{
			m_pGfx->DrawBmp(SCREEN_WIDTH/2, y+seed, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
			m_pGfx->DrawBmp(SCREEN_WIDTH/2-m_Images[IMAGE_MENULINE]->w, y+seed, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS|GFX_FLIPX);
		}	else
			if (i==sel+1)	{
				m_pGfx->DrawBmp(SCREEN_WIDTH/2, y-seed, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
				m_pGfx->DrawBmp(SCREEN_WIDTH/2-m_Images[IMAGE_MENULINE]->w, y-seed, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS|GFX_FLIPX);
			}	else	{
				m_pGfx->DrawBmp(SCREEN_WIDTH/2, y, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
				m_pGfx->DrawBmp(SCREEN_WIDTH/2-m_Images[IMAGE_MENULINE]->w, y, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS|GFX_FLIPX);
			}
		if (i==sel)	{
			m_pGfx->DrawFadeMask(0, 255, MAKERGB(239, 89, 239), 88, y+3+seed, 80, 26-seed*2);
			m_pGfx->DrawFadeMask(255, 0, MAKERGB(239, 89, 239), 8, y+3+seed, 80, 26-seed*2);
			y += 14;
		}
		i++;
		y+=13;
	}
	m_pGfx->DrawBmp(SCREEN_WIDTH/2, y-(sel+1==i?seed:0), m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
	m_pGfx->DrawBmp(SCREEN_WIDTH/2-m_Images[IMAGE_MENULINE]->w, y-(sel+1==i?seed:0), m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS|GFX_FLIPX);
}

void CUI::MainMenuArrow(int x, int y)
{
	m_pAnim[IDA_MENU].drawModule(7, x+((++m_arrAni&4)>>2), y);
}

void CUI::BonusScoreBoard(int y, int pinMode, int playerid, 
						 int aimpinid, int aimpos, int aimdir, const char* p1name, int lvl, int game, int trytime, int pass)
{
	m_pAnim[IDA_INFOBAR].drawFrame(INFOBARF_ONEPLAYER, 0, -y);
	m_pFont->drawString(p1name, 3, 40-y, -1, FONT_MINI);
	m_pAnim[IDA_HEAD].drawModule(playerid, 2, 2-y);
	DrawBottle(pinMode,y, aimpinid, aimpos, aimdir);
	const int ystart = 4-y;
	const int xstart = 39;
	char str[20] = "";
	DrawMenuString(xstart, ystart, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_BONUS_TITLE]);
	DrawMenuString(xstart, ystart+10, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_BONUS_LEVEL]);
	SPRINTF(str, "      %d-%d", lvl, game);
	DrawMenuString(xstart, ystart+10, str, 0, 0);
	DrawMenuString(xstart, ystart+20, "try");
	SPRINTF(str, "%d", trytime);
	DrawMenuString(xstart+22, ystart+20, str, 0, 0);
	DrawMenuString(xstart+35, ystart+20, "of");
	DrawMenuString(xstart+52, ystart+20, "10");
	DrawMenuString(xstart+65, ystart+20, "pass");
	SPRINTF(str, "%d", pass);
	DrawMenuString(xstart+92, ystart+20, str, 0, 0);
}

void CUI::BigNum(int x, int y, int num, int size)
{
	SYS_ASSERT(size<4&&size>0&&num>=0);
	if (num==12)
		m_pAnim[IDA_RESULTNUM].drawModule(97, x-2, y-2);
	else
		m_pAnim[IDA_RESULTNUM].drawModule(num + size*13, x-2, y-2);
}

int CUI::BStr2Len(const char *str) const
{
	if (!str)
		return 0;
	int i, len;
	len = 0;
	for (i=0; str[i]; i++)
		len+=m_pAnim[IDA_MENUFONT2].GetModuleWidth(GetB2CharModuleid(str[i]))-4;
	return len;
}

void CUI::BigString2(int x, int y, const char *str, int align, int underline)
{
	int p, i, j, k, l;
	if (align)	{
		p = BStr2Len(str);
		if (align == 1)
			p = x-p/2;
		else
			p = x-p;
	}	else
		p = x;
	for (i=0; str[i]; i++)	{
		j = GetB2CharModuleid(str[i]);
		if (str[i] != ' ')
			m_pAnim[IDA_MENUFONT2].drawModule(j, p, y);
		k = m_pAnim[IDA_MENUFONT2].GetModuleWidth(j);
		l = m_pAnim[IDA_MENUFONT2].GetModuleHeight(j);
		if (i==underline)
			m_pGfx->DrawLine(p, y+l+3, p+k-4, y+l+3, MAKERGB(0, 255, 255));
		p+=k-4;
	}
}

void CUI::QMark(int x, int y)
{
	m_pAnim[IDA_MENU].drawFrame(MENUF_QMARK, x, y);
}

//Qiu Li, 2005/1/19
bool CUI::DrawStringEffect(const char ** str, int strCount, int *lineFormats, int cpt, int timeType)
{
	int step = 27;
	int drawPosX, drawPosY;
	int string_width;
	int string_height=m_pAnim[IDA_MENUFONT2].GetModuleHeight(0);//20;
	int height_space = 7;
	bool bNextline = false;
	int center;
	char **string = (char **)str;
	bool ret = false;

	if( cpt == 0 )
	{
		curLine = 0;
		curLine_deltacpt = 0;
	}
	else
	{
		curLine_deltacpt++;
	}

	drawPosY = (SCREEN_HEIGHT - (strCount*(string_height+height_space) - height_space))/2;

	if( timeType == STRING_ONEBYONE )
	{
		for(int i=0; i< strCount; i++ )
		{
			//string_width = STRLEN(*string) * (12) - 3;
			string_width = BStr2Len(*string);
			center = (SCREEN_WIDTH - string_width)/2;

			if( i < curLine )
			{
				drawPosX = center;
				BigString2(drawPosX, drawPosY, *string, 0);	//align left
			}
			else if( i == curLine )
			{	
				//draw string effect
				switch( lineFormats[i] )
				{
				case STRING_FROM_LEFT:
					drawPosX = -string_width + curLine_deltacpt*step - 50;
					if( drawPosX >= center + 30 )
					{
						drawPosX = center;
						bNextline = true;
					}
					BigString2(drawPosX, drawPosY, *string, 0);	//align left
					break;
				case STRING_FROM_RIGHT:
					drawPosX = SCREEN_WIDTH - curLine_deltacpt*step + 50;
					if( drawPosX <= center - 30 )
					{
						drawPosX = center;
						bNextline = true;
					}
					BigString2(drawPosX, drawPosY, *string, 0);	//align left
					break;
				case STRING_FLASH_INTO:
					if( curLine_deltacpt > 5 )
					{
						drawPosX = center;
						BigString2(drawPosX, drawPosY, *string, 0);	//align left
						bNextline = true;
					}
					break;
				default:
					break;
				}

				if( bNextline )
				{
					curLine++;
					curLine_deltacpt=0;
					bNextline = false;
				}

			}//else

			string++;
			drawPosY += string_height+height_space;

		}//for
		if( curLine >= strCount )
			ret = true;
	}
	else if( timeType == STRING_ALL )
	{
		ret = true;

		for( int i=0; i<strCount; i++ )
		{
			//string_width = STRLEN(*string) * (12) - 3;
			string_width = BStr2Len(*string);
			center = (SCREEN_WIDTH - string_width)/2;

			//draw string effect
			switch( lineFormats[i] )
			{
			case STRING_FROM_LEFT:
				drawPosX = -string_width + curLine_deltacpt*step - 50;
				if( drawPosX >= center + 30 )
				{
					drawPosX = center;
				}
				else
					ret = false;
				BigString2(drawPosX, drawPosY, *string, 0);	//align left
				break;
			case STRING_FROM_RIGHT:
				drawPosX = SCREEN_WIDTH - curLine_deltacpt*step + 50;
				if( drawPosX <= center - 30 )
				{
					drawPosX = center;
				}
				else
					ret = false;
				BigString2(drawPosX, drawPosY, *string, 0);	//align left
				break;
			case STRING_FLASH_INTO:
				if( curLine_deltacpt > 5 )
				{
					drawPosX = center;
					BigString2(drawPosX, drawPosY, *string, 0);	//align left
				}
				else
					ret = false;
				break;
			default:
				break;
			}//switch

			string++;
			drawPosY += string_height+height_space;
		}//for
	}//else

	return ret;
}
//Qiu Li

void CUI::Loading(int s)
{
	m_pGfx->DrawBmp(0, 0, m_Images[IMAGE_SPLASH]->w, m_Images[IMAGE_SPLASH]->h, m_Images[IMAGE_SPLASH], 0, 0, 0);
	m_pAnim[IDA_LOGOSPLASH].drawFrame(1, 99, 141);
}

void CUI::TutDialog(int x, int y, char *str, int lr, int bAnim)
{
	int i, j, k;
	if (!bAnim)	{
		if (lr)
			m_pAnim[IDA_INFOBAR].drawFrame(INFOBARF_L, x, y);
		else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -