class OptionsMenu(DirectObject): def __init__(self): """Default constructor""" # create a main frame as big as the window self.frameMain = DirectFrame( # set framesize the same size as the window frameSize=(base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), image="LogoTextGlow.png", image_scale=(1.06 / 2.0, 1, 0.7 / 2.0), image_pos=(0, 0, 0.7), # position center pos=(0, 0, 0), # set tramsparent background color frameColor=(0, 0, 0, 0)) self.frameMain.setTransparency(1) self.frameMain.setBin("fixed", 100) sliderscale = 0.5 buttonScale = 0.25 textscale = 0.1 checkboxscale = 0.05 left = -0.5 right = 0.5 self.sliderTextspeed = DirectSlider( scale=sliderscale, pos=(left, 0, 0.2), range=(0.2, 0.01), scrollSize=0.01, text=_("Textspeed %0.1f%%") % (base.textWriteSpeed * 10), text_scale=textscale, text_align=TextNode.ACenter, text_pos=(0.0, 0.15), text_fg=(1, 1, 1, 1), thumb_frameColor=(0.65, 0.65, 0.0, 1), thumb_relief=DGG.FLAT, frameColor=(0.15, 0.15, 0.15, 1), value=base.textWriteSpeed, command=self.sliderTextspeed_ValueChanged) self.sliderTextspeed.reparentTo(self.frameMain) self.cbParticles = DirectCheckButton( text=_(" Enable Particles"), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 0.35), pos=(left, 0, -0.0), scale=checkboxscale, frameColor=(0, 0, 0, 0), command=self.cbParticles_CheckedChanged, rolloverSound=None, clickSound=None, pressEffect=False, boxPlacement="below", boxBorder=0.8, boxRelief=DGG.FLAT, indicator_scale=1.5, indicator_text_fg=(0.65, 0.65, 0.0, 1), indicator_text_shadow=(0, 0, 0, 0.35), indicator_frameColor=(0.15, 0.15, 0.15, 1), indicatorValue=base.particleMgrEnabled) self.cbParticles.indicator['text'] = (' ', 'x') self.cbParticles.indicator['text_pos'] = (0, 0.1) #self.cbParticles.indicator.setX(self.cbParticles.indicator, -0.5) #self.cbParticles.indicator.setZ(self.cbParticles.indicator, -0.1) #self.cbParticles.setFrameSize() self.cbParticles.setTransparency(1) self.cbParticles.reparentTo(self.frameMain) volume = base.musicManager.getVolume() self.sliderVolume = DirectSlider( scale=sliderscale, pos=(left, 0, -0.35), range=(0, 1), scrollSize=0.01, text=_("Volume %d%%") % volume * 100, text_scale=textscale, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(1, 1, 1, 1), thumb_frameColor=(0.65, 0.65, 0.0, 1), thumb_relief=DGG.FLAT, frameColor=(0.15, 0.15, 0.15, 1), value=volume, command=self.sliderVolume_ValueChanged) self.sliderVolume.reparentTo(self.frameMain) self.lblControltype = DirectLabel(text=_("Control type"), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 0.35), frameColor=(0, 0, 0, 0), scale=textscale / 2, pos=(right, 0, 0.27)) self.lblControltype.setTransparency(1) self.lblControltype.reparentTo(self.frameMain) selectedControlType = 0 if base.controlType == "MouseAndKeyboard": selectedControlType = 1 self.controltype = DirectOptionMenu( pos=(right, 0, 0.18), text_fg=(1, 1, 1, 1), scale=0.1, items=[_("Keyboard"), _("Keyboard + Mouse")], initialitem=selectedControlType, frameColor=(0.15, 0.15, 0.15, 1), popupMarker_frameColor=(0.65, 0.65, 0.0, 1), popupMarker_relief=DGG.FLAT, highlightColor=(0.65, 0.65, 0.0, 1), relief=DGG.FLAT, command=self.controlType_Changed) self.controltype.reparentTo(self.frameMain) b = self.controltype.getBounds() xPos = right - ((b[1] - b[0]) / 2.0 * 0.1) self.controltype.setX(xPos) setItems(self.controltype) self.controltype.setItems = setItems self.controltype.showPopupMenu = showPopupMenu self.controltype.popupMarker.unbind(DGG.B1PRESS) self.controltype.popupMarker.bind(DGG.B1PRESS, showPopupMenu) self.controltype.unbind(DGG.B1PRESS) self.controltype.bind(DGG.B1PRESS, showPopupMenuExtra, [self.controltype]) isChecked = not base.AppHasAudioFocus img = None if base.AppHasAudioFocus: img = "AudioSwitch_on.png" else: img = "AudioSwitch_off.png" self.cbVolumeMute = DirectCheckBox( text=_("Mute Audio"), text_scale=0.5, text_align=TextNode.ACenter, text_pos=(0.0, 0.65), text_fg=(1, 1, 1, 1), pos=(right, 0, -0.35), scale=0.21 / 2.0, command=self.cbVolumeMute_CheckedChanged, rolloverSound=None, clickSound=None, relief=None, pressEffect=False, isChecked=isChecked, image=img, image_scale=0.5, checkedImage="AudioSwitch_off.png", uncheckedImage="AudioSwitch_on.png") self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.setImage() self.cbVolumeMute.reparentTo(self.frameMain) sensitivity = base.mouseSensitivity self.sliderSensitivity = DirectSlider( scale=sliderscale, pos=(right, 0, -0.075), range=(0.5, 2), scrollSize=0.01, text=_("Mouse Sensitivity %0.1fx") % sensitivity, text_scale=textscale, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(1, 1, 1, 1), thumb_frameColor=(0.65, 0.65, 0.0, 1), thumb_relief=DGG.FLAT, frameColor=(0.15, 0.15, 0.15, 1), value=sensitivity, command=self.sliderSensitivity_ValueChanged) self.sliderSensitivity.reparentTo(self.frameMain) if base.controlType == "Gamepad": self.sliderSensitivity.hide() # create the back button self.btnBack = DirectButton( scale=buttonScale, # position on the window pos=(0, 0, base.a2dBottom + 0.15), frameColor=(0, 0, 0, 0), # text properties text=_("Back"), text_scale=0.5, text_fg=(1, 1, 1, 1), text_pos=(0.0, -0.15), text_shadow=(0, 0, 0, 0.35), text_shadowOffset=(-0.05, -0.05), # sounds that should be played rolloverSound=None, clickSound=None, pressEffect=False, relief=None, # the event which is thrown on clickSound command=lambda: base.messenger.send("options_back")) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.frameMain) self.hide() def show(self, enableResume=False): self.frameMain.show() def hide(self): self.frameMain.hide() def cbVolumeMute_CheckedChanged(self, checked): if checked: base.disableAllAudio() else: base.enableAllAudio() def sliderVolume_ValueChanged(self): volume = round(self.sliderVolume["value"], 2) self.sliderVolume["text"] = _("Volume %d%%") % int(volume * 100) base.sfxManagerList[0].setVolume(volume) base.musicManager.setVolume(volume) def sliderSensitivity_ValueChanged(self): sensitivity = round(self.sliderSensitivity["value"], 2) self.sliderSensitivity["text"] = _( "Mouse Sensitivity %0.1fx") % sensitivity base.mouseSensitivity = sensitivity def sliderTextspeed_ValueChanged(self): newSpeed = round(self.sliderTextspeed["value"], 2) displaySpeed = 1.0 / newSpeed self.sliderTextspeed["text"] = _("Textspeed %0.1f%%") % displaySpeed base.textWriteSpeed = newSpeed def cbParticles_CheckedChanged(self, unchecked): if unchecked: base.enableParticles() else: base.disableParticles() def controlType_Changed(self, arg): if arg == _("Keyboard"): self.sliderSensitivity.hide() base.controlType = "Gamepad" elif arg == _("Keyboard + Mouse"): self.sliderSensitivity.show() base.controlType = "MouseAndKeyboard"
class OptionsMenu(DirectObject): def __init__(self): """Default constructor""" # create a main frame as big as the window self.frameMain = DirectFrame( # set framesize the same size as the window frameSize = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), image = "LogoTextGlow.png", image_scale = (1.06/2.0, 1, 0.7/2.0), image_pos = (0, 0, 0.7), # position center pos = (0, 0, 0), # set tramsparent background color frameColor = (0, 0, 0, 0)) self.frameMain.setTransparency(1) self.frameMain.setBin("fixed", 100) sliderscale = 0.5 buttonScale = 0.25 textscale = 0.1 checkboxscale = 0.05 left = -0.5 right = 0.5 self.sliderTextspeed = DirectSlider( scale = sliderscale, pos = (left, 0, 0.2), range = (0.2,0.01), scrollSize = 0.01, text = _("Textspeed %0.1f%%")%(base.textWriteSpeed * 10), text_scale = textscale, text_align = TextNode.ACenter, text_pos = (0.0, 0.15), text_fg = (1,1,1,1), thumb_frameColor = (0.65, 0.65, 0.0, 1), thumb_relief = DGG.FLAT, frameColor = (0.15, 0.15, 0.15, 1), value = base.textWriteSpeed, command = self.sliderTextspeed_ValueChanged) self.sliderTextspeed.reparentTo(self.frameMain) self.cbParticles = DirectCheckButton( text = _(" Enable Particles"), text_fg = (1, 1, 1, 1), text_shadow = (0, 0, 0, 0.35), pos = (left, 0, -0.0), scale = checkboxscale, frameColor = (0,0,0,0), command = self.cbParticles_CheckedChanged, rolloverSound = None, clickSound = None, pressEffect = False, boxPlacement = "below", boxBorder = 0.8, boxRelief = DGG.FLAT, indicator_scale = 1.5, indicator_text_fg = (0.65, 0.65, 0.0, 1), indicator_text_shadow = (0, 0, 0, 0.35), indicator_frameColor = (0.15, 0.15, 0.15, 1), indicatorValue = base.particleMgrEnabled ) self.cbParticles.indicator['text'] = (' ', 'x') self.cbParticles.indicator['text_pos'] = (0, 0.1) #self.cbParticles.indicator.setX(self.cbParticles.indicator, -0.5) #self.cbParticles.indicator.setZ(self.cbParticles.indicator, -0.1) #self.cbParticles.setFrameSize() self.cbParticles.setTransparency(1) self.cbParticles.reparentTo(self.frameMain) volume = base.musicManager.getVolume() self.sliderVolume = DirectSlider( scale = sliderscale, pos = (left, 0, -0.35), range = (0,1), scrollSize = 0.01, text = _("Volume %d%%")%volume*100, text_scale = textscale, text_align = TextNode.ACenter, text_pos = (.0, 0.15), text_fg = (1,1,1,1), thumb_frameColor = (0.65, 0.65, 0.0, 1), thumb_relief = DGG.FLAT, frameColor = (0.15, 0.15, 0.15, 1), value = volume, command = self.sliderVolume_ValueChanged) self.sliderVolume.reparentTo(self.frameMain) self.lblControltype = DirectLabel( text = _("Control type"), text_fg = (1, 1, 1, 1), text_shadow = (0, 0, 0, 0.35), frameColor = (0, 0, 0, 0), scale = textscale/2, pos = (right, 0, 0.27)) self.lblControltype.setTransparency(1) self.lblControltype.reparentTo(self.frameMain) selectedControlType = 0 if base.controlType == "MouseAndKeyboard": selectedControlType = 1 self.controltype = DirectOptionMenu( pos = (right, 0, 0.18), text_fg = (1, 1, 1, 1), scale = 0.1, items = [_("Keyboard"),_("Keyboard + Mouse")], initialitem = selectedControlType, frameColor = (0.15, 0.15, 0.15, 1), popupMarker_frameColor = (0.65, 0.65, 0.0, 1), popupMarker_relief = DGG.FLAT, highlightColor = (0.65, 0.65, 0.0, 1), relief = DGG.FLAT, command=self.controlType_Changed) self.controltype.reparentTo(self.frameMain) b = self.controltype.getBounds() xPos = right - ((b[1] - b[0]) / 2.0 * 0.1) self.controltype.setX(xPos) setItems(self.controltype) self.controltype.setItems = setItems self.controltype.showPopupMenu = showPopupMenu self.controltype.popupMarker.unbind(DGG.B1PRESS) self.controltype.popupMarker.bind(DGG.B1PRESS, showPopupMenu) self.controltype.unbind(DGG.B1PRESS) self.controltype.bind(DGG.B1PRESS, showPopupMenuExtra, [self.controltype]) isChecked = not base.AppHasAudioFocus img = None if base.AppHasAudioFocus: img = "AudioSwitch_on.png" else: img = "AudioSwitch_off.png" self.cbVolumeMute = DirectCheckBox( text = _("Mute Audio"), text_scale = 0.5, text_align = TextNode.ACenter, text_pos = (0.0, 0.65), text_fg = (1,1,1,1), pos = (right, 0, -0.35), scale = 0.21/2.0, command = self.cbVolumeMute_CheckedChanged, rolloverSound = None, clickSound = None, relief = None, pressEffect = False, isChecked = isChecked, image = img, image_scale = 0.5, checkedImage = "AudioSwitch_off.png", uncheckedImage = "AudioSwitch_on.png") self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.setImage() self.cbVolumeMute.reparentTo(self.frameMain) sensitivity = base.mouseSensitivity self.sliderSensitivity = DirectSlider( scale = sliderscale, pos = (right, 0, -0.075), range = (0.5,2), scrollSize = 0.01, text = _("Mouse Sensitivity %0.1fx")%sensitivity, text_scale = textscale, text_align = TextNode.ACenter, text_pos = (.0, 0.15), text_fg = (1,1,1,1), thumb_frameColor = (0.65, 0.65, 0.0, 1), thumb_relief = DGG.FLAT, frameColor = (0.15, 0.15, 0.15, 1), value = sensitivity, command = self.sliderSensitivity_ValueChanged) self.sliderSensitivity.reparentTo(self.frameMain) if base.controlType == "Gamepad": self.sliderSensitivity.hide() # create the back button self.btnBack = DirectButton( scale = buttonScale, # position on the window pos = (0, 0, base.a2dBottom + 0.15), frameColor = (0,0,0,0), # text properties text = _("Back"), text_scale = 0.5, text_fg = (1,1,1,1), text_pos = (0.0, -0.15), text_shadow = (0, 0, 0, 0.35), text_shadowOffset = (-0.05, -0.05), # sounds that should be played rolloverSound = None, clickSound = None, pressEffect = False, relief = None, # the event which is thrown on clickSound command = lambda: base.messenger.send("options_back")) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.frameMain) self.hide() def show(self, enableResume=False): self.frameMain.show() def hide(self): self.frameMain.hide() def cbVolumeMute_CheckedChanged(self, checked): if checked: base.disableAllAudio() else: base.enableAllAudio() def sliderVolume_ValueChanged(self): volume = round(self.sliderVolume["value"], 2) self.sliderVolume["text"] = _("Volume %d%%") % int(volume * 100) base.sfxManagerList[0].setVolume(volume) base.musicManager.setVolume(volume) def sliderSensitivity_ValueChanged(self): sensitivity = round(self.sliderSensitivity["value"], 2) self.sliderSensitivity["text"] = _("Mouse Sensitivity %0.1fx") % sensitivity base.mouseSensitivity = sensitivity def sliderTextspeed_ValueChanged(self): newSpeed = round(self.sliderTextspeed["value"], 2) displaySpeed = 1.0 / newSpeed self.sliderTextspeed["text"] = _("Textspeed %0.1f%%")%displaySpeed base.textWriteSpeed = newSpeed def cbParticles_CheckedChanged(self, unchecked): if unchecked: base.enableParticles() else: base.disableParticles() def controlType_Changed(self, arg): if arg == _("Keyboard"): self.sliderSensitivity.hide() base.controlType = "Gamepad" elif arg == _("Keyboard + Mouse"): self.sliderSensitivity.show() base.controlType = "MouseAndKeyboard"
def _show_conf(self): """Show game configurations GUI.""" clear_wids(self.save_wids) clear_wids(self.tactics_wids) clear_wids(self.cred_wids) self.conf_wids.append( DirectLabel( # Resolution: parent=self._main_fr, text=base.labels.MAIN_MENU[22], # noqa: F821, text_fg=RUST_COL, text_scale=0.04, text_font=base.main_font, # noqa: F821 pos=(-0.3, 0, 0.5), frameColor=(0, 0, 0, 0), )) if base.game_config.resolution in RESOLUTIONS: # noqa: F821 res_ind = RESOLUTIONS.index( base.game_config.resolution) # noqa: F821 else: res_ind = len(RESOLUTIONS) RESOLUTIONS.append(base.game_config.resolution) # noqa: F821 res_chooser = ListChooser() res_chooser.prepare(self._main_fr, (0.1, 0, 0.51), RESOLUTIONS, res_ind) self.conf_wids.append(res_chooser) self.conf_wids.append( DirectLabel( # Tutorial: parent=self._main_fr, text=base.labels.MAIN_MENU[23], # noqa: F821, text_fg=RUST_COL, text_scale=0.04, text_font=base.main_font, # noqa: F821 pos=(-0.3, 0, 0.4), frameColor=(0, 0, 0, 0), )) tutorial_check = DirectCheckButton( parent=self._main_fr, indicatorValue=base.game_config.tutorial_enabled, # noqa: F821 clickSound=self.click_snd, scale=0.02, pos=(0.12, 0, 0.41), boxBorder=0, boxImage=(GUI_PIC + "no_check.png", GUI_PIC + "check.png", None), boxRelief=None, relief="flat", frameColor=RUST_COL, ) tutorial_check.setTransparency(TransparencyAttrib.MAlpha) self.conf_wids.append(tutorial_check) self.conf_wids.append( DirectLabel( # Language parent=self._main_fr, text=base.labels.MAIN_MENU[24], # noqa: F821, text_fg=RUST_COL, text_scale=0.04, text_font=base.main_font, # noqa: F821 pos=(-0.3, 0, 0.3), frameColor=(0, 0, 0, 0), )) lang_chooser = ListChooser() lang_chooser.prepare( self._main_fr, (0.1, 0, 0.31), LANGUAGES, LANGUAGES.index(base.game_config.language), # noqa: F821, ) self.conf_wids.append(lang_chooser) self.conf_wids.append( DirectLabel( # Framerate limit parent=self._main_fr, text=base.labels.MAIN_MENU[29], # noqa: F821, text_fg=RUST_COL, text_scale=0.04, text_font=base.main_font, # noqa: F821 pos=(-0.3, 0, 0.21), frameColor=(0, 0, 0, 0), )) fps_chooser = ListChooser() fps_chooser.prepare( self._main_fr, (0.1, 0, 0.22), FPS, FPS.index(str(base.game_config.fps_limit)), # noqa: F821 ) self.conf_wids.append(fps_chooser) self.conf_wids.append( DirectLabel( # FPS meter: parent=self._main_fr, text=base.labels.MAIN_MENU[36], # noqa: F821, text_fg=RUST_COL, text_scale=0.04, text_font=base.main_font, # noqa: F821 pos=(-0.3, 0, 0.11), frameColor=(0, 0, 0, 0), )) fps_meter = DirectCheckButton( parent=self._main_fr, indicatorValue=base.game_config.fps_meter, # noqa: F821 clickSound=self.click_snd, scale=0.02, pos=(0.12, 0, 0.12), boxBorder=0, boxImage=(GUI_PIC + "no_check.png", GUI_PIC + "check.png", None), boxRelief=None, relief="flat", frameColor=RUST_COL, ) fps_meter.setTransparency(TransparencyAttrib.MAlpha) self.conf_wids.append(fps_meter) self.conf_wids.append( DirectLabel( # Multi threading: parent=self._main_fr, text=base.labels.MAIN_MENU[37], # noqa: F821, text_fg=RUST_COL, text_scale=0.04, text_font=base.main_font, # noqa: F821 pos=(-0.3, 0, 0.01), frameColor=(0, 0, 0, 0), )) multi_threading = DirectCheckButton( parent=self._main_fr, indicatorValue=base.game_config.multi_threading, # noqa: F821 clickSound=self.click_snd, scale=0.02, pos=(0.12, 0, 0.02), boxBorder=0, boxImage=(GUI_PIC + "no_check.png", GUI_PIC + "check.png", None), boxRelief=None, relief="flat", frameColor=RUST_COL, ) multi_threading.setTransparency(TransparencyAttrib.MAlpha) self.conf_wids.append(multi_threading) self.conf_wids.append( DirectLabel( # Multi threading: parent=self._main_fr, text=base.labels.MAIN_MENU[38], # noqa: F821, text_fg=SILVER_COL, text_scale=0.025, text_font=base.main_font, # noqa: F821 pos=(-0.3, 0, -0.03), frameColor=(0, 0, 0, 0), )) but = DirectButton( # Save and restart parent=self._main_fr, text_scale=0.045, text_fg=RUST_COL, text=base.labels.MAIN_MENU[25], # noqa: F821, text_font=base.main_font, # noqa: F821 relief=None, command=self._save_conf_and_restart, extraArgs=[ res_chooser, tutorial_check, lang_chooser, fps_chooser, fps_meter, multi_threading, ], pos=(0.1, 0, -0.2), clickSound=self.click_snd, ) self.bind_button(but) self.conf_wids.append(but)