def __init__(self, text, command): self.charGui = loader.loadModel('models/gui/toplevel_gui') uncheckedImage = (self.charGui.find('**/main_gui_checkbox_off'), self.charGui.find('**/main_gui_checkbox_halfcheck'), self.charGui.find('**/main_gui_checkbox_off_over'), self.charGui.find('**/main_gui_checkbox_off_disable')) checkedImage = (self.charGui.find('**/main_gui_checkbox_on'), self.charGui.find('**/main_gui_checkbox_halfcheck'), self.charGui.find('**/main_gui_checkbox_on_over'), self.charGui.find('**/main_gui_checkbox_on_disable')) DirectCheckBox.__init__(self, relief = None, pos = (0, 0, 0), text = text, text_scale = PiratesGuiGlobals.TextScaleLarge, text_align = TextNode.ACenter, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_pos = (0.080000000000000002, 0.025000000000000001), image = uncheckedImage, image_scale = (0.070000000000000007, 0.070000000000000007, 0.070000000000000007), image_pos = (-0.01, 0.0, 0.035000000000000003), command = command, uncheckedImage = uncheckedImage, checkedImage = checkedImage) self.initialiseoptions(CheckBox) self.charGui.removeNode()
def __init__(self, text, command): self.charGui = loader.loadModel('models/gui/toplevel_gui') uncheckedImage = ( self.charGui.find('**/main_gui_checkbox_off'), self.charGui.find('**/main_gui_checkbox_halfcheck'), self.charGui.find('**/main_gui_checkbox_off_over'), self.charGui.find('**/main_gui_checkbox_off_disable')) checkedImage = (self.charGui.find('**/main_gui_checkbox_on'), self.charGui.find('**/main_gui_checkbox_halfcheck'), self.charGui.find('**/main_gui_checkbox_on_over'), self.charGui.find('**/main_gui_checkbox_on_disable')) DirectCheckBox.__init__(self, relief=None, pos=(0, 0, 0), text=text, text_scale=PiratesGuiGlobals.TextScaleLarge, text_align=TextNode.ACenter, text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, text_pos=(0.080000000000000002, 0.025000000000000001), image=uncheckedImage, image_scale=(0.070000000000000007, 0.070000000000000007, 0.070000000000000007), image_pos=(-0.01, 0.0, 0.035000000000000003), command=command, uncheckedImage=uncheckedImage, checkedImage=checkedImage) self.initialiseoptions(CheckBox) self.charGui.removeNode()
class BetterCheckbox(DebugObject): def __init__(self, parent=None, x=0, y=0, callback=None, extraArgs=None, radio=False, expandW=100, checked=False): DebugObject.__init__(self, "BCheckbox") prefix = "Checkbox" if not radio else "Radiobox" checkedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Active.png") uncheckedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Empty.png") for tex in [checkedImg, uncheckedImg]: tex.setMinfilter(Texture.FTNearest) tex.setMagfilter(Texture.FTNearest) tex.setAnisotropicDegree(0) tex.setWrapU(Texture.WMClamp) tex.setWrapV(Texture.WMClamp) self._node = DirectCheckBox(parent=parent, pos=( x + 7.5, 1, -y - 7.5), scale=(15 / 2.0, 1, 15 / 2.0), checkedImage=checkedImg, uncheckedImage=uncheckedImg, image=uncheckedImg, extraArgs = extraArgs, state=DGG.NORMAL, relief=DGG.FLAT, command=self._updateStatus) self._node["frameColor"] = (0, 0, 0, 0.0) self._node["frameSize"] = (-2, 2 + expandW / 7.5, -1.6, 1.6) self._node.setTransparency(TransparencyAttrib.MAlpha) self.callback = callback self.extraArgs = extraArgs self.collection = None if checked: self._setChecked(True) def _setCollection(self, coll): self.collection = coll def _updateStatus(self, status, *args): if self.collection: if status: self.collection._changed(self) # A radio box can't be unchecked self._node["state"] = DGG.DISABLED if self.callback is not None: self.callback(*([status] + self.extraArgs)) def _setChecked(self, val): self._node["isChecked"] = val if val: self._node['image'] = self._node['checkedImage'] else: self._node['image'] = self._node['uncheckedImage'] if self.callback is not None: self.callback(*([val] + self.extraArgs))
def __init__(self, parent=None, x=0, y=0, callback=None, extra_args=None, radio=False, expand_width=100, checked=False, enabled=True): RPObject.__init__(self) prefix = "checkbox" if not radio else "radiobox" if enabled: checked_img = RPLoader.load_texture("/$$rp/data/gui/" + prefix + "_checked.png") unchecked_img = RPLoader.load_texture("/$$rp/data/gui/" + prefix + "_default.png") else: checked_img = RPLoader.load_texture("/$$rp/data/gui/" + prefix + "_disabled.png") unchecked_img = checked_img # Set near filter, otherwise textures look like crap for tex in [checked_img, unchecked_img]: tex.set_minfilter(SamplerState.FT_linear) tex.set_magfilter(SamplerState.FT_linear) tex.set_wrap_u(SamplerState.WM_clamp) tex.set_wrap_v(SamplerState.WM_clamp) tex.set_anisotropic_degree(0) self._node = DirectCheckBox(parent=parent, pos=(x + 11, 1, -y - 8), scale=(10 / 2.0, 1, 10 / 2.0), checkedImage=checked_img, uncheckedImage=unchecked_img, image=unchecked_img, extraArgs=extra_args, state=DGG.NORMAL, relief=DGG.FLAT, command=self._update_status) self._node["frameColor"] = (0, 0, 0, 0) self._node["frameSize"] = (-2.6, 2 + expand_width / 7.5, -2.35, 2.5) self._node.set_transparency(TransparencyAttrib.M_alpha) self._callback = callback self._extra_args = extra_args self._collection = None if checked: self.set_checked(True, False)
def __init__(self, parent=None, x=0, y=0, callback=None, extraArgs=None, radio=False, expandW=100, checked=False): DebugObject.__init__(self, "BetterCheckbox") prefix = "Checkbox" if not radio else "Radiobox" checkedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Active.png") uncheckedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Empty.png") # Set near filter, otherwise textures look like crap for tex in [checkedImg, uncheckedImg]: tex.setMinfilter(Texture.FTNearest) tex.setMagfilter(Texture.FTNearest) tex.setAnisotropicDegree(0) tex.setWrapU(Texture.WMClamp) tex.setWrapV(Texture.WMClamp) self._node = DirectCheckBox(parent=parent, pos=(x + 7.5, 1, -y - 7.5), scale=(15 / 2.0, 1, 15 / 2.0), checkedImage=checkedImg, uncheckedImage=uncheckedImg, image=uncheckedImg, extraArgs=extraArgs, state=DGG.NORMAL, relief=DGG.FLAT, command=self._updateStatus) self._node["frameColor"] = (0, 0, 0, 0.0) self._node["frameSize"] = (-2, 2 + expandW / 7.5, -1.6, 1.6) self._node.setTransparency(TransparencyAttrib.MAlpha) self.callback = callback self.extraArgs = extraArgs self.collection = None if checked: self._setChecked(True)
def __init__(self, parent=None, x=0, y=0, callback=None, extraArgs=None, radio=False, expandW=100, checked=False): DebugObject.__init__(self, "BCheckbox") prefix = "Checkbox" if not radio else "Radiobox" checkedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Active.png") uncheckedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Empty.png") for tex in [checkedImg, uncheckedImg]: tex.setMinfilter(Texture.FTNearest) tex.setMagfilter(Texture.FTNearest) tex.setAnisotropicDegree(0) tex.setWrapU(Texture.WMClamp) tex.setWrapV(Texture.WMClamp) self._node = DirectCheckBox(parent=parent, pos=( x + 7.5, 1, -y - 7.5), scale=(15 / 2.0, 1, 15 / 2.0), checkedImage=checkedImg, uncheckedImage=uncheckedImg, image=uncheckedImg, extraArgs = extraArgs, state=DGG.NORMAL, relief=DGG.FLAT, command=self._updateStatus) self._node["frameColor"] = (0, 0, 0, 0.0) self._node["frameSize"] = (-2, 2 + expandW / 7.5, -1.6, 1.6) self._node.setTransparency(TransparencyAttrib.MAlpha) self.callback = callback self.extraArgs = extraArgs self.collection = None if checked: self._setChecked(True)
def createDirectCheckBox(self, parent=None): parent = self.getEditorRootCanvas() if parent is None else parent pos = self.editorCenter if parent == self.getEditorRootCanvas() else (0,0,0) if self.visEditorInAspect2D: element = DirectCheckBox( #image="icons/minusnode.gif", #uncheckedImage="icons/minusnode.gif", #checkedImage="icons/plusnode.gif", parent=parent, scale=0.1) else: element = DirectCheckBox( pos=pos, borderWidth=(2, 2), #image="icons/minusnode.gif", #uncheckedImage="icons/minusnode.gif", #checkedImage="icons/plusnode.gif", parent=parent, scale=1) elementInfo = ElementInfo(element, "DirectCheckBox") self.setupBind(elementInfo) return elementInfo
def __init__(self, parent=None, x=0, y=0, callback=None, extra_args=None, radio=False, expand_width=100, checked=False, enabled=True): RPObject.__init__(self) prefix = "checkbox" if not radio else "radiobox" if enabled: checked_img = RPLoader.load_texture( "/$$rp/data/gui/" + prefix + "_checked.png") unchecked_img = RPLoader.load_texture( "/$$rp/data/gui/" + prefix + "_default.png") else: checked_img = RPLoader.load_texture( "/$$rp/data/gui/" + prefix + "_disabled.png") unchecked_img = checked_img # Set near filter, otherwise textures look like crap for tex in [checked_img, unchecked_img]: tex.set_minfilter(SamplerState.FT_linear) tex.set_magfilter(SamplerState.FT_linear) tex.set_wrap_u(SamplerState.WM_clamp) tex.set_wrap_v(SamplerState.WM_clamp) tex.set_anisotropic_degree(0) self._node = DirectCheckBox( parent=parent, pos=(x + 11, 1, -y - 8), scale=(10 / 2.0, 1, 10 / 2.0), checkedImage=checked_img, uncheckedImage=unchecked_img, image=unchecked_img, extraArgs=extra_args, state=DGG.NORMAL, relief=DGG.FLAT, command=self._update_status) self._node["frameColor"] = (0, 0, 0, 0) self._node["frameSize"] = (-2.6, 2 + expand_width / 7.5, -2.35, 2.5) self._node.set_transparency(TransparencyAttrib.M_alpha) self._callback = callback self._extra_args = extra_args self._collection = None if checked: self.set_checked(True, False)
class Checkbox(RPObject): """ This is a wrapper around DirectCheckBox, providing a simpler interface and better visuals """ def __init__(self, parent=None, x=0, y=0, callback=None, extra_args=None, radio=False, expand_width=100, checked=False, enabled=True): RPObject.__init__(self) prefix = "checkbox" if not radio else "radiobox" if enabled: checked_img = RPLoader.load_texture("/$$rp/data/gui/" + prefix + "_checked.png") unchecked_img = RPLoader.load_texture("/$$rp/data/gui/" + prefix + "_default.png") else: checked_img = RPLoader.load_texture("/$$rp/data/gui/" + prefix + "_disabled.png") unchecked_img = checked_img # Set near filter, otherwise textures look like crap for tex in [checked_img, unchecked_img]: tex.set_minfilter(SamplerState.FT_linear) tex.set_magfilter(SamplerState.FT_linear) tex.set_wrap_u(SamplerState.WM_clamp) tex.set_wrap_v(SamplerState.WM_clamp) tex.set_anisotropic_degree(0) self._node = DirectCheckBox(parent=parent, pos=(x + 11, 1, -y - 8), scale=(10 / 2.0, 1, 10 / 2.0), checkedImage=checked_img, uncheckedImage=unchecked_img, image=unchecked_img, extraArgs=extra_args, state=DGG.NORMAL, relief=DGG.FLAT, command=self._update_status) self._node["frameColor"] = (0, 0, 0, 0) self._node["frameSize"] = (-2.6, 2 + expand_width / 7.5, -2.35, 2.5) self._node.set_transparency(TransparencyAttrib.M_alpha) self._callback = callback self._extra_args = extra_args self._collection = None if checked: self.set_checked(True, False) @property def collection(self): """ Returns a handle to the assigned checkbox collection, or None if no collection was assigned """ return self._collection @collection.setter def collection(self, coll): """ Internal method to add a checkbox to a checkbox collection, this is used for radio-buttons """ self._collection = coll @property def checked(self): """ Returns whether the node is currently checked """ return self._node["isChecked"] @property def node(self): """ Returns a handle to the internally used node """ return self._node def _update_status(self, status): """ Internal method when another checkbox in the same radio group changed it's value """ if not status and self._collection: self._node.commandFunc(None) return if self._collection: if status: self._collection.on_checkbox_changed(self) # A radio box can't be unchecked # self._node["state"] = DGG.DISABLED if self._callback is not None: self._callback(*([status] + self._extra_args)) def set_checked(self, val, do_callback=True): """ Internal method to check/uncheck the checkbox """ self._node["isChecked"] = val if val: self._node["image"] = self._node["checkedImage"] else: self._node["image"] = self._node["uncheckedImage"] if do_callback and self._callback is not None: self._callback(*([val] + self._extra_args))
class Checkbox(RPObject): """ This is a wrapper around DirectCheckBox, providing a simpler interface and better visuals """ def __init__(self, parent=None, x=0, y=0, callback=None, extra_args=None, radio=False, expand_width=100, checked=False, enabled=True): RPObject.__init__(self) prefix = "checkbox" if not radio else "radiobox" if enabled: checked_img = RPLoader.load_texture( "/$$rp/data/gui/" + prefix + "_checked.png") unchecked_img = RPLoader.load_texture( "/$$rp/data/gui/" + prefix + "_default.png") else: checked_img = RPLoader.load_texture( "/$$rp/data/gui/" + prefix + "_disabled.png") unchecked_img = checked_img # Set near filter, otherwise textures look like crap for tex in [checked_img, unchecked_img]: tex.set_minfilter(SamplerState.FT_linear) tex.set_magfilter(SamplerState.FT_linear) tex.set_wrap_u(SamplerState.WM_clamp) tex.set_wrap_v(SamplerState.WM_clamp) tex.set_anisotropic_degree(0) self._node = DirectCheckBox( parent=parent, pos=(x + 11, 1, -y - 8), scale=(10 / 2.0, 1, 10 / 2.0), checkedImage=checked_img, uncheckedImage=unchecked_img, image=unchecked_img, extraArgs=extra_args, state=DGG.NORMAL, relief=DGG.FLAT, command=self._update_status) self._node["frameColor"] = (0, 0, 0, 0) self._node["frameSize"] = (-2.6, 2 + expand_width / 7.5, -2.35, 2.5) self._node.set_transparency(TransparencyAttrib.M_alpha) self._callback = callback self._extra_args = extra_args self._collection = None if checked: self.set_checked(True, False) @property def collection(self): """ Returns a handle to the assigned checkbox collection, or None if no collection was assigned """ return self._collection @collection.setter def collection(self, coll): """ Internal method to add a checkbox to a checkbox collection, this is used for radio-buttons """ self._collection = coll @property def checked(self): """ Returns whether the node is currently checked """ return self._node["isChecked"] @property def node(self): """ Returns a handle to the internally used node """ return self._node def _update_status(self, status): """ Internal method when another checkbox in the same radio group changed it's value """ if not status and self._collection: self._node.commandFunc(None) return if self._collection: if status: self._collection.on_checkbox_changed(self) # A radio box can't be unchecked # self._node["state"] = DGG.DISABLED if self._callback is not None: self._callback(*([status] + self._extra_args)) def set_checked(self, val, do_callback=True): """ Internal method to check/uncheck the checkbox """ self._node["isChecked"] = val if val: self._node["image"] = self._node["checkedImage"] else: self._node["image"] = self._node["uncheckedImage"] if do_callback and self._callback is not None: self._callback(*([val] + self._extra_args))
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()
class BetterCheckbox(DebugObject): """ This is a wrapper arround DirectCheckBox, providing a simpler interface and better visuals """ def __init__(self, parent=None, x=0, y=0, callback=None, extraArgs=None, radio=False, expandW=100, checked=False): DebugObject.__init__(self, "BetterCheckbox") prefix = "Checkbox" if not radio else "Radiobox" checkedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Active.png") uncheckedImg = Globals.loader.loadTexture("Data/GUI/" + prefix + "Empty.png") # Set near filter, otherwise textures look like crap for tex in [checkedImg, uncheckedImg]: tex.setMinfilter(Texture.FTNearest) tex.setMagfilter(Texture.FTNearest) tex.setAnisotropicDegree(0) tex.setWrapU(Texture.WMClamp) tex.setWrapV(Texture.WMClamp) self._node = DirectCheckBox(parent=parent, pos=(x + 7.5, 1, -y - 7.5), scale=(15 / 2.0, 1, 15 / 2.0), checkedImage=checkedImg, uncheckedImage=uncheckedImg, image=uncheckedImg, extraArgs=extraArgs, state=DGG.NORMAL, relief=DGG.FLAT, command=self._updateStatus) self._node["frameColor"] = (0, 0, 0, 0.0) self._node["frameSize"] = (-2, 2 + expandW / 7.5, -1.6, 1.6) self._node.setTransparency(TransparencyAttrib.MAlpha) self.callback = callback self.extraArgs = extraArgs self.collection = None if checked: self._setChecked(True) def _setCollection(self, coll): """ Internal method to add a checkbox to a checkbox collection, this is used for radio-buttons """ self.collection = coll def _updateStatus(self, status, *args): """ Internal method when another checkbox in the same radio group changed it's value """ if self.collection: if status: self.collection._changed(self) # A radio box can't be unchecked self._node["state"] = DGG.DISABLED if self.callback is not None: self.callback(*([status] + self.extraArgs)) def _setChecked(self, val): """ Internal method to check/uncheck the checkbox """ self._node["isChecked"] = val if val: self._node['image'] = self._node['checkedImage'] else: self._node['image'] = self._node['uncheckedImage'] if self.callback is not None: self.callback(*([val] + self.extraArgs))
def __makeStructureFrameTreeItem(self, elementNP, elementInfo, parentsLevel, z): if elementInfo is None: lbl = DirectLabel(text=elementNP.getName(), text_align=TextNode.ALeft, frameColor=(0, 0, 0, 0), relief=DGG.FLAT, pos=(self.structureFrame["frameSize"][0] + 20 * parentsLevel, 0, z), scale=16, parent=self.structureFrame.getCanvas()) self.maxWidth = max( self.maxWidth, lbl.getX() + lbl.getWidth() * lbl.getScale()[0]) else: margin = 5 shift = 6 if hasattr(elementNP, "getChildren"): if len(elementNP.getChildren()) > 0: # Collapse Button btnC = DirectCheckBox( relief=DGG.FLAT, pos=(self.structureFrame["frameSize"][0] + 20 * parentsLevel - 16 + margin, 0, z + shift), frameSize=(-8, 8, -8, 8), frameColor=(0, 0, 0, 0), command=self.__collapseElement, extraArgs=[elementInfo], image="icons/Collapsed.png" if elementInfo in self.collapsedElements else "icons/Collapse.png", uncheckedImage="icons/Collapse.png", checkedImage="icons/Collapsed.png", image_scale=8, isChecked=elementInfo in self.collapsedElements, parent=self.structureFrame.getCanvas()) btnC.setTransparency(TransparencyAttrib.M_alpha) btnC.bind(DGG.MWDOWN, self.scroll, [0.01]) btnC.bind(DGG.MWUP, self.scroll, [-0.01]) # Element Name btn = DirectButton( frameColor=( VBase4(1, 1, 1, 1), #normal VBase4(0.9, 0.9, 0.9, 1), #click VBase4(0.8, 0.8, 0.8, 1), #hover VBase4(0.5, 0.5, 0.5, 1)), #disabled text=elementInfo.name, text_align=TextNode.ALeft, relief=DGG.FLAT, pos=(self.structureFrame["frameSize"][0] + 20 * parentsLevel, 0, z), scale=16, command=self.__selectElement, extraArgs=[elementInfo], parent=self.structureFrame.getCanvas()) btn.bind(DGG.MWDOWN, self.scroll, [0.01]) btn.bind(DGG.MWUP, self.scroll, [-0.01]) if self.selectedElement is not None and self.selectedElement == elementInfo: btn.setColorScale(1, 1, 0, 1) # Delete Button btnX = DirectButton( relief=DGG.FLAT, pos=(self.structureFrame["frameSize"][0] + 8 + margin + 20 * parentsLevel + btn.getWidth() * btn.getScale()[0], 0, z + shift), frameSize=(-8, 8, -8, 8), frameColor=(0, 0, 0, 0), command=self.__removeElement, extraArgs=[elementInfo], image="icons/DeleteSmall.png", image_scale=8, parent=self.structureFrame.getCanvas()) btnX.setTransparency(TransparencyAttrib.M_multisample) btnX.bind(DGG.MWDOWN, self.scroll, [0.01]) btnX.bind(DGG.MWUP, self.scroll, [-0.01]) # Visibility Button btnV = DirectCheckBox( relief=DGG.FLAT, pos=(self.structureFrame["frameSize"][0] + 8 + margin * 2 + 20 * parentsLevel + btn.getWidth() * btn.getScale()[0] + btnX.getWidth(), 0, z + shift), frameSize=(-8, 8, -8, 8), frameColor=(0, 0, 0, 0), command=self.__toggleElementVisibility, extraArgs=[elementInfo], image="icons/VisibilityOffSmall.png" if elementInfo.element.isHidden() else "icons/VisibilityOnSmall.png", uncheckedImage="icons/VisibilityOffSmall.png", checkedImage="icons/VisibilityOnSmall.png", image_scale=8, isChecked=not elementInfo.element.isHidden(), parent=self.structureFrame.getCanvas()) btnV.setTransparency(TransparencyAttrib.M_multisample) btnV.bind(DGG.MWDOWN, self.scroll, [0.01]) btnV.bind(DGG.MWUP, self.scroll, [-0.01]) self.maxWidth = max(self.maxWidth, btnV.getX() + 8)
class BetterCheckbox(DebugObject): """ This is a wrapper around DirectCheckBox, providing a simpler interface and better visuals """ def __init__(self, parent=None, x=0, y=0, callback=None, extraArgs=None, radio=False, expandW=100, checked=False): DebugObject.__init__(self, "BetterCheckbox") prefix = "Checkbox" if not radio else "Radiobox" checkedImg = Globals.loader.loadTexture( "Data/GUI/" + prefix + "Active.png") uncheckedImg = Globals.loader.loadTexture( "Data/GUI/" + prefix + "Empty.png") # Set near filter, otherwise textures look like crap for tex in [checkedImg, uncheckedImg]: tex.setMinfilter(Texture.FTNearest) tex.setMagfilter(Texture.FTNearest) tex.setAnisotropicDegree(0) tex.setWrapU(Texture.WMClamp) tex.setWrapV(Texture.WMClamp) self._node = DirectCheckBox(parent=parent, pos=( x + 7.5, 1, -y - 7.5), scale=(15 / 2.0, 1, 15 / 2.0), checkedImage=checkedImg, uncheckedImage=uncheckedImg, image=uncheckedImg, extraArgs = extraArgs, state=DGG.NORMAL, relief=DGG.FLAT, command=self._updateStatus) self._node["frameColor"] = (0, 0, 0, 0.0) self._node["frameSize"] = (-2, 2 + expandW / 7.5, -1.6, 1.6) self._node.setTransparency(TransparencyAttrib.MAlpha) self.callback = callback self.extraArgs = extraArgs self.collection = None if checked: self._setChecked(True) def _setCollection(self, coll): """ Internal method to add a checkbox to a checkbox collection, this is used for radio-buttons """ self.collection = coll def _updateStatus(self, status, *args): """ Internal method when another checkbox in the same radio group changed it's value """ if self.collection: if status: self.collection._changed(self) # A radio box can't be unchecked self._node["state"] = DGG.DISABLED if self.callback is not None: self.callback(*([status] + self.extraArgs)) def _setChecked(self, val): """ Internal method to check/uncheck the checkbox """ self._node["isChecked"] = val if val: self._node['image'] = self._node['checkedImage'] else: self._node['image'] = self._node['uncheckedImage'] if self.callback is not None: self.callback(*([val] + self.extraArgs))
class MainMenu(DirectObject): """This class represents the main menu as seen directly after the application has been started""" def __init__(self): # loading music self.menuMusic = loader.loadMusic("music/01Menu.mp3") self.menuMusic.setLoop(True) # 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), # position center pos = (0, 0, 0), # set tramsparent background color frameColor = (0.15, 0.15, 0.15, 1)) #self.frameMain.reparentTo(render2d) self.menuBackground = OnscreenImage( image = 'gui/Background.png', scale = (1.66, 1, 1), pos = (0, 0, 0)) self.menuBackground.reparentTo(self.frameMain) self.defaultBtnMap = base.loader.loadModel("gui/button_map") self.buttonGeom = ( self.defaultBtnMap.find("**/button_ready"), self.defaultBtnMap.find("**/button_click"), self.defaultBtnMap.find("**/button_rollover"), self.defaultBtnMap.find("**/button_disabled")) self.defaultTxtMap = base.loader.loadModel("gui/textbox_map") self.textboxGeom = self.defaultTxtMap.find("**/textbox") monospace = loader.loadFont('gui/DejaVuSansMono.ttf') defaultFont = loader.loadFont('gui/eufm10.ttf') # create the title self.textscale = 0.25 self.title = DirectLabel( # scale and position scale = self.textscale, pos = (0.0, 0.0, base.a2dTop - self.textscale), # frame frameColor = (0, 0, 0, 0), # Text text = "Dungeon Crawler", text_align = TextNode.ACenter, text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont) self.title.setTransparency(1) self.title.reparentTo(self.frameMain) # create a host button self.btnHostPos = Vec3(0, 0, .45) self.btnHostScale = 0.25 self.btnHost = DirectButton( # Scale and position scale = self.btnHostScale, pos = self.btnHostPos, # Text text = "Host", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, # Frame geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, # Functionality command = self.host, rolloverSound = None, clickSound = None) self.btnHost.setTransparency(1) self.btnHost.reparentTo(self.frameMain) # create a join button self.btnJoinPos = Vec3(0, 0, 0) self.btnJoinScale = 0.25 self.btnJoin = DirectButton( scale = self.btnJoinScale, pos = self.btnJoinPos, text = "Join", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, command = self.join, rolloverSound = None, clickSound = None) self.btnJoin.setTransparency(1) self.btnJoin.reparentTo(self.frameMain) # create the IP input field self.txtIPPos = Vec3(0, 0, -.30) self.txtIPScale = 0.25 self.txtIPWidth = 9 self.txtIP = DirectEntry( # scale and position pos = self.txtIPPos, scale = self.txtIPScale, width = self.txtIPWidth, # Text entryFont = monospace, text_align = TextNode.ACenter, text = "", text_scale = 0.5, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (0.04, 0.04), initialText = "127.0.0.1", numLines = 1, # Frame geom = self.textboxGeom, frameColor = (0, 0, 0, 0), relief = 0, # Functionality command = self.join, focusInCommand = self.clearText) self.txtIP.reparentTo(self.frameMain) # create an exit button self.btnExitPos = Vec3(0, 0, -.75) self.btnExitScale = 0.25 self.btnExit = DirectButton( scale = self.btnExitScale, pos = self.btnExitPos, text = "Exit", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, command = lambda: base.messenger.send("escape"), rolloverSound = None, clickSound = None) self.btnExit.setTransparency(1) self.btnExit.reparentTo(self.frameMain) # create a mute checkbox self.cbVolumeMute = DirectCheckBox( # set size scale = (0.1, 0.1, 0.1), frameSize = (-1, 1, 1, -1), # functionality and visuals command = self.cbVolumeMute_CheckedChanged, isChecked = True, checkedImage = "gui/SoundSwitch_off.png", uncheckedImage = "gui/SoundSwitch_on.png", # mouse behaviour relief = 0, pressEffect = False, rolloverSound = None, clickSound = None ) self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.reparentTo(self.frameMain) self.cbVolumeMute.commandFunc(None) # catch window resizes and recalculate the aspectration self.accept("window-event", self.recalcAspectRatio) self.accept("showerror", self.showError) # show the menu right away self.show() def host(self): """Function which will be called by pressing the host button""" self.hide() base.messenger.send("start_server") def join(self, ip=None): """Function which will be called by pressing the join button""" if ip == None: ip = self.txtIP.get(True) if ip == "": return self.hide() base.messenger.send("start_client", [ip]) def showError(self, msg): self.show() self.dialog = OkDialog( dialogName="ErrorDialog", text="Error: {}".format(msg), command=self.closeDialog) def closeDialog(self, args): self.dialog.hide() def show(self): """Show the GUI""" self.frameMain.show() self.menuMusic.play() def hide(self): """Hide the GUI""" self.frameMain.hide() self.menuMusic.stop() def clearText(self): """Function to clear the text that was previously entered in the IP input field""" self.txtIP.enterText("") def cbVolumeMute_CheckedChanged(self, checked): if bool(checked): base.disableAllAudio() else: base.enableAllAudio() def recalcAspectRatio(self, window): """get the new aspect ratio to resize the mainframe""" # set the mainframe size to the window borders again self.frameMain["frameSize"] = ( base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom) # calculate new aspec tratio wp = window.getProperties() aspX = 1.0 aspY = 1.0 wpXSize = wp.getXSize() wpYSize = wp.getYSize() if wpXSize > wpYSize: aspX = wpXSize / float(wpYSize) else: aspY = wpYSize / float(wpXSize) # calculate new position/size/whatever of the gui items self.title.setPos(0.0, 0.0, base.a2dTop - self.textscale) self.menuBackground.setScale(1.0 * aspX, 1.0, 1.0 * aspY) self.cbVolumeMute.setPos(base.a2dRight - 0.15, 0, base.a2dBottom + 0.15)
def initGeneralTab(self): """ This function will set up the content of the general tab """ self.frameGeneral = DirectFrame( # size of the frame frameSize = (base.a2dLeft, base.a2dRight, -0.6, 0.6), # position of the frame pos = (0, 0, 0), # tramsparent bg color frameColor = (0, 0, 0, 0.5)) yPos = 0.45 shiftY = 0.25 self.lblLanguage = DirectLabel( text = _("Language"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.cmbLanguage = DirectOptionMenu( text = "languages", scale = 0.15, pos = (base.a2dRight - 1.5, 0, 0.45), items = ["Deutsch","English","русский", "français"], initialitem = 0, highlightColor = (0.65,0.65,0.65,1), #text_font = self.defaultFontRegular, #item_text_font = self.defaultFontRegular, command = self.cmbLanguage_SelectionChanged) yPos -= shiftY self.lblResolution = DirectLabel( text = _("Screen resolution"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) # get the display resolutions di = base.pipe.getDisplayInformation() sizes = [] for index in range(di.getTotalDisplayModes()): tmptext = "{0}x{1}".format( di.getDisplayModeWidth(index), di.getDisplayModeHeight(index)) if not tmptext in sizes: sizes.append(tmptext) self.cmbResolution = DirectOptionMenu( text = "resolutions", scale = 0.15, pos = (base.a2dRight - 1.5, 0, yPos), items = sizes, initialitem = 0, highlightColor = (0.65, 0.65, 0.65, 1), #text_font = self.defaultFontRegular, #item_text_font = self.defaultFontRegular, command = self.cmbResolution_SelectionChanged) yPos -= shiftY self.lblGraphicQuality = DirectLabel( text = _("Graphic quality"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.graphicqualityTextMap = { 0:_("Low"), 1:_("Medium"), 2:_("High")} self.sliderGraphicQuality = DirectSlider( scale = 0.5, pos = (base.a2dRight - 1, 0, yPos + 0.05), range = (0,2), scrollSize = 1, text = self.graphicqualityTextMap[self.engine.settings.graphicquality], text_scale = 0.25, text_align = TextNode.ALeft, text_pos = (1.1, -0.1), text_fg = (1,1,1,1), #text_font = self.defaultFont, value = self.engine.settings.graphicquality, command = self.sliderGraphicQuality_ValueChanged) yPos -= shiftY self.lblVolume = DirectLabel( text = _("Volume"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.sliderVolume = DirectSlider( scale = 0.5, pos = (base.a2dRight - 1, 0, yPos + 0.05), range = (0,1), scrollSize = 0.01, text = str(int(self.engine.settings.volume * 100)) + "%", text_scale = 0.25, text_align = TextNode.ALeft, text_pos = (1.1, -0.1), text_fg = (1,1,1,1), #text_font = self.defaultFont, value = self.engine.settings.volume, command = self.sliderVolume_ValueChanged) yPos -= shiftY self.lblVolumeMute = DirectLabel( text = _("Mute"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.cbVolumeMute = DirectCheckBox( text = "X", pos = (base.a2dRight - 1, 0, yPos), scale = (0.25, 0.25, 0.25), command = self.cbVolumeMute_CheckedChanged, rolloverSound = None, clickSound = None, relief = 0, pressEffect = False, #frameColor = (0,0,0,0), checkedImage = "gui/buttons/options/SoundSwitch_off.png", uncheckedImage = "gui/buttons/options/SoundSwitch_on.png" ) self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.setImage() self.cbVolumeMute["image_scale"] = 0.25 self.cbVolumeMute["text"] = "" self.createBackButton(self.btnBack_Click) self.lblLanguage.reparentTo(self.frameGeneral) self.cmbLanguage.reparentTo(self.frameGeneral) self.lblResolution.reparentTo(self.frameGeneral) self.cmbResolution.reparentTo(self.frameGeneral) self.lblGraphicQuality.reparentTo(self.frameGeneral) self.sliderGraphicQuality.reparentTo(self.frameGeneral) self.lblVolume.reparentTo(self.frameGeneral) self.sliderVolume.reparentTo(self.frameGeneral) self.lblVolumeMute.reparentTo(self.frameGeneral) self.cbVolumeMute.reparentTo(self.frameGeneral) self.frameGeneral.reparentTo(self.frameMain) self.accept("LanguageChanged", self.setText)
class MenuOptions(Menu): def __init__(self, _engine): """ This function will initialise the main screen of the options and prepare the tabs with the various settings """ Menu.__init__(self) # Engine self.engine = _engine self.initGeneralTab() self.initControlTab() self.currentTab = [0] self.tabGroup = [ DirectRadioButton( text = _("General"), variable = self.currentTab, value = [0], scale = 0.05, pos = (-0.6, 0, 0.65), command = self.showGeneralTab), DirectRadioButton( text = _("Controls"), variable = self.currentTab, value = [1], scale = 0.05, pos = (0.6, 0, 0.65), command = self.showControlTab) ] for tab in self.tabGroup: tab.reparentTo(self.frameMain) tab.setOthers(self.tabGroup) # set the text of all GUI elements self.setText() self.hideBase() def initGeneralTab(self): """ This function will set up the content of the general tab """ self.frameGeneral = DirectFrame( # size of the frame frameSize = (base.a2dLeft, base.a2dRight, -0.6, 0.6), # position of the frame pos = (0, 0, 0), # tramsparent bg color frameColor = (0, 0, 0, 0.5)) yPos = 0.45 shiftY = 0.25 self.lblLanguage = DirectLabel( text = _("Language"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.cmbLanguage = DirectOptionMenu( text = "languages", scale = 0.15, pos = (base.a2dRight - 1.5, 0, 0.45), items = ["Deutsch","English","русский", "français"], initialitem = 0, highlightColor = (0.65,0.65,0.65,1), #text_font = self.defaultFontRegular, #item_text_font = self.defaultFontRegular, command = self.cmbLanguage_SelectionChanged) yPos -= shiftY self.lblResolution = DirectLabel( text = _("Screen resolution"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) # get the display resolutions di = base.pipe.getDisplayInformation() sizes = [] for index in range(di.getTotalDisplayModes()): tmptext = "{0}x{1}".format( di.getDisplayModeWidth(index), di.getDisplayModeHeight(index)) if not tmptext in sizes: sizes.append(tmptext) self.cmbResolution = DirectOptionMenu( text = "resolutions", scale = 0.15, pos = (base.a2dRight - 1.5, 0, yPos), items = sizes, initialitem = 0, highlightColor = (0.65, 0.65, 0.65, 1), #text_font = self.defaultFontRegular, #item_text_font = self.defaultFontRegular, command = self.cmbResolution_SelectionChanged) yPos -= shiftY self.lblGraphicQuality = DirectLabel( text = _("Graphic quality"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.graphicqualityTextMap = { 0:_("Low"), 1:_("Medium"), 2:_("High")} self.sliderGraphicQuality = DirectSlider( scale = 0.5, pos = (base.a2dRight - 1, 0, yPos + 0.05), range = (0,2), scrollSize = 1, text = self.graphicqualityTextMap[self.engine.settings.graphicquality], text_scale = 0.25, text_align = TextNode.ALeft, text_pos = (1.1, -0.1), text_fg = (1,1,1,1), #text_font = self.defaultFont, value = self.engine.settings.graphicquality, command = self.sliderGraphicQuality_ValueChanged) yPos -= shiftY self.lblVolume = DirectLabel( text = _("Volume"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.sliderVolume = DirectSlider( scale = 0.5, pos = (base.a2dRight - 1, 0, yPos + 0.05), range = (0,1), scrollSize = 0.01, text = str(int(self.engine.settings.volume * 100)) + "%", text_scale = 0.25, text_align = TextNode.ALeft, text_pos = (1.1, -0.1), text_fg = (1,1,1,1), #text_font = self.defaultFont, value = self.engine.settings.volume, command = self.sliderVolume_ValueChanged) yPos -= shiftY self.lblVolumeMute = DirectLabel( text = _("Mute"), scale = 0.15, pos = (base.a2dLeft + 0.25, 0, yPos), frameColor = (0,0,0,0), text_fg = (1,1,1,1), #text_font = self.defaultFont, text_align = TextNode.ALeft) self.cbVolumeMute = DirectCheckBox( text = "X", pos = (base.a2dRight - 1, 0, yPos), scale = (0.25, 0.25, 0.25), command = self.cbVolumeMute_CheckedChanged, rolloverSound = None, clickSound = None, relief = 0, pressEffect = False, #frameColor = (0,0,0,0), checkedImage = "gui/buttons/options/SoundSwitch_off.png", uncheckedImage = "gui/buttons/options/SoundSwitch_on.png" ) self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.setImage() self.cbVolumeMute["image_scale"] = 0.25 self.cbVolumeMute["text"] = "" self.createBackButton(self.btnBack_Click) self.lblLanguage.reparentTo(self.frameGeneral) self.cmbLanguage.reparentTo(self.frameGeneral) self.lblResolution.reparentTo(self.frameGeneral) self.cmbResolution.reparentTo(self.frameGeneral) self.lblGraphicQuality.reparentTo(self.frameGeneral) self.sliderGraphicQuality.reparentTo(self.frameGeneral) self.lblVolume.reparentTo(self.frameGeneral) self.sliderVolume.reparentTo(self.frameGeneral) self.lblVolumeMute.reparentTo(self.frameGeneral) self.cbVolumeMute.reparentTo(self.frameGeneral) self.frameGeneral.reparentTo(self.frameMain) self.accept("LanguageChanged", self.setText) def initControlTab(self): """ This function will set up the content of the control tab """ self.frameControl = DirectFrame( # size of the frame frameSize = (base.a2dLeft, base.a2dRight, -0.6, 0.6), # position of the frame pos = (0, 0, 0), # tramsparent bg color frameColor = (0, 0, 0, 0.5)) numItemsVisible = 9 itemHeight = 0.10 # the list field for the keyboard maping to the actions self.controlsList = DirectScrolledList( decButton_pos= (0, 0, -0.05), decButton_text = _("up"), decButton_text_scale = 0.04, decButton_borderWidth = (0.005, 0.005), incButton_pos= (0, 0, -1.05), incButton_text = _("down"), incButton_text_scale = 0.04, incButton_borderWidth = (0.005, 0.005), frameSize = (-1, 1, -1.1, 0.0), frameColor = (0,0,0,0.5), pos = (0, 0, 0.6), numItemsVisible = numItemsVisible, forceHeight = itemHeight, itemFrame_frameSize = (-0.9, 0.9, -0.9, 0), itemFrame_pos = (0, 0, -0.1), ) self.fillControlsList() self.controlsList.reparentTo(self.frameControl) self.frameControl.reparentTo(self.frameMain) def fillControlsList(self): for key, value in sorted(self.engine.settings.playerKeys.items()): # the base frame of any item in the list itemFrame = DirectFrame( frameSize = (-0.9, 0.9, -0.09, 0), frameColor = (0, 1, 0, 0)) def changeKey(key, value): # all possible keyboard keys to set for a specific action keyboard = [ "escape", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", "print_screen", "scroll_lock", "pause", "num_lock", "insert", "delete", "home", "end", "page_up", "page_down", "tab", "caps_lock", "shift", "rcontrol", "lcontrol", "ralt", "lalt", "space", "backspace", "enter", "arrow_left", "arrow_up", "arrow_down", "arrow_right", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ä", "ö", "ü", ",", ";", ".", ":", "_", "-", "#", "'", "+", "*", "~", "'", "`", "!", "\"", "§", "$", "%", "&", "/", "(", ")", "=", "?", "{", "}", "[", "]", "\\", "^", "°" ] def setKey(arg): """ This function will set the chosen key for the given action """ # ignore all keyboard inputs again for keyboardKey in keyboard: self.ignore(keyboardKey) if arg == 1: # if the dialog was closed with OK # set the settings to the new value self.engine.settings.playerKeys[key][0] = self.selectedKey if len(self.engine.settings.playerKeys[key]) > 1: # just set the run key value if it is possible newKey = self.engine.settings.playerKeys["run"][0] + "-" + self.selectedKey self.engine.settings.playerKeys[key][1] = newKey # refresh the controls list self.controlsList.removeAllItems() self.fillControlsList() # finaly close the dialog self.keySelectDialog.hide() self.keySelectDialog = None # this variable will store the selected key for the given action self.selectedKey = value[0] def setSelectedKey(selkey): """ set the pressed key as the selected one and actualise the text on the dialog """ self.selectedKey = selkey self.keySelectDialog["text"] = "{0}: {1}".format(key, self.selectedKey) # accept all keyboard keys for keyboardKey in keyboard: self.accept( keyboardKey, setSelectedKey, [keyboardKey]) # set up a dialog wich will ask for the new key for the chosen action self.keySelectDialog = OkCancelDialog( dialogName = "OkCancelDialog", text = "{0}: {1}".format(key, value[0]), fadeScreen = 1, command = setKey ) # show the dialog self.keySelectDialog.show() # add the change button to change the key of the action itemBtnChange = DirectButton( text = _("change"), scale = 0.05, pos = (0.5, 0, -0.05), command = changeKey, extraArgs = [key, value] ) itemBtnChange.reparentTo(itemFrame) # add the label wich will show the name and key of the action itemText = DirectLabel( text = "{0} - {1}".format(key, value[0]), text_scale = 0.06, text_align = TextNode.ALeft, pos = (-0.88, 0, -0.06)) itemText.reparentTo(itemFrame) # finaly add the item to the list self.controlsList.addItem(itemFrame) def show(self): self.setText() self.showBase() def showGeneralTab(self): # set the selected language in the textbox if self.engine.settings.selectedLanguage == "de-DE": self.cmbLanguage.set(0, False) elif self.engine.settings.selectedLanguage == "ru-RU": self.cmbLanguage.set(2, False) elif self.engine.settings.selectedLanguage == "fr-FR": self.cmbLanguage.set(3, False) else: self.cmbLanguage.set(1, False) res = str(self.engine.settings.windowSize[0]) + "x" + str(self.engine.settings.windowSize[1]) i = 0 for item in self.cmbResolution["items"]: if item == res: self.cmbResolution.set(i, False) i += 1 self.sliderGraphicQuality["value"] = self.engine.settings.graphicquality self.sliderVolume["value"] = self.engine.settings.volume #self.cbVolumeMute["indicatorValue"] = settings.muted self.cbVolumeMute["isChecked"] = not self.engine.settings.muted self.cbVolumeMute.commandFunc(None) #self.cbVolumeMute.setIndicatorValue() self.frameGeneral.show() self.hideControlTab() def showControlTab(self): self.frameControl.show() self.hideGeneralTab() def hide(self): self.hideBase() def hideGeneralTab(self): self.frameGeneral.hide() def hideControlTab(self): self.frameControl.hide() def setText(self): self.title["text"] = _("Options") self.btnBack["text"] = _("Back") self.lblLanguage["text"] = _("Language") self.lblResolution["text"] = _("Screen resolution") self.lblGraphicQuality["text"] = _("Graphic quality") self.graphicqualityTextMap = { 0:_("Low"), 1:_("Medium"), 2:_("High")} self.sliderGraphicQuality["text"] = self.graphicqualityTextMap[ self.engine.settings.graphicquality] self.lblVolume["text"] = _("Volume") self.lblVolumeMute["text"] = _("Mute") def cmbLanguage_SelectionChanged(self, arg): # TODO: get available languages and maping from language class! if arg == "Deutsch": self.engine.lng.changeLanguage("de-DE") self.engine.settings.selectedLanguage = "de-DE" elif arg == "русский": self.engine.lng.changeLanguage("ru-RU") self.engine.settings.selectedLanguage = "ru-RU" elif arg == "français": self.engine.lng.changeLanguage("fr-FR") self.engine.settings.selectedLanguage = "fr-FR" else: self.engine.lng.changeLanguage("en-US") self.engine.settings.selectedLanguage = "en-US" def cmbResolution_SelectionChanged(self, arg): resx = int(arg.split("x")[0]) resy = int(arg.split("x")[1]) self.engine.settings.windowSize = [resx, resy] self.engine.graphicMgr.setResolution(resx, resy) def sliderGraphicQuality_ValueChanged(self): val = int(round(self.sliderGraphicQuality["value"], 0)) self.sliderGraphicQuality["text"] = self.graphicqualityTextMap[val] if val != self.engine.settings.graphicquality: self.engine.settings.graphicquality = val self.engine.graphicMgr.setGraphicQuality(self.engine.settings.graphicquality) def sliderVolume_ValueChanged(self): val = round(self.sliderVolume["value"], 2) self.sliderVolume["text"] = str(int(val * 100)) + "%" self.engine.settings.volume = val self.engine.audioMgr.setVolume(self.engine.settings.volume) def cbVolumeMute_CheckedChanged(self, checked): self.cbVolumeMute["image_scale"] = 0.35 self.cbVolumeMute["image_pos"] = (0.05,0,0.25) self.engine.settings.muted = bool(checked) self.engine.audioMgr.mute(self.engine.settings.muted) def btnBack_Click(self): base.messenger.send("OptMenu_back")
def __init__(self, tooltip, grid): self.tt = tooltip self.grid = grid screenWidthPx = base.getSize()[0] left = screenWidthPx * 0.25 barWidth = screenWidthPx * 0.75 color = ( (0.25, 0.25, 0.25, 1), # Normal (0.35, 0.35, 1, 1), # Click (0.25, 0.25, 1, 1), # Hover (0.1, 0.1, 0.1, 1)) # Disabled # # Toolbar # self.toolBar = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1), frameSize=(0, barWidth, -24, 24), autoUpdateFrameSize=False, pos=(0, 0, 0), parent=base.pixel2d) buttonColor = ( (0.8, 0.8, 0.8, 1), # Normal (0.9, 0.9, 1, 1), # Click (0.8, 0.8, 1, 1), # Hover (0.5, 0.5, 0.5, 1)) # Disabled btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, command=base.messenger.send, extraArgs=["newProject"], image="icons/New.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Create New GUI (Ctrl-N)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, command=base.messenger.send, extraArgs=["saveProject"], image="icons/Save.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Save GUI as gui Project (Ctrl-S)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, text_scale=0.33, relief=DGG.FLAT, command=base.messenger.send, extraArgs=["exportProject"], image="icons/Export.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Export GUI as python script (Ctrl-E)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["loadProject"], image="icons/Load.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Load GUI project (Ctrl-O)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) placeholder = DirectFrame(text="|", frameSize=(-1, 1, -24, 24), pad=(4, 0), frameColor=(0, 0, 0, 1)) self.toolBar.addItem(placeholder) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["undo"], image="icons/Undo.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Undo last action (Ctrl-Z)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["redo"], image="icons/Redo.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Redo last action (Ctrl-Y)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["cycleRedo"], image="icons/CycleRedo.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Cycle through redo branches (Ctrl-Shift-Y)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) placeholder = DirectFrame(text="|", frameSize=(-1, 1, -24, 24), pad=(4, 0), frameColor=(0, 0, 0, 1)) self.toolBar.addItem(placeholder) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["removeElement"], image="icons/Delete.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Delete selected element (Del)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) placeholder = DirectFrame(text="|", frameSize=(-1, 1, -24, 24), pad=(4, 0), frameColor=(0, 0, 0, 1)) self.toolBar.addItem(placeholder) self.cb_grid = DirectCheckBox( frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=12, image="icons/GridOff.png" if self.grid.isHidden() else "icons/GridOn.png", uncheckedImage="icons/GridOff.png", checkedImage="icons/GridOn.png", image_scale=24, isChecked=not self.grid.isHidden(), command=self.toggleGrid) self.cb_grid.setTransparency(TransparencyAttrib.M_multisample) self.cb_grid.bind(DGG.ENTER, self.tt.show, ["Toggle Grid (Ctrl-G)"]) self.cb_grid.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(self.cb_grid) self.cb_scale = DirectCheckBox(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=12, image="icons/Scale1.png", uncheckedImage="icons/Scale2.png", checkedImage="icons/Scale1.png", image_scale=24, isChecked=True, command=self.toggleVisualEditorParent) self.cb_scale.setTransparency(TransparencyAttrib.M_alpha) self.cb_scale.bind(DGG.ENTER, self.tt.show, ["Toggle editor scale (Aspect/Pixel)"]) self.cb_scale.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(self.cb_scale) placeholder = DirectFrame(text="|", frameSize=(-1, 1, -24, 24), pad=(4, 0), frameColor=(0, 0, 0, 1)) self.toolBar.addItem(placeholder) zoomHolder = DirectFrame( frameSize=(-48, 48, -24, 24), #pad=(4, 0), frameColor=(0, 0, 0, 0)) self.toolBar.addItem(zoomHolder) self.zoomSlider = DirectSlider(zoomHolder, scale=(48, 1, 96), pos=(0, 0, 0), range=(0.1, 1.5), command=self.zoomSliderChanged) self.zoomSlider.bind(DGG.ENTER, self.tt.show, ["Zoom"]) self.zoomSlider.bind(DGG.EXIT, self.tt.hide) #self.toolBar.addItem(self.zoomSlider) placeholder = DirectFrame(text="|", frameSize=(-1, 1, -24, 24), pad=(4, 0), frameColor=(0, 0, 0, 1)) self.toolBar.addItem(placeholder) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["quitApp"], image="icons/Quit.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_alpha) btn.bind(DGG.ENTER, self.tt.show, ["Quit Direct GUI Designer (Ctrl-Q)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) placeholder = DirectFrame(text="|", frameSize=(-1, 1, -24, 24), pad=(4, 0), frameColor=(0, 0, 0, 1)) self.toolBar.addItem(placeholder) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["showHelp"], image="icons/Help.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Show a help Dialog (F1)"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) btn = DirectButton(frameSize=(-24, 24, -24, 24), frameColor=buttonColor, relief=DGG.FLAT, text_scale=0.33, command=base.messenger.send, extraArgs=["showSettings"], image="icons/Settings.png", image_scale=24) btn.setTransparency(TransparencyAttrib.M_multisample) btn.bind(DGG.ENTER, self.tt.show, ["Show Designer Settings"]) btn.bind(DGG.EXIT, self.tt.hide) self.toolBar.addItem(btn) if not ConfigVariableBool("show-toolbar", True).getValue(): self.toolBar.hide() self.accept("setVisualEditorParent", self.setVisualEditorParent) self.accept("toggleGrid", self.setGrid)
def __init__(self): # loading music self.menuMusic = loader.loadMusic("music/01Menu.mp3") self.menuMusic.setLoop(True) # 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), # position center pos = (0, 0, 0), # set tramsparent background color frameColor = (0.15, 0.15, 0.15, 1)) #self.frameMain.reparentTo(render2d) self.menuBackground = OnscreenImage( image = 'gui/Background.png', scale = (1.66, 1, 1), pos = (0, 0, 0)) self.menuBackground.reparentTo(self.frameMain) self.defaultBtnMap = base.loader.loadModel("gui/button_map") self.buttonGeom = ( self.defaultBtnMap.find("**/button_ready"), self.defaultBtnMap.find("**/button_click"), self.defaultBtnMap.find("**/button_rollover"), self.defaultBtnMap.find("**/button_disabled")) self.defaultTxtMap = base.loader.loadModel("gui/textbox_map") self.textboxGeom = self.defaultTxtMap.find("**/textbox") monospace = loader.loadFont('gui/DejaVuSansMono.ttf') defaultFont = loader.loadFont('gui/eufm10.ttf') # create the title self.textscale = 0.25 self.title = DirectLabel( # scale and position scale = self.textscale, pos = (0.0, 0.0, base.a2dTop - self.textscale), # frame frameColor = (0, 0, 0, 0), # Text text = "Dungeon Crawler", text_align = TextNode.ACenter, text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont) self.title.setTransparency(1) self.title.reparentTo(self.frameMain) # create a host button self.btnHostPos = Vec3(0, 0, .45) self.btnHostScale = 0.25 self.btnHost = DirectButton( # Scale and position scale = self.btnHostScale, pos = self.btnHostPos, # Text text = "Host", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, # Frame geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, # Functionality command = self.host, rolloverSound = None, clickSound = None) self.btnHost.setTransparency(1) self.btnHost.reparentTo(self.frameMain) # create a join button self.btnJoinPos = Vec3(0, 0, 0) self.btnJoinScale = 0.25 self.btnJoin = DirectButton( scale = self.btnJoinScale, pos = self.btnJoinPos, text = "Join", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, command = self.join, rolloverSound = None, clickSound = None) self.btnJoin.setTransparency(1) self.btnJoin.reparentTo(self.frameMain) # create the IP input field self.txtIPPos = Vec3(0, 0, -.30) self.txtIPScale = 0.25 self.txtIPWidth = 9 self.txtIP = DirectEntry( # scale and position pos = self.txtIPPos, scale = self.txtIPScale, width = self.txtIPWidth, # Text entryFont = monospace, text_align = TextNode.ACenter, text = "", text_scale = 0.5, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (0.04, 0.04), initialText = "127.0.0.1", numLines = 1, # Frame geom = self.textboxGeom, frameColor = (0, 0, 0, 0), relief = 0, # Functionality command = self.join, focusInCommand = self.clearText) self.txtIP.reparentTo(self.frameMain) # create an exit button self.btnExitPos = Vec3(0, 0, -.75) self.btnExitScale = 0.25 self.btnExit = DirectButton( scale = self.btnExitScale, pos = self.btnExitPos, text = "Exit", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, command = lambda: base.messenger.send("escape"), rolloverSound = None, clickSound = None) self.btnExit.setTransparency(1) self.btnExit.reparentTo(self.frameMain) # create a mute checkbox self.cbVolumeMute = DirectCheckBox( # set size scale = (0.1, 0.1, 0.1), frameSize = (-1, 1, 1, -1), # functionality and visuals command = self.cbVolumeMute_CheckedChanged, isChecked = True, checkedImage = "gui/SoundSwitch_off.png", uncheckedImage = "gui/SoundSwitch_on.png", # mouse behaviour relief = 0, pressEffect = False, rolloverSound = None, clickSound = None ) self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.reparentTo(self.frameMain) self.cbVolumeMute.commandFunc(None) # catch window resizes and recalculate the aspectration self.accept("window-event", self.recalcAspectRatio) self.accept("showerror", self.showError) # show the menu right away self.show()
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 __init__(self): self.frameMain = DirectFrame(image="optionsmenu.png", image_scale=(1.7778, 1, 1), frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0, 0, 0, 0)) self.frameMain.setTransparency(True) volume = base.musicManager.getVolume() self.sliderMusicVolume = DirectSlider( scale=0.5, pos=(0, 0, -0.1), range=(0, 1), scrollSize=0.01, text="Music Volume: %d%%" % volume * 100, text_scale=0.15, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), thumb_frameColor=(0.8, 0, 1, 0.75), thumb_relief=DGG.FLAT, frameColor=(0.25, 0.25, 0.55, 1), value=volume, command=self.sliderMusicVolume_ValueChanged) self.sliderMusicVolume.reparentTo(self.frameMain) volume = base.sfxManagerList[0].getVolume() self.sliderSFXVolume = DirectSlider( scale=0.5, pos=(0, 0, -0.3), range=(0, 1), scrollSize=0.01, text="SFX Volume: %d%%" % volume * 100, text_scale=0.15, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), thumb_frameColor=(0.8, 0, 1, 0.75), thumb_relief=DGG.FLAT, frameColor=(0.25, 0.25, 0.55, 1), value=volume, command=self.sliderSFXVolume_ValueChanged) self.sliderSFXVolume.reparentTo(self.frameMain) isChecked = not base.AppHasAudioFocus img = None imgON = "AudioSwitch_on.png" imgOFF = "AudioSwitch_off.png" if base.AppHasAudioFocus: img = imgON else: img = imgOFF self.cbVolumeMute = DirectCheckBox( scale=0.5, text="Mute Audio", text_scale=0.15, text_align=TextNode.ACenter, text_pos=(0.0, 0.15), text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), pos=(0, 0, -0.5), command=self.cbVolumeMute_CheckedChanged, rolloverSound=None, clickSound=None, relief=None, pressEffect=False, isChecked=isChecked, image=img, image_scale=0.1, checkedImage=imgOFF, uncheckedImage=imgON) self.cbVolumeMute.setTransparency(True) self.cbVolumeMute.setImage() self.cbVolumeMute.reparentTo(self.frameMain) radio = base.loader.loadModel("radioBtn") radioGeom = (radio.find("**/RadioButtonReady"), radio.find("**/RadioButtonChecked")) self.lblDifficulty = DirectLabel(text="Difficulty", text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), text_scale=0.6, scale=0.15, frameColor=(0, 0, 0, 0), pos=(-0.5, 0, -0.6)) self.lblDifficulty.reparentTo(self.frameMain) self.difficulty = [base.difficulty] def createDifficultyDRB(self, text, value, initialValue, xPos): drb = DirectRadioButton( text=text, text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), variable=self.difficulty, value=value, indicatorValue=initialValue, boxGeom=radioGeom, boxGeomScale=0.5, #indicator_pad = (0.1, 0.1), scale=0.05, frameColor=(0.5, 0.5, 0.5, 1), pressEffect=False, relief=1, pad=(0.5, 0, 0.5, 0.5), pos=(xPos, 0, -0.6), command=self.rbDifficulty_ValueChanged) drb.indicator.setX(drb.indicator.getX() + 0.1) drb.indicator.setZ(drb.indicator.getZ() + 0.1) drb.reparentTo(self.frameMain) return drb self.difficultyButtons = [ createDifficultyDRB(self, "Easy", [0], 1 if base.difficulty == 0 else 0, 0.5 - 0.3), createDifficultyDRB(self, "Medium", [1], 1 if base.difficulty == 1 else 0, 0.5), createDifficultyDRB(self, "Hard", [2], 1 if base.difficulty == 2 else 0, 0.5 + 0.3) ] for button in self.difficultyButtons: button.setOthers(self.difficultyButtons) self.btnBack = DirectButton(text="Back", scale=0.15, text_pos=(-0.3, -0.2), text_scale=0.6, text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), frameColor=(0, 0, 0, 0), image=("btnExit.png", "btnExit_hover.png", "btnExit_hover.png", "btnExit_hover.png"), image_scale=(1, 1, 0.5), pos=(0, 0, -0.8), command=base.messenger.send, extraArgs=["menu_Back"]) self.btnBack.setTransparency(True) self.btnBack.reparentTo(self.frameMain) self.hide()
def __init__(self): self.frameMain = DirectFrame( image="gui/MenuBackground.png", image_scale=(1.7778, 1, 1), #image_pos=(0, 0, 0.25), frameSize=( base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), frameColor=(0,0,0,0)) self.frameMain.setTransparency(True) self.logo = DirectFrame( image="Logo.png", image_scale=0.25, image_pos=(0, 0, 0.55), frameSize=( base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), frameColor=(0,0,0,0)) self.logo.reparentTo(self.frameMain) btnGeom = "gui/button" self.btnBack = menuHelper.createButton(_("Back"), btnGeom, 0, -0.7, ["options_back"]) self.btnBack.reparentTo(self.frameMain) volume = base.musicManager.getVolume() self.sliderVolume = DirectSlider( scale=0.5, pos=(-0.5, 0, 0), range=(0, 1), scrollSize=0.01, text=_("Volume %d%%") % volume*100, text_scale=0.1, text_pos=(0, 0.15), text_fg=(1, 1, 1, 1), thumb_frameColor=(0,0.75, 0.25, 1), frameColor=(0.35, 0.15, 0.05, 1), value=volume, command=self.sliderVolume_ValueChanged) self.sliderVolume.reparentTo(self.frameMain) isChecked = not base.AppHasAudioFocus img = None imgON = "gui/AudioSwitch_on.png" imgOFF = "gui/AudioSwitch_off.png" if base.AppHasAudioFocus: img = imgON else: img = imgOFF self.cbVolumeMute = DirectCheckBox( text=_("Mute Audio"), text_scale=0.5, text_align=TextNode.ACenter, text_pos=(0, 0.65), text_fg=(1, 1, 1, 1), scale=0.105, pos=(0.5, 0, 0), command=self.cbVolumeMute_CheckedChanged, relief=None, pressEffect=False, isChecked=isChecked, image=img, image_scale=0.5, checkedImage=imgOFF, uncheckedImage=imgON) self.cbVolumeMute.setTransparency(True) self.cbVolumeMute.setImage() self.cbVolumeMute.reparentTo(self.frameMain) prcPath = os.path.join(basedir, "%s.prc"%appName) self.advancedOptions = DirectLabel( text=_("Advanced options can be made in the following text file\n%s")%prcPath, text_scale=0.5, text_fg=(1, 1, 1, 1), scale=0.1, pos=(0, 0, -0.25), frameColor=(0, 0, 0, 0)) self.advancedOptions.setTransparency(True) self.advancedOptions.reparentTo(self.frameMain) self.hide()