SBSPSS/source/frontend/start.cpp

572 lines
14 KiB
C++
Raw Normal View History

2000-11-24 18:20:44 +01:00
/*=========================================================================
start.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "frontend\start.h"
2001-06-11 00:56:33 +02:00
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
2000-11-24 18:20:44 +01:00
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.h"
#endif
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
#ifndef __GFX_FADER_H__
#include "gfx\fader.h"
#endif
#ifndef __PRIM_HEADER__
#include "gfx\prim.h"
#endif
2001-02-12 17:06:24 +01:00
#ifndef __GUI_GFACTORY_H__
#include "gui\gfactory.h"
#endif
#ifndef __GUI_GFRAME_H__
#include "gui\gframe.h"
#endif
2001-01-15 23:02:25 +01:00
2001-06-11 00:56:33 +02:00
#ifndef __GUI_GTEXTBOX_H__
#include "gui\gtextbox.h"
#endif
#ifndef __GAME_GAMESLOT_H__
#include "game\gameslot.h"
#endif
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2001-06-13 16:48:33 +02:00
#ifndef __MAP_MAP_H__
#include "map\map.h"
#endif
2000-11-24 18:20:44 +01:00
/* Std Lib
------- */
/* Data
---- */
2001-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2000-11-24 18:20:44 +01:00
#endif
2001-06-11 00:56:33 +02:00
#ifndef __SPR_SHOP_H__
#include <shop.h>
#endif
2000-11-24 18:20:44 +01:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-06-11 01:42:05 +02:00
const int CFrontEndStart::s_itemFrames[]=
{
2001-07-13 17:42:58 +02:00
FRM_TEDDY, // SHOPITEM_TEDDY
FRM_SARNIE, // SHOPITEM_SARNIE
2001-06-11 01:42:05 +02:00
FRM_CUPCAKE, // SHOPITEM_CUPCAKE
2001-07-13 17:42:58 +02:00
FRM_PREZZIE, // SHOPITEM_PREZZIE
2001-06-11 01:42:05 +02:00
FRM_JELLY2, // SHOPITEM_JELLY2
2001-07-13 17:42:58 +02:00
FRM_CAKE, // SHOPITEM_CAKE
FRM_BLOWER, // SHOPITEM_BLOWER
2001-06-11 01:42:05 +02:00
FRM_PARTYHAT, // SHOPITEM_PARTYHAT
};
2001-02-12 17:06:24 +01:00
2000-11-24 18:20:44 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::init()
{
2001-06-11 00:56:33 +02:00
CGUITextBox *tb;
m_emptyGuiFrame=new ("Frame") CGUIGroupFrame();
m_emptyGuiFrame->init(NULL);
m_emptyGuiFrame->setObjectXYWH((512-416)/2,130,416,96);
m_emptyGuiFrame->setFlags(CGUIObject::FLAG_DRAWBORDER);
m_confirmEraseGuiFrame=new ("Frame") CGUIControlFrame();
m_confirmEraseGuiFrame->init(NULL);
m_confirmEraseGuiFrame->setObjectXYWH((512-416)/2,130,416,96);
CGUIFactory::createValueButtonFrame(m_confirmEraseGuiFrame,
8,55,400,20,
STR__NO,&m_confirmFlag,CONFIRM_NO);
CGUIFactory::createValueButtonFrame(m_confirmEraseGuiFrame,
8,70,400,20,
STR__YES,&m_confirmFlag,CONFIRM_YES);
tb=new ("textbox") CGUITextBox();
tb->init(m_confirmEraseGuiFrame);
tb->setObjectXYWH(8,5,400,35);
tb->setText(STR__SLOT_SELECT_SCREEN__CONFIRM_ERASE_GAME);
m_createdSlotGuiFrame=new ("Frame") CGUIControlFrame();
m_createdSlotGuiFrame->init(NULL);
m_createdSlotGuiFrame->setObjectXYWH((512-416)/2,130,416,96);
CGUIFactory::createValueButtonFrame(m_createdSlotGuiFrame,
8,55,400,20,
STR__OK,&m_confirmFlag,CONFIRM_OK);
tb=new ("textbox") CGUITextBox();
tb->init(m_createdSlotGuiFrame);
tb->setObjectXYWH(8,5,400,35);
tb->setText(STR__SLOT_SELECT_SCREEN__NEW_SLOT_CREATED);
m_font=new ("ChooseSlotFont") FontBank();
m_font->initialise(&standardFont);
m_font->setJustification(FontBank::JUST_LEFT);
2001-06-26 21:18:56 +02:00
m_font->setOt(0);
2001-06-11 00:56:33 +02:00
m_font->setPrintArea(0,0,712,256);
m_spriteBank=new ("PartItemSprites") SpriteBank();
m_spriteBank->load(SHOP_SHOP_SPR);
2000-11-24 18:20:44 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::shutdown()
{
2001-06-11 00:56:33 +02:00
m_spriteBank->dump(); delete m_spriteBank;
m_font->dump(); delete m_font;
m_createdSlotGuiFrame->shutdown();
m_confirmEraseGuiFrame->shutdown();
m_emptyGuiFrame->shutdown();
2000-11-24 18:20:44 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::select()
{
CFader::setFadingIn();
2001-06-11 00:56:33 +02:00
m_state=STATE_SELECT;
m_selectedSlot=0;
m_slotDrawOffset=0;
2001-07-02 18:44:52 +02:00
CSoundMediator::setSong(CSoundMediator::SONG_MEMCARD2);
2001-07-03 22:28:04 +02:00
m_musicStarted=false;
2000-11-24 18:20:44 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::unselect()
{
2001-07-02 18:44:52 +02:00
CSoundMediator::dumpSong();
2000-11-24 18:20:44 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::render()
{
POLY_G4 *g4;
g4=GetPrimG4();
setXYWH(g4,0,0,512,256);
2001-06-11 00:56:33 +02:00
setRGB0(g4, 0,150, 50);
setRGB1(g4, 0,150, 50);
setRGB2(g4,150, 50, 0);
setRGB3(g4,150, 50, 0);
2001-01-05 22:26:29 +01:00
AddPrimToList(g4,MAX_OT-1);
2001-01-15 23:02:25 +01:00
2001-06-11 00:56:33 +02:00
drawGameSlot(m_slotDrawOffset,m_selectedSlot);
if(m_slotDrawOffset)
{
int ofs;
ofs=m_slotDrawOffset<0?512:-512;
drawGameSlot(ofs+m_slotDrawOffset,m_lastSelectedSlot);
}
switch(m_state)
{
case STATE_SELECT:
if(!m_slotDrawOffset)
{
drawInstructions();
}
2001-06-26 21:18:56 +02:00
m_emptyGuiFrame->render();
2001-06-11 00:56:33 +02:00
break;
case STATE_CONFIRM_ERASE:
m_confirmEraseGuiFrame->render();
break;
case STATE_EXITING_TO_FRONT_END:
case STATE_EXITING_TO_GAME:
m_emptyGuiFrame->render();
break;
case STATE_SLOT_CREATED:
m_createdSlotGuiFrame->render();
break;
}
2000-11-24 18:20:44 +01:00
}
2001-06-11 00:56:33 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::drawGameSlot(int _xOff,int _slotNumber)
{
int xbase;
CGameSlotManager::GameSlot *gameSlot;
POLY_F4 *f4;
int x,y;
sFrameHdr *fh;
int i;
2001-07-24 00:51:03 +02:00
char buf[100];
2001-06-11 00:56:33 +02:00
2001-06-11 01:42:05 +02:00
xbase=_xOff+SLOT_FRAME_X;
2001-06-11 00:56:33 +02:00
CGameSlotManager::setActiveSlot(_slotNumber);
gameSlot=CGameSlotManager::getSlotData();
2001-06-11 01:42:05 +02:00
drawBambooBorder(xbase,SLOT_FRAME_Y,SLOT_FRAME_W,SLOT_FRAME_H,3);
2001-06-11 00:56:33 +02:00
f4=GetPrimF4();
2001-06-11 01:42:05 +02:00
setXYWH(f4,xbase,SLOT_FRAME_Y,SLOT_FRAME_W,SLOT_FRAME_H);
2001-06-11 00:56:33 +02:00
setRGB0(f4, 0, 0, 90);
setSemiTrans(f4,true);
AddPrimToList(f4,3);
2001-07-24 00:51:03 +02:00
x=xbase+SLOT_SLOTNUMBER_X;
y=SLOT_FRAME_Y+SLOT_SLOTNUMBER_Y;
sprintf(buf,TranslationDatabase::getString(STR__SLOT_SELECT_SCREEN__SLOT_NUMBER),_slotNumber+1,4);
m_font->print(x,y,buf);
2001-06-11 00:56:33 +02:00
if(gameSlot->m_isInUse)
{
2001-06-13 16:48:33 +02:00
int chapter,level;
2001-06-11 01:42:05 +02:00
2001-06-13 16:48:33 +02:00
gameSlot->getHighestLevelOpen(&chapter,&level);
sprintf(buf,TranslationDatabase::getString(STR__SLOT_SELECT_SCREEN__LEVEL_REACHED),chapter+1,level+1);
2001-06-11 01:42:05 +02:00
m_font->print(xbase+SLOT_LEVEL_TEXT_X,SLOT_FRAME_Y+SLOT_LEVEL_TEXT_Y,buf);
2001-06-11 00:56:33 +02:00
2001-06-11 01:42:05 +02:00
x=xbase+SLOT_TOKENCOUNT_X;
y=SLOT_FRAME_Y+SLOT_TOKENCOUNT_Y;
2001-06-11 00:56:33 +02:00
fh=m_spriteBank->getFrameHeader(FRM_SMALLTOKEN);
m_spriteBank->printFT4(fh,x,y,0,0,2);
x+=fh->W;
sprintf(buf,"x%d",CGameSlotManager::getSlotData()->getNumberOfKelpTokensHeld());
m_font->print(x,y,buf);
2001-06-11 01:42:05 +02:00
x=xbase+SLOT_ITEM_X;
y=SLOT_FRAME_Y+SLOT_ITEM_Y;
2001-06-11 00:56:33 +02:00
for(i=0;i<8;i++)
{
POLY_FT4 *ft4;
ft4=m_spriteBank->printFT4(s_itemFrames[i],x,y,0,0,2);
if(!gameSlot->isPartyItemHeld(i))
{
setRGB0(ft4,35,35,35);
}
2001-06-11 01:42:05 +02:00
x+=SLOT_ITEM_YGAP;
2001-06-11 00:56:33 +02:00
}
}
else
{
m_font->setJustification(FontBank::JUST_CENTRE);
2001-06-11 01:42:05 +02:00
m_font->print(xbase+SLOT_EMPTYTEXT_X,SLOT_FRAME_Y+SLOT_EMPTYTEXT_Y,STR__SLOT_SELECT_SCREEN__EMPTY_SLOT);
2001-06-11 00:56:33 +02:00
m_font->setJustification(FontBank::JUST_LEFT);
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::drawInstructions()
{
int slotInUse;
SpriteBank *sb;
sFrameHdr *fh1,*fh2;
int width;
int x,y;
int text;
CGameSlotManager::setActiveSlot(m_selectedSlot);
slotInUse=CGameSlotManager::getSlotData()->m_isInUse;
sb=CGameScene::getSpriteBank();
m_font->setColour(255,255,255);
2001-06-11 01:42:05 +02:00
y=INSTRUCTIONS_YSTART;
2001-06-11 00:56:33 +02:00
fh1=sb->getFrameHeader(FRM__BUTL);
fh2=sb->getFrameHeader(FRM__BUTR);
2001-06-11 01:42:05 +02:00
width=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS+fh2->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT+m_font->getStringWidth(STR__SLOT_SELECT_SCREEN__LEFT_RIGHT_TO_SELECT_SLOT);
2001-06-11 00:56:33 +02:00
x=256-(width/2);
2001-06-11 01:42:05 +02:00
sb->printFT4(fh1,x,y+INSTRUCTIONS_BUTTON_Y_OFFSET,0,0,0);
x+=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS;
sb->printFT4(fh2,x,y+INSTRUCTIONS_BUTTON_Y_OFFSET,0,0,0);
x+=fh2->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT;
2001-06-11 00:56:33 +02:00
m_font->print(x,y,STR__SLOT_SELECT_SCREEN__LEFT_RIGHT_TO_SELECT_SLOT);
text=slotInUse?STR__SLOT_SELECT_SCREEN__CROSS_TO_CONFIRM:STR__SLOT_SELECT_SCREEN__CROSS_TO_CREATE;
2001-06-11 01:42:05 +02:00
y+=INSTRUCTIONS_Y_SPACE_BETWEEN_LINES;
2001-06-11 00:56:33 +02:00
fh1=sb->getFrameHeader(FRM__BUTX);
2001-06-11 01:42:05 +02:00
width=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT+m_font->getStringWidth(text);
2001-06-11 00:56:33 +02:00
x=256-(width/2);
2001-06-11 01:42:05 +02:00
sb->printFT4(fh1,x,y+INSTRUCTIONS_BUTTON_Y_OFFSET,0,0,0);
x+=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT;
2001-06-11 00:56:33 +02:00
m_font->print(x,y,text);
2001-06-11 01:42:05 +02:00
y+=INSTRUCTIONS_Y_SPACE_BETWEEN_LINES;
2001-06-11 00:56:33 +02:00
fh1=sb->getFrameHeader(FRM__BUTC);
2001-06-11 01:42:05 +02:00
width=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT+m_font->getStringWidth(STR__SLOT_SELECT_SCREEN__CIRCLE_TO_ERASE_SLOT);
2001-06-11 00:56:33 +02:00
x=256-(width/2);
if(slotInUse)
{
2001-06-11 01:42:05 +02:00
sb->printFT4(fh1,x,y+INSTRUCTIONS_BUTTON_Y_OFFSET,0,0,0);
2001-06-11 00:56:33 +02:00
}
2001-06-11 01:42:05 +02:00
x+=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT;
2001-06-11 00:56:33 +02:00
if(slotInUse)
{
m_font->print(x,y,STR__SLOT_SELECT_SCREEN__CIRCLE_TO_ERASE_SLOT);
}
2001-06-11 01:42:05 +02:00
y+=INSTRUCTIONS_Y_SPACE_BETWEEN_LINES;
2001-06-11 00:56:33 +02:00
fh1=sb->getFrameHeader(FRM__BUTT);
2001-06-11 01:42:05 +02:00
width=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT+m_font->getStringWidth(STR__SLOT_SELECT_SCREEN__TRIANGLE_TO_EXIT);
2001-06-11 00:56:33 +02:00
x=256-(width/2);
2001-06-11 01:42:05 +02:00
sb->printFT4(fh1,x,y+INSTRUCTIONS_BUTTON_Y_OFFSET,0,0,0);
x+=fh1->W+INSTRUCTIONS_GAP_BETWEEN_BUTTONS_AND_TEXT;
2001-06-11 00:56:33 +02:00
m_font->print(x,y,STR__SLOT_SELECT_SCREEN__TRIANGLE_TO_EXIT);
}
2000-11-24 18:20:44 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndStart::think(int _frames)
{
2001-02-12 17:06:24 +01:00
if(!CFader::isFading())
{
2001-07-03 22:28:04 +02:00
if(!m_musicStarted)
{
CSoundMediator::playSong();
m_musicStarted=true;
}
2001-06-11 00:56:33 +02:00
if(m_slotDrawOffset==0)
{
if(m_state==STATE_SELECT)
{
// Select a slot
int pad=PadGetDown(0);
if(pad&PAD_LEFT)
{
m_lastSelectedSlot=m_selectedSlot;
if(--m_selectedSlot<0)
{
m_selectedSlot=CGameSlotManager::NUM_GAME_SLOTS-1;
}
m_slotDrawOffset=-500;
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__MOVE_CURSOR);
}
else if(pad&PAD_RIGHT)
{
m_lastSelectedSlot=m_selectedSlot;
if(++m_selectedSlot>=CGameSlotManager::NUM_GAME_SLOTS)
{
m_selectedSlot=0;
}
m_slotDrawOffset=+500;
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__MOVE_CURSOR);
}
else if(pad&PAD_CROSS)
{
CGameSlotManager::GameSlot *gameSlot;
CGameSlotManager::setActiveSlot(m_selectedSlot);
gameSlot=CGameSlotManager::getSlotData();
if(gameSlot->m_isInUse)
{
2001-06-13 16:48:33 +02:00
int chapter,level;
gameSlot->getHighestLevelOpen(&chapter,&level);
CMapScene::setLevelToStartOn(chapter,level);
2001-07-10 20:15:12 +02:00
gameSlot->m_lives=CGameSlotManager::INITIAL_LIVES;
gameSlot->m_continues=CGameSlotManager::INITIAL_CONTINUES;
2001-06-11 00:56:33 +02:00
m_state=STATE_EXITING_TO_GAME;
CFader::setFadingOut();
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__OK);
}
else
{
m_state=STATE_SLOT_CREATED;
2001-06-11 01:42:05 +02:00
m_confirmFlag=CONFIRM_NONE;
2001-06-11 00:56:33 +02:00
m_createdSlotGuiFrame->select();
gameSlot->m_isInUse=true;
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__OK);
}
}
else if(pad&PAD_CIRCLE)
{
CGameSlotManager::GameSlot *gameSlot;
CGameSlotManager::setActiveSlot(m_selectedSlot);
gameSlot=CGameSlotManager::getSlotData();
if(gameSlot->m_isInUse)
{
m_state=STATE_CONFIRM_ERASE;
m_confirmFlag=CONFIRM_NONE;
m_confirmEraseGuiFrame->select();
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__OK);
}
}
else if(pad&PAD_TRIANGLE)
{
m_state=STATE_EXITING_TO_FRONT_END;
CFader::setFadingOut();
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__OK);
}
m_emptyGuiFrame->think(_frames);
}
else if(m_state==STATE_SLOT_CREATED)
{
m_createdSlotGuiFrame->think(_frames);
if(m_confirmFlag==CONFIRM_OK)
{
m_createdSlotGuiFrame->unselect();
m_state=STATE_SELECT;
}
}
else if(m_state==STATE_CONFIRM_ERASE)
{
m_confirmEraseGuiFrame->think(_frames);
if(m_confirmFlag==CONFIRM_YES)
{
CGameSlotManager::eraseGameSlot(m_selectedSlot);
m_state=STATE_SELECT;
m_confirmEraseGuiFrame->unselect();
}
else if(m_confirmFlag==CONFIRM_NO)
{
m_state=STATE_SELECT;
m_confirmEraseGuiFrame->unselect();
}
}
}
else
{
// Slide the slot boxes about..
for(int i=0;i<_frames;i++)
{
int delta=m_slotDrawOffset/3;
if(m_slotDrawOffset<0)
{
if(!delta)delta=-1;
}
else if(m_slotDrawOffset>0)
{
if(!delta)delta=+1;
}
else
{
break;
}
m_slotDrawOffset-=delta;
}
}
2001-02-12 17:06:24 +01:00
}
2001-06-11 00:56:33 +02:00
/*
2000-11-24 18:20:44 +01:00
if(!m_shuttingDown)
{
2001-06-11 00:56:33 +02:00
if(/m_selectedSlot!=NO_SLOT_SELECTED||
m_escapeToTitles||/
2001-02-12 17:06:24 +01:00
{
2000-11-24 18:20:44 +01:00
m_shuttingDown=true;
CFader::setFadingOut();
}
}
2001-06-11 00:56:33 +02:00
*/
2000-11-24 18:20:44 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CFrontEndStart::isReadyToExit()
{
2001-06-11 00:56:33 +02:00
return !CFader::isFading()&&(m_state==STATE_EXITING_TO_FRONT_END||m_state==STATE_EXITING_TO_GAME);
2000-11-24 18:20:44 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CFrontEndScene::FrontEndMode CFrontEndStart::getNextMode()
{
2001-06-22 22:06:39 +02:00
return m_state==STATE_EXITING_TO_GAME?CFrontEndScene::MODE__EXIT_TO_GAME:CFrontEndScene::MODE__MAIN_TITLES;
2000-11-24 18:20:44 +01:00
}
/*===========================================================================
end */