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

📄 ui.cpp

📁 一个3D的保龄球的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			startx = (SCREEN_WIDTH - SCORE_SHORT_LEN*5 + 4)>>1;
			startx2 = startx;
			firstlinecnt = 5;
		}
		DrawMenuString(startx, y-10, name);
		//draw scores
		for (int i = 0; i<maxRound; i++)
		{
			startx = DrawRoundScore(maxRound,i, pScore, startx, starty, curround)-1;
			if (i == firstlinecnt-1)
			{
				startx = startx2;
				starty += 36;
			}
		}
		m_pAnim[IDA_SCOREBAR].drawModule(2, startx, starty);
		m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_TOTAL, startx+18, starty+3);
		
		if (pScore->iScores == maxRound*2+1)
		{
			m_pGfx->FillRec(startx+3, starty+3, 31, 6, SCORED_FILL_COLOR);
			m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_TOTAL, startx+18, starty+3);
			
			char plus[2];
			if(isDraw)//|| pScore->extraCount > 0)
			{
				DrawScoreNum(startx+10, starty+18, pScore->totalScores[maxRound]);
				SPRINTF(plus, "+");
				m_pFont->drawString(plus, startx+18, starty+15, -1, FONT_NORMAL);
				//SPRINTF(plus, "%d", pScore->extraCount);
				//m_pFont->drawString(plus, startx+26, starty+18, -1, FONT_MINI);
				DrawScoreNum(startx+29, starty+18, pScore->extraCount);	
			}	
			else
			{
				DrawScoreNum(startx+18, starty+18, pScore->totalScores[maxRound]);		
			}
		}
}


void CUI::LoadAnimations(CEngine *pEngine)
{	
	void *m_pFile = NULL;
	const char Anim_String[] = "res\\out.bin";
	int rest_size;
	rest_size = pEngine->GetRes()->LoadFileToStack(Anim_String, &m_pFile);
	CBufReader pData;
	if( m_pFile )
		pData.CBufReader_init(m_pFile, rest_size);
	else	{
		pEngine->GetMem()->StackFree(NULL);
		return;
	}
	byte *temp;
	m_AnimCount = 0;
	m_AnimCount = pData.ReadUShortReverse();
	if (m_AnimCount)	{
		temp = new byte[m_AnimCount*4];
		pData.ReadBlock(temp, m_AnimCount*4);
		delete []temp;
	}
	m_aImageCount = pData.ReadUShortReverse();
	m_AnimString = NULL;
	m_AnimString = new char[m_aImageCount][30];
	m_pAnimImage = (GFXBMP **)pEngine->GetMem()->GlobalMalloc((sizeof(GFXBMP*)) * m_aImageCount);
	if (!m_AnimString)	{
		pEngine->GetMem()->StackFree(NULL);
		return;
	}
	int i;
	for (i=0; i<m_aImageCount; i++)	{
		pData.ReadChar();
		STRCPY(m_AnimString[i], "res\\");
		pData.ReadString(&m_AnimString[i][4]);
		int len = STRLEN(m_AnimString[i]);
		STRCPY(&m_AnimString[i][len-3], "bbm");
		m_pAnimImage[i] = pEngine->GetGfx()->LoadBmp(m_AnimString[i], true);
	}
	m_AnimCount = pData.ReadUShortReverse();
	if (!m_AnimCount)	{
		pEngine->GetMem()->StackFree(NULL);
		return;
	}
	m_pAnim = NULL;
	m_pAnim = new CAnimation[m_AnimCount];
	if (!m_AnimCount)	{
		pEngine->GetMem()->StackFree(NULL);
		return;
	}
	for (i=0; i<m_AnimCount; i++)	{
		m_pAnim[i].SetEngine(pEngine);
		pData.ReadUShortReverse();
		m_pAnim[i].loadAnimation(pData);
		m_pAnim[i].m_pImage = m_pAnimImage[m_pAnim[i].ImageID];
	}
	pEngine->GetMem()->StackFree(NULL);
}

