r88 - in trunk: . src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Thu Feb 10 18:45:16 EST 2005


Author: jonas
Date: 2005-02-10 18:45:16 -0500 (Thu, 10 Feb 2005)
New Revision: 88

Added:
   trunk/src/menu.cpp
   trunk/src/menu.h
Modified:
   trunk/lost_penguins.conf
   trunk/src/Makefile
   trunk/src/anim.cpp
   trunk/src/common.cpp
   trunk/src/common.h
   trunk/src/gfxeng.cpp
   trunk/src/gfxeng.h
   trunk/src/input.cpp
   trunk/src/input.h
   trunk/src/lost_penguins.cpp
   trunk/src/scenario.cpp
Log:
Introduced prelimenary menu support:
 - Added a new abstract class Menu and created a derived TestMenu
 - The main game loop now checks for the existence of a menu
 - In game menu switching can be done using the "Escape" key...
 - InputHandler has now a separate pollMEvents() for menu
 - The menu has a semitransparent background when used during the game
 - Most menu related code is either in menu.* (format) or gfxeng.* (displaying)



Modified: trunk/lost_penguins.conf
===================================================================
--- trunk/lost_penguins.conf	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/lost_penguins.conf	2005-02-10 23:45:16 UTC (rev 88)
@@ -1,7 +1,7 @@
 #General configuration file
 datadir /usr/local/share/lost_penguins/
 map map2.cfg
-full 1
+full 0
 width 1024
 height 768
 bpp 32
\ No newline at end of file

Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/Makefile	2005-02-10 23:45:16 UTC (rev 88)
@@ -9,7 +9,7 @@
 OBJS  = common.o anim.o gfxeng.o input.o font.o lost_penguins.o scenario.o\
         objects_common.o sfxeng.o players_common.o monsters_common.o\
         characters_common.o objectpools.o weapons.o events.o imgcache.o\
-        sndcache.o
+        sndcache.o menu.o
 PLUGS = objects.a
 BIN   = ../lost_penguins
 

Modified: trunk/src/anim.cpp
===================================================================
--- trunk/src/anim.cpp	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/anim.cpp	2005-02-10 23:45:16 UTC (rev 88)
@@ -87,6 +87,7 @@
     dt=(SDL_GetTicks()-tcurrent);
     tcurrent=SDL_GetTicks();
 
+    //Game is running normally
     if (!paused) {
         //released keys of player
         if (scenario->player != NULL) {
@@ -150,6 +151,7 @@
             } else if ((*obit)->isRunning()) (*obit)->updateAnim(dt);
             ++obit;
         }
