~ubuntu-branches/ubuntu/natty/plee-the-bear/natty

« back to all changes in this revision

Viewing changes to bear-factory/level-editor/src/bf/code/main_frame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    Bear Engine - Level editor
3
3
 
4
 
    Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
    Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
    This program is free software; you can redistribute it and/or modify it
7
7
    under the terms of the GNU General Public License as published by the
37
37
#include "bf/item_instance.hpp"
38
38
#include "bf/layer_list_frame.hpp"
39
39
#include "bf/layer_properties_frame.hpp"
 
40
#include "bf/level_editor.hpp"
40
41
#include "bf/level_file_xml_reader.hpp"
41
42
#include "bf/level_properties_frame.hpp"
42
43
#include "bf/path_configuration.hpp"
43
44
#include "bf/properties_frame.hpp"
 
45
#include "bf/windows_layout.hpp"
44
46
#include "bf/wx_facilities.hpp"
45
47
 
46
48
#include <wx/notebook.h>
 
49
#include <wx/filename.h>
 
50
#include <wx/toolbar.h>
 
51
#include <wx/artprov.h>
 
52
 
47
53
#include <claw/logger.hpp>
48
54
 
 
55
DECLARE_APP(bf::level_editor)
 
56
 
49
57
/*----------------------------------------------------------------------------*/
50
58
/**
51
59
 * \brief Default constructor.
54
62
  : wxFrame(NULL, wxID_ANY, wxT("Bear Factory - Level editor")),
55
63
    m_windows_layout(NULL)
56
64
{
57
 
  m_config.load();
58
 
 
59
 
  if ( path_configuration::get_instance().item_class_path.empty()
60
 
       || path_configuration::get_instance().data_path.empty() )
61
 
    configure_paths();
62
 
 
63
 
  m_class_pool.scan_directory
64
 
    ( path_configuration::get_instance().item_class_path );
65
 
 
66
 
  std::list<std::string>::const_iterator it;
67
 
 
68
 
  for ( it=path_configuration::get_instance().data_path.begin();
69
 
        it!=path_configuration::get_instance().data_path.end(); ++it )
70
 
    image_pool::get_instance().scan_directory(*it);
71
 
 
72
 
  SetSize( m_config.main_rect );
 
65
  SetSize( wxGetApp().get_config().main_rect );
73
66
  Show();
74
67
 
75
68
  SetSizer( new wxBoxSizer(wxVERTICAL) );
78
71
    new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
79
72
 
80
73
  layer_list_frame* lay = new layer_list_frame( tabs );
81
 
  lay->Show( m_config.layer_list_visible );
 
74
  lay->Show( wxGetApp().get_config().layer_list_visible );
82
75
  tabs->AddPage( lay, _("Layers") );
83
76
 
84
 
  m_class_tree = new class_tree_ctrl( m_class_pool, tabs );
85
 
  m_class_tree->Show( m_config.item_class_pool_visible );
 
77
  m_class_tree =
 
78
    new class_tree_ctrl
 
79
    ( wxGetApp().get_item_class_pool(), tabs, IDC_CLASS_LIST );
 
80
  m_class_tree->Show( wxGetApp().get_config().item_class_pool_visible );
86
81
  tabs->AddPage( m_class_tree, _("Class") );
87
82
 
88
83
  properties_frame* prop = new properties_frame( tabs );
89
 
  prop->Show( m_config.properties_visible );
 
84
  prop->Show( wxGetApp().get_config().properties_visible );
90
85
  tabs->AddPage( prop, _("Properties") );
91
86
 
92
 
  m_windows_layout = new windows_layout( m_class_pool, *this, *prop, *lay );
 
87
  m_windows_layout =
 
88
    new windows_layout( wxGetApp().get_item_class_pool(), *this, *prop, *lay );
93
89
 
94
90
  create_menu();
95
91
  create_controls();
123
119
  if ( dlg.ShowModal() == wxID_OK )
124
120
    {
125
121
      gui_level* lvl =
126
 
        new gui_level( dlg.get_width(), dlg.get_height(), dlg.get_music() );
 
122
        new gui_level
 
123
        ( dlg.get_name(), dlg.get_width(), dlg.get_height(), dlg.get_music() );
127
124
 
128
125
      add_level_view( new ingame_view_frame(*m_windows_layout, lvl, path) );
129
126
    }
136
133
 */
137
134
void bf::main_frame::load_level( const wxString& path )
138
135
{
 
136
  wxLogNull no_log;
 
137
 
139
138
  level_file_xml_reader reader;
140
 
 
141
 
  gui_level* lvl = reader.load(m_class_pool, path);
142
 
 
 
139
  gui_level* lvl = reader.load(wxGetApp().get_item_class_pool(), path);
143
140
  add_level_view( new ingame_view_frame(*m_windows_layout, lvl, path) );
144
141
} // main_frame::load_level()
145
142
 
156
153
/*----------------------------------------------------------------------------*/
157
154
/**
158
155
 * \brief Enable/disable the controls relative to the levels.
159
 
 * \param b Tell if the controls are enabled.
 
156
 * \param enable Tell if the controls are enabled.
160
157
 */
161
 
void bf::main_frame::turn_level_entries( bool b )
 
158
void bf::main_frame::turn_level_entries( bool enable )
162
159
{
163
 
  GetMenuBar()->Enable( wxID_SAVE, b );
164
 
  GetMenuBar()->Enable( wxID_SAVEAS, b );
165
 
  GetMenuBar()->Enable( IDM_SAVE_ALL_LEVELS, b );
 
160
  GetMenuBar()->Enable( wxID_SAVE, enable );
 
161
  GetMenuBar()->Enable( wxID_SAVEAS, enable );
 
162
  GetMenuBar()->Enable( IDM_SAVE_ALL_LEVELS, enable );
 
163
  GetMenuBar()->Enable( IDM_UPDATE_IMAGE_POOL, enable );
166
164
 
167
 
  FindWindowById( wxID_SAVE, this )->Enable( b );
 
165
  GetToolBar()->EnableTool( wxID_SAVE, enable );
168
166
} // main_frame::turn_level_entries()
169
167
 
170
168
/*----------------------------------------------------------------------------*/
188
186
 */
189
187
void bf::main_frame::create_controls()
190
188
{
191
 
  wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
192
 
  const wxSize btn_size(25, 25);
193
 
 
194
 
  sizer->Add
195
 
    ( new wxButton(this, wxID_NEW, wxT("N"), wxDefaultPosition, btn_size), 0,
196
 
      wxALL, 3 );
197
 
  sizer->Add
198
 
    ( new wxButton(this, wxID_OPEN, wxT("O"), wxDefaultPosition, btn_size), 0,
199
 
      wxALL, 3 );
200
 
  sizer->Add
201
 
    ( new wxButton(this, wxID_SAVE, wxT("S"), wxDefaultPosition, btn_size), 0,
202
 
      wxALL, 3 );
203
 
 
204
 
  GetSizer()->Add(sizer, 0, wxALL, 0);
 
189
  wxToolBar* bar = CreateToolBar();
 
190
 
 
191
  bar->AddTool
 
192
    ( wxID_NEW, _("&New"), wxArtProvider::GetBitmap(wxART_NEW), _("New") );
 
193
  bar->AddTool
 
194
    ( wxID_OPEN, _("&Open"), wxArtProvider::GetBitmap(wxART_FILE_OPEN),
 
195
      _("Open") );
 
196
  bar->AddTool
 
197
    ( wxID_SAVE, _("&Save"), wxArtProvider::GetBitmap(wxART_FILE_SAVE),
 
198
      _("Save") );
 
199
 
 
200
  bar->Realize();
205
201
} // main_frame::create_controls()
206
202
 
