Allows the widget managet to use filenames to set them as textures.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1798 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
cosmosninja 2008-05-01 22:05:33 +00:00
parent 9d03c22898
commit a78596f348
6 changed files with 45 additions and 29 deletions

View File

@ -52,19 +52,19 @@ CharSel::CharSel(int whichPlayer)
ssgContext* oldContext = ssgGetCurrentContext();
m_context = new ssgContext;
oldContext->makeCurrent();
// If m_player_index is 0 then this is a single player game or the first
// player of a multiplayer game so we need to ensure that all karts are available.
// If m_player_index is less than the number of elements in selected_karts then
// the user is moving back through the menus and the last value in the vector
// the user is moving back through the menus and the last value in the vector
// needs to be made available again.
if (m_player_index == 0)
kart_properties_manager->m_selected_karts.clear();
if (m_player_index < (int)kart_properties_manager->m_selected_karts.size())
kart_properties_manager->m_selected_karts.pop_back();
widget_manager->setInitialActivationState(false);
kart_properties_manager->m_selected_karts.clear();
if (m_player_index < (int)kart_properties_manager->m_selected_karts.size())
kart_properties_manager->m_selected_karts.pop_back();
widget_manager->setInitialActivationState(false);
widget_manager->addWgt( WTOK_TITLE, 60, 10);
widget_manager->showWgtRect( WTOK_TITLE );
char heading[MAX_MESSAGE_LENGTH];
@ -85,11 +85,10 @@ CharSel::CharSel(int whichPlayer)
{
const KartProperties* kp= kart_properties_manager->getKartById(i);
if(unlock_manager->isLocked(kp->getIdent())) continue;
Material *m = material_manager->getMaterial(kp->getIconFile());
widget_manager->addWgt( WTOK_RACER0 + i, 8, 11);
widget_manager->showWgtRect( WTOK_RACER0 + i);
widget_manager->setWgtColor( WTOK_RACER0 + i, WGT_GRAY);
widget_manager->setWgtTexture( WTOK_RACER0 + i, m->getState()->getTextureHandle());
widget_manager->setWgtTexture( WTOK_RACER0 + i, kp->getIconFile() );
widget_manager->showWgtTexture( WTOK_RACER0 + i );
widget_manager->activateWgt( WTOK_RACER0 + i );
}
@ -111,7 +110,7 @@ CharSel::CharSel(int whichPlayer)
m_current_kart = -1;
const int LAST_KART = user_config->m_player[m_player_index].getLastKartId();
if( LAST_KART != -1 && kartAvailable(LAST_KART))// is LAST_KART not in vector of selected karts
if( LAST_KART != -1 && kartAvailable(LAST_KART))// is LAST_KART not in vector of selected karts
{
widget_manager->setSelectedWgt(WTOK_RACER0 + LAST_KART);
switchCharacter(LAST_KART);
@ -254,13 +253,13 @@ bool CharSel::kartAvailable(int kart)
{
if (!kart_properties_manager->m_selected_karts.empty())
{
std::vector<int>::iterator it;
for (it = kart_properties_manager->m_selected_karts.begin();
it < kart_properties_manager->m_selected_karts.end(); it++)
{
if ( kart == *it)
return false;
}
std::vector<int>::iterator it;
for (it = kart_properties_manager->m_selected_karts.begin();
it < kart_properties_manager->m_selected_karts.end(); it++)
{
if ( kart == *it)
return false;
}
}
return true;
}

View File

@ -61,9 +61,8 @@ TrackSel::TrackSel()
widget_manager->hideWgtText(WTOK_TRACK0 + i);
widget_manager->deactivateWgt(WTOK_TRACK0 + i);
const Material *m = material_manager->getMaterial("gui_lock.rgb", false);
widget_manager->setWgtColor( WTOK_TRACK0 + i, WGT_WHITE);
widget_manager->setWgtTexture( WTOK_TRACK0 + i, m->getState()->getTextureHandle() );
widget_manager->setWgtTexture( WTOK_TRACK0 + i, "gui_lock.rgb" );
widget_manager->showWgtTexture( WTOK_TRACK0 + i );
}
if( i%2 != 0 ) widget_manager->breakLine();
@ -101,7 +100,6 @@ void TrackSel::update(float dt)
SELECTED_TRACK < (int)track_manager->getTrackCount() )
{
const Track* TRACK = track_manager->getTrack( SELECTED_TRACK );
const bool FULL_PATH=true;
widget_manager->setWgtText( WTOK_AUTHOR, TRACK->getDescription() );
@ -110,26 +108,23 @@ void TrackSel::update(float dt)
if( !screenshot.empty() && !topview.empty() )
{
const Material *m =material_manager->getMaterial(screenshot, FULL_PATH);
widget_manager->setWgtColor( WTOK_IMG0, WGT_WHITE);
widget_manager->showWgtRect( WTOK_IMG0 );
widget_manager->setWgtTexture( WTOK_IMG0, m->getState()->getTextureHandle() );
widget_manager->setWgtTexture( WTOK_IMG0, screenshot.c_str() );
widget_manager->showWgtTexture( WTOK_IMG0 );
widget_manager->hideWgtTrack( WTOK_IMG0 );
m = material_manager->getMaterial(topview, FULL_PATH);
widget_manager->setWgtColor( WTOK_IMG1, WGT_WHITE);
widget_manager->showWgtRect( WTOK_IMG1 );
widget_manager->setWgtTexture( WTOK_IMG1, m->getState()->getTextureHandle() );
widget_manager->setWgtTexture( WTOK_IMG1, topview.c_str() );
widget_manager->showWgtTexture( WTOK_IMG1 );
widget_manager->hideWgtTrack( WTOK_IMG1 );
}
else if( topview.empty() )
{
const Material *m = material_manager->getMaterial(screenshot, FULL_PATH);
widget_manager->setWgtColor( WTOK_IMG0, WGT_WHITE);
widget_manager->showWgtRect( WTOK_IMG0 );
widget_manager->setWgtTexture( WTOK_IMG0, m->getState()->getTextureHandle() );
widget_manager->setWgtTexture( WTOK_IMG0, screenshot.c_str() );
widget_manager->showWgtTexture( WTOK_IMG0 );
widget_manager->hideWgtTrack( WTOK_IMG0 );
@ -145,10 +140,9 @@ void TrackSel::update(float dt)
widget_manager->setWgtTrackNum( WTOK_IMG0, SELECTED_TRACK );
widget_manager->showWgtTrack( WTOK_IMG0 );
Material *m = material_manager->getMaterial(topview, FULL_PATH);
widget_manager->setWgtColor( WTOK_IMG1, WGT_WHITE);
widget_manager->showWgtRect( WTOK_IMG1 );
widget_manager->setWgtTexture( WTOK_IMG1, m->getState()->getTextureHandle() );
widget_manager->setWgtTexture( WTOK_IMG1, topview.c_str() );
widget_manager->showWgtTexture( WTOK_IMG1 );
widget_manager->hideWgtTrack( WTOK_IMG1 );
}

View File

@ -24,6 +24,7 @@
#include "constants.hpp"
#include "track_manager.hpp"
#include "material_manager.hpp"
#include "track.hpp"
#include <cmath>
#include <iostream>
@ -248,6 +249,13 @@ void Widget::setFont( const WidgetFont FONT )
m_curr_widget_font = FONT;
}
//-----------------------------------------------------------------------------
void Widget::setTexture( const char* FILENAME )
{
Material *m = material_manager->getMaterial( FILENAME );
m_texture = m->getState()->getTextureHandle();
}
/** Initialize a display list containing a rectangle that can have rounded
* corners, with texture coordinates to properly apply a texture
* map to the rectangle as though the corners were not rounded . Returns

View File

@ -204,6 +204,7 @@ class Widget
void darkenColor();
void setFont( const WidgetFont FONT );
void setTexture( const char* FILENAME );
/* Functions created simply to organize the code */
bool createRect(int radius);

View File

@ -1093,6 +1093,7 @@ void WidgetManager::hideWgtBorder(const int TOKEN)
}
}
//-----------------------------------------------------------------------------
void WidgetManager::setWgtTexture(const int TOKEN, const int TEXTURE)
{
@ -1105,6 +1106,18 @@ void WidgetManager::setWgtTexture(const int TOKEN, const int TEXTURE)
}
}
//-----------------------------------------------------------------------------
void WidgetManager::setWgtTexture(const int TOKEN, const char* FILENAME)
{
const int ID = findId(TOKEN);
if( ID != WGT_NONE ) m_widgets[ID].widget->setTexture( FILENAME );
else
{
std::cerr << "WARNING: tried to set the texture of an unnamed " <<
"widget with token " << TOKEN << '\n';
}
}
//-----------------------------------------------------------------------------
void WidgetManager::showWgtTexture(const int TOKEN)
{

View File

@ -312,6 +312,7 @@ public:
//TODO: add initial border colors, if I don't erase those functions.
void setWgtTexture(const int TOKEN, const int TEXTURE);
void setWgtTexture(const int TOKEN, const char* FILENAME);
void showWgtTexture(const int TOKEN);
void hideWgtTexture(const int TOKEN);