+    //Game is paused
     } else {
         if (input->getState(INPUT_RIGHT)) {
             input->unsetState(INPUT_RIGHT);

Modified: trunk/src/common.cpp
===================================================================
--- trunk/src/common.cpp	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/common.cpp	2005-02-10 23:45:16 UTC (rev 88)
@@ -1,4 +1,5 @@
 #include "common.h"
+#include "menu.h"
 
 ImageCache* imgcache;
 SoundCache* sndcache;
@@ -10,6 +11,8 @@
 Font* font2;
 Config config;
 bool paused=false;
+bool running=false;
+Menu* menu;
 
 string itos(int i) {
     std::stringstream s;
@@ -22,3 +25,23 @@
     else return a=min(0,a-b);
 }
 
+Menu* setMenu(Menu* newmenu) {
+    newmenu->setLast(menu);
+    return menu=newmenu;
+}
+
+Menu* closeMenu() {
+    if (menu) {
+        Menu* tmp=menu->getLast();
+        delete menu;
+        return menu=tmp;
+    } else {
+        return NULL;
+    }
+}
+
+void closeMenus() {
+    while (menu) {
+        closeMenu();
+    }
+}

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/common.h	2005-02-10 23:45:16 UTC (rev 88)
@@ -2,6 +2,9 @@
 #define _COMMON_H 1
 
 /// Common header file
+///
+/// \todo Create a game class and move almost all remaining global
+///   variables/functions there...
 #include <iostream>
 #include <fstream>
 #include <sstream>
@@ -37,6 +40,7 @@
 class Event;
 class Weapon;
 class Animation;
+class Menu;
 
 typedef std::set<Object *>::iterator object_iterator;
 typedef std::set<Character *>::iterator character_iterator;
@@ -111,6 +115,13 @@
 string itos(int);
 /// Helper function boost that increases/decreases the absolute value
 int boost(int,int);
+
+/// Set the current menu
+Menu* setMenu(Menu* newmenu);
+/// Close the current menus
+Menu* closeMenu();
+/// Close all menus (menu=NULL)
+void closeMenus();
 //@}
 
 //global variables
@@ -135,6 +146,10 @@
 extern Font* font2;
 /// True if the game is paused
 extern bool paused;
+/// True if a map is currently running
+extern bool running;
+/// Currently used menu, NULL if not inside a menu
+extern Menu* menu;
 //@}
 
 #endif

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/gfxeng.cpp	2005-02-10 23:45:16 UTC (rev 88)
@@ -5,23 +5,39 @@
 #include "players_common.h"
 #include "imgcache.h"
 #include "scenario.h"
+#include "menu.h"
 #include "gfxeng.h"
 
 
 GraphicsEngine::GraphicsEngine():
+  screen(NULL),
+  menubg(NULL),
   Dfps(0),
   Dframes(0),
   currentfps(0),
   tcurrent(SDL_GetTicks()),
+  menu_done(false),
   show_bar(true),
   show_fps(true),
   fullscreen(config.full) {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+    rmask = 0xff000000;
+    gmask = 0x00ff0000;
+    bmask = 0x0000ff00;
+    amask = 0x000000ff;
+#else
+    rmask = 0x000000ff;
+    gmask = 0x0000ff00;
+    bmask = 0x00ff0000;
+    amask = 0xff000000;
+#endif
     resize(config.width, config.height);
     lifeimage=new Animation(imgcache->loadImage("life.bmp"));
 }
 
 GraphicsEngine::~GraphicsEngine() {
     delete lifeimage;
+    if (menubg) SDL_FreeSurface(menubg);
     SDL_FreeSurface(screen);
 }
 
@@ -148,6 +164,7 @@
 }
 
 void GraphicsEngine::renderScene(bool insist) {
+    resetMenuBG();
     if (scenario->background && (!paused || insist)) {
         //We don't want to change pos!
         SDL_Rect tmprect,shift,srcpos;
@@ -231,3 +248,80 @@
         resize(screen->w,screen->h);
     }
 }
+
+void GraphicsEngine::drawMenu() {
+    if (!menu_done) {
+        menu_done=true;
+        //Semitransparent background
+        setGameMenuBG();
+        SDL_BlitSurface(menubg,NULL,screen,NULL);
+
+        menu->font_title->writeCenter(screen,menu->title,0);
+
+        Uint16 h;
+        for (Uint8 i=0; i< menu->getSize(); i++) {
+            if (i<=menu->currententry) {
+                h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2;
+            } else {
+                h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i)*(menu->font->getHeight()))/2;
+            }
+            if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h);
+            else menu->font->writeCenter(screen,menu->entries[i],h);
+        }
+
+        SDL_Flip(screen);
+    }
+}
+
+//this could probably be done much easier ;)
+inline void GraphicsEngine::setGameMenuBG() {
+    if (!menubg) {
+        SDL_Surface* tmp = SDL_CreateRGBSurface (
+          SDL_HWSURFACE,
+          screen->w,
+          screen->h,
+          32,
+          rmask,gmask,bmask,0);
+#ifdef ALPHA
+        menubg = SDL_CreateRGBSurface (
+          SDL_HWSURFACE,
+          screen->w,
+          screen->h,
+          32,
+          rmask,gmask,bmask,0);
+        SDL_BlitSurface(screen,NULL,menubg,NULL);
+        SDL_SetAlpha(menubg,SDL_SRCALPHA,60);
+        SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
+        SDL_BlitSurface(menubg,NULL,tmp,NULL);
+        SDL_FreeSurface(menubg);
+        menubg=SDL_DisplayFormatAlpha(tmp);
+#else
+        SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
+        menubg=SDL_DisplayFormat(tmp);
+#endif
+        SDL_FreeSurface(tmp);
+    }
+}
+
+void GraphicsEngine::setMenuBG(SDL_Surface* menu_background) {
+    if (menubg) SDL_FreeSurface(menubg);
+    if (menu_background) {
+        menubg=menu_background;
+    } else {
+        SDL_Surface* tmp = SDL_CreateRGBSurface (
+          SDL_HWSURFACE,
+          screen->w,
+          screen->h,
+          32,
+          rmask,gmask,bmask,0);
+        SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
+        menubg=SDL_DisplayFormat(tmp);
+    }
+}
+
+void GraphicsEngine::resetMenuBG() {
+    if (menubg) {
+        SDL_FreeSurface(menubg);
+        menubg=NULL;
+    }
+}

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/gfxeng.h	2005-02-10 23:45:16 UTC (rev 88)
@@ -3,6 +3,7 @@
 
 #define BAR_HEIGHT      138
 #define ICON_SIZE       46
