2
2
Bear Engine - Level editor
4
Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
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"
46
48
#include <wx/notebook.h>
49
#include <wx/filename.h>
50
#include <wx/toolbar.h>
51
#include <wx/artprov.h>
47
53
#include <claw/logger.hpp>
55
DECLARE_APP(bf::level_editor)
49
57
/*----------------------------------------------------------------------------*/
51
59
* \brief Default constructor.
54
62
: wxFrame(NULL, wxID_ANY, wxT("Bear Factory - Level editor")),
55
63
m_windows_layout(NULL)
59
if ( path_configuration::get_instance().item_class_path.empty()
60
|| path_configuration::get_instance().data_path.empty() )
63
m_class_pool.scan_directory
64
( path_configuration::get_instance().item_class_path );
66
std::list<std::string>::const_iterator it;
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);
72
SetSize( m_config.main_rect );
65
SetSize( wxGetApp().get_config().main_rect );
75
68
SetSizer( new wxBoxSizer(wxVERTICAL) );
78
71
new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
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") );
84
m_class_tree = new class_tree_ctrl( m_class_pool, tabs );
85
m_class_tree->Show( m_config.item_class_pool_visible );
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") );
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") );
92
m_windows_layout = new windows_layout( m_class_pool, *this, *prop, *lay );
88
new windows_layout( wxGetApp().get_item_class_pool(), *this, *prop, *lay );
123
119
if ( dlg.ShowModal() == wxID_OK )
126
new gui_level( dlg.get_width(), dlg.get_height(), dlg.get_music() );
123
( dlg.get_name(), dlg.get_width(), dlg.get_height(), dlg.get_music() );
128
125
add_level_view( new ingame_view_frame(*m_windows_layout, lvl, path) );
137
134
void bf::main_frame::load_level( const wxString& path )
139
138
level_file_xml_reader reader;
141
gui_level* lvl = reader.load(m_class_pool, path);
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()
156
153
/*----------------------------------------------------------------------------*/
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.
161
void bf::main_frame::turn_level_entries( bool b )
158
void bf::main_frame::turn_level_entries( bool enable )
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 );
167
FindWindowById( wxID_SAVE, this )->Enable( b );
165
GetToolBar()->EnableTool( wxID_SAVE, enable );
168
166
} // main_frame::turn_level_entries()
170
168
/*----------------------------------------------------------------------------*/
189
187
void bf::main_frame::create_controls()
191
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
192
const wxSize btn_size(25, 25);
195
( new wxButton(this, wxID_NEW, wxT("N"), wxDefaultPosition, btn_size), 0,
198
( new wxButton(this, wxID_OPEN, wxT("O"), wxDefaultPosition, btn_size), 0,
201
( new wxButton(this, wxID_SAVE, wxT("S"), wxDefaultPosition, btn_size), 0,
204
GetSizer()->Add(sizer, 0, wxALL, 0);
189
wxToolBar* bar = CreateToolBar();
192
( wxID_NEW, _("&New"), wxArtProvider::GetBitmap(wxART_NEW), _("New") );
194
( wxID_OPEN, _("&Open"), wxArtProvider::GetBitmap(wxART_FILE_OPEN),
197
( wxID_SAVE, _("&Save"), wxArtProvider::GetBitmap(wxART_FILE_SAVE),
205
201
} // main_frame::create_controls()
207
203
/*----------------------------------------------------------------------------*/
275
271
void bf::main_frame::save_config()
277
m_config.main_rect = GetScreenRect();
273
wxGetApp().get_config().main_rect = GetScreenRect();
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();
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();
285
wxGetApp().get_config().save();
290
286
} // main_frame::save_config()
292
288
/*----------------------------------------------------------------------------*/
301
297
if ( m_windows_layout->get_current_level_view() != NULL )
302
298
s = m_windows_layout->get_current_level_view()->GetSize();
304
s = m_config.default_level_window_size;
300
s = wxGetApp().get_config().default_level_window_size;
306
302
view->SetSize(s);
310
306
/*----------------------------------------------------------------------------*/
312
* \brief Show the path configuration dialog.
314
void bf::main_frame::configure_paths()
316
config_frame dlg(this);
318
if ( dlg.ShowModal() == wxID_OK )
320
} // main_frame::configure_paths()
322
/*----------------------------------------------------------------------------*/
324
* \brief Add the paths of the configuration in the image pool.
326
void bf::main_frame::update_image_pool()
328
std::list<std::string>::const_iterator it;
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()
335
/*----------------------------------------------------------------------------*/
337
308
* \brief Answer to a click on "Configuration" menu.
338
309
* \param event This event occured.
340
void bf::main_frame::on_configuration_menu(wxCommandEvent& event)
311
void bf::main_frame::on_configuration_menu( wxCommandEvent& WXUNUSED(event) )
313
wxGetApp().configure();
343
314
} // main_frame::on_configuration_menu()
345
316
/*----------------------------------------------------------------------------*/
347
318
* \brief Answer to a click on "Update image pool" menu.
348
319
* \param event This event occured.
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) )
324
wxGetApp().update_image_pool();
353
325
} // main_frame::on_update_image_pool_menu()
355
327
/*----------------------------------------------------------------------------*/
357
329
* \brief Answer to a click on "Item properties" in the window menu.
358
330
* \param event This event occured.
360
void bf::main_frame::on_item_properties_menu(wxCommandEvent& event)
332
void bf::main_frame::on_item_properties_menu( wxCommandEvent& event )
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.
370
void bf::main_frame::on_layer_list_menu(wxCommandEvent& event)
342
void bf::main_frame::on_layer_list_menu( wxCommandEvent& event )
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.
380
void bf::main_frame::on_item_class_pool_menu(wxCommandEvent& event)
352
void bf::main_frame::on_item_class_pool_menu( wxCommandEvent& event )
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.
390
void bf::main_frame::on_new_level(wxCommandEvent& event)
362
void bf::main_frame::on_new_level( wxCommandEvent& WXUNUSED(event) )
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.
400
void bf::main_frame::on_open_level(wxCommandEvent& event)
372
void bf::main_frame::on_open_level( wxCommandEvent& WXUNUSED(event) )
402
wxFileDialog dlg( this, _("Choose a level"), wxT(""), wxT(""),
376
if ( m_windows_layout->get_current_level_view() != NULL )
378
path = m_windows_layout->get_current_level_view()->get_level_file();
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();
385
wxFileDialog dlg( this, _("Choose a level"), path.GetPath(), wxEmptyString,
403
386
_("Level files (*.lvl)|*.lvl"),
404
387
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
423
406
* \brief Answer to a click on "Save as".
424
407
* \param event This event occured.
426
void bf::main_frame::on_save_as(wxCommandEvent& event)
409
void bf::main_frame::on_save_as( wxCommandEvent& WXUNUSED(event) )
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.
436
void bf::main_frame::on_save(wxCommandEvent& event)
419
void bf::main_frame::on_save( wxCommandEvent& WXUNUSED(event) )
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.
446
void bf::main_frame::on_save_all(wxCommandEvent& event)
429
void bf::main_frame::on_save_all( wxCommandEvent& WXUNUSED(event) )
448
431
windows_layout::iterator it;
456
439
* \brief Answer to a click on "Exit".
457
440
* \param event This event occured.
459
void bf::main_frame::on_exit(wxCommandEvent& event)
442
void bf::main_frame::on_exit( wxCommandEvent& WXUNUSED(event) )
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.
469
void bf::main_frame::on_menu_open(wxMenuEvent& event)
452
void bf::main_frame::on_menu_open( wxMenuEvent& WXUNUSED(event) )
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.
485
void bf::main_frame::on_menu_highlight(wxMenuEvent& event)
468
void bf::main_frame::on_menu_highlight( wxMenuEvent& event )
487
470
ingame_view_frame* current_view = m_windows_layout->get_current_level_view();
496
479
* \brief Answer to an activation of the "online doc" menu.
497
480
* \param event This event occured.
499
void bf::main_frame::on_online_doc(wxCommandEvent& event)
482
void bf::main_frame::on_online_doc( wxCommandEvent& WXUNUSED(event) )
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.
511
void bf::main_frame::on_about(wxCommandEvent& event)
494
void bf::main_frame::on_about( wxCommandEvent& WXUNUSED(event) )
513
496
about_dialog dlg(*this);
563
546
} // main_frame::on_close()
565
548
/*----------------------------------------------------------------------------*/
550
* \brief Procedure called when the user picks a class in the class list.
551
* \param event This event occured.
553
void bf::main_frame::on_class_selected( class_selected_event& event )
555
ingame_view_frame* view = m_windows_layout->get_current_level_view();
558
view->add_item(event.get_class_name());
559
} // main_frame::on_class_selected()
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 )
594
590
EVT_CLOSE( bf::main_frame::on_close )
592
EVT_CLASS_SELECTED( bf::main_frame::IDC_CLASS_LIST,
593
bf::main_frame::on_class_selected )
595
594
END_EVENT_TABLE()