2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "entityinspector.h"
24 #include "debugging/debugging.h"
27 #include "ifilesystem.h"
29 #include "iscenegraph.h"
30 #include "iselection.h"
35 #include <gdk/gdkkeysyms.h>
36 #include <gtk/gtktreemodel.h>
37 #include <gtk/gtktreeview.h>
38 #include <gtk/gtkcellrenderertext.h>
39 #include <gtk/gtktreeselection.h>
40 #include <gtk/gtkliststore.h>
41 #include <gtk/gtktextview.h>
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtktable.h>
44 #include <gtk/gtktogglebutton.h>
45 #include <gtk/gtkcheckbutton.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkvpaned.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkentry.h>
51 #include <gtk/gtkcombobox.h>
55 #include "eclasslib.h"
57 #include "generic/callback.h"
59 #include "stream/stringstream.h"
60 #include "moduleobserver.h"
64 #include "gtkutil/accelerator.h"
65 #include "gtkutil/dialog.h"
66 #include "gtkutil/filechooser.h"
67 #include "gtkutil/messagebox.h"
68 #include "gtkutil/nonmodal.h"
69 #include "gtkutil/button.h"
70 #include "gtkutil/entry.h"
71 #include "gtkutil/container.h"
77 #include "mainframe.h"
78 #include "textureentry.h"
79 #include "groupdialog.h"
81 GtkEntry* numeric_entry_new(){
82 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
83 gtk_widget_show( GTK_WIDGET( entry ) );
84 gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 );
90 typedef std::map<CopiedString, CopiedString> KeyValues;
91 KeyValues g_selectedKeyValues;
92 KeyValues g_selectedDefaultKeyValues;
95 const char* SelectedEntity_getValueForKey( const char* key ){
97 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
98 if ( i != g_selectedKeyValues.end() ) {
99 return ( *i ).second.c_str();
103 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
104 if ( i != g_selectedDefaultKeyValues.end() ) {
105 return ( *i ).second.c_str();
111 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
112 StringOutputStream command( 256 );
113 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
114 UndoableCommand undo( command.c_str() );
115 Scene_EntitySetKeyValue_Selected( key, value );
118 class EntityAttribute
121 virtual GtkWidget* getWidget() const = 0;
122 virtual void update() = 0;
123 virtual void release() = 0;
126 class BooleanAttribute : public EntityAttribute
129 GtkCheckButton* m_check;
131 static gboolean toggled( GtkWidget *widget, BooleanAttribute* self ){
136 BooleanAttribute( const char* key ) :
139 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
140 gtk_widget_show( GTK_WIDGET( check ) );
144 guint handler = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( toggled ), this );
145 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
149 GtkWidget* getWidget() const {
150 return GTK_WIDGET( m_check );
156 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_check ) ) ? "1" : "0" );
158 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
161 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
162 if ( !string_empty( value ) ) {
163 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), atoi( value ) != 0 );
167 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), false );
170 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
174 class StringAttribute : public EntityAttribute
178 NonModalEntry m_nonModal;
180 StringAttribute( const char* key ) :
183 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
184 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
185 gtk_widget_show( GTK_WIDGET( entry ) );
186 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
189 m_nonModal.connect( m_entry );
191 GtkWidget* getWidget() const {
192 return GTK_WIDGET( m_entry );
194 GtkEntry* getEntry() const {
202 StringOutputStream value( 64 );
203 value << gtk_entry_get_text( m_entry );
204 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
206 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
209 StringOutputStream value( 64 );
210 value << SelectedEntity_getValueForKey( m_key.c_str() );
211 gtk_entry_set_text( m_entry, value.c_str() );
213 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
216 class ShaderAttribute : public StringAttribute
219 ShaderAttribute( const char* key ) : StringAttribute( key ){
220 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
225 class ModelAttribute : public EntityAttribute
228 BrowsedPathEntry m_entry;
229 NonModalEntry m_nonModal;
231 ModelAttribute( const char* key ) :
233 m_entry( BrowseCaller( *this ) ),
234 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
235 m_nonModal.connect( m_entry.m_entry.m_entry );
240 GtkWidget* getWidget() const {
241 return GTK_WIDGET( m_entry.m_entry.m_frame );
244 StringOutputStream value( 64 );
245 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
246 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
248 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
250 StringOutputStream value( 64 );
251 value << SelectedEntity_getValueForKey( m_key.c_str() );
252 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
254 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
255 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
256 const char *filename = misc_model_dialog( gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) );
258 if ( filename != 0 ) {
263 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
266 const char* browse_sound( GtkWidget* parent ){
267 StringOutputStream buffer( 1024 );
269 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
271 if ( !file_readable( buffer.c_str() ) ) {
274 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
277 const char* filename = file_dialog( parent, TRUE, "Open Wav File", buffer.c_str(), "sound" );
278 if ( filename != 0 ) {
279 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
280 if ( relative == filename ) {
281 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
288 class SoundAttribute : public EntityAttribute
291 BrowsedPathEntry m_entry;
292 NonModalEntry m_nonModal;
294 SoundAttribute( const char* key ) :
296 m_entry( BrowseCaller( *this ) ),
297 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
298 m_nonModal.connect( m_entry.m_entry.m_entry );
303 GtkWidget* getWidget() const {
304 return GTK_WIDGET( m_entry.m_entry.m_frame );
307 StringOutputStream value( 64 );
308 value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) );
309 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
311 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
313 StringOutputStream value( 64 );
314 value << SelectedEntity_getValueForKey( m_key.c_str() );
315 gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() );
317 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
318 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
319 const char *filename = browse_sound( gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) );
321 if ( filename != 0 ) {
326 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
329 inline double angle_normalised( double angle ){
330 return float_mod( angle, 360.0 );
333 class AngleAttribute : public EntityAttribute
337 NonModalEntry m_nonModal;
339 AngleAttribute( const char* key ) :
342 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
343 GtkEntry* entry = numeric_entry_new();
345 m_nonModal.connect( m_entry );
350 GtkWidget* getWidget() const {
351 return GTK_WIDGET( m_entry );
354 StringOutputStream angle( 32 );
355 angle << angle_normalised( entry_get_float( m_entry ) );
356 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
358 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
361 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
362 if ( !string_empty( value ) ) {
363 StringOutputStream angle( 32 );
364 angle << angle_normalised( atof( value ) );
365 gtk_entry_set_text( m_entry, angle.c_str() );
369 gtk_entry_set_text( m_entry, "0" );
372 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
377 typedef const char* String;
378 const String buttons[] = { "up", "down", "z-axis" };
381 class DirectionAttribute : public EntityAttribute
385 NonModalEntry m_nonModal;
387 NonModalRadio m_nonModalRadio;
390 DirectionAttribute( const char* key ) :
393 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
394 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
395 m_nonModalRadio( ApplyRadioCaller( *this ) ){
396 GtkEntry* entry = numeric_entry_new();
398 m_nonModal.connect( m_entry );
400 m_nonModalRadio.connect( m_radio.m_radio );
402 m_hbox = GTK_HBOX( gtk_hbox_new( FALSE, 4 ) );
403 gtk_widget_show( GTK_WIDGET( m_hbox ) );
405 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_radio.m_hbox ), TRUE, TRUE, 0 );
406 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_entry ), TRUE, TRUE, 0 );
411 GtkWidget* getWidget() const {
412 return GTK_WIDGET( m_hbox );
415 StringOutputStream angle( 32 );
416 angle << angle_normalised( entry_get_float( m_entry ) );
417 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
419 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
422 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
423 if ( !string_empty( value ) ) {
424 float f = float(atof( value ) );
426 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
427 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
428 gtk_entry_set_text( m_entry, "" );
430 else if ( f == -2 ) {
431 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
432 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
433 gtk_entry_set_text( m_entry, "" );
437 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), TRUE );
438 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
439 StringOutputStream angle( 32 );
440 angle << angle_normalised( f );
441 gtk_entry_set_text( m_entry, angle.c_str() );
446 gtk_entry_set_text( m_entry, "0" );
449 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
452 int index = radio_button_get_active( m_radio.m_radio );
454 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
456 else if ( index == 1 ) {
457 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
459 else if ( index == 2 ) {
463 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
473 AnglesEntry() : m_roll( 0 ), m_pitch( 0 ), m_yaw( 0 ){
477 typedef BasicVector3<double> DoubleVector3;
479 class AnglesAttribute : public EntityAttribute
482 AnglesEntry m_angles;
483 NonModalEntry m_nonModal;
486 AnglesAttribute( const char* key ) :
488 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
489 m_hbox = GTK_BOX( gtk_hbox_new( TRUE, 4 ) );
490 gtk_widget_show( GTK_WIDGET( m_hbox ) );
492 GtkEntry* entry = numeric_entry_new();
493 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
494 m_angles.m_pitch = entry;
495 m_nonModal.connect( m_angles.m_pitch );
498 GtkEntry* entry = numeric_entry_new();
499 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
500 m_angles.m_yaw = entry;
501 m_nonModal.connect( m_angles.m_yaw );
504 GtkEntry* entry = numeric_entry_new();
505 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
506 m_angles.m_roll = entry;
507 m_nonModal.connect( m_angles.m_roll );
513 GtkWidget* getWidget() const {
514 return GTK_WIDGET( m_hbox );
517 StringOutputStream angles( 64 );
518 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
519 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
520 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
521 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
523 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
526 StringOutputStream angle( 32 );
527 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
528 if ( !string_empty( value ) ) {
529 DoubleVector3 pitch_yaw_roll;
530 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
531 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
534 angle << angle_normalised( pitch_yaw_roll.x() );
535 gtk_entry_set_text( m_angles.m_pitch, angle.c_str() );
538 angle << angle_normalised( pitch_yaw_roll.y() );
539 gtk_entry_set_text( m_angles.m_yaw, angle.c_str() );
542 angle << angle_normalised( pitch_yaw_roll.z() );
543 gtk_entry_set_text( m_angles.m_roll, angle.c_str() );
548 gtk_entry_set_text( m_angles.m_pitch, "0" );
549 gtk_entry_set_text( m_angles.m_yaw, "0" );
550 gtk_entry_set_text( m_angles.m_roll, "0" );
553 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
562 Vector3Entry() : m_x( 0 ), m_y( 0 ), m_z( 0 ){
566 class Vector3Attribute : public EntityAttribute
569 Vector3Entry m_vector3;
570 NonModalEntry m_nonModal;
573 Vector3Attribute( const char* key ) :
575 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
576 m_hbox = GTK_BOX( gtk_hbox_new( TRUE, 4 ) );
577 gtk_widget_show( GTK_WIDGET( m_hbox ) );
579 GtkEntry* entry = numeric_entry_new();
580 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
581 m_vector3.m_x = entry;
582 m_nonModal.connect( m_vector3.m_x );
585 GtkEntry* entry = numeric_entry_new();
586 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
587 m_vector3.m_y = entry;
588 m_nonModal.connect( m_vector3.m_y );
591 GtkEntry* entry = numeric_entry_new();
592 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
593 m_vector3.m_z = entry;
594 m_nonModal.connect( m_vector3.m_z );
600 GtkWidget* getWidget() const {
601 return GTK_WIDGET( m_hbox );
604 StringOutputStream vector3( 64 );
605 vector3 << entry_get_float( m_vector3.m_x )
606 << " " << entry_get_float( m_vector3.m_y )
607 << " " << entry_get_float( m_vector3.m_z );
608 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
610 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
613 StringOutputStream buffer( 32 );
614 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
615 if ( !string_empty( value ) ) {
617 if ( !string_parse_vector3( value, x_y_z ) ) {
618 x_y_z = DoubleVector3( 0, 0, 0 );
622 gtk_entry_set_text( m_vector3.m_x, buffer.c_str() );
626 gtk_entry_set_text( m_vector3.m_y, buffer.c_str() );
630 gtk_entry_set_text( m_vector3.m_z, buffer.c_str() );
635 gtk_entry_set_text( m_vector3.m_x, "0" );
636 gtk_entry_set_text( m_vector3.m_y, "0" );
637 gtk_entry_set_text( m_vector3.m_z, "0" );
640 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
643 class NonModalComboBox
646 guint m_changedHandler;
648 static gboolean changed( GtkComboBox *widget, NonModalComboBox* self ){
654 NonModalComboBox( const Callback& changed ) : m_changed( changed ), m_changedHandler( 0 ){
656 void connect( GtkComboBox* combo ){
657 m_changedHandler = g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( changed ), this );
659 void setActive( GtkComboBox* combo, int value ){
660 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
661 gtk_combo_box_set_active( combo, value );
666 class ListAttribute : public EntityAttribute
669 GtkComboBox* m_combo;
670 NonModalComboBox m_nonModal;
671 const ListAttributeType& m_type;
673 ListAttribute( const char* key, const ListAttributeType& type ) :
676 m_nonModal( ApplyCaller( *this ) ),
678 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
680 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
682 gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), ( *i ).first.c_str() );
685 gtk_widget_show( GTK_WIDGET( combo ) );
686 m_nonModal.connect( combo );
693 GtkWidget* getWidget() const {
694 return GTK_WIDGET( m_combo );
697 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
699 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
702 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
703 ListAttributeType::const_iterator i = m_type.findValue( value );
704 if ( i != m_type.end() ) {
705 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
709 m_nonModal.setActive( m_combo, 0 );
712 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
718 GtkWidget* g_entity_split1 = 0;
719 GtkWidget* g_entity_split2 = 0;
720 int g_entitysplit1_position;
721 int g_entitysplit2_position;
723 bool g_entityInspector_windowConstructed = false;
725 GtkTreeView* g_entityClassList;
726 GtkTextView* g_entityClassComment;
728 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
730 GtkEntry* g_entityKeyEntry;
731 GtkEntry* g_entityValueEntry;
733 GtkListStore* g_entlist_store;
734 GtkListStore* g_entprops_store;
735 const EntityClass* g_current_flags = 0;
736 const EntityClass* g_current_comment = 0;
737 const EntityClass* g_current_attributes = 0;
739 // the number of active spawnflags
740 int g_spawnflag_count;
741 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
742 int spawn_table[MAX_FLAGS];
743 // we change the layout depending on how many spawn flags we need to display
744 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
745 GtkTable* g_spawnflagsTable;
747 GtkVBox* g_attributeBox = 0;
748 typedef std::vector<EntityAttribute*> EntityAttributes;
749 EntityAttributes g_entityAttributes;
752 void GlobalEntityAttributes_clear(){
753 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
757 g_entityAttributes.clear();
760 class GetKeyValueVisitor : public Entity::Visitor
762 KeyValues& m_keyvalues;
764 GetKeyValueVisitor( KeyValues& keyvalues )
765 : m_keyvalues( keyvalues ){
768 void visit( const char* key, const char* value ){
769 m_keyvalues.insert( KeyValues::value_type( CopiedString( key ), CopiedString( value ) ) );
774 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
775 GetKeyValueVisitor visitor( keyvalues );
777 entity.forEachKeyValue( visitor );
779 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
781 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
783 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
787 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
788 class EntityGetKeyValues : public SelectionSystem::Visitor
790 KeyValues& m_keyvalues;
791 KeyValues& m_defaultValues;
792 mutable std::set<Entity*> m_visited;
794 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
795 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
797 void visit( scene::Instance& instance ) const {
798 Entity* entity = Node_getEntity( instance.path().top() );
799 if ( entity == 0 && instance.path().size() != 1 ) {
800 entity = Node_getEntity( instance.path().parent() );
802 if ( entity != 0 && m_visited.insert( entity ).second ) {
803 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
806 } visitor( keyvalues, defaultValues );
807 GlobalSelectionSystem().foreachSelected( visitor );
810 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
811 KeyValues::iterator i = keyvalues.find( CopiedString( key ) );
812 if ( i != keyvalues.end() ) {
813 return ( *i ).second.c_str();
818 class EntityClassListStoreAppend : public EntityClassVisitor
822 EntityClassListStoreAppend( GtkListStore* store_ ) : store( store_ ){
824 void visit( EntityClass* e ){
826 gtk_list_store_append( store, &iter );
827 gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
831 void EntityClassList_fill(){
832 EntityClassListStoreAppend append( g_entlist_store );
833 GlobalEntityClassManager().forEach( append );
836 void EntityClassList_clear(){
837 gtk_list_store_clear( g_entlist_store );
840 void SetComment( EntityClass* eclass ){
841 if ( eclass == g_current_comment ) {
845 g_current_comment = eclass;
847 GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment );
848 gtk_text_buffer_set_text( buffer, eclass->comments(), -1 );
851 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
852 if ( eclass == g_current_flags ) {
856 g_current_flags = eclass;
858 int spawnflag_count = 0;
861 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
862 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
864 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
865 spawn_table[spawnflag_count] = i;
871 // disable all remaining boxes
872 // NOTE: these boxes might not even be on display
874 for ( int i = 0; i < g_spawnflag_count; ++i )
876 GtkWidget* widget = GTK_WIDGET( g_entitySpawnflagsCheck[i] );
877 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), " " );
878 gtk_widget_hide( widget );
879 gtk_widget_ref( widget );
880 gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget );
884 g_spawnflag_count = spawnflag_count;
887 for ( int i = 0; i < g_spawnflag_count; ++i )
889 GtkWidget* widget = GTK_WIDGET( g_entitySpawnflagsCheck[i] );
890 gtk_widget_show( widget );
892 StringOutputStream str( 16 );
893 str << LowerCase( eclass->flagnames[spawn_table[i]] );
895 gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1,
896 (GtkAttachOptions)( GTK_FILL ),
897 (GtkAttachOptions)( GTK_FILL ), 0, 0 );
898 gtk_widget_unref( widget );
900 gtk_label_set_text( GTK_LABEL( GTK_BIN( widget )->child ), str.c_str() );
905 void EntityClassList_selectEntityClass( EntityClass* eclass ){
906 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
908 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
911 gtk_tree_model_get( model, &iter, 0, &text, -1 );
912 if ( strcmp( text, eclass->name() ) == 0 ) {
913 GtkTreeView* view = g_entityClassList;
914 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
915 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
916 if ( GTK_WIDGET_REALIZED( view ) ) {
917 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
919 gtk_tree_path_free( path );
926 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
927 GtkTable* row = DialogRow_new( name, attribute.getWidget() );
928 DialogVBox_packRow( g_attributeBox, GTK_WIDGET( row ) );
932 template<typename Attribute>
933 class StatelessAttributeCreator
936 static EntityAttribute* create( const char* name ){
937 return new Attribute( name );
941 class EntityAttributeFactory
943 typedef EntityAttribute* ( *CreateFunc )( const char* name );
944 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
947 EntityAttributeFactory(){
948 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
949 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
950 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
951 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
952 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
953 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
954 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
955 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
956 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
957 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
958 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
959 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
960 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
962 EntityAttribute* create( const char* type, const char* name ){
963 Creators::iterator i = m_creators.find( type );
964 if ( i != m_creators.end() ) {
965 return ( *i ).second( name );
967 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
968 if ( listType != 0 ) {
969 return new ListAttribute( name, *listType );
975 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
977 void EntityInspector_setEntityClass( EntityClass *eclass ){
978 EntityClassList_selectEntityClass( eclass );
979 SurfaceFlags_setEntityClass( eclass );
981 if ( eclass != g_current_attributes ) {
982 g_current_attributes = eclass;
984 container_remove_all( GTK_CONTAINER( g_attributeBox ) );
985 GlobalEntityAttributes_clear();
987 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
989 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
990 if ( attribute != 0 ) {
991 g_entityAttributes.push_back( attribute );
992 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
998 void EntityInspector_updateSpawnflags(){
1000 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
1001 for ( int i = 0; i < g_spawnflag_count; ++i )
1003 int v = !!( f & ( 1 << spawn_table[i] ) );
1005 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), v );
1009 // take care of the remaining ones
1010 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1012 toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), FALSE );
1017 void EntityInspector_applySpawnflags(){
1022 for ( i = 0; i < g_spawnflag_count; ++i )
1024 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1025 f |= v << spawn_table[i];
1028 sprintf( sz, "%i", f );
1029 const char* value = ( f == 0 ) ? "" : sz;
1032 StringOutputStream command;
1033 command << "entitySetFlags -flags " << f;
1034 UndoableCommand undo( "entitySetSpawnflags" );
1036 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1041 void EntityInspector_updateKeyValues(){
1042 g_selectedKeyValues.clear();
1043 g_selectedDefaultKeyValues.clear();
1044 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1046 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1048 EntityInspector_updateSpawnflags();
1050 GtkListStore* store = g_entprops_store;
1052 // save current key/val pair around filling epair box
1053 // row_select wipes it and sets to first in list
1054 CopiedString strKey( gtk_entry_get_text( g_entityKeyEntry ) );
1055 CopiedString strVal( gtk_entry_get_text( g_entityValueEntry ) );
1057 gtk_list_store_clear( store );
1058 // Walk through list and add pairs
1059 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1062 gtk_list_store_append( store, &iter );
1063 StringOutputStream key( 64 );
1064 key << ( *i ).first.c_str();
1065 StringOutputStream value( 64 );
1066 value << ( *i ).second.c_str();
1067 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1070 gtk_entry_set_text( g_entityKeyEntry, strKey.c_str() );
1071 gtk_entry_set_text( g_entityValueEntry, strVal.c_str() );
1073 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1079 class EntityInspectorDraw
1081 IdleDraw m_idleDraw;
1083 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1086 m_idleDraw.queueDraw();
1090 EntityInspectorDraw g_EntityInspectorDraw;
1093 void EntityInspector_keyValueChanged(){
1094 g_EntityInspectorDraw.queueDraw();
1096 void EntityInspector_selectionChanged( const Selectable& ){
1097 EntityInspector_keyValueChanged();
1100 // Creates a new entity based on the currently selected brush and entity type.
1102 void EntityClassList_createEntity(){
1103 GtkTreeView* view = g_entityClassList;
1105 // find out what type of entity we are trying to create
1106 GtkTreeModel* model;
1108 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1109 gtk_MessageBox( gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) ), "You must have a selected class to create an entity", "info" );
1114 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1117 StringOutputStream command;
1118 command << "entityCreate -class " << text;
1120 UndoableCommand undo( command.c_str() );
1122 Entity_createFromSelection( text, g_vector3_identity );
1127 void EntityInspector_applyKeyValue(){
1128 // Get current selection text
1129 StringOutputStream key( 64 );
1130 key << gtk_entry_get_text( g_entityKeyEntry );
1131 StringOutputStream value( 64 );
1132 value << gtk_entry_get_text( g_entityValueEntry );
1135 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1136 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1137 gtk_MessageBox( gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry ) ), "Cannot change \"classname\" key back to worldspawn.", 0, eMB_OK );
1142 // RR2DO2: we don't want spaces in entity keys
1143 if ( strstr( key.c_str(), " " ) ) {
1144 gtk_MessageBox( gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry ) ), "No spaces are allowed in entity keys.", 0, eMB_OK );
1148 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1149 StringOutputStream command;
1150 command << "entitySetClass -class " << value.c_str();
1151 UndoableCommand undo( command.c_str() );
1152 Scene_EntitySetClassname_Selected( value.c_str() );
1156 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1160 void EntityInspector_clearKeyValue(){
1161 // Get current selection text
1162 StringOutputStream key( 64 );
1163 key << gtk_entry_get_text( g_entityKeyEntry );
1165 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1166 StringOutputStream command;
1167 command << "entityDeleteKey -key " << key.c_str();
1168 UndoableCommand undo( command.c_str() );
1169 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1173 void EntityInspector_clearAllKeyValues(){
1174 UndoableCommand undo( "entityClear" );
1176 // remove all keys except classname
1177 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1179 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1180 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1185 // =============================================================================
1188 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1189 GtkTreeModel* model;
1190 GtkTreeIter selected;
1191 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1192 EntityClass* eclass;
1193 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1194 if ( eclass != 0 ) {
1195 SetComment( eclass );
1200 static gint EntityClassList_button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){
1201 if ( event->type == GDK_2BUTTON_PRESS ) {
1202 EntityClassList_createEntity();
1208 static gint EntityClassList_keypress( GtkWidget* widget, GdkEventKey* event, gpointer data ){
1209 unsigned int code = gdk_keyval_to_upper( event->keyval );
1211 if ( event->keyval == GDK_Return ) {
1212 EntityClassList_createEntity();
1216 // select the entity that starts with the key pressed
1217 if ( code <= 'Z' && code >= 'A' ) {
1218 GtkTreeView* view = g_entityClassList;
1219 GtkTreeModel* model;
1221 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1222 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1223 gtk_tree_model_get_iter_first( model, &iter );
1226 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1229 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1231 if ( toupper( text[0] ) == (int)code ) {
1232 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1233 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1234 if ( GTK_WIDGET_REALIZED( view ) ) {
1235 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1237 gtk_tree_path_free( path );
1243 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1244 gtk_tree_model_get_iter_first( model, &iter );
1253 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1254 // find out what type of entity we are trying to create
1255 GtkTreeModel* model;
1257 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1263 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1265 gtk_entry_set_text( g_entityKeyEntry, key );
1266 gtk_entry_set_text( g_entityValueEntry, val );
1272 static void SpawnflagCheck_toggled( GtkWidget *widget, gpointer data ){
1273 EntityInspector_applySpawnflags();
1276 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1277 if ( event->keyval == GDK_Return ) {
1278 if ( widget == g_entityKeyEntry ) {
1279 gtk_entry_set_text( g_entityValueEntry, "" );
1280 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1284 EntityInspector_applyKeyValue();
1288 if ( event->keyval == GDK_Escape ) {
1289 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1296 void EntityInspector_destroyWindow( GtkWidget* widget, gpointer data ){
1297 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1298 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1300 g_entityInspector_windowConstructed = false;
1301 GlobalEntityAttributes_clear();
1304 GtkWidget* EntityInspector_constructWindow( GtkWindow* toplevel ){
1305 GtkWidget* vbox = gtk_vbox_new( FALSE, 2 );
1306 gtk_widget_show( vbox );
1307 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1309 g_signal_connect( G_OBJECT( vbox ), "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1312 GtkWidget* split1 = gtk_vpaned_new();
1313 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1314 gtk_widget_show( split1 );
1316 g_entity_split1 = split1;
1319 GtkWidget* split2 = gtk_vpaned_new();
1320 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1321 gtk_widget_show( split2 );
1323 g_entity_split2 = split2;
1327 GtkWidget* scr = gtk_scrolled_window_new( 0, 0 );
1328 gtk_widget_show( scr );
1329 gtk_paned_add1( GTK_PANED( split2 ), scr );
1330 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1331 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1334 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER );
1336 GtkTreeView* view = GTK_TREE_VIEW( gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) ) );
1337 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1338 gtk_tree_view_set_headers_visible( view, FALSE );
1339 g_signal_connect( G_OBJECT( view ), "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1340 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1343 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1344 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Key", renderer, "text", 0, 0 );
1345 gtk_tree_view_append_column( view, column );
1349 GtkTreeSelection* selection = gtk_tree_view_get_selection( view );
1350 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1353 gtk_widget_show( GTK_WIDGET( view ) );
1355 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( view ) );
1357 g_object_unref( G_OBJECT( store ) );
1358 g_entityClassList = view;
1359 g_entlist_store = store;
1364 GtkWidget* scr = gtk_scrolled_window_new( 0, 0 );
1365 gtk_widget_show( scr );
1366 gtk_paned_add2( GTK_PANED( split2 ), scr );
1367 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1368 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1371 GtkTextView* text = GTK_TEXT_VIEW( gtk_text_view_new() );
1372 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1373 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1374 gtk_text_view_set_editable( text, FALSE );
1375 gtk_widget_show( GTK_WIDGET( text ) );
1376 gtk_container_add( GTK_CONTAINER( scr ), GTK_WIDGET( text ) );
1377 g_entityClassComment = text;
1383 GtkWidget* split2 = gtk_vpaned_new();
1384 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1385 gtk_widget_show( split2 );
1388 GtkWidget* vbox2 = gtk_vbox_new( FALSE, 2 );
1389 gtk_widget_show( vbox2 );
1390 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1393 // Spawnflags (4 colums wide max, or window gets too wide.)
1394 GtkTable* table = GTK_TABLE( gtk_table_new( 4, 4, FALSE ) );
1395 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1396 gtk_widget_show( GTK_WIDGET( table ) );
1398 g_spawnflagsTable = table;
1400 for ( int i = 0; i < MAX_FLAGS; i++ )
1402 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new_with_label( "" ) );
1403 gtk_widget_ref( GTK_WIDGET( check ) );
1404 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1405 g_entitySpawnflagsCheck[i] = check;
1411 GtkWidget* scr = gtk_scrolled_window_new( 0, 0 );
1412 gtk_widget_show( scr );
1413 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1414 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1415 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1418 GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING );
1420 GtkWidget* view = gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) );
1421 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1422 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1425 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1426 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, 0 );
1427 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1431 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1432 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 1, 0 );
1433 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1437 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
1438 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1441 gtk_widget_show( view );
1443 gtk_container_add( GTK_CONTAINER( scr ), view );
1445 g_object_unref( G_OBJECT( store ) );
1447 g_entprops_store = store;
1453 GtkTable* table = GTK_TABLE( gtk_table_new( 2, 2, FALSE ) );
1454 gtk_widget_show( GTK_WIDGET( table ) );
1455 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1456 gtk_table_set_row_spacings( table, 3 );
1457 gtk_table_set_col_spacings( table, 5 );
1460 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
1461 gtk_widget_show( GTK_WIDGET( entry ) );
1462 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1463 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1464 (GtkAttachOptions)( 0 ), 0, 0 );
1465 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1466 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1467 g_entityKeyEntry = entry;
1471 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
1472 gtk_widget_show( GTK_WIDGET( entry ) );
1473 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1474 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1475 (GtkAttachOptions)( 0 ), 0, 0 );
1476 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1477 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1478 g_entityValueEntry = entry;
1482 GtkLabel* label = GTK_LABEL( gtk_label_new( "Value" ) );
1483 gtk_widget_show( GTK_WIDGET( label ) );
1484 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1485 (GtkAttachOptions)( GTK_FILL ),
1486 (GtkAttachOptions)( 0 ), 0, 0 );
1487 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1491 GtkLabel* label = GTK_LABEL( gtk_label_new( "Key" ) );
1492 gtk_widget_show( GTK_WIDGET( label ) );
1493 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1494 (GtkAttachOptions)( GTK_FILL ),
1495 (GtkAttachOptions)( 0 ), 0, 0 );
1496 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1501 GtkBox* hbox = GTK_BOX( gtk_hbox_new( TRUE, 4 ) );
1502 gtk_widget_show( GTK_WIDGET( hbox ) );
1503 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1506 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Clear All" ) );
1507 gtk_widget_show( GTK_WIDGET( button ) );
1508 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1509 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1512 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Delete Key" ) );
1513 gtk_widget_show( GTK_WIDGET( button ) );
1514 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1515 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1521 GtkWidget* scr = gtk_scrolled_window_new( 0, 0 );
1522 gtk_widget_show( scr );
1523 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1525 GtkWidget* viewport = gtk_viewport_new( 0, 0 );
1526 gtk_widget_show( viewport );
1527 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1529 g_attributeBox = GTK_VBOX( gtk_vbox_new( FALSE, 2 ) );
1530 gtk_widget_show( GTK_WIDGET( g_attributeBox ) );
1532 gtk_container_add( GTK_CONTAINER( viewport ), GTK_WIDGET( g_attributeBox ) );
1533 gtk_container_add( GTK_CONTAINER( scr ), viewport );
1534 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1541 // show the sliders in any case
1542 if ( g_entitysplit2_position > 22 ) {
1543 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1546 g_entitysplit2_position = 22;
1547 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1549 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1550 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1553 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1557 g_entityInspector_windowConstructed = true;
1558 EntityClassList_fill();
1560 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1561 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1562 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1565 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1570 class EntityInspector : public ModuleObserver
1572 std::size_t m_unrealised;
1574 EntityInspector() : m_unrealised( 1 ){
1577 if ( --m_unrealised == 0 ) {
1578 if ( g_entityInspector_windowConstructed ) {
1579 //globalOutputStream() << "Entity Inspector: realise\n";
1580 EntityClassList_fill();
1585 if ( ++m_unrealised == 1 ) {
1586 if ( g_entityInspector_windowConstructed ) {
1587 //globalOutputStream() << "Entity Inspector: unrealise\n";
1588 EntityClassList_clear();
1594 EntityInspector g_EntityInspector;
1596 #include "preferencesystem.h"
1597 #include "stringio.h"
1599 void EntityInspector_construct(){
1600 GlobalEntityClassManager().attach( g_EntityInspector );
1602 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1603 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1607 void EntityInspector_destroy(){
1608 GlobalEntityClassManager().detach( g_EntityInspector );
1611 const char *EntityInspector_getCurrentKey(){
1612 if ( !GroupDialog_isShown() ) {
1615 if ( GroupDialog_getPage() != g_page_entity ) {
1618 return gtk_entry_get_text( g_entityKeyEntry );