| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- from game.ui.ui import UIInstance
- import pygame
- from game.file_loader.fileLoader import load_png
- import game.const.game as G
- class DlgPveFunc(UIInstance):
- def __init__(self):
- super().__init__("game", "dlg_pveFuncRouge")
- self.rect.x = 619
- self.rect.y = 537 + G.H_INCREMENT
- self.exitBtn = ExitBtn()
- W,H = self.rect.size
- # 创建一个W+200,H 的surface
- self.imageNew = pygame.Surface((W+G.W_INCREMENT,H), pygame.SRCALPHA, 32)
- from game.level.level import current_level
- self.imageNew.fill((20, 174, 227, 255), (0, 3, W+G.W_INCREMENT, H))
- self.imageNew.fill((106,40,126, 255), (0, 3, W+G.W_INCREMENT, 3+H))
- #self.imageNew.fill((122, 211, 245, 255), (5, 3, 190, H))
- self.imageNew.blit(self.image, (G.W_INCREMENT,0))
- self.image = self.imageNew
- def update(self):
- super().update()
- self.exitBtn.update()
- def draw(self, screen: pygame.Surface):
- super().draw(screen)
- self.exitBtn.draw(screen)
- class ExitBtn(pygame.sprite.Sprite):
- def __init__(self):
- super().__init__()
- self.image_on = load_png("res/img/ui/common/btn_leave_0_2.png")
- self.image_down = load_png("res/img/ui/common/btn_leave_0_3.png")
- # 默认图片为空
- self.defaultImage = pygame.Surface((self.image_on.get_width(), self.image_on.get_height()), pygame.SRCALPHA, 32)
- self.rect = self.image_on.get_rect()
- self.rect.x = 732 + G.W_INCREMENT
- self.rect.y = 545 + G.H_INCREMENT
- self.mouseOn = False # 鼠标是否在按钮上
- self.mouseDown = False # 鼠标是否按下
- self.mouseUp = False # 鼠标是否抬起
- def update(self):
- mousePos = pygame.mouse.get_pos()
- mouseState = pygame.mouse.get_pressed()
- if self.rect.collidepoint(mousePos):
- self.mouseOn = True
- if mouseState[0]:
- self.mouseDown = True
- else:
- if self.mouseDown:
- self.mouseUp = True
- self.mouseDown = False
- else:
- self.mouseOn = False
- self.mouseDown = False
- if self.mouseOn:
- if self.mouseDown:
- self.image = self.image_down
- else:
- self.image = self.image_on
- else:
- self.image = self.defaultImage
- if self.mouseUp:
- self.mouseUp = False # 退出游戏
- # app_task = tk.Tk()
- # roguetest.App(app_task)
- pygame.event.post(pygame.event.Event(pygame.QUIT))
- return True
- return False
- def draw(self, screen: pygame.Surface):
- screen.blit(self.image, self.rect)
|