class SoundCategory(OptionsCategory): Name = "Sound" def __init__(self, page): OptionsCategory.__init__(self, page) self.musicSlider = SliderWidget(page, "Music Volume", (0.0, 1.0), self.__setMusicVol, (0, 0, 0.475)) self.sfxSlider = SliderWidget(page, "Sound Volume", (0.0, 1.0), self.__setSfxVol, (0, 0, 0.335)) self.chatSounds = ChoiceWidget(self.page, None, (0, 0.1, 0.1), widgetName="Chat Sounds", settingKeyName='chs') self.discardChanges() def _setDefaults(self): self.origMusicVol = base.musicManager.getVolume() self.origSfxVol = base.sfxManagerList[0].getVolume() def __setMusicVol(self): val = self.musicSlider.getSliderVal() base.musicManager.setVolume(val) self.musicSlider.setValText("{:.0f}%".format(val * 100)) def __setSfxVol(self): val = self.sfxSlider.getSliderVal() base.sfxManagerList[0].setVolume(val) self.sfxSlider.setValText("{:.0f}%".format(val * 100)) def applyChanges(self): self._showApplying() self.chatSounds.saveSetting() if (base.musicManager.getVolume() != self.origMusicVol): self.settingsMgr.getSetting("musvol").setValue( base.musicManager.getVolume()) if (base.sfxManagerList[0].getVolume() != self.origSfxVol): self.settingsMgr.getSetting("sfxvol").setValue( base.sfxManagerList[0].getVolume()) self.settingsMgr.saveFile() self._setDefaults() self._hideApplying() def discardChanges(self): if not hasattr(self, 'origMusicVol'): self._setDefaults() base.musicManager.setVolume(self.origMusicVol) self.musicSlider.setSliderVal(self.origMusicVol) self.musicSlider.setValText("{:.0f}%".format(self.origMusicVol * 100)) base.sfxManagerList[0].setVolume(self.origSfxVol) self.sfxSlider.setSliderVal(self.origSfxVol) self.sfxSlider.setValText("{:.0f}%".format(self.origSfxVol * 100)) self.chatSounds.reset() self._setDefaults() def cleanup(self): self.discardChanges() if hasattr(self, 'musicSlider'): self.musicSlider.destroy() del self.musicSlider if hasattr(self, 'sfxSlider'): self.sfxSlider.destroy() del self.sfxSlider if hasattr(self, 'chatSounds'): self.chatSounds.cleanup() del self.chatSounds del self.origMusicVol del self.origSfxVol OptionsCategory.cleanup(self)
class ControlsCategory(OptionsCategory): Name = "Controls" def __init__(self, page): OptionsCategory.__init__(self, page) self.gagKey = ChoiceWidget(page, None, pos=(0, 0.47, 0.47), widgetName="Use Gag", settingKeyName='gagkey', mode=MULTICHOICE) self.bpov = ChoiceWidget(page, None, pos=(0, 0.25, 0.25), widgetName="Battle POV", settingKeyName='bpov', mode=INDEX, choiceTextScale=0.053) self.fpmsSlider = SliderWidget(page, "Mouse Sensitivity\n(First Person)", (0.05, 0.3), self.__setFPMS, (0, 0, 0.1)) self.fpfovSlider = SliderWidget(page, "Field of View\n(First Person)", (54.0, 70.0), self.__setFPFov, (0, 0, -0.15)) self.genFovSlider = SliderWidget(page, "Field of View\n(General Gameplay)", (40.0, 70.0), self.__setGenFov, (0, 0, -0.4)) self.keysChanged = 0 self.discardChanges() def _setDefaults(self): self.origFPms = float( CIGlobals.getSettingsMgr().getSetting("fpmgms").getValue()) self.origFPfov = float( CIGlobals.getSettingsMgr().getSetting("fpmgfov").getValue()) self.origGenFov = float( CIGlobals.getSettingsMgr().getSetting("genfov").getValue()) self.fpFov = self.origFPfov self.fpMs = self.origFPms self.genFov = self.origGenFov self.keysChanged = 0 self.gagKey.reset() self.bpov.reset() def __updateGagKey(self, _): self.keysChanged += 1 def __setFPMS(self): val = self.fpmsSlider.getSliderVal() self.fpmsSlider.setValText("{:.2f}".format(val * 10.0)) self.fpMs = val def __setFPFov(self): val = self.fpfovSlider.getSliderVal() self.fpfovSlider.setValText("{:.0f}".format(val)) self.fpFov = val def __setGenFov(self): val = self.genFovSlider.getSliderVal() self.genFovSlider.setValText("{:.0f}".format(val)) self.genFov = val def applyChanges(self): self._showApplying() self.gagKey.saveSetting() self.bpov.saveSetting() if (self.fpFov != self.origFPfov): # They changed the first person fov! self.settingsMgr.getSetting("fpmgfov").setValue(self.fpFov) if (self.fpMs != self.origFPms): self.settingsMgr.getSetting("fpmgms").setValue(self.fpMs) if (self.genFov != self.origGenFov): self.settingsMgr.getSetting("genfov").setValue(self.genFov) # We need to let the chat input know when we updated keys. if self.keysChanged > 0: base.localAvatar.chatInput.setKeyList() self.settingsMgr.saveFile() self._setDefaults() self._hideApplying() def discardChanges(self): self._setDefaults() self.fpmsSlider.setSliderVal(self.origFPms) self.fpmsSlider.setValText("{:.2f}".format(self.origFPms * 10.0)) self.fpfovSlider.setSliderVal(self.origFPfov) self.fpfovSlider.setValText("{:.0f}".format(self.origFPfov)) self.genFovSlider.setSliderVal(self.origGenFov) self.genFovSlider.setValText("{:.0f}".format(self.origGenFov)) def cleanup(self): self.discardChanges() OptionsCategory.cleanup(self) for widget in [ self.gagKey, self.fpmsSlider, self.fpfovSlider, self.genFovSlider, self.bpov ]: widget.cleanup() del self.gagKey del self.bpov del self.fpmsSlider del self.fpfovSlider del self.genFovSlider del self.origFPms del self.origFPfov del self.origGenFov del self.fpFov del self.fpMs del self.genFov del self.keysChanged