~ubuntu-branches/ubuntu/precise/supertuxkart/precise

« back to all changes in this revision

Viewing changes to src/gui/CharSel.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Gonéri Le Bouder, Gonéri Le Bouder, Eddy Petrişor
  • Date: 2006-09-08 22:59:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060908225925-3spug0pnh9ekwlpw
Tags: 0.2-1
[ Gonéri Le Bouder ]
* new upstream release candidate
 + Closes: #388021
 + remove supertuxkart.sh
 + add supertuxkart(|-data).install
 + clean up
 + remove deps on ${shlibs:Depends}, ${misc:Depends} for supertuxkart-data
* fix French comment was tagged de_DE
* fix not-binnmuable-any-depends-all
* fix FTBFS on 64bit arch
 + Closes: #370810

[ Eddy Petrişor ]
* added Romanian translation to desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  $Id: CharSel.cxx 493 2004-12-21 03:12:00Z grumbel $
2
 
//
3
 
//  TuxKart - a fun racing game with go-kart
4
 
//  Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
5
 
//
6
 
//  This program is free software; you can redistribute it and/or
7
 
//  modify it under the terms of the GNU General Public License
8
 
//  as published by the Free Software Foundation; either version 2
9
 
//  of the License, or (at your option) any later version.
10
 
//
11
 
//  This program is distributed in the hope that it will be useful,
12
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
//  GNU General Public License for more details.
15
 
//
16
 
//  You should have received a copy of the GNU General Public License
17
 
//  along with this program; if not, write to the Free Software
18
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 
 
20
 
#include <set>
21
 
#include <iostream>
22
 
#include "sdldrv.h"
23
 
#include "Loader.h"
24
 
#include "CharSel.h"
25
 
#include "tuxkart.h"
26
 
#include "Loader.h"
27
 
#include "material.h"
28
 
#include "KartManager.h"
29
 
#include "preprocessor.h"
30
 
#include "WidgetSet.h"
31
 
#include "RaceManager.h"
32
 
#include "StartScreen.h"
33
 
 
34
 
CharSel::CharSel(int whichPlayer)
35
 
  : kart(0), playerIndex(whichPlayer)
36
 
{
37
 
        current_kart = -1;
38
 
        switch_to_character(3);
39
 
 
40
 
        // for some strange reasons plib calls makeCurrent() in ssgContext
41
 
        // constructor, so we have to save the old one here and restore it
42
 
        ssgContext* oldContext = ssgGetCurrentContext();
43
 
        context = new ssgContext;
44
 
        oldContext->makeCurrent();
45
 
 
46
 
        menu_id = widgetSet -> vstack(0);
47
 
        char output[60];
48
 
        sprintf(output, "Player %d, choose your character", playerIndex + 1);
49
 
        widgetSet -> label(menu_id, output, GUI_LRG, GUI_ALL, 0, 0);
50
 
        widgetSet -> space(menu_id);
51
 
 
52
 
        int ha = widgetSet -> harray(menu_id);
53
 
        widgetSet -> filler(ha);
54
 
        int va = widgetSet -> varray(ha);
55
 
 
56
 
        int icon_size = 64;
57
 
 
58
 
        int row1 = widgetSet -> harray(va);
59
 
        for(KartManager::KartPropertiesVector::size_type i = 0;
60
 
            i < kart_manager.karts.size(); ++i)
61
 
        {
62
 
                //widgetSet ->state(row2, kart_manager.karts[i].name.c_str(), GUI_MED, i, 0);
63
 
                int c = widgetSet -> image(row1,
64
 
                    loader->getPath(
65
 
                      "images/" + kart_manager.karts[i]->icon_file).c_str(),
66
 
                    icon_size, icon_size);
67
 
                widgetSet -> activate_widget(c, i, 0);
68
 
                
69
 
                if (i == kart_manager.karts.size() - 1)
70
 
                        widgetSet -> set_active(c);
71
 
        }
72
 
 
73
 
        if (0)
74
 
        {
75
 
                int row2 = widgetSet -> harray(va);
76
 
                for(KartManager::KartPropertiesVector::size_type i = 0;
77
 
                    i < kart_manager.karts.size()/2; ++i)
78
 
                {
79
 
                        //widgetSet ->state(row1, kart_manager.karts[i].name.c_str(), GUI_MED, i, 0);
80
 
                        // FIXME: images needs to be 'clickable'
81
 
                        int c = widgetSet -> image(row1,
82
 
                            loader->getPath(
83
 
                              "images/" + kart_manager.karts[i]->icon_file).c_str(),
84
 
                            icon_size, icon_size);
85
 
                        widgetSet -> activate_widget(c, i, 0);
86
 
                }
87
 
                for(KartManager::KartPropertiesVector::size_type i =
88
 
                    kart_manager.karts.size()/2; i < kart_manager.karts.size(); ++i)
89
 
                {
90
 
                        //widgetSet ->state(row2, kart_manager.karts[i].name.c_str(), GUI_MED, i, 0);
91
 
                        int c = widgetSet -> image(row2,
92
 
                            loader->getPath("images/" + kart_manager.karts[i]->icon_file).c_str(), icon_size, icon_size);
93
 
                        widgetSet -> activate_widget(c, i, 0);
94
 
                }
95
 
        }
96
 
 
97
 
 
98
 
        widgetSet -> filler(ha);
99
 
 
100
 
        widgetSet -> layout(menu_id, 0, 1);
101
 
 
102
 
        clock = 0;
103
 
        //test
104
 
 
105
 
}
106
 
 
107
 
