~ubuntu-branches/ubuntu/natty/smc/natty

« back to all changes in this revision

Viewing changes to src/objects/levelexit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Muammar El Khatib
  • Date: 2008-10-20 00:31:35 UTC
  • mfrom: (1.1.4 upstream) (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081020003135-5ac8cpecomfohvv5
Tags: 1.6-1
* New upstream release. (Closes:#479415)
* Bumped standards version to 3.8.0.
* debian/control: dpatch build dependency has been removed temporarily.
* debian/control: smc-data does not depend on smc anymore. This change will
  avoid a circular dependency. (Closes: #478712)
* smc does not segfault. (Closes: #500039, #491590) 
* Icon is not missed in Gnome Menu. Thanks to Saïvann for providing a 
  solution. (Closes: #491885)
* debian/control: smc-data's and smc-music's descriptions have been improved.
  (Closes: #493630)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
     levelexit.cpp  -  area to exit the current level
3
 
                             -------------------
4
 
    copyright            :      (C) 2003 - 2007 by Florian Richter
 
2
 * levelexit.cpp  -  area to exit the current level
 
3
 *
 
4
 * Copyright (C) 2003 - 2008 Florian Richter
5
5
 ***************************************************************************/
6
6
/*
7
7
   This program is free software; you can redistribute it and/or modify
25
25
#include "../video/font.h"
26
26
#include "../video/renderer.h"
27
27
#include "../level/level.h"
 
28
#include "../core/i18n.h"
28
29
 
29
30
/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
30
31
 
31
32
cLevel_Exit :: cLevel_Exit( float x, float y )
32
33
: cImageObjectSprite( x, y )
33
34
{
34
 
        Init();
 
35
        cLevel_Exit::Init();
35
36
}
36
37
 
37
 
cLevel_Exit :: cLevel_Exit( XMLAttributes &attributes )
 
38
cLevel_Exit :: cLevel_Exit( CEGUI::XMLAttributes &attributes )
38
39
: cImageObjectSprite()
39
40
{
40
 
        Init();
41
 
        Create_from_Stream( attributes );
 
41
        cLevel_Exit::Init();
 
42
        cLevel_Exit::Create_from_Stream( attributes );
42
43
}
43
44
 
44
45
cLevel_Exit :: ~cLevel_Exit( void )
53
54
void cLevel_Exit :: Init( void )
54
55
{
55
56
        sprite_array = ARRAY_ACTIVE;
56
 
        type = TYPE_LEVELEXIT;
 
57
        type = TYPE_LEVEL_EXIT;
57
58
        massivetype = MASS_PASSIVE;
58
59
        editor_posz = 0.111f;
59
60
        player_range = 1000;
81
82
        level_exit->Set_Type( exit_type );
82
83
        level_exit->Set_Direction( start_direction );
83
84
        level_exit->Set_Level( dest_level );
 
85
        level_exit->Set_Entry( dest_entry );
84
86
 
85
87
        return level_exit;
86
88
}
87
89
 
88
 
void cLevel_Exit :: Create_from_Stream( XMLAttributes &attributes )
 
90
void cLevel_Exit :: Create_from_Stream( CEGUI::XMLAttributes &attributes )
89
91
{
90
92
        // position
91
93
        Set_Pos( static_cast<float>(attributes.getValueAsInteger( "posx" )), static_cast<float>(attributes.getValueAsInteger( "posy" )), 1 );
92
94
        // type
93
 
        Set_Type( (Level_Exit_type)attributes.getValueAsInteger( "type", exit_type ) );
 
95
        Set_Type( static_cast<Level_Exit_type>(attributes.getValueAsInteger( "type", exit_type )) );
94
96
        // destination level
95
97
        Set_Level( attributes.getValueAsString( "level_name" ).c_str() );
96
98
        // destination entry
98
100
        // direction
99
101
        if( exit_type == LEVELEXIT_WARP )
100
102
        {
101
 
                Set_Direction( Get_Direction_id( attributes.getValueAsString( "direction", Get_Direction_name( start_direction ) ).c_str() ) );
 
103
                Set_Direction( Get_Direction_Id( attributes.getValueAsString( "direction", Get_Direction_Name( start_direction ) ).c_str() ) );
102
104
        }
103
105
}
104
106
 
129
131
        if( exit_type == LEVELEXIT_WARP )
130
132
        {
131
133
                // direction
132
 
                file << "\t\t<Property name=\"direction\" value=\"" << Get_Direction_name( start_direction ) << "\" />" << std::endl;
 
134
                file << "\t\t<Property name=\"direction\" value=\"" << Get_Direction_Name( start_direction ) << "\" />" << std::endl;
133
135
        }
134
136
 
135
137
        // end levelexit
151
153
 
152
154
void cLevel_Exit :: Create_Name( void )
153
155
{
154
 
    name = "Level";
 
156
    name = _("Level");
155
157
 
156
158
    if( exit_type == LEVELEXIT_BEAM )
157
159
    {
158
 
        name += " Beam";
 
160
        name += _(" Beam");
159
161
    }
160
162
    else if( exit_type == LEVELEXIT_WARP )
161
163
    {
162
 
                name += " Warp";
 
164
                name += _(" Warp");
163
165
 
164
166
                if( direction == DIR_UP )
165
167
                {
187
189
                return;
188
190
        }
189
191
 
190
 
        // editor enabled
191
 
        if( !editor_level_enabled )
192
 
        {
193
 
                return;
194
 
        }
195
 
 
196
192
        // draw color rect
197
 
        pVideo->Draw_Rect( col_rect.x - pCamera->x, col_rect.y - pCamera->y, col_rect.w, col_rect.h, editor_posz, &editor_color );
 
193
        pVideo->Draw_Rect( col_rect.x - pActive_Camera->x, col_rect.y - pActive_Camera->y, col_rect.w, col_rect.h, editor_posz, &editor_color );
198
194
 
199
195
        // draw destination entry name
200
196
        if( editor_entry_name )
202
198
                // create request
203
199
                cSurfaceRequest *surface_request = new cSurfaceRequest();
204
200
                // blit
205
 
                editor_entry_name->Blit( col_rect.x + col_rect.w + 5 - pCamera->x, col_rect.y - pCamera->y, editor_posz, surface_request );
 
201
                editor_entry_name->Blit( col_rect.x + col_rect.w + 5 - pActive_Camera->x, col_rect.y - pActive_Camera->y, editor_posz, surface_request );
206
202
                surface_request->shadow_pos = 2;
207
203
                surface_request->shadow_color = lightgreyalpha64;
208
204
                // add request
212
208
 
213
209
void cLevel_Exit :: Activate( void )
214
210
{
215
 
        pAudio->FadeOutMusic( 500 );
 
211
        // if leaving level
 
212
        if( dest_level.empty() && dest_entry.empty() )
 
213
        {
 
214
                // fade out music
 
215
                pAudio->Fadeout_Music( 500 );
 
216
        }
216
217
 
217
218
        // warp player out
218
219
        if( exit_type == LEVELEXIT_WARP )
219
220
        {
220
 
                pAudio->PlaySound( "enter_pipe.ogg" );
 
221
                pAudio->Play_Sound( "enter_pipe.ogg" );
221
222
 
222
 
                pPlayer->Set_MovingState( STA_FALL );
 
223
                pPlayer->Set_Moving_State( STA_FALL );
223
224
                pPlayer->Set_Image( pPlayer->Get_Image() + pPlayer->direction );
224
 
                pPlayer->Stop_ducking();
225
 
                pPlayer->Reset_onGround();
 
225
                pPlayer->Stop_Ducking();
 
226
                pPlayer->Reset_on_Ground();
226
227
 
227
228
                // set position and image
228
229
                if( direction == DIR_UP || direction == DIR_DOWN )
229
230
                {
230
 
                        pPlayer->Set_PosX( col_rect.x - pPlayer->col_pos.x + ( col_rect.w * 0.5f ) - ( pPlayer->col_rect.w * 0.5f ) );
 
231
                        pPlayer->Set_Pos_X( col_rect.x - pPlayer->col_pos.x + ( col_rect.w * 0.5f ) - ( pPlayer->col_rect.w * 0.5f ) );
231
232
                }
232
233
                else if( direction == DIR_LEFT || direction == DIR_RIGHT )
233
234
                {
234
 
                        pPlayer->Set_PosY( col_rect.y - pPlayer->col_pos.y + ( col_rect.h * 0.5f ) - ( pPlayer->col_rect.h * 0.5f ) );
 
235
                        pPlayer->Set_Pos_Y( col_rect.y - pPlayer->col_pos.y + ( col_rect.h * 0.5f ) - ( pPlayer->col_rect.h * 0.5f ) );
235
236
 
236
237
                        // set rotation
237
238
                        if( direction == DIR_RIGHT )
238
239
                        {
239
 
                                pPlayer->Set_RotationZ( 90 );
 
240
                                pPlayer->Set_Rotation_Z( 90 );
240
241
                        }
241
242
                        else if( direction == DIR_LEFT )
242
243
                        {
243
 
                                pPlayer->Set_RotationZ( 270 );
 
244
                                pPlayer->Set_Rotation_Z( 270 );
244
245
                        }
245
246
                }
246
247
 
247
248
                float player_posz = pPlayer->posz;
248
 
                pPlayer->posz = 0.0799f; // just before massive
 
249
                // posz just before massive
 
250
                pPlayer->posz = 0.0799f;
249
251
 
250
 
                for( float i = 0; i < ( DESIRED_FPS * 0.9f ); i += pFramerate->speedfactor )
 
252
                for( float i = 0; i < ( speedfactor_fps * 0.9f ); i += pFramerate->speedfactor )
251
253
                {
252
254
                        if( direction == DIR_DOWN )
253
255
                        {
280
282
 
281
283
                if( direction == DIR_RIGHT || direction == DIR_LEFT )
282
284
                {
283
 
                        pPlayer->Set_RotationZ( 0 );
 
285
                        pPlayer->Set_Rotation_Z( 0 );
284
286
                }
285
287
        }
286
288
 
287
289
        pPlayer->Collisions_Clear();
288
290
 
289
 
        if( dest_level.length() )
 
291
        // exit level
 
292
        if( dest_level.empty() && dest_entry.empty() )
290
293
        {
291
 
                pPlayer->Goto_SubLevel( dest_level, dest_entry );
 
294
                pAudio->Play_Music( "game/courseclear.ogg" );
 
295
                pPlayer->Goto_Next_Level();
292
296
        }
 
297
        // enter entry
293
298
        else
294
299
        {
295
 
                pAudio->PlayMusic( "game/courseclear.ogg" );
296
 
                pPlayer->Goto_next_Level();
 
300
                pPlayer->Goto_Sub_Level( dest_level, dest_entry );
297
301
        }
298
302
}
299
303
 
306
310
 
307
311
void cLevel_Exit :: Set_Level( string filename )
308
312
{
309
 
        if( filename.empty() )
 
313
        if( filename.empty() && dest_entry.empty() )
310
314
        {
311
315
                dest_level.clear();
312
316
                // red for no destination level
320
324
        editor_color.alpha = 128;
321
325
 
322
326
        // erase file type and directory if set
323
 
        dest_level = Get_filename( filename, 0, 0 );
 
327
        dest_level = Get_Filename( filename, 0, 0 );
324
328
}
325
329
 
326
330
void cLevel_Exit :: Set_Entry( string entry_name )
340
344
                return;
341
345
        }
342
346
 
343
 
        editor_entry_name = pFont->RenderText( pFont->font_small, dest_entry, white );
 
347
        editor_entry_name = pFont->Render_Text( pFont->font_small, dest_entry, white );
344
348
}
345
349
 
346
350
string cLevel_Exit :: Get_Level( bool with_dir /* = 1 */, bool with_end /* = 1 */ )
348
352
        string name = dest_level;
349
353
 
350
354
        // Get level
351
 
        pLevel->Get_path( name );
 
355
        pActive_Level->Get_Path( name );
352
356
 
353
357
        // return
354
 
        return Get_filename( name, with_dir, with_end );
 
358
        return Get_Filename( name, with_dir, with_end );
355
359
}
356
360
 
357
 
bool cLevel_Exit :: is_Draw_valid( void )
 
361
bool cLevel_Exit :: Is_Draw_Valid( void )
358
362
{
359
363
        // if editor not enabled
360
364
        if( !editor_enabled )
361
365
        {
362
 
                // not visible
363
 
                if( !visible || !image )
364
 
                {
365
 
                        return 0;
366
 
                }
 
366
                return 0;
367
367
        }
368
368
 
369
 
        // not visible on the screen
370
 
        if( !is_Visible_onScreen() )
 
369
        // if not visible on the screen
 
370
        if( !visible || !Is_Visible_on_Screen() )
371
371
        {
372
372
                return 0;
373
373
        }
377
377
 
378
378
void cLevel_Exit :: Editor_Activate( void )
379
379
{
380
 
        WindowManager &wmgr = WindowManager::getSingleton();
 
380
        CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
381
381
 
382
382
        // warp
383
383
        if( exit_type == LEVELEXIT_WARP )
384
384
        {
385
385
                // direction
386
 
                Combobox *combobox = static_cast<Combobox *>(wmgr.createWindow( "TaharezLook/Combobox", "level_exit_direction" ));
387
 
                combobox->getEditbox()->setTooltipText( "Direction" );
388
 
                Editor_Add( combobox, 100, 105 );
389
 
 
390
 
                combobox->addItem( new ListboxTextItem( "up" ) );
391
 
                combobox->addItem( new ListboxTextItem( "down" ) );
392
 
                combobox->addItem( new ListboxTextItem( "right" ) );
393
 
                combobox->addItem( new ListboxTextItem( "left" ) );
394
 
                combobox->setText( Get_Direction_name( start_direction ) );
395
 
 
396
 
                combobox->subscribeEvent( Combobox::EventListSelectionAccepted, Event::Subscriber( &cLevel_Exit::Editor_Direction_Select, this ) );
 
386
                CEGUI::Combobox *combobox = static_cast<CEGUI::Combobox *>(wmgr.createWindow( "TaharezLook/Combobox", "level_exit_direction" ));
 
387
                Editor_Add( UTF8_("Direction"), UTF8_("Direction to move in"), combobox, 100, 105 );
 
388
 
 
389
                combobox->addItem( new CEGUI::ListboxTextItem( "up" ) );
 
390
                combobox->addItem( new CEGUI::ListboxTextItem( "down" ) );
 
391
                combobox->addItem( new CEGUI::ListboxTextItem( "right" ) );
 
392
                combobox->addItem( new CEGUI::ListboxTextItem( "left" ) );
 
393
                combobox->setText( Get_Direction_Name( start_direction ) );
 
394
 
 
395
                combobox->subscribeEvent( CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber( &cLevel_Exit::Editor_Direction_Select, this ) );
397
396
        }
398
397
 
399
398
        // destination level
400
 
        Editbox *editbox = static_cast<Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "level_exit_destination_level" ));
401
 
        editbox->setTooltipText( "Destination Level" );
402
 
        Editor_Add( editbox, 150 );
 
399
        CEGUI::Editbox *editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "level_exit_destination_level" ));
 
400
        Editor_Add( UTF8_("Destination Level"), UTF8_("Name of the level that should be entered. If empty uses the current level."), editbox, 150 );
403
401
 
404
402
        editbox->setText( Get_Level( 0, 0 ) );
405
 
        editbox->subscribeEvent( Editbox::EventKeyUp, Event::Subscriber( &cLevel_Exit::Editor_Destination_Level_Key, this ) );
 
403
        editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cLevel_Exit::Editor_Destination_Level_Key, this ) );
