Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes
PlayerControls Class Reference

#include <player_controls.hpp>

Inheritance diagram for PlayerControls:
Inheritance graph
[legend]
Collaboration diagram for PlayerControls:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PlayerControls (int whichPlayer)
 ~PlayerControls ()
void select ()
void clearMapping ()
void handle (GameAction, int)
void inputKeyboard (SDLKey, int)
void addKeyLabel (int change_id, KartAction control, bool start)
void setKeyInfoString (KartAction control)
virtual void update (float dt)
virtual void countdown ()
void inputPointer (int x, int y)
void lockInput ()
void unlockInput ()
void TimeToString (const double time, char *s)

Protected Attributes

bool m_locked
int m_menu_id

Private Member Functions

void updateAllKeyLabels ()

Private Attributes

int m_player_index
bool m_grab_input
KartAction m_edit_action
 Stores the KartAction for which the input is being sensed.
std::string m_name
std::string m_key_names [KC_COUNT]

Static Private Attributes

static const size_t PLAYER_NAME_MAX = 10
 Limits the maximum length of the player name.

Detailed Description

Definition at line 28 of file player_controls.hpp.


Constructor & Destructor Documentation

PlayerControls::PlayerControls ( int  whichPlayer)

Definition at line 69 of file player_controls.cpp.

                                             :
    m_player_index(whichPlayer),
    m_grab_input(false)
{
    char heading[MAX_MESSAGE_LENGTH];
    snprintf(heading, sizeof(heading), _("Choose your controls, %s"),
            user_config->m_player[m_player_index].getName().c_str() );

    widget_manager->addTitleWgt( WTOK_TITLE, 60, 7, heading );
    widget_manager->breakLine();

    widget_manager->addTextWgt( WTOK_PLYR_NAME0, 30, 7, _("Player name") );

    m_name = user_config->m_player[m_player_index].getName();
    widget_manager->addTextButtonWgt( WTOK_PLYR_NAME1, 30, 7, m_name );
    widget_manager->breakLine();

    widget_manager->switchOrder();
    for(int i = KA_FIRST; i <= KA_LAST; i++)
    {
        // Note: even though that all strings in sKartAction2Strings above
        // are in _(), they are not translated (since gettext is actually 
        // called at startup (just after loading) of the program, when
        // gettext is not yet initialised - so it returns the untranslated
        // strings). So we add an additional _() here (and in help_page_one).
        widget_manager->addTextWgt( WTOK_KEY0 + i, 30, 7, _(sKartAction2String[i]) );
    }
    widget_manager->breakLine();


    KartAction control;
    widget_manager->switchOrder();
    for(int i = KA_FIRST; i <= KA_LAST; i++)
    {
        control = (KartAction)i;
        m_key_names[control] = user_config->getMappingAsString(m_player_index, control);

        widget_manager->addTextButtonWgt( WTOK_LEFT + i, 30, 7,
            m_key_names[control].c_str());
    }
    widget_manager->breakLine();
    widget_manager->breakLine();

    widget_manager->addTextButtonWgt( WTOK_QUIT, 60, 7, _("Press <ESC> to go back") );
    widget_manager->setWgtTextSize( WTOK_QUIT, WGT_FNT_SML);

    widget_manager->layout(WGT_AREA_ALL);
}   // PlayerControls

Here is the call graph for this function:

Definition at line 119 of file player_controls.cpp.

{
    widget_manager->reset();
    // The unicode translation is not generally needed, so disable it again.
}   // ~PlayerControls

Here is the call graph for this function:


Member Function Documentation

void PlayerControls::addKeyLabel ( int  change_id,
KartAction  control,
bool  start 
)

Definition at line 209 of file player_controls.cpp.

