class GUI: def __init__(self, rootParent=None): self.volume = DirectSlider( pos=LPoint3f(0.2, 0, 0.325), text='Volume', text_pos=(-1.05, -0.02), text_fg=(1, 1, 1, 1), text_scale=0.1, text_align=TextNode.ARight, parent=rootParent, command=base.messenger.send, extraArgs=["volumeChange"], ) self.volume.setTransparency(0) self.audioMute = DirectCheckButton( frameSize=(-2.925000047683716, 3.024999713897705, -0.225, 0.8250000238418579), pos=LPoint3f(0, 0, 0), scale=LVecBase3f(0.1, 0.1, 0.1), text='Mute', parent=rootParent, command=self.toggleMute, ) self.audioMute.setTransparency(0) self.btnBack = DirectButton( frameSize=(-1.5249999523162843, 1.6499999523162843, -0.21250001192092896, 0.8250000238418579), pos=LPoint3f(0, 0, -0.575), scale=LVecBase3f(0.1, 0.1, 0.1), text='Back', parent=rootParent, command=base.messenger.send, extraArgs=["optionBack"], pressEffect=1, ) self.btnBack.setTransparency(0) self.fullscreen = DirectCheckButton( frameSize=(-3.35, 2.6, -0.213, 0.825), pos=LPoint3f(0.045, 0, -0.175), scale=LVecBase3f(0.1, 0.1, 0.1), text='Fullscreen', parent=rootParent, command=self.toggleFullscreen, ) self.fullscreen.setTransparency(0) def show(self): self.volume.show() self.audioMute.show() self.btnBack.show() self.fullscreen.show() def hide(self): self.volume.hide() self.audioMute.hide() self.btnBack.hide() self.fullscreen.hide() def destroy(self): self.volume.destroy() self.audioMute.destroy() self.btnBack.destroy() self.fullscreen.destroy()
class MainMenu(ShowBase): def __init__(self): ShowBase.__init__(self) self.accept("Exit",self.__exit) self.__rm = ResourcesManager() self.__destroySetting = False # 菜单界面 def start(self): #全屏 self.setFullScreen(0) #load background image self.__image = OnscreenImage(image='../../resources/images/menu/home1.png',scale=1) self.__image.setSx(self.getAspectRatio()) self.__image.setTransparency(TransparencyAttrib.MAlpha) # 监听输入 self.__keyInput = MenuPlayerInputHandler() self.accept("NewGame",self.__new_game) self.accept("LoadGame",self.__load_game) self.accept("Description",self.__description) self.accept("ChangeMenu",self.__change_menu) self.accept("a",self.setting_menu) self.accept("b",self.setting_destroy) # 设置全屏 def setFullScreen(self,full): if full == 1 : self.__setFullscreen(2560,1600,0,0,1) else: self.__setFullscreen(800,600,150,50,0) # 清除界面,清除监听 def destroy(self): self.__image.destroy() self.__keyInput.destroy() # 私有函数,选择全屏 def __setFullscreen(self, width, height, posX, posY, full): winProps = WindowProperties() winProps.setOrigin(posX, posY) winProps.setSize(width, height) winProps.setFullscreen(full) self.win.requestProperties(winProps) # 私有函数,进入新建游戏界面 def __new_game(self): print '进入new game' messenger.send("serious_new_game") print '发送了serious_new_game' # 私有函数,进入读取游戏界面 def __load_game(self): print '进入load game' messenger.send("serious_load_game") print '发送了serious_load_game' # 私有函数,进入about界面 def __description(self): print '进入description' messenger.send("serious_description") print '发送了serious_description' # 私有函数,用来自建的选择进入的游戏界面 def __change_mode(self,image_path): self.__image.setImage(image_path) def __exit(self): print '进入exit' # self.__del__() exit() # 私有函数,更改游戏目录 def __change_menu(self): switch_count = {0:'../../resources/images/menu/home1.png', 1:'../../resources/images/menu/home2.png', 2:'../../resources/images/menu/home3.png', 3:'../../resources/images/menu/home4.png',} self.__change_mode(switch_count[self.__keyInput.get_count()]) #设置界面 def setting_menu(self): if self.__destroySetting==False: # 设置界面背景图 self.__background = OnscreenImage(image='../../resources/images/settings/setting_frame.png', pos=(0, 0, 0), scale=(1.0, 0, 0.7)) self.__background.setTransparency(TransparencyAttrib.MAlpha) ##滑动条 self.__slider = DirectSlider(pos=(0.16, 0, 0.26), scale=0.5, value=0.5, command=self.__setMusicSliderVolume, frameSize=(-1.0, 0.9, -0.06, 0.06), image='../../resources/images/settings/slide_bar.png', image_pos=(-0.05, 0, 0.0), image_scale=(1.0, 0, 0.05), thumb_image='../../resources/images/settings/slide_btn.png', thumb_image_pos=(-0.0, 0, 0.0), thumb_image_scale=0.1, thumb_frameSize=(0.0, 0.0, 0.0, 0.0)) self.__slider.setTransparency(TransparencyAttrib.MAlpha) # self.__musicButton = DirectButton(pos=(0.9, 0, 0.75), text="Close", scale=0.1, pad=(0.2, 0.2), rolloverSound=None, # clickSound=None, command=self.toggleMusicBox,extraArgs=[base]) # 继续按钮 self.__continueButton = DirectButton(pos=(-0.25, 0, 0.0), text="", scale=(0.2, 0, 0.1), command=self.__continue_game, image=("../../resources/images/settings/btn_continue_0.png", "../../resources/images/settings/btn_continue_0.png" , "../../resources/images/settings/btn_continue_1.png"), frameColor=(0, 0, 0, 0)) self.__continueButton.setTransparency(TransparencyAttrib.MAlpha) # 存档按钮 self.__saveButton = DirectButton(pos=(0.33, 0, 0.0), text="", scale=(0.2, 0, 0.1), command=self.__save_game, image=("../../resources/images/settings/btn_save_0.png", "../../resources/images/settings/btn_save_0.png" , "../../resources/images/settings/btn_save_1.png"), frameColor=(0, 0, 0, 0)) self.__saveButton.setTransparency(TransparencyAttrib.MAlpha) # 帮助按钮 self.__helpButton = DirectButton(pos=(-0.25, 0, -0.25), text="", scale=(0.2, 0, 0.1), command=self.__help, image=("../../resources/images/settings/btn_help_0.png", "../../resources/images/settings/btn_help_0.png" , "../../resources/images/settings/btn_help_1.png"), frameColor=(0, 0, 0, 0)) self.__helpButton.setTransparency(TransparencyAttrib.MAlpha) # 回到主界面按钮 self.__homeButton = DirectButton(pos=(0.33, 0, -0.25), text="", scale=(0.2, 0, 0.1), command=self.__return_home, image=("../../resources/images/settings/btn_home_0.png", "../../resources/images/settings/btn_home_0.png" , "../../resources/images/settings/btn_home_1.png"), frameColor=(0, 0, 0, 0)) self.__homeButton.setTransparency(TransparencyAttrib.MAlpha) # 设置滑动条value self.__slider['value'] = self.__rm.get_volume() self.__destroySetting = True #移除设置界面所有控件 def setting_destroy(self): if self.__destroySetting==True: self.__background.destroy() self.__rm.set_volume(self.__slider['value']) self.__slider.destroy() # self.__musicButton.destroy() self.__continueButton.destroy() self.__saveButton.destroy() self.__helpButton.destroy() self.__homeButton.destroy() self.__destroySetting = False # 设置音乐声音大小 def __setMusicSliderVolume(self): newVolume = self.__slider.guiItem.getValue() self.__rm.set_volume(newVolume) # 设置界面,私有函数,继续游戏 def __continue_game(self): self.setting_destroy() # 设置界面,私有函数,存档 def __save_game(self): self.setting_destroy() # 设置界面,私有函数,游戏帮助 def __help(self): self.setting_destroy() # 设置界面,私有函数,回到主界面 def __return_home(self): self.setting_destroy()
class ToontownShaderManager(DirectFrame): def __init__(self, parent): self._parent = parent DirectFrame.__init__(self, parent=self._parent, relief=None, pos=(0.0, 0.0, 0.0), scale=(1.0, 1.0, 1.0)) self.filter = CommonFilters(base.win, base.cam) # Only affects primary window # Ambient Occlusion self.samples = 0 self.radius = 0.0 self.amount = 0.0 self.strength = 0.0 # Blur/Sharpen self.blur = 1.0 # this is normal value, 0.0 blurs it # Cartoon Ink self.cartoonSep = 0.0 self.cartoonR = 0.0 self.cartoonB = 0.0 self.cartoonG = 0.0 # todo: Add bloom # Boolean Filters self.HDREnabled = False self.invertedEnabled = False self.sRGBEnabled = False self.halfPixelShiftEnabled = False self.viewGlowEnabled = False # Other Filters self.exposure = 0.0 self.SAMPLES_MAX = 128 self.RAD_MAX = 1.0 self.AMT_MAX = 64.0 self.STR_MAX = 0.01 self.INCREMENT = 1 self.numSamples = None self.numRadius = None self.circleModel = loader.loadModel( 'phase_3/models/gui/tt_m_gui_mat_nameShop') self.barTexture = loader.loadTexture('phase_3/maps/slider.png') self.loadGUI() # self.newWindow() # Disabled for now def loadGUI(self): self.textRowHeight = 0.2 self.buttonbase_xcoord = 1.4 self.buttonbase_ycoord = 0.45 self.loadAmbientOcclusionGUI() self.loadBlurGUI() self.loadExposureGUI() self.loadCartoonInkGUI() self.loadHotkeys() def loadHotkeys(self): # for now instead of gui buttons i'ma just put the bool filters as hotkeys self.accept('4', self.__toggleHDR) self.accept('5', self.__toggleInverted) self.accept('6', self.__toggleSRGB) self.accept('7', self.__toggleHalfPixelShift) self.accept('8', self.__toggleViewGlow) def loadAmbientOcclusionGUI(self): self.numSamples = DirectSlider( parent=self, value=self.samples, pos=(self.buttonbase_xcoord + 0.1, 0.0, self.buttonbase_ycoord - self.textRowHeight * 3.5), thumb_relief=None, range=(0, 32), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeAOValue) # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength)) self.numSamples.setScale(0.5) self.numSamples.setTransparency(True) self.numSamplesText = OnscreenText( pos=(self.buttonbase_xcoord + 0.1, self.buttonbase_ycoord - self.textRowHeight * 3.2), scale=0.05, text="AO Sample Count = {}".format(self.samples), style=5, mayChange=True) self.numRadius = DirectSlider( parent=self, value=self.radius, pos=(self.buttonbase_xcoord + 0.1, 0.0, (self.buttonbase_ycoord - self.textRowHeight * 4.5)), thumb_relief=None, range=(0, 1), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeAOValue) self.numRadius.setScale(0.5) self.numRadius.setTransparency(True) self.numRadiusText = OnscreenText( pos=(self.buttonbase_xcoord + 0.1, self.buttonbase_ycoord - self.textRowHeight * 4.2), scale=0.05, text="AO Radius = {}".format(str(self.radius)), style=5, mayChange=True) self.numAmount = DirectSlider( parent=self, value=self.amount, pos=(self.buttonbase_xcoord + 0.1, 0.0, (self.buttonbase_ycoord - self.textRowHeight * 5.5)), thumb_relief=None, range=(0, 64), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeAOValue) self.numAmount.setScale(0.5) self.numAmount.setTransparency(True) self.numAmountText = OnscreenText( pos=(self.buttonbase_xcoord + 0.1, self.buttonbase_ycoord - self.textRowHeight * 5.2), scale=0.05, text="AO Amount = {}".format(self.amount), style=5, mayChange=True) self.numStrength = DirectSlider( parent=self, value=self.strength, pos=(self.buttonbase_xcoord + 0.1, 0.0, (self.buttonbase_ycoord - self.textRowHeight * 6.5)), thumb_relief=None, range=(0, 0.1), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeAOValue) self.numStrength.setScale(0.5) self.numStrength.setTransparency(True) self.numStrengthText = OnscreenText( pos=(self.buttonbase_xcoord + 0.1, self.buttonbase_ycoord - self.textRowHeight * 6.2), scale=0.05, text="AO Strength = {}".format(self.strength), style=5, mayChange=True) def loadCartoonInkGUI(self): self.cSep = DirectSlider( parent=self, value=self.cartoonSep, pos=(-self.buttonbase_xcoord + 0.1, 0.0, self.buttonbase_ycoord - self.textRowHeight * 2.5), thumb_relief=None, range=(0, 32), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeCartoon) # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength)) self.cSep.setScale(0.5) self.cSep.setTransparency(True) self.cRed = DirectSlider( parent=self, value=self.cartoonR, pos=(-self.buttonbase_xcoord + 0.1, 0.0, self.buttonbase_ycoord - self.textRowHeight * 3.5), thumb_relief=None, range=(0, 1), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeCartoon) # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength)) self.cRed.setScale(0.5) self.cRed.setTransparency(True) self.cBlue = DirectSlider( parent=self, value=self.cartoonB, pos=(-self.buttonbase_xcoord + 0.1, 0.0, self.buttonbase_ycoord - self.textRowHeight * 4.5), thumb_relief=None, range=(0, 1), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeCartoon) # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength)) self.cBlue.setScale(0.5) self.cBlue.setTransparency(True) self.cGreen = DirectSlider( parent=self, value=self.cartoonG, pos=(-self.buttonbase_xcoord + 0.1, 0.0, self.buttonbase_ycoord - self.textRowHeight * 5.5), thumb_relief=None, range=(0, 1), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeCartoon) # command=self.__changeAOValue(self.samples, self.radius, self.amount, self.strength)) self.cGreen.setScale(0.5) self.cGreen.setTransparency(True) def loadBlurGUI(self): self.numBlur = DirectSlider( parent=self, value=self.blur, # pos=(0.0, 0.0, 0.0), # for new window pos=(self.buttonbase_xcoord + 0.1, 0.0, (self.buttonbase_ycoord - self.textRowHeight * 0.5)), thumb_relief=None, range=(-10, 10), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeBlur) self.numBlur.setScale(0.5) self.numBlur.setTransparency(True) self.numBlurText = OnscreenText( pos=(self.buttonbase_xcoord + 0.1, self.buttonbase_ycoord - self.textRowHeight * 0.2), scale=0.05, text="Blur Amount = {}".format(self.blur), style=5, mayChange=True) def loadExposureGUI(self): self.numExposure = DirectSlider( parent=self, value=self.exposure, pos=(self.buttonbase_xcoord + 0.1, 0.0, (self.buttonbase_ycoord - self.textRowHeight * 2.2)), thumb_relief=None, range=(0, 5), # self.SAMPLES_MAX thumb_geom=self.circleModel.find( '**/tt_t_gui_mat_namePanelCircle'), frameTexture=self.barTexture, frameSize=(-0.5, 0.5, -0.08, 0.08), command=self.__changeExposure) self.numExposure.setScale(0.5) self.numExposure.setTransparency(True) self.numExposureText = OnscreenText( pos=(self.buttonbase_xcoord + 0.1, self.buttonbase_ycoord - self.textRowHeight * 1.9), scale=0.05, text="Exposure Amount = {}".format(self.blur), style=5, mayChange=True) def printValue(self): print(self.numSamples['value']) def __changeCartoon(self): self.filter.delCartoonInk() s = self.cSep['value'] self.cartoonSep = s r = self.cRed['value'] self.cartoonR = r b = self.cBlue['value'] self.cartoonB = b g = self.cGreen['value'] self.cartoonG = g self.filter.setCartoonInk(s, (r, g, b, 1)) # a doesn't change def __changeBlur(self): self.filter.delBlurSharpen() b = self.numBlur['value'] self.blur = b self.numBlurText.setText("Blur amount = {}".format(b)) self.filter.setBlurSharpen(b) def __changeAOValue(self): if self.numSamples is None: print("NONE") return self.filter.delAmbientOcclusion() s = self.numSamples['value'] self.samples = s self.numSamplesText.setText("AO Sample Count = {}".format(s)) if (s == 0): return r = self.numRadius['value'] self.radius = r self.numRadiusText.setText("AO Radius = {}".format(r)) if (r == 0): return a = self.numAmount['value'] self.amount = a self.numAmountText.setText("AO Amount = {}".format(a)) if (a == 0): return st = self.numStrength['value'] self.strength = st self.numStrengthText.setText("AO Strength = {}".format(st)) if (st == 0): return self.filter.setAmbientOcclusion(numsamples=s, radius=r, amount=a, strength=st) print( "sample count: {} | radius count: {} | amount count: {} | strength count: {}" .format(self.samples, self.radius, self.amount, self.strength)) # WARNING: Won't work with relatively older Panda versions because this is new def __changeExposure(self): self.filter.delExposureAdjust() e = self.numExposure['value'] self.exposure = e self.numExposureText.setText("Exposure amount = {}".format(e)) self.filter.setExposureAdjust(e) def __toggleInverted(self): if not self.invertedEnabled: self.filter.setInverted() self.invertedEnabled = True else: self.filter.delInverted() self.invertedEnabled = False def __toggleHDR(self): if not self.HDREnabled: self.filter.setHighDynamicRange() self.HDREnabled = True else: self.filter.delHighDynamicRange() self.HDREnabled = False def __toggleSRGB(self): if not self.sRGBEnabled: self.filter.setSrgbEncode(True) self.sRGBEnabled = True else: self.filter.delSrgbEncode() self.sRGBEnabled = False def __toggleHalfPixelShift(self): if not self.halfPixelShiftEnabled: self.filter.setHalfPixelShift() self.halfPixelShiftEnabled = True else: self.filter.delHalfPixelShift() self.halfPixelShiftEnabled = False def __toggleViewGlow(self): if not self.viewGlowEnabled: self.filter.setViewGlow() self.viewGlowEnabled = True else: self.filter.delViewGlow() self.viewGlowEnabled = False def getValue(self, item, item_MAX): return item / item_MAX # Not gonna use this feature since it makes it very laggy. I will have to figure out # a better way to layout UI some other time. # https://discourse.panda3d.org/t/how-to-open-a-new-window/23929/4 def newWindow(self): self.wp = WindowProperties() self.wp.setSize(700, 500) self.wp.setRawMice(True) print(self.wp.getMouseMode()) win2mouseWatcher = MouseWatcher() ar = 1 self.win2 = base.openWindow(props=self.wp, aspectRatio=ar) self.window2render2d = NodePath('window2render2d') self.window2render2d.setDepthTest(0) self.window2render2d.setDepthWrite(0) self.window2camera2d = base.makeCamera2d(self.win2) self.window2camera2d.reparentTo(self.window2render2d) # Parent gui to this self.window2aspect2d = self.window2render2d.attachNewNode( PGTop('window2aspect2d')) self.window2aspect2d.setScale(1.0 / ar, 1.0, 1.0) name = self.win2.getInputDeviceName(0) mk = base.dataRoot.attachNewNode(MouseAndKeyboard(self.win2, 0, name)) mw = mk.attachNewNode(MouseWatcher(name)) self.window2aspect2d.node().setMouseWatcher(mw.node())