def __init__(self, windows): Window.__init__(self, windows) PickBeltWidget.__init__(self) self._settings = horizons.globals.fife._setting self.widget.mapEvents({ 'okButton': self.apply_settings, 'defaultButton': self.set_defaults, 'cancelButton': self._windows.close, }) languages = find_available_languages().keys() language_names = [LANGUAGENAMES[x] for x in sorted(languages)] fps = {0: _lazy("Disabled"), 30: 30, 45: 45, 60: 60, 90: 90, 120: 120} FIFE = SETTINGS.FIFE_MODULE UH = SETTINGS.UH_MODULE def get_resolutions(): return get_screen_resolutions(self._settings.get(FIFE, 'ScreenResolution')) self._options = [ # Graphics/Sound/Input Setting(FIFE, 'ScreenResolution', 'screen_resolution', get_resolutions, restart=True), Setting(FIFE, 'FullScreen', 'enable_fullscreen', restart=True), Setting(FIFE, 'FrameLimit', 'fps_rate', fps, restart=True, callback=self._on_FrameLimit_changed), Setting(UH, 'VolumeMusic', 'volume_music', callback=self._on_VolumeMusic_changed), Setting(UH, 'VolumeEffects', 'volume_effects', callback=self._on_VolumeEffects_changed), Setting(FIFE, 'PlaySounds', 'enable_sound', callback=self._on_PlaySounds_changed), Setting(UH, 'EdgeScrolling', 'edgescrolling'), Setting(UH, 'CursorCenteredZoom', 'cursor_centered_zoom'), Setting(UH, 'MiddleMousePan', 'middle_mouse_pan'), Setting(FIFE, 'MouseSensitivity', 'mousesensitivity', restart=True), # Game Setting(UH, 'AutosaveInterval', 'autosaveinterval'), Setting(UH, 'AutosaveMaxCount', 'autosavemaxcount'), Setting(UH, 'QuicksaveMaxCount', 'quicksavemaxcount'), Setting(UH, 'Language', 'uni_language', language_names, callback=self._on_Language_changed), Setting(UH, 'MinimapRotation', 'minimaprotation'), Setting(UH, 'UninterruptedBuilding', 'uninterrupted_building'), Setting(UH, 'AutoUnload', 'auto_unload'), Setting(UH, 'DebugLog', 'debug_log', callback=self._on_DebugLog_changed), Setting(UH, 'ShowResourceIcons', 'show_resource_icons'), Setting(UH, 'ScrollSpeed', 'scrollspeed'), Setting(UH, 'QuotesType', 'quotestype', QUOTES_SETTINGS), Setting(UH, 'NetworkPort', 'network_port', callback=self._on_NetworkPort_changed), ] self._fill_widgets() # key configuration hk = HotkeyConfiguration() number = self.sections.index(('hotkeys_settings', _('Hotkeys'))) self.page_widgets[number].addChild(hk.widget) self.hotkey_interface = hk
def add_settings(self): def update_minimap(*args): MinimapRotationSettingChanged.broadcast(None) def update_autosave_interval(*args): AutosaveIntervalChanged.broadcast(None) #self.createAndAddEntry(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False) self._setting.createAndAddEntry(UH_MODULE, "AutosaveInterval", "autosaveinterval", applyfunction=update_autosave_interval) self._setting.createAndAddEntry(UH_MODULE, "AutosaveMaxCount", "autosavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "QuicksaveMaxCount", "quicksavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "EdgeScrolling", "edgescrolling") self._setting.createAndAddEntry(UH_MODULE, "CursorCenteredZoom", "cursor_centered_zoom") self._setting.createAndAddEntry(UH_MODULE, "ScrollSpeed", "scrollspeed") self._setting.createAndAddEntry(UH_MODULE, "MiddleMousePan", "middle_mouse_pan") self._setting.createAndAddEntry(UH_MODULE, "UninterruptedBuilding", "uninterrupted_building") self._setting.createAndAddEntry(UH_MODULE, "AutoUnload", "auto_unload") self._setting.createAndAddEntry(UH_MODULE, "MinimapRotation", "minimaprotation", applyfunction=update_minimap) self._setting.createAndAddEntry(UH_MODULE, "QuotesType", "quotestype", initialdata=QUOTES_SETTINGS, applyfunction=self.set_quotestype) self._setting.createAndAddEntry(UH_MODULE, "ShowResourceIcons", "show_resource_icons") self._setting.createAndAddEntry(FIFE_MODULE, "BitsPerPixel", "screen_bpp", initialdata={0: _("Default"), 16: _("16 bit"), 32: _("32 bit")}, requiresrestart=True) languages = find_available_languages().keys() self._setting.createAndAddEntry(UH_MODULE, "Language", "uni_language", applyfunction=self.update_languages, initialdata= [LANGUAGENAMES[x] for x in sorted(languages)]) self._setting.createAndAddEntry(UH_MODULE, "VolumeMusic", "volume_music", applyfunction=self.set_volume_music) self._setting.createAndAddEntry(UH_MODULE, "VolumeEffects", "volume_effects", applyfunction=self.set_volume_effects) self._setting.createAndAddEntry(UH_MODULE, "NetworkPort", "network_port", applyfunction=self.set_network_port) self._setting.createAndAddEntry(UH_MODULE, "DebugLog", "debug_log", applyfunction=self.set_debug_log) self._setting.entries[FIFE_MODULE]['PlaySounds'].applyfunction = lambda x: self.engine.sound.setup_sound() self._setting.entries[FIFE_MODULE]['PlaySounds'].requiresrestart = False self._setting.entries[FIFE_MODULE]['RenderBackend'].applyfunction = lambda x: self._show_renderbackend_warning() self._setting.createAndAddEntry(FIFE_MODULE, "FrameLimit", "fps_rate", initialdata=[30, 45, 60, 90, 120], requiresrestart=True) self._setting.createAndAddEntry(FIFE_MODULE, "MouseSensitivity", "mousesensitivity", #read comment in set_mouse_sensitivity function about this #applyfunction=self.set_mouse_sensitivity, \ requiresrestart=True)
def add_settings(self): # TODO: find a way to apply changing to a running game in a clean fashion # possibility: use signaling via changelistener def update_minimap(*args): try: horizons.main._modules.session.ingame_gui.minimap.draw() except AttributeError: pass # session or gui not yet initialised def update_autosave_interval(*args): try: horizons.main._modules.session.reset_autosave() except AttributeError: pass # session or gui not yet initialised #self.createAndAddEntry(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False) self._setting.createAndAddEntry(UH_MODULE, "AutosaveInterval", "autosaveinterval", applyfunction=update_autosave_interval) self._setting.createAndAddEntry(UH_MODULE, "AutosaveMaxCount", "autosavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "QuicksaveMaxCount", "quicksavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "EdgeScrolling", "edgescrolling") self._setting.createAndAddEntry(UH_MODULE, "CursorCenteredZoom", "cursor_centered_zoom") self._setting.createAndAddEntry(UH_MODULE, "UninterruptedBuilding", "uninterrupted_building") self._setting.createAndAddEntry(UH_MODULE, "AutoUnload", "auto_unload") self._setting.createAndAddEntry(UH_MODULE, "MinimapRotation", "minimaprotation", \ applyfunction=update_minimap) self._setting.createAndAddEntry(FIFE_MODULE, "BitsPerPixel", "screen_bpp", initialdata=[0, 16, 32], requiresrestart=True) languages = find_available_languages().keys() self._setting.createAndAddEntry(UH_MODULE, "Language", "uni_language", applyfunction=self.update_languages, initialdata= [LANGUAGENAMES[x] for x in sorted(languages)]) self._setting.createAndAddEntry(UH_MODULE, "VolumeMusic", "volume_music", applyfunction=self.set_volume_music) self._setting.createAndAddEntry(UH_MODULE, "VolumeEffects", "volume_effects", applyfunction=self.set_volume_effects) self._setting.createAndAddEntry(UH_MODULE, "NetworkPort", "network_port", applyfunction=self.set_network_port) self._setting.createAndAddEntry(UH_MODULE, "DebugLog", "debug_log", applyfunction=self.set_debug_log) self._setting.entries[FIFE_MODULE]['PlaySounds'].applyfunction = lambda x: self.engine.sound.setup_sound() self._setting.entries[FIFE_MODULE]['PlaySounds'].requiresrestart = False self._setting.entries[FIFE_MODULE]['RenderBackend'].applyfunction = lambda x: self._show_renderbackend_warning() self._setting.createAndAddEntry(FIFE_MODULE, "FrameLimit", "fps_rate", initialdata=[30, 45, 60, 90, 120], requiresrestart=True) self._setting.createAndAddEntry(FIFE_MODULE, "MouseSensitivity", "mousesensitivity", \ #read comment in set_mouse_sensitivity function about this #applyfunction=self.set_mouse_sensitivity, \ requiresrestart=True)
def add_settings(self): #self.createAndAddEntry(module, name_in_settings_xml, widgetname, # applyfunction=None, initialdata=None, requiresrestart=False) uh_add = partial(self._setting.createAndAddEntry, UH_MODULE) fife_add = partial(self._setting.createAndAddEntry, FIFE_MODULE) uh_add("AutosaveInterval", "autosaveinterval") uh_add("AutosaveMaxCount", "autosavemaxcount") uh_add("QuicksaveMaxCount", "quicksavemaxcount") uh_add("EdgeScrolling", "edgescrolling") uh_add("CursorCenteredZoom", "cursor_centered_zoom") uh_add("ScrollSpeed", "scrollspeed") uh_add("MiddleMousePan", "middle_mouse_pan") uh_add("UninterruptedBuilding", "uninterrupted_building") uh_add("AutoUnload", "auto_unload") uh_add("MinimapRotation", "minimaprotation") uh_add("QuotesType", "quotestype", initialdata=QUOTES_SETTINGS) uh_add("ShowResourceIcons", "show_resource_icons") bpp = {0: _lazy("Default"), 16: _lazy("16 bit"), 32: _lazy("32 bit")} fife_add("BitsPerPixel", "screen_bpp", initialdata=bpp, requiresrestart=True) languages = find_available_languages().keys() uh_add("Language", "uni_language", applyfunction=self.update_languages, initialdata=[LANGUAGENAMES[x] for x in sorted(languages)]) uh_add("VolumeMusic", "volume_music", applyfunction=self.set_volume_music) uh_add("VolumeEffects", "volume_effects", applyfunction=self.set_volume_effects) uh_add("NetworkPort", "network_port", applyfunction=self.set_network_port) uh_add("DebugLog", "debug_log", applyfunction=self.set_debug_log) play_sounds = self._setting.entries[FIFE_MODULE]['PlaySounds'] play_sounds.applyfunction = lambda x: self.engine.sound.setup_sound() play_sounds.requiresrestart = False # This is set to True in FIFE render_backend = self._setting.entries[FIFE_MODULE]['RenderBackend'] render_backend.applyfunction = lambda x: self._show_renderbackend_warning( ) fps = [30, 45, 60, 90, 120] fife_add("FrameLimit", "fps_rate", initialdata=fps, requiresrestart=True) fife_add("MouseSensitivity", "mousesensitivity", requiresrestart=True)
def __init__(self, windows): Window.__init__(self, windows) PickBeltWidget.__init__(self) self._settings = horizons.globals.fife._setting self.widget.mapEvents( {"okButton": self.apply_settings, "defaultButton": self.set_defaults, "cancelButton": self._windows.close} ) languages = find_available_languages().keys() language_names = [LANGUAGENAMES[x] for x in sorted(languages)] fps = {0: _lazy("Disabled"), 30: 30, 45: 45, 60: 60, 90: 90, 120: 120} FIFE = SETTINGS.FIFE_MODULE UH = SETTINGS.UH_MODULE def get_resolutions(): return get_screen_resolutions(self._settings.get(FIFE, "ScreenResolution")) self._options = [ # Graphics/Sound/Input Setting(FIFE, "ScreenResolution", "screen_resolution", get_resolutions, restart=True), Setting(FIFE, "FullScreen", "enable_fullscreen", restart=True), Setting(FIFE, "FrameLimit", "fps_rate", fps, restart=True, callback=self._on_FrameLimit_changed), Setting(UH, "VolumeMusic", "volume_music", callback=self._on_VolumeMusic_changed), Setting(UH, "VolumeEffects", "volume_effects", callback=self._on_VolumeEffects_changed), Setting(FIFE, "PlaySounds", "enable_sound", callback=self._on_PlaySounds_changed), Setting(UH, "EdgeScrolling", "edgescrolling"), Setting(UH, "CursorCenteredZoom", "cursor_centered_zoom"), Setting(UH, "MiddleMousePan", "middle_mouse_pan"), Setting(FIFE, "MouseSensitivity", "mousesensitivity", restart=True), # Game Setting(UH, "AutosaveInterval", "autosaveinterval"), Setting(UH, "AutosaveMaxCount", "autosavemaxcount"), Setting(UH, "QuicksaveMaxCount", "quicksavemaxcount"), Setting(UH, "Language", "uni_language", language_names, callback=self._on_Language_changed), Setting(UH, "MinimapRotation", "minimaprotation"), Setting(UH, "UninterruptedBuilding", "uninterrupted_building"), Setting(UH, "AutoUnload", "auto_unload"), Setting(UH, "DebugLog", "debug_log", callback=self._on_DebugLog_changed), Setting(UH, "ShowResourceIcons", "show_resource_icons"), Setting(UH, "ScrollSpeed", "scrollspeed"), Setting(UH, "QuotesType", "quotestype", QUOTES_SETTINGS), Setting(UH, "NetworkPort", "network_port", callback=self._on_NetworkPort_changed), ] self._fill_widgets() # key configuration hk = HotkeyConfiguration() number = self.sections.index(("hotkeys_settings", _("Hotkeys"))) self.page_widgets[number].addChild(hk.widget) self.hotkey_interface = hk
def _init_settings(self): """Init the settings with the stored values.""" languages = list(find_available_languages().keys()) language_names = [LANGUAGENAMES[x] for x in sorted(languages)] fps = {0: LazyT("Disabled"), 30: 30, 45: 45, 60: 60, 90: 90, 120: 120} FIFE = SETTINGS.FIFE_MODULE UH = SETTINGS.UH_MODULE def get_resolutions(): return get_screen_resolutions(self._settings.get(FIFE, 'ScreenResolution')) self._options = [ # Graphics/Sound/Input Setting(FIFE, 'ScreenResolution', 'screen_resolution', get_resolutions, restart=True), Setting(FIFE, 'FullScreen', 'enable_fullscreen', restart=True), Setting(FIFE, 'FrameLimit', 'fps_rate', fps, restart=True, callback=self._apply_FrameLimit), Setting(UH, 'VolumeMusic', 'volume_music', callback=self._apply_VolumeMusic, on_change=self._on_slider_changed), Setting(UH, 'VolumeEffects', 'volume_effects', callback=self._apply_VolumeEffects, on_change=self._on_slider_changed), Setting(FIFE, 'PlaySounds', 'enable_sound', callback=self._apply_PlaySounds), Setting(UH, 'EdgeScrolling', 'edgescrolling'), Setting(UH, 'CursorCenteredZoom', 'cursor_centered_zoom'), Setting(UH, 'MiddleMousePan', 'middle_mouse_pan'), Setting(FIFE, 'MouseSensitivity', 'mousesensitivity', restart=True, on_change=self._on_slider_changed), # Game Setting(UH, 'AutosaveInterval', 'autosaveinterval', on_change=self._on_slider_changed), Setting(UH, 'AutosaveMaxCount', 'autosavemaxcount', on_change=self._on_slider_changed), Setting(UH, 'QuicksaveMaxCount', 'quicksavemaxcount', on_change=self._on_slider_changed), Setting(UH, 'Language', 'uni_language', language_names, callback=self._apply_Language, on_change=self._on_Language_changed), Setting(UH, 'MinimapRotation', 'minimaprotation'), Setting(UH, 'UninterruptedBuilding', 'uninterrupted_building'), Setting(UH, 'AutoUnload', 'auto_unload'), Setting(UH, 'DebugLog', 'debug_log', callback=self._apply_DebugLog), Setting(UH, 'ShowResourceIcons', 'show_resource_icons'), Setting(UH, 'ScrollSpeed', 'scrollspeed', on_change=self._on_slider_changed), Setting(UH, 'QuotesType', 'quotestype', QUOTES_SETTINGS), Setting(UH, 'NetworkPort', 'network_port', callback=self._apply_NetworkPort), ] self._fill_widgets() # key configuration self.hotkey_interface = HotkeyConfiguration() number = self.sections.index(('hotkeys_settings', T('Hotkeys'))) self.page_widgets[number].removeAllChildren() self.page_widgets[number].addChild(self.hotkey_interface.widget)
def setup_i18n(self): """ Load available translations for server messages. """ domain = 'unknown-horizons-server' for lang, dir in find_available_languages(domain).items(): if len(dir) <= 0: continue try: self.i18n[lang] = gettext.translation(domain, dir, [lang]) except IOError: pass
def _init_settings(self): """Init the settings with the stored values.""" languages = list(find_available_languages().keys()) language_names = [LANGUAGENAMES[x] for x in sorted(languages)] fps = {0: LazyT("Disabled"), 30: 30, 45: 45, 60: 60, 90: 90, 120: 120} FIFE = SETTINGS.FIFE_MODULE UH = SETTINGS.UH_MODULE def get_resolutions(): return get_screen_resolutions(self._settings.get(FIFE, 'ScreenResolution')) self._options = [ # Graphics/Sound/Input Setting(FIFE, 'ScreenResolution', 'screen_resolution', get_resolutions, restart=True), Setting(FIFE, 'FullScreen', 'enable_fullscreen', restart=True), Setting(FIFE, 'FrameLimit', 'fps_rate', fps, restart=True, callback=self._apply_FrameLimit), Setting(UH, 'VolumeMusic', 'volume_music', callback=self._apply_VolumeMusic, on_change=self._on_slider_changed), Setting(UH, 'VolumeEffects', 'volume_effects', callback=self._apply_VolumeEffects, on_change=self._on_slider_changed), Setting(FIFE, 'PlaySounds', 'enable_sound', callback=self._apply_PlaySounds), Setting(UH, 'EdgeScrolling', 'edgescrolling'), Setting(UH, 'CursorCenteredZoom', 'cursor_centered_zoom'), Setting(UH, 'MiddleMousePan', 'middle_mouse_pan'), Setting(FIFE, 'MouseSensitivity', 'mousesensitivity', restart=True, on_change=self._on_slider_changed), # Game Setting(UH, 'AutosaveInterval', 'autosaveinterval', on_change=self._on_slider_changed), Setting(UH, 'AutosaveMaxCount', 'autosavemaxcount', on_change=self._on_slider_changed), Setting(UH, 'QuicksaveMaxCount', 'quicksavemaxcount', on_change=self._on_slider_changed), Setting(UH, 'Language', 'uni_language', language_names, callback=self._apply_Language, on_change=self._on_Language_changed), Setting(UH, 'UninterruptedBuilding', 'uninterrupted_building'), Setting(UH, 'AutoUnload', 'auto_unload'), Setting(UH, 'DebugLog', 'debug_log', callback=self._apply_DebugLog), Setting(UH, 'ShowResourceIcons', 'show_resource_icons'), Setting(UH, 'ScrollSpeed', 'scrollspeed', on_change=self._on_slider_changed), Setting(UH, 'QuotesType', 'quotestype', QUOTES_SETTINGS), Setting(UH, 'NetworkPort', 'network_port', callback=self._apply_NetworkPort), ] self._fill_widgets() # key configuration self.hotkey_interface = HotkeyConfiguration() number = self.sections.index(('hotkeys_settings', T('Hotkeys'))) self.page_widgets[number].removeAllChildren() self.page_widgets[number].addChild(self.hotkey_interface.widget)
def setup_i18n(self): domain = 'unknown-horizons-server' for lang, dir in find_available_languages(domain).items(): if len(dir) <= 0: continue try: self.i18n[lang] = gettext.translation(domain, dir, [lang]) except IOError: pass import __builtin__ __builtin__.__dict__['S_'] = self.gettext __builtin__.__dict__['SN_'] = self.ngettext __builtin__.__dict__['__'] = lambda x : x
def get_available_scenarios(cls, include_displaynames=True, locales=False, hide_test_scenarios=False): """Returns available scenarios.""" afiles = [] anames = [] sfiles, snames = cls.get_scenarios(include_displaynames=True) for i, sname in enumerate(snames): if hide_test_scenarios and cls.get_scenario_info( name=sname).get('test_scenario'): continue #get file's locale cur_locale = '_' + cls.get_scenario_info(name=sname).get('locale') #if the locale is nodefault then don't add it #we use this locale in test scenarios and they are not included to the list if cur_locale == "_nodefault": continue #don't add language postfix sname = sname.split(cur_locale)[0] if not sname in anames: anames.append(sname) afiles.append(sfiles[i][:sfiles[i].rfind(cur_locale)]) def _list_maps_with_language(prefixlist, language): maplist = [] for (listitem, language) in itertools.product(prefixlist, languages): maplist.append(listitem + '_' + language + '.' + SavegameManager.scenario_extension) return maplist #we use scenario map name + language extension languages = find_available_languages().keys() #we use full map paths (with language extensions) scenario_map_paths = _list_maps_with_language(afiles, languages) #we use full map names (with language extensions) scenario_map_names = _list_maps_with_language(anames, languages) #if needed we should return with language extensions if locales: afiles = scenario_map_paths anames = scenario_map_names if not include_displaynames: return (afiles, ) return (afiles, anames)
def get_available_scenarios(cls, include_displaynames=True, locales=False, hide_test_scenarios=False): """Returns available scenarios.""" afiles = [] anames = [] sfiles, snames = cls.get_scenarios(include_displaynames = True) for i, sname in enumerate(snames): if hide_test_scenarios and cls.get_scenario_info(name=sname).get('test_scenario'): continue #get file's locale cur_locale = '_' + cls.get_scenario_info(name=sname).get('locale') #if the locale is nodefault then don't add it #we use this locale in test scenarios and they are not included to the list if cur_locale == "_nodefault": continue #don't add language postfix sname = sname.split(cur_locale)[0] if not sname in anames: anames.append(sname) afiles.append(sfiles[i][:sfiles[i].rfind(cur_locale)]) def _list_maps_with_language(prefixlist, language): maplist = [] for (listitem, language) in itertools.product(prefixlist, languages): maplist.append(listitem + '_' + language + '.' + SavegameManager.scenario_extension) return maplist #we use scenario map name + language extension languages = find_available_languages().keys() #we use full map paths (with language extensions) scenario_map_paths = _list_maps_with_language(afiles, languages) #we use full map names (with language extensions) scenario_map_names = _list_maps_with_language(anames, languages) #if needed we should return with language extensions if locales: afiles = scenario_map_paths anames = scenario_map_names if not include_displaynames: return (afiles,) return (afiles, anames)
def add_settings(self): #self.createAndAddEntry(module, name_in_settings_xml, widgetname, # applyfunction=None, initialdata=None, requiresrestart=False) uh_add = partial(self._setting.createAndAddEntry, UH_MODULE) fife_add = partial(self._setting.createAndAddEntry, FIFE_MODULE) uh_add("AutosaveInterval", "autosaveinterval") uh_add("AutosaveMaxCount", "autosavemaxcount") uh_add("QuicksaveMaxCount", "quicksavemaxcount") uh_add("EdgeScrolling", "edgescrolling") uh_add("CursorCenteredZoom", "cursor_centered_zoom") uh_add("ScrollSpeed", "scrollspeed") uh_add("MiddleMousePan", "middle_mouse_pan") uh_add("UninterruptedBuilding", "uninterrupted_building") uh_add("AutoUnload", "auto_unload") uh_add("MinimapRotation", "minimaprotation") uh_add("QuotesType", "quotestype", initialdata=QUOTES_SETTINGS) uh_add("ShowResourceIcons", "show_resource_icons") bpp = {0: _lazy("Default"), 16: _lazy("16 bit"), 32: _lazy("32 bit")} fife_add("BitsPerPixel", "screen_bpp", initialdata=bpp, requiresrestart=True) languages = find_available_languages().keys() uh_add("Language", "uni_language", applyfunction=self.update_languages, initialdata=[LANGUAGENAMES[x] for x in sorted(languages)]) uh_add("VolumeMusic", "volume_music", applyfunction=self.set_volume_music) uh_add("VolumeEffects", "volume_effects", applyfunction=self.set_volume_effects) uh_add("NetworkPort", "network_port", applyfunction=self.set_network_port) uh_add("DebugLog", "debug_log", applyfunction=self.set_debug_log) play_sounds = self._setting.entries[FIFE_MODULE]['PlaySounds'] play_sounds.applyfunction = lambda x: self.engine.sound.setup_sound() play_sounds.requiresrestart = False # This is set to True in FIFE render_backend = self._setting.entries[FIFE_MODULE]['RenderBackend'] render_backend.applyfunction = lambda x: self._show_renderbackend_warning() fps = [30, 45, 60, 90, 120] fife_add("FrameLimit", "fps_rate", initialdata=fps, requiresrestart=True) fife_add("MouseSensitivity", "mousesensitivity", requiresrestart=True)
def _get_available_languages(self, mapfile=None): return sorted([ LANGUAGENAMES[lang] for lang in find_available_languages() if os.path.exists(self._find_map_filename(lang, mapfile)) ])
def _get_available_languages(self, mapfile=None): return sorted( [LANGUAGENAMES[lang] for lang in find_available_languages() if os.path.exists(self._find_map_filename(lang, mapfile))])
def add_settings(self): # TODO: find a way to apply changing to a running game in a clean fashion # possibility: use signaling via changelistener def update_minimap(*args): try: horizons.main._modules.session.ingame_gui.minimap.draw() except AttributeError: pass # session or gui not yet initialised def update_autosave_interval(*args): try: horizons.main._modules.session.reset_autosave() except AttributeError: pass # session or gui not yet initialised #self.createAndAddEntry(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False) self._setting.createAndAddEntry(UH_MODULE, "AutosaveInterval", "autosaveinterval", applyfunction=update_autosave_interval) self._setting.createAndAddEntry(UH_MODULE, "AutosaveMaxCount", "autosavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "QuicksaveMaxCount", "quicksavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "EdgeScrolling", "edgescrolling") self._setting.createAndAddEntry(UH_MODULE, "CursorCenteredZoom", "cursor_centered_zoom") self._setting.createAndAddEntry(UH_MODULE, "UninterruptedBuilding", "uninterrupted_building") self._setting.createAndAddEntry(UH_MODULE, "AutoUnload", "auto_unload") self._setting.createAndAddEntry(UH_MODULE, "MinimapRotation", "minimaprotation", applyfunction=update_minimap) self._setting.createAndAddEntry(UH_MODULE, "QuotesType", "quotestype", initialdata=QUOTES_SETTINGS, applyfunction=self.set_quotestype) self._setting.createAndAddEntry(UH_MODULE, "ShowResourceIcons", "show_resource_icons") self._setting.createAndAddEntry(FIFE_MODULE, "BitsPerPixel", "screen_bpp", initialdata={ 0: _("Default"), 16: _("16 bit"), 32: _("32 bit") }, requiresrestart=True) languages = find_available_languages().keys() self._setting.createAndAddEntry( UH_MODULE, "Language", "uni_language", applyfunction=self.update_languages, initialdata=[LANGUAGENAMES[x] for x in sorted(languages)]) self._setting.createAndAddEntry(UH_MODULE, "VolumeMusic", "volume_music", applyfunction=self.set_volume_music) self._setting.createAndAddEntry(UH_MODULE, "VolumeEffects", "volume_effects", applyfunction=self.set_volume_effects) self._setting.createAndAddEntry(UH_MODULE, "NetworkPort", "network_port", applyfunction=self.set_network_port) self._setting.createAndAddEntry(UH_MODULE, "DebugLog", "debug_log", applyfunction=self.set_debug_log) self._setting.entries[FIFE_MODULE][ 'PlaySounds'].applyfunction = lambda x: self.engine.sound.setup_sound( ) self._setting.entries[FIFE_MODULE][ 'PlaySounds'].requiresrestart = False self._setting.entries[FIFE_MODULE][ 'RenderBackend'].applyfunction = lambda x: self._show_renderbackend_warning( ) self._setting.createAndAddEntry(FIFE_MODULE, "FrameLimit", "fps_rate", initialdata=[30, 45, 60, 90, 120], requiresrestart=True) self._setting.createAndAddEntry( FIFE_MODULE, "MouseSensitivity", "mousesensitivity", #read comment in set_mouse_sensitivity function about this #applyfunction=self.set_mouse_sensitivity, \ requiresrestart=True)
def add_settings(self): def update_minimap(*args): MinimapRotationSettingChanged.broadcast(None) def update_autosave_interval(*args): AutosaveIntervalChanged.broadcast(None) #self.createAndAddEntry(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False) self._setting.createAndAddEntry(UH_MODULE, "AutosaveInterval", "autosaveinterval", applyfunction=update_autosave_interval) self._setting.createAndAddEntry(UH_MODULE, "AutosaveMaxCount", "autosavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "QuicksaveMaxCount", "quicksavemaxcount") self._setting.createAndAddEntry(UH_MODULE, "EdgeScrolling", "edgescrolling") self._setting.createAndAddEntry(UH_MODULE, "CursorCenteredZoom", "cursor_centered_zoom") self._setting.createAndAddEntry(UH_MODULE, "ScrollSpeed", "scrollspeed") self._setting.createAndAddEntry(UH_MODULE, "MiddleMousePan", "middle_mouse_pan") self._setting.createAndAddEntry(UH_MODULE, "UninterruptedBuilding", "uninterrupted_building") self._setting.createAndAddEntry(UH_MODULE, "AutoUnload", "auto_unload") self._setting.createAndAddEntry(UH_MODULE, "MinimapRotation", "minimaprotation", applyfunction=update_minimap) self._setting.createAndAddEntry(UH_MODULE, "QuotesType", "quotestype", initialdata=QUOTES_SETTINGS, applyfunction=self.set_quotestype) self._setting.createAndAddEntry(UH_MODULE, "ShowResourceIcons", "show_resource_icons") self._setting.createAndAddEntry(FIFE_MODULE, "BitsPerPixel", "screen_bpp", initialdata={ 0: _("Default"), 16: _("16 bit"), 32: _("32 bit") }, requiresrestart=True) languages = find_available_languages().keys() self._setting.createAndAddEntry( UH_MODULE, "Language", "uni_language", applyfunction=self.update_languages, initialdata=[LANGUAGENAMES[x] for x in sorted(languages)]) self._setting.createAndAddEntry(UH_MODULE, "VolumeMusic", "volume_music", applyfunction=self.set_volume_music) self._setting.createAndAddEntry(UH_MODULE, "VolumeEffects", "volume_effects", applyfunction=self.set_volume_effects) self._setting.createAndAddEntry(UH_MODULE, "NetworkPort", "network_port", applyfunction=self.set_network_port) self._setting.createAndAddEntry(UH_MODULE, "DebugLog", "debug_log", applyfunction=self.set_debug_log) self._setting.entries[FIFE_MODULE][ 'PlaySounds'].applyfunction = lambda x: self.engine.sound.setup_sound( ) self._setting.entries[FIFE_MODULE][ 'PlaySounds'].requiresrestart = False self._setting.entries[FIFE_MODULE][ 'RenderBackend'].applyfunction = lambda x: self._show_renderbackend_warning( ) self._setting.createAndAddEntry(FIFE_MODULE, "FrameLimit", "fps_rate", initialdata=[30, 45, 60, 90, 120], requiresrestart=True) self._setting.createAndAddEntry( FIFE_MODULE, "MouseSensitivity", "mousesensitivity", #read comment in set_mouse_sensitivity function about this #applyfunction=self.set_mouse_sensitivity, \ requiresrestart=True)
def _update_infos(): """Fill in infos of selected scenario to label""" def _find_map_filename(locale = None): """Finds the selected map's filename with its locale.""" this_locale = "" new_map_name = "" if locale is None: this_locale = LANGUAGENAMES.get_by_value(lang_list.selected_item) else: this_locale = locale #check if selected map's file ends with .yaml if self._get_selected_map().find('.yaml') == -1: new_map_name = self._get_selected_map() + '_' + \ this_locale + '.' + \ SavegameManager.scenario_extension #if selected map's file ends with .yaml then get current locale #to remove locale postfix from selected_map's name else: #get current locale to split current map file name current_locale = yamlcache.YamlCache.get_file(self._get_selected_map(), \ game_data=True)['locale'] new_map_name = self._get_selected_map()[:self._get_selected_map().\ find('_' + current_locale)] + '_' + \ this_locale + '.' + \ SavegameManager.scenario_extension return new_map_name cur_selected_language = lang_list.selected_item selectable_languages = [] #show only selectable languages for i in find_available_languages().keys(): if os.path.exists(_find_map_filename(i)): selectable_languages.append(LANGUAGENAMES[i]) selectable_languages.sort() lang_list.items = selectable_languages if cur_selected_language in lang_list.items: lang_list.selected = lang_list.items.index(cur_selected_language) else: lang_list.selected = 0 def _update_translation_infos(new_map_name): """Fill in translation infos of selected scenario to translation label. It gets translation_status from new_map_file. If there is no attribute like translation_status then selected locale is the original locale of the selected scenario. In this case, hide translation_status_label. If there are fuzzy translations, show them as untranslated. This function also sets scenario map name using locale. (e.g. tutorial -> tutorial_en.yaml)""" translation_status_label = self.current.findChild(name="translation_status") try: #get translation status translation_status_message = yamlcache.YamlCache.get_file(new_map_name, \ game_data=True)['translation_status'] #find integers in translation_levels string translation_levels = [int(x) for x in re.findall(r'\d+', translation_status_message)] #if translation_levels' len is 3 it shows us there are fuzzy ones #show them as untranslated if len(translation_levels) == 3: translation_levels[2] += translation_levels[1] #if everything is translated then set untranslated count as 0 if len(translation_levels) == 1: translation_levels.append(0) translation_status_label.text = _("Translation status:") + '\n' + \ _("{translated} translated messages, {untranslated} untranslated messages")\ .format(translated=translation_levels[0], \ untranslated=translation_levels[-1]) #if selected language is english then don't show translation status translation_status_label.show() #if there is no translation_status then hide it except KeyError: translation_status_label.hide() self.current.files[ self.active_right_side.collectData('maplist') ] = new_map_name #Add locale postfix to fix scenario file try: _update_translation_infos(_find_map_filename()) #if there is no scenario with selected locale then select system's default except IOError: default_locale = "" _default_locale, default_encoding = locale.getdefaultlocale() try: default_locale = _default_locale.split('_')[0] except: # If default locale could not be detected use 'EN' as fallback default_locale = "en" #check if default_locale is in list if LANGUAGENAMES[default_locale] in lang_list.items: lang_list.selected = lang_list.items.index(LANGUAGENAMES[default_locale]) #if default locale is not in list then select first one else: lang_list.selected = 0 _update_infos() try: difficulty = ScenarioEventHandler.get_difficulty_from_file( self._get_selected_map() ) desc = ScenarioEventHandler.get_description_from_file( self._get_selected_map() ) author = ScenarioEventHandler.get_author_from_file( self._get_selected_map() ) except InvalidScenarioFileFormat as e: self._show_invalid_scenario_file_popup(e) return self.current.findChild(name="uni_map_difficulty").text = \ _("Difficulty: {difficulty}").format(difficulty=difficulty) #xgettext:python-format self.current.findChild(name="uni_map_author").text = \ _("Author: {author}").format(author=author) #xgettext:python-format self.current.findChild(name="uni_map_desc").text = \ _("Description: {desc}").format(desc=desc) #xgettext:python-format
def _select_single(self, show): assert show in ('random', 'scenario', 'campaign', 'free_maps') self.hide() event_map = { 'cancel' : Callback.ChainedCallbacks(self._save_player_name, self.show_main), 'okay' : self.start_single, 'scenario' : Callback(self._select_single, show='scenario'), 'campaign' : Callback(self._select_single, show='campaign'), 'random' : Callback(self._select_single, show='random'), 'free_maps' : Callback(self._select_single, show='free_maps') } # init gui for subcategory del event_map[show] right_side = self.widgets['sp_%s' % show] show_ai_options = False self.current.findChild(name=show).marked = True self.current.aidata.hide() # hide previous widget, unhide new right side widget if self.active_right_side is not None: self.active_right_side.parent.hideChild(self.active_right_side) right_side.parent.showChild(right_side) self.active_right_side = right_side self._current_mode = show if show == 'random': show_ai_options = True self._setup_random_map_selection(right_side) self._setup_game_settings_selection() self._on_random_map_parameter_changed() self.active_right_side.findChild(name="open_random_map_archive").capture(self._open_random_map_archive) elif show == 'free_maps': self.current.files, maps_display = SavegameManager.get_maps() self.active_right_side.distributeInitialData({ 'maplist' : maps_display, }) def _update_infos(): number_of_players = SavegameManager.get_recommended_number_of_players( self._get_selected_map() ) #xgettext:python-format self.current.findChild(name="recommended_number_of_players_lbl").text = \ _("Recommended number of players: {number}").format(number=number_of_players) self.map_preview.update_map(self._get_selected_map()) if len(maps_display) > 0: # select first entry self.active_right_side.distributeData({ 'maplist' : 0, }) _update_infos() # update preview whenever something is selected in the list self.active_right_side.findChild(name="maplist").mapEvents({ 'maplist/action' : _update_infos }) self.active_right_side.findChild(name="maplist").capture(_update_infos, event_name="keyPressed") show_ai_options = True self._setup_game_settings_selection() else: choosable_locales = ['en', horizons.main.fife.get_locale()] if show == 'campaign': self.current.files, maps_display = SavegameManager.get_campaigns() # tell people that we don't have any content text = u"We currently don't have any campaigns available for you. " + \ u"If you are interested in adding campaigns to Unknown Horizons, " + \ u"please contact us via our website (http://www.unknown-horizons.org)!" self.show_popup("No campaigns available yet", text) elif show == 'scenario': self.current.files, maps_display = SavegameManager.get_available_scenarios() # get the map files and their display names. display tutorials on top. prefer_tutorial = lambda x : ('tutorial' not in x, x) maps_display.sort(key=prefer_tutorial) self.current.files.sort(key=prefer_tutorial) #add all locales to lang list, select current locale as default and sort lang_list = self.current.findChild(name="uni_langlist") self.active_right_side.distributeInitialData({ 'maplist' : maps_display, }) # select first entry self.active_right_side.distributeData({ 'maplist' : 0, }) selectable_languages = [] #show only selectable languages for i in find_available_languages().keys(): if os.path.exists(self._get_selected_map() + '_' + i + '.' + SavegameManager.scenario_extension): selectable_languages.append(LANGUAGENAMES[i]) selectable_languages.sort() lang_list.items = selectable_languages cur_locale = horizons.main.fife.get_locale() if LANGUAGENAMES[cur_locale] in lang_list.items: lang_list.selected = lang_list.items.index(LANGUAGENAMES[cur_locale]) else: lang_list.selected = 0 self.active_right_side.distributeInitialData({ 'maplist' : maps_display, }) if len(maps_display) > 0: # select first entry self.active_right_side.distributeData({ 'maplist' : 0, }) if show == 'scenario': # update infos for scenario from horizons.scenario import ScenarioEventHandler, InvalidScenarioFileFormat def _update_infos(): """Fill in infos of selected scenario to label""" def _find_map_filename(locale = None): """Finds the selected map's filename with its locale.""" this_locale = "" new_map_name = "" if locale is None: this_locale = LANGUAGENAMES.get_by_value(lang_list.selected_item) else: this_locale = locale #check if selected map's file ends with .yaml if self._get_selected_map().find('.yaml') == -1: new_map_name = self._get_selected_map() + '_' + \ this_locale + '.' + \ SavegameManager.scenario_extension #if selected map's file ends with .yaml then get current locale #to remove locale postfix from selected_map's name else: #get current locale to split current map file name current_locale = yamlcache.YamlCache.get_file(self._get_selected_map(), \ game_data=True)['locale'] new_map_name = self._get_selected_map()[:self._get_selected_map().\ find('_' + current_locale)] + '_' + \ this_locale + '.' + \ SavegameManager.scenario_extension return new_map_name cur_selected_language = lang_list.selected_item selectable_languages = [] #show only selectable languages for i in find_available_languages().keys(): if os.path.exists(_find_map_filename(i)): selectable_languages.append(LANGUAGENAMES[i]) selectable_languages.sort() lang_list.items = selectable_languages if cur_selected_language in lang_list.items: lang_list.selected = lang_list.items.index(cur_selected_language) else: lang_list.selected = 0 def _update_translation_infos(new_map_name): """Fill in translation infos of selected scenario to translation label. It gets translation_status from new_map_file. If there is no attribute like translation_status then selected locale is the original locale of the selected scenario. In this case, hide translation_status_label. If there are fuzzy translations, show them as untranslated. This function also sets scenario map name using locale. (e.g. tutorial -> tutorial_en.yaml)""" translation_status_label = self.current.findChild(name="translation_status") try: #get translation status translation_status_message = yamlcache.YamlCache.get_file(new_map_name, \ game_data=True)['translation_status'] #find integers in translation_levels string translation_levels = [int(x) for x in re.findall(r'\d+', translation_status_message)] #if translation_levels' len is 3 it shows us there are fuzzy ones #show them as untranslated if len(translation_levels) == 3: translation_levels[2] += translation_levels[1] #if everything is translated then set untranslated count as 0 if len(translation_levels) == 1: translation_levels.append(0) translation_status_label.text = _("Translation status:") + '\n' + \ _("{translated} translated messages, {untranslated} untranslated messages")\ .format(translated=translation_levels[0], \ untranslated=translation_levels[-1]) #if selected language is english then don't show translation status translation_status_label.show() #if there is no translation_status then hide it except KeyError: translation_status_label.hide() self.current.files[ self.active_right_side.collectData('maplist') ] = new_map_name #Add locale postfix to fix scenario file try: _update_translation_infos(_find_map_filename()) #if there is no scenario with selected locale then select system's default except IOError: default_locale = "" _default_locale, default_encoding = locale.getdefaultlocale() try: default_locale = _default_locale.split('_')[0] except: # If default locale could not be detected use 'EN' as fallback default_locale = "en" #check if default_locale is in list if LANGUAGENAMES[default_locale] in lang_list.items: lang_list.selected = lang_list.items.index(LANGUAGENAMES[default_locale]) #if default locale is not in list then select first one else: lang_list.selected = 0 _update_infos() try: difficulty = ScenarioEventHandler.get_difficulty_from_file( self._get_selected_map() ) desc = ScenarioEventHandler.get_description_from_file( self._get_selected_map() ) author = ScenarioEventHandler.get_author_from_file( self._get_selected_map() ) except InvalidScenarioFileFormat as e: self._show_invalid_scenario_file_popup(e) return self.current.findChild(name="uni_map_difficulty").text = \ _("Difficulty: {difficulty}").format(difficulty=difficulty) #xgettext:python-format self.current.findChild(name="uni_map_author").text = \ _("Author: {author}").format(author=author) #xgettext:python-format self.current.findChild(name="uni_map_desc").text = \ _("Description: {desc}").format(desc=desc) #xgettext:python-format self.active_right_side.findChild(name="uni_langlist").mapEvents({ 'uni_langlist/action': _update_infos }) self.active_right_side.findChild(name="uni_langlist").capture(_update_infos, event_name="keyPressed") _update_infos() #hide and show current window to keep bugs away from us #if we don't do this, translation_label doesn't hide even if #selected language is english or doesn't show if selected #language has translation_status attribute self.current.hide() self.current.show() elif show == 'campaign': # update infos for campaign def _update_infos(): """Fill in infos of selected campaign to label""" campaign_info = SavegameManager.get_campaign_info(filename = self._get_selected_map()) if not campaign_info: self._show_invalid_scenario_file_popup("Unknown error") return self.current.findChild(name="map_difficulty").text = \ _("Difficulty: {difficulty}").format(difficulty=campaign_info.get('difficulty', '')) #xgettext:python-format self.current.findChild(name="map_author").text = \ _("Author: {author}").format(author=campaign_info.get('author', '')) #xgettext:python-format self.current.findChild(name="map_desc").text = \ _("Description: {desc}").format(desc=campaign_info.get('description', '')) #xgettext:python-format self.active_right_side.findChild(name="maplist").mapEvents({ 'maplist/action': _update_infos }) self.active_right_side.findChild(name="maplist").capture(_update_infos, event_name="keyPressed") _update_infos() self.current.mapEvents(event_map) if show_ai_options: self.current.aidata.show() self.current.show() self.on_escape = self.show_main