2 * entity_panel_platform.cpp
4 * Created on: 17 nov. 2008
13 #include "ob_editor.h"
14 #include "images__MyPalette.h"
15 #include "entity__enums.h"
16 #include "entity__globals.h"
17 #include "entity__MyAnimationZone.h"
20 Panel_Platform
*panel_Platform
;
23 //************************************************************************************
25 Panel_Platform::Panel_Platform(wxNotebook
* _parent
)
26 :Panel_withAnims(_parent
)
28 panel_Platform
= this;
39 wxBoxSizer
*sizer_main
= new wxBoxSizer( wxVERTICAL
);
41 //Top part of the panel
42 wxBoxSizer
*sizer_top
= new wxBoxSizer( wxHORIZONTAL
);
43 sizer_main
->Add( sizer_top
, 1, wxALL
| wxEXPAND
);
45 wxBoxSizer
*sizer_topLeft
= new wxBoxSizer( wxHORIZONTAL
);
46 sizer_top
->Add( sizer_topLeft
, 0, wxALL
| wxEXPAND
);
48 wxBoxSizer
*sizer_scrollWndFrameProps
= new wxBoxSizer( wxVERTICAL
);
49 sizer_top
->Add( sizer_scrollWndFrameProps
, 0, wxALL
| wxEXPAND
, 6 );
51 wxBoxSizer
*sizer_topRight
= new wxBoxSizer( wxVERTICAL
);
52 sizer_top
->Add( sizer_topRight
, 1, wxALL
| wxEXPAND
);
54 wxBoxSizer
*sizer_topRightUp
= new wxBoxSizer( wxHORIZONTAL
);
55 sizer_topRight
->Add( sizer_topRightUp
, 0, wxALL
| wxEXPAND
);
57 wxBoxSizer
*sizer_topRightDown
= new wxBoxSizer( wxVERTICAL
);
58 sizer_topRight
->Add( sizer_topRightDown
, 1, wxALL
| wxEXPAND
);
61 //Bottom part of the panel
62 wxSizer
*sizer_bottom
= new wxBoxSizer( wxHORIZONTAL
);
63 sizer_main
->Add( sizer_bottom
, 0, wxALL
| wxEXPAND
);
69 //**************************
71 //**************************
73 list_Anims
= new wListAnims(this);
74 list_Anims
->SetMinSize( wxSize(150,50));
75 sizer_topLeft
->Add( list_Anims
, 0, wxALL
|wxEXPAND
);
78 //**************************
80 //**************************
82 scrollPanel
= new AScrollPanel( this );
83 sizer_scrollWndFrameProps
->Add( scrollPanel
, 1, wxALL
, 0 );
85 wxBoxSizer
*sizer_topCenter
= new wxBoxSizer( wxVERTICAL
);
87 scrollPanel
->SetSizer( sizer_topCenter
);
91 //**************************
93 //**************************
95 chckbx_noplatform
= new wxCheckBox(scrollPanel
, ID_NO_PLATFORM
, wxT("No/Clone Platform"), wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
);
96 chckbx_noplatform
->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEventHandler(Panel_Platform::EvtButtonClick
), NULL
, this );
97 sizer_topCenter
->Add( chckbx_noplatform
, 0, wxALL
| wxALIGN_LEFT
, border_size
);
99 wxStaticBoxSizer
*sizer_PlatformDatas
= new wxStaticBoxSizer( wxVERTICAL
, scrollPanel
, wxT("Platform Datas") );
100 sizer_topCenter
->Add( sizer_PlatformDatas
, 0, wxALL
, border_size
);
102 wxGridSizer
*sizer_temp
= new wxGridSizer( 8, 2, border_size
, border_size
);
103 sizer_PlatformDatas
->Add( sizer_temp
, 0 , wxEXPAND
);
107 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("xPos"), wxPoint(wxDefaultCoord
, 8) );
108 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
110 txtctrl_off_x
= new wxTextCtrl(scrollPanel
, ID_PLAT_OFF_X
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
111 txtctrl_off_x
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
112 sizer_temp
->Add( txtctrl_off_x
, 0, wxALL
| wxCENTER
, border_size
);
118 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("yPos"), wxPoint(wxDefaultCoord
, 8) );
119 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
121 txtctrl_off_y
= new wxTextCtrl(scrollPanel
, ID_PLAT_OFF_Y
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
122 txtctrl_off_y
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
123 txtctrl_off_y
->MoveAfterInTabOrder( txtctrl_off_x
);
124 sizer_temp
->Add( txtctrl_off_y
, 0, wxALL
| wxCENTER
, border_size
);
130 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("upperleft"), wxPoint(wxDefaultCoord
, 8) );
131 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
133 txtctrl_up_l
= new wxTextCtrl(scrollPanel
, ID_PLAT_UPL
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
134 txtctrl_up_l
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
135 txtctrl_up_l
->MoveAfterInTabOrder( txtctrl_off_y
);
136 sizer_temp
->Add( txtctrl_up_l
, 0, wxALL
| wxCENTER
, border_size
);
142 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("lowerleft"), wxPoint(wxDefaultCoord
, 8) );
143 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
145 txtctrl_d_l
= new wxTextCtrl(scrollPanel
, ID_PLAT_DL
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
146 txtctrl_d_l
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
147 txtctrl_d_l
->MoveAfterInTabOrder( txtctrl_up_l
);
148 sizer_temp
->Add( txtctrl_d_l
, 0, wxALL
| wxCENTER
, border_size
);
154 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("upperright"), wxPoint(wxDefaultCoord
, 8) );
155 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
157 txtctrl_up_r
= new wxTextCtrl(scrollPanel
, ID_PLAT_UPR
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
158 txtctrl_up_r
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
159 txtctrl_up_r
->MoveAfterInTabOrder( txtctrl_d_l
);
160 sizer_temp
->Add( txtctrl_up_r
, 0, wxALL
| wxCENTER
, border_size
);
166 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("lowerright"), wxPoint(wxDefaultCoord
, 8) );
167 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
169 txtctrl_l_r
= new wxTextCtrl(scrollPanel
, ID_PLAT_LR
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
170 txtctrl_l_r
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
171 txtctrl_l_r
->MoveAfterInTabOrder( txtctrl_up_r
);
172 sizer_temp
->Add( txtctrl_l_r
, 0, wxALL
| wxCENTER
, border_size
);
178 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("depth"), wxPoint(wxDefaultCoord
, 8) );
179 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
181 txtctrl_depth
= new wxTextCtrl(scrollPanel
, ID_PLAT_DEPTH
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
182 txtctrl_depth
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
183 txtctrl_depth
->MoveAfterInTabOrder( txtctrl_l_r
);
184 sizer_temp
->Add( txtctrl_depth
, 0, wxALL
| wxCENTER
, border_size
);
190 wxStaticText
*txt_temp
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("alt"), wxPoint(wxDefaultCoord
, 8) );
191 sizer_temp
->Add( txt_temp
, 0, wxALL
| wxCENTER
, border_size
);
193 txtctrl_alt
= new wxTextCtrl(scrollPanel
, ID_PLAT_ALT
, wxString(),wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
| wxTE_RIGHT
);
194 txtctrl_alt
->Connect( wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEventHandler(Panel_Platform::EvtCommand
), NULL
, this);
195 txtctrl_alt
->MoveAfterInTabOrder( txtctrl_depth
);
196 sizer_temp
->Add( txtctrl_alt
, 0, wxALL
| wxCENTER
, border_size
);
199 // The color chooser of the platform
200 wxSizer
*sizer_color
= new wxBoxSizer( wxHORIZONTAL
);
201 sizer_topCenter
->Add( sizer_color
, 0 , wxALL
);
203 wxStaticText
*txt_color
= new wxStaticText( scrollPanel
, wxID_ANY
, wxT("Color :"), wxPoint(wxDefaultCoord
, 8) );
204 sizer_color
->Add( txt_color
, 0, wxALL
| wxCENTER
, border_size
);
206 plat_color
= new MyPaletteElementCtrl(scrollPanel
);
207 plat_color
->SetId( ID_BBOX_COLOR
);
208 plat_color
->SetRGB( 0,0,0 );
209 plat_color
->SetMode( AUTO_ELTCOLOR
);
210 sizer_color
->Add( plat_color
, 0, wxCENTER
| wxALL
, 2 );
212 //**************************
214 //**************************
216 sizer_topRightUp
->AddStretchSpacer();
218 //**************************
220 wxBoxSizer
*sizer_anim_ctrls
= new wxBoxSizer( wxHORIZONTAL
);
221 sizer_topRightUp
->Add( sizer_anim_ctrls
, 0, wxALL
|wxEXPAND
, 6 );
223 wxBitmapButton
* butt_Zoom_M
= new wxBitmapButton( this, ID_ZOOM_M
,
224 wxBitmap( wxImage( GetRessourceFile_String(wxT("zoom-out.png")))));
225 sizer_anim_ctrls
->Add( butt_Zoom_M
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 2 );
227 wxBitmapButton
* butt_Zoom_P
= new wxBitmapButton( this, ID_ZOOM_P
,
228 wxBitmap( wxImage( GetRessourceFile_String(wxT("zoom-in.png")))));
229 sizer_anim_ctrls
->Add( butt_Zoom_P
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 2 );
231 sizer_topRightUp
->AddStretchSpacer();
234 //**************************
235 // THE ANIMATION ZONE
236 //**************************
238 platformView
= new MyPlatformViewerCtrl(this );
239 sizer_topRightDown
->Add( platformView
, 1, wxALL
| wxEXPAND
, 2 );
241 //**************************
243 //**************************
245 wList_frames
= new wListFrames( this );
246 sizer_bottom
->Add( wList_frames
, 1, wxALL
);
249 //**************************
251 //**************************
252 SetSizer( sizer_main
);
253 wList_frames
->AssociateToListAnims( list_Anims
);
254 list_Anims
->AssociateToListFrame( wList_frames
);
255 list_Anims
->ReloadLastSessionAnim();
256 list_Anims
->Refresh_List();
262 //************************************************************************************
264 Panel_Platform::~Panel_Platform()
269 //************************************************************************************
271 void Panel_Platform::OnActivate()
273 Panel_withAnims::OnActivate();
275 if( b_entity_has_change
)
277 // Check for new platform datas
278 Update_PlaftformDatas();
281 platformView
->UpdateFrames();
283 scrollPanel
->EvtSize( event
);
288 //*********************************************************************
290 void Panel_Platform::Reload()
292 Panel_withAnims::Refresh();
293 Update_PlaftformDatas();
294 platformView
->UpdateFrames();
298 //*********************************************************************
300 void Panel_Platform::ReloadGifs()
302 Panel_withAnims::ReloadGifs();
303 platformView
->UpdateFrames();
307 //************************************************************************************
309 extern wxColour cloneColour
;
311 void Panel_Platform::Update_PlaftformDatas()
313 if( entity
== NULL
|| curr_anim
== NULL
)
315 scrollPanel
->Enable( false );
319 if( frameActive
== NULL
|| frameActive
->GetImage() == noImg
)
321 scrollPanel
->Enable( false );
322 wxMessageBox( wxT("Not a valid frame for making a platform"), wxT("ProPlem"), wxOK
| wxICON_INFORMATION
, this );
326 scrollPanel
->Enable( true );
328 ob_object
* platform_prop
= frameActive
->GetSubObject( wxT("platform") );
330 if( platform_prop
== NULL
)
331 EnablePlatform( false );
334 int nb_tokens
= platform_prop
->nb_tokens
;
335 if( nb_tokens
!= 6 && nb_tokens
!= 8 )
337 scrollPanel
->Enable( false );
338 wxMessageBox( wxT("Malformed platform property in entity header"), wxT("ProPlem"), wxOK
| wxICON_INFORMATION
, this );
342 EnablePlatform( true );
344 // In case of old platform format, convert to new format
347 // set some default value to offset x and y
348 ob_object
* fr_offsets
= frameActive
->GetSubObject( wxT("offset") );
349 platform_prop
->SetName( wxT("platform" ));
350 platform_prop
->SetToken( 0, fr_offsets
->GetToken( 0 ) );
351 platform_prop
->SetToken( 1, fr_offsets
->GetToken( 1 ) );
353 for( int i
=0; i
< 6; i
++ )
354 platform_prop
->SetToken( i
+2, platform_prop
->GetToken(i
) );
356 entity
->SetChanged();
359 txtctrl_off_x
->ChangeValue( platform_prop
->GetToken(0));
360 txtctrl_off_y
->ChangeValue( platform_prop
->GetToken(1));
361 txtctrl_up_l
->ChangeValue( platform_prop
->GetToken(2));
362 txtctrl_d_l
->ChangeValue( platform_prop
->GetToken(3));
363 txtctrl_up_r
->ChangeValue( platform_prop
->GetToken(4));
364 txtctrl_l_r
->ChangeValue( platform_prop
->GetToken(5));
365 txtctrl_depth
->ChangeValue( platform_prop
->GetToken(6));
366 txtctrl_alt
->ChangeValue( platform_prop
->GetToken(7));
368 UpdateBG_colours( platform_prop
);
374 //************************************************************************************
376 void Panel_Platform::EnablePlatform( bool b_enable
)
378 chckbx_noplatform
->SetValue( ! b_enable
);
380 txtctrl_off_x
->Enable( b_enable
);
381 txtctrl_off_y
->Enable( b_enable
);
382 txtctrl_up_l
->Enable( b_enable
);
383 txtctrl_d_l
->Enable( b_enable
);
384 txtctrl_up_r
->Enable( b_enable
);
385 txtctrl_l_r
->Enable( b_enable
);
386 txtctrl_depth
->Enable( b_enable
);
387 txtctrl_alt
->Enable( b_enable
);
391 //************************************************************************************
393 void Panel_Platform::EvtCommand(wxCommandEvent
& event
)
395 Update_entity_platform();
399 //************************************************************************************
401 void Panel_Platform::Update_entity_platform()
403 if( curr_anim
== NULL
|| frameActive
== NULL
)
405 wxMessageBox( wxT("No animation selected !!"), wxT("ProPlem"), wxOK
| wxICON_INFORMATION
, this );
409 ob_object
* platform_prop
= frameActive
->GetSubObject( wxT("platform" ));
411 if( platform_prop
== NULL
)
416 if( platform_prop
->GetToken(0) == txtctrl_off_x
->GetValue()
417 && platform_prop
->GetToken(1) == txtctrl_off_y
->GetValue()
418 && platform_prop
->GetToken(2) == txtctrl_up_l
->GetValue()
419 && platform_prop
->GetToken(3) == txtctrl_d_l
->GetValue()
420 && platform_prop
->GetToken(4) == txtctrl_up_r
->GetValue()
421 && platform_prop
->GetToken(5) == txtctrl_l_r
->GetValue()
422 && platform_prop
->GetToken(6) == txtctrl_depth
->GetValue()
423 && platform_prop
->GetToken(7) == txtctrl_alt
->GetValue()
427 platform_prop
->SetToken(0, txtctrl_off_x
->GetValue() );
428 platform_prop
->SetToken(1, txtctrl_off_y
->GetValue() );
429 platform_prop
->SetToken(2, txtctrl_up_l
->GetValue() );
430 platform_prop
->SetToken(3, txtctrl_d_l
->GetValue() );
431 platform_prop
->SetToken(4, txtctrl_up_r
->GetValue() );
432 platform_prop
->SetToken(5, txtctrl_l_r
->GetValue() );
433 platform_prop
->SetToken(6, txtctrl_depth
->GetValue() );
434 platform_prop
->SetToken(7, txtctrl_alt
->GetValue() );
436 entity
->SetChanged();
438 UpdateBG_colours( platform_prop
);
439 platformView
->UpdateFrames();
444 //************************************************************************************
446 void Panel_Platform::UpdateBG_colours( ob_object
* platform_prop
)
448 wxColour
t_col( *wxWHITE
);
449 if( platform_prop
->parent
!= NULL
450 && ((ob_frame
*) platform_prop
->parent
)->b_platform_cloned
== true )
453 txtctrl_off_x
->SetBackgroundColour( t_col
);
454 txtctrl_off_y
->SetBackgroundColour( t_col
);
455 txtctrl_up_l
->SetBackgroundColour( t_col
);
456 txtctrl_d_l
->SetBackgroundColour( t_col
);
457 txtctrl_up_r
->SetBackgroundColour( t_col
);
458 txtctrl_l_r
->SetBackgroundColour( t_col
);
459 txtctrl_depth
->SetBackgroundColour( t_col
);
460 txtctrl_alt
->SetBackgroundColour( t_col
);
465 //************************************************************************************
467 void Panel_Platform::EvtAnimSelectionChange(wxCommandEvent
& event
)
469 Panel_withAnims::EvtAnimSelectionChange(event
);
473 //************************************************************************************
475 void Panel_Platform::EvtButtonClick(wxCommandEvent
& event
)
478 wxWindow
*winSrc
= (wxWindow
*) event
.GetEventObject();
481 id_wind
= winSrc
->GetId();
485 id_wind
= event
.GetId();
491 platformView
->Zoom(0.8);
492 list_Anims
->SetFocus();
496 platformView
->Zoom(1.3);
497 list_Anims
->SetFocus();
501 if( curr_anim
== NULL
|| frameActive
== NULL
)
505 if( chckbx_noplatform
->GetValue() == true )
507 ob_object
* platform_prop
= frameActive
->GetSubObject( wxT("platform" ));
508 if( platform_prop
!= NULL
)
511 entity
->SetChanged();
513 Frame_CascadeChanges();
514 Update_PlaftformDatas();
515 // If a cloned value has appear, decheck the box
516 if( frameActive
->GetSubObject( wxT("platform") ) != NULL
)
517 chckbx_noplatform
->SetValue( false );
518 platformView
->UpdateFrames();
524 if( frameActive
== NULL
|| frameActive
->GetImage() == NULL
|| frameActive
->GetImage() == noImg
)
526 scrollPanel
->Enable( false );
527 wxMessageBox( wxT("Not a valid frame for making a platform"), wxT("ProPlem"), wxOK
| wxICON_INFORMATION
, this );
531 entity
->SetChanged();
533 // set some default value
534 ob_object
* fr_offsets
= frameActive
->GetSubObject( wxT("offset") );
535 wxString new_tokens
[8];
536 new_tokens
[0] = fr_offsets
->GetToken( 0 );
537 new_tokens
[1] = fr_offsets
->GetToken( 1 );
539 wxImage
* curr_img
= frameActive
->GetImage();
540 int w
= curr_img
->GetWidth();
541 int h
= curr_img
->GetHeight();
542 new_tokens
[2] = IntToStr( -w
/4 );
543 new_tokens
[3] = IntToStr( -w
/4 );
544 new_tokens
[4] = IntToStr( w
/4 );
545 new_tokens
[5] = IntToStr( w
/4 );
546 new_tokens
[6] = IntToStr( w
/4 );
547 new_tokens
[7] = IntToStr( 2*h
/3 );
549 frameActive
->SetProperty( wxT("platform"), new_tokens
, 8 );
551 Update_PlaftformDatas();
552 platformView
->UpdateFrames();
559 //************************************************************************************
561 void Panel_Platform::EvtFrameSelectionChange(wxCommandEvent
& event
)
563 Panel_withAnims::EvtFrameSelectionChange(event
);
565 Frame_CascadeChanges();
566 Update_PlaftformDatas();
568 if( platformView
!= NULL
)
570 platformView
->UpdateFrames();
577 //************************************************************************************
578 //************************************************************************************
579 //************************************************************************************
580 //************************************************************************************
581 //************************************************************************************
583 BEGIN_EVENT_TABLE(Panel_Platform
, Panel_withAnims
)
585 EVT_BUTTON (ID_ZOOM_M
, Panel_Platform::EvtButtonClick
)
586 EVT_BUTTON (ID_ZOOM_P
, Panel_Platform::EvtButtonClick
)