void CUI::DrawDeliverResult(int resultType, int anim)
{
	int x, y;
	if (resultType == RESULTNUMA_STRIKE)	{
		if (anim >= m_pAnim[IDA_STRIKE].GetActionSize(STRIKEA_STRIKE))
			anim = m_pAnim[IDA_STRIKE].GetActionSize(STRIKEA_STRIKE)-1;
	}	else
		if (anim >= m_pAnim[IDA_RESULTNUM].GetActionSize(resultType))
			anim = m_pAnim[IDA_RESULTNUM].GetActionSize(resultType)-1;
		switch (resultType)	{
		case RESULTNUMA_REPLAY:
			x =17;
#ifdef LG
			y = 25;
#else
			y = 26;
#endif
			break;
		default:
		x=SCREEN_WIDTH/2;
		y = 95;
	}
	if (resultType == RESULTNUMA_STRIKE)
		m_pAnim[IDA_STRIKE].drawAction(STRIKEA_STRIKE, anim, x, y);
	else
		m_pAnim[IDA_RESULTNUM].drawAction(resultType, anim, x, y);
}

int CUI::GetMenuCharModuleid(char c) const
{
	if ((c >= 'A') && (c <= 'Z'))
		return c-'A';
	if ((c >= 'a') && (c <= 'z'))
		return c-'a';
	if ((c >= '0') && (c <= '9'))
		return c-'0'+26;
	switch (c)	{
	case '-':
		return 36;
	case '/':
		return 37;
	case '*':
		return 38;
	case '\'':
		return 39;
	case '#':
		return 40;
	case ',':
		return 41;
	case '.':
		return 42;
	case '?':
		return 43;
	case '!':
		return 44;
	case ':':
		return 45;
	case '@':
		return 46;
	case '(':
		return 47;
	case ')':
		return 48;
	case '&':
		return 49;
	case '$':
		return 50;
	case '%':
		return 51;
	}
	return 0;
}

void CUI::DrawBonus(const int score, const int suc, int anim)
{
	anim >>= 1;
	if (anim > 4)
		anim = 4;
	SYS_ASSERT(score>0&&score<10&&suc>0&&suc<4&&anim>=0);
	const int aa[5] = {3, 2, 1, 0, 1};
	anim = aa[anim];
	int w = 0;
	w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(10 + anim*13);
	w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(score + anim*13);
	if (suc>1)	{
		w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(11 + anim*13);
		w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(suc + anim*13);
	}
	if (score > 6)
		w += (score-6)*m_pAnim[IDA_RESULTNUM].GetModuleWidth(12 + anim*13);
	w = (SCREEN_WIDTH-w)/2;
	m_pAnim[IDA_RESULTNUM].drawModule(10 + anim*13, w, 110);
	w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(10 + anim*13);
	m_pAnim[IDA_RESULTNUM].drawModule(score + anim*13, w, 110);
	w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(score + anim*13);
	if (suc>1)	{
		m_pAnim[IDA_RESULTNUM].drawModule(11 + anim*13, w, 110);
		w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(11 + anim*13);
		m_pAnim[IDA_RESULTNUM].drawModule(suc + anim*13, w, 110);
		w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(suc + anim*13);
	}
	if (score > 6)	{
		m_pAnim[IDA_RESULTNUM].drawModule(12 + anim*13, w, 110);
		w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(12 + anim*13);
		if (score > 7)	{
			m_pAnim[IDA_RESULTNUM].drawModule(12 + anim*13, w, 110);
			w += m_pAnim[IDA_RESULTNUM].GetModuleWidth(12 + anim*13);
			if (score > 8)
				m_pAnim[IDA_RESULTNUM].drawModule(12 + anim*13, w, 110);	
		}
	}
}