{
       const int selected = widget_manager->getSelectedWgt();
       if (selected >= WTOK_LEFT && selected <= WTOK_LOOK_BACK)
       {
              user_config->clearInput(m_player_index,
                                                   (KartAction) (selected - WTOK_LEFT));
              updateAllKeyLabels();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::countdown ( ) [virtual, inherited]

Reimplemented in DisplayResConfirm.

Definition at line 147 of file base_gui.cpp.

{
}
void PlayerControls::handle ( GameAction  ga,
int  value 
) [virtual]

Reimplemented from BaseGUI.

Definition at line 220 of file player_controls.cpp.

{
       if (value)
              return;
       
       switch (ga)
       {
              case GA_CLEAR_MAPPING:
            clearMapping();

                     break;
              case GA_SENSE_COMPLETE:
                     // Updates the configuration with the newly sensed input.
            user_config->setInput(m_player_index,
                                                          m_edit_action,
                                                          inputDriver->getSensedInput());
                     // Fall through to recover the widget labels.
              case GA_SENSE_CANCEL:
                     inputDriver->setMode(MENU);
              
                     // Refresh all key labels since they mave changed because of
                     // conflicting bindings.
                     updateAllKeyLabels();
                     break;
              case GA_ENTER:
                     // If the user is typing her name this will be finished at this
                     // point.
                     if (inputDriver->isInMode(LOWLEVEL))
                     {
                            // Prevents zero-length names.
                            if (m_name.length() == 0)
                                   m_name = _("Player ") + m_player_index;
                            user_config->m_player[m_player_index].setName(m_name);
                            widget_manager->setWgtText(WTOK_PLYR_NAME1, m_name.c_str());

                            inputDriver->setMode(MENU);
                     }
                     else
                            select();
                     break;
              case GA_LEAVE:
                     // If the user is typing her name this will be cancelled at this
                     // point.
                     if (inputDriver->isInMode(LOWLEVEL))
                     {
                            m_name = user_config->m_player[m_player_index].getName();
                            widget_manager->setWgtText(WTOK_PLYR_NAME1, m_name.c_str());

                            inputDriver->setMode(MENU);
                            break;
                     }
                     // Fall through to reach the usual GA_LEAVE code (leave menu).
              default:
                     BaseGUI::handle(ga, value);
       }
       
}

Here is the call graph for this function:

void PlayerControls::inputKeyboard ( SDLKey  key,
int  unicode 
) [virtual]

Reimplemented from BaseGUI.

Definition at line 165 of file player_controls.cpp.

{
       switch (key)
       {
       case SDLK_RSHIFT:
       case SDLK_LSHIFT:
              // Ignore shift, otherwise shift will disable input
              // (making it impossible to enter upper case characters)
       case SDLK_SPACE:
              // Ignore space to prevent invisible names.
                     
              // Note: This will never happen as long as SPACE has a mapping which
              // causes GA_ENTER and therefore finishes the typing. Please leave this
              // because I am not sure whether this is good behavior (that SPACE
              // cannot reach inputKeyboard()) and with some changes to the input
              // driver this code has suddenly a useful effect.
       case SDLK_KP_ENTER:
       case SDLK_RETURN:
       case SDLK_ESCAPE:
              // Ignore some control keys. What they could provide is implemented
              // in the handle() method.
              return;
       case SDLK_BACKSPACE:
              // Handle backspace.
              if (m_name.size() >=1)
                     m_name.erase(m_name.size()-1, 1);
              
              widget_manager->setWgtText(WTOK_PLYR_NAME1, (m_name + "<").c_str());
              break;
              break;
       default:
              // Adds the character to the name.
              // For this menu only unicode translation is enabled.
              // So we use the unicode character here, since this will
              // take care of upper/lower case etc.
              if (unicode && m_name.size() <= PLAYER_NAME_MAX)
                     m_name += (char) unicode;
              widget_manager->setWgtText(WTOK_PLYR_NAME1, (m_name + "<").c_str());
              break;
       }

}

Here is the call graph for this function:

void BaseGUI::inputPointer ( int  x,
int  y 
) [inherited]

Definition at line 102 of file base_gui.cpp.

{
    if( m_locked ) return;

    const int PREV_SELECTED_WGT = widget_manager->getSelectedWgt();
    const int SELECTED_WGT = widget_manager->handlePointer( x, y );

    if( SELECTED_WGT != WidgetManager::WGT_NONE )
    {
        if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
        {
            widget_manager->darkenWgtColor( PREV_SELECTED_WGT );
        }

        widget_manager->lightenWgtColor( SELECTED_WGT );
        widget_manager->pulseWgt( SELECTED_WGT );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::lockInput ( ) [inline, inherited]

Definition at line 49 of file base_gui.hpp.

{ m_locked = true; }
void PlayerControls::select ( ) [virtual]

Implements BaseGUI.

Definition at line 127 of file player_controls.cpp.

{
    const int selected = widget_manager->getSelectedWgt();
       switch (selected)
       {
              case WTOK_PLYR_NAME1:
                     // Switch to typing in the player's name.
                     widget_manager->setWgtText(WTOK_PLYR_NAME1, (m_name + "<").c_str());
              
                     inputDriver->setMode(LOWLEVEL);
              
              break;
              case WTOK_QUIT:
                     // Leave menu.
               menu_manager->popMenu();
              
                     break;
              default:
                     // Switch to input sensing.

                     // If the only remaining and not yet handled widgets are the ones
                     // that deal with the kart controls and the values are still in the
                     // correct order the assertion should hold. If not did something
                     // bad.
                     assert (selected >= WTOK_LEFT
                                   && selected <= WTOK_LOOK_BACK);
              
                     
                  m_edit_action = static_cast<KartAction>(selected - WTOK_LEFT);
                  widget_manager->setWgtText(selected, _("Press key"));
                     
                     inputDriver->setMode(INPUT_SENSE);
                     
                     break;
       }
}   // select

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::TimeToString ( const double  time,
char *  s 
) [inherited]

Definition at line 130 of file base_gui.cpp.

{
    int min     = (int) floor ( TIME / 60.0 ) ;
    int sec     = (int) floor ( TIME - (double) ( 60 * min ) ) ;
    int tenths  = (int) floor ( 10.0f * (TIME - (double)(sec + 60* min)));
    sprintf ( s, "%d:%02d:%d", min,  sec,  tenths ) ;
}   // TimeToString

Here is the caller graph for this function:

void BaseGUI::unlockInput ( ) [inline, inherited]

Definition at line 50 of file base_gui.hpp.

{ m_locked = false; }
void BaseGUI::update ( float  dt) [virtual, inherited]

Reimplemented in RaceGUI, CharSel, HelpPageOne, GrandPrixEnd, LeaderResult, GrandPrixSelect, ChallengesMenu, StartRaceFeedback, and TrackSel.

Definition at line 123 of file base_gui.cpp.

{
    widget_manager->update(dt);
}   // update

Here is the call graph for this function:

Definition at line 280 of file player_controls.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Stores the KartAction for which the input is being sensed.

Definition at line 49 of file player_controls.hpp.

Definition at line 46 of file player_controls.hpp.

std::string PlayerControls::m_key_names[KC_COUNT] [private]

Definition at line 52 of file player_controls.hpp.

bool BaseGUI::m_locked [protected, inherited]

Definition at line 55 of file base_gui.hpp.

int BaseGUI::m_menu_id [protected, inherited]

Definition at line 56 of file base_gui.hpp.

std::string PlayerControls::m_name [private]

Definition at line 51 of file player_controls.hpp.

Definition at line 45 of file player_controls.hpp.

const size_t PlayerControls::PLAYER_NAME_MAX = 10 [static, private]

Limits the maximum length of the player name.

Definition at line 54 of file player_controls.hpp.


The documentation for this class was generated from the following files: