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"
28 #include "ifilesystem.h"
30 #include "iscenegraph.h"
31 #include "iselection.h"
36 #include <gdk/gdkkeysyms.h>
37 #include <uilib/uilib.h>
38 #include <util/buffer.h>
42 #include "eclasslib.h"
44 #include "generic/callback.h"
46 #include "stream/stringstream.h"
47 #include "moduleobserver.h"
51 #include "gtkutil/accelerator.h"
52 #include "gtkutil/dialog.h"
53 #include "gtkutil/filechooser.h"
54 #include "gtkutil/messagebox.h"
55 #include "gtkutil/nonmodal.h"
56 #include "gtkutil/button.h"
57 #include "gtkutil/entry.h"
58 #include "gtkutil/container.h"
64 #include "mainframe.h"
65 #include "textureentry.h"
66 #include "groupdialog.h"
68 ui::Entry numeric_entry_new(){
69 auto entry = ui::Entry(ui::New);
71 entry.dimensions(64, -1);
77 typedef std::map<CopiedString, CopiedString> KeyValues;
78 KeyValues g_selectedKeyValues;
79 KeyValues g_selectedDefaultKeyValues;
82 const char* SelectedEntity_getValueForKey( const char* key ){
84 KeyValues::const_iterator i = g_selectedKeyValues.find( key );
85 if ( i != g_selectedKeyValues.end() ) {
86 return ( *i ).second.c_str();
90 KeyValues::const_iterator i = g_selectedDefaultKeyValues.find( key );
91 if ( i != g_selectedDefaultKeyValues.end() ) {
92 return ( *i ).second.c_str();
98 void Scene_EntitySetKeyValue_Selected_Undoable( const char* key, const char* value ){
99 StringOutputStream command( 256 );
100 command << "entitySetKeyValue -key " << makeQuoted( key ) << " -value " << makeQuoted( value );
101 UndoableCommand undo( command.c_str() );
102 Scene_EntitySetKeyValue_Selected( key, value );
105 class EntityAttribute
108 virtual ~EntityAttribute() = default;
109 virtual ui::Widget getWidget() const = 0;
110 virtual void update() = 0;
111 virtual void release() = 0;
114 class BooleanAttribute : public EntityAttribute
117 ui::CheckButton m_check;
119 static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){
124 BooleanAttribute( const char* key ) :
127 auto check = ui::CheckButton(ui::New);
132 guint handler = check.connect( "toggled", G_CALLBACK( toggled ), this );
133 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler ) );
137 ui::Widget getWidget() const {
144 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_check.active() ? "1" : "0" );
146 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::apply> ApplyCaller;
149 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
150 if ( !string_empty( value ) ) {
151 toggle_button_set_active_no_signal( m_check, atoi( value ) != 0 );
155 toggle_button_set_active_no_signal( m_check, false );
158 typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
162 class StringAttribute : public EntityAttribute
166 NonModalEntry m_nonModal;
168 StringAttribute( const char* key ) :
171 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
172 auto entry = ui::Entry(ui::New);
174 entry.dimensions(50, -1);
177 m_nonModal.connect( m_entry );
179 ui::Widget getWidget() const {
182 ui::Entry getEntry() const {
190 StringOutputStream value( 64 );
191 value << m_entry.text();
192 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
194 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
197 StringOutputStream value( 64 );
198 value << SelectedEntity_getValueForKey( m_key.c_str() );
199 m_entry.text(value.c_str());
201 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
204 class ShaderAttribute : public StringAttribute
207 ShaderAttribute( const char* key ) : StringAttribute( key ){
208 GlobalShaderEntryCompletion::instance().connect( StringAttribute::getEntry() );
213 class ModelAttribute : public EntityAttribute
216 BrowsedPathEntry m_entry;
217 NonModalEntry m_nonModal;
219 ModelAttribute( const char* key ) :
221 m_entry( BrowseCaller( *this ) ),
222 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
223 m_nonModal.connect( m_entry.m_entry.m_entry );
228 ui::Widget getWidget() const {
229 return m_entry.m_entry.m_frame;
232 StringOutputStream value( 64 );
233 value << m_entry.m_entry.m_entry.text();
234 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
236 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
238 StringOutputStream value( 64 );
239 value << SelectedEntity_getValueForKey( m_key.c_str() );
240 m_entry.m_entry.m_entry.text(value.c_str());
242 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
243 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
244 const char *filename = misc_model_dialog( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) ) ));
246 if ( filename != 0 ) {
251 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse> BrowseCaller;
254 const char* browse_sound( ui::Widget parent ){
255 StringOutputStream buffer( 1024 );
257 buffer << g_qeglobals.m_userGamePath.c_str() << "sound/";
259 if ( !file_readable( buffer.c_str() ) ) {
262 buffer << g_qeglobals.m_userGamePath.c_str() << "/";
265 const char* filename = parent.file_dialog(TRUE, "Open Wav File", buffer.c_str(), "sound" );
266 if ( filename != 0 ) {
267 const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
268 if ( relative == filename ) {
269 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
276 class SoundAttribute : public EntityAttribute
279 BrowsedPathEntry m_entry;
280 NonModalEntry m_nonModal;
282 SoundAttribute( const char* key ) :
284 m_entry( BrowseCaller( *this ) ),
285 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
286 m_nonModal.connect( m_entry.m_entry.m_entry );
291 ui::Widget getWidget() const {
292 return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame ));
295 StringOutputStream value( 64 );
296 value << m_entry.m_entry.m_entry.text();
297 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() );
299 typedef MemberCaller<SoundAttribute, &SoundAttribute::apply> ApplyCaller;
301 StringOutputStream value( 64 );
302 value << SelectedEntity_getValueForKey( m_key.c_str() );
303 m_entry.m_entry.m_entry.text(value.c_str());
305 typedef MemberCaller<SoundAttribute, &SoundAttribute::update> UpdateCaller;
306 void browse( const BrowsedPathEntry::SetPathCallback& setPath ){
307 const char *filename = browse_sound( ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( m_entry.m_entry.m_frame ) )) );
309 if ( filename != 0 ) {
314 typedef MemberCaller1<SoundAttribute, const BrowsedPathEntry::SetPathCallback&, &SoundAttribute::browse> BrowseCaller;
317 inline double angle_normalised( double angle ){
318 return float_mod( angle, 360.0 );
321 class AngleAttribute : public EntityAttribute
325 NonModalEntry m_nonModal;
327 AngleAttribute( const char* key ) :
330 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
331 auto entry = numeric_entry_new();
333 m_nonModal.connect( m_entry );
338 ui::Widget getWidget() const {
339 return ui::Widget(GTK_WIDGET( m_entry ));
342 StringOutputStream angle( 32 );
343 angle << angle_normalised( entry_get_float( m_entry ) );
344 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
346 typedef MemberCaller<AngleAttribute, &AngleAttribute::apply> ApplyCaller;
349 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
350 if ( !string_empty( value ) ) {
351 StringOutputStream angle( 32 );
352 angle << angle_normalised( atof( value ) );
353 m_entry.text(angle.c_str());
360 typedef MemberCaller<AngleAttribute, &AngleAttribute::update> UpdateCaller;
365 typedef const char* String;
366 const String buttons[] = { "up", "down", "z-axis" };
369 class DirectionAttribute : public EntityAttribute
373 NonModalEntry m_nonModal;
375 NonModalRadio m_nonModalRadio;
376 ui::HBox m_hbox{ui::null};
378 DirectionAttribute( const char* key ) :
381 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
382 m_radio( RadioHBox_new( STRING_ARRAY_RANGE( buttons ) ) ),
383 m_nonModalRadio( ApplyRadioCaller( *this ) ){
384 auto entry = numeric_entry_new();
386 m_nonModal.connect( m_entry );
388 m_nonModalRadio.connect( m_radio.m_radio );
390 m_hbox = ui::HBox( FALSE, 4 );
393 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_radio.m_hbox ), TRUE, TRUE, 0 );
394 gtk_box_pack_start( GTK_BOX( m_hbox ), GTK_WIDGET( m_entry ), TRUE, TRUE, 0 );
399 ui::Widget getWidget() const {
400 return ui::Widget(GTK_WIDGET( m_hbox ));
403 StringOutputStream angle( 32 );
404 angle << angle_normalised( entry_get_float( m_entry ) );
405 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angle.c_str() );
407 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::apply> ApplyCaller;
410 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
411 if ( !string_empty( value ) ) {
412 float f = float(atof( value ) );
414 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
415 radio_button_set_active_no_signal( m_radio.m_radio, 0 );
418 else if ( f == -2 ) {
419 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE );
420 radio_button_set_active_no_signal( m_radio.m_radio, 1 );
425 gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), TRUE );
426 radio_button_set_active_no_signal( m_radio.m_radio, 2 );
427 StringOutputStream angle( 32 );
428 angle << angle_normalised( f );
429 m_entry.text(angle.c_str());
437 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::update> UpdateCaller;
440 int index = radio_button_get_active( m_radio.m_radio );
442 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-1" );
444 else if ( index == 1 ) {
445 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), "-2" );
447 else if ( index == 2 ) {
451 typedef MemberCaller<DirectionAttribute, &DirectionAttribute::applyRadio> ApplyRadioCaller;
461 AnglesEntry() : m_roll( ui::null ), m_pitch( ui::null ), m_yaw( ui::null ){
465 typedef BasicVector3<double> DoubleVector3;
467 class AnglesAttribute : public EntityAttribute
470 AnglesEntry m_angles;
471 NonModalEntry m_nonModal;
474 AnglesAttribute( const char* key ) :
476 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ),
477 m_hbox(ui::HBox( TRUE, 4 ))
481 auto entry = numeric_entry_new();
482 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
483 m_angles.m_pitch = entry;
484 m_nonModal.connect( m_angles.m_pitch );
487 auto entry = numeric_entry_new();
488 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
489 m_angles.m_yaw = entry;
490 m_nonModal.connect( m_angles.m_yaw );
493 auto entry = numeric_entry_new();
494 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
495 m_angles.m_roll = entry;
496 m_nonModal.connect( m_angles.m_roll );
502 ui::Widget getWidget() const {
503 return ui::Widget(GTK_WIDGET( m_hbox ));
506 StringOutputStream angles( 64 );
507 angles << angle_normalised( entry_get_float( m_angles.m_pitch ) )
508 << " " << angle_normalised( entry_get_float( m_angles.m_yaw ) )
509 << " " << angle_normalised( entry_get_float( m_angles.m_roll ) );
510 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), angles.c_str() );
512 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::apply> ApplyCaller;
515 StringOutputStream angle( 32 );
516 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
517 if ( !string_empty( value ) ) {
518 DoubleVector3 pitch_yaw_roll;
519 if ( !string_parse_vector3( value, pitch_yaw_roll ) ) {
520 pitch_yaw_roll = DoubleVector3( 0, 0, 0 );
523 angle << angle_normalised( pitch_yaw_roll.x() );
524 m_angles.m_pitch.text(angle.c_str());
527 angle << angle_normalised( pitch_yaw_roll.y() );
528 m_angles.m_yaw.text(angle.c_str());
531 angle << angle_normalised( pitch_yaw_roll.z() );
532 m_angles.m_roll.text(angle.c_str());
537 m_angles.m_pitch.text("0");
538 m_angles.m_yaw.text("0");
539 m_angles.m_roll.text("0");
542 typedef MemberCaller<AnglesAttribute, &AnglesAttribute::update> UpdateCaller;
551 Vector3Entry() : m_x( ui::null ), m_y( ui::null ), m_z( ui::null ){
555 class Vector3Attribute : public EntityAttribute
558 Vector3Entry m_vector3;
559 NonModalEntry m_nonModal;
560 ui::Box m_hbox{ui::null};
562 Vector3Attribute( const char* key ) :
564 m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){
565 m_hbox = ui::HBox( TRUE, 4 );
568 auto entry = numeric_entry_new();
569 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
570 m_vector3.m_x = entry;
571 m_nonModal.connect( m_vector3.m_x );
574 auto entry = numeric_entry_new();
575 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
576 m_vector3.m_y = entry;
577 m_nonModal.connect( m_vector3.m_y );
580 auto entry = numeric_entry_new();
581 gtk_box_pack_start( m_hbox, GTK_WIDGET( entry ), TRUE, TRUE, 0 );
582 m_vector3.m_z = entry;
583 m_nonModal.connect( m_vector3.m_z );
589 ui::Widget getWidget() const {
590 return ui::Widget(GTK_WIDGET( m_hbox ));
593 StringOutputStream vector3( 64 );
594 vector3 << entry_get_float( m_vector3.m_x )
595 << " " << entry_get_float( m_vector3.m_y )
596 << " " << entry_get_float( m_vector3.m_z );
597 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), vector3.c_str() );
599 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::apply> ApplyCaller;
602 StringOutputStream buffer( 32 );
603 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
604 if ( !string_empty( value ) ) {
606 if ( !string_parse_vector3( value, x_y_z ) ) {
607 x_y_z = DoubleVector3( 0, 0, 0 );
611 m_vector3.m_x.text(buffer.c_str());
615 m_vector3.m_y.text(buffer.c_str());
619 m_vector3.m_z.text(buffer.c_str());
624 m_vector3.m_x.text("0");
625 m_vector3.m_y.text("0");
626 m_vector3.m_z.text("0");
629 typedef MemberCaller<Vector3Attribute, &Vector3Attribute::update> UpdateCaller;
632 class NonModalComboBox
635 guint m_changedHandler;
637 static gboolean changed( GtkComboBox *widget, NonModalComboBox* self ){
643 NonModalComboBox( const Callback& changed ) : m_changed( changed ), m_changedHandler( 0 ){
645 void connect( ui::ComboBox combo ){
646 m_changedHandler = combo.connect( "changed", G_CALLBACK( changed ), this );
648 void setActive( ui::ComboBox combo, int value ){
649 g_signal_handler_disconnect( G_OBJECT( combo ), m_changedHandler );
650 gtk_combo_box_set_active( combo, value );
655 class ListAttribute : public EntityAttribute
658 ui::ComboBox m_combo;
659 NonModalComboBox m_nonModal;
660 const ListAttributeType& m_type;
662 ListAttribute( const char* key, const ListAttributeType& type ) :
665 m_nonModal( ApplyCaller( *this ) ),
667 auto combo = ui::ComboBoxText(ui::New);
669 for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i )
671 gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), ( *i ).first.c_str() );
675 m_nonModal.connect( combo );
682 ui::Widget getWidget() const {
683 return ui::Widget(GTK_WIDGET( m_combo ));
686 Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_type[gtk_combo_box_get_active( m_combo )].second.c_str() );
688 typedef MemberCaller<ListAttribute, &ListAttribute::apply> ApplyCaller;
691 const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
692 ListAttributeType::const_iterator i = m_type.findValue( value );
693 if ( i != m_type.end() ) {
694 m_nonModal.setActive( m_combo, static_cast<int>( std::distance( m_type.begin(), i ) ) );
698 m_nonModal.setActive( m_combo, 0 );
701 typedef MemberCaller<ListAttribute, &ListAttribute::update> UpdateCaller;
707 ui::Widget g_entity_split1{ui::null};
708 ui::Widget g_entity_split2{ui::null};
709 int g_entitysplit1_position;
710 int g_entitysplit2_position;
712 bool g_entityInspector_windowConstructed = false;
714 GtkTreeView* g_entityClassList;
715 ui::TextView g_entityClassComment{ui::null};
717 GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS];
719 ui::Entry g_entityKeyEntry{ui::null};
720 ui::Entry g_entityValueEntry{ui::null};
722 ui::ListStore g_entlist_store{ui::null};
723 ui::ListStore g_entprops_store{ui::null};
724 const EntityClass* g_current_flags = 0;
725 const EntityClass* g_current_comment = 0;
726 const EntityClass* g_current_attributes = 0;
728 // the number of active spawnflags
729 int g_spawnflag_count;
730 // table: index, match spawnflag item to the spawnflag index (i.e. which bit)
731 int spawn_table[MAX_FLAGS];
732 // we change the layout depending on how many spawn flags we need to display
733 // the table is a 4x4 in which we need to put the comment box g_entityClassComment and the spawn flags..
734 GtkTable* g_spawnflagsTable;
736 ui::VBox g_attributeBox{ui::null};
737 typedef std::vector<EntityAttribute*> EntityAttributes;
738 EntityAttributes g_entityAttributes;
741 void GlobalEntityAttributes_clear(){
742 for ( EntityAttributes::iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
746 g_entityAttributes.clear();
749 class GetKeyValueVisitor : public Entity::Visitor
751 KeyValues& m_keyvalues;
753 GetKeyValueVisitor( KeyValues& keyvalues )
754 : m_keyvalues( keyvalues ){
757 void visit( const char* key, const char* value ){
758 m_keyvalues.insert( KeyValues::value_type( CopiedString( key ), CopiedString( value ) ) );
763 void Entity_GetKeyValues( const Entity& entity, KeyValues& keyvalues, KeyValues& defaultValues ){
764 GetKeyValueVisitor visitor( keyvalues );
766 entity.forEachKeyValue( visitor );
768 const EntityClassAttributes& attributes = entity.getEntityClass().m_attributes;
770 for ( EntityClassAttributes::const_iterator i = attributes.begin(); i != attributes.end(); ++i )
772 defaultValues.insert( KeyValues::value_type( ( *i ).first, ( *i ).second.m_value ) );
776 void Entity_GetKeyValues_Selected( KeyValues& keyvalues, KeyValues& defaultValues ){
777 class EntityGetKeyValues : public SelectionSystem::Visitor
779 KeyValues& m_keyvalues;
780 KeyValues& m_defaultValues;
781 mutable std::set<Entity*> m_visited;
783 EntityGetKeyValues( KeyValues& keyvalues, KeyValues& defaultValues )
784 : m_keyvalues( keyvalues ), m_defaultValues( defaultValues ){
786 void visit( scene::Instance& instance ) const {
787 Entity* entity = Node_getEntity( instance.path().top() );
788 if ( entity == 0 && instance.path().size() != 1 ) {
789 entity = Node_getEntity( instance.path().parent() );
791 if ( entity != 0 && m_visited.insert( entity ).second ) {
792 Entity_GetKeyValues( *entity, m_keyvalues, m_defaultValues );
795 } visitor( keyvalues, defaultValues );
796 GlobalSelectionSystem().foreachSelected( visitor );
799 const char* keyvalues_valueforkey( KeyValues& keyvalues, const char* key ){
800 KeyValues::iterator i = keyvalues.find( CopiedString( key ) );
801 if ( i != keyvalues.end() ) {
802 return ( *i ).second.c_str();
807 class EntityClassListStoreAppend : public EntityClassVisitor
811 EntityClassListStoreAppend( ui::ListStore store_ ) : store( store_ ){
813 void visit( EntityClass* e ){
815 gtk_list_store_append( store, &iter );
816 gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
820 void EntityClassList_fill(){
821 EntityClassListStoreAppend append( g_entlist_store );
822 GlobalEntityClassManager().forEach( append );
825 void EntityClassList_clear(){
826 gtk_list_store_clear( g_entlist_store );
829 void SetComment( EntityClass* eclass ){
830 if ( eclass == g_current_comment ) {
834 g_current_comment = eclass;
836 g_entityClassComment.text(eclass->comments());
839 void SurfaceFlags_setEntityClass( EntityClass* eclass ){
840 if ( eclass == g_current_flags ) {
844 g_current_flags = eclass;
846 int spawnflag_count = 0;
849 // do a first pass to count the spawn flags, don't touch the widgets, we don't know in what state they are
850 for ( int i = 0 ; i < MAX_FLAGS ; i++ )
852 if ( eclass->flagnames[i] && eclass->flagnames[i][0] != 0 && strcmp( eclass->flagnames[i],"-" ) ) {
853 spawn_table[spawnflag_count] = i;
859 // disable all remaining boxes
860 // NOTE: these boxes might not even be on display
862 for ( int i = 0; i < g_spawnflag_count; ++i )
864 auto widget = ui::Widget(GTK_WIDGET(g_entitySpawnflagsCheck[i]));
865 auto label = ui::Label(GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget))));
867 gtk_widget_hide( widget );
868 g_object_ref( widget );
869 gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget );
873 g_spawnflag_count = spawnflag_count;
876 for ( int i = 0; i < g_spawnflag_count; ++i )
878 ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] ));
881 StringOutputStream str( 16 );
882 str << LowerCase( eclass->flagnames[spawn_table[i]] );
884 gtk_table_attach( g_spawnflagsTable, widget, i % 4, i % 4 + 1, i / 4, i / 4 + 1,
885 (GtkAttachOptions)( GTK_FILL ),
886 (GtkAttachOptions)( GTK_FILL ), 0, 0 );
889 auto label = ui::Label(GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget)) ));
890 label.text(str.c_str());
895 void EntityClassList_selectEntityClass( EntityClass* eclass ){
896 GtkTreeModel* model = GTK_TREE_MODEL( g_entlist_store );
898 for ( gboolean good = gtk_tree_model_get_iter_first( model, &iter ); good != FALSE; good = gtk_tree_model_iter_next( model, &iter ) )
901 gtk_tree_model_get( model, &iter, 0, &text, -1 );
902 if ( strcmp( text, eclass->name() ) == 0 ) {
903 GtkTreeView* view = g_entityClassList;
904 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
905 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
906 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
907 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
909 gtk_tree_path_free( path );
916 void EntityInspector_appendAttribute( const char* name, EntityAttribute& attribute ){
917 auto row = DialogRow_new( name, attribute.getWidget() );
918 DialogVBox_packRow( ui::VBox(g_attributeBox), row );
922 template<typename Attribute>
923 class StatelessAttributeCreator
926 static EntityAttribute* create( const char* name ){
927 return new Attribute( name );
931 class EntityAttributeFactory
933 typedef EntityAttribute* ( *CreateFunc )( const char* name );
934 typedef std::map<const char*, CreateFunc, RawStringLess> Creators;
937 EntityAttributeFactory(){
938 m_creators.insert( Creators::value_type( "string", &StatelessAttributeCreator<StringAttribute>::create ) );
939 m_creators.insert( Creators::value_type( "color", &StatelessAttributeCreator<StringAttribute>::create ) );
940 m_creators.insert( Creators::value_type( "integer", &StatelessAttributeCreator<StringAttribute>::create ) );
941 m_creators.insert( Creators::value_type( "real", &StatelessAttributeCreator<StringAttribute>::create ) );
942 m_creators.insert( Creators::value_type( "shader", &StatelessAttributeCreator<ShaderAttribute>::create ) );
943 m_creators.insert( Creators::value_type( "boolean", &StatelessAttributeCreator<BooleanAttribute>::create ) );
944 m_creators.insert( Creators::value_type( "angle", &StatelessAttributeCreator<AngleAttribute>::create ) );
945 m_creators.insert( Creators::value_type( "direction", &StatelessAttributeCreator<DirectionAttribute>::create ) );
946 m_creators.insert( Creators::value_type( "angles", &StatelessAttributeCreator<AnglesAttribute>::create ) );
947 m_creators.insert( Creators::value_type( "model", &StatelessAttributeCreator<ModelAttribute>::create ) );
948 m_creators.insert( Creators::value_type( "sound", &StatelessAttributeCreator<SoundAttribute>::create ) );
949 m_creators.insert( Creators::value_type( "vector3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
950 m_creators.insert( Creators::value_type( "real3", &StatelessAttributeCreator<Vector3Attribute>::create ) );
952 EntityAttribute* create( const char* type, const char* name ){
953 Creators::iterator i = m_creators.find( type );
954 if ( i != m_creators.end() ) {
955 return ( *i ).second( name );
957 const ListAttributeType* listType = GlobalEntityClassManager().findListType( type );
958 if ( listType != 0 ) {
959 return new ListAttribute( name, *listType );
965 typedef Static<EntityAttributeFactory> GlobalEntityAttributeFactory;
967 void EntityInspector_setEntityClass( EntityClass *eclass ){
968 EntityClassList_selectEntityClass( eclass );
969 SurfaceFlags_setEntityClass( eclass );
971 if ( eclass != g_current_attributes ) {
972 g_current_attributes = eclass;
974 container_remove_all( g_attributeBox );
975 GlobalEntityAttributes_clear();
977 for ( EntityClassAttributes::const_iterator i = eclass->m_attributes.begin(); i != eclass->m_attributes.end(); ++i )
979 EntityAttribute* attribute = GlobalEntityAttributeFactory::instance().create( ( *i ).second.m_type.c_str(), ( *i ).first.c_str() );
980 if ( attribute != 0 ) {
981 g_entityAttributes.push_back( attribute );
982 EntityInspector_appendAttribute( EntityClassAttributePair_getName( *i ), *g_entityAttributes.back() );
988 void EntityInspector_updateSpawnflags(){
990 int f = atoi( SelectedEntity_getValueForKey( "spawnflags" ) );
991 for ( int i = 0; i < g_spawnflag_count; ++i )
993 int v = !!( f & ( 1 << spawn_table[i] ) );
995 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), v );
999 // take care of the remaining ones
1000 for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
1002 toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), FALSE );
1007 void EntityInspector_applySpawnflags(){
1009 auto sz = u::buffer<32>();
1012 for ( i = 0; i < g_spawnflag_count; ++i )
1014 v = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ) );
1015 f |= v << spawn_table[i];
1018 sprintf( sz, "%i", f );
1019 const char* value = ( f == 0 ) ? "" : sz;
1022 StringOutputStream command;
1023 command << "entitySetFlags -flags " << f;
1024 UndoableCommand undo( "entitySetSpawnflags" );
1026 Scene_EntitySetKeyValue_Selected( "spawnflags", value );
1031 void EntityInspector_updateKeyValues(){
1032 g_selectedKeyValues.clear();
1033 g_selectedDefaultKeyValues.clear();
1034 Entity_GetKeyValues_Selected( g_selectedKeyValues, g_selectedDefaultKeyValues );
1036 EntityInspector_setEntityClass( GlobalEntityClassManager().findOrInsert( keyvalues_valueforkey( g_selectedKeyValues, "classname" ), false ) );
1038 EntityInspector_updateSpawnflags();
1040 ui::ListStore store = g_entprops_store;
1042 // save current key/val pair around filling epair box
1043 // row_select wipes it and sets to first in list
1044 CopiedString strKey( g_entityKeyEntry.text() );
1045 CopiedString strVal( g_entityValueEntry.text() );
1047 gtk_list_store_clear( store );
1048 // Walk through list and add pairs
1049 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1052 gtk_list_store_append( store, &iter );
1053 StringOutputStream key( 64 );
1054 key << ( *i ).first.c_str();
1055 StringOutputStream value( 64 );
1056 value << ( *i ).second.c_str();
1057 gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
1060 g_entityKeyEntry.text( strKey.c_str() );
1061 g_entityValueEntry.text( strVal.c_str() );
1063 for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i )
1069 class EntityInspectorDraw
1071 IdleDraw m_idleDraw;
1073 EntityInspectorDraw() : m_idleDraw( FreeCaller<EntityInspector_updateKeyValues>( ) ){
1076 m_idleDraw.queueDraw();
1080 EntityInspectorDraw g_EntityInspectorDraw;
1083 void EntityInspector_keyValueChanged(){
1084 g_EntityInspectorDraw.queueDraw();
1086 void EntityInspector_selectionChanged( const Selectable& ){
1087 EntityInspector_keyValueChanged();
1090 // Creates a new entity based on the currently selected brush and entity type.
1092 void EntityClassList_createEntity(){
1093 GtkTreeView* view = g_entityClassList;
1095 // find out what type of entity we are trying to create
1096 GtkTreeModel* model;
1098 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE ) {
1099 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityClassList ) )).alert( "You must have a selected class to create an entity", "info" );
1104 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1107 StringOutputStream command;
1108 command << "entityCreate -class " << text;
1110 UndoableCommand undo( command.c_str() );
1112 Entity_createFromSelection( text, g_vector3_identity );
1117 void EntityInspector_applyKeyValue(){
1118 // Get current selection text
1119 StringOutputStream key( 64 );
1120 key << gtk_entry_get_text( g_entityKeyEntry );
1121 StringOutputStream value( 64 );
1122 value << gtk_entry_get_text( g_entityValueEntry );
1125 // TTimo: if you change the classname to worldspawn you won't merge back in the structural brushes but create a parasite entity
1126 if ( !strcmp( key.c_str(), "classname" ) && !strcmp( value.c_str(), "worldspawn" ) ) {
1127 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "Cannot change \"classname\" key back to worldspawn.", 0, ui::alert_type::OK );
1132 // RR2DO2: we don't want spaces in entity keys
1133 if ( strstr( key.c_str(), " " ) ) {
1134 ui::Widget(gtk_widget_get_toplevel( GTK_WIDGET( g_entityKeyEntry )) ).alert( "No spaces are allowed in entity keys.", 0, ui::alert_type::OK );
1138 if ( strcmp( key.c_str(), "classname" ) == 0 ) {
1139 StringOutputStream command;
1140 command << "entitySetClass -class " << value.c_str();
1141 UndoableCommand undo( command.c_str() );
1142 Scene_EntitySetClassname_Selected( value.c_str() );
1146 Scene_EntitySetKeyValue_Selected_Undoable( key.c_str(), value.c_str() );
1150 void EntityInspector_clearKeyValue(){
1151 // Get current selection text
1152 StringOutputStream key( 64 );
1153 key << gtk_entry_get_text( g_entityKeyEntry );
1155 if ( strcmp( key.c_str(), "classname" ) != 0 ) {
1156 StringOutputStream command;
1157 command << "entityDeleteKey -key " << key.c_str();
1158 UndoableCommand undo( command.c_str() );
1159 Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
1163 void EntityInspector_clearAllKeyValues(){
1164 UndoableCommand undo( "entityClear" );
1166 // remove all keys except classname
1167 for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
1169 if ( strcmp( ( *i ).first.c_str(), "classname" ) != 0 ) {
1170 Scene_EntitySetKeyValue_Selected( ( *i ).first.c_str(), "" );
1175 // =============================================================================
1178 static void EntityClassList_selection_changed( GtkTreeSelection* selection, gpointer data ){
1179 GtkTreeModel* model;
1180 GtkTreeIter selected;
1181 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
1182 EntityClass* eclass;
1183 gtk_tree_model_get( model, &selected, 1, &eclass, -1 );
1184 if ( eclass != 0 ) {
1185 SetComment( eclass );
1190 static gint EntityClassList_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
1191 if ( event->type == GDK_2BUTTON_PRESS ) {
1192 EntityClassList_createEntity();
1198 static gint EntityClassList_keypress( ui::Widget widget, GdkEventKey* event, gpointer data ){
1199 unsigned int code = gdk_keyval_to_upper( event->keyval );
1201 if ( event->keyval == GDK_KEY_Return ) {
1202 EntityClassList_createEntity();
1206 // select the entity that starts with the key pressed
1207 if ( code <= 'Z' && code >= 'A' ) {
1208 GtkTreeView* view = g_entityClassList;
1209 GtkTreeModel* model;
1211 if ( gtk_tree_selection_get_selected( gtk_tree_view_get_selection( view ), &model, &iter ) == FALSE
1212 || gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1213 gtk_tree_model_get_iter_first( model, &iter );
1216 for ( std::size_t count = gtk_tree_model_iter_n_children( model, 0 ); count > 0; --count )
1219 gtk_tree_model_get( model, &iter, 0, &text, -1 );
1221 if ( toupper( text[0] ) == (int)code ) {
1222 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
1223 gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
1224 if ( gtk_widget_get_realized( GTK_WIDGET(view) ) ) {
1225 gtk_tree_view_scroll_to_cell( view, path, 0, FALSE, 0, 0 );
1227 gtk_tree_path_free( path );
1233 if ( gtk_tree_model_iter_next( model, &iter ) == FALSE ) {
1234 gtk_tree_model_get_iter_first( model, &iter );
1243 static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpointer data ){
1244 // find out what type of entity we are trying to create
1245 GtkTreeModel* model;
1247 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) == FALSE ) {
1253 gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 );
1255 g_entityKeyEntry.text( key );
1256 g_entityValueEntry.text( val );
1262 static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){
1263 EntityInspector_applySpawnflags();
1266 static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){
1267 if ( event->keyval == GDK_KEY_Return ) {
1268 if ( widget == g_entityKeyEntry ) {
1269 g_entityValueEntry.text( "" );
1270 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) );
1274 EntityInspector_applyKeyValue();
1278 if ( event->keyval == GDK_KEY_Escape ) {
1279 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), NULL );
1286 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
1287 g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
1288 g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
1290 g_entityInspector_windowConstructed = false;
1291 GlobalEntityAttributes_clear();
1294 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
1295 ui::Widget vbox = ui::VBox( FALSE, 2 );
1297 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
1299 vbox.connect( "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
1302 ui::Widget split1 = ui::VPaned(ui::New);
1303 gtk_box_pack_start( GTK_BOX( vbox ), split1, TRUE, TRUE, 0 );
1306 g_entity_split1 = split1;
1309 ui::Widget split2 = ui::VPaned(ui::New);
1310 gtk_paned_add1( GTK_PANED( split1 ), split2 );
1313 g_entity_split2 = split2;
1317 auto scr = ui::ScrolledWindow(ui::New);
1319 gtk_paned_add1( GTK_PANED( split2 ), scr );
1320 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1321 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1324 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
1326 auto view = ui::TreeView( ui::TreeModel( GTK_TREE_MODEL( store ) ));
1327 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1328 gtk_tree_view_set_headers_visible( view, FALSE );
1329 view.connect( "button_press_event", G_CALLBACK( EntityClassList_button_press ), 0 );
1330 view.connect( "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 );
1333 auto renderer = ui::CellRendererText(ui::New);
1334 GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} );
1335 gtk_tree_view_append_column( view, column );
1339 auto selection = ui::TreeSelection(gtk_tree_view_get_selection( view ));
1340 selection.connect( "changed", G_CALLBACK( EntityClassList_selection_changed ), 0 );
1348 g_entityClassList = view;
1349 g_entlist_store = store;
1354 auto scr = ui::ScrolledWindow(ui::New);
1356 gtk_paned_add2( GTK_PANED( split2 ), scr );
1357 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
1358 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1361 auto text = ui::TextView(ui::New);
1362 gtk_widget_set_size_request( GTK_WIDGET( text ), 0, -1 ); // allow shrinking
1363 gtk_text_view_set_wrap_mode( text, GTK_WRAP_WORD );
1364 gtk_text_view_set_editable( text, FALSE );
1367 g_entityClassComment = text;
1373 ui::Widget split2 = ui::VPaned(ui::New);
1374 gtk_paned_add2( GTK_PANED( split1 ), split2 );
1378 ui::Widget vbox2 = ui::VBox( FALSE, 2 );
1380 gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
1383 // Spawnflags (4 colums wide max, or window gets too wide.)
1384 auto table = ui::Table( 4, 4, FALSE );
1385 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1388 g_spawnflagsTable = table;
1390 for ( int i = 0; i < MAX_FLAGS; i++ )
1392 auto check = ui::CheckButton( "" );
1393 g_object_ref( GTK_WIDGET( check ) );
1394 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( check.connect( "toggled", G_CALLBACK( SpawnflagCheck_toggled ), 0 ) ) );
1395 g_entitySpawnflagsCheck[i] = check;
1401 auto scr = ui::ScrolledWindow(ui::New);
1403 gtk_box_pack_start( GTK_BOX( vbox2 ), scr, TRUE, TRUE, 0 );
1404 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1405 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
1408 ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ));
1410 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
1411 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), FALSE );
1412 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
1415 auto renderer = ui::CellRendererText(ui::New);
1416 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
1417 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1421 auto renderer = ui::CellRendererText(ui::New);
1422 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 1}} );
1423 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
1427 auto selection = ui::TreeSelection(gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ));
1428 selection.connect( "changed", G_CALLBACK( EntityProperties_selection_changed ), 0 );
1437 g_entprops_store = store;
1443 auto table = ui::Table( 2, 2, FALSE );
1445 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), FALSE, TRUE, 0 );
1446 gtk_table_set_row_spacings( table, 3 );
1447 gtk_table_set_col_spacings( table, 5 );
1450 auto entry = ui::Entry(ui::New);
1452 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
1453 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1454 (GtkAttachOptions)( 0 ), 0, 0 );
1455 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1456 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1457 g_entityKeyEntry = entry;
1461 auto entry = ui::Entry(ui::New);
1463 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
1464 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
1465 (GtkAttachOptions)( 0 ), 0, 0 );
1466 gtk_widget_set_events( GTK_WIDGET( entry ), GDK_KEY_PRESS_MASK );
1467 entry.connect( "key_press_event", G_CALLBACK( EntityEntry_keypress ), 0 );
1468 g_entityValueEntry = entry;
1472 auto label = ui::Label( "Value" );
1474 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1475 (GtkAttachOptions)( GTK_FILL ),
1476 (GtkAttachOptions)( 0 ), 0, 0 );
1477 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1481 auto label = ui::Label( "Key" );
1483 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1484 (GtkAttachOptions)( GTK_FILL ),
1485 (GtkAttachOptions)( 0 ), 0, 0 );
1486 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1491 auto hbox = ui::HBox( TRUE, 4 );
1493 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
1496 auto button = ui::Button( "Clear All" );
1498 button.connect( "clicked", G_CALLBACK( EntityInspector_clearAllKeyValues ), 0 );
1499 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1502 auto button = ui::Button( "Delete Key" );
1504 button.connect( "clicked", G_CALLBACK( EntityInspector_clearKeyValue ), 0 );
1505 gtk_box_pack_start( hbox, GTK_WIDGET( button ), TRUE, TRUE, 0 );
1511 auto scr = ui::ScrolledWindow(ui::New);
1513 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
1515 auto viewport = ui::Container(GTK_CONTAINER(gtk_viewport_new( 0, 0 )));
1517 gtk_viewport_set_shadow_type( GTK_VIEWPORT( viewport ), GTK_SHADOW_NONE );
1519 g_attributeBox = ui::VBox( FALSE, 2 );
1520 g_attributeBox.show();
1522 viewport.add(g_attributeBox);
1524 gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
1531 // show the sliders in any case
1532 if ( g_entitysplit2_position > 22 ) {
1533 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
1536 g_entitysplit2_position = 22;
1537 gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
1539 if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
1540 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
1543 gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
1547 g_entityInspector_windowConstructed = true;
1548 EntityClassList_fill();
1550 typedef FreeCaller1<const Selectable&, EntityInspector_selectionChanged> EntityInspectorSelectionChangedCaller;
1551 GlobalSelectionSystem().addSelectionChangeCallback( EntityInspectorSelectionChangedCaller() );
1552 GlobalEntityCreator().setKeyValueChangedFunc( EntityInspector_keyValueChanged );
1555 gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL );
1560 class EntityInspector : public ModuleObserver
1562 std::size_t m_unrealised;
1564 EntityInspector() : m_unrealised( 1 ){
1567 if ( --m_unrealised == 0 ) {
1568 if ( g_entityInspector_windowConstructed ) {
1569 //globalOutputStream() << "Entity Inspector: realise\n";
1570 EntityClassList_fill();
1575 if ( ++m_unrealised == 1 ) {
1576 if ( g_entityInspector_windowConstructed ) {
1577 //globalOutputStream() << "Entity Inspector: unrealise\n";
1578 EntityClassList_clear();
1584 EntityInspector g_EntityInspector;
1586 #include "preferencesystem.h"
1587 #include "stringio.h"
1589 void EntityInspector_construct(){
1590 GlobalEntityClassManager().attach( g_EntityInspector );
1592 GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) );
1593 GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) );
1597 void EntityInspector_destroy(){
1598 GlobalEntityClassManager().detach( g_EntityInspector );
1601 const char *EntityInspector_getCurrentKey(){
1602 if ( !GroupDialog_isShown() ) {
1605 if ( GroupDialog_getPage() != g_page_entity ) {
1608 return gtk_entry_get_text( g_entityKeyEntry );