📄 ui.cpp
字号:
// UI.cpp: implementation of the CUI class.
//
//////////////////////////////////////////////////////////////////////
#include "UI.h"
#include "..\System\resfile.h"
#include "Game.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CUI::CUI(CEngine*p)
{
m_pGfx = 0;
m_arrAni = 0;
m_lastresult = -1;
m_angle = 0;
m_iPowerBarFlashCpt = 0;
m_pEngine = p;
}
CUI::~CUI()
{
if (m_pAnim)
delete []m_pAnim;
if (m_AnimString)
delete []m_AnimString;
}
void CUI::LoadRes(CEngine *pEngine)
{
SYS_ASSERT(m_pGfx != 0 && pEngine != 0);
LoadAnimations(pEngine);
m_Images[IMAGE_SMALLPIN] = m_pGfx->LoadBmp("res\\pin.bbm", true);
m_Images[IMAGE_BG] = m_pGfx->LoadBmp("res\\MENU_BG.bbm", true);
m_Images[IMAGE_BG2] = m_pGfx->LoadBmp("res\\MENU_BG2.bbm", true);
m_Images[IMAGE_BG3] = m_pGfx->LoadBmp("res\\MENU_BG3.bbm", true);
m_Images[IMAGE_GAMELOFT] = m_pGfx->LoadBmp("res\\gameloft.bbm");
m_Images[IMAGE_STAR] = m_pGfx->LoadBmp("res\\star.bbm", true);
m_Images[IMAGE_MENULINE] = m_pGfx->LoadBmp("res\\menuline.bbm", true);
m_Images[IMAGE_CLUB] = m_pGfx->LoadBmp("res\\clubs.bbm", true);
m_Images[IMAGE_SPLASH] = m_pGfx->LoadBmp("res\\splash.bbm", true);
m_Images[IMAGE_POWERFIRE] = m_pGfx->LoadBmp("res\\fire.bbm", true);
m_Images[IMAGE_TVSPECULAR] = m_pGfx->LoadBmp("res\\pm.bbm", true);
m_Images[IMAGE_REPTUT] = m_pGfx->LoadBmp("res\\reptut.bbm", true);
m_Images[IMAGE_TVSPLASHA1] = m_pGfx->LoadBmp("res\\tvsplasha_1.bbm", true);
m_Images[IMAGE_TVSPLASHA2] = m_pGfx->LoadBmp("res\\tvsplasha_2.bbm", true);
m_Images[IMAGE_TVSPLASHA3] = m_pGfx->LoadBmp("res\\tvsplasha_3.bbm", true);
m_Images[IMAGE_TVSPLASHA4] = m_pGfx->LoadBmp("res\\tvsplasha_4.bbm", true);
m_Images[IMAGE_TVSPLASHA5] = m_pGfx->LoadBmp("res\\tvsplasha_5.bbm", true);
m_Images[IMAGE_TVSPLASHA6] = m_pGfx->LoadBmp("res\\tvsplasha_6.bbm", true);
m_Images[IMAGE_TVSPLASHA7] = m_pGfx->LoadBmp("res\\tvsplasha_7.bbm", true);
m_Images[IMAGE_TVSPLASHA8] = m_pGfx->LoadBmp("res\\tvsplasha_8.bbm", true);
m_Images[IMAGE_TVSPLASHB1] = m_pGfx->LoadBmp("res\\tvsplashb_1.bbm", true);
m_Images[IMAGE_TVSPLASHB2] = m_pGfx->LoadBmp("res\\tvsplashb_2.bbm", true);
m_Images[IMAGE_TVSPLASHB3] = m_pGfx->LoadBmp("res\\tvsplashb_3.bbm", true);
m_Images[IMAGE_TVSPLASHB4] = m_pGfx->LoadBmp("res\\tvsplashb_4.bbm", true);
m_Images[IMAGE_TVSPLASHB5] = m_pGfx->LoadBmp("res\\tvsplashb_5.bbm", true);
m_Images[IMAGE_TVSPLASHB6] = m_pGfx->LoadBmp("res\\tvsplashb_6.bbm", true);
m_Images[IMAGE_TVSPLASHB7] = m_pGfx->LoadBmp("res\\tvsplashb_7.bbm", true);
m_Images[IMAGE_TVSPLASHB8] = m_pGfx->LoadBmp("res\\tvsplashb_8.bbm", true);
m_Icon[ICON_A] = m_pGfx->LoadBmp("res\\chooseball_a.bbm", true);
m_Icon[ICON_B] = m_pGfx->LoadBmp("res\\chooseball_b.bbm", true);
m_Icon[ICON_C] = m_pGfx->LoadBmp("res\\chooseball_c.bbm", true);
m_Icon[ICON_D] = m_pGfx->LoadBmp("res\\chooseball_d.bbm", true);
m_Icon[ICON_E] = m_pGfx->LoadBmp("res\\chooseball_e.bbm", true);
m_Icon[ICON_F] = m_pGfx->LoadBmp("res\\chooseball_f.bbm", true);
m_Icon[ICON_G] = m_pGfx->LoadBmp("res\\chooseball_g.bbm", true);
if ((m_Images[IMAGE_GAMELOFT] == NULL)) {
DBGPRINTF("Image Load Failure");
SYS_ASSERT(0);
}
}
void CUI::DrawSmallPin(int x, int y, bool bInv)
{
m_pGfx->DrawBmp(x-2, y-4, m_Images[IMAGE_SMALLPIN]->w, m_Images[IMAGE_SMALLPIN]->h, m_Images[IMAGE_SMALLPIN], 0, 0, 0);
}
void CUI::DrawButton(int type, const char *str)
{
switch (type)
{
case 0: //left
m_pAnim[IDA_BUTTON].drawFrame(BUTTONF_LEFT, 0, SCREEN_HEIGHT);
DrawMenuString(18, SCREEN_HEIGHT-10, str, 1);
break;
case 1: //right
m_pAnim[IDA_BUTTON].drawFrame(BUTTONF_RIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
DrawMenuString(SCREEN_WIDTH-18, SCREEN_HEIGHT-10, str, 1);
break;
case 2: //in game
m_pAnim[IDA_BUTTON].drawFrame(BUTTONF_INGAME, SCREEN_WIDTH, SCREEN_HEIGHT);
break;
}
}
// x: [-n..n]
void CUI::DrawDirection(const CGraphics3D *p, int x, int base)
{
int xx, yy;
if (p->get2DPos(base+x/2, 800, 10, xx, yy))
m_pAnim[IDA_AIMSPOT].drawFrame(AIMSPOTF_PT4, xx, yy);
if (p->get2DPos(base+x/3, 600, 10, xx, yy))
m_pAnim[IDA_AIMSPOT].drawFrame(AIMSPOTF_PT3, xx, yy);
if (p->get2DPos(base+x/6, 400, 10, xx, yy))
m_pAnim[IDA_AIMSPOT].drawFrame(AIMSPOTF_PT2, xx, yy);
if (p->get2DPos(base, 200, 10, xx, yy))
m_pAnim[IDA_AIMSPOT].drawFrame(AIMSPOTF_PT1, xx, yy);
}
void CUI::FirstInit(CGfx *pGfx, CFont *pFont)
{
m_pGfx = pGfx;
m_pFont = pFont;
}
// curPower from 0-100;
void CUI::DrawPowerBar(int curPower, int ballWeight, bool bflash)
{
SYS_ASSERT((0<=curPower) && (curPower<=100));
m_iPowerBarFlashCpt++;
//loop in 5, 6, 7
if (m_iPowerBarFlashCpt > 7)
m_iPowerBarFlashCpt = 5;
int i = curPower;
const int DOWN_POWER_LEN = 40;
const int YTOP=80;
int foulpower = 80;//FOUL_POWER(ballWeight); //Milo 01-27
if (i > foulpower)
{
if (m_iPowerBarFlashCpt < 5)
m_iPowerBarFlashCpt = 5;
if (bflash)
{
if (m_iPowerBarFlashCpt>6)
{
m_pAnim[IDA_POWERBAR].drawFrame(POWERBARF_POWEROUT, 10, YTOP);//
if(i>97)
m_pAnim[IDA_POWERBAR].drawFrame(POWERBARF_FOUL, 10, YTOP);//
}
m_pAnim[IDA_POWERBAR].drawFrame(POWERBARF_WARNING, 10, YTOP);
}
else
m_pAnim[IDA_POWERBAR].drawFrame(POWERBARF_NORMAL, 10, YTOP);
m_pGfx->DrawBmp(12, YTOP+3+100-i, 23, i, m_pAnim[IDA_POWERBAR].m_pImage, 63, 3+100-i, 0);
}
else
{
m_pAnim[IDA_POWERBAR].drawFrame(POWERBARF_NORMAL, 10, YTOP);
m_pGfx->DrawBmp(12, YTOP+3+100-i, 23, i, m_pAnim[IDA_POWERBAR].m_pImage, 29, 7+100-i, 0);
if (bflash && i == foulpower)
m_pGfx->DrawBmp(-1, YTOP-28, 43, 136, m_Images[IMAGE_POWERFIRE], m_iPowerBarFlashCpt*43,
0, GFX_SEMITRANS);
}
//draw GREEN ARROW
m_pAnim[IDA_POWERBAR].drawFrame(POWERBARF_ARROW, 10, YTOP+2+100-foulpower);//ballWeight
}
void CUI::DrawBottle(int status, int y, int aimpinid, int aimpos, int aimdir)
{
const int pos[10][2] = {{153, 24}, {149, 18}, {157, 18}, {145, 12}, {153, 12}, {161, 12}, {141, 6}, {149, 6}, {157, 6}, {165, 6}};
for (int i=0; i<10; i++) {
if (status&1)
m_pAnim[IDA_AIMSPOT].drawModule(5, pos[i][0]-1, pos[i][1]-1-y);
else
m_pAnim[IDA_AIMSPOT].drawModule(6, pos[i][0], pos[i][1]-y);
status >>=1;
}
int ax, ay;
if (aimpos == -1)
{
ax = pos[aimpinid][0]-1;
ay = pos[aimpinid][1]-y;
}
else if (aimpos == 1)
{
ax = pos[aimpinid][0]+6;
ay = pos[aimpinid][1]-y;
}
else
{
ax = pos[aimpinid][0]+3;
ay = pos[aimpinid][1]-y+5;
}
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_AIMMID-aimdir, ax, ay);
}
void CUI::DrawScoreNum(int x, int y, int num)
{
char temp[4];
SPRINTF(temp, "%d", num);
int sx = x;
int count = STRLEN(temp);
sx = x-count*5/2;
for (int i=0; i<count; i++, sx+=5)
m_pAnim[IDA_SCOREBAR].drawModule((temp[i]-48) + 4, sx, y);
}
#define SCORED_FILL_COLOR 0xE811
//return the right x position
int CUI::DrawRoundScore(const int maxRound,int roundindex, const ScoreInfo *pScore, int x, int y, int curround)
{
if (roundindex >=maxRound) return x;
int re = x+m_pAnim[IDA_SCOREBAR].GetModuleWidth(0);
if (roundindex == maxRound-1)
{
m_pAnim[IDA_SCOREBAR].drawModule(1, x, y);
DrawScoreNum(x+18, y+3, roundindex+1);
re = x+m_pAnim[IDA_SCOREBAR].GetModuleWidth(1);
}
else
{
m_pAnim[IDA_SCOREBAR].drawModule(0, x, y);
DrawScoreNum(x+12, y+3, roundindex+1);
}
if (pScore->iScores <= roundindex*2)
return re;
int maxScored = maxRound*2+1;
int score1 = pScore->scores[roundindex * 2];
int score2 = (pScore->iScores< (roundindex+1)*2)?-1:pScore->scores[roundindex * 2+1];
int ya = y+13, yc = y+25, startx=x;
if (roundindex == maxRound-1)
{
m_pGfx->FillRec(x+3, y+3, 31, 6, SCORED_FILL_COLOR);
DrawScoreNum(x+18, y+3, roundindex+1);
int i;
if (pScore->iScores==maxScored)
{
DrawScoreNum(startx+18, yc, pScore->totalScores[maxRound-1]);
}
for (i=0; i<3; i++)
{
if (roundindex * 2+i == pScore->iScores)
return re;
score1 = pScore->scores[roundindex * 2+i];
if (score1 == 10)
{
if(i>1 && pScore->scores[roundindex*2+i-1] == 0)
{
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_SPARE, startx+2, ya);
}
else
{
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_STRIKE, startx+2, ya);
}
}
else if(score1 == 0)
{
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_GUTTER, startx+2, ya);
}
else if (i==1 && score1 + pScore->scores[roundindex*2+i-1] == 10)
{
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_SPARE, startx+2, ya);
}
else if (i==2 && score1 + pScore->scores[roundindex*2+i-1] == 10
&& pScore->scores[roundindex*2+i-1] + pScore->scores[roundindex*2+i-2] != 10)
{
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_SPARE, startx+2, ya);
}
else
{
DrawScoreNum(startx+7, ya, score1);
}
startx += 12;
}
return re;
}
m_pGfx->FillRec(x+3, y+3, 19, 6, SCORED_FILL_COLOR);
DrawScoreNum(x+13, y+3, roundindex+1);
if (score1 == 10)
{
//draw strike at a
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_STRIKE, x+3, ya);
//draw c
if ((pScore->iScores-roundindex*2 >= 5 ||
(pScore->iScores-roundindex*2==4 && pScore->scores[(roundindex+1)*2] != 10) ||
pScore->iScores==maxScored))
DrawScoreNum(x+14, yc, pScore->totalScores[roundindex]);
}
else
{
//draw a
if (score1 == 0)
{
//draw gutter at a
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_GUTTER, x+3, ya);
}
else
{
//draw num
DrawScoreNum(x+7, ya, score1);
}
//draw b
if (score2 < 0)
return re;
if (score2 == 0)
{
//draw gutter at b
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_GUTTER, x+14, ya);
}
else if (score2 + score1 == 10)
{
//draw space at b
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_SPARE, x+14, ya);
}
else
{
//draw num
DrawScoreNum(x+18, ya, score2);
}
//draw c
if ((!(pScore->iScores-roundindex*2 < 3 && score2 + score1 == 10)) ||
pScore->iScores==maxScored)
DrawScoreNum(x+12, yc, pScore->totalScores[roundindex]);
}
return re;
}
void CUI::DrawScoreBoard(int y, const ScoreInfo *pScore, int pinMode, int playerid, int maxRound
, int aimpinid, int aimpos, int aimdir, const char* p1name,
const char*p2name, bool isDraw, int p2ExtraCount, int player2score)
{
char str[4]; //score string
char plus[2];
SPRINTF(str, "%d", pScore->preciseScore);
m_pAnim[IDA_INFOBAR].drawFrame(INFOBARF_ONEPLAYER+(p2name==0?0:1), 0, -y);
m_pFont->drawString(p1name, 3, 40-y, -1, FONT_MINI);
if(isDraw)
{
m_pFont->drawString(str, 1, 46-y, -1, FONT_MINI);
SPRINTF(plus, "+");
m_pFont->drawString(plus, 14, 43-y, -1, FONT_NORMAL);
SPRINTF(str, "%d", pScore->extraCount);
m_pFont->drawString(str, 20, 46-y, -1, FONT_MINI);
}
else
{
m_pFont->drawString(str, 3, 46-y, -1, FONT_MINI);
}
if (p2name)
{
SPRINTF(str, "%d", player2score);
m_pFont->drawString(p2name, 40, 40-y, MAKERGB(128, 128, 128), FONT_MINI);
if(isDraw)
{
m_pFont->drawString(str, 34, 46-y, MAKERGB(128, 128, 128), FONT_MINI);
SPRINTF(plus, "+");
m_pFont->drawString(plus, 46, 43-y,MAKERGB(128, 128, 128), FONT_NORMAL);
SPRINTF(str, "%d", p2ExtraCount);
m_pFont->drawString(str, 53, 46-y,MAKERGB(128, 128, 128), FONT_MINI);
}
else
{
m_pFont->drawString(str, 40, 46-y, MAKERGB(128, 128, 128), FONT_MINI);
}
}
int curround = (pScore->iScores-1)/2;
if (curround < 0) curround = 0;
if (curround > (maxRound-1)) curround = (maxRound-1);
int temp = curround;
if (curround*2 == pScore->iScores)
temp--;
if (temp<0) temp = 0;
byte id = temp/4;
int startx = 38, xoff = 24;
m_pAnim[IDA_HEAD].drawModule(playerid, 2, 2-y);
DrawBottle(pinMode,y, aimpinid, aimpos, aimdir);
//draw scores
int i = 0;
if(maxRound == 8)
{//deal with maxRound is 8
if(curround<4)
{
for (i = 0; i<4; i++)
{
startx = DrawRoundScore(maxRound,i, pScore, startx, 1-y, curround)-1;
}
}
else if(curround<7)
{
for (i = 4; i<7; i++)
{
startx = DrawRoundScore(maxRound,i, pScore, startx, 1-y, curround)-1;
}
}
else if(curround < 8)
{
i =7;
startx = DrawRoundScore(maxRound,i, pScore, startx, 1-y, curround)-1;
++i;
}
}
else
{
for (i = id*4; (i<(id+1)*4)&&i<maxRound; i++)
{
startx = DrawRoundScore(maxRound,i, pScore, startx, 1-y, curround)-1;
}
}
if (i > maxRound-1)
{
m_pAnim[IDA_SCOREBAR].drawModule(2, startx, 1-y);
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_TOTAL, startx+18, 4-y);
}
if (pScore->iScores == maxRound*2+1)
{
m_pGfx->FillRec(startx+3, 4-y, 31, 6, SCORED_FILL_COLOR);
m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_TOTAL, startx+18, 4-y);
char plus[2];
if(isDraw)
{
DrawScoreNum(startx+10, 26-y,pScore->totalScores[maxRound]);
SPRINTF(plus, "+");
m_pFont->drawString(plus, startx+18, 24-y, -1, FONT_NORMAL);
DrawScoreNum(startx+30,26-y, pScore->extraCount);
}
else
{
DrawScoreNum(startx+18, 26-y, pScore->totalScores[maxRound]);
}
}
}
void CUI::DrawHintInfo(int y, char *str, int x)
{
const unsigned short color = MAKERGB(0,0,160);//(73, 80, 125);
m_pGfx->DrawColorMask(MAKERGB(64, 64, 64), color, 2, 38-y+1, 172, 12);
DrawMenuString(x, 38-y+3, str, 0, 1, 0, 1100);
m_pAnim[IDA_INFOBAR].drawFrame(INFOBARF_HINT, 0, 38-y);
}
void CUI::DrawAllScoreBoard(const int maxRound, const ScoreInfo *pScore, int y, const char* name, bool isDraw)
{
int curround = pScore->iScores/2;
if (curround > (maxRound-1)) curround = maxRound-1;
byte id = curround/4;
const int SCORE_SHORT_LEN = m_pAnim[IDA_SCOREBAR].GetModuleWidth(0);
const int SCORE_LONG_LEN = m_pAnim[IDA_SCOREBAR].GetModuleWidth(1);
int startx = (SCREEN_WIDTH - SCORE_SHORT_LEN*6 + 5)>>1, starty = y, firstlinecnt = 6;
int startx2 = startx;
//m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_BAR61, 88, y);
//m_pAnim[IDA_SCOREBAR].drawFrame(SCOREBARF_BAR62, 88, y+36);
if (maxRound == 5)
{
startx = (SCREEN_WIDTH - SCORE_SHORT_LEN*4 + 3)>>1;
startx2 = (SCREEN_WIDTH-SCORE_LONG_LEN*2+1)>>1;
firstlinecnt = 4;
}
else if (maxRound == 6)
{
startx = (SCREEN_WIDTH - SCORE_SHORT_LEN*4 + 3)>>1;
startx2 = startx;
firstlinecnt = 4;
}
else if (maxRound == 8)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -