Added support (incl. gui) to change the menu background

pictures.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2888 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-01-12 12:29:31 +00:00
parent cc79071ae0
commit d1eea398a1
8 changed files with 80 additions and 30 deletions

View File

@ -10,9 +10,11 @@
;; points 1st, 0 is least points
;; 1st
(title-music "main_theme.music")
(mainmenu-background "st_title_screen.rgb")
(menu-background "menu_background.rgb")
(game-style "nitro") ;; "wheelie" or "nitro"
;; Two lists which must have the same length, containing the list of all
;; possible main menu and background images.
(mainmenu-background "st_title_screen.rgb" "st_title_screen2.rgb")
(menu-background "menu_background.rgb" "menu_background2.rgb")
(max-history 10000) ;; maximum number of history frames.
(max-skidmarks 100) ;; max. number of skidmarks per kart.
(skid-fadeout-time 60) ;; Time till skidm marks fade out

View File

@ -18,6 +18,8 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config_display.hpp"
#include "main_loop.hpp"
#include "widget_manager.hpp"
#include "user_config.hpp"
#include "menu_manager.hpp"
@ -35,6 +37,7 @@ enum WidgetTokens
WTOK_TITLE,
WTOK_FULLSCREEN,
WTOK_NEXT_BACKGROUND,
WTOK_INCR_RES,
WTOK_DECR_RES,
WTOK_CURRENT_RES,
@ -78,12 +81,14 @@ ConfigDisplay::ConfigDisplay()
}
}
widget_manager->addTextButtonWgt(WTOK_NEXT_BACKGROUND, 60, 7, _("Next background"));
widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 60, 2 );
char msg [MAX_MESSAGE_LENGTH];
//I18N: displays current resolution
snprintf( msg, MAX_MESSAGE_LENGTH, _("Current: %dx%d"), m_curr_width, m_curr_height );
widget_manager->addTextWgt( WTOK_CURRENT_RES, 60, 7, msg);
widget_manager->hideWgtRect(WTOK_CURRENT_RES);
widget_manager->addTextButtonWgt( WTOK_INCR_RES, 60, 7,
_("Increase Resolution"));
@ -131,7 +136,10 @@ void ConfigDisplay::select()
}
changeApplyButton();
break;
case WTOK_NEXT_BACKGROUND:
user_config->nextBackgroundIndex();
main_loop->loadBackgroundImages();
break;
case WTOK_INCR_RES:
{
const int NUM_RES = (int)m_sizes.size();

View File

@ -19,15 +19,6 @@
#include "main_loop.hpp"
#ifdef __APPLE__
# include <OpenGL/gl.h>
#else
# ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# endif
# include <GL/gl.h>
#endif
#include <SDL/SDL.h>
#include <assert.h>
#include "sdldrv.hpp"
@ -56,17 +47,23 @@ MainLoop::~MainLoop()
{
} // ~MainLoop
//-----------------------------------------------------------------------------
void MainLoop::loadBackgroundImages()
{
int ind = user_config->getBackgroundIndex();
const std::string &main = stk_config->getMainMenuPicture(ind);
m_title_screen_texture = material_manager->getMaterial(main)->getState()->getTextureHandle();
const std::string &background = stk_config->getBackgroundPicture(ind);
m_bg_texture = material_manager->getMaterial(background)->getState()->getTextureHandle();
} // loadBackgroundImages
//-----------------------------------------------------------------------------
/** Run the actual main loop.
*/
void MainLoop::run()
{
static const GLuint TITLE_SCREEN_TEXTURE =
material_manager->getMaterial(stk_config->m_mainmenu_background)->getState()->getTextureHandle();
static const GLuint MENUS_BG_TEXTURE =
material_manager->getMaterial(stk_config->m_menu_background)->getState()->getTextureHandle();
loadBackgroundImages();
bool music_on = false;
m_curr_time = SDL_GetTicks();
@ -191,9 +188,9 @@ void MainLoop::run()
//Draw the splash screen
if(menu_manager->isMainMenuActive())
glBindTexture(GL_TEXTURE_2D, TITLE_SCREEN_TEXTURE);
glBindTexture(GL_TEXTURE_2D, m_title_screen_texture);
else
glBindTexture(GL_TEXTURE_2D, MENUS_BG_TEXTURE);
glBindTexture(GL_TEXTURE_2D, m_bg_texture);
glBegin ( GL_QUADS ) ;
glColor3f (1, 1, 1 ) ;

View File

@ -19,6 +19,16 @@
#ifndef HEADER_MAIN_LOOP_HPP
#define HEADER_MAIN_LOOP_HPP
#ifdef __APPLE__
# include <OpenGL/gl.h>
#else
# ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# endif
# include <GL/gl.h>
#endif
#include <SDL/SDL_types.h>
/** Management class for the whole gameflow, this is where the
@ -31,12 +41,15 @@ private:
int m_frame_count;
Uint32 m_curr_time;
Uint32 m_prev_time;
GLuint m_title_screen_texture;
GLuint m_bg_texture;
public:
MainLoop();
~MainLoop();
void run();
void abort();
void loadBackgroundImages();
}; // MainLoop
extern MainLoop* main_loop;

View File

@ -147,6 +147,24 @@ void STKConfig::init_defaults()
m_leader_intervals.clear();
} // init_defaults
//-----------------------------------------------------------------------------
const std::string &STKConfig::getMainMenuPicture(int n)
{
if(n>=0 && n<(int)m_mainmenu_background.size())
return m_mainmenu_background[n];
else
return m_mainmenu_background[0];
} // getMainMenuPicture
//-----------------------------------------------------------------------------
const std::string &STKConfig::getBackgroundPicture(int n)
{
if(n>=0 && n<(int)m_menu_background.size())
return m_menu_background[n];
else
return m_menu_background[0];
} // getBackgroundPicture
//-----------------------------------------------------------------------------
/** Extracts the actual information from a lisp file.
* \param lisp Pointer to the lisp data structure.
@ -181,8 +199,8 @@ void STKConfig::getAllData(const lisp::Lisp* lisp)
lisp->get("slowdown-factor", m_slowdown_factor );
lisp->get("delay-finish-time", m_delay_finish_time );
lisp->get("music-credit-time", m_music_credit_time );
lisp->get("menu-background", m_menu_background );
lisp->get("mainmenu-background", m_mainmenu_background );
lisp->getVector("menu-background", m_menu_background );
lisp->getVector("mainmenu-background", m_mainmenu_background );
lisp->get("enable_networking", m_enable_networking );
std::string title_music;
lisp->get("title-music", title_music );

View File

@ -80,9 +80,9 @@ public:
MusicInformation
*m_title_music; /**<Filename of the title music to play.*/
std::string
std::vector<std::string>
m_mainmenu_background; /**<Picture used as menu background. */
std::string
std::vector<std::string>
m_menu_background; /**<Picture used as background for other menus. */
/** Empty constructor. The actual work is done in load. */
@ -93,6 +93,8 @@ public:
/** Returns the default kart properties for each kart. */
const KartProperties &
getDefaultKartProperties() const {return m_kart_properties; }
const std::string &getMainMenuPicture(int n);
const std::string &getBackgroundPicture(int n);
}
; // STKConfig

View File

@ -17,8 +17,10 @@
// 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 <stdio.h>
#include "user_config.hpp"
#include <stdio.h>
#include <stdexcept>
#include <sstream>
#include <string>
@ -38,8 +40,8 @@
#define _WINSOCKAPI_
#include <plib/ul.h>
#include "stk_config.hpp"
#include "actionmap.hpp"
#include "user_config.hpp"
#include "lisp/lisp.hpp"
#include "lisp/parser.hpp"
#include "lisp/writer.hpp"
@ -291,7 +293,15 @@ void UserConfig::setDefaults()
} // setDefaults
// -----------------------------------------------------------------------------
/** Sets the next background image index. */
void UserConfig::nextBackgroundIndex()
{
m_background_index++;
if(m_background_index>=(int)stk_config->m_mainmenu_background.size())
m_background_index = 0;
}
// -----------------------------------------------------------------------------
/**
* load default configuration file for this platform

View File

@ -244,8 +244,8 @@ public:
/** Returns the default difficulty. */
int getDefaultDifficulty() const { return m_difficulty; }
/** Sets the index of the background image. */
void setBackgroundIndex(int n) { m_background_index = n; }
void nextBackgroundIndex();
/** Get the index of the background image. */
int getBackgroundIndex() const { return m_background_index; }