def on_export_heightmap(self, evt): """ Show a file browser and export the heightmap with the entered file name """ target_directory = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_Heightmap) dlg = wx.FileDialog( self.get_frame(), message="Save heightmap as", defaultDir=target_directory, wildcard="BMP image (*.bmp)|*.bmp|" \ "TGA image (*.tga)|*.tga|" \ "jpeg image (*.jpg)|*.jpg|" \ "PNG image (*.png)|*.png|" \ "dds image (*.dds)|*.dds|" \ "PPM image(*.ppm)|*.ppm|" \ "DIB image (*.dib)|*.dib|" \ "PFM image (*.pfm)|*.pfm|" | "Any file (*.*)|*.*", style=wx.SAVE|wx.OVERWRITE_PROMPT ) dlg.SetFilterIndex(1) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() path = servers.get_file_server().manglepath(str(path)) trn.get_terrain_module().exportheightmap(str(path)) # Record last directory last_directory = format.get_directory(path) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_Heightmap, last_directory) dlg.Destroy()
def postlevel_process(is_new_level): if not is_new_level: return # What follows should be done only for new and open level commands # Load the level preset apply_level_preset() # Set the new outdoor to the terrain state if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor( app.get_outdoor_obj() ) # End the persist-restore process (continue from prelevel_process) # Close guiDialog windows frame = app.get_top_window() for child in frame.get_child_dialogs(): child.Close() # Refresh other GUI features frame.refresh_all() # Restore persisted guiDialog windows for data in prelevel_process.child_data: restore_window(data) prelevel_process.child_data = []
def on_export_heightmap(self, evt): """ Show a file browser and export the heightmap with the entered file name """ target_directory = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_Heightmap ) dlg = wx.FileDialog( self.get_frame(), message="Save heightmap as", defaultDir=target_directory, wildcard="BMP image (*.bmp)|*.bmp|" \ "TGA image (*.tga)|*.tga|" \ "jpeg image (*.jpg)|*.jpg|" \ "PNG image (*.png)|*.png|" \ "dds image (*.dds)|*.dds|" \ "PPM image(*.ppm)|*.ppm|" \ "DIB image (*.dib)|*.dib|" \ "PFM image (*.pfm)|*.pfm|" | "Any file (*.*)|*.*", style=wx.SAVE|wx.OVERWRITE_PROMPT ) dlg.SetFilterIndex(1) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() path = servers.get_file_server().manglepath( str(path) ) trn.get_terrain_module().exportheightmap( str(path) ) # Record last directory last_directory = format.get_directory( path ) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_Heightmap, last_directory ) dlg.Destroy()
def on_import_heightmap(self, evt): """Show a file browser and import the selected heightmap""" source_directory = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_Heightmap ) dlg = wx.FileDialog( self.get_frame(), message="Choose a heightmap file to import", defaultDir=source_directory, wildcard="Image files (*.bmp,*.tga,*.jpg,*.jpeg,*.png," \ "*.dds,*.ppm,*.dib,*.pfm,*.*)|*.bmp;*.tga;" \ "*.jpg;*.jpeg;*.png;*.dds;*.ppm;*.dib;*.pfm;*.*", style=wx.OPEN ) if dlg.ShowModal() == wx.ID_OK: trn.get_terrain_module().importheightmap( str( dlg.GetPath() ) ) # Record last directory last_directory = format.get_directory( dlg.GetPath() ) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_Heightmap, last_directory ) dlg.Destroy()
def on_generate_weightmaps(self, event): """Generate terrain weightmaps""" try: try: dlg = waitdlg.WaitDialog(self.get_frame(), "Generating weightmaps...") trn.get_terrain_module().createterrainweightmaps() finally: dlg.Destroy() except: # make sure any errors are not hidden raise
def on_preprocess_horizon(self, event): """Preprocess terrain horizon culling information""" try: try: dlg = waitdlg.WaitDialog(self.get_frame(), "Preprocessing horizon...") trn.get_terrain_module().preprocesshorizon() finally: dlg.Destroy() except: # make sure any errors are not hidden raise
def on_generate_global_texture(self, event): """Generate the terrain global texture""" try: try: dlg = waitdlg.WaitDialog(self.get_frame(), "Generating global texture...") trn.get_terrain_module().createterrainglobaltexture() finally: dlg.Destroy() except: # make sure any errors are not hidden raise
def on_preprocess_horizon(self, event): """Preprocess terrain horizon culling information""" try: try: dlg = waitdlg.WaitDialog( self.get_frame(), "Preprocessing horizon..." ) trn.get_terrain_module().preprocesshorizon() finally: dlg.Destroy() except: # make sure any errors are not hidden raise
def on_generate_weightmaps(self, event): """Generate terrain weightmaps""" try: try: dlg = waitdlg.WaitDialog( self.get_frame(), "Generating weightmaps..." ) trn.get_terrain_module().createterrainweightmaps() finally: dlg.Destroy() except: # make sure any errors are not hidden raise
def on_generate_global_texture(self, event): """Generate the terrain global texture""" try: try: dlg = waitdlg.WaitDialog( self.get_frame(), "Generating global texture..." ) trn.get_terrain_module().createterrainglobaltexture() finally: dlg.Destroy() except: # make sure any errors are not hidden raise
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_ok(self, event): if app.get_outdoor() is not None: cjr.show_error_message( "The level already has a terrain instance." ) return if self.list.GetSelection() == wx.NOT_FOUND: cjr.show_error_message( "Please select a terrain class." ) else: # Create a new terrain dlg = waitdlg.WaitDialog( self.GetParent(), "Creating terrain instance..." ) created_ok = trn.get_terrain_module().createterraininstance( str( self.list.GetStringSelection() ) ) dlg.Destroy() if not created_ok: cjr.show_error_message( "Unable to create the terrain instance." ) else: # Closes dialog reporting OK self.EndModal(wx.ID_OK)
def __init__(self, parent): togwin.ChildToggableDialog.__init__(self, "Terrain edit tool", parent) self.terrain = trn.get_terrain_module() self.imgbox_brushes = imgbox.ImageBox( self, image_size=wx.Size(64, 64), text_size=8 ) self.imgbox_tools = imgbox.ImageBox( self, image_size=wx.Size(32, 32), text_size=8 ) self.sizer_brush_group_staticbox = wx.StaticBox(self, -1, "Brush") self.sizer_tool_group_staticbox = wx.StaticBox(self, -1, "Tool") self.slider_size = intslider.IntSlider( self, -1, "Size", 10, 1, 20 ) self.button_range = wx.Button(self, -1, "[1,20]", style=wx.BU_EXACTFIT) self.choicebook_tool = ToolChoicebook(self, -1) self.__set_properties() self.__do_layout() self.__bind_events()
def __postterrain_process(self): # Set the new outdoor in the terrain state if app.get_current_state() == 'terrain': trn.get_terrain_module().setoutdoor(app.get_outdoor_obj()) # Close and reopen the terrain editors dialogs children_data = [] for child in self.get_frame().GetChildren(): if isinstance( child, (trntoolpanel.ToolDialog, trnlayersdlg.LayerManagerDialog)): data = levelcmds.persist_window(child) if data is not None: children_data.append(data) child.Close() for data in children_data: levelcmds.restore_window(data) # Refresh terrain menu self.get_frame().get_menubar().get_menu('&Terrain').refresh()
def __postterrain_process(self): # Set the new outdoor in the terrain state if app.get_current_state() == 'terrain': trn.get_terrain_module().setoutdoor( app.get_outdoor_obj() ) # Close and reopen the terrain editors dialogs children_data = [] for child in self.get_frame().GetChildren(): if isinstance( child, (trntoolpanel.ToolDialog, trnlayersdlg.LayerManagerDialog) ): data = levelcmds.persist_window(child) if data is not None: children_data.append(data) child.Close() for data in children_data: levelcmds.restore_window(data) # Refresh terrain menu self.get_frame().get_menubar().get_menu('&Terrain').refresh()
def on_import_heightmap(self, evt): """Show a file browser and import the selected heightmap""" source_directory = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_Heightmap) dlg = wx.FileDialog( self.get_frame(), message="Choose a heightmap file to import", defaultDir=source_directory, wildcard="Image files (*.bmp,*.tga,*.jpg,*.jpeg,*.png," \ "*.dds,*.ppm,*.dib,*.pfm,*.*)|*.bmp;*.tga;" \ "*.jpg;*.jpeg;*.png;*.dds;*.ppm;*.dib;*.pfm;*.*", style=wx.OPEN ) if dlg.ShowModal() == wx.ID_OK: trn.get_terrain_module().importheightmap(str(dlg.GetPath())) # Record last directory last_directory = format.get_directory(dlg.GetPath()) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_Heightmap, last_directory) dlg.Destroy()
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 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 postlevel_process(is_new_level): if not is_new_level: return # What follows should be done only for new and open level commands # Load the level preset apply_level_preset() # Set the new outdoor to the terrain state if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor(app.get_outdoor_obj()) # End the persist-restore process (continue from prelevel_process) # Close guiDialog windows frame = app.get_top_window() for child in frame.get_child_dialogs(): child.Close() # Refresh other GUI features frame.refresh_all() # Restore persisted guiDialog windows for data in prelevel_process.child_data: restore_window(data) prelevel_process.child_data = []
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): togwin.ChildToggableDialog.__init__(self, "Terrain edit tool", parent) self.terrain = trn.get_terrain_module() self.imgbox_brushes = imgbox.ImageBox(self, image_size=wx.Size(64, 64), text_size=8) self.imgbox_tools = imgbox.ImageBox(self, image_size=wx.Size(32, 32), text_size=8) self.sizer_brush_group_staticbox = wx.StaticBox(self, -1, "Brush") self.sizer_tool_group_staticbox = wx.StaticBox(self, -1, "Tool") self.slider_size = intslider.IntSlider(self, -1, "Size", 10, 1, 20) self.button_range = wx.Button(self, -1, "[1,20]", style=wx.BU_EXACTFIT) self.choicebook_tool = ToolChoicebook(self, -1) self.__set_properties() self.__do_layout() self.__bind_events()
def on_ok(self, event): if app.get_outdoor() is not None: cjr.show_error_message("The level already has a terrain instance.") return if self.list.GetSelection() == wx.NOT_FOUND: cjr.show_error_message("Please select a terrain class.") else: # Create a new terrain dlg = waitdlg.WaitDialog(self.GetParent(), "Creating terrain instance...") created_ok = trn.get_terrain_module().createterraininstance( str(self.list.GetStringSelection())) dlg.Destroy() if not created_ok: cjr.show_error_message( "Unable to create the terrain instance.") else: # Closes dialog reporting OK self.EndModal(wx.ID_OK)
def __init__(self, *args, **kwds): wx.Choicebook.__init__(self, *args, **kwds) self.terrain = trn.get_terrain_module() self.raise_panel = RaisePanel(self, -1) self.flatten_panel = FlattenPanel(self, -1) self.slope_panel = SlopePanel(self, -1) self.smooth_panel = SmoothPanel(self, -1) self.noise_panel = NoisePanel(self, -1) self.paint_panel = PaintPanel(self, -1) self.grass_panel = GrassPanel(self, -1) self.hole_panel = HolePanel(self, -1) self.AddPage( self.raise_panel, "Raise/Dig" ) self.AddPage( self.flatten_panel, "Flatten" ) self.AddPage( self.slope_panel, "Slope" ) self.AddPage( self.smooth_panel, "Smooth" ) self.AddPage( self.noise_panel, "Noise" ) self.AddPage( self.paint_panel, "Paint" ) self.AddPage( self.grass_panel, "Grass" ) self.AddPage( self.hole_panel, "Hole" ) self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.on_select_tool, self)
def __init__(self, *args, **kwds): wx.Choicebook.__init__(self, *args, **kwds) self.terrain = trn.get_terrain_module() self.raise_panel = RaisePanel(self, -1) self.flatten_panel = FlattenPanel(self, -1) self.slope_panel = SlopePanel(self, -1) self.smooth_panel = SmoothPanel(self, -1) self.noise_panel = NoisePanel(self, -1) self.paint_panel = PaintPanel(self, -1) self.grass_panel = GrassPanel(self, -1) self.hole_panel = HolePanel(self, -1) self.AddPage(self.raise_panel, "Raise/Dig") self.AddPage(self.flatten_panel, "Flatten") self.AddPage(self.slope_panel, "Slope") self.AddPage(self.smooth_panel, "Smooth") self.AddPage(self.noise_panel, "Noise") self.AddPage(self.paint_panel, "Paint") self.AddPage(self.grass_panel, "Grass") self.AddPage(self.hole_panel, "Hole") self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.on_select_tool, self)
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_ok(self, event): ec_server = servers.get_entity_class_server() # Verify that has been given a valid class name name = str( self.text_classname.GetValue().capitalize() ) if not ec_server.checkclassname( name ): cjr.show_error_message( "Please enter a valid class name." ) return # Verify that there isn't another class with the given name outdoors = ec_server.getentityclass("neoutdoor") outdoor = outdoors.gethead() while outdoor is not None: if outdoor.getname() == name: msg = "There is an existing terrain class with " \ "the given name.\n\nPlease enter another." cjr.show_error_message(msg) return outdoor = outdoor.getsucc() # Check that a level size has been entered if not self.has_level_size(): cjr.show_error_message( "Please select a level size." ) return if self.are_min_and_max_height_values_equal(): cjr.show_error_message( "Minimum and maximum height values cannot be the same." ) return # Create the terrain class dlg = waitdlg.WaitDialog( self.GetParent(), "Creating terrain class..." ) try: terrain = trn.get_terrain_module() created_ok = terrain.createterrainclass( name, self.props_ctrls.get_current_resolution(), self.props_ctrls.get_current_block_size(), # N.B. we pass the terrain module the selection # index of the "Cells per terrain block" choice # Since the cells are in the format "2n x 2n", # we are in effect passing the value of n int( self.props_ctrls.choice_veg_cells_per_block.GetSelection() ), int( self.props_ctrls.choice_vegetation_res.GetStringSelection() ), int( self.props_ctrls.choice_weightmap.GetStringSelection() ), int( self.props_ctrls.choice_global_res.GetStringSelection() ), self.props_ctrls.get_point_separation() ) if not created_ok: cjr.show_error_message( "Unable to create the terrain class." ) return flatten_at_value = self.props_ctrls.get_flatten_at_value() if flatten_at_value == '': flatten_at_value = '0.0' set_params_ok = terrain.setterrainclassparams( name, float( self.props_ctrls.text_ctrl_min.get_value() ), float( self.props_ctrls.text_ctrl_max.get_value() ), bool( self.props_ctrls.is_flatten_all_selected() ), float(flatten_at_value) ) if not set_params_ok: cjr.show_error_message( "Unable to create the terrain class " \ "due to invalid parameters." ) return #set the level size centre_to_boundary_trn = (self.props_ctrls.get_terrain_size_in_metres() ) / 2 centre_to_boundary_level = ( self.props_ctrls.get_current_level_size() ) / 2 new_class = ec_server.getentityclass(name) new_class.setoriginalbbox( centre_to_boundary_trn, 0, centre_to_boundary_trn, centre_to_boundary_level, centre_to_boundary_level, centre_to_boundary_level ) # Create a terrain instance, if enabled if self.checkbox_make_terrain.IsChecked(): dlg.set_message( "Creating terrain instance..." ) created_trn_ok = terrain.createterraininstance( name ) if not created_trn_ok: cjr.show_error_message( "Unable to create the terrain instance." ) finally: # Closes dialog dlg.Destroy() #report OK self.EndModal(wx.ID_OK)