Removed the widget set and put in it's place a work-in-progress replacement

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1293 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
cosmosninja 2007-11-20 02:13:53 +00:00
parent 1da4736435
commit afca5cf6c6
42 changed files with 3363 additions and 2652 deletions

View File

@ -67,7 +67,8 @@ supertuxkart_SOURCES = main.cpp \
shadow.cpp shadow.hpp \
particle_system.cpp particle_system.hpp \
game_manager.cpp game_manager.hpp \
widget_set.cpp widget_set.hpp \
widget_manager.cpp widget_manager.hpp \
widget.cpp widget.hpp \
camera.cpp camera.hpp \
sdldrv.cpp sdldrv.hpp \
moveable.cpp moveable.hpp \
@ -107,7 +108,6 @@ supertuxkart_SOURCES = main.cpp \
gui/main_menu.cpp gui/main_menu.hpp \
gui/help_menu.cpp gui/help_menu.hpp \
gui/credits_menu.cpp gui/credits_menu.hpp \
gui/scrolled_text.cpp gui/scrolled_text.hpp \
gui/grand_prix_select.cpp gui/grand_prix_select.hpp \
gui/font.hpp gui/font.cpp \
robots/default_robot.cpp robots/default_robot.hpp \

View File

@ -20,7 +20,7 @@
#include <SDL/SDL.h>
#include "base_gui.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "world.hpp"
#include "menu_manager.hpp"
@ -31,6 +31,34 @@ void BaseGUI::input(InputType type, int id0, int id1, int id2, int value)
case IT_KEYBOARD:
inputKeyboard(id0, value);
break;
case IT_MOUSEMOTION:
{
const int PREV_SELECTED_WGT = widget_manager->get_selected_wgt();
const int SELECTED_WGT = widget_manager->handle_mouse( id0, id1 );
//FIXME: I should take WGT_NONE out of the class.
if( SELECTED_WGT != WidgetManager::WGT_NONE )
{
if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
{
widget_manager->darken_wgt_color( PREV_SELECTED_WGT );
}
widget_manager->lighten_wgt_color( SELECTED_WGT );
widget_manager->pulse_wgt( SELECTED_WGT );
}
#ifdef ALT_MOUSE_HANDLING
if (id0 == 1 && value)
if (id1 == AD_NEGATIVE)
inputKeyboard(SDLK_UP, 1);
else
inputKeyboard(SDLK_DOWN, 1);
#endif
break;
}
case IT_MOUSEBUTTON:
if (!value) // Act on button release only.
switch (id0)
@ -105,7 +133,28 @@ void BaseGUI::inputKeyboard(int key, int pressed)
case SDLK_RIGHT:
case SDLK_UP:
case SDLK_DOWN:
widgetSet->pulse(widgetSet->cursor(m_menu_id, key), 1.2f);
{
const int PREV_SELECTED_WGT = widget_manager->get_selected_wgt();
const int SELECTED_WGT = widget_manager->handle_keyboard( key );
if( SELECTED_WGT != WidgetManager::WGT_NONE )
{
if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
{
widget_manager->darken_wgt_color( PREV_SELECTED_WGT );
}
widget_manager->lighten_wgt_color( SELECTED_WGT );
widget_manager->pulse_wgt( SELECTED_WGT );
}
break;
}
case SDLK_PLUS:
case SDLK_MINUS:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
widget_manager->handle_keyboard( key );
break;
case SDLK_SPACE:
@ -118,7 +167,7 @@ void BaseGUI::inputKeyboard(int key, int pressed)
{
if(menu_manager->isCurrentMenu(MENUID_RACEMENU))
world->unpause();
menu_manager->popMenu();
}
break;
@ -131,14 +180,29 @@ void BaseGUI::inputKeyboard(int key, int pressed)
void
BaseGUI::inputPointer(int x, int y)
{
widgetSet->pulse(widgetSet->point(m_menu_id, x, y), 1.2f);
const int PREV_SELECTED_WGT = widget_manager->get_selected_wgt();
const int SELECTED_WGT = widget_manager->handle_mouse( x, y );
if( SELECTED_WGT != WidgetManager::WGT_NONE )
{
if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
{
widget_manager->darken_wgt_color( PREV_SELECTED_WGT );
}
widget_manager->lighten_wgt_color( SELECTED_WGT );
widget_manager->pulse_wgt( SELECTED_WGT );
}
}
//-----------------------------------------------------------------------------
void BaseGUI::update(float dt)
{
widget_manager->update(dt);
#if 0
widgetSet -> timer(m_menu_id, dt) ;
widgetSet -> paint(m_menu_id) ;
#endif
} // update
//-----------------------------------------------------------------------------

View File

