class SettingsWindow(SettingsWindowMeta):
    settingsCore = dependency.descriptor(ISettingsCore)
    lobbyContext = dependency.descriptor(ILobbyContext)

    def __init__(self, ctx=None):
        super(SettingsWindow, self).__init__()
        self.__redefinedKeyModeEnabled = ctx.get('redefinedKeyMode', True)
        self.__isBattleSettings = ctx.get('isBattleSettings', False)
        if 'tabIndex' in ctx and ctx['tabIndex'] is not None:
            _setLastTabIndex(ctx['tabIndex'])
        self.params = SettingsParams()
        return

    @proto_getter(PROTO_TYPE.BW_CHAT2)
    def bwProto(self):
        return None

    def __getSettingsParam(self):
        settings = {SETTINGS_GROUP.GAME_SETTINGS: self.params.getGameSettings(),
         SETTINGS_GROUP.GRAPHICS_SETTINGS: self.params.getGraphicsSettings(),
         SETTINGS_GROUP.SOUND_SETTINGS: self.params.getSoundSettings(),
         SETTINGS_GROUP.CONTROLS_SETTINGS: self.params.getControlsSettings(),
         SETTINGS_GROUP.AIM_SETTINGS: self.params.getAimSettings(),
         SETTINGS_GROUP.MARKERS_SETTINGS: self.params.getMarkersSettings(),
         SETTINGS_GROUP.OTHER_SETTINGS: self.params.getOtherSettings(),
         SETTINGS_GROUP.FEEDBACK_SETTINGS: self.params.getFeedbackSettings()}
        return settings

    def __getSettings(self):
        settings = self.__getSettingsParam()
        reformatted_settings = {}
        for key, value in settings.iteritems():
            reformatted_keys = []
            reformatted_values = []
            reformatted_settings[key] = {'keys': reformatted_keys,
             'values': reformatted_values}
            for settingName, settingValue in value.iteritems():
                reformatted_keys.append(settingName)
                reformatted_values.append(settingValue)

        return reformatted_settings

    def __commitSettings(self, settings=None, restartApproved=False, isCloseWnd=False):
        if settings is None:
            settings = {}
        self.__apply(settings, restartApproved, isCloseWnd)
        return

    def __apply(self, settings, restartApproved=False, isCloseWnd=False):
        LOG_DEBUG('Settings window: apply settings', restartApproved, settings)
        self.settingsCore.isDeviseRecreated = False
        self.settingsCore.isChangesConfirmed = True
        isRestart = self.params.apply(settings, restartApproved)
        if settings_constants.GRAPHICS.INTERFACE_SCALE in settings:
            self.__updateInterfaceScale()
        isPresetApplied = self.__isGraphicsPresetApplied(settings)
        if self.settingsCore.isChangesConfirmed and isCloseWnd:
            self.onWindowClose()
        if isRestart:
            BigWorld.savePreferences()
            if restartApproved:
                _delayCall(0.3, self.__restartGame)
            elif self.settingsCore.isDeviseRecreated:
                self.onRecreateDevice()
                self.settingsCore.isDeviseRecreated = False
            else:
                _delayCall(0.0, functools.partial(BigWorld.changeVideoMode, -1, BigWorld.getWindowMode()))
        elif not isPresetApplied:
            DialogsInterface.showI18nInfoDialog('graphicsPresetNotInstalled', None)
        return

    def __restartGame(self):
        BigWorld.savePreferences()
        BigWorld.worldDrawEnabled(False)
        BigWorld.restartGame()

    def _populate(self):
        super(SettingsWindow, self)._populate()
        dataVO = [{'label': SETTINGS.FEEDBACK_TAB_DAMAGEINDICATOR,
          'linkage': VIEW_ALIAS.FEEDBACK_DAMAGE_INDICATOR},
         {'label': SETTINGS.FEEDBACK_TAB_EVENTSINFO,
          'linkage': VIEW_ALIAS.FEEDBACK_BATTLE_EVENTS},
         {'label': SETTINGS.FEEDBACK_TAB_DAMAGELOGPANEL,
          'linkage': VIEW_ALIAS.FEEDBACK_DAMAGE_LOG},
         {'label': SETTINGS.FEEDBACK_TAB_BATTLEBORDERMAP,
          'linkage': VIEW_ALIAS.FEEDBACK_BATTLE_BORDER_MAP}]
        if self.lobbyContext.getServerSettings().isPMBattleProgressEnabled():
            dataVO.append({'label': SETTINGS.FEEDBACK_TAB_QUESTSPROGRESS,
             'linkage': VIEW_ALIAS.FEEDBACK_QUESTS_PROGRESS})
        self.as_setFeedbackDataProviderS(dataVO)
        if self.__redefinedKeyModeEnabled:
            BigWorld.wg_setRedefineKeysMode(True)
        self.__currentSettings = self.params.getMonitorSettings()
        self.as_setInitDataS(BigWorld.wg_isRunningOnWinXP())
        self._update()
        VibroManager.g_instance.onConnect += self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect += self.onVibroManagerDisconnect
        self.settingsCore.onSettingsChanged += self.__onColorSettingsChange
        g_guiResetters.add(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(self.onRecreateDevice)

    def _update(self):
        self.as_setDataS(self.__getSettings())
        newSettings = getNewSettings()
        if newSettings:
            self.as_setCountersDataS(newSettings)
        self.as_updateVideoSettingsS(self.params.getMonitorSettings())
        self.as_openTabS(_getLastTabIndex())
        self.__setColorGradingTechnique()

    def _dispose(self):
        if self.__redefinedKeyModeEnabled:
            BigWorld.wg_setRedefineKeysMode(False)
        g_guiResetters.discard(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(None)
        self.stopVoicesPreview()
        self.stopAltBulbPreview()
        VibroManager.g_instance.onConnect -= self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect -= self.onVibroManagerDisconnect
        self.settingsCore.onSettingsChanged -= self.__onColorSettingsChange
        super(SettingsWindow, self)._dispose()
        return

    def onVibroManagerConnect(self):
        self.as_onVibroManagerConnectS(True)

    def onVibroManagerDisconnect(self):
        self.as_onVibroManagerConnectS(False)

    def onTabSelected(self, tabId):
        if tabId == SETTINGS.SOUNDTITLE:
            self.bwProto.voipController.invalidateInitialization()
        if tabId in _PAGES_INDICES:
            _setLastTabIndex(_PAGES_INDICES[tabId])
        else:
            LOG_WARNING("Unknown settings window's page id", tabId)

    def onCounterTargetVisited(self, tabName, subTabName, controlsIDs):
        isSettingsChanged = invalidateSettings(tabName, subTabName, controlsIDs)
        if isSettingsChanged:
            newSettings = getNewSettings()
            self.as_setCountersDataS(newSettings)

    def onSettingsChange(self, settingName, settingValue):
        settingValue = flashObject2Dict(settingValue)
        LOG_DEBUG('onSettingsChange', settingName, settingValue)
        self.params.preview(settingName, settingValue)

    def applySettings(self, settings, isCloseWnd):
        self._applySettings(flashObject2Dict(settings), isCloseWnd)

    def _applySettings(self, settings, isCloseWnd):
        applyMethod = self.params.getApplyMethod(settings)

        def confirmHandler(isOk):
            self.as_ConfirmationOfApplicationS(isOk)
            if isOk:
                self.__commitSettings(settings, isOk, isCloseWnd)
            else:
                self.params.revert()
            if not isCloseWnd:
                self._update()

        if applyMethod == APPLY_METHOD.RESTART:
            DialogsInterface.showI18nConfirmDialog('graphicsPresetRestartConfirmation', confirmHandler)
        elif applyMethod == APPLY_METHOD.DELAYED:
            DialogsInterface.showI18nConfirmDialog('graphicsPresetDelayedConfirmation', confirmHandler)
        elif applyMethod == APPLY_METHOD.NEXT_BATTLE and self.__isBattleSettings:
            DialogsInterface.showI18nConfirmDialog('nextBattleOptionConfirmation', confirmHandler)
        else:
            confirmHandler(True)

    def onWindowClose(self):
        self.params.revert()
        self.startVOIPTest(False)
        self.destroy()

    def onRecreateDevice(self):
        actualSettings = self.params.getMonitorSettings()
        if self.__currentSettings and self.__currentSettings != actualSettings:
            curDrr = self.__currentSettings[settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            actualDrr = actualSettings[settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            self.__currentSettings = actualSettings
            result = self.__currentSettings.copy()
            if curDrr == actualDrr:
                result[settings_constants.GRAPHICS.DYNAMIC_RENDERER] = None
            self.as_updateVideoSettingsS(result)
        return

    def autodetectQuality(self):
        result = BigWorld.autoDetectGraphicsSettings()
        self.onRecreateDevice()
        return result

    def autodetectAcousticType(self):
        option = self.settingsCore.options.getSetting(settings_constants.SOUND.SOUND_SPEAKERS)
        return option.getSystemPreset()

    def canSelectAcousticType(self, index):
        index = int(index)
        option = self.settingsCore.options.getSetting(settings_constants.SOUND.SOUND_SPEAKERS)
        if not option.isPresetSupportedByIndex(index):

            def _apply(result):
                LOG_DEBUG('Player result', result)
                self.as_onSoundSpeakersPresetApplyS(result)

            DialogsInterface.showI18nConfirmDialog('soundSpeakersPresetDoesNotMatch', callback=_apply)
            return False
        return True

    def startVOIPTest(self, isStart):
        LOG_DEBUG('Vivox test: %s' % str(isStart))
        rh = VOIP.getVOIPManager()
        if isStart:
            rh.enterTestChannel()
        else:
            rh.leaveTestChannel()
        return False

    @decorators.process('__updateCaptureDevices')
    def updateCaptureDevices(self):
        yield self.bwProto.voipController.requestCaptureDevices()
        opt = self.settingsCore.options.getSetting(settings_constants.SOUND.CAPTURE_DEVICES)
        self.as_setCaptureDevicesS(opt.get(), opt.getOptions())

    def altVoicesPreview(self):
        setting = self.settingsCore.options.getSetting(settings_constants.SOUND.ALT_VOICES)
        setting.playPreviewSound()

    def altBulbPreview(self, sampleID):
        setting = self.settingsCore.options.getSetting(settings_constants.SOUND.DETECTION_ALERT_SOUND)
        setting.playPreviewSound(sampleID)

    def stopVoicesPreview(self):
        setting = self.settingsCore.options.getSetting(settings_constants.SOUND.ALT_VOICES)
        setting.clearPreviewSound()

    def stopAltBulbPreview(self):
        setting = self.settingsCore.options.getSetting(settings_constants.SOUND.DETECTION_ALERT_SOUND)
        setting.clearPreviewSound()

    def isSoundModeValid(self):
        setting = self.settingsCore.options.getSetting(settings_constants.SOUND.ALT_VOICES)
        return setting.isSoundModeValid()

    def showWarningDialog(self, dialogID, settings, isCloseWnd):

        def callback(isOk):
            if isOk:
                self.applySettings(settings, False)
            self.as_confirmWarningDialogS(isOk, dialogID)
            if isCloseWnd and isOk:
                self.onWindowClose()

        DialogsInterface.showI18nConfirmDialog(dialogID, callback)

    def openGammaWizard(self, x, y, size):
        g_eventBus.handleEvent(events.LoadViewEvent(alias=VIEW_ALIAS.GAMMA_WIZARD, ctx={'x': x,
         'y': y,
         'size': size}), EVENT_BUS_SCOPE.DEFAULT)

    def openColorSettings(self):
        g_eventBus.handleEvent(events.LoadViewEvent(alias=VIEW_ALIAS.COLOR_SETTING), EVENT_BUS_SCOPE.DEFAULT)

    def __updateInterfaceScale(self):
        self.as_updateVideoSettingsS(self.params.getMonitorSettings())

    def __isGraphicsPresetApplied(self, settings):
        allsettings = BigWorld.getGraphicsPresetPropertyNames()
        isGraphicsQualitySettings = False
        for settingKey in settings.iterkeys():
            if settingKey in allsettings:
                isGraphicsQualitySettings = True
                break

        return self.as_isPresetAppliedS() if isGraphicsQualitySettings else True

    def __onColorSettingsChange(self, diff):
        if settings_constants.GRAPHICS.COLOR_GRADING_TECHNIQUE in diff:
            self.__setColorGradingTechnique(diff.get(settings_constants.GRAPHICS.COLOR_GRADING_TECHNIQUE, None))
        return

    def __setColorGradingTechnique(self, value=None):
        colorSettingsSelectedTab = AccountSettings.getSettings(COLOR_SETTINGS_TAB_IDX)
        if colorSettingsSelectedTab is None or not graphics.isRendererPipelineDeferred():
            colorSettingsSelectedTab = 0
        label = SETTINGS.GRAPHICSSETTINGSOPTIONS_NONE
        image = RES_ICONS.MAPS_ICONS_SETTINGS_COLOR_GRADING_TECHNIQUE_NONE
        if colorSettingsSelectedTab == 2:
            label = SETTINGS.COLORSETTINGS_TAB_CUSTOMSETTINGS
            image = RES_ICONS.MAPS_ICONS_SETTINGS_COLOR_GRADING_TECHNIQUE_RANDOM
        elif colorSettingsSelectedTab == 1:
            setting = self.settingsCore.options.getSetting(settings_constants.GRAPHICS.COLOR_GRADING_TECHNIQUE)
            images = graphics.getGraphicSettingImages(settings_constants.GRAPHICS.COLOR_GRADING_TECHNIQUE)
            label = SETTINGS.GRAPHICSSETTINGSOPTIONS_NONE
            image = None
            filterIdx = setting.get() if value is None else value
            if setting is not None:
                for option in setting.getOptions():
                    currentIdx = option.get('data', 0)
                    if currentIdx == filterIdx:
                        label = option.get('label')
                        image = images.get(option.get('data', 0))
                        break

            if image is None:
                image = RES_ICONS.MAPS_ICONS_SETTINGS_COLOR_GRADING_TECHNIQUE_NONE
        self.as_setColorGradingTechniqueS(image, label)
        return
Esempio n. 2
0
class SettingsWindow(SettingsWindowMeta):
    settingsCore = dependency.descriptor(ISettingsCore)

    def __init__(self, ctx=None):
        super(SettingsWindow, self).__init__()
        self.__redefinedKeyModeEnabled = ctx.get('redefinedKeyMode', True)
        if 'tabIndex' in ctx and ctx['tabIndex'] is not None:
            _setLastTabIndex(ctx['tabIndex'])
        self.params = SettingsParams()
        return

    @proto_getter(PROTO_TYPE.BW_CHAT2)
    def bwProto(self):
        """
        Returns instance of chat plugin to have access to VOIP Controller
        :return: instance of chat plugin
        """
        return None

    def __getSettingsParam(self):
        """Read settings from SettingsParam
        """
        settings = {
            SETTINGS_GROUP.GAME_SETTINGS: self.params.getGameSettings(),
            SETTINGS_GROUP.GRAPHICS_SETTINGS:
            self.params.getGraphicsSettings(),
            SETTINGS_GROUP.SOUND_SETTINGS: self.params.getSoundSettings(),
            SETTINGS_GROUP.CONTROLS_SETTINGS:
            self.params.getControlsSettings(),
            SETTINGS_GROUP.AIM_SETTINGS: self.params.getAimSettings(),
            SETTINGS_GROUP.MARKERS_SETTINGS: self.params.getMarkersSettings(),
            SETTINGS_GROUP.OTHER_SETTINGS: self.params.getOtherSettings(),
            SETTINGS_GROUP.FEEDBACK_SETTINGS:
            self.params.getFeedbackSettings()
        }
        return settings

    def __getSettings(self):
        """Create dict of settings divided by groups
        :return: dict { settingsGroup :  {keys: [settingsName], values: [settingsValues] }}
        """
        settings = self.__getSettingsParam()
        reformatted_settings = {}
        for key, value in settings.iteritems():
            reformatted_keys = []
            reformatted_values = []
            reformatted_settings[key] = {
                'keys': reformatted_keys,
                'values': reformatted_values
            }
            for settingName, settingValue in value.iteritems():
                reformatted_keys.append(settingName)
                reformatted_values.append(settingValue)

        return reformatted_settings

    def __commitSettings(self,
                         settings=None,
                         restartApproved=False,
                         isCloseWnd=False):
        if settings is None:
            settings = {}
        self.__apply(settings, restartApproved, isCloseWnd)
        return

    def __apply(self, settings, restartApproved=False, isCloseWnd=False):
        LOG_DEBUG('Settings window: apply settings', restartApproved, settings)
        self.settingsCore.isDeviseRecreated = False
        self.settingsCore.isChangesConfirmed = True
        isRestart = self.params.apply(settings, restartApproved)
        if settings_constants.GRAPHICS.INTERFACE_SCALE in settings:
            self.__updateInterfaceScale()
        isPresetApplied = self.__isGraphicsPresetApplied(settings)
        if self.settingsCore.isChangesConfirmed and isCloseWnd:
            self.onWindowClose()
        if isRestart:
            BigWorld.savePreferences()
            if restartApproved:
                BigWorld.callback(0.3, self.__restartGame)
            elif self.settingsCore.isDeviseRecreated:
                self.onRecreateDevice()
                self.settingsCore.isDeviseRecreated = False
            else:
                BigWorld.callback(
                    0.0,
                    functools.partial(BigWorld.changeVideoMode, -1,
                                      BigWorld.getWindowMode()))
        elif not isPresetApplied:
            DialogsInterface.showI18nInfoDialog('graphicsPresetNotInstalled',
                                                None)
        return

    def __restartGame(self):
        BigWorld.savePreferences()
        BigWorld.worldDrawEnabled(False)
        BigWorld.restartGame()

    def _populate(self):
        super(SettingsWindow, self)._populate()
        if self.__redefinedKeyModeEnabled:
            BigWorld.wg_setRedefineKeysMode(True)
        self.__currentSettings = self.params.getMonitorSettings()
        self._update()
        VibroManager.g_instance.onConnect += self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect += self.onVibroManagerDisconnect
        g_guiResetters.add(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(self.onRecreateDevice)

    def _update(self):
        self.as_setDataS(self.__getSettings())
        newSettings = getNewSettings()
        if len(newSettings):
            self.as_setCountersDataS(newSettings)
        self.as_updateVideoSettingsS(self.__currentSettings)
        self.as_openTabS(_getLastTabIndex())

    def _dispose(self):
        if self.__redefinedKeyModeEnabled:
            BigWorld.wg_setRedefineKeysMode(False)
        g_guiResetters.discard(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(None)
        self.stopVoicesPreview()
        self.stopAltBulbPreview()
        VibroManager.g_instance.onConnect -= self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect -= self.onVibroManagerDisconnect
        super(SettingsWindow, self)._dispose()
        return

    def onVibroManagerConnect(self):
        self.as_onVibroManagerConnectS(True)

    def onVibroManagerDisconnect(self):
        self.as_onVibroManagerConnectS(False)

    def onTabSelected(self, tabId):
        if tabId == SETTINGS.SOUNDTITLE:
            self.bwProto.voipController.invalidateInitialization()
        if tabId in _PAGES_INDICES:
            _setLastTabIndex(_PAGES_INDICES[tabId])
        else:
            LOG_WARNING("Unknown settings window's page id", tabId)

    def onCounterTargetVisited(self, tabName, subTabName, controlId):
        """Notify that user visited tab
        """
        isSettingsChanged = invalidateSettings(tabName, subTabName, controlId)
        if isSettingsChanged:
            newSettings = getNewSettings()
            self.as_setCountersDataS(newSettings)

    def onSettingsChange(self, settingName, settingValue):
        settingValue = flashObject2Dict(settingValue)
        LOG_DEBUG('onSettingsChange', settingName, settingValue)
        self.params.preview(settingName, settingValue)

    def applySettings(self, settings, isCloseWnd):
        self._applySettings(flashObject2Dict(settings), isCloseWnd)

    def _applySettings(self, settings, isCloseWnd):
        applyMethod = self.params.getApplyMethod(settings)

        def confirmHandler(isOk):
            self.as_ConfirmationOfApplicationS(isOk)
            if isOk:
                self.__commitSettings(settings, isOk, isCloseWnd)
            else:
                self.params.revert()
                self._update()

        if applyMethod == APPLY_METHOD.RESTART:
            DialogsInterface.showI18nConfirmDialog(
                'graphicsPresetRestartConfirmation', confirmHandler)
        elif applyMethod == APPLY_METHOD.DELAYED:
            DialogsInterface.showI18nConfirmDialog(
                'graphicsPresetDelayedConfirmation', confirmHandler)
        else:
            confirmHandler(True)

    def onWindowClose(self):
        self.params.revert()
        self.startVOIPTest(False)
        self.destroy()

    def onRecreateDevice(self):
        actualSettings = self.params.getMonitorSettings()
        if self.__currentSettings and self.__currentSettings != actualSettings:
            curDrr = self.__currentSettings[
                settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            actualDrr = actualSettings[
                settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            self.__currentSettings = actualSettings
            result = self.__currentSettings.copy()
            if curDrr == actualDrr:
                result[settings_constants.GRAPHICS.DYNAMIC_RENDERER] = None
            self.as_updateVideoSettingsS(result)
        return

    def autodetectQuality(self):
        result = BigWorld.autoDetectGraphicsSettings()
        self.onRecreateDevice()
        return result

    def autodetectAcousticType(self):
        option = self.settingsCore.options.getSetting(
            settings_constants.SOUND.SOUND_SPEAKERS)
        return option.getSystemPreset()

    def canSelectAcousticType(self, index):
        index = int(index)
        option = self.settingsCore.options.getSetting(
            settings_constants.SOUND.SOUND_SPEAKERS)
        if not option.isPresetSupportedByIndex(index):

            def apply(result):
                LOG_DEBUG('Player result', result)
                self.as_onSoundSpeakersPresetApplyS(result)

            DialogsInterface.showI18nConfirmDialog(
                'soundSpeakersPresetDoesNotMatch', callback=apply)
            return False
        else:
            return True

    def startVOIPTest(self, isStart):
        LOG_DEBUG('Vivox test: %s' % str(isStart))
        rh = VOIP.getVOIPManager()
        rh.enterTestChannel() if isStart else rh.leaveTestChannel()
        return False

    @decorators.process('__updateCaptureDevices')
    def updateCaptureDevices(self):
        yield self.bwProto.voipController.requestCaptureDevices()
        opt = self.settingsCore.options.getSetting(
            settings_constants.SOUND.CAPTURE_DEVICES)
        self.as_setCaptureDevicesS(opt.get(), opt.getOptions())

    def altVoicesPreview(self):
        setting = self.settingsCore.options.getSetting(
            settings_constants.SOUND.ALT_VOICES)
        setting.playPreviewSound()

    def altBulbPreview(self, sampleID):
        setting = self.settingsCore.options.getSetting(
            settings_constants.SOUND.DETECTION_ALERT_SOUND)
        setting.playPreviewSound(sampleID)

    def stopVoicesPreview(self):
        setting = self.settingsCore.options.getSetting(
            settings_constants.SOUND.ALT_VOICES)
        setting.clearPreviewSound()

    def stopAltBulbPreview(self):
        setting = self.settingsCore.options.getSetting(
            settings_constants.SOUND.DETECTION_ALERT_SOUND)
        setting.clearPreviewSound()

    def isSoundModeValid(self):
        setting = self.settingsCore.options.getSetting(
            settings_constants.SOUND.ALT_VOICES)
        return setting.isSoundModeValid()

    def showWarningDialog(self, dialogID, settings, isCloseWnd):
        def callback(isOk):
            if isOk:
                self.applySettings(settings, False)
            self.as_confirmWarningDialogS(isOk, dialogID)
            if isCloseWnd and isOk:
                self.onWindowClose()

        DialogsInterface.showI18nConfirmDialog(dialogID, callback)

    def onRecreateDevice(self):
        actualSettings = self.params.getMonitorSettings()
        curDrr = self.__currentSettings[
            settings_constants.GRAPHICS.DYNAMIC_RENDERER]
        actualDrr = actualSettings[
            settings_constants.GRAPHICS.DYNAMIC_RENDERER]
        self.__currentSettings = actualSettings
        result = self.__currentSettings.copy()
        if curDrr == actualDrr:
            result[settings_constants.GRAPHICS.DYNAMIC_RENDERER] = None
        self.as_updateVideoSettingsS(result)
        return

    def __updateInterfaceScale(self):
        self.as_updateVideoSettingsS(self.params.getMonitorSettings())

    def __isGraphicsPresetApplied(self, settings):
        allsettings = BigWorld.getGraphicsPresetPropertyNames()
        isGraphicsQualitySettings = False
        for settingKey in settings.iterkeys():
            if settingKey in allsettings:
                isGraphicsQualitySettings = True
                break

        if isGraphicsQualitySettings:
            return self.as_isPresetAppliedS()
        return True
Esempio n. 3
0
class SettingsWindow(SettingsWindowMeta):

    def __init__(self, ctx = None):
        super(SettingsWindow, self).__init__()
        self.__redefinedKeyModeEnabled = ctx.get('redefinedKeyMode', True)
        self.__initialTabIdx = ctx.get('tabIndex', -1)
        self.params = SettingsParams()

    def __getSettings(self):
        settings = {'GameSettings': self.params.getGameSettings(),
         'GraphicSettings': self.params.getGraphicsSettings(),
         'SoundSettings': self.params.getSoundSettings(),
         'ControlsSettings': self.params.getControlsSettings(),
         'AimSettings': self.params.getAimSettings(),
         'MarkerSettings': self.params.getMarkersSettings(),
         'OtherSettings': self.params.getOtherSettings()}
        reformatted_settings = {}
        for key, value in settings.iteritems():
            reformatted_keys = []
            reformatted_values = []
            reformatted_settings[key] = {'keys': reformatted_keys,
             'values': reformatted_values}
            for key, value in value.iteritems():
                reformatted_keys.append(key)
                reformatted_values.append(value)

        return reformatted_settings

    def __commitSettings(self, settings = None, restartApproved = False, isCloseWnd = False):
        if settings is None:
            settings = {}
        self.__apply(settings, restartApproved, isCloseWnd)
        return

    def __apply(self, settings, restartApproved = False, isCloseWnd = False):
        LOG_DEBUG('Settings window: apply settings', restartApproved, settings)
        g_settingsCore.isDeviseRecreated = False
        g_settingsCore.isChangesConfirmed = True
        isRestart = self.params.apply(settings, restartApproved)
        if settings_constants.GRAPHICS.INTERFACE_SCALE in settings:
            self.__updateInterfaceScale()
        isPresetApplied = self.__isGraphicsPresetApplied(settings)
        if g_settingsCore.isChangesConfirmed and isCloseWnd:
            self.onWindowClose()
        if isRestart:
            BigWorld.savePreferences()
            if restartApproved:
                BigWorld.callback(0.3, self.__restartGame)
            elif g_settingsCore.isDeviseRecreated:
                self.onRecreateDevice()
                g_settingsCore.isDeviseRecreated = False
            else:
                BigWorld.callback(0.0, functools.partial(BigWorld.changeVideoMode, -1, BigWorld.isVideoWindowed()))
        elif not isPresetApplied:
            DialogsInterface.showI18nInfoDialog('graphicsPresetNotInstalled', None)
        return

    def __restartGame(self):
        BigWorld.savePreferences()
        BigWorld.restartGame()

    def _populate(self):
        super(SettingsWindow, self)._populate()
        self.__currentSettings = self.params.getMonitorSettings()
        self._update()
        VibroManager.g_instance.onConnect += self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect += self.onVibroManagerDisconnect
        g_guiResetters.add(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(self.onRecreateDevice)
        SoundGroups.g_instance.enableVoiceSounds(True)

    def _update(self):
        self.as_setDataS(self.__getSettings())
        self.as_updateVideoSettingsS(self.__currentSettings)
        self.as_openTabS(self.__initialTabIdx)

    def _dispose(self):
        if not g_sessionProvider.getCtx().isInBattle:
            SoundGroups.g_instance.enableVoiceSounds(False)
        g_guiResetters.discard(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(None)
        VibroManager.g_instance.onConnect -= self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect -= self.onVibroManagerDisconnect
        super(SettingsWindow, self)._dispose()
        return

    def onVibroManagerConnect(self):
        self.as_onVibroManagerConnectS(True)

    def onVibroManagerDisconnect(self):
        self.as_onVibroManagerConnectS(False)

    def onTabSelected(self, tabId):
        if tabId == SETTINGS.SOUNDTITLE:
            self.app.voiceChatManager.checkForInitialization()

    def onSettingsChange(self, settingName, settingValue):
        settingValue = flashObject2Dict(settingValue)
        LOG_DEBUG('onSettingsChange', settingName, settingValue)
        self.params.preview(settingName, settingValue)

    def applySettings(self, settings, isCloseWnd):
        self._applySettings(flashObject2Dict(settings), isCloseWnd)

    def _applySettings(self, settings, isCloseWnd):
        applyMethod = self.params.getApplyMethod(settings)

        def confirmHandler(isOk):
            self.as_ConfirmationOfApplicationS(isOk)
            if isOk:
                self.__commitSettings(settings, isOk, isCloseWnd)
            else:
                self.params.revert()
                self._update()

        if applyMethod == APPLY_METHOD.RESTART:
            DialogsInterface.showI18nConfirmDialog('graphicsPresetRestartConfirmation', confirmHandler)
        elif applyMethod == APPLY_METHOD.DELAYED:
            DialogsInterface.showI18nConfirmDialog('graphicsPresetDelayedConfirmation', confirmHandler)
        else:
            confirmHandler(True)

    def onWindowClose(self):
        self.params.revert()
        self.startVOIPTest(False)
        self.destroy()

    def onRecreateDevice(self):
        actualSettings = self.params.getMonitorSettings()
        if self.__currentSettings and self.__currentSettings != actualSettings:
            curDrr = self.__currentSettings[settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            actualDrr = actualSettings[settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            self.__currentSettings = actualSettings
            result = self.__currentSettings.copy()
            if curDrr == actualDrr:
                result[settings_constants.GRAPHICS.DYNAMIC_RENDERER] = None
            self.as_updateVideoSettingsS(result)
        return

    def useRedifineKeysMode(self, isUse):
        if self.__redefinedKeyModeEnabled:
            BigWorld.wg_setRedefineKeysMode(isUse)

    def autodetectQuality(self):
        result = BigWorld.autoDetectGraphicsSettings()
        self.onRecreateDevice()
        return result

    def startVOIPTest(self, isStart):
        LOG_DEBUG('Vivox test: %s' % str(isStart))
        rh = VOIP.getVOIPManager()
        rh.enterTestChannel() if isStart else rh.leaveTestChannel()
        return False

    @decorators.process('__updateCaptureDevices')
    def updateCaptureDevices(self):
        yield self.app.voiceChatManager.requestCaptureDevices()
        opt = g_settingsCore.options.getSetting(settings_constants.SOUND.CAPTURE_DEVICES)
        self.as_setCaptureDevicesS(opt.get(), opt.getOptions())

    def altVoicesPreview(self):
        setting = g_settingsCore.options.getSetting(settings_constants.SOUND.ALT_VOICES)
        if setting is not None:
            setting.playPreviewSound()
        return

    def isSoundModeValid(self):
        setting = g_settingsCore.options.getSetting(settings_constants.SOUND.ALT_VOICES)
        if setting is not None:
            return setting.isSoundModeValid()
        else:
            return False

    def showWarningDialog(self, dialogID, settings, isCloseWnd):

        def callback(isOk):
            if isOk:
                self.applySettings(settings, False)
            self.as_confirmWarningDialogS(isOk, dialogID)
            if isCloseWnd and isOk:
                self.onWindowClose()

        DialogsInterface.showI18nConfirmDialog(dialogID, callback)

    def __updateInterfaceScale(self):
        self.as_setDataS(self.__getSettings())
        self.as_updateVideoSettingsS(self.params.getMonitorSettings())

    def __isGraphicsPresetApplied(self, settings):
        isGraphicsQualitySettings = False
        for settingKey in settings.iterkeys():
            if settingKey in GraphicsPresets.GRAPHICS_QUALITY_SETTINGS:
                isGraphicsQualitySettings = True
                break

        if isGraphicsQualitySettings:
            return self.as_isPresetAppliedS()
        return True
Esempio n. 4
0
class SettingsWindow(SettingsWindowMeta):
    def __init__(self, ctx=None):
        super(SettingsWindow, self).__init__()
        self.__redefinedKeyModeEnabled = ctx.get('redefinedKeyMode', True)
        if 'tabIndex' in ctx and ctx['tabIndex'] is not None:
            _setLastTabIndex(ctx['tabIndex'])
        self.params = SettingsParams()
        return

    @proto_getter(PROTO_TYPE.BW_CHAT2)
    def bwProto(self):
        """
        Returns instance of chat plugin to have access to VOIP Controller
        :return: instance of chat plugin
        """
        return None

    def __getSettings(self):
        settings = {
            'GameSettings': self.params.getGameSettings(),
            'GraphicSettings': self.params.getGraphicsSettings(),
            'SoundSettings': self.params.getSoundSettings(),
            'ControlsSettings': self.params.getControlsSettings(),
            'AimSettings': self.params.getAimSettings(),
            'MarkerSettings': self.params.getMarkersSettings(),
            'OtherSettings': self.params.getOtherSettings()
        }
        reformatted_settings = {}
        for key, value in settings.iteritems():
            reformatted_keys = []
            reformatted_values = []
            reformatted_settings[key] = {
                'keys': reformatted_keys,
                'values': reformatted_values
            }
            for key, value in value.iteritems():
                reformatted_keys.append(key)
                reformatted_values.append(value)

        return reformatted_settings

    def __commitSettings(self,
                         settings=None,
                         restartApproved=False,
                         isCloseWnd=False):
        if settings is None:
            settings = {}
        self.__apply(settings, restartApproved, isCloseWnd)
        return

    def __apply(self, settings, restartApproved=False, isCloseWnd=False):
        LOG_DEBUG('Settings window: apply settings', restartApproved, settings)
        g_settingsCore.isDeviseRecreated = False
        g_settingsCore.isChangesConfirmed = True
        isRestart = self.params.apply(settings, restartApproved)
        if settings_constants.GRAPHICS.INTERFACE_SCALE in settings:
            self.__updateInterfaceScale()
        isPresetApplied = self.__isGraphicsPresetApplied(settings)
        if g_settingsCore.isChangesConfirmed and isCloseWnd:
            self.onWindowClose()
        if isRestart:
            BigWorld.savePreferences()
            if restartApproved:
                BigWorld.callback(0.3, self.__restartGame)
            elif g_settingsCore.isDeviseRecreated:
                self.onRecreateDevice()
                g_settingsCore.isDeviseRecreated = False
            else:
                BigWorld.callback(
                    0.0,
                    functools.partial(BigWorld.changeVideoMode, -1,
                                      BigWorld.isVideoWindowed()))
        elif not isPresetApplied:
            DialogsInterface.showI18nInfoDialog('graphicsPresetNotInstalled',
                                                None)
        return

    def __restartGame(self):
        BigWorld.savePreferences()
        BigWorld.worldDrawEnabled(False)
        BigWorld.restartGame()

    def _populate(self):
        super(SettingsWindow, self)._populate()
        if self.__redefinedKeyModeEnabled:
            BigWorld.wg_setRedefineKeysMode(True)
        self.__currentSettings = self.params.getMonitorSettings()
        self._update()
        VibroManager.g_instance.onConnect += self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect += self.onVibroManagerDisconnect
        g_guiResetters.add(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(self.onRecreateDevice)

    def _update(self):
        self.as_setDataS(self.__getSettings())
        self.as_updateVideoSettingsS(self.__currentSettings)
        self.as_openTabS(_getLastTabIndex())

    def _dispose(self):
        if self.__redefinedKeyModeEnabled:
            BigWorld.wg_setRedefineKeysMode(False)
        g_guiResetters.discard(self.onRecreateDevice)
        BigWorld.wg_setAdapterOrdinalNotifyCallback(None)
        self.stopVoicesPreview()
        VibroManager.g_instance.onConnect -= self.onVibroManagerConnect
        VibroManager.g_instance.onDisconnect -= self.onVibroManagerDisconnect
        super(SettingsWindow, self)._dispose()
        return

    def onVibroManagerConnect(self):
        self.as_onVibroManagerConnectS(True)

    def onVibroManagerDisconnect(self):
        self.as_onVibroManagerConnectS(False)

    def onTabSelected(self, tabId):
        if tabId == SETTINGS.SOUNDTITLE:
            self.bwProto.voipController.invalidateInitialization()
        if tabId in _PAGES_INDICES:
            _setLastTabIndex(_PAGES_INDICES[tabId])
        else:
            LOG_WARNING("Unknown settings window's page id", tabId)

    def onSettingsChange(self, settingName, settingValue):
        settingValue = flashObject2Dict(settingValue)
        LOG_DEBUG('onSettingsChange', settingName, settingValue)
        self.params.preview(settingName, settingValue)

    def applySettings(self, settings, isCloseWnd):
        self._applySettings(flashObject2Dict(settings), isCloseWnd)

    def _applySettings(self, settings, isCloseWnd):
        applyMethod = self.params.getApplyMethod(settings)

        def confirmHandler(isOk):
            self.as_ConfirmationOfApplicationS(isOk)
            if isOk:
                self.__commitSettings(settings, isOk, isCloseWnd)
            else:
                self.params.revert()
                self._update()

        if applyMethod == APPLY_METHOD.RESTART:
            DialogsInterface.showI18nConfirmDialog(
                'graphicsPresetRestartConfirmation', confirmHandler)
        elif applyMethod == APPLY_METHOD.DELAYED:
            DialogsInterface.showI18nConfirmDialog(
                'graphicsPresetDelayedConfirmation', confirmHandler)
        else:
            confirmHandler(True)

    def onWindowClose(self):
        self.params.revert()
        self.startVOIPTest(False)
        self.destroy()

    def onRecreateDevice(self):
        actualSettings = self.params.getMonitorSettings()
        if self.__currentSettings and self.__currentSettings != actualSettings:
            curDrr = self.__currentSettings[
                settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            actualDrr = actualSettings[
                settings_constants.GRAPHICS.DYNAMIC_RENDERER]
            self.__currentSettings = actualSettings
            result = self.__currentSettings.copy()
            if curDrr == actualDrr:
                result[settings_constants.GRAPHICS.DYNAMIC_RENDERER] = None
            self.as_updateVideoSettingsS(result)
        return

    def autodetectQuality(self):
        result = BigWorld.autoDetectGraphicsSettings()
        self.onRecreateDevice()
        return result

    def startVOIPTest(self, isStart):
        LOG_DEBUG('Vivox test: %s' % str(isStart))
        rh = VOIP.getVOIPManager()
        rh.enterTestChannel() if isStart else rh.leaveTestChannel()
        return False

    @decorators.process('__updateCaptureDevices')
    def updateCaptureDevices(self):
        yield self.bwProto.voipController.requestCaptureDevices()
        opt = g_settingsCore.options.getSetting(
            settings_constants.SOUND.CAPTURE_DEVICES)
        self.as_setCaptureDevicesS(opt.get(), opt.getOptions())

    def altVoicesPreview(self):
        setting = g_settingsCore.options.getSetting(
            settings_constants.SOUND.ALT_VOICES)
        if setting is not None:
            setting.playPreviewSound()
        return

    def stopVoicesPreview(self):
        setting = g_settingsCore.options.getSetting(
            settings_constants.SOUND.ALT_VOICES)
        if setting is not None:
            setting.clearPreviewSound()
        return

    def isSoundModeValid(self):
        setting = g_settingsCore.options.getSetting(
            settings_constants.SOUND.ALT_VOICES)
        if setting is not None:
            return setting.isSoundModeValid()
        else:
            return False

    def showWarningDialog(self, dialogID, settings, isCloseWnd):
        def callback(isOk):
            if isOk:
                self.applySettings(settings, False)
            self.as_confirmWarningDialogS(isOk, dialogID)
            if isCloseWnd and isOk:
                self.onWindowClose()

        DialogsInterface.showI18nConfirmDialog(dialogID, callback)

    def onRecreateDevice(self):
        actualSettings = self.params.getMonitorSettings()
        curDrr = self.__currentSettings[
            settings_constants.GRAPHICS.DYNAMIC_RENDERER]
        actualDrr = actualSettings[
            settings_constants.GRAPHICS.DYNAMIC_RENDERER]
        self.__currentSettings = actualSettings
        result = self.__currentSettings.copy()
        if curDrr == actualDrr:
            result[settings_constants.GRAPHICS.DYNAMIC_RENDERER] = None
        self.as_updateVideoSettingsS(result)
        return

    def __updateInterfaceScale(self):
        self.as_setDataS(self.__getSettings())
        self.as_updateVideoSettingsS(self.params.getMonitorSettings())

    def __isGraphicsPresetApplied(self, settings):
        isGraphicsQualitySettings = False
        for settingKey in settings.iterkeys():
            if settingKey in GraphicsPresets.GRAPHICS_QUALITY_SETTINGS:
                isGraphicsQualitySettings = True
                break

        if isGraphicsQualitySettings:
            return self.as_isPresetAppliedS()
        return True