CharSel::~CharSel()
108
 
{
109
 
        widgetSet -> delete_widget(menu_id) ;
110
 
        ssgDeRefDelete(kart);
111
 
 
112
 
        delete context;
113
 
}
114
 
 
115
 
void CharSel::switch_to_character(int n)
116
 
{
117
 
        if (current_kart != n && n >= 0 && n < int(kart_manager.karts.size()))
118
 
        {
119
 
                current_kart = n;
120
 
                ssgDeRefDelete(kart);
121
 
                kart = new ssgTransform;
122
 
                kart->ref();
123
 
                ssgEntity* kartentity = kart_manager.karts[n]->getModel();
124
 
 
125
 
                kart->addKid(kartentity);
126
 
 
127
 
                preProcessObj ( kart, 0 );
128
 
        }
129
 
}
130
 
        
131
 
void CharSel::update(float dt)
132
 
{
133
 
        clock += dt * 40.0f;
134
 
 
135
 
        widgetSet -> timer(menu_id, dt) ;
136
 
        widgetSet -> paint(menu_id) ;
137
 
 
138
 
        switch_to_character(widgetSet->token(widgetSet->click()));
139
 
 
140
 
        if (kart)
141
 
        {
142
 
                ssgContext* oldContext = ssgGetCurrentContext();
143
 
                context -> makeCurrent();                                   
144
 
            
145
 
                glClear(GL_DEPTH_BUFFER_BIT);
146
 
                // FIXME: A bit hackish...
147
 
                glViewport ( 0, 0, 800, 320);
148
 
 
149
 
                context -> setFOV ( 45.0f, 45.0f * 320.0f/800.0f ) ;
150
 
                context -> setNearFar ( 0.05f, 1000.0f ) ;
151
 
 
152
 
                sgCoord cam_pos;
153
 
                sgSetCoord(&cam_pos, 0, 0, 0, 0, 0, 0);
154
 
                context -> setCamera ( &cam_pos ) ;
155
 
 
156
 
                glEnable (GL_DEPTH_TEST);
157
 
                sgCoord trans;
158
 
                sgSetCoord(&trans, 0, 3, -.4, clock, 0, 0);
159
 
                kart->setTransform (&trans) ;
160
 
                //glShadeModel(GL_SMOOTH);
161
 
                ssgCullAndDraw ( kart ) ;
162
 
 
163
 
                glViewport ( 0, 0, getScreenWidth(), getScreenHeight() ) ;
164
 
 
165
 
                glDisable (GL_DEPTH_TEST);
166
 
                oldContext->makeCurrent();
167
 
        }
168
 
}
169
 
 
170
 
void CharSel::select()
171
 
{
172
 
        int token = widgetSet -> token (widgetSet -> click());
173
 
 
174
 
        if (token >= 0 && token < static_cast<int>(kart_manager.karts.size()))
175
 
          RaceManager::instance()->setPlayerKart(playerIndex,
176
 
              kart_manager.getKartById(token)->ident);
177
 
 
178
 
        if (RaceManager::instance()->getNumPlayers() > 1)
179
 
        {
180
 
                if (guiStack.back() == GUIS_CHARSEL)
181
 
                {
182
 
                        guiStack.push_back(GUIS_CHARSELP2); 
183
 
                        return;
184
 
                }
185
 
                        
186
 
                if (RaceManager::instance()->getNumPlayers() > 2)
187
 
                {
188
 
                        if (guiStack.back() == GUIS_CHARSELP2)
189
 
                        {
190
 
                                guiStack.push_back(GUIS_CHARSELP3); 
191
 
                                return;
192
 
                        }
193
 
 
194
 
                        if (RaceManager::instance()->getNumPlayers() > 3)
195
 
                        {
196
 
                                if (guiStack.back() == GUIS_CHARSELP3)
197
 
                                {
198
 
                                        guiStack.push_back(GUIS_CHARSELP4); 
199
 
                                        return;
200
 
                                }
201
 
                        }       
202
 
                }       
203
 
        }
204
 
        
205
 
        if (RaceManager::instance()->getRaceMode() != RaceSetup::RM_GRAND_PRIX)
206
 
          guiStack.push_back(GUIS_TRACKSEL); 
207
 
        else
208
 
          startScreen->switchToGame();
209
 
}
210
 
 
211