SBSPSS/source/frontend/maintitl.cpp

521 lines
11 KiB
C++
Raw Normal View History

2000-11-13 20:38:51 +01:00
/*=========================================================================
maintitl.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "frontend\maintitl.h"
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.h"
#endif
2000-11-15 16:37:12 +01:00
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
#ifndef __MATHTABLE_HEADER__
#include "utils\mathtab.h"
#endif
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
#ifndef __GFX_FADER_H__
#include "gfx\fader.h"
#endif
2000-11-22 23:52:08 +01:00
#ifndef __GUI_GFACTORY_H__
#include "gui\gfactory.h"
2000-11-20 16:45:17 +01:00
#endif
#ifndef __GUI_GFRAME_H__
#include "gui\gframe.h"
#endif
2000-11-28 01:06:22 +01:00
#ifndef _FILEIO_HEADER_
#include "fileio\fileio.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-01-19 17:25:05 +01:00
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2001-04-19 23:11:46 +02:00
#ifndef __FRONTEND_FRONTEND_H__
#include "frontend\frontend.h"
#endif
2001-04-25 17:08:23 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-06-20 00:14:00 +02:00
#ifndef __GAME_GAMESLOT_H__
#include "game\gameslot.h"
#endif
2000-11-13 20:38:51 +01:00
/* Std Lib
------- */
/* Data
---- */
2001-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2000-11-13 20:38:51 +01:00
#endif
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2000-11-15 16:37:12 +01:00
///////////////
2001-04-24 01:28:21 +02:00
/*
2000-11-16 00:41:47 +01:00
int seaw=1;
int seah=50;
2000-11-15 16:37:12 +01:00
int seaspeed=20;
int seagap=120;
2000-11-16 00:41:47 +01:00
int seascale=4200;
2000-11-15 16:37:12 +01:00
int seascalegrow=-50;
2000-11-16 00:41:47 +01:00
int colourbase=64;
int colourscale=4000;
int colourpostscale=10;
2000-11-15 16:37:12 +01:00
int sval=0;
2001-04-24 01:28:21 +02:00
*/
2000-11-15 16:37:12 +01:00
///////////////
2000-11-13 20:38:51 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndMainTitles::init()
{
2000-11-15 16:37:12 +01:00
m_sprites=new ("MainTitle Sprites") SpriteBank();
2001-04-20 16:53:35 +02:00
m_sprites->load(SPRITES_SPRITES_SPR);
2000-11-15 16:37:12 +01:00
m_smallFont=new ("MainTitle SmallFont") FontBank();
m_smallFont->initialise(&standardFont);
m_smallFont->setJustification(FontBank::JUST_CENTRE);
2001-04-19 23:11:46 +02:00
m_smallFont->setOt(5);
2000-11-15 16:37:12 +01:00
2001-06-19 23:26:50 +02:00
// Create the main menu ( START GAME/OPTIONS )
2000-11-20 16:45:17 +01:00
m_mainMenu=new ("Main Menu GUI") CGUIControlFrame();
m_mainMenu->init(NULL);
2001-03-07 16:50:17 +01:00
m_mainMenu->setObjectXYWH(106,145,300,60);
2000-11-20 16:45:17 +01:00
m_mainMenu->clearFlags(CGUIObject::FLAG_DRAWBORDER);
2000-11-22 23:52:08 +01:00
CGUIFactory::createValueButtonFrame(m_mainMenu,
50,0,200,20,
STR__FRONTEND__START_GAME,
&m_startGameFlag,true);
CGUIFactory::createValueButtonFrame(m_mainMenu,
50,20,200,20,
STR__FRONTEND__OPTIONS,
&m_gotoOptionsFlag,true);
2000-11-22 18:02:04 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndMainTitles::shutdown()
{
m_mainMenu->shutdown(); // GUI items delete themselves when shutdown..
m_smallFont->dump(); delete m_smallFont;
m_sprites->dump(); delete m_sprites;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2000-11-28 01:06:22 +01:00
static u8 *s_image;
2001-04-25 17:08:23 +02:00
static FileEquate s_imageFiles[4]=
{
BACKDROP_START1_GFX,
BACKDROP_START2_GFX,
BACKDROP_START3_GFX,
BACKDROP_START4_GFX,
};
2000-11-22 18:02:04 +01:00
void CFrontEndMainTitles::select()
{
m_mode=MODE__PRESS_START;
2000-11-20 16:45:17 +01:00
m_startGameFlag=false;
m_gotoOptionsFlag=false;
2000-11-24 01:00:10 +01:00
m_demoTimeout=0;
2001-07-28 18:45:46 +02:00
s_image=LoadPakScreen(s_imageFiles[CGameSlotManager::getNumberOfFrontendScreenToUse()]);
2000-11-28 01:06:22 +01:00
ASSERT(s_image);
SetScreenImage(s_image);
2001-06-19 17:59:09 +02:00
CSoundMediator::setSong(CSoundMediator::SONG_TITLE);
2001-02-09 18:01:04 +01:00
m_musicStarted=false;
2000-11-15 16:37:12 +01:00
CFader::setFadingIn();
2000-11-13 20:38:51 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2000-11-22 18:02:04 +01:00
void CFrontEndMainTitles::unselect()
2000-11-13 20:38:51 +01:00
{
2001-01-19 17:25:05 +01:00
CSoundMediator::dumpSong();
2000-11-28 01:06:22 +01:00
ClearScreenImage();
MemFree(s_image); s_image=NULL;
2000-11-13 20:38:51 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-24 01:28:21 +02:00
/*
2000-11-16 00:41:47 +01:00
int isx=39;
int isy=3;
int isw=100;
int ish=56;
2001-04-24 01:28:21 +02:00
*/
2000-11-21 23:06:31 +01:00
2000-11-13 20:38:51 +01:00
void CFrontEndMainTitles::render()
{
2001-04-26 23:17:47 +02:00
CFrontEndScene::renderLogo();
2001-04-24 01:28:21 +02:00
/*
2000-11-13 20:38:51 +01:00
sFrameHdr *fh;
2000-11-15 16:37:12 +01:00
POLY_FT4 *ft4;
2000-11-13 20:38:51 +01:00
2000-11-15 16:37:12 +01:00
// Game logo/title
2000-11-28 01:06:22 +01:00
CFrontEndScene::renderLogo();
2000-11-21 23:06:31 +01:00
2000-11-15 16:37:12 +01:00
// The island
fh=m_sprites->getFrameHeader(FRM__ISLAND);
2001-04-19 23:11:46 +02:00
m_sprites->printFT4(fh,ISLAND_LEFT_X,ISLAND_BOTTOM_Y-(fh->H),0,0,FE_OT__SEAPOS);
2000-11-15 16:37:12 +01:00
2001-04-19 23:11:46 +02:00
// Sea
2000-11-16 00:41:47 +01:00
renderSeaSection(m_sprites->getFrameHeader(FRM__ISLAND),isx,HORIZON_LEVEL+isy,isw,ish);
renderSeaSection(m_sprites->getFrameHeader(FRM_SKY),0,HORIZON_LEVEL,512,256-HORIZON_LEVEL+SEA_OVERLAP);
2001-04-24 01:28:21 +02:00
*/
2000-11-15 16:37:12 +01:00
switch(m_mode)
{
case MODE__PRESS_START:
renderPressStart();
break;
2000-11-20 16:45:17 +01:00
2000-11-15 16:37:12 +01:00
case MODE__SELECT_OPTION:
2000-11-20 16:45:17 +01:00
m_mainMenu->render();
break;
default:
2000-11-15 16:37:12 +01:00
break;
}
2000-11-13 20:38:51 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndMainTitles::think(int _frames)
{
2001-04-24 01:28:21 +02:00
/*
2000-11-15 16:37:12 +01:00
sval=(sval+(seaspeed*_frames))&4095;
2001-04-24 01:28:21 +02:00
*/
2000-11-15 16:37:12 +01:00
2001-02-09 18:01:04 +01:00
// Wait until fade in has finished before starting music
if(!m_musicStarted&&!CFader::isFading())
{
CSoundMediator::playSong();
m_musicStarted=true;
}
2000-11-15 16:37:12 +01:00
switch(m_mode)
{
case MODE__PRESS_START:
if(!CFader::isFading()&&PadGetDown(0)&PAD_START)
{
2001-01-31 17:11:42 +01:00
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__OK);
2000-11-15 16:37:12 +01:00
m_mode=MODE__SELECT_OPTION;
2001-01-12 22:10:44 +01:00
m_mainMenu->select();
2000-11-15 16:37:12 +01:00
}
break;
2000-11-20 16:45:17 +01:00
case MODE__SELECT_OPTION:
m_mainMenu->think(_frames);
if(m_startGameFlag)
{
2000-11-20 18:28:21 +01:00
CFader::setFadingOut();
2000-11-24 18:30:49 +01:00
m_mode=MODE__GOTO_CHOOSE_SLOT;
2001-01-12 22:10:44 +01:00
m_mainMenu->unselect();
2000-11-20 16:45:17 +01:00
}
else if(m_gotoOptionsFlag)
{
CFader::setFadingOut();
m_mode=MODE__GOTO_OPTIONS;
2001-01-12 22:10:44 +01:00
m_mainMenu->unselect();
2000-11-20 16:45:17 +01:00
}
break;
default:
break;
}
2000-11-24 01:00:10 +01:00
if(m_mode==MODE__PRESS_START||m_mode==MODE__SELECT_OPTION)
{
2001-07-12 16:54:02 +02:00
m_demoTimeout+=_frames;
/*
2000-11-24 01:00:10 +01:00
if(!PadGetHeld(0))
{
if(m_demoTimeout>DEMO_TIMEOUT_IN_SECONDS*GameState::getOneSecondInFrames())
{
CFader::setFadingOut();
m_mode=MODE__GOTO_DEMO;
2001-01-12 22:10:44 +01:00
if(m_mainMenu->isSelected())
m_mainMenu->unselect();
2000-11-24 01:00:10 +01:00
}
}
else
{
m_demoTimeout=0;
}
2001-07-12 16:54:02 +02:00
*/
2000-11-24 01:00:10 +01:00
}
2000-11-20 16:45:17 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CFrontEndMainTitles::isReadyToExit()
{
2001-06-19 23:26:50 +02:00
return !CFader::isFading()&&(m_mode==MODE__GOTO_CHOOSE_SLOT||m_mode==MODE__GOTO_OPTIONS||m_mode==MODE__GOTO_DEMO);
2000-11-20 16:45:17 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CFrontEndScene::FrontEndMode CFrontEndMainTitles::getNextMode()
{
CFrontEndScene::FrontEndMode ret;
ret=CFrontEndScene::MODE__NONE;
switch(m_mode)
{
case MODE__PRESS_START:
2000-11-15 16:37:12 +01:00
case MODE__SELECT_OPTION:
2000-11-20 16:45:17 +01:00
ASSERT(0);
break;
2000-11-24 18:30:49 +01:00
case MODE__GOTO_CHOOSE_SLOT:
2001-06-11 00:56:33 +02:00
ret=CFrontEndScene::MODE__CHOOSE_SLOT;
2000-11-20 16:45:17 +01:00
break;
case MODE__GOTO_OPTIONS:
2000-11-22 18:02:04 +01:00
ret=CFrontEndScene::MODE__GAME_OPTIONS;
2000-11-15 16:37:12 +01:00
break;
2000-11-24 01:00:10 +01:00
case MODE__GOTO_DEMO:
ret=CFrontEndScene::MODE__DEMO;
break;
2000-11-15 16:37:12 +01:00
}
2000-11-20 16:45:17 +01:00
return ret;
2000-11-15 16:37:12 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-24 01:28:21 +02:00
/*
2000-11-20 16:45:17 +01:00
POLY_FT4 *CFrontEndMainTitles::prepareSeaPortionFT4(sFrameHdr *_fh,int _x,int _y,int _w,int _h,int _rgb)
2000-11-15 16:37:12 +01:00
{
int u,v,w,h;
POLY_FT4 *ft4;
w=(_fh->W*_w)>>8;
h=(_fh->H*_h)>>8;
u=_fh->U+((_fh->W*_x)>>8);
v=_fh->V+_fh->H-((_fh->H*_y)>>8)-h;
ft4=GetPrimFT4();
setShadeTexPolyFT4(ft4);
setShadeTex(ft4,0);
2000-11-16 00:41:47 +01:00
setRGB0(ft4,_rgb,_rgb,_rgb);
2000-11-15 16:37:12 +01:00
ft4->u0=u;
ft4->u1=u+w;
ft4->u2=u;
ft4->u3=u+w;
ft4->v0=v+h-1;
ft4->v1=v+h-1;
ft4->v2=v-1;
ft4->v3=v-1;
ft4->tpage=_fh->TPage;
ft4->clut=_fh->Clut;
return ft4;
}
2001-04-24 01:28:21 +02:00
*/
2000-11-15 16:37:12 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-24 01:28:21 +02:00
/*
2000-11-16 00:41:47 +01:00
typedef struct
{
int x,y;
int colour;
} SeaGrid;
void CFrontEndMainTitles::renderSeaSection(sFrameHdr *_fh,int _x,int _y,int _w,int _h)
2000-11-15 16:37:12 +01:00
{
int xloop,yloop;
int xstep,ystep;
int x,y;
int scale;
POLY_FT4 *ft4;
2000-11-16 00:41:47 +01:00
SeaGrid grid[seaw+1][seah+1];
2000-11-15 16:37:12 +01:00
int waveval;
// Grow the grid
2000-11-16 00:41:47 +01:00
xstep=(_w<<8)/seaw;
ystep=(_h<<8)/seah;
y=_y<<8;
2000-11-15 16:37:12 +01:00
waveval=sval;
scale=seascale;
for(yloop=0;yloop<seah+1;yloop++)
{
2000-11-16 00:41:47 +01:00
x=_x<<8;
2000-11-15 16:37:12 +01:00
for(xloop=0;xloop<seaw+1;xloop++)
{
2000-11-16 00:41:47 +01:00
grid[xloop][yloop].x=(x>>8)+0;
grid[xloop][yloop].y=(y>>8)+(msin(waveval)/scale);
2000-11-28 01:06:22 +01:00
// grid[xloop][yloop].colour=colourbase+((msin(waveval)/colourscale)*colourpostscale);
2000-11-15 16:37:12 +01:00
x+=xstep;
}
y+=ystep;
scale+=seascalegrow;
waveval=(waveval+seagap)&4095;
}
// Draw it
xstep=(256<<8)/seaw;
ystep=(256<<8)/seah;
y=0;
for(yloop=0;yloop<seah;yloop++)
{
x=0;
for(xloop=0;xloop<seaw;xloop++)
{
2000-11-16 00:41:47 +01:00
ft4=prepareSeaPortionFT4(_fh,x>>8,y>>8,xstep>>8,ystep>>8,64);//grid[xloop][yloop].colour);
ft4->x0=grid[xloop ][yloop ].x;
ft4->y0=grid[xloop ][yloop ].y;
ft4->x1=grid[xloop+1][yloop ].x;
ft4->y1=grid[xloop+1][yloop ].y;
ft4->x3=grid[xloop+1][yloop+1].x;
ft4->y3=grid[xloop+1][yloop+1].y;
ft4->x2=grid[xloop ][yloop+1].x;
ft4->y2=grid[xloop ][yloop+1].y;
2001-04-19 23:11:46 +02:00
AddPrimToList(ft4,FE_OT__SEAPOS);
2000-11-15 16:37:12 +01:00
x+=xstep;
}
y+=ystep;
}
2001-04-19 23:11:46 +02:00
// //////////////////////// bg
// POLY_F4 *f4;
// f4=GetPrimF4();
// setXYWH(f4,0,HORIZON_LEVEL,512,256-HORIZON_LEVEL);
// setRGB0(f4,80,70,60);
// AddPrimToList(f4,FE_OT__SEAPOS);
// //////////////////////// bg
2000-11-15 16:37:12 +01:00
}
2001-04-24 01:28:21 +02:00
*/
2000-11-15 16:37:12 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndMainTitles::renderPressStart()
{
2001-07-10 22:06:10 +02:00
if(!CFader::isFading() && m_demoTimeout & 32)
2000-11-15 16:37:12 +01:00
{
2000-11-20 18:28:21 +01:00
m_smallFont->setColour(PRESS_START_TEXT_R,PRESS_START_TEXT_G,PRESS_START_TEXT_B);
2000-11-20 16:45:17 +01:00
m_smallFont->print(256,PRESS_START_TEXT_Y,STR__FRONTEND__PRESS_START);
2001-04-24 01:28:21 +02:00
m_smallFont->setColour(0,0,0);
m_smallFont->print(256-1,PRESS_START_TEXT_Y-1,STR__FRONTEND__PRESS_START);
m_smallFont->print(256+1,PRESS_START_TEXT_Y-1,STR__FRONTEND__PRESS_START);
m_smallFont->print(256-1,PRESS_START_TEXT_Y+1,STR__FRONTEND__PRESS_START);
m_smallFont->print(256+1,PRESS_START_TEXT_Y+1,STR__FRONTEND__PRESS_START);
2000-11-15 16:37:12 +01:00
}
2000-11-13 20:38:51 +01:00
}
/*===========================================================================
end */