SBSPSS/source/frontend/options.cpp

530 lines
13 KiB
C++
Raw Normal View History

2000-11-22 17:04:18 +01:00
/*=========================================================================
options.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "frontend\options.h"
#ifndef __MEMORY_HEADER__
#include "mem\memory.h"
#endif
#ifndef __GFX_FADER_H__
#include "gfx\fader.h"
#endif
#ifndef __FRONTEND_SCROLLBG_H__
#include "frontend\scrollbg.h"
#endif
#ifndef __PRIM_HEADER__
#include "gfx\prim.h"
#endif
2000-11-22 23:52:08 +01:00
#ifndef __GUI_GFACTORY_H__
#include "gui\gfactory.h"
2000-11-22 17:04:18 +01:00
#endif
#ifndef __GUI_GFRAME_H__
#include "gui\gframe.h"
#endif
2000-11-23 20:55:33 +01:00
#ifndef __GUI_GTEXTBOX_H__
#include "gui\gtextbox.h"
2000-11-23 18:00:09 +01:00
#endif
2000-11-22 17:04:18 +01:00
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
2000-11-22 23:52:08 +01:00
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2000-11-23 20:55:33 +01:00
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
2000-11-24 17:14:55 +01:00
#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
2000-11-22 17:04:18 +01:00
/* Std Lib
------- */
/* Data
---- */
#ifndef __SPR_FRONTEND_H__
#include <frontend.h>
#endif
2000-11-23 20:55:33 +01:00
#ifndef __SPR_UIGFX_H__
#include <uigfx.h>
#endif
2000-11-22 17:04:18 +01:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2000-11-23 20:55:33 +01:00
int CFrontEndOptions::s_controlStyleValues[CPadConfig::NUM_PAD_CONFIGS+1]=
2000-11-23 18:00:09 +01:00
{
0,1,2,3,
-1
};
2000-11-23 20:55:33 +01:00
CGUITextReadout::TextReadoutData CFrontEndOptions::s_controlStyleReadoutText[CPadConfig::NUM_PAD_CONFIGS]=
2000-11-23 18:00:09 +01:00
{
{ 0,STR__FRONTEND__A },
{ 1,STR__FRONTEND__B },
{ 2,STR__FRONTEND__C },
{ 3,STR__FRONTEND__D },
};
2000-11-23 20:55:33 +01:00
int CFrontEndOptions::s_buttonOrder[]=
{
CPadConfig::PAD_CFG_UP,
CPadConfig::PAD_CFG_DOWN,
CPadConfig::PAD_CFG_LEFT,
CPadConfig::PAD_CFG_RIGHT,
CPadConfig::PAD_CFG_JUMP,
CPadConfig::PAD_CFG_ACTION,
};
CGUISpriteReadout::SpriteReadoutData CFrontEndOptions::s_controlReadoutSprites[]=
{
{ ICON_UP,FRM__BUTU },
{ ICON_DOWN,FRM__BUTD },
{ ICON_LEFT,FRM__BUTL },
{ ICON_RIGHT,FRM__BUTR },
{ ICON_CROSS,FRM__BUTX },
{ ICON_CIRCLE,FRM__BUTC },
{ ICON_SQUARE,FRM__BUTS },
{ ICON_TRIANGLE,FRM__BUTT },
};
CFrontEndOptions::ButtonToIconMap CFrontEndOptions::s_controlMap[]=
{
{ PAD_UP, ICON_UP },
{ PAD_DOWN, ICON_DOWN },
{ PAD_LEFT, ICON_LEFT },
{ PAD_RIGHT, ICON_RIGHT },
{ PAD_CROSS, ICON_CROSS },
{ PAD_SQUARE, ICON_SQUARE },
{ PAD_CIRCLE, ICON_CIRCLE },
{ PAD_TRIANGLE, ICON_TRIANGLE },
};
2001-03-09 20:57:10 +01:00
// Frame dimensions
static const int OPTIONS_FRAME_W=416;
static const int OPTIONS_FRAME_H=160;
2001-03-11 21:44:42 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params: _hue = 0..4095, _brightness = 0..255, _rgb -> int[3]
Returns:
---------------------------------------------------------------------- */
static void paulColourSpaceToRGB(int _hue,int _brightness,int *_rgb)
{
static const int s_colourTab[16][3]=
{
{ 255, 0, 0 },
{ 255, 97, 0 },
{ 255,192, 0 },
{ 222,255, 0 },
{ 127,255, 0 },
{ 31,255, 0 },
{ 0,255, 67 },
{ 0,255,162 },
{ 0,252,255 },
{ 0,157,255 },
{ 0, 61,255 },
{ 37, 0,255 },
{ 132, 0,255 },
{ 228, 0,255 },
{ 255, 0,186 },
{ 255, 0, 91 },
};
const int *c1,*c2;
int *cr;
int i,component;
c1=&s_colourTab[(_hue>>8)&15][0];
c2=&s_colourTab[((_hue>>8)+1)&15][0];
cr=_rgb;
for(i=0;i<3;i++)
{
component=*c1+(((*c2-*c1)*(_hue&0xff))>>8);
component=(component*_brightness)>>8;
*cr=component;
c1++;
c2++;
cr++;
}
}
2000-11-22 17:04:18 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndOptions::init()
{
2000-11-22 23:52:08 +01:00
int i;
2000-11-23 20:55:33 +01:00
CGUIGroupFrame *fr;
CGUITextBox *tb;
CGUISpriteReadout *sr;
2000-11-22 17:04:18 +01:00
m_background=new ("Options Background") CScrollyBackground();
m_background->init();
2001-01-05 01:17:57 +01:00
m_background->setOt(MAX_OT-2);
2000-11-22 17:04:18 +01:00
2000-11-22 23:52:08 +01:00
// Create the menu frames
for(i=0;i<MODE__COUNT;i++)
{
CGUIControlFrame **mm=&m_modeMenus[i];
*mm=new ("optionsframe") CGUIControlFrame();
(*mm)->init(NULL);
2001-03-09 20:57:10 +01:00
(*mm)->setObjectXYWH((512-OPTIONS_FRAME_W)/2,(256-OPTIONS_FRAME_H)/2,OPTIONS_FRAME_W,OPTIONS_FRAME_H);
2000-11-22 23:52:08 +01:00
}
// Populate OPTIONS menu
CGUIFactory::createValueButtonFrame(m_modeMenus[MODE__OPTIONS],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER,OPTIONS_FRAME_W-(X_BORDER*2),20,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__CONTROLS,
&m_nextMode,MODE__CONTROL);
CGUIFactory::createValueButtonFrame(m_modeMenus[MODE__OPTIONS],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER+30,OPTIONS_FRAME_W-(X_BORDER*2),20,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__SCREEN,
&m_nextMode,MODE__SCREEN);
CGUIFactory::createValueButtonFrame(m_modeMenus[MODE__OPTIONS],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER+60,OPTIONS_FRAME_W-(X_BORDER*2),20,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__SOUND,
&m_nextMode,MODE__SOUND);
CGUIFactory::createValueButtonFrame(m_modeMenus[MODE__OPTIONS],
2001-03-09 20:57:10 +01:00
X_BORDER,OPTIONS_FRAME_H-Y_BORDER-20,OPTIONS_FRAME_W-(X_BORDER*2),20,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__EXIT,
&m_exitFlag,true);
// Populate CONTROLS menu
2000-11-23 18:00:09 +01:00
CGUIFactory::createCycleButtonFrame(m_modeMenus[MODE__CONTROL],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER,OPTIONS_FRAME_W-(X_BORDER*2),40,
2000-11-23 18:00:09 +01:00
STR__FRONTEND__CONTROL_STYLE,
2000-11-23 20:55:33 +01:00
&m_controlStyle,s_controlStyleValues,s_controlStyleReadoutText);
fr=new ("frame") CGUIGroupFrame();
fr->init(m_modeMenus[MODE__CONTROL]);
2001-03-09 20:57:10 +01:00
fr->setObjectXYWH(X_BORDER*2,55,OPTIONS_FRAME_W-(X_BORDER*4),60); //292
2000-11-23 20:55:33 +01:00
sr=new ("spritereadout") CGUISpriteReadout();
sr->init(fr);
sr->setObjectXYWH(0,0,26,15); //146
sr->setReadoutTarget(&m_controlIcons[CONTROL_UP]);
sr->setReadoutData(s_controlReadoutSprites);
tb=new ("textbox") CGUITextBox();
tb->init(fr);
tb->setObjectXYWH(26,0,120,15);
tb->setText(STR__FRONTEND__UP);
sr=new ("spritereadout") CGUISpriteReadout();
sr->init(fr);
sr->setObjectXYWH(0,15,26,15);
sr->setReadoutTarget(&m_controlIcons[CONTROL_DOWN]);
sr->setReadoutData(s_controlReadoutSprites);
tb=new ("textbox") CGUITextBox();
tb->init(fr);
tb->setObjectXYWH(26,15,120,15);
tb->setText(STR__FRONTEND__DOWN);
sr=new ("spritereadout") CGUISpriteReadout();
sr->init(fr);
sr->setObjectXYWH(0,30,26,15);
sr->setReadoutTarget(&m_controlIcons[CONTROL_LEFT]);
sr->setReadoutData(s_controlReadoutSprites);
tb=new ("textbox") CGUITextBox();
tb->init(fr);
tb->setObjectXYWH(26,30,120,15);
tb->setText(STR__FRONTEND__LEFT);
sr=new ("spritereadout") CGUISpriteReadout();
sr->init(fr);
sr->setObjectXYWH(0,45,26,15);
sr->setReadoutTarget(&m_controlIcons[CONTROL_RIGHT]);
sr->setReadoutData(s_controlReadoutSprites);
tb=new ("textbox") CGUITextBox();
tb->init(fr);
tb->setObjectXYWH(26,45,120,15);
tb->setText(STR__FRONTEND__RIGHT);
sr=new ("spritereadout") CGUISpriteReadout();
sr->init(fr);
sr->setObjectXYWH(146,0,26,15);
sr->setReadoutTarget(&m_controlIcons[CONTROL_JUMP]);
sr->setReadoutData(s_controlReadoutSprites);
tb=new ("textbox") CGUITextBox();
tb->init(fr);
tb->setObjectXYWH(146+26,0,120,15);
tb->setText(STR__FRONTEND__JUMP);
sr=new ("spritereadout") CGUISpriteReadout();
sr->init(fr);
sr->setObjectXYWH(146,15,26,15);
sr->setReadoutTarget(&m_controlIcons[CONTROL_ACTION]);
sr->setReadoutData(s_controlReadoutSprites);
tb=new ("textbox") CGUITextBox();
tb->init(fr);
tb->setObjectXYWH(146+26,15,120,15);
tb->setText(STR__FRONTEND__ACTION);
2000-11-22 23:52:08 +01:00
// Populate SCREEN menu
2000-11-24 17:14:55 +01:00
CGUIFactory::createSliderButtonFrame(m_modeMenus[MODE__SCREEN],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER,OPTIONS_FRAME_W-(X_BORDER*2),35,
2000-11-24 17:14:55 +01:00
STR__FRONTEND__HORIZONTAL_POSITION,
&m_screenXOff,0,64);
CGUIFactory::createSliderButtonFrame(m_modeMenus[MODE__SCREEN],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER+40,OPTIONS_FRAME_W-(X_BORDER*2),35,
2000-11-24 17:14:55 +01:00
STR__FRONTEND__VERTICAL_POSITION,
&m_screenYOff,0,32);
2000-11-22 23:52:08 +01:00
// Populate SOUND menu
CGUIFactory::createSliderButtonFrame(m_modeMenus[MODE__SOUND],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER,OPTIONS_FRAME_W-(X_BORDER*2),35,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__BGM,
&m_bgmVolume,CSoundMediator::MIN_VOLUME,CSoundMediator::MAX_VOLUME);
CGUIFactory::createSliderButtonFrame(m_modeMenus[MODE__SOUND],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER+35,OPTIONS_FRAME_W-(X_BORDER*2),35,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__SFX,
&m_sfxVolume,CSoundMediator::MIN_VOLUME,CSoundMediator::MAX_VOLUME);
CGUIFactory::createSliderButtonFrame(m_modeMenus[MODE__SOUND],
2001-03-09 20:57:10 +01:00
X_BORDER,Y_BORDER+70,OPTIONS_FRAME_W-(X_BORDER*2),35,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__SPEECH,
&m_speechVolume,CSoundMediator::MIN_VOLUME,CSoundMediator::MAX_VOLUME);
// Add BACK to all of the sub menus
for(i=1;i<MODE__COUNT;i++)
{
CGUIFactory::createValueButtonFrame(m_modeMenus[i],
2001-03-09 20:57:10 +01:00
X_BORDER,OPTIONS_FRAME_H-Y_BORDER-20,OPTIONS_FRAME_W-(X_BORDER*2),20,
2000-11-22 23:52:08 +01:00
STR__FRONTEND__BACK,
&m_nextMode,MODE__OPTIONS);
}
2001-01-03 21:43:49 +01:00
m_bgmVolume=CSoundMediator::getVolume(CSoundMediator::VOL_SONG);
m_sfxVolume=CSoundMediator::getVolume(CSoundMediator::VOL_SFX);
m_speechVolume=CSoundMediator::getVolume(CSoundMediator::VOL_SPEECH);
2000-11-23 20:55:33 +01:00
m_controlStyle=CPadConfig::getConfig();
2000-11-24 17:14:55 +01:00
m_screenXOff=VidGetXOfs();
m_screenYOff=VidGetYOfs();
2000-11-22 18:02:04 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndOptions::shutdown()
{
2000-11-22 23:52:08 +01:00
int i;
for(i=0;i<MODE__COUNT;i++)
{
2000-11-23 18:00:09 +01:00
m_modeMenus[i]->shutdown();
2000-11-22 23:52:08 +01:00
}
2000-11-22 18:02:04 +01:00
m_background->shutdown(); delete m_background;
}
2000-11-22 17:04:18 +01:00
2000-11-22 18:02:04 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CFrontEndOptions::select()
{
2000-11-22 23:52:08 +01:00
m_modeMenus[MODE__OPTIONS]->select();
m_mode=m_nextMode=MODE__OPTIONS;
2000-11-22 17:04:18 +01:00
m_exitFlag=false;
m_closingDown=false;
2000-11-22 18:02:04 +01:00
2001-01-19 17:25:05 +01:00
CSoundMediator::setSong(CSoundMediator::SONG_OPTIONS);
CSoundMediator::playSong();
2000-11-22 17:04:18 +01:00
CFader::setFadingIn();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2000-11-22 18:02:04 +01:00
void CFrontEndOptions::unselect()
2000-11-22 17:04:18 +01:00
{
2001-01-19 17:25:05 +01:00
CSoundMediator::dumpSong();
2000-11-22 23:52:08 +01:00
m_modeMenus[m_mode]->unselect();
2000-11-22 17:04:18 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-11 21:44:42 +01:00
int rh=0;
int rb=80;
int rspeed=5;
int rstep=1024;
2000-11-22 17:04:18 +01:00
void CFrontEndOptions::render()
{
POLY_G4 *g4;
2001-03-11 21:44:42 +01:00
int rgb[3];
rh+=rspeed;
rh&=4095;
paulColourSpaceToRGB(rh,rb,rgb);
2000-11-22 17:04:18 +01:00
g4=GetPrimG4();
setXYWH(g4,0,0,512,256);
2001-03-11 21:44:42 +01:00
paulColourSpaceToRGB(rh,rb,rgb);
setRGB0(g4,rgb[0],rgb[1],rgb[2]);
paulColourSpaceToRGB(rh+(rstep*1),rb,rgb);
setRGB1(g4,rgb[0],rgb[1],rgb[2]);
paulColourSpaceToRGB(rh+(rstep*3),rb,rgb);
setRGB2(g4,rgb[0],rgb[1],rgb[2]);
paulColourSpaceToRGB(rh+(rstep*2),rb,rgb);
setRGB3(g4,rgb[0],rgb[1],rgb[2]);
2001-01-05 01:17:57 +01:00
AddPrimToList(g4,MAX_OT-1);
2000-11-22 17:04:18 +01:00
m_background->render();
2000-11-22 23:52:08 +01:00
m_modeMenus[m_mode]->render();
2000-11-22 17:04:18 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int ox=-1;
int oy=-1;
int os=0;
void CFrontEndOptions::think(int _frames)
{
2000-11-23 20:55:33 +01:00
int i,j,button;
2000-11-22 17:04:18 +01:00
m_background->setSpeed(ox,oy);
m_background->setSpeedScale(os);
m_background->think(_frames);
if(!CFader::isFading())
{
2000-11-22 23:52:08 +01:00
if(m_nextMode!=m_mode)
{
m_modeMenus[m_mode]->unselect();
m_mode=m_nextMode;
m_modeMenus[m_mode]->select();
}
m_modeMenus[m_mode]->think(_frames);
if(m_mode==MODE__SOUND)
{
2001-01-03 21:43:49 +01:00
if(m_bgmVolume!=CSoundMediator::getVolume(CSoundMediator::VOL_SONG))
2000-11-22 23:52:08 +01:00
{
2001-01-03 21:43:49 +01:00
CSoundMediator::setVolume(CSoundMediator::VOL_SONG,m_bgmVolume);
2000-11-22 23:52:08 +01:00
}
2001-01-03 21:43:49 +01:00
if(m_sfxVolume!=CSoundMediator::getVolume(CSoundMediator::VOL_SFX))
2000-11-22 23:52:08 +01:00
{
2001-01-03 21:43:49 +01:00
CSoundMediator::setVolume(CSoundMediator::VOL_SFX,m_sfxVolume);
2000-11-22 23:52:08 +01:00
}
2001-01-03 21:43:49 +01:00
if(m_speechVolume!=CSoundMediator::getVolume(CSoundMediator::VOL_SPEECH))
2000-11-22 23:52:08 +01:00
{
2001-01-03 21:43:49 +01:00
CSoundMediator::setVolume(CSoundMediator::VOL_SPEECH,m_speechVolume);
2000-11-22 23:52:08 +01:00
}
}
2000-11-24 17:14:55 +01:00
else if(m_mode==MODE__SCREEN)
{
VidSetXYOfs(m_screenXOff,m_screenYOff);
}
2000-11-22 17:04:18 +01:00
}
if(!m_closingDown&&m_exitFlag)
{
CFader::setFadingOut();
m_closingDown=true;
}
2000-11-22 23:52:08 +01:00
2000-11-23 20:55:33 +01:00
// Change the icons on the control display
CPadConfig::setConfig(m_controlStyle);
for(i=0;i<CONTROL_COUNT;i++)
{
button=CPadConfig::getButton((CPadConfig::PAD_CFG)s_buttonOrder[i]);
for(j=0;j<ICON_COUNT;j++)
{
if(s_controlMap[j].m_padButton==button)
{
m_controlIcons[i]=s_controlMap[j].m_icon;
break;
}
}
}
2000-11-22 17:04:18 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CFrontEndOptions::isReadyToExit()
{
return m_closingDown&&!CFader::isFading();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CFrontEndScene::FrontEndMode CFrontEndOptions::getNextMode()
{
return CFrontEndScene::MODE__MAIN_TITLES;
}
/*===========================================================================
end */