~ubuntu-branches/ubuntu/natty/balder2d/natty

« back to all changes in this revision

Viewing changes to src/menu/menu.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bjørn Hansen
  • Date: 2008-06-15 17:15:38 UTC
  • mfrom: (1.1.1 upstream) (3.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080615171538-e407e07wbtdy0qs8
Tags: 1.0-1
* new upstream release
* update for guichan 8.1 (Closes: #482584)
* use physicsfs to make data/config/map/aiscript loading more flexible
* new skins for menus
* fix typo in control file long description (Closes: #458401)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 ***************************************************************************/
20
20
 
21
21
#include <SDL/SDL_mixer.h>
22
 
#include "../../include/menu/menu.h"
23
 
#include "../../include/menu/mainmenu.h"
24
 
#include "../../include/soundmanager.h"
 
22
#include "menu/menu.h"
 
23
#include "menu/mainmenu.h"
 
24
#include "soundmanager.h"
 
25
#include "imageloader.h"
 
26
#include "renderer.h"
25
27
#include <iostream>
26
28
 
27
29
using namespace Balder;
28
30
 
29
31
SDLKey Menu::lastKeyPressed = SDLKey(0);
30
32
 
31
 
Menu::Menu(SoundManager* s): startgame(false), sound(s)
 
33
Menu::Menu(Renderer *r, SoundManager* s): startgame(false), render(r), sound(s)
32
34
{
33
35
  //screen = SDL_GetVideoSurface();
34
36
 
60
62
  // Load the image font.
61
63
  try
62
64
  {
63
 
    font = new gcn::ImageFont("menu/balderfont.png");
 
65
    font = ImageLoader::LoadGcnImageFont("menu/balderfont.png");
64
66
  }
65
67
  catch(gcn::Exception e)
66
68
  {
68
70
  }
69
71
  // The global font is static and must be set.
70
72
  gcn::Widget::setGlobalFont(font);
71
 
 
72
73
  // create top level wigets we want on all menus
73
 
  headerImage = new gcn::Image("menu/balderheader.png");
 
74
  pulseAnimation = new Animation(/* Film Strip File Name */"menu/pulse1.png",
 
75
    /* Has Base Frame */true, /* Is Looped */true, /* Play when finished loading */true,
 
76
    /* Strip Location */ 0, /* Frame Width */100, /* Frame Height */100, /* Base Frame Index */0,
 
77
    /* Starting Frame Index */1, /* Animation Frame Quantity Including Starting Frame */3,
 
78
    /* Frame Interval in MS (1Sec == 1000MS) */115);
 
79
  twinkleAnimation = new Animation(/* Film Strip File Name */"menu/twinkle1.png",
 
80
    /* Has Base Frame */true, /* Is Looped */true, /* Play when finished loading */true,
 
81
    /* Strip Location */ 0, /* Frame Width */100, /* Frame Height */100, /* Base Frame Index */0,
 
82
    /* Starting Frame Index */1, /* Animation Frame Quantity Including Starting Frame */3,
 
83
    /* Frame Interval in MS (1Sec == 1000MS) */1);
 
84
  backgroundImage = ImageLoader::LoadGcnImage("menu/menubackground.png");
 
85
  backgroundIcon = new gcn::Icon(backgroundImage);
 
86
  headerImage = ImageLoader::LoadGcnImage("menu/balderheader.png");
74
87
  headerIcon = new gcn::Icon(headerImage);
 
88
  topContainer->add(backgroundIcon, 0, 0);
 
89
  topContainer->add(pulseAnimation,575,50);
 
90
  topContainer->add(twinkleAnimation,600,420);
75
91
  topContainer->add(headerIcon, 250, 40);
76
92
 
77
93
  // now initialize menus
94
110
bool Menu::Run()
95
111
{
96
112
  screen = SDL_GetVideoSurface();
97
 
  graphics->setTarget(screen);
 
113
  graphics->setTarget(screen);
 
114
  bool fullscreen;
98
115
  running = true;
99
116
  while(running)
100
117
  {
 
118
    // Set fullscreen status for menu.
 
119
    if (fullscreen != ConfigManager::GetIntValue("Video", "fullscreen")) {
 
120
        fullscreen = ConfigManager::GetIntValue("Video", "fullscreen");
 
121
        render->SetScreen(800, 600, fullscreen);
 
122
    }
 
123
 
 
124
    // Check to see if music is playing.
101
125
    if (!sound->IsMusicPlaying())
102
126
    {
103
127
      sound->PlayMusic("menu");
111
135
    // update the screen
112
136
    SDL_UpdateRect(screen,0,0,0,0);
113
137
  }
114
 
  Menu::action("saveSettings");
115
138
  if (startgame)
116
139
  {
117
140
    return true;
119
142
  return false;
120
143
}
121
144
 
122
 
void Menu::action(const std::string& action)
 
145
void Menu::action(const gcn::ActionEvent& action)
123
146
{
124
147
  // Main menu events.********************************************************
125
 
  if (action == "startgame")
 
148
  if (action.getId() == "startgame")
126
149
  {
127
150
    running = false;
128
151
    startgame = true;
129
152
  }
130
 
  else if (action == "quitgame")
 
153
  else if (action.getId() == "quitgame")
131
154
  {
132
155
    running = false;
133
156
    startgame = false;
145
168
    if (event.type == SDL_KEYDOWN)
146
169
    {
147
170
        Menu::lastKeyPressed = event.key.keysym.sym;
148
 
//       if (event.key.keysym.sym == SDLK_ESCAPE)
149
 
//       {
150
 
//         if (bindNextKey)
151
 
//         {
152
 
//           bindNextKey = false;
153
 
//           RefreshKeys();
154
 
//         }
155
 
//         else
156
 
//         {
157
 
//           running = false;
158
 
//           startgame = false;
159
 
//         }
160
 
//       }
161
 
//       if (bindNextKey)
162
 
//       {
163
 
//         ConfigManager::SetPlayerControl(currentPlayer, actionToBind,
164
 
//                                         Input::GetKeyString(event.key.keysym.sym));
165
 
//         bindNextKey = false;
166
 
//         RefreshKeys();
167
 
//       }
168
171
    }
169
172
   else if(event.type == SDL_QUIT)
170
173
    {