@ -23,7 +23,7 @@
#include "loader.hpp"
#include "char_sel.hpp"
#include "kart_properties_manager.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "race_manager.hpp"
#include "user_config.hpp"
#include "menu_manager.hpp"
@ -35,62 +35,78 @@
# define snprintf _snprintf
#endif
enum WidgetTokens
{
WTOK_RACER0,
WTOK_RACER1,
WTOK_RACER2,
WTOK_RACER3,
WTOK_RACER4,
WTOK_RACER5,
WTOK_RACER6,
WTOK_RACER7,
WTOK_RACER8,
WTOK_RACER9,
WTOK_TITLE,
WTOK_NAME,
WTOK_QUIT
};
CharSel::CharSel(int whichPlayer)
: m_kart(0), m_player_index(whichPlayer)
{
// for some strange reasons plib calls makeCurrent() in ssgContextf
// For some strange reasons plib calls makeCurrent() in ssgContext
// constructor, so we have to save the old one here and restore it
ssgContext* oldContext = ssgGetCurrentContext();
m_context = new ssgContext;
oldContext->makeCurrent();
m_menu_id = widgetSet -> vstack(0);
const int HS1 = widgetSet -> hstack (m_menu_id);
widgetSet -> filler(HS1);
// Due to widgetSet constraints, this must be static!
static char HEADING[MAX_MESSAGE_LENGTH];
widget_manager->set_initial_activation_state(false);
widget_manager->add_wgt( WTOK_TITLE, 60, 10);
widget_manager->show_wgt_rect( WTOK_TITLE );
char HEADING[MAX_MESSAGE_LENGTH];
snprintf(HEADING, sizeof(HEADING), _("Player %d, choose a driver"),
m_player_index + 1);
widget_manager->set_wgt_text( WTOK_TITLE, HEADING);
widget_manager->set_wgt_text_size( WTOK_TITLE, WGT_FNT_LRG);
widget_manager->show_wgt_text( WTOK_TITLE );
widget_manager->break_line();
widgetSet -> label(HS1, HEADING, GUI_LRG, GUI_ALL, 0, 0);
widgetSet -> filler(HS1);
widget_manager->add_wgt( WidgetManager::WGT_NONE, 100, 2);
widget_manager->break_line();
widgetSet -> filler(m_menu_id);
const int HA = widgetSet -> harray(m_menu_id);
const int ICON_SIZE = 64;
unsigned int lastKartId = user_config->m_player[m_player_index].getLastKartId();
bool skipActivatingLast = false;
//FIXME: this supports only a static number of karts
// unsigned int lastKartId = user_config->m_player[m_player_index].getLastKartId();
// bool skipActivatingLast = false;
for (unsigned int i = 0; i < kart_properties_manager->getNumberOfKarts(); i++)
{
const KartProperties* kp= kart_properties_manager->getKartById(i);
Material *m = material_manager->getMaterial(kp->getIconFile());
const int C = widgetSet->image(HA, m->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE);
widgetSet->activate_widget(C, i, 0);
if (i == lastKartId)
{
widgetSet->set_active(C);
skipActivatingLast = true;
}
if (!skipActivatingLast &&
i == kart_properties_manager->getNumberOfKarts() - 1)
widgetSet->set_active(C);
widget_manager->add_wgt( WTOK_RACER0 + i, 10, 13);
widget_manager->show_wgt_rect( WTOK_RACER0 + i);
widget_manager->set_wgt_color( WTOK_RACER0 + i, WGT_GRAY);
widget_manager->set_wgt_texture( WTOK_RACER0 + i, m->getState()->getTextureHandle());
widget_manager->show_wgt_texture( WTOK_RACER0 + i );
widget_manager->activate_wgt( WTOK_RACER0 + i );
}
const int HS2 = widgetSet -> hstack(m_menu_id);
widgetSet -> filler (HS2);
m_kart_name_label = widgetSet -> label(HS2, _("No driver choosed"),
GUI_MED, GUI_ALL);
widgetSet -> filler (HS2);
widgetSet -> layout(m_menu_id, 0, 1);
widget_manager->break_line();
widget_manager->add_wgt( WidgetManager::WGT_NONE, 100, 2);
widget_manager->break_line();
//FIXME: the widget should check if the dimensions > 100
widget_manager->add_wgt( WTOK_NAME, 20, 7);
widget_manager->show_wgt_rect( WTOK_NAME );
widget_manager->show_wgt_text( WTOK_NAME );
//FIXME: widget_manager says that token -1 is already in use
widget_manager->layout(WGT_AREA_TOP);
m_current_kart = -1;
switchCharacter(1);
switchCharacter(0);
m_clock = 0;
//test
@ -100,7 +116,7 @@ CharSel::CharSel(int whichPlayer)
//-----------------------------------------------------------------------------
CharSel::~CharSel()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
ssgDeRefDelete(m_kart);
delete m_context;
@ -112,7 +128,8 @@ void CharSel::switchCharacter(int n)
const KartProperties* kp= kart_properties_manager->getKartById(n);
if (m_current_kart != n && kp != NULL)
{
widgetSet -> set_label(m_kart_name_label, kp->getName().c_str());
//widgetSet -> set_label(m_kart_name_label, kp->getName().c_str());
widget_manager->set_wgt_text( WTOK_NAME, kp->getName().c_str());
m_current_kart = n;
ssgDeRefDelete(m_kart);
@ -130,7 +147,7 @@ void CharSel::update(float dt)
m_clock += dt * 40.0f;
BaseGUI::update(dt);
switchCharacter(widgetSet->get_token(widgetSet->click()));
switchCharacter(widget_manager->get_selected_wgt() - WTOK_RACER0);
if (m_kart != NULL)
{
@ -168,7 +185,7 @@ void CharSel::update(float dt)
//----------------------------------------------------------------------------
void CharSel::select()
{
const int TOKEN = widgetSet -> get_token (widgetSet -> click());
const int TOKEN = 0;
const KartProperties* KP = kart_properties_manager->getKartById(TOKEN);
if (KP != NULL)
{

View File

@ -31,7 +31,6 @@ private:
ssgContext* m_context;
ssgTransform* m_kart;
int m_current_kart;
int m_kart_name_label;
float m_clock;
int m_player_index;

View File

@ -18,19 +18,72 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config_controls.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
enum WidgetTokens {
WTOK_TITLE,
WTOK_PLYR1,
WTOK_PLYR2,
WTOK_PLYR3,
WTOK_PLYR4,
WTOK_SPACE,
WTOK_QUIT
};
ConfigControls::ConfigControls()
{
m_menu_id = widgetSet -> vstack(0);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widget_manager->add_wgt( WTOK_TITLE, 60, 7 );
widget_manager->set_wgt_text( WTOK_TITLE, _("Edit controls for which player?"));
widget_manager->break_line();
widget_manager->set_initial_activation_state(true);
widget_manager->add_wgt( WTOK_PLYR1 , 60, 7 );
widget_manager->set_wgt_text( WTOK_PLYR1, _("Player 1"));
widget_manager->break_line();
widget_manager->add_wgt( WTOK_PLYR2 , 60, 7 );
widget_manager->set_wgt_text( WTOK_PLYR2, _("Player 2"));
widget_manager->break_line();
widget_manager->add_wgt( WTOK_PLYR3 , 60, 7 );
widget_manager->set_wgt_text( WTOK_PLYR3, _("Player 3"));
widget_manager->break_line();
widget_manager->add_wgt( WTOK_PLYR4 , 60, 7 );
widget_manager->set_wgt_text( WTOK_PLYR4, _("Player 4"));
widget_manager->break_line();
widget_manager->add_wgt( WTOK_SPACE, 60, 5);
widget_manager->deactivate_wgt( WTOK_SPACE );
widget_manager->hide_wgt_rect( WTOK_SPACE );
widget_manager->hide_wgt_text( WTOK_SPACE );
widget_manager->break_line();
widget_manager->add_wgt( WTOK_QUIT , 60, 7 );
widget_manager->set_wgt_text( WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->set_wgt_text_size( WTOK_QUIT, WGT_FNT_SML );
widget_manager->layout( WGT_AREA_ALL );
/*
* m_menu_id = widgetSet -> vstack(0);
widgetSet -> label(m_menu_id, _("Edit controls for which player?"), GUI_LRG);
const int VA = widgetSet -> varray(m_menu_id);
static char playerN[4][MAX_MESSAGE_LENGTH];
for(int i=1; i<=4; i++)
{
@ -45,33 +98,33 @@ ConfigControls::ConfigControls()
widgetSet -> space(VA);
widgetSet -> state(VA, _("Press <ESC> to go back"), GUI_SML, 5);
widgetSet -> layout(m_menu_id, 0, 0);
widgetSet -> layout(m_menu_id, 0, 0);*/
}
//-----------------------------------------------------------------------------
ConfigControls::~ConfigControls()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
// widgetSet -> delete_widget(m_menu_id) ;
}
//-----------------------------------------------------------------------------
void ConfigControls::update(float dt)
/*void ConfigControls::update(float dt)
{
widgetSet -> timer(m_menu_id, dt) ;
widgetSet -> paint(m_menu_id) ;
}
*/
//-----------------------------------------------------------------------------
void ConfigControls::select()
{
switch ( widgetSet -> get_token (widgetSet -> click()) )
switch ( widget_manager->get_selected_wgt() )
{
case 1: menu_manager->pushMenu(MENUID_CONFIG_P1); break;
case 2: menu_manager->pushMenu(MENUID_CONFIG_P2); break;
case 3: menu_manager->pushMenu(MENUID_CONFIG_P3); break;
case 4: menu_manager->pushMenu(MENUID_CONFIG_P4); break;
case 5: menu_manager->popMenu(); break;
default: break;
case WTOK_PLYR1: menu_manager->pushMenu(MENUID_CONFIG_P1); break;
case WTOK_PLYR2: menu_manager->pushMenu(MENUID_CONFIG_P2); break;
case WTOK_PLYR3: menu_manager->pushMenu(MENUID_CONFIG_P3); break;
case WTOK_PLYR4: menu_manager->pushMenu(MENUID_CONFIG_P4); break;
case WTOK_QUIT: menu_manager->popMenu(); break;
}
}

View File

@ -28,7 +28,7 @@ public:
ConfigControls();
~ConfigControls();
void update(float dt);
// void update(float dt);
void select();
};

View File

@ -18,70 +18,91 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config_display.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "user_config.hpp"
#include "menu_manager.hpp"
#include "sdldrv.hpp"
#include "translation.hpp"
enum WidgetTokens {
WTOK_FULLSCREEN, WTOK_BACK
WTOK_TITLE,
WTOK_FULLSCREEN,
WTOK_EMPTY,
WTOK_QUIT
};
ConfigDisplay::ConfigDisplay()
{
CreateMenu();
}
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
//-----------------------------------------------------------------------------
void ConfigDisplay::CreateMenu()
{
m_menu_id = widgetSet -> vstack(0);
widgetSet -> label(m_menu_id, _("Display Settings"), GUI_LRG, GUI_ALL, 0, 0);
const int VA = widgetSet -> varray(m_menu_id);
m_fullscreen_menu_id = widgetSet -> start(VA, _("Fullscreen mode"), GUI_MED,
WTOK_FULLSCREEN);
widget_manager->add_wgt( WTOK_TITLE, 40, 7);
widget_manager->set_wgt_text( WTOK_TITLE, _("Display Settings"));
widget_manager->break_line();
widget_manager->set_initial_activation_state(true);
widget_manager->add_wgt( WTOK_FULLSCREEN, 40, 7);
if(user_config->m_fullscreen)
widgetSet->set_label(m_fullscreen_menu_id, _("Window mode"));
widgetSet -> space(VA);
widgetSet -> state(VA, _("Press <ESC> to go back"), GUI_SML, WTOK_BACK);
widgetSet -> layout(m_menu_id, 0, 0);
} // CreateMenu
{
widget_manager->set_wgt_text( WTOK_FULLSCREEN, _("Fullscreen mode"));
}
else
{
widget_manager->set_wgt_text( WTOK_FULLSCREEN, _("Fullscreen mode"));
}
widget_manager->break_line();
widget_manager->add_wgt( WTOK_EMPTY, 40, 2);
widget_manager->deactivate_wgt( WTOK_EMPTY );
widget_manager->hide_wgt_rect( WTOK_EMPTY );
widget_manager->hide_wgt_text( WTOK_EMPTY );
widget_manager->break_line();
widget_manager->add_wgt( WTOK_QUIT, 40, 7);
widget_manager->set_wgt_text( WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->set_wgt_text_size( WTOK_QUIT, WGT_FNT_SML );
widget_manager->layout( WGT_AREA_ALL );
}
//-----------------------------------------------------------------------------
ConfigDisplay::~ConfigDisplay()
{
widgetSet -> delete_widget(m_menu_id) ;
// widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
}
//-----------------------------------------------------------------------------
void ConfigDisplay::update(float dt)
/*void ConfigDisplay::update(float dt)
{
widgetSet -> timer(m_menu_id, dt) ;
widgetSet -> paint(m_menu_id) ;
}
}*/
//-----------------------------------------------------------------------------
void ConfigDisplay::select()
{
switch ( widgetSet -> get_token (widgetSet -> click()) )
switch ( widget_manager->get_selected_wgt())
{
case WTOK_FULLSCREEN:
drv_toggleFullscreen();
widgetSet -> delete_widget(m_menu_id) ;
// widgetSet -> delete_widget(m_menu_id) ;
// Since changing the video mode in drv_toggleFullscreen deletes all
// display lists, textures etc., we have to load the menu again.
// drv_toggleFullscreen takes care of general material, general
// widgetSet, etc.
CreateMenu();
// CreateMenu();
if(user_config->m_fullscreen)
widgetSet->set_label(m_fullscreen_menu_id, _("Window mode"));
widget_manager->set_wgt_text( WTOK_FULLSCREEN, _("Window mode"));
else
widgetSet->set_label(m_fullscreen_menu_id, _("Fullscreen mode"));
widget_manager->set_wgt_text( WTOK_FULLSCREEN, _("Fullscreen mode"));
break;
case WTOK_BACK:
case WTOK_QUIT:
menu_manager->popMenu();
break;
default: break;

View File

@ -24,12 +24,11 @@
class ConfigDisplay: public BaseGUI
{
void CreateMenu();
public:
ConfigDisplay();
~ConfigDisplay();
void update(float dt);
// void update(float dt);
void select();
private:

View File

@ -18,90 +18,109 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config_sound.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "user_config.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
enum WidgetTokens {
WTOK_TITLE,
WTOK_MUSIC,
WTOK_SFX,
WTOK_BACK,
WTOK_EMPTY,
WTOK_QUIT,
};
ConfigSound::ConfigSound()
{
m_menu_id = widgetSet -> vstack(0);
widgetSet -> label(m_menu_id, _("Sound Settings"), GUI_LRG, GUI_ALL, 0, 0);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
const int VA = widgetSet -> varray(m_menu_id);
// The spaces are important, otherwise the set_label calls below will
// increase the width of the container, resulting in a warning being
// printed by widgetSet.
widget_manager->add_wgt(WTOK_TITLE, 40, 7);
widget_manager->set_wgt_text( WTOK_TITLE, _("Sound Settings"));
widget_manager->break_line();
widget_manager->set_initial_activation_state(true);
widget_manager->add_wgt(WTOK_MUSIC, 40, 7);
if( user_config->doMusic() )
m_music_menu_id = widgetSet->start(VA,_(" Turn off music "),
GUI_MED, WTOK_MUSIC, GUI_ON);
{
widget_manager->set_wgt_text( WTOK_MUSIC, _("Turn off music"));
}
else
m_music_menu_id = widgetSet->start(VA,_(" Turn on music "),
GUI_MED, WTOK_MUSIC, GUI_OFF);
{
widget_manager->set_wgt_text( WTOK_MUSIC, _("Turn on music"));
}
widget_manager->break_line();
widget_manager->add_wgt(WTOK_SFX, 40, 7);
if( user_config->doSFX() )
m_sfx_menu_id = widgetSet->state(VA,_(" Turn off sound effects "),
GUI_MED, WTOK_SFX, GUI_ON);
{
widget_manager->set_wgt_text( WTOK_SFX, _("Turn off sound effects"));
}
else
m_sfx_menu_id = widgetSet->state(VA,_(" Turn on sound effects "),
GUI_MED, WTOK_SFX, GUI_OFF);
{
widget_manager->set_wgt_text( WTOK_SFX, _("Turn on sound effects"));
}
widget_manager->break_line();
widgetSet -> space(VA);
widgetSet -> state(VA, _("Press <ESC> to go back"), GUI_SML, WTOK_BACK);
widgetSet -> layout(m_menu_id, 0, 0);
widget_manager->add_wgt(WTOK_EMPTY, 40, 5);
widget_manager->deactivate_wgt(WTOK_EMPTY);
widget_manager->hide_wgt_rect(WTOK_EMPTY);
widget_manager->hide_wgt_text(WTOK_EMPTY);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUIT, 40, 7);
widget_manager->set_wgt_text( WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->set_wgt_text_size(WTOK_QUIT, WGT_FNT_SML);
widget_manager->break_line();
widget_manager->layout(WGT_AREA_ALL);
}
//-----------------------------------------------------------------------------
ConfigSound::~ConfigSound()
{
widgetSet -> delete_widget(m_menu_id) ;
}
//-----------------------------------------------------------------------------
void ConfigSound::update(float dt)
{
widgetSet -> timer(m_menu_id, dt) ;
widgetSet -> paint(m_menu_id) ;
widget_manager->delete_wgts();
}
//-----------------------------------------------------------------------------
void ConfigSound::select()
{
switch ( widgetSet -> get_token (widgetSet -> click()) )
switch ( widget_manager->get_selected_wgt())
{
case WTOK_MUSIC:
if(user_config->doMusic())
{
user_config->setMusic(UserConfig::UC_DISABLE);
widgetSet->set_label(m_music_menu_id, _("Turn on music"));
widget_manager->set_wgt_text(WTOK_MUSIC, _("Turn on music"));
}
else
{
user_config->setMusic(UserConfig::UC_ENABLE);
widgetSet->set_label(m_music_menu_id, _("Turn off music"));
widget_manager->set_wgt_text(WTOK_MUSIC, _("Turn off music"));
}
widgetSet->toggle(m_music_menu_id);
//FIXME:'Toggling' can be achieved with a simple color change, if desired.
// widgetSet->toggle(m_music_menu_id);
break;
case WTOK_SFX:
if(user_config->doSFX())
{
user_config->setSFX(UserConfig::UC_DISABLE);
widgetSet->set_label(m_sfx_menu_id, _("Turn on sound effects"));
widget_manager->set_wgt_text(WTOK_SFX, _("Turn on sound effects"));
}
else
{
user_config->setSFX(UserConfig::UC_ENABLE);
widgetSet->set_label(m_sfx_menu_id, _("Turn off sound effects"));
widget_manager->set_wgt_text(WTOK_SFX, _("Turn off sound effects"));
}
widgetSet->toggle(m_sfx_menu_id);
// widgetSet->toggle(m_sfx_menu_id);
break;
case WTOK_BACK:
case WTOK_QUIT:
menu_manager->popMenu();
break;
default: break;

View File

@ -28,7 +28,6 @@ public:
ConfigSound();
~ConfigSound();
void update(float dt);
void select();
private:

View File

@ -16,48 +16,88 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <fstream>
#include <stdexcept>
#include <iostream>
#include "credits_menu.hpp"
#include "loader.hpp"
#include "translation.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define strdup _strdup
#endif
enum WidgetTokens
{
WTOK_CREDITS,
WTOK_QUIT
};
CreditsMenu::CreditsMenu()
{
std::string filename;
StringList credits_text_list;
try
std::string line;
std::string credits_text;
filename = loader->getPath("data/CREDITS");
std::ifstream file(filename.c_str());
if( file.is_open() )
{
filename = loader->getPath("data/CREDITS");
//FIXME: we should change to c++ - filestreams
FILE *fd = fopen(filename.c_str(), "r");
char s[1024];
char *p;
while(fgets(s, 1023, fd))
while( !file.eof() )
{
credits_text_list.push_back(std::string(s));
getline(file, line);
credits_text.append(line);
credits_text.push_back('\n');
} // while
fclose(fd);
fd = NULL;
file.close();
}
catch(std::runtime_error& e)
else
{
printf(_("Couldn't load '%s'\n"),filename.c_str());
credits_text_list.push_back(_("CREDIT file was not installed properly!!"));
credits_text_list.push_back(_("Please check 'data/CREDIT'!!"));
credits_text.append(_("CREDIT file was not installed properly!!\n"));
credits_text.append(_("Please check 'data/CREDITS'!!"));
}
setText(credits_text_list);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
const WidgetFontSize TEXT_SIZE = WGT_FNT_SML;
widget_manager->set_initial_activation_state( true );
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", TEXT_SIZE, Font::ALIGN_CENTER, Font::ALIGN_CENTER);
widget_manager->add_wgt( WTOK_CREDITS, 100, 93);
widget_manager->set_wgt_text( WTOK_CREDITS, credits_text );
widget_manager->set_wgt_text_x_alignment( WTOK_CREDITS, Font::ALIGN_LEFT );
//FIXME: maybe I should make scroll names more consistent
widget_manager->enable_wgt_scroll( WTOK_CREDITS );
widget_manager->break_line();
widget_manager->add_wgt( WTOK_QUIT, 40, 7);
widget_manager->set_wgt_text( WTOK_QUIT, _("Go back to the main menu"));
widget_manager->layout( WGT_AREA_TOP );
} // CreditsMenu
//-----------------------------------------------------------------------------
CreditsMenu::~CreditsMenu()
{
widget_manager->delete_wgts() ;
} // ~CreditsMenu
//-----------------------------------------------------------------------------
void CreditsMenu::select()
{
switch( widget_manager->get_selected_wgt() )
{
case WTOK_QUIT:
menu_manager->popMenu();
break;
}
}
/* EOF */

View File

@ -20,23 +20,17 @@
#ifndef HEADER_CREDITSMENU_H
#define HEADER_CREDITSMENU_H
#include <string>
#include <plib/fnt.h>
#include "scrolled_text.hpp"
#include "base_gui.hpp"
#include "player.hpp"
//#include "player.hpp"
class CreditsMenu: public ScrolledText
class CreditsMenu: public BaseGUI
{
private:
int m_xLeft, m_xRight, m_yBottom, m_yTop;
float m_yPos, m_ySpeed;
int m_numberOfLines;
int m_fontSize;
public:
CreditsMenu();
~CreditsMenu();
void select ();
};
#endif

View File

@ -19,45 +19,63 @@
#include "difficulty.hpp"
#include "race_manager.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
enum WidgetTokens {
WTOK_TITLE,
WTOK_HARD,
WTOK_MEDIUM,
WTOK_EASY,
WTOK_BACK
WTOK_QUIT
};
Difficulty::Difficulty()
{
m_menu_id = widgetSet -> vstack(0);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widgetSet -> label(m_menu_id, _("Choose your skill level"), GUI_LRG, GUI_ALL, 0, 0);
widget_manager->add_wgt(WTOK_TITLE, 60, 7);
widget_manager->show_wgt_rect(WTOK_TITLE);
widget_manager->show_wgt_text(WTOK_TITLE);
widget_manager->set_wgt_text(WTOK_TITLE,
_("Choose your skill level"));
widget_manager->break_line();
const int VA = widgetSet -> varray(m_menu_id);
widgetSet -> space(m_menu_id);
widgetSet -> space(m_menu_id);
widgetSet -> state(VA, _("Racer"), GUI_MED, WTOK_HARD);
widgetSet -> state(VA, _("Driver"), GUI_MED, WTOK_MEDIUM);
widgetSet -> start(VA, _("Novice"), GUI_MED, WTOK_EASY);
widgetSet -> space(VA);
widgetSet -> state(VA, _("Press <ESC> to go back"), GUI_SML, WTOK_BACK);
widget_manager->set_initial_activation_state(true);
widget_manager->add_wgt(WTOK_HARD, 60, 7);
widget_manager->set_wgt_text(WTOK_HARD, _("Racer"));
widget_manager->break_line();
widgetSet -> layout(m_menu_id, 0, 0);
widget_manager->add_wgt(WTOK_MEDIUM, 60, 7);
widget_manager->set_wgt_text(WTOK_MEDIUM, _("Driver"));
widget_manager->break_line();
widget_manager->add_wgt(WTOK_EASY, 60, 7);
widget_manager->set_wgt_text(WTOK_EASY, _("Novice"));
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUIT, 60, 7);
widget_manager->set_wgt_text(WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->layout(WGT_AREA_ALL);
} // Difficulty
//-----------------------------------------------------------------------------
Difficulty::~Difficulty()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
} // ~Difficulty
//-----------------------------------------------------------------------------
void Difficulty::select()
{
switch ( widgetSet -> get_token (widgetSet -> click()) )
switch ( widget_manager->get_selected_wgt())
{
case WTOK_EASY:
race_manager->setDifficulty(RD_EASY);
@ -71,7 +89,7 @@ void Difficulty::select()
race_manager->setDifficulty(RD_HARD);
menu_manager->pushMenu(MENUID_CHARSEL_P1);
break;
case WTOK_BACK:
case WTOK_QUIT:
menu_manager->popMenu();
break;
default: break;

View File

@ -18,12 +18,13 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "game_mode.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "race_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
enum WidgetTokens {
WTOK_TITLE,
WTOK_GP,
WTOK_QUICKRACE,
WTOK_TIMETRIAL,
@ -32,7 +33,52 @@ enum WidgetTokens {
GameMode::GameMode()
{
m_menu_id = widgetSet -> vstack(0);
widget_manager->add_wgt(WTOK_TITLE, 50, 7);
widget_manager->show_wgt_rect( WTOK_TITLE );
widget_manager->set_wgt_text( WTOK_TITLE, _("Choose a Race Mode"));
widget_manager->set_wgt_text_size( WTOK_TITLE, WGT_FNT_LRG );
widget_manager->show_wgt_text( WTOK_TITLE );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_GP, 50, 7);
widget_manager->show_wgt_rect( WTOK_GP );
widget_manager->set_wgt_text( WTOK_GP, _("Grand Prix"));
widget_manager->set_wgt_text_size( WTOK_GP, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_GP );
widget_manager->activate_wgt( WTOK_GP );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUICKRACE, 50, 7);
widget_manager->show_wgt_rect( WTOK_QUICKRACE );
widget_manager->set_wgt_text( WTOK_QUICKRACE, _("Quick Race"));
widget_manager->set_wgt_text_size( WTOK_QUICKRACE, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_QUICKRACE );
widget_manager->activate_wgt( WTOK_QUICKRACE );
widget_manager->break_line();
if( race_manager->getNumPlayers() == 1 )
{
widget_manager->add_wgt(WTOK_TIMETRIAL, 50, 7);
widget_manager->show_wgt_rect( WTOK_TIMETRIAL );
widget_manager->set_wgt_text( WTOK_TIMETRIAL, _("Time Trial"));
widget_manager->set_wgt_text_size( WTOK_TIMETRIAL, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_TIMETRIAL );
widget_manager->activate_wgt( WTOK_TIMETRIAL );
widget_manager->break_line();
}
widget_manager->add_wgt(WidgetManager::WGT_NONE, 50, 7);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_BACK, 50, 7);
widget_manager->show_wgt_rect( WTOK_BACK );
widget_manager->set_wgt_text( WTOK_BACK, _("Press <ESC> to go back"));
widget_manager->set_wgt_text_size( WTOK_BACK, WGT_FNT_SML );
widget_manager->show_wgt_text( WTOK_BACK );
widget_manager->activate_wgt( WTOK_BACK );
widget_manager->layout(WGT_AREA_ALL);
/* m_menu_id = widgetSet -> vstack(0);
widgetSet -> label(m_menu_id, _("Choose a Race Mode"), GUI_LRG);
@ -47,19 +93,20 @@ GameMode::GameMode()
widgetSet -> space(VA);
widgetSet -> state(VA,_("Press <ESC> to go back"), GUI_SML, WTOK_BACK);
widgetSet -> space(VA);
widgetSet -> layout(m_menu_id, 0, 0);
widgetSet -> layout(m_menu_id, 0, 0);*/
}
//-----------------------------------------------------------------------------
GameMode::~GameMode()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
}
//-----------------------------------------------------------------------------
void GameMode::select()
{
switch ( widgetSet -> get_token (widgetSet -> click()) )
// switch ( widgetSet -> get_token (widgetSet -> click()) )
switch ( widget_manager->get_selected_wgt() )
{
case WTOK_GP:
race_manager->setRaceMode(RaceSetup::RM_GRAND_PRIX);

View File

@ -26,7 +26,7 @@
#include "sound_manager.hpp"
#include "grand_prix_ending.hpp"
#include "kart_properties_manager.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "race_manager.hpp"
#include "game_manager.hpp"
#include "user_config.hpp"
@ -39,6 +39,16 @@
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
enum WidgetTokens
{
WTOK_TITLE,
WTOK_QUIT,
WTOK_FIRSTKART
};
GrandPrixEnd::GrandPrixEnd()
: m_kart(0)
{
@ -48,7 +58,7 @@ GrandPrixEnd::GrandPrixEnd()
m_context = new ssgContext;
oldContext->makeCurrent();
m_menu_id = widgetSet -> vstack(0);
// m_menu_id = widgetSet -> vstack(0);
int highest = 0;
//FIXME: We go from the back to the front because the players are in the
@ -64,13 +74,19 @@ GrandPrixEnd::GrandPrixEnd()
static char output[MAX_MESSAGE_LENGTH];
snprintf(output, sizeof(output),
_("The winner is %s!"),WINNING_KART->getName().c_str());
widgetSet -> label(m_menu_id, output, GUI_LRG, GUI_ALL, 0, 0);
widget_manager->add_wgt( WTOK_TITLE, 60, 10);
widget_manager->show_wgt_rect(WTOK_TITLE);
widget_manager->show_wgt_text(WTOK_TITLE);
widget_manager->set_wgt_text(WTOK_TITLE, output);
widget_manager->set_wgt_text_size(WTOK_TITLE, WGT_FNT_LRG);
widget_manager->break_line();
// widgetSet -> label(m_menu_id, output, GUI_LRG, GUI_ALL, 0, 0);
const unsigned int MAX_STR_LEN = 60;
const unsigned int NUM_KARTS = world->getNumKarts();
const int VA = widgetSet->varray(m_menu_id);
// const int VA = widgetSet->varray(m_menu_id);
Kart *kart;
int *scores = new int[NUM_KARTS];
@ -114,16 +130,25 @@ GrandPrixEnd::GrandPrixEnd()
kart = world->getKart(position[i]);
sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %d",
i + 1, kart->getName().c_str(), scores[i]);
widgetSet -> label(VA, (char*)(m_score + MAX_STR_LEN * i), GUI_MED,
GUI_ALL);
widget_manager->add_wgt(WTOK_FIRSTKART + i, 40, 5);
widget_manager->show_wgt_rect(WTOK_FIRSTKART + i);
widget_manager->show_wgt_text(WTOK_FIRSTKART + i);
widget_manager->set_wgt_text(WTOK_FIRSTKART + i,
(char*)(m_score + MAX_STR_LEN * i));
widget_manager->set_wgt_text_size(WTOK_FIRSTKART + i, WGT_FNT_SML);
widget_manager->break_line();
}
delete []scores;
delete []position;
widgetSet -> space(m_menu_id);
widgetSet -> label(m_menu_id, _("Back to the main menu"), GUI_LRG, GUI_ALL, 0, 0);
widget_manager->add_wgt(WTOK_QUIT, 40, 7);
widget_manager->activate_wgt(WTOK_QUIT);
widget_manager->show_wgt_rect(WTOK_QUIT);
widget_manager->show_wgt_text(WTOK_QUIT);
widget_manager->set_wgt_text(WTOK_QUIT, _("Back to the main menu"));
widgetSet -> layout(m_menu_id, 0, 1);
widget_manager->layout(WGT_AREA_ALL);
m_kart = new ssgTransform;
m_kart->ref();
@ -146,7 +171,8 @@ GrandPrixEnd::GrandPrixEnd()
//-----------------------------------------------------------------------------
GrandPrixEnd::~GrandPrixEnd()
{
widgetSet -> delete_widget(m_menu_id);
widget_manager->delete_wgts();
//widgetSet -> delete_widget(m_menu_id);
ssgDeRefDelete(m_kart);
delete m_context;

View File

@ -21,23 +21,42 @@
#include "loader.hpp"
#include "string_utils.hpp"
#include "grand_prix_select.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#include "race_manager.hpp"
#include "user_config.hpp"
#include "font.hpp"
#include "translation.hpp"
enum WidgetTokens
{
WTOK_TITLE,
//FIXME: finish the tokens
WTOK_EMPTY0,
WTOK_DESCRIPTION,
WTOK_EMPTY1,
WTOK_QUIT,
WTOK_FIRSTPRIX
};
GrandPrixSelect::GrandPrixSelect()
{
m_menu_id = widgetSet -> varray(0);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widgetSet -> label(m_menu_id, _("Choose a Grand Prix"), GUI_LRG, GUI_ALL, 0, 0);
widgetSet -> space(m_menu_id);
widget_manager->add_wgt(WTOK_TITLE, 40, 7);
widget_manager->set_wgt_text(WTOK_TITLE, _("Choose a Grand Prix"));
widget_manager->break_line();
std::set<std::string> result;
loader->listFiles(result, "data");
widget_manager->set_initial_activation_state(true);
// Findout which grand prixs are available and load them
int nId = 0;
for(std::set<std::string>::iterator i = result.begin();
@ -48,37 +67,67 @@ GrandPrixSelect::GrandPrixSelect()
std::string fullPath= "data/" + (std::string)*i;
CupData cup(fullPath.c_str());
m_all_cups.push_back(cup);
if(nId==0)
widget_manager->add_wgt(WTOK_FIRSTPRIX + nId, 40, 7);
widget_manager->set_wgt_text(WTOK_FIRSTPRIX + nId, cup.getName());
/* if(nId==0)
{
widgetSet -> start(m_menu_id, cup.getName(), GUI_SML, nId, 0);
}
else
{
widgetSet -> state(m_menu_id, cup.getName(), GUI_SML, nId, 0);
}
}*/
widget_manager->break_line();
nId++;
} // if
} // for i
widgetSet -> space(m_menu_id);
widgetSet -> state(m_menu_id,_("Press <ESC> to go back"), GUI_SML, -1);
widgetSet -> layout(m_menu_id, 0, 0);
m_rect = widgetSet->rect(10, 10, user_config->m_width-20, 34, GUI_ALL, 10);
widget_manager->set_initial_activation_state(false);
widget_manager->add_wgt(WTOK_EMPTY0, 60, 7);
widget_manager->hide_wgt_rect(WTOK_EMPTY0);
widget_manager->hide_wgt_text(WTOK_EMPTY0);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_DESCRIPTION, 80, 7);
widget_manager->hide_wgt_rect(WTOK_DESCRIPTION);
widget_manager->set_wgt_text(WTOK_DESCRIPTION, _("No Grand Prix selected"));
widget_manager->set_wgt_text_size(WTOK_DESCRIPTION, WGT_FNT_SML);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_EMPTY1, 60, 7);
widget_manager->hide_wgt_rect(WTOK_EMPTY1);
widget_manager->hide_wgt_text(WTOK_EMPTY1);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUIT, 60, 7);
widget_manager->set_wgt_text(WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->set_wgt_text_size(WTOK_QUIT, WGT_FNT_SML);
widget_manager->activate_wgt(WTOK_QUIT);
widget_manager->layout(WGT_AREA_ALL);
//m_rect = widgetSet->rect(10, 10, user_config->m_width-20, 34, GUI_ALL, 10);*/
} // GrandPrixSelect
//-----------------------------------------------------------------------------
GrandPrixSelect::~GrandPrixSelect()
{
widgetSet -> delete_widget(m_menu_id) ;
glDeleteLists(m_rect, 1);
widget_manager->delete_wgts();
// widgetSet -> delete_widget(m_menu_id) ;
// glDeleteLists(m_rect, 1);
} // GrandPrixSelect
//-----------------------------------------------------------------------------
void GrandPrixSelect::update(float dt)
{
BaseGUI::update(dt);
const int CLICKED_TOKEN = widgetSet->get_token(widgetSet->click());
if(CLICKED_TOKEN == -1) return;
const int CLICKED_TOKEN = widget_manager->get_selected_wgt();
if(CLICKED_TOKEN < WTOK_FIRSTPRIX) return;
const CupData &cup = m_all_cups[CLICKED_TOKEN - WTOK_FIRSTPRIX];
widget_manager->set_wgt_text(WTOK_DESCRIPTION, cup.getDescription());
//FIXME: The following triggers a crash; it is left to be investigated later.
#if 0
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
@ -90,14 +139,14 @@ void GrandPrixSelect::update(float dt)
glBindTexture(GL_TEXTURE_2D, 0);
const GLfloat BACKGROUND_COLOUR[4] = { 0.3f, 0.3f, 0.3f, 0.5f };
glColor4fv(BACKGROUND_COLOUR);
glCallList(m_rect);
glPopMatrix();
font_gui->Print(cup.getDescription(), GUI_MED,
font_gui->Print(cup.getDescription(), WGT_FNT_MED,
Font::ALIGN_CENTER, -1, Font::ALIGN_BOTTOM, 10);
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
#endif
return;
}
@ -105,8 +154,8 @@ void GrandPrixSelect::update(float dt)
//-----------------------------------------------------------------------------
void GrandPrixSelect::select()
{
const int CLICKED_TOKEN = widgetSet->get_token(widgetSet->click());
if(CLICKED_TOKEN == -1)
const int CLICKED_TOKEN = widget_manager->get_selected_wgt();
if(CLICKED_TOKEN == WTOK_QUIT)
{
menu_manager->popMenu();
return;

View File

@ -28,7 +28,6 @@ class GrandPrixSelect: public BaseGUI
{
private:
std::vector<CupData> m_all_cups;
int m_rect;
public:
GrandPrixSelect();
~GrandPrixSelect();

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "help_menu.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "race_manager.hpp"
#include "menu_manager.hpp"
#include "user_config.hpp"
@ -27,7 +27,46 @@
#include "material.hpp"
#include "translation.hpp"
enum WidgetTokens {
enum WidgetTokens
{
/* For the first screen */
WTOK_MSG1,
WTOK_MSG2,
WTOK_MSG3,
WTOK_MSG4,
WTOK_MSG5,
WTOK_EMPTY,
//Change this so it's not a static amount of keys that is supported
WTOK_LEFT,
WTOK_RIGHT,
WTOK_ACCEL,
WTOK_BRAKE,
WTOK_WHEELIE,
WTOK_RESCUE,
WTOK_FIRE,
WTOK_JUMP,
WTOK_LEFTKEY,
WTOK_RIGHTKEY,
WTOK_ACCELKEY,
WTOK_BRAKEKEY,
WTOK_WHEELIEKEY,
WTOK_RESCUEKEY,
WTOK_FIREKEY,
WTOK_JUMPKEY,
/* For the second screen */
WTOK_MSG6,
WTOK_ITEMIMG1, WTOK_ITEMTXT1,
WTOK_ITEMIMG2, WTOK_ITEMTXT2,
WTOK_ITEMIMG3, WTOK_ITEMTXT3,
WTOK_ITEMIMG4, WTOK_ITEMTXT4,
WTOK_ITEMIMG5, WTOK_ITEMTXT5,
WTOK_ITEMIMG6, WTOK_ITEMTXT6,
WTOK_FIRST_PAGE,
WTOK_SECOND_PAGE,
WTOK_QUIT
@ -53,7 +92,7 @@ HelpMenu::HelpMenu()
//-----------------------------------------------------------------------------
HelpMenu::~HelpMenu()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts() ;
if (m_box != NULL && m_silver_coin != NULL && m_gold_coin != NULL
&& m_banana != NULL )
@ -124,18 +163,26 @@ void HelpMenu::update(float dt)
//-----------------------------------------------------------------------------
void HelpMenu::switch_to_first_screen()
{
m_menu_id = widgetSet->vstack(0);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
const WidgetFontSize TEXT_SIZE = WGT_FNT_SML;
//FIXME: if an hstack has no items, it segfaults
const int HS1 = widgetSet->hstack(m_menu_id);
widgetSet -> filler(HS1);
widgetSet -> label(HS1, _("Force your rivals bite *your* dust!"), GUI_SML);
widgetSet -> filler(HS1);
widget_manager->set_initial_rect_state( SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK );
widget_manager->set_initial_text_state( SHOW_TEXT, "", TEXT_SIZE, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
const int HS2 = widgetSet->harray(m_menu_id);
widgetSet->label(HS2, _("Avoid bananas"), GUI_SML);
widgetSet->label(HS2, _("Grab blue boxes and coins"), GUI_SML);
/*Help header*/
widget_manager->add_wgt(WTOK_MSG1, 50, 7);
widget_manager->set_wgt_text( WTOK_MSG1, _("Force your rivals bite *your* dust!") );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_MSG2, 60, 7);
widget_manager->set_wgt_text( WTOK_MSG2, _("Grab blue boxes and coins") );
widget_manager->add_wgt(WTOK_MSG3, 30, 7);
widget_manager->set_wgt_text( WTOK_MSG3, _("Avoid bananas") );
widget_manager->break_line();
/*Rotating 3D models*/
ssgEntity* hm = herring_manager->getHerringModel(HE_RED);
ssgDeRefDelete(m_box);
m_box = new ssgTransform;
@ -160,119 +207,241 @@ void HelpMenu::switch_to_first_screen()
m_banana->ref();
m_banana->addKid(hm);
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
/*Empty widget to cover the space for the 3D models*/
widget_manager->add_wgt(WTOK_EMPTY, 100, 15);
widget_manager->hide_wgt_rect(WTOK_EMPTY);
widget_manager->hide_wgt_text(WTOK_EMPTY);
widget_manager->break_line();
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
widgetSet -> filler(m_menu_id);
widgetSet->multi(m_menu_id,
widget_manager->add_wgt(WTOK_MSG4, 100, 10);
widget_manager->set_wgt_text( WTOK_MSG4,
//Next line starts at column 0 to avoid spaces in the GUI
_("At high speeds wheelies drive you faster, but you can't steer. If you\n\
get stuck or fall too far, use the rescue button to get back on track."),
GUI_SML);
get stuck or fall too far, use the rescue button to get back on track."));
widget_manager->break_line();
widgetSet -> filler(m_menu_id);
/*Current key bindings*/
widget_manager->add_wgt(WTOK_MSG5, 70, 7);
widget_manager->set_wgt_text( WTOK_MSG5,
_("Check the current key bindings for the first player"));
widget_manager->break_line();
widgetSet->label(m_menu_id,
_("Check the current keys bindings for the first player:"),
GUI_SML);
widget_manager->add_wgt(WTOK_LEFT, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_LEFT, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_LEFT, sKartAction2String[KC_LEFT]);
widget_manager->add_wgt(WTOK_LEFTKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_LEFTKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_LEFTKEY,
user_config->getInputAsString(0, (KartActions)KC_LEFT).c_str());
widget_manager->break_line();
const int HS3 = widgetSet->hstack(m_menu_id);
widgetSet -> filler(HS3);
const int CHANGE_ID = widgetSet->varray(HS3);
const int LABEL_ID = widgetSet->varray(HS3);
widgetSet -> filler(HS3);
widget_manager->add_wgt(WTOK_RIGHT, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_RIGHT, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_RIGHT, sKartAction2String[KC_RIGHT]);
widget_manager->add_wgt(WTOK_RIGHTKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_RIGHTKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_RIGHTKEY,
user_config->getInputAsString(0, (KartActions)KC_RIGHT).c_str());
widget_manager->break_line();
for(int i = KC_FIRST; i <= KC_LAST; i++)
{
// *sigh* widget set stores only pointer to strings, so
// to make sure that all key-strings are permanent, they
// are assigned to an array m_all_keys within this object.
m_all_keys[i]=user_config->getInputAsString(0, (KartActions)i);
widgetSet->label(LABEL_ID, sKartAction2String[i], GUI_SML, GUI_LFT);
widgetSet->label(CHANGE_ID, m_all_keys[i].c_str(), GUI_SML, GUI_RGT);
}
widgetSet->start(m_menu_id,_("Next screen"), GUI_SML, WTOK_SECOND_PAGE);
widgetSet->state(m_menu_id,_("Go back to the main menu"), GUI_SML, WTOK_QUIT);
widgetSet->layout(m_menu_id, 0, 0);
widget_manager->add_wgt(WTOK_ACCEL, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_ACCEL, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_ACCEL, sKartAction2String[KC_ACCEL]);
widget_manager->add_wgt(WTOK_ACCELKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_ACCELKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_ACCELKEY,
user_config->getInputAsString(0, (KartActions)KC_ACCEL).c_str());
widget_manager->break_line();
widget_manager->add_wgt(WTOK_BRAKE, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_BRAKE, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_BRAKE, sKartAction2String[KC_BRAKE]);
widget_manager->add_wgt(WTOK_BRAKEKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_BRAKEKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_BRAKEKEY,
user_config->getInputAsString(0, (KartActions)KC_BRAKE).c_str());
widget_manager->break_line();
widget_manager->add_wgt(WTOK_WHEELIE, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_WHEELIE, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_WHEELIE, sKartAction2String[KC_WHEELIE]);
widget_manager->add_wgt(WTOK_WHEELIEKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_WHEELIEKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_WHEELIEKEY,
user_config->getInputAsString(0, (KartActions)KC_WHEELIE).c_str());
widget_manager->break_line();
widget_manager->add_wgt(WTOK_RESCUE, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_RESCUE, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_RESCUE, sKartAction2String[KC_RESCUE]);
widget_manager->add_wgt(WTOK_RESCUEKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_RESCUEKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_RESCUEKEY,
user_config->getInputAsString(0, (KartActions)KC_RESCUE).c_str());
widget_manager->break_line();
widget_manager->add_wgt(WTOK_FIRE, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_FIRE, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_FIRE, sKartAction2String[KC_FIRE]);
widget_manager->add_wgt(WTOK_FIREKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_FIREKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_FIREKEY,
user_config->getInputAsString(0, (KartActions)KC_FIRE).c_str());
widget_manager->break_line();
widget_manager->add_wgt(WTOK_JUMP, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_JUMP, WGT_AREA_LFT );
widget_manager->set_wgt_text(WTOK_JUMP, sKartAction2String[KC_JUMP]);
widget_manager->add_wgt(WTOK_JUMPKEY, 20, 5);
widget_manager->set_wgt_round_corners(WTOK_JUMPKEY, WGT_AREA_RGT );
widget_manager->set_wgt_text(WTOK_JUMPKEY,
user_config->getInputAsString(0, (KartActions)KC_JUMP).c_str());
widget_manager->break_line();
/*Buttons at the bottom*/
widget_manager->add_wgt(WTOK_SECOND_PAGE, 20, 7);
widget_manager->set_wgt_text(WTOK_SECOND_PAGE, _("Next screen"));
widget_manager->activate_wgt(WTOK_SECOND_PAGE);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUIT, 40, 7);
widget_manager->set_wgt_text(WTOK_QUIT, _("Go back to the main menu"));
widget_manager->activate_wgt(WTOK_QUIT);
widget_manager->layout( WGT_AREA_TOP );
}
//-----------------------------------------------------------------------------
void HelpMenu::switch_to_second_screen()
{
/* Delete 3D models from the first screen */
ssgDeRefDelete(m_box); m_box = 0;
ssgDeRefDelete(m_silver_coin); m_silver_coin = 0;
ssgDeRefDelete(m_gold_coin); m_gold_coin = 0;
ssgDeRefDelete(m_banana); m_banana = 0;
m_menu_id = widgetSet->vstack(0);
/* Add the widgets */
const bool SHOW_RECT = true;
const WidgetFontSize TEXT_SIZE = WGT_FNT_SML;
widget_manager->set_initial_rect_state( SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK );
widget_manager->set_initial_text_state( false, "", TEXT_SIZE, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widgetSet->label(m_menu_id,
_("To help you win, there are certain collectables you can grab:"),
GUI_SML);
widget_manager->add_wgt(WTOK_MSG6, 100, 8);
widget_manager->set_wgt_text(WTOK_MSG6,
_("To help you win, there are certain collectables you can grab:"));
widget_manager->show_wgt_text( WTOK_MSG6 );
widget_manager->break_line();
const int HA = widgetSet->hstack(m_menu_id);
const int LABEL_ID = widgetSet->varray(HA);
const int IMAGE_ID = widgetSet->vstack(HA);
/* Collectable images and descriptions */
widget_manager->add_wgt(WTOK_ITEMIMG1, 10, 13);
widget_manager->set_wgt_texture(WTOK_ITEMIMG1,
collectable_manager->getIcon(COLLECT_MISSILE)->getState()->getTextureHandle());
widget_manager->set_wgt_color(WTOK_ITEMIMG1, WGT_WHITE);
widget_manager->show_wgt_texture(WTOK_ITEMIMG1);
widget_manager->set_wgt_round_corners(WTOK_ITEMIMG1, WGT_AREA_NONE);
const int ICON_SIZE = 64;
widget_manager->add_wgt(WTOK_ITEMTXT1, 90, 13);
widget_manager->set_wgt_text( WTOK_ITEMTXT1,
_("Missile - fast stopper in a straight line"));
widget_manager->show_wgt_text( WTOK_ITEMTXT1 );
widget_manager->break_line();
widgetSet->image(IMAGE_ID, collectable_manager->getIcon(COLLECT_MISSILE)->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE, GUI_NONE);
widgetSet->label(LABEL_ID, _("Missile - fast stopper in a straight line"), GUI_SML);
widget_manager->add_wgt(WTOK_ITEMIMG2, 10, 13);
widget_manager->set_wgt_texture(WTOK_ITEMIMG2,
collectable_manager->getIcon(COLLECT_HOMING_MISSILE)->getState()->getTextureHandle());
widget_manager->set_wgt_color(WTOK_ITEMIMG2, WGT_WHITE);
widget_manager->show_wgt_texture( WTOK_ITEMIMG2 );
widget_manager->set_wgt_round_corners(WTOK_ITEMIMG2, WGT_AREA_NONE);
widgetSet->image(IMAGE_ID, collectable_manager->getIcon(COLLECT_HOMING_MISSILE)->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE, GUI_NONE);
widgetSet->label(LABEL_ID, _("Homing missile - follows rivals, but is slower than the missile"), GUI_SML);
widget_manager->add_wgt(WTOK_ITEMTXT2, 90, 13);
widget_manager->set_wgt_text( WTOK_ITEMTXT2,
_("Homing missile - follows rivals, but is slower than the missile"));
widget_manager->show_wgt_text( WTOK_ITEMTXT2 );
widget_manager->break_line();
widgetSet->image(IMAGE_ID, collectable_manager->getIcon(COLLECT_SPARK)->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE, GUI_NONE);
widgetSet->label(LABEL_ID, _("Fuzzy blob/Spark - very slow, but bounces from walls"), GUI_SML);
widget_manager->add_wgt(WTOK_ITEMIMG3, 10, 13);
widget_manager->set_wgt_texture(WTOK_ITEMIMG3,
collectable_manager->getIcon(COLLECT_SPARK)->getState()->getTextureHandle());
widget_manager->set_wgt_color(WTOK_ITEMIMG3, WGT_WHITE);
widget_manager->show_wgt_texture( WTOK_ITEMIMG3 );
widget_manager->set_wgt_round_corners(WTOK_ITEMIMG3, WGT_AREA_NONE);
widgetSet->image(IMAGE_ID, collectable_manager->getIcon(COLLECT_ZIPPER)->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE, GUI_NONE);
widgetSet->label(LABEL_ID, _("Zipper - speed boost"), GUI_SML);
widget_manager->add_wgt(WTOK_ITEMTXT3, 90, 13);
widget_manager->set_wgt_text( WTOK_ITEMTXT3,
_("Fuzzy blob/Spark - very slow, but bounces from walls"));
widget_manager->show_wgt_text( WTOK_ITEMTXT3 );
widget_manager->break_line();
widgetSet->image(IMAGE_ID, collectable_manager->getIcon(COLLECT_PARACHUTE)->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE, GUI_NONE);
widgetSet->label(LABEL_ID, _("Parachute - slows down all karts in a better position!"), GUI_SML);
widget_manager->add_wgt(WTOK_ITEMIMG4, 10, 13);
widget_manager->set_wgt_texture(WTOK_ITEMIMG4,
collectable_manager->getIcon(COLLECT_ZIPPER)->getState()->getTextureHandle());
widget_manager->set_wgt_color(WTOK_ITEMIMG4, WGT_WHITE);
widget_manager->show_wgt_texture( WTOK_ITEMIMG4 );
widget_manager->set_wgt_round_corners(WTOK_ITEMIMG4, WGT_AREA_NONE);
widgetSet->image(IMAGE_ID, collectable_manager->getIcon(COLLECT_ANVIL)->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE, GUI_NONE);
widgetSet->label(LABEL_ID, _("Anvil - slows down greatly the kart in the first position"), GUI_SML);
widget_manager->add_wgt(WTOK_ITEMTXT4, 90, 13);
widget_manager->set_wgt_text( WTOK_ITEMTXT4,
_("Zipper - speed boost"));
widget_manager->show_wgt_text( WTOK_ITEMTXT4 );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_ITEMIMG5, 10, 13);
widget_manager->set_wgt_texture(WTOK_ITEMIMG5,
collectable_manager->getIcon(COLLECT_PARACHUTE)->getState()->getTextureHandle());
widget_manager->set_wgt_color(WTOK_ITEMIMG5, WGT_WHITE);
widget_manager->show_wgt_texture( WTOK_ITEMIMG5 );
widget_manager->set_wgt_round_corners(WTOK_ITEMIMG5, WGT_AREA_NONE);
widget_manager->add_wgt(WTOK_ITEMTXT5, 90, 13);
widget_manager->set_wgt_text( WTOK_ITEMTXT5,
_("Parachute - slows down all karts in a better position!"));
widget_manager->show_wgt_text( WTOK_ITEMTXT5 );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_ITEMIMG6, 10, 13);
widget_manager->set_wgt_texture(WTOK_ITEMIMG6,
collectable_manager->getIcon(COLLECT_ANVIL)->getState()->getTextureHandle());
widget_manager->set_wgt_color(WTOK_ITEMIMG6, WGT_WHITE);
widget_manager->show_wgt_texture( WTOK_ITEMIMG6 );
widget_manager->set_wgt_round_corners(WTOK_ITEMIMG6, WGT_AREA_NONE);
widget_manager->add_wgt(WTOK_ITEMTXT6, 90, 13);
widget_manager->set_wgt_text( WTOK_ITEMTXT6,
_("Anvil - slows down greatly the kart in the first position"));
widget_manager->show_wgt_text( WTOK_ITEMTXT6 );
widget_manager->break_line();
#ifdef USE_MAGNETS
widgetSet->image(IMAGE_ID, collectable_manager->getIcon(COLLECT_PARACHUTE)->getState()->getTextureHandle(),
ICON_SIZE, ICON_SIZE, GUI_NONE);
widgetSet->label(LABEL_ID, _("Missile - fast stopper in a straight line"), GUI_SML);
//Magnets are currently disabled.
#endif
widgetSet->start(m_menu_id,_("Previous screen"), GUI_SML, WTOK_FIRST_PAGE);
widgetSet->state(m_menu_id,_("Go back to the main menu"), GUI_SML, WTOK_QUIT);
widgetSet->layout(m_menu_id, 0, 0);
/*Buttons at the bottom*/
widget_manager->add_wgt(WTOK_FIRST_PAGE, 25, 7);
widget_manager->set_wgt_text(WTOK_FIRST_PAGE, _("Previous screen"));
widget_manager->show_wgt_text( WTOK_FIRST_PAGE );
widget_manager->activate_wgt(WTOK_FIRST_PAGE);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUIT, 40, 7);
widget_manager->set_wgt_text(WTOK_QUIT, _("Go back to the main menu"));
widget_manager->show_wgt_text( WTOK_QUIT );
widget_manager->activate_wgt(WTOK_QUIT);
widget_manager->layout( WGT_AREA_TOP );
}
//-----------------------------------------------------------------------------
void HelpMenu::select()
{
switch( widgetSet->get_token (widgetSet->click()))
switch ( widget_manager->get_selected_wgt() )
{
case WTOK_FIRST_PAGE:
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
switch_to_first_screen();
break;
case WTOK_SECOND_PAGE:
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
switch_to_second_screen();
break;

View File

@ -22,7 +22,7 @@
#include <string>
#include "base_gui.hpp"
#include "player.hpp"
//#include "player.hpp"
class ssgTransform;
class ssgContext;
@ -30,8 +30,6 @@ class ssgContext;
class HelpMenu: public BaseGUI
{
private:
std::string m_all_keys[KC_LAST+1];
ssgContext* m_context;
ssgTransform* m_box;
ssgTransform* m_banana;

View File

@ -20,7 +20,7 @@
#include <SDL/SDL.h>
#include "main_menu.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "race_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
@ -29,38 +29,65 @@ enum WidgetTokens {
WTOK_SINGLE,
WTOK_MULTI,
WTOK_OPTIONS,
WTOK_REPLAY,
WTOK_QUIT,
WTOK_EMPTY,
WTOK_HELP,
WTOK_CREDITS,
WTOK_CREDITS
};
MainMenu::MainMenu()
{
m_menu_id = widgetSet -> varray(0);
widgetSet -> space(m_menu_id);
widgetSet -> space(m_menu_id);
widgetSet -> start(m_menu_id, _("Single Player"), GUI_MED, WTOK_SINGLE);
widgetSet -> state(m_menu_id, _("Multiplayer"), GUI_MED, WTOK_MULTI);
widgetSet -> state(m_menu_id, _("Options"), GUI_MED, WTOK_OPTIONS);
widgetSet -> state(m_menu_id, _("Quit"), GUI_MED, WTOK_QUIT);
widgetSet -> space(m_menu_id);
widgetSet -> state(m_menu_id, _("Help"), GUI_SML, WTOK_HELP);
widgetSet -> state(m_menu_id, _("Credits"), GUI_SML, WTOK_CREDITS);
widgetSet -> space(m_menu_id);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_activation_state(true);
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widgetSet -> layout(m_menu_id, 0, 0);
widget_manager->add_wgt(WTOK_SINGLE, 25, 7);
widget_manager->set_wgt_text( WTOK_SINGLE, _("Single Player") );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_MULTI, 25, 7);
widget_manager->set_wgt_text( WTOK_MULTI, _("Multiplayer") );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_OPTIONS, 25, 7);
widget_manager->set_wgt_text( WTOK_OPTIONS, _("Options") );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUIT, 25, 7);
widget_manager->set_wgt_text( WTOK_QUIT, _("Quit") );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_EMPTY, 25, 7);
widget_manager->hide_wgt_text( WTOK_EMPTY );
widget_manager->hide_wgt_rect( WTOK_EMPTY );
widget_manager->deactivate_wgt( WTOK_EMPTY );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_HELP, 25, 7);
widget_manager->set_wgt_text( WTOK_HELP, _("Help") );
//FIXME: if text size is not set, we get a crash when resizing the rect to the text
widget_manager->set_wgt_text_size( WTOK_HELP, WGT_FNT_SML );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_CREDITS, 25, 7);
widget_manager->set_wgt_text( WTOK_CREDITS, _("Credits") );
widget_manager->set_wgt_text_size( WTOK_CREDITS, WGT_FNT_SML );
widget_manager->layout(WGT_AREA_ALL);
}
//-----------------------------------------------------------------------------
MainMenu::~MainMenu()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts() ;
}
//-----------------------------------------------------------------------------
void MainMenu::select()
{
#if 0
switch ( widgetSet -> get_token (widgetSet -> click()) )
{
case WTOK_SINGLE:
@ -89,6 +116,31 @@ void MainMenu::select()
menu_manager->pushMenu(MENUID_CREDITS);
break;
}
#endif
switch ( widget_manager->get_selected_wgt() )
{
case WTOK_SINGLE:
race_manager->setNumPlayers(1);
menu_manager->pushMenu(MENUID_GAMEMODE);
break;
case WTOK_MULTI:
menu_manager->pushMenu(MENUID_NUMPLAYERS);
break;
case WTOK_OPTIONS:
menu_manager->pushMenu(MENUID_OPTIONS);
break;
case WTOK_QUIT:
menu_manager->pushMenu(MENUID_EXITGAME);
break;
case WTOK_HELP:
menu_manager->pushMenu(MENUID_HELP);
break;
case WTOK_CREDITS:
menu_manager->pushMenu(MENUID_CREDITS);
break;
}
}
//-----------------------------------------------------------------------------

View File

@ -47,6 +47,7 @@
#include "grand_prix_select.hpp"
#include "sound_manager.hpp"
#include "sdldrv.hpp"
#include "widget_manager.hpp"
MenuManager* menu_manager= new MenuManager();
@ -187,6 +188,11 @@ void MenuManager::update()
default:
break;
} // switch
if( widget_manager->get_selected_wgt() != WidgetManager::WGT_NONE )
{
widget_manager->lighten_wgt_color(widget_manager->get_selected_wgt());
}
}
}

View File

@ -19,19 +19,79 @@
#include "num_laps.hpp"
#include "race_manager.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
enum WidgetTokens {
WTOK_TITLE,
WTOK_NUMLAPS,
WTOK_LESS,
WTOK_MORE,
WTOK_START,
WTOK_QUIT
};
NumLaps::NumLaps() : laps(3)
{
m_menu_id = widgetSet -> varray(0);
widget_manager->add_wgt(WTOK_TITLE, 50, 7);
widget_manager->show_wgt_rect(WTOK_TITLE);
widget_manager->show_wgt_text(WTOK_TITLE);
widget_manager->set_wgt_text(WTOK_TITLE, _("Choose number of laps"));
widget_manager->break_line();
widget_manager->add_wgt( WidgetManager::WGT_NONE, 100, 5);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_NUMLAPS, 20, 7);
widget_manager->show_wgt_rect(WTOK_NUMLAPS);
widget_manager->show_wgt_text(WTOK_NUMLAPS);
widget_manager->set_wgt_text(WTOK_NUMLAPS, _("Laps: 3"));
widget_manager->break_line();
widget_manager->add_wgt( WidgetManager::WGT_NONE, 100, 5);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_LESS, 20, 7);
widget_manager->show_wgt_rect(WTOK_LESS);
widget_manager->show_wgt_text(WTOK_LESS);
widget_manager->set_wgt_text(WTOK_LESS, _("Less"));
widget_manager->activate_wgt(WTOK_LESS);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_MORE, 20, 7);
widget_manager->show_wgt_rect(WTOK_MORE);
widget_manager->show_wgt_text(WTOK_MORE);
widget_manager->set_wgt_text(WTOK_MORE, _("More"));
widget_manager->activate_wgt(WTOK_MORE);
widget_manager->break_line();
widget_manager->add_wgt( WidgetManager::WGT_NONE, 100, 5);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_START, 30, 7);
widget_manager->show_wgt_rect(WTOK_START);
widget_manager->show_wgt_text(WTOK_START);
widget_manager->set_wgt_text(WTOK_START, _("Start race"));
widget_manager->activate_wgt(WTOK_START);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_QUIT, 50, 7);
widget_manager->show_wgt_rect(WTOK_QUIT);
widget_manager->show_wgt_text(WTOK_QUIT);
widget_manager->set_wgt_text(WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->activate_wgt(WTOK_QUIT);
/* m_menu_id = widgetSet -> varray(0);
widgetSet -> label(m_menu_id, _("Choose number of laps"), GUI_LRG, GUI_ALL, 0, 0 );
widgetSet -> space(m_menu_id);
lap_label_id = widgetSet -> label(m_menu_id, _("Laps: 3"));
widgetSet -> space(m_menu_id);
widgetSet -> state(m_menu_id, _("Less"), GUI_MED, 10);
@ -41,37 +101,40 @@ NumLaps::NumLaps() : laps(3)
widgetSet -> state(m_menu_id, _("Press <ESC> to go back"), GUI_SML, -1);
widgetSet -> space(m_menu_id);
widgetSet -> layout(m_menu_id, 0, 0);
widgetSet -> layout(m_menu_id, 0, 0);*/
widget_manager->layout(WGT_AREA_ALL);
}
// -----------------------------------------------------------------------------
NumLaps::~NumLaps()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
} // ~NumLaps
// -----------------------------------------------------------------------------
void NumLaps::select()
{
const int id = widgetSet->click();
const int n = widgetSet->get_token(id);
switch (n)
const int WGT = widget_manager->get_selected_wgt();
/* const int id = widgetSet->click();
const int n = widgetSet->get_token(id);*/
//TEMP
switch (WGT)
{
case 10:
case WTOK_LESS:
laps = std::max(1, laps-1);
snprintf(lap_label, MAX_MESSAGE_LENGTH, "Laps: %d", laps);
widgetSet->set_label(lap_label_id, lap_label);
break;
case 20:
snprintf(lap_label, MAX_MESSAGE_LENGTH, "Laps: %d", laps);
widget_manager->set_wgt_text(WTOK_NUMLAPS, lap_label);
break;
case WTOK_MORE:
laps = std::min(10, laps+1);
snprintf(lap_label, MAX_MESSAGE_LENGTH, "Laps: %d", laps);
widgetSet->set_label(lap_label_id, lap_label);
break;
case 30:
snprintf(lap_label, MAX_MESSAGE_LENGTH, "Laps: %d", laps);
widget_manager->set_wgt_text(WTOK_NUMLAPS, lap_label);
break;
case WTOK_START:
race_manager->setNumLaps(laps);
race_manager->start();
break;
case -1:
case WTOK_QUIT:
menu_manager->popMenu();
break;
}

View File

@ -19,7 +19,7 @@
#include "num_players.hpp"
#include "race_manager.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
@ -32,34 +32,58 @@ enum WidgetTokens {
NumPlayers::NumPlayers()
{
m_menu_id = widgetSet -> varray(0);
widgetSet -> space(m_menu_id);
widgetSet -> start(m_menu_id, _("Two Players"), GUI_MED, WTOK_PLAYER_2);
widgetSet -> state(m_menu_id, _("Three Players"), GUI_MED, WTOK_PLAYER_3);
widgetSet -> state(m_menu_id, _("Four Players"), GUI_MED, WTOK_PLAYER_4);
widgetSet -> space(m_menu_id);
widgetSet -> state(m_menu_id,_("Press <ESC> to go back"), GUI_SML, WTOK_BACK);
widgetSet -> space(m_menu_id);
widget_manager->add_wgt(WTOK_PLAYER_2, 35, 7);
widget_manager->show_wgt_rect( WTOK_PLAYER_2 );
widget_manager->set_wgt_text( WTOK_PLAYER_2, _("Two Players") );
widget_manager->set_wgt_text_size( WTOK_PLAYER_2, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_PLAYER_2 );
widget_manager->activate_wgt( WTOK_PLAYER_2 );
widget_manager->break_line();
widgetSet -> layout(m_menu_id, 0, 0);
widget_manager->add_wgt(WTOK_PLAYER_3, 35, 7);
widget_manager->show_wgt_rect( WTOK_PLAYER_3 );
widget_manager->set_wgt_text( WTOK_PLAYER_3, _("Three Players") );
widget_manager->set_wgt_text_size( WTOK_PLAYER_3, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_PLAYER_3 );
widget_manager->activate_wgt( WTOK_PLAYER_3);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_PLAYER_4, 35, 7);
widget_manager->show_wgt_rect( WTOK_PLAYER_4 );
widget_manager->set_wgt_text( WTOK_PLAYER_4, _("Four Players") );
widget_manager->set_wgt_text_size( WTOK_PLAYER_4, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_PLAYER_4 );
widget_manager->activate_wgt( WTOK_PLAYER_4 );
widget_manager->break_line();
widget_manager->add_wgt(WidgetManager::WGT_NONE, 35, 7);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_BACK, 35, 7);
widget_manager->show_wgt_rect( WTOK_BACK );
widget_manager->set_wgt_text( WTOK_BACK, _("Press <ESC> to go back") );
widget_manager->set_wgt_text_size( WTOK_BACK, WGT_FNT_SML );
widget_manager->show_wgt_text( WTOK_BACK );
widget_manager->activate_wgt( WTOK_BACK );
widget_manager->layout(WGT_AREA_ALL);
}
// -----------------------------------------------------------------------------
NumPlayers::~NumPlayers()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts() ;
}
// -----------------------------------------------------------------------------
void NumPlayers::select()
{
const int CLICKED_ID = widgetSet -> get_token (widgetSet -> click());
switch (CLICKED_ID)
switch ( widget_manager->get_selected_wgt() )
{
case WTOK_PLAYER_2:
case WTOK_PLAYER_3:
case WTOK_PLAYER_4:
race_manager->setNumPlayers(CLICKED_ID);
race_manager->setNumPlayers(widget_manager->get_selected_wgt());
menu_manager->pushMenu(MENUID_GAMEMODE);
break;
case WTOK_BACK:

View File

@ -18,11 +18,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "options.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
enum WidgetTokens {
WTOK_TITLE,
WTOK_CONTROLS,
WTOK_DISPLAY,
WTOK_SOUND,
@ -31,7 +32,7 @@ enum WidgetTokens {
Options::Options()
{
m_menu_id = widgetSet -> varray(0);
/* m_menu_id = widgetSet -> varray(0);
widgetSet -> space(m_menu_id);
widgetSet -> space(m_menu_id);
@ -51,26 +52,69 @@ Options::Options()
widgetSet -> space(m_menu_id);
widgetSet -> state(m_menu_id, _("Press <ESC> to go back"), GUI_SML, WTOK_BACK);
widgetSet -> layout(m_menu_id, 0, 0);
widgetSet -> layout(m_menu_id, 0, 0);*/
widget_manager->add_wgt(WTOK_TITLE, 35, 7);
widget_manager->show_wgt_rect( WTOK_TITLE );
widget_manager->set_wgt_text( WTOK_TITLE, _("Options") );
widget_manager->set_wgt_text_size( WTOK_TITLE, WGT_FNT_LRG );
widget_manager->show_wgt_text( WTOK_TITLE );
widget_manager->break_line();
widget_manager->add_wgt(WTOK_CONTROLS, 35, 7);
widget_manager->show_wgt_rect( WTOK_CONTROLS );
widget_manager->set_wgt_text( WTOK_CONTROLS, _("Player Config") );
widget_manager->set_wgt_text_size( WTOK_CONTROLS, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_CONTROLS );
widget_manager->activate_wgt( WTOK_CONTROLS);
widget_manager->break_line();
// Don't display the fullscreen menu when called from within the race.
// The fullscreen mode will reload all textures, reload the models,
// ... basically creating a big mess!! (and all of this only thanks
// to windows, who discards all textures, ...)
if(!menu_manager->isSomewhereOnStack(MENUID_RACE))
{
widget_manager->add_wgt(WTOK_DISPLAY, 35, 7);
widget_manager->show_wgt_rect( WTOK_DISPLAY );
widget_manager->set_wgt_text( WTOK_DISPLAY, _("Display") );
widget_manager->set_wgt_text_size( WTOK_DISPLAY, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_DISPLAY );
widget_manager->activate_wgt( WTOK_DISPLAY );
widget_manager->break_line();
}
widget_manager->add_wgt(WTOK_SOUND, 35, 7);
widget_manager->show_wgt_rect( WTOK_SOUND );
widget_manager->set_wgt_text( WTOK_SOUND, _("Sound") );
widget_manager->set_wgt_text_size( WTOK_SOUND, WGT_FNT_MED );
widget_manager->show_wgt_text( WTOK_SOUND );
widget_manager->activate_wgt( WTOK_SOUND );
widget_manager->break_line();
widget_manager->add_wgt(WidgetManager::WGT_NONE, 35, 7);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_BACK, 35, 7);
widget_manager->show_wgt_rect( WTOK_BACK );
widget_manager->set_wgt_text( WTOK_BACK, _("Press <ESC> to go back") );
widget_manager->set_wgt_text_size( WTOK_BACK, WGT_FNT_SML );
widget_manager->show_wgt_text( WTOK_BACK );
widget_manager->activate_wgt( WTOK_BACK );
widget_manager->layout(WGT_AREA_ALL);
}
// -----------------------------------------------------------------------------
Options::~Options()
{
widgetSet -> delete_widget(m_menu_id) ;
}
// -----------------------------------------------------------------------------
void Options::update(float dt)
{
widgetSet -> timer(m_menu_id, dt) ;
widgetSet -> paint(m_menu_id) ;
widget_manager->delete_wgts() ;
}
// -----------------------------------------------------------------------------
void Options::select()
{
switch ( widgetSet -> get_token (widgetSet -> click()) )
switch ( widget_manager->get_selected_wgt() )
// switch ( widgetSet -> get_token (widgetSet -> click()) )
{
case WTOK_CONTROLS:
menu_manager->pushMenu(MENUID_CONFIG_CONTROLS);

View File

@ -28,7 +28,6 @@ public:
Options();
~Options();
void update(float dt);
void select();
};

View File

@ -20,7 +20,7 @@
#include <SDL/SDL.h>
#include "player_controls.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "user_config.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
@ -28,43 +28,94 @@
#include <string>
enum WidgetTokens
{
WTOK_TITLE,
WTOK_PLYR_NAME0,
WTOK_PLYR_NAME1,
WTOK_LEFT,
WTOK_RIGHT,
WTOK_ACCEL,
WTOK_BRAKE,
WTOK_WHEELIE,
WTOK_JUMP,
WTOK_RESCUE,
WTOK_FIRE,
WTOK_LOOK_BACK,
WTOK_KEY0,
WTOK_KEY1,
WTOK_KEY2,
WTOK_KEY3,
WTOK_KEY4,
WTOK_KEY5,
WTOK_KEY6,
WTOK_KEY7,
WTOK_KEY8,
WTOK_QUIT
};
const char *sKartAction2String[KC_LAST+1] = {_("Left"), _("Right"), _("Accelerate"),
_("Brake"), _("Wheelie"), _("Jump"),
_("Rescue"), _("Fire"), _("Look back") };
PlayerControls::PlayerControls(int whichPlayer): m_player_index(whichPlayer),
m_grab_input(false)
PlayerControls::PlayerControls(int whichPlayer):
m_grab_id(WidgetManager::WGT_NONE), m_player_index(whichPlayer),
m_grab_input(false)
{
// We need the unicode character here, so enable the translation
SDL_EnableUNICODE(1);
m_menu_id = widgetSet -> vstack(0);
sprintf(m_heading, _("Choose your controls, %s"),
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widget_manager->add_wgt( WTOK_TITLE, 60, 7);
sprintf(m_heading, _("Choose your controls, %s"),
user_config->m_player[m_player_index].getName().c_str());
widgetSet -> label(m_menu_id, m_heading, GUI_LRG, GUI_ALL, 0, 0);
widget_manager->set_wgt_text( WTOK_TITLE, m_heading);
widget_manager->break_line();
const int HA = widgetSet->harray(m_menu_id);
const int CHANGE_ID = widgetSet->varray(HA);
const int LABEL_ID = widgetSet->varray(HA);
widget_manager->add_wgt( WTOK_PLYR_NAME0, 30, 7);
widget_manager->set_wgt_text( WTOK_PLYR_NAME0, _("Player name"));
widgetSet->label(LABEL_ID, _("Player name"));
widget_manager->add_wgt( WTOK_PLYR_NAME1, 30, 7);
m_name = user_config->m_player[m_player_index].getName();
m_name_id = widgetSet->state(CHANGE_ID, m_name.c_str(), GUI_MED, -2);
widget_manager->set_wgt_text( WTOK_PLYR_NAME1, m_name);
widget_manager->activate_wgt( WTOK_PLYR_NAME1);
widget_manager->break_line();
KartActions control;
for(int i=0; i<=KC_LAST; i++)
{
addKeyLabel(CHANGE_ID, (KartActions)i, i==0 );
widgetSet->label(LABEL_ID, sKartAction2String[i]);
widget_manager->add_wgt( WTOK_KEY0 + i, 30, 7);
widget_manager->set_wgt_text( WTOK_KEY0 + i, sKartAction2String[i]);
control = (KartActions)i;
m_key_names[control] = user_config->getInputAsString(m_player_index, control);
widget_manager->add_wgt( WTOK_LEFT + i, 30, 7);
widget_manager->set_wgt_text( WTOK_LEFT + i, m_key_names[control].c_str());
widget_manager->activate_wgt( WTOK_LEFT + i);
widget_manager->break_line();
}
widgetSet->state(m_menu_id,_("Press <ESC> to go back"), GUI_SML, -1);
widgetSet -> layout(m_menu_id, 0, 0);
widget_manager->add_wgt( WTOK_QUIT, 60, 7);
widget_manager->set_wgt_text( WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->set_wgt_text_size( WTOK_QUIT, WGT_FNT_SML);
widget_manager->activate_wgt( WTOK_QUIT);
widget_manager->layout(WGT_AREA_ALL);
} // PlayerControls
//-----------------------------------------------------------------------------
PlayerControls::~PlayerControls()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
// The unicode translation is not generally needed, so disable it again.
SDL_EnableUNICODE(0);
} // ~PlayerControls
@ -74,15 +125,16 @@ void PlayerControls::select()
{
if (m_grab_input) return;
m_grab_id = widgetSet -> click();
if(m_grab_id == m_name_id)
m_grab_id = widget_manager->get_selected_wgt();
if(m_grab_id == WTOK_PLYR_NAME1)
{
m_grab_input = true;
return;
}
const int MENU_CHOICE = widgetSet -> get_token (m_grab_id);
if(MENU_CHOICE == -1)
const int MENU_CHOICE = widget_manager->get_selected_wgt() - WTOK_LEFT;
if(MENU_CHOICE == WTOK_QUIT)
{
menu_manager->popMenu();
return;
@ -91,7 +143,7 @@ void PlayerControls::select()
m_grab_input = true;
drv_hidePointer();
widgetSet->set_label(m_grab_id, _("Press key"));
widget_manager->set_wgt_text(m_grab_id, _("Press key"));
} // select
//-----------------------------------------------------------------------------
@ -101,7 +153,7 @@ void PlayerControls::input(InputType type, int id0, int id1, int id2, int value)
{
// Handle input of user name
// -------------------------
if(m_grab_id == m_name_id)
if(m_grab_id == WTOK_PLYR_NAME1)
{
if(type==IT_KEYBOARD)
{
@ -113,13 +165,14 @@ void PlayerControls::input(InputType type, int id0, int id1, int id2, int value)
{
if(m_name.size()>=1) m_name.erase(m_name.size()-1,1);
}
// All other control characters are ignored and will end
// All other control characters are ignored and will end
// entering the name
else if(id0<32 || id0>255)
{
m_grab_input = false;
m_grab_id = WidgetManager::WGT_NONE;
user_config->m_player[m_player_index].setName(m_name);
BaseGUI::input(type, id0, id1, id2, value);
// BaseGUI::input(type, id0, id1, id2, value);
return;
}
else // Add the character to the name
@ -129,8 +182,8 @@ void PlayerControls::input(InputType type, int id0, int id1, int id2, int value)
// take care of upper/lower case etc.
m_name = m_name + (char)id1;
}
widgetSet->set_label(m_name_id, m_name.c_str());
}
widget_manager->set_wgt_text(WTOK_PLYR_NAME1, m_name.c_str());
}
else
{
// Ignore all other events, e.g. when pressing the mouse
@ -147,17 +200,17 @@ void PlayerControls::input(InputType type, int id0, int id1, int id2, int value)
// Do not accept pressing ESC as input.
if (type != IT_KEYBOARD || id0 != SDLK_ESCAPE)
{
// Since unicode translation is enabled, the value of id1 will
// Since unicode translation is enabled, the value of id1 will
// be the unicode value. Since unicode is usually not enabled
// in the race we have to set this value to zero (unicode
// in the race we have to set this value to zero (unicode
// translation is only enabled here to help entering the name),
// otherwise the keys will not be recognised in the race!!
if(type==IT_KEYBOARD) id1=0;
user_config->m_player[m_player_index].setInput(m_edit_action, type,
if(type==IT_KEYBOARD) id1=0;
user_config->m_player[m_player_index].setInput(m_edit_action, type,
id0, id1, id2);
}
changeKeyLabel(m_grab_id, m_edit_action);
widget_manager->set_wgt_text(m_grab_id, m_key_names[m_edit_action].c_str());
}
}
else
@ -165,7 +218,7 @@ void PlayerControls::input(InputType type, int id0, int id1, int id2, int value)
}
//-----------------------------------------------------------------------------
void PlayerControls::addKeyLabel(int CHANGE_ID, KartActions control, bool start)
/*void PlayerControls::addKeyLabel(int CHANGE_ID, KartActions control, bool start)
{
setKeyInfoString(control);
@ -187,5 +240,5 @@ void PlayerControls::changeKeyLabel(int m_grab_id, KartActions control)
//-----------------------------------------------------------------------------
void PlayerControls::setKeyInfoString(KartActions control)
{
m_key_names[control] = user_config->getInputAsString(m_player_index, control);
} // setKeyInfoString
*/

View File

@ -33,14 +33,10 @@ public:
void select();
void input(InputType type, int id0, int id1, int id2, int value);
void addKeyLabel(int change_id, KartActions control, bool start);
void changeKeyLabel(int grab_id, KartActions control);
void setKeyInfoString(KartActions control);
private:
int m_grab_id;
int m_player_index;
int m_name_id;
bool m_grab_input;
KartActions m_edit_action;
// Stores the heading - making this an attribute here avoids

View File

@ -22,7 +22,6 @@
#include "user_config.hpp"
#include "race_gui.hpp"
#include "history.hpp"
#include "widget_set.hpp"
#include "track.hpp"
#include "material_manager.hpp"
#include "menu_manager.hpp"
@ -817,8 +816,7 @@ void RaceGUI::cleanupMessages()
void RaceGUI::drawAllMessages(Kart* player_kart, int offset_x, int offset_y,
float ratio_x, float ratio_y )
{
int x, y;
x = SCREEN_CENTERED_TEXT;
int y;
// First line of text somewhat under the top of the screen. For now
// start just under the timer display
y = (int)(ratio_y*(user_config->m_height -164)+offset_y);

View File

@ -22,7 +22,7 @@
#include "race_menu.hpp"
#include "user_config.hpp"
#include "world.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "menu_manager.hpp"
#include "race_manager.hpp"
@ -30,33 +30,54 @@
#include "translation.hpp"
enum WidgetTokens {
WTOK_PAUSE,
WTOK_RETURN_RACE,
WTOK_OPTIONS,
WTOK_HELP,
WTOK_RESTART_RACE,
WTOK_SETUP_NEW_RACE,
WTOK_EXIT_RACE,
WTOK_QUIT,
};
RaceMenu::RaceMenu()
{
m_menu_id = widgetSet -> vstack(0);
widgetSet -> label(m_menu_id, _("Paused"), GUI_LRG, GUI_ALL, 0, 0);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
const int VA = widgetSet -> varray(m_menu_id);
widgetSet -> start(VA, _("Return To Race"), GUI_MED, WTOK_RETURN_RACE);
widgetSet -> state(VA, _("Options"), GUI_MED, WTOK_OPTIONS);
widgetSet -> state(VA, _("Help"), GUI_MED, WTOK_HELP);
widgetSet -> state(VA, _("Restart Race"), GUI_MED, WTOK_RESTART_RACE);
widget_manager->add_wgt(WTOK_PAUSE, 30, 7);
widget_manager->set_wgt_text(WTOK_PAUSE, _("Paused"));
widget_manager->break_line();
widget_manager->set_initial_activation_state(true);
widget_manager->add_wgt(WTOK_RETURN_RACE, 30, 7);
widget_manager->set_wgt_text(WTOK_RETURN_RACE, _("Return To Race"));
widget_manager->break_line();
widget_manager->add_wgt(WTOK_OPTIONS, 30, 7);
widget_manager->set_wgt_text(WTOK_OPTIONS, _("Options"));
widget_manager->break_line();
widget_manager->add_wgt(WTOK_HELP, 30, 7);
widget_manager->set_wgt_text(WTOK_HELP, _("Help"));
widget_manager->break_line();
widget_manager->add_wgt(WTOK_RESTART_RACE, 30, 7);
widget_manager->set_wgt_text(WTOK_RESTART_RACE, _("Restart Race"));
widget_manager->break_line();
if(world->m_race_setup.m_mode==RaceSetup::RM_QUICK_RACE)
{
widgetSet->state(VA, _("Setup New Race"),GUI_MED, WTOK_SETUP_NEW_RACE);
widget_manager->add_wgt(WTOK_SETUP_NEW_RACE, 30, 7);
widget_manager->set_wgt_text(WTOK_SETUP_NEW_RACE, _("Setup New Race"));
widget_manager->break_line();
}
widgetSet -> state(VA, _("Exit Race"), GUI_MED, WTOK_EXIT_RACE);
widget_manager->add_wgt(WTOK_QUIT, 30, 7);
widget_manager->set_wgt_text(WTOK_QUIT, _("Exit Race"));
widgetSet -> layout(m_menu_id, 0, 0);
widget_manager->layout(WGT_AREA_ALL);
if(user_config->m_fullscreen) SDL_ShowCursor(SDL_ENABLE);
}
@ -64,20 +85,14 @@ RaceMenu::RaceMenu()
//-----------------------------------------------------------------------------
RaceMenu::~RaceMenu()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
}
//-----------------------------------------------------------------------------
void RaceMenu::update(float dt)
{
widgetSet -> timer(m_menu_id, dt) ;
widgetSet -> paint(m_menu_id) ;
}
//-----------------------------------------------------------------------------
void RaceMenu::select()
{
int clicked_token = widgetSet->get_token(widgetSet->click());
int clicked_token = widget_manager->get_selected_wgt();
switch (clicked_token)
{
@ -108,7 +123,7 @@ void RaceMenu::select()
menu_manager->pushMenu(MENUID_HELP);
break;
case WTOK_EXIT_RACE:
case WTOK_QUIT:
world->unpause();
race_manager->exit_race();
break;

View File

@ -28,7 +28,6 @@ public:
RaceMenu();
~RaceMenu();
void update(float dt);
void select();
void inputKeyboard(int key, int pressed);
};

View File

@ -21,7 +21,7 @@
#include <SDL/SDL.h>
#include "race_results_gui.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "kart_properties.hpp"
#include "world.hpp"
#include "menu_manager.hpp"
@ -29,24 +29,41 @@
#include "translation.hpp"
enum WidgetTokens {
WTOK_TITLE,
WTOK_EMPTY,
WTOK_HIGHSCORES,
WTOK_RESULTS,
WTOK_CONTINUE,
WTOK_RESTART_RACE,
WTOK_SETUP_NEW_RACE,
WTOK_FIRST_RESULT
};
RaceResultsGUI::RaceResultsGUI()
{
m_menu_id = widgetSet -> vstack(0);
widgetSet -> label(m_menu_id, _("Result"), GUI_LRG, GUI_ALL, 0, 0);
const unsigned int MAX_STR_LEN = 60;
widgetSet -> space(m_menu_id);
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widget_manager->add_wgt(WTOK_TITLE, 60, 7);
widget_manager->set_wgt_text(WTOK_TITLE, _("Result"));
widget_manager->break_line();
const int HA = widgetSet->harray(m_menu_id);
const int HIGHSCORE_TABLE = widgetSet->varray(HA);
const int RESULT_TABLE = widgetSet->varray(HA);
widgetSet -> label(RESULT_TABLE, _("Race results"),GUI_LRG,GUI_ALL,0,0);
widgetSet -> label(HIGHSCORE_TABLE, _("Highscores"), GUI_LRG,GUI_ALL,0,0);
widget_manager->add_wgt(WTOK_EMPTY, 60, 5);
widget_manager->hide_wgt_rect(WTOK_EMPTY);
widget_manager->hide_wgt_text(WTOK_EMPTY);
widget_manager->break_line();
widget_manager->add_wgt(WTOK_RESULTS, 40, 7);
widget_manager->set_wgt_text(WTOK_RESULTS, _("Race results"));
widget_manager->add_wgt(WTOK_HIGHSCORES, 40, 7);
widget_manager->set_wgt_text(WTOK_HIGHSCORES, _("Highscores"));
widget_manager->break_line();
const unsigned int MAX_STR_LEN = 60;
const unsigned int NUM_KARTS = world->getNumKarts();
int* order = new int [NUM_KARTS];
m_score = new char[NUM_KARTS * MAX_STR_LEN];
unsigned int max_name_len = 1;
@ -75,20 +92,22 @@ RaceResultsGUI::RaceResultsGUI()
TimeToString(T, sTime);
}
//This shows position + driver name + time + points earned + total points
if(world->m_race_setup.m_mode==RaceSetup::RM_GRAND_PRIX)
{
sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %s +%d %d",
KART->getPosition(), KART_NAME.c_str(), sTime,
race_manager->getPositionScore(i+1),
race_manager->getKartScore(order[i]));
}
else
if(world->m_race_setup.m_mode==RaceSetup::RM_GRAND_PRIX)
{
sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %s",
KART->getPosition(), KART_NAME.c_str(), sTime);
}
widgetSet -> label(RESULT_TABLE, (char*)(m_score + MAX_STR_LEN * i),
GUI_MED, GUI_ALL);
sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %s +%d %d",
KART->getPosition(), KART_NAME.c_str(), sTime,
race_manager->getPositionScore(i+1),
race_manager->getKartScore(order[i]));
}
else
{
sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %s",
KART->getPosition(), KART_NAME.c_str(), sTime);
}
widget_manager->add_wgt(WTOK_FIRST_RESULT + i, 80, 7);
widget_manager->set_wgt_text(WTOK_FIRST_RESULT + i,
(char*)(m_score + MAX_STR_LEN * i));
}
delete[] order;
@ -106,14 +125,15 @@ RaceResultsGUI::RaceResultsGUI()
const int TENTHS = (int) floor ( 10.0f * (T - (float)(SECS + 60*MINS)));
sprintf((char*)(m_highscores + MAX_STR_LEN * i),
"%s: %3d:%02d.%01d", name.c_str(), MINS, SECS, TENTHS);
widgetSet->label(HIGHSCORE_TABLE, (char*)(m_highscores+MAX_STR_LEN*i),
GUI_MED, GUI_ALL);
/* widgetSet->label(HIGHSCORE_TABLE, (char*)(m_highscores+MAX_STR_LEN*i),
GUI_MED, GUI_ALL);*/
}
widgetSet -> space(m_menu_id);
// widgetSet -> space(m_menu_id);
// const int VA = widgetSet -> varray(m_menu_id);
#if 0
static int dev_msg_counter = 0;
if(dev_msg_counter == 2)
{
@ -122,28 +142,31 @@ if you want to help contact us!"), GUI_SML, GUI_ALL, 0, 0);
dev_msg_counter = 0;
}
++dev_msg_counter;
#endif
if(world->m_race_setup.m_mode==RaceSetup::RM_GRAND_PRIX)
{
widgetSet -> start(m_menu_id, _("Continue Grand Prix"), GUI_MED, WTOK_CONTINUE);
// widgetSet -> start(m_menu_id, _("Continue Grand Prix"), GUI_MED, WTOK_CONTINUE);
}
else
{
widgetSet -> start(m_menu_id, _("Back to the main menu"), GUI_MED, WTOK_CONTINUE);
// widgetSet -> start(m_menu_id, _("Back to the main menu"), GUI_MED, WTOK_CONTINUE);
}
widgetSet -> start(m_menu_id, _("Race in this track again"), GUI_MED, WTOK_RESTART_RACE);
// widgetSet -> start(m_menu_id, _("Race in this track again"), GUI_MED, WTOK_RESTART_RACE);
if(world->m_race_setup.m_mode==RaceSetup::RM_QUICK_RACE)
{
widgetSet -> start(m_menu_id, _("Setup New Race"), GUI_MED, WTOK_SETUP_NEW_RACE);
// widgetSet -> start(m_menu_id, _("Setup New Race"), GUI_MED, WTOK_SETUP_NEW_RACE);
}
widgetSet -> layout(m_menu_id, 0, 0);
// widgetSet -> layout(m_menu_id, 0, 0);
widget_manager->layout(WGT_AREA_ALL);
} // RaceResultsGUI
//-----------------------------------------------------------------------------
RaceResultsGUI::~RaceResultsGUI()
{
widgetSet -> delete_widget(m_menu_id) ;
widget_manager->delete_wgts();
//widgetSet -> delete_widget(m_menu_id) ;
delete[] m_score;
delete[] m_highscores;
} // ~RaceResultsGUI
@ -151,7 +174,7 @@ RaceResultsGUI::~RaceResultsGUI()
//-----------------------------------------------------------------------------
void RaceResultsGUI::select()
{
switch( widgetSet->get_token( widgetSet->click() ) )
switch( widget_manager->get_selected_wgt() )
{
case WTOK_CONTINUE:
world->unpause();

View File

@ -1,124 +0,0 @@
// $Id: credits_menu.cpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <SDL/SDL.h>
#include "scrolled_text.hpp"
#include "widget_set.hpp"
#include "menu_manager.hpp"
#include "user_config.hpp"
#include "translation.hpp"
#include "font.hpp"
ScrolledText::ScrolledText()
{
float r = user_config->m_width/800.0f;
m_x_left = (int)(30.0*r); m_x_right = user_config->m_width -m_x_left;
r = user_config->m_height/600.0f;
m_y_bottom = (int)(50.0*r); m_y_top = user_config->m_height-(int)(50.0f*r);
m_y_speed = 50.0f;
m_font_size = 24;
m_y_pos = m_y_bottom-m_font_size;
m_rect = 0;
m_menu_id = widgetSet -> varray(0);
widgetSet->layout(m_menu_id, 0, 0);
} // ScrolledText
//-----------------------------------------------------------------------------
ScrolledText::~ScrolledText()
{
glDeleteLists(m_rect, 1);
} // ~ScrolledText
//-----------------------------------------------------------------------------
void ScrolledText::setText(StringList const &sl_)
{
m_string_list=sl_;
if(m_rect) glDeleteLists(m_rect, 1);
m_rect = widgetSet->rect(m_x_left, m_y_bottom, m_x_right-m_x_left, m_y_top-m_y_bottom,
GUI_ALL, 10);
} // setText
//-----------------------------------------------------------------------------
void ScrolledText::update(float dt)
{
BaseGUI::update(dt);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, user_config->m_width, 0.0, user_config->m_height, -1.0, +1.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_BLEND);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, 0);
const GLfloat backgroundColour[4] = { 0.3f, 0.3f, 0.3f, 0.5f };
glColor4fv(backgroundColour);
glCallList(m_rect);
glPopMatrix();
font_gui->Print(_("Press <ESC> to go back"), 24,
Font::ALIGN_CENTER, -1, Font::ALIGN_BOTTOM, 20);
glViewport(m_x_left, m_y_bottom, m_x_right-m_x_left, m_y_top-m_y_bottom);
glScalef(1.0f, user_config->m_width/(m_y_top-m_y_bottom), 1.0f);
for(unsigned int i=0; i<m_string_list.size(); i++)
{
if((m_y_pos-i*m_font_size < m_y_top + m_y_bottom ) && m_y_pos-i*m_font_size > -m_font_size)
font_gui->Print(m_string_list[i].c_str(), 24,
m_x_left,(int)m_y_pos-i*m_font_size);
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,user_config->m_width, user_config->m_height);
m_y_pos=m_y_pos+dt*m_y_speed;
if(m_y_speed>0 && m_y_pos>m_string_list.size()*m_font_size+m_y_top-m_y_bottom) m_y_pos=-m_font_size;
if(m_y_speed<0 && m_y_pos<0) m_y_pos=m_string_list.size()*m_font_size+m_y_top-m_y_bottom;
} // update
//-----------------------------------------------------------------------------
void ScrolledText::inputKeyboard(int key, int pressed)
{
switch(key)
{
case SDLK_PLUS :
case SDLK_UP : m_y_speed -= 10.0f; break;
case SDLK_PAGEUP : m_y_speed -= 50.0f; break;
case SDLK_PAGEDOWN : m_y_speed += 50.0f; break;
case SDLK_MINUS :
case SDLK_DOWN : m_y_speed += 10.0f; break;
case SDLK_ESCAPE : menu_manager->popMenu();
default : break;
} // switch
if (m_y_speed > 500.0f) m_y_speed = 500.0f;
if (m_y_speed < -500.0f) m_y_speed = -500.0f;
} // inputKeyboard
//-----------------------------------------------------------------------------
void ScrolledText::select()
{
// must be esc, nothing else is available. So just pop this menu
menu_manager->popMenu();
} // select
/* EOF */

