def on_duplicate_events(self, event): table = self.sound.safegetsoundtable() events = [] for i in range(table.getnumberofsounds()): event, material, sound_id = table.getsoundevent(i) if not event in events: events.append(event) dialog = wx.SingleChoiceDialog(self, "Select an event to copy", "Select event", events) val = dialog.ShowModal() if val == wx.ID_OK: event_name = dialog.GetStringSelection() dialog2 = wx.TextEntryDialog(self, 'Enter new event name', 'Duplicate events', '') dest_event = "" if dialog2.ShowModal() == wx.ID_OK: dest_event = dialog2.GetValue() dialog2.Destroy() if dest_event == "": return num_added = table.duplicatesoundevent(str(event_name), str(dest_event)) if num_added != 0: servers.get_entity_class_server().setentityclassdirty( self.sound, True) self.refresh() dialog.Destroy()
def on_save_button(self, evt): # Send a enter key event to property for update values event = wx.KeyEvent(wx.wxEVT_CHAR) event.m_keyCode = wx.WXK_RETURN self.cmds_pg.GetEventHandler().ProcessEvent(event) # make this object the current nebulagui.nebula_object = self.object # Get redo command self.redo = self.__get_redo_command() # Get undo command self.undo = self.__get_undo_command() # new command servers.get_command_server().newcommand(str(self.redo), str(self.undo)) self.draw_state_commands(self.object) if self.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( self.object, True) elif self.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( self.object, True) if self.object.isa("nscenenode"): self.object.loadresources() self.object.setobjectdirty(True)
def on_import_sound(self, event): lib = servers.get_sound_library() groups = [] for index in range( lib.getnumberofsoundgroups() ): groups.append( lib.getsoundgroupname(index) ) dialog = wx.SingleChoiceDialog( self, "Select a group", "Select sound group", groups ) val = dialog.ShowModal() if val == wx.ID_OK: table = self.sound.safegetsoundtable() groupname = dialog.GetStringSelection() suc = table.importsoundgroup( str(groupname) ) if suc: servers.get_entity_class_server().setentityclassdirty( self.sound, True ) self.refresh() else: cjr.show_error_message( "%s group not found" % groupname ) dialog.Destroy()
def on_add(self, event): event = self.text_event.GetValue() material = self.text_material.GetValue() sound_id = self.list_ids.GetStringSelection() parent = self.GetParent() for index in range( parent.list.GetItemCount() ): if parent.list.GetItem(index, parent.Col_Event).GetText() == event and \ parent.list.GetItem(index, parent.Col_Material).GetText() == material: cjr.show_error_message( "There's already another sound event with the" \ " name '" + event + "' and material '" + material + "'." ) return self.sound.safegetsoundtable().addsoundevent( str(event), str(material), str(sound_id) ) servers.get_entity_class_server().setentityclassdirty( self.sound, True ) index = parent.list.InsertStringItem( 0, event ) parent.list.SetStringItem( index, parent.Col_Material, material ) parent.list.SetStringItem( index, parent.Col_SoundId, sound_id ) self.EndModal(wx.ID_OK)
def set_event_flag(self, index, enabled): if self.entity.isa('nentityclass'): if self.events_set == InEvents: self.entity.setperceivableevent(index, enabled) else: self.entity.setemittedevent(index, enabled) servers.get_entity_class_server().setentityclassdirty( self.entity, True) else: self.entity.seteventflag(index, enabled) servers.get_entity_object_server().setentityobjectdirty( self.entity, True)
def on_delete_sound(self, event): index = self.__get_selected_list_index() if index != -1: event = self.__get_selected_list_item(self.Col_Event) material = self.__get_selected_list_item(self.Col_Material) table = self.sound.safegetsoundtable() table.removesoundevent(str(event), str(material)) servers.get_entity_class_server().setentityclassdirty( self.sound, True) self.list.DeleteItem(index) self.__update_ctrls() self.__update_sound_triggers()
def on_select_fsm(self, event): type = self.__get_selected_list_item( self.ID_AgentType ) if type != "": sm_name = self.choice_fsm.GetStringSelection() if sm_name == "<none>": sm = None else: sm_path = format.append_to_path( fsm.get_fsms_lib(), sm_name ) sm = pynebula.lookup( sm_path ) entity_class = servers.get_entity_class_server().getentityclass( str(type) ) entity_class.setparentfsm( sm ) servers.get_entity_class_server().setentityclassdirty( entity_class, True ) index = self.__get_selected_list_index() self.list.SetStringItem( index, self.ID_FSM, sm_name )
def on_delete_sound(self, event): index = self.__get_selected_list_index() if index != -1: event = self.__get_selected_list_item( self.Col_Event ) material = self.__get_selected_list_item( self.Col_Material ) table = self.sound.safegetsoundtable() table.removesoundevent( str(event), str(material) ) servers.get_entity_class_server().setentityclassdirty( self.sound, True ) self.list.DeleteItem( index ) self.__update_ctrls() self.__update_sound_triggers()
def CreateClass( name, libraryPath, textureName = 'home:export/textures/materials/rauch.dds' ): name = name.capitalize() # valid name for a class entityServer = servers.get_entity_class_server() neBrushClass = entityServer.getentityclass( 'nebrush' ) if not entityServer.checkclassname(name): wx.MessageBox("\"%s\" is invalid name for a class" %(name), "Conjurer", wx.ICON_ERROR) return None if None != entityServer.getentityclass( name ): wx.MessageBox("the class \"%s\" already exists" %(name), "Conjurer", wx.ICON_ERROR) return None particleNode, assetPath = CreateAsset( name , textureName ) if particleNode == None: return None newClass = entityServer.newentityclass( neBrushClass, name ) newClass.setasseteditable(True) newClass.setresourcefile( assetPath ) newClass.setbbox( 0.0, 0.5 , 0.0, 0.500000, 0.5, 0.500000) library = pynebula.lookup( libraryPath ) library.appendstring( name ) # Mark the library as dirty app.get_libraries().setobjectdirty( True ) return particleNode
def on_inspect_class_button(self, event): class_name = str(self.model.get_object_class()) entity_server = servers.get_entity_class_server() class_to_inspect = entity_server.getentityclass(class_name) win = objdlg.create_window(app.get_top_window(), class_to_inspect.getfullname()) win.display()
def CreateClass(name, libraryPath, textureName='home:export/textures/materials/rauch.dds'): name = name.capitalize() # valid name for a class entityServer = servers.get_entity_class_server() neBrushClass = entityServer.getentityclass('nebrush') if not entityServer.checkclassname(name): wx.MessageBox("\"%s\" is invalid name for a class" % (name), "Conjurer", wx.ICON_ERROR) return None if None != entityServer.getentityclass(name): wx.MessageBox("the class \"%s\" already exists" % (name), "Conjurer", wx.ICON_ERROR) return None particleNode, assetPath = CreateAsset(name, textureName) if particleNode == None: return None newClass = entityServer.newentityclass(neBrushClass, name) newClass.setasseteditable(True) newClass.setresourcefile(assetPath) newClass.setbbox(0.0, 0.5, 0.0, 0.500000, 0.5, 0.500000) library = pynebula.lookup(libraryPath) library.appendstring(name) # Mark the library as dirty app.get_libraries().setobjectdirty(True) return particleNode
def set_event_flag(self, index, enabled): if self.entity.isa('nentityclass'): if self.events_set == InEvents: self.entity.setperceivableevent( index, enabled ) else: self.entity.setemittedevent( index, enabled ) servers.get_entity_class_server().setentityclassdirty( self.entity, True ) else: self.entity.seteventflag( index, enabled ) servers.get_entity_object_server().setentityobjectdirty( self.entity, True )
def has_valid_class_name(self): name = self.get_new_class_name() if name == "": return False else: ecs = servers.get_entity_class_server() return ecs.checkclassname(str(name.capitalize()))
def has_valid_parent_class_name(self): parent_class_name = self.get_parent_class_name() if parent_class_name == "": return False else: ecs = servers.get_entity_class_server() return ecs.checkclassname( str( parent_class_name.capitalize() ) )
def on_select_fsm(self, event): type = self.__get_selected_list_item(self.ID_AgentType) if type != "": sm_name = self.choice_fsm.GetStringSelection() if sm_name == "<none>": sm = None else: sm_path = format.append_to_path(fsm.get_fsms_lib(), sm_name) sm = pynebula.lookup(sm_path) entity_class = servers.get_entity_class_server().getentityclass( str(type)) entity_class.setparentfsm(sm) servers.get_entity_class_server().setentityclassdirty( entity_class, True) index = self.__get_selected_list_index() self.list.SetStringItem(index, self.ID_FSM, sm_name)
def init(self, parent, particle_system_name): childdialoggui.InstanceTrackingChildDialogGUI.init( self, "", parent ) ec_server = servers.get_entity_class_server() self.particle_system = ec_server.getentityclass( particle_system_name ) self.list_emitters = wx.ListBox( self, -1, choices=[], style=wx.LB_SORT ) self.button_new = wx.Button(self, -1, "&New") self.button_edit = wx.Button(self, -1, "&Edit") self.button_delete = wx.Button(self, -1, "&Delete") self.button_visibility = wx.Button(self, -1, "Hide") self.button_close = wx.Button(self, wx.ID_CANCEL, "&Close") self.__set_properties() self.__do_layout() self.__bind_events()
def import_materials_to_outdoor(self, outdoor): terrain_class_name = self.get_selected_terrain_class_as_string() ec_server = servers.get_entity_class_server() source_outdoor = ec_server.getentityclass( terrain_class_name ) number_of_materials = source_outdoor.getnumberofgrowthmaterials() material_list = [] for each_index in range(number_of_materials): material = source_outdoor.getgrowthmaterialbyid(each_index) # do NOT add the default grass material since it cannot be imported if material.getname() != "Default": material_list.append(material) if len(material_list) == 0: cjr.show_error_message( "'%s' outdoor has no grass materials suitable for import." % terrain_class_name ) result = False else: dlg = MaterialsForImportSelectionDialog( self, outdoor, material_list ) result = ( dlg.ShowModal() == wx.ID_OK ) dlg.Destroy() return result
def get_selected_class(self): """ Return the actual class, if one is selected. """ if self.has_item_selected(): ec_server = servers.get_entity_class_server() return ec_server.getentityclass(str( self.get_selected_class_name())) else: return None
def __update_button_ok(self): if self.text_name.GetValue() == "": enable = False else: enable = servers.get_entity_class_server().checkclassname( str(self.text_name.GetValue().capitalize()) ) enable = enable and self.target_library != None self.button_ok.Enable( enable )
def __is_dirty(self, obj): if servers.get_entity_class_server().getentityclassdirty(obj): return True child = obj.gethead() while child is not None: if self.__is_dirty(child): return True child = child.getsucc() return False
def get_selected_class(self): """ Return the actual class, if one is selected. """ if self.has_item_selected(): ec_server = servers.get_entity_class_server() return ec_server.getentityclass( str( self.get_selected_class_name() ) ) else: return None
def on_import_sound(self, event): lib = servers.get_sound_library() groups = [] for index in range(lib.getnumberofsoundgroups()): groups.append(lib.getsoundgroupname(index)) dialog = wx.SingleChoiceDialog(self, "Select a group", "Select sound group", groups) val = dialog.ShowModal() if val == wx.ID_OK: table = self.sound.safegetsoundtable() groupname = dialog.GetStringSelection() suc = table.importsoundgroup(str(groupname)) if suc: servers.get_entity_class_server().setentityclassdirty( self.sound, True) self.refresh() else: cjr.show_error_message("%s group not found" % groupname) dialog.Destroy()
def on_duplicate_events(self, event): table = self.sound.safegetsoundtable() events = [] for i in range( table.getnumberofsounds() ): event, material, sound_id = table.getsoundevent(i) if not event in events: events.append( event ) dialog = wx.SingleChoiceDialog( self, "Select an event to copy", "Select event", events ) val = dialog.ShowModal() if val == wx.ID_OK: event_name = dialog.GetStringSelection() dialog2 = wx.TextEntryDialog( self, 'Enter new event name', 'Duplicate events', '' ) dest_event = "" if dialog2.ShowModal() == wx.ID_OK: dest_event = dialog2.GetValue() dialog2.Destroy() if dest_event == "": return num_added = table.duplicatesoundevent( str(event_name), str(dest_event) ) if num_added != 0: servers.get_entity_class_server().setentityclassdirty( self.sound, True ) self.refresh() dialog.Destroy()
def on_add(self, event): event = self.text_event.GetValue() material = self.text_material.GetValue() sound_id = self.list_ids.GetStringSelection() parent = self.GetParent() for index in range(parent.list.GetItemCount()): if parent.list.GetItem(index, parent.Col_Event).GetText() == event and \ parent.list.GetItem(index, parent.Col_Material).GetText() == material: cjr.show_error_message( "There's already another sound event with the" \ " name '" + event + "' and material '" + material + "'." ) return self.sound.safegetsoundtable().addsoundevent(str(event), str(material), str(sound_id)) servers.get_entity_class_server().setentityclassdirty(self.sound, True) index = parent.list.InsertStringItem(0, event) parent.list.SetStringItem(index, parent.Col_Material, material) parent.list.SetStringItem(index, parent.Col_SoundId, sound_id) self.EndModal(wx.ID_OK)
def on_inspect_class_button(self, event): class_name = str( self.model.get_object_class() ) entity_server = servers.get_entity_class_server() class_to_inspect = entity_server.getentityclass( class_name ) win = objdlg.create_window( app.get_top_window(), class_to_inspect.getfullname() ) win.display()
def create_class(name, parent_name, library_path): name = name.capitalize() # valid name for a class entity_server = servers.get_entity_class_server() if not entity_server.checkclassname(name): cjr.show_error_message("'%s' is not a valid name for a class" % (name)) return False if entity_server.getentityclass(name) is not None: cjr.show_error_message("A class called '%s' already exists" % (name)) return False #Get the class for the given parent class name, checking that it is valid parent_class = entity_server.getentityclass(parent_name) if parent_class is None: cjr.show_error_message( "The new class cannot derive from '%s' "\ "because it does not exist" % (parent_name) ) return False new_class = entity_server.newentityclass(parent_class, name) new_class.setclasskeyint("ParticleSystem", 1) new_class.setasseteditable(True) new_class.setbbox(0.0, 0.5, 0.0, 0.5, 0.5, 0.5) asset_path = 'wc:export/assets/%s' % name file_server = servers.get_file_server() if (not file_server.makepath(asset_path)): return False new_class.setresourcefile(asset_path) scene_path = asset_path + '/scene' if (not file_server.makepath(scene_path)): return False materials_path = asset_path + '/materials' if (not file_server.makepath(materials_path)): return False # create the root node root_node_path = scene_path + '/' + name root_node = pynebula.new('ntransformnode', root_node_path) result = root_node.saveas(root_node_path + '.n2') if not result: return False library = pynebula.lookup(library_path) library.appendstring(name) # Mark the library as dirty app.get_libraries().setobjectdirty(True) return True
def prelevel_process(is_new_level): # Forbid any level operation while in game mode if app.is_in_gameplay_mode(): cjr.show_error_message( "Operation not allowed while in game mode" ) return False # Exit from any test mode app.get_ai_tester().disablegameplayupdating() app.get_ai_tester().disablesoundsources() # Clear undo buffer servers.get_command_server().clean() if not is_new_level: return True # Discard deleted entities servers.get_entity_object_server().discarddeletedobjects() servers.get_entity_class_server().discarddeletedclasses() # What follows should be done only for new and open level commands # Clear selection app.get_object_state().resetselection() # Make terrain state release some buffers if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor(None) # Begin a persist-restore process to close those invalid windows for # the new level and refresh the valid ones (continue in postlevel_process) # Persist guiDialog windows frame = app.get_top_window() prelevel_process.child_data = [] for child in frame.get_child_dialogs(): data = persist_window(child) if data is not None: prelevel_process.child_data.insert(0, data) return True
def on_change_sound_id(self, event): index = self.__get_selected_list_index() if index != -1: sound_ids = [] lib = servers.get_sound_library() for i in range(lib.getnumberofsounds()): if not lib.getsoundid(i) in sound_ids: sound_ids.append(lib.getsoundid(i)) dlg = wx.SingleChoiceDialog(None, "Sound IDs", "Choose a Sound ID", sound_ids) if dlg.ShowModal() == wx.ID_OK and dlg.GetStringSelection() != "": sound_id = dlg.GetStringSelection() event = self.__get_selected_list_item(self.Col_Event) material = self.__get_selected_list_item(self.Col_Material) table = self.__get_sound_table() table.setsoundid(str(event), str(material), str(sound_id)) servers.get_entity_class_server().setentityclassdirty( self.sound, True) self.list.SetStringItem(index, self.Col_SoundId, sound_id) self.button_id.SetLabel(sound_id) self.__update_sound_triggers() dlg.Destroy()
def __set_properties(self): # Sound source class list ec_server = servers.get_entity_class_server() sound_source = ec_server.getentityclass("nesoundsource") #we need to make sure all subclasses are loaded ec_server.loadentitysubclasses(sound_source) next_sound_source = sound_source.gethead() while next_sound_source is not None: self.list.Append( next_sound_source.getname() ) next_sound_source = next_sound_source.getsucc() self.__update_ok_button() # Default button for return key press self.button_ok.SetDefault()
def __set_properties(self): # Terrain classes list ec_server = servers.get_entity_class_server() outdoors = ec_server.getentityclass("neoutdoor") # make sure all subclasses are loaded ec_server.loadentitysubclasses(outdoors) outdoor = outdoors.gethead() while outdoor is not None: self.list.Append( outdoor.getname() ) outdoor = outdoor.getsucc() # Default button for return key press self.button_ok.SetDefault()
def __set_properties(self): # Sound source class list ec_server = servers.get_entity_class_server() sound_source = ec_server.getentityclass("nesoundsource") #we need to make sure all subclasses are loaded ec_server.loadentitysubclasses(sound_source) next_sound_source = sound_source.gethead() while next_sound_source is not None: self.list.Append(next_sound_source.getname()) next_sound_source = next_sound_source.getsucc() self.__update_ok_button() # Default button for return key press self.button_ok.SetDefault()
def __set_properties(self): # Terrain classes list ec_server = servers.get_entity_class_server() outdoors = ec_server.getentityclass("neoutdoor") # make sure all subclasses are loaded ec_server.loadentitysubclasses(outdoors) outdoor = outdoors.gethead() while outdoor is not None: self.list.Append(outdoor.getname()) outdoor = outdoor.getsucc() # Default button for return key press self.button_ok.SetDefault()
def on_new_class(self, event): # Ask for a class name dlg = wx.TextEntryDialog( None, "Enter the class name", "New class" ) result_ok = dlg.ShowModal() == wx.ID_OK if result_ok: class_name = dlg.GetValue().capitalize() dlg.Destroy() # Create the new class if result_ok: # Do some name validations ec_server = servers.get_entity_class_server() if not ec_server.checkclassname( str(class_name) ): cjr.show_error_message( "Invalid class name" ) return k_server = servers.get_kernel_server() if k_server.findclass( str(class_name) ) != "": cjr.show_error_message( "There is already another class called '%s'" % class_name ) return # Finally create the class parent_name = self.tree_classes.get_selected_class_name() if not ec_server.newclass( str(parent_name), str(class_name) ): msg = "Unknown error.\n\n" \ "Unable to create the class '%s'." % class_name cjr.show_error_message(msg) return set_nclass_dirty_flag(True) servers.get_script_server().addclass( str(class_name) ) # For some classes, add commands and implementation by default class_group = self.tree_classes.get_current_class_group() if class_group is not None: add_cmds_func_name = '_CommandManagerDialog__add_commands_of_' + class_group if CommandManagerDialog.__dict__.has_key( add_cmds_func_name ): CommandManagerDialog.__dict__[add_cmds_func_name]( self, class_name ) servers.get_script_server().refreshclass( str(class_name) ) # Refresh the branch of the currently selected class self.tree_classes.on_new_class( class_name )
def prelevel_process(is_new_level): # Forbid any level operation while in game mode if app.is_in_gameplay_mode(): cjr.show_error_message("Operation not allowed while in game mode") return False # Exit from any test mode app.get_ai_tester().disablegameplayupdating() app.get_ai_tester().disablesoundsources() # Clear undo buffer servers.get_command_server().clean() if not is_new_level: return True # Discard deleted entities servers.get_entity_object_server().discarddeletedobjects() servers.get_entity_class_server().discarddeletedclasses() # What follows should be done only for new and open level commands # Clear selection app.get_object_state().resetselection() # Make terrain state release some buffers if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor(None) # Begin a persist-restore process to close those invalid windows for # the new level and refresh the valid ones (continue in postlevel_process) # Persist guiDialog windows frame = app.get_top_window() prelevel_process.child_data = [] for child in frame.get_child_dialogs(): data = persist_window(child) if data is not None: prelevel_process.child_data.insert(0, data) return True
def on_ok(self, event): # Verify that has been given a valid class name name = str(self.text_classname.GetValue().capitalize()) if not servers.get_entity_class_server().checkclassname(name): cjr.show_error_message("Invalid class name.") return # get lightmap size lightmap_size = self.get_lightmap_resolution() # get lightmap size shadowmap_size = self.get_shadowmap_resolution() # get the global lightmap size global_lightmap_size = self.get_global_lightmap_resolution() # get light id lightid = app.get_level().findentity("terrain_lightmap_light") distance = self.text_ctrl_distance.get_value() offset_u = self.text_ctrl_offset_u.get_value() offset_v = self.text_ctrl_offset_v.get_value() aaliasing = self.text_ctrl_aaliasing.get_value() overwrite = self.checkbox_overwrite.IsChecked() # if light not found if lightid == 0: cjr.show_information_message("Please use the 'Select lightmap light' " "option to select the light") return # Create the terrain class dlg = waitdlg.WaitDialog(self.GetParent(), "Creating terrain lightmap...") terrain = trn.get_terrain_module() terrain.createterrainlightmaps( name, lightmap_size, shadowmap_size, global_lightmap_size, lightid, overwrite, distance, offset_u, offset_v, aaliasing, ) # Closes dialog reporting OK dlg.Destroy() self.EndModal(wx.ID_OK)
def init(self, parent, particle_system_name): childdialoggui.InstanceTrackingChildDialogGUI.init(self, "", parent) ec_server = servers.get_entity_class_server() self.particle_system = ec_server.getentityclass(particle_system_name) self.list_emitters = wx.ListBox(self, -1, choices=[], style=wx.LB_SORT) self.button_new = wx.Button(self, -1, "&New") self.button_edit = wx.Button(self, -1, "&Edit") self.button_delete = wx.Button(self, -1, "&Delete") self.button_visibility = wx.Button(self, -1, "Hide") self.button_close = wx.Button(self, wx.ID_CANCEL, "&Close") self.__set_properties() self.__do_layout() self.__bind_events()
def on_save_button (self, evt): # Send a enter key event to property for update values event = wx.KeyEvent(wx.wxEVT_CHAR) event.m_keyCode = wx.WXK_RETURN self.cmds_pg.GetEventHandler().ProcessEvent(event) # make this object the current nebulagui.nebula_object = self.object # Get redo command self.redo = self.__get_redo_command() # Get undo command self.undo = self.__get_undo_command() # new command servers.get_command_server().newcommand(str(self.redo), str(self.undo)) self.draw_state_commands(self.object) if self.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( self.object, True ) elif self.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( self.object, True ) if self.object.isa("nscenenode"): self.object.loadresources() self.object.setobjectdirty(True)
def on_change_sound_id(self, event): index = self.__get_selected_list_index() if index != -1: sound_ids = [] lib = servers.get_sound_library() for i in range( lib.getnumberofsounds() ): if not lib.getsoundid(i) in sound_ids: sound_ids.append( lib.getsoundid(i) ) dlg = wx.SingleChoiceDialog( None, "Sound IDs", "Choose a Sound ID", sound_ids ) if dlg.ShowModal() == wx.ID_OK and dlg.GetStringSelection() != "": sound_id = dlg.GetStringSelection() event = self.__get_selected_list_item( self.Col_Event ) material = self.__get_selected_list_item( self.Col_Material ) table = self.__get_sound_table() table.setsoundid( str(event), str(material), str(sound_id) ) servers.get_entity_class_server().setentityclassdirty( self.sound, True ) self.list.SetStringItem( index, self.Col_SoundId, sound_id ) self.button_id.SetLabel( sound_id ) self.__update_sound_triggers() dlg.Destroy()
def on_ok(self, event): # Verify that has been given a valid class name name = str(self.text_classname.GetValue().capitalize()) if not servers.get_entity_class_server().checkclassname(name): cjr.show_error_message("Invalid class name.") return # get lightmap size lightmap_size = self.get_lightmap_resolution() # get lightmap size shadowmap_size = self.get_shadowmap_resolution() # get the global lightmap size global_lightmap_size = self.get_global_lightmap_resolution() # get light id lightid = app.get_level().findentity("terrain_lightmap_light") distance = self.text_ctrl_distance.get_value() offset_u = self.text_ctrl_offset_u.get_value() offset_v = self.text_ctrl_offset_v.get_value() aaliasing = self.text_ctrl_aaliasing.get_value() overwrite = self.checkbox_overwrite.IsChecked() # if light not found if lightid == 0: cjr.show_information_message( "Please use the 'Select lightmap light' " \ "option to select the light" ) return # Create the terrain class dlg = waitdlg.WaitDialog(self.GetParent(), "Creating terrain lightmap...") terrain = trn.get_terrain_module() terrain.createterrainlightmaps(name, lightmap_size, shadowmap_size, global_lightmap_size, lightid, overwrite, distance, offset_u, offset_v, aaliasing) # Closes dialog reporting OK dlg.Destroy() self.EndModal(wx.ID_OK)
def __build_particle_list(self): self.list_particles.Clear() ec_server = servers.get_entity_class_server() particle_list = [] try: wx.BeginBusyCursor() for each in particle2dlg.valid_parent_class_names(): parent_class = ec_server.getentityclass(each) ec_server.loadentitysubclasses(parent_class) next_class = parent_class.gethead() while next_class is not None: if next_class.getclasskeyint("ParticleSystem"): particle_list.append(next_class) next_class = next_class.getsucc() for each_item in particle_list: self.list_particles.Append( each_item.getname() ) finally: wx.EndBusyCursor()
def __build_particle_list(self): self.list_particles.Clear() ec_server = servers.get_entity_class_server() particle_list = [] try: wx.BeginBusyCursor() for each in particle2dlg.valid_parent_class_names(): parent_class = ec_server.getentityclass(each) ec_server.loadentitysubclasses(parent_class) next_class = parent_class.gethead() while next_class is not None: if next_class.getclasskeyint("ParticleSystem"): particle_list.append(next_class) next_class = next_class.getsucc() for each_item in particle_list: self.list_particles.Append(each_item.getname()) finally: wx.EndBusyCursor()
def __set_properties(self): # List columns self.list.InsertColumn(self.ID_AgentType, "Agent type") self.list.InsertColumn(self.ID_FSM, "Finite state machine") # Fill list self.list.DeleteAllItems() types = self.__get_agent_types() for type in types: entity_class = servers.get_entity_class_server().getentityclass( str(type) ) sm = entity_class.getparentfsm() if sm == None: sm = "<none>" else: sm = sm.getname() self.list.Append( [type, sm] ) # Update controls that depends on selected agent type self.__update_attach_ctrls()
def __update_attach_ctrls(self): # Update FSM choicer type = self.__get_selected_list_item( self.ID_AgentType ) self.choice_fsm.Enable( type != "" ) if type != "": # Fill choice with all available FSMs self.choice_fsm.Clear() self.choice_fsm.Append("<none>") fsm_paths = fsm.get_fsms() for fsm_path in fsm_paths: fsm_name = format.get_name( fsm_path ) self.choice_fsm.Append( fsm_name ) # Select current FSM entity_class = servers.get_entity_class_server().getentityclass( str(type) ) current_fsm = entity_class.getparentfsm() if current_fsm == None: self.choice_fsm.SetStringSelection("<none>") else: self.choice_fsm.SetStringSelection( current_fsm.getname() )
def on_new_class(self, event): # Ask for a class name dlg = wx.TextEntryDialog(None, "Enter the class name", "New class") result_ok = dlg.ShowModal() == wx.ID_OK if result_ok: class_name = dlg.GetValue().capitalize() dlg.Destroy() # Create the new class if result_ok: # Do some name validations ec_server = servers.get_entity_class_server() if not ec_server.checkclassname(str(class_name)): cjr.show_error_message("Invalid class name") return k_server = servers.get_kernel_server() if k_server.findclass(str(class_name)) != "": cjr.show_error_message( "There is already another class called '%s'" % class_name) return # Finally create the class parent_name = self.tree_classes.get_selected_class_name() if not ec_server.newclass(str(parent_name), str(class_name)): msg = "Unknown error.\n\n" \ "Unable to create the class '%s'." % class_name cjr.show_error_message(msg) return set_nclass_dirty_flag(True) servers.get_script_server().addclass(str(class_name)) # For some classes, add commands and implementation by default class_group = self.tree_classes.get_current_class_group() if class_group is not None: add_cmds_func_name = '_CommandManagerDialog__add_commands_of_' + class_group if CommandManagerDialog.__dict__.has_key(add_cmds_func_name): CommandManagerDialog.__dict__[add_cmds_func_name]( self, class_name) servers.get_script_server().refreshclass(str(class_name)) # Refresh the branch of the currently selected class self.tree_classes.on_new_class(class_name)
def __update_attach_ctrls(self): # Update FSM choicer type = self.__get_selected_list_item(self.ID_AgentType) self.choice_fsm.Enable(type != "") if type != "": # Fill choice with all available FSMs self.choice_fsm.Clear() self.choice_fsm.Append("<none>") fsm_paths = fsm.get_fsms() for fsm_path in fsm_paths: fsm_name = format.get_name(fsm_path) self.choice_fsm.Append(fsm_name) # Select current FSM entity_class = servers.get_entity_class_server().getentityclass( str(type)) current_fsm = entity_class.getparentfsm() if current_fsm == None: self.choice_fsm.SetStringSelection("<none>") else: self.choice_fsm.SetStringSelection(current_fsm.getname())
def __set_properties(self): # List columns self.list.InsertColumn(self.ID_AgentType, "Agent type") self.list.InsertColumn(self.ID_FSM, "Finite state machine") # Fill list self.list.DeleteAllItems() types = self.__get_agent_types() for type in types: entity_class = servers.get_entity_class_server().getentityclass( str(type)) sm = entity_class.getparentfsm() if sm == None: sm = "<none>" else: sm = sm.getname() self.list.Append([type, sm]) # Update controls that depends on selected agent type self.__update_attach_ctrls()
def import_materials_to_outdoor(self, outdoor): terrain_class_name = self.get_selected_terrain_class_as_string() ec_server = servers.get_entity_class_server() source_outdoor = ec_server.getentityclass(terrain_class_name) number_of_materials = source_outdoor.getnumberofgrowthmaterials() material_list = [] for each_index in range(number_of_materials): material = source_outdoor.getgrowthmaterialbyid(each_index) # do NOT add the default grass material since it cannot be imported if material.getname() != "Default": material_list.append(material) if len(material_list) == 0: cjr.show_error_message( "'%s' outdoor has no grass materials suitable for import." % terrain_class_name) result = False else: dlg = MaterialsForImportSelectionDialog(self, outdoor, material_list) result = (dlg.ShowModal() == wx.ID_OK) dlg.Destroy() return result
def on_delete_class(self, event): # Ask for delete confirmation class_name = self.tree_classes.get_selected_class_name() if class_name is None: return msg = "Deleting a class cannot be undone.\n\n" \ "Are you sure that you want to delete " \ "the class '%s'?" % class_name should_delete = cjr.warn_yes_no( self, msg ) # Delete the class if the user has said they want to go ahead if should_delete == wx.ID_YES: class_group = self.tree_classes.get_current_top_class_group() # Forbid deleting some classes in some situations if class_group is not None: can_delete_func_name = '_CommandManagerDialog__can_delete_' + class_group if CommandManagerDialog.__dict__.has_key(can_delete_func_name): if not CommandManagerDialog.__dict__[can_delete_func_name](self, class_name): return # Delete the class servers.get_script_server().deleteclass( str(class_name) ) if not servers.get_entity_class_server().removeclass( str(class_name) ): msg = "Couldn't delete the class '" + class_name + "'.\n" \ "Causes may be an instantiated object of that class, " \ "a class with children or a native class." cjr.show_error_message(msg) return set_nclass_dirty_flag( True ) # Delete the class directory class_path = self.__get_class_path( class_name ) if os.path.exists( class_path ): remove_class_dir( class_path ) # Refresh the class tree (and indirectly the command list) self.tree_classes.on_delete_class()
def on_delete_class(self, event): # Ask for delete confirmation class_name = self.tree_classes.get_selected_class_name() if class_name is None: return msg = "Deleting a class cannot be undone.\n\n" \ "Are you sure that you want to delete " \ "the class '%s'?" % class_name should_delete = cjr.warn_yes_no(self, msg) # Delete the class if the user has said they want to go ahead if should_delete == wx.ID_YES: class_group = self.tree_classes.get_current_top_class_group() # Forbid deleting some classes in some situations if class_group is not None: can_delete_func_name = '_CommandManagerDialog__can_delete_' + class_group if CommandManagerDialog.__dict__.has_key(can_delete_func_name): if not CommandManagerDialog.__dict__[can_delete_func_name]( self, class_name): return # Delete the class servers.get_script_server().deleteclass(str(class_name)) if not servers.get_entity_class_server().removeclass( str(class_name)): msg = "Couldn't delete the class '" + class_name + "'.\n" \ "Causes may be an instantiated object of that class, " \ "a class with children or a native class." cjr.show_error_message(msg) return set_nclass_dirty_flag(True) # Delete the class directory class_path = self.__get_class_path(class_name) if os.path.exists(class_path): remove_class_dir(class_path) # Refresh the class tree (and indirectly the command list) self.tree_classes.on_delete_class()
def create_class( name, parent_name, library_path ): name = name.capitalize() # valid name for a class entity_server = servers.get_entity_class_server() if not entity_server.checkclassname( name ): cjr.show_error_message( "'%s' is not a valid name for a class" % (name) ) return False if entity_server.getentityclass( name ) is not None: cjr.show_error_message( "A class called '%s' already exists" % (name) ) return False #Get the class for the given parent class name, checking that it is valid parent_class = entity_server.getentityclass(parent_name) if parent_class is None: cjr.show_error_message( "The new class cannot derive from '%s' "\ "because it does not exist" % (parent_name) ) return False new_class = entity_server.newentityclass( parent_class, name ) new_class.setclasskeyint( "ParticleSystem", 1 ) new_class.setasseteditable( True ) new_class.setbbox( 0.0, 0.5, 0.0, 0.5, 0.5, 0.5 ) asset_path = 'wc:export/assets/%s' % name file_server = servers.get_file_server() if ( not file_server.makepath( asset_path ) ): return False new_class.setresourcefile( asset_path ) scene_path = asset_path + '/scene' if ( not file_server.makepath( scene_path ) ): return False materials_path = asset_path + '/materials' if ( not file_server.makepath( materials_path ) ): return False # create the root node root_node_path = scene_path + '/' + name root_node = pynebula.new( 'ntransformnode', root_node_path ) result = root_node.saveas( root_node_path + '.n2' ) if not result: return False library = pynebula.lookup( library_path ) library.appendstring( name ) # Mark the library as dirty app.get_libraries().setobjectdirty( True ) return True
def __has_valid_class_name(self): name = self.__get_class_name().capitalize() return (len(name) == 0) or servers.get_entity_class_server().checkclassname(name)
def import_materials_to_outdoor(self, outdoor): ec_server = servers.get_entity_class_server() entity_class = ec_server.getentityclass( self.get_selected_terrain_class_as_string()) return outdoor.importmaterials(entity_class)
def import_materials_to_outdoor(self, outdoor): ec_server = servers.get_entity_class_server() entity_class = ec_server.getentityclass( self.get_selected_terrain_class_as_string() ) return outdoor.importmaterials(entity_class)
def __get_skeleton(self): skeleton = self.character.getentityclass() if self.character.isa('necharacter'): skeleton = servers.get_entity_class_server().getentityclass( skeleton.getskeletonclass()) return skeleton
def execute (inspector): # make this object the current nebulagui.nebula_object = inspector.object # Construct the command string to be called. # A variable will be use for storage the return value/s command = "import nebulagui;" command = command + "result = nebulagui.nebula_object.%s" % inspector.cmds.GetValue()+ "(" i = 0 for param in inspector.in_params: field = inspector.in_elements[i] param_type = inspector.xml.get_param_type(param) if param_type == 's': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "'%s'," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass name and use it as parameter object_id = re.compile("(\w*)\(").search(string) getentity_string = str( object_id.group(1) ) command = command + getentity_string + "," else: command = command + "'%s'," % field.GetValueAsString(0) elif param_type == 'o': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "lookup('%s')," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass id for get the entity object and use it as parameter object_id = re.compile("id=(\d*)").search(string) getentity_string = "servers.get_entity_object_server().getentityobject("+ str(object_id.group(1)) + ")" command = command + getentity_string + "," else: command = command + "lookup('%s')," % field.GetValueAsString(0) else: command = command + "%s," % field.GetValueAsString(0) i = i + 1 if i > 0: command = command[:-1] command = command + ")" # Run the command servers.get_python_server().run(str(command)) # Look for return values. If it have, extract it from the result # and fill the propertygrid fields. if len(inspector.out_params) > 0: if len(inspector.out_params) > 1: for i in xrange(len(inspector.out_params)): servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result[" + str(i) +"]") __draw_return_values( inspector, ret, inspector.out_params[i], inspector.out_elements[i] ) else: servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result") __draw_return_values( inspector, ret, inspector.out_params[0], inspector.out_elements[0] ) # delete temp variable servers.get_python_server().run( str("del result") ) # if is a entity dirt the object. # TODO: Ugly hack! Find a better way to do this if inspector.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( inspector.object, True ) elif inspector.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( inspector.object, True ) # Refresh control inspector.cmds_pg.CollapseAll() inspector.cmds_pg.ExpandAll() inspector.executed = True
def __get_skeleton(self): skeleton = self.character.getentityclass() if self.character.isa('necharacter'): skeleton = servers.get_entity_class_server().getentityclass( skeleton.getskeletonclass() ) return skeleton
def on_save_classes(self, event): """Save the entity classes""" servers.get_entity_class_server().saveentityclasses() cmdmgrdlg.set_nclass_dirty_flag(False)
def execute(inspector): # make this object the current nebulagui.nebula_object = inspector.object # Construct the command string to be called. # A variable will be use for storage the return value/s command = "import nebulagui;" command = command + "result = nebulagui.nebula_object.%s" % inspector.cmds.GetValue( ) + "(" i = 0 for param in inspector.in_params: field = inspector.in_elements[i] param_type = inspector.xml.get_param_type(param) if param_type == 's': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "'%s'," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass name and use it as parameter object_id = re.compile("(\w*)\(").search(string) getentity_string = str(object_id.group(1)) command = command + getentity_string + "," else: command = command + "'%s'," % field.GetValueAsString(0) elif param_type == 'o': if "nroot" == inspector.xml.get_param_subtype(param): command = command + "lookup('%s')," % field.GetValueAsString(0) elif "nobjectclass" == inspector.xml.get_param_subtype(param): string = field.GetValueAsString(0) # get the nobjectclass id for get the entity object and use it as parameter object_id = re.compile("id=(\d*)").search(string) getentity_string = "servers.get_entity_object_server().getentityobject(" + str( object_id.group(1)) + ")" command = command + getentity_string + "," else: command = command + "lookup('%s')," % field.GetValueAsString(0) else: command = command + "%s," % field.GetValueAsString(0) i = i + 1 if i > 0: command = command[:-1] command = command + ")" # Run the command servers.get_python_server().run(str(command)) # Look for return values. If it have, extract it from the result # and fill the propertygrid fields. if len(inspector.out_params) > 0: if len(inspector.out_params) > 1: for i in xrange(len(inspector.out_params)): servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result[" + str(i) +"]") __draw_return_values(inspector, ret, inspector.out_params[i], inspector.out_elements[i]) else: servers.get_python_server().\ run("import xmlinspector;"\ "xmlinspector.ret = "\ "result") __draw_return_values(inspector, ret, inspector.out_params[0], inspector.out_elements[0]) # delete temp variable servers.get_python_server().run(str("del result")) # if is a entity dirt the object. # TODO: Ugly hack! Find a better way to do this if inspector.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( inspector.object, True) elif inspector.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( inspector.object, True) # Refresh control inspector.cmds_pg.CollapseAll() inspector.cmds_pg.ExpandAll() inspector.executed = True