207
203
/*----------------------------------------------------------------------------*/
274
270
 */
275
271
void bf::main_frame::save_config()
276
272
{
277
 
  m_config.main_rect = GetScreenRect();
 
273
  wxGetApp().get_config().main_rect = GetScreenRect();
278
274
 
279
 
  m_config.properties_visible =
 
275
  wxGetApp().get_config().properties_visible =
280
276
    m_windows_layout->get_properties_frame().IsShown();
281
 
  m_config.layer_list_visible =
 
277
  wxGetApp().get_config().layer_list_visible =
282
278
    m_windows_layout->get_layer_list_frame().IsShown();
283
 
  m_config.item_class_pool_visible = m_class_tree->IsShown();
 
279
  wxGetApp().get_config().item_class_pool_visible = m_class_tree->IsShown();
284
280
 
285
281
  if ( m_windows_layout->get_current_level_view() != NULL )
286
 
    m_config.default_level_window_size =
 
282
    wxGetApp().get_config().default_level_window_size =
287
283
      m_windows_layout->get_current_level_view()->GetSize();
288
284
 
289
 
  m_config.save();
 
285
  wxGetApp().get_config().save();
290
286
} // main_frame::save_config()
291
287
 
292
288
/*----------------------------------------------------------------------------*/
301
297
  if ( m_windows_layout->get_current_level_view() != NULL )
302
298
    s = m_windows_layout->get_current_level_view()->GetSize();
303
299
  else
304
 
    s = m_config.default_level_window_size;
 
300
    s = wxGetApp().get_config().default_level_window_size;
305
301
 
306
302
  view->SetSize(s);
307
303
  view->Show();
309
305
 
310
306
/*----------------------------------------------------------------------------*/
311
307
/**
312
 
 * \brief Show the path configuration dialog.
313
 
 */
314
 
void bf::main_frame::configure_paths()
315
 
{
316
 
  config_frame dlg(this);
317
 
 
318
 
  if ( dlg.ShowModal() == wxID_OK )
319
 
    update_image_pool();
320
 
} // main_frame::configure_paths()
321
 
 
322
 
/*----------------------------------------------------------------------------*/
323
 
/**
324
 
 * \brief Add the paths of the configuration in the image pool.
325
 
 */
326
 
void bf::main_frame::update_image_pool()
327
 
{
328
 
  std::list<std::string>::const_iterator it;
329
 
 
330
 
  for ( it=path_configuration::get_instance().data_path.begin();
331
 
        it!=path_configuration::get_instance().data_path.end(); ++it )
332
 
    image_pool::get_instance().scan_directory(*it);
333
 
} // main_frame::update_image_pool()
334
 
 
335
 
/*----------------------------------------------------------------------------*/
336
 
/**
337
308
 * \brief Answer to a click on "Configuration" menu.
338
309
 * \param event This event occured.
339
310
 */
340
 
void bf::main_frame::on_configuration_menu(wxCommandEvent& event)
 
311
void bf::main_frame::on_configuration_menu( wxCommandEvent& WXUNUSED(event) )
341
312
{
342
 
  configure_paths();
 
313
  wxGetApp().configure();
343
314
} // main_frame::on_configuration_menu()
344
315
 
345
316
/*----------------------------------------------------------------------------*/
347
318
 * \brief Answer to a click on "Update image pool" menu.
348
319
 * \param event This event occured.
349
320
 */
350
 
void bf::main_frame::on_update_image_pool_menu(wxCommandEvent& event)
 
321
void bf::main_frame::on_update_image_pool_menu
 
322
( wxCommandEvent& WXUNUSED(event) )
351
323
{
352
 
  update_image_pool();
 
324
  wxGetApp().update_image_pool();
353
325
} // main_frame::on_update_image_pool_menu()
354
326
 
355
327
/*----------------------------------------------------------------------------*/
357
329
 * \brief Answer to a click on "Item properties" in the window menu.
