def __init__(self, screen, config, time): super(AstartTest, self).__init__(screen, config, time) self.cols, self.rows = 100, 100 self.grid = [] self.openSet, self.closeSet = [], [] self.start, self.end = None, None self.w, self.h = screen.get_width() / self.cols, screen.get_height( ) / self.rows self.path = [] self.done = False self.noSolution = False self.points = [] self.__E_TEXT = TextElement( pygame.Rect(centeredXPos(self.width, 220), 260, 220, 60), '', gl_Font, 50, (255, 255, 0), 1) for i in range(0, self.cols): self.grid.append([]) for i in range(0, self.cols): for j in range(0, self.rows): self.grid[i].append(Spot(i, j)) for i in range(0, self.cols): for j in range(0, self.rows): self.grid[i][j].addNeighbors(self.cols, self.rows, self.grid) self.start = self.grid[0][0] self.end = self.grid[self.cols - 1][self.rows - 1] self.start.wall = False self.end.wall = False self.openSet.append(self.start)
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 __getPos(self, x, length, size): if x == 0: return centeredXPos(self.__rect.w, length), 0 if x == 1: return 0, centeredYPos(self.__rect.h, length) if x == 2: return self.__rect.w - length, centeredYPos(self.__rect.h, length) if x == 3: return centeredXPos(self.__rect.w, length), self.__rect.h - size if x == 10: return 0, 0 if x == 11: return self.__rect.w - length, 0 if x == 12: return 0, self.__rect.h - size if x == 13: return self.__rect.w - length, self.__rect.h - size if x == 99: return centeredXYPos(self.__rect.w, length, self.__rect.h, size)
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 __init__(self, *args): super(AnimaEditor, self).__init__(*args) self.caption = "sgf-py GUITools AnimeEditor GUI工具 动画编辑器" self.materialList = list() self.butOutput = butElement((10, 10, 34, 18), "导出", gl_Font_opt, 16, (255, 255, 255), 1) self.butInput = butElement((50, 10, 34, 18), "导入", gl_Font_opt, 16, (255, 255, 255), 1) self.butClear = butElement((90, 10, 34, 18), "清空", gl_Font_opt, 16, (255, 255, 255), 1) self.butDel = butElement((130, 10, 34, 18), "删除", gl_Font_opt, 16, (255, 255, 255), 1) self.butStart = butElement((170, 10, 34, 18), "开始", gl_Font_opt, 16, (255, 255, 255), 1) self.__flg_isStart = False self.butKeyFrame = butElement((210, 10, 82, 18), "设定关键帧", gl_Font_opt, 16, (255, 255, 255), 1) self.butSetTime = butElement((300, 10, 66, 18), "设定时间", gl_Font_opt, 16, (255, 255, 255), 1) self.butSetIntpol = butElement((370, 10, 66, 18), "插值方式", gl_Font_opt, 16, (255, 255, 255), 1) self.butHelp = butElement((440, 10, 34, 18), "帮助", gl_Font_opt, 16, (255, 255, 255), 1) self.currentShow = showImgWin((600, 0, 200, 150)) self.currentShow.zIndex = 999 self.butReshow = butElement((10, self.height - 30, 34, 18), "回放", gl_Font_opt, 16, (255, 255, 255), 1) self.__flg_reshow = False self.butReshowAll = butElement((50, self.height - 30, 66, 18), "全部回放", gl_Font_opt, 16, (255, 255, 255), 1) self.butClearData = butElement((120, self.height - 30, 66, 18), "清除数据", gl_Font_opt, 16, (255, 255, 255), 1) self.__flg_reshowAll = False self.__flg_currentShowIsDownsize = False self.currentShow.Events.appendEvent(ioEvent3Enum.mouseLeftKeyClick, lambda: self.__evn_scale(), 1) self.inputBox = InputElement( (centeredXPos(self.width, 200), self.height - 30, 200, 20), "input") self.inputBox.zIndex = 999 self.currtOp = None self.__prop_Interval = 1 self.__recordStartTime = 0 self.__index = 0
def showImg(self, currentOperation): _tex = currentOperation.getInitTexture() _texW = _tex.get_rect().w _texH = _tex.get_rect().h if _texH > _texW: scaleSizeY = self.area.size()[1] scaleSizeX = scaleSizeY / _texH * _texW blitLocal = (centeredXPos(self.area.w, scaleSizeX), 0) else: scaleSizeX = self.area.size()[0] scaleSizeY = scaleSizeX / _texW * _texH blitLocal = (0, centeredYPos(self.area.h, scaleSizeY)) suf = pygame.transform.scale(_tex, (int(scaleSizeX), int(scaleSizeY))) self.clear((0, 0, 0)) self.res_surface.blit(suf, blitLocal)
def __init__(self, name, bgWidth, bgHeight, _id): self.texture = pygame.image.load(name) self.__texture_w = self.texture.get_rect().w self.__texture_h = self.texture.get_rect().h area = Rectangle(centeredXPos(bgWidth, self.__texture_w), centeredYPos(bgHeight, self.__texture_h), self.__texture_w, self.__texture_h) super(Operation, self).__init__(area, name) self.id = _id self.Interpolation = None self.InterpData = dict() self.__bkupTex = self.texture self.__AnimeSequence = list() self.__AnimeFrames = list() self.Events.appendEvent(ioEvent3Enum.mouseRollDown, lambda: self.__evn_downsizeTex(1), 0) self.Events.appendEvent(ioEvent3Enum.mouseRollUp, lambda: self.__evn_downsizeTex(0), 0) self.__index = 0
def __init__(self, bgWidth, bgHeight, text): super(MessageBox, self).__init__( pygame.Rect(centeredXPos(bgWidth, 180, 0), centeredXPos(bgHeight, 100, 0), 180, 100)) self.__Text = text self.__buildSurface()
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 __init__(self, *args): super(OriginTitle, self).__init__(*args) self.__tempSurf = None self.resPath = {'bg_back': 'bg_back.jpg', 'bg_gear': 'bg_gear.png', 'bg_town': 'bg_town.png', 'bg_airship': 'bg_airship.png', 'bgm': 'bg_BGM.wav', 'bg_title': 'bg_title.png', 'bg_options': 'bg_options.bmp', 'bg_rive': 'bg_rive.png', 'bg_reflect': 'bg_reflect.jpg', 'bg_traveller': 'bg_traveller.png', 'bg_bridge': 'bg_bridge.png', 'bg_pen': 'bg_pen.png', 'bg_copyright': 'bg_copyright.png', 'bg_penBk': 'bg_pen_bk.png', 'bg_cursor': 'cursor.bmp'} self.__ele_mask = MaskElement((0, 0, self.width, self.height)) self.__bgGear_InitImg = pygame.image.load(g_resPath + self.resPath['bg_gear']) self.__spr_bgGear = GearSprite(self.__bgGear_InitImg, pygame.Rect(300, 100, 528, 528)) self.__spr_bgGear.zIndex = 10 self.__spr_airship0 = AirShipSprite(pygame.image.load(g_resPath + self.resPath['bg_airship']), pygame.Rect(250, 45, 166, 153)) self.__spr_airship1 = AirShipSprite(pygame.image.load(g_resPath + self.resPath['bg_airship']), pygame.Rect(100, 70, 83, 77)) self.__spr_airship1.vel = 2 self.__spr_airship2 = AirShipSprite(pygame.image.load(g_resPath + self.resPath['bg_airship']), pygame.Rect(180, 200, 33, 31)) self.__spr_airship2.vel = -1 self.__spr_traveller = TravellerSprite( pygame.image.load(g_resPath + self.resPath['bg_traveller']).convert_alpha(), pygame.Rect(540, 660, 93, 47)) self.__ele_bgTown = ImgElement((0, 0, 1280, 720), g_resPath + self.resPath['bg_town']) self.__ele_bgTown.zIndex = 20 self.__ele_bgBridge = ImgElement((612, self.height - 173, 247, 173), g_resPath + self.resPath['bg_bridge']) self.__ele_bgBridge.zIndex = 30 self.__ele_bgRive = ImgElement((0, 650, 1280, 70), g_resPath + self.resPath['bg_rive']) self.__ele_bgRive.zIndex = 18 self.__ele_bgReflect = ReflectElement((-250, 570, 1280, 184), g_resPath + self.resPath['bg_reflect'], 80) self.__ele_bgTitle = ImgElement((centeredXPos(1280, 450) + 40, 240, 450, 80), g_resPath + self.resPath['bg_title']) self.__ele_bgTitle.zIndex = 100 self.__ele_bgOptions = ImgElement((centeredXPos(self.width, 88), 320, 88, 109), g_resPath + self.resPath['bg_options']) # 选项与鼠标精灵################################################################################## self.__spr_currentOptList = [] self.__spr_currentOpt = None self.__spr_lastOpt = None self.__spr_option1 = OptionSprite(g_resPath + self.resPath['bg_options'], (centeredXPos(self.width, 88), 320, 91, 25), clipSize=(0, 0)) self.__spr_option1.Events.appendEvent(ioEvent3Enum.mouseLeftKeyUp, lambda: self.__clickOption('mouse_left_key_up: scene_title_option1\n'), 1) self.__spr_option2 = OptionSprite(g_resPath + self.resPath['bg_options'], (centeredXPos(self.width, 88), 350, 91, 25), clipSize=(30, 0)) self.__spr_option2.Events.appendEvent(ioEvent3Enum.mouseLeftKeyUp, lambda: self.__clickOption('mouse_left_key_up: scene_title_option2\n'), 1) self.__spr_option3 = OptionSprite(g_resPath + self.resPath['bg_options'], (centeredXPos(self.width, 88), 380, 91, 25), clipSize=(60, 0)) self.__spr_option3.Events.appendEvent(ioEvent3Enum.mouseLeftKeyUp, lambda: self.__clickOption('mouse_left_key_up: scene_title_option3\n'), 1) self.__spr_option4 = OptionSprite(g_resPath + self.resPath['bg_options'], (centeredXPos(self.width, 88), 410, 91, 25), clipSize=(90, 0)) self.__spr_option4.Events.appendEvent(ioEvent3Enum.mouseLeftKeyUp, lambda: self.__clickOption('mouse_left_key_up: scene_title_option4\n'), 1) self.__sprg_mouse_pot = SpriteGroup(self.screenRect, self.__spr_option1, self.__spr_option2, self.__spr_option3, self.__spr_option4) self.__ele_bgPenBk = ImgElement((-999, -999, 102, 5), g_resPath + self.resPath['bg_penBk']) self.__ele_bgPenBk.zIndex = 98 self.__ele_bgPen = PenElement((self.__ele_bgPenBk.area.x, self.__ele_bgPenBk.area.y, 12, 21), g_resPath + self.resPath['bg_pen']) self.__ele_bgCopyright = ImgElement((2, self.height - 22, 274, 18), g_resPath + self.resPath['bg_copyright']) self.__ele_bgCopyright.zIndex = 999 self.rot = 0 self.mixer.addSound('wave_bgm', g_resPath + self.resPath['bgm'])