def on_texture(self, event): # Let the user choose a file among the shared textures mangled_shared_dir = format.mangle_path( "wc:export/textures" ) dir = cfg.Repository.getsettingvalue( cfg.ID_BrowserPath_SharedMaterial ) if dir == "": dir = mangled_shared_dir dlg = wx.FileDialog( self, message="Choose an image file", defaultDir = dir, wildcard="Image files (*.dds)|*.dds", style=wx.OPEN ) if dlg.ShowModal() == wx.ID_OK: mangled_path = format.mangle_path( dlg.GetPath() ) if not mangled_path.startswith( mangled_shared_dir ): wx.MessageBox("You should choose a texture file from the" \ " directory 'wc:export/textures' or below.", "Conjurer", style=wx.ICON_ERROR) else: self.button_texture.SetLabel( format.get_relative_path( mangled_shared_dir, mangled_path ) ) # Record last directory dir = format.get_directory( mangled_path ) cfg.Repository.setsettingvalue( cfg.ID_BrowserPath_SharedMaterial, dir ) dlg.Destroy()
def on_choose_shared_texture(self, event): # let the user choose a file among the shared textures mangled_shared_dir = format.mangle_path(self.get_shared_path()) target_dir = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_SharedMaterial) if target_dir == "": target_dir = mangled_shared_dir dlg = wx.FileDialog(self.window, message="Choose an image file", defaultDir=target_dir, wildcard="Image files (*.dds)|*.dds", style=wx.OPEN) if dlg.ShowModal() == wx.ID_OK: mangled_path = format.mangle_path(dlg.GetPath()) if not mangled_path.startswith(mangled_shared_dir): cjr.show_error_message( "You should choose a texture file from the " \ "'%s' directory ' or below." % self.get_shared_path() ) else: self.button_shared_texture.SetLabel( format.get_relative_path(mangled_shared_dir, mangled_path)) self.radio_shared_texture.Enable(True) self.radio_local_texture.SetValue(False) self.radio_shared_texture.SetValue(True) # Record last directory target_dir = format.get_directory(mangled_path) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_SharedMaterial, target_dir) dlg.Destroy()
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_custom_texture(self, event): # Let the user choose a file from the shared textures mangled_shared_dir = format.mangle_path("wc:export/textures") directory = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_SharedMaterial) if directory == "": directory = mangled_shared_dir dlg = wx.FileDialog(self, message="Choose an image file", defaultDir=directory, wildcard="Image files (*.dds)|*.dds", style=wx.OPEN) if dlg.ShowModal() == wx.ID_OK: mangled_path = format.mangle_path(dlg.GetPath()) if not mangled_path.startswith(mangled_shared_dir): msg = "You should choose a texture file from the" \ " directory 'wc:export/textures' or below." cjr.show_error_message(msg) else: self.set_custom_texture( format.get_relative_path(mangled_shared_dir, mangled_path)) # Record last directory directory = format.get_directory(mangled_path) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_SharedMaterial, directory) dlg.Destroy()
def on_custom_texture(self, event): # Let the user choose a file from the shared textures mangled_shared_dir = format.mangle_path( "wc:export/textures" ) directory = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_SharedMaterial ) if directory == "": directory = mangled_shared_dir dlg = wx.FileDialog( self, message="Choose an image file", defaultDir = directory, wildcard="Image files (*.dds)|*.dds", style=wx.OPEN ) if dlg.ShowModal() == wx.ID_OK: mangled_path = format.mangle_path( dlg.GetPath() ) if not mangled_path.startswith( mangled_shared_dir ): msg = "You should choose a texture file from the" \ " directory 'wc:export/textures' or below." cjr.show_error_message(msg) else: self.set_custom_texture( format.get_relative_path( mangled_shared_dir, mangled_path ) ) # Record last directory directory = format.get_directory(mangled_path) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_SharedMaterial, directory ) dlg.Destroy()
def __init__(self, parent, fsm_path=None): wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.NO_FULL_REPAINT_ON_RESIZE) self.fsm_path = fsm_path global fsm_count preview_filename = format.mangle_path( str("outgui:images/temp/fsm" + str(fsm_count))) self.dot_path = preview_filename + ".dot" self.image_path = preview_filename + ".gif" self.map_path = preview_filename + ".map" self.html_path = preview_filename + ".html" fsm_count += 1 self.ie = iewin.IEHtmlWindow(self, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.ie, 1, wx.EXPAND) self.SetSizer(sizer) self.Bind(iewin.EVT_BeforeNavigate2, self.__on_before_navigate, self.ie)
def __init__ (self, parent): wx.Panel.__init__( self, parent, -1 ) self.SetBackgroundColour( cfg.HEADER_BACKGROUND_COLOUR ) self.label = wx.StaticText( self, -1, 'Filter by natives' ) font_to_use = self.label.GetFont() font_to_use.SetWeight( wx.FONTWEIGHT_BOLD ) self.label.SetFont(font_to_use) bmap = wx.Bitmap( format.mangle_path( "outgui:images/tools/tiny_close.bmp" ) ) self.button_close = wx.BitmapButton( self, -1, bmap, style = wx.NO_BORDER ) self.__do_layout()
def on_save_outdoor(self, event): """Save the outdoor's navigation mesh on a user specified file""" outdoor = app.get_outdoor_obj() if outdoor == None: cjr.show_error_message( "The current level doesn't have an outdoor" ) return dlg = wx.FileDialog( self.get_frame(), message="Enter a file name", wildcard="Navigation mesh ASCII file (*.txt)|*.txt|" \ "Navigation mesh binary file (*.nav)|*.nav|" \ "Navigation mesh compressed file (*.rle)|*.rle", defaultDir=format.mangle_path( "level:ai/" + \ hex(outdoor.getid())[2:] ), defaultFile="navmesh", style=wx.SAVE | wx.OVERWRITE_PROMPT ) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() # Append extension if needed if dlg.GetFilterIndex() == 0 and not path.endswith(".txt"): path = path + ".txt" elif dlg.GetFilterIndex() == 1 and not path.endswith(".nav"): path = path + ".nav" elif dlg.GetFilterIndex() == 2 and not path.endswith(".rle"): path = path + ".rle" # Save the navigation mesh navbuilder = app.get_navbuilder() if not navbuilder.saveoutdoornavmesh( str(dlg.GetPath()) ): msg = "Unable to save the navigation mesh file '%s'" % dlg.GetPath() cjr.show_error_message(msg) dlg.Destroy()
def on_save_outdoor(self, event): """Save the outdoor's navigation mesh on a user specified file""" outdoor = app.get_outdoor_obj() if outdoor == None: cjr.show_error_message("The current level doesn't have an outdoor") return dlg = wx.FileDialog( self.get_frame(), message="Enter a file name", wildcard="Navigation mesh ASCII file (*.txt)|*.txt|" \ "Navigation mesh binary file (*.nav)|*.nav|" \ "Navigation mesh compressed file (*.rle)|*.rle", defaultDir=format.mangle_path( "level:ai/" + \ hex(outdoor.getid())[2:] ), defaultFile="navmesh", style=wx.SAVE | wx.OVERWRITE_PROMPT ) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() # Append extension if needed if dlg.GetFilterIndex() == 0 and not path.endswith(".txt"): path = path + ".txt" elif dlg.GetFilterIndex() == 1 and not path.endswith(".nav"): path = path + ".nav" elif dlg.GetFilterIndex() == 2 and not path.endswith(".rle"): path = path + ".rle" # Save the navigation mesh navbuilder = app.get_navbuilder() if not navbuilder.saveoutdoornavmesh(str(dlg.GetPath())): msg = "Unable to save the navigation mesh file '%s'" % dlg.GetPath( ) cjr.show_error_message(msg) dlg.Destroy()
def __init__(self, parent, id=-1, label="", value="", size=wx.DefaultSize, validator=None, allow_empty=False): wx.PyControl.__init__(self, parent, id, style=wx.NO_BORDER) self.label = wx.StaticText(self, -1, label, style=wx.TE_RIGHT) self.text = wx.TextCtrl(self, id, value, size=size, style=wx.TE_PROCESS_ENTER) bmap = wx.Bitmap(format.mangle_path("outgui:images/tools/ok.bmp")) self.button = wx.BitmapButton(self, -1, bmap, style=wx.BU_AUTODRAW, size=(21, 21)) self.old_value = value self.validator = validator self.allow_empty = allow_empty self.__do_layout() self.__bind_events()
def __get_cmd_path(self, class_name, cmd_name, unmangled=False): path = format.append_to_path( self.__get_class_path(class_name), cmd_name + ".lua" ) if unmangled: return path return format.mangle_path( path )
def __init__(self, parent, image_path=None): wx.PyScrolledWindow.__init__(self, parent, style=wx.SUNKEN_BORDER) self.image = wx.StaticBitmap(self, -1, wx.Bitmap(format.mangle_path(image_path))) self.SetScrollRate(1, 1) self.SetVirtualSize(self.image.GetSize())
def __get_template_path(self, template_name, unmangled=False): path = format.append_to_path( TemplatesPath, template_name + ".lua" ) if unmangled: return path return format.mangle_path( path )
def __init__(self, parent, image_path=None): wx.PyScrolledWindow.__init__(self, parent, style=wx.SUNKEN_BORDER) self.image = wx.StaticBitmap( self, -1, wx.Bitmap( format.mangle_path(image_path)) ) self.SetScrollRate(1,1) self.SetVirtualSize( self.image.GetSize() )
def get_class_commands(class_name, inherited_cmds = False): """Return the prototype of all the scripted commands for a class""" path = format.append_to_path( ClassesPath, class_name ) path = format.mangle_path( path ) cmds_list = filedlg.get_file_list( path, ['lua'] ) if inherited_cmds: class_name = servers.get_kernel_server().getsuperclass( class_name ) if class_name != ':null:': cmds_list.extend( get_class_commands(class_name, True) ) cmds_list.sort() return cmds_list
def get_class_commands(class_name, inherited_cmds=False): """Return the prototype of all the scripted commands for a class""" path = format.append_to_path(ClassesPath, class_name) path = format.mangle_path(path) cmds_list = filedlg.get_file_list(path, ['lua']) if inherited_cmds: class_name = servers.get_kernel_server().getsuperclass(class_name) if class_name != ':null:': cmds_list.extend(get_class_commands(class_name, True)) cmds_list.sort() return cmds_list
def on_resource(self, event): # Let the user choose a file mangled_dir = format.mangle_path(self.location) dlg = wx.FileDialog( self, message="Choose a sound file", defaultDir=mangled_dir, wildcard="WAV files (*.wav)|*.wav|OGG files (*.ogg)|*.ogg", style=wx.OPEN) if dlg.ShowModal() == wx.ID_OK: path_string = dlg.GetPath() if not self.__is_valid_resource_name(path_string): msg = "You must choose a sound file from %s" % self.location cjr.show_error_message(msg) else: self.set_resource( format.get_relative_path( self.__get_mangled_sound_root_dir(), format.mangle_path(path_string))) dlg.Destroy()
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_choose_shared_texture(self, event): # let the user choose a file among the shared textures mangled_shared_dir = format.mangle_path( self.get_shared_path() ) target_dir = guisettings.Repository.getsettingvalue( guisettings.ID_BrowserPath_SharedMaterial ) if target_dir == "": target_dir = mangled_shared_dir dlg = wx.FileDialog( self.window, message="Choose an image file", defaultDir = target_dir, wildcard="Image files (*.dds)|*.dds", style=wx.OPEN ) if dlg.ShowModal() == wx.ID_OK: mangled_path = format.mangle_path( dlg.GetPath() ) if not mangled_path.startswith( mangled_shared_dir ): cjr.show_error_message( "You should choose a texture file from the " \ "'%s' directory ' or below." % self.get_shared_path() ) else: self.button_shared_texture.SetLabel( format.get_relative_path( mangled_shared_dir, mangled_path ) ) self.radio_shared_texture.Enable(True) self.radio_local_texture.SetValue(False) self.radio_shared_texture.SetValue(True) # Record last directory target_dir = format.get_directory( mangled_path ) guisettings.Repository.setsettingvalue( guisettings.ID_BrowserPath_SharedMaterial, target_dir ) dlg.Destroy()
def __init__(self, parent, id=-1, label="", value="", size=wx.DefaultSize, validator=None, allow_empty=False): wx.PyControl.__init__(self, parent, id, style=wx.NO_BORDER) self.label = wx.StaticText(self, -1, label, style=wx.TE_RIGHT) self.text = wx.TextCtrl(self, id, value, size=size, style=wx.TE_PROCESS_ENTER) bmap = wx.Bitmap( format.mangle_path("outgui:images/tools/ok.bmp") ) self.button = wx.BitmapButton(self, -1, bmap, style=wx.BU_AUTODRAW, size=(21,21)) self.old_value = value self.validator = validator self.allow_empty = allow_empty self.__do_layout() self.__bind_events()
def on_resource(self, event): # Let the user choose a file mangled_dir = format.mangle_path(self.location) dlg = wx.FileDialog( self, message="Choose a sound file", defaultDir = mangled_dir, wildcard="WAV files (*.wav)|*.wav|OGG files (*.ogg)|*.ogg", style=wx.OPEN ) if dlg.ShowModal() == wx.ID_OK: path_string = dlg.GetPath() if not self.__is_valid_resource_name(path_string): msg = "You must choose a sound file from %s" % self.location cjr.show_error_message(msg) else: self.set_resource( format.get_relative_path( self.__get_mangled_sound_root_dir(), format.mangle_path(path_string) ) ) dlg.Destroy()
def __init__(self, parent, fsm_path=None): wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE) self.fsm_path = fsm_path global fsm_count preview_filename = format.mangle_path( str("outgui:images/temp/fsm" + str(fsm_count)) ) self.dot_path = preview_filename + ".dot" self.image_path = preview_filename + ".gif" self.map_path = preview_filename + ".map" self.html_path = preview_filename + ".html" fsm_count += 1 self.ie = iewin.IEHtmlWindow(self, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.ie, 1, wx.EXPAND) self.SetSizer(sizer) self.Bind(iewin.EVT_BeforeNavigate2, self.__on_before_navigate, self.ie)
def __init__(self, parent): wx.TreeCtrl.__init__(self, parent, -1, style=wx.TR_HAS_BUTTONS | wx.TR_DEFAULT_STYLE | wx.SUNKEN_BORDER) self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.__on_item_expanding, self) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.__on_item_collapsed, self) # Icons used to show if a node is a folder or an element image_size = (16, 16) image_list = wx.ImageList(image_size[0], image_size[1]) self.close_img = image_list.Add( wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, image_size)) self.open_img = image_list.Add( wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, image_size)) self.native_img = image_list.Add( wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, image_size)) bmp = wx.Bitmap(format.mangle_path("outgui:images/tools/red_doc.bmp")) self.no_native_img = image_list.Add(bmp) self.global_image = image_list.Add( wx.ArtProvider_GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, image_size)) self.SetImageList(image_list) self.il = image_list # Build root branch # To define a special expand/collapse behavior for a branch set an id # as data for that branch. Then implement the expand/collpase function # by postfixing the id to the function name (see current # implementations for examples) root_item = self.AddRoot("Classes", self.close_img, -1, wx.TreeItemData('root')) self.SetItemImage(root_item, self.open_img, wx.TreeItemIcon_Expanded) self.SetItemHasChildren(root_item, True) # Expand root branch by default self.Expand(root_item)
def save(self, overwrite=True): """ Save the dialog's script If it's a new script or the user doesn't want to overwrite the file a new file name is asked, otherwise the old file name is overwrited. \param overwrite False to ask for a new file name, true to overwrite it \return True if script has been saved, false otherwise """ # It's a new script? if self.filename == "" or overwrite == False: # Ask for a file name file_dlg = wx.FileDialog( self.GetParent(), message="Choose a script file", wildcard = "Lua script files (*.lua)|*.lua|" \ "Python script files (*.py)|*.py", style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR ) # Set new file name or cancel save if file_dlg.ShowModal() == wx.ID_OK: self.filename = file_dlg.GetPath() self.__set_highlighting() file_dlg.Destroy() else: file_dlg.Destroy() return False # Save the script f = codecs.open(format.mangle_path(self.filename), 'w', 'latin-1', 'replace') f.write(self.stc.GetText()) f.close() self.stc.empty_undo_buffer() self.__update_title() return True
def save(self, overwrite=True): """ Save the dialog's script If it's a new script or the user doesn't want to overwrite the file a new file name is asked, otherwise the old file name is overwrited. \param overwrite False to ask for a new file name, true to overwrite it \return True if script has been saved, false otherwise """ # It's a new script? if self.filename == "" or overwrite == False: # Ask for a file name file_dlg = wx.FileDialog( self.GetParent(), message="Choose a script file", wildcard = "Lua script files (*.lua)|*.lua|" \ "Python script files (*.py)|*.py", style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR ) # Set new file name or cancel save if file_dlg.ShowModal() == wx.ID_OK: self.filename = file_dlg.GetPath() self.__set_highlighting() file_dlg.Destroy() else: file_dlg.Destroy() return False # Save the script f = codecs.open(format.mangle_path(self.filename),'w','latin-1','replace') f.write( self.stc.GetText() ) f.close() self.stc.empty_undo_buffer() self.__update_title() return True
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 __get_class_path(self, class_name, unmangled=False): path = format.append_to_path( ClassesPath, class_name ) if unmangled: return path return format.mangle_path( path )
def __set_properties(self): self.SetSize((500, 400)) self.stc.set_font( cfg.Repository.get_font(cfg.ID_Font_ScriptEditor) ) if self.filename != "": self.load( format.mangle_path(self.filename) )
def get_brief(self): if self.filename == "": name = "<Unknown>" else: name = format.get_name( format.mangle_path(self.filename) ) return "(script) " + name
def __init__(self, parent): wx.TreeCtrl.__init__( self, parent, -1, style=wx.TR_HAS_BUTTONS|wx.TR_DEFAULT_STYLE|wx.SUNKEN_BORDER ) self.Bind( wx.EVT_TREE_ITEM_EXPANDING, self.__on_item_expanding, self ) self.Bind( wx.EVT_TREE_ITEM_COLLAPSED, self.__on_item_collapsed, self ) # Icons used to show if a node is a folder or an element image_size = (16, 16) image_list = wx.ImageList(image_size[0], image_size[1]) self.close_img = image_list.Add( wx.ArtProvider_GetBitmap( wx.ART_FOLDER, wx.ART_OTHER, image_size ) ) self.open_img = image_list.Add( wx.ArtProvider_GetBitmap( wx.ART_FILE_OPEN, wx.ART_OTHER, image_size ) ) self.native_img = image_list.Add( wx.ArtProvider_GetBitmap( wx.ART_NORMAL_FILE, wx.ART_OTHER, image_size ) ) bmp = wx.Bitmap( format.mangle_path( "outgui:images/tools/red_doc.bmp" ) ) self.no_native_img = image_list.Add(bmp) self.global_image = image_list.Add( wx.ArtProvider_GetBitmap( wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, image_size ) ) self.SetImageList(image_list) self.il = image_list # Build root branch # To define a special expand/collapse behavior for a branch set an id # as data for that branch. Then implement the expand/collpase function # by postfixing the id to the function name (see current # implementations for examples) root_item = self.AddRoot( "Classes", self.close_img, -1, wx.TreeItemData('root') ) self.SetItemImage( root_item, self.open_img, wx.TreeItemIcon_Expanded ) self.SetItemHasChildren( root_item, True ) # Expand root branch by default self.Expand( root_item )
def get_brief(self): if self.filename == "": name = "<Unknown>" else: name = format.get_name(format.mangle_path(self.filename)) return "(script) " + name
def __get_class_path(self, class_name, unmangled=False): path = format.append_to_path(ClassesPath, class_name) if unmangled: return path return format.mangle_path(path)
def __get_cmd_path(self, class_name, cmd_name, unmangled=False): path = format.append_to_path(self.__get_class_path(class_name), cmd_name + ".lua") if unmangled: return path return format.mangle_path(path)
def __is_valid_resource_name(self, resource_path): mangled_path = format.mangle_path( resource_path ) mangled_sound_directory = self.__get_mangled_sound_root_dir() return mangled_path.startswith(mangled_sound_directory)
def get_mangled_root_directory(self): return format.mangle_path(self.root_directory)
def restore(self, data_list): # set brush and tool images # load images only once to speed things up if not self.restored: # brushes fileserver = servers.get_file_server() brushes_nb = self.terrain.paintbrushcount() for i in range(brushes_nb): path = self.terrain.getpaintbrushthumbnail(i) path = fileserver.manglepath(path) bmp = wx.Bitmap(path, wx.BITMAP_TYPE_ANY) if self.terrain.issizeablepaintbrush(i): img_name = 'Resizable' else: img_name = str(self.terrain.getpaintbrushsizebyindex(i)) self.imgbox_brushes.append_image(bmp, name=img_name) # tools tool_names = [ 'Raise', 'Flatten', 'Slope', 'Smooth', 'Noise', 'Paint', 'Grass', 'Hole' ] for name in tool_names: path = "outgui:images/terrain/%s.bmp" % name.lower() path = format.mangle_path(path) bmp = wx.Bitmap(path) self.imgbox_tools.append_image(bmp, name=name) self.restored = True # restore brush size range data = data_list[0] min_value = 1 if data.has_key('brush min size'): min_value = data['brush min size'] max_value = 20 if data.has_key('brush max size'): max_value = data['brush max size'] self.slider_size.set_range(min_value, max_value) self.button_range.SetLabel("[%s,%s]" % (min_value, max_value)) # restore conjurer terrain object self.terrain.selectpaintbrush(data['selected brush']) size = data['brush size'] if size < min_value: size = min_value elif size > max_value: size = max_value self.choicebook_tool.set_tools_brush_size(size) # restore controls if self.terrain.getselectedpaintbrush() != wx.NOT_FOUND: self.imgbox_brushes.set_selection( self.terrain.getselectedpaintbrush()) selection_index = self.imgbox_brushes.get_selection() self.enable_disable_brush_size_range( self.terrain.issizeablepaintbrush(selection_index)) self.slider_size.set_value(self.terrain.getpaintbrushsize()) self.imgbox_tools.set_selection(self.terrain.getselectedtool()) # restore children self.choicebook_tool.restore(data['tools'])
def __set_properties(self): # default projection self.choice_projection.SetSelection(0) # allowed UV size values outdoor = app.get_outdoor() min_value = 0.25 self.max_uvsize = outdoor.getheightmap().getgridscale() * \ (outdoor.getblocksize() - 1) while min_value <= self.max_uvsize: self.choice_u.Append( str(min_value) ) self.choice_v.Append( str(min_value) ) min_value = min_value * 2 # valid texture files self.__update_combo_local_texture() # default texture files self.button_shared_texture.SetLabel( "dds/ground/cesped_test_terrain.dds" ) if self.combo_local_texture.GetCount() == 0: self.radio_local_texture.Enable(False) else: self.combo_local_texture.SetSelection(0) self.radio_local_texture.SetValue(False) self.radio_shared_texture.SetValue(True) # default UV size self.choice_u.SetValue("1.0") self.choice_v.SetValue("1.0") # align texture box fields by setting all labels to longest length format.align_labels([ self.radio_local_texture, self.radio_shared_texture, self.label_u, self.label_projection ]) # valid game materials self.__update_game_materials_choicer() # current settings if self.layer_ctrl is not None: self.text_name.SetValue( self.layer_ctrl.get_layer_name() ) mangled_path = format.mangle_path( self.layer_ctrl.get_texture_filename() ) mangled_local_dir = format.mangle_path( self.get_textures_path() ) mangled_shared_dir = format.mangle_path( self.get_shared_path() ) if mangled_path.startswith( mangled_local_dir ): self.combo_local_texture.SetStringSelection( format.get_relative_path( mangled_local_dir, mangled_path ) ) self.radio_shared_texture.SetValue(False) self.radio_local_texture.SetValue(True) else: self.button_shared_texture.SetLabel( format.get_relative_path( mangled_shared_dir, mangled_path ) ) self.radio_local_texture.SetValue(False) self.radio_shared_texture.SetValue(True) uv_scale = self.layer_ctrl.get_uv_scale() self.choice_u.SetValue( str( self.uvscale2size(uv_scale[0]) ) ) self.choice_v.SetValue( str( self.uvscale2size(uv_scale[1]) ) ) self.choice_projection.SetSelection( self.layer_ctrl.get_projection() ) color = self.layer_ctrl.get_color_mask().Get() self.color_sel.set_value(color)
def __is_valid_resource_name(self, resource_path): mangled_path = format.mangle_path(resource_path) mangled_sound_directory = self.__get_mangled_sound_root_dir() return mangled_path.startswith(mangled_sound_directory)
def __get_template_path(self, template_name, unmangled=False): path = format.append_to_path(TemplatesPath, template_name + ".lua") if unmangled: return path return format.mangle_path(path)
def __get_script_path(self, obj_path): script_name = format.get_name( obj_path ) + ".lua" script_path = format.append_to_path( self.disk_lib_path, script_name ) return format.mangle_path( script_path )
def __set_properties(self): # default projection self.choice_projection.SetSelection(0) # allowed UV size values outdoor = app.get_outdoor() min_value = 0.25 self.max_uvsize = outdoor.getheightmap().getgridscale() * \ (outdoor.getblocksize() - 1) while min_value <= self.max_uvsize: self.choice_u.Append(str(min_value)) self.choice_v.Append(str(min_value)) min_value = min_value * 2 # valid texture files self.__update_combo_local_texture() # default texture files self.button_shared_texture.SetLabel( "dds/ground/cesped_test_terrain.dds") if self.combo_local_texture.GetCount() == 0: self.radio_local_texture.Enable(False) else: self.combo_local_texture.SetSelection(0) self.radio_local_texture.SetValue(False) self.radio_shared_texture.SetValue(True) # default UV size self.choice_u.SetValue("1.0") self.choice_v.SetValue("1.0") # align texture box fields by setting all labels to longest length format.align_labels([ self.radio_local_texture, self.radio_shared_texture, self.label_u, self.label_projection ]) # valid game materials self.__update_game_materials_choicer() # current settings if self.layer_ctrl is not None: self.text_name.SetValue(self.layer_ctrl.get_layer_name()) mangled_path = format.mangle_path( self.layer_ctrl.get_texture_filename()) mangled_local_dir = format.mangle_path(self.get_textures_path()) mangled_shared_dir = format.mangle_path(self.get_shared_path()) if mangled_path.startswith(mangled_local_dir): self.combo_local_texture.SetStringSelection( format.get_relative_path(mangled_local_dir, mangled_path)) self.radio_shared_texture.SetValue(False) self.radio_local_texture.SetValue(True) else: self.button_shared_texture.SetLabel( format.get_relative_path(mangled_shared_dir, mangled_path)) self.radio_local_texture.SetValue(False) self.radio_shared_texture.SetValue(True) uv_scale = self.layer_ctrl.get_uv_scale() self.choice_u.SetValue(str(self.uvscale2size(uv_scale[0]))) self.choice_v.SetValue(str(self.uvscale2size(uv_scale[1]))) self.choice_projection.SetSelection( self.layer_ctrl.get_projection()) color = self.layer_ctrl.get_color_mask().Get() self.color_sel.set_value(color)
def restore(self, data_list): # set brush and tool images # load images only once to speed things up if not self.restored: # brushes fileserver = servers.get_file_server() brushes_nb = self.terrain.paintbrushcount() for i in range(brushes_nb): path = self.terrain.getpaintbrushthumbnail(i) path = fileserver.manglepath(path) bmp = wx.Bitmap(path, wx.BITMAP_TYPE_ANY) if self.terrain.issizeablepaintbrush(i): img_name = 'Resizable' else: img_name = str( self.terrain.getpaintbrushsizebyindex(i) ) self.imgbox_brushes.append_image(bmp, name=img_name) # tools tool_names = ['Raise', 'Flatten', 'Slope', 'Smooth', 'Noise', 'Paint', 'Grass', 'Hole'] for name in tool_names: path = "outgui:images/terrain/%s.bmp" % name.lower() path = format.mangle_path( path ) bmp = wx.Bitmap(path) self.imgbox_tools.append_image( bmp, name=name ) self.restored = True # restore brush size range data = data_list[0] min_value = 1 if data.has_key('brush min size'): min_value = data['brush min size'] max_value = 20 if data.has_key('brush max size'): max_value = data['brush max size'] self.slider_size.set_range(min_value, max_value ) self.button_range.SetLabel( "[%s,%s]" % (min_value, max_value) ) # restore conjurer terrain object self.terrain.selectpaintbrush( data['selected brush'] ) size = data['brush size'] if size < min_value: size = min_value elif size > max_value: size = max_value self.choicebook_tool.set_tools_brush_size( size ) # restore controls if self.terrain.getselectedpaintbrush() != wx.NOT_FOUND: self.imgbox_brushes.set_selection( self.terrain.getselectedpaintbrush() ) selection_index = self.imgbox_brushes.get_selection() self.enable_disable_brush_size_range( self.terrain.issizeablepaintbrush( selection_index ) ) self.slider_size.set_value( self.terrain.getpaintbrushsize() ) self.imgbox_tools.set_selection( self.terrain.getselectedtool() ) # restore children self.choicebook_tool.restore( data['tools'] )
def __set_properties(self): self.SetSize((500, 400)) self.stc.set_font(cfg.Repository.get_font(cfg.ID_Font_ScriptEditor)) if self.filename != "": self.load(format.mangle_path(self.filename))