def on_select_lightmap_light(self, event): # get light num_entities = app.get_object_state().getselectioncount() lightid = -1 for i in xrange(num_entities): entity = app.get_object_state().getselectedentity(i) if entity.isa("nelight") : lightid = entity.getid() break # if light not found if lightid == -1 : cjr.show_error_message( "No nelight instance found as lightmap light source" ) return # if found create in the level app.get_level().setentityname( lightid, "terrain_lightmap_light" ) cjr.show_information_message( "Terrain lightmap light selected" )
def on_delete(self, event): """Delete selected entities""" # undo batches before removing them for entity in self.get_selected_entities(): if entity.hascomponent('ncSpatialBatch'): entity.clearsubentities() # delete the selected entities app.get_object_state().delentities()
def deselect_entity_in_summoner (self, idx): """ Deselect entity in summoner """ entity_id = self.__get_entity_id_for_row(idx) entity = self.__get_entity_with_id(entity_id) if self.can_entity_be_selected_in_summoner(entity): app.get_object_state().removeentityfromselection(entity_id) return True else: return False
def __select_rows(self, row_index_list, add_to_selection=False): if not add_to_selection: self.ClearSelection() app.get_object_state().resetselection() for row_index in row_index_list: self.select_entity_in_summoner(row_index) # select manually in the grid too self.SelectRow(row_index, True) self.GetParent().parent.update_toolbar()
def __on_move_mode(self, event): mode = self.choice_move_mode.GetSelection() menu = self.GetParent().get_menubar().get_menu('&View') if mode == 0: id_move = viewcmds.ID_MoveThroughTerrain elif mode == 1: id_move = viewcmds.ID_MoveToTerrain else: id_move = viewcmds.ID_MoveOnTerrain menu.Check( id_move, True ) app.get_object_state().setcanmovethroughterrain( mode )
def on_copy(self, event): """Copy selected entities""" try: # Apply copy on current editor if it implements it... active_editor = self.get_frame().GetActiveChild() if active_editor.handle_copy(): return except: pass # ...otherwise delegate the copy to the object state app.get_object_state().copyentities()
def on_paste(self, event): """Paste entities in clipboard""" try: # Apply paste on current editor if it implements it... active_editor = self.get_frame().GetActiveChild() if active_editor.handle_paste(): return except: pass # ...otherwise delegate the paste to the object state app.get_object_state().pasteentities()
def __on_move_mode(self, event): mode = self.choice_move_mode.GetSelection() menu = self.GetParent().get_menubar().get_menu('&View') if mode == 0: id_move = viewcmds.ID_MoveThroughTerrain elif mode == 1: id_move = viewcmds.ID_MoveToTerrain else: id_move = viewcmds.ID_MoveOnTerrain menu.Check(id_move, True) app.get_object_state().setcanmovethroughterrain(mode)
def on_add_to_area(self, event): """Add selection to loading area""" # select an area and add current selection to it dlg = nodelibdlg.NodeLibDialog(self.get_frame(), nodelibdlg.OPEN, 'area', 'Area', "/usr/areas") if dlg.ShowModal() == wx.ID_OK: # Check that's an existing area if not dlg.node_exists(): msg = "There is no area called '%s'" % dlg.get_guiname() cjr.show_error_message(msg) else: # assign selected entities to the area app.get_object_state().addtoloadarea(str(dlg.get_guiname())) dlg.Destroy()
def on_ok(self, event): distance = self.text_ctrl_distance.get_value() rebuild = self.checkbox_rebuild.IsChecked() testsubentities = self.checkbox_testsubentities.IsChecked() object_state = app.get_object_state() object_state.setbatchrebuildresource(rebuild) object_state.setbatchtestsubentities(testsubentities) object_state.setbatchmindistance(distance) # Create the batch(es) if self.style == SELECTION: object_state.batchentities() elif self.style == TERRAIN: dlg = waitdlg.WaitDialog( self.GetParent(), "Creating batch(es)..." ) object_state.createterrainbatches() dlg.Destroy() # Close dialog reporting OK self.EndModal(wx.ID_OK)
def refresh(self): if self.first_refresh: # Do the binding here because the object state doesn't exist yet # when this menu is created pynebula.pyBindSignal(app.get_object_state(), 'toolselected', self, 'ontoolselectedsignal', 0) self.first_refresh = False
def on_select_entity(self, event): index = self.__get_selected_plug_index() if index != -1: entity_id = self.entity.getpluggedentity(index) if entity_id != 0: state = app.get_object_state() state.addentitytoselection(entity_id)
def on_select_entity(self, event): index = self.__get_selected_attach_index() if index != -1: entity_id = self.character.getattachedentity(index) if entity_id != 0: state = app.get_object_state() state.addentitytoselection(entity_id)
def on_polygon_sound_source_tool(self, evt): """Select the polygonal sound source creation tool If the selected item in the ingui is a polygonal sound source, do NOT prompt the user for a source source class since the tool will be used to edit the selected sound source area.""" class_name = None state = app.get_object_state() num_entities = state.getselectioncount() if num_entities == 1: entity = state.getselectedentity(0) if self.__is_polygonal_sound_source(entity): class_name = entity.getclass() if class_name is None: class_name = self.__prompt_user_for_sound_source_class() if class_name is None: self.__select_null_tool() else: self.Check( ID_PolygonSoundSourceTool, True ) self.__toggle_tool( ID_PolygonSoundSourceTool, True ) self.__set_conjurer_state("object") self.__select_tool_with_parameter( object_tool_ids[ID_PolygonSoundSourceTool], class_name )
def ontoolselectedsignal(self): """Check the menu option and tool button for the new selected tool""" tool_id = app.get_object_state().getselectedtoolindex() for menu_id in object_tool_ids.keys(): if object_tool_ids[menu_id] == tool_id: self.Check(menu_id, True) self.__toggle_tool(menu_id, True)
def on_select_waypoints(self, event): """Set the selection waypoints mode""" enabled = event.Checked() self.Check( ID_SelectWaypoints, enabled ) succeed = app.get_object_state().setselectionmode( 1, False ) if succeed: self.__get_toolbar().select_selection_mode( 1 )
def ontoolselectedsignal(self): """Check the menu option and tool button for the new selected tool""" tool_id = app.get_object_state().getselectedtoolindex() for menu_id in object_tool_ids.keys(): if object_tool_ids[menu_id] == tool_id: self.Check( menu_id, True ) self.__toggle_tool( menu_id, True )
def get_selected_entities(self): state = app.get_object_state() number_of_items = state.getselectioncount() entity_list = [] for index in range(number_of_items): entity_list.append(state.getselectedentity(index)) return entity_list
def on_select_waypoints(self, event): """Set the selection waypoints mode""" enabled = event.Checked() self.Check(ID_SelectWaypoints, enabled) succeed = app.get_object_state().setselectionmode(1, False) if succeed: self.__get_toolbar().select_selection_mode(1)
def __get_selected_waypoints(self): waypoints = [] state = app.get_object_state() for index in range(state.getselectioncount()): entity = state.getselectedentity(index) if entity.hascomponent('ncRnsWaypoint'): waypoints.append(entity) return waypoints
def __get_selected_waypoints(self): waypoints = [] state = app.get_object_state() for index in range( state.getselectioncount() ): entity = state.getselectedentity(index) if entity.hascomponent( 'ncRnsWaypoint' ): waypoints.append( entity ) return waypoints
def get_entities_selected_in_summoner(self): state = app.get_object_state() select_count = state.getselectioncount() entity_list = [] for i in range(select_count): entity = state.getselectedentity(i) entity_list.append(entity) return entity_list
def select_entities_from_summoner (self): """ Select all entities that are selected in Summoner """ num_entities = self.__get_num_entities_selected_in_summoner() entity_id_list = [] for index in xrange(num_entities): entity = app.get_object_state().getselectedentity(index) entity_id_list.append( entity.getid() ) self.grid.select_entities_with_ids(entity_id_list)
def select_entity_in_summoner(self, idx): """ Select entity in Summoner. Return true if selected OK, otherwise false.""" entity_id = self.__get_entity_id_for_row(idx) entity = self.__get_entity_with_id(entity_id) if self.can_entity_be_selected_in_summoner(entity): if app.is_terrain_cell_mode_active(): cjr.show_error_message( "Entity %s cannot be selected in Summoner "\ "when in terrain cell mode." % entity_id ) return False else: app.get_object_state().addentitytoselection(entity_id) return True else: return False
def __del__ (self): """ Unbind used signals """ pynebula.pyUnbindTargetObject( app.get_object_state(), 'singleentityplaced', self.entity_browser ) pynebula.pyUnbindTargetObject( servers.get_command_server(), 'entitymodified', self.entity_browser ) pynebula.pyUnbindTargetObject( app.get_object_state(), 'selectionchanged', self.entity_browser )
def on_select_spawner(self, event): name = self.__get_selected_list_item(self.ID_Spawner) spawner = servers.get_world_interface().getgameentity(str(name)) if spawner is None: cjr.show_error_message("Spawner '" + name + "' not found.") else: state = app.get_object_state() entity_id = spawner.getid() state.addentitytoselection(entity_id)
def onselectionchanged(self): state = app.get_object_state() select_count = state.getselectioncount() entity_list = [] for index in range(select_count): entity = state.getselectedentity(index) entity_list.append(entity) self.entities = entity_list self.show_details()
def get_selected_entities(self): state = app.get_object_state() number_of_items = state.getselectioncount() entity_list = [] for index in range (number_of_items): entity_list.append( state.getselectedentity(index) ) return entity_list
def on_add_to_area(self, event): """Add selection to loading area""" # select an area and add current selection to it dlg = nodelibdlg.NodeLibDialog( self.get_frame(), nodelibdlg.OPEN, 'area', 'Area', "/usr/areas" ) if dlg.ShowModal() == wx.ID_OK: # Check that's an existing area if not dlg.node_exists(): msg = "There is no area called '%s'" % dlg.get_guiname() cjr.show_error_message(msg) else: # assign selected entities to the area app.get_object_state().addtoloadarea( str(dlg.get_guiname()) ) dlg.Destroy()
def on_select_lightmap_light(self, event): # get light num_entities = app.get_object_state().getselectioncount() lightid = -1 for i in xrange(num_entities): entity = app.get_object_state().getselectedentity(i) if entity.isa("nelight"): lightid = entity.getid() break # if light not found if lightid == -1: cjr.show_error_message( "No nelight instance found as lightmap light source") return # if found create in the level app.get_level().setentityname(lightid, "terrain_lightmap_light") cjr.show_information_message("Terrain lightmap light selected")
def __init__(self, parent, modal=False): togwin.ChildToggableDialog.__init__( self, "Entity Browser", parent ) self.entity_browser = EntityBrowser(self, modal) self.__create_toolbar() sizer = wx.BoxSizer(wx.VERTICAL) horizontal_line = wx.StaticLine( self, -1, (-1, -1), (-1, -1), wx.LI_HORIZONTAL ) sizer.Add(horizontal_line, 0, wx.EXPAND) sizer.Add(self.entity_browser, 1, wx.EXPAND|wx.ALL, cfg.BORDER_WIDTH) self.SetSizer(sizer) self.SetSize(wx.Size(430, 510)) # Binding this signals will be warned about object changes pynebula.pyBindSignal( app.get_object_state(), 'singleentityplaced', self.entity_browser, 'refresh', 0 ) pynebula.pyBindSignal( app.get_object_state(), 'entitymodified', self.entity_browser, 'refresh', 0 ) pynebula.pyBindSignal( app.get_object_state(), 'selectionchanged', self.entity_browser, 'selectionchanged', 0 )
def on_select_objects(self, event): """Set the selection objects mode""" enabled = event.Checked() self.Check(ID_SelectObjects, enabled) msg = "Do you want to save subentity changes?" result = cjr.confirm_yes_no(app.get_top_window(), msg) save = (result == wx.ID_YES) succeed = app.get_object_state().setselectionmode(0, save) if succeed: self.__get_toolbar().select_selection_mode(0)
def __on_selection_mode(self, event): mode = self.choice_selection_mode.GetSelection() menu = self.GetParent().get_menubar().get_menu('&View') succeed = False if mode == 0 and app.is_subentity_mode_active(): result = cjr.confirm_yes_no( app.get_top_window(), "Do you want to save subentity changes?") save = (result == wx.ID_YES) succeed = app.get_object_state().setselectionmode(mode, save) else: succeed = app.get_object_state().setselectionmode(mode, False) if succeed: if mode == 0: id_selection = viewcmds.ID_SelectObjects elif mode == 1: id_selection = viewcmds.ID_SelectWaypoints else: id_selection = viewcmds.ID_SelectTerrainCells menu.Check(id_selection, True)
def on_select_spawner(self, event): name = self.__get_selected_list_item( self.ID_Spawner ) spawner = servers.get_world_interface().getgameentity( str(name) ) if spawner is None: cjr.show_error_message( "Spawner '" + name + "' not found." ) else: state = app.get_object_state() entity_id = spawner.getid() state.addentitytoselection( entity_id )
def refresh(self): if self.first_refresh: # Do the binding here because the object state doesn't exist yet # when this menu is created pynebula.pyBindSignal( app.get_object_state(), 'toolselected', self, 'ontoolselectedsignal', 0 ) self.first_refresh = False
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_select_all(self, event): if self.layer_selected is None: cjr.show_error_message("Please select a layer") else: entity_list = self.get_all_non_deleted_entities_for_selected_layer() if entity_list: obj_state = app.get_object_state() for each_entity in entity_list: obj_state.addentitytoselection( each_entity.getid() ) else: cjr.show_error_message( "There are no selectable entities in this layer" )
def __bind_events(self): pynebula.pyBindSignal( app.get_object_state(), 'selectionchanged', self, 'onselectionchanged', 0 ) self.Bind( wx.EVT_BUTTON, self.on_click_close_button, self.button_close )
def on_select_objects(self, event): """Set the selection objects mode""" enabled = event.Checked() self.Check( ID_SelectObjects, enabled ) msg = "Do you want to save subentity changes?" result = cjr.confirm_yes_no( app.get_top_window(), msg ) save = (result == wx.ID_YES) succeed = app.get_object_state().setselectionmode( 0, save ) if succeed: self.__get_toolbar().select_selection_mode( 0 )
def update_selection_exceptions(self): editor_state = app.get_object_state() editor_state.resetselectionexceptions() if self.apply_filter_when_selecting: # if self.natives is none it means that no # natives have been selected for exclusion, # so don't do the next bit if self.natives is not None: for each_native in self.master_native_list: if each_native not in self.natives: editor_state.addselectionexception( each_native )
def __on_selection_mode(self, event): mode = self.choice_selection_mode.GetSelection() menu = self.GetParent().get_menubar().get_menu('&View') succeed = False if mode == 0 and app.is_subentity_mode_active(): result = cjr.confirm_yes_no( app.get_top_window(), "Do you want to save subentity changes?" ) save = (result == wx.ID_YES) succeed = app.get_object_state().setselectionmode( mode, save ) else: succeed = app.get_object_state().setselectionmode( mode, False ) if succeed: if mode == 0: id_selection = viewcmds.ID_SelectObjects elif mode == 1: id_selection = viewcmds.ID_SelectWaypoints else: id_selection = viewcmds.ID_SelectTerrainCells menu.Check( id_selection, True )
def __set_properties(self): self.button_ok.SetDefault() object_state = app.get_object_state() self.checkbox_rebuild.SetValue( object_state.getbatchrebuildresource() ) self.checkbox_testsubentities.SetValue( object_state.getbatchtestsubentities() ) self.text_ctrl_distance.set_value( object_state.getbatchmindistance() )
def on_select_all(self, event): if self.layer_selected is None: cjr.show_error_message("Please select a layer") else: entity_list = self.get_all_non_deleted_entities_for_selected_layer( ) if entity_list: obj_state = app.get_object_state() for each_entity in entity_list: obj_state.addentitytoselection(each_entity.getid()) else: cjr.show_error_message( "There are no selectable entities in this layer")
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_loadselection(self, event): """Load a saved selection of entities """ dlg = wx.FileDialog(self.get_frame(), message="Choose a file", wildcard="Nebula2 file (*.n2)|*.n2", style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() if not app.get_object_state().loadselectionfromfile(str(path)): msg = "Unable to load saved selection from file '%s'" % path cjr.show_error_message(msg) dlg.Destroy()
def on_toggle_play(self, event): # Play/stop all selected entities with the ncSound component state = app.get_object_state() play = self.button_play.GetValue() for i in range(state.getselectioncount()): entity = state.getselectedentity(i) if entity.hascommand('playmaterial'): if play: event = self.__get_selected_list_item(self.Col_Event) material = self.__get_selected_list_item(self.Col_Material) repeat = self.spin_repeat.GetValue() entity.playmaterial(str(event), str(material), repeat) else: entity.stopsound()
def refresh(self): """Update some checkmarks""" self.Check(ID_SnapToGrid, cfg.Repository.getsettingvalue(cfg.ID_Grid)['snap enabled']) self.Check( ID_AngleSnap, cfg.Repository.getsettingvalue(cfg.ID_AngleSnapping)['enabled']) self.Check( ID_SizeSnap, cfg.Repository.getsettingvalue(cfg.ID_SizeSnapping)['enabled']) self.Check(ID_SingleViewport, servers.get_viewport_ui().getsingleviewport()) pynebula.pyBindSignal(app.get_object_state(), 'lockedmodechanged', self, 'on_locked_mode_changed', 0)