void CUI::DrawMenuBg(int b)
{
	switch (b)	{
	case 0:
//		m_pGfx->FillRec(0, 0, SCREEN_HEIGHT, SCREEN_HEIGHT, 0xffff);
		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(0, 86, 130);
		m_pAnim[IDA_LOGOSPLASH].drawFrame(2, 88, 194);
		return;
	case 1:
		m_pGfx->DrawBmp(0, 0, m_Images[IMAGE_BG]->w, m_Images[IMAGE_BG]->h, m_Images[IMAGE_BG], 0, 0, 0);
		break;
	case 2:
		m_pGfx->DrawBmp(0, 0, m_Images[IMAGE_BG2]->w, m_Images[IMAGE_BG2]->h, m_Images[IMAGE_BG2], 0, 0, 0);
		break;
	case 3:
		m_pGfx->DrawBmp(0, 0, m_Images[IMAGE_BG3]->w, m_Images[IMAGE_BG3]->h, m_Images[IMAGE_BG3], 0, 0, 0);
		break;
	default:
		m_pGfx->FillRec(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
	}
}

void CUI::DrawGameloft(){
	m_pGfx->DrawBmp((SCREEN_WIDTH-m_Images[IMAGE_GAMELOFT]->w)>>1, (SCREEN_HEIGHT-m_Images[IMAGE_GAMELOFT]->h)>>1, 
		m_Images[IMAGE_GAMELOFT]->w, m_Images[IMAGE_GAMELOFT]->h, m_Images[IMAGE_GAMELOFT], 0, 0, 0);
}

void CUI::DrawMenuString(int x, int y, const char *str, int align, int color, int withArrow, int maxLength)
{
	int endx;
	if (!str)
		return;
	int p;
	int i;
	if (align)	{
		p=0;
		for (i=0; str[i]; i++)
			if (p<maxLength)
				p+=m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(str[i]));
			else
				break;
		if (p>maxLength)
			p-=m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(str[i-1]));
		if (align == 1)
			p=x-p/2;
		else
			p=x-p;
	}	else
		p=x;
	endx = p+maxLength;
	if (withArrow)
		m_pAnim[IDA_MENU].drawModule(0, p-8, y+1);
	if (color)
		for (i=0; str[i]; i++)
			if (p<endx)
				if (str[i] != ' ')	{
					m_pAnim[IDA_MENUFONT].drawModule(GetMenuCharModuleid(str[i]), p, y);
					p+=m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(str[i]));
				}	else
					p+=m_pAnim[IDA_MENUFONT].GetModuleWidth(0);
			else	{
				p-=m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(str[i-1]));
				break;
			}
	else
		for (i=0; str[i]; i++)
			if (p<endx)
				if (str[i] != ' ')	{
					m_pAnim[IDA_MENUFONT].drawModule(GetMenuCharModuleid(str[i])+52, p, y);
					p+=m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(str[i])+52);
				}	else
					p+=m_pAnim[IDA_MENUFONT].GetModuleWidth(0);
			else	{
				p-=m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(str[i-1])+52);
				break;
			}
	if (withArrow)
		m_pAnim[IDA_MENU].drawModule(1, p+4, y+1);
}

