/* $Id: playerconfigwindow.cpp,v 1.3 2005/12/12 21:02:29 chfreund Exp $ */ #include "playerconfigwindow.hpp" #include #include "player.hpp" #include "textlabel.h" PlayerConfigWindow::PlayerConfigWindow( Player* player ) { m_configContainer = new WidgetComposite(); TableLayout* configLayout = new TableLayout( m_configContainer, 2 ); configLayout->setHorizontalSpacing( 10 ); configLayout->setColumnStretch( 1, FILL ); m_configContainer->setLayout( configLayout ); SDL_Color black = {0, 0, 0, 0}; TextLabel* label = new TextLabel( "Name:" ); label->setColor( black ); m_configContainer->add( label ); m_nameField = new TextField( player->getName().getString(), 200, 20 ); // m_nameField->setColor( black ); m_nameField->addActionListener( this ); m_configContainer->add( m_nameField ); label = new TextLabel( "Team:" ); label->setColor( black ); m_configContainer->add( label ); std::ostringstream ostr; ostr << static_cast( player->getTeamID() ); m_teamField = new TextField( ostr.str(), 200, 20 ); // m_teamField->setColor( black ); m_teamField->addActionListener( this ); m_configContainer->add( m_teamField ); Uint32 color = player->getPlayerColor(); Uint32 r = ( color >> 16 ) & 0xff; Uint32 g = ( color >> 8 ) & 0xff; Uint32 b = color & 0xff; label = new TextLabel( "Color R:" ); label->setColor( black ); m_configContainer->add( label ); ostr.str( "" ); ostr << r; m_rField = new TextField( ostr.str(), 200, 20 ); // m_rField->setColor( black ); m_rField->addActionListener( this ); m_configContainer->add( m_rField ); label = new TextLabel( "Color G:" ); label->setColor( black ); m_configContainer->add( label ); ostr.str( "" ); ostr << g; m_gField = new TextField( ostr.str(), 200, 20 ); // m_gField->setColor( black ); m_gField->addActionListener( this ); m_configContainer->add( m_gField ); label = new TextLabel( "Color B:" ); label->setColor( black ); m_configContainer->add( label ); ostr.str( "" ); ostr << b; m_bField = new TextField( ostr.str(), 200, 20 ); // m_bField->setColor( black ); m_bField->addActionListener( this ); m_configContainer->add( m_bField ); m_buttonRow = new WidgetComposite(); HorizontalLayout* buttonLayout = new HorizontalLayout( m_buttonRow ); m_buttonRow->setLayout( buttonLayout ); buttonLayout->setSpacing( 5 ); m_okButton = new TextButton( "Ok" ); m_okButton->setHighlightable( true ); m_okButton->addActionListener( this ); m_buttonRow->add( m_okButton ); buttonLayout->setStretch( m_okButton, FILL ); m_cancelButton = new TextButton( "Cancel" ); m_cancelButton->setHighlightable( true ); m_cancelButton->addActionListener( this ); m_buttonRow->add( m_cancelButton ); buttonLayout->setStretch( m_cancelButton, FILL ); m_buttonRow->setWidth( 300 ); m_content = new WidgetComposite(); VerticalLayout* contentLayout = new VerticalLayout( m_content ); m_content->setLayout( contentLayout ); m_content->add( m_configContainer ); m_content->add( m_buttonRow ); setTitle( "Player configuration" ); setWidget( m_content ); } PlayerConfigWindow::PlayerConfigWindow( const char* name, Uint8 team, Uint32 color ) { m_configContainer = new WidgetComposite(); TableLayout* configLayout = new TableLayout( m_configContainer, 2 ); configLayout->setHorizontalSpacing( 10 ); configLayout->setColumnStretch( 1, FILL ); m_configContainer->setLayout( configLayout ); SDL_Color black = {0, 0, 0, 0}; TextLabel* label = new TextLabel( "Name:" ); label->setColor( black ); m_configContainer->add( label ); m_nameField = new TextField( name, 200, 20 ); m_nameField->addActionListener( this ); m_configContainer->add( m_nameField ); label = new TextLabel( "Team:" ); label->setColor( black ); m_configContainer->add( label ); std::ostringstream ostr; ostr << static_cast( team ); m_teamField = new TextField( ostr.str(), 200, 20 ); m_teamField->addActionListener( this ); m_configContainer->add( m_teamField ); Uint32 r = ( color >> 16 ) & 0xff; Uint32 g = ( color >> 8 ) & 0xff; Uint32 b = color & 0xff; label = new TextLabel( "Color R:" ); label->setColor( black ); m_configContainer->add( label ); ostr.str( "" ); ostr << r; m_rField = new TextField( ostr.str(), 200, 20 ); m_rField->addActionListener( this ); m_configContainer->add( m_rField ); label = new TextLabel( "Color G:" ); label->setColor( black ); m_configContainer->add( label ); ostr.str( "" ); ostr << g; m_gField = new TextField( ostr.str(), 200, 20 ); m_gField->addActionListener( this ); m_configContainer->add( m_gField ); label = new TextLabel( "Color B:" ); label->setColor( black ); m_configContainer->add( label ); ostr.str( "" ); ostr << b; m_bField = new TextField( ostr.str(), 200, 20 ); m_bField->addActionListener( this ); m_configContainer->add( m_bField ); m_buttonRow = new WidgetComposite(); HorizontalLayout* buttonLayout = new HorizontalLayout( m_buttonRow ); m_buttonRow->setLayout( buttonLayout ); buttonLayout->setSpacing( 5 ); m_okButton = new TextButton( "Ok" ); m_okButton->setHighlightable( true ); m_okButton->addActionListener( this ); m_buttonRow->add( m_okButton ); buttonLayout->setStretch( m_okButton, FILL ); m_cancelButton = new TextButton( "Cancel" ); m_cancelButton->setHighlightable( true ); m_cancelButton->addActionListener( this ); m_buttonRow->add( m_cancelButton ); buttonLayout->setStretch( m_cancelButton, FILL ); m_buttonRow->setWidth( 300 ); m_content = new WidgetComposite(); VerticalLayout* contentLayout = new VerticalLayout( m_content ); m_content->setLayout( contentLayout ); m_content->add( m_configContainer ); m_content->add( m_buttonRow ); setTitle( "Player configuration" ); setWidget( m_content ); } void PlayerConfigWindow::actionPerformed( Uint32 cmd, void* source ) { if ( source == m_okButton && cmd == Button::BUTTON_PRESSED ) { fireAction( OK_PRESSED, this ); } else if ( source == m_cancelButton && cmd == Button::BUTTON_PRESSED ) { fireAction( CANCEL_PRESSED, this ); } } bool PlayerConfigWindow::handleEvent( SDL_Event* event ) { if ( event->type == SDL_KEYDOWN ) { if ( event->key.keysym.sym == SDLK_ESCAPE ) { fireAction( CANCEL_PRESSED, this ); return true; } } return WopWindow::handleEvent( event ); } const Uint8 PlayerConfigWindow::getTeamID() const { std::stringstream sstr; int teamID; sstr << m_teamField->getText(); sstr >> teamID; return teamID; } const Uint8 PlayerConfigWindow::getColorR() const { std::stringstream sstr; int color; sstr << m_rField->getText(); sstr >> color; return color; } const Uint8 PlayerConfigWindow::getColorG() const { std::stringstream sstr; int color; sstr << m_gField->getText(); sstr >> color; return color; } const Uint8 PlayerConfigWindow::getColorB() const { std::stringstream sstr; int color; sstr << m_bField->getText(); sstr >> color; return color; }