358
330
 * \param event This event occured.
359
331
 */
360
 
void bf::main_frame::on_item_properties_menu(wxCommandEvent& event)
 
332
void bf::main_frame::on_item_properties_menu( wxCommandEvent& event )
361
333
{
362
334
  m_windows_layout->get_properties_frame().Show( event.IsChecked() );
363
335
} // main_frame::on_item_properties_menu()
367
339
 * \brief Answer to a click on "Layer list" in the window menu.
368
340
 * \param event This event occured.
369
341
 */
370
 
void bf::main_frame::on_layer_list_menu(wxCommandEvent& event)
 
342
void bf::main_frame::on_layer_list_menu( wxCommandEvent& event )
371
343
{
372
344
  m_windows_layout->get_layer_list_frame().Show( event.IsChecked() );
373
345
} // main_frame::on_layer_list_menu()
377
349
 * \brief Answer to a click on "Item classes" in the window menu.
378
350
 * \param event This event occured.
379
351
 */
380
 
void bf::main_frame::on_item_class_pool_menu(wxCommandEvent& event)
 
352
void bf::main_frame::on_item_class_pool_menu( wxCommandEvent& event )
381
353
{
382
354
  m_class_tree->Show( event.IsChecked() );
383
355
} // main_frame::on_item_class_pool_menu()
387
359
 * \brief Answer to a click on "New level".
388
360
 * \param event This event occured.
389
361
 */
390
 
void bf::main_frame::on_new_level(wxCommandEvent& event)
 
362
void bf::main_frame::on_new_level( wxCommandEvent& WXUNUSED(event) )
391
363
{
392
364
  new_level( wxEmptyString );
393
365
} // main_frame::on_new_level()
397
369
 * \brief Answer to a click on "Open level".
398
370
 * \param event This event occured.
399
371
 */
400
 
void bf::main_frame::on_open_level(wxCommandEvent& event)
 