406
404
 
407
405
        // destination entry
408
 
        editbox = static_cast<Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "level_exit_destination_entry" ));
409
 
        editbox->setTooltipText( "Destination Entry" );
410
 
        Editor_Add( editbox, 150 );
 
406
        editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "level_exit_destination_entry" ));
 
407
        Editor_Add( UTF8_("Destination Entry"), UTF8_("Name of the Entry in the destination level. If empty the entry point is the player start position."), editbox, 150 );
411
408
 
412
409
        editbox->setText( dest_entry.c_str() );
413
 
        editbox->subscribeEvent( Editbox::EventKeyUp, Event::Subscriber( &cLevel_Exit::Editor_Destination_Entry_Key, this ) );
 
410
        editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cLevel_Exit::Editor_Destination_Entry_Key, this ) );
414
411
 
415
 
        // set position
416
 
        Editor_pos_update();
 
412
        // init
 
413
        Editor_Init();
417
414
}
418
415
 
419
 
bool cLevel_Exit :: Editor_Direction_Select( const EventArgs &event )
 
416
bool cLevel_Exit :: Editor_Direction_Select( const CEGUI::EventArgs &event )
420
417
{
421
 
        const WindowEventArgs &windowEventArgs = static_cast<const WindowEventArgs&>( event );
422
 
        ListboxItem *item = static_cast<Combobox *>( windowEventArgs.window )->getSelectedItem();
 
418
        const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
 
419
        CEGUI::ListboxItem *item = static_cast<CEGUI::Combobox *>( windowEventArgs.window )->getSelectedItem();
423
420
 
424
 
        Set_Direction( Get_Direction_id( item->getText().c_str() ) );
 
421
        Set_Direction( Get_Direction_Id( item->getText().c_str() ) );
425
422
 
426
423
        return 1;
427
424
}
428
425
 
429
 
bool cLevel_Exit :: Editor_Destination_Level_Key( const EventArgs &event )
 
426
bool cLevel_Exit :: Editor_Destination_Level_Key( const CEGUI::EventArgs &event )
430
427
{
431
 
        const WindowEventArgs &windowEventArgs = static_cast<const WindowEventArgs&>( event );
432
 
        string str_text = static_cast<Editbox *>( windowEventArgs.window )->getText().c_str();
 
428
        const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
 
429
        string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
433
430
 
434
431
        Set_Level( str_text );
435
432
 
436
433
        return 1;
437
434
}
438
435
 
439
 
bool cLevel_Exit :: Editor_Destination_Entry_Key( const EventArgs &event )
 
436
bool cLevel_Exit :: Editor_Destination_Entry_Key( const CEGUI::EventArgs &event )
440
437
{
441
 
        const WindowEventArgs &windowEventArgs = static_cast<const WindowEventArgs&>( event );
442
 
        string str_text = static_cast<Editbox *>( windowEventArgs.window )->getText().c_str();
 
438
        const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
 
439
        string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
443
440
 
444
441
        Set_Entry( str_text );
445
442