added codes for option entry and option icons

This commit is contained in:
Chris Danford
2002-09-03 00:22:12 +00:00
parent 0b75b00f55
commit 7fb4b9c977
4 changed files with 293 additions and 0 deletions
+192
View File
@@ -0,0 +1,192 @@
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
Class: Course
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "CodeDetector.h"
#include "GameState.h"
#include "InputQueue.h"
#include "ThemeManager.h"
#include "RageLog.h"
#include "GameDef.h"
#include "StyleDef.h"
enum Code {
CODE_EASIER1,
CODE_EASIER2,
CODE_HARDER1,
CODE_HARDER2,
CODE_NEXT_SORT1,
CODE_NEXT_SORT2,
CODE_MIRROR,
CODE_LEFT,
CODE_RIGHT,
CODE_SHUFFLE,
CODE_SUPER_SHUFFLE,
CODE_LITTLE,
CODE_NEXT_SCROLL_SPEED,
CODE_BOOST,
CODE_NEXT_EFFECT,
CODE_NEXT_APPEARANCE,
CODE_NEXT_TURN,
CODE_REVERSE,
CODE_NEXT_COLOR,
CODE_HOLDS,
CODE_DARK,
CODE_CANCEL_ALL,
NUM_CODES // leave this at the end
};
const CString g_sCodeNames[NUM_CODES] = {
"Easier1",
"Easier2",
"Harder1",
"Harder2",
"NextSort1",
"NextSort2",
"Mirror",
"Left",
"Right",
"Shuffle",
"SuperShuffle",
"Little",
"NextScrollSpeed",
"Boost",
"NextEffect",
"NextAppearance",
"NextTurn",
"Reverse",
"NextColor",
"HoldNotes",
"Dark",
"CancelAll"
};
struct CodeCacheItem {
int iNumButtons;
GameButton buttons[10];
};
CodeCacheItem g_CodeCacheItems[NUM_CODES];
bool MatchesCacheItem( GameController controller, Code code )
{
if( g_CodeCacheItems[code].iNumButtons > 0 )
if( INPUTQUEUE->MatchesPattern(controller, g_CodeCacheItems[code].buttons, g_CodeCacheItems[code].iNumButtons) )
return true;
return false;
}
void RefreshCacheItem( int iIndex )
{
CodeCacheItem& item = g_CodeCacheItems[iIndex];
const GameDef* pGameDef = GAMESTATE->GetCurrentGameDef();
CString sCodeName = g_sCodeNames[iIndex];
CString sButtonsNames = THEME->GetMetric("CodeDetector",sCodeName);
CStringArray asButtonNames;
split( sButtonsNames, ",", asButtonNames, false );
if( asButtonNames.GetSize() < 2 )
{
LOG->Trace( "The code '%s' is less than 2 buttons, so it will be ignored.", sCodeName );
item.iNumButtons = 0;
return;
}
for( int i=0; i<asButtonNames.GetSize(); i++ ) // for each button in this code
{
CString sButtonName = asButtonNames[i];
// Search for the corresponding GameButton
GameButton& gb = item.buttons[i];
gb = -1;
for( int j=0; j<pGameDef->m_iButtonsPerController; j++ )
{
if( 0==stricmp(sButtonName,pGameDef->m_szButtonNames[j]) )
{
gb = j;
item.iNumButtons = i+1;
break; // found it. Don't keep searching
}
}
if( gb == -1 ) // didn't find it
{
LOG->Trace( "The code '%s' contains an unrecognized button '%s'.", sCodeName, sButtonName );
item.iNumButtons = 0;
return;
}
}
// if we make it here, we found all the buttons in the code
}
void CodeDetector::RefreshCacheItems()
{
for( int i=0; i<NUM_CODES; i++ )
RefreshCacheItem( i );
}
bool CodeDetector::EnteredEasierDifficulty( GameController controller )
{
return MatchesCacheItem(controller,CODE_EASIER1) || MatchesCacheItem(controller,CODE_EASIER2);
}
bool CodeDetector::EnteredHarderDifficulty( GameController controller )
{
return MatchesCacheItem(controller,CODE_HARDER1) || MatchesCacheItem(controller,CODE_HARDER2);
}
bool CodeDetector::EnteredNextSort( GameController controller )
{
return MatchesCacheItem(controller,CODE_NEXT_SORT1) || MatchesCacheItem(controller,CODE_NEXT_SORT2);
}
#define TOGGLE(v,a,b) if(v!=a) v=a; else v=b;
#define INCREMENT_SCROLL_SPEED(s) (s==0.5f) ? s=0.75f : (s==0.75f) ? s=1.0f : (s==1.0f) ? s=1.5f : (s==1.5f) ? s=2.0f : (s==2.0f) ? s=3.0f : (s==3.0f) ? s=4.0f : (s==4.0f) ? s=5.0f : (s==5.0f) ? s=8.0f : s=0.5f;
bool CodeDetector::DetectAndAdjustOptions( GameController controller )
{
const StyleDef* pStyleDef = GAMESTATE->GetCurrentStyleDef();
PlayerNumber pn = pStyleDef->ControllerToPlayerNumber( controller );
for( int c=CODE_MIRROR; c<NUM_CODES; c++ )
{
Code code = (Code)c;
if( MatchesCacheItem(controller,code) )
{
switch( code )
{
case CODE_MIRROR: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_TurnType, PlayerOptions::TURN_MIRROR, PlayerOptions::TURN_NONE ); break;
case CODE_LEFT: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_TurnType, PlayerOptions::TURN_LEFT, PlayerOptions::TURN_NONE ); break;
case CODE_RIGHT: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_TurnType, PlayerOptions::TURN_RIGHT, PlayerOptions::TURN_NONE ); break;
case CODE_SHUFFLE: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_TurnType, PlayerOptions::TURN_SHUFFLE, PlayerOptions::TURN_NONE ); break;
case CODE_SUPER_SHUFFLE: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_TurnType, PlayerOptions::TURN_SUPER_SHUFFLE, PlayerOptions::TURN_NONE ); break;
case CODE_LITTLE: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_bLittle, true, false ); break;
case CODE_NEXT_SCROLL_SPEED:INCREMENT_SCROLL_SPEED( GAMESTATE->m_PlayerOptions[pn].m_fArrowScrollSpeed ); break;
case CODE_BOOST: /* what goes here? */ break;
case CODE_NEXT_EFFECT: GAMESTATE->m_PlayerOptions[pn].m_EffectType = PlayerOptions::EffectType( (GAMESTATE->m_PlayerOptions[pn].m_EffectType+1) %NUM_EFFECT_TYPES ); break;
case CODE_NEXT_APPEARANCE: GAMESTATE->m_PlayerOptions[pn].m_AppearanceType = PlayerOptions::AppearanceType((GAMESTATE->m_PlayerOptions[pn].m_AppearanceType+1) %PlayerOptions::NUM_APPEARANCE_TYPES ); break;
case CODE_NEXT_TURN: GAMESTATE->m_PlayerOptions[pn].m_TurnType = PlayerOptions::TurnType( (GAMESTATE->m_PlayerOptions[pn].m_TurnType+1) %PlayerOptions::NUM_TURN_TYPES ); break;
case CODE_REVERSE: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_bReverseScroll, true, false ); break;
case CODE_NEXT_COLOR: GAMESTATE->m_PlayerOptions[pn].m_ColorType = PlayerOptions::ColorType( (GAMESTATE->m_PlayerOptions[pn].m_ColorType+1) %PlayerOptions::NUM_COLOR_TYPES ); break;
case CODE_HOLDS: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_bHoldNotes, true, false ); break;
case CODE_DARK: TOGGLE( GAMESTATE->m_PlayerOptions[pn].m_bDark, true, false ); break;
case CODE_CANCEL_ALL: GAMESTATE->m_PlayerOptions[pn] = PlayerOptions(); break;
default:
ASSERT(0); // unhandled code
}
return true; // don't check any more
}
}
return false;
}
+26
View File
@@ -0,0 +1,26 @@
#pragma once
/*
-----------------------------------------------------------------------------
Class: CodeDetector
Desc: Uses InputQueue to detect input of codes that would affect player and song options.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "GameInput.h"
class CodeDetector
{
public:
static void RefreshCacheItems(); // call this before checking codes, but call infrequently
static bool EnteredEasierDifficulty( GameController controller );
static bool EnteredHarderDifficulty( GameController controller );
static bool EnteredNextSort( GameController controller );
static bool DetectAndAdjustOptions( GameController controller );
};
+43
View File
@@ -0,0 +1,43 @@
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
Class: OptionIcon
Desc: A graphic displayed in the OptionIcon during Dancing.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "OptionIcon.h"
#include "ThemeManager.h"
#include "PlayerOptions.h"
#define TEXT_X THEME->GetMetricF("OptionIcon","TextX")
#define TEXT_Y THEME->GetMetricF("OptionIcon","TextY")
#define TEXT_H_ALIGN THEME->GetMetricI("OptionIcon","TextHAlign")
#define TEXT_V_ALIGN THEME->GetMetricI("OptionIcon","TextVAlign")
#define TEXT_WIDTH THEME->GetMetricI("OptionIcon","TextWidth")
OptionIcon::OptionIcon()
{
m_spr.Load( THEME->GetPathTo("Graphics","select music option icons 3x2") );
this->AddChild( &m_spr );
m_text.LoadFromFont( THEME->GetPathTo("Fonts","option icons") );
this->AddChild( &m_text );
}
void OptionIcon::Load( PlayerNumber pn, CString sText, bool bHeader )
{
bool bVacant = (sText=="");
m_spr.SetState( pn*3 + bVacant?1:2 );
m_text.SetText( sText );
m_text.CropToWidth( TEXT_WIDTH );
m_text.SetXY( TEXT_X, TEXT_Y );
m_text.SetHorizAlign( (Actor::HorizAlign)TEXT_H_ALIGN );
m_text.SetVertAlign( (Actor::VertAlign)TEXT_V_ALIGN );
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef OptionIcon_H
#define OptionIcon_H
/*
-----------------------------------------------------------------------------
Class: OptionIcon
Desc: Shows PlayerOptions and SongOptions in icon form.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "ActorFrame.h"
#include "Sprite.h"
#include "BitmapText.h"
#include "GameConstantsAndTypes.h"
class OptionIcon : public ActorFrame
{
public:
OptionIcon();
void Load( PlayerNumber pn, CString sText, bool bHeader = false );
protected:
BitmapText m_text;
Sprite m_spr;
};
#endif