void CUI::MainMenuAnim(int y, int sel, int count, int seed)
{
	y-=5;
	int i=0;
	m_angle += 40;
	m_angle%=2048;
	//	m_pGfx->DrawBmp(SCREEN_WIDTH-10-m_Images[IMAGE_STAR]->w-(Sinus(m_angle)*20>>COS_SIN_SHIFT), SCREEN_HEIGHT-m_Images[IMAGE_STAR]->h-(Cosinus(m_angle)*30>>COS_SIN_SHIFT), m_Images[IMAGE_STAR]->w, m_Images[IMAGE_STAR]->h, m_Images[IMAGE_STAR], 0, 0, GFX_SEMITRANS);
	int halfw = m_Images[IMAGE_STAR]->w>>1, halfh = m_Images[IMAGE_STAR]->h>>1;
	//int radius = distanceP2P(halfw, halfh, 0, 0);
	//m_pGfx->DrawRotBmp(SCREEN_WIDTH-10-halfw-((radius*Cosinus(255+m_angle))>>COS_SIN_SHIFT), SCREEN_HEIGHT-halfh-((radius*Sinus(255+m_angle))>>COS_SIN_SHIFT), m_Images[IMAGE_STAR]->w, m_Images[IMAGE_STAR]->h, m_Images[IMAGE_STAR], 0, 0, m_angle, GFX_SEMITRANS);
	m_pGfx->DrawRotBmp(129, 166, m_Images[IMAGE_STAR]->w, m_Images[IMAGE_STAR]->h, m_Images[IMAGE_STAR], 0, 0, m_angle, GFX_SEMITRANS);
	
	seed = 5-seed;
	if (seed < 0)
		seed = 0;
	m_pGfx->DrawFadeMask(0, 255, 0, 0, y+5, 100, 130-(9-count)*13-(sel==(count-1)?seed:0));
	m_pGfx->FillRec(0, 191, SCREEN_WIDTH, SCREEN_HEIGHT-191, 0);
	while (i<count)	{
		if (i==sel)
			m_pGfx->DrawBmp(0, y+seed, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
		else
			if (i==sel+1)
				m_pGfx->DrawBmp(0, y-seed, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
			else
				m_pGfx->DrawBmp(0, y, m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
		if (i==sel)	{
//			m_pGfx->DrawBmp(0, y+3, m_Images[IMAGE_FONTBK]->w, m_Images[IMAGE_FONTBK]->h, m_Images[IMAGE_FONTBK], 0, 0, GFX_SEMITRANS);
			m_pGfx->DrawFadeMask(0, 255, MAKERGB(239, 89, 239), 45, y+3+seed, 60, 26-seed*2);
			m_pGfx->DrawFadeMask(192, 0, MAKERGB(239, 89, 239), 0, y+3+seed, 45, 26-seed*2);
			y += 14;
		}
		i++;
		y+=13;
	}
	m_pGfx->DrawBmp(0, y-(sel+1==i?seed:0), m_Images[IMAGE_MENULINE]->w, m_Images[IMAGE_MENULINE]->h, m_Images[IMAGE_MENULINE], 0, 0, GFX_SEMITRANS);
}

void CUI::DrawMenuHead(int s, int offset, int arr, int enable)
{
	const int y = 20;
	const int w = m_pAnim[IDA_HEAD].GetModuleWidth(0);
	const int h = m_pAnim[IDA_HEAD].GetModuleHeight(0);
	const int count = m_pAnim[IDA_HEAD].GetModuleCount();
	const int span = (SCREEN_WIDTH-w*3)/4;
	const int left = span+offset;
	short color = 255-255*Abs(offset)/30/2;
	color = MAKERGB(color, color, color);
	m_pGfx->FillRec(0, y-6, SCREEN_WIDTH, h+12, 0);
	m_pAnim[IDA_HEAD].drawModule((s+count-2)%count, left-w-span, y);
	m_pGfx->DrawColorMask(MAKERGB(128, 128, 128), 0, left-w-span, y, w, h);
	m_pAnim[IDA_HEAD].drawModule((s+count-1)%count, left, y);
	m_pGfx->DrawColorMask(MAKERGB(128, 128, 128), 0, left, y, w, h);
	const int mid = left+w+span;
	m_pAnim[IDA_HEAD].drawModule(s, mid, y);
	m_pGfx->DrawColorMask(color, 0, mid, y, w, h);
//	m_pGfx->DrawRect(mid-1, y-1, w+1, h+1, 0x07e0);
	const int right = mid+w+span;
	m_pAnim[IDA_HEAD].drawModule((s+1)%count, right, y);
	m_pGfx->DrawColorMask(MAKERGB(128, 128, 128), 0, right, y, w, h);
	m_pAnim[IDA_HEAD].drawModule((s+2)%count, right+w+span, y);
	m_pGfx->DrawColorMask(MAKERGB(128, 128, 128), 0, right+w+span, y, w, h);
	m_arrAni %= m_pAnim[IDA_MENU].GetActionSize(MENUA_2_A)*4;
	if ((!offset) && (arr))	{
		m_pAnim[IDA_MENU].drawAction(MENUA_2_A, (m_arrAni++)/4, SCREEN_WIDTH/2, y+h/2);
		m_pGfx->DrawRect(mid, y, w, h, 0x3ADD);
	}
	if (!arr)
		m_pAnim[IDA_MENU].drawAction(MENUA_2_A, (m_arrAni++)/4, SCREEN_WIDTH/2+40, 120);
	if (enable)	{
		m_pAnim[IDA_MENU].drawFrame(MENUF_2_BG, 8, 100);
		DrawMenuString(17, 112, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_POWER]);
		DrawMenuString(17, 130, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_PRECISION]);
		DrawMenuString(17, 148, ((CGame*)m_pEngine->m_pGame)->GetDataManager()->m_pStringItem[ID_UI_ROTATION]);
		m_pAnim[IDA_MENUFONT2].drawModule(40+s, 30, 88);
	}
	for (int k=0; k<5; k++)	{
		m_pGfx->FillRec(left-6+k*10-w-span, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(left-6+k*10-w-span, y+h+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(left-6+k*10, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(left-6+k*10, y+h+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(mid-6+k*10, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(mid-6+k*10, y+h+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right-6+k*10, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right-6+k*10, y+h+2, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right-6+k*10+w+span, y-4, 3, 2, MAKERGB(128, 128, 128));
		m_pGfx->FillRec(right-6+k*10+w+span, y+h+2, 3, 2, MAKERGB(128, 128, 128));
	}
}

int CUI::StoryString(int playerid, const char *pname, const char *storystring, int next)
{
	m_pAnim[IDA_INFOBAR].drawFrame(INFOBARF_ONEPLAYER, 0, 0);
	m_pFont->drawString(pname, 3, 40, -1, FONT_MINI);
	PlayerHead(playerid);
	if (storystring != m_strStory)	{
		m_strStory = storystring;
		m_iStoryStart = 0;
		m_iStoryCur = 0;
		m_iStoryFull = 0;
		m_iStoryWait = 0;
	}
	if (next)
		if (m_iStoryFull)	{
			if (m_iStoryCur != STRLEN(m_strStory))	{
				m_iStoryStart = m_iStoryCur;
				m_iStoryFull = 0;
			}
		}	else
			m_iStoryCur = STRLEN(m_strStory);
	if (m_iStoryFull)	{
		m_iStoryWait++;
		if (m_iStoryWait > 40)	{
			m_iStoryStart = m_iStoryCur;
			m_iStoryFull = 0;
			m_iStoryWait = 0;
		}
	}	else
		m_iStoryCur+=1;

	if (m_iStoryCur > STRLEN(m_strStory))
		m_iStoryCur = STRLEN(m_strStory);
	const int ystart = 4;
	const int yend = 36-m_pAnim[IDA_MENUFONT].GetModuleHeight(0)-2;
	const int xstart = 39;
	const int xend = 174;
	int curx = xstart;
	int cury = ystart;
	unsigned int i=m_iStoryStart;
	unsigned int j;
	int length;
	while (i<m_iStoryCur)	{
		while (i<m_iStoryCur)
			if (m_strStory[i] == ' ')	{
				i++;
				curx += m_pAnim[IDA_MENUFONT].GetModuleWidth(0);
			}	else
				break;
		j = i;
		while (m_strStory[j] && m_strStory[j] != ' ')
			j++;
		length = 0;
		while (j>i)	{
			j--;
			length += m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(m_strStory[j]));
		}
		if (curx + length>xend)	{
			cury += m_pAnim[IDA_MENUFONT].GetModuleHeight(0)+1;
			if (cury > yend)	{
				m_iStoryCur = i;
				m_iStoryFull = 1;
				return m_iStoryCur-m_iStoryStart;
			}
			curx = xstart;
		}
		while ((i<m_iStoryCur) && m_strStory[i]  != ' ')	{
			m_pAnim[IDA_MENUFONT].drawModule(GetMenuCharModuleid(m_strStory[i]), curx, cury);
			curx += m_pAnim[IDA_MENUFONT].GetModuleWidth(GetMenuCharModuleid(m_strStory[i]));
			i++;
		}
	}
	if (m_iStoryCur >= STRLEN(m_strStory))
		return -1;
	return m_iStoryCur-m_iStoryStart;
}

int CUI::UISplash(int y, int height, int anim)
{
	if (anim < 0)	{
		m_pGfx->DrawColorMask(MAKERGB(32, 32, 32), MAKERGB(0x6e, 9, 0x6a), 0, y-height/2, SCREEN_WIDTH, height);
		return false;
	}
	const int __totalframe = 20;
	const int __finalheight = 100;
	const int __finalwidth = SCREEN_WIDTH;
	anim++;
	if (anim > __totalframe)
		anim = __totalframe;
	const int __curwidth = anim*__finalwidth/__totalframe;
	const int __curheight = anim*__finalheight/__totalframe;
	m_pGfx->DrawColorMask(MAKERGB(64, 64, 64), MAKERGB(0x6e, 9, 0x6a), SCREEN_WIDTH/2-__curwidth/2, SCREEN_HEIGHT/2-__curheight/2, __curwidth, __curheight);
	if (anim == __totalframe)
		return true;
	else
		return false;
}

⌨️ 快捷键说明

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