View File

@ -1,51 +0,0 @@
// $Id: credits_menu.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_SCROLL_TEXT_HPP
#define HEADER_SCROLL_TEXT_HPP
#include <string>
#include <vector>
#include "base_gui.hpp"
#include "player.hpp"
class ScrolledText: public BaseGUI
{
protected:
typedef std::vector<std::string> StringList;
private:
int m_x_left, m_x_right, m_y_bottom, m_y_top;
float m_y_pos, m_y_speed;
int m_font_size;
StringList m_string_list;
int m_rect;
public:
ScrolledText();
~ScrolledText();
void setText (StringList const &sl_);
void select ();
void update (float dt);
void inputKeyboard (int key, int pressed);
};
#endif

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "track_sel.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "race_manager.hpp"
#include "track_manager.hpp"
#include "track.hpp"
@ -30,44 +30,78 @@
#include "translation.hpp"
enum WidgetTokens {
WTOK_RETURN,
WTOK_OPTIONS,
WTOK_RESTART,
WTOK_EXIT,
WTOK_TITLE,
WTOK_TRACK0,
WTOK_TRACK1,
WTOK_TRACK2,
WTOK_TRACK3,
WTOK_TRACK4,
WTOK_TRACK5,
WTOK_TRACK6,
WTOK_TRACK7,
WTOK_TRACK8,
WTOK_TRACK9,
WTOK_TRACK10,
WTOK_TRACK11,
WTOK_TRACK12,
WTOK_TRACK13,
WTOK_IMG0,
WTOK_IMG1,
WTOK_AUTHOR
};
TrackSel::TrackSel()
{
m_menu_id = widgetSet -> vstack(0);
widget_manager->add_wgt( WTOK_TITLE, 40, 7);
widget_manager->show_wgt_rect( WTOK_TITLE );
widget_manager->set_wgt_text( WTOK_TITLE, _("Choose a track"));
widget_manager->show_wgt_text( WTOK_TITLE );
widget_manager->break_line();
widgetSet -> label(m_menu_id, _("Choose a Track"), GUI_LRG, GUI_TOP, 0, 0);
widgetSet -> space(m_menu_id);
widget_manager->add_wgt( WidgetManager::WGT_NONE, 100, 2);
widget_manager->break_line();
const int HA = widgetSet -> harray(m_menu_id);
const int COL1 = widgetSet -> varray(HA);
const int COL2 = widgetSet -> varray(HA);
for (size_t i = 0; i != track_manager->getTrackCount()/2; ++i)
widgetSet -> state(COL1, track_manager->getTrack(i)->getName(), GUI_SML, i, 0);
for (size_t i = track_manager->getTrackCount()/2;
i != track_manager->getTrackCount(); ++i)
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->set_initial_activation_state(true);
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(SHOW_TEXT, "", WGT_FNT_SML, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
for (size_t i = 0; i != track_manager->getTrackCount(); i += 2)
{
int tmp = widgetSet -> state(COL2, track_manager->getTrack(i)->getName(), GUI_SML, i, 0);
if (i == track_manager->getTrackCount()/2)
widgetSet -> set_active(tmp);
widget_manager->add_wgt( WTOK_TRACK0 + i, 40, 7);
widget_manager->set_wgt_text( WTOK_TRACK0 + i, track_manager->getTrack(i)->getName());
widget_manager->add_wgt( WTOK_TRACK0 + i + 1, 40, 7);
widget_manager->set_wgt_text( WTOK_TRACK0 + i + 1, track_manager->getTrack(i+1)->getName());
widget_manager->break_line();
}
widgetSet -> layout(m_menu_id, 0, 1);
m_rect = widgetSet->rect(10, 10, user_config->m_width-20, 34, GUI_ALL, 10);
//FIXME: Right now, the image and the author's name is not controlled by the widget manager.
#if 0
widget_manager->set_initial_rect_state(false, WGT_AREA_ALL, WGT_TRANS_BLACK);
widget_manager->set_initial_text_state(false, "", WGT_FNT_MED, Font::ALIGN_CENTER, Font::ALIGN_CENTER );
widget_manager->set_initial_activation_state(false);
widget_manager->add_wgt( WidgetManager::WGT_NONE, 100, 5);
widget_manager->break_line();
widget_manager->set_initial_rect_state(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_WHITE);
widget_manager->add_wgt( WTOK_IMG0, 40, 30);
widget_manager->add_wgt( WidgetManager::WGT_NONE, 5, 30);
widget_manager->add_wgt( WTOK_IMG0, 40, 30);
widget_manager->break_line();
widget_manager->add_wgt( WTOK_AUTHOR, 100, 10);
widget_manager->show_wgt_text( WTOK_AUTHOR );
#endif
widget_manager->layout(WGT_AREA_TOP);
}
//-----------------------------------------------------------------------------
TrackSel::~TrackSel()
{
widgetSet -> delete_widget(m_menu_id);
glDeleteLists(m_rect, 1);
widget_manager->delete_wgts();
}
//-----------------------------------------------------------------------------
@ -78,8 +112,9 @@ void TrackSel::update(float dt)
glClear(GL_DEPTH_BUFFER_BIT);
// draw a track preview of the currently highlighted track menu entry
const int CLICKED_TOKEN = widgetSet->get_token(widgetSet->click());
const Track* TRACK = track_manager->getTrack(CLICKED_TOKEN);
// const int CLICKED_TOKEN = widgetSet->get_token(widgetSet->click());
const int CLICKED_TOKEN = widget_manager->get_selected_wgt();
const Track* TRACK = track_manager->getTrack(CLICKED_TOKEN - WTOK_TRACK0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@ -136,9 +171,9 @@ void TrackSel::update(float dt)
glBindTexture(GL_TEXTURE_2D, 0);
const GLfloat backgroundColour[4] = { 0.3f, 0.3f, 0.3f, 0.5f };
glColor4fv(backgroundColour);
glCallList(m_rect);
// glCallList(m_rect);
glPopMatrix();
font_gui->Print(TRACK->getDescription(), GUI_MED,
font_gui->Print(TRACK->getDescription(), WGT_FNT_MED,
Font::ALIGN_CENTER, -1,
Font::ALIGN_BOTTOM, 10);
glDisable(GL_BLEND);
@ -151,8 +186,9 @@ void TrackSel::update(float dt)
//-----------------------------------------------------------------------------
void TrackSel::select()
{
const int CLICKED_TOKEN = widgetSet->get_token(widgetSet->click());
const Track* TRACK = track_manager->getTrack(CLICKED_TOKEN);
const int CLICKED_TOKEN = widget_manager->get_selected_wgt();
//const int CLICKED_TOKEN = widgetSet->get_token(widgetSet->click());
const Track* TRACK = track_manager->getTrack(CLICKED_TOKEN - WTOK_TRACK0);
race_manager->setTrack(TRACK->getIdent());
menu_manager->pushMenu(MENUID_NUMLAPS);

View File

@ -24,8 +24,8 @@
class TrackSel: public BaseGUI
{
protected:
int m_rect;
/*protected:
int m_rect;*/
public:
TrackSel();
~TrackSel();

View File

@ -48,7 +48,7 @@
#include "race_manager.hpp"
#include "loader.hpp"
#include "game_manager.hpp"
#include "widget_set.hpp"
#include "widget_manager.hpp"
#include "material_manager.hpp"
#include "sdldrv.hpp"
#include "callback_manager.hpp"
@ -374,7 +374,7 @@ int main(int argc, char *argv[] )
herring_manager -> loadDefaultHerrings();
attachment_manager -> loadModels ();
scene = new Scene();
widgetSet = new WidgetSet;
widget_manager = new WidgetManager;
menu_manager->switchToMainMenu();
// Replay a race

537
src/widget.cpp Normal file
View File

@ -0,0 +1,537 @@
// $Id: widget_set.cpp 1094 2007-05-21 06:49:06Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// This code originally from Neverball copyright (C) 2003 Robert Kooima
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "widget.hpp"
#include "gui/font.hpp"
//FIXME: this should be removed when the scrolling is cleaned
#include "user_config.hpp"
#include <cmath>
#include <iostream>
const GLfloat WGT_WHITE [4] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat WGT_GRAY [4] = { 0.5f, 0.5f, 0.5f, 1.0f };
const GLfloat WGT_BLACK [4] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat WGT_YELLOW [4] = { 1.0f, 1.0f, 0.0f, 1.0f };
const GLfloat WGT_RED [4] = { 1.0f, 0.0f, 0.0f, 1.0f };
const GLfloat WGT_GREEN [4] = { 0.0f, 1.0f, 0.0f, 1.0f };
const GLfloat WGT_BLUE [4] = { 0.0f, 0.0f, 1.0f, 1.0f };
const GLfloat WGT_TRANS_WHITE [4] = { 1.0f, 1.0f, 1.0f, 0.5f };
const GLfloat WGT_TRANS_GRAY [4] = { 0.5f, 0.5f, 0.5f, 0.5f };
const GLfloat WGT_TRANS_BLACK [4] = { 0.0f, 0.0f, 0.0f, 0.5f };
const GLfloat WGT_TRANS_YELLOW [4] = { 1.0f, 1.0f, 0.0f, 0.5f };
const GLfloat WGT_TRANS_RED [4] = { 1.0f, 0.0f, 0.0f, 0.5f };
const GLfloat WGT_TRANS_GREEN [4] = { 0.0f, 1.0f, 0.0f, 0.5f };
const GLfloat WGT_TRANS_BLUE [4] = { 0.0f, 0.0f, 1.0f, 0.5f };
//FIXME: I should change 'LIGHT' for 'LIT'.
const GLfloat WGT_LIGHT_GRAY [4] = {1.0f, 1.0f, 1.0f, 1.0f};
const GLfloat WGT_LIGHT_BLACK [4] = {0.5f, 0.5f, 0.5f, 1.0f};
const GLfloat WGT_LIGHT_YELLOW [4] = {1.0f, 1.0f, 0.5f, 1.0f};
const GLfloat WGT_LIGHT_RED [4] = {1.0f, 0.5f, 0.5f, 1.0f};
const GLfloat WGT_LIGHT_GREEN [4] = {0.5f, 1.0f, 0.5f, 1.0f};
const GLfloat WGT_LIGHT_BLUE [4] = {0.5f, 0.5f, 1.0f, 1.0f};
const GLfloat WGT_LIGHT_TRANS_GRAY [4] = {1.0f, 1.0f, 1.0f, 0.8f};
const GLfloat WGT_LIGHT_TRANS_BLACK [4] = {0.5f, 0.5f, 0.5f, 0.8f};
const GLfloat WGT_LIGHT_TRANS_YELLOW [4] = {1.0f, 1.0f, 0.5f, 0.8f};
const GLfloat WGT_LIGHT_TRANS_RED [4] = {1.0f, 0.5f, 0.5f, 0.8f};
const GLfloat WGT_LIGHT_TRANS_GREEN [4] = {0.5f, 1.0f, 0.5f, 0.5f};
const GLfloat WGT_LIGHT_TRANS_BLUE [4] = {0.5f, 0.5f, 1.0f, 0.8f};
Widget::Widget
(
const int X_,
const int Y_,
const int WIDTH_,
const int HEIGHT_
) :
//Switch features are not set here to sane defaults because the WidgetManager
//handles that.
m_x(X_), m_y(Y_),
m_width(WIDTH_), m_height(HEIGHT_),
m_rect_list(0),
m_round_corners(WGT_AREA_ALL),
/*m_scroll_pos_x(0),*/ m_scroll_pos_y(0),
/*m_scroll_speed_x(0),*/ m_scroll_speed_y(0),
m_text_scale(1.0f)
{
}
//-----------------------------------------------------------------------------
Widget::~Widget()
{
if(glIsList(m_rect_list))
{
glDeleteLists(m_rect_list, 1);
}
}
//-----------------------------------------------------------------------------
void Widget::update(const float DELTA)
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
/*Handle delta time dependant features*/
if(m_text_scale > MIN_TEXT_SCALE)
{
m_text_scale -= MIN_TEXT_SCALE * DELTA;
if(m_text_scale < MIN_TEXT_SCALE) m_text_scale = MIN_TEXT_SCALE;
}
/*Handle on/off features*/
//Draw widget
if(m_enable_texture)
{
glEnable(GL_TEXTURE_2D);
if(glIsTexture(m_texture))
{
glBindTexture(GL_TEXTURE_2D, m_texture);
}
else
{
std::cerr << "Warning: widget tried to draw null texture.\n";
std::cerr << "(Did you set the texture?)\n";
}
}
else
{
//This ensures that a texture from another module doesn't affects the widget
glDisable(GL_TEXTURE_2D);
}
if(m_enable_rect)
{
if(glIsList(m_rect_list))
{
glColor4fv(m_rect_color);
glCallList(m_rect_list);
}
else
{
std::cerr << "Warning: widget tried to draw null rect list.\n";
std::cerr << "(Did you created the rect?)\n";
}
}
//For multilines we have to do a *very* ugly workaround for a plib
//bug which causes multiline strings to move to the left, at least
//while centering, and also gives wrong values for the size of the
//text when there are multiple lines. Hopefully this work around will
//be removed when we move away from plib; the scrolling and the other
//text handling should be cleaned. Also, for some reason, different
//positions are needed if the text is centered. Sorry for the mess.
size_t line_end = 0;
int lines = 0;
do
{
line_end = m_text.find_first_of('\n', line_end + 1);
++lines;
} while( line_end != std::string::npos );
if(m_enable_scroll)
{
//TODO: constrain speed to sane values
/*m_scroll_pos_x += m_scroll_speed_x;*/
m_scroll_pos_y += m_scroll_speed_y;
if( m_text_y_alignment == Font::ALIGN_CENTER )
{
const int LIMIT = lines * m_text_size + m_height;
if(m_scroll_pos_y * 2 > LIMIT)
{
m_scroll_pos_y = -LIMIT / 2;
}
else if(-m_scroll_pos_y * 2 > LIMIT)
{
m_scroll_pos_y = LIMIT / 2;
}
}
else if( m_text_y_alignment == Font::ALIGN_BOTTOM )
{
const int TEXT_HEIGHT = lines * m_text_size;
if(m_scroll_pos_y > TEXT_HEIGHT / 2)
{
m_scroll_pos_y = -m_height - (TEXT_HEIGHT) / 2;
}
else if(m_scroll_pos_y < - m_height - TEXT_HEIGHT / 2)
{
m_scroll_pos_y = TEXT_HEIGHT / 2 + m_text_size;
}
}
/*
float left, right;
font_gui->getBBox(m_text.c_str(), m_text_size, false, &left, &right, NULL, NULL);
const int TEXT_WIDTH = (int)(right - left) / m_text_size;
if( m_text_x_alignment == Font::ALIGN_CENTER )
{
const int LIMIT = TEXT_WIDTH + m_width;
if(m_scroll_pos_x * 2 > LIMIT)
{
m_scroll_pos_x = -LIMIT / 2;
}
else if(-m_scroll_pos_x * 2 > LIMIT)
{
m_scroll_pos_x = LIMIT / 2;
}
}
else if( m_text_x_alignment == Font::ALIGN_LEFT )
{
if(m_scroll_pos_x > TEXT_WIDTH / 2)
{
m_scroll_pos_x = -m_width - (TEXT_WIDTH) / 2;
}
else if(m_scroll_pos_x < - m_width - TEXT_WIDTH / 2)
{
m_scroll_pos_x = TEXT_WIDTH / 2 + m_text_size;
}
}
*/
}
if(m_enable_text)
{
if(m_text.empty())
{
std::cerr << "Warning: widget tried to print an empty string.\n";
std::cerr << "(Did you set the text?)\n";
}
int x_pos = m_x;// + m_scroll_pos_x;
int y_pos = m_y - m_scroll_pos_y + ((lines - 1 )* m_text_size) / 2;
if( m_text_x_alignment == Font::ALIGN_CENTER ) x_pos += m_width / 2;
if( m_text_y_alignment == Font::ALIGN_CENTER )
{
y_pos += m_height / 2;
}
size_t line_start = 0;
bool draw;
bool out_of_rect = false;
glEnable( GL_SCISSOR_TEST );
do
{
draw = true;
if(y_pos + m_text_size / 2 > m_y + m_height )
{
if(y_pos - m_text_size / 2 > m_y + m_height) draw = false;
else
{
out_of_rect = true;
glScissor(m_x, m_y, m_width, m_height);
}
}
else if(y_pos - m_text_size / 2 < m_y)
{
if(y_pos + m_text_size / 2 < m_y) draw = false;
else
{
out_of_rect = true;
glScissor(m_x, m_y, m_width, m_height);
}
}
line_end = m_text.find_first_of('\n', line_start);
if( draw )
{
font_gui->Print(m_text.substr(line_start, line_end - line_start).c_str(), m_text_size,
m_text_x_alignment, x_pos, m_text_y_alignment, y_pos,
255, 255, 255, m_text_scale, m_text_scale);
}
y_pos -= m_text_size;
line_start = line_end + 1;
if( out_of_rect )
{
out_of_rect = false;
glScissor(0, 0, user_config->m_width, user_config->m_height);
}
} while( line_end != std::string::npos );
glDisable( GL_SCISSOR_TEST );
}
glPopMatrix();
}
/** 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
* false if the call to glGenLists failed, otherwise it returns true.
*/
bool Widget::create_rect(int radius)
{
//TODO: show warning if text > rect
if(radius > m_width * 0.5)
{
std::cerr << "Warning: widget's radius > half width.\n";
}
if(radius > m_height * 0.5)
{
std::cerr << "Warning: widget's radius > half height.\n";
}
if(radius < 1)
{
std::cerr << "Warning: widget's radius < 1, setting to 1.\n";
radius = 1;
}
if(m_width == 0)
{
std::cerr << "Warning: creating widget rect with width 0, " <<
"setting to 1.\n";
m_width = 1;
}
if(m_height == 0)
{
std::cerr << "Warning: creating widget rect with height 0, " <<
"setting to 1.\n";
m_height = 1;
}
if(!glIsList(m_rect_list))
{
m_rect_list = glGenLists(1);
if(m_rect_list == 0)
{
std::cerr << "Error: could not create a widget's rect list.\n";
return false;
}
}
//Calculate the number of quads each side should have. The algorithm
//isn't based on pure logic, instead it's based on the perception of
//roundness and some visual testing.
const int MIN_QUADS = 2;
const float QUAD_RADIUS_RAISE = 0.413f;
const int NUM_QUADS = MIN_QUADS + (int)(pow((float)radius, QUAD_RADIUS_RAISE));
int i;
glNewList(m_rect_list, GL_COMPILE);
{
//To create a rounded rectangle, we generate lines that are
//progressively bigger, which are given as vertex points for each
//quad.
glBegin(GL_QUAD_STRIP);
{
//Draw the left side of a rectangle.
for (i = 0; i <= NUM_QUADS; ++i)
{
//To find the position in the X and Y axis of each point of
//the quads, we use the property of the unit circle (a circle
//with radius = 1) that at any given angle, cos(angle) is the
//position of the unit circle at that angle in the X axis,
//and that sin(angle) is the position of the unit circle at
//that angle in the Y axis. Then the values from cos(angle)
//and sin(angle) are multiplied by the radius.
//
//First we find the angle: since 2 * pi is the number of
//radians in an entire circle, 0.5 * pi is a quarter of the
//circle, which is a corner of the rounded rectangle. Based
//on that, we just split the radians in a corner in NUM_QUADS
//+ 1 parts, and use the angles at those parts to find the
//X and Y position of the points.
const float ANGLE = 0.5f * M_PI * (float)i / (float)NUM_QUADS;
const float CIRCLE_X = radius * cos(ANGLE);
const float CIRCLE_Y = radius * sin(ANGLE);
//After we generate the positions in circle for the angles,
//we have to position each rounded corner properly depending
//on the position of the rectangle and the radius. The y
//position for the circle is dependant on rect; if a corner
//wasn't given, then the y position is computed as if it was
//for a rectangle without rounder corners.
const float VERTEX_X = m_x + radius - CIRCLE_X;
const float VERTEX_YA = m_y + m_height +
((m_round_corners & WGT_AREA_NW) ? (CIRCLE_Y - radius) : 0);
const float VERTEX_YB = m_y + ((m_round_corners & WGT_AREA_SW) ?
(radius - CIRCLE_Y) : 0);
glTexCoord2f((VERTEX_X - m_x) / m_width,
(VERTEX_YA - m_y) / m_height);
glVertex2f(VERTEX_X, VERTEX_YA);
glTexCoord2f((VERTEX_X - m_x) / m_width,
(VERTEX_YB - m_y) / m_height);
glVertex2f(VERTEX_X, VERTEX_YB);
}
//Draw the right side of a rectangle
for (i = 0; i <= NUM_QUADS; ++i)
{
const float ANGLE = 0.5f * M_PI * (float) i / (float) NUM_QUADS;
//By inverting the use of sin and cos we get corners that are
//drawn from left to right instead of right to left
const float CIRCLE_X = radius * sin(ANGLE);
const float CIRCLE_Y = radius * cos(ANGLE);
float VERTEX_X = m_x + m_width - radius + CIRCLE_X;
float VERTEX_YA = m_y + m_height + ((m_round_corners &
WGT_AREA_NE) ? (CIRCLE_Y - radius) : 0);
float VERTEX_YB = m_y + ((m_round_corners & WGT_AREA_SE) ?
(radius - CIRCLE_Y) : 0);
glTexCoord2f((VERTEX_X - m_x) / m_width,
(VERTEX_YA - m_y) / m_height);
glVertex2f(VERTEX_X, VERTEX_YA);
glTexCoord2f((VERTEX_X - m_x) / m_width,
(VERTEX_YB - m_y) / m_height);
glVertex2f(VERTEX_X, VERTEX_YB);
}
}
glEnd();
}
glEndList();
return true;
}
//-----------------------------------------------------------------------------
void Widget::resize_to_text()
{
if( !m_text.empty() )
{
float left, right, bottom, top;
font_gui->getBBox(m_text.c_str(), m_text_size, false, &left, &right, &bottom, &top);
const int TEXT_WIDTH = (int)(right - left);
const int TEXT_HEIGHT = (int)(bottom - top);
if( TEXT_WIDTH > m_width ) m_width = TEXT_WIDTH;
if( TEXT_HEIGHT > m_height ) m_height = TEXT_HEIGHT;
}
}
//-----------------------------------------------------------------------------
/* Please note that this function only lightens 'non-light' colors */
void Widget::lighten_color()
{
if(m_rect_color == WGT_GRAY)
{
m_rect_color = WGT_LIGHT_GRAY;
}
if(m_rect_color == WGT_BLACK)
{
m_rect_color = WGT_LIGHT_BLACK;
}
else if (m_rect_color == WGT_YELLOW)
{
m_rect_color = WGT_LIGHT_YELLOW;
}
else if (m_rect_color == WGT_RED)
{
m_rect_color = WGT_LIGHT_RED;
}
else if (m_rect_color == WGT_GREEN)
{
m_rect_color = WGT_LIGHT_GREEN;
}
else if (m_rect_color == WGT_BLUE)
{
m_rect_color = WGT_LIGHT_BLUE;
}
else if (m_rect_color == WGT_TRANS_GRAY)
{
m_rect_color = WGT_LIGHT_TRANS_GRAY;
}
else if (m_rect_color == WGT_TRANS_BLACK)
{
m_rect_color = WGT_LIGHT_TRANS_BLACK;
}
else if (m_rect_color == WGT_TRANS_YELLOW)
{
m_rect_color = WGT_LIGHT_TRANS_YELLOW;
}
else if (m_rect_color == WGT_TRANS_RED)
{
m_rect_color = WGT_LIGHT_TRANS_RED;
}
else if (m_rect_color == WGT_TRANS_GREEN)
{
m_rect_color = WGT_LIGHT_TRANS_GREEN;
}
else if (m_rect_color == WGT_TRANS_BLUE)
{
m_rect_color = WGT_LIGHT_TRANS_BLUE;
}
}
//-----------------------------------------------------------------------------
/* Please note that this function only darkens 'light' colors. */
void Widget::darken_color()
{
if(m_rect_color == WGT_LIGHT_GRAY)
{
m_rect_color = WGT_GRAY;
}
if(m_rect_color == WGT_LIGHT_BLACK)
{
m_rect_color = WGT_BLACK;
}
else if (m_rect_color == WGT_LIGHT_YELLOW)
{
m_rect_color = WGT_YELLOW;
}
else if (m_rect_color == WGT_LIGHT_RED)
{
m_rect_color = WGT_RED;
}
else if (m_rect_color == WGT_LIGHT_GREEN)
{
m_rect_color = WGT_GREEN;
}
else if (m_rect_color == WGT_LIGHT_BLUE)
{
m_rect_color = WGT_BLUE;
}
else if (m_rect_color == WGT_LIGHT_TRANS_GRAY)
{
m_rect_color = WGT_TRANS_GRAY;
}
else if (m_rect_color == WGT_LIGHT_TRANS_BLACK)
{
m_rect_color = WGT_TRANS_BLACK;
}
else if (m_rect_color == WGT_LIGHT_TRANS_YELLOW)
{
m_rect_color = WGT_TRANS_YELLOW;
}
else if (m_rect_color == WGT_LIGHT_TRANS_RED)
{
m_rect_color = WGT_TRANS_RED;
}
else if (m_rect_color == WGT_LIGHT_TRANS_GREEN)
{
m_rect_color = WGT_TRANS_GREEN;
}
else if (m_rect_color == WGT_LIGHT_TRANS_BLUE)
{
m_rect_color = WGT_TRANS_BLUE;
}
}

180
src/widget.hpp Normal file
View File

@ -0,0 +1,180 @@
//
// SuperTuxKart - a fun racing game with go-kart
// This code originally from Neverball copyright (C) 2003 Robert Kooima
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* This file should only be used directly by the widget manager. Also, all
* the coordinates in the widget.* and widget_manager.* are based on OpenGL,
* which means that the 0 in the Y-axis is in the bottom, not the top.
*/
#ifndef HEADER_WIDGET_H
#define HEADER_WIDGET_H
#ifdef __APPLE__
# include <OpenGL/gl.h>
#else
# include <GL/gl.h>
#endif
#include <string>
#include "gui/font.hpp"
enum WidgetFontSize { WGT_FNT_SML = 18, WGT_FNT_MED = 24, WGT_FNT_LRG = 30};
enum WidgetArea //One of the uses of this, is for rounded corners
{
WGT_AREA_NONE = 0,
WGT_AREA_NW = 1, WGT_AREA_SW = 2, WGT_AREA_NE = 4, WGT_AREA_SE = 8,
WGT_AREA_LFT = (WGT_AREA_NW | WGT_AREA_SW),
WGT_AREA_RGT = (WGT_AREA_NE | WGT_AREA_SE),
WGT_AREA_TOP = (WGT_AREA_NW | WGT_AREA_NE),
WGT_AREA_BOT = (WGT_AREA_SW | WGT_AREA_SE),
WGT_AREA_ALL = (WGT_AREA_TOP | WGT_AREA_BOT)
};
//I suggest that you do not use the white or light colors for the rects in
//most cases, because they don't have lighter versions that can be used to
//highlight those rects and then revert them, for example, when you select a
//widget. For textures, you should use WGT_WHITE usually, thought you can get
//nice effects by using other colors.
extern const GLfloat WGT_WHITE [4];
extern const GLfloat WGT_GRAY [4];
extern const GLfloat WGT_BLACK [4];
extern const GLfloat WGT_YELLOW [4];
extern const GLfloat WGT_RED [4];
extern const GLfloat WGT_GREEN [4];
extern const GLfloat WGT_BLUE [4];
extern const GLfloat WGT_TRANS_WHITE [4];
extern const GLfloat WGT_TRANS_GRAY [4];
extern const GLfloat WGT_TRANS_BLACK [4];
extern const GLfloat WGT_TRANS_YELLOW [4];
extern const GLfloat WGT_TRANS_RED [4];
extern const GLfloat WGT_TRANS_GREEN [4];
extern const GLfloat WGT_TRANS_BLUE [4];
extern const GLfloat WGT_LIGHT_GRAY [4];
extern const GLfloat WGT_LIGHT_BLACK [4];
extern const GLfloat WGT_LIGHT_YELLOW [4];
extern const GLfloat WGT_LIGHT_RED [4];
extern const GLfloat WGT_LIGHT_GREEN [4];
extern const GLfloat WGT_LIGHT_BLUE [4];
extern const GLfloat WGT_LIGHT_TRANS_GRAY [4];
extern const GLfloat WGT_LIGHT_TRANS_BLACK [4];
extern const GLfloat WGT_LIGHT_TRANS_YELLOW [4];
extern const GLfloat WGT_LIGHT_TRANS_RED [4];
extern const GLfloat WGT_LIGHT_TRANS_GREEN [4];
extern const GLfloat WGT_LIGHT_TRANS_BLUE [4];
class Widget
{
friend class WidgetManager;
/* Basic widget properties that will always be used. */
int m_x, m_y;
int m_width, m_height;
/* On/off features, these are not dependant on the delta time and are not
* animated. They are off by default. */
bool m_enable_rect;
GLuint m_rect_list; //A display list number that draws the rectangle with
//possibly rounded corners.
const GLfloat *m_rect_color; //This const cannot change the value it points to, but it
//can change where it points to.
WidgetArea m_round_corners;
bool m_enable_texture;
GLuint m_texture;
bool m_enable_text;
std::string m_text;
WidgetFontSize m_text_size;
Font::FontAlignType m_text_x_alignment;
Font::FontAlignType m_text_y_alignment;
bool m_enable_scroll;
/* int m_scroll_pos_x;*/
int m_scroll_pos_y;
/* int m_scroll_speed_x;*/
int m_scroll_speed_y;
/* Delta time dependant features, these deactivate after a certain time,
* and are dependant on the delta time. They have animations. */
static const float MAX_TEXT_SCALE = 1.2f;
static const float MIN_TEXT_SCALE = 1.0f;
float m_text_scale; //Used for the pulse effect
/*public:*/
Widget
(
const int X_,
const int Y_,
const int WIDTH_,
const int HEIGHT_
);
~Widget();
void update(const float DELTA);
/* int get_x_pos() const { return m_x; }
int get_y_pos() const { return m_y; }
int get_width() const { return m_width; }
int get_height() const { return m_height; }
void set_x_pos( const int X ) { m_x = X; }
void set_y_pos( const int Y ) { m_y = Y; }
void set_width( const int WIDTH ) { m_width = WIDTH; }
void set_height( const int HEIGHT ) { m_height = HEIGHT; }*/
void resize_to_text(); //This checks if the widget is smaller than the
//text, and if so, changes the width and height.
bool create_rect(int radius);
/* Switch features functions. */
/* void enable_rect() {m_enable_rect = true;}
void disable_rect() {m_enable_rect = false;}*/
// void toggle_rect() {m_enable_rect = m_enable_rect ? false : true;}
/* void set_rect_color(const GLfloat *COLOR) {m_rect_color = COLOR;}
const GLfloat* get_rect_color() const {return m_rect_color;}*/
/* void enable_texture() {m_enable_texture = true;}
void disable_texture() {m_enable_texture = false;}*/
// void toggle_texture() {m_enable_texture = m_enable_texture ? false : true;}
/* void set_texture(const int TEXTURE) {m_texture = TEXTURE;}
int get_texture () const {return m_texture;}*/
/* void enable_text() {m_enable_text = true;}
void disable_text() {m_enable_text = false;}
void toggle_text() {m_enable_text = m_enable_text ? false : true;}
void set_text(const char* TEXT) {m_text.assign(TEXT);}
void set_text(const std::string TEXT) {m_text.assign(TEXT);}
std::string get_text() const {return m_text;}
void set_text_size( const WidgetFontSize SIZE ) { m_text_size = SIZE; }
WidgetFontSize get_text_size() { return m_text_size; }*/
/* Time limited features' functions. */
void pulse() {m_text_scale = MAX_TEXT_SCALE;}
/* Convenience functions. */
void lighten_color();
void darken_color();
};
#endif
/* EOF */

1152
src/widget_manager.cpp Normal file

File diff suppressed because it is too large Load Diff

191
src/widget_manager.hpp Normal file
View File

@ -0,0 +1,191 @@
//
// SuperTuxKart - a fun racing game with go-kart
// This code originally from Neverball copyright (C) 2003 Robert Kooima
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_WIDGET_MANAGER_H
#define HEADER_WIDGET_MANAGER_H
#include "widget.hpp"
#include <vector>
/* Here are some big-picture instructions about how to use this widget
* manager: the extern widget_manager is a global interface to the class. Call
* add_wgt() to specify the widgets you want, and for each widget specify the
* details of it with the 'switch features', that can be changed between
* show/hide, the initial setting for all of them is to be hidden. You will
* usually have to call it's set_*() function, then the show_*() functions.
* After you have defined all the widgets in the screen, call layout(), that
* will do the actual work at creating the widgets. Call the activated
* functions during the time the widgets are alive, and make sure that
* update() is called each frame.
*
* You can use set_initial_*state() to avoid setting the state of the same
* switch features with same values over and over; the default states are
* reset when you call layout() or you can use reset_default_states().
*/
class WidgetManager
{
struct WidgetID
{
int token;
bool active; //If true, then this widget is interactive(though by
//definition, widgets are supposed to be interactive).
//The percentages of the container this widget takes
int min_width;
int min_height;
Widget *widget;
};
std::vector<WidgetID> m_widgets;
std::vector<int> m_breaks;
int m_x;
int m_y;
int m_selected_wgt_token;
//TODO: change 'default' to 'initial'
bool m_default_active;
bool m_default_show_rect;
bool m_default_rect_round_corners;
const GLfloat *m_default_rect_color;
bool m_default_show_texture;
int m_default_texture;
bool m_default_show_text;
std::string m_default_text;
WidgetFontSize m_default_text_size;
Font::FontAlignType m_default_text_x_alignment;
Font::FontAlignType m_default_text_y_alignment;
bool m_default_enable_scroll;
/* int m_default_scroll_x_pos;*/
int m_default_scroll_y_pos;
/* int m_default_scroll_x_speed;*/
int m_default_scroll_y_speed;
bool line_breaks( const int WGT ) const;
int find_id(const int TOKEN) const;
int calc_width() const;
int calc_height() const;
int calc_line_width(const int START_WGT) const;
int calc_line_height(const int START_WGT) const;
int find_left_widget(const int START_WGT) const;
int find_right_widget(const int START_WGT) const;
int find_top_widget(const int START_WGT) const;
int find_bottom_widget(const int START_WGT) const;
public:
//FIXME: maybe I should get this out of this class?
static const int WGT_NONE;
WidgetManager();
~WidgetManager();
bool add_wgt
(
const int TOKEN, //A number that names the widget.
const int MIN_WIDTH, //These values are percentages not pixels. If
//the widget is inside a container, 100%
//represents container space, otherwise 100% is
//the screen space.
const int MIN_HEIGHT
);
bool break_line();
void delete_wgts();
void update(const float DELTA);
//TODO: WGT_AREA_NONE and WGT_AREA_ALL should have some difference.
//Both WGT_AREA_NONE and WGT_AREA_ALL will produce centered widgets.
bool layout( const WidgetArea POSITION );
//TODO: make all get functions const
int get_selected_wgt() const { return m_selected_wgt_token;}
void set_selected_wgt(const int TOKEN);
/* On/off widget switch features. They are all disabled/hidden initially. */
void set_initial_activation_state( const bool ACTIVE);
void set_initial_rect_state(const bool SHOW, const WidgetArea ROUND_CORNERS, const GLfloat* const COLOR );
void set_initial_texture_state(const bool SHOW, const int TEXTURE );
void set_initial_text_state
(
const bool SHOW,
const std::string TEXT,
const WidgetFontSize SIZE,
const Font::FontAlignType X_ALIGN,
const Font::FontAlignType Y_ALIGN
);
void set_initial_scroll_state(const bool ENABLE, /*const int X_POS,*/ const int Y_POS, /*const int X_SPEED, */const int Y_SPEED );
void restore_default_states();
void activate_wgt(const int TOKEN);
void deactivate_wgt(const int TOKEN);
//FIXME: maybe this should be set_wgt_rect_color ? and put after the other rect funcs?
void set_wgt_color(const int TOKEN, const GLfloat* const COLOR);
void set_wgt_round_corners(const int TOKEN, const WidgetArea CORNERS);
void show_wgt_rect(const int TOKEN);
void hide_wgt_rect(const int TOKEN);
// void toggle_wgt_rect(const int TOKEN);
void set_wgt_texture(const int TOKEN, const int TEXTURE);
void show_wgt_texture(const int TOKEN);
void hide_wgt_texture(const int TOKEN);
// void toggle_wgt_texture(const int TOKEN);
void set_wgt_text( const int TOKEN, const char* TEXT );
void set_wgt_text( const int TOKEN, const std::string TEXT );
void set_wgt_text_size( const int TOKEN, const WidgetFontSize SIZE);
void show_wgt_text( const int TOKEN );
void hide_wgt_text( const int TOKEN );
// void toggle_wgt_text( const int TOKEN );
void set_wgt_text_x_alignment( const int TOKEN, const Font::FontAlignType ALIGN );
void set_wgt_text_y_alignment( const int TOKEN, const Font::FontAlignType ALIGN );
void enable_wgt_scroll( const int TOKEN );
void disable_wgt_scroll( const int TOKEN );
/* void set_wgt_x_scroll_pos( const int TOKEN, const int POS );*/
void set_wgt_y_scroll_pos( const int TOKEN, const int POS );
/* void set_wgt_x_scroll_speed( const int TOKEN, const int SPEED );*/
void set_wgt_y_scroll_speed( const int TOKEN, const int SPEED );
/* Activated widget features. */
void pulse_wgt( const int TOKEN ) const;
/* Convenience widget functions. */
void lighten_wgt_color(const int TOKEN);
void darken_wgt_color(const int TOKEN);
/* Input device handling. */
int handle_mouse( const int X, const int Y );
int handle_keyboard( const int KEY );
int handle_joystick( int axis, int dir, int value );
};
extern WidgetManager *widget_manager;
#endif
/* EOF */

File diff suppressed because it is too large Load Diff

View File

@ -1,339 +0,0 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// This code originally from Neverball copyright (C) 2003 Robert Kooima
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_WIDGETSET_H
#define HEADER_WIDGETSET_H
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#ifdef WIN32
# include <windows.h>
#endif
#include <GL/gl.h>
#endif
#include <string>
/*---------------------------------------------------------------------------*/
enum WidgetFontSize { GUI_SML = 18, GUI_MED = 24, GUI_LRG = 30};
enum WidgetArea //One of the uses of this, is to say which corners are rounded
{
GUI_NONE = 0,
GUI_NW = 1, GUI_SW = 2, GUI_NE = 4, GUI_SE = 8,
GUI_LFT = (GUI_NW | GUI_SW),
GUI_RGT = (GUI_NE | GUI_SE),
GUI_TOP = (GUI_NW | GUI_NE),
GUI_BOT = (GUI_SW | GUI_SE),
GUI_ALL = (GUI_TOP | GUI_BOT)
};
enum WidgetValue { GUI_OFF = 0, GUI_ON = 1 }; //For the widget values, for
// on / off switch.
#define SCREEN_CENTERED_TEXT -10000
/*---------------------------------------------------------------------------*/
#define MAX_WIDGETS 256
#define GUI_TYPE 0xFFFE
enum GuiType
{
GUI_FREE = 0, //Unused widget
GUI_STATE = 1, //Button that has a state assigned.
GUI_HARRAY = 2, //Horizantal container for groups of other types, all with
//the same size.
GUI_VARRAY = 4, //Vertical container for groups of other types, all with
//the same.
GUI_HSTACK = 8, //Horizontal container for groups of other types, each one
//on top of the other, with individual sizes.
GUI_VSTACK = 16, //Vertical container for groups of other types, each one
//on top the other, with individual sizes.
GUI_FILLER = 32, //Empty space, cannot be traveled through
GUI_IMAGE = 64, //Image widget using an OpenGL texture
GUI_LABEL = 128, //Single line text
GUI_COUNT = 256,
GUI_CLOCK = 512,
GUI_SPACE = 1024,//Empty space, can be traveled through
GUI_PAUSE = 2048
};
/*---------------------------------------------------------------------------*/
//previously in config.h:
#define MAX_STR 256
/*---------------------------------------------------------------------------*/
//TODO:fix widget set colors, it seems only white works.
const GLfloat gui_wht[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat gui_yel[4] = { 1.0f, 1.0f, 0.0f, 1.0f };
const GLfloat gui_red[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
const GLfloat gui_grn[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
const GLfloat gui_blu[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
const GLfloat gui_blk[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat gui_gry[4] = { 0.3f, 0.3f, 0.3f, 1.0f };
struct Widget
{
Widget() :
type(0), token(0), value(0), size(0), rect(0), x(0), y(0), w(0), h(0),
yOffset(0), car(0), cdr(0), _text(""), count_text(""), text_width(0),
text_img(0), rect_obj(0), color0(NULL), color1(NULL), scale(0.0f) {}
int type;
int token;//The token is a number supplied by the programmer to name
//recognize a widget. You could also store the id, but
//that wouldn't let you use a switch/enum combination.
int value;//On/Off switch using the WidgetValue.
int size;
int rect; //This uses the WidgetAreas, and determines which corners
//are rounded, GUI_ALL rounds all corners.
int x, y;
int w, h;
int yOffset;
int car;
int cdr;
std::string _text;
std::string count_text;
int text_width;
GLuint text_img;
GLuint rect_obj;
const GLfloat *color0;
const GLfloat *color1;
GLfloat scale;
};
class WidgetSet
{
public:
/*
* Initialization/deinitialization functions
*/
WidgetSet();
~WidgetSet();
void reInit(); // necessary in case of fullscreen/window mode change on windows
/*
* Get/set functions
*/
void set_label(int id, const std::string&);
void set_multi(int id, const char *);
void set_count(int id, int);
void set_clock(int id, int);
const std::string& get_label(int id) { return m_widgets[id]._text; }
int get_token(int id) const;
int get_value(int id) const;
/*
* Creation functions, the first argument is the parent id of the new
* widget (0 if no parent)
*/
//arrays, these are used to setup the layout of your widgets
int harray(int parent);
int varray(int parent);
int hstack(int parent);
int vstack(int parent);
//fills up space
int filler(int parent);
//a widget that consists of a texture (which must be completely
//handled by the application)
int image(int parent, int, int, int, int rect=GUI_ALL);
//a normal text menu entry, except that it is automatically immediately activated
int start(int parent, const std::string&, int, int, int value=GUI_OFF);
//a normal text menu entry
int state(int parent, const std::string&, int, int, int value=GUI_OFF);
//a text label (cannot be selected). c0 and c1 are two colours that the text is shaded with
int label(int parent, const std::string &text, int size=GUI_MED, int rect=GUI_ALL,
const float *c0=0, const float *c1=0);
//Create a multi-line text box using a vertical array of labels.
//Parse the text for '\' characters and treat them as line-breaks.
//Preserve the rect specifation across the entire array.
int multi(int parent, const char *, int size=GUI_MED, int rect=GUI_ALL,
const float *c0=0, const float *c1=0);
//widget is a single number - e.g. an fps counter or whatever
int count(int parent, int, int, int);
//widget consists of a time in minutes and seconds
int clock(int parent, int, int, int);
//just a blank space
int space(int parent);
/*---------------------------------------------------------------------------*/
/* prints out debugging info */
void dump(int id, int);
/* Use this after you have first created your widgets to set their
* positioning xd and yd have possible values of 1(right/top), 0(center),
* -1(left/bottom).
*/
void layout(int id, int xd, int yd);
int search(int id, int, int);
/*
* Activate a widget, allowing it to behave as a normal state widget.
* This may be used to create image buttons, or cause an array of
* widgets to behave as a single state widget.
*/
int activate_widget(int id, int, int);
/* you only need to call this for parents, children will automatically be deleted by their parents */
int delete_widget(int id);
/*---------------------------------------------------------------------------*/
/* call once a frame to update your widgets on the screen
You only need to call this for parents, children will automatically be painted by their parents */
void paint(int id);
/* call "gui_pulse(gui_point(id, x, y), 1.2f);" whenever the mouse moves to make widgets pulse when the mouse goes over them */
void pulse(int id, float);
/* call once a frame, passing on the value given to BaseGUI::update(int)
You only need to call this for parents, children will automatically be updated by their parents */
void timer(int id, float);
/* mouse movement */
int point(int id, int x, int y);
/* joystick movement */
int stick(int id, int axis, int dir, int value);
/* keyboard cursors */
int cursor(int id, int key);
/* mouse click */
int click();
/* where id's value is being used as a bool, this toggles it */
void toggle(int id);
//force id to be the current active widget
void set_active(int id);
/*---------------------------------------------------------------------------*/
void tgl_paused();
bool get_paused() const { return m_paused; }
GLuint rect
(
const int X,
const int Y,
const int WIDTH,
const int HEIGHT,
const int RECT,
const int RADIUS
);
private:
int hot(int id);
GLuint list(int x, int y, int w, int h, const float *c0, const float *c1);
int add_widget(int parent, int type);
int pause(int parent);
/*---------------------------------------------------------------------------*/
void widget_up(int id);
void harray_up(int id);
void varray_up(int id);
void hstack_up(int id);
void vstack_up(int id);
void paused_up(int id);
void button_up(int id);
void widget_dn(int id, int x, int y, int w, int h);
void harray_dn(int id, int x, int y, int w, int h);
void varray_dn(int id, int x, int y, int w, int h);
void hstack_dn(int id, int x, int y, int w, int h);
void vstack_dn(int id, int x, int y, int w, int h);
void filler_dn(int id, int x, int y, int w, int h);
void button_dn(int id, int x, int y, int w, int h);
/*---------------------------------------------------------------------------*/
void paint_rect(int id, int st);
void paint_text(int id);;
void paint_array(int id);
void paint_image(int id);
void paint_count(int id);
void paint_clock(int id);
void paint_label(int id);
/*---------------------------------------------------------------------------*/
int vert_test(int id, int jd);
int horz_test(int id, int jd);
int stick_L(int id, int dd);
int stick_R(int id, int dd);
int stick_D(int id, int dd);
int stick_U(int id, int dd);
/*---------------------------------------------------------------------------*/
void config_push_persp(float, float, float);
void config_push_ortho();
void config_pop_matrix();
/*---------------------------------------------------------------------------*/
Widget m_widgets[MAX_WIDGETS];
int m_active;
int m_radius;
int m_pause_id;
bool m_paused;
};
extern WidgetSet *widgetSet;
#endif
/* EOF */