def on_new_layer(self, event): if app.get_outdoor() is None: cjr.show_information_message( "You need to create a terrain first" ) return if app.get_outdoor().getlayercount() >= MaxLayers: cjr.show_information_message( "You cannot have more than %s layers" % str(MaxLayers) ) return dlg = trnlayerprefsdlg.NewLayerDialog(self) if dlg.ShowModal() == wx.ID_OK: try: try: wx.BeginBusyCursor() # create new layer layer_id = app.get_outdoor().createlayer() app.get_outdoor().getlayerbyhandle(layer_id).loadresources() # create new layer control self.Freeze() layer_ctrl = self.__add_layer_ctrl(layer_id) dlg.apply_layer_settings(layer_ctrl) self.__refresh_layers() self.Thaw() finally: wx.EndBusyCursor() except: # make sure any errors are not hidden raise 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 on_change_layout(self, event): if set_layout( event.get_selection() ): pass else: cjr.show_information_message( "Sorry, the selected layout isn't supported yet." )
def on_ok(self, event): if not self.__has_valid_class_name(): cjr.show_error_message( "Invalid class name." ) return False new_name = self.__get_class_name().capitalize() global_lightmap_size = self.get_global_lightmap_resolution() dlg = waitdlg.WaitDialog( self.GetParent(), "Creating global terrain lightmap..." ) terrain = trn.get_terrain_module() result = terrain.createterraingloballightmap( new_name, global_lightmap_size ) # Closes dialog reporting OK dlg.Destroy() if result: cjr.show_information_message( "Successfully created global terrain lightmap %s" % new_name ) self.EndModal(wx.ID_OK) else: cjr.show_error_message( "Unable to create the global terrain lightmap" ) self.EndModal(wx.ID_OK)
def __finder(self, obj, pattern, mode): """ Search a pattern in the NOH tree. You can search by object names or object class names. This is a good way for list all objects of a specific class. \param Object where the search begins \param Pattern to find \param Search mode: Object name or class name """ if obj != None: if obj.hascommand("getfullname"): try: while obj != None: if mode == "object": search_string = obj.getname() elif mode == "class": search_string = obj.getclass() else: search_string = obj.getfullname() if re.compile(pattern, re.IGNORECASE).search(search_string): self.find.Append(obj.getfullname()) self.matches = self.matches + 1 self.__finder(obj.gethead(), pattern, self.search_mode) obj = obj.getsucc() except re.error: cjr.show_information_message("Bad expresion, try again")
def __finder(self, obj, pattern, mode): """ Search a pattern in the NOH tree. You can search by object names or object class names. This is a good way for list all objects of a specific class. \param Object where the search begins \param Pattern to find \param Search mode: Object name or class name """ if obj != None: if obj.hascommand("getfullname"): try: while (obj != None): if mode == "object": search_string = obj.getname() elif mode == "class": search_string = obj.getclass() else: search_string = obj.getfullname() if re.compile(pattern, re.IGNORECASE).search(search_string): self.find.Append(obj.getfullname()) self.matches = self.matches + 1 self.__finder(obj.gethead(), pattern, self.search_mode) obj = obj.getsucc() except re.error: cjr.show_information_message("Bad expresion, try again")
def on_run(self, event): # ask for save before run if script has been modified if self.stc.GetModify(): answer = cjr.confirm_yes_no( self, "Save changes to '%s' ?" % self.filename ) if answer == wx.ID_YES: self.save(True) elif answer == wx.ID_CANCEL: return if self.filename == "": cjr.show_information_message( "I'm quite stupid, so please you Supreme Intelligence\n" \ "save the file so I can look at its extension and know\n" \ "which file type this script is." ) if self.filename.endswith('.lua'): servers.get_lua_server().runscript( str( format.mangle_path(self.filename) ) ) elif self.filename.endswith('.py'): servers.get_python_server().runscript( str( format.mangle_path(self.filename) ) )
def rename_entity ( self ): """ Renames the name of an entity """ rows = self.grid.GetSelectedRows() entity_server = servers.get_entity_object_server() for idx in rows: row = self.grid.data[idx] entity_id = row[0] entity = entity_server.getentityobject(entity_id) if not entity.hascomponent("ncGameplay"): cjr.show_information_message( "Only gameplay entities may have a name" ) else: dlg = wx.TextEntryDialog( None, "Enter entity name:", "Rename entity", entity.getname() ) if dlg.ShowModal() == wx.ID_OK: name = dlg.GetValue() entity.setname( str(name) ) entity_server.setentityobjectdirty(entity, True) self.refresh() dlg.Destroy()
def save(self, overwrite=True): """Save the fsm being edited by this dialog""" if not overwrite: cjr.show_information_message( "Saving a FSM with another name isn't allowed.\n" \ "Use the duplicate option in the FSMs library instead." ) return False servers.get_fsm_server().savefsm( self.get_fsm() ) self.get_fsm().setdirty( False ) self.__update_title() return True
def save_current_window_layout(self): # Ask for a name for the layout file dlg = filedlg.FileDialog(self, filedlg.SAVE, 'layout file', 'Save window layout', self.__window_layout_file_location(), self.__window_layout_file_suffixes()) if dlg.ShowModal() == wx.ID_OK: saved_ok = self.save_window_layout_to_file(dlg.get_path()) if saved_ok: #let the user know if the file saved OK msg = "Saved window layout as '%s'." % dlg.get_guiname() cjr.show_information_message(msg) 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 on_find_key(self, evt): # Execute the search user query if evt.KeyCode() == wx.WXK_RETURN: self.find.Clear() word = self.find.GetValue() if word != "": obj = pynebula.sel("/") self.__finder(obj.gethead(), word, self.search_mode) self.matches_text.SetLabel("Matches: %d" % self.matches) self.find.SetValue(word) self.matches = 0 else: cjr.show_information_message("Please enter a search expression.") else: evt.Skip()
def on_toggle_temporary_mode(self, event): """Toggle working in temporary mode""" cjr.show_information_message( "When the 'wc' assign becomes and assign group let\n" \ "carles.ros know it and he will enable this feature." ) return temp_path = guisettings.Repository.getsettingvalue( guisettings.ID_TemporaryWorkingPath) temp_path = servers.get_file_server().manglepath(str(temp_path)) fileserver = servers.get_file_server() if event.IsChecked(): fileserver.setassigngroup2('wc', str(temp_path), str(self.wc_path)) else: fileserver.setassigngroup2('wc', str(self.wc_path), str(self.wc_path))
def on_find_key(self, evt): # Execute the search user query if evt.KeyCode() == wx.WXK_RETURN: self.find.Clear() word = self.find.GetValue() if word != "": obj = pynebula.sel('/') self.__finder(obj.gethead(), word, self.search_mode) self.matches_text.SetLabel("Matches: %d" % self.matches) self.find.SetValue(word) self.matches = 0 else: cjr.show_information_message( "Please enter a search expression.") else: evt.Skip()
def on_end_edit(self, event): new_name = event.GetLabel() if not event.IsEditCancelled(): if re.compile('^[a-zA-Z0-9_\.]+$').match(new_name): obj = self.GetPyData(self.current) obj = pynebula.sel(obj.getfullname()) obj.setname(str(new_name)) old_name = self.GetItemText(event.GetItem()) file_tmp = self.files[old_name] self.files.pop(old_name) self.files[new_name] = file_tmp else: msg = "Bad name for library: \n\n" \ "Only alphanumerics," \ " '.' and '_' can be used" cjr.show_information_message(msg) event.Veto()
def save_current_window_layout(self): # Ask for a name for the layout file dlg = filedlg.FileDialog( self, filedlg.SAVE, 'layout file', 'Save window layout', self.__window_layout_file_location(), self.__window_layout_file_suffixes() ) if dlg.ShowModal() == wx.ID_OK: saved_ok = self.save_window_layout_to_file( dlg.get_path() ) if saved_ok: #let the user know if the file saved OK msg = "Saved window layout as '%s'." % dlg.get_guiname() cjr.show_information_message(msg) dlg.Destroy()
def on_end_edit (self, event): new_name = event.GetLabel() if not event.IsEditCancelled(): if re.compile('^[a-zA-Z0-9_\.]+$').match(new_name): obj = self.GetPyData(self.current) obj = pynebula.sel(obj.getfullname()) obj.setname( str(new_name) ) old_name = self.GetItemText(event.GetItem()) file_tmp = self.files[old_name] self.files.pop(old_name) self.files[new_name] = file_tmp else: msg = "Bad name for library: \n\n" \ "Only alphanumerics," \ " '.' and '_' can be used" cjr.show_information_message(msg) event.Veto()
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 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_new_transition(self, event): """Create a new transition with default values""" # Get the first free condition by default cond_paths = fsmtransitiontype.get_free_event_conditions( self.state_path ) if len(cond_paths) == 0: cond_paths = fsmtransitiontype.get_free_script_conditions( self.state_path ) if len(cond_paths) == 0: cjr.show_information_message( "This state already has transitions for all " \ "the available conditions." ) return condition = pynebula.lookup( cond_paths[0] ) # Create the transition with a free name transition_path = fsm.get_free_name( self.__get_transitions_path(), 'transition' ) transition = pynebula.new( "ntransition", transition_path ) transition.setcondition( condition ) self.__get_state().addtransition( transition ) self.list_transitions.Append( get_transition_gui_name( transition.getfullname() ) ) self.__update_new_button() fsmevents.signal_fsm_change(self, fsmevents.ID_NewTransition)
def on_run(self, event): # ask for save before run if script has been modified if self.stc.GetModify(): answer = cjr.confirm_yes_no( self, "Save changes to '%s' ?" % self.filename) if answer == wx.ID_YES: self.save(True) elif answer == wx.ID_CANCEL: return if self.filename == "": cjr.show_information_message( "I'm quite stupid, so please you Supreme Intelligence\n" \ "save the file so I can look at its extension and know\n" \ "which file type this script is." ) if self.filename.endswith('.lua'): servers.get_lua_server().runscript( str(format.mangle_path(self.filename))) elif self.filename.endswith('.py'): servers.get_python_server().runscript( str(format.mangle_path(self.filename)))
def on_clean_commands(self, event): """Delete the whole directories of the non existent classes""" # Remove the classes directories ks = servers.get_kernel_server() removed_cmds = [] classes_path = format.mangle_path( cmdmgrdlg.ClassesPath ) filenames = os.listdir( classes_path ) for filename in filenames: if filename.startswith("."): # skip special directories/files continue file_path = format.append_to_path( classes_path, filename ) if os.path.isdir( file_path ) and ks.findclass(str(filename)) == "": cmdmgrdlg.remove_class_dir( file_path, removed_cmds, filename ) # Show which have been the removed classes if len( removed_cmds ) == 0: cjr.show_information_message( "No trash command has been found." ) else: dlg = CleanReportDialog( self.get_frame(), removed_cmds ) dlg.ShowModal() dlg.Destroy()
def on_ok(self, event): if not self.__has_valid_class_name(): cjr.show_error_message("Invalid class name.") return False new_name = self.__get_class_name().capitalize() global_lightmap_size = self.get_global_lightmap_resolution() dlg = waitdlg.WaitDialog(self.GetParent(), "Creating global terrain lightmap...") terrain = trn.get_terrain_module() result = terrain.createterraingloballightmap(new_name, global_lightmap_size) # Closes dialog reporting OK dlg.Destroy() if result: cjr.show_information_message( "Successfully created global terrain lightmap %s" % new_name) self.EndModal(wx.ID_OK) else: cjr.show_error_message( "Unable to create the global terrain lightmap") self.EndModal(wx.ID_OK)
def on_toggle_temporary_mode(self, event): """Toggle working in temporary mode""" cjr.show_information_message( "When the 'wc' assign becomes and assign group let\n" \ "carles.ros know it and he will enable this feature." ) return temp_path = guisettings.Repository.getsettingvalue( guisettings.ID_TemporaryWorkingPath ) temp_path = servers.get_file_server().manglepath( str(temp_path) ) fileserver = servers.get_file_server() if event.IsChecked(): fileserver.setassigngroup2( 'wc', str(temp_path), str(self.wc_path) ) else: fileserver.setassigngroup2( 'wc', str(self.wc_path), str(self.wc_path) )
def on_change_layout(self, event): if set_layout(event.get_selection()): pass else: cjr.show_information_message( "Sorry, the selected layout isn't supported yet.")