def __buildSurface(self): self.res_surface = blankSurface((int(self.area.w), int(self.area.h)), self.__bgColor) if self.__offsetHeight >= 0: self.__areaBg = blankSurface((self.area.w, self.__allTextLength), self.__bgColor) if self.__verticalSlidLock: self.__verticalSlidLock = False else: self.__areaBg = blankSurface((self.area.w, self.area.h), self.__bgColor) if not self.__verticalSlidLock: self.__verticalSlidLock = True self.__buildTextSurface() if not self.__verticalSlidLock: slidHeight = (self.area.h / self.__allTextLength) * self.area.h self.__slid = blankSurface((self.__slidWidth, slidHeight), self.__slidColor) self.__slidPosY = self.__getSlidYByBgPos() if self.__areaBgPos[1] >= 0: self.__rollToTop = True else: self.__rollToTop = False if self.__allTextLength <= self.area.h + abs(self.__areaBgPos[1]): self.__rollToBottom = True else: self.__rollToBottom = False
def __init__(self, area, padding_x=10, padding_y=10, font=gl_Font, fontSize=16, readonly=False, bgColor=(0, 0, 0, 255), baseColor=(0, 0, 0, 255), fontColor=(-1, -1, -1, -1), slidColor=(255, 255, 255, 100), slidWidth=10, autoLine=True, lineSpace=5, textSpace=2): super(TextArea, self).__init__(area) self.__padding_x = padding_x self.__padding_y = padding_y self.__font = font self.__fontSize = fontSize self.__readonly = readonly self.__bgColor = bgColor self.__baseColor = baseColor self.__antiBgColor = (255 - self.__bgColor[0], 255 - self.__bgColor[1], 255 - self.__bgColor[2], 255) if fontColor == (-1, -1, -1, -1): self.__fontColor = self.__antiBgColor else: self.__fontColor = fontColor self.__slidColor = slidColor self.__slidWidth = slidWidth self.__autoLine = autoLine self.__lineSpace = lineSpace self.__textSpace = textSpace self.__verticalSlidLock = True self.__horizontalSlidLock = True self.__rollToTop = False self.__rollToBottom = False self.__allTextLength = 0 self.__maxTextWidth = 0 self.__text = '' self.__renderTextList = list() self.trueOneFontSize = self.__fontSize self.__offsetHeight = -1 self.res_surface = None self.__areaBg = blankSurface((self.area.w, self.area.h), self.__bgColor) self.__slid = blankSurface((self.__slidWidth, self.area.h), self.__slidColor) self.__fontType = pygame.font.Font(self.__font, self.__fontSize) self.__areaBgPos = (0, 0) self.__curPtr = 0 self.__lineList = list() self.__slidPosY = 0 self.__nextTextPosX = self.__padding_x self.__nextTextPosY = self.__padding_y self.__interval = 0 self.__showFlash = True self.Events.appendEvent(ioEvent3Enum.mouseRollDown, lambda: self.rollDown(True, self.trueOneFontSize), 1) self.Events.appendEvent(ioEvent3Enum.mouseRollUp, lambda: self.rollDown(False, self.trueOneFontSize), 1) self.Events.appendEvent(ioEvent3Enum.mouseLeftKeyDown, lambda: self.__mouKey(), 1) self.Events.appendEvent(ioEvent3Enum.mouseMotion, lambda: self.__dragSlidBar(), 1) self.Events.appendEvent(ioEvent3Enum.keyDown, self.keyInput, 1) self.Events.appendEvent(ioEvent3Enum.keyDowning, self.keyInput, 1) self.__buildSurface() self.__counter = 0
def __init__(self, area, caption, size): super(Button, self).__init__(area) self.__caption = caption self.__textSize = size self.__size = self.area.size() self.__resShader = blankSurface(self.__size, (10, 10, 10, 200)) self.__shaderRenderLocal = (self.area.x, self.area.y + 20) self.__resSuf = blankSurface(self.__size, (255, 255, 255)) self.__build() self.Events.appendEvent(ioEvent3Enum.mouseLeftKeyDown, lambda: self.__evn_chShader(True), 0) self.Events.appendEvent(ioEvent3Enum.mouseLeftKeyUp, lambda: self.__evn_chShader(False), 0)
def __buildSurface(self): if self.Path is None: self.res_surface = blankSurface(self.area.size(), (0, 0, 0, self.Alpha)) else: self.res_surface = pygame.image.load(self.Path) self.res_surface.set_alpha(self.Alpha) if self.ColorKey: self.res_surface.set_colorkey(self.ColorKey)
def __buildSurface(self): self.__E_bg = blankSurface((180, 100), (255, 255, 255, 100)) concernWidth = len(self.__Text) * 18 self.__E_Text = TextElement( pygame.Rect(centeredXPos(180, concernWidth, self.area.left), centeredYPos(100, 18, self.area.top), concernWidth, 20), self.__Text, gl_Font_opt, 18, (0, 0, 0), True) self.__E_okButt = TextElement( pygame.Rect(self.area.left + 40, self.area.top + 70, 36, 18), '确定', gl_Font_opt, 16, (0, 0, 0), True) self.__E_cancelButt = TextElement( pygame.Rect(self.area.left + 80, self.area.top + 70, 36, 18), '取消', gl_Font_opt, 16, (0, 0, 0), True)
def draw(self, screen): sec = time.clock() flashSurf = blankSurface((self.trueOneFontSize, self.trueOneFontSize), self.__bgColor) if sec - self.__interval >= 0.5: self.__showFlash = not self.__showFlash self.__interval = sec self.res_surface.fill(self.__bgColor) if self.__showFlash: flashSurf.blit(self.__fontType.render('|', 1, self.__antiBgColor), (0, 0)) self.__areaBg.blit(flashSurf, (self.__nextTextPosX, self.__nextTextPosY)) self.res_surface.blit(self.__areaBg, self.__areaBgPos) if not self.__verticalSlidLock: self.res_surface.blit(self.__slid, (self.area.w - self.__slidWidth, self.__slidPosY)) screen.blit(self.res_surface, (self.area.x, self.area.y))
def __init__(self, area, path): super(SudokuSprite, self).__init__(area, path) self.__index = (0, 0) self.__shaderDistance = 10 self.__mask = blankSurface((area.h, area.w), (40, 40, 40, 80)) self.__val = 0 self.__isStatic = False self.Events.appendEvent(ioEvent3Enum.mouseLeftKeyDown, lambda: self.__chaShader(True), 0) self.Events.appendEvent(ioEvent3Enum.mouseLeftKeyUp, lambda: self.__chaShader(False), 0) self.Events.appendEvent(ioEvent3Enum.mouseRightKeyDown, lambda: self.__clearVal(), 0)
def __init__(self, *args): super(OriginLogo, self).__init__(*args) # 注册与该场景相关的场景 from source.config.AppConfig import registerScene registerScene(101, OriginTitle) self.nextSceneNum = 101 self.resPath = {'logoText1': 'logo.jpg', 'logoText2': 'logo2.jpg'} self.bgSurface = blankSurface((self.width, self.height)) self.__ele_Logo1 = ImgElement((centeredXPos(self.width, 211), centeredYPos(self.height, 27) - 20, 211, 27), g_resPath + self.resPath['logoText1']) self.__ele_Logo2 = ImgElement((centeredXPos(self.width, 444), centeredYPos(self.height, 35) - 20, 444, 35), g_resPath + self.resPath['logoText2']) self.__ele_Logo2.visual = False self.__beginTime = 0 self.__nextTime = 0 self.__nowTime = 0
def setup(self): self.bgSurface = self.__sudokuMap.getBgSurface() self.__sucScore = self.__sudokuMap.getSucScore() self.__insertList = self.__sudokuMap.getInitSpritePosList() self.__mask = blankSurface(self.__sudokuMap.getSpriteSize(), (40, 40, 40, 80)) self.__allSprite = self.__sudokuMap.buildSpriteMap() self.createTextElement("Time:", color=(0, 0, 0), size=14) self.createTextElement("Level:" + self.__sudokuMap.getName(), color=(0, 0, 0), size=14, pos=self.TOP_RIGHT) self.caption = "Sudoku Game 数独的游戏 v1.0.0 by 小叮铃制作组" self.render.open() self.render.add(self.__allSprite) self.render.close() # print(self.render,log()) self.__sudokuMap.playBGM()
def __buildBG(self, color): self.__bg = blankSurface((self.area[2] - 22, self.area[3] - 22), color)
def __buildSurface(self): self.res_surface = blankSurface((self.area.w, self.area.h), self.Color)
def __init__(self, *args): super(pickTest, self).__init__(*args) self.__flag_isEnter = False self.__alpha = 0 self.__flag_recordStartTime = False self.__start_time = 0 self.__now_time = 0 self.res_Img_BG_Name = 'OPT_BG.bmp' self.res_Sound_Choose_Name = 'OPT_C.wav' self.res_UI_RightButton = 'OPT_BR.png' self.res_UI_LeftButton = 'OPT_BL.png' self.__Clock = pygame.time.Clock() self.__KV_AA = {} self.__KV_WAVE = {} self.__ElementsMap = {} if self.config.getTextAntiAlias(): self.__KV_AA['key'] = '开' self.__KV_AA['val'] = '1' else: self.__KV_AA['key'] = '关' self.__KV_AA['val'] = '0' self.res_Sound_Choose = pygame.mixer.Sound(gl_SoundPath + self.res_Sound_Choose_Name) self.res_Sound_Choose.set_volume(self.config.getVolumeSound()) self.res_Img_BG = pygame.image.load(gl_ImgPath + self.res_Img_BG_Name) self.__E_BGBlankL1 = OptButtonElement((40, 60, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankL2 = OptButtonElement((40, 110, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankL3 = OptButtonElement((40, 160, 200, 40), (255, 255, 255, 100)) self.__E_BGBlankLRet = OptButtonElement((50, 520, 80, 40), (255, 255, 255, 100)) self.__E_BGBlankLApply = OptButtonElement((150, 520, 80, 40), (255, 255, 255, 100)) self.__E_BGBlankR = TitleConstElement( (260, 60, 510, 500), blankSurface((510, 500), (255, 255, 255, 100))) self.__E_Text_Apply = TextElement( (centeredXPos(80, 40, 150), centeredYPos(40, 20, 520), 120, 20), '应用', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Apply.zIndex = 1 self.__E_Text_Ret = TextElement( (centeredXPos(80, 40, 50), centeredYPos(40, 20, 520), 120, 20), '返回', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Ret.zIndex = 1 self.__E_Text_Draw = TextElement( (centeredXPos(200, 80, 40), centeredYPos(40, 20, 60), 80, 20), '画面设置', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Draw.zIndex = 1 self.__E_Text_AntiAlias = TextElement((270, 70, 120, 20), '抗锯齿:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_AntiAlias.zIndex = 1 self.__E_Text_AA_Val = TextElement( (670, 70, 20, 20), self.__KV_AA['key'], gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_AA_Val.zIndex = 1 self.__E_UI_AA_RightButton = OptUIElement( (700, 70, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_AA_RightButton.zIndex = 1 self.__E_UI_AA_LeftButton = OptUIElement( (640, 70, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_AA_LeftButton.zIndex = 1 self.__E_Text_Wave = TextElement( (centeredXPos(200, 80, 40), centeredYPos(40, 20, 110), 80, 20), '声音设置', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Wave.zIndex = 1 self.__E_Text_BGMVolume = TextElement((270, 70, 120, 20), '音乐音量:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_BGMVolume.zIndex = 1 self.__E_Text_BGM_Val = TextElement((660, 70, 30, 20), str(self.config.VolumeBGM), gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_BGM_Val.zIndex = 1 self.__E_UI_BGM_RightButton = OptUIElement( (700, 70, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_BGM_RightButton.zIndex = 1 self.__E_UI_BGM_LeftButton = OptUIElement( (630, 70, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_BGM_LeftButton.zIndex = 1 self.__E_Text_SoundVolume = TextElement((270, 100, 120, 20), '音效音量:', gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_SoundVolume.zIndex = 1 self.__E_Text_Sou_Val = TextElement((660, 100, 30, 20), str(self.config.VolumeSound), gl_Font_opt, 18, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Sou_Val.zIndex = 1 self.__E_UI_Sou_RightButton = OptUIElement( (700, 100, 20, 20), gl_UIPath + self.res_UI_RightButton) self.__E_UI_Sou_RightButton.zIndex = 1 self.__E_UI_Sou_LeftButton = OptUIElement( (630, 100, 20, 20), gl_UIPath + self.res_UI_LeftButton) self.__E_UI_Sou_LeftButton.zIndex = 1 self.__E_Text_Licence = TextElement( (centeredXPos(200, 120, 40), centeredYPos(40, 20, 160), 120, 20), '开源软件许可', gl_Font_opt, 20, (0, 0, 0), self.config.getTextAntiAlias()) self.__E_Text_Licence.zIndex = 1 self.__E_Img_Licence = ImgElement(self.__E_BGBlankR.area, gl_ImgPath + 'OPT_L.lice', 255, (128, 128, 128)) self.__E_Img_Licence.zIndex = 1 # 画面设置绑定事件 self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Draw, True), 1) self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([ self.__E_Text_AntiAlias, self.__E_Text_AA_Val, self. __E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ]), 2) self.__E_BGBlankL1.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Draw, False), 1) # 声音设置绑定事件 self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Wave, True), 1) self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([ self.__E_Text_BGMVolume, self.__E_Text_SoundVolume, self. __E_Text_BGM_Val, self.__E_Text_Sou_Val, self. __E_UI_BGM_RightButton, self.__E_UI_BGM_LeftButton, self. __E_UI_Sou_RightButton, self.__E_UI_Sou_LeftButton ]), 2) self.__E_BGBlankL2.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Wave, False), 1) # 开源软件许可按钮绑定事件 self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Licence, True), 1) self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: self.__rebuildElementsToList2([self.__E_Img_Licence]), 2) self.__E_BGBlankL3.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Licence, False), 1) # 应用按钮绑定事件 self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Apply, True), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Apply, False), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_OPT_APPLY), 1) self.__E_BGBlankLApply.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__updConfig(), 2) # 返回按钮绑定事件 self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyDown, lambda: ChePos(self.__E_Text_Ret, True), 1) self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyUp, lambda: ChePos(self.__E_Text_Ret, False), 1) self.__E_BGBlankLRet.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__retSignalIsReadyToEnd(SCENENUM_TITLE), 1) # 抗锯齿UI按钮绑定事件 self.__E_UI_AA_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_AA_Txt(), 1) self.__E_UI_AA_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_AA_Txt(), 1) # 改变音量UI按钮绑定事件 self.__E_UI_BGM_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_BGM_Val, False, GLC_INI_PARAM_BGMVOLUME), 1) self.__E_UI_BGM_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_BGM_Val, True, GLC_INI_PARAM_BGMVOLUME), 1) self.__E_UI_Sou_LeftButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_Sou_Val, False, GLC_INI_PARAM_SOUNDVOLUME), 1) self.__E_UI_Sou_RightButton.Events.appendEvent( ioEvent3Enum.mouseLeftKeyClick, lambda: self.__chVal_WaveParam_Txt( self.__E_Text_Sou_Val, True, GLC_INI_PARAM_SOUNDVOLUME), 1) self.__ElementsMap['Draw1'] = [ self.__E_BGBlankL1, self.__E_BGBlankL2, self.__E_BGBlankL3, self.__E_BGBlankR, self.__E_Text_Draw, self.__E_Text_Wave, self.__E_Text_Licence, self.__E_BGBlankLApply, self.__E_Text_Apply, self.__E_BGBlankLRet, self.__E_Text_Ret ] self.__ElementsMap['Draw2'] = [ self.__E_Text_AntiAlias, self.__E_Text_AA_Val, self.__E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ] self.__ElementsMap['Interact1'] = [ self.__E_BGBlankL1, self.__E_BGBlankL2, self.__E_BGBlankL3, self.__E_BGBlankLApply, self.__E_BGBlankLRet ] self.__ElementsMap['Interact2'] = [ self.__E_UI_AA_RightButton, self.__E_UI_AA_LeftButton ] self.__ElementsMap[ 'Draw'] = self.__ElementsMap['Draw1'] + self.__ElementsMap['Draw2'] self.__ElementsMap['Interact'] = self.__ElementsMap[ 'Interact1'] + self.__ElementsMap['Interact2'] self.render.add(self.__ElementsMap['Draw1']) self.render.add(self.__ElementsMap['Interact']) self.render.close() # 设定渲染参数 self.__step = 4 self.__frameRate = self.config.getFrameRate() if self.__frameRate: self.__step = 255 / (1.5 * self.__frameRate)
def __buildSurface(self): textSize = self.area.h - self.__padding * 2 textTemp = pygame.font.Font(self.__font, textSize) self.res_surface = blankSurface(self.area.size(), (200, 200, 200)) textSurface = textTemp.render(self.__text, self.__antiAlias, self.__color, self.__bgColor) self.res_surface.blit(textSurface, (0, centeredYPos(self.area.h, textSize)))
def __build(self, size, color): self.res_surface = blankSurface(size, color)
def __clearVal(self): if not self.__isStatic: self.__val = 0 self.setImg(blankSurface(self.area.size()))