def enterDisplayPage(self): self.book.createPageButtons(False, False) self.book.setTitle("Display Options") dialog_gui = loader.loadModel( "phase_3/models/gui/dialog_box_buttons_gui.bam") width, height, fs, music, sfx, tex_detail, model_detail, aa, af = SettingsManager( ).getSettings("settings.json") self.width = width self.height = height self.windowType = [fs] self.buttons = [ DirectRadioButton(text="Windowed", variable=self.windowType, value=[False], scale=0.1, pos=(-0.45, 0.15, 0.15)), DirectRadioButton(text="Fullscreen", variable=self.windowType, value=[True], scale=0.1, pos=(-0.45, -0.15, -0.15)) ] for button in self.buttons: button.setOthers(self.buttons) self.resoLbl = DirectLabel(text="%sx%s" % (width, height), scale=0.08, relief=None, pos=(0.25, 0, 0)) self.resSlider = DirectSlider(range=(0, 200), pageSize=50, command=self.setResoText, scale=0.3, orientation=DGG.VERTICAL, pos=(0.6, 0, 0)) self.okBtn = DirectButton(text="OK", geom=CIGlobals.getOkayBtnGeom(), relief=None, pos=(-0.5, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.applyDisplaySettings) self.cancelBtn = DirectButton(text="Cancel", geom=CIGlobals.getCancelBtnGeom(), relief=None, pos=(-0.3, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.cancelDisplaySettings) if self.resoLbl['text'] == "640x480": self.resSlider['value'] = 0 elif self.resoLbl['text'] == "800x600": self.resSlider['value'] = 50 elif self.resoLbl['text'] == "1024x768": self.resSlider['value'] = 100 elif self.resoLbl['text'] == "1280x1024": self.resSlider['value'] = 150 elif self.resoLbl['text'] == "1600x1200": self.resSlider['value'] = 200
class MapConfig(DirectFrame): def __init__(self, *args, **kwargs): kwargs['suppressMouse'] = 0 super(self.__class__, self).__init__(*args, **kwargs) self.initialiseoptions(self.__class__) self.setTransparency(1) self.setup() def setup(self): if hasattr(self, 'mainFrame'): self.mainFrame.destroy() self.mainFrame = DirectFrame(parent = self, relief = None) def setVisibility(): value = self.visSlider['value'] self.setColorScale(Vec4(1, 1, 1, value)) self.visSlider = DirectSlider(guiId = 'visSlider', parent = self.mainFrame, scale = 0.40000000000000002, thumb_relief = DGG.FLAT, thumb_color = (0.25, 1.0, 0.25, 1), pos = (0.40000000000000002, 0, -0.84999999999999998), text = 'Visibility', text_scale = 0.20000000000000001, text_pos = (0, 0.10000000000000001, 0), text_bg = (0.80000000000000004, 0.80000000000000004, 0.80000000000000004, 1), value = 1.0, command = setVisibility) self.visSlider.getChild(0).setTransparency(0) self.camFrame = DirectFrame(guiId = 'camFrame', parent = self.mainFrame, relief = DGG.RIDGE, frameSize = (0.0, 0.80000000000000004, 0.0, 0.32000000000000001), frameColor = (1, 1, 0.75, 1), borderWidth = (0.0050000000000000001, 0.0050000000000000001), pos = (0, 0, 0.59999999999999998), text = 'Camera', text_fg = (0, 0, 0, 1), text_scale = 0.050000000000000003, text_pos = (0.10000000000000001, 0.26000000000000001, 0)) self.camSlider = RangeSlider(guiId = 'zoom', label = 'Zoom (Y-axis)', range = (-0.75, 0.25), value = 0, parent = self.camFrame, pos = (0.39500000000000002, 0, 0.070000000000000007)) self.worldFrame = DirectFrame(guiId = 'worldFrame', parent = self.mainFrame, relief = DGG.RIDGE, frameSize = (0.0, 0.80000000000000004, -0.55000000000000004, 0.5), frameColor = (1, 0.75, 0.75, 1), borderWidth = (0.0050000000000000001, 0.0050000000000000001), pos = (0.0, 0, 0), text = 'World', text_fg = (0, 0, 0, 1), text_scale = 0.050000000000000003, text_pos = (0.10000000000000001, 0.42999999999999999, 0)) self.worldPSlider = RangeSlider(guiId = 'worldP', label = 'World P', range = (-90, 0), value = 0.0, parent = self.worldFrame, pos = (0.39500000000000002, 0, 0.23999999999999999)) self.worldDecorScaleSlider = RangeSlider(guiId = 'worldP', label = 'World Decor Scale', range = (0.20000000000000001, 0.29999999999999999), value = 0.25, parent = self.worldFrame, pos = (0.39500000000000002, 0, 0.0)) self.finalSlider = RangeSlider(guiId = 'final', label = 'Final', range = (0, 1), value = 0, parent = self.worldFrame, pos = (0.39500000000000002, 0, -0.47999999999999998)) self.saveState0Button = DirectButton(guiId = 'save0Button', parent = self.mainFrame, scale = 0.10000000000000001, pos = (0.20000000000000001, 0, -0.65000000000000002), borderWidth = (0.10000000000000001, 0.10000000000000001), text = 'save pt0') self.saveState1Button = DirectButton(guiId = 'save1Button', parent = self.mainFrame, scale = 0.10000000000000001, pos = (0.59999999999999998, 0, -0.65000000000000002), borderWidth = (0.10000000000000001, 0.10000000000000001), text = 'save pt1')
class SliderWidget(DirectFrame): notify = directNotify.newCategory("SliderWidget") def __init__(self, page, widgetname, slrange, slcommand, pos = (0, 0, 0)): DirectFrame.__init__(self, parent = page.book, pos = pos) self.page = page self.text = OnscreenText(text = widgetname + ":", pos = (-0.7, 0, 0), align = TextNode.ALeft, parent = self) self.slider = DirectSlider(range=slrange, pageSize=0.1, command=slcommand, scale=0.3, orientation=DGG.HORIZONTAL, pos=(0.35, 0, 0.025), parent = self) self.valText = OnscreenText(text = "", pos = (0.7, -0.005, -0.005), align = TextNode.ALeft, parent = self) def setValText(self, text): self.valText.setText(text) def getSliderVal(self): return self.slider['value'] def setSliderVal(self, val): self.slider['value'] = val def cleanup(self): if hasattr(self, 'text'): self.text.destroy() del self.text if hasattr(self, 'slider'): self.slider.destroy() del self.slider if hasattr(self, 'valText'): self.valText.destroy() del self.valText del self.page
def __init__(self, page, widgetname, slrange, slcommand, pos = (0, 0, 0)): DirectFrame.__init__(self, parent = page.book, pos = pos) self.page = page self.text = OnscreenText(text = widgetname + ":", pos = (-0.7, 0, 0), align = TextNode.ALeft, parent = self) self.slider = DirectSlider(range=slrange, pageSize=0.1, command=slcommand, scale=0.3, orientation=DGG.HORIZONTAL, pos=(0.35, 0, 0.025), parent = self) self.valText = OnscreenText(text = "", pos = (0.7, -0.005, -0.005), align = TextNode.ALeft, parent = self)
class do4d(DirectObject, HasKeybinds): def __init__(self): tsteps = 10 # this is really molecules npoints = 999 # this is realy timesteps self.slider = DirectSlider(range=(0,1), value=0, pageSize=1, thumb_frameSize=(0,.04,-.02,.02), command=self.t_set) self.slider.setPos((0,0,-.9)) data = np.cumsum(np.random.randint(-1,2,(tsteps,npoints,3)), axis=1) data2 = [data[:,i,:] for i in range(len(data[0]))] #embed() ctup = np.random.rand(tsteps, 4) tm1 = [treeMe(None, d, np.array(['%s'%uuid4() for _ in d]),np.ones(len(d))) for d in data] self.f1 = fourObject(make4d(data,ctup, geomType = GeomLinestrips), tm1 ) sc1 = lambda: self.set_selected(self.f1) self.f1.coll_parent.setPythonTag('selection_callbacks', [sc1]) self.set_selected(self.f1) tm2 = [treeMe(None, d, np.array(['%s'%uuid4() for _ in d]),np.ones(len(d))) for d in data2] self.f2 = fourObject(make4d(data2,ctup), tm2) self.f2.set_size(3) self.f2.stash() sc2 = lambda: self.set_selected(self.f2) self.f2.coll_parent.setPythonTag('selection_callbacks', [sc2]) # TODO make clicking not on the button set the slider position? self.accept('s',self.set_selected, [self.f2]) def set_selected(self, fourObject): # TODO type check? self.selected = fourObject self.selected.unstash() self.slider['range'] = (0,len(self.selected)-1) self.slider['value'] = fourObject.__index__ print('selected set to', fourObject) @event_callback('a') def t_all(self): if not self.selected._all: self.selected.show_all() else: self.selected.hide_all() def t_set(self): value = int(self.slider['value']) if value != self.selected.__index__: self.selected.goto_index(value) @event_callback((']',']-repeat')) def t_up(self): #self.selected.next_index() self.slider['value'] = (self.slider['value'] + 1) % len(self.selected) @event_callback(('[','[-repeat')) def t_down(self): #self.selected.prev_index() self.slider['value'] = (self.slider['value'] - 1) % len(self.selected)
def add_axis(offset, axis_name): slider_width = canvas_width / 2 label = DirectLabel( text=axis_name, **left_aligned_small_text, pos=(0.05, 0, offset), parent=panel_canvas, ) slider = DirectSlider( value=0.0, range=(-1.0, 1.0), state=DGG.DISABLED, frameSize=VBase4( 0, slider_width, -0.1, 0, ), thumb_frameSize=VBase4( 0.0, 0.04, -0.04, 0.04), frameColor=VBase4(0.3, 0.3, 0.3, 1), pos=(canvas_width - slider_width, 0, offset), parent=panel_canvas, ) return slider
def __init__(self): tsteps = 10 # this is really molecules npoints = 999 # this is realy timesteps self.slider = DirectSlider(range=(0,1), value=0, pageSize=1, thumb_frameSize=(0,.04,-.02,.02), command=self.t_set) self.slider.setPos((0,0,-.9)) data = np.cumsum(np.random.randint(-1,2,(tsteps,npoints,3)), axis=1) data2 = [data[:,i,:] for i in range(len(data[0]))] #embed() ctup = np.random.rand(tsteps, 4) tm1 = [treeMe(None, d, np.array(['%s'%uuid4() for _ in d]),np.ones(len(d))) for d in data] self.f1 = fourObject(make4d(data,ctup, geomType = GeomLinestrips), tm1 ) sc1 = lambda: self.set_selected(self.f1) self.f1.coll_parent.setPythonTag('selection_callbacks', [sc1]) self.set_selected(self.f1) tm2 = [treeMe(None, d, np.array(['%s'%uuid4() for _ in d]),np.ones(len(d))) for d in data2] self.f2 = fourObject(make4d(data2,ctup), tm2) self.f2.set_size(3) self.f2.stash() sc2 = lambda: self.set_selected(self.f2) self.f2.coll_parent.setPythonTag('selection_callbacks', [sc2]) # TODO make clicking not on the button set the slider position? self.accept('s',self.set_selected, [self.f2])
def add_vibration(offset, axis_name, index): slider_width = canvas_width / 2 label = DirectLabel( text=axis_name, **left_aligned_small_text, pos=(0.05, 0, offset), parent=panel_canvas, ) slider = DirectSlider( value=0.0, range=(0.0, 1.0), command=self.update_vibration, frameSize=VBase4( 0, slider_width, -0.1, 0, ), thumb_frameSize=VBase4( 0.0, 0.04, -0.04, 0.04), frameColor=VBase4(0.3, 0.3, 0.3, 1), pos=(canvas_width - slider_width, 0, offset), parent=panel_canvas, ) return slider
def setup(self, label, range, value, orientation, *args, **kwargs): def updateField(widget, field, value): widget[field] = value def finalCommand(): val = self.slider['value'] updateField(self.slider, 'text', '%1.3f' % val) self.slider = DirectSlider(parent=self, relief=DGG.FLAT, range=range, value=value, orientation=orientation, scale=0.25, thumb_relief=DGG.FLAT, thumb_color=(0, 1, 1, 1), pos=(0, 0, 0), text='0.0', text_scale=0.20000000000000001, text_pos=(0, 0.10000000000000001, 0)) updateField(self.slider, 'command', finalCommand) width = 3 if orientation == DGG.HORIZONTAL: pos = (-0.27500000000000002 - width * 0.050000000000000003, 0, -0.02) else: pos = (-0.025000000000000001 * width, 0, -0.34999999999999998) self.min = DirectEntry(parent=self, initialText=` float(self.slider['range'][0]) `, scale=0.050000000000000003, width=width, pos=pos) updateField( self.min, 'command', lambda x: updateField(self.slider, 'range', (float(x), self.slider['range'][1]))) if orientation == DGG.HORIZONTAL: pos = (0.27500000000000002, 0, -0.02) else: pos = (-0.025000000000000001 * width, 0, 0.29999999999999999) self.max = DirectEntry(parent=self, initialText=` float(self.slider['range'][1]) `, scale=0.050000000000000003, width=width, pos=pos) updateField( self.max, 'command', lambda x: updateField(self.slider, 'range', (self.slider['range'][0], float(x)))) self.label = DirectLabel( parent=self, relief=None, text=label, text_scale=0.050000000000000003, text_pos=(0.029999999999999999 - 0.39500000000000002, 0.34999999999999998 - 0.23999999999999999, 0), text_align=TextNode.ALeft)
def createMaterialSliders(self): OnscreenText(text='Specular', pos=(-base.getAspectRatio() + 0.1, 0.85), scale=0.04, align=TextNode.ALeft, fg=(1, 1, 1, 1)) OnscreenText(text='Metallic', pos=(-base.getAspectRatio() + 0.1, 0.75), scale=0.04, align=TextNode.ALeft, fg=(1, 1, 1, 1)) OnscreenText(text='Roughness', pos=(-base.getAspectRatio() + 0.1, 0.65), scale=0.04, align=TextNode.ALeft, fg=(1, 1, 1, 1)) self.specSlider = DirectSlider(range=(0, 100), value=50, pageSize=3, command=self.setSpecular, scale=(0.6, 0.5, 0.2), pos=(-base.getAspectRatio() + 0.7, 0, 0.82)) self.metSlider = DirectSlider(range=(0, 100), value=50, pageSize=3, command=self.setMetallic, scale=(0.6, 0.5, 0.2), pos=(-base.getAspectRatio() + 0.7, 0, 0.72)) self.roughSlider = DirectSlider(range=(0, 100), value=50, pageSize=3, command=self.setRoughness, scale=(0.6, 0.5, 0.2), pos=(-base.getAspectRatio() + 0.7, 0, 0.62)) # Set initial values self.setSpecular() self.setMetallic() self.setRoughness()
def __init__(self, parent: DirectFrame, text: str, value: float, slider_edit_callback: Callable[['ColourChannel', float], None], entry_edit_callback: Callable[['ColourChannel', float], None], mouse1_press_callbacks: List[Callable[[], None]]): self.__frame = DirectFrame(parent=parent) self.__slider_edit_callback = slider_edit_callback self.__entry_edit_callback = entry_edit_callback self.__label = DirectLabel(parent=self.__frame, text=text, text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, pos=(-0.5, 0.0, 0.0), scale=(0.1, 1.0, 0.1)) self.__slider = DirectSlider(parent=self.__frame, orientation=DGG.HORIZONTAL, borderWidth=(0.0, 0.0), frameColor=WIDGET_BG_COLOUR, frameSize=(-1.0, 1.0, -0.4, 0.4), thumb_frameSize=(-0.075, 0.075, -0.2, 0.2), value=value, pos=(0.05, 0.0, 0.0255), scale=(0.45, 1.0, 0.5)) self.__entry_hovered = False mouse1_press_callbacks.append(self.__entry_mouse_click_callback) self.__entry = DirectEntry(parent=self.__frame, frameColor=WIDGET_BG_COLOUR, text_fg=WHITE, initialText=str(value), scale=0.1, width=3, suppressKeys=True, pos=(0.55, 0.0, -0.01105)) self.__entry.bind(DGG.EXIT, self.__entry_exit_callback) self.__entry.bind(DGG.ENTER, self.__entry_enter_callback) self.__entry.bind(DGG.B1PRESS, self.__entry_mouse_click_callback) self.accept("mouse1", self.__entry_mouse_click_callback) self.__disable_frame_overlay = DirectButton(parent=self.__frame, frameColor=TRANSPARENT, borderWidth=(0.0, 0.0), frameSize=(-0.6, 0.9, -0.2, 0.2), suppressMouse=True) self.__disable_frame_overlay.hide() self.__enabled = True self.__set_callbacks()
def make_slider(self, parent, pos: tuple, value, command=None): """Get slider of default format with provided args.""" command = command or (lambda *args, **kwargs: None) slider = DirectSlider( command=command, pos=pos, scale=(256, 1, 128), value=value, parent=parent, relief=DGG.FLAT, ) return slider
def __init__(self): tsteps = 10 # this is really molecules npoints = 999 # this is realy timesteps self.slider = DirectSlider(range=(0, 1), value=0, pageSize=1, thumb_frameSize=(0, .04, -.02, .02), command=self.t_set) self.slider.setPos((0, 0, -.9)) data = np.cumsum(np.random.randint(-1, 2, (tsteps, npoints, 3)), axis=1) data2 = [data[:, i, :] for i in range(len(data[0]))] #embed() ctup = np.random.rand(tsteps, 4) tm1 = [ treeMe(None, d, np.array(['%s' % uuid4() for _ in d]), np.ones(len(d))) for d in data ] self.f1 = fourObject(make4d(data, ctup, geomType=GeomLinestrips), tm1) sc1 = lambda: self.set_selected(self.f1) self.f1.coll_parent.setPythonTag('selection_callbacks', [sc1]) self.set_selected(self.f1) tm2 = [ treeMe(None, d, np.array(['%s' % uuid4() for _ in d]), np.ones(len(d))) for d in data2 ] self.f2 = fourObject(make4d(data2, ctup), tm2) self.f2.set_size(3) self.f2.stash() sc2 = lambda: self.set_selected(self.f2) self.f2.coll_parent.setPythonTag('selection_callbacks', [sc2]) # TODO make clicking not on the button set the slider position? self.accept('s', self.set_selected, [self.f2])
def create_slider_entry(self, frame, param, component=None): if component is not None: scaled_value = param.get_param_component(component, scale=True) else: scaled_value = param.get_param(scale=True) hsizer = Sizer("horizontal") slider = DirectSlider(parent=frame, scale=(self.font_size * 16, 1, self.font_size * 6), value=scaled_value, range=param.get_range(scale=True), suppressKeys=1, command=self.do_update_slider) widget = SizerWidget(slider) hsizer.add(widget, alignments=("expand", "center"), borders=self.borders) widget = self.create_spin_entry(frame, param, slider, component) hsizer.add(widget, alignments=("min", "center"), borders=self.borders) slider['extraArgs'] = [slider, widget.dgui_obj, param, component] return hsizer
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 setup(self): if hasattr(self, 'mainFrame'): self.mainFrame.destroy() self.mainFrame = DirectFrame(parent=self, relief=None) def setVisibility(): value = self.visSlider['value'] self.setColorScale(Vec4(1, 1, 1, value)) self.visSlider = DirectSlider(guiId='visSlider', parent=self.mainFrame, scale=0.40000000000000002, thumb_relief=DGG.FLAT, thumb_color=(0.25, 1.0, 0.25, 1), pos=(0.40000000000000002, 0, -0.84999999999999998), text='Visibility', text_scale=0.20000000000000001, text_pos=(0, 0.10000000000000001, 0), text_bg=(0.80000000000000004, 0.80000000000000004, 0.80000000000000004, 1), value=1.0, command=setVisibility) self.visSlider.getChild(0).setTransparency(0) self.camFrame = DirectFrame( guiId='camFrame', parent=self.mainFrame, relief=DGG.RIDGE, frameSize=(0.0, 0.80000000000000004, 0.0, 0.32000000000000001), frameColor=(1, 1, 0.75, 1), borderWidth=(0.0050000000000000001, 0.0050000000000000001), pos=(0, 0, 0.59999999999999998), text='Camera', text_fg=(0, 0, 0, 1), text_scale=0.050000000000000003, text_pos=(0.10000000000000001, 0.26000000000000001, 0)) self.camSlider = RangeSlider(guiId='zoom', label='Zoom (Y-axis)', range=(-0.75, 0.25), value=0, parent=self.camFrame, pos=(0.39500000000000002, 0, 0.070000000000000007)) self.worldFrame = DirectFrame( guiId='worldFrame', parent=self.mainFrame, relief=DGG.RIDGE, frameSize=(0.0, 0.80000000000000004, -0.55000000000000004, 0.5), frameColor=(1, 0.75, 0.75, 1), borderWidth=(0.0050000000000000001, 0.0050000000000000001), pos=(0.0, 0, 0), text='World', text_fg=(0, 0, 0, 1), text_scale=0.050000000000000003, text_pos=(0.10000000000000001, 0.42999999999999999, 0)) self.worldPSlider = RangeSlider(guiId='worldP', label='World P', range=(-90, 0), value=0.0, parent=self.worldFrame, pos=(0.39500000000000002, 0, 0.23999999999999999)) self.worldDecorScaleSlider = RangeSlider(guiId='worldP', label='World Decor Scale', range=(0.20000000000000001, 0.29999999999999999), value=0.25, parent=self.worldFrame, pos=(0.39500000000000002, 0, 0.0)) self.finalSlider = RangeSlider(guiId='final', label='Final', range=(0, 1), value=0, parent=self.worldFrame, pos=(0.39500000000000002, 0, -0.47999999999999998)) self.saveState0Button = DirectButton(guiId='save0Button', parent=self.mainFrame, scale=0.10000000000000001, pos=(0.20000000000000001, 0, -0.65000000000000002), borderWidth=(0.10000000000000001, 0.10000000000000001), text='save pt0') self.saveState1Button = DirectButton(guiId='save1Button', parent=self.mainFrame, scale=0.10000000000000001, pos=(0.59999999999999998, 0, -0.65000000000000002), borderWidth=(0.10000000000000001, 0.10000000000000001), text='save pt1')
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 MapConfig(DirectFrame): def __init__(self, *args, **kwargs): kwargs['suppressMouse'] = 0 super(self.__class__, self).__init__(*args, **kwargs) self.initialiseoptions(self.__class__) self.setTransparency(1) self.setup() def setup(self): if hasattr(self, 'mainFrame'): self.mainFrame.destroy() self.mainFrame = DirectFrame(parent=self, relief=None) def setVisibility(): value = self.visSlider['value'] self.setColorScale(Vec4(1, 1, 1, value)) self.visSlider = DirectSlider(guiId='visSlider', parent=self.mainFrame, scale=0.4, thumb_relief=DGG.FLAT, thumb_color=(0.25, 1.0, 0.25, 1), pos=(0.4, 0, -0.85), text='Visibility', text_scale=0.2, text_pos=(0, 0.1, 0), text_bg=(0.8, 0.8, 0.8, 1), value=1.0, command=setVisibility) self.visSlider.getChild(0).setTransparency(0) self.camFrame = DirectFrame(guiId='camFrame', parent=self.mainFrame, relief=DGG.RIDGE, frameSize=(0.0, 0.8, 0.0, 0.32), frameColor=(1, 1, 0.75, 1), borderWidth=(0.005, 0.005), pos=(0, 0, 0.6), text='Camera', text_fg=(0, 0, 0, 1), text_scale=0.05, text_pos=(0.1, 0.26, 0)) self.camSlider = RangeSlider(guiId='zoom', label='Zoom (Y-axis)', range=(-0.75, 0.25), value=0, parent=self.camFrame, pos=(0.395, 0, 0.07)) self.worldFrame = DirectFrame(guiId='worldFrame', parent=self.mainFrame, relief=DGG.RIDGE, frameSize=(0.0, 0.8, -0.55, 0.5), frameColor=(1, 0.75, 0.75, 1), borderWidth=(0.005, 0.005), pos=(0.0, 0, 0), text='World', text_fg=(0, 0, 0, 1), text_scale=0.05, text_pos=(0.1, 0.43, 0)) self.worldPSlider = RangeSlider(guiId='worldP', label='World P', range=(-90, 0), value=0.0, parent=self.worldFrame, pos=(0.395, 0, 0.24)) self.worldDecorScaleSlider = RangeSlider(guiId='worldP', label='World Decor Scale', range=(0.2, 0.3), value=0.25, parent=self.worldFrame, pos=(0.395, 0, 0.0)) self.finalSlider = RangeSlider(guiId='final', label='Final', range=(0, 1), value=0, parent=self.worldFrame, pos=(0.395, 0, -0.48)) self.saveState0Button = DirectButton(guiId='save0Button', parent=self.mainFrame, scale=0.1, pos=(0.2, 0, -0.65), borderWidth=(0.1, 0.1), text='save pt0') self.saveState1Button = DirectButton(guiId='save1Button', parent=self.mainFrame, scale=0.1, pos=(0.6, 0, -0.65), borderWidth=(0.1, 0.1), text='save pt1') return
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 do4d(DirectObject, HasKeybinds): def __init__(self): tsteps = 10 # this is really molecules npoints = 999 # this is realy timesteps self.slider = DirectSlider(range=(0, 1), value=0, pageSize=1, thumb_frameSize=(0, .04, -.02, .02), command=self.t_set) self.slider.setPos((0, 0, -.9)) data = np.cumsum(np.random.randint(-1, 2, (tsteps, npoints, 3)), axis=1) data2 = [data[:, i, :] for i in range(len(data[0]))] #embed() ctup = np.random.rand(tsteps, 4) tm1 = [ treeMe(None, d, np.array(['%s' % uuid4() for _ in d]), np.ones(len(d))) for d in data ] self.f1 = fourObject(make4d(data, ctup, geomType=GeomLinestrips), tm1) sc1 = lambda: self.set_selected(self.f1) self.f1.coll_parent.setPythonTag('selection_callbacks', [sc1]) self.set_selected(self.f1) tm2 = [ treeMe(None, d, np.array(['%s' % uuid4() for _ in d]), np.ones(len(d))) for d in data2 ] self.f2 = fourObject(make4d(data2, ctup), tm2) self.f2.set_size(3) self.f2.stash() sc2 = lambda: self.set_selected(self.f2) self.f2.coll_parent.setPythonTag('selection_callbacks', [sc2]) # TODO make clicking not on the button set the slider position? self.accept('s', self.set_selected, [self.f2]) def set_selected(self, fourObject): # TODO type check? self.selected = fourObject self.selected.unstash() self.slider['range'] = (0, len(self.selected) - 1) self.slider['value'] = fourObject.__index__ print('selected set to', fourObject) @event_callback('a') def t_all(self): if not self.selected._all: self.selected.show_all() else: self.selected.hide_all() def t_set(self): value = int(self.slider['value']) if value != self.selected.__index__: self.selected.goto_index(value) @event_callback((']', ']-repeat')) def t_up(self): #self.selected.next_index() self.slider['value'] = (self.slider['value'] + 1) % len(self.selected) @event_callback(('[', '[-repeat')) def t_down(self): #self.selected.prev_index() self.slider['value'] = (self.slider['value'] - 1) % len(self.selected)
def __init__(self, mesh, pm_filebuf): scene_members = getSceneMembers(mesh) base = ShowBase() if len(scene_members) > 1: print 'There is more than one geometry in the scene, so I think this is not a progressive base mesh.' sys.exit(1) rotateNode = GeomNode("rotater") rotatePath = render.attachNewNode(rotateNode) matrix = numpy.identity(4) if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP: r = collada.scene.RotateTransform(0, 1, 0, 90) matrix = r.matrix elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP: r = collada.scene.RotateTransform(1, 0, 0, 90) matrix = r.matrix rotatePath.setMat(Mat4(*matrix.T.flatten().tolist())) geom, renderstate, mat4 = scene_members[0] node = GeomNode("primitive") node.addGeom(geom) if renderstate is not None: node.setGeomState(0, renderstate) self.geomPath = rotatePath.attachNewNode(node) self.geomPath.setMat(mat4) wrappedNode = ensureCameraAt(self.geomPath, base.camera) base.disableMouse() attachLights(render) render.setShaderAuto() render.setTransparency(TransparencyAttrib.MDual, 1) base.render.analyze() KeyboardMovement() MouseDrag(wrappedNode) MouseScaleZoom(wrappedNode) ButtonUtils(wrappedNode) MouseCamera() print 'Loading pm into memory... ', sys.stdout.flush() self.pm_refinements = readPDAE(pm_filebuf) self.pm_index = 0 print 'Done' self.slider = DirectSlider(range=(0, len(self.pm_refinements)), value=0, pageSize=len(self.pm_refinements) / 20, command=self.sliderMoved, pos=(0, 0, -.9), scale=1) for key, val in uiArgs.iteritems(): self.slider.thumb[key] = val self.triText = OnscreenText(text="", pos=(-1, 0.85), scale=0.15, fg=(1, 0.5, 0.5, 1), align=TextNode.ALeft, mayChange=1) base.run()
def setup(self, node): colours = self.app.theme.colours SLIDER_PROPERTIES = { 'range': (0, 100), 'pageSize': 100, 'scrollSize': 0, 'parent': node, 'scale': 0.5, 'frameSize': (-0.85, 0.85, -0.08, 0.08), 'thumb_relief': DGG.RIDGE, } TEXT_PROPERTIES = { 'parent': node, 'text_scale': 0.08, 'text_fg': colours.listboxButtons, 'text_align': TextNode.A_left, 'relief': None, 'textMayChange': True, } label = DirectLabel( text='Music volume', **TEXT_PROPERTIES ) align(label, left=-0.85, midZ=0.25) self.musicSlider = DirectSlider(**SLIDER_PROPERTIES) align(self.musicSlider, left=-0.2, midZ=0.25) self.musicLabel = DirectLabel( text='100', **TEXT_PROPERTIES ) align(self.musicLabel, left=0.70, midZ=0.25) label = DirectLabel( text='Enable music', **TEXT_PROPERTIES ) align(label, left=-0.85, midZ=0.10) self.musicCheckbox = DirectCheckButton( scale=0.06, parent=node, command=self.applySettings, ) align(self.musicCheckbox, left=-0.2, midZ=0.10) label = DirectLabel( text='Sound volume', **TEXT_PROPERTIES ) align(label, left=-0.85, midZ=-0.05) self.soundSlider = DirectSlider(**SLIDER_PROPERTIES) align(self.soundSlider, left=-0.2, midZ=-0.05) self.soundLabel = DirectLabel( text='100', **TEXT_PROPERTIES ) align(self.soundLabel, left=0.70, midZ=-0.05) label = DirectLabel( text='Enable sound', **TEXT_PROPERTIES ) align(label, left=-0.85, midZ=-0.20) self.soundCheckbox = DirectCheckButton( scale=0.06, parent=node, command=self.applySettings, ) align(self.soundCheckbox, left=-0.2, midZ=-0.20) BUTTON_PROPERTIES = { 'scale': 0.04, 'frameSize': (-5.0, 5.0, -1.0, 1.5), 'parent': node, } button = DirectButton( text='Back', command=self.parent.showMainButtons, **BUTTON_PROPERTIES ) align(button, right=0.87, z=-0.63)
class OptionPage(StateData): def __init__(self, book, parentFSM): self.book = book self.parentFSM = parentFSM StateData.__init__(self, 'optionPageDone') self.fsm = ClassicFSM('OptionPage', [ State('off', self.enterOff, self.exitOff), State('basePage', self.enterBasePage, self.exitBasePage), State('displayPage', self.enterDisplayPage, self.exitDisplayPage) ], 'off', 'off') self.fsm.enterInitialState() self.parentFSM.getStateNamed('optionPage').addChild(self.fsm) def enterOff(self): pass def exitOff(self): pass def load(self): StateData.load(self) def unload(self): StateData.unload(self) def enter(self): StateData.enter(self) self.fsm.request('basePage') def exit(self): self.fsm.request('off') StateData.exit(self) def openDisplayPage(self): self.fsm.request('displayPage') def enterDisplayPage(self): self.book.createPageButtons(False, False) self.book.setTitle('Display Options') dialog_gui = loader.loadModel( 'phase_3/models/gui/dialog_box_buttons_gui.bam') width, height, fs, music, sfx, tex_detail, model_detail, aa, af = SettingsManager( ).getSettings('settings.json') self.width = width self.height = height self.windowType = [fs] self.buttons = [ DirectRadioButton(text='Windowed', variable=self.windowType, value=[False], scale=0.1, pos=(-0.45, 0.15, 0.15)), DirectRadioButton(text='Fullscreen', variable=self.windowType, value=[True], scale=0.1, pos=(-0.45, -0.15, -0.15)) ] for button in self.buttons: button.setOthers(self.buttons) self.resoLbl = DirectLabel(text='%sx%s' % (width, height), scale=0.08, relief=None, pos=(0.25, 0, 0)) self.resSlider = DirectSlider(range=(0, 200), pageSize=50, command=self.setResoText, scale=0.3, orientation=DGG.VERTICAL, pos=(0.6, 0, 0)) self.okBtn = DirectButton(text='OK', geom=CIGlobals.getOkayBtnGeom(), relief=None, pos=(-0.5, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.applyDisplaySettings) self.cancelBtn = DirectButton(text='Cancel', geom=CIGlobals.getCancelBtnGeom(), relief=None, pos=(-0.3, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.cancelDisplaySettings) if self.resoLbl['text'] == '640x480': self.resSlider['value'] = 0 else: if self.resoLbl['text'] == '800x600': self.resSlider['value'] = 50 else: if self.resoLbl['text'] == '1024x768': self.resSlider['value'] = 100 else: if self.resoLbl['text'] == '1280x1024': self.resSlider['value'] = 150 else: if self.resoLbl['text'] == '1600x1200': self.resSlider['value'] = 200 return def exitDisplayPage(self): for button in self.buttons: button.destroy() del button self.resoLbl.destroy() del self.resoLbl self.resSlider.destroy() del self.resSlider self.okBtn.destroy() del self.okBtn self.cancelBtn.destroy() del self.cancelBtn del self.width del self.height del self.windowType del self.buttons self.book.clearTitle() def changeSetting(self, setting, value): if setting == 'music': if value: value = False else: if not value: value = True base.enableMusic(value) self.music_btn['extraArgs'] = ['music', value] if value: valueTxt = 'On' else: valueTxt = 'Off' self.music_lbl['text'] = str(valueTxt).capitalize() else: if setting == 'sfx': if value: value = False else: if not value: value = True base.enableSoundEffects(value) self.sfx_btn['extraArgs'] = ['sfx', value] if value: valueTxt = 'On' else: valueTxt = 'Off' self.sfx_lbl['text'] = str(valueTxt).capitalize() else: if setting == 'model-detail': if value == 'high': value = 'low' else: if value == 'medium': value = 'high' else: if value == 'low': value = 'medium' self.moddet_lbl['text'] = value.capitalize() self.moddet_btn['extraArgs'] = ['model-detail', value] else: if setting == 'texture-detail': if value == 'normal': value = 'low' loadPrcFileData('', 'compressed-textures 1') else: if value == 'low': value = 'normal' loadPrcFileData('', 'compressed-textures 0') self.texdet_lbl['text'] = value.capitalize() self.texdet_btn['extraArgs'] = [ 'texture-detail', value ] else: if setting == 'aa': if value == 'on': value = 'off' render.clear_antialias() else: if value == 'off': value = 'on' render.set_antialias(AntialiasAttrib.MAuto) self.aa_lbl['text'] = value.capitalize() self.aa_btn['extraArgs'] = ['aa', value] else: if setting == 'af': if value == 'on': value = 'off' else: if value == 'off': value = 'on' self.af_lbl['text'] = value.capitalize() self.af_btn['extraArgs'] = ['af', value] SettingsManager().writeSettingToFile(setting, value, 'settings.json') def setResoText(self): if self.resSlider['value'] == 200: self.width = 1600 self.height = 1200 else: if 150 <= self.resSlider['value'] <= 199: self.width = 1280 self.height = 1024 else: if 100 <= self.resSlider['value'] <= 149: self.width = 1024 self.height = 768 else: if 50 <= self.resSlider['value'] <= 99: self.width = 800 self.height = 600 else: if self.resSlider['value'] == 0: self.width = 640 self.height = 480 self.resoLbl['text'] = str(self.width) + 'x' + str(self.height) def applyDisplaySettings(self): SettingsManager().writeSettingToFile('resolution', (self.width, self.height), 'settings.json', apply=1) SettingsManager().writeSettingToFile('fullscreen', self.windowType, 'settings.json', apply=1) self.fsm.request('basePage') def cancelDisplaySettings(self): self.fsm.request('basePage') def enterBasePage(self): self.book.createPageButtons(None, 'districtPage') self.book.setTitle('Options') width, height, fs, music, sfx, tex_detail, model_detail, aa, af = SettingsManager( ).getSettings('settings.json') if music: musicTxt = 'On' else: musicTxt = 'Off' if sfx: sfxTxt = 'On' else: sfxTxt = 'Off' if fs: fsTxt = 'On' else: fsTxt = 'Off' self.music_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='Music', scale=1, text_scale=0.055, command=self.changeSetting, extraArgs=['music', music], pos=(-0.45, 0.55, 0.55), text_pos=(0, -0.01)) self.music_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.55, 0.52), text_align=TextNode.ACenter) self.music_lbl['text'] = str(musicTxt).capitalize() self.sfx_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='SFX', scale=1, text_scale=0.055, command=self.changeSetting, extraArgs=['sfx', sfx], pos=(-0.45, 0.45, 0.45), text_pos=(0, -0.01)) self.sfx_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.45, 0.42), text_align=TextNode.ACenter) self.sfx_lbl['text'] = str(sfxTxt).capitalize() self.moddet_btn = DirectButton( geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='Model Detail', scale=1, text_scale=0.055, command=self.changeSetting, extraArgs=['model-detail', model_detail], pos=(-0.45, 0.35, 0.35), text_pos=(0, -0.01)) self.moddet_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.35, 0.32), text_align=TextNode.ACenter) self.moddet_lbl['text'] = model_detail.capitalize() self.moddet_btn.bind(DGG.ENTER, self.createMustRestartGui) self.moddet_btn.bind(DGG.EXIT, self.removeMustRestartGui) self.texdet_btn = DirectButton( geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='Texture Detail', scale=1, text_scale=0.0535, command=self.changeSetting, extraArgs=['texture-detail', tex_detail], pos=(-0.45, 0.25, 0.25), text_pos=(0, -0.01)) self.texdet_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.25, 0.22), text_align=TextNode.ACenter) self.texdet_lbl['text'] = tex_detail.capitalize() self.texdet_btn.bind(DGG.ENTER, self.createMustRestartGui) self.texdet_btn.bind(DGG.EXIT, self.removeMustRestartGui) self.display_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='Display', command=self.openDisplayPage, scale=1, text_scale=0.0535, pos=(-0.45, -0.25, 0.02), text_pos=(0, -0.01)) self.display_lbl = DirectLabel(relief=None, scale=0.06, pos=(0.45, -0.25, 0.02), text_align=TextNode.ACenter) self.display_lbl['text'] = 'Fullscreen: %s\nResolution: %s' % ( str(fsTxt).capitalize(), (width, height)) self.aa_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='Anti-Aliasing', command=self.changeSetting, extraArgs=['aa', aa], scale=1, text_scale=0.0535, pos=(-0.45, -0.35, -0.18), text_pos=(0, -0.01)) self.aa_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, -0.35, -0.21), text_align=TextNode.ACenter) self.aa_lbl['text'] = aa.capitalize() self.af_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='Anisotropic Filtering', command=self.changeSetting, extraArgs=['af', af], scale=1, text_scale=0.0435, pos=(-0.45, -0.35, -0.28), text_pos=(0, -0.01)) self.af_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, -0.35, -0.31), text_align=TextNode.ACenter) self.af_lbl['text'] = af.capitalize() self.af_btn.bind(DGG.ENTER, self.createMustRestartGui) self.af_btn.bind(DGG.EXIT, self.removeMustRestartGui) self.exit_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text='Exit Toontown', scale=1.2, text_scale=0.0535, command=self.book.finished, extraArgs=['exit'], pos=(-0.45, -0.65, -0.6), text_pos=(0, -0.01)) return def createMustRestartGui(self, foo): self.mustRestartLbl = DirectLabel( text='Changing this setting requires a game restart.', text_fg=(0.9, 0, 0, 1), text_shadow=(0, 0, 0, 1), text_scale=0.06, text_align=TextNode.ACenter, pos=(0, 0, -0.435), relief=None) return def removeMustRestartGui(self, foo): if hasattr(self, 'mustRestartLbl'): self.mustRestartLbl.destroy() del self.mustRestartLbl def exitBasePage(self): self.music_btn.destroy() del self.music_btn self.sfx_btn.destroy() del self.sfx_btn self.moddet_btn.destroy() del self.moddet_btn self.texdet_btn.destroy() del self.texdet_btn self.display_btn.destroy() del self.display_btn self.aa_btn.destroy() del self.aa_btn self.exit_btn.destroy() del self.exit_btn self.music_lbl.destroy() del self.music_lbl self.sfx_lbl.destroy() del self.sfx_lbl self.moddet_lbl.destroy() del self.moddet_lbl self.texdet_lbl.destroy() del self.texdet_lbl self.display_lbl.destroy() del self.display_lbl self.aa_lbl.destroy() del self.aa_lbl self.af_btn.destroy() del self.af_btn self.af_lbl.destroy() del self.af_lbl self.book.deletePageButtons(False, True) self.book.clearTitle()
class Option: """docstring for Option""" def __init__(self): self.testMusic = loader.loadMusic("Audio/click.wav") self.testSfx = loader.loadSfx("Audio/click.wav") self.frameOption = DirectFrame(image="gui/BackGround_o.png", image_scale=(1.7778, 1, 1), frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0, 0, 0, 0)) self.frameOption.setTransparency(1) self.title = DirectLabel(scale=0.15, text_align=TextNode.ALeft, pos=(-0.3, 0, 0.5), frameColor=(0, 0, 0, 0), text="", text_fg=(1, 1, 1, 1)) self.title.setTransparency(1) self.title.reparentTo(self.frameOption) self.title_volume = DirectLabel(scale=0.1, text_align=TextNode.ALeft, pos=(base.a2dLeft + 1.3, 0, -0.2), frameColor=(0, 0, 0, 0), text="Music", text_fg=(1, 1, 1, 1)) self.title_volume.setTransparency(1) self.title_volume.reparentTo(self.frameOption) self.slider_volume = DirectSlider(pos=(base.a2dLeft + 2.2, 0, -0.2), value=50, range=(0, 100), pageSize=5, scale=0.5, command=base.messenger.send, extraArgs=["ChangeVolume"]) self.slider_volume.reparentTo(self.frameOption) self.testMusicBtn = self.createButton(-0.2, self.testMusic) self.title_sound = DirectLabel(scale=0.1, text_align=TextNode.ALeft, pos=(base.a2dLeft + 1.3, 0, -0.4), frameColor=(0, 0, 0, 0), text="Sfx", text_fg=(1, 1, 1, 1)) self.title_sound.setTransparency(1) self.title_sound.reparentTo(self.frameOption) self.slider_sound = DirectSlider( pos=(base.a2dLeft + 2.2, 0, -0.4), value=50, range=(0, 100), pageSize=5, #frameSize = (1,1,1,1) scale=0.5, command=base.messenger.send, extraArgs=["ChangeSound"]) self.slider_sound.reparentTo(self.frameOption) self.testSfxBtn = self.createButton(-0.4, self.testSfx) # self.title_leapmotion = DirectLabel( # scale = 0.1, # text_align = TextNode.ALeft, # pos = (base.a2dLeft + 0.6 , 0, -0.6), # frameColor = (0, 0, 0, 0), # text = "Leapmotion", # text_fg = (1,1,1,1)) # self.title_leapmotion.reparentTo(self.frameOption) # self.cbtn_leapmotion = DirectCheckButton( # text = "needed",text_fg=(1,1,1,1), # scale = .1, # pos = (base.a2dLeft + 1.5 , 0, -0.6), # command = base.messenger.send, # extraArgs = ["ChangeLeapmotion"]) # self.cbtn_leapmotion.reparentTo(self.frameOption) self.hide() def createButton(self, verticalPos, eventArgs): maps = loader.loadModel("gui/button_map") btnGeom = (maps.find("**/btn_ready"), maps.find("**/btn_click"), maps.find("**/btn_rollover"), maps.find("**/btn_disabled")) btn = DirectButton(text="apply", text_fg=(1, 1, 1, 1), text_scale=0.05, text_pos=(0.15, -0.013), text_align=TextNode.ALeft, scale=2, geom=btnGeom, pos=(base.a2dRight - 0.7, 0, verticalPos), relief=0, frameColor=(1, 1, 1, 1), command=self.testPlay, extraArgs=[ eventArgs, ], pressEffect=True, rolloverSound=None) btn.reparentTo(self.frameOption) btn.setTransparency(1) return btn def testPlay(self, sound): sound.play() def show(self): self.frameOption.show() def hide(self): self.frameOption.hide()
class OptionPage(StateData): def __init__(self, book, parentFSM): self.book = book self.parentFSM = parentFSM StateData.__init__(self, 'optionPageDone') self.fsm = ClassicFSM('OptionPage', [ State('off', self.enterOff, self.exitOff), State('basePage', self.enterBasePage, self.exitBasePage), State('displayPage', self.enterDisplayPage, self.exitDisplayPage) ], 'off', 'off') self.fsm.enterInitialState() self.parentFSM.getStateNamed('optionPage').addChild(self.fsm) def enterOff(self): pass def exitOff(self): pass def load(self): StateData.load(self) def unload(self): StateData.unload(self) def enter(self): StateData.enter(self) self.fsm.request('basePage') def exit(self): self.fsm.request('off') StateData.exit(self) def openDisplayPage(self): self.fsm.request('displayPage') def enterDisplayPage(self): self.book.createPageButtons(False, False) self.book.setTitle("Display Options") dialog_gui = loader.loadModel( "phase_3/models/gui/dialog_box_buttons_gui.bam") width, height, fs, music, sfx, tex_detail, model_detail, aa, af = SettingsManager( ).getSettings("settings.json") self.width = width self.height = height self.windowType = [fs] self.buttons = [ DirectRadioButton(text="Windowed", variable=self.windowType, value=[False], scale=0.1, pos=(-0.45, 0.15, 0.15)), DirectRadioButton(text="Fullscreen", variable=self.windowType, value=[True], scale=0.1, pos=(-0.45, -0.15, -0.15)) ] for button in self.buttons: button.setOthers(self.buttons) self.resoLbl = DirectLabel(text="%sx%s" % (width, height), scale=0.08, relief=None, pos=(0.25, 0, 0)) self.resSlider = DirectSlider(range=(0, 200), pageSize=50, command=self.setResoText, scale=0.3, orientation=DGG.VERTICAL, pos=(0.6, 0, 0)) self.okBtn = DirectButton(text="OK", geom=CIGlobals.getOkayBtnGeom(), relief=None, pos=(-0.5, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.applyDisplaySettings) self.cancelBtn = DirectButton(text="Cancel", geom=CIGlobals.getCancelBtnGeom(), relief=None, pos=(-0.3, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.cancelDisplaySettings) if self.resoLbl['text'] == "640x480": self.resSlider['value'] = 0 elif self.resoLbl['text'] == "800x600": self.resSlider['value'] = 50 elif self.resoLbl['text'] == "1024x768": self.resSlider['value'] = 100 elif self.resoLbl['text'] == "1280x1024": self.resSlider['value'] = 150 elif self.resoLbl['text'] == "1600x1200": self.resSlider['value'] = 200 def exitDisplayPage(self): for button in self.buttons: button.destroy() del button self.resoLbl.destroy() del self.resoLbl self.resSlider.destroy() del self.resSlider self.okBtn.destroy() del self.okBtn self.cancelBtn.destroy() del self.cancelBtn del self.width del self.height del self.windowType del self.buttons self.book.clearTitle() def changeSetting(self, setting, value): if setting == "music": if value: value = False elif not value: value = True base.enableMusic(value) self.music_btn['extraArgs'] = ["music", value] if value: valueTxt = "On" else: valueTxt = "Off" self.music_lbl['text'] = str(valueTxt).capitalize() elif setting == "sfx": if value: value = False elif not value: value = True base.enableSoundEffects(value) self.sfx_btn['extraArgs'] = ["sfx", value] if value: valueTxt = "On" else: valueTxt = "Off" self.sfx_lbl['text'] = str(valueTxt).capitalize() elif setting == "model-detail": if value == "high": value = "low" elif value == "medium": value = "high" elif value == "low": value = "medium" self.moddet_lbl['text'] = value.capitalize() self.moddet_btn['extraArgs'] = ["model-detail", value] elif setting == "texture-detail": if value == "normal": value = "low" loadPrcFileData("", "compressed-textures 1") elif value == "low": value = "normal" loadPrcFileData("", "compressed-textures 0") self.texdet_lbl['text'] = value.capitalize() self.texdet_btn['extraArgs'] = ["texture-detail", value] elif setting == "aa": if value == "on": value = "off" render.clear_antialias() elif value == "off": value = "on" render.set_antialias(AntialiasAttrib.MAuto) self.aa_lbl['text'] = value.capitalize() self.aa_btn['extraArgs'] = ["aa", value] elif setting == "af": if value == "on": value = "off" elif value == "off": value = "on" self.af_lbl['text'] = value.capitalize() self.af_btn['extraArgs'] = ["af", value] SettingsManager().writeSettingToFile(setting, value, "settings.json") def setResoText(self): if self.resSlider['value'] == 200: self.width = 1600 self.height = 1200 elif 150 <= self.resSlider['value'] <= 199: self.width = 1280 self.height = 1024 elif 100 <= self.resSlider['value'] <= 149: self.width = 1024 self.height = 768 elif 50 <= self.resSlider['value'] <= 99: self.width = 800 self.height = 600 elif self.resSlider['value'] == 0: self.width = 640 self.height = 480 self.resoLbl['text'] = str(self.width) + "x" + str(self.height) def applyDisplaySettings(self): SettingsManager().writeSettingToFile("resolution", (self.width, self.height), "settings.json", apply=1) SettingsManager().writeSettingToFile("fullscreen", self.windowType, "settings.json", apply=1) self.fsm.request('basePage') def cancelDisplaySettings(self): self.fsm.request('basePage') def enterBasePage(self): self.book.createPageButtons(None, 'districtPage') self.book.setTitle("Options") width, height, fs, music, sfx, tex_detail, model_detail, aa, af = SettingsManager( ).getSettings("settings.json") if music: musicTxt = "On" else: musicTxt = "Off" if sfx: sfxTxt = "On" else: sfxTxt = "Off" if fs: fsTxt = "On" else: fsTxt = "Off" self.music_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="Music", scale=1, text_scale=0.055, command=self.changeSetting, extraArgs=["music", music], pos=(-0.45, 0.55, 0.55), text_pos=(0, -0.01)) self.music_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.55, 0.52), text_align=TextNode.ACenter) self.music_lbl['text'] = str(musicTxt).capitalize() self.sfx_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="SFX", scale=1, text_scale=0.055, command=self.changeSetting, extraArgs=["sfx", sfx], pos=(-0.45, 0.45, 0.45), text_pos=(0, -0.01)) self.sfx_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.45, 0.42), text_align=TextNode.ACenter) self.sfx_lbl['text'] = str(sfxTxt).capitalize() self.moddet_btn = DirectButton( geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="Model Detail", scale=1, text_scale=0.055, command=self.changeSetting, extraArgs=["model-detail", model_detail], pos=(-0.45, 0.35, 0.35), text_pos=(0, -0.01)) self.moddet_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.35, 0.32), text_align=TextNode.ACenter) self.moddet_lbl['text'] = model_detail.capitalize() self.moddet_btn.bind(DGG.ENTER, self.createMustRestartGui) self.moddet_btn.bind(DGG.EXIT, self.removeMustRestartGui) self.texdet_btn = DirectButton( geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="Texture Detail", scale=1, text_scale=0.0535, command=self.changeSetting, extraArgs=["texture-detail", tex_detail], pos=(-0.45, 0.25, 0.25), text_pos=(0, -0.01)) self.texdet_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, 0.25, 0.22), text_align=TextNode.ACenter) self.texdet_lbl['text'] = tex_detail.capitalize() self.texdet_btn.bind(DGG.ENTER, self.createMustRestartGui) self.texdet_btn.bind(DGG.EXIT, self.removeMustRestartGui) self.display_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="Display", command=self.openDisplayPage, scale=1, text_scale=0.0535, pos=(-0.45, -0.25, 0.02), text_pos=(0, -0.01)) self.display_lbl = DirectLabel(relief=None, scale=0.06, pos=(0.45, -0.25, 0.02), text_align=TextNode.ACenter) self.display_lbl['text'] = "Fullscreen: %s\nResolution: %s" % ( str(fsTxt).capitalize(), (width, height)) self.aa_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="Anti-Aliasing", command=self.changeSetting, extraArgs=["aa", aa], scale=1, text_scale=0.0535, pos=(-0.45, -0.35, -0.18), text_pos=(0, -0.01)) self.aa_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, -0.35, -0.21), text_align=TextNode.ACenter) self.aa_lbl['text'] = aa.capitalize() self.af_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="Anisotropic Filtering", command=self.changeSetting, extraArgs=["af", af], scale=1, text_scale=0.0435, pos=(-0.45, -0.35, -0.28), text_pos=(0, -0.01)) self.af_lbl = DirectLabel(relief=None, scale=0.09, pos=(0.45, -0.35, -0.31), text_align=TextNode.ACenter) self.af_lbl['text'] = af.capitalize() self.af_btn.bind(DGG.ENTER, self.createMustRestartGui) self.af_btn.bind(DGG.EXIT, self.removeMustRestartGui) self.exit_btn = DirectButton(geom=(qt_btn.find('**/QuitBtn_UP'), qt_btn.find('**/QuitBtn_DN'), qt_btn.find('**/QuitBtn_RLVR')), relief=None, text="Exit Toontown", scale=1.2, text_scale=0.0535, command=self.book.finished, extraArgs=["exit"], pos=(-0.45, -0.65, -0.60), text_pos=(0, -0.01)) def createMustRestartGui(self, foo): self.mustRestartLbl = DirectLabel( text="Changing this setting requires a game restart.", text_fg=(0.9, 0, 0, 1), text_shadow=(0, 0, 0, 1), text_scale=0.06, text_align=TextNode.ACenter, pos=(0, 0, -0.435), relief=None) def removeMustRestartGui(self, foo): if hasattr(self, 'mustRestartLbl'): self.mustRestartLbl.destroy() del self.mustRestartLbl def exitBasePage(self): self.music_btn.destroy() del self.music_btn self.sfx_btn.destroy() del self.sfx_btn self.moddet_btn.destroy() del self.moddet_btn self.texdet_btn.destroy() del self.texdet_btn self.display_btn.destroy() del self.display_btn self.aa_btn.destroy() del self.aa_btn self.exit_btn.destroy() del self.exit_btn self.music_lbl.destroy() del self.music_lbl self.sfx_lbl.destroy() del self.sfx_lbl self.moddet_lbl.destroy() del self.moddet_lbl self.texdet_lbl.destroy() del self.texdet_lbl self.display_lbl.destroy() del self.display_lbl self.aa_lbl.destroy() del self.aa_lbl self.af_btn.destroy() del self.af_btn self.af_lbl.destroy() del self.af_lbl self.book.deletePageButtons(False, True) self.book.clearTitle()
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()
def __init__(self): self.testMusic = loader.loadMusic("Audio/click.wav") self.testSfx = loader.loadSfx("Audio/click.wav") self.frameOption = DirectFrame(image="gui/BackGround_o.png", image_scale=(1.7778, 1, 1), frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0, 0, 0, 0)) self.frameOption.setTransparency(1) self.title = DirectLabel(scale=0.15, text_align=TextNode.ALeft, pos=(-0.3, 0, 0.5), frameColor=(0, 0, 0, 0), text="", text_fg=(1, 1, 1, 1)) self.title.setTransparency(1) self.title.reparentTo(self.frameOption) self.title_volume = DirectLabel(scale=0.1, text_align=TextNode.ALeft, pos=(base.a2dLeft + 1.3, 0, -0.2), frameColor=(0, 0, 0, 0), text="Music", text_fg=(1, 1, 1, 1)) self.title_volume.setTransparency(1) self.title_volume.reparentTo(self.frameOption) self.slider_volume = DirectSlider(pos=(base.a2dLeft + 2.2, 0, -0.2), value=50, range=(0, 100), pageSize=5, scale=0.5, command=base.messenger.send, extraArgs=["ChangeVolume"]) self.slider_volume.reparentTo(self.frameOption) self.testMusicBtn = self.createButton(-0.2, self.testMusic) self.title_sound = DirectLabel(scale=0.1, text_align=TextNode.ALeft, pos=(base.a2dLeft + 1.3, 0, -0.4), frameColor=(0, 0, 0, 0), text="Sfx", text_fg=(1, 1, 1, 1)) self.title_sound.setTransparency(1) self.title_sound.reparentTo(self.frameOption) self.slider_sound = DirectSlider( pos=(base.a2dLeft + 2.2, 0, -0.4), value=50, range=(0, 100), pageSize=5, #frameSize = (1,1,1,1) scale=0.5, command=base.messenger.send, extraArgs=["ChangeSound"]) self.slider_sound.reparentTo(self.frameOption) self.testSfxBtn = self.createButton(-0.4, self.testSfx) # self.title_leapmotion = DirectLabel( # scale = 0.1, # text_align = TextNode.ALeft, # pos = (base.a2dLeft + 0.6 , 0, -0.6), # frameColor = (0, 0, 0, 0), # text = "Leapmotion", # text_fg = (1,1,1,1)) # self.title_leapmotion.reparentTo(self.frameOption) # self.cbtn_leapmotion = DirectCheckButton( # text = "needed",text_fg=(1,1,1,1), # scale = .1, # pos = (base.a2dLeft + 1.5 , 0, -0.6), # command = base.messenger.send, # extraArgs = ["ChangeLeapmotion"]) # self.cbtn_leapmotion.reparentTo(self.frameOption) 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, mesh_path, progressive_texture_path): resolutions = [] f = tarfile.open(progressive_texture_path) for resolution_name in f.getnames(): toset = { 'size': resolution_name[:-4], 'contents': f.extractfile(resolution_name).read() } texpnm = PNMImage() texpnm.read(StringStream(toset['contents']), 'something.jpg') newtex = Texture() newtex.load(texpnm) toset['texture'] = newtex resolutions.append(toset) self.resolutions = resolutions def aux_loader(fname): return resolutions[0]['contents'] mesh = collada.Collada(mesh_path, aux_file_loader=aux_loader) scene_members = getSceneMembers(mesh) base = ShowBase() rotateNode = GeomNode("rotater") rotatePath = render.attachNewNode(rotateNode) matrix = numpy.identity(4) if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP: r = collada.scene.RotateTransform(0, 1, 0, 90) matrix = r.matrix elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP: r = collada.scene.RotateTransform(1, 0, 0, 90) matrix = r.matrix rotatePath.setMat(Mat4(*matrix.T.flatten().tolist())) geom, renderstate, mat4 = scene_members[0] node = GeomNode("primitive") node.addGeom(geom) if renderstate is not None: node.setGeomState(0, renderstate) self.geomPath = rotatePath.attachNewNode(node) self.geomPath.setMat(mat4) wrappedNode = ensureCameraAt(self.geomPath, base.camera) base.disableMouse() attachLights(render) render.setShaderAuto() render.setTransparency(TransparencyAttrib.MDual, 1) base.render.analyze() KeyboardMovement() MouseDrag(wrappedNode) MouseScaleZoom(wrappedNode) MouseCamera() num_resolutions = len(resolutions) - 1 self.slider = DirectSlider(range=(0, num_resolutions), value=0, pageSize=1, command=self.sliderMoved, pos=(0, 0, -.9), scale=1) for key, val in uiArgs.iteritems(): self.slider.thumb[key] = val self.triText = OnscreenText(text="", pos=(-1, 0.85), scale=0.15, fg=(1, 0.5, 0.5, 1), align=TextNode.ALeft, mayChange=1) base.run()
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)