+#define DFONT           40
 
 /** \brief Graphics engine
 
@@ -15,35 +16,61 @@
         ~GraphicsEngine();
         /// Runs SDL_SetVideoMode with the new parameters.
         void resize(Uint16 width, Uint16 height);
-        ///\brief update the scene
+        ///\brief update the scene in a running scenario
         ///
-        /// Draws the background and all objects in the pool if the game isn't
-        /// paused. Optionally also the player bar and/or the current frames per
-        /// second.
+        /// If a scenario is running this draws the background and all objects
+        /// in the pool. If the game is paused, only the player bar is drawn.
+        /// Optionally also the player bar and/or the current frames per second
+        /// are displayed.
         /// \param insist True if the objects should be drawn even if the game
         ///        is paused
-        void renderScene(bool insist=true);
+        void renderScene(bool insist=false);
         void togglePlayerBar();
         void toggleFPS();
         void toggleFullScreen();
+        ///\brief draw the menu
+        ///
+        /// If no scenario is running or the scenario was interrupted this will
+        /// draw the menu.
+        void drawMenu();
+        void updateMenu() {
+            menu_done=false;
+        }
+        void setMenuBG(SDL_Surface* menu_background=NULL);
+        void resetMenuBG();
+        Uint16 getFPS() {
+            if (show_fps) return currentfps;
+            else return 0;
+        }
     private:
+        Uint32 rmask;
+        Uint32 gmask;
+        Uint32 bmask;
+        Uint32 amask;
         inline SDL_Rect clipToBG(SDL_Rect dest) const;
-        //updates backpos and returns the new shift vector (ignore w,h)
+        /// updates backpos and returns the new shift vector (ignore w,h)
         inline SDL_Rect setShift(SDL_Rect center);
-        //simple vector addition, should be replaced by operator
+        /// simple vector addition, should be replaced by operator
         inline SDL_Rect* shiftMapArea(SDL_Rect& area, const SDL_Rect& shift);
-        //draw player bar
+        /// draw player bar
         inline void drawPlayerBar();
-        //currently visible part of the map area
+        /// currently visible part of the map area
         SDL_Rect vis_map;
-        //main screen
+        /// main screen
         SDL_Surface* screen;
-        //player bar
+        /// menu background
+        SDL_Surface* menubg;
+        /// sets the menu background while playing a scenario
+        inline void setGameMenuBG();
+        /// player bar
         SDL_Rect bar;
-        //player bar
+        /// symbol for one life of a player
         Animation* lifeimage;
         //fps stuff
         Uint16 Dfps,Dframes,currentfps,tcurrent;
+        //for drawMenu
+        bool menu_done;
+        //visual flags
         bool show_bar;
         bool show_fps;
         bool fullscreen;

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/input.cpp	2005-02-10 23:45:16 UTC (rev 88)
@@ -7,6 +7,7 @@
 #include "sfxeng.h"
 #include "scenario.h"
 #include "objectpools.h"
+#include "menu.h"
 #include "objects_common.h"
 
 
@@ -19,6 +20,176 @@
 InputHandler::~InputHandler() {
 }
 
+void InputHandler::pollMEvents() {
+    SDL_Event event;
+
+    while(SDL_PollEvent(&event)) {
+        switch(event.type) {
+           // special events
+         case SDL_VIDEORESIZE: {
+             gfxeng->resize(event.resize.w, event.resize.h);
+             gfxeng->renderScene(true);
+             gfxeng->updateMenu();
+             gfxeng->drawMenu();
+             break;
+         }
+            // keyboard events
+            case SDL_QUIT: {
+                quitGame(0);
+            }
+            case SDL_KEYUP: {
+                switch(event.key.keysym.sym) {
+                    case SDLK_LEFT: {
+                        if (state&INPUT_LEFT) setState(INPUTR_LEFT);
+                        state&=~INPUT_LEFT;
+                        break;
+                    }
+                    case SDLK_RIGHT: {
+                        if (state&INPUT_RIGHT) state|=INPUTR_RIGHT;
+                        state&=~INPUT_RIGHT;
+                        break;
+                    }
+                    case SDLK_UP: {
+                        if (state&INPUT_UP) setState(INPUTR_UP);
+                        state&=~INPUT_UP;
+                        break;
+                    }
+                    case SDLK_DOWN: {
+                        if (state&INPUT_DOWN) setState(INPUTR_DOWN);
+                        state&=~INPUT_DOWN;
+                        break;
+                    }
+                    case SDLK_SPACE: {
+                        if (state&INPUT_SP1) setState(INPUTR_SP1);
+                        state&=~INPUT_SP1;
+                        break;
+                    }
+                    case SDLK_LSHIFT: {
+                        if (state&INPUT_SP2) setState(INPUTR_SP2);
+                        state&=~INPUT_SP2;
+                        break;
+                    }
+                    case SDLK_TAB: {
+                        state&=~INPUT_PAUSE;
+                        break;
+                    }
+                    case SDLK_ESCAPE: {
+                        state&=~INPUT_MENU;
+                        break;
+                    }
+                    case SDLK_RETURN: {
+                        if (state&INPUT_ACT) setState(INPUTR_ACT);
+                        state&=~INPUT_ACT;
+                        break;
+                    }
+                    case SDLK_INSERT: {
+                        if (state&INPUT_USE) setState(INPUTR_USE);
+                        state&=~INPUT_USE;
+                        break;
+                    }
+                    case SDLK_DELETE: {
+                        if (state&INPUT_DEL) setState(INPUTR_DEL);
+                        state&=~INPUT_DEL;
+                        break;
+                    }
+                    default: {
+                        break;
+                    }
+                }
+                break;
+            }
+            case SDL_KEYDOWN: {
+                switch(event.key.keysym.sym) {
+                    case SDLK_LEFT: {
+                        state|=INPUT_LEFT;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_RIGHT: {
+                        state|=INPUT_RIGHT;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_UP: {
+                        if (state&INPUT_UP) break;
+                        menu->increaseEntry(false);
+                        state|=INPUT_UP;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_DOWN: {
+                        if (state&INPUT_DOWN) break;
+                        menu->increaseEntry();
+                        state|=INPUT_DOWN;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_SPACE: {
+                        state|=INPUT_SP1;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_LSHIFT: {
+                        state|=INPUT_SP2;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_RETURN: {
+                        state|=INPUT_ACT;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_INSERT: {
+                        state|=INPUT_USE;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_DELETE: {
+                        state|=INPUT_DEL;
+                        gfxeng->updateMenu();
+                        break;
+                    }
+                    case SDLK_ESCAPE: {
+                         if (state&INPUT_MENU) {
+                             break;
+                         } else if (menu) {
+                             state|=INPUT_MENU;
+                             if (!closeMenu()) {
+                                 gfxeng->renderScene(true);
+                                 scenario->anim->resetTime();
+                                 sfxeng->resumeMusic();
+                             }
+                         } else {
+                             state|=INPUT_MENU;
+                             sfxeng->pauseMusic();
+                             menu=new TestMenu();
+                         }
+                         gfxeng->updateMenu();
+                         break;
+                    }
+                    case SDLK_f: {
+                         gfxeng->toggleFullScreen();
+                         gfxeng->updateMenu();
+                         break;
+                    }
+                    case SDLK_q: {
+                         quitGame(0);
+                         gfxeng->updateMenu();
+                         break;
+                    }
+                    default: {
+                        break;
+                    }
+                }
+                break;
+            }
+            default: {
+                break;
+            }
+        }
+    }    
+}
+
 void InputHandler::pollEvents() {
     SDL_Event event;
 
@@ -30,7 +201,7 @@
              gfxeng->renderScene(true);
              break;
          }
-           // keyboard events
+            // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
             }
@@ -70,6 +241,10 @@
                         state&=~INPUT_PAUSE;
                         break;
                     }
+                    case SDLK_ESCAPE: {
+                        state&=~INPUT_MENU;
+                        break;
+                    }
                     case SDLK_RETURN: {
                         if (state&INPUT_ACT) setState(INPUTR_ACT);
                         state&=~INPUT_ACT;
@@ -151,6 +326,23 @@
                          }
                          break;
                     }
+                    case SDLK_ESCAPE: {
+                         if (state&INPUT_MENU) {
+                             break;
+                         } else if (menu) {   
+                             state|=INPUT_MENU;
+                             if (!closeMenu()) {
+                                 gfxeng->renderScene(true);
+                                 scenario->anim->resetTime();
+                                 sfxeng->resumeMusic();
+                             }
+                         } else {
+                             state|=INPUT_MENU;
+                             sfxeng->pauseMusic();
+                             menu=new TestMenu();
+                         }
+                         break;
+                    }
                     case SDLK_F1: {
                          gfxeng->togglePlayerBar();
                          break;

Modified: trunk/src/input.h
===================================================================
--- trunk/src/input.h	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/input.h	2005-02-10 23:45:16 UTC (rev 88)
@@ -21,16 +21,22 @@
 #define INPUTR_USE      0x00800000
 #define INPUTR_DEL      0x01000000
 #define INPUT_PAUSE     0x10000000
+#define INPUT_MENU      0x20000000
 
 /** \brief Handels keyboard events
 
+    \remark A key release event which is passed on to the AnimHandler
+      mustn't be cummulative (see player code as well). Ie. If the event
+      is triggered twice it should do the same as if once... 
 */
 class InputHandler {
     public:
         InputHandler();
         ~InputHandler();
-        /// Check for keyboard events
+        /// Check for keyboard events in game
         void pollEvents();
+        /// Check for keyboard events in menu
+        void pollMEvents();
         bool getState(Uint32 cstate) {
             return (state&cstate);
         }
@@ -40,6 +46,9 @@
         void unsetState(Uint32 cstate) {
             state&=~cstate;
         }
+        void clearStates() {
+            state=NOTHING;
+        }
     private:
         /// Information about which buttons are pressed
         Uint32 state;

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/lost_penguins.cpp	2005-02-10 23:45:16 UTC (rev 88)
@@ -9,6 +9,7 @@
 #include "gfxeng.h"
 #include "sfxeng.h"
 #include "objectpools.h"
+#include "menu.h"
 #include "players_common.h"
 
 
@@ -43,22 +44,33 @@
     sfxeng=new SoundsEngine();
     cout << "Fonts...\n";
     font=new Font(imgcache->loadImage("font_arial_white_16_01.png"));
-    font2=new Font(imgcache->loadImage("font_arial_12_01.bmp"));
+    font2=new Font(imgcache->loadImage("font_arial_red_16_01.png"));
     cout << "InputHandler...\n";
     input=new InputHandler();
-    //TODO: menu, szenarios, etc
     cout << "Initializing Scenario...\n";
     scenario=new Scenario();
+
+    //TODO: menu, szenarios, etc
+
+    //gfxeng->setMenuBG();
+    //menu=new TestMenu();
+
     scenario->loadMap(config.map);
+    cout << "Starting game...\n" << endl;
 
-    cout << "Starting game...\n" << endl;
     while (true) {
-        //Drawing
-        gfxeng->renderScene();
-        //Check input
-        input->pollEvents();
-        //Run Animations
-        scenario->anim->runAnims();
+        if (menu) {
+            gfxeng->drawMenu();
+            input->pollMEvents();
+        } else if (running) {
+            gfxeng->renderScene();
+            //Check input
+            input->pollEvents();
+            //Run Animations
+            scenario->anim->runAnims();
+        } else {
+            quitGame(-6);
+        }
     }
 
     quitGame(-2);
@@ -66,6 +78,7 @@
 
 int quitGame(int errorcode=0) {
     cout << endl << "Quitting game (exit code: " << errorcode << ")...\n";
+    closeMenus();
     delete scenario;
     cout << "Scenario closed...\n";
     delete sfxeng;

Added: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/menu.cpp	2005-02-10 23:45:16 UTC (rev 88)
@@ -0,0 +1,32 @@
+#include "common.h"
+#include "gfxeng.h"
+#include "menu.h"
+
+Menu::Menu():
+  title("MENU"),
+  last(NULL),
+  currententry(0),
+  //don't forget the "::"
+  font(::font),
+  font_title(font),
+  font_high(font2) {
+}
+Menu::~Menu() { }
+void Menu::increaseEntry(bool forward) {
+    if (forward) {
+        if (currententry<(entries.size()-1)) currententry++;
+    } else {
+        if (currententry>0) currententry--;
+    }
+}
+
+TestMenu::TestMenu(): Menu() { init(); }
+void TestMenu::act() { }
+void TestMenu::init() {
+    title="-== TEST MENU ==-";
+    entries.resize(4);
+    entries[0]="FPS: " + itos(gfxeng->getFPS());
+    entries[1]="Start Game";
+    entries[2]="Configuration";
+    entries[3]="Quit";
+}

Added: trunk/src/menu.h
===================================================================
--- trunk/src/menu.h	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/menu.h	2005-02-10 23:45:16 UTC (rev 88)
@@ -0,0 +1,66 @@
+#ifndef _MENU_H
+#define _MENU_H 1
+
+/** \brief abstract menu base class
+
+    Abstract base class for menus. The main part is in the constructor and in the
+    virtual function act(), overload it in the child classes. Only the base class
+    is needed to draw the menu in gfxeng. The background depends from where the
+    menu is called.
+
+    \todo Create the actual menus (StartMenu, etc)...
+*/
+class Menu {
+    friend class GraphicsEngine;
+    public:
+        Menu();
+        virtual ~Menu();
+        /// Name of the menu
+        string title;
+        /// Main menu function, depends on currententry (changed by input), overload this.
+        virtual void act() = 0;
+        void setLast(Menu* lastmenu) {
+            last=lastmenu;
+        }
+        Menu* getLast() {
+            return last;
+        }
+        Uint8 getSize() {
+            return entries.size();
+        }
+        void increaseEntry(bool forward=true);
+    protected:
+        /// Pointer to the last used menu. NULL if there is no last menu.
+        Menu* last;
+        /// Currently selected menu entry
+        Uint8 currententry;
+        /// List of all Menu entry names
+        std::vector<string> entries;
+        /// Font for non highlighted menu entries
+        Font* font;
+        /// Font for the menu title
+        Font* font_title;
+        /// Font for the selected menu entry
+        Font* font_high;
+};
+
+class StartMenu : public Menu {
+    public:
+        StartMenu();
+        virtual ~StartMenu();
+        virtual void act();
+    private:
+        /// Helper function
+        void init();
+};
+
+class TestMenu : public Menu {
+    public:
+        TestMenu();
+        virtual void act();
+    private:
+        /// Helper function
+        void init();
+};
+
+#endif

Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp	2005-02-09 22:35:03 UTC (rev 87)
+++ trunk/src/scenario.cpp	2005-02-10 23:45:16 UTC (rev 88)
@@ -124,6 +124,7 @@
         if (pool->playerspool.size()>0) player=*pool->playerspool.begin();
         else player=NULL;
         if (player==NULL) cout << "No player found!\n";
+        running=true;
         return 0;
     } else {
        cout << "Map loading failed: No background found!\n";




More information about the lostpenguins-commits mailing list