372
void bf::main_frame::on_open_level( wxCommandEvent& WXUNUSED(event) )
401
373
{
402
 
  wxFileDialog dlg( this, _("Choose a level"), wxT(""), wxT(""),
 
374
  wxFileName path;
 
375
 
 
376
  if ( m_windows_layout->get_current_level_view() != NULL )
 
377
    {
 
378
      path = m_windows_layout->get_current_level_view()->get_level_file();
 
379
 
 
380
      for ( windows_layout::iterator it=m_windows_layout->begin();
 
381
            path.GetPath().empty() && (it!=m_windows_layout->end()); ++it )
 
382
        path = it->get_level_file();
 
383
    }
 
384
 
 
385
  wxFileDialog dlg( this, _("Choose a level"), path.GetPath(), wxEmptyString,
403
386
                    _("Level files (*.lvl)|*.lvl"),
404
387
                    wxFD_OPEN | wxFD_FILE_MUST_EXIST );
405
388
 
423
406
 * \brief Answer to a click on "Save as".
424
407
 * \param event This event occured.
425
408
 */
426
 
void bf::main_frame::on_save_as(wxCommandEvent& event)
 
409
void bf::main_frame::on_save_as( wxCommandEvent& WXUNUSED(event) )
427
410
{
428
411
  m_windows_layout->get_current_level_view()->save_as();
429
412
} // main_frame::on_save_as()
433
416
 * \brief Answer to a click on "Save".
434
417
 * \param event This event occured.
435
418
 */
436
 
void bf::main_frame::on_save(wxCommandEvent& event)
 
419
void bf::main_frame::on_save( wxCommandEvent& WXUNUSED(event) )
437
420
{
438
421
  m_windows_layout->get_current_level_view()->save();
439
422
} // main_frame::on_save()
443
426
 * \brief Answer to a click on "Save all".
444
427
 * \param event This event occured.
445
428
 */
446
 
void bf::main_frame::on_save_all(wxCommandEvent& event)
 
429
void bf::main_frame::on_save_all( wxCommandEvent& WXUNUSED(event) )
447
430
{
448
431
  windows_layout::iterator it;
449
432
 
456
439
 * \brief Answer to a click on "Exit".
457
440
 * \param event This event occured.
458
441
 */
459
 
void bf::main_frame::on_exit(wxCommandEvent& event)
 
442
void bf::main_frame::on_exit( wxCommandEvent& WXUNUSED(event) )
460
443
{
461
444
  Close();
462
445
} // main_frame::on_exit()
466
449
 * \brief Answer to the event that occurs when opening menus.
467
450
 * \param event This event occured.
468
451
 */
469
 
void bf::main_frame::on_menu_open(wxMenuEvent& event)
 
452
void bf::main_frame::on_menu_open( wxMenuEvent& WXUNUSED(event) )
470
453
{
471
454
  GetMenuBar()->Check
472
455
    ( IDM_ITEM_PROPERTIES, m_windows_layout->get_properties_frame().IsShown() );
482
465
 * \brief A menu entry is highlighted.
483
466
 * \param event This event occured.
484
467
 */
485
 
void bf::main_frame::on_menu_highlight(wxMenuEvent& event)
 
468
void bf::main_frame::on_menu_highlight( wxMenuEvent& event )
486
469
{
487
470
  ingame_view_frame* current_view = m_windows_layout->get_current_level_view();
488
471
 
496
479
 * \brief Answer to an activation of the "online doc" menu.
497
480
 * \param event This event occured.
498
481
 */
499
 
void bf::main_frame::on_online_doc(wxCommandEvent& event)
 
482
void bf::main_frame::on_online_doc( wxCommandEvent& WXUNUSED(event) )
500
483
{
501
484
  wxLaunchDefaultBrowser
502
485
    ( wxT("http://plee-the-bear.sourceforge.net/" )
508
491
 * \brief Answer to an activation of the "about" menu.
509
492
 * \param event This event occured.
510
493
 */
511
 
void bf::main_frame::on_about(wxCommandEvent& event)
 
494
void bf::main_frame::on_about( wxCommandEvent& WXUNUSED(event) )
512
495
{
513
496
  about_dialog dlg(*this);
514
497
 
520
503
 * \brief Procedure called when closing the window.
521
504
 * \param event This event occured.
522
505
 */
523
 
void bf::main_frame::on_close(wxCloseEvent& event)
 
506
void bf::main_frame::on_close( wxCloseEvent& event )
524
507
{
525
508
  save_config();
526
509
 
563
546
} // main_frame::on_close()
564
547
 
565
548
/*----------------------------------------------------------------------------*/
 
549
/**
 
550
 * \brief Procedure called when the user picks a class in the class list.
 
551
 * \param event This event occured.
 
552
 */
 
553
void bf::main_frame::on_class_selected( class_selected_event& event )
 
554
{
 
555
  ingame_view_frame* view = m_windows_layout->get_current_level_view();
 
556
 
 
557
  if ( view != NULL )
 
558
    view->add_item(event.get_class_name());
 
559
} // main_frame::on_class_selected()
 
560
 
 
561
/*----------------------------------------------------------------------------*/
566
562
BEGIN_EVENT_TABLE(bf::main_frame, wxFrame)
567
563
  EVT_BUTTON( wxID_NEW, bf::main_frame::on_new_level )
568
564
  EVT_BUTTON( wxID_OPEN, bf::main_frame::on_open_level )
592
588
  EVT_MENU( wxID_ABOUT, bf::main_frame::on_about )
593
589
 
594
590
  EVT_CLOSE( bf::main_frame::on_close )
 
591
 
 
592
  EVT_CLASS_SELECTED( bf::main_frame::IDC_CLASS_LIST,
 
593
                      bf::main_frame::on_class_selected )
595
594
END